From eb08dc97f7850541f728462feb6908c931d16fbd Mon Sep 17 00:00:00 2001 From: Michiel Broek Date: Mon, 10 May 2004 19:52:41 +0000 Subject: [PATCH] Added POST to mbnntpd, experimental --- ChangeLog | 2 +- mbfido/README | 4 +- mbnntp/commands.c | 114 ++++++++++++++++++++++++++++++++++++++++++--- mbnntp/mbnntp.c | 3 +- mbnntp/postecho.c | 2 +- mbnntp/rfc2ftn.c | 2 +- mbnntp/storeecho.c | 42 ++++------------- mbnntp/storeecho.h | 2 +- 8 files changed, 124 insertions(+), 47 deletions(-) diff --git a/ChangeLog b/ChangeLog index 73a5682f..e26b962c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -62,7 +62,7 @@ v0.51.4 11-Apr-2004 mbnntp: New program, news server to read echomail with a news client. - Reading news works, no posts yet. + Reading news works, posts partial tested. mbsebbs: Added logging of virus scanner results. diff --git a/mbfido/README b/mbfido/README index f2d9568f..101235c2 100644 --- a/mbfido/README +++ b/mbfido/README @@ -9,8 +9,8 @@ +-----------+ +-----------+ | | | email/UUCP +--+ | | stdin | | +---------+ +-------------+ | v | pipe +-----------------------+------------------+ rfc2ftn | | | | - | rnews | | | +------+ | +----> mailer outbound - +-----------+ | +-----------+ | v | + | rnews | | | +------+ | +----> mailer + +-----------+ | +-----------+ | v | outbound RFC | | | ^ +-----------+ format | | +-------------+ | | | scan news | | | | +---------------+ diff --git a/mbnntp/commands.c b/mbnntp/commands.c index 4b576414..777675aa 100644 --- a/mbnntp/commands.c +++ b/mbnntp/commands.c @@ -32,6 +32,7 @@ #include "../lib/users.h" #include "../lib/msg.h" #include "../lib/msgtext.h" +#include "../lib/mbsedb.h" #include "ttyio.h" #include "mbnntp.h" #include "rfc2ftn.h" @@ -43,7 +44,9 @@ unsigned long article = 0L; /* Current article */ char currentgroup[81]; /* Current newsgroup */ extern unsigned long sentbytes; +extern unsigned long rcvdbytes; +extern char *ttystat[]; void send_xlat(char *); char *make_msgid(char *); @@ -378,15 +381,59 @@ void command_list(char *cmd) +/* + * POST + */ +int get_post(char *buf, int max) +{ + int c, len; + + len = 0; + memset(buf, 0, sizeof(buf)); + while (TRUE) { + c = tty_getc(180); + if (c <= 0) { + if (c == -2) { + /* + * Timeout + */ + send_nntp("400 Service discontinued, timeout"); + } + Syslog('+', "Receiver status %s", ttystat[- c]); + return c; + } + if (c != '\n') { + buf[len] = c; + len++; + buf[len] = '\0'; + if (c == '\r') { + rcvdbytes += len; + return len; + } + } + if (len >= max) { + WriteError("Input buffer full"); + return len; + } + } + + return 0; /* Not reached */ +} + + + /* * POST */ void command_post(char *cmd) { FILE *fp = NULL; - int rc, Done = FALSE; - char buf[1024]; + int i, rc, maxrc, Done = FALSE, nrofgroups; + char buf[1024], *group, *groups[25]; + IsDoing("Post"); + Syslog('+', "%s", cmd); + if ((fp = tmpfile()) == NULL) { WriteError("$Can't create tmpfile"); send_nntp("503 Out of memory"); @@ -396,7 +443,19 @@ void command_post(char *cmd) send_nntp("340 Send article to be posted. End with ."); while (Done == FALSE) { - rc = get_nntp(buf, sizeof(buf) -1); + rc = get_post(buf, sizeof(buf) -1); + /* + * Strip CR/LF + */ + if (buf[strlen(buf)-1] == '\n') { + buf[strlen(buf)-1] = '\0'; + rc--; + } + if (buf[strlen(buf)-1] == '\r') { + buf[strlen(buf)-1] = '\0'; + rc--; + } + Syslog('n', "%02d \"%s\"", rc, printable(buf, 0)); if (rc < 0) { WriteError("nntp_get failed, abort"); return; @@ -409,13 +468,54 @@ void command_post(char *cmd) } } - rc = rfc2ftn(fp); + /* + * Make a list of newsgroups to post in + */ + rewind(fp); + nrofgroups = 0; + while (fgets(buf, sizeof(buf) -1, fp)) { + if (!strncasecmp(buf, "Newsgroups: ", 12)) { + if (buf[strlen(buf)-1] == '\n') + buf[strlen(buf)-1] = '\0'; + if (buf[strlen(buf)-1] == '\r') + buf[strlen(buf)-1] = '\0'; + strtok(buf, " \0"); + while ((group = strtok(NULL, ",\0"))) { + Syslog('f', "group: \"%s\"", printable(group, 0)); + if (SearchMsgsNews(group)) { + Syslog('n', "Add group \"%s\" (%s)", msgs.Newsgroup, msgs.Tag); + groups[nrofgroups] = xstrcpy(group); + nrofgroups++; + } else { + Syslog('+', "Newsgroup \"%s\" doesn't exist", group); + } + } + } + } + + if (nrofgroups == 0) { + Syslog('+', "No newsgroups found for POST"); + send_nntp("441 Posting failed"); + fclose(fp); + return; + } + + maxrc = 0; + for (i = 0; i < nrofgroups; i++) { + Syslog('+', "Posting in newsgroup %s", groups[i]); + if (SearchMsgsNews(groups[i])) { + rc = rfc2ftn(fp); + if (rc > maxrc) + maxrc = rc; + } + free(groups[i]); + } fclose(fp); - if (rc) - send_nntp("503 Post failed:"); + if (maxrc) + send_nntp("441 Posting failed"); else - send_nntp("240 Article posted"); + send_nntp("240 Article posted OK"); } diff --git a/mbnntp/mbnntp.c b/mbnntp/mbnntp.c index 39b909e1..ca884364 100644 --- a/mbnntp/mbnntp.c +++ b/mbnntp/mbnntp.c @@ -121,6 +121,7 @@ int main(int argc, char *argv[]) InitMsgs(); InitUser(); InitFidonet(); + InitNode(); umask(002); memset(&usrconfig, 0, sizeof(usrconfig)); @@ -276,7 +277,7 @@ void nntp(void) } else if (strncasecmp(buf, "HEAD", 4) == 0) { if (check_auth(buf)) command_abhs(buf); - } else if (strncasecmp(buf, "HEAD", 4) == 0) { + } else if (strncasecmp(buf, "POST", 4) == 0) { if (check_auth(buf)) command_post(buf); } else if (strncasecmp(buf, "IHAVE", 5) == 0) { diff --git a/mbnntp/postecho.c b/mbnntp/postecho.c index a991d34c..061a6f71 100644 --- a/mbnntp/postecho.c +++ b/mbnntp/postecho.c @@ -422,7 +422,7 @@ int postecho(faddr *p_from, faddr *f, faddr *t, char *orig, char *subj, time_t m /* * Import this echomail, even if it's bad or a dupe. */ - if ((rc = storeecho(f, t, mdate, flags, subj, msgid, reply, bad, dupe, nfp)) || bad || dupe) { + if ((rc = storeecho(f, t, mdate, flags, subj, msgid, reply, nfp)) || bad || dupe) { /* * Store failed or it was bad or a dupe. Only log failed store. */ diff --git a/mbnntp/rfc2ftn.c b/mbnntp/rfc2ftn.c index f93833b7..d9ab8a5a 100644 --- a/mbnntp/rfc2ftn.c +++ b/mbnntp/rfc2ftn.c @@ -383,7 +383,7 @@ int rfc2ftn(FILE *fp) } if (!(hdr((char *)"X-FTN-Tearline", msg)) && !(hdr((char *)"X-FTN-TID", msg))) { - sprintf(temp, " MBSE-FIDO %s (%s-%s)", VERSION, OsName(), OsCPU()); + sprintf(temp, " MBSE-NNTPD %s (%s-%s)", VERSION, OsName(), OsCPU()); hdrsize += 4 + strlen(temp); fprintf(ofp, "\1TID:"); kludgewrite(temp, ofp); diff --git a/mbnntp/storeecho.c b/mbnntp/storeecho.c index 7c15ae53..da00c40a 100644 --- a/mbnntp/storeecho.c +++ b/mbnntp/storeecho.c @@ -46,7 +46,7 @@ * 1 - Can't access messagebase. * */ -int storeecho(faddr *f, faddr *t, time_t mdate, int flags, char *subj, char *msgid, char *reply, int bad, int dupe, FILE *fp) +int storeecho(faddr *f, faddr *t, time_t mdate, int flags, char *subj, char *msgid, char *reply, FILE *fp) { int result; unsigned long crc2; @@ -55,33 +55,13 @@ int storeecho(faddr *f, faddr *t, time_t mdate, int flags, char *subj, char *msg /* * Update import counters */ - if (!bad && !dupe) { - StatAdd(&msgs.Received, 1L); - msgs.LastRcvd = time(NULL); - StatAdd(&mgroup.MsgsRcvd, 1L); - mgroup.LastDate = time(NULL); - UpdateMsgs(); - } + StatAdd(&msgs.Received, 1L); + msgs.LastRcvd = time(NULL); + StatAdd(&mgroup.MsgsRcvd, 1L); + mgroup.LastDate = time(NULL); + UpdateMsgs(); - if (bad) { - if (strlen(CFG.badboard) == 0) { - Syslog('+', "Killing bad message"); - return 0; - } else { - if ((result = Msg_Open(CFG.badboard))) - Syslog('+', "Tossing in bad board"); - } - } else if (dupe) { - if (strlen(CFG.dupboard) == 0) { - Syslog('+', "Killing dupe message"); - return 0; - } else { - if ((result = Msg_Open(CFG.dupboard))) - Syslog('+', "Tossing in dupe board"); - } - } else { - result = Msg_Open(msgs.Base); - } + result = Msg_Open(msgs.Base); if (!result) { WriteError("Can't open JAMmb %s", msgs.Base); @@ -107,8 +87,6 @@ int storeecho(faddr *f, faddr *t, time_t mdate, int flags, char *subj, char *msg */ if ((flags & M_PVT) && ((msgs.MsgKinds == BOTH) || (msgs.MsgKinds == PRIVATE))) Msg.Private = TRUE; - if (flags & M_FILE) - Msg.FileAttach = TRUE; /* * Set MSGID and REPLY crc. @@ -124,13 +102,11 @@ int storeecho(faddr *f, faddr *t, time_t mdate, int flags, char *subj, char *msg /* * Start write the message - * If not a bad or dupe message, eat the first - * line (AREA:tag). + * Eat the first line (AREA:tag). */ buf = calloc(MAX_LINE_LENGTH +1, sizeof(char)); rewind(fp); - if (!dupe && !bad) - fgets(buf , MAX_LINE_LENGTH, fp); + fgets(buf , MAX_LINE_LENGTH, fp); Msg_Write(fp); Msg_AddMsg(); Msg_UnLock(); diff --git a/mbnntp/storeecho.h b/mbnntp/storeecho.h index 864ef69b..0184fa81 100644 --- a/mbnntp/storeecho.h +++ b/mbnntp/storeecho.h @@ -3,7 +3,7 @@ /* $Id$ */ -int storeecho(faddr *, faddr *, time_t, int, char *, char *, char *, int, int, FILE *); +int storeecho(faddr *, faddr *, time_t, int, char *, char *, char *, FILE *); #endif