From 4bd2d5cddfaed291e407c37b9e6f301d4071b8f2 Mon Sep 17 00:00:00 2001 From: Michiel Broek Date: Sat, 1 Jun 2002 12:27:11 +0000 Subject: [PATCH] Fixed virus scan path for mbfile adopt/import --- ChangeLog | 2 ++ TODO | 3 ++ mbfido/mbfadopt.c | 9 ++++-- mbfido/mbfimport.c | 13 +++++--- mbfido/ptic.c | 2 +- mbfido/virscan.c | 77 +++++++++++++++++++++++++++++++--------------- mbfido/virscan.h | 2 +- 7 files changed, 74 insertions(+), 34 deletions(-) diff --git a/ChangeLog b/ChangeLog index 41d7b82d..67881511 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4797,6 +4797,8 @@ v0.33.20 10-Feb-2002 letter 't'. When a virus scanner is started, de mbtask connection timeout is set to one hour. + The virus scanner was sometimes not executed in the right + directory with the adopt and import functions. mball: Will not crash anymore when it needs more then 10 minutes to diff --git a/TODO b/TODO index d0c04b94..ec412cfd 100644 --- a/TODO +++ b/TODO @@ -35,6 +35,9 @@ mbsebbs: L: E-mail downloads with e-mail verification. + N: When a file is attached with netmail that doesn't exist the user + doesn't see an error message. + mbfido: U: Code cleanup and make a structure in this program. Remove duplicate or similar functions. diff --git a/mbfido/mbfadopt.c b/mbfido/mbfadopt.c index ad19de42..b56108d5 100644 --- a/mbfido/mbfadopt.c +++ b/mbfido/mbfadopt.c @@ -48,7 +48,7 @@ extern int do_annon; /* Supress announce file */ void AdoptFile(int Area, char *File, char *Description) { FILE *fp; - char *temp, *temp2, *unarc, *pwd; + char *temp, *temp2, *tmpdir, *unarc, *pwd; char Desc[256], TDesc[256]; int IsArchive = FALSE, MustRearc = FALSE, UnPacked = FALSE; int IsVirus = FALSE, File_Id = FALSE; @@ -67,6 +67,7 @@ void AdoptFile(int Area, char *File, char *Description) temp = calloc(PATH_MAX, sizeof(char)); temp2 = calloc(PATH_MAX, sizeof(char)); pwd = calloc(PATH_MAX, sizeof(char)); + tmpdir = calloc(PATH_MAX, sizeof(char)); if (CheckFDB(Area, area.Path)) die(0); @@ -79,6 +80,7 @@ void AdoptFile(int Area, char *File, char *Description) } sprintf(temp, "%s/%s", pwd, File); + sprintf(tmpdir, "%s/tmp/arc", getenv("MBSE_ROOT")); if ((unarc = unpacker(File)) == NULL) { Syslog('+', "No known archive: %s", File); sprintf(temp2, "%s/tmp/arc/%s", getenv("MBSE_ROOT"), File); @@ -93,7 +95,7 @@ void AdoptFile(int Area, char *File, char *Description) printf("Virscan \b\b\b\b\b\b\b\b\b\b"); fflush(stdout); } - IsVirus = VirScan(); + IsVirus = VirScan(tmpdir); if (IsVirus) { DeleteVirusWork(); chdir(pwd); @@ -116,7 +118,7 @@ void AdoptFile(int Area, char *File, char *Description) fflush(stdout); } - IsVirus = VirScan(); + IsVirus = VirScan(tmpdir); if (IsVirus) { DeleteVirusWork(); chdir(pwd); @@ -277,6 +279,7 @@ void AdoptFile(int Area, char *File, char *Description) free(pwd); free(temp2); free(temp); + free(tmpdir); } else { WriteError("Area %d is not available", Area); if (!do_quiet) diff --git a/mbfido/mbfimport.c b/mbfido/mbfimport.c index 21140676..3f81ab4d 100644 --- a/mbfido/mbfimport.c +++ b/mbfido/mbfimport.c @@ -47,7 +47,7 @@ extern int do_annon; /* Supress announce files */ void ImportFiles(int Area) { - char *pwd, *temp, *temp2, *String, *token, *dest, *unarc; + char *pwd, *temp, *temp2, *tmpdir, *String, *token, *dest, *unarc; FILE *fbbs; int Append = FALSE, Files = 0, rc, i, j = 0, k = 0, x, Doit; int Imported = 0, Errors = 0, Present = FALSE; @@ -66,12 +66,14 @@ void ImportFiles(int Area) temp = calloc(PATH_MAX, sizeof(char)); temp2 = calloc(PATH_MAX, sizeof(char)); pwd = calloc(PATH_MAX, sizeof(char)); + tmpdir = calloc(PATH_MAX, sizeof(char)); String = calloc(4096, sizeof(char)); dest = calloc(PATH_MAX, sizeof(char)); getcwd(pwd, PATH_MAX); if (CheckFDB(Area, area.Path)) die(0); + sprintf(tmpdir, "%s/tmp/arc", getenv("MBSE_ROOT")); IsDoing("Import files"); @@ -114,7 +116,7 @@ void ImportFiles(int Area) printf("Virscan \b\b\b\b\b\b\b\b\b\b"); fflush(stdout); } - if (VirScan()) { + if (VirScan(tmpdir)) { Doit = FALSE; } } @@ -128,7 +130,7 @@ void ImportFiles(int Area) printf("Virscan \b\b\b\b\b\b\b\b\b\b"); fflush(stdout); } - if (VirScan()) { + if (VirScan(tmpdir)) { Doit = FALSE; } } else { @@ -313,7 +315,7 @@ void ImportFiles(int Area) printf("Virscan \b\b\b\b\b\b\b\b\b\b"); fflush(stdout); } - if (VirScan()) { + if (VirScan(tmpdir)) { Doit = FALSE; } } @@ -327,7 +329,7 @@ void ImportFiles(int Area) printf("Virscan \b\b\b\b\b\b\b\b\b\b"); fflush(stdout); } - if (VirScan()) { + if (VirScan(tmpdir)) { Doit = FALSE; } } else { @@ -354,6 +356,7 @@ void ImportFiles(int Area) free(pwd); free(temp2); free(temp); + free(tmpdir); } else { if (!area.Available) { WriteError("Area not available"); diff --git a/mbfido/ptic.c b/mbfido/ptic.c index cab94dde..d9f2924d 100644 --- a/mbfido/ptic.c +++ b/mbfido/ptic.c @@ -513,7 +513,7 @@ int ProcessTic(fa_list *sbl) fflush(stdout); } - if (VirScan()) { + if (VirScan(NULL)) { DeleteVirusWork(); chdir(TIC.Inbound); Bad((char *)"Possible virus found!"); diff --git a/mbfido/virscan.c b/mbfido/virscan.c index f21d5396..0bf0a240 100644 --- a/mbfido/virscan.c +++ b/mbfido/virscan.c @@ -37,40 +37,69 @@ #include "virscan.h" -int VirScan(void) +/* + * Check for known viri, optional in a defined path. + */ +int VirScan(char *path) { - char *temp, *cmd = NULL; + char *pwd, *temp, *cmd = NULL; FILE *fp; - int rc = FALSE; + int rc = FALSE, has_scan = FALSE; temp = calloc(PATH_MAX, sizeof(char)); sprintf(temp, "%s/etc/virscan.data", getenv("MBSE_ROOT")); if ((fp = fopen(temp, "r")) == NULL) { WriteError("No virus scanners defined"); - } else { - fread(&virscanhdr, sizeof(virscanhdr), 1, fp); - - while (fread(&virscan, virscanhdr.recsize, 1, fp) == 1) { - cmd = NULL; - if (virscan.available) { - Altime(3600); - cmd = xstrcpy(virscan.scanner); - cmd = xstrcat(cmd, (char *)" "); - cmd = xstrcat(cmd, virscan.options); - if (execute(cmd, (char *)"*", (char *)NULL, (char *)"/dev/null", - (char *)"/dev/null" , (char *)"/dev/null") != virscan.error) { - Syslog('!', "Virus found by %s", virscan.comment); - rc = TRUE; - } - free(cmd); - Altime(0); - Nopper(); - } - } - fclose(fp); + free(temp); + return FALSE; } + fread(&virscanhdr, sizeof(virscanhdr), 1, fp); + while (fread(&virscan, virscanhdr.recsize, 1, fp) == 1) { + if (virscan.available) + has_scan = TRUE; + } + if (!has_scan) { + Syslog('+', "No active virus scanners, skipping scan"); + fclose(fp); + free(temp); + return FALSE; + } + + pwd = calloc(PATH_MAX, sizeof(char)); + getcwd(pwd, PATH_MAX); + if (path) { + chdir(path); + Syslog('+', "Start virusscan in %s", path); + } else { + Syslog('+', "Start virusscan in %s", pwd); + } + + fseek(fp, virscanhdr.hdrsize, SEEK_SET); + while (fread(&virscan, virscanhdr.recsize, 1, fp) == 1) { + cmd = NULL; + if (virscan.available) { + Altime(3600); + cmd = xstrcpy(virscan.scanner); + cmd = xstrcat(cmd, (char *)" "); + cmd = xstrcat(cmd, virscan.options); + if (execute(cmd, (char *)"*", (char *)NULL, (char *)"/dev/null", + (char *)"/dev/null" , (char *)"/dev/null") != virscan.error) { + Syslog('!', "Virus found by %s", virscan.comment); + rc = TRUE; + } + free(cmd); + Altime(0); + Nopper(); + } + } + fclose(fp); + + if (path) + chdir(pwd); + + free(pwd); free(temp); return rc; } diff --git a/mbfido/virscan.h b/mbfido/virscan.h index 78f8e46d..39e683e7 100644 --- a/mbfido/virscan.h +++ b/mbfido/virscan.h @@ -3,7 +3,7 @@ #ifndef _VIRSCAN_H #define _VIRSCAN_H -int VirScan(void); +int VirScan(char *); #endif