Index: ossp-pkg/lmtp2nntp/.cvsignore RCS File: /v/ossp/cvs/ossp-pkg/lmtp2nntp/.cvsignore,v rcsdiff -q -kk '-r1.10' '-r1.11' -u '/v/ossp/cvs/ossp-pkg/lmtp2nntp/.cvsignore,v' 2>/dev/null --- .cvsignore 2001/09/07 10:27:51 1.10 +++ .cvsignore 2001/09/07 13:53:16 1.11 @@ -10,4 +10,4 @@ lmtp2nntp.1 lmtp2nntp-*.tar.gz dmalloc.log -logtest +logfile Index: ossp-pkg/lmtp2nntp/00TODO RCS File: /v/ossp/cvs/ossp-pkg/lmtp2nntp/00TODO,v rcsdiff -q -kk '-r1.26' '-r1.27' -u '/v/ossp/cvs/ossp-pkg/lmtp2nntp/00TODO,v' 2>/dev/null --- 00TODO 2001/09/05 09:14:26 1.26 +++ 00TODO 2001/09/07 13:53:16 1.27 @@ -1,8 +1,12 @@ whatsup draufleiten - -[B<-b> I] +panic = unexpected +error = i/o error, errno ... +warning = NNTP connect failed + info = *MOST COMMON* step by step +trace = ist bisheriger trace.c +debug = developer meldungen Hallo Thomas, wir haben festgestellt, dass wir noch ein feature brauchen. @@ -14,7 +18,6 @@ use L2 for logging, grab ID through RFC1891 ENVID, 6.2 [B<-i> I] -[B<-l> I] CU/CUS Index: ossp-pkg/lmtp2nntp/Makefile.in RCS File: /v/ossp/cvs/ossp-pkg/lmtp2nntp/Makefile.in,v rcsdiff -q -kk '-r1.13' '-r1.14' -u '/v/ossp/cvs/ossp-pkg/lmtp2nntp/Makefile.in,v' 2>/dev/null --- Makefile.in 2001/09/05 09:10:28 1.13 +++ Makefile.in 2001/09/07 13:53:16 1.14 @@ -43,7 +43,7 @@ POD2MAN = pod2man PROG = lmtp2nntp -HDRS = lmtp.h nntp.h sa.h argz.h shpat_match.h msg.h trace.h +HDRS = lmtp2nntp.h lmtp.h nntp.h sa.h argz.h shpat_match.h msg.h trace.h OBJS = lmtp2nntp.o lmtp.o nntp.o sa.o argz.o shpat_match.o msg.o trace.o version.o SUBDIRS = @SUBDIR_STR@ @SUBDIR_L2@ Index: ossp-pkg/lmtp2nntp/lmtp2nntp.c RCS File: /v/ossp/cvs/ossp-pkg/lmtp2nntp/Attic/lmtp2nntp.c,v rcsdiff -q -kk '-r1.41' '-r1.42' -u '/v/ossp/cvs/ossp-pkg/lmtp2nntp/Attic/lmtp2nntp.c,v' 2>/dev/null --- lmtp2nntp.c 2001/09/05 15:01:57 1.41 +++ lmtp2nntp.c 2001/09/07 13:53:16 1.42 @@ -37,9 +37,10 @@ #include "str.h" #include "argz.h" #include "shpat_match.h" -#include "l2/l2.h" //FIXME +#include "l2.h" /* own headers */ +#include "lmtp2nntp.h" #ifdef HAVE_CONFIG_H #include "config.h" #endif @@ -105,8 +106,8 @@ }; typedef struct { - int option_verbose; - int option_tracing; + char *progname; + char *option_logfile; int option_groupmode; int option_deliverymode; char *option_deliverymodefakestatus; @@ -172,6 +173,26 @@ return; } +static l2_result_t +formatter_prefix(l2_context_t *_ctx, const char id, const char *param, + char *bufptr, size_t bufsize, size_t *buflen, va_list *ap) +{ + lmtp2nntp_t *ctx = (lmtp2nntp_t *)_ctx->vp; + + sprintf(bufptr, "%s[%ld]", ctx->progname, (long)getpid()); + *buflen = strlen(bufptr); + return L2_OK; +} + +static l2_result_t +formatter_errno(l2_context_t *_ctx, const char id, const char *param, + char *bufptr, size_t bufsize, size_t *buflen, va_list *ap) +{ + sprintf(bufptr, "(%d) %s", errno, strerror(errno)); + *buflen = strlen(bufptr); + return L2_OK; +} + int main(int argc, char **argv) { lmtp_t *lmtp; @@ -179,7 +200,6 @@ lmtp2nntp_t *ctx; int i; /* general purpose scratch int, index ... */ char *cp; /* general purpose character pointer */ - char *progname; char *azHosts; size_t asHosts; char *cpHost; @@ -189,13 +209,11 @@ l2_channel_t *chBuf; l2_channel_t *chFile; - progname = argv[0]; - /* create application context */ if ((ctx = (lmtp2nntp_t *)malloc(sizeof(lmtp2nntp_t))) == NULL) exit(ERR_EXECUTION); - ctx->option_verbose = FALSE; - ctx->option_tracing = FALSE; + ctx->progname = strdup(argv[0]); + ctx->option_logfile = NULL; ctx->option_groupmode = GROUPMODE_ARG; ctx->option_deliverymode = DELIVERYMODE_FAKE; ctx->option_deliverymodefakestatus = "553"; /* Requested action not taken: mailbox name not allowed */ @@ -203,7 +221,7 @@ ctx->option_maxmessagesize = 8 * 1024 * 1024; ctx->option_waittime = -1; ctx->option_mailfrom = NULL; - ctx->option_levelmask = L2_LEVEL_UPTO(L2_LEVEL_ERROR); + ctx->option_levelmask = L2_LEVEL_UPTO(L2_LEVEL_WARNING); ctx->l2 = NULL; ctx->cpBindh = NULL; ctx->cpBindp = NULL; @@ -222,7 +240,7 @@ initsession(&ctx->session); ctx->msg = NULL; if (uname(&ctx->uname) == -1) { - fprintf(stderr, "%s:Error: uname failed \"%s\"\n", progname, strerror(errno)); + fprintf(stderr, "%s:Error: uname failed \"%s\"\n", ctx->progname, strerror(errno)); exit(ERR_EXECUTION); } @@ -241,57 +259,6 @@ } #endif - if ((ctx->l2 = l2_stream_create()) == NULL) { - fprintf(stderr, "%s:Error: logging failed to create stream\n", progname); - exit(ERR_EXECUTION); - } - - if ((chPrefix = l2_channel_create(&l2_handler_prefix)) == NULL) { - fprintf(stderr, "%s:Error: logging failed to create prefix channel\n", progname); - exit(ERR_EXECUTION); - } - if (l2_channel_configure(chPrefix, "timefmt,timezone", "[%d-%m-%Y/%H:%M:%S] ", "local") != L2_OK) { - fprintf(stderr, "%s:Error: logging failed to configure prefix channel\n", progname); - exit(ERR_EXECUTION); - } - - if ((chBuf = l2_channel_create(&l2_handler_buffer)) == NULL) { - fprintf(stderr, "%s:Error: logging failed to create buffer channel\n", progname); - exit(ERR_EXECUTION); - } - if (l2_channel_configure(chBuf, "size", 4096) != L2_OK) { - fprintf(stderr, "%s:Error: logging failed to configure buffer channel\n", progname); - exit(ERR_EXECUTION); - } - - if ((chFile = l2_channel_create(&l2_handler_file)) == NULL) { - fprintf(stderr, "%s:Error: logging failed to create file channel\n", progname); - exit(ERR_EXECUTION); - } - if (l2_channel_configure(chFile, "path,append,perm", "logtest", TRUE, 0644) != L2_OK) { - fprintf(stderr, "%s:Error: logging failed to configure file channel\n", progname); - exit(ERR_EXECUTION); - } - - if (l2_channel_stack(chFile, chBuf) != L2_OK) { - fprintf(stderr, "%s:Error: logging failed to stack buffer channel on top of file channel\n", progname); - exit(ERR_EXECUTION); - } - if (l2_channel_stack(chBuf, chPrefix) != L2_OK) { - fprintf(stderr, "%s:Error: logging failed to stack prefix channel on top of buffer channel\n", progname); - exit(ERR_EXECUTION); - } - - if (l2_channel_open(chPrefix) != L2_OK) { - fprintf(stderr, "%s:Error: logging failed to open buffer channel\n", progname); - exit(ERR_EXECUTION); - } - - if (l2_stream_channel(ctx->l2, chPrefix, L2_LEVEL_UPTO(L2_LEVEL_DEBUG)) != L2_OK) { - fprintf(stderr, "%s:Error: logging failed to attach channel into stream\n", progname); - exit(ERR_EXECUTION); - } - /*POD B */ /* use @@ -300,19 +267,8 @@ */ /* read in the arguments */ - while ((i = getopt(argc, argv, "L:Vb:d:g:h:l:m:n:s:t:vw:")) != -1) { + while ((i = getopt(argc, argv, "b:d:g:h:l:m:n:s:vw:")) != -1) { switch (i) { - case 'L': /*POD B<-L> I*/ - if (l2_util_s2l(optarg, strlen(optarg), ',', &ctx->option_levelmask) != L2_OK) { - fprintf(stderr, "%s:Error: Invalid format \"%s\" to option -L\n", progname, optarg); - exit(ERR_EXECUTION); - } - //FIXME - break; - case 'V': /*POD [B<-V>] (version)*/ - fprintf(stdout, "%s\n", lmtp2nntp_version.v_gnu); - exit(0); - break; case 'b': /*POD [B<-b> I[I<:port>] */ /* parse host[:port] string into host and port */ ctx->cpBindh = strdup(optarg); @@ -326,23 +282,12 @@ fprintf(stderr, "DEBUG: creating TCP socket address for \"%s:%s\"\n", ctx->cpBindh, ctx->cpBindp); if ((ctx->saBind = sa_create(SA_IP, "tcp", ctx->cpBindh, ctx->cpBindp)) == NULL) { fprintf(stderr, "%s:Error: creating TCP socket address failed for \"%s:%s\": %s\n", - progname, + ctx->progname, ctx->cpBindh, ctx->cpBindp, strerror(errno)); exit(ERR_EXECUTION); } - fprintf(stderr, "DEBUG: saBind->sa_len=%d\n", - ctx->saBind->sa_buf->sa_len); - fprintf(stderr, "DEBUG: saBind->sa_family=%d\n", (int)ctx->saBind->sa_buf->sa_family); - for (i=0; i<14; i++) - fprintf(stderr, "DEBUG: saBind->sa_data[%2d]=%2x %d\n", i, - (unsigned int)(unsigned char)ctx->saBind->sa_buf->sa_data[i], - (unsigned int)(unsigned char)ctx->saBind->sa_buf->sa_data[i]); - ctx->saBind->sa_buf->sa_data[ 7]='0'; //DEBUG - ctx->saBind->sa_buf->sa_data[ 8]='0'; //DEBUG - ctx->saBind->sa_buf->sa_data[ 9]='0'; //DEBUG - ctx->saBind->sa_buf->sa_data[10]='0'; //DEBUG break; case 'd': /*POD [B<-d> I] */ if (strcasecmp(optarg, "post") == 0) @@ -351,12 +296,12 @@ ctx->option_deliverymode = DELIVERYMODE_FEED; else { if (strlen(optarg) != 9) { - fprintf(stderr, "%s:Error: Invalid format or length \"%s\" to option -d\n", progname, optarg); + fprintf(stderr, "%s:Error: Invalid format or length \"%s\" to option -d\n", ctx->progname, optarg); exit(ERR_EXECUTION); } if (optarg[3] != '/') { - fprintf(stderr, "%s:Error: Invalid format or missing slash \"%s\" to option -d\n", progname, optarg); + fprintf(stderr, "%s:Error: Invalid format or missing slash \"%s\" to option -d\n", ctx->progname, optarg); exit(ERR_EXECUTION); } @@ -368,7 +313,7 @@ || !isdigit((int)ctx->option_deliverymodefakestatus[0]) || !isdigit((int)ctx->option_deliverymodefakestatus[1]) || !isdigit((int)ctx->option_deliverymodefakestatus[2])) { - fprintf(stderr, "%s:Error: Invalid status in format \"%s\" to option -d\n", progname, optarg); + fprintf(stderr, "%s:Error: Invalid status in format \"%s\" to option -d\n", ctx->progname, optarg); exit(ERR_EXECUTION); } @@ -379,7 +324,7 @@ || (ctx->option_deliverymodefakedsn[3] != '.') || !isdigit((int)ctx->option_deliverymodefakedsn[4]) || (ctx->option_deliverymodefakedsn[0] != ctx->option_deliverymodefakestatus[0])) { - fprintf(stderr, "%s:Error: Invalid dsn in format \"%s\" to option -d\n", progname, optarg); + fprintf(stderr, "%s:Error: Invalid dsn in format \"%s\" to option -d\n", ctx->progname, optarg); exit(ERR_EXECUTION); } } @@ -392,7 +337,7 @@ else if (strcasecmp(optarg, "header") == 0) ctx->option_groupmode = GROUPMODE_HEADER; else { - fprintf(stderr, "%s:Error: Invalid mode \"%s\" to option -g\n", progname, optarg); + fprintf(stderr, "%s:Error: Invalid mode \"%s\" to option -g\n", ctx->progname, optarg); exit(ERR_EXECUTION); } break; @@ -402,7 +347,7 @@ cp = NULL; while ((cp = argz_next(azHosts, asHosts, cp)) != NULL) { if (ctx->nsc >= MAXNEWSSERVICES) { - fprintf(stderr, "%s:Error: Too many services (%d) using option -h\n", progname, ctx->nsc); + fprintf(stderr, "%s:Error: Too many services (%d) using option -h\n", ctx->progname, ctx->nsc); exit(ERR_EXECUTION); } @@ -421,7 +366,7 @@ ctx->ns[ctx->nsc].h, ctx->ns[ctx->nsc].p)) == NULL) { fprintf(stderr, "%s:Error: creating TCP socket address failed for \"%s:%s\": %s\n", - progname, + ctx->progname, ctx->ns[ctx->nsc].h, ctx->ns[ctx->nsc].p, strerror(errno)); @@ -431,7 +376,7 @@ if ((ctx->ns[ctx->nsc].s = socket(sa->sa_buf->sa_family, SOCK_STREAM, sa->sa_proto)) == -1) { fprintf(stderr, "%s:Error: Creating TCP socket failed for \"%s:%s\": %s\n", - progname, + ctx->progname, ctx->ns[ctx->nsc].h, ctx->ns[ctx->nsc].p, strerror(errno)); @@ -447,7 +392,7 @@ break; case 'n': /*POD [B<-n> I] */ if (strlen(optarg) > sizeof(ctx->uname.nodename)-1) { - fprintf(stderr, "%s:Error: nodename \"%s\" to long to option -n.\n", progname, optarg); + fprintf(stderr, "%s:Error: nodename \"%s\" to long to option -n.\n", ctx->progname, optarg); exit(ERR_EXECUTION); } strcpy(ctx->uname.nodename, optarg); @@ -455,28 +400,42 @@ case 's': /*POD [B<-s> I] */ ctx->option_maxmessagesize = atoi(optarg); if(ctx->option_maxmessagesize < 64) { - fprintf(stderr, "%s:Error: maximum message size is unacceptable small.\n", progname); + fprintf(stderr, "%s:Error: maximum message size is unacceptable small.\n", ctx->progname); exit(ERR_EXECUTION); } - case 't': /*POD [B<-t> I] */ - ctx->option_tracing = TRUE; - trace_read (-1, optarg, 0); - trace_write(-1, optarg, 0); + case 'l': /*POD [B<-l> I[:I]] */ + if ((cp = strrchr(optarg, ':')) != NULL) { + *cp++ = NUL; + if (*cp == NUL) { + fprintf(stderr, "%s:Error: empty logfile to option -l\n", ctx->progname); + exit(ERR_EXECUTION); + } + else + ctx->option_logfile = strdup(cp); + } + else + ctx->option_logfile = strdup("logfile"); + + if (l2_util_s2l(optarg, strlen(optarg), ',', &ctx->option_levelmask) != L2_OK) { + fprintf(stderr, "%s:Error: invalid level \"%s\" to option -l\n", ctx->progname, optarg); + exit(ERR_EXECUTION); + } + ctx->option_levelmask = L2_LEVEL_UPTO(ctx->option_levelmask); break; - case 'v': /*POD [B<-v>] (verbose)*/ - ctx->option_verbose = TRUE; + case 'v': /*POD [B<-v>] (version)*/ + fprintf(stdout, "%s\n", lmtp2nntp_version.v_gnu); + exit(0); break; case 'w': /*POD [B<-w> I] */ ctx->option_waittime = atoi(optarg); if(ctx->option_waittime < 1) { - fprintf(stderr, "%s:Error: waittime %d to option -w must be greater 1 second.\n", - progname, ctx->option_waittime); + fprintf(stderr, "%s:Error: waittime %d to option -w must be greater 1 second.\n", ctx->progname, ctx->option_waittime); exit(ERR_EXECUTION); } break; case '?': default: - usage(progname); + usage(ctx->progname); exit(ERR_EXECUTION); } } @@ -485,32 +444,94 @@ argz_add(&ctx->azGroupargs, &ctx->asGroupargs, argv[i]); } - /* initialize L2 logging context */ - fprintf(stderr, "DEBUG: ctx->option_levelmask=0x%x\n", ctx->option_levelmask); - if (l2_stream_levels(ctx->l2, ctx->option_levelmask) != L2_OK) { - fprintf(stderr, "%s:Error: logging failed to set global logging level\n", progname); + if ((ctx->l2 = l2_stream_create()) == NULL) { + fprintf(stderr, "%s:Error: logging failed to create stream\n", ctx->progname); exit(ERR_EXECUTION); } - if (l2_stream_log(ctx->l2, L2_LEVEL_INFO, "%s: Startup", progname) != L2_OK) { - fprintf(stderr, "%s:Error: logging failed to log \"Startup\" message to stream\n", progname); + if (l2_stream_formatter(ctx->l2, 'P', formatter_prefix, (l2_context_t *)&ctx) != L2_OK) { + fprintf(stderr, "%s:Error: logging failed to register formatter\n", ctx->progname); exit(ERR_EXECUTION); } - if (l2_stream_log(ctx->l2, L2_LEVEL_DEBUG, "%s: Startup DEBUG-test", progname) != L2_OK) { - fprintf(stderr, "%s:Error: logging failed to log \"Startup\" message to stream\n", progname); + if (l2_stream_formatter(ctx->l2, 'D', l2_util_fmt_dump, NULL) != L2_OK) { + fprintf(stderr, "%s:Error: logging failed to register dump formatter\n", ctx->progname); exit(ERR_EXECUTION); } - if (l2_stream_log(ctx->l2, L2_LEVEL_PANIC, "%s: Startup PANIC-test", progname) != L2_OK) { - fprintf(stderr, "%s:Error: logging failed to log \"Startup\" message to stream\n", progname); + if (l2_stream_formatter(ctx->l2, 'm', formatter_errno, NULL) != L2_OK) { + fprintf(stderr, "%s:Error: logging failed to register dump formatter\n", ctx->progname); exit(ERR_EXECUTION); } + if ((chPrefix = l2_channel_create(&l2_handler_prefix)) == NULL) { + fprintf(stderr, "%s:Error: logging failed to create prefix channel\n", ctx->progname); + exit(ERR_EXECUTION); + } + if (l2_channel_configure(chPrefix, "timefmt,timezone", "[%d-%m-%Y/%H:%M:%S] ", "local") != L2_OK) { + fprintf(stderr, "%s:Error: logging failed to configure prefix channel\n", ctx->progname); + exit(ERR_EXECUTION); + } + + if ((chBuf = l2_channel_create(&l2_handler_buffer)) == NULL) { + fprintf(stderr, "%s:Error: logging failed to create buffer channel\n", ctx->progname); + exit(ERR_EXECUTION); + } + if (l2_channel_configure(chBuf, "size", 4) != L2_OK) { //FIXME 4096 + fprintf(stderr, "%s:Error: logging failed to configure buffer channel\n", ctx->progname); + exit(ERR_EXECUTION); + } + + if ((chFile = l2_channel_create(&l2_handler_file)) == NULL) { + fprintf(stderr, "%s:Error: logging failed to create file channel\n", ctx->progname); + exit(ERR_EXECUTION); + } + if (l2_channel_configure(chFile, "path,append,perm", ctx->option_logfile, TRUE, 0644) != L2_OK) { + fprintf(stderr, "%s:Error: logging failed to configure file channel\n", ctx->progname); + exit(ERR_EXECUTION); + } + + if (l2_channel_stack(chFile, chBuf) != L2_OK) { + fprintf(stderr, "%s:Error: logging failed to stack buffer channel on top of file channel\n", ctx->progname); + exit(ERR_EXECUTION); + } + if (l2_channel_stack(chBuf, chPrefix) != L2_OK) { + fprintf(stderr, "%s:Error: logging failed to stack prefix channel on top of buffer channel\n", ctx->progname); + exit(ERR_EXECUTION); + } + + if (l2_channel_open(chPrefix) != L2_OK) { + fprintf(stderr, "%s:Error: logging failed to open buffer channel\n", ctx->progname); + exit(ERR_EXECUTION); + } + + if (l2_stream_channel(ctx->l2, chPrefix, L2_LEVEL_UPTO(L2_LEVEL_DEBUG)) != L2_OK) { + fprintf(stderr, "%s:Error: logging failed to attach channel into stream\n", ctx->progname); + exit(ERR_EXECUTION); + } + +fprintf(stderr, "DEBUG: ctx->option_levelmask=0x%x\n", ctx->option_levelmask); + if (l2_stream_levels(ctx->l2, ctx->option_levelmask) != L2_OK) { + fprintf(stderr, "%s:Error: logging failed to set global logging level\n", ctx->progname); + exit(ERR_EXECUTION); + } + + if (l2_stream_log(ctx->l2, L2_LEVEL_INFO, "%P: 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); + } + + if (ctx->option_logfile && (ctx->option_levelmask >= L2_LEVEL_TRACE)) { + trace_read (-1, ctx->option_logfile, 0); + trace_write(-1, ctx->option_logfile, 0); + } + /* initialize LMTP context */ lmtp_io.select = NULL; lmtp_io.read = trace_read; lmtp_io.write = trace_write; - if ((lmtp = lmtp_create(STDIN_FILENO, STDOUT_FILENO, ctx->option_tracing ? &lmtp_io : NULL)) == NULL) { - fprintf(stderr, "%s:Error: Unable to initialize LMTP library\n", progname); + if ((lmtp = lmtp_create(STDIN_FILENO, STDOUT_FILENO, + (ctx->option_logfile && (ctx->option_levelmask >= L2_LEVEL_TRACE)) ? + &lmtp_io : NULL )) == NULL) { + fprintf(stderr, "%s:Error: Unable to initialize LMTP library\n", ctx->progname); exit(ERR_EXECUTION); } /* RFC0821, 4.5.1. MINIMUM IMPLEMENTATION @@ -540,19 +561,20 @@ lmtp_loop(lmtp); /* graceful shutdown */ + log0(ctx, INFO, "%P: graceful shutdown, no more logging until exit"); lmtp_gfs_quit(ctx); lmtp_gfs_lhlo(ctx); lmtp_destroy(lmtp); + if (ctx->option_logfile != NULL) + free(ctx->option_logfile); + if (ctx->progname != NULL) + free(ctx->progname); if (ctx->azGroupargs != NULL) free(ctx->azGroupargs); if (ctx != NULL) free(ctx); str_parse(NULL, NULL); - - if (l2_stream_destroy(ctx->l2) != L2_OK) { - fprintf(stderr, "%s:Error: logging failed to destroy stream\n", progname); - exit(ERR_EXECUTION); - } + l2_stream_destroy(ctx->l2); return 0; } @@ -657,6 +679,8 @@ int i; nntp_io_t nntp_io; + log0(ctx, INFO, "lmtp_cb_lhlo"); + nntp_io.select = NULL; nntp_io.read = trace_read; nntp_io.write = trace_write; @@ -701,35 +725,56 @@ i = 0; do { bOk = TRUE; - if (bOk && (ctx->saBind != NULL) && - bind(ctx->ns[i].s, ctx->saBind->sa_buf, ctx->saBind->sa_len) < 0) { - bOk = FALSE; - fprintf(stderr, "DEBUG: errno=%d\n", errno); - } - if (ctx->option_waittime > 0) { - if (connect_nonb(ctx->ns[i].s, ctx->ns[i].sa->sa_buf, ctx->ns[i].sa->sa_len, - ctx->option_waittime) < 0) { + if (bOk && (ctx->saBind != NULL)) { + log0(ctx, DEBUG, "bind"); + if (bind(ctx->ns[i].s, ctx->saBind->sa_buf, ctx->saBind->sa_len) < 0) { bOk = FALSE; + log0(ctx, ERROR, "bind=%m"); } } - else { - if (connect(ctx->ns[i].s, ctx->ns[i].sa->sa_buf, ctx->ns[i].sa->sa_len) < 0) { - bOk = FALSE; + if (bOk) { + if(ctx->option_waittime > 0) { + log0(ctx, DEBUG, "connect_nonb"); + if (connect_nonb(ctx->ns[i].s, ctx->ns[i].sa->sa_buf, ctx->ns[i].sa->sa_len, + ctx->option_waittime) < 0) { + bOk = FALSE; + log0(ctx, ERROR, "connect_nonb=%m"); + } + } + else { + log0(ctx, DEBUG, "connect"); + if (connect(ctx->ns[i].s, ctx->ns[i].sa->sa_buf, ctx->ns[i].sa->sa_len) < 0) { + bOk = FALSE; + log0(ctx, ERROR, "connect=%m"); + } } } - if (bOk && ((ctx->ns[i].nntp = nntp_create(ctx->ns[i].s, ctx->ns[i].s, - ctx->option_tracing ? &nntp_io : NULL)) == NULL)) { - bOk = FALSE; + if (bOk) { + log0(ctx, DEBUG, "nntp_create"); + if ((ctx->ns[i].nntp = nntp_create(ctx->ns[i].s, ctx->ns[i].s, + (ctx->option_logfile && (ctx->option_levelmask >= L2_LEVEL_TRACE)) ? + &nntp_io : NULL)) == NULL) { + bOk = FALSE; + log0(ctx, ERROR, "nntp_create failed"); + } } if (bOk && ctx->option_waittime >= 0) { + log1(ctx, DEBUG, "nntp_timeout(%d)", ctx->option_waittime); nntp_timeout(ctx->ns[i].nntp, ctx->option_waittime); } - if (bOk && ((rc = nntp_init(ctx->ns[i].nntp)) != NNTP_OK)) { - bOk = FALSE; + if (bOk) { + log0(ctx, DEBUG, "nntp_init"); + if ((rc = nntp_init(ctx->ns[i].nntp)) != NNTP_OK) { + bOk = FALSE; + log2(ctx, ERROR, "nntp_init=(%m) %s", rc, nntp_error(rc)); + } } - if (bOk) + if (bOk) { + log0(ctx, INFO, "nntp connection successfully established"); i++; + } else { + log0(ctx, INFO, "nntp connection establishment failed"); if (i < --ctx->nsc) { memcpy(&ctx->ns[i], &ctx->ns[i+1], (ctx->nsc - i ) * sizeof(struct ns)); } @@ -915,6 +960,8 @@ lmtp2nntp_t *ctx = (lmtp2nntp_t *)_ctx; lmtp_res_t res; + log0(ctx, INFO, "lmtp_cb_mail"); + /* RFC0821 4.2.1. REPLY CODES BY FUNCTION GROUPS 553 Requested action not taken: mailbox name not allowed * RFC1893 2. Status Codes 5.X.X Permanent Failure * RFC1893 3.5 Network and Routing Status X.1.8 Bad sender's system address @@ -1011,6 +1058,8 @@ char *cp; char *group; + log0(ctx, INFO, "lmtp_cb_rcpt"); + /* RFC0821 4.2.1. REPLY CODES BY FUNCTION GROUPS 503 Bad sequence of commands * RFC1893 2. Status Codes 5.X.X Permanent Failure * RFC1893 3.5 Network and Routing Status X.5.0 Other or undefined protocol status @@ -1114,6 +1163,8 @@ int bSuccess; char *cp; + log0(ctx, INFO, "lmtp_cb_data"); + /* RFC0821 4.2.1. REPLY CODES BY FUNCTION GROUPS 503 Bad sequence of commands * RFC1893 2. Status Codes 5.X.X Permanent Failure * RFC1893 3.5 Network and Routing Status X.5.0 Other or undefined protocol status @@ -1371,11 +1422,14 @@ return LMTP_OK; } -static lmtp_rc_t lmtp_cb_noop(lmtp_t *lmtp, lmtp_io_t *io, lmtp_req_t *req, void *ctx) +static lmtp_rc_t lmtp_cb_noop(lmtp_t *lmtp, lmtp_io_t *io, lmtp_req_t *req, void *_ctx) { + lmtp2nntp_t *ctx = (lmtp2nntp_t *)_ctx; lmtp_res_t res; lmtp_rc_t rc = LMTP_OK; + log0(ctx, INFO, "lmtp_cb_noop"); + /* RFC0821 4.2.1. REPLY CODES BY FUNCTION GROUPS 250 Requested mail action okay, completed * RFC1893 2. Status Codes 2.X.X Success * RFC1893 3.5 Network and Routing Status X.0.0 Other undefined Status @@ -1393,6 +1447,8 @@ lmtp_res_t res; lmtp_rc_t rc = LMTP_OK; + log0(ctx, INFO, "lmtp_cb_rset"); + lmtp_gfs_rset(ctx); /* RFC0821 4.2.1. REPLY CODES BY FUNCTION GROUPS 250 Requested mail action okay, completed @@ -1421,6 +1477,8 @@ lmtp_res_t res; lmtp_rc_t rc = LMTP_EOF; + log0(ctx, INFO, "lmtp_cb_quit"); + lmtp_gfs_quit(ctx); /* RFC0821 4.2.1. REPLY CODES BY FUNCTION GROUPS 221 Service closing transmission channel Index: ossp-pkg/lmtp2nntp/lmtp2nntp.h RCS File: /v/ossp/cvs/ossp-pkg/lmtp2nntp/Attic/lmtp2nntp.h,v co -q -kk -p'1.1' '/v/ossp/cvs/ossp-pkg/lmtp2nntp/Attic/lmtp2nntp.h,v' | diff -u /dev/null - -L'ossp-pkg/lmtp2nntp/lmtp2nntp.h' 2>/dev/null --- ossp-pkg/lmtp2nntp/lmtp2nntp.h +++ - 2024-05-05 16:26:04.946496335 +0200 @@ -0,0 +1,39 @@ +/* +** Copyright (c) 2001 The OSSP Project +** Copyright (c) 2001 Cable & Wireless Deutschland +** +** This file is part of OSSP lmtp2nntp, an LMTP speaking local +** mailer which forwards mails as Usenet news articles via NNTP. +** It can be found at http://www.ossp.org/pkg/lmtp2nntp/. +** +** This program is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License +** as published by the Free Software Foundation; either version +** 2.0 of the License, or (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this file; if not, write to the Free Software +** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +** USA, or contact the OSSP project . +** +** lmtp2nntp.h: LMTP to NNTP global header +*/ + +#ifndef __LMTP2NNTP_H__ +#define __LMTP2NNTP_H__ + +#define log0(ctx,level,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) +#define log2(ctx,level,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) + +#endif /* __LMTP2NNTP_H__ */ Index: ossp-pkg/lmtp2nntp/lmtp2nntp.pod RCS File: /v/ossp/cvs/ossp-pkg/lmtp2nntp/lmtp2nntp.pod,v rcsdiff -q -kk '-r1.17' '-r1.18' -u '/v/ossp/cvs/ossp-pkg/lmtp2nntp/lmtp2nntp.pod,v' 2>/dev/null --- lmtp2nntp.pod 2001/09/05 15:01:57 1.17 +++ lmtp2nntp.pod 2001/09/07 13:53:16 1.18 @@ -33,7 +33,6 @@ =head1 SYNOPSIS B -[B<-V>] [B<-b> I[I<:port>] [B<-d> I] [B<-g> I] @@ -41,14 +40,13 @@ [B<-m> I] [B<-n> I] [B<-s> I] -[B<-t> I] +[B<-l> I[:I]] [B<-v>] [B<-w> I] I [I ...] B [B<-i> I] -[B<-l> I] =head1 DESCRIPTION @@ -64,10 +62,6 @@ =over 4 -=item B<-V> - -Print version information. - =item B<-b> I[I<:port>] Bind address and/or port to be used by the LMTP client. If an address is @@ -132,15 +126,9 @@ Size limitation on message in bytes. Default is 8388608 (8M). Values below 64 are considered unacceptable small. -=item B<-t> I - -Enable LMTP and NNTP protocol tracing into tracefile. When using C -these messages are logged with C level. - =item B<-v> -Enable verbose processing messages in logfile. When using C these -messages are logged with C level. +Print version information. =item B<-w> I @@ -157,38 +145,10 @@ B -=item B<-o> I - -Outgoing network IP address or hostname to bind to. - =item B<-i> I Message id of MTA (for logging purposes only). -=item B<-p> I - -Incoming protocol. Default is C which means B -reads the incoming mail from F in RFC822 message format and reports errors to F. -Alternatively if I is C, B speaks Local Mail -Transport Protocol (LMTP) according to RFC 2033 on F/F. - -=item B<-l> C - -=item B<-l> C[C<:>I] - -=item B<-l> CI - - -Logging target. This option can be specified more than once. Default is no -logging. Default I for C is C. - -=item B<-L> I - -Logging level. Default is C. Possible levels from highest priority with -least output to lowest priority with most most outpout are C, -C, C, C, C, C, C, C -where the chosen level includes all levels with higher priority. - =back =head1 SENDMAIL INTEGRATION Index: ossp-pkg/lmtp2nntp/test/.cvsignore RCS File: /v/ossp/cvs/ossp-pkg/lmtp2nntp/test/Attic/.cvsignore,v rcsdiff -q -kk '-r1.1' '-r1.2' -u '/v/ossp/cvs/ossp-pkg/lmtp2nntp/test/Attic/.cvsignore,v' 2>/dev/null --- .cvsignore 2001/09/07 10:27:51 1.1 +++ .cvsignore 2001/09/07 13:53:17 1.2 @@ -1,2 +1,2 @@ dmalloc.log -logtest +logfile Index: ossp-pkg/lmtp2nntp/test/run.sh RCS File: /v/ossp/cvs/ossp-pkg/lmtp2nntp/test/Attic/run.sh,v rcsdiff -q -kk '-r1.11' '-r1.12' -u '/v/ossp/cvs/ossp-pkg/lmtp2nntp/test/Attic/run.sh,v' 2>/dev/null --- run.sh 2001/08/28 13:12:59 1.11 +++ run.sh 2001/09/07 13:53:17 1.12 @@ -42,12 +42,8 @@ lmtp() { newmsg lmtp - set -x cat /tmp/testmessage \ - | ../lmtp2nntp -t /tmp/tracing -d $1 -g $2 -h dev16,141.1.23.116:nntp -h dev16.de.cw.net:119 $3 >/dev/null; echo $? - set +x -# cat /tmp/testmessage \ -# | ../lmtp2nntp -t /tmp/tracing -d $1 -g $2 -h dev16 $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 $? } sendmaildup() Index: ossp-pkg/lmtp2nntp/test/testmessage.vialmtp RCS File: /v/ossp/cvs/ossp-pkg/lmtp2nntp/test/Attic/testmessage.vialmtp,v rcsdiff -q -kk '-r1.4' '-r1.5' -u '/v/ossp/cvs/ossp-pkg/lmtp2nntp/test/Attic/testmessage.vialmtp,v' 2>/dev/null --- testmessage.vialmtp 2001/08/28 14:27:35 1.4 +++ testmessage.vialmtp 2001/09/07 13:53:17 1.5 @@ -4,7 +4,7 @@ RCPT To: RCPT To: DATA -Date: Tue, 26 Aug 2001 14:51:48 +0200 (CEST) +Date: Tue, 6 Sep 2001 14:51:48 +0200 (CEST) Message-Id: <200108141251.f7ECpmn74812@dev.de.cw.net> From: Thomas Lotterer Subject: lmtp2nntp testmessage.viasendmail