New tmp workdir functions
This commit is contained in:
parent
e722bd1d17
commit
033f9611dd
@ -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
|
||||
|
1
Makefile
1
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}
|
||||
|
@ -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
|
||||
|
@ -260,6 +260,7 @@ void die(int onsig)
|
||||
|
||||
signal(onsig, SIG_IGN);
|
||||
deinitnl();
|
||||
clean_tmpwork();
|
||||
|
||||
if (!do_quiet) {
|
||||
show_log = TRUE;
|
||||
|
@ -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");
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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 */
|
||||
|
@ -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);
|
||||
|
||||
/*
|
||||
|
@ -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];
|
||||
|
@ -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);
|
||||
|
Reference in New Issue
Block a user