diff options
| -rw-r--r-- | ChangeLog | 1 | ||||
| -rw-r--r-- | configure.in | 4 | ||||
| -rw-r--r-- | src/clamsmtpd.c | 38 | 
3 files changed, 32 insertions, 11 deletions
@@ -7,6 +7,7 @@    - Ability to drop privileges and run as a different user [Rubio Vaughan]    - Fixed config file bugs    - Virus Actions. Run a script every time a virus is found. +  - By default don't use ClamAV sessions  0.8    - clamsmtpd now uses a configuration file diff --git a/configure.in b/configure.in index b57dd73..f8cb5bf 100644 --- a/configure.in +++ b/configure.in @@ -36,8 +36,8 @@ dnl  Nate Nielsen <nielsen@memberwebs.com>  dnl  dnl Process this file with autoconf to produce a configure script. -AC_INIT(clamsmtp, 0.8.93, nielsen@memberwebs.com) -AM_INIT_AUTOMAKE(clamsmtp, 0.8.93) +AC_INIT(clamsmtp, 0.8.95, nielsen@memberwebs.com) +AM_INIT_AUTOMAKE(clamsmtp, 0.8.95)  LDFLAGS="$LDFLAGS -L/usr/local/lib"  CFLAGS="$CFLAGS -I/usr/local/include" 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;  }  /* ----------------------------------------------------------------------------------  | 
