Added POST to mbnntpd, experimental
This commit is contained in:
parent
1136b45378
commit
eb08dc97f7
@ -62,7 +62,7 @@ v0.51.4 11-Apr-2004
|
|||||||
|
|
||||||
mbnntp:
|
mbnntp:
|
||||||
New program, news server to read echomail with a news client.
|
New program, news server to read echomail with a news client.
|
||||||
Reading news works, no posts yet.
|
Reading news works, posts partial tested.
|
||||||
|
|
||||||
mbsebbs:
|
mbsebbs:
|
||||||
Added logging of virus scanner results.
|
Added logging of virus scanner results.
|
||||||
|
@ -9,8 +9,8 @@
|
|||||||
+-----------+ +-----------+ | | | email/UUCP +--+ |
|
+-----------+ +-----------+ | | | email/UUCP +--+ |
|
||||||
| stdin | | +---------+ +-------------+ | v
|
| stdin | | +---------+ +-------------+ | v
|
||||||
| pipe +-----------------------+------------------+ rfc2ftn | | | |
|
| pipe +-----------------------+------------------+ rfc2ftn | | | |
|
||||||
| rnews | | | +------+ | +----> mailer outbound
|
| rnews | | | +------+ | +----> mailer
|
||||||
+-----------+ | +-----------+ | v |
|
+-----------+ | +-----------+ | v | outbound
|
||||||
RFC | | | ^
|
RFC | | | ^
|
||||||
+-----------+ format | | +-------------+ | |
|
+-----------+ format | | +-------------+ | |
|
||||||
| scan news | | | | +---------------+
|
| scan news | | | | +---------------+
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
#include "../lib/users.h"
|
#include "../lib/users.h"
|
||||||
#include "../lib/msg.h"
|
#include "../lib/msg.h"
|
||||||
#include "../lib/msgtext.h"
|
#include "../lib/msgtext.h"
|
||||||
|
#include "../lib/mbsedb.h"
|
||||||
#include "ttyio.h"
|
#include "ttyio.h"
|
||||||
#include "mbnntp.h"
|
#include "mbnntp.h"
|
||||||
#include "rfc2ftn.h"
|
#include "rfc2ftn.h"
|
||||||
@ -43,7 +44,9 @@ unsigned long article = 0L; /* Current article */
|
|||||||
char currentgroup[81]; /* Current newsgroup */
|
char currentgroup[81]; /* Current newsgroup */
|
||||||
|
|
||||||
extern unsigned long sentbytes;
|
extern unsigned long sentbytes;
|
||||||
|
extern unsigned long rcvdbytes;
|
||||||
|
|
||||||
|
extern char *ttystat[];
|
||||||
|
|
||||||
void send_xlat(char *);
|
void send_xlat(char *);
|
||||||
char *make_msgid(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
|
* POST
|
||||||
*/
|
*/
|
||||||
void command_post(char *cmd)
|
void command_post(char *cmd)
|
||||||
{
|
{
|
||||||
FILE *fp = NULL;
|
FILE *fp = NULL;
|
||||||
int rc, Done = FALSE;
|
int i, rc, maxrc, Done = FALSE, nrofgroups;
|
||||||
char buf[1024];
|
char buf[1024], *group, *groups[25];
|
||||||
|
|
||||||
|
IsDoing("Post");
|
||||||
|
Syslog('+', "%s", cmd);
|
||||||
|
|
||||||
if ((fp = tmpfile()) == NULL) {
|
if ((fp = tmpfile()) == NULL) {
|
||||||
WriteError("$Can't create tmpfile");
|
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>");
|
send_nntp("340 Send article to be posted. End with <CR-LF>.<CR-LF>");
|
||||||
|
|
||||||
while (Done == FALSE) {
|
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) {
|
if (rc < 0) {
|
||||||
WriteError("nntp_get failed, abort");
|
WriteError("nntp_get failed, abort");
|
||||||
return;
|
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);
|
fclose(fp);
|
||||||
|
|
||||||
if (rc)
|
if (maxrc)
|
||||||
send_nntp("503 Post failed:");
|
send_nntp("441 Posting failed");
|
||||||
else
|
else
|
||||||
send_nntp("240 Article posted");
|
send_nntp("240 Article posted OK");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -121,6 +121,7 @@ int main(int argc, char *argv[])
|
|||||||
InitMsgs();
|
InitMsgs();
|
||||||
InitUser();
|
InitUser();
|
||||||
InitFidonet();
|
InitFidonet();
|
||||||
|
InitNode();
|
||||||
umask(002);
|
umask(002);
|
||||||
memset(&usrconfig, 0, sizeof(usrconfig));
|
memset(&usrconfig, 0, sizeof(usrconfig));
|
||||||
|
|
||||||
@ -276,7 +277,7 @@ void nntp(void)
|
|||||||
} else if (strncasecmp(buf, "HEAD", 4) == 0) {
|
} else if (strncasecmp(buf, "HEAD", 4) == 0) {
|
||||||
if (check_auth(buf))
|
if (check_auth(buf))
|
||||||
command_abhs(buf);
|
command_abhs(buf);
|
||||||
} else if (strncasecmp(buf, "HEAD", 4) == 0) {
|
} else if (strncasecmp(buf, "POST", 4) == 0) {
|
||||||
if (check_auth(buf))
|
if (check_auth(buf))
|
||||||
command_post(buf);
|
command_post(buf);
|
||||||
} else if (strncasecmp(buf, "IHAVE", 5) == 0) {
|
} else if (strncasecmp(buf, "IHAVE", 5) == 0) {
|
||||||
|
@ -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.
|
* 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.
|
* Store failed or it was bad or a dupe. Only log failed store.
|
||||||
*/
|
*/
|
||||||
|
@ -383,7 +383,7 @@ int rfc2ftn(FILE *fp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!(hdr((char *)"X-FTN-Tearline", msg)) && !(hdr((char *)"X-FTN-TID", msg))) {
|
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);
|
hdrsize += 4 + strlen(temp);
|
||||||
fprintf(ofp, "\1TID:");
|
fprintf(ofp, "\1TID:");
|
||||||
kludgewrite(temp, ofp);
|
kludgewrite(temp, ofp);
|
||||||
|
@ -46,7 +46,7 @@
|
|||||||
* 1 - Can't access messagebase.
|
* 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;
|
int result;
|
||||||
unsigned long crc2;
|
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
|
* Update import counters
|
||||||
*/
|
*/
|
||||||
if (!bad && !dupe) {
|
StatAdd(&msgs.Received, 1L);
|
||||||
StatAdd(&msgs.Received, 1L);
|
msgs.LastRcvd = time(NULL);
|
||||||
msgs.LastRcvd = time(NULL);
|
StatAdd(&mgroup.MsgsRcvd, 1L);
|
||||||
StatAdd(&mgroup.MsgsRcvd, 1L);
|
mgroup.LastDate = time(NULL);
|
||||||
mgroup.LastDate = time(NULL);
|
UpdateMsgs();
|
||||||
UpdateMsgs();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bad) {
|
result = Msg_Open(msgs.Base);
|
||||||
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) {
|
if (!result) {
|
||||||
WriteError("Can't open JAMmb %s", msgs.Base);
|
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)))
|
if ((flags & M_PVT) && ((msgs.MsgKinds == BOTH) || (msgs.MsgKinds == PRIVATE)))
|
||||||
Msg.Private = TRUE;
|
Msg.Private = TRUE;
|
||||||
if (flags & M_FILE)
|
|
||||||
Msg.FileAttach = TRUE;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set MSGID and REPLY crc.
|
* 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
|
* Start write the message
|
||||||
* If not a bad or dupe message, eat the first
|
* Eat the first line (AREA:tag).
|
||||||
* line (AREA:tag).
|
|
||||||
*/
|
*/
|
||||||
buf = calloc(MAX_LINE_LENGTH +1, sizeof(char));
|
buf = calloc(MAX_LINE_LENGTH +1, sizeof(char));
|
||||||
rewind(fp);
|
rewind(fp);
|
||||||
if (!dupe && !bad)
|
fgets(buf , MAX_LINE_LENGTH, fp);
|
||||||
fgets(buf , MAX_LINE_LENGTH, fp);
|
|
||||||
Msg_Write(fp);
|
Msg_Write(fp);
|
||||||
Msg_AddMsg();
|
Msg_AddMsg();
|
||||||
Msg_UnLock();
|
Msg_UnLock();
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
/* $Id$ */
|
/* $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
|
#endif
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user