From 79327388e9cdb4f0b969d0b3cb45cfbb35c1c0ca Mon Sep 17 00:00:00 2001 From: Michiel Broek Date: Mon, 5 Aug 2002 13:30:44 +0000 Subject: [PATCH] New mail queue system --- mbfido/Makefile | 40 +- mbfido/addpkt.c | 281 +++++---- mbfido/dirlock.c | 129 ++++ mbfido/dirlock.h | 7 + mbfido/dirsession.c | 18 +- mbfido/dirsession.h | 6 +- mbfido/forward.c | 6 +- mbfido/mbfido.c | 1091 +++++++++++++++++----------------- mbfido/mgrutil.c | 4 +- mbfido/pack.c | 539 ----------------- mbfido/pack.h | 11 - mbfido/ptic.c | 2 +- mbfido/queue.c | 523 ++++++++++++++++ mbfido/queue.h | 4 + mbfido/rfc2ftn.c | 1 - mbfido/rnews.c | 4 +- mbfido/scan.c | 4 +- mbfido/scannews.c | 4 +- mbfido/tic.c | 6 +- mbfido/ulock.h | 11 - mbfido/{ulock.c => unpack.c} | 78 +-- mbfido/unpack.h | 9 + 22 files changed, 1437 insertions(+), 1341 deletions(-) create mode 100644 mbfido/dirlock.c create mode 100644 mbfido/dirlock.h delete mode 100644 mbfido/pack.c delete mode 100644 mbfido/pack.h delete mode 100644 mbfido/ulock.h rename mbfido/{ulock.c => unpack.c} (65%) create mode 100644 mbfido/unpack.h diff --git a/mbfido/Makefile b/mbfido/Makefile index 33843732..446aca3a 100644 --- a/mbfido/Makefile +++ b/mbfido/Makefile @@ -4,9 +4,9 @@ include ../Makefile.global -SRCS = addbbs.c backalias.c flock.c hatch.c mbdiff.c mgrutil.c pack.c \ +SRCS = addbbs.c backalias.c flock.c hatch.c mbdiff.c mgrutil.c \ ptic.c sendmail.c tracker.c addpkt.c bwrite.c forward.c lhash.c \ - mbfido.c mkftnhdr.c ping.c rfc2ftn.c storeecho.c ulock.c aliasdb.c \ + mbfido.c mkftnhdr.c ping.c rfc2ftn.c storeecho.c unpack.c aliasdb.c \ fsort.c magic.c mbfile.c mover.c post.c rnews.c storenet.c \ utic.c announce.c fflist.c ftn2rfc.c makestat.c mbindex.c msgutil.c \ postecho.c rollover.c tic.c areamgr.c filefind.c grlist.c maketags.c \ @@ -14,25 +14,26 @@ SRCS = addbbs.c backalias.c flock.c hatch.c mbdiff.c mgrutil.c pack.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 \ mbfimport.c virscan.c mbftoberep.c mbfmove.c mbfdel.c bounce.c \ - createm.c createf.c msgflags.c dirsession.c queue.c -HDRS = addbbs.h backalias.h flock.h hatch.h mbdiff.h mgrutil.h pack.h \ + createm.c createf.c msgflags.c dirsession.c queue.c dirlock.c +HDRS = addbbs.h backalias.h flock.h hatch.h mbdiff.h mgrutil.h \ postnetmail.h scannews.h tosspkt.h addpkt.h bwrite.h forward.h \ lhash.h mbfido.h mkftnhdr.h ptic.h sendmail.h tracker.h \ aliasdb.h fsort.h magic.h mbfile.h mover.h ping.h rfc2ftn.h \ - storeecho.h ulock.h announce.h fflist.h ftn2rfc.h makestat.h mbindex.h \ + storeecho.h unpack.h announce.h fflist.h ftn2rfc.h makestat.h mbindex.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 \ mbfimport.h virscan.h mbftoberep.h mbfmove.h mbfdel.h bounce.h \ - createm.h createf.h msgflags.h dirsession.h queue.h + createm.h createf.h msgflags.h dirsession.h queue.h dirlock.h MBFIDO_OBJS = flock.o tosspkt.o mbfido.o hatch.o maketags.o virscan.o tracker.o \ - makestat.o scannews.o lhash.o bounce.o pack.o ulock.o tic.o ptic.o \ + makestat.o scannews.o lhash.o bounce.o unpack.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 forward.o sendmail.o scan.o addpkt.o \ storenet.o storeecho.o areamgr.o filemgr.o notify.o mgrutil.o rollover.o \ bwrite.o rfc2ftn.o rnews.o newspost.o aliasdb.o postemail.o postnetmail.o \ - postecho.o backalias.o createm.o createf.o msgflags.o dirsession.o queue.o + postecho.o backalias.o createm.o createf.o msgflags.o dirsession.o \ + queue.o dirlock.o MBSEQ_OBJS = mbseq.o MBAFF_OBJS = announce.o fflist.o filefind.o grlist.o mbaff.o msgutil.o MBINDEX_OBJS = mbindex.o @@ -139,28 +140,27 @@ backalias.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib flock.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/clcomm.h flock.h hatch.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbtic.h utic.h rollover.h hatch.h mbdiff.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h mbdiff.h -mgrutil.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbnode.h ../lib/diesel.h sendmail.h rollover.h addpkt.h pack.h createm.h createf.h mgrutil.h -pack.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/dbftn.h ../lib/clcomm.h ../lib/dbnode.h dirsession.h pack.h -ptic.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.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 createf.h virscan.h +mgrutil.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbnode.h ../lib/diesel.h sendmail.h rollover.h addpkt.h createm.h createf.h mgrutil.h +ptic.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/dbtic.h ../lib/clcomm.h ../lib/dbnode.h ../lib/dbdupe.h unpack.h mover.h toberep.h tic.h utic.h addbbs.h magic.h forward.h rollover.h ptic.h magic.h createf.h virscan.h sendmail.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/dbnode.h ../lib/clcomm.h ../lib/dbmsgs.h addpkt.h rollover.h sendmail.h tracker.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbnode.h ../lib/dbftn.h tracker.h -addpkt.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/clcomm.h ../lib/common.h ../lib/dbnode.h ../lib/dbmsgs.h pack.h addpkt.h +addpkt.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/clcomm.h ../lib/common.h ../lib/dbnode.h ../lib/dbmsgs.h addpkt.h bwrite.o: ../config.h ../lib/libs.h ../lib/memwatch.h bwrite.h forward.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbnode.h ../lib/dbtic.h ../lib/diesel.h tic.h sendmail.h rollover.h mgrutil.h forward.h dirsession.h lhash.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/clcomm.h lhash.h -mbfido.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbdupe.h ../lib/dbcfg.h ../lib/dbnode.h ../lib/dbmsgs.h ../lib/dbuser.h ../lib/dbftn.h ../lib/dbtic.h ../lib/msg.h flock.h tosspkt.h pack.h ulock.h tic.h fsort.h scan.h mbfido.h tracker.h notify.h rollover.h hatch.h scannews.h maketags.h makestat.h newspost.h rnews.h mgrutil.h backalias.h rfc2ftn.h dirsession.h +mbfido.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbdupe.h ../lib/dbcfg.h ../lib/dbnode.h ../lib/dbmsgs.h ../lib/dbuser.h ../lib/dbftn.h ../lib/dbtic.h ../lib/msg.h flock.h tosspkt.h unpack.h tic.h fsort.h scan.h mbfido.h tracker.h notify.h rollover.h hatch.h scannews.h maketags.h makestat.h newspost.h rnews.h mgrutil.h backalias.h rfc2ftn.h dirsession.h dirlock.h queue.h mkftnhdr.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h atoul.h hash.h msgflags.h aliasdb.h mkftnhdr.h ping.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/msg.h ../lib/msgtext.h ../lib/dbcfg.h ../lib/dbnode.h ../lib/dbtic.h ../lib/dbdupe.h ../lib/dbuser.h ../lib/dbftn.h sendmail.h postnetmail.h ping.h -rfc2ftn.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.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 mkftnhdr.h hash.h rollover.h pack.h postnetmail.h postecho.h msgflags.h rfc2ftn.h +rfc2ftn.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.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 mkftnhdr.h hash.h rollover.h postnetmail.h postecho.h msgflags.h rfc2ftn.h storeecho.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/msg.h ../lib/msgtext.h ../lib/dbmsgs.h ../lib/dbuser.h rollover.h storeecho.h -ulock.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h flock.h ulock.h +unpack.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h flock.h unpack.h aliasdb.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h aliasdb.h fsort.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/clcomm.h fsort.h magic.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbtic.h tic.h utic.h magic.h mbfile.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.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 mbftoberep.h mbfmove.h mbfdel.h mbfutil.h mbfile.h mover.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h tic.h mover.h post.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h ../lib/msg.h ../lib/msgtext.h post.h -rnews.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.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 +rnews.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.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 rfc2ftn.h mbfido.h ../paths.h rnews.h storenet.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/msg.h ../lib/msgtext.h ../lib/dbmsgs.h ../lib/dbuser.h msgflags.h rollover.h storenet.h utic.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h tic.h mover.h tic.h utic.h announce.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h ../lib/msg.h ../lib/msgtext.h ../lib/diesel.h grlist.h msgutil.h announce.h @@ -171,7 +171,7 @@ mbindex.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/u msgutil.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h ../lib/msg.h ../lib/msgtext.h ../lib/diesel.h msgutil.h postecho.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/msg.h ../lib/msgtext.h ../lib/dbcfg.h ../lib/dbnode.h ../lib/dbmsgs.h ../lib/dbdupe.h ../lib/dbuser.h ../lib/dbftn.h ftn2rfc.h postecho.h storeecho.h addpkt.h rollover.h rollover.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h rollover.h -tic.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/dbftn.h ../lib/clcomm.h ulock.h ptic.h fsort.h pack.h tic.h +tic.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/dbftn.h ../lib/clcomm.h unpack.h ptic.h fsort.h tic.h areamgr.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/msg.h ../lib/msgtext.h ../lib/dbcfg.h ../lib/dbnode.h ../lib/dbmsgs.h ../lib/dbdupe.h ../lib/dbuser.h ../lib/dbftn.h ../lib/diesel.h sendmail.h mgrutil.h scan.h createm.h areamgr.h filefind.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h ../lib/msg.h ../lib/msgtext.h ../lib/diesel.h fflist.h filefind.h msgutil.h grlist.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/clcomm.h grlist.h @@ -179,7 +179,7 @@ maketags.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/ mbmsg.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/msg.h ../lib/dbcfg.h post.h mbmsg.h newspost.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/mbinet.h newspost.h postemail.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/dbuser.h ../lib/common.h ../lib/clcomm.h ../lib/mbinet.h postemail.h -scan.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/msg.h ../lib/clcomm.h ../lib/msgtext.h ../lib/dbnode.h ../lib/dbmsgs.h addpkt.h pack.h tracker.h ftn2rfc.h rfc2ftn.h postemail.h scan.h +scan.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/msg.h ../lib/clcomm.h ../lib/msgtext.h ../lib/dbnode.h ../lib/dbmsgs.h addpkt.h tracker.h ftn2rfc.h rfc2ftn.h postemail.h scan.h toberep.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h tic.h toberep.h atoul.o: ../config.h ../lib/libs.h ../lib/memwatch.h atoul.h filemgr.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/msg.h ../lib/msgtext.h ../lib/dbcfg.h ../lib/dbnode.h ../lib/dbtic.h ../lib/dbdupe.h ../lib/dbuser.h ../lib/dbftn.h ../lib/diesel.h sendmail.h mgrutil.h createf.h filemgr.h @@ -188,7 +188,7 @@ mbaff.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/use mbseq.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h mbseq.h notify.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/msg.h ../lib/msgtext.h ../lib/dbnode.h filemgr.h areamgr.h sendmail.h notify.h postnetmail.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/common.h ../lib/records.h ../lib/dbcfg.h ../lib/dbuser.h ../lib/dbnode.h ../lib/dbftn.h ../lib/clcomm.h tracker.h addpkt.h storenet.h ftn2rfc.h areamgr.h filemgr.h ping.h bounce.h postemail.h -scannews.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.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 mkftnhdr.h hash.h rollover.h pack.h storeecho.h rfc2ftn.h scannews.h +scannews.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.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 mkftnhdr.h hash.h rollover.h storeecho.h rfc2ftn.h scannews.h tosspkt.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/msg.h ../lib/msgtext.h ../lib/dbcfg.h ../lib/dbnode.h ../lib/dbmsgs.h ../lib/dbdupe.h ../lib/dbuser.h ../lib/dbftn.h tosspkt.h postnetmail.h postecho.h rollover.h createm.h mbfkill.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h mbfkill.h mbfutil.h mbfutil.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h mbfutil.h mbfile.h @@ -207,4 +207,6 @@ createm.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/u createf.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h mgrutil.h createf.h msgflags.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/clcomm.h msgflags.h dirsession.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h dirsession.h +queue.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbnode.h ../lib/dbftn.h fsort.h dirsession.h queue.h +dirlock.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h flock.h dirlock.h # End of generated dependencies diff --git a/mbfido/addpkt.c b/mbfido/addpkt.c index 84804b68..c20a64b5 100644 --- a/mbfido/addpkt.c +++ b/mbfido/addpkt.c @@ -38,10 +38,11 @@ #include "../lib/common.h" #include "../lib/dbnode.h" #include "../lib/dbmsgs.h" -#include "pack.h" #include "addpkt.h" +extern int do_flush; + static char *months[]={(char *)"Jan",(char *)"Feb",(char *)"Mar", (char *)"Apr",(char *)"May",(char *)"Jun", @@ -51,80 +52,128 @@ static char *months[]={(char *)"Jan",(char *)"Feb",(char *)"Mar", extern int do_unprot; +/* + * Prepare ARCmail, this is actually just a rename of the temporary + * .pkt file on the queue to a permanent .pkt name that will later + * be added to the real ARCmail bundle. + */ +int PrepARC(char *, fidoaddr); +int PrepARC(char *Queue, fidoaddr Dest) +{ + char *pktfile; + FILE *fp; + + Syslog('p', "Prepare ARCmail for %s", aka2str(Dest)); + + if (!SearchNode(Dest)) { + WriteError("Downlink %s not found", aka2str(Dest)); + return FALSE; + } + + pktfile = calloc(PATH_MAX, sizeof(char)); + sprintf(pktfile, "%s/%d.%d.%d.%d/%08lx.pkt", CFG.out_queue, Dest.zone, Dest.net, Dest.node, Dest.point, sequencer()); + Syslog('p', "Rename .pkt to %s", pktfile); + + if (rename(Queue, pktfile)) { + WriteError("$Can't rename %s to %s", Queue, pktfile); + free(pktfile); + return FALSE; + } + + /* + * Add zero word to end of .pkt file + */ + if ((fp = fopen(pktfile, "a+")) == NULL) { + WriteError("$Can't open %s", pktfile); + free(pktfile); + return FALSE; + } + putc('\0', fp); + putc('\0', fp); + fsync(fileno(fp)); + fclose(fp); + + free(pktfile); + return TRUE; +} + + + FILE *CreatePkt(char *, fidoaddr, fidoaddr, char *); FILE *CreatePkt(char *Queue, fidoaddr Orig, fidoaddr Dest, char *Extension) { - FILE *qp; - unsigned char buffer[0x3a]; - time_t Now; - int i; - struct tm *Tm; - char str[81]; + static FILE *qp; + unsigned char buffer[0x3a]; + time_t Now; + int i; + struct tm *Tm; + char str[81]; - if ((qp = fopen(Queue, "a")) == NULL) { - WriteError("$Can't create Queue %s", Queue); - return NULL; + if ((qp = fopen(Queue, "a")) == NULL) { + WriteError("$Can't create Queue %s", Queue); + return NULL; + } + Syslog('p', "CreatePkt(%s, %s, %s)", Queue, aka2str(Dest), Extension); + + /* + * Write .PKT header, see FSC-0039 rev. 4 + */ + memset(&buffer, 0, sizeof(buffer)); + Now = time(NULL); + Tm = localtime(&Now); + if (Tm->tm_sec > 59) + Tm->tm_sec = 59; + + buffer[0x00] = (Orig.node & 0x00ff); + buffer[0x01] = (Orig.node & 0xff00) >> 8; + buffer[0x02] = (Dest.node & 0x00ff); + buffer[0x03] = (Dest.node & 0xff00) >> 8; + buffer[0x04] = ((Tm->tm_year + 1900) & 0x00ff); + buffer[0x05] = ((Tm->tm_year + 1900) & 0xff00) >> 8; + buffer[0x06] = Tm->tm_mon; + buffer[0x08] = Tm->tm_mday; + buffer[0x0a] = Tm->tm_hour; + buffer[0x0c] = Tm->tm_min; + buffer[0x0e] = Tm->tm_sec; + buffer[0x12] = 2; + buffer[0x14] = (Orig.net & 0x00ff); + buffer[0x15] = (Orig.net & 0xff00) >> 8; + buffer[0x16] = (Dest.net & 0x00ff); + buffer[0x17] = (Dest.net & 0xff00) >> 8; + buffer[0x18] = 0xfe; + + memset(&str, 0, 8); /* Packet password */ + if (SearchNode(Dest)) { + if (strlen(nodes.Epasswd)) { + sprintf(str, "%s", nodes.Epasswd); } + } - /* - * Write .PKT header, see FSC-0039 rev. 4 - */ - memset(&buffer, 0, sizeof(buffer)); - Now = time(NULL); - Tm = localtime(&Now); - if (Tm->tm_sec > 59) - Tm->tm_sec = 59; + for (i = 0; i < 8; i++) + buffer[0x1a + i] = str[i]; - buffer[0x00] = (Orig.node & 0x00ff); - buffer[0x01] = (Orig.node & 0xff00) >> 8; - buffer[0x02] = (Dest.node & 0x00ff); - buffer[0x03] = (Dest.node & 0xff00) >> 8; - buffer[0x04] = ((Tm->tm_year + 1900) & 0x00ff); - buffer[0x05] = ((Tm->tm_year + 1900) & 0xff00) >> 8; - buffer[0x06] = Tm->tm_mon; - buffer[0x08] = Tm->tm_mday; - buffer[0x0a] = Tm->tm_hour; - buffer[0x0c] = Tm->tm_min; - buffer[0x0e] = Tm->tm_sec; - buffer[0x12] = 2; - buffer[0x14] = (Orig.net & 0x00ff); - buffer[0x15] = (Orig.net & 0xff00) >> 8; - buffer[0x16] = (Dest.net & 0x00ff); - buffer[0x17] = (Dest.net & 0xff00) >> 8; - buffer[0x18] = 0xfe; + buffer[0x22] = (Orig.zone & 0x00ff); + buffer[0x23] = (Orig.zone & 0xff00) >> 8; + buffer[0x24] = (Dest.zone & 0x00ff); + buffer[0x25] = (Dest.zone & 0xff00) >> 8; + buffer[0x29] = 1; + buffer[0x2c] = 1; + buffer[0x2e] = buffer[0x22]; + buffer[0x2f] = buffer[0x23]; + buffer[0x30] = buffer[0x24]; + buffer[0x31] = buffer[0x25]; + buffer[0x32] = (Orig.point & 0x00ff); + buffer[0x33] = (Orig.point & 0xff00) >> 8; + buffer[0x34] = (Dest.point & 0x00ff); + buffer[0x35] = (Dest.point & 0xff00) >> 8; + buffer[0x36] = 'm'; + buffer[0x37] = 'b'; + buffer[0x38] = 's'; + buffer[0x39] = 'e'; + fwrite(buffer, 1, 0x3a, qp); - memset(&str, 0, 8); /* Packet password */ - if (SearchNode(Dest)) { - if (strlen(nodes.Epasswd)) { - sprintf(str, "%s", nodes.Epasswd); - } - } - - for (i = 0; i < 8; i++) - buffer[0x1a + i] = str[i]; - - buffer[0x22] = (Orig.zone & 0x00ff); - buffer[0x23] = (Orig.zone & 0xff00) >> 8; - buffer[0x24] = (Dest.zone & 0x00ff); - buffer[0x25] = (Dest.zone & 0xff00) >> 8; - buffer[0x29] = 1; - buffer[0x2c] = 1; - buffer[0x2e] = buffer[0x22]; - buffer[0x2f] = buffer[0x23]; - buffer[0x30] = buffer[0x24]; - buffer[0x31] = buffer[0x25]; - buffer[0x32] = (Orig.point & 0x00ff); - buffer[0x33] = (Orig.point & 0xff00) >> 8; - buffer[0x34] = (Dest.point & 0x00ff); - buffer[0x35] = (Dest.point & 0xff00) >> 8; - buffer[0x36] = 'm'; - buffer[0x37] = 'b'; - buffer[0x38] = 's'; - buffer[0x39] = 'e'; - fwrite(buffer, 1, 0x3a, qp); - - fsync(fileno(qp)); - return qp; + fsync(fileno(qp)); + return qp; } @@ -136,59 +185,59 @@ FILE *CreatePkt(char *Queue, fidoaddr Orig, fidoaddr Dest, char *Extension) */ FILE *OpenPkt(fidoaddr Orig, fidoaddr Dest, char *Extension) { - char Queue[128], qname[128]; - FILE *qp; + char *Queue; + static FILE *qp; - sprintf(Queue, "%s/tmp/%d.%d.%d.%d.%s", getenv("MBSE_ROOT"), - Dest.zone, Dest.net, Dest.node, Dest.point, Extension); + Queue = calloc(PATH_MAX, sizeof(char)); - if (file_exist(Queue, R_OK)) - qp = CreatePkt(Queue, Orig, Dest, Extension); - else { - if ((qp = fopen(Queue, "a")) == NULL) { - WriteError("$Can't reopen Queue %s", Queue); - return NULL; - } - - if (CFG.maxpktsize && (ftell(qp) >= (CFG.maxpktsize * 1024)) && - (strncmp(Extension, "qqq", 3) == 0)) { - /* - * It's a pkt that's meant to be send archived and it's - * bigger then maxpktsize. Try to add this pkt to the - * outbound archive for this node. - */ - sprintf(qname, "%s/tmp", getenv("MBSE_ROOT")); - chdir(qname); - sprintf(qname, "%d.%d.%d.%d.qqq", Dest.zone, Dest.net, Dest.node, Dest.point); - fsync(fileno(qp)); - fclose(qp); - if (pack_queue(qname) == TRUE) { - /* - * If the pack succeeded create a fresh packet. - */ - qp = CreatePkt(Queue, Orig, Dest, Extension); - } else { - /* - * If the pack failed the existing queue is - * reopened and we continue adding to that - * existing packet. This is the case when the - * node is locked. - */ - Syslog('s', "pack_queue failed"); - qp = fopen(Queue, "a"); - } - - /* - * Go back to the original inbound directory. - */ - if (do_unprot) - chdir(CFG.inbound); - else - chdir(CFG.pinbound); - } + sprintf(Queue, "%s/%d.%d.%d.%d/mailpkt.%s", CFG.out_queue, Dest.zone, Dest.net, Dest.node, Dest.point, Extension); + mkdirs(Queue, 0750); + Syslog('p', "OpenPkt(%s, %s)", aka2str(Dest), Extension); + + if (file_exist(Queue, R_OK)) + qp = CreatePkt(Queue, Orig, Dest, Extension); + else { + if ((qp = fopen(Queue, "a")) == NULL) { + WriteError("$Can't reopen Queue %s", Queue); + free(Queue); + return NULL; } - return qp; + if (CFG.maxpktsize && (ftell(qp) >= (CFG.maxpktsize * 1024)) && (strcmp(Extension, "qqq") == 0)) { + /* + * It's a pkt that's meant to be send archived and it's + * bigger then maxpktsize. Try to add this pkt to the + * outbound archive for this node. + */ + fsync(fileno(qp)); + fclose(qp); + if (PrepARC(Queue, Dest) == TRUE) { + /* + * If the pack succeeded create a fresh packet. + */ + qp = CreatePkt(Queue, Orig, Dest, Extension); + } else { + /* + * If the pack failed the existing queue is + * reopened and we continue adding to that + * existing packet. + */ + Syslog('s', "PrepARC failed"); + qp = fopen(Queue, "a"); + } + + /* + * Go back to the original inbound directory. + */ + if (do_unprot) + chdir(CFG.inbound); + else + chdir(CFG.pinbound); + } + } + + do_flush = TRUE; + return qp; } diff --git a/mbfido/dirlock.c b/mbfido/dirlock.c new file mode 100644 index 00000000..bca5dca4 --- /dev/null +++ b/mbfido/dirlock.c @@ -0,0 +1,129 @@ +/***************************************************************************** + * + * $Id$ + * Purpose ...............: Lock mbfido processing. + * + ***************************************************************************** + * Copyright (C) 1997-2002 + * + * 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 + * Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + *****************************************************************************/ + +#include "../config.h" +#include "../lib/libs.h" +#include "../lib/memwatch.h" +#include "../lib/structs.h" +#include "../lib/users.h" +#include "../lib/records.h" +#include "../lib/common.h" +#include "../lib/clcomm.h" +#include "flock.h" +#include "dirlock.h" + +#define TMPNAME "TMP." +#define LCKNAME "LOCKFILE" + + + +/* + * Put a lock on this program. + */ +int lockdir(char *directory) +{ + char *Tmpfile, *lockfile; + FILE *fp; + pid_t oldpid; + + Tmpfile = calloc(PATH_MAX, sizeof(char)); + lockfile = calloc(PATH_MAX, sizeof(char)); + sprintf(Tmpfile, "%s/", directory); + strcpy(lockfile, Tmpfile); + sprintf(Tmpfile + strlen(Tmpfile), "%s%u", TMPNAME, getpid()); + sprintf(lockfile + strlen(lockfile), "%s", LCKNAME); + + if ((fp = fopen(Tmpfile, "w")) == NULL) { + WriteError("$Can't create lockfile \"%s\"", Tmpfile); + free(Tmpfile); + free(lockfile); + return FALSE; + } + fprintf(fp, "%10u\n", getpid()); + fclose(fp); + + while (TRUE) { + if (link(Tmpfile, lockfile) == 0) { + unlink(Tmpfile); + free(Tmpfile); + free(lockfile); + return TRUE; + } + if ((fp = fopen(lockfile, "r")) == NULL) { + WriteError("$Can't open lockfile \"%s\"", Tmpfile); + unlink(Tmpfile); + free(Tmpfile); + free(lockfile); + return FALSE; + } + if (fscanf(fp, "%u", &oldpid) != 1) { + WriteError("$Can't read old pid from \"%s\"", Tmpfile); + fclose(fp); + unlink(Tmpfile); + free(Tmpfile); + free(lockfile); + return FALSE; + } + fclose(fp); + if (kill(oldpid,0) == -1) { + if (errno == ESRCH) { + Syslog('+', "Stale lock found for pid %u", oldpid); + unlink(lockfile); + /* no return, try lock again */ + } else { + WriteError("$Kill for %u failed",oldpid); + unlink(Tmpfile); + free(Tmpfile); + free(lockfile); + return FALSE; + } + } else { + Syslog('+', "mbfido already running, pid=%u", oldpid); + unlink(Tmpfile); + free(Tmpfile); + free(lockfile); + return FALSE; + } + } +} + + + +void ulockdir(char *directory) +{ + char *lockfile; + + lockfile = calloc(PATH_MAX, sizeof(char)); + sprintf(lockfile, "%s/", directory); + sprintf(lockfile + strlen(lockfile), "%s", LCKNAME); + (void)unlink(lockfile); + free(lockfile); +} + diff --git a/mbfido/dirlock.h b/mbfido/dirlock.h new file mode 100644 index 00000000..d1415c65 --- /dev/null +++ b/mbfido/dirlock.h @@ -0,0 +1,7 @@ +#ifndef _DIRLOCK_H +#define _DIRLOCK_H + +int lockdir(char *); +void ulockdir(char *); + +#endif diff --git a/mbfido/dirsession.c b/mbfido/dirsession.c index 6b0c0b15..06367c1c 100644 --- a/mbfido/dirsession.c +++ b/mbfido/dirsession.c @@ -45,13 +45,13 @@ extern int do_unprot; /* * Check for lock, return TRUE if node is locked. */ -int islocked(char *lockfile, int chklck, int waitclr) +int islocked(char *lockfile, int chklck, int waitclr, int loglvl) { int i; time_t now, ftime; if (chklck && strlen(lockfile)) { - Syslog('m', "Checking lockfile %s", lockfile); + Syslog(loglvl, "Checking lockfile %s", lockfile); /* * First check for stale lockfile. @@ -103,13 +103,13 @@ int islocked(char *lockfile, int chklck, int waitclr) * Create a 1 byte lockfile if create is TRUE. * Returns FALSE if failed. */ -int setlock(char *lockfile, int create) +int setlock(char *lockfile, int create, int loglvl) { FILE *fp; char temp[1]; if (create && strlen(lockfile)) { - Syslog('m', "create lockfile %s", lockfile); + Syslog(loglvl, "create lockfile %s", lockfile); if ((fp = fopen(lockfile, "w")) == NULL) { WriteError("$Can't create lock %s", lockfile); return FALSE; @@ -128,13 +128,13 @@ int setlock(char *lockfile, int create) /* * Removing lockfile */ -void remlock(char *lockfile, int create) +void remlock(char *lockfile, int create, int loglvl) { if (create) { if (file_rm(lockfile)) WriteError("$Can't remove lock %s", lockfile); else - Syslog('m', "Removed lock %s", lockfile); + Syslog(loglvl, "Removed lock %s", lockfile); } } @@ -159,9 +159,9 @@ void dirinbound(void) if (nodes.Session_in == S_DIR && strlen(nodes.Dir_in_path)) { fileptr = ftell(fp) - nodeshdr.recsize; Syslog('+', "Directory inbound session for node %s", aka2str(nodes.Aka[0])); - if (! islocked(nodes.Dir_in_clock, nodes.Dir_in_chklck, nodes.Dir_in_waitclr)) { + if (! islocked(nodes.Dir_in_clock, nodes.Dir_in_chklck, nodes.Dir_in_waitclr, 'm')) { Syslog('m', "Node is free, start processing"); - setlock(nodes.Dir_in_mlock, nodes.Dir_in_mklck); + setlock(nodes.Dir_in_mlock, nodes.Dir_in_mklck, 'm'); if ((dp = opendir(nodes.Dir_in_path)) == NULL) { WriteError("$Can't open directory %s", nodes.Dir_in_path); @@ -197,7 +197,7 @@ void dirinbound(void) free(from); } - remlock(nodes.Dir_in_mlock, nodes.Dir_in_mklck); + remlock(nodes.Dir_in_mlock, nodes.Dir_in_mklck, 'm'); } /* diff --git a/mbfido/dirsession.h b/mbfido/dirsession.h index 94d5bf95..27b827e0 100644 --- a/mbfido/dirsession.h +++ b/mbfido/dirsession.h @@ -4,9 +4,9 @@ /* $Id$ */ -int islocked(char *, int, int); /* Is directory locked */ -int setlock(char *, int); /* Lock directory */ -void remlock(char *, int); /* Unlock directory */ +int islocked(char *, int, int, int); /* Is directory locked */ +int setlock(char *, int, int); /* Lock directory */ +void remlock(char *, int, int); /* Unlock directory */ void dirinbound(void); /* Process nodes */ #endif diff --git a/mbfido/forward.c b/mbfido/forward.c index f5354e22..e21db6d2 100644 --- a/mbfido/forward.c +++ b/mbfido/forward.c @@ -115,13 +115,13 @@ void ForwardFile(fidoaddr Node, fa_list *sbl) routeto = fido2faddr(Node); dest = fido2faddr(Node); if (nodes.Session_out == S_DIR) { - if (islocked(nodes.Dir_out_clock, nodes.Dir_out_chklck, nodes.Dir_out_waitclr)) { + if (islocked(nodes.Dir_out_clock, nodes.Dir_out_chklck, nodes.Dir_out_waitclr, 'p')) { /* * Not good, should go to a queue */ attach(*routeto, fwdfile, LEAVE, flavor); } else { - if (! setlock(nodes.Dir_out_mlock, nodes.Dir_out_mklck)) { + if (! setlock(nodes.Dir_out_mlock, nodes.Dir_out_mklck, 'p')) { /* * Not good again */ @@ -348,7 +348,7 @@ void ForwardFile(fidoaddr Node, fa_list *sbl) } if (nodes.Session_out == S_DIR) - remlock(nodes.Dir_out_mlock, nodes.Dir_out_mklck); + remlock(nodes.Dir_out_mlock, nodes.Dir_out_mklck, 'p'); /* * Update the nodes statistic counters diff --git a/mbfido/mbfido.c b/mbfido/mbfido.c index d4dd081e..639f5869 100644 --- a/mbfido/mbfido.c +++ b/mbfido/mbfido.c @@ -47,8 +47,7 @@ #include "../lib/msg.h" #include "flock.h" #include "tosspkt.h" -#include "pack.h" -#include "ulock.h" +#include "unpack.h" #include "tic.h" #include "fsort.h" #include "scan.h" @@ -66,6 +65,8 @@ #include "backalias.h" #include "rfc2ftn.h" #include "dirsession.h" +#include "dirlock.h" +#include "queue.h" #define UNPACK_FACTOR 300 @@ -88,6 +89,7 @@ int do_unsec = FALSE; /* Unsecure tossing */ int do_learn = FALSE; /* News articles learnmode */ int check_crc = TRUE; /* Check .tic crc values */ int check_dupe = TRUE; /* Check duplicates */ +int do_flush = FALSE; /* Flush outbound queue */ extern int do_quiet; /* Quiet flag */ extern int e_pid; /* Pid of child process */ extern int show_log; /* Show logging on screen */ @@ -113,38 +115,38 @@ extern int notify, filemgr, areamgr; */ void Help(void) { - do_quiet = FALSE; - ProgName(); + do_quiet = FALSE; + ProgName(); - colour(11, 0); - printf("\nUsage: mbfido [command(s)] \n\n"); - colour(9, 0); - printf(" Commands are:\n\n"); - colour(3, 0); - printf(" a areas Process Areas taglists\n"); - printf(" m mail ... MTA Mail mode\n"); - printf(" ne news Scan for new news\n"); - printf(" no notify Send notify messages\n"); - printf(" r roll Rollover statistic counters\n"); - printf(" s scan Scan outgoing Fido mail\n"); - printf(" ta tag Create taglists\n"); - printf(" te test Do routing test for node\n"); - printf(" ti tic Process .tic files\n"); - printf(" to toss Toss incoming Fido mail\n"); - printf(" u uucp Process UUCP batchfile\n"); - printf(" w web Create WWW statistics\n\n"); - colour(9, 0); - printf(" Options are:\n\n"); - colour(3, 0); - printf(" -f -full Full Mailscan\n"); - printf(" -l -learn Learn News dupes\n"); - printf(" -noc -nocrc Skip CRC checking\n"); - printf(" -nod -nodupe Skip dupe checking\n"); - printf(" -q -quiet Quiet mode\n"); - printf(" -uns -unsecure Toss unsecure\n"); - printf(" -unp -unprotect Toss unprotected inbound\n"); - colour(7, 0); - ExitClient(0); + colour(LIGHTCYAN, BLACK); + printf("\nUsage: mbfido [command(s)] \n\n"); + colour(LIGHTBLUE, BLACK); + printf(" Commands are:\n\n"); + colour(CYAN, BLACK); + printf(" a areas Process Areas taglists\n"); + printf(" m mail ... MTA Mail mode\n"); + printf(" ne news Scan for new news\n"); + printf(" no notify Send notify messages\n"); + printf(" r roll Rollover statistic counters\n"); + printf(" s scan Scan outgoing Fido mail\n"); + printf(" ta tag Create taglists\n"); + printf(" te test Do routing test for node\n"); + printf(" ti tic Process .tic files\n"); + printf(" to toss Toss incoming Fido mail\n"); + printf(" u uucp Process UUCP batchfile\n"); + printf(" w web Create WWW statistics\n\n"); + colour(LIGHTBLUE, BLACK); + printf(" Options are:\n\n"); + colour(CYAN, BLACK); + printf(" -f -full Full Mailscan\n"); + printf(" -l -learn Learn News dupes\n"); + printf(" -noc -nocrc Skip CRC checking\n"); + printf(" -nod -nodupe Skip dupe checking\n"); + printf(" -q -quiet Quiet mode\n"); + printf(" -uns -unsecure Toss unsecure\n"); + printf(" -unp -unprotect Toss unprotected inbound\n"); + colour(LIGHTGRAY, BLACK); + ExitClient(0); } @@ -154,411 +156,425 @@ void Help(void) */ void ProgName(void) { - if (do_quiet) - return; + if (do_quiet) + return; - colour(15, 0); - printf("\nMBFIDO: MBSE BBS %s - Fidonet File and Mail processor\n", VERSION); - colour(14, 0); - printf(" %s\n", COPYRIGHT); + colour(WHITE, BLACK); + printf("\nMBFIDO: MBSE BBS %s - Fidonet File and Mail processor\n", VERSION); + colour(YELLOW, BLACK); + printf(" %s\n", COPYRIGHT); } void die(int onsig) { - /* - * First check if there is a child running, if so, kill it. - */ - if (e_pid) { - if ((kill(e_pid, SIGTERM)) == 0) - Syslog('+', "SIGTERM to pid %d succeeded", e_pid); - else { - if ((kill(e_pid, SIGKILL)) == 0) - Syslog('+', "SIGKILL to pid %d succeeded", e_pid); - else - WriteError("Failed to kill pid %d", e_pid); - } - - /* - * In case the child had the tty in raw mode, reset the tty. - */ - system("stty sane"); + /* + * First check if there is a child running, if so, kill it. + */ + if (e_pid) { + if ((kill(e_pid, SIGTERM)) == 0) + Syslog('+', "SIGTERM to pid %d succeeded", e_pid); + else { + if ((kill(e_pid, SIGKILL)) == 0) + Syslog('+', "SIGKILL to pid %d succeeded", e_pid); + else + WriteError("Failed to kill pid %d", e_pid); } - CloseDupes(); - /* - * Check for locked and open message base. + * In case the child had the tty in raw mode, reset the tty. */ - if (MsgBase.Locked) - Msg_UnLock(); - if (MsgBase.Open) - Msg_Close(); + system("stty sane"); + } - signal(onsig, SIG_IGN); + CloseDupes(); - if (!do_quiet) { - show_log = TRUE; - colour(3, 0); - } + /* + * Check for locked and open message base. + */ + if (MsgBase.Locked) + Msg_UnLock(); + if (MsgBase.Open) + Msg_Close(); - if (onsig) { - if (onsig <= NSIG) - WriteError("Terminated on signal %d (%s)", onsig, SigName[onsig]); - else - WriteError("Terminated with error %d", onsig); - } + signal(onsig, SIG_IGN); - if (echo_imp + net_imp + net_out + echo_out) - CreateSema((char *)"msglink"); + if (!do_quiet) { + show_log = TRUE; + colour(CYAN, BLACK); + } - if (echo_out + net_out + tic_out) - CreateSema((char *)"scanout"); + if (onsig) { + if (onsig <= NSIG) + WriteError("Terminated on signal %d (%s)", onsig, SigName[onsig]); + else + WriteError("Terminated with error %d", onsig); + } - if (tic_imp) - CreateSema((char *)"reqindex"); + if (echo_imp + net_imp + net_out + echo_out) + CreateSema((char *)"msglink"); - if (net_in + net_imp + net_out + net_bad) - Syslog('+', "Netmail [%4d] import [%4d] out [%4d] bad [%4d]", - net_in, net_imp, net_out, net_bad); - if (email_in + email_imp + email_out + email_bad) - Syslog('+', "Email [%4d] import [%4d] out [%4d] bad [%4d]", - email_in, email_imp, email_out, email_bad); - if (echo_in + echo_imp + echo_out + echo_bad + echo_dupe) - Syslog('+', "Echomail [%4d] import [%4d] out [%4d] bad [%4d] dupe [%4d]", - echo_in, echo_imp, echo_out, echo_bad, echo_dupe); - if (news_in + news_imp + news_out + news_bad + news_dupe) - Syslog('+', "News [%4d] import [%4d] out [%4d] bad [%4d] dupe [%4d]", - news_in, news_imp, news_out, news_bad, news_dupe); - if (tic_in + tic_imp + tic_out + tic_bad + tic_dup) - Syslog('+', "TICfiles [%4d] import [%4d] out [%4d] bad [%4d] dupe [%4d]", - tic_in, tic_imp, tic_out, tic_bad, tic_dup); - if (Magics + Hatched) - Syslog('+', " Magics [%4d] hatch [%4d]", Magics, Hatched); - if (notify + areamgr + filemgr) - Syslog('+', "Notify msgs [%4d] AreaMgr [%4d] FileMgr [%4d]", notify, areamgr, filemgr); + if (echo_out + net_out + tic_out) + CreateSema((char *)"scanout"); - t_end = time(NULL); - Syslog(' ', "MBFIDO finished in %s", t_elapsed(t_start, t_end)); - ulockunpack(); + if (tic_imp) + CreateSema((char *)"reqindex"); - if (!do_quiet) - colour(7, 0); - ExitClient(onsig); + if (net_in + net_imp + net_out + net_bad) + Syslog('+', "Netmail [%4d] import [%4d] out [%4d] bad [%4d]", net_in, net_imp, net_out, net_bad); + if (email_in + email_imp + email_out + email_bad) + Syslog('+', "Email [%4d] import [%4d] out [%4d] bad [%4d]", email_in, email_imp, email_out, email_bad); + if (echo_in + echo_imp + echo_out + echo_bad + echo_dupe) + Syslog('+', "Echomail [%4d] import [%4d] out [%4d] bad [%4d] dupe [%4d]", echo_in, echo_imp, echo_out, echo_bad, echo_dupe); + if (news_in + news_imp + news_out + news_bad + news_dupe) + Syslog('+', "News [%4d] import [%4d] out [%4d] bad [%4d] dupe [%4d]", news_in, news_imp, news_out, news_bad, news_dupe); + if (tic_in + tic_imp + tic_out + tic_bad + tic_dup) + Syslog('+', "TICfiles [%4d] import [%4d] out [%4d] bad [%4d] dupe [%4d]", tic_in, tic_imp, tic_out, tic_bad, tic_dup); + if (Magics + Hatched) + Syslog('+', " Magics [%4d] hatch [%4d]", Magics, Hatched); + if (notify + areamgr + filemgr) + Syslog('+', "Notify msgs [%4d] AreaMgr [%4d] FileMgr [%4d]", notify, areamgr, filemgr); + + /* + * There should be no locks anymore, but in case of a crash try to unlock + * all possible directories. + */ + ulockdir(CFG.inbound); + ulockdir(CFG.pinbound); + ulockdir(CFG.out_queue); + + t_end = time(NULL); + Syslog(' ', "MBFIDO finished in %s", t_elapsed(t_start, t_end)); + + if (!do_quiet) + colour(LIGHTGRAY, BLACK); + ExitClient(onsig); } int main(int argc, char **argv) { - int i, Loop; - char *p, *cmd, *temp, Options[81]; - struct passwd *pw; - struct tm *t; - fa_list **envrecip, *envrecip_start = NULL; - faddr *taddr = NULL; - int envrecip_count = 0; - FILE *ofp; + int i, Loop, envrecip_count = 0; + char *p, *cmd, *temp, Options[81]; + struct passwd *pw; + struct tm *t; + fa_list **envrecip, *envrecip_start = NULL; + faddr *taddr = NULL; + FILE *ofp; #ifdef MEMWATCH - mwInit(); + mwInit(); #endif - /* - * The next trick is to supply a fake environment variable - * MBSE_ROOT in case we are started from UUCP or the MTA. - * this will setup the variable so InitConfig() will work. - * The /etc/passwd must point to the correct homedirectory. - * Some programs can't set uid to mbse, so mbfido is installed - * setuid mbse. - */ - if (getenv("MBSE_ROOT") == NULL) { - pw = getpwuid(getuid()); - if (strcmp(pw->pw_name, "mbse")) { - /* - * We are not running as user mbse. - */ - pw = getpwnam("mbse"); - if (setuid(pw->pw_uid)) { - printf("Fatal error: can't set uid to user mbse\n"); - } - } - envptr = xstrcpy((char *)"MBSE_ROOT="); - envptr = xstrcat(envptr, pw->pw_dir); - putenv(envptr); + /* + * The next trick is to supply a fake environment variable + * MBSE_ROOT in case we are started from UUCP or the MTA. + * this will setup the variable so InitConfig() will work. + * The /etc/passwd must point to the correct homedirectory. + * Some programs can't set uid to mbse, so mbfido is installed + * setuid mbse. + */ + if (getenv("MBSE_ROOT") == NULL) { + pw = getpwuid(getuid()); + if (strcmp(pw->pw_name, "mbse")) { + /* + * We are not running as user mbse. + */ + pw = getpwnam("mbse"); + if (setuid(pw->pw_uid)) { + printf("Fatal error: can't set uid to user mbse\n"); + } } + envptr = xstrcpy((char *)"MBSE_ROOT="); + envptr = xstrcat(envptr, pw->pw_dir); + putenv(envptr); + } - InitConfig(); - memset(&Options, 0, sizeof(Options)); + InitConfig(); + memset(&Options, 0, sizeof(Options)); - /* - * Initialize global variables, data records. - */ - InitNode(); - InitMsgs(); - InitTic(); - InitUser(); - InitFidonet(); - TermInit(1); - t_start = time(NULL); - t = localtime(&t_start); - Diw = t->tm_wday; - Miy = t->tm_mon; - umask(002); + /* + * Initialize global variables, data records. + */ + InitNode(); + InitMsgs(); + InitTic(); + InitUser(); + InitFidonet(); + TermInit(1); + t_start = time(NULL); + t = localtime(&t_start); + Diw = t->tm_wday; + Miy = t->tm_mon; + umask(002); - /* - * Catch all the signals we can, and ignore the rest. - */ - for(i = 0; i < NSIG; i++) { + /* + * Catch all the signals we can, and ignore the rest. + */ + for(i = 0; i < NSIG; i++) { - if ((i == SIGINT) || (i == SIGBUS) || (i == SIGILL) || - (i == SIGSEGV) || (i == SIGTERM) || (i == SIGKILL)) - signal(i, (void (*))die); - else - signal(i, SIG_IGN); - } - - if ((p = strrchr(argv[0], '/'))) - p++; + if ((i == SIGINT) || (i == SIGBUS) || (i == SIGILL) || (i == SIGSEGV) || (i == SIGTERM) || (i == SIGKILL)) + signal(i, (void (*))die); else - p = argv[0]; - if (!strcmp(p, "mbmail")) { - do_quiet = TRUE; - do_mail = TRUE; - cmd = xstrcpy((char *)"Cmd: mbmail"); - } else if (!strcmp(p, "mbnews")) { - do_quiet = TRUE; - do_uucp = TRUE; - cmd = xstrcpy((char *)"Cmd: mbnews"); - } else { - if (argc < 2) - Help(); - cmd = xstrcpy((char *)"Cmd: mbfido"); - } + signal(i, SIG_IGN); + } - envrecip = &envrecip_start; - for (i = 1; i < argc; i++) { - cmd = xstrcat(cmd, (char *)" "); - cmd = xstrcat(cmd, argv[i]); + if ((p = strrchr(argv[0], '/'))) + p++; + else + p = argv[0]; + if (!strcmp(p, "mbmail")) { + do_quiet = TRUE; + do_mail = TRUE; + cmd = xstrcpy((char *)"Cmd: mbmail"); + } else if (!strcmp(p, "mbnews")) { + do_quiet = TRUE; + do_uucp = TRUE; + cmd = xstrcpy((char *)"Cmd: mbnews"); + } else { + if (argc < 2) + Help(); + cmd = xstrcpy((char *)"Cmd: mbfido"); + } - if (strncmp(tl(argv[i]), "ne", 2) == 0) - do_news = TRUE; - if (strncmp(tl(argv[i]), "no", 2) == 0) { - do_notify = TRUE; - if (((i + 1) < argc) && + envrecip = &envrecip_start; + for (i = 1; i < argc; i++) { + cmd = xstrcat(cmd, (char *)" "); + cmd = xstrcat(cmd, argv[i]); + + if (strncmp(tl(argv[i]), "ne", 2) == 0) + do_news = TRUE; + if (strncmp(tl(argv[i]), "no", 2) == 0) { + do_notify = TRUE; + if (((i + 1) < argc) && ((strchr(argv[i + 1], ':') != NULL) || (atoi(argv[i + 1])) || (strncmp(argv[i + 1], "*", 1) == 0))) { sprintf(Options, "%s", argv[i + 1]); i++; - } - } - if (strncmp(tl(argv[i]), "r", 1) == 0) - do_roll = TRUE; - else if (strncmp(tl(argv[i]), "a", 1) == 0) - do_areas = TRUE; - else if (strncmp(tl(argv[i]), "s", 1) == 0) - do_scan = TRUE; - else if (strncmp(tl(argv[i]), "ta", 2) == 0) - do_tags = TRUE; - else if (strncmp(tl(argv[i]), "ti", 2) == 0) - do_tic = TRUE; - else if (strncmp(tl(argv[i]), "te", 2) == 0) { - do_test = TRUE; - if ((i + 1) < argc) { - if ((taddr = parsefaddr(argv[i + 1])) == NULL) { - Help(); - } - i++; - cmd = xstrcat(cmd, (char *)" "); - cmd = xstrcat(cmd, argv[i]); - } - } else if (strncmp(tl(argv[i]), "to", 2) == 0) - do_toss = TRUE; - else if (strncmp(tl(argv[i]), "u", 1) == 0) - do_uucp = TRUE; - else if (strncmp(tl(argv[i]), "m", 1) == 0) - do_mail = TRUE; - else if (strncmp(tl(argv[i]), "w", 1) == 0) - do_stat = TRUE; - else if (strncmp(tl(argv[i]), "-f", 2) == 0) - do_full = TRUE; - else if (strncmp(tl(argv[i]), "-l", 2) == 0) - do_learn = TRUE; - else if (strncmp(tl(argv[i]), "-noc", 4) == 0) - check_crc = FALSE; - else if (strncmp(tl(argv[i]), "-nod", 4) == 0) - check_dupe = FALSE; - else if (strncmp(tl(argv[i]), "-q", 2) == 0) - do_quiet = TRUE; - else if (strncmp(tl(argv[i]), "-a", 2) == 0) - WriteError("The -a option is obsolete, adjust your setup"); - else if (strncmp(tl(argv[i]), "-unp", 4) == 0) - do_unprot = TRUE; - else if (strncmp(tl(argv[i]), "-uns", 4) == 0) - do_unsec = TRUE; - else if (do_mail) { - /* - * Possible recipient address(es). - */ - if ((taddr = parsefaddr(argv[i]))) { - (*envrecip) = (fa_list*)malloc(sizeof(fa_list)); - (*envrecip)->next = NULL; - (*envrecip)->addr = taddr; - envrecip = &((*envrecip)->next); - envrecip_count++; - } else { - cmd = strcat(cmd, (char *)" <- unparsable recipient! "); - } - } - } - - ProgName(); - pw = getpwuid(getuid()); - InitClient(pw->pw_name, (char *)"mbfido", CFG.location, CFG.logfile, CFG.util_loglevel, CFG.error_log); - - Syslog(' ', " "); - Syslog(' ', "MBFIDO v%s", VERSION); - Syslog(' ', cmd); - free(cmd); - - InitDupes(); - - if (!diskfree(CFG.freespace)) - die(101); - - if (do_mail) { - /* - * Try to get a lock for a long time, another mbfido may be legally - * running since mbmail is started by the MTA instead of by mbtask. - * The timeout is 10 minutes. If mbmail times out, the MTA will - * bounce the message. What happens during the time we wait is - * unknown, will the MTA be patient enough? - */ - i = 30; - while (TRUE) { - if (lockunpack() == 0) - break; - i--; - if (! i) { - WriteError("Lock timeout, aborting"); - die(101); - } - sleep(20); - Nopper(); } + } + if (strncmp(tl(argv[i]), "r", 1) == 0) + do_roll = TRUE; + else if (strncmp(tl(argv[i]), "a", 1) == 0) + do_areas = TRUE; + else if (strncmp(tl(argv[i]), "s", 1) == 0) + do_scan = TRUE; + else if (strncmp(tl(argv[i]), "ta", 2) == 0) + do_tags = TRUE; + else if (strncmp(tl(argv[i]), "ti", 2) == 0) + do_tic = TRUE; + else if (strncmp(tl(argv[i]), "te", 2) == 0) { + do_test = TRUE; + if ((i + 1) < argc) { + if ((taddr = parsefaddr(argv[i + 1])) == NULL) { + Help(); + } + i++; + cmd = xstrcat(cmd, (char *)" "); + cmd = xstrcat(cmd, argv[i]); + } + } else if (strncmp(tl(argv[i]), "to", 2) == 0) + do_toss = TRUE; + else if (strncmp(tl(argv[i]), "u", 1) == 0) + do_uucp = TRUE; + else if (strncmp(tl(argv[i]), "m", 1) == 0) + do_mail = TRUE; + else if (strncmp(tl(argv[i]), "w", 1) == 0) + do_stat = TRUE; + else if (strncmp(tl(argv[i]), "-f", 2) == 0) + do_full = TRUE; + else if (strncmp(tl(argv[i]), "-l", 2) == 0) + do_learn = TRUE; + else if (strncmp(tl(argv[i]), "-noc", 4) == 0) + check_crc = FALSE; + else if (strncmp(tl(argv[i]), "-nod", 4) == 0) + check_dupe = FALSE; + else if (strncmp(tl(argv[i]), "-q", 2) == 0) + do_quiet = TRUE; + else if (strncmp(tl(argv[i]), "-a", 2) == 0) + WriteError("The -a option is obsolete, adjust your setup"); + else if (strncmp(tl(argv[i]), "-unp", 4) == 0) + do_unprot = TRUE; + else if (strncmp(tl(argv[i]), "-uns", 4) == 0) + do_unsec = TRUE; + else if (do_mail) { + /* + * Possible recipient address(es). + */ + if ((taddr = parsefaddr(argv[i]))) { + (*envrecip) = (fa_list*)malloc(sizeof(fa_list)); + (*envrecip)->next = NULL; + (*envrecip)->addr = taddr; + envrecip = &((*envrecip)->next); + envrecip_count++; + } else { + cmd = strcat(cmd, (char *)" <- unparsable recipient! "); + } + } + } + + ProgName(); + pw = getpwuid(getuid()); + InitClient(pw->pw_name, (char *)"mbfido", CFG.location, CFG.logfile, CFG.util_loglevel, CFG.error_log); + + Syslog(' ', " "); + Syslog(' ', "MBFIDO v%s", VERSION); + Syslog(' ', cmd); + free(cmd); + + InitDupes(); + + if (!diskfree(CFG.freespace)) + die(101); + + if (do_mail) { + /* + * Try to get a lock for a long time, another mbfido may be legally + * running since mbmail is started by the MTA instead of by mbtask. + * The timeout is 10 minutes. If mbmail times out, the MTA will + * bounce the message. What happens during the time we wait is + * unknown, will the MTA be patient enough? + */ + i = 30; + while (TRUE) { + if (do_unprot) { + if (lockdir(CFG.inbound)) + break; + } else { + if (lockdir(CFG.pinbound)) + break; + } + i--; + if (! i) { + WriteError("Lock timeout, aborting"); + die(101); + } + sleep(20); + Nopper(); + } + } else { + /* + * Started under control of mbtask, that means if there is a lock then + * there is something wrong; abort. + */ + if (do_unprot) { + if (! lockdir(CFG.inbound)) + die(101); } else { - /* - * Started under control of mbtask, that means if there is a lock then - * there is something wrong; abort. - */ - if (lockunpack()) + if (! lockdir(CFG.pinbound)) die(101); } + } - if (initnl()) - die(101); - if (!do_mail && !do_uucp) - Rollover(); - if (!do_quiet) - printf("\n"); + if (initnl()) + die(101); + if (!do_mail && !do_uucp) + Rollover(); + if (!do_quiet) + printf("\n"); - /* - * Read alias file - */ - cmd = calloc(PATH_MAX, sizeof(char)); - sprintf(cmd, "%s/etc/aliases", getenv("MBSE_ROOT")); - if ((do_news || do_scan || do_toss || do_mail) && file_exist(cmd, R_OK) == 0) - readalias(cmd); - free(cmd); + /* + * Read alias file + */ + cmd = calloc(PATH_MAX, sizeof(char)); + sprintf(cmd, "%s/etc/aliases", getenv("MBSE_ROOT")); + if ((do_news || do_scan || do_toss || do_mail) && file_exist(cmd, R_OK) == 0) + readalias(cmd); + free(cmd); - if (do_mail) { - if (!envrecip_count) { - WriteError("No valid receipients specified, aborting"); - die(105); - } - - umask(066); - if ((ofp = tmpfile()) == NULL) { - WriteError("$Can't open tmpfile for RFC message"); - die(104); - } - temp = calloc(10240, sizeof(char)); - while (fgets(temp, 10240, stdin)) - fprintf(ofp, temp); - free(temp); - - for (envrecip = &envrecip_start; *envrecip; envrecip = &((*envrecip)->next)) { - Syslog('+', "Message to: %s", ascfnode((*envrecip)->addr, 0x7f)); - rfc2ftn(ofp, (*envrecip)->addr); - } - - fclose(ofp); - packmail(); - die(0); + if (do_mail) { + if (!envrecip_count) { + WriteError("No valid receipients specified, aborting"); + die(105); } - if (do_notify) - if (Notify(Options)) - packmail(); - if (do_tic) { - if (IsSema((char *)"mailin")) - RemoveSema((char *)"mailin"); - /* - * Hatch new files and process .tic files - * until nothing left to do. - */ - Loop = TRUE; - do { - Hatch(); - switch (Tic()) { - case -1: die(0); - break; - case 0: Loop = FALSE; - break; - default: break; - } - } while (Loop); + umask(066); + if ((ofp = tmpfile()) == NULL) { + WriteError("$Can't open tmpfile for RFC message"); + die(104); } - if (do_news) { - ScanNews(); - if (IsSema((char *)"newnews")) - RemoveSema((char *)"newnews"); + temp = calloc(10240, sizeof(char)); + while (fgets(temp, 10240, stdin)) + fprintf(ofp, temp); + free(temp); + + for (envrecip = &envrecip_start; *envrecip; envrecip = &((*envrecip)->next)) { + Syslog('+', "Message to: %s", ascfnode((*envrecip)->addr, 0x7f)); + rfc2ftn(ofp, (*envrecip)->addr); } - if (do_scan) - ScanMail(do_full); - if (do_toss) { - if (IsSema((char *)"mailin")) - RemoveSema((char *)"mailin"); - if (TossMail() == FALSE) - die(0); - } - if (do_tic || do_toss) { - /* - * Do inbound direcory sessions - */ - dirinbound(); - } - if (!do_uucp) - newspost(); - if (do_test) { - if (taddr == NULL) - Help(); - TestTracker(taddr); - tidy_faddr(taddr); - } - if (do_tags) - MakeTags(); - if (do_stat) - MakeStat(); - if (do_uucp) - NewsUUCP(); - if (do_areas) - Areas(); + + fclose(ofp); + flush_queue(); die(0); - return 0; + } + + if (do_notify) + if (Notify(Options)) { + do_flush = TRUE; + } + if (do_tic) { + if (IsSema((char *)"mailin")) + RemoveSema((char *)"mailin"); + /* + * Hatch new files and process .tic files + * until nothing left to do. + */ + Loop = TRUE; + do { + Hatch(); + switch (Tic()) { + case -1: die(0); + break; + case 0: Loop = FALSE; + break; + default: break; + } + } while (Loop); + } + if (do_news) { + ScanNews(); + if (IsSema((char *)"newnews")) + RemoveSema((char *)"newnews"); + } + if (do_scan) + ScanMail(do_full); + if (do_toss) { + if (IsSema((char *)"mailin")) + RemoveSema((char *)"mailin"); + if (TossMail() == FALSE) + die(0); + } + if (do_tic || do_toss) { + /* + * Do inbound direcory sessions + */ + dirinbound(); + } + if (!do_uucp) + newspost(); + if (do_test) { + if (taddr == NULL) + Help(); + TestTracker(taddr); + tidy_faddr(taddr); + } + if (do_tags) + MakeTags(); + if (do_stat) + MakeStat(); + if (do_uucp) + NewsUUCP(); + if (do_areas) + Areas(); + if (do_flush) + flush_queue(); + + die(0); + return 0; } @@ -568,102 +584,95 @@ int main(int argc, char **argv) */ int TossMail(void) { - char *inbound, *fname; - DIR *dp; - struct dirent *de; - struct stat sbuf; - int files = 0, files_ok = 0; - int rc = 0, maxrc = 0; - fd_list *fdl = NULL; + char *inbound, *fname; + DIR *dp; + struct dirent *de; + struct stat sbuf; + int files = 0, files_ok = 0, rc = 0, maxrc = 0; + fd_list *fdl = NULL; - if (do_unprot) - inbound = xstrcpy(CFG.inbound); + if (do_unprot) + inbound = xstrcpy(CFG.inbound); + else + inbound = xstrcpy(CFG.pinbound); + + Syslog('+', "Pass: toss netmail (%s)", inbound); + + if (chdir(inbound) == -1) { + WriteError("$Can't chdir(%s)", inbound); + die(0); + } + + /* + * First toss any netmail packets. + */ + maxrc = rc = TossPkts(); + chdir(inbound); + + /* + * Scan the directory for ARCmail archives. The archive extension + * numbering doesn't matter, as long as there is something, so + * all kind of ARCmail naming schemes are recognized. + */ + if ((dp = opendir(inbound)) == NULL) { + WriteError("$Can't opendir(%s)", inbound); + die(0); + } + + Syslog('+', "Pass: toss ARCmail (%s)", inbound); + + /* + * Add all ARCmail filenames to the memory array. + */ + sync(); + while ((de=readdir(dp))) + if ((strlen(de->d_name) == 12) && ((strncasecmp(de->d_name+8,".su",3) == 0) || + (strncasecmp(de->d_name+8,".mo",3) == 0) || (strncasecmp(de->d_name+8,".tu",3) == 0) || + (strncasecmp(de->d_name+8,".we",3) == 0) || (strncasecmp(de->d_name+8,".th",3) == 0) || + (strncasecmp(de->d_name+8,".fr",3) == 0) || (strncasecmp(de->d_name+8,".sa",3) == 0))) { + stat(de->d_name, &sbuf); + fill_fdlist(&fdl, de->d_name, sbuf.st_mtime); + } + + closedir(dp); + sort_fdlist(&fdl); + + /* + * Now process the archives, the oldest first. + */ + while ((fname = pull_fdlist(&fdl)) != NULL) { + files++; + IsDoing("Unpack arcmail"); + + if (IsSema((char *)"upsalarm")) { + Syslog('+', "Detected upsalarm semafore, aborting toss"); + break; + } + if (!diskfree(CFG.freespace)) { + rc = 101; + break; + } + + if (checkspace(inbound, fname, UNPACK_FACTOR)) + if ((rc = unpack(fname)) == 0) { + files_ok++; + sync(); + rc = TossPkts(); + chdir(inbound); + } else + WriteError("Error unpacking file %s", fname); else - inbound = xstrcpy(CFG.pinbound); - - Syslog('+', "Pass: toss netmail (%s)", inbound); - - if (chdir(inbound) == -1) { - WriteError("$Can't chdir(%s)", inbound); - die(0); - } - - /* - * First toss any netmail packets. - */ - maxrc = rc = TossPkts(); - chdir(inbound); - - /* - * Scan the directory for ARCmail archives. The archive extension - * numbering doesn't matter, as long as there is something, so - * all kind of ARCmail naming schemes are recognized. - */ - if ((dp = opendir(inbound)) == NULL) { - WriteError("$Can't opendir(%s)", inbound); - die(0); - } - - Syslog('+', "Pass: toss ARCmail (%s)", inbound); - - /* - * Add all ARCmail filenames to the memory array. - */ - sync(); - while ((de=readdir(dp))) - if ((strlen(de->d_name) == 12) && - ((strncasecmp(de->d_name+8,".su",3) == 0) || - (strncasecmp(de->d_name+8,".mo",3) == 0) || - (strncasecmp(de->d_name+8,".tu",3) == 0) || - (strncasecmp(de->d_name+8,".we",3) == 0) || - (strncasecmp(de->d_name+8,".th",3) == 0) || - (strncasecmp(de->d_name+8,".fr",3) == 0) || - (strncasecmp(de->d_name+8,".sa",3) == 0))) { - stat(de->d_name, &sbuf); - fill_fdlist(&fdl, de->d_name, sbuf.st_mtime); - } - - closedir(dp); - sort_fdlist(&fdl); - - /* - * Now process the archives, the oldest first. - */ - while ((fname = pull_fdlist(&fdl)) != NULL) { - files++; - IsDoing("Unpack arcmail"); - - if (IsSema((char *)"upsalarm")) { - Syslog('+', "Detected upsalarm semafore, aborting toss"); - break; - } - if (!diskfree(CFG.freespace)) { - rc = 101; - break; - } - - if (checkspace(inbound, fname, UNPACK_FACTOR)) - if ((rc = unpack(fname)) == 0) { - files_ok++; - sync(); - rc = TossPkts(); - chdir(inbound); - } else - WriteError("Error unpacking file %s", fname); - else - Syslog('!', "Insufficient space to unpack file %s", fname); + Syslog('!', "Insufficient space to unpack file %s", fname); - if (rc > maxrc) - maxrc = rc; - } + if (rc > maxrc) + maxrc = rc; + } - free(inbound); - if ((files || packets) && - ((files_ok != files) || (packets_ok != packets))) - Syslog('!', "Processed %d of %d files, %d of %d packets, rc=%d", - files_ok, files, packets_ok, packets, maxrc); + free(inbound); + if ((files || packets) && ((files_ok != files) || (packets_ok != packets))) + Syslog('!', "Processed %d of %d files, %d of %d packets, rc=%d", files_ok, files, packets_ok, packets, maxrc); - return TRUE; + return TRUE; } @@ -674,68 +683,67 @@ int TossMail(void) */ int TossPkts(void) { - char *inbound = NULL, *fname; - DIR *dp; - struct dirent *de; - struct stat sbuf; - int rc = 0, maxrc = 0; - fd_list *fdl = NULL; + char *inbound = NULL, *fname; + DIR *dp; + struct dirent *de; + struct stat sbuf; + int rc = 0, maxrc = 0; + fd_list *fdl = NULL; - IsDoing("Tossing mail"); + IsDoing("Tossing mail"); - if (do_unprot) - inbound = xstrcpy(CFG.inbound); - else - inbound = xstrcpy(CFG.pinbound); + if (do_unprot) + inbound = xstrcpy(CFG.inbound); + else + inbound = xstrcpy(CFG.pinbound); - if ((dp = opendir(inbound)) == NULL) { - WriteError("$Can't opendir(%s)", inbound); - return FALSE; + if ((dp = opendir(inbound)) == NULL) { + WriteError("$Can't opendir(%s)", inbound); + return FALSE; + } + + /* + * Read all .pkt filenames, get the timestamp and add them + * to the memory array for later sort on filedate. + */ + while ((de = readdir(dp))) + if ((strlen(de->d_name) == 12) && (strncasecmp(de->d_name+8,".pkt",4) == 0)) { + stat(de->d_name, &sbuf); + fill_fdlist(&fdl, de->d_name, sbuf.st_mtime); } - /* - * Read all .pkt filenames, get the timestamp and add them - * to the memory array for later sort on filedate. - */ - while ((de = readdir(dp))) - if ((strlen(de->d_name) == 12) && (strncasecmp(de->d_name+8,".pkt",4) == 0)) { - stat(de->d_name, &sbuf); - fill_fdlist(&fdl, de->d_name, sbuf.st_mtime); - } + closedir(dp); + sort_fdlist(&fdl); - closedir(dp); - sort_fdlist(&fdl); + /* + * Get the filenames, the oldest first until nothing left. + */ + while ((fname = pull_fdlist(&fdl)) != NULL) { + + if (!diskfree(CFG.freespace)) + return FALSE; + packets++; /* - * Get the filenames, the oldest first until nothing left. + * See if "pktdate" from Tobias Ernst (or another preprocessor) is installed. */ - while ((fname = pull_fdlist(&fdl)) != NULL) { - - if (!diskfree(CFG.freespace)) - return FALSE; - packets++; - - /* - * See if "pktdate" from Tobias Ernst (or another - * preprocessor) is installed. - */ - if (strlen(CFG.pktdate)) { - rc = execute(CFG.pktdate, fname, (char *)NULL, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null"); - if (rc) - Syslog('+', "%s preprocessing rc=%d", fname, rc); - } - - if ((rc = toss(fname)) == 0) - packets_ok++; - else - WriteError("Error tossing packet %s", fname); - if (rc > maxrc) - maxrc = rc; + if (strlen(CFG.pktdate)) { + rc = execute(CFG.pktdate, fname, (char *)NULL, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null"); + if (rc) + Syslog('+', "%s preprocessing rc=%d", fname, rc); } - free(inbound); - packmail(); - return maxrc; + if ((rc = toss(fname)) == 0) + packets_ok++; + else + WriteError("Error tossing packet %s", fname); + if (rc > maxrc) + maxrc = rc; + } + + free(inbound); + do_flush = TRUE; + return maxrc; } @@ -745,27 +753,26 @@ int TossPkts(void) */ int toss(char *fn) { - int rc, ld; - char newname[16]; + int rc = 0, ld; + char newname[16]; - rc = 0; - /* - * Lock the packet - */ - if ((ld = f_lock(fn)) == -1) - return 1; + /* + * Lock the packet + */ + if ((ld = f_lock(fn)) == -1) + return 1; - rc = TossPkt(fn); - if (rc == 0) { - unlink(fn); - } else { - strncpy(newname,fn,sizeof(newname)-1); - strcpy(newname+8,".bad"); - rename(fn,newname); - } + rc = TossPkt(fn); + if (rc == 0) { + unlink(fn); + } else { + strncpy(newname,fn,sizeof(newname)-1); + strcpy(newname+8,".bad"); + rename(fn,newname); + } - funlock(ld); - return rc; + funlock(ld); + return rc; } diff --git a/mbfido/mgrutil.c b/mbfido/mgrutil.c index d2ba0f89..46635d3c 100644 --- a/mbfido/mgrutil.c +++ b/mbfido/mgrutil.c @@ -41,7 +41,6 @@ #include "sendmail.h" #include "rollover.h" #include "addpkt.h" -#include "pack.h" #include "createm.h" #include "createf.h" #include "mgrutil.h" @@ -49,6 +48,7 @@ extern int net_out; extern int do_quiet; +extern int do_flush; void tidy_arealist(AreaList **); @@ -981,7 +981,7 @@ int Areas(void) free(buf); free(temp); if (net_out) - packmail(); + do_flush = TRUE; return TRUE; } diff --git a/mbfido/pack.c b/mbfido/pack.c deleted file mode 100644 index 481d3826..00000000 --- a/mbfido/pack.c +++ /dev/null @@ -1,539 +0,0 @@ -/***************************************************************************** - * - * $Id$ - * Purpose ...............: Pack mail - * - ***************************************************************************** - * Copyright (C) 1997-2002 - * - * 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 - * Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. - *****************************************************************************/ - -#include "../config.h" -#include "../lib/libs.h" -#include "../lib/memwatch.h" -#include "../lib/structs.h" -#include "../lib/users.h" -#include "../lib/records.h" -#include "../lib/common.h" -#include "../lib/dbftn.h" -#include "../lib/clcomm.h" -#include "../lib/dbnode.h" -#include "dirsession.h" -#include "pack.h" - - -extern int do_quiet; /* Quiet flag */ - - -static char *dow[] = {(char *)"su", (char *)"mo", (char *)"tu", (char *)"we", - (char *)"th", (char *)"fr", (char *)"sa"}; - - -/* - * Pack queued arcmail mail for a node. If the node is locked, the mail won't - * be packed, and the queue stays as it is. The mail will then be packed - * on a next run. - */ -int pack_queue(char *name) -{ - FILE *fp; - faddr noden, *bestaka; - fidoaddr nodenr; - char flavor, nr, oldnr, maxnr, *ext, srcfile[128], *arcfile, *pktfile; - int Attach, fage; - long fsize; - time_t Now; - struct tm *ptm; - - sprintf(srcfile, "%s", name); - - /* - * Get the nodenumber from the filename - */ - noden.domain = NULL; - noden.name = NULL; - noden.zone = atoi(strtok(name, ".")); - noden.net = atoi(strtok(NULL, ".")); - noden.node = atoi(strtok(NULL, ".")); - noden.point = atoi(strtok(NULL, ".")); - if (SearchFidonet(noden.zone)) - noden.domain = xstrcpy(fidonet.domain); - - memset(&nodenr, 0, sizeof(nodenr)); - nodenr.zone = noden.zone; - nodenr.net = noden.net; - nodenr.node = noden.node; - nodenr.point = noden.point; - sprintf(nodenr.domain, "%s", noden.domain); - - if (!SearchNode(nodenr)) { - WriteError("Downlink %s not found", aka2str(nodenr)); - if (noden.domain) - free(noden.domain); - return FALSE; - } - - /* - * If we route via another aka, change everything. - */ - if (nodes.RouteVia.zone) { - Syslog('p', "Route Via %s", aka2str(nodes.RouteVia)); - noden.zone = nodes.RouteVia.zone; - noden.net = nodes.RouteVia.net; - noden.node = nodes.RouteVia.node; - noden.point = nodes.RouteVia.point; - if (noden.domain) - free(noden.domain); - noden.domain = xstrcpy(nodes.RouteVia.domain); - /* - * Load routevia noderecord to get the correct flavor. - * If there is no noderecord, reload the old one. - */ - if (!SearchNode(nodes.RouteVia)) - SearchNode(nodenr); - } - - Syslog('+', "Pack ARCmail for %s, via %s", aka2str(nodenr), ascfnode(&noden, 0x1f)); - - if (!do_quiet) { - printf("\rAdding ARCmail for %s ", ascfnode(&noden, 0x1f)); - fflush(stdout); - } - - if (getarchiver((char *)"ZIP")) { - flavor = 'f'; - if (nodes.Crash) - flavor = 'c'; - if (nodes.Hold) - flavor = 'h'; - } else { - WriteError("Archiver ZIP not found"); - if (noden.domain) - free(noden.domain); - return FALSE; - } - - /* - * Generate ARCmail filename and .PKT filename, - */ - arcfile = calloc(PATH_MAX, sizeof(char)); - if (nodes.Session_out == S_DIR) { - - Now = time(NULL); - ptm = localtime(&Now); - ext = dow[ptm->tm_wday]; - - if (!nodes.ARCmailCompat && (nodes.Aka[0].zone != noden.zone)) { - /* - * Generate ARCfile name from the CRC of the ASCII string - * of the node address. - */ - sprintf(arcfile, "%s/%08lx.%s0", nodes.Dir_out_path, StringCRC32(ascfnode(&noden, 0x1f)), ext); - } else { - bestaka = bestaka_s(&noden); - - if (noden.point) { - sprintf(arcfile, "%s/%04x%04x.%s0", nodes.Dir_out_path, ((bestaka->net) - (noden.net)) & 0xffff, - ((bestaka->node) - (noden.node) + (noden.point)) & 0xffff, ext); - } else if (bestaka->point) { - /* - * Inserted the next code for if we are a point, - * I hope this is ARCmail 0.60 compliant. 21-May-1999 - */ - sprintf(arcfile, "%s/%04x%04x.%s0", nodes.Dir_out_path, ((bestaka->net) - (noden.net)) & 0xffff, - ((bestaka->node) - (noden.node) - (bestaka->point)) & 0xffff, ext); - } else { - sprintf(arcfile, "%s/%04x%04x.%s0", nodes.Dir_out_path, ((bestaka->net) - (noden.net)) & 0xffff, - ((bestaka->node) - (noden.node)) &0xffff, ext); - } - } - Syslog('m', "Arcmail file %s", arcfile); - } else { - sprintf(arcfile, "%s", arcname(&noden, nodes.Aka[0].zone, nodes.ARCmailCompat)); - } - pktfile = calloc(40, sizeof(char)); - sprintf(pktfile, "%08lx.pkt", sequencer()); - - if (nodes.Session_out == S_DIR) { - if (islocked(nodes.Dir_out_clock, nodes.Dir_out_chklck, nodes.Dir_out_waitclr)) { - Syslog('+', "Mail stays in queue, will be added later"); - if (noden.domain) - free(noden.domain); - free(arcfile); - free(pktfile); - return FALSE; - } else { - if (! setlock(nodes.Dir_out_mlock, nodes.Dir_out_mklck)) { - Syslog('+', "Mail stays in queue, will be added later"); - if (noden.domain) - free(noden.domain); - free(arcfile); - free(pktfile); - return FALSE; - } - } - } else { - if (nodelock(&noden)) { - Syslog('+', "Mail stays in queue, will be added later"); - if (noden.domain) - free(noden.domain); - free(arcfile); - free(pktfile); - return FALSE; - } - } - - if (rename(srcfile, pktfile)) { - WriteError("$Can't rename %s to %s", srcfile, pktfile); - if (nodes.Session_out == S_DIR) - remlock(nodes.Dir_out_mlock, nodes.Dir_out_mklck); - else - nodeulock(&noden); - if (noden.domain) - free(noden.domain); - free(arcfile); - free(pktfile); - return FALSE; - } - - /* - * Add zero word at the end of the .pkt file - */ - if ((fp = fopen(pktfile, "a+")) == NULL) { - WriteError("$Can't open %s", pktfile); - if (nodes.Session_out == S_DIR) - remlock(nodes.Dir_out_mlock, nodes.Dir_out_mklck); - else - nodeulock(&noden); - if (noden.domain) - free(noden.domain); - free(arcfile); - free(pktfile); - return FALSE; - } - putc('\0', fp); - putc('\0', fp); - fsync(fileno(fp)); - fclose(fp); - - /* - * Check the size of the existing archive if there is a size limit. - * Change to new archive names if the existing is too large. - * If the archive size is zero, it's an already sent archive, the - * number will be bumped also. - * If the archive is older then 6 days, the name is also bumped. - * Do this until we find a new name or if the last digit is a '9' or 'z'. - * Purge archives older then toss_days. - */ - nr = oldnr = '0'; - Now = time(NULL); - if (nodes.ARCmailAlpha) - maxnr = 'z'; - else - maxnr = '9'; - Attach = FALSE; - - for (;;) { - fsize = file_size(arcfile); - fage = (int)((Now - file_time(arcfile)) / 86400); - - if (fsize == -1L) { - Attach = TRUE; - break; - } - - if (fsize == 0L) { - if ((fage > 6) && (nr < maxnr)) { - /* - * Remove truncated ARCmail files older then 6 days. - */ - unlink(arcfile); - fsize = -1L; - Attach = TRUE; - break; - } - /* - * Increase filename extension if there is a truncated file of today. - */ - nr++; - if (nr == ('9' +1)) - nr = 'a'; - arcfile[strlen(arcfile) -1] = nr; - - } else if (CFG.maxarcsize && (fsize > (CFG.maxarcsize * 1024)) && (nr < maxnr)) { - /* - * Use a new ARCmail file if the last one is too big. - */ - nr++; - if (nr == ('9' +1)) - nr = 'a'; - arcfile[strlen(arcfile) -1] = nr; - } - - fsize = file_size(arcfile); - fage = (int)((Now - file_time(arcfile)) / 86400); - - if ((fsize > 0L) && (fage > 6) && (nr < maxnr)) { - /* - * If there is ARCmail of a week old or older, add mail - * to a new ARCmail bundle. - */ - nr++; - if (nr == ('9' +1)) - nr = 'a'; - arcfile[strlen(arcfile) -1] = nr; - } - - if (oldnr == nr) - break; - else - oldnr = nr; - } - - fsize = file_size(arcfile); - if (execute(archiver.marc, arcfile, pktfile, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null") == 0) { - unlink(pktfile); - } else { - sync(); - sleep(1); - Syslog('+', "Create ARCmail failed, trying again after sync()"); - if (execute(archiver.marc, arcfile, pktfile, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null") == 0) { - unlink(pktfile); - } else { - WriteError("Can't add %s to ARCmail archive", pktfile); - } - } - - if (nodes.Session_out == S_DIR) { - /* - * Change filemode so downlink has rights to the file. - */ - chmod(arcfile, 0660); - } - - /* - * Attach file to .flo, not for FTP or Directory sessions. - */ - if (Attach && nodes.Session_out == S_DIRECT) - attach(noden, arcfile, TFS, flavor); - - if (nodes.Session_out == S_DIR) - remlock(nodes.Dir_out_mlock, nodes.Dir_out_mklck); - else - nodeulock(&noden); - if (noden.domain) - free(noden.domain); - free(arcfile); - free(pktfile); - return TRUE; -} - - - -/* - * Add queued unpacked mail for a node. If the node is locked, the mail - * stays in the queue. - */ -int add_queue(char *name) -{ - faddr noden; - char flavor, srcfile[128], *outfile, *buf; - FILE *inf, *ouf; - int bread; - - sprintf(srcfile, "%s", name); - - /* - * Get the nodenumber from the filename - */ - noden.domain = NULL; - noden.name = NULL; - noden.zone = atoi(strtok(name, ".")); - noden.net = atoi(strtok(NULL, ".")); - noden.node = atoi(strtok(NULL, ".")); - noden.point = atoi(strtok(NULL, ".")); - if (SearchFidonet(noden.zone)) - noden.domain = xstrcpy(fidonet.domain); - - Syslog('+', "Add Netmail for %s", ascfnode(&noden, 0x1f)); - if (!do_quiet) { - printf("\rAdding Netmail for %s ", ascfnode(&noden, 0x1f)); - fflush(stdout); - } - - outfile = calloc(PATH_MAX, sizeof(char)); - if (strstr(srcfile, ".iii")) - flavor = 'i'; - else if (strstr(srcfile, ".ccc")) - flavor = 'c'; - else if (strstr(srcfile, ".hhh")) - flavor = 'h'; - else - flavor = 'f'; - if (nodes.Session_out == S_DIR) { - if (flavor == 'f') - flavor = 'o'; - if (noden.point) - sprintf(outfile, "%s/%08x.%cut", nodes.Dir_out_path, noden.point, flavor); - else - sprintf(outfile, "%s/%04x%04x.%cut", nodes.Dir_out_path, noden.net, noden.node, flavor); - } else { - sprintf(outfile, "%s", pktname(&noden, flavor)); - } - Syslog('p', "Outfile: %s", outfile); - - if (nodes.Session_out == S_DIR) { - if (islocked(nodes.Dir_out_clock, nodes.Dir_out_chklck, nodes.Dir_out_waitclr)) { - Syslog('+', "Mail stays in queue, will be added later"); - if (noden.domain) - free(noden.domain); - return FALSE; - } else { - if (! setlock(nodes.Dir_out_mlock, nodes.Dir_out_mklck)) { - Syslog('+', "Mail stays in queue, will be added later"); - if (noden.domain) - free(noden.domain); - return FALSE; - } - } - } else { - if (nodelock(&noden)) { - Syslog('+', "Mail stays in queue, will be added later"); - free(outfile); - if (noden.domain) - free(noden.domain); - return FALSE; - } - } - - /* - * Now we must see if there is already mail in the outbound. - * If that's the case, we must skip the .pkt header from the queue - * because there is already a .pkt header also, append to the - * outbound 2 bytes before the end of file, this is the zero word. - */ - if ((inf = fopen(srcfile, "r")) != NULL) { - if (access(outfile, R_OK) == -1) { - ouf = fopen(outfile, "w"); /* create new */ - Syslog('p', "Create new %s", outfile); - } else { - ouf = fopen(outfile, "r+"); /* open R/W */ - fseek(ouf, -2, SEEK_END); /* b4 0 word */ - fseek(inf, 58, SEEK_SET); /* skip header */ - Syslog('p', "Append to %s", outfile); - } - if (ouf != NULL) { - buf = malloc(16384); - - do { - bread = fread(buf, 1, 16384, inf); - fwrite(buf, 1, bread, ouf); - } while (bread); - - free(buf); - putc('\0', ouf); - putc('\0', ouf); - fsync(fileno(ouf)); - fclose(ouf); - fclose(inf); - unlink(srcfile); - } else { - WriteError("$Can't open %s", outfile); - fclose(inf); - } - } - - if (nodes.Session_out == S_DIR) { - /* - * Change filemode so downlink has rights to the file. - */ - chmod(outfile, 0660); - } - - if (nodes.Session_out == S_DIR) - remlock(nodes.Dir_out_mlock, nodes.Dir_out_mklck); - else - nodeulock(&noden); - if (noden.domain) - free(noden.domain); - free(outfile); - return TRUE; -} - - - -/* - * Pack mailqueue file(s) in the $MBSE_ROOT/tmp directory. - */ -void packmail() -{ - char *temp; - struct dirent *de; - DIR *dp; - - if (!diskfree(CFG.freespace)) - return; - - IsDoing("Packing mail"); - if (!do_quiet) { - colour(9, 0); - printf("Packing mail\n"); - colour(3, 0); - } - - temp = calloc(PATH_MAX, sizeof(char)); - sprintf(temp, "%s/tmp", getenv("MBSE_ROOT")); - - if (chdir(temp) == -1) { - WriteError("$Error chdir to %s", temp); - free(temp); - return; - } - - if ((dp = opendir(temp)) == NULL) { - WriteError("$Error opendir %s", temp); - free(temp); - return; - } - - /* - * Scan the $MBSE_ROOT/tmp directory for .qqq or .nnn files - */ - while ((de = readdir(dp))) { - if (strstr(de->d_name, ".qqq")) - pack_queue(de->d_name); - if (strstr(de->d_name, ".nnn") || strstr(de->d_name, ".iii") || strstr(de->d_name, ".ccc") || strstr(de->d_name, ".hhh")) - add_queue(de->d_name); - } - - closedir(dp); - free(temp); - - if (!do_quiet) { - printf("\r \r"); - fflush(stdout); - } -} - - - diff --git a/mbfido/pack.h b/mbfido/pack.h deleted file mode 100644 index b2a4f635..00000000 --- a/mbfido/pack.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef _PACK_H -#define _PACK_H - - -int pack_queue(char *); -int add_queue(char *); -void packmail(void); - - -#endif - diff --git a/mbfido/ptic.c b/mbfido/ptic.c index 0f0139fe..34eb1ae0 100644 --- a/mbfido/ptic.c +++ b/mbfido/ptic.c @@ -39,7 +39,7 @@ #include "../lib/clcomm.h" #include "../lib/dbnode.h" #include "../lib/dbdupe.h" -#include "ulock.h" +#include "unpack.h" #include "mover.h" #include "toberep.h" #include "tic.h" diff --git a/mbfido/queue.c b/mbfido/queue.c index 67d20dc0..77a5f263 100644 --- a/mbfido/queue.c +++ b/mbfido/queue.c @@ -36,7 +36,530 @@ #include "../lib/records.h" #include "../lib/common.h" #include "../lib/clcomm.h" +#include "../lib/dbnode.h" +#include "../lib/dbftn.h" +#include "fsort.h" +#include "dirsession.h" #include "queue.h" +static char *dow[] = {(char *)"su", (char *)"mo", (char *)"tu", (char *)"we", + (char *)"th", (char *)"fr", (char *)"sa"}; + + +extern int do_quiet; + + +void flush_dir(char *); +void flush_dir(char *ndir) +{ + struct dirent *de; + DIR *dp; + FILE *fp, *inf, *ouf; + faddr noden, *bestaka; + fidoaddr nodenr; + int flavor, Attach, fage, first, bread; + long fsize; + char *temp, *fname, *arcfile, *pktfile, *ext, maxnr, nr, oldnr, *buf; + time_t Now; + struct tm *ptm; + struct stat sbuf; + fd_list *fdl = NULL; + + temp = calloc(PATH_MAX, sizeof(char)); + sprintf(temp, "%s/%s", CFG.out_queue, ndir); + if (chdir(temp) == -1) { + WriteError("$Error chdir to %s", temp); + free(temp); + return; + } + Syslog('p', "Processing outbound queue %s", temp); + + /* + * Get the nodenumber from the filename + */ + noden.domain = NULL; + noden.name = NULL; + noden.zone = atoi(strtok(ndir, ".")); + noden.net = atoi(strtok(NULL, ".")); + noden.node = atoi(strtok(NULL, ".")); + noden.point = atoi(strtok(NULL, "\0")); + if (SearchFidonet(noden.zone)) + noden.domain = xstrcpy(fidonet.domain); + + memset(&nodenr, 0, sizeof(nodenr)); + nodenr.zone = noden.zone; + nodenr.net = noden.net; + nodenr.node = noden.node; + nodenr.point = noden.point; + sprintf(nodenr.domain, "%s", noden.domain); + + if (!SearchNode(nodenr)) { + WriteError("Downlink %s not found", aka2str(nodenr)); + if (noden.domain) + free(noden.domain); + free(temp); + return; + } + + /* + * If we route via another aka, change everything. + */ + if (nodes.RouteVia.zone) { + Syslog('p', "Route Via %s", aka2str(nodes.RouteVia)); + noden.zone = nodes.RouteVia.zone; + noden.net = nodes.RouteVia.net; + noden.node = nodes.RouteVia.node; + noden.point = nodes.RouteVia.point; + if (noden.domain) + free(noden.domain); + noden.domain = xstrcpy(nodes.RouteVia.domain); + /* + * Load routevia noderecord to get the correct flavor. + * If there is no noderecord, reload the old one. + */ + if (!SearchNode(nodes.RouteVia)) + SearchNode(nodenr); + } + + /* + * At this point we are ready to add everything to the real outbound. + * Lock the node, if this fails because the node is busy we abort + * and try to add at a later time. + */ + if (nodes.Session_out == S_DIR) { + if (islocked(nodes.Dir_out_clock, nodes.Dir_out_chklck, nodes.Dir_out_waitclr, 'p')) { + Syslog('+', "Mail and files stay in queue, will be added later"); + if (noden.domain) + free(noden.domain); + free(temp); + return; + } else { + if (! setlock(nodes.Dir_out_mlock, nodes.Dir_out_mklck, 'p')) { + Syslog('+', "Mail and files stay in queue, will be added later"); + if (noden.domain) + free(noden.domain); + free(temp); + return; + } + } + } else { + if (nodelock(&noden)) { + Syslog('+', "Mail and files stay in queue, will be added later"); + if (noden.domain) + free(noden.domain); + free(temp); + return; + } + } + + /* + * Create arcmail filename for this node. + */ + Now = time(NULL); + arcfile = calloc(PATH_MAX, sizeof(char)); + if (nodes.Session_out == S_DIR) { + + ptm = localtime(&Now); + ext = dow[ptm->tm_wday]; + + if (!nodes.ARCmailCompat && (nodes.Aka[0].zone != noden.zone)) { + /* + * Generate ARCfile name from the CRC of the ASCII string of the node address. + */ + sprintf(arcfile, "%s/%08lx.%s0", nodes.Dir_out_path, StringCRC32(ascfnode(&noden, 0x1f)), ext); + } else { + bestaka = bestaka_s(&noden); + + if (noden.point) { + sprintf(arcfile, "%s/%04x%04x.%s0", nodes.Dir_out_path, ((bestaka->net) - (noden.net)) & 0xffff, + ((bestaka->node) - (noden.node) + (noden.point)) & 0xffff, ext); + } else if (bestaka->point) { + /* + * Inserted the next code for if we are a point, + * I hope this is ARCmail 0.60 compliant. 21-May-1999 + */ + sprintf(arcfile, "%s/%04x%04x.%s0", nodes.Dir_out_path, ((bestaka->net) - (noden.net)) & 0xffff, + ((bestaka->node) - (noden.node) - (bestaka->point)) & 0xffff, ext); + } else { + sprintf(arcfile, "%s/%04x%04x.%s0", nodes.Dir_out_path, ((bestaka->net) - (noden.net)) & 0xffff, + ((bestaka->node) - (noden.node)) &0xffff, ext); + } + } + } else { + sprintf(arcfile, "%s", arcname(&noden, nodes.Aka[0].zone, nodes.ARCmailCompat)); + } + Syslog('p', "Arcmail file %s", arcfile); + + /* + * If a not finished .pkt file exist, close it first and rename it. + */ + pktfile = calloc(PATH_MAX, sizeof(char)); + fname = calloc(PATH_MAX, sizeof(char)); + sprintf(fname, "%s/mailpkt.qqq", temp); + if (access(fname, W_OK) == 0) { + sprintf(pktfile, "%s/%08lx.pkt", temp, sequencer()); + if (rename(fname, pktfile)) { + WriteError("$Can't rename %s to %s", fname, pktfile); + } else { + /* + * Add zero word to end of .pkt file + */ + if ((fp = fopen(pktfile, "a+")) == NULL) { + WriteError("$Can't open %s", pktfile); + } + putc('\0', fp); + putc('\0', fp); + fsync(fileno(fp)); + fclose(fp); + Syslog('p', "Renamed %s to %s", fname, pktfile); + } + } + free(fname); + + /* + * Now all mail pkts are ready to archive + */ + if ((dp = opendir(temp)) == NULL) { + WriteError("$Can't open %s", temp); + free(temp); + free(arcfile); + if (nodes.Session_out == S_DIR) + remlock(nodes.Dir_out_mlock, nodes.Dir_out_mklck, 'p'); + else + nodeulock(&noden); + if (noden.domain) + free(noden.domain); + return; + } + + /* + * Read all .pkt filenames, get the timestamp and add them + * to the memory array for later sort on filedate. + */ + while ((de = readdir(dp))) + if ((strlen(de->d_name) == 12) && (strncasecmp(de->d_name+8,".pkt",4) == 0)) { + stat(de->d_name, &sbuf); + Syslog('p', "Adding %s to filelist", de->d_name); + fill_fdlist(&fdl, de->d_name, sbuf.st_mtime); + } + + closedir(dp); + sort_fdlist(&fdl); + + if (getarchiver((char *)"ZIP")) { + flavor = 'f'; + if (nodes.Crash) + flavor = 'c'; + if (nodes.Hold) + flavor = 'h'; + } else { + WriteError("Archiver ZIP not found"); + if (noden.domain) + free(noden.domain); + free(temp); + free(arcfile); + return; + } + + first = TRUE; + while ((fname = pull_fdlist(&fdl)) != NULL) { + /* + * Check the size of the existing archive if there is a size limit. + * Change to new archive names if the existing is too large. + * If the archive size is zero, it's an already sent archive, the + * number will be bumped also. + * If the archive is older then 6 days, the name is also bumped. + * Do this until we find a new name or if the last digit is a '9' or 'z'. + * Purge archives older then toss_days. + */ + Syslog('p', "Pulled %s", fname); + + nr = oldnr = '0'; + if (nodes.ARCmailAlpha) + maxnr = 'z'; + else + maxnr = '9'; + Attach = FALSE; + + for (;;) { + fsize = file_size(arcfile); + fage = (int)((Now - file_time(arcfile)) / 86400); + + if (fsize == -1L) { + Attach = TRUE; + break; + } + + if (fsize == 0L) { + if ((fage > 6) && (nr < maxnr)) { + /* + * Remove truncated ARCmail files older then 6 days. + */ + unlink(arcfile); + fsize = -1L; + Attach = TRUE; + break; + } + + /* + * Increase filename extension if there is a truncated file of today. + */ + nr++; + if (nr == ('9' +1)) + nr = 'a'; + arcfile[strlen(arcfile) -1] = nr; + } else if (CFG.maxarcsize && (fsize > (CFG.maxarcsize * 1024)) && (nr < maxnr)) { + /* + * Use a new ARCmail file if the last one is too big. + */ + nr++; + if (nr == ('9' +1)) + nr = 'a'; + arcfile[strlen(arcfile) -1] = nr; + } + + fsize = file_size(arcfile); + fage = (int)((Now - file_time(arcfile)) / 86400); + + if ((fsize > 0L) && (fage > 6) && (nr < maxnr)) { + /* + * If there is ARCmail of a week old or older, add mail + * to a new ARCmail bundle. + */ + nr++; + if (nr == ('9' +1)) + nr = 'a'; + arcfile[strlen(arcfile) -1] = nr; + } + + if (oldnr == nr) + break; + else + oldnr = nr; + } + + fsize = file_size(arcfile); + + if (first) { + Syslog('+', "Pack ARCmail for %s, via %s", aka2str(nodenr), ascfnode(&noden, 0x1f)); + if (!do_quiet) { + printf("\rAdding ARCmail for %s ", ascfnode(&noden, 0x1f)); + fflush(stdout); + } + first = FALSE; + } + + if (execute(archiver.marc, arcfile, fname, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null") == 0) { + unlink(fname); + } else { + Syslog('+', "Create ARCmail failed, trying again after sync()"); + sync(); + sleep(1); + if (execute(archiver.marc, arcfile, fname, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null") == 0) { + unlink(fname); + } else { + WriteError("Can't add %s to ARCmail archive", fname); + Attach = FALSE; + } + } + + /* + * Change filemode so downlink has rights to the file. + */ + if (nodes.Session_out == S_DIR) + chmod(arcfile, 0660); + + /* + * Attach file to .flo, not for FTP or Directory sessions. + */ + if (Attach && nodes.Session_out == S_DIRECT) + attach(noden, arcfile, TFS, flavor); + } + Syslog('p', "Done with ARCmail"); + + /* + * Open directory again. + */ + if ((dp = opendir(temp)) == NULL) { + WriteError("$Can't open %s", temp); + free(temp); + free(arcfile); + if (nodes.Session_out == S_DIR) + remlock(nodes.Dir_out_mlock, nodes.Dir_out_mklck, 'p'); + else + nodeulock(&noden); + if (noden.domain) + free(noden.domain); + return; + } + + /* + * Read all other mail filenames, get the timestamp and add them + * to the memory array for later sort on filedate. + */ + while ((de = readdir(dp))) + if ((strlen(de->d_name) == 11) && (strncasecmp(de->d_name,"mailpkt.",8) == 0)) { + stat(de->d_name, &sbuf); + Syslog('p', "Adding %s to filelist", de->d_name); + fill_fdlist(&fdl, de->d_name, sbuf.st_mtime); + } + + closedir(dp); + sort_fdlist(&fdl); + + first = TRUE; + while ((fname = pull_fdlist(&fdl)) != NULL) { + if (first) { + Syslog('+', "Pack unpacked mail for %s, via %s", aka2str(nodenr), ascfnode(&noden, 0x1f)); + if (!do_quiet) { + printf("\rAdding netmail for %s ", ascfnode(&noden, 0x1f)); + fflush(stdout); + } + first = FALSE; + } + + sprintf(pktfile, "%s/%s", temp, fname); + + if (strstr(fname, ".iii")) + flavor = 'i'; + else if (strstr(fname, ".ccc")) + flavor = 'c'; + else if (strstr(fname, ".hhh")) + flavor = 'h'; + else + flavor = 'o'; + + if (nodes.Session_out == S_DIR) { + if (noden.point) + sprintf(arcfile, "%s/%08x.%cut", nodes.Dir_out_path, noden.point, flavor); + else + sprintf(arcfile, "%s/%04x%04x.%cut", nodes.Dir_out_path, noden.net, noden.node, flavor); + } else { + sprintf(arcfile, "%s", pktname(&noden, flavor)); + } + Syslog('p', "Outfile: %s", arcfile); + Syslog('p', "Pktfile: %s", pktfile); + + /* + * Now we must see if there is already mail in the outbound. + * If that's the case, we must skip the .pkt header from the queue + * because there is already a .pkt header also, append to the + * outbound 2 bytes before the end of file, this is the zero word. + */ + if ((inf = fopen(pktfile, "r")) != NULL) { + if (access(arcfile, R_OK) == -1) { + ouf = fopen(arcfile, "w"); /* create new */ + Syslog('p', "Create new %s", arcfile); + } else { + ouf = fopen(arcfile, "r+"); /* open R/W */ + fseek(ouf, -2, SEEK_END); /* b4 0 word */ + fseek(inf, 58, SEEK_SET); /* skip header */ + Syslog('p', "Append to %s", arcfile); + } + + if (ouf != NULL) { + buf = malloc(16384); + + do { + bread = fread(buf, 1, 16384, inf); + fwrite(buf, 1, bread, ouf); + } while (bread); + + free(buf); + putc('\0', ouf); + putc('\0', ouf); + fsync(fileno(ouf)); + fclose(ouf); + fclose(inf); + unlink(pktfile); + } else { + WriteError("$Can't open %s", arcfile); + fclose(inf); + } + } + + /* + * Change filemode so downlink has rights to the file. + */ + if (nodes.Session_out == S_DIR) + chmod(arcfile, 0660); + } + Syslog('p', "Done with netmail"); + +// Add files + + + /* + * We are done, the queue is flushed, unlock the node. + */ + if (nodes.Session_out == S_DIR) + remlock(nodes.Dir_out_mlock, nodes.Dir_out_mklck, 'p'); + else + nodeulock(&noden); + + if (noden.domain) + free(noden.domain); + free(temp); + free(arcfile); + free(pktfile); + return; +} + + + +/* + * Flush outbound queue to real outbound. + */ +void flush_queue(void) +{ + char *temp; + struct dirent *de; + DIR *dp; + + Syslog('+', "Flushing outbound queue"); + if (!diskfree(CFG.freespace)) + return; + + IsDoing("Flush queue"); + if (!do_quiet) { + colour(LIGHTBLUE, BLACK); + printf("Flushing outbound queue\n"); + colour(CYAN, BLACK); + } + + temp = calloc(PATH_MAX, sizeof(char)); + sprintf(temp, "%s/foobar", CFG.out_queue); + mkdirs(temp, 0750); + + if ((dp = opendir(CFG.out_queue)) == 0) { + WriteError("$Can't open %s", CFG.out_queue); + free(temp); + return; + } + + /* + * The outbound queue contains subdirectories which actuallly hold the + * queue outbound files. Process each found subdirectory. + */ + while ((de = readdir(dp))) { + if (strcmp(de->d_name, ".") && strcmp(de->d_name, "..")) { + sprintf(temp, "%s/%s", CFG.out_queue, de->d_name); + Syslog('p', "Queue directory %s", temp); + flush_dir(de->d_name); + if (chdir(CFG.out_queue)) + WriteError("$Can't chdir to %s", CFG.out_queue); + if (rmdir(temp)) + WriteError("$Can't rmdir %s", temp); + } + } + closedir(dp); + free(temp); + + if (!do_quiet) { + printf("\r \r"); + fflush(stdout); + } +} + diff --git a/mbfido/queue.h b/mbfido/queue.h index d302638c..c4c24a88 100644 --- a/mbfido/queue.h +++ b/mbfido/queue.h @@ -3,4 +3,8 @@ /* $Id$ */ + +void flush_queue(void); + + #endif diff --git a/mbfido/rfc2ftn.c b/mbfido/rfc2ftn.c index 151529ba..01d96c95 100644 --- a/mbfido/rfc2ftn.c +++ b/mbfido/rfc2ftn.c @@ -45,7 +45,6 @@ #include "mkftnhdr.h" #include "hash.h" #include "rollover.h" -#include "pack.h" #include "postnetmail.h" #include "postecho.h" #include "msgflags.h" diff --git a/mbfido/rnews.c b/mbfido/rnews.c index b07fba61..11f8ead8 100644 --- a/mbfido/rnews.c +++ b/mbfido/rnews.c @@ -43,7 +43,6 @@ #include "../lib/dbmsgs.h" #include "../lib/msg.h" #include "../lib/msgtext.h" -#include "pack.h" #include "rfc2ftn.h" #include "mbfido.h" #include "../paths.h" @@ -100,6 +99,7 @@ extern int most_debug; extern int news_in; extern int news_dupe; extern int check_dupe; +extern int do_flush; void ProcessOne(FILE *); @@ -561,7 +561,7 @@ void NewsUUCP(void) most_debug = FALSE; WaitForChildren(i); Syslog('+', "End of UUCP batch, rc=%d", rc); - packmail(); + do_flush = TRUE; if (!do_quiet) printf("\r \r"); diff --git a/mbfido/scan.c b/mbfido/scan.c index 02bdb539..5e37cb87 100644 --- a/mbfido/scan.c +++ b/mbfido/scan.c @@ -41,7 +41,6 @@ #include "../lib/dbnode.h" #include "../lib/dbmsgs.h" #include "addpkt.h" -#include "pack.h" #include "tracker.h" #include "ftn2rfc.h" #include "rfc2ftn.h" @@ -56,6 +55,7 @@ extern int echo_in; extern int email_out; extern int echo_out; extern int most_debug; +extern int do_flush; int scanned; #define MAXSEEN 70 @@ -133,7 +133,7 @@ void ScanMail(int DoAll) ScanFull(); if (echo_out || net_out) - packmail(); + do_flush = TRUE; RemoveSema((char *)"mailout"); } diff --git a/mbfido/scannews.c b/mbfido/scannews.c index 5f406874..2c265416 100644 --- a/mbfido/scannews.c +++ b/mbfido/scannews.c @@ -45,7 +45,6 @@ #include "mkftnhdr.h" #include "hash.h" #include "rollover.h" -#include "pack.h" #include "storeecho.h" #include "rfc2ftn.h" #include "scannews.h" @@ -75,6 +74,7 @@ extern int news_imp; extern int news_dupe; extern int echo_out; extern int echo_in; +extern int do_flush; extern char *replyaddr; @@ -243,7 +243,7 @@ void ScanNews(void) free(tmp->field); free(tmp); } - packmail(); + do_flush = TRUE; if (!do_quiet) printf("\r \r"); diff --git a/mbfido/tic.c b/mbfido/tic.c index 5f91d65d..a0b7cec4 100644 --- a/mbfido/tic.c +++ b/mbfido/tic.c @@ -37,10 +37,9 @@ #include "../lib/common.h" #include "../lib/dbftn.h" #include "../lib/clcomm.h" -#include "ulock.h" +#include "unpack.h" #include "ptic.h" #include "fsort.h" -#include "pack.h" #include "tic.h" #define UNPACK_FACTOR 300 @@ -55,6 +54,7 @@ int tic_dup = 0; /* dupe .tic files */ extern int do_unprot; extern int do_quiet; extern int tic_in; +extern int do_flush; /* @@ -149,7 +149,7 @@ int Tic() } if (rc) - packmail(); + do_flush = TRUE; if (CompileNL) CreateSema((char *)"mbindex"); diff --git a/mbfido/ulock.h b/mbfido/ulock.h deleted file mode 100644 index b91f61ab..00000000 --- a/mbfido/ulock.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef _ULOCK_H -#define _ULOCK_H - -int checkspace(char *, char *, int); -int lockunpack(void); -void ulockunpack(void); -int unpack(char *); - -#endif - - diff --git a/mbfido/ulock.c b/mbfido/unpack.c similarity index 65% rename from mbfido/ulock.c rename to mbfido/unpack.c index c133a7f9..87fa7aab 100644 --- a/mbfido/ulock.c +++ b/mbfido/unpack.c @@ -1,7 +1,7 @@ /***************************************************************************** * * $Id$ - * Purpose ...............: Lock mbfido processing. + * Purpose ...............: Unpacker * ***************************************************************************** * Copyright (C) 1997-2002 @@ -37,85 +37,13 @@ #include "../lib/common.h" #include "../lib/clcomm.h" #include "flock.h" -#include "ulock.h" +#include "unpack.h" #define UNPACK_FACTOR 300 #define TOSS_FACTOR 120 -#define TMPNAME "TMP." -#define LCKNAME "LOCKFILE" -static char lockfile[81]; - -extern int do_quiet; -static int is_locked = FALSE; - - -/* - * Put a lock on this program. - */ -int lockunpack(void) -{ - char Tmpfile[81]; - FILE *fp; - pid_t oldpid; - - sprintf(Tmpfile, "%s/", CFG.inbound); - strcpy(lockfile, Tmpfile); - sprintf(Tmpfile + strlen(Tmpfile), "%s%u", TMPNAME, getpid()); - sprintf(lockfile + strlen(lockfile), "%s", LCKNAME); - - if ((fp = fopen(Tmpfile, "w")) == NULL) { - WriteError("$Can't create lockfile \"%s\"", Tmpfile); - return 1; - } - fprintf(fp, "%10u\n", getpid()); - fclose(fp); - - while (1) { - if (link(Tmpfile, lockfile) == 0) { - unlink(Tmpfile); - is_locked = TRUE; - return 0; - } - if ((fp = fopen(lockfile, "r")) == NULL) { - WriteError("$Can't open lockfile \"%s\"", Tmpfile); - unlink(Tmpfile); - return 1; - } - if (fscanf(fp, "%u", &oldpid) != 1) { - WriteError("$Can't read old pid from \"%s\"", Tmpfile); - fclose(fp); - unlink(Tmpfile); - return 1; - } - fclose(fp); - if (kill(oldpid,0) == -1) { - if (errno == ESRCH) { - Syslog('+', "Stale lock found for pid %u", oldpid); - unlink(lockfile); - /* no return, try lock again */ - } else { - WriteError("$Kill for %u failed",oldpid); - unlink(Tmpfile); - return 1; - } - } else { - Syslog('+', "mbfido already running, pid=%u", oldpid); - unlink(Tmpfile); - return 1; - } - } -} - - - -void ulockunpack(void) -{ - if (is_locked && lockfile) - (void)unlink(lockfile); -} - +extern int do_quiet; int checkspace(char *dir, char *fn, int factor) diff --git a/mbfido/unpack.h b/mbfido/unpack.h new file mode 100644 index 00000000..4d9286ef --- /dev/null +++ b/mbfido/unpack.h @@ -0,0 +1,9 @@ +#ifndef _UNPACK_H +#define _UNPACK_H + +/* $Id$ */ + +int checkspace(char *, char *, int); +int unpack(char *); + +#endif