Package: ssmtp Version: 2.61-12 Tags: patch Severity: wishlist Hi. Included below is a patch to configure logging in ssmtp. It adds the option of setting 'log_level' via the config file.
This patch also makes a minor change in the way logging behaves: - Setting "loglevel=1" in ssmtp.conf will cause the SMTP dialog to be syslogged but the message contents (from "DATA" to the final ".") will not be syslogged. This setting can be used to keep track of SMTP sessions. - Setting "loglevel=2" in ssmtp.conf will cause both the SMTP dialog and the message contents to be syslogged. This setting can be used for full debugging. Hope this helps. P Kern U Toronto, CNS. ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- --- ssmtp.c 2007/05/04 18:00:29 1.1 +++ ssmtp.c 2007/05/04 18:50:42 @@ -814,6 +814,13 @@ log_event(LOG_INFO, "Set Root=\"%s\"\n", root); } } + else if(strcasecmp(p, "LogLevel") == 0) { + log_level = atoi(q); + + if(log_level > 0) { + log_event(LOG_INFO, "Set LogLevel=\"%d\"\n", log_level); + } + } else if(strcasecmp(p, "MailHub") == 0) { if((mailhost = strdup(q)) == (char *)NULL) { die("parse_config() -- strdup() failed"); @@ -1193,16 +1200,16 @@ if(fd_gets(response, BUF_SZ, fd) == NULL) { return(0); } - } - while(response[3] == '-'); - if(log_level > 0) { - log_event(LOG_INFO, "%s\n", response); - } + if(log_level > 0) { + log_event(LOG_INFO, "%s\n", response); + } - if(minus_v) { - (void)fprintf(stderr, "[<-] %s\n", response); + if(minus_v) { + (void)fprintf(stderr, "[<-] %s\n", response); + } } + while(response[3] == '-'); return(atoi(response) / 100); } @@ -1282,6 +1289,8 @@ int i, sock; uid_t uid; + int old_log_level; + uid = getuid(); if((pw = getpwuid(uid)) == (struct passwd *)NULL) { die("Could not find password entry for UID %d", uid); @@ -1442,6 +1451,15 @@ smtp_write(sock, "DATA"); (void)alarm((unsigned) MEDWAIT); + /* + * log_level hack: + * + * if log_level <= 1, message contents will not be logged. + * if log_level > 1, message contents _will_ be logged. + */ + old_log_level = log_level; + log_level--; + if(smtp_read(sock, buf) != 3) { /* Oops, we were expecting "354 send your data" */ die("%s", buf); @@ -1484,6 +1502,8 @@ (void)alarm((unsigned) MEDWAIT); } /* End of body */ + + log_level = old_log_level; /* Undo log_level hack. */ smtp_write(sock, "."); (void)alarm((unsigned) MAXWAIT); ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]