Index: ossp-pkg/lmtp2nntp/.configure RCS File: /v/ossp/cvs/ossp-pkg/lmtp2nntp/Attic/.configure,v rcsdiff -q -kk '-r1.8' '-r1.9' -u '/v/ossp/cvs/ossp-pkg/lmtp2nntp/Attic/.configure,v' 2>/dev/null --- .configure 2001/09/10 06:55:33 1.8 +++ .configure 2001/09/11 13:41:22 1.9 @@ -3,8 +3,8 @@ ./autogen.sh fi PATH=/cw/bin:$PATH -# --with-dmalloc=/cw \ ./configure \ + --with-dmalloc=/cw \ --enable-debug \ --prefix=/tmp/lmtp2nntp Index: ossp-pkg/lmtp2nntp/00TODO RCS File: /v/ossp/cvs/ossp-pkg/lmtp2nntp/00TODO,v rcsdiff -q -kk '-r1.33' '-r1.34' -u '/v/ossp/cvs/ossp-pkg/lmtp2nntp/00TODO,v' 2>/dev/null --- 00TODO 2001/09/11 06:43:13 1.33 +++ 00TODO 2001/09/11 13:41:22 1.34 @@ -1,18 +1,16 @@ -- [B<-i> I] -- CU/CUS -- str debugging - FIXME - signal handler to catch EINTR and segfaults - check gcc3 compatiblity - how to log nothing +- improve sendmail.m4 templates +- l2 date format should be same as syslog - -l syslog:[mask]//[localhost[:port]][/facility] - -l smtp:[mask]//[localhost[:port]][/tag:value ...] + -l syslog:[mask]//[localhost[:port]][/tag=value ...] with /tag=value i.e. facility=local0 + -l smtp:[mask]//[localhost[:port]][/tag=value ...] with /tag=value i.e. to=foo@example.com -l file:[mask]//path/file -L streamlog - **** DEVELOPMENT INFORMATION **** Debugging: Index: ossp-pkg/lmtp2nntp/lmtp2nntp.c RCS File: /v/ossp/cvs/ossp-pkg/lmtp2nntp/Attic/lmtp2nntp.c,v rcsdiff -q -kk '-r1.50' '-r1.51' -u '/v/ossp/cvs/ossp-pkg/lmtp2nntp/Attic/lmtp2nntp.c,v' 2>/dev/null --- lmtp2nntp.c 2001/09/11 06:41:59 1.50 +++ lmtp2nntp.c 2001/09/11 13:41:22 1.51 @@ -241,7 +241,11 @@ { lmtp2nntp_t *ctx = (lmtp2nntp_t *)_ctx->vp; - sprintf(bufptr, "%s[%ld]", ctx->progname, (long)getpid()); + if ((ctx->msg != NULL) && + (ctx->msg->cpFid != NULL)) + sprintf(bufptr, "%s[%ld]: %s: ", ctx->progname, (long)getpid(), ctx->msg->cpFid); + else + sprintf(bufptr, "%s[%ld]: ", ctx->progname, (long)getpid()); *buflen = strlen(bufptr); return L2_OK; } @@ -592,7 +596,7 @@ exit(ERR_EXECUTION); } - if (l2_stream_log(ctx->l2, L2_LEVEL_NOTICE, "%P: startup, version %s", lmtp2nntp_version.v_gnu) != L2_OK) { + if (log1(ctx, NOTICE, "startup, version %s", lmtp2nntp_version.v_gnu) != L2_OK) { fprintf(stderr, "%s:Error: logging failed to log startup message to stream\n", ctx->progname); exit(ERR_EXECUTION); } @@ -637,7 +641,7 @@ /* graceful shutdown */ lmtp_gfs_quit(ctx); lmtp_gfs_lhlo(ctx); - log0(ctx, NOTICE, "%P: graceful shutdown shortly before exit - no more logging"); + log0(ctx, NOTICE, "graceful shutdown shortly before exit - no more logging"); l2_stream_destroy(ctx->l2); lmtp_destroy(lmtp); if (ctx->option_logfile != NULL) @@ -936,6 +940,8 @@ free(ctx->cpBindh); if (ctx->cpBindp != NULL) free(ctx->cpBindp); + if (ctx->saBind != NULL) + sa_destroy(ctx->saBind); } static int helo_rfc0821domain(char *msg, char **domain) @@ -1099,6 +1105,7 @@ res.statusmsg = "Internal error - memory."; CU(LMTP_ERR_MEM); } + ctx->msg->l2 = ctx->l2; /* RFC1652 2. Framework for the 8bit MIME Transport Extension * (4) one optional parameter using the keyword BODY is added to the MAIL @@ -1492,8 +1499,9 @@ if (ctx->option_deliverymode == DELIVERYMODE_FAKE) { str_format(errorstring, sizeof(errorstring), - "NNTP running in fake mode, delivery of %s %s but delivery status forced to", + "NNTP running in fake mode, delivery of %s [%d bytes] %s but delivery status forced to", ctx->msg->cpMsgid, + strlen(ctx->msg->cpMsg), ((bSuccess == NNTP_OK) ? "succeeded" : (bSuccess == NNTP_DEFER) ? "deferred" : "failed")); switch (ctx->option_deliverymodefakestatus[0]) { @@ -1511,9 +1519,11 @@ break; } } else { - str_format(errorstring, sizeof(errorstring), "%sdelivery of %s", - ((ctx->option_deliverymode == DELIVERYMODE_POST) ? "post " : - (ctx->option_deliverymode == DELIVERYMODE_FEED) ? "feed " : ""), ctx->msg->cpMsgid); + str_format(errorstring, sizeof(errorstring), "%sdelivery of %s [%d bytes]", + ((ctx->option_deliverymode == DELIVERYMODE_POST) ? "post " : + (ctx->option_deliverymode == DELIVERYMODE_FEED) ? "feed " : ""), + ctx->msg->cpMsgid, + strlen(ctx->msg->cpMsg)); if (bSuccess == NNTP_OK) log2(ctx, NOTICE, "%s %s", errorstring, "succeeded"); else if(bSuccess == NNTP_DEFER) @@ -1522,6 +1532,7 @@ log2(ctx, ERROR, "%s %s", errorstring, "failed"); } + /* RFC0821 4.2.1. REPLY CODES BY FUNCTION GROUPS 250 Requested mail action okay, completed * 451 Requested action aborted: local error in processing * 554 Transaction failed Index: ossp-pkg/lmtp2nntp/lmtp2nntp.h RCS File: /v/ossp/cvs/ossp-pkg/lmtp2nntp/Attic/lmtp2nntp.h,v rcsdiff -q -kk '-r1.4' '-r1.5' -u '/v/ossp/cvs/ossp-pkg/lmtp2nntp/Attic/lmtp2nntp.h,v' 2>/dev/null --- lmtp2nntp.h 2001/09/11 06:37:53 1.4 +++ lmtp2nntp.h 2001/09/11 13:41:22 1.5 @@ -35,15 +35,15 @@ #endif #define log0(ctx,level,msg) \ - l2_stream_log((ctx)->l2, L2_LEVEL_##level, "%P: " msg) + l2_stream_log((ctx)->l2, L2_LEVEL_##level, "%P" msg) #define log1(ctx,level,msg,a1) \ - l2_stream_log((ctx)->l2, L2_LEVEL_##level, "%P: " msg, a1) + l2_stream_log((ctx)->l2, L2_LEVEL_##level, "%P" msg, a1) #define log2(ctx,level,msg,a1,a2) \ - l2_stream_log((ctx)->l2, L2_LEVEL_##level, "%P: " msg, a1, a2) + l2_stream_log((ctx)->l2, L2_LEVEL_##level, "%P" msg, a1, a2) #define log3(ctx,level,msg,a1,a2,a3) \ - l2_stream_log((ctx)->l2, L2_LEVEL_##level, "%P: " msg, a1, a2, a3) + l2_stream_log((ctx)->l2, L2_LEVEL_##level, "%P" msg, a1, a2, a3) #define log4(ctx,level,msg,a1,a2,a3,a4) \ - l2_stream_log((ctx)->l2, L2_LEVEL_##level, "%P: " msg, a1, a2, a3, a4) + l2_stream_log((ctx)->l2, L2_LEVEL_##level, "%P" msg, a1, a2, a3, a4) #define STMT(stuff) do { stuff } while (0) #define CU(returncode) STMT( rc = returncode; goto CUS; ) Index: ossp-pkg/lmtp2nntp/msg.c RCS File: /v/ossp/cvs/ossp-pkg/lmtp2nntp/Attic/msg.c,v rcsdiff -q -kk '-r1.16' '-r1.17' -u '/v/ossp/cvs/ossp-pkg/lmtp2nntp/Attic/msg.c,v' 2>/dev/null --- msg.c 2001/09/04 09:46:06 1.16 +++ msg.c 2001/09/11 13:41:22 1.17 @@ -31,6 +31,9 @@ #include "str.h" #include "argz.h" +/* third party */ +#include "l2.h" + #ifdef HAVE_CONFIG_H #include "config.h" #endif @@ -50,6 +53,7 @@ msg->cpMsg = NULL; msg->azHeaders = NULL; msg->asHeaders = 0; + msg->cpFid = NULL; msg->cpBody = NULL; msg->cpMsgid = NULL; msg->mail_from = NULL; @@ -57,6 +61,7 @@ msg->asRcpt = 0; msg->azNewsgroups = NULL; msg->asNewsgroups = 0; + msg->l2 = NULL; /* this is a copy only */ return msg; } @@ -72,6 +77,8 @@ free(msg->cpMsg); if (msg->azHeaders != NULL) free(msg->azHeaders); + if (msg->cpFid != NULL) + free(msg->cpFid); if (msg->cpBody != NULL) free(msg->cpBody); if (msg->cpMsgid != NULL) @@ -82,6 +89,7 @@ free(msg->azRcpt); if (msg->azNewsgroups != NULL) free(msg->azNewsgroups); + msg->l2 = NULL; /* this is a copy only, the "parent" needs to clean this up */ free(msg); return; @@ -126,29 +134,30 @@ * header information. */ - /* split message into header and body */ + log0(msg, DEBUG, "split message into header and body"); if (str_parse(msg->cpMsg, "m/((?:.*?)\\n)\\n(.*)$/s", &cpHeaders, &msg->cpBody) <= 0) return MSG_ERR_SPLITHEADBODY; free(msg->cpMsg); msg->cpMsg = NULL; - /* replace envelope From w/o colon by X-F: pseudotag. This eliminates the - * special case of having one header, which is really an embedded - * envelope, not ending with a colon while all others do. After splitting - * headers into name and value pairs this envelope ist stripped off. + log0(msg, DEBUG, "replace envelope From w/o colon by X-F: pseudotag"); + /* This eliminates the special case of having one header, which is really + * an embedded envelope, not ending with a colon while all others do. + * After splitting headers into name and value pairs this envelope ist + * stripped off. */ if (strncasecmp(cpHeaders, "From", 4) == 0) memcpy(cpHeaders, "X-F:", 4); - /* unwrap header lines */ + log0(msg, DEBUG, "unwrap header lines"); /* poor man's s///g simulator as current str library doesn't support global substitution */ while (str_parse(cpHeaders, "s/(.*?)\\n[ \\t]+(.*)/$1 $2/s", &cpRem) > 0) { free(cpHeaders); cpHeaders = cpRem; } - /* split header lines into names and values */ + log0(msg, DEBUG, "split header lines into names and values"); while (str_parse(cpHeaders, "m/^([\\w-]+?:)[ \\t]*([^\\n]*?)[ \\t]*\\n(.*)/s", &cpName, &cpValue, &cpRem) > 0) { free(cpHeaders); cpHeaders = cpRem; @@ -156,12 +165,13 @@ argz_add(&msg->azHeaders, &msg->asHeaders, cpValue); } - /* check for headers we care about and do whatever neccessary */ + log0(msg, DEBUG, "check for headers we care about and do whatever neccessary"); msg->cpMsgid = NULL; msg->azNewsgroups = NULL; msg->asNewsgroups = 0; cp = msg->azHeaders; while (cp != NULL) { + log1(msg, DEBUG, "processing header \"%s\"", cp); if (strcasecmp("X-F:", cp) == 0) { argz_delete(&msg->azHeaders, &msg->asHeaders, cp); /* del name */ argz_delete(&msg->azHeaders, &msg->asHeaders, cp); /* del value */ @@ -174,6 +184,9 @@ } if (strcasecmp("Received:", cp) == 0) { argz_delete(&msg->azHeaders, &msg->asHeaders, cp); /* del name */ + if ((msg->cpFid == NULL) && + (str_parse(cp, "m/\\sid\\s+cpFid) > 0)) + log1(msg, DEBUG, "found foreign-ID \"%s\" for logging", msg->cpFid); argz_delete(&msg->azHeaders, &msg->asHeaders, cp); /* del value */ continue; } @@ -210,17 +223,23 @@ if ((cp = argz_next(msg->azHeaders, msg->asHeaders, cp)) == NULL) /* next name */ break; } + + log0(msg, DEBUG, "checking Message-ID"); if (msg->cpMsgid == NULL) return MSG_ERR_SPLITIDNONE; + log0(msg, DEBUG, "checking Newsgroups"); if (msg->azNewsgroups != NULL) { argz_stringify(msg->azNewsgroups, msg->asNewsgroups, ','); if (argz_create_sep(msg->azNewsgroups, ',', &msg->azNewsgroups, &msg->asNewsgroups) != 0) return MSG_ERR_MEM; } + + log0(msg, DEBUG, "adding mandatory Path: header"); argz_add(&msg->azHeaders, &msg->asHeaders, "Path:"); argz_add(&msg->azHeaders, &msg->asHeaders, "not-for-mail"); + log0(msg, DEBUG, "split complete"); return MSG_OK; } @@ -238,7 +257,7 @@ int n; char *cpHeaders; - /* verify asNewsgroups */ + log0(msg, DEBUG, "verify Newsgroups"); if (msg->azNewsgroups == NULL) return MSG_ERR_JOINGROUPNONE; argz_stringify(msg->azNewsgroups, msg->asNewsgroups, ','); @@ -247,7 +266,7 @@ argz_add(&msg->azHeaders, &msg->asHeaders, "Newsgroups:"); argz_add(&msg->azHeaders, &msg->asHeaders, msg->azNewsgroups); - /* verify Message-ID */ + log0(msg, DEBUG, "verify Message-ID"); if (msg->cpMsgid == NULL) return MSG_ERR_JOINIDNONE; if (strlen(msg->cpMsgid) == 0) @@ -255,7 +274,7 @@ argz_add(&msg->azHeaders, &msg->asHeaders, "Message-ID:"); argz_add(&msg->azHeaders, &msg->asHeaders, msg->cpMsgid); - /* merge name/value pairs into single string */ + log0(msg, DEBUG, "merge name/value pairs into single string"); argz_add(&msg->azHeaders, &msg->asHeaders, ""); /* append empty string */ if ((aHeaders = (char **)malloc((argz_count(msg->azHeaders, msg->asHeaders) + 1) * sizeof(char *))) == NULL) return MSG_ERR_MEM; @@ -273,9 +292,8 @@ } free(aHeaders); - /* fold headers - * - * A logical line is split into one or more physical '\n'-terminated + log0(msg, DEBUG, "fold headers"); + /* A logical line is split into one or more physical '\n'-terminated * lines. The physical line is never longer than WRAPAT characters. This * includes the folded data and the header name + colon + space for the * first line and WRAPUSING string prefix for all other lines. Leading and @@ -327,6 +345,7 @@ } } + log0(msg, DEBUG, "strigify headers"); argz_stringify(msg->azHeaders, msg->asHeaders, '\n'); cpHeaders = msg->azHeaders; @@ -334,6 +353,7 @@ * header + CRLF + body + '.' + CRLF + NUL, replacing NL with CRLF * ********************************************************************/ + log0(msg, DEBUG, "assemble header and body"); n = 0; /* count size of headers, reserve space for NL to CRLF conversion */ for (i = 0; ((c = cpHeaders[i]) != NUL); i++) { @@ -401,6 +421,7 @@ msg->cpMsg[n++] = '\n'; msg->cpMsg[n] = NUL; + log0(msg, DEBUG, "join complete"); return MSG_OK; } Index: ossp-pkg/lmtp2nntp/msg.h RCS File: /v/ossp/cvs/ossp-pkg/lmtp2nntp/Attic/msg.h,v rcsdiff -q -kk '-r1.5' '-r1.6' -u '/v/ossp/cvs/ossp-pkg/lmtp2nntp/Attic/msg.h,v' 2>/dev/null --- msg.h 2001/09/04 09:46:06 1.5 +++ msg.h 2001/09/11 13:41:22 1.6 @@ -28,6 +28,8 @@ #define __MSG_H__ #include +#include "l2.h" +#include "lmtp2nntp.h" typedef struct { char *azEnvgroups; /* Groups according to Envelope in GROUPMODE_ENVELOPE */ @@ -35,6 +37,7 @@ char *cpMsg; /* the wholly message to be received by DATA command */ char *azHeaders; /* header part of message above */ size_t asHeaders; + char *cpFid; /* foreign (aka sendmail queue) id from parsing headers */ char *cpBody; /* body part of message above */ char *cpMsgid; char *mail_from; @@ -42,6 +45,7 @@ size_t asRcpt; char *azNewsgroups; size_t asNewsgroups; + l2_stream_t *l2; } msg_t; #define WRAPAT 120 /* join wraps header lines when exceeding this value */ Index: ossp-pkg/lmtp2nntp/test/run.sh RCS File: /v/ossp/cvs/ossp-pkg/lmtp2nntp/test/Attic/run.sh,v rcsdiff -q -kk '-r1.13' '-r1.14' -u '/v/ossp/cvs/ossp-pkg/lmtp2nntp/test/Attic/run.sh,v' 2>/dev/null --- run.sh 2001/09/10 06:55:33 1.13 +++ run.sh 2001/09/11 13:41:22 1.14 @@ -6,24 +6,6 @@ # -h news.ecrc.de # -h dev16 -before () -{ - #set -v -x - h="H" - z="Z" - e="E" - if [ -e /tmp/tracing ]; then - rm -f /tmp/tracing - fi - touch /tmp/tracing - chmod 666 /tmp/tracing - if [ -e /tmp/testmessage ]; then - rm -f /tmp/testmessage - fi - touch /tmp/testmessage - chmod 666 /tmp/testmessage -} - post1000 () { for h in 0 1 2 3 4 5 6 7 8 9 @@ -45,8 +27,9 @@ { newmsg lmtp cat /tmp/testmessage \ - | ../lmtp2nntp -l debug:/tmp/tracing -w 1 -d $1 -g $2 -b 127.0.0.1 -h 127.0.0.1 $3 >/dev/null; echo $? - #| ../lmtp2nntp -l debug:/tmp/tracing -w 1 -d $1 -g $2 -b dev12 -h dev16,141.1.23.116:nntp -h dev16.de.cw.net:119 $3 >/dev/null; echo $? + | ../lmtp2nntp -l $1:$FILE -w 1 -d $2 -g $2 -b dev12 -h dev16,141.1.23.116:nntp -h dev16.de.cw.net:119 $3 >/dev/null; echo $? + #| ../lmtp2nntp -l $1:$FILE -w 1 -d 255/2.5.5 -g $3 -b 127.0.0.1 $4 >/dev/null; echo $? + #| ../lmtp2nntp -l $1:$FILE -w 1 -d $2 -g $3 -b 127.0.0.1 -h 127.0.0.2 $4 >/dev/null; echo $? } sendmaildup() @@ -79,26 +62,70 @@ fi echo ----------------------------------------------------------- } + +before () +{ + set -v -x + h="H" + z="Z" + e="E" + + if [ -e $FILE ]; then + rm -f $FILE + fi + touch $FILE + chmod 666 $FILE + + if [ -e /tmp/testmessage ]; then + rm -f /tmp/testmessage + fi + touch /tmp/testmessage + chmod 666 /tmp/testmessage + + if [ -e dmalloc.log ]; then + rm -f dmalloc.log + fi + touch dmalloc.log + chmod 666 dmalloc.log +} + after () { - if [ -r /tmp/tracing ] + if [ -r $FILE ] then - less -S /tmp/tracing - #tail -f /tmp/tracing + read DUMMY + less -S $FILE + fi + + if [ -r dmalloc.log ] + then + read DUMMY + less -S dmalloc.log fi } +# lmtp notice post arg cw.de.sd.apps.dev.test +# newmsg sendmail; ls -l /tmp/testmessage && cat /tmp/testmessage +# lmtp feed arg +# lmtp post envelope '*.test.* cw.*.dev.*' +# lmtp post header '*.test.* cw.*.dev.* *foo*' +# lmtp feed envelope +# lmtp post envelope +# sendmaildup +# post1000 + + LOG="notice" + FILE="/tmp/tracing" +GROUP="cw.de.sd.apps.dev.test" +LOCAL="dev12" +HOST="dev16,141.1.23.116:nntp -h dev16.de.cw.net:119" before -#newmsg sendmail; ls -l /tmp/testmessage && cat /tmp/testmessage -#lmtp feed arg -lmtp post arg cw.de.sd.apps.dev.test -#ok lmtp post envelope '*.test.* cw.*.dev.*' -#ok lmtp post header '*.test.* cw.*.dev.* *foo*' -#lmtp feed envelope -#lmtp post envelope -#sendmaildup -#post1000 +newmsg lmtp +../lmtp2nntp /dev/null; echo $? + +#newmsg sendmail +# sendmail -i /dev/null --- testmessage.vialmtp 2001/09/07 13:53:17 1.5 +++ testmessage.vialmtp 2001/09/11 13:41:22 1.6 @@ -7,6 +7,15 @@ Date: Tue, 6 Sep 2001 14:51:48 +0200 (CEST) Message-Id: <200108141251.f7ECpmn74812@dev.de.cw.net> From: Thomas Lotterer +Received: from augias.ecrc.de (augias.ecrc.de [141.1.1.32]) + by ns1.ecrc.de (8.9.2/8.9.2/$Revision$) with SMTP id NAA08840 + for ; Mon, 2 Apr 2001 13:20:25 +0200 (MET DST) +Received: from clhq029 (clhq029.computerlinks.de [195.143.102.41]) + by augias.ecrc.de (8.11.0/8.11.0/$Revision$) with ESMTP id f32BKPb12235 + for ; Mon, 2 Apr 2001 13:20:25 +0200 +Received: from computerlinks.de (nwrulez.computerlinks.de [195.143.103.160]) + by clhq029 (8.8.8/8.8.8) with ESMTP id LAA12678; + Mon, 2 Apr 2001 11:23:14 GMT Subject: lmtp2nntp testmessage.viasendmail ..