changeset 310:802e2b779ed1

enable smtp verify logging
author Carl Byington <carl@five-ten-sg.com>
date Sun, 18 Sep 2016 18:32:37 -0700
parents 358b764a862e
children f5547e7b3a09
files configure.in src/context.cpp src/context.h src/dnsbl.cpp src/dnsbl.h src/includes.h
diffstat 6 files changed, 22 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/configure.in	Wed Aug 03 08:28:31 2016 -0700
+++ b/configure.in	Sun Sep 18 18:32:37 2016 -0700
@@ -3,6 +3,7 @@
 AC_INIT(dnsbl,6.45,carl@five-ten-sg.com)
 AC_CONFIG_SRCDIR([config.h.in])
 AC_CONFIG_HEADER([config.h])
+AC_CONFIG_MACRO_DIR([m4])
 
 AM_INIT_AUTOMAKE($PACKAGE_NAME,$PACKAGE_VERSION)
 
--- a/src/context.cpp	Wed Aug 03 08:28:31 2016 -0700
+++ b/src/context.cpp	Sun Sep 18 18:32:37 2016 -0700
@@ -250,14 +250,14 @@
     void SMTP::log(const char *m, int v) {
         char buf[maxlen];
         snprintf(buf, maxlen, m, v);
-        my_syslog(buf);
+        my_syslog(queueid, buf);
     }
 
 
     void SMTP::log(const char *m, const char *v) {
         char buf[maxlen];
         snprintf(buf, maxlen, m, v);
-        my_syslog(buf);
+        my_syslog(queueid, buf);
     }
 #endif
 
@@ -371,11 +371,12 @@
 }
 
 
-bool VERIFY::ok(const char *from, const char *to) {
+bool VERIFY::ok(const char *queueid, const char *from, const char *to) {
     if (host == token_myhostname) return true;
     SMTP *conn = get_connection();
     if (!conn) return true;    // cannot verify right now, we have socket errors
     int rc;
+    conn->set_id(queueid);
     rc = conn->from(from);
     #ifdef VERIFY_DEBUG
         conn->log("verify::ok() from sees %d", rc);
--- a/src/context.h	Wed Aug 03 08:28:31 2016 -0700
+++ b/src/context.h	Sun Sep 18 18:32:37 2016 -0700
@@ -56,15 +56,17 @@
     char    efrom[maxlen];  // last envelope from sent on this socket
     int     pending;        // unread bytes in buffer, not including the null terminator
     char    buffer[maxlen];
+    const char  *queueid;   // last queueid for logging
 public:
     SMTP(int f)             {fd = f; error = false; now(); efrom[0] = '\0'; init();};
     ~SMTP()                 {if (!error) quit(); closefd();};
-    void    init()          {pending = 0; buffer[0] = '\0';};
+    void    init()          {pending = 0; buffer[0] = '\0'; queueid = NULL;};
     void    append(const char *c)   {strncat(buffer, c, max(0, maxlen-1-(int)strlen(c)));};
     bool    err()           {return error;};
     void    now()           {stamp = time(NULL);};
     time_t  get_stamp()     {return stamp;};
     int     get_fd()        {return fd;};
+    void    set_id(const char *id)  {queueid = id;};
     int     writer();
     int     reader();
     int     read_line();
@@ -78,8 +80,8 @@
     int     quit();
     void    closefd();
 #ifdef VERIFY_DEBUG
-    static void log(const char *m, int v);
-    static void log(const char *m, const char *v);
+    void log(const char *m, int v);
+    void log(const char *m, const char *v);
 #endif
 };
 
@@ -93,7 +95,7 @@
     void    closer();           // if the oldest socket is ancient, close it
     SMTP    *get_connection();
     void    put_connection(SMTP *conn);
-    bool    ok(const char *from, const char *to);
+    bool    ok(const char *queueid, const char *from, const char *to);
 };
 
 class WHITELISTER {
--- a/src/dnsbl.cpp	Wed Aug 03 08:28:31 2016 -0700
+++ b/src/dnsbl.cpp	Sun Sep 18 18:32:37 2016 -0700
@@ -748,10 +748,10 @@
 ////////////////////////////////////////////////
 // syslog a message
 //
-void my_syslog(mlfiPriv *priv, const char *text) {
+void my_syslog(const char *queueid, const char *text) {
     char buf[maxlen];
-    if (priv) {
-        snprintf(buf, sizeof(buf), "%s: %s", priv->queueid, text);
+    if (queueid) {
+        snprintf(buf, sizeof(buf), "%s: %s", queueid, text);
         text = buf;
     }
     if (use_syslog) {
@@ -768,6 +768,11 @@
     }
 }
 
+void my_syslog(mlfiPriv *priv, const char *text) {
+    if (priv) my_syslog(priv->queueid, text);
+    else      my_syslog((const char *)NULL, text);
+}
+
 void my_syslog(mlfiPriv *priv, const string text) {
     if (debug_syslog > 3) {
         char buf[maxlen];
@@ -778,7 +783,7 @@
 }
 
 void my_syslog(const char *text) {
-    my_syslog(NULL, text);
+    my_syslog((const char *)NULL, text);
 }
 
 
@@ -1338,7 +1343,7 @@
     if (ver) {
         // try to verify this from/to pair of addresses even if it might be explicitly whitelisted
         const char *loto = to_lower_string(rcptaddr);
-        bool rc = ver->ok(priv.mailaddr, loto);
+        bool rc = ver->ok(priv.queueid, priv.mailaddr, loto);
         free((void*)loto);
         if (!rc) {
             smfi_setreply(ctx, (char*)"550", (char*)"5.7.1", (char*)"no such user");
--- a/src/dnsbl.h	Wed Aug 03 08:28:31 2016 -0700
+++ b/src/dnsbl.h	Sun Sep 18 18:32:37 2016 -0700
@@ -78,6 +78,7 @@
     void need_content_filter(const char *rcpt, CONTEXT &con);
 };
 
+void my_syslog(const char *queueid, const char *text);
 void my_syslog(mlfiPriv *priv, const char *text);
 void my_syslog(mlfiPriv *priv, const string text);
 void my_syslog(const char *text);
--- a/src/includes.h	Wed Aug 03 08:28:31 2016 -0700
+++ b/src/includes.h	Sun Sep 18 18:32:37 2016 -0700
@@ -8,7 +8,6 @@
 
 #define VERIFY_DEBUG   1
 #define RESOLVER_DEBUG 1
-#undef	VERIFY_DEBUG
 #undef	RESOLVER_DEBUG
 
 #ifdef HAVE_CONFIG_H