diff -urNB qpopper4.0.5/common/logit.c qpopper4.0.5g26/common/logit.c --- qpopper4.0.5/common/logit.c Wed Jan 1 21:39:02 2003 +++ qpopper4.0.5g26/common/logit.c Fri Mar 21 11:19:43 2003 @@ -182,9 +182,11 @@ pYear = pDate + ( iDateLen - 5 ); /* point to start of year */ date_time [ iDateLen - 2 ] = '\0'; /* cut off the year */ lMsec = (tval.tv_usec + 500) / 1000; /* convert useconds to milliseconds */ - fprintf ( str, "%s.%03ld %.4s [%ld] %s\n", + fprintf ( str, "%s.%03ld %.4s %ld %s\n", pDate, lMsec, pYear, (long) getpid(), msgbuf ); + /* 20020306 grg deleted extra line fprintf ( str, "%s.%03ld %.4s \n", pDate, lMsec, pYear ); + */ fflush ( str ); } else { diff -urNB qpopper4.0.5/popper/main.c qpopper4.0.5g26/popper/main.c --- qpopper4.0.5/popper/main.c Wed Jan 1 21:39:02 2003 +++ qpopper4.0.5g26/popper/main.c Fri Mar 21 11:19:44 2003 @@ -141,6 +141,14 @@ # define SERV_TCP_PORT 110 #endif /* _DEBUG */ +#ifndef PIDFILEDIR +# define PIDFILEDIR "/var/run" +#endif + +#ifndef PIDFILE +# define PIDFILE "pid" +#endif + #define BAD_ADDR ( (unsigned long) -1 ) /* @@ -170,6 +178,7 @@ int hupit ( SIGPARAM ); int cleanup ( SIGPARAM ); void roll_it ( void ); +void pid_rewrite(char *, char *); void motherforker ( int newsockfd, int sockfd ); @@ -185,9 +194,13 @@ BOOL debug = FALSE; FILE *trace_file = NULL; char *trace_name = NULL; +FILE *logfile_file= NULL; +char *logfile_name= NULL; char msg_buf [ 2048 ] = ""; FILE *msg_out = NULL; FILE *err_out = NULL; +char pid_name[ 128 ] = ""; +FILE *pid_file = NULL; /* @@ -248,6 +261,8 @@ pname = ptr + 1; } + Qargv [ 0 ] = pname; /* originally argv [ 0 ] dcg for ecc */ + /* * The first specified parameter may be an IP address * and/or a port number. If so, this is what we bind @@ -305,7 +320,7 @@ err_dump ( HERE, "unable to allocate memory" ); Qargv_alloc = TRUE; bzero ( Qargv, rslt ); - Qargv [ 0 ] = argv [ 0 ]; + Qargv [ 0 ] = pname; /* originally argv [ 0 ] dcg for ecc */ for ( rslt = 2; rslt < argc; rslt++ ) Qargv [ rslt - 1 ] = argv [ rslt ]; Qargc = argc - 1; @@ -323,7 +338,7 @@ /* * See if debug or trace options specified */ - i = getopt ( Qargc, Qargv, "b:BcCdD:e:f:FkK:l:L:p:RsSt:T:uUvy:" ); + i = getopt ( Qargc, Qargv, "b:BcCdD:e:f:FkK:l:L:o:p:RsSt:T:uUvy:z:" ); while ( i != EOF ) { switch ( i ) @@ -332,6 +347,16 @@ debug = TRUE; break; + case 'o': + logfile_name = strdup ( optarg ); + logfile_file = fopen ( optarg, "a" ); + if ( logfile_file == NULL ) + err_dump ( HERE, "Unable to open trace file \"%s\"", optarg ); + TRACE ( trace_file, POP_DEBUG, HERE, + "Opened log file \"%s\" as %d", + logfile_name, fileno(logfile_file) ); + break; + case 't': debug = TRUE; trace_name = strdup ( optarg ); @@ -343,11 +368,24 @@ trace_name, fileno(trace_file) ); break; + case 'z': + pid_rewrite(pid_name,optarg); + if ( strcmp(pid_name,"") != 0) + { + pid_file = fopen ( pid_name, "w" ); + if ( pid_file == NULL ) + err_dump ( HERE, "Unable to open pid file \"%s\"", pid_name); + TRACE ( trace_file, POP_DEBUG, HERE, + "Opened pid file \"%s\" as %d", + pid_name, fileno(pid_file) ); + } + break; + default: break; } - i = getopt ( Qargc, Qargv, "b:BcCdD:e:f:FkK:l:L:p:RsSt:T:uUvy:" ); + i = getopt ( Qargc, Qargv, "b:BcCdD:e:f:FkK:l:L:o:p:RsSt:T:uUvy:z:" ); } optind = 1; /* reset for pop_init */ @@ -449,7 +487,19 @@ TRACE ( trace_file, POP_DEBUG, HERE, "closing file descs %d to 0", sysconf ( _SC_OPEN_MAX ) ); for ( i = sysconf ( _SC_OPEN_MAX ); i >= 0; i-- ) { - if ( debug == FALSE || trace_file == NULL || i != fileno(trace_file) ) + if ( debug == TRUE ) + if ( trace_file != NULL ) + if ( i == fileno(trace_file) ) + continue; + + if ( logfile_file != NULL ) + if ( i == fileno(logfile_file) ) + continue; + + if ( pid_file != NULL ) + if ( i == fileno(pid_file) ) + continue; + close ( i ); } @@ -476,6 +526,15 @@ fileno(stdin), fileno(stdout), fileno(stderr), i, rslt, msg_out ); #endif /* not _DEBUG */ + if ( logfile_file != NULL ) + { + logit ( logfile_file, POP_DEBUG, HERE, + "Info %s%.*s%s version %s (non-standalone)", + QPOP_NAME, + (strlen(BANNERSFX)>0 ? 1 : 0), " ", + BANNERSFX, + VERSION ); + } /* * Set up the socket on which we listen @@ -531,9 +590,26 @@ /* * Now we're ready to go */ + /* 20020306 grg deleted extra newline msg ( HERE, "listening on %s:%d\n", inet_ntoa ( serv_addr.sin_addr ), ntohs ( serv_addr.sin_port ) ); + */ + msg ( HERE, "listening on %s:%d", + inet_ntoa ( serv_addr.sin_addr ), + ntohs ( serv_addr.sin_port ) ); + + /* + * Store our PID into a file, like a good unix daemon. + * We do this late in the game as we don't wish to overwrite that file + * if we cannot bind to a port. + */ + if ( pid_file != NULL ) + { + fprintf(pid_file, "%i", getpid()); + fclose(pid_file); + } + TRACE ( trace_file, POP_DEBUG, HERE, "listening using socket fd %d", sockfd ); @@ -579,6 +655,17 @@ fclose ( trace_file ); trace_file = NULL; } + if ( logfile_file != NULL ) + { + fclose ( logfile_file ); + logfile_file = NULL; + } + if ( pid_file != NULL ) + { + fclose ( pid_file ); + pid_file = NULL; + /* unlink ( pid_name ); -- don't, after chdir(/) may be bad */ + } exit ( 0 ); } @@ -610,11 +697,22 @@ newsockfd = accept ( sockfd, (struct sockaddr *) &cli_addr, &clilen ); TRACE ( trace_file, POP_DEBUG, HERE, + /* 20020305 grg delete extra newline "accept=%d; sockfd=%d; clilen=%d; cli_addr=%s:%d\n", + */ + "accept=%d; sockfd=%d; clilen=%d; cli_addr=%s:%d", newsockfd, sockfd, clilen, inet_ntoa ( cli_addr.sin_addr ), ntohs ( cli_addr.sin_port ) ); + if ( logfile_file != NULL) + { + logit( logfile_file, POP_INFO, HERE, + "Connection %s %d", + inet_ntoa ( cli_addr.sin_addr ), + ntohs ( cli_addr.sin_port ) ); + } + if ( newsockfd > 0 ) motherforker ( newsockfd, sockfd ); else @@ -706,6 +804,8 @@ fprintf ( err_out, "%s\n", msg_buf ); logit ( trace_file, POP_PRIORITY, fn, ln, "%s", msg_buf ); + if ( logfile_file != NULL) + logit ( logfile_file, POP_PRIORITY, fn, ln, "%s", msg_buf ); if ( Qargv_alloc ) { @@ -718,6 +818,17 @@ fclose ( trace_file ); trace_file = NULL; } + if ( logfile_file != NULL ) + { + fclose ( logfile_file ); + logfile_file = NULL; + } + if ( pid_file != NULL ) + { + fclose ( pid_file ); + pid_file = NULL; + /* unlink ( pid_name ); -- don't, after chdir(/) may be bad */ + } fflush ( err_out ); @@ -766,6 +877,8 @@ fprintf ( err_out, "%s\n", msg_buf ); logit ( trace_file, POP_PRIORITY, fn, ln, "%s", msg_buf ); + if ( logfile_file != NULL) + logit ( logfile_file, POP_PRIORITY, fn, ln, "%s", msg_buf ); fflush ( err_out ); } @@ -882,6 +995,73 @@ trace_name, fileno(trace_file) ); } + if ( logfile_file != NULL && logfile_name != NULL ) + { + TRACE ( trace_file, POP_DEBUG, HERE, "rolling over log file..." ); + fflush ( logfile_file ); + fclose ( logfile_file ); + + logfile_file = fopen ( logfile_name, "a" ); + if ( logfile_file == NULL ) + err_dump ( HERE, "Unable to open trace file '%s'", logfile_name ); + + TRACE ( trace_file, POP_DEBUG, HERE, "Opened log file \"%s\" as %d", + logfile_name, fileno(logfile_file) ); + } +} + + +/* + * Interprets what the user wants when placing a PID file. + */ +void pid_rewrite(char *result, char *file_guess) +{ + struct stat filestat; + int error = 0; + + strcpy(result,""); + + if (stat(file_guess,&filestat) == 0) /* if it exists... */ + { + if (S_ISDIR(filestat.st_mode)) + { /* a directory means that we must supply the filename */ + strncpy(result,file_guess,110); + strcat(result,"/"); + if (strstr(file_guess,pname) == NULL) + { + strcat(result,pname); + strcat(result,".pid"); + } + else + strcat(result,PIDFILE); + } + else if (S_ISREG(filestat.st_mode)) + strcpy(result,file_guess); + else /* goofy destinations like /dev/null */ + error = 1; + } else { + if (errno == ENOENT) /* does not exist, create it */ + { + if (strchr(file_guess,'/') == NULL) /* just a file, needs a dir */ + { + strcpy(result,PIDFILEDIR); + strcat(result,"/"); + strncat(result,file_guess,512); + } + else + strcpy(result,file_guess); + } + else + error = 1; + } + + + TRACE ( trace_file, POP_DEBUG, HERE, + "User wants to use PID file: \"%s\" Rewriting to: \"%s\"", + file_guess, result); + if (error) + TRACE ( trace_file, POP_DEBUG, HERE, + "ERROR, non-normal entity: \"%s\" ignoring option", file_guess); } @@ -961,6 +1141,12 @@ { fclose ( trace_file ); trace_file = NULL; + } + + if ( logfile_file != NULL ) + { + fclose ( logfile_file ); + logfile_file = NULL; } _exit ( 0 ); diff -urNB qpopper4.0.5/popper/pop_get_command.c qpopper4.0.5g26/popper/pop_get_command.c --- qpopper4.0.5/popper/pop_get_command.c Wed Mar 12 21:06:37 2003 +++ qpopper4.0.5g26/popper/pop_get_command.c Fri Mar 21 11:19:44 2003 @@ -78,7 +78,7 @@ /* * Save a copy of the original client line */ - if ( DEBUGGING && p->debug ) + if ( (DEBUGGING && p->debug) || p->logfile != NULL) strncpy(buf, mp, sizeof(buf)); /* @@ -103,6 +103,27 @@ buf [ len ] = '\0'; pop_log ( p, POP_DEBUG, HERE, "Received (%d): \"%s\"", len, buf ); + } + } + + /* + * We want these logged into the log file + */ + if ( p->logfile ) { + if ( strcmp ( p->pop_command, "pass" ) == 0 ) + logit ( p->logfile, POP_DEBUG, HERE, + "Recv %s@%s \"%s xxxxxxxxx\"", + p->user, p->ipaddr, p->pop_command ); + else { + int len = strlen(buf); + while ( len > 0 && + ( buf [ len - 1 ] == '\n' || buf [ len - 1 ] == '\r' ) ) + len--; + + buf [ len ] = '\0'; + logit ( p->logfile, POP_DEBUG, HERE, + "Recv %s@%s \"%s\"", + p->user, p->ipaddr, buf ); } } diff -urNB qpopper4.0.5/popper/pop_init.c qpopper4.0.5g26/popper/pop_init.c --- qpopper4.0.5/popper/pop_init.c Wed Mar 12 21:06:37 2003 +++ qpopper4.0.5g26/popper/pop_init.c Fri Mar 21 11:19:44 2003 @@ -663,6 +663,8 @@ #ifdef LOG_LOGIN p->pLog_login = "(v%0) POP login by user \"%1\" at (%2) %3"; +#else + p->pLog_login = NULL; #endif /* LOG_LOGIN */ StackInit ( & ( p->InProcess ) ); @@ -692,7 +694,7 @@ /* * Process command line arguments */ - while ( ( c = getopt ( argcount, argmessage, "b:BcCdD:e:f:FkK:l:L:p:RsSt:T:uUvy:") ) != EOF ) + while ( ( c = getopt ( argcount, argmessage, "b:BcCdD:e:f:FkK:l:L:o:p:RsSt:T:uUvy:z:") ) != EOF ) switch ( c ) { case 'b': /* Bulletins requested */ @@ -803,6 +805,29 @@ p->check_lock_refresh ); break; + case 'o': /* log file specified */ +#ifdef STANDALONE + { + extern FILE *logfile_file; + p->logfile = logfile_file; + } +#else /* not STANDALONE */ + p->logfile = fopen ( optarg, "a" ); +#endif /* STANDALONE */ + + if ( p->logfile == NULL ) { + pop_log ( p, POP_PRIORITY, HERE, + "Unable to open log file \"%s\": %s (%d)", + optarg, STRERROR(errno), errno ); + fprintf ( stderr, "Unable to open log file \"%s\": %s (%d)\n", + optarg, STRERROR(errno), errno ); + EXIT ( 1 ); + } + p->logfile_name = optarg; + DEBUG_LOG1 ( p, "Log destination is file \"%s\"", + p->logfile_name ); + break; + case 'p': /* Set clear text password handling */ pw_handling = atoi ( optarg ); switch ( pw_handling ) { @@ -920,6 +945,9 @@ errflag++; } + case 'z': /* PID file (handled in main.c) -- DO NOT USE */ + break; + default: /* Unknown option received */ errflag++; } @@ -982,6 +1010,7 @@ "%s" /* -K / kerberos service, if KERBEROS set */ "%s" /* -l / tls_support, if QPOP_SSL set */ "[-L lock refresh] " + "[-o log-file] " "%s" /* -p / plain-text passwd stuff, if APOP or SCRAM */ "[-R] " "[-s] " @@ -991,6 +1020,7 @@ "[-u] " "[-U] " "[-v] " + "[-z PID file] " "\n", argmessage[0], xB, /* -B (or not) */ @@ -1084,9 +1114,11 @@ */ ch = gethostbyaddr ( (char *) &cs.sin_addr, sizeof(cs.sin_addr), AF_INET ); if ( ch == NULL ) { +#if 0 /* we don't care */ pop_log ( p, POP_DEBUG, HERE, "(v%s) Unable to get canonical name of client %s: %s (%d)", VERSION, p->ipaddr, hstrerror(h_errno), h_errno ); +#endif p->client = p->ipaddr; } /* diff -urNB qpopper4.0.5/popper/pop_log.c qpopper4.0.5g26/popper/pop_log.c --- qpopper4.0.5/popper/pop_log.c Wed Mar 12 21:06:37 2003 +++ qpopper4.0.5g26/popper/pop_log.c Fri Mar 21 11:19:44 2003 @@ -138,7 +138,9 @@ lMsec = (tval.tv_usec + 500) / 1000; /* convert useconds to milliseconds */ fprintf ( p->trace, "%s.%03ld %.4s [%ld] %s\n", pDate, lMsec, pYear, (long) getpid(), msgbuf ); - fprintf ( p->trace, "%s.%03ld %.4s \n", pDate, lMsec, pYear ); + /* 20020304 grg delete extra line on every log message + fprintf ( p->trace, "%s.%03ld %.4s XXXX\n", pDate, lMsec, pYear ); + */ fflush ( p->trace ); } else { diff -urNB qpopper4.0.5/popper/pop_pass.c qpopper4.0.5g26/popper/pop_pass.c --- qpopper4.0.5/popper/pop_pass.c Wed Mar 12 21:06:37 2003 +++ qpopper4.0.5g26/popper/pop_pass.c Fri Mar 21 11:19:44 2003 @@ -460,7 +460,7 @@ return ( pop_msg ( p, POP_FAILURE, HERE, GP_ERRSTRING, p->user, pam_strerror(NULL, erc), erc ) ); } - pamerror = pam_authenticate ( pamh, 0 ); + pamerror = pam_authenticate ( pamh, PAM_SILENT ); /* * Need to reopen log after calling pam_authenticate, since diff -urNB qpopper4.0.5/popper/pop_updt.c qpopper4.0.5g26/popper/pop_updt.c --- qpopper4.0.5/popper/pop_updt.c Wed Jan 1 21:39:03 2003 +++ qpopper4.0.5g26/popper/pop_updt.c Fri Mar 21 11:19:44 2003 @@ -293,11 +293,21 @@ DEBUG_LOG0 ( p, "Checking to see if all messages were deleted" ); if ( p->bStats ) { + if ( p->logfile ) { + logit( p->logfile, POP_PRIORITY, HERE, + "Stats %s %d %ld %d %ld %s %s", + p->user, p->msgs_deleted, p->bytes_deleted, + p->msg_count - p->msgs_deleted, + p->drop_size - p->bytes_deleted, + p->client, p->ipaddr ); + } else { pop_log ( p, POP_PRIORITY, HERE, "Stats: %s %d %ld %d %ld %s %s", p->user, p->msgs_deleted, p->bytes_deleted, p->msg_count - p->msgs_deleted, p->drop_size - p->bytes_deleted, p->client, p->ipaddr ); + } + } if ( p->server_mode && p->dirty == FALSE ) { diff -urNB qpopper4.0.5/popper/popper.h qpopper4.0.5g26/popper/popper.h --- qpopper4.0.5/popper/popper.h Wed Mar 12 21:06:38 2003 +++ qpopper4.0.5g26/popper/popper.h Fri Mar 21 11:19:44 2003 @@ -587,6 +587,8 @@ buffer */ FILE * trace; /* Debugging trace file */ char * trace_name; /* Name of debugging trace file */ + FILE * logfile; /* Log file */ + char * logfile_name; /* Name of log file */ FILE * hold; /* In SERVER_MODE, this value holds the drop FILE */ CALLSTACK InProcess; /* Call Stack that holds the diff -urNB qpopper4.0.5/popper/version.h qpopper4.0.5g26/popper/version.h --- qpopper4.0.5/popper/version.h Wed Mar 12 21:06:38 2003 +++ qpopper4.0.5g26/popper/version.h Fri Mar 21 11:27:23 2003 @@ -13,7 +13,7 @@ * Current version of Qpopper */ -#define VERS_NUM "4.0.5" +#define VERS_NUM "4.0.5g26" #ifdef KERBEROS # ifdef KRB4