diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/clamsmtpd.c | 38 |
1 files changed, 29 insertions, 9 deletions
diff --git a/src/clamsmtpd.c b/src/clamsmtpd.c index ed85ad1..44ccf46 100644 --- a/src/clamsmtpd.c +++ b/src/clamsmtpd.c @@ -94,11 +94,13 @@ clctx_t; #define CLAM_ERROR "ERROR" #define CLAM_FOUND "FOUND" -#define CONNECT_RSP "PONG" #define CLAM_SCAN "SCAN " +#ifdef USE_CLAM_SESSION +#define CONNECT_RSP "PONG" #define CLAM_CONNECT "SESSION\nPING\n" #define CLAM_DISCONNECT "END\n" +#endif #define DEFAULT_CONFIG CONF_PREFIX "/clamsmtpd.conf" #define DEFAULT_CLAMAV "/var/run/clamav/clamd" @@ -479,8 +481,8 @@ static int connect_clam(clctx_t* ctx) spio_read_junk(sp, &(ctx->clam)); +#ifdef USE_CLAM_SESSION /* Send a session and a check header to ClamAV */ - if(spio_write_data(sp, &(ctx->clam), "SESSION\n") == -1) RETURN(-1); @@ -497,10 +499,11 @@ static int connect_clam(clctx_t* ctx) RETURN(-1); } */ +#endif cleanup: - if(ret < 0) + if(ret < 0 && spio_valid(&(ctx->clam))) spio_disconnect(sp, &(ctx->clam)); return ret; @@ -513,8 +516,10 @@ static int disconnect_clam(clctx_t* ctx) if(!spio_valid(&(ctx->clam))) return 0; +#ifdef USE_CLAM_SESSION if(spio_write_data(sp, &(ctx->clam), CLAM_DISCONNECT) != -1) spio_read_junk(sp, &(ctx->clam)); +#endif spio_disconnect(sp, &(ctx->clam)); return 0; @@ -523,9 +528,17 @@ static int disconnect_clam(clctx_t* ctx) static int clam_scan_file(clctx_t* ctx, const char** virus) { int len, x; + int ret = 0; char* line; spctx_t* sp = &(ctx->sp); + /* Connect to clamav */ + if(!spio_valid(&(ctx->clam))) + { + if(connect_clam(ctx) == -1) + RETURN(-1); + } + ASSERT(ctx && virus); *virus = NULL; @@ -539,20 +552,20 @@ static int clam_scan_file(clctx_t* ctx, const char** virus) strcat(line, "\n"); if(spio_write_data(sp, &(ctx->clam), line) == -1) - return -1; + RETURN(-1); len = spio_read_line(sp, &(ctx->clam), SPIO_DISCARD | SPIO_TRIM); if(len == 0) { sp_messagex(sp, LOG_ERR, "clamd disconnected unexpectedly"); - return -1; + RETURN(-1); } if(is_last_word(line, CLAM_OK, KL(CLAM_OK))) { sp_add_log(sp, "status=", "CLEAN"); sp_messagex(sp, LOG_DEBUG, "no virus"); - return 0; + RETURN(0); } /* @@ -588,19 +601,26 @@ static int clam_scan_file(clctx_t* ctx, const char** virus) *virus = "Unparsable.Virus.Name"; } - return 1; + RETURN(1); } if(is_last_word(line, CLAM_ERROR, KL(CLAM_ERROR))) { sp_messagex(sp, LOG_ERR, "clamav error: %s", line); sp_add_log(sp, "status=", "CLAMAV-ERROR"); - return -1; + RETURN(-1); } sp_add_log(sp, "status=", "CLAMAV-ERROR"); sp_messagex(sp, LOG_ERR, "unexepected response from clamd: %s", line); - return -1; + RETURN(-1); + +cleanup: +#ifndef USE_CLAM_SESSION + disconnect_clam(ctx); +#endif + + return ret; } /* ---------------------------------------------------------------------------------- |