2001-08-17 05:46:24 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
*
|
2001-11-18 23:19:08 +00:00
|
|
|
* $Id$
|
2001-08-17 05:46:24 +00:00
|
|
|
* Purpose ...............: Utilities for tic processing
|
|
|
|
*
|
|
|
|
*****************************************************************************
|
2005-08-28 11:56:06 +00:00
|
|
|
* Copyright (C) 1997-2005
|
2001-08-17 05:46:24 +00:00
|
|
|
*
|
|
|
|
* Michiel Broek FIDO: 2:280/2802
|
|
|
|
* Beekmansbos 10
|
|
|
|
* 1971 BV IJmuiden
|
|
|
|
* the Netherlands
|
|
|
|
*
|
|
|
|
* This file is part of MBSE BBS.
|
|
|
|
*
|
|
|
|
* This BBS is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2, or (at your option) any
|
|
|
|
* later version.
|
|
|
|
*
|
|
|
|
* MBSE BBS is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with MBSE BBS; see the file COPYING. If not, write to the Free
|
2003-08-15 20:05:34 +00:00
|
|
|
* Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
|
2001-08-17 05:46:24 +00:00
|
|
|
*****************************************************************************/
|
|
|
|
|
2002-06-30 12:48:44 +00:00
|
|
|
#include "../config.h"
|
2004-02-21 17:22:00 +00:00
|
|
|
#include "../lib/mbselib.h"
|
2005-11-12 12:52:30 +00:00
|
|
|
#include "orphans.h"
|
2001-08-17 05:46:24 +00:00
|
|
|
#include "tic.h"
|
|
|
|
#include "mover.h"
|
|
|
|
#include "tic.h"
|
|
|
|
#include "utic.h"
|
|
|
|
|
|
|
|
|
|
|
|
extern int tic_bad;
|
|
|
|
extern int do_quiet;
|
|
|
|
|
|
|
|
|
|
|
|
char *MakeTicName()
|
|
|
|
{
|
2002-11-26 20:35:50 +00:00
|
|
|
static char buf[13];
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2002-11-26 20:35:50 +00:00
|
|
|
buf[12] = '\0';
|
2005-10-11 20:49:41 +00:00
|
|
|
snprintf(buf, 13, "%08x.tic", sequencer());
|
2002-11-26 20:35:50 +00:00
|
|
|
buf[0] = 'm';
|
|
|
|
buf[1] = 'b';
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2002-11-26 20:35:50 +00:00
|
|
|
return buf;
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return day in the year, 0..365
|
|
|
|
*/
|
|
|
|
int Day_Of_Year()
|
|
|
|
{
|
2002-11-26 20:35:50 +00:00
|
|
|
time_t Now;
|
|
|
|
struct tm *Tm;
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2002-11-26 20:35:50 +00:00
|
|
|
Now = time(NULL);
|
|
|
|
Tm = localtime(&Now);
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2002-11-26 20:35:50 +00:00
|
|
|
return Tm->tm_yday;
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ReArc files in the current directory
|
|
|
|
*/
|
|
|
|
int Rearc(char *unarc)
|
|
|
|
{
|
2002-11-26 20:35:50 +00:00
|
|
|
int i = 0, j = 0, k = 0;
|
|
|
|
char temp[PATH_MAX], *cmd = NULL;
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2002-11-26 20:35:50 +00:00
|
|
|
Syslog('f', "Entering Rearc(%s)", unarc);
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2002-11-26 20:35:50 +00:00
|
|
|
if (!getarchiver(unarc)) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
cmd = xstrcpy(archiver.farc);
|
|
|
|
if (cmd == NULL) {
|
|
|
|
WriteError("Rearc(): No arc command available");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2002-11-26 20:35:50 +00:00
|
|
|
while (TIC.NewFile[i] != '.')
|
|
|
|
i++;
|
|
|
|
i++;
|
|
|
|
|
|
|
|
while (TIC.NewFullName[k] != '.')
|
|
|
|
k++;
|
|
|
|
k++;
|
|
|
|
|
|
|
|
for (; i < strlen(TIC.NewFile); i++) {
|
|
|
|
if (TIC.NewFile[i] > '9') {
|
|
|
|
TIC.NewFile[i] = toupper(unarc[j]);
|
|
|
|
if (isupper(TIC.NewFullName[i]))
|
|
|
|
TIC.NewFullName[i] = toupper(unarc[k]);
|
|
|
|
else
|
|
|
|
TIC.NewFullName[i] = tolower(unarc[k]);
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
2002-11-26 20:35:50 +00:00
|
|
|
j++;
|
|
|
|
k++;
|
|
|
|
}
|
2001-08-17 05:46:24 +00:00
|
|
|
|
|
|
|
|
2002-11-26 20:35:50 +00:00
|
|
|
Syslog('f' , "NewFile=\"%s\", NewFullName=\"%s\"", TIC.NewFile, TIC.NewFullName);
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2005-08-28 14:10:06 +00:00
|
|
|
snprintf(temp, PATH_MAX, "%s/%s .", TIC.Inbound, TIC.NewFile);
|
2004-03-02 20:47:23 +00:00
|
|
|
if (execute_str(cmd, temp, (char *)NULL, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null") == 0) {
|
2002-11-26 20:35:50 +00:00
|
|
|
free(cmd);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2002-11-26 20:35:50 +00:00
|
|
|
/*
|
|
|
|
* Restore filenames
|
|
|
|
*/
|
|
|
|
strncpy(TIC.NewFile, TIC.TicIn.File, sizeof(TIC.NewFile) -1);
|
|
|
|
strncpy(TIC.NewFullName, TIC.TicIn.FullName, sizeof(TIC.NewFullName) -1);
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2002-11-26 20:35:50 +00:00
|
|
|
free(cmd);
|
|
|
|
WriteError("Rearc(%s) Failed", unarc);
|
|
|
|
return FALSE;
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void DeleteVirusWork()
|
|
|
|
{
|
2002-11-26 20:35:50 +00:00
|
|
|
char *buf, *temp;
|
|
|
|
|
|
|
|
buf = calloc(PATH_MAX, sizeof(char));
|
|
|
|
temp = calloc(PATH_MAX, sizeof(char));
|
|
|
|
getcwd(buf, PATH_MAX);
|
2005-08-28 14:10:06 +00:00
|
|
|
snprintf(temp, PATH_MAX, "%s/tmp", getenv("MBSE_ROOT"));
|
2002-11-26 20:35:50 +00:00
|
|
|
|
|
|
|
if (chdir(temp) == 0) {
|
|
|
|
Syslog('f', "DeleteVirusWork %s/arc", temp);
|
2004-03-02 20:47:23 +00:00
|
|
|
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");
|
2002-11-26 20:35:50 +00:00
|
|
|
} else
|
|
|
|
WriteError("$Can't chdir to %s", temp);
|
|
|
|
|
|
|
|
chdir(buf);
|
|
|
|
free(temp);
|
|
|
|
free(buf);
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Bad(char *format, ...)
|
|
|
|
{
|
2002-11-26 20:35:50 +00:00
|
|
|
char outstr[1024];
|
|
|
|
va_list va_ptr;
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2002-11-26 20:35:50 +00:00
|
|
|
va_start(va_ptr, format);
|
2005-08-28 14:10:06 +00:00
|
|
|
vsnprintf(outstr, 1024, format, va_ptr);
|
2002-11-26 20:35:50 +00:00
|
|
|
va_end(va_ptr);
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2002-11-26 20:35:50 +00:00
|
|
|
WriteError(outstr);
|
|
|
|
MoveBad();
|
|
|
|
tic_bad++;
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ReCalcCrc(char *fn)
|
|
|
|
{
|
2002-11-26 20:35:50 +00:00
|
|
|
TIC.Crc_Int = file_crc(fn, CFG.slow_util && do_quiet);
|
2005-10-11 20:49:41 +00:00
|
|
|
snprintf(TIC.TicIn.Crc, 9, "%08X", TIC.Crc_Int);
|
2002-11-26 20:35:50 +00:00
|
|
|
strcpy(T_File.Crc, TIC.TicIn.Crc);
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int Get_File_Id()
|
|
|
|
{
|
2002-05-01 14:40:45 +00:00
|
|
|
char *temp;
|
|
|
|
char Desc[1024];
|
|
|
|
FILE *fp;
|
|
|
|
int i, j, lines = 0;
|
|
|
|
|
|
|
|
temp = calloc(PATH_MAX, sizeof(char));
|
2005-08-28 14:10:06 +00:00
|
|
|
snprintf(temp, PATH_MAX, "%s/tmp/FILE_ID.DIZ", getenv("MBSE_ROOT"));
|
2002-05-01 14:40:45 +00:00
|
|
|
if ((fp = fopen(temp, "r")) == NULL) {
|
2005-08-28 14:10:06 +00:00
|
|
|
snprintf(temp, PATH_MAX, "%s/tmp/file_id.diz", getenv("MBSE_ROOT"));
|
2001-12-09 15:20:51 +00:00
|
|
|
if ((fp = fopen(temp, "r")) == NULL) {
|
2002-05-01 14:40:45 +00:00
|
|
|
free(temp);
|
|
|
|
return FALSE;
|
2001-12-09 15:20:51 +00:00
|
|
|
}
|
2002-05-01 14:40:45 +00:00
|
|
|
}
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2002-05-01 14:40:45 +00:00
|
|
|
/*
|
|
|
|
* Read no more then 25 lines.
|
|
|
|
*/
|
|
|
|
while (((fgets(Desc, 1023, fp)) != NULL) && (TIC.File_Id_Ct < 25)) {
|
|
|
|
lines++;
|
2001-08-17 05:46:24 +00:00
|
|
|
/*
|
2002-05-01 14:40:45 +00:00
|
|
|
* Check if the FILE_ID.DIZ is in a normal layout.
|
|
|
|
* The layout should be max. 10 lines of max. 48 characters.
|
|
|
|
* We check at 51 characters and if the lines are longer,
|
|
|
|
* we trash the FILE_ID.DIZ file.
|
2001-08-17 05:46:24 +00:00
|
|
|
*/
|
2002-05-01 14:40:45 +00:00
|
|
|
if (strlen(Desc) > 51) {
|
|
|
|
fclose(fp);
|
|
|
|
unlink(temp);
|
|
|
|
for (i = 0; i < 25; i++)
|
|
|
|
TIC.File_Id[i][0] = '\0';
|
|
|
|
TIC.File_Id_Ct = 0;
|
|
|
|
Syslog('f', "FILE_ID.DIZ line %d is %d chars", lines, strlen(Desc));
|
|
|
|
Syslog('!', "Trashing illegal formatted FILE_ID.DIZ");
|
|
|
|
free(temp);
|
|
|
|
return FALSE;
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
2002-05-01 14:40:45 +00:00
|
|
|
if (strlen(Desc) > 0) {
|
|
|
|
j = 0;
|
|
|
|
for (i = 0; i < strlen(Desc); i++) {
|
|
|
|
if (isprint(Desc[i])) {
|
|
|
|
TIC.File_Id[TIC.File_Id_Ct][j] = Desc[i];
|
|
|
|
j++;
|
|
|
|
if (j > 47)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2002-05-01 14:40:45 +00:00
|
|
|
/*
|
|
|
|
* Remove trailing spaces
|
|
|
|
*/
|
|
|
|
while (j && isspace(TIC.File_Id[TIC.File_Id_Ct][j-1]))
|
|
|
|
j--;
|
|
|
|
TIC.File_Id[TIC.File_Id_Ct][j] = '\0';
|
|
|
|
TIC.File_Id_Ct++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose(fp);
|
|
|
|
unlink(temp);
|
|
|
|
free(temp);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Strip empty lines at end of FILE_ID.DIZ
|
|
|
|
*/
|
|
|
|
while ((strlen(TIC.File_Id[TIC.File_Id_Ct-1]) == 0) && (TIC.File_Id_Ct))
|
|
|
|
TIC.File_Id_Ct--;
|
|
|
|
|
|
|
|
Syslog('f', "Got %d FILE_ID.DIZ lines", TIC.File_Id_Ct);
|
|
|
|
if (TIC.File_Id_Ct)
|
|
|
|
return TRUE;
|
|
|
|
else
|
|
|
|
return FALSE;
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|