From 339bf141b99bf64e44818fb704be31a098ddd943 Mon Sep 17 00:00:00 2001 From: Michiel Broek Date: Sun, 25 Nov 2001 12:18:18 +0000 Subject: [PATCH] Added mbfile import command --- ChangeLog | 19 +++ Makefile | 8 +- files.css | 4 +- mbcico/mbcico.c | 25 ---- mbfido/Makefile | 18 ++- mbfido/mbfadopt.c | 368 +++++++++++++++------------------------------- mbfido/mbfcheck.c | 10 +- mbfido/mbfile.c | 16 +- mbfido/mbfindex.c | 2 +- mbfido/mbfpack.c | 16 +- mbfido/mbfutil.c | 235 ++++++++++++++++++++++++++++- mbfido/mbfutil.h | 3 + mbfido/ptic.c | 39 ++--- mbsetup/m_fdb.c | 4 +- 14 files changed, 431 insertions(+), 336 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9b9fd835..2b2af288 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4288,6 +4288,10 @@ v0.33.19 26-Oct-2001 New program, run by user bbs. This is only to register a new bbs user. Should be started by the bbs account. + mbcico: + Removed IEMSI support since mbsebbs doesn't support it + anymore. + mbtask: Changed to handle the External Doors flag in the lastcaller information. @@ -4315,4 +4319,19 @@ v0.33.19 26-Oct-2001 mbfile: During check the file databases are reset to filemode 0660. Implemented "mbfile adopt" function. + Started working on long filename support. The real name on + disk is the long filename, the database records also holds + an uppercase 8.3 filename. In most cases this is just the + same name in upper and lowercase. + Implemented "mbfile import" function, this imports complete + areas from files.bbs information. + + mball: + The index function now creates the web pages with the use of + the long filenames instead of the uppercase dos 8.3 filenames. + Fixed html output for Konqueror browser. + + mbfbgen: + Obsolete and removed from the distribution. The function is + now in mbfile. diff --git a/Makefile b/Makefile index bccdce97..bb383247 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,3 @@ -# Copyright (c) M. Broek, 1997-2000 # Top-level makefile for MBSE BBS package # $Id$ @@ -25,6 +24,9 @@ install: @if [ "`id -un`" != "root" ] ; then \ echo; echo " Must be root to install!"; echo; exit 3; \ fi + @if [ -z ${PREFIX} ] ; then \ + echo; echo "PREFIX is not set!"; echo; exit 3; \ + fi @if [ ! -d ${PREFIX}/bin ] ; then \ mkdir ${PREFIX}/bin ; \ ${CHOWN} ${OWNER}.${GROUP} ${PREFIX}/bin ; \ @@ -56,8 +58,8 @@ install: @if [ ! -d ${PREFIX}/sema ] ; then \ mkdir ${PREFIX}/sema ; \ ${CHOWN} ${OWNER}.${GROUP} ${PREFIX}/sema ; \ - chmod 0777 ${PREFIX}/sema ; \ fi + @chmod 0777 ${PREFIX}/sema @if [ ! -d ${PREFIX}/var ] ; then \ mkdir ${PREFIX}/var ; \ ${CHOWN} ${OWNER}.${GROUP} ${PREFIX}/var ; \ @@ -65,8 +67,8 @@ install: @if [ ! -d ${PREFIX}/tmp ] ; then \ mkdir ${PREFIX}/tmp ; \ ${CHOWN} ${OWNER}.${GROUP} ${PREFIX}/tmp ; \ - chmod 0777 ${PREFIX}/tmp ; \ fi + @chmod 0775 ${PREFIX}/tmp @if [ ! -d ${PREFIX}/dutch ] ; then \ mkdir ${PREFIX}/dutch ; \ mkdir ${PREFIX}/dutch/txtfiles ; \ diff --git a/files.css b/files.css index deb1987c..41ce9870 100644 --- a/files.css +++ b/files.css @@ -1,4 +1,5 @@ /* + * $Id$ * Example stylesheet MBSE BBS file listings. */ @@ -22,5 +23,4 @@ A:active { color: red } TABLE { background: #CCCCCC } TH { background: #99CCFF; font-family: Helvetica } TH.head { background: #FF9900; font-family: Helvetica } -TD { font-family: Fixed; font-size: 12pt } - +TD { font-family: Fixed; font-size: 10pt } diff --git a/mbcico/mbcico.c b/mbcico/mbcico.c index f9546611..c5984f30 100644 --- a/mbcico/mbcico.c +++ b/mbcico/mbcico.c @@ -154,7 +154,6 @@ int main(int argc, char *argv[]) int rc, maxrc, callno = 0, succno = 0; char *answermode = NULL, *p = NULL, *cmd = NULL; struct passwd *pw; - char temp[81]; FILE *fp; #ifdef MEMWATCH @@ -288,30 +287,6 @@ int main(int argc, char *argv[]) while (argv[optind]) { for (p = argv[optind]; (*p) && (*p == '*'); p++); - - if (strncasecmp(p, "EMSI_NAKEEC3", 12) == 0) { - - Syslog('+', "Detected IEMSI client, starting BBS"); - sprintf(temp, "%s/bin/mbsebbs", getenv("MBSE_ROOT")); - socket_shutdown(mypid); - - if (execl(temp, "mbsebbs", (char *)NULL) == -1) - perror("FATAL: Error loading BBS!"); - - /* - * If this happens, nothing is logged! - */ - printf("\n\nFATAL: Loading of the BBS failed!\n\n"); - sleep(3); - free_mem(); - if (envptr) - free(envptr); -#ifdef MEMWATCH - mwTerm(); -#endif - exit(100); - } - if ((strcasecmp(argv[optind],"tsync") == 0) || (strcasecmp(argv[optind],"yoohoo") == 0) || (strcasecmp(argv[optind],"ibn") == 0) || diff --git a/mbfido/Makefile b/mbfido/Makefile index fce6641a..02337735 100644 --- a/mbfido/Makefile +++ b/mbfido/Makefile @@ -12,7 +12,8 @@ SRCS = addbbs.c backalias.c flock.c hatch.c mbdiff.c mgrutil.c pack.c \ postecho.c rollover.c tic.c areamgr.c filefind.c grlist.c maketags.c \ mbmsg.c newspost.c postemail.c scan.c toberep.c atoul.c filemgr.c \ hash.c mbaff.c mbseq.c notify.c postnetmail.c scannews.c tosspkt.c \ - mbfkill.c mbfutil.c mbfindex.c mbfcheck.c mbfpack.c mbflist.c mbfadopt.c + mbfkill.c mbfutil.c mbfindex.c mbfcheck.c mbfpack.c mbflist.c mbfadopt.c \ + mbfimport.c virscan.c HDRS = addbbs.h backalias.h flock.h hatch.h mbdiff.h mgrutil.h pack.h \ postnetmail.h scannews.h tosspkt.h addpkt.h bwrite.h forward.h \ lhash.h mbfido.h mkftnhdr.h paths.h ptic.h sendmail.h tracker.h \ @@ -21,8 +22,9 @@ HDRS = addbbs.h backalias.h flock.h hatch.h mbdiff.h mgrutil.h pack.h \ msgutil.h post.h rnews.h storenet.h utic.h areamgr.h filefind.h \ grlist.h maketags.h mbmsg.h newspost.h postecho.h rollover.h tic.h \ atoul.h filemgr.h hash.h mbaff.h mbseq.h notify.h postemail.h scan.h toberep.h \ - mbfkill.h mbfutil.h mbfindex.h mbfcheck.h mbfpack.h mbflist.h mbfadopt.h -MBFIDO_OBJS = flock.o tosspkt.o mbfido.o hatch.o maketags.o \ + mbfkill.h mbfutil.h mbfindex.h mbfcheck.h mbfpack.h mbflist.h mbfadopt.h \ + mbfimport.h virscan.h +MBFIDO_OBJS = flock.o tosspkt.o mbfido.o hatch.o maketags.o virscan.o \ tracker.o makestat.o scannews.o lhash.o \ pack.o ulock.o tic.o ptic.o utic.o mover.o hash.o mkftnhdr.o \ addbbs.o magic.o fsort.o toberep.o ftn2rfc.o atoul.o ping.o \ @@ -33,7 +35,8 @@ MBSEQ_OBJS = mbseq.o MBAFF_OBJS = announce.o fflist.o filefind.o grlist.o mbaff.o msgutil.o MBINDEX_OBJS = mbindex.o MBDIFF_OBJS = mbdiff.o -MBFILE_OBJS = mbfile.o mbfkill.o mbfutil.o mbfindex.o mbfcheck.o mbfpack.o mbflist.o mbfadopt.o +MBFILE_OBJS = mbfile.o mbfkill.o mbfutil.o mbfindex.o mbfcheck.o mbfpack.o mbflist.o mbfadopt.o \ + mbfimport.o virscan.o MBMSG_OBJS = post.o mbmsg.o MBFIDO_LIBS = ../lib/libmemwatch.a ../lib/libclcomm.a ../lib/libcommon.a ../lib/libmsgbase.a \ ../lib/libdbase.a ../lib/libmbinet.a @@ -134,7 +137,7 @@ hatch.o: ../lib/libs.h ../lib/structs.h ../lib/records.h ../lib/common.h ../lib/ mbdiff.o: ../lib/libs.h ../lib/structs.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h mbdiff.h mgrutil.o: ../lib/libs.h ../lib/structs.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbnode.h sendmail.h mgrutil.h pack.o: ../lib/libs.h ../lib/structs.h ../lib/records.h ../lib/common.h ../lib/dbftn.h ../lib/clcomm.h ../lib/dbnode.h pack.h -ptic.o: ../lib/libs.h ../lib/structs.h ../lib/records.h ../lib/common.h ../lib/dbtic.h ../lib/clcomm.h ../lib/dbnode.h ../lib/dbdupe.h ulock.h mover.h toberep.h tic.h utic.h addbbs.h magic.h forward.h rollover.h ptic.h magic.h +ptic.o: ../lib/libs.h ../lib/structs.h ../lib/records.h ../lib/common.h ../lib/dbtic.h ../lib/clcomm.h ../lib/dbnode.h ../lib/dbdupe.h ulock.h mover.h toberep.h tic.h utic.h addbbs.h magic.h forward.h rollover.h ptic.h magic.h virscan.h sendmail.o: ../lib/libs.h ../lib/structs.h ../lib/records.h ../lib/common.h ../lib/dbnode.h ../lib/clcomm.h ../lib/dbmsgs.h addpkt.h rollover.h sendmail.h tracker.o: ../lib/libs.h ../lib/structs.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbnode.h ../lib/dbftn.h tracker.h addpkt.o: ../lib/libs.h ../lib/structs.h ../lib/records.h ../lib/clcomm.h ../lib/common.h ../lib/dbnode.h ../lib/dbmsgs.h pack.h addpkt.h @@ -151,7 +154,7 @@ aliasdb.o: ../lib/libs.h ../lib/structs.h ../lib/records.h ../lib/common.h ../li cookie.o: ../lib/libs.h ../lib/structs.h ../lib/records.h ../lib/common.h ../lib/clcomm.h cookie.h fsort.o: ../lib/libs.h ../lib/clcomm.h fsort.h magic.o: ../lib/libs.h ../lib/structs.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbtic.h tic.h utic.h magic.h -mbfile.o: ../lib/libs.h ../lib/structs.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h mbfkill.h mbfindex.h mbfcheck.h mbfpack.h mbflist.h mbfutil.h mbfile.h +mbfile.o: ../lib/libs.h ../lib/structs.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h mbfkill.h mbfadopt.h mbfindex.h mbfcheck.h mbfpack.h mbflist.h mbfimport.h mbfutil.h mbfile.h mover.o: ../lib/libs.h ../lib/structs.h ../lib/records.h ../lib/common.h ../lib/clcomm.h tic.h mover.h post.o: ../lib/libs.h ../lib/structs.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h ../lib/msg.h ../lib/msgtext.h post.h rnews.o: ../lib/libs.h ../lib/structs.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/mbinet.h ../lib/dbdupe.h ../lib/dbnode.h ../lib/dbmsgs.h ../lib/msg.h ../lib/msgtext.h pack.h rfc2ftn.h mbfido.h paths.h rnews.h @@ -190,4 +193,7 @@ mbfindex.o: ../lib/libs.h ../lib/structs.h ../lib/records.h ../lib/common.h ../l mbfcheck.o: ../lib/libs.h ../lib/structs.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h mbfutil.h mbfcheck.h mbfpack.o: ../lib/libs.h ../lib/structs.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h mbfutil.h mbfpack.h mbflist.o: ../lib/libs.h ../lib/structs.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h mbfutil.h mbflist.h +mbfadopt.o: ../lib/libs.h ../lib/structs.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h virscan.h mbfutil.h mbflist.h +mbfimport.o: ../lib/libs.h ../lib/structs.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h mbfutil.h mbfimport.h +virscan.o: ../lib/libs.h ../lib/structs.h ../lib/records.h ../lib/common.h ../lib/clcomm.h virscan.h # End of generated dependencies diff --git a/mbfido/mbfadopt.c b/mbfido/mbfadopt.c index 5adc2fea..bda595fa 100644 --- a/mbfido/mbfadopt.c +++ b/mbfido/mbfadopt.c @@ -34,6 +34,7 @@ #include "../lib/common.h" #include "../lib/clcomm.h" #include "../lib/dbcfg.h" +#include "virscan.h" #include "mbfutil.h" #include "mbflist.h" @@ -45,13 +46,12 @@ extern int do_quiet; /* Supress screen output */ void AdoptFile(int Area, char *File, char *Description) { - FILE *pAreas, *pFile, *fp; - char *sAreas, *fAreas, *temp, *temp2, *unarc, *cmd, *pwd; + FILE *pAreas, *fp; + char *sAreas, *temp, *temp2, *unarc, *pwd; char Desc[256], TDesc[256]; int IsArchive = FALSE, MustRearc = FALSE, UnPacked = FALSE; int IsVirus = FALSE, File_Id = FALSE; int i, j, k, lines = 0, File_id_cnt = 0; - int Insert, Done = FALSE, Found = FALSE; struct FILERecord fdb; Syslog('-', "Adopt(%d, %s, %s)", Area, MBSE_SS(File), MBSE_SS(Description)); @@ -89,23 +89,13 @@ void AdoptFile(int Area, char *File, char *Description) } if (area.Available) { - fAreas = calloc(PATH_MAX, sizeof(char)); temp = calloc(PATH_MAX, sizeof(char)); + temp2 = calloc(PATH_MAX, sizeof(char)); pwd = calloc(PATH_MAX, sizeof(char)); - sprintf(fAreas, "%s/fdb/fdb%d.data", getenv("MBSE_ROOT"), Area); + if (CheckFDB(Area, area.Path)) + die(0); getcwd(pwd, PATH_MAX); - - /* - * Open the file database, create new one if it doesn't excist. - */ - if ((pFile = fopen(fAreas, "r+")) == NULL) { - Syslog('!', "Creating new %s", fAreas); - if ((pFile = fopen(fAreas, "a+")) == NULL) { - WriteError("$Can't create %s", fAreas); - die(0); - } - } if (!do_quiet) { printf("Adopt file: %s ", File); @@ -113,116 +103,68 @@ void AdoptFile(int Area, char *File, char *Description) fflush(stdout); } - if ((unarc = unpacker(File)) == NULL) - Syslog('+', "Unknown archive format %s", File); - else { - IsArchive = TRUE; - if (strlen(area.Archiver) && (strcmp(unarc, area.Archiver) == 0)) - MustRearc = TRUE; - } - - if (IsArchive) { - /* - * Check if there is a temp directory to unpack the archive. - */ - sprintf(temp, "%s/tmp/arc", getenv("MBSE_ROOT")); - if ((access(temp, R_OK)) != 0) { - if (mkdir(temp, 0777)) { - WriteError("$Can't create %s", temp); + sprintf(temp, "%s/%s", pwd, File); + if ((unarc = unpacker(File)) == NULL) { + Syslog('+', "No known archive: %s", File); + sprintf(temp2, "%s/tmp/arc/%s", getenv("MBSE_ROOT"), File); + mkdirs(temp2); + if (file_cp(temp, temp2)) { + WriteError("Can't copy file to %s", temp2); + if (!do_quiet) + printf("Can't copy file to %s\n", temp2); + die(0); + } else { + if (!do_quiet) { + printf("Virscan \b\b\b\b\b\b\b\b\b\b"); + fflush(stdout); + } + IsVirus = VirScan(); + if (IsVirus) { + DeleteVirusWork(); + chdir(pwd); + WriteError("Virus found"); if (!do_quiet) - printf("Can't create %s\n", temp); + printf("Virus found\n"); die(0); } } - - /* - * Check for stale FILE_ID.DIZ files - */ - sprintf(temp, "%s/tmp/arc/FILE_ID.DIZ", getenv("MBSE_ROOT")); - if (!unlink(temp)) - Syslog('+', "Removed stale %s", temp); - sprintf(temp, "%s/tmp/arc/file_id.diz", getenv("MBSE_ROOT")); - if (!unlink(temp)) - Syslog('+', "Removed stale %s", temp); - - if (!getarchiver(unarc)) { - WriteError("No archiver available for %s", File); - if (!do_quiet) - printf("No archiver available for %s\n", File); - die(0); - } - - cmd = xstrcpy(archiver.funarc); - if ((cmd == NULL) || (cmd == "")) { - WriteError("No unarc command available"); - if (!do_quiet) - printf("No unarc command available\n"); - die(0); - } - - sprintf(temp, "%s/tmp/arc", getenv("MBSE_ROOT")); - if (chdir(temp) != 0) { - WriteError("$Can't change to %s", temp); + } else { + IsArchive = TRUE; + if (strlen(area.Archiver) && (strcmp(unarc, area.Archiver) == 0)) + MustRearc = TRUE; + UnPacked = UnpackFile(temp); + if (!UnPacked) die(0); - } - - sprintf(temp, "%s/%s", pwd, File); - if (execute(cmd, temp, (char *)NULL, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null") == 0) { - UnPacked = TRUE; - } else { - chdir(pwd); - WriteError("Unpack error, file may be corrupt"); - DeleteVirusWork(); - die(0); - } if (!do_quiet) { printf("Virscan \b\b\b\b\b\b\b\b\b\b"); fflush(stdout); } - 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) { - 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) { - WriteError("Virus found by %s", virscan.comment); - IsVirus = TRUE; - } - free(cmd); - } - } - fclose(fp); - - if (IsVirus) { - DeleteVirusWork(); - chdir(pwd); - WriteError("Virus found"); - if (!do_quiet) - printf("Virus found\n"); - die(0); - } + IsVirus = VirScan(); + if (IsVirus) { + DeleteVirusWork(); + chdir(pwd); + WriteError("Virus found"); + if (!do_quiet) + printf("Virus found\n"); + die(0); } + } - if (!do_quiet) { - printf("Checking \b\b\b\b\b\b\b\b\b\b"); - fflush(stdout); - } + if (!do_quiet) { + printf("Checking \b\b\b\b\b\b\b\b\b\b"); + fflush(stdout); + } - memset(&fdb, 0, sizeof(fdb)); - strcpy(fdb.Uploader, CFG.sysop_name); - fdb.UploadDate = time(NULL); - - temp2 = calloc(PATH_MAX, sizeof(char)); + memset(&fdb, 0, sizeof(fdb)); + strcpy(fdb.Uploader, CFG.sysop_name); + fdb.UploadDate = time(NULL); + + if (UnPacked) { + /* + * Try to get a FILE_ID.DIZ + */ sprintf(temp, "%s/tmp/arc/FILE_ID.DIZ", getenv("MBSE_ROOT")); sprintf(temp2, "%s/tmp/FILE_ID.DIZ", getenv("MBSE_ROOT")); if (file_cp(temp, temp2) == 0) { @@ -232,6 +174,7 @@ void AdoptFile(int Area, char *File, char *Description) if (file_cp(temp, temp2) == 0) File_Id = TRUE; } + if (File_Id) { Syslog('-', "FILE_ID.DIZ found"); if ((fp = fopen(temp2, "r"))) { @@ -280,158 +223,87 @@ void AdoptFile(int Area, char *File, char *Description) Syslog('f', "\"%s\"", fdb.Desc[i]); } } + } - if (!File_id_cnt) { - if (Description == NULL) { - WriteError("No FILE_ID.DIZ and no description on the commandline"); - DeleteVirusWork(); - fclose(pFile); - die(0); - } else { - /* - * Create description from the commandline. - */ - if (strlen(Description) < 48) { - strcpy(fdb.Desc[0], Description); - File_id_cnt++; - } else { - memset(&TDesc, 0, sizeof(TDesc)); - strcpy(TDesc, Description); - while (strlen(TDesc) > 48) { - j = 48; - while (TDesc[j] != ' ') - j--; - strncat(fdb.Desc[File_id_cnt], TDesc, j); - File_id_cnt++; - k = strlen(TDesc); - j++; /* Correct space */ - for (i = 0; i <= k; i++, j++) - TDesc[i] = TDesc[j]; - } - strcpy(fdb.Desc[File_id_cnt], TDesc); - File_id_cnt++; - } - } - } - - /* - * Import the file. - */ - chdir(pwd); - DeleteVirusWork(); - strcpy(fdb.Name, File); - strcpy(fdb.LName, File); - fdb.Size = file_size(File); - fdb.Crc32 = file_crc(File, TRUE); - fdb.FileDate = file_time(File); - sprintf(temp2, "%s/%s", area.Path, File); - - if (!do_quiet) { - printf("Adding \b\b\b\b\b\b\b\b\b\b"); - fflush(stdout); - } - - mkdirs(temp2); - if (file_cp(fdb.LName, temp2)) { - WriteError("Can't move file in place"); - fclose(pFile); + if (!File_id_cnt) { + if (Description == NULL) { + WriteError("No FILE_ID.DIZ and no description on the commandline"); + if (!do_quiet) + printf("No FILE_ID.DIZ and no description on the commandline\n"); + DeleteVirusWork(); die(0); - } - - sprintf(temp2, "%s/fdb/fdb%d.temp", getenv("MBSE_ROOT"), Area); - fseek(pFile, 0, SEEK_END); - if (ftell(pFile) == 0) { - /* - * No records yet - */ - fwrite(&fdb, sizeof(fdb), 1, pFile); - fclose(pFile); - free(temp2); - Syslog('+', "Added file in area %d", Area); } else { /* - * Files are already there. Find the right spot. + * Create description from the commandline. */ - fseek(pFile, 0, SEEK_SET); - - Insert = 0; - do { - if (fread(&file, sizeof(file), 1, pFile) != 1) - Done = TRUE; - if (!Done) { - if (strcmp(fdb.Name, file.Name) == 0) { - Found = TRUE; - Insert++; - } else { - if (strcmp(fdb.Name, file.Name) < 0) - Found = TRUE; - else - Insert++; - } - } - } while ((!Found) && (!Done)); - - if (Found) { - if ((fp = fopen(temp2, "a+")) == NULL) { - WriteError("Can't create %s", temp2); - die(0); - } - - fseek(pFile, 0, SEEK_SET); + if (strlen(Description) < 48) { /* - * Copy until the insert point + * Less then 48 chars, copy and ready. */ - for (i = 0; i < Insert; i++) { - fread(&file, sizeof(file), 1, pFile); - /* - * If we are importing a file with the same name, - * skip the original record and put the new one in place. - */ - if (strcmp(file.Name, fdb.Name) != 0) - fwrite(&file, sizeof(file), 1, fp); - } - if (area.AddAlpha) - fwrite(&fdb, sizeof(fdb), 1, fp); - - /* - * Append the rest of the records - */ - while (fread(&file, sizeof(file), 1, fp) == 1) { - if (strcmp(file.Name, fdb.Name) != 0) - fwrite(&file, sizeof(file), 1, fp); - } - if (!area.AddAlpha) - fwrite(&fdb, sizeof(fdb), 1, fp); - fclose(fp); - fclose(pFile); - - if (unlink(fAreas) == 0) { - rename(temp2, fAreas); - chmod(fAreas, 0660); - Syslog('+', "Added file in area %d", Area); - } else { - WriteError("$Can't unlink %s", fAreas); - unlink(temp2); - } + strcpy(fdb.Desc[0], Description); + File_id_cnt++; } else { /* - * Append file record + * More then 48 characters, break into multiple + * lines not longer then 48 characters. */ - fseek(pFile, 0, SEEK_END); - fwrite(&fdb, sizeof(fdb), 1, pFile); - fclose(pFile); - Syslog('+', "Added file in area %d", Area); + memset(&TDesc, 0, sizeof(TDesc)); + strcpy(TDesc, Description); + while (strlen(TDesc) > 48) { + j = 48; + while (TDesc[j] != ' ') + j--; + strncat(fdb.Desc[File_id_cnt], TDesc, j); + File_id_cnt++; + k = strlen(TDesc); + j++; /* Correct space */ + for (i = 0; i <= k; i++, j++) + TDesc[i] = TDesc[j]; + } + strcpy(fdb.Desc[File_id_cnt], TDesc); + File_id_cnt++; } } - - if (MustRearc) { - /* Here we should call the rearc function */ - } + } + + /* + * Import the file. + */ + chdir(pwd); + DeleteVirusWork(); + if (strlen(File) < 13) { + strcpy(fdb.Name, File); + for (i = 0; i < strlen(File); i++) + fdb.Name[i] = toupper(fdb.Name[i]); + } else { + WriteError("Long filename conversion not supported"); + if (!do_quiet) + printf("Long filename conversion not supported\n"); + die(0); + } + strcpy(fdb.LName, File); + fdb.Size = file_size(File); + fdb.Crc32 = file_crc(File, TRUE); + fdb.FileDate = file_time(File); + sprintf(temp2, "%s/%s", area.Path, File); + + if (!do_quiet) { + printf("Adding \b\b\b\b\b\b\b\b\b\b"); + fflush(stdout); + } + + if (AddFile(fdb, Area, temp2, File) == FALSE) { + die(0); + } + Syslog('+', "File %s added to area %d", File, Area); + + if (MustRearc) { + /* Here we should call the rearc function */ } free(pwd); + free(temp2); free(temp); - free(fAreas); } else { WriteError("Area %d is not available", Area); if (!do_quiet) diff --git a/mbfido/mbfcheck.c b/mbfido/mbfcheck.c index b288b8ca..289d4be9 100644 --- a/mbfido/mbfcheck.c +++ b/mbfido/mbfcheck.c @@ -136,7 +136,7 @@ void Check(void) while (fread(&file, sizeof(file), 1, pFile) == 1) { iTotal++; - sprintf(newdir, "%s/%s", area.Path, file.Name); + sprintf(newdir, "%s/%s", area.Path, file.LName); if (file_exist(newdir, R_OK)) { Syslog('+', "File %s area %d not on disk.", newdir, i); @@ -155,19 +155,19 @@ void Check(void) Marker(); Update = FALSE; if (file_time(newdir) != file.FileDate) { - Syslog('!', "Date mismatch area %d file %s", i, file.Name); + Syslog('!', "Date mismatch area %d file %s", i, file.LName); file.FileDate = file_time(newdir); iErrors++; Update = TRUE; } if (file_size(newdir) != file.Size) { - Syslog('!', "Size mismatch area %d file %s", i, file.Name); + Syslog('!', "Size mismatch area %d file %s", i, file.LName); file.Size = file_size(newdir); iErrors++; Update = TRUE; } if (file_crc(newdir, CFG.slow_util && do_quiet) != file.Crc32) { - Syslog('!', "CRC error area %d, file %s", i, file.Name); + Syslog('!', "CRC error area %d, file %s", i, file.LName); file.Crc32 = file_crc(newdir, CFG.slow_util && do_quiet); iErrors++; Update = TRUE; @@ -192,7 +192,7 @@ void Check(void) Found = FALSE; rewind(pFile); while (fread(&file, sizeof(file), 1, pFile) == 1) { - if (strcmp(file.Name, de->d_name) == 0) { + if (strcmp(file.LName, de->d_name) == 0) { Found = TRUE; break; } diff --git a/mbfido/mbfile.c b/mbfido/mbfile.c index 17054fce..7eb2707d 100644 --- a/mbfido/mbfile.c +++ b/mbfido/mbfile.c @@ -40,6 +40,7 @@ #include "mbfcheck.h" #include "mbfpack.h" #include "mbflist.h" +#include "mbfimport.h" #include "mbfutil.h" #include "mbfile.h" @@ -51,6 +52,7 @@ int do_pack = FALSE; /* Pack filebase */ int do_check = FALSE; /* Check filebase */ int do_kill = FALSE; /* Kill/move old files */ int do_index = FALSE; /* Create request index */ +int do_import= FALSE; /* Import files in area */ int do_list = FALSE; /* List fileareas */ extern int e_pid; /* Pid of external process */ extern int show_log; /* Show logging */ @@ -113,6 +115,15 @@ int main(int argc, char **argv) } if (!strncmp(argv[i], "in", 2)) do_index = TRUE; + if (!strncmp(argv[i], "im", 2)) { + if (argc > (i + 1)) { + do_import = TRUE; + i++; + Area = atoi(argv[i]); + cmd = xstrcat(cmd, (char *)" "); + cmd = xstrcat(cmd, argv[i]); + } + } if (!strncmp(argv[i], "l", 1)) do_list = TRUE; if (!strncmp(argv[i], "p", 1)) @@ -125,7 +136,7 @@ int main(int argc, char **argv) do_quiet = TRUE; } - if (!(do_pack || do_check || do_kill || do_index || do_list || do_adopt)) + if (!(do_pack || do_check || do_kill || do_index || do_import || do_list || do_adopt)) Help(); ProgName(); @@ -146,6 +157,9 @@ int main(int argc, char **argv) if (do_adopt) AdoptFile(Area, FileName, Description); + if (do_import) + ImportFiles(Area); + if (do_kill) Kill(); diff --git a/mbfido/mbfindex.c b/mbfido/mbfindex.c index 9f21c594..0e98d328 100644 --- a/mbfido/mbfindex.c +++ b/mbfido/mbfindex.c @@ -138,7 +138,7 @@ void Index(void) fAreas = calloc(PATH_MAX, sizeof(char)); sIndex = calloc(PATH_MAX, sizeof(char)); - IsDoing("Kill files"); + IsDoing("Index files"); if (!do_quiet) { colour(3, 0); printf("Create filerequest index...\n"); diff --git a/mbfido/mbfpack.c b/mbfido/mbfpack.c index 7d1aedc6..b7a50d76 100644 --- a/mbfido/mbfpack.c +++ b/mbfido/mbfpack.c @@ -40,16 +40,6 @@ extern int do_quiet; /* Supress screen output */ -//int do_pack = FALSE; /* Pack filebase */ -//int do_check = FALSE; /* Check filebase */ -//int do_kill = FALSE; /* Kill/move old files */ -//int do_index = FALSE; /* Create request index */ -//int do_list = FALSE; /* List fileareas */ -//extern int e_pid; /* Pid of external process */ -//extern int show_log; /* Show logging */ -//time_t t_start; /* Start time */ -//time_t t_end; /* End time */ - @@ -60,7 +50,7 @@ extern int do_quiet; /* Supress screen output */ void PackFileBase(void) { FILE *fp, *pAreas, *pFile; - int i, iAreas, iAreasNew = 0; + int i, iAreas, iAreasNew = 0, rc; int iTotal = 0, iRemoved = 0; char *sAreas, *fAreas, *fTmp, fn[PATH_MAX]; @@ -127,7 +117,9 @@ void PackFileBase(void) iRemoved++; Syslog('+', "Removed file \"%s\" from area %d", file.Name, i); sprintf(fn, "%s/%s", area.Path, file.Name); - Syslog('+', "Unlink %s result %d", fn, unlink(fn)); + rc = unlink(fn); + if (rc) + Syslog('+', "Unlink %s result %d", fn, rc); /* * If a dotted version (thumbnail) exists, remove it silently */ diff --git a/mbfido/mbfutil.c b/mbfido/mbfutil.c index 609d28fb..f5d368da 100644 --- a/mbfido/mbfutil.c +++ b/mbfido/mbfutil.c @@ -116,7 +116,7 @@ void Help(void) printf(" a adopt [desc] Adopt file to area\n"); printf(" c check Check filebase\n"); // printf(" d delete Mark file in area for deletion\n"); -// printf(" im import Import files in current dir to area\n"); + printf(" im import Import files in current dir to area\n"); printf(" in index Create filerequest index\n"); printf(" k kill Kill/move old files\n"); printf(" l list List file areas\n"); @@ -220,3 +220,236 @@ void DeleteVirusWork() } + +int UnpackFile(char *File) +{ + char *temp, *pwd, *unarc, *cmd; + + Syslog('f', "UnpackFile(%s)", File); + + if ((unarc = unpacker(File)) == NULL) { + Syslog('+', "Unknown archive format %s", File); + return FALSE; + } + + temp = calloc(PATH_MAX, sizeof(char)); + pwd = calloc(PATH_MAX, sizeof(char)); + getcwd(pwd, PATH_MAX); + + /* + * Check if there is a temp directory to unpack the archive. + */ + sprintf(temp, "%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("Can't create %s\n", temp); + die(0); + } + } + + /* + * Check for stale FILE_ID.DIZ files + */ + sprintf(temp, "%s/tmp/arc/FILE_ID.DIZ", getenv("MBSE_ROOT")); + if (!unlink(temp)) + Syslog('+', "Removed stale %s", temp); + sprintf(temp, "%s/tmp/arc/file_id.diz", getenv("MBSE_ROOT")); + if (!unlink(temp)) + Syslog('+', "Removed stale %s", temp); + + if (!getarchiver(unarc)) { + WriteError("No archiver available for %s", File); + if (!do_quiet) + printf("No archiver available for %s\n", File); + return FALSE; + } + + cmd = xstrcpy(archiver.funarc); + if ((cmd == NULL) || (cmd == "")) { + WriteError("No unarc command available"); + if (!do_quiet) + printf("No unarc command available\n"); + return FALSE; + } + + sprintf(temp, "%s/tmp/arc", getenv("MBSE_ROOT")); + if (chdir(temp) != 0) { + WriteError("$Can't change to %s", temp); + die(0); + } + + if (execute(cmd, File, (char *)NULL, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null") == 0) { + chdir(pwd); + free(temp); + free(pwd); + free(cmd); + return TRUE; + } else { + chdir(pwd); + WriteError("Unpack error, file may be corrupt"); + DeleteVirusWork(); + } + return FALSE; +} + + + +/* + * Add file to the BBS. The file is in the current + * directory. The fdb record already has all needed + * information. + */ +int AddFile(struct FILERecord fdb, int Area, char *DestPath, char *FromPath) +{ + char *temp1, *temp2; + FILE *fp1, *fp2; + int i, Insert, Done = FALSE, Found = FALSE; + + mkdirs(DestPath); + if (file_cp(FromPath, DestPath)) { + WriteError("Can't move file in place"); + return FALSE; + } + + temp1 = calloc(PATH_MAX, sizeof(char)); + temp2 = calloc(PATH_MAX, sizeof(char)); + sprintf(temp1, "%s/fdb/fdb%d.data", getenv("MBSE_ROOT"), Area); + sprintf(temp2, "%s/fdb/fdb%d.temp", getenv("MBSE_ROOT"), Area); + + fp1 = fopen(temp1, "r+"); + fseek(fp1, 0, SEEK_END); + if (ftell(fp1) == 0) { + /* + * No records yet + */ + fwrite(&fdb, sizeof(fdb), 1, fp1); + fclose(fp1); + } else { + /* + * Files are already there. Find the right spot. + */ + fseek(fp1, 0, SEEK_SET); + + Insert = 0; + do { + if (fread(&file, sizeof(file), 1, fp1) != 1) + Done = TRUE; + if (!Done) { + if (strcmp(fdb.Name, file.Name) == 0) { + Found = TRUE; + Insert++; + } else { + if (strcmp(fdb.Name, file.Name) < 0) + Found = TRUE; + else + Insert++; + } + } + } while ((!Found) && (!Done)); + + if (Found) { + if ((fp2 = fopen(temp2, "a+")) == NULL) { + WriteError("Can't create %s", temp2); + return FALSE; + } + + fseek(fp1, 0, SEEK_SET); + /* + * Copy until the insert point + */ + for (i = 0; i < Insert; i++) { + fread(&file, sizeof(file), 1, fp1); + /* + * If we are importing a file with the same name, + * skip the original record and put the new one in place. + */ + if (strcmp(file.Name, fdb.Name) != 0) + fwrite(&file, sizeof(file), 1, fp2); + } + + if (area.AddAlpha) + fwrite(&fdb, sizeof(fdb), 1, fp2); + + /* + * Append the rest of the records + */ + while (fread(&file, sizeof(file), 1, fp1) == 1) { + if (strcmp(file.Name, fdb.Name) != 0) + fwrite(&file, sizeof(file), 1, fp2); + } + if (!area.AddAlpha) + fwrite(&fdb, sizeof(fdb), 1, fp2); + fclose(fp1); + fclose(fp2); + + if (unlink(temp1) == 0) { + rename(temp2, temp1); + chmod(temp1, 0660); + } else { + WriteError("$Can't unlink %s", temp1); + unlink(temp2); + return FALSE; + } + } else { /* if (Found) */ + /* + * Append file record + */ + fseek(fp1, 0, SEEK_END); + fwrite(&fdb, sizeof(fdb), 1, fp1); + fclose(fp1); + } + } + + free(temp1); + free(temp2); + return TRUE; +} + + + +int CheckFDB(int Area, char *Path) +{ + char *temp; + FILE *fp; + int rc = FALSE; + + temp = calloc(PATH_MAX, sizeof(char)); + sprintf(temp, "%s/fdb/fdb%d.data", getenv("MBSE_ROOT"), Area); + + /* + * Open the file database, create new one if it doesn't excist. + */ + if ((fp = fopen(temp, "r+")) == NULL) { + Syslog('!', "Creating new %s", temp); + if ((fp = fopen(temp, "a+")) == NULL) { + WriteError("$Can't create %s", temp); + rc = TRUE; + } else { + fclose(fp); + } + } else { + fclose(fp); + } + + /* + * Set the right attributes + */ + chmod(temp, 0660); + + /* + * Now check the download directory + */ + if (access(Path, W_OK) == -1) { + sprintf(temp, "%s/foobar", Path); + if (mkdirs(temp)) + Syslog('+', "Created directory %s", Path); + } + + free(temp); + + return rc; +} + + diff --git a/mbfido/mbfutil.h b/mbfido/mbfutil.h index 02414d7a..05f65c22 100644 --- a/mbfido/mbfutil.h +++ b/mbfido/mbfutil.h @@ -8,5 +8,8 @@ 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 FILERecord, int, char *, char *); +int CheckFDB(int, char *); /* Check FDB of area */ #endif diff --git a/mbfido/ptic.c b/mbfido/ptic.c index cc934feb..68607ac7 100644 --- a/mbfido/ptic.c +++ b/mbfido/ptic.c @@ -1,8 +1,7 @@ /***************************************************************************** * - * File ..................: mbfido/ptic.c + * $Id$ * Purpose ...............: Process 1 .tic file - * Last modification date : 31-Jul-2001 * ***************************************************************************** * Copyright (C) 1997-2001 @@ -48,6 +47,7 @@ #include "rollover.h" #include "ptic.h" #include "magic.h" +#include "virscan.h" #define UNPACK_FACTOR 300 @@ -501,35 +501,14 @@ int ProcessTic(fa_list *sbl, char *Realname) printf("Virscan \b\b\b\b\b\b\b\b\b\b"); fflush(stdout); } - sprintf(temp2, "%s/etc/virscan.data", getenv("MBSE_ROOT")); - if ((fp = fopen(temp2, "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) { - 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); - IsVirus = TRUE; - } - free(cmd); - } - } - fclose(fp); - - if (IsVirus) { - DeleteVirusWork(); - chdir(TIC.Inbound); - Bad((char *)"Possible virus found!"); - free(Temp); - return 1; - } + IsVirus = VirScan(); + if (IsVirus) { + DeleteVirusWork(); + chdir(TIC.Inbound); + Bad((char *)"Possible virus found!"); + free(Temp); + return 1; } if (!do_quiet) { diff --git a/mbsetup/m_fdb.c b/mbsetup/m_fdb.c index 1ce74ddf..f96d9f0e 100644 --- a/mbsetup/m_fdb.c +++ b/mbsetup/m_fdb.c @@ -163,7 +163,7 @@ void E_F(long areanr) set_color(WHITE, BLACK); mvprintw(y, 1, (char *)"%4d.", o + i); - sprintf(temp, "%s/%s", area.Path, file.Name); + sprintf(temp, "%s/%s", area.Path, file.LName); Ondisk = ((stat(temp, &statfile)) != -1); if (Ondisk) @@ -240,7 +240,7 @@ void E_F(long areanr) crc = 0xffffffff; crc = upd_crc32((char *)&file, crc, sizeof(file)); - sprintf(temp, "%s/%s", area.Path, file.Name); + sprintf(temp, "%s/%s", area.Path, file.LName); if (stat(temp, &statfile) == -1) file.Missing = TRUE;