Mercurial > dnsbl
changeset 311:f5547e7b3a09
enable smtp verify logging
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Mon, 19 Sep 2016 09:11:30 -0700 |
parents | 802e2b779ed1 |
children | 9c71faaae576 |
files | ChangeLog NEWS configure.in src/context.cpp src/context.h src/dnsbl.cpp src/includes.h |
diffstat | 7 files changed, 36 insertions(+), 34 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Sun Sep 18 18:32:37 2016 -0700 +++ b/ChangeLog Mon Sep 19 09:11:30 2016 -0700 @@ -1,3 +1,6 @@ +6.46 2016-09-18 + Enable smtp verify logging + 6.45 2015-04-09 Add bitcoin donation address
--- a/NEWS Sun Sep 18 18:32:37 2016 -0700 +++ b/NEWS Mon Sep 19 09:11:30 2016 -0700 @@ -1,3 +1,4 @@ +6.46 2016-09-18 Enable smtp verify logging 6.45 2015-04-09 Add bitcoin donation address 6.44 2014-10-13 Generic regex now matches against the reverse dns PTR value 6.43 2014-07-18 Allow broken SRS0+ rather than the correct SRS0= tag.
--- a/configure.in Sun Sep 18 18:32:37 2016 -0700 +++ b/configure.in Mon Sep 19 09:11:30 2016 -0700 @@ -1,6 +1,6 @@ AC_PREREQ(2.59) -AC_INIT(dnsbl,6.45,carl@five-ten-sg.com) +AC_INIT(dnsbl,6.46,carl@five-ten-sg.com) AC_CONFIG_SRCDIR([config.h.in]) AC_CONFIG_HEADER([config.h]) AC_CONFIG_MACRO_DIR([m4])
--- a/src/context.cpp Sun Sep 18 18:32:37 2016 -0700 +++ b/src/context.cpp Mon Sep 19 09:11:30 2016 -0700 @@ -175,6 +175,7 @@ flush_line(r); continue; } + log("read_response() sees line with %s", buffer); return atoi(buffer); } return 0; @@ -216,6 +217,7 @@ if (strncmp(efrom, f, maxlen)) { rset(); strncpy(efrom, f, maxlen); + efrom[maxlen-1] = '\0'; // ensure null termination init(); append("MAIL FROM:<"); if (*f != '<') append(f); @@ -246,7 +248,6 @@ } -#ifdef VERIFY_DEBUG void SMTP::log(const char *m, int v) { char buf[maxlen]; snprintf(buf, maxlen, m, v); @@ -259,7 +260,6 @@ snprintf(buf, maxlen, m, v); my_syslog(queueid, buf); } -#endif //////////////////////////////////////////////// @@ -304,11 +304,12 @@ } -SMTP* VERIFY::get_connection() { +SMTP* VERIFY::get_connection(const char *queueid) { SMTP *conn = NULL; pthread_mutex_lock(&mutex); if (!connections.empty()) { conn = connections.front(); + conn->set_id(queueid); connections.pop_front(); #ifdef VERIFY_DEBUG conn->log("get_connection() %d from cache", conn->get_fd()); @@ -341,10 +342,13 @@ } if (sock != NULL_SOCKET) { conn = new SMTP(sock); + conn->set_id(queueid); #ifdef VERIFY_DEBUG conn->log("get_connection() %d new socket", conn->get_fd()); #endif - if (conn->helo() == 250) return conn; + int rc = conn->helo(); + conn->log("verify::get_connection() helo sees %d", rc); + if (rc == 250) return conn; delete conn; } return NULL; @@ -373,23 +377,17 @@ bool VERIFY::ok(const char *queueid, const char *from, const char *to) { if (host == token_myhostname) return true; - SMTP *conn = get_connection(); + SMTP *conn = get_connection(queueid); 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); - #endif if (rc != 250) { - conn->rset(); put_connection(conn); return (rc >= 500) ? false : true; } rc = conn->rcpt(to); - #ifdef VERIFY_DEBUG conn->log("verify::ok() rcpt sees %d", rc); - #endif put_connection(conn); return (rc >= 500) ? false : true; }
--- a/src/context.h Sun Sep 18 18:32:37 2016 -0700 +++ b/src/context.h Mon Sep 19 09:11:30 2016 -0700 @@ -50,23 +50,24 @@ class SMTP { static const int maxlen = 1000; + static const int qlen = 20; int fd; bool error; time_t stamp; 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 + char queueid[qlen]; // last queueid for logging public: - SMTP(int f) {fd = f; error = false; now(); efrom[0] = '\0'; init();}; + SMTP(int f) {fd = f; error = false; now(); efrom[0] = '\0'; queueid[0] = '\0'; init();}; ~SMTP() {if (!error) quit(); closefd();}; - void init() {pending = 0; buffer[0] = '\0'; queueid = NULL;}; + void init() {pending = 0; buffer[0] = '\0';}; 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;}; + void set_id(const char *id) {strncpy(queueid, id, qlen); queueid[qlen-1] = '\0';}; int writer(); int reader(); int read_line(); @@ -79,10 +80,8 @@ int rcpt(const char *t); int quit(); void closefd(); -#ifdef VERIFY_DEBUG void log(const char *m, int v); void log(const char *m, const char *v); -#endif }; class VERIFY { @@ -93,7 +92,7 @@ public: VERIFY(const char *h); void closer(); // if the oldest socket is ancient, close it - SMTP *get_connection(); + SMTP *get_connection(const char *queueid); void put_connection(SMTP *conn); bool ok(const char *queueid, const char *from, const char *to); };
--- a/src/dnsbl.cpp Sun Sep 18 18:32:37 2016 -0700 +++ b/src/dnsbl.cpp Mon Sep 19 09:11:30 2016 -0700 @@ -750,7 +750,7 @@ // void my_syslog(const char *queueid, const char *text) { char buf[maxlen]; - if (queueid) { + if (queueid && queueid[0]) { snprintf(buf, sizeof(buf), "%s: %s", queueid, text); text = buf; }