From adda1c3b6afc93a5cf7387cb9d5add01721f2400 Mon Sep 17 00:00:00 2001 From: Michiel Broek Date: Sun, 17 Feb 2008 18:46:37 +0000 Subject: [PATCH] Switched to virus scanner from library --- ChangeLog | 1 + mbsebbs/filesub.c | 176 ++++++++++++---------------------------------- 2 files changed, 45 insertions(+), 132 deletions(-) diff --git a/ChangeLog b/ChangeLog index d0493fa3..d5e7dd7a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -18,6 +18,7 @@ v0.95.1 07-Jan-2008 mbsebbs: Added MIB counters. + Switched to virus scanner from library. mbsetup: Added support for TCP stream scanners. diff --git a/mbsebbs/filesub.c b/mbsebbs/filesub.c index a8458020..d880a2fc 100644 --- a/mbsebbs/filesub.c +++ b/mbsebbs/filesub.c @@ -481,75 +481,28 @@ void Home() */ int ScanDirect(char *fn) { - FILE *fp, *lp; - int err, Found = FALSE; - char *temp, *temp1, *stdlog, *errlog, buf[256], msg[81]; + int Found = FALSE; + char *temp, msg[81]; temp = calloc(PATH_MAX, sizeof(char)); - temp1 = calloc(PATH_MAX, sizeof(char)); - stdlog = calloc(PATH_MAX, sizeof(char)); - errlog = calloc(PATH_MAX, sizeof(char)); - - snprintf(temp, PATH_MAX, "%s/%s/upl/%s", CFG.bbs_usersdir, exitinfo.Name, fn); - snprintf(temp1, PATH_MAX, "%s/etc/virscan.data", getenv("MBSE_ROOT")); - snprintf(stdlog, PATH_MAX, "%s/tmp/stdlog%d", getenv("MBSE_ROOT"), mypid); - snprintf(errlog, PATH_MAX, "%s/tmp/errlog%d", getenv("MBSE_ROOT"), mypid); + snprintf(temp, PATH_MAX, "%s/%s/upl/%s", CFG.bbs_usersdir, exitinfo.Name, fn); - if ((fp = fopen(temp1, "r")) != NULL) { - fread(&virscanhdr, sizeof(virscanhdr), 1, fp); + /* Scanning */ + snprintf(msg, 81, "%s %s ", (char *) Language(132), fn); + pout(CFG.TextColourF, CFG.TextColourB, msg); - while (fread(&virscan, virscanhdr.recsize, 1, fp) == 1) { - - if (virscan.available && (file_exist(virscan.scanner, X_OK) == 0)) { - /* Scanning */ /* with */ - snprintf(msg, 81, "%s %s %s %s ", (char *) Language(132), fn, (char *) Language(133), virscan.comment); - pout(CFG.TextColourF, CFG.TextColourB, msg); - - Altime(3600); - err = execute_str(virscan.scanner, virscan.options, temp, (char *)"/dev/null", stdlog, errlog); - if (file_size(stdlog)) { - if ((lp = fopen(stdlog, "r"))) { - while (fgets(buf, sizeof(buf) -1, lp)) { - Striplf(buf); - Syslog('+', "stdout: \"%s\"", printable(buf, 0)); - } - fclose(lp); - } - } - if (file_size(errlog)) { - if ((lp = fopen(errlog, "r"))) { - while (fgets(buf, sizeof(buf) -1, lp)) { - Striplf(buf); - Syslog('+', "stderr: \"%s\"", printable(buf, 0)); - } - fclose(lp); - } - } - unlink(stdlog); - unlink(errlog); - if (err != virscan.error) { - WriteError("VIRUS ALERT: Result %d (%s)", err, virscan.comment); - /* Possible VIRUS found! */ - snprintf(msg, 81, "%s", (char *) Language(199)); - pout(CFG.HiliteF, CFG.HiliteB, msg); - Found = TRUE; - } else { - /* Ok */ - snprintf(msg, 81, "%s", (char *) Language(200)); - PUTSTR(msg); - } - Enter(1); - Altime(0); - Nopper(); - } - } - fclose(fp); + if (VirScanFile(temp)) { + /* Possible VIRUS found! */ + snprintf(msg, 81, "%s", (char *) Language(199)); + pout(CFG.HiliteF, CFG.HiliteB, msg); + Found = TRUE; + } else { + /* Ok */ + snprintf(msg, 81, "%s", (char *) Language(200)); + PUTSTR(msg); } - + Enter(1); free(temp); - free(temp1); - free(stdlog); - free(errlog); return Found; } @@ -565,18 +518,32 @@ int ScanDirect(char *fn) */ int ScanArchive(char *fn, char *ftype) { - FILE *fp, *lp; - int err = 0, Found = FALSE; - char *temp, *stdlog, *errlog, buf[256], msg[81]; - char *cwd = NULL, *fid; + FILE *fp; + char *temp, *temp2, msg[81], *cwd = NULL, *fid; + + temp = calloc(PATH_MAX, sizeof(char)); + + /* + * Scan file for viri + */ + snprintf(msg, 81, "%s %s ", (char *) Language(132), fn); + pout(CFG.TextColourF, CFG.TextColourB, msg); + snprintf(temp, PATH_MAX, "%s/%s/upl/%s", CFG.bbs_usersdir, exitinfo.Name, fn); + if (VirScanFile(temp)) { + /* Possible VIRUS found! */ + pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(199)); + free(temp); + Enter(1); + return 2; + } else { + /* Ok */ + PUTSTR((char *) Language(200)); + } + Enter(1); /* - * First search for the right archiver program + * Search the right archiver program. */ - temp = calloc(PATH_MAX, sizeof(char)); - stdlog = calloc(PATH_MAX, sizeof(char)); - errlog = calloc(PATH_MAX, sizeof(char)); - snprintf(temp, PATH_MAX, "%s/etc/archiver.data", getenv("MBSE_ROOT")); if ((fp = fopen(temp, "r")) == NULL) { @@ -636,65 +603,15 @@ int ScanArchive(char *fn, char *ftype) snprintf(temp, PATH_MAX, "%s/%s/tmp", CFG.bbs_usersdir, exitinfo.Name); if (getfilecase(temp, fid)) { snprintf(temp, PATH_MAX, "%s/%s/tmp/%s", CFG.bbs_usersdir, exitinfo.Name, fid); - snprintf(stdlog, PATH_MAX, "%s/%s/wrk/FILE_ID.DIZ", CFG.bbs_usersdir, exitinfo.Name); - if (file_cp(temp, stdlog) == 0) { + temp2 = calloc(PATH_MAX, sizeof(char)); + snprintf(temp2, PATH_MAX, "%s/%s/wrk/FILE_ID.DIZ", CFG.bbs_usersdir, exitinfo.Name); + if (file_cp(temp, temp2) == 0) { Syslog('b', "Copied %s", temp); } + free(temp2); } free(fid); - snprintf(stdlog, PATH_MAX, "%s/tmp/stdlog%d", getenv("MBSE_ROOT"), mypid); - snprintf(errlog, PATH_MAX, "%s/tmp/errlog%d", getenv("MBSE_ROOT"), mypid); - snprintf(temp, PATH_MAX, "%s/etc/virscan.data", getenv("MBSE_ROOT")); - - if ((fp = fopen(temp, "r")) != NULL) { - fread(&virscanhdr, sizeof(virscanhdr), 1, fp); - while (fread(&virscan, virscanhdr.recsize, 1, fp) == 1) { - - if (virscan.available && (file_exist(virscan.scanner, X_OK) == 0)) { - /* Scanning */ /* with */ - snprintf(msg, 81, "%s %s %s %s ", (char *) Language(132), fn, (char *) Language(133), virscan.comment); - pout(CFG.TextColourF, CFG.TextColourB, msg); - - Altime(3600); - err = execute_str(virscan.scanner, virscan.options, (char *)NULL, (char *)"/dev/null", stdlog, errlog); - if (file_size(stdlog)) { - if ((lp = fopen(stdlog, "r"))) { - while (fgets(buf, sizeof(buf) -1, lp)) { - Striplf(buf); - Syslog('+', "stdout: \"%s\"", printable(buf, 0)); - } - fclose(lp); - } - } - if (file_size(errlog)) { - if ((lp = fopen(errlog, "r"))) { - while (fgets(buf, sizeof(buf) -1, lp)) { - Striplf(buf); - Syslog('+', "stderr: \"%s\"", printable(buf, 0)); - } - fclose(lp); - } - } - unlink(stdlog); - unlink(errlog); - if (err != virscan.error) { - WriteError("VIRUS ALERT: Result %d (%s)", err, virscan.comment); - /* Possible VIRUS found! */ - pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(199)); - Found = TRUE; - } else { - /* Ok */ - PUTSTR((char *) Language(200)); - } - Enter(1); - Altime(0); - Nopper(); - } - } - fclose(fp); - } - /* * Remove and recreate tmp directory if it was used (or not) */ @@ -706,13 +623,8 @@ int ScanArchive(char *fn, char *ftype) chdir(cwd); free(cwd); free(temp); - free(stdlog); - free(errlog); - if (Found) - return 2; - else - return 0; + return 0; }