--- avcheck.c.orig Sun Jul 28 00:22:05 2002 +++ avcheck.c Tue Jan 13 14:04:27 2004 @@ -37,6 +37,9 @@ #ifndef DRWEB # define DRWEB 1 #endif +#ifndef CLAMAV +# define CLAMAV 1 +#endif #ifndef SOPHIE # define SOPHIE 0 /* sophie can't handle MIME properly */ #endif @@ -628,6 +631,53 @@ #endif /* DRWEB */ +#if CLAMAV + +static int +scan_clamav(int fd, const char *path, const char *avname) { + +#define CLAMAV_SCAN_CMD "SCAN" +#define CLAMAV_RETURN_OK "OK" +#define CLAMAV_RETURN_ERROR "ERROR" +#define CLAMAV_RETURN_FOUND "FOUND" + + int l = 0; + char *p, *q; + + snprintf(buf, sizeof(buf), "%s %s\n", CLAMAV_SCAN_CMD, path); + l = strlen(buf); + if (iwrite(fd, buf, l) < 0) + err(errno, "error sending command to %s daemon", avname); + if ((l = read(fd, buf, sizeof(buf))) < 0) + err(errno, "error reading %s daemon response", avname); + buf[l] = '\0'; + if ( !(p = strchr(buf, ' ')) ) + { + err(0, "%s daemon returned unexpected response: %s", buf); + return 1; + } + p++; + if (q = strstr(p, CLAMAV_RETURN_OK)) + return 0; + if (q = strstr(p, CLAMAV_RETURN_ERROR)) + { + *(q - 1) = '\0'; + err(0, "%s daemon returned error: %s", avname, p); + return 1; + } + if (q = strstr(p, CLAMAV_RETURN_FOUND)) + { + *(q - 1) = '\0'; + snprintf(buf, sizeof(buf), "%s", p); + return 1; + } + else + err(0, "%s daemon returned unexpected response: %s", p); + return 1; +} + +#endif /* CLAMAV */ + #if SOPHIE || TROPHIE static int @@ -687,6 +737,9 @@ #endif #if DRWEB { "DrWeb", "127.0.0.1:3000", scan_drweb }, +#endif +#if CLAMAV + { "ClamAV", "127.0.0.1:3310", scan_clamav }, #endif #if SOPHIE { "Sophie", "/var/run/sophie", scan_sophie_trophie },