Implemented directory inbound sessions

This commit is contained in:
Michiel Broek 2002-08-03 19:52:57 +00:00
parent 0018fbc498
commit ae5dd4bfbe
5 changed files with 242 additions and 4 deletions

View File

@ -29,6 +29,7 @@ v0.35.03 06-Jul-2002
Added routing tables for special cases. Most systems don't Added routing tables for special cases. Most systems don't
need this. need this.
The route test command now works exactly as netmails do. The route test command now works exactly as netmails do.
Implemented directory inbound tossing.
newuser: newuser:
Check for Unix accounts is now case sensitive. Check for Unix accounts is now case sensitive.

View File

@ -14,7 +14,7 @@ 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 \ hash.c mbaff.c mbseq.c notify.c postnetmail.c scannews.c tosspkt.c \
mbfkill.c mbfutil.c mbfindex.c mbfcheck.c mbfpack.c mbflist.c mbfadopt.c \ mbfkill.c mbfutil.c mbfindex.c mbfcheck.c mbfpack.c mbflist.c mbfadopt.c \
mbfimport.c virscan.c mbftoberep.c mbfmove.c mbfdel.c bounce.c \ mbfimport.c virscan.c mbftoberep.c mbfmove.c mbfdel.c bounce.c \
createm.c createf.c msgflags.c createm.c createf.c msgflags.c dirsession.c
HDRS = addbbs.h backalias.h flock.h hatch.h mbdiff.h mgrutil.h pack.h \ HDRS = addbbs.h backalias.h flock.h hatch.h mbdiff.h mgrutil.h pack.h \
postnetmail.h scannews.h tosspkt.h addpkt.h bwrite.h forward.h \ postnetmail.h scannews.h tosspkt.h addpkt.h bwrite.h forward.h \
lhash.h mbfido.h mkftnhdr.h ptic.h sendmail.h tracker.h \ lhash.h mbfido.h mkftnhdr.h ptic.h sendmail.h tracker.h \
@ -25,14 +25,14 @@ HDRS = addbbs.h backalias.h flock.h hatch.h mbdiff.h mgrutil.h pack.h \
atoul.h filemgr.h hash.h mbaff.h mbseq.h notify.h postemail.h scan.h toberep.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 \ 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 \ mbfimport.h virscan.h mbftoberep.h mbfmove.h mbfdel.h bounce.h \
createm.h createf.h msgflags.h createm.h createf.h msgflags.h dirsession.h
MBFIDO_OBJS = flock.o tosspkt.o mbfido.o hatch.o maketags.o virscan.o tracker.o \ 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 pack.o ulock.o tic.o ptic.o \
utic.o mover.o hash.o mkftnhdr.o addbbs.o magic.o fsort.o toberep.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 \ 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 \ 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 \ bwrite.o rfc2ftn.o rnews.o newspost.o aliasdb.o postemail.o postnetmail.o \
postecho.o backalias.o createm.o createf.o msgflags.o postecho.o backalias.o createm.o createf.o msgflags.o dirsession.o
MBSEQ_OBJS = mbseq.o MBSEQ_OBJS = mbseq.o
MBAFF_OBJS = announce.o fflist.o filefind.o grlist.o mbaff.o msgutil.o MBAFF_OBJS = announce.o fflist.o filefind.o grlist.o mbaff.o msgutil.o
MBINDEX_OBJS = mbindex.o MBINDEX_OBJS = mbindex.o
@ -148,7 +148,7 @@ addpkt.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/us
bwrite.o: ../config.h ../lib/libs.h ../lib/memwatch.h bwrite.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 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
lhash.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/clcomm.h lhash.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 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
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 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 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 pack.h postnetmail.h postecho.h msgflags.h rfc2ftn.h
@ -206,4 +206,5 @@ bounce.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/us
createm.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 mgrutil.h createm.h createm.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 mgrutil.h createm.h
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 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 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
# End of generated dependencies # End of generated dependencies

219
mbfido/dirsession.c Normal file
View File

@ -0,0 +1,219 @@
/*****************************************************************************
*
* $Id$
* Purpose ...............: Directory Mail/Files sessions
*
*****************************************************************************
* 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 "dirsession.h"
extern int do_unprot;
/*
* Check for lock, return TRUE if node is locked.
*/
int islocked(char *, int, int);
int islocked(char *lockfile, int chklck, int waitclr)
{
int i;
time_t now, ftime;
if (chklck && strlen(lockfile)) {
Syslog('m', "Checking lockfile %s", lockfile);
/*
* First check for stale lockfile.
*/
if (! file_exist(lockfile, R_OK)) {
ftime = file_time(lockfile);
now = time(NULL);
if ((now - ftime) > 21600) {
Syslog('+', "Removing stale lockfile %s, older then 6 hours", lockfile);
file_rm(lockfile);
}
}
/*
* Next check for lockfile with wait for clear
*/
if ((file_exist(lockfile, R_OK) == 0) && waitclr) {
Syslog('+', "Node is locked, waiting 10 minutes");
i = 120;
while (TRUE) {
sleep(5);
Nopper();
if (file_exist(lockfile, R_OK))
break;
i--;
if (i == 0) {
Syslog('+', "Timeout waiting for lock %s", lockfile);
break;
}
}
}
/*
* Check again if lockfile exists.
*/
if (file_exist(lockfile, R_OK)) {
return FALSE;
} else {
Syslog('+', "Lockfile exists, skipping this node");
return TRUE;
}
}
return FALSE;
}
/*
* Create a 1 byte lockfile if create is TRUE.
* Returns FALSE if failed.
*/
int setlock(char *, int);
int setlock(char *lockfile, int create)
{
FILE *fp;
char temp[1];
if (create && strlen(lockfile)) {
Syslog('m', "create lockfile %s", lockfile);
if ((fp = fopen(lockfile, "w")) == NULL) {
WriteError("$Can't create lock %s", lockfile);
return FALSE;
}
fwrite(temp, 1, sizeof(char), fp);
fsync(fileno(fp));
fclose(fp);
chmod(lockfile, 0664);
}
return TRUE;
}
/*
* Removing lockfile
*/
void remlock(char *, int);
void remlock(char *lockfile, int create)
{
if (create) {
if (file_rm(lockfile))
WriteError("$Can't remove lock %s", lockfile);
else
Syslog('m', "Removed lock %s", lockfile);
}
}
void dirinbound(void)
{
FILE *fp;
char *temp, *from, *too;
long fileptr;
struct dirent *de;
DIR *dp;
Syslog('m', "Starting directory inbound sessions");
temp = calloc(PATH_MAX, sizeof(char));
sprintf(temp, "%s/etc/nodes.data", getenv("MBSE_ROOT"));
if ((fp = fopen(temp, "r")) != NULL) {
fread(&nodeshdr, sizeof(nodeshdr), 1, fp);
while (fread(&nodes, nodeshdr.recsize, 1, fp) == 1) {
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)) {
Syslog('m', "Node is free, start processing");
setlock(nodes.Dir_in_mlock, nodes.Dir_in_mklck);
if ((dp = opendir(nodes.Dir_in_path)) == NULL) {
WriteError("$Can't open directory %s", nodes.Dir_in_path);
} else {
from = calloc(PATH_MAX, sizeof(char));
too = calloc(PATH_MAX, sizeof(char));
while ((de = readdir(dp))) {
if (strcmp(de->d_name, ".") && strcmp(de->d_name, "..")) {
sprintf(from, "%s/%s", nodes.Dir_in_path, de->d_name);
if (access(from, R_OK | W_OK)) {
WriteError("$No rights to move %s", from);
} else {
/*
* Inbound is set by previous toss or tic to
* protected or unprotected inbound.
*/
if (do_unprot)
sprintf(too, "%s/%s", CFG.inbound, de->d_name);
else
sprintf(too, "%s/%s", CFG.pinbound, de->d_name);
if (access(too, F_OK) == 0) {
WriteError("File %s already in inbound, skip", too);
} else {
Syslog('m', "Move %s to %s", from, too);
if (file_mv(from, too)) {
WriteError("$Move %s to %s failed", from, too);
}
}
}
}
}
free(too);
free(from);
}
remlock(nodes.Dir_in_mlock, nodes.Dir_in_mklck);
}
/*
* Reread noderecord
*/
fseek(fp, fileptr, SEEK_SET);
fread(&nodes, nodeshdr.recsize, 1, fp);
}
fseek(fp, nodeshdr.filegrp + nodeshdr.mailgrp, SEEK_CUR);
}
}
free(temp);
Syslog('m', "Finished directory inbound sessions");
}

10
mbfido/dirsession.h Normal file
View File

@ -0,0 +1,10 @@
#ifndef _DIRSESSION_H
#define _DIRSESSION_H
/* $Id$ */
void dirinbound(void);
#endif

View File

@ -65,6 +65,7 @@
#include "mgrutil.h" #include "mgrutil.h"
#include "backalias.h" #include "backalias.h"
#include "rfc2ftn.h" #include "rfc2ftn.h"
#include "dirsession.h"
#define UNPACK_FACTOR 300 #define UNPACK_FACTOR 300
@ -534,6 +535,12 @@ int main(int argc, char **argv)
if (TossMail() == FALSE) if (TossMail() == FALSE)
die(0); die(0);
} }
if (do_tic || do_toss) {
/*
* Do inbound direcory sessions
*/
dirinbound();
}
if (!do_uucp) if (!do_uucp)
newspost(); newspost();
if (do_test) { if (do_test) {