Added POST to mbnntpd, experimental

This commit is contained in:
Michiel Broek 2004-05-10 19:52:41 +00:00
parent 1136b45378
commit eb08dc97f7
8 changed files with 124 additions and 47 deletions

View File

@ -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.

View File

@ -9,8 +9,8 @@
+-----------+ +-----------+ | | | email/UUCP +--+ |
| stdin | | +---------+ +-------------+ | v
| pipe +-----------------------+------------------+ rfc2ftn | | | |
| rnews | | | +------+ | +----> mailer outbound
+-----------+ | +-----------+ | v |
| rnews | | | +------+ | +----> mailer
+-----------+ | +-----------+ | v | outbound
RFC | | | ^
+-----------+ format | | +-------------+ | |
| scan news | | | | +---------------+

View File

@ -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,14 +381,58 @@ 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");
@ -396,7 +443,19 @@ void command_post(char *cmd)
send_nntp("340 Send article to be posted. End with <CR-LF>.<CR-LF>");
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)
}
}
/*
* 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");
}

View File

@ -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) {

View File

@ -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.
*/

View File

@ -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);

View File

@ -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();
}
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);
}
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,12 +102,10 @@ 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);
Msg_Write(fp);
Msg_AddMsg();

View File

@ -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