From 033f9611dd9d6e69b72e27b83e541839a76df65b Mon Sep 17 00:00:00 2001 From: Michiel Broek Date: Sat, 3 Dec 2005 14:52:34 +0000 Subject: [PATCH] New tmp workdir functions --- ChangeLog | 7 ++++++ Makefile | 1 + mbfido/mbfadopt.c | 25 ++++++++++++++-------- mbfido/mbfido.c | 1 + mbfido/mbfimport.c | 18 ++++++++++------ mbfido/mbfutil.c | 45 +++++++++------------------------------ mbfido/mbfutil.h | 1 - mbfido/ptic.c | 53 ++++++++++++++++++++++------------------------ mbfido/utic.c | 23 -------------------- mbfido/utic.h | 1 - 10 files changed, 71 insertions(+), 104 deletions(-) diff --git a/ChangeLog b/ChangeLog index 82c63fb0..22bab4ec 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,10 +2,17 @@ $Id$ v0.83.2 16-Nov-2005 + libmbse.a: + Added temp workdirectory functions. + mbfido: Fixed crash when receiving bad tics. Reinstalled tic orphans and bad crc handling using new method. Removed some debug logging. + Now using new tmp workdirectory functions. + + mbfile: + Now using new tmp workdirectory functions. mbsebbs: Added check for users homedirectory permissions and attempt to diff --git a/Makefile b/Makefile index d155da5d..587aa6d1 100644 --- a/Makefile +++ b/Makefile @@ -146,6 +146,7 @@ install: echo "you may remove that obsolete directory." ; \ fi @rm -rf ${PREFIX}/sema + @rm -rf ${PREFIX}/tmp/arc dist tar: ${TARFILE} diff --git a/mbfido/mbfadopt.c b/mbfido/mbfadopt.c index 661432bf..9cdbbb60 100644 --- a/mbfido/mbfadopt.c +++ b/mbfido/mbfadopt.c @@ -77,12 +77,18 @@ void AdoptFile(int Area, char *File, char *Description) fflush(stdout); } + snprintf(tmpdir, PATH_MAX, "%s/tmp/arc%d", getenv("MBSE_ROOT"), (int)getpid()); + if (create_tmpwork()) { + WriteError("Can't create %s", tmpdir); + if (!do_quiet) + printf("\nCan't create dir %s\n", tmpdir); + die(MBERR_INIT_ERROR); + } + snprintf(temp, PATH_MAX, "%s/%s", pwd, File); - snprintf(tmpdir, PATH_MAX, "%s/tmp/arc", getenv("MBSE_ROOT")); if ((unarc = unpacker(File)) == NULL) { Syslog('+', "No known archive: %s", File); - snprintf(temp2, PATH_MAX, "%s/tmp/arc/%s", getenv("MBSE_ROOT"), File); - mkdirs(temp2, 0755); + snprintf(temp2, PATH_MAX, "%s/tmp/arc%d/%s", getenv("MBSE_ROOT"), (int)getpid(), File); if ((rc = file_cp(temp, temp2))) { WriteError("Can't copy file to %s, %s", temp2, strerror(rc)); if (!do_quiet) @@ -99,7 +105,7 @@ void AdoptFile(int Area, char *File, char *Description) IsVirus = FALSE; } if (IsVirus) { - DeleteVirusWork(); + clean_tmpwork(); chdir(pwd); WriteError("Virus found"); if (!do_quiet) @@ -126,7 +132,7 @@ void AdoptFile(int Area, char *File, char *Description) } if (IsVirus) { - DeleteVirusWork(); + clean_tmpwork(); chdir(pwd); WriteError("Virus found"); if (!do_quiet) @@ -150,12 +156,12 @@ void AdoptFile(int Area, char *File, char *Description) /* * Try to get a FILE_ID.DIZ */ - snprintf(temp, PATH_MAX, "%s/tmp/arc/FILE_ID.DIZ", getenv("MBSE_ROOT")); + snprintf(temp, PATH_MAX, "%s/tmp/arc%d/FILE_ID.DIZ", getenv("MBSE_ROOT"), (int)getpid()); snprintf(temp2, PATH_MAX, "%s/tmp/FILE_ID.DIZ", getenv("MBSE_ROOT")); if (file_cp(temp, temp2) == 0) { File_Id = TRUE; } else { - snprintf(temp, PATH_MAX, "%s/tmp/arc/file_id.diz", getenv("MBSE_ROOT")); + snprintf(temp, PATH_MAX, "%s/tmp/arc%d/file_id.diz", getenv("MBSE_ROOT"), (int)getpid()); if (file_cp(temp, temp2) == 0) File_Id = TRUE; } @@ -215,7 +221,7 @@ void AdoptFile(int Area, char *File, char *Description) WriteError("No FILE_ID.DIZ and no description on the commandline"); if (!do_quiet) printf("\nNo FILE_ID.DIZ and no description on the commandline\n"); - DeleteVirusWork(); + clean_tmpwork(); die(MBERR_COMMANDLINE); } else { /* @@ -255,7 +261,8 @@ void AdoptFile(int Area, char *File, char *Description) * Import the file. */ chdir(pwd); - DeleteVirusWork(); + clean_tmpwork(); + /* * Work out the kind of filename, is it a long filename * or a 8.3 DOS filename. The file on disk must become diff --git a/mbfido/mbfido.c b/mbfido/mbfido.c index 2af9b176..3fb9bf3f 100644 --- a/mbfido/mbfido.c +++ b/mbfido/mbfido.c @@ -260,6 +260,7 @@ void die(int onsig) signal(onsig, SIG_IGN); deinitnl(); + clean_tmpwork(); if (!do_quiet) { show_log = TRUE; diff --git a/mbfido/mbfimport.c b/mbfido/mbfimport.c index c89d1aae..4e68b20e 100644 --- a/mbfido/mbfimport.c +++ b/mbfido/mbfimport.c @@ -86,8 +86,14 @@ void ImportFiles(int Area) getcwd(pwd, PATH_MAX); if (CheckFDB(Area, area.Path)) die(MBERR_GENERAL); - snprintf(tmpdir, PATH_MAX, "%s/tmp/arc", getenv("MBSE_ROOT")); + snprintf(tmpdir, PATH_MAX, "%s/tmp/arc%d", getenv("MBSE_ROOT"), (int)getpid()); + if (create_tmpwork()) { + WriteError("Can't create %s", tmpdir); + if (!do_quiet) + printf("\nCan't create %s\n", tmpdir); + die(MBERR_GENERAL); + } IsDoing("Import files"); /* @@ -117,8 +123,7 @@ void ImportFiles(int Area) Doit = TRUE; if ((unarc = unpacker(temp)) == NULL) { Syslog('+', "Unknown archive format %s", temp); - snprintf(temp2, PATH_MAX, "%s/tmp/arc/%s", getenv("MBSE_ROOT"), f_db.Name); - mkdirs(temp2, 0755); + snprintf(temp2, PATH_MAX, "%s/tmp/arc%d/%s", getenv("MBSE_ROOT"), (int)getpid(), f_db.Name); if ((rc = file_cp(temp, temp2))) { WriteError("Can't copy file to %s, %s", temp2, strerror(rc)); if (!do_quiet) @@ -154,7 +159,7 @@ void ImportFiles(int Area) Doit = FALSE; } } - DeleteVirusWork(); + clean_tmpwork(); if (Doit) { if (!do_quiet) { printf("Adding \b\b\b\b\b\b\b\b\b\b"); @@ -375,8 +380,7 @@ void ImportFiles(int Area) Doit = TRUE; if ((unarc = unpacker(temp)) == NULL) { Syslog('+', "Unknown archive format %s", temp); - snprintf(temp2, PATH_MAX, "%s/tmp/arc/%s", getenv("MBSE_ROOT"), f_db.LName); - mkdirs(temp2, 0755); + snprintf(temp2, PATH_MAX, "%s/tmp/arc%d/%s", getenv("MBSE_ROOT"), (int)getpid(), f_db.LName); if ((rc = file_cp(temp, temp2))) { WriteError("Can't copy file to %s, %s", temp2, strerror(rc)); Doit = FALSE; @@ -410,7 +414,7 @@ void ImportFiles(int Area) Doit = FALSE; } } - DeleteVirusWork(); + clean_tmpwork(); if (Doit) { if (!do_quiet) { printf("Adding \b\b\b\b\b\b\b\b\b\b"); diff --git a/mbfido/mbfutil.c b/mbfido/mbfutil.c index 68512700..b88e8409 100644 --- a/mbfido/mbfutil.c +++ b/mbfido/mbfutil.c @@ -90,6 +90,7 @@ void die(int onsig) WriteError("Terminated with error %d", onsig); } + clean_tmpwork(); ulockprogram((char *)"mbfile"); t_end = time(NULL); Syslog(' ', "MBFILE finished in %s", t_elapsed(t_start, t_end)); @@ -202,29 +203,6 @@ void Marker(void) -void DeleteVirusWork() -{ - char *buf, *temp; - - buf = calloc(PATH_MAX, sizeof(char)); - temp = calloc(PATH_MAX, sizeof(char)); - getcwd(buf, PATH_MAX); - snprintf(temp, PATH_MAX, "%s/tmp", getenv("MBSE_ROOT")); - - if (chdir(temp) == 0) { - Syslog('f', "DeleteVirusWork %s/arc", temp); - execute_pth((char *)"rm", (char *)"-r -f arc", (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null"); - execute_pth((char *)"mkdir", (char *)"arc", (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null"); - } else - WriteError("$Can't chdir to %s", temp); - - chdir(buf); - free(temp); - free(buf); -} - - - int UnpackFile(char *File) { char *temp, *pwd, *unarc, *cmd; @@ -243,23 +221,20 @@ int UnpackFile(char *File) /* * Check if there is a temp directory to unpack the archive. */ - snprintf(temp, PATH_MAX, "%s/tmp/arc", getenv("MBSE_ROOT")); - if ((access(temp, R_OK)) != 0) { - if (mkdir(temp, 0777)) { - WriteError("$Can't create %s", temp); - if (!do_quiet) - printf("\nCan't create %s\n", temp); - die(MBERR_GENERAL); - } + if (create_tmpwork()) { + snprintf(temp, PATH_MAX, "%s/tmp/arc", getenv("MBSE_ROOT")); + if (!do_quiet) + printf("\nCan't create %s\n", temp); + die(MBERR_GENERAL); } /* * Check for stale FILE_ID.DIZ files */ - snprintf(temp, PATH_MAX, "%s/tmp/arc/FILE_ID.DIZ", getenv("MBSE_ROOT")); + snprintf(temp, PATH_MAX, "%s/tmp/arc%d/FILE_ID.DIZ", getenv("MBSE_ROOT"), (int)getpid()); if (!unlink(temp)) Syslog('+', "Removed stale %s", temp); - snprintf(temp, PATH_MAX, "%s/tmp/arc/file_id.diz", getenv("MBSE_ROOT")); + snprintf(temp, PATH_MAX, "%s/tmp/arc%d/file_id.diz", getenv("MBSE_ROOT"), (int)getpid()); if (!unlink(temp)) Syslog('+', "Removed stale %s", temp); @@ -278,7 +253,7 @@ int UnpackFile(char *File) return FALSE; } - snprintf(temp, PATH_MAX, "%s/tmp/arc", getenv("MBSE_ROOT")); + snprintf(temp, PATH_MAX, "%s/tmp/arc%d", getenv("MBSE_ROOT"), (int)getpid()); if (chdir(temp) != 0) { WriteError("$Can't change to %s", temp); die(MBERR_GENERAL); @@ -293,7 +268,7 @@ int UnpackFile(char *File) } else { chdir(pwd); WriteError("Unpack error, file may be corrupt"); - DeleteVirusWork(); + clean_tmpwork(); } return FALSE; } diff --git a/mbfido/mbfutil.h b/mbfido/mbfutil.h index 467c6610..7706b5c6 100644 --- a/mbfido/mbfutil.h +++ b/mbfido/mbfutil.h @@ -7,7 +7,6 @@ void ProgName(void); /* Program name header */ void die(int onsig); /* Shutdown and cleanup */ void Help(void); /* Show help screen */ void Marker(void); /* Eyecatcher */ -void DeleteVirusWork(void); /* Delete unarc directory */ int UnpackFile(char *File); /* Unpack archive */ int AddFile(struct FILE_record, int, char *, char *, char *); int CheckFDB(int, char *); /* Check FDB of area */ diff --git a/mbfido/ptic.c b/mbfido/ptic.c index 389070f0..d9d68312 100644 --- a/mbfido/ptic.c +++ b/mbfido/ptic.c @@ -367,33 +367,30 @@ int ProcessTic(fa_list **sbl, orphans **opl) if ((tic.VirScan || MustRearc) && IsArchive) { /* - * Check if there is a temp directory for the archive conversion. + * Create a temp directory for the archive conversion. */ - snprintf(temp2, PATH_MAX, "%s/tmp/arc", getenv("MBSE_ROOT")); - if ((access(temp2, R_OK)) != 0) { - if (mkdir(temp2, 0777)) { - WriteError("$Can't create %s", temp2); - free(Temp); - tidy_qualify(&qal); - return 1; - } + snprintf(temp2, PATH_MAX, "%s/tmp/arc%d", getenv("MBSE_ROOT"), (int)getpid()); + if (create_tmpwork) { + free(Temp); + tidy_qualify(&qal); + return 1; } /* * Check for stale FILE_ID.DIZ files */ - snprintf(temp1, PATH_MAX, "%s/tmp/arc/FILE_ID.DIZ", getenv("MBSE_ROOT")); - if (!unlink(temp1)) - Syslog('+', "Removed stale %s", temp1); - snprintf(temp1, PATH_MAX, "%s/tmp/arc/file_id.diz", getenv("MBSE_ROOT")); - if (!unlink(temp1)) - Syslog('+', "Removed stale %s", temp1); - snprintf(temp1, PATH_MAX, "%s/tmp/FILE_ID.DIZ", getenv("MBSE_ROOT")); - if (!unlink(temp1)) - Syslog('+', "Removed stale %s", temp1); - snprintf(temp1, PATH_MAX, "%s/tmp/file_id.diz", getenv("MBSE_ROOT")); - if (!unlink(temp1)) - Syslog('+', "Removed stale %s", temp1); +// snprintf(temp1, PATH_MAX, "%s/tmp/arc/FILE_ID.DIZ", getenv("MBSE_ROOT")); +// if (!unlink(temp1)) +// Syslog('+', "Removed stale %s", temp1); +// snprintf(temp1, PATH_MAX, "%s/tmp/arc/file_id.diz", getenv("MBSE_ROOT")); +// if (!unlink(temp1)) +// Syslog('+', "Removed stale %s", temp1); +// snprintf(temp1, PATH_MAX, "%s/tmp/FILE_ID.DIZ", getenv("MBSE_ROOT")); +// if (!unlink(temp1)) +// Syslog('+', "Removed stale %s", temp1); +// snprintf(temp1, PATH_MAX, "%s/tmp/file_id.diz", getenv("MBSE_ROOT")); +// if (!unlink(temp1)) +// Syslog('+', "Removed stale %s", temp1); if (!checkspace(temp2, TIC.TicIn.File, UNPACK_FACTOR)) { Bad((char *)"Not enough free diskspace left"); @@ -429,7 +426,7 @@ int ProcessTic(fa_list **sbl, orphans **opl) chdir(TIC.Inbound); Bad((char *)"Archive maybe corrupt"); free(Temp); - DeleteVirusWork(); + clean_tmpwork(); return 1; } free(cmd); @@ -443,7 +440,7 @@ int ProcessTic(fa_list **sbl, orphans **opl) * with worms or other macro viri */ snprintf(temp1, PATH_MAX, "%s/%s", TIC.Inbound, TIC.TicIn.File); - snprintf(temp2, PATH_MAX, "%s/tmp/arc/%s", getenv("MBSE_ROOT"), TIC.TicIn.File); + snprintf(temp2, PATH_MAX, "%s/tmp/arc%d/%s", getenv("MBSE_ROOT"), (int)getpid(), TIC.TicIn.File); if ((rc = file_cp(temp1, temp2))) { WriteError("Can't copy %s to %s: %s", temp1, temp2, strerror(rc)); @@ -452,7 +449,7 @@ int ProcessTic(fa_list **sbl, orphans **opl) return 1; } - snprintf(temp2, PATH_MAX, "%s/tmp/arc", getenv("MBSE_ROOT")); + snprintf(temp2, PATH_MAX, "%s/tmp/arc%d", getenv("MBSE_ROOT"), (int)getpid()); if (chdir(temp2) != 0) { WriteError("$Can't change to %s", temp2); free(Temp); @@ -469,7 +466,7 @@ int ProcessTic(fa_list **sbl, orphans **opl) } if (VirScan(NULL)) { - DeleteVirusWork(); + clean_tmpwork(); chdir(TIC.Inbound); Bad((char *)"Possible virus found!"); free(Temp); @@ -486,12 +483,12 @@ int ProcessTic(fa_list **sbl, orphans **opl) if (tic.FileId && tic.FileArea && IsArchive) { if (UnPacked) { - snprintf(temp1, PATH_MAX, "%s/tmp/arc/FILE_ID.DIZ", getenv("MBSE_ROOT")); + snprintf(temp1, PATH_MAX, "%s/tmp/arc%d/FILE_ID.DIZ", getenv("MBSE_ROOT"), (int)getpid()); snprintf(temp2, PATH_MAX, "%s/tmp/FILE_ID.DIZ", getenv("MBSE_ROOT")); if (file_cp(temp1, temp2) == 0) { File_Id = TRUE; } else { - snprintf(temp1, PATH_MAX, "%s/tmp/arc/file_id.diz", getenv("MBSE_ROOT")); + snprintf(temp1, PATH_MAX, "%s/tmp/arc%d/file_id.diz", getenv("MBSE_ROOT"), (int)getpid()); if (file_cp(temp1, temp2) == 0) { File_Id = TRUE; } @@ -631,7 +628,7 @@ int ProcessTic(fa_list **sbl, orphans **opl) } } - DeleteVirusWork(); + clean_tmpwork(); chdir(TIC.Inbound); /* diff --git a/mbfido/utic.c b/mbfido/utic.c index ec035009..cdaf75b7 100644 --- a/mbfido/utic.c +++ b/mbfido/utic.c @@ -132,29 +132,6 @@ int Rearc(char *unarc) -void DeleteVirusWork() -{ - char *buf, *temp; - - buf = calloc(PATH_MAX, sizeof(char)); - temp = calloc(PATH_MAX, sizeof(char)); - getcwd(buf, PATH_MAX); - snprintf(temp, PATH_MAX, "%s/tmp", getenv("MBSE_ROOT")); - - if (chdir(temp) == 0) { - Syslog('f', "DeleteVirusWork %s/arc", temp); - execute_pth((char *)"rm", (char *)"-r -f arc", (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null"); - execute_pth((char *)"mkdir", (char *)"arc", (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null"); - } else - WriteError("$Can't chdir to %s", temp); - - chdir(buf); - free(temp); - free(buf); -} - - - void Bad(char *format, ...) { char outstr[1024]; diff --git a/mbfido/utic.h b/mbfido/utic.h index 98d4b152..826466dd 100644 --- a/mbfido/utic.h +++ b/mbfido/utic.h @@ -6,7 +6,6 @@ char *MakeTicName(void); int Day_Of_Year(void); int Rearc(char *); -void DeleteVirusWork(void); void Bad(char *, ...); void ReCalcCrc(char *); int Get_File_Id(void);