diff src/dnsbl.cpp @ 41:d95af8129dfa

updates for 3.2, changing file layout, add queueid to messages
author carl
date Mon, 05 Jul 2004 10:52:02 -0700
parents dc3d8d1aa2d2
children afcf403709ef
line wrap: on
line diff
--- a/src/dnsbl.cpp	Mon Jun 07 21:07:40 2004 -0700
+++ b/src/dnsbl.cpp	Mon Jul 05 10:52:02 2004 -0700
@@ -179,6 +179,8 @@
 static pthread_mutex_t  syslog_mutex;
 static pthread_mutex_t  resolve_mutex;
 
+struct mlfiPriv;
+
 
 ////////////////////////////////////////////////
 // helper to discard the strings and objects held by an ns_map
@@ -229,14 +231,7 @@
 ////////////////////////////////////////////////
 // syslog a message
 //
-static void my_syslog(char *text);
-static void my_syslog(char *text) {
-    pthread_mutex_lock(&syslog_mutex);
-        openlog("dnsbl", LOG_PID, LOG_MAIL);
-        syslog(LOG_NOTICE, "%s", text);
-        closelog();
-    pthread_mutex_unlock(&syslog_mutex);
-}
+static void my_syslog(mlfiPriv *priv, char *text);
 
 
 // include the content scanner
@@ -254,6 +249,7 @@
     map<DNSBLP, status> checked;    // status from those lists
     // message specific data
     char    *mailaddr;      // envelope from value
+    char    *queueid;       // sendmail queue id
     bool    authenticated;  // client authenticated? if so, suppress all dnsbl checks
     bool    have_whites;    // have at least one whitelisted recipient? need to accept content and remove all non-whitelisted recipients if it fails
     bool    only_whites;    // every recipient is whitelisted?
@@ -271,10 +267,11 @@
     pthread_mutex_unlock(&config_mutex);
     ip            = 0;
     mailaddr      = NULL;
+    queueid       = NULL;
     authenticated = false;
     have_whites   = false;
     only_whites   = true;
-    memory        = new recorder(&pc->html_tags, &pc->tlds);
+    memory        = new recorder(this, &pc->html_tags, &pc->tlds);
     scanner       = new url_scanner(memory);
 }
 mlfiPriv::~mlfiPriv() {
@@ -285,15 +282,17 @@
 }
 void mlfiPriv::reset(bool final) {
     if (mailaddr) free(mailaddr);
+    if (queueid)  free(queueid);
     discard(non_whites);
     delete memory;
     delete scanner;
     if (!final) {
         mailaddr      = NULL;
+        queueid       = NULL;
         authenticated = false;
         have_whites   = false;
         only_whites   = true;
-        memory        = new recorder(&pc->html_tags, &pc->tlds);
+        memory        = new recorder(this, &pc->html_tags, &pc->tlds);
         scanner       = new url_scanner(memory);
     }
 }
@@ -302,6 +301,27 @@
 
 
 ////////////////////////////////////////////////
+// syslog a message
+//
+static void my_syslog(mlfiPriv *priv, char *text) {
+    char buf[1000];
+    if (priv) {
+        snprintf(buf, sizeof(buf), "%s %s", priv->queueid, text);
+        text = buf;
+    }
+    pthread_mutex_lock(&syslog_mutex);
+        openlog("dnsbl", LOG_PID, LOG_MAIL);
+        syslog(LOG_NOTICE, "%s", text);
+        closelog();
+    pthread_mutex_unlock(&syslog_mutex);
+}
+
+static void my_syslog(char *text);
+static void my_syslog(char *text) {
+    my_syslog(NULL, text);
+}
+
+////////////////////////////////////////////////
 // register a global string
 //
 static char* register_string(char *name);
@@ -584,7 +604,7 @@
             else {
                 snprintf(buf, sizeof(buf), "host %s not found", host);
             }
-            my_syslog(buf);
+            my_syslog(&priv, buf);
         }
         if (ip) {
             status st = check_single(ip, dc.content_suffix);
@@ -615,7 +635,7 @@
             else {
                 snprintf(buf, sizeof(buf), "ns %s not found", host);
             }
-            my_syslog(buf);
+            my_syslog(&priv, buf);
         }
         if (ip) {
             status st = check_single(ip, dc.content_suffix);
@@ -631,7 +651,7 @@
     int bin = priv.memory->binary_tags;
     int bad = priv.memory->bad_html_tags;
     lim = priv.pc->tag_limit;
-    if (bin > bad) return oksofar;  // probably .zip or .tar.gz with random content
+    if (3*bin > bad) return oksofar;    // probably .zip or .tar.gz with random content
     if ((bad > lim) && (lim > 0)) return reject_tag;
     return oksofar;
 }
@@ -669,6 +689,7 @@
     status st = oksofar;
     mlfiPriv &priv = *MLFIPRIV;
     CONFIG &dc = *priv.pc;
+    if (!priv.queueid) priv.queueid = strdup(smfi_getsymval(ctx, "i");
     char *rcptaddr = rcpt[0];
     char *dnsname  = lookup(rcptaddr, dc.env_to_dnsbll);
     char *fromname = lookup(rcptaddr, dc.env_to_chkfrom);