From 9c5300b9b64c475143cbaaad10b04dae64c90f9c Mon Sep 17 00:00:00 2001 From: Michiel Broek Date: Sat, 19 Oct 2002 11:43:45 +0000 Subject: [PATCH] Bad netmail goes into the badmail area --- ChangeLog | 2 + TODO | 4 + mbfido/storenet.c | 226 +++++++++++++++++++++++++--------------------- 3 files changed, 127 insertions(+), 105 deletions(-) diff --git a/ChangeLog b/ChangeLog index 546a9381..992bbb49 100644 --- a/ChangeLog +++ b/ChangeLog @@ -33,6 +33,8 @@ v0.35.04 29-Sep-2002 Removed some debug logging with files replace. Fixed trashing news dupes file when mbfido was called multiple times. Improved program locking. + Netmail received for a zone/net without netmail board will be + stored in the badmail area. mbsetup: Added setup for the nodes record for security flags. diff --git a/TODO b/TODO index f67d2bb0..827557f1 100644 --- a/TODO +++ b/TODO @@ -81,6 +81,10 @@ mbfido: L: Add netmail notification of changed areas. + L: Maybe store insecure echomail in badmail area. + + L: Maybe store echomail for unknown areas in badmail area. + mbcico: L: Implement modem connect response translation for ISDN lines, i.e. make the CAUSE responses human readable. see McMail for this diff --git a/mbfido/storenet.c b/mbfido/storenet.c index 7bc3146f..85dc1403 100644 --- a/mbfido/storenet.c +++ b/mbfido/storenet.c @@ -64,114 +64,130 @@ extern int net_bad; /* Bad netmails (tracking errors */ */ int storenet(faddr *f, faddr *t, time_t mdate, int flags, char *Subj, char *msgid, char *reply, FILE *fp, char *flagstr) { - int result, i, empty = TRUE; - unsigned long crc2; - char *Buf; + int result = FALSE, i, empty = TRUE, bad; + unsigned long crc2; + char *Buf; - if (SearchNetBoard(t->zone, t->net)) { - StatAdd(&msgs.Received, 1L); - msgs.LastRcvd = time(NULL); - UpdateMsgs(); - - result = Msg_Open(msgs.Base); - if (!result) { - WriteError("Can't open msgbase %s", msgs.Base); - net_bad++; - return 1; - } - - if (Msg_Lock(30L)) { - Msg_New(); - Syslog('m', "Flagfield 0x%04x", flags); - strcpy(Msg.From, f->name); - strcpy(Msg.To, usr.sUserName); - strcpy(Msg.FromAddress, ascfnode(f,0x1f)); - strcpy(Msg.ToAddress, ascfnode(t,0x1f)); - strcpy(Msg.Subject, Subj); - Msg.Written = mdate; - Msg.Arrived = time(NULL) - (gmt_offset((time_t)0) * 60); - Msg.Netmail = TRUE; - - /* - * Set flags for the message base. - */ - if ((msgs.MsgKinds == BOTH) || (msgs.MsgKinds == PRIVATE)) - Msg.Private = (((flags & M_PVT) ? TRUE:FALSE) || flag_on((char *)"PVT", flagstr)); - else - Msg.Private = TRUE; /* Allways */ - Msg.Crash = ((flags & M_CRASH) || flag_on((char *)"CRA", flagstr)); - Msg.FileAttach = ((flags & M_FILE) || flag_on((char *)"FIL", flagstr)); - Msg.Intransit = ((flags & M_TRANSIT)); - Msg.FileRequest = ((flags & M_REQ) || flag_on((char *)"FRQ", flagstr)); - Msg.ReceiptRequest = ((flags & M_RRQ) || flag_on((char *)"RRQ", flagstr)); - Msg.Immediate = flag_on((char *)"IMM", flagstr); - Msg.Direct = flag_on((char *)"DIR", flagstr); - Msg.Gate = flag_on((char *)"ZON", flagstr); - Msg.ConfirmRequest = ((flags & M_AUDIT) || flag_on((char *)"CFM", flagstr)); - Msg.Orphan = ((flags & M_ORPHAN)); - - if (Msg.ReceiptRequest) { - Syslog('+', "Netmail has ReceiptRequest flag, no message created"); - } - - /* - * Set MSGID and REPLY crc. - */ - if (msgid != NULL) { - crc2 = -1; - Msg.MsgIdCRC = upd_crc32(msgid, crc2, strlen(msgid)); - } - if (reply != NULL) { - crc2 = -1; - Msg.ReplyCRC = upd_crc32(reply, crc2, strlen(reply)); - } - - /* - * Check if this is an empty netmail - */ - rewind(fp); - Buf = calloc(2049, sizeof(char)); - while ((fgets(Buf, 2048, fp)) != NULL) { - - for (i = 0; i < strlen(Buf); i++) { - if (*(Buf + i) == '\0') - break; - if (*(Buf + i) == '\n') - *(Buf + i) = '\0'; - if (*(Buf + i) == '\r') - *(Buf + i) = '\0'; - } - if (*(Buf) != '\0') { - if ((*(Buf) != '\001') && - (strcmp(Buf, (char *)"--- "))) - empty = FALSE; - } - } - free(Buf); - - if (!empty) { - Syslog('+', "Import netmail to %s", usr.sUserName); - rewind(fp); - Msg_Write(fp); - Msg_AddMsg(); - net_imp++; - } else { - Syslog('+', "Empty netmail for %s dropped", usr.sUserName); - } - Msg_UnLock(); - Msg_Close(); - - return 0; - } else { - WriteError("Can't lock msgbase %s", msgs.Base); - Msg_Close(); - return 1; - } + if (! SearchNetBoard(t->zone, t->net)) { + bad = TRUE; + WriteError("Can't find netmail board for %d:%d/%d", t->zone, t->net, t->node); + if (strlen(CFG.badboard) == 0) { + Syslog('+', "Killing bad message, no badmail area"); + net_bad++; + return 2; } else { - WriteError("Can't find a netmail board"); + if ((result = Msg_Open(CFG.badboard))) + Syslog('+', "Tossing in bad board"); + } + } else { + bad = FALSE; + StatAdd(&msgs.Received, 1L); + msgs.LastRcvd = time(NULL); + UpdateMsgs(); + result = Msg_Open(msgs.Base); + } + + if (!result) { + WriteError("Can't open msgbase %s", msgs.Base); + net_bad++; + return 1; + } + + if (Msg_Lock(30L)) { + Msg_New(); + Syslog('m', "Flagfield 0x%04x", flags); + strcpy(Msg.From, f->name); + strcpy(Msg.To, usr.sUserName); + strcpy(Msg.FromAddress, ascfnode(f,0x1f)); + strcpy(Msg.ToAddress, ascfnode(t,0x1f)); + strcpy(Msg.Subject, Subj); + Msg.Written = mdate; + Msg.Arrived = time(NULL) - (gmt_offset((time_t)0) * 60); + Msg.Netmail = TRUE; + + /* + * Set flags for the message base. + */ + if (bad) { + Msg.Private = (((flags & M_PVT) ? TRUE:FALSE) || flag_on((char *)"PVT", flagstr)); + } else if ((msgs.MsgKinds == BOTH) || (msgs.MsgKinds == PRIVATE)) { + Msg.Private = (((flags & M_PVT) ? TRUE:FALSE) || flag_on((char *)"PVT", flagstr)); + } else { + Msg.Private = TRUE; /* Allways */ + } + Msg.Crash = ((flags & M_CRASH) || flag_on((char *)"CRA", flagstr)); + Msg.FileAttach = ((flags & M_FILE) || flag_on((char *)"FIL", flagstr)); + Msg.Intransit = ((flags & M_TRANSIT)); + Msg.FileRequest = ((flags & M_REQ) || flag_on((char *)"FRQ", flagstr)); + Msg.ReceiptRequest = ((flags & M_RRQ) || flag_on((char *)"RRQ", flagstr)); + Msg.Immediate = flag_on((char *)"IMM", flagstr); + Msg.Direct = flag_on((char *)"DIR", flagstr); + Msg.Gate = flag_on((char *)"ZON", flagstr); + Msg.ConfirmRequest = ((flags & M_AUDIT) || flag_on((char *)"CFM", flagstr)); + Msg.Orphan = ((flags & M_ORPHAN)); + + if (Msg.ReceiptRequest) { + Syslog('+', "Netmail has ReceiptRequest flag, no message created"); + } + + /* + * Set MSGID and REPLY crc. + */ + if (msgid != NULL) { + crc2 = -1; + Msg.MsgIdCRC = upd_crc32(msgid, crc2, strlen(msgid)); + } + if (reply != NULL) { + crc2 = -1; + Msg.ReplyCRC = upd_crc32(reply, crc2, strlen(reply)); + } + + /* + * Check if this is an empty netmail + */ + rewind(fp); + Buf = calloc(2049, sizeof(char)); + while ((fgets(Buf, 2048, fp)) != NULL) { + + for (i = 0; i < strlen(Buf); i++) { + if (*(Buf + i) == '\0') + break; + if (*(Buf + i) == '\n') + *(Buf + i) = '\0'; + if (*(Buf + i) == '\r') + *(Buf + i) = '\0'; + } + if (*(Buf) != '\0') { + if ((*(Buf) != '\001') && (strcmp(Buf, (char *)"--- "))) + empty = FALSE; + } + } + free(Buf); + + if (!empty) { + if (bad) + Syslog('+', "Import netmail to %s in badmail board", usr.sUserName); + else + Syslog('+', "Import netmail to %s", usr.sUserName); + rewind(fp); + Msg_Write(fp); + Msg_AddMsg(); + if (bad) net_bad++; - return 2; - } /* if SearchNetBoard() */ + else + net_imp++; + } else { + Syslog('+', "Empty netmail for %s dropped", usr.sUserName); + } + Msg_UnLock(); + Msg_Close(); + + return 0; + } else { + WriteError("Can't lock msgbase %s, netmail is lost", msgs.Base); + Msg_Close(); + return 1; + } }