Switched to virus scanner from library

This commit is contained in:
Michiel Broek 2008-02-17 18:46:37 +00:00
parent e9dbd74830
commit adda1c3b6a
2 changed files with 45 additions and 132 deletions

View File

@ -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.

View File

@ -481,54 +481,17 @@ 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);
if ((fp = fopen(temp1, "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);
/* Scanning */
snprintf(msg, 81, "%s %s ", (char *) Language(132), fn);
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);
if (VirScanFile(temp)) {
/* Possible VIRUS found! */
snprintf(msg, 81, "%s", (char *) Language(199));
pout(CFG.HiliteF, CFG.HiliteB, msg);
@ -539,17 +502,7 @@ int ScanDirect(char *fn)
PUTSTR(msg);
}
Enter(1);
Altime(0);
Nopper();
}
}
fclose(fp);
}
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));
/*
* First search for the right archiver program
* Scan file for viri
*/
temp = calloc(PATH_MAX, sizeof(char));
stdlog = calloc(PATH_MAX, sizeof(char));
errlog = calloc(PATH_MAX, sizeof(char));
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);
/*
* Search the right archiver program.
*/
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,12 +623,7 @@ int ScanArchive(char *fn, char *ftype)
chdir(cwd);
free(cwd);
free(temp);
free(stdlog);
free(errlog);
if (Found)
return 2;
else
return 0;
}