Bumped version number, added support for nodes outbound boxes

This commit is contained in:
Michiel Broek
2002-06-24 20:34:07 +00:00
parent cf432130e8
commit d864d6a2a9
28 changed files with 1503 additions and 921 deletions

View File

@@ -43,46 +43,47 @@
#define PATH_MAX 512
#endif
extern int master;
int made_request;
extern int master;
extern int Loaded;
int made_request;
static char *tmpkname(void);
static char *tmpkname(void)
{
static char buf[16];
static char buf[16];
sprintf(buf,"%08lx.pkt", sequencer());
return buf;
sprintf(buf,"%08lx.pkt", sequencer());
return buf;
}
char *xtodos(char *orig)
{
char buf[13], *copy, *p;
char buf[13], *copy, *p;
if (orig == NULL)
return NULL;
if (orig == NULL)
return NULL;
if ((remote_flags & SESSION_FNC) == 0) {
Syslog('o', "No filename conversion for \"%s\"", MBSE_SS(orig));
return xstrcpy(orig);
}
if ((remote_flags & SESSION_FNC) == 0) {
Syslog('o', "No filename conversion for \"%s\"", MBSE_SS(orig));
return xstrcpy(orig);
}
copy = xstrcpy(orig);
if ((p = strrchr(copy,'/')))
p++;
else
p = copy;
copy = xstrcpy(orig);
if ((p = strrchr(copy,'/')))
p++;
else
p = copy;
name_mangle(p);
memset(&buf, 0, sizeof(buf));
strncpy(buf, p, 12);
Syslog('o', "name \"%s\" converted to \"%s\"", MBSE_SS(orig), MBSE_SS(buf));
free(copy);
return xstrcpy(buf);
name_mangle(p);
memset(&buf, 0, sizeof(buf));
strncpy(buf, p, 12);
Syslog('o', "name \"%s\" converted to \"%s\"", MBSE_SS(orig), MBSE_SS(buf));
free(copy);
return xstrcpy(buf);
}
@@ -100,29 +101,28 @@ char *xtodos(char *orig)
*/
void add_list(file_list **lst, char *local, char *Remote, int disposition, off_t floff, FILE *flofp, int toend)
{
file_list **tmpl;
file_list *tmp;
file_list **tmpl, *tmp;
Syslog('o', "add_list(\"%s\",\"%s\",%d,%s)", MBSE_SS(local),MBSE_SS(Remote),disposition,toend?"to end":"to beg");
Syslog('o', "add_list(\"%s\",\"%s\",%d,%s)", MBSE_SS(local),MBSE_SS(Remote),disposition,toend?"to end":"to beg");
if (toend)
for (tmpl = lst; *tmpl; tmpl =&((*tmpl)->next));
else
tmpl = &tmp;
*tmpl = (file_list*)malloc(sizeof(file_list));
if (toend) {
(*tmpl)->next = NULL;
} else {
(*tmpl)->next = *lst;
*lst = *tmpl;
}
if (toend)
for (tmpl = lst; *tmpl; tmpl =&((*tmpl)->next));
else
tmpl = &tmp;
*tmpl = (file_list*)malloc(sizeof(file_list));
if (toend) {
(*tmpl)->next = NULL;
} else {
(*tmpl)->next = *lst;
*lst = *tmpl;
}
(*tmpl)->remote = xtodos(Remote);
(*tmpl)->local = xstrcpy(local);
(*tmpl)->disposition = disposition;
(*tmpl)->floff = floff;
(*tmpl)->flofp = flofp;
return;
(*tmpl)->remote = xtodos(Remote);
(*tmpl)->local = xstrcpy(local);
(*tmpl)->disposition = disposition;
(*tmpl)->floff = floff;
(*tmpl)->flofp = flofp;
return;
}
@@ -130,187 +130,248 @@ void add_list(file_list **lst, char *local, char *Remote, int disposition, off_t
static void check_flo(file_list **, char *);
static void check_flo(file_list **lst, char *nm)
{
FILE *fp;
off_t off;
struct flock fl;
char buf[PATH_MAX],buf2[PATH_MAX],*p,*q;
int disposition;
struct stat stbuf;
Syslog('O', "check_flo(\"%s\")",MBSE_SS(nm));
if ((fp = fopen(nm,"r+")) == NULL) {
Syslog('O',"no flo file");
return;
}
fl.l_type = F_RDLCK;
fl.l_whence = 0;
fl.l_start = 0L;
fl.l_len = 0L;
if (fcntl(fileno(fp), F_SETLK, &fl) != 0) {
if (errno != EAGAIN)
WriteError("$cannot read-lock \"%s\"",MBSE_SS(nm));
else
Syslog('O',"flo file busy");
fclose(fp);
return;
}
if (stat(nm, &stbuf) != 0) {
WriteError("$cannot access \"%s\"",MBSE_SS(nm));
fclose(fp);
return;
}
while (!feof(fp) && !ferror(fp)) {
off = ftell(fp);
if (fgets(buf, sizeof(buf)-1, fp) == NULL)
continue;
if (buf[0] == '~')
continue; /* skip sent files */
if (*(p=buf + strlen(buf) -1) == '\n')
*p-- = '\0';
if (*p == '\r')
*p = '\0';
switch (buf[0]) {
case '#': p=buf+1; disposition=TFS; break;
case '-':
case '^': p=buf+1; disposition=KFS; break;
case '@': p=buf+1; disposition=LEAVE; break;
case 0: continue;
default: p=buf; disposition=LEAVE; break;
}
memset(&buf2, 0, sizeof(buf2));
if (strlen(CFG.dospath)) {
if (strncasecmp(p, CFG.dospath, strlen(CFG.dospath)) == 0) {
strcpy(buf2,uxoutbound);
for (p+=strlen(CFG.dospath), q=buf2+strlen(buf2); *p; p++, q++)
*q = ((*p) == '\\')?'/':tolower(*p);
*q = '\0';
p = buf2;
}
// FIXME: removed because it is useless, but it may break some systems.
// } else {
// if (strncasecmp(p, CFG.uxpath, strlen(CFG.uxpath)) == 0) {
// for (p=p, q=buf2+strlen(buf2); *p; p++, q++)
// *q = ((*p) == '\\')?'/':tolower(*p);
// *q = '\0';
// p = buf2;
// }
}
if ((q=strrchr(p,'/')))
q++;
else
q = p;
add_list(lst, p, q, disposition, off, fp, 1);
}
FILE *fp;
off_t off;
struct flock fl;
char buf[PATH_MAX], buf2[PATH_MAX], *p, *q;
int disposition;
struct stat stbuf;
if ((fp = fopen(nm,"r+")) == NULL) {
/*
* Add flo file to file list
* If no flo file, return.
*/
add_list(lst, nm, NULL, KFS, -1L, fp, 1);
/* here, we leave .flo file open, it will be closed by */
/* execute_disposition */
return;
}
Syslog('o', "check_flo(\"%s\")",MBSE_SS(nm));
fl.l_type = F_RDLCK;
fl.l_whence = 0;
fl.l_start = 0L;
fl.l_len = 0L;
if (fcntl(fileno(fp), F_SETLK, &fl) != 0) {
if (errno != EAGAIN)
WriteError("$Can't read-lock \"%s\"", MBSE_SS(nm));
else
Syslog('o',"flo file busy");
fclose(fp);
return;
}
if (stat(nm, &stbuf) != 0) {
WriteError("$Can't access \"%s\"", MBSE_SS(nm));
fclose(fp);
return;
}
while (!feof(fp) && !ferror(fp)) {
off = ftell(fp);
if (fgets(buf, sizeof(buf)-1, fp) == NULL)
continue;
if (buf[0] == '~')
continue; /* skip sent files */
if (*(p=buf + strlen(buf) -1) == '\n')
*p-- = '\0';
if (*p == '\r')
*p = '\0';
switch (buf[0]) {
case '#': p=buf+1; disposition=TFS; break;
case '-':
case '^': p=buf+1; disposition=KFS; break;
case '@': p=buf+1; disposition=LEAVE; break;
case 0: continue;
default: p=buf; disposition=LEAVE; break;
}
memset(&buf2, 0, sizeof(buf2));
if (strlen(CFG.dospath)) {
if (strncasecmp(p, CFG.dospath, strlen(CFG.dospath)) == 0) {
strcpy(buf2,uxoutbound);
for (p+=strlen(CFG.dospath), q=buf2+strlen(buf2); *p; p++, q++)
*q = ((*p) == '\\')?'/':tolower(*p);
*q = '\0';
p = buf2;
}
}
if ((q=strrchr(p,'/')))
q++;
else
q = p;
add_list(lst, p, q, disposition, off, fp, 1);
}
/*
* Add flo file to file list
*/
add_list(lst, nm, NULL, KFS, -1L, fp, 1);
/* here, we leave .flo file open, it will be closed by */
/* execute_disposition */
return;
}
file_list *create_filelist(fa_list *al, char *fl, int create)
{
file_list *st=NULL;
file_list *tmpf;
fa_list *tmpa;
char flavor, *tmpfl;
char *nm;
char tmpreq[13];
struct stat stbuf;
int packets = 0;
FILE *fp;
unsigned char buffer[2];
file_list *st = NULL, *tmpf;
fa_list *tmpa;
char flavor, *tmpfl, *nm, *temp, tmpreq[13];
struct stat stbuf;
int packets = 0;
FILE *fp;
DIR *dp;
struct dirent *de;
unsigned char buffer[2];
struct passwd *pw;
Syslog('o', "Create_filelist(%s,\"%s\",%d)", al?ascfnode(al->addr,0x1f):"<none>", MBSE_SS(fl), create);
made_request = 0;
Syslog('o', "Create_filelist(%s,\"%s\",%d)", al?ascfnode(al->addr,0x1f):"<none>", MBSE_SS(fl), create);
made_request = 0;
for (tmpa = al; tmpa; tmpa = tmpa->next) {
Syslog('o', "Check address %s", ascfnode(tmpa->addr, 0x1f));
for (tmpa = al; tmpa; tmpa = tmpa->next) {
Syslog('o', "Check address %s", ascfnode(tmpa->addr, 0x1f));
/*
* Check spool files, these are more or less useless but they
* create a filelist of files to send which are never send.
* It gives the transfer protocols something "to do".
*/
if (strchr(fl, 'o')) {
nm = splname(tmpa->addr);
if ((fp = fopen(nm, "w")))
fclose(fp);
if ((nm != NULL) && (stat(nm, &stbuf) == 0))
add_list(&st, nm, NULL, DSF, 0L, NULL, 1);
}
/*
* Check .pol files
*/
nm = polname(tmpa->addr);
if ((nm != NULL) && (stat(nm,&stbuf) == 0))
add_list(&st,nm,NULL,DSF,0L,NULL,1);
/*
* Check other files, all flavors
*/
tmpfl = fl;
while ((flavor = *tmpfl++)) {
/*
* Check normal mail packets
*/
nm = pktname(tmpa->addr,flavor);
if ((nm != NULL) && (stat(nm,&stbuf) == 0)) {
packets++;
add_list(&st, nm, tmpkname(), KFS, 0L, NULL, 1);
}
/*
* Check .flo files for file attaches
*/
nm = floname(tmpa->addr,flavor);
check_flo(&st, nm);
}
if ((session_flags & SESSION_WAZOO) &&
((session_flags & SESSION_HYDRA) == 0) && (master || ((session_flags & SESSION_IFNA) == 0))) {
/*
* we don't distinguish flavoured reqs
*/
nm = reqname(tmpa->addr);
if ((nm != NULL) && (stat(nm, &stbuf) == 0)) {
sprintf(tmpreq, "%04X%04X.REQ", tmpa->addr->net, tmpa->addr->node);
add_list(&st, nm, tmpreq, DSF, 0L, NULL, 1);
made_request = 1;
/*
* For the main aka, check the outbox.
*/
if ((tmpa->addr) && Loaded && strlen(nodes.OutBox) &&
(tmpa->addr->zone == nodes.Aka[0].zone) && (tmpa->addr->net == nodes.Aka[0].net) &&
(tmpa->addr->node == nodes.Aka[0].node) && (tmpa->addr->point == nodes.Aka[0].point)) {
Syslog('o', "checking outbox %s", nodes.OutBox);
if (nodes.Crash)
flavor = 'c';
else if (nodes.Hold)
flavor = 'h';
else
flavor = 'o';
if ((dp = opendir(nodes.OutBox)) == NULL) {
Syslog('o', "\"%s\" cannot be opened, proceed", MBSE_SS(nodes.OutBox));
} else {
temp = calloc(PATH_MAX, sizeof(char));
pw = getpwnam((char *)"mbse");
while ((de = readdir(dp))) {
if (strcmp(de->d_name, ".") && strcmp(de->d_name, "..")) {
sprintf(temp, "%s/%s", nodes.OutBox, de->d_name);
if (stat(temp, &stbuf) == 0) {
Syslog('o' ,"checking file \"%s\"", de->d_name);
if (S_ISREG(stbuf.st_mode)) {
if (pw->pw_uid == stbuf.st_uid) {
/*
* We own the file
*/
if ((stbuf.st_mode & S_IRUSR) && (stbuf.st_mode & S_IWUSR)) {
add_list(&st, temp, de->d_name, KFS, 0L, NULL, 1);
} else {
Syslog('+', "No R/W permission on %s", temp);
}
} else if (pw->pw_gid == stbuf.st_gid) {
/*
* We own the file group
*/
if ((stbuf.st_mode & S_IRGRP) && (stbuf.st_mode & S_IWGRP)) {
add_list(&st, temp, de->d_name, KFS, 0L, NULL, 1);
} else {
Syslog('+', "No R/W permission on %s", temp);
}
} else {
/*
* No owner of file
*/
if ((stbuf.st_mode & S_IROTH) && (stbuf.st_mode & S_IWOTH)) {
add_list(&st, temp, de->d_name, KFS, 0L, NULL, 1);
} else {
Syslog('+', "No R/W permission on %s", temp);
}
}
} else {
Syslog('+', "Not a regular file %s", temp);
}
} else {
WriteError("Can't stat %s", temp);
}
}
}
closedir(dp);
free(temp);
}
}
if (((st == NULL) && (create > 1)) || ((st != NULL) && (packets == 0) && (create > 0))) {
Syslog('o', "Create packet for %s", ascfnode(al->addr,0x1f));
if ((fp = openpkt(NULL, al->addr, 'o'))) {
memset(&buffer, 0, sizeof(buffer));
fwrite(buffer, 1, 2, fp);
fclose(fp);
}
add_list(&st, pktname(al->addr,'o'), tmpkname(), KFS, 0L, NULL, 0);
/*
* Check spool files, these are more or less useless but they
* create a filelist of files to send which are never send.
* It gives the transfer protocols something "to do".
*/
if (strchr(fl, 'o')) {
nm = splname(tmpa->addr);
if ((fp = fopen(nm, "w")))
fclose(fp);
if ((nm != NULL) && (stat(nm, &stbuf) == 0))
add_list(&st, nm, NULL, DSF, 0L, NULL, 1);
}
for (tmpf = st; tmpf; tmpf = tmpf->next)
Syslog('O',"flist: \"%s\" -> \"%s\" dsp:%d flofp:%lu floff:%lu",
MBSE_SS(tmpf->local), MBSE_SS(tmpf->remote), tmpf->disposition,
(unsigned long)tmpf->flofp, (unsigned long)tmpf->floff);
/*
* Check .pol files
*/
nm = polname(tmpa->addr);
if ((nm != NULL) && (stat(nm,&stbuf) == 0))
add_list(&st,nm,NULL,DSF,0L,NULL,1);
return st;
/*
* Check other files, all flavors
*/
tmpfl = fl;
while ((flavor = *tmpfl++)) {
/*
* Check normal mail packets
*/
nm = pktname(tmpa->addr,flavor);
if ((nm != NULL) && (stat(nm,&stbuf) == 0)) {
packets++;
add_list(&st, nm, tmpkname(), KFS, 0L, NULL, 1);
}
/*
* Check .flo files for file attaches
*/
nm = floname(tmpa->addr,flavor);
check_flo(&st, nm);
}
if ((session_flags & SESSION_WAZOO) &&
((session_flags & SESSION_HYDRA) == 0) && (master || ((session_flags & SESSION_IFNA) == 0))) {
/*
* we don't distinguish flavoured reqs
*/
nm = reqname(tmpa->addr);
if ((nm != NULL) && (stat(nm, &stbuf) == 0)) {
sprintf(tmpreq, "%04X%04X.REQ", tmpa->addr->net, tmpa->addr->node);
add_list(&st, nm, tmpreq, DSF, 0L, NULL, 1);
made_request = 1;
}
}
}
if (((st == NULL) && (create > 1)) || ((st != NULL) && (packets == 0) && (create > 0))) {
Syslog('o', "Create packet for %s", ascfnode(al->addr,0x1f));
if ((fp = openpkt(NULL, al->addr, 'o'))) {
memset(&buffer, 0, sizeof(buffer));
fwrite(buffer, 1, 2, fp);
fclose(fp);
}
add_list(&st, pktname(al->addr,'o'), tmpkname(), KFS, 0L, NULL, 0);
}
for (tmpf = st; tmpf; tmpf = tmpf->next)
Syslog('o',"flist: \"%s\" -> \"%s\" dsp:%d flofp:%lu floff:%lu",
MBSE_SS(tmpf->local), MBSE_SS(tmpf->remote), tmpf->disposition,
(unsigned long)tmpf->flofp, (unsigned long)tmpf->floff);
return st;
}
@@ -320,157 +381,154 @@ file_list *create_filelist(fa_list *al, char *fl, int create)
*/
file_list *create_freqlist(fa_list *al)
{
file_list *st = NULL, *tmpf;
fa_list *tmpa;
char *nm;
char tmpreq[13];
struct stat stbuf;
file_list *st = NULL, *tmpf;
fa_list *tmpa;
char *nm, tmpreq[13];
struct stat stbuf;
Syslog('o', "create_freqlist(%s)", al?ascfnode(al->addr, 0x1f):"<none>");
made_request = 0;
Syslog('o', "create_freqlist(%s)", al?ascfnode(al->addr, 0x1f):"<none>");
made_request = 0;
for (tmpa = al; tmpa; tmpa = tmpa->next) {
nm = reqname(tmpa->addr);
if ((nm != NULL) && (stat(nm, &stbuf) == 0)) {
sprintf(tmpreq, "%04X%04X.REQ", tmpa->addr->net, tmpa->addr->node);
add_list(&st, nm, tmpreq, DSF, 0L, NULL, 1);
made_request = 1;
}
for (tmpa = al; tmpa; tmpa = tmpa->next) {
nm = reqname(tmpa->addr);
if ((nm != NULL) && (stat(nm, &stbuf) == 0)) {
sprintf(tmpreq, "%04X%04X.REQ", tmpa->addr->net, tmpa->addr->node);
add_list(&st, nm, tmpreq, DSF, 0L, NULL, 1);
made_request = 1;
}
}
if (made_request) {
for (tmpf = st; tmpf; tmpf = tmpf->next)
Syslog('O', "flist: \"%s\" -> \"%s\" dsp:%d flofp:%lu floff:%lu",
MBSE_SS(tmpf->local), MBSE_SS(tmpf->remote), tmpf->disposition,
tmpf->flofp, tmpf->floff);
Syslog('o', "flist: \"%s\" -> \"%s\" dsp:%d flofp:%lu floff:%lu",
MBSE_SS(tmpf->local), MBSE_SS(tmpf->remote), tmpf->disposition, tmpf->flofp, tmpf->floff);
}
return st;
return st;
}
void tidy_filelist(file_list *fl, int dsf)
{
file_list *tmp;
file_list *tmp;
if (fl == NULL)
return;
for (tmp=fl;fl;fl=tmp) {
tmp=fl->next;
if (dsf && (fl->disposition == DSF)) {
Syslog('o',"Removing sent file \"%s\"",MBSE_SS(fl->local));
if (unlink(fl->local) != 0) {
if (errno == ENOENT)
Syslog('o',"Cannot unlink nonexistent file \"%s\"", MBSE_SS(fl->local));
else
WriteError("$Cannot unlink file \"%s\"", MBSE_SS(fl->local));
}
}
if (fl->local)
free(fl->local);
if (fl->remote)
free(fl->remote);
else if (fl->flofp)
fclose(fl->flofp);
free(fl);
}
if (fl == NULL)
return;
for (tmp=fl;fl;fl=tmp) {
tmp=fl->next;
if (dsf && (fl->disposition == DSF)) {
Syslog('o',"Removing sent file \"%s\"",MBSE_SS(fl->local));
if (unlink(fl->local) != 0) {
if (errno == ENOENT)
Syslog('o',"Cannot unlink nonexistent file \"%s\"", MBSE_SS(fl->local));
else
WriteError("$Cannot unlink file \"%s\"", MBSE_SS(fl->local));
}
}
if (fl->local)
free(fl->local);
if (fl->remote)
free(fl->remote);
else if (fl->flofp)
fclose(fl->flofp);
free(fl);
}
return;
}
void execute_disposition(file_list *fl)
{
FILE *fp=NULL;
char *nm;
char tpl='~';
FILE *fp=NULL;
char *nm, tpl='~';
Syslog('o', "execute_disposition(%s)", fl->local);
nm = fl->local;
if (fl->flofp) {
/*
* Check for special case: flo-file
*/
if (fl->floff == -1) {
/*
* We check if there are any files left for transmission
* in the flo-file to decide whether to remove or leave
* it on disk.
*/
char buf[PATH_MAX];
int files_remain = 0;
Syslog('o', "execute_disposition(%s)", fl->local);
nm = fl->local;
if (fl->flofp) {
/*
* Check for special case: flo-file
*/
if (fl->floff == -1) {
/*
* We check if there are any files left for transmission
* in the flo-file to decide whether to remove or leave
* it on disk.
*/
char buf[PATH_MAX];
int files_remain = 0;
if (fseek(fl->flofp, 0L, 0) == 0) {
while (!feof(fl->flofp) && !ferror(fl->flofp)) {
if (fgets(buf, sizeof(buf)-1, fl->flofp) == NULL)
continue;
if (fseek(fl->flofp, 0L, 0) == 0) {
while (!feof(fl->flofp) && !ferror(fl->flofp)) {
if (fgets(buf, sizeof(buf)-1, fl->flofp) == NULL)
continue;
/*
* Count nr of files which haven't been
* sent yet
*/
if (buf[0] != '~')
files_remain++;
}
/*
* Count nr of files which haven't been sent yet
*/
if (buf[0] != '~')
files_remain++;
}
} else {
WriteError("$Error seeking in .flo to 0");
files_remain = -1; /* Keep flo-file */
}
} else {
WriteError("$Error seeking in .flo to 0");
files_remain = -1; /* Keep flo-file */
}
if (files_remain) {
Syslog('o', "Leaving flo-file \"%s\", %d files remaining", MBSE_SS(nm), files_remain);
fl->disposition = LEAVE;
} else {
fl->disposition = KFS;
}
} else {
/*
* Mark files as sent in flo-file
*/
if (fseek(fl->flofp, fl->floff, 0) == 0) {
if (fwrite(&tpl,1,1,fl->flofp) != 1) {
WriteError("$Error writing '~' to .flo at %lu", (unsigned long)fl->floff);
}
fflush(fl->flofp);
if (files_remain) {
Syslog('o', "Leaving flo-file \"%s\", %d files remaining", MBSE_SS(nm), files_remain);
fl->disposition = LEAVE;
} else {
fl->disposition = KFS;
}
} else {
/*
* Mark files as sent in flo-file
*/
if (fseek(fl->flofp, fl->floff, 0) == 0) {
if (fwrite(&tpl,1,1,fl->flofp) != 1) {
WriteError("$Error writing '~' to .flo at %lu", (unsigned long)fl->floff);
}
fflush(fl->flofp);
#ifdef HAVE_FDATASYNC
fdatasync(fileno(fl->flofp));
fdatasync(fileno(fl->flofp));
#else
#ifdef HAVE_FSYNC
fsync(fileno(fl->flofp));
fsync(fileno(fl->flofp));
#endif
#endif
} else
WriteError("$error seeking in .flo to %lu", (unsigned long)fl->floff);
}
} else
WriteError("$error seeking in .flo to %lu", (unsigned long)fl->floff);
}
}
switch (fl->disposition) {
switch (fl->disposition) {
case DSF:
case LEAVE:
break;
case TFS:
Syslog('o', "Truncating sent file \"%s\"",MBSE_SS(nm));
if ((fp=fopen(nm,"w")))
fclose(fp);
else
WriteError("$Cannot truncate file \"%s\"",MBSE_SS(nm));
break;
case KFS:
Syslog('o', "Removing sent file \"%s\"",MBSE_SS(nm));
if (unlink(nm) != 0) {
if (errno == ENOENT)
Syslog('o', "Cannot unlink nonexistent file \"%s\"", MBSE_SS(nm));
else
WriteError("$Cannot unlink file \"%s\"", MBSE_SS(nm));
}
break;
default: WriteError("execute_disposition: unknown disp %d for \"%s\"",
fl->disposition,MBSE_SS(nm));
break;
}
case LEAVE: break;
return;
case TFS: Syslog('o', "Truncating sent file \"%s\"",MBSE_SS(nm));
if ((fp=fopen(nm,"w")))
fclose(fp);
else
WriteError("$Cannot truncate file \"%s\"",MBSE_SS(nm));
break;
case KFS: Syslog('o', "Removing sent file \"%s\"",MBSE_SS(nm));
if (unlink(nm) != 0) {
if (errno == ENOENT)
Syslog('o', "Cannot unlink nonexistent file \"%s\"", MBSE_SS(nm));
else
WriteError("$Cannot unlink file \"%s\"", MBSE_SS(nm));
}
break;
default: WriteError("execute_disposition: unknown disp %d for \"%s\"", fl->disposition,MBSE_SS(nm));
break;
}
return;
}

View File

@@ -66,55 +66,138 @@ static struct _alist
int outstat()
{
int rc;
struct _alist *tmp, *old;
char flstr[6];
time_t age;
char temp[81];
callstat *cst;
int rc;
struct _alist *tmp, *old;
char flstr[6], *temp, flavor;
time_t age;
faddr *fa;
callstat *cst;
FILE *fp;
DIR *dp = NULL;
struct dirent *de;
struct stat sb;
struct passwd *pw;
if ((rc = scanout(each))) {
WriteError("Error scanning outbound, aborting");
return rc;
}
if ((rc = scanout(each))) {
WriteError("Error scanning outbound, aborting");
return rc;
}
if (!do_quiet) {
colour(10, 0);
printf("flavor try size age address\n");
colour(3, 0);
}
/*
* Check private outbound box for nodes in the setup.
*/
temp = calloc(PATH_MAX, sizeof(char));
sprintf(temp, "%s/etc/nodes.data", getenv("MBSE_ROOT"));
if ((fp = fopen(temp, "r")) == NULL) {
WriteError("Error open %s, aborting", temp);
free(temp);
return 1;
}
fread(&nodeshdr, sizeof(nodeshdr), 1, fp);
fseek(fp, 0, SEEK_SET);
fread(&nodeshdr, nodeshdr.hdrsize, 1, fp);
pw = getpwnam((char *)"mbse");
Syslog('+', "Flavor Try Size Age Address");
for (tmp = alist; tmp; tmp = tmp->next) {
if ((tmp->flavors & F_FREQ) || (tmp->size) || 1) {
strcpy(flstr,"......");
if ((tmp->flavors) & F_IMM ) flstr[0]='I';
if ((tmp->flavors) & F_CRASH ) flstr[1]='C';
if ((tmp->flavors) & F_NORMAL) flstr[2]='N';
if ((tmp->flavors) & F_HOLD ) flstr[3]='H';
if ((tmp->flavors) & F_FREQ ) flstr[4]='R';
if ((tmp->flavors) & F_POLL ) flstr[5]='P';
cst = getstatus(&(tmp->addr));
age = time(NULL);
age -= tmp->time;
sprintf(temp, "%s %3d %9lu %s %s", flstr, cst->tryno, (long)tmp->size,
str_time(age), ascfnode(&(tmp->addr), 0x1f));
if (!do_quiet)
printf("%s\n", temp);
Syslog('+', "%s", temp);
while ((fread(&nodes, nodeshdr.recsize, 1, fp)) == 1) {
if (strlen(nodes.OutBox)) {
if (nodes.Crash)
flavor = 'c';
else if (nodes.Hold)
flavor = 'h';
else
flavor = 'o';
fa = fido2faddr(nodes.Aka[0]);
Syslog('o', "checking outbox %s (%s)", nodes.OutBox, ascfnode(fa, 0x2f));
if ((dp = opendir(nodes.OutBox)) == NULL) {
Syslog('o', "\"%s\" cannot be opened, proceed", MBSE_SS(nodes.OutBox));
} else {
while ((de = readdir(dp))) {
if (strcmp(de->d_name, ".") && strcmp(de->d_name, "..")) {
sprintf(temp, "%s/%s", nodes.OutBox, de->d_name);
if (stat(temp, &sb) == 0) {
Syslog('o' ,"checking: \"%s\"", de->d_name);
if (S_ISREG(sb.st_mode)) {
if (pw->pw_uid == sb.st_uid) {
/*
* We own the file
*/
if ((sb.st_mode & S_IRUSR) && (sb.st_mode & S_IWUSR)) {
each(fa, flavor, 0, temp);
} else {
Syslog('o', "no R/W permission on %s", temp);
}
} else if (pw->pw_gid == sb.st_gid) {
/*
* We own the file group
*/
if ((sb.st_mode & S_IRGRP) && (sb.st_mode & S_IWGRP)) {
each(fa, flavor, 0, temp);
} else {
Syslog('o', "no R/W permission on %s", temp);
}
} else {
/*
* No owner of file
*/
if ((sb.st_mode & S_IROTH) && (sb.st_mode & S_IWOTH)) {
each(fa, flavor, 0, temp);
} else {
Syslog('o', "no R/W permission on %s", temp);
}
}
} else {
Syslog('o', "not a regular file");
}
} else {
WriteError("Can't stat %s", temp);
}
}
}
closedir(dp);
}
tidy_faddr(fa);
}
fseek(fp, nodeshdr.filegrp + nodeshdr.mailgrp, SEEK_CUR);
}
fclose(fp);
for (tmp = alist; tmp; tmp = old) {
old = tmp->next;
free(tmp->addr.domain);
free(tmp);
if (!do_quiet) {
colour(10, 0);
printf("flavor try size age address\n");
colour(3, 0);
}
Syslog('+', "Flavor Try Size Age Address");
for (tmp = alist; tmp; tmp = tmp->next) {
if ((tmp->flavors & F_FREQ) || (tmp->size) || 1) {
strcpy(flstr,"......");
if ((tmp->flavors) & F_IMM ) flstr[0]='I';
if ((tmp->flavors) & F_CRASH ) flstr[1]='C';
if ((tmp->flavors) & F_NORMAL) flstr[2]='N';
if ((tmp->flavors) & F_HOLD ) flstr[3]='H';
if ((tmp->flavors) & F_FREQ ) flstr[4]='R';
if ((tmp->flavors) & F_POLL ) flstr[5]='P';
cst = getstatus(&(tmp->addr));
age = time(NULL);
age -= tmp->time;
sprintf(temp, "%s %3d %9lu %s %s", flstr, cst->tryno, (long)tmp->size, str_time(age), ascfnode(&(tmp->addr), 0x1f));
if (!do_quiet)
printf("%s\n", temp);
Syslog('+', "%s", temp);
}
alist = NULL;
}
return 0;
free(temp);
for (tmp = alist; tmp; tmp = old) {
old = tmp->next;
free(tmp->addr.domain);
free(tmp);
}
alist = NULL;
return 0;
}
@@ -126,6 +209,8 @@ int each(faddr *addr, char flavor, int isflo, char *fname)
FILE *fp;
char buf[256], *p;
Syslog('o', "each(%s, %c, %s, %s)", ascfnode(addr, 0x2f), flavor, isflo?"isflo":"noflo", fname);
if ((isflo != OUT_PKT) && (isflo != OUT_FLO) && (isflo != OUT_REQ) && (isflo != OUT_POL))
return 0;

View File

@@ -57,121 +57,118 @@ extern time_t t_start;
static int scan_dir(int (*)(faddr*,char,int,char*),char*,int);
static int scan_dir(int (*fn)(faddr *, char, int, char *), char *dname, int ispoint)
{
char fname[PATH_MAX];
char flavor = '?';
DIR *dp = NULL;
struct dirent *de;
int rc = 0, isflo, fage;
char fname[PATH_MAX];
char flavor = '?';
DIR *dp = NULL;
struct dirent *de;
int rc = 0, isflo, fage;
Syslog('o' ,"scan_dir \"%s\" (%s)",MBSE_SS(dname),ispoint?"point":"node");
Syslog('o' ,"scan_dir \"%s\" (%s)",MBSE_SS(dname),ispoint?"point":"node");
if ((dp = opendir(dname)) == NULL) {
Syslog('-', "Creating directory %s", dname);
/*
* Create a fake filename, mkdirs() likes that.
*/
sprintf(fname, "%s/foo", dname);
(void)mkdirs(fname, 0770);
if ((dp = opendir(dname)) == NULL) {
Syslog('-', "Creating directory %s", dname);
/*
* Create a fake filename, mkdirs() likes that.
*/
sprintf(fname, "%s/foo", dname);
(void)mkdirs(fname, 0770);
if ((dp = opendir(dname)) == NULL) {
Syslog('o' ,"\"%s\" cannot be opened, proceed",MBSE_SS(dname));
return 0;
}
Syslog('o' ,"\"%s\" cannot be opened, proceed",MBSE_SS(dname));
return 0;
}
}
while ((de=readdir(dp)))
if ((strlen(de->d_name) == 12) && (de->d_name[8] == '.') &&
(strspn(de->d_name,"0123456789abcdefABCDEF") == 8)) {
Syslog('o' ,"checking: \"%s\"",de->d_name);
addr.point= 0;
strncpy(fname,dname,PATH_MAX-2);
strcat(fname,"/");
strncat(fname,de->d_name,PATH_MAX-strlen(fname)-2);
while ((de=readdir(dp)))
if ((strlen(de->d_name) == 12) && (de->d_name[8] == '.') && (strspn(de->d_name,"0123456789abcdefABCDEF") == 8)) {
Syslog('o' ,"checking: \"%s\"",de->d_name);
addr.point= 0;
strncpy(fname,dname,PATH_MAX-2);
strcat(fname,"/");
strncat(fname,de->d_name,PATH_MAX-strlen(fname)-2);
if ((strcasecmp(de->d_name+9,"pnt") == 0) && !ispoint) {
if ((strcasecmp(de->d_name+9,"pnt") == 0) && !ispoint) {
sscanf(de->d_name,"%04x%04x",&addr.net,&addr.node);
if ((rc = scan_dir(fn, fname, 1)))
goto exout;
} else if ((strcasecmp(de->d_name+8,".out") == 0) ||
(strcasecmp(de->d_name+8,".cut") == 0) ||
(strcasecmp(de->d_name+8,".hut") == 0) ||
(strcasecmp(de->d_name+8,".iut") == 0) ||
(strcasecmp(de->d_name+8,".opk") == 0) ||
(strcasecmp(de->d_name+8,".cpk") == 0) ||
(strcasecmp(de->d_name+8,".hpk") == 0) ||
(strcasecmp(de->d_name+8,".ipk") == 0) ||
(strcasecmp(de->d_name+8,".flo") == 0) ||
(strcasecmp(de->d_name+8,".clo") == 0) ||
(strcasecmp(de->d_name+8,".hlo") == 0) ||
(strcasecmp(de->d_name+8,".ilo") == 0) ||
(strcasecmp(de->d_name+8,".req") == 0) ||
(strcasecmp(de->d_name+8,".pol") == 0)) {
if (ispoint)
sscanf(de->d_name,"%08x", &addr.point);
else
sscanf(de->d_name,"%04x%04x", &addr.net,&addr.node);
flavor = tolower(de->d_name[9]);
if (flavor == 'f')
flavor='o';
if (strcasecmp(de->d_name+10,"ut") == 0)
isflo=OUT_PKT;
else if (strcasecmp(de->d_name+10,"pk") == 0)
isflo=OUT_DIR;
else if (strcasecmp(de->d_name+10,"lo") == 0)
isflo=OUT_FLO;
else if (strcasecmp(de->d_name+9,"req") == 0)
isflo=OUT_REQ;
else if (strcasecmp(de->d_name+9,"pol") == 0)
isflo=OUT_POL;
else
isflo=-1;
Syslog('o' ,"%s \"%s\"",
(isflo == OUT_FLO) ? "flo file" : "packet",
de->d_name);
if ((rc=fn(&addr,flavor,isflo,fname)))
goto exout;
} else if ((strncasecmp(de->d_name+9,"su",2) == 0) ||
(strncasecmp(de->d_name+9,"mo",2) == 0) ||
(strncasecmp(de->d_name+9,"tu",2) == 0) ||
(strncasecmp(de->d_name+9,"we",2) == 0) ||
(strncasecmp(de->d_name+9,"th",2) == 0) ||
(strncasecmp(de->d_name+9,"fr",2) == 0) ||
(strncasecmp(de->d_name+9,"sa",2) == 0)) {
isflo = OUT_ARC;
if ((rc = fn(&addr, flavor, isflo, fname)))
goto exout;
} else if ((strcasecmp(de->d_name+8,".out") == 0) ||
(strcasecmp(de->d_name+8,".cut") == 0) ||
(strcasecmp(de->d_name+8,".hut") == 0) ||
(strcasecmp(de->d_name+8,".iut") == 0) ||
(strcasecmp(de->d_name+8,".opk") == 0) ||
(strcasecmp(de->d_name+8,".cpk") == 0) ||
(strcasecmp(de->d_name+8,".hpk") == 0) ||
(strcasecmp(de->d_name+8,".ipk") == 0) ||
(strcasecmp(de->d_name+8,".flo") == 0) ||
(strcasecmp(de->d_name+8,".clo") == 0) ||
(strcasecmp(de->d_name+8,".hlo") == 0) ||
(strcasecmp(de->d_name+8,".ilo") == 0) ||
(strcasecmp(de->d_name+8,".req") == 0) ||
(strcasecmp(de->d_name+8,".pol") == 0)) {
if (ispoint)
sscanf(de->d_name,"%08x", &addr.point);
else
sscanf(de->d_name,"%04x%04x", &addr.net,&addr.node);
flavor = tolower(de->d_name[9]);
if (flavor == 'f')
flavor='o';
if (strcasecmp(de->d_name+10,"ut") == 0)
isflo=OUT_PKT;
else if (strcasecmp(de->d_name+10,"pk") == 0)
isflo=OUT_DIR;
else if (strcasecmp(de->d_name+10,"lo") == 0)
isflo=OUT_FLO;
else if (strcasecmp(de->d_name+9,"req") == 0)
isflo=OUT_REQ;
else if (strcasecmp(de->d_name+9,"pol") == 0)
isflo=OUT_POL;
else
isflo=-1;
Syslog('o' ,"%s \"%s\"", (isflo == OUT_FLO) ? "flo file" : "packet", de->d_name);
if ((rc=fn(&addr,flavor,isflo,fname)))
goto exout;
} else if ((strncasecmp(de->d_name+9,"su",2) == 0) ||
(strncasecmp(de->d_name+9,"mo",2) == 0) ||
(strncasecmp(de->d_name+9,"tu",2) == 0) ||
(strncasecmp(de->d_name+9,"we",2) == 0) ||
(strncasecmp(de->d_name+9,"th",2) == 0) ||
(strncasecmp(de->d_name+9,"fr",2) == 0) ||
(strncasecmp(de->d_name+9,"sa",2) == 0)) {
isflo = OUT_ARC;
if ((rc = fn(&addr, flavor, isflo, fname)))
goto exout;
Syslog('o' ,"arcmail file \"%s\"",de->d_name);
sprintf(fname, "%s/%s", dname, de->d_name);
fage = (int)((t_start - file_time(fname)) / 86400);
Syslog('o' ,"arcmail file \"%s\"",de->d_name);
sprintf(fname, "%s/%s", dname, de->d_name);
fage = (int)((t_start - file_time(fname)) / 86400);
if (file_size(fname) == 0) {
Syslog('o', "Age %d days", fage);
/*
* Remove truncated ARCmail that has a day extension
* other then the current day or if the file is older
* then 6 days.
*/
if ((strncasecmp(de->d_name+9, dayname(), 2)) || (fage > 6)) {
if (unlink(fname) == 0)
Syslog('-', "Removed truncated ARCmail file %s", fname);
}
}
if (CFG.toss_days && (fage > CFG.toss_days)) {
/*
* Remove ARCmail that is on hold too long.
*/
if (unlink(fname) == 0)
Syslog('+', "Removed ARCmail %s, %d days", fname, fage);
}
} else {
Syslog('o' ,"skipping \"%s\"",de->d_name);
if (file_size(fname) == 0) {
Syslog('o', "Age %d days", fage);
/*
* Remove truncated ARCmail that has a day extension
* other then the current day or if the file is older
* then 6 days.
*/
if ((strncasecmp(de->d_name+9, dayname(), 2)) || (fage > 6)) {
if (unlink(fname) == 0)
Syslog('+', "Removed truncated ARCmail file %s", fname);
}
}
if (CFG.toss_days && (fage > CFG.toss_days)) {
/*
* Remove ARCmail that is on hold too long.
*/
if (unlink(fname) == 0)
Syslog('+', "Removed ARCmail %s, %d days", fname, fage);
}
} else {
Syslog('o' ,"skipping \"%s\"",de->d_name);
}
}
exout:
closedir(dp);
return rc;
closedir(dp);
return rc;
}