Mercurial > dnsbl
diff src/dnsbl.cpp @ 163:97d7da45fe2a
spamassassin changes
author | carl |
---|---|
date | Sun, 26 Aug 2007 19:03:17 -0700 |
parents | c4bce911c276 |
children | 5809bcdc325b |
line wrap: on
line diff
--- a/src/dnsbl.cpp Sat Jul 14 12:25:17 2007 -0700 +++ b/src/dnsbl.cpp Sun Aug 26 19:03:17 2007 -0700 @@ -13,7 +13,7 @@ -c Check the config, and print a copy to stdout. Don't start the milter or do anything with the socket. -s Stress test by loading and deleting the current config in a loop. --d increase debug level +-d level set the debug level -e f|t Print the results of looking up from address f and to address t in the current config @@ -65,8 +65,10 @@ extern "C" { #include <libmilter/mfapi.h> sfsistat mlfi_connect(SMFICTX *ctx, char *hostname, _SOCK_ADDR *hostaddr); + sfsistat mlfi_helo(SMFICTX * ctx, char *helohost); sfsistat mlfi_envfrom(SMFICTX *ctx, char **argv); sfsistat mlfi_envrcpt(SMFICTX *ctx, char **argv); + sfsistat mlfi_header(SMFICTX* ctx, char* headerf, char* headerv); sfsistat mlfi_body(SMFICTX *ctx, u_char *data, size_t len); sfsistat mlfi_eom(SMFICTX *ctx); sfsistat mlfi_abort(SMFICTX *ctx); @@ -243,6 +245,7 @@ pthread_mutex_unlock(&config_mutex); get_fd(); ip = 0; + helo = NULL; mailaddr = NULL; queueid = NULL; authenticated = NULL; @@ -264,6 +267,7 @@ bool last = (!pc->reference_count) && (pc != config); pthread_mutex_unlock(&config_mutex); if (last) delete pc; // free this config, since we were the last reference to it + if (helo) free(helo); reset(true); } @@ -274,6 +278,7 @@ discard(env_to); if (memory) delete memory; if (scanner) delete scanner; + if (assassin) delete assassin; if (!final) { mailaddr = NULL; queueid = NULL; @@ -282,6 +287,7 @@ only_whites = true; memory = NULL; scanner = NULL; + assassin = NULL; content_suffix = NULL; content_message = NULL; uribl_suffix = NULL; @@ -428,6 +434,15 @@ } } +void my_syslog(mlfiPriv *priv, string text) { + if (debug_syslog > 3) { + char buf[maxlen]; + strncpy(buf, text.c_str(), sizeof(buf)); + buf[maxlen-1] = '\0'; // ensure null termination + my_syslog(priv, buf); + } +} + void my_syslog(char *text) { my_syslog(NULL, text); } @@ -935,12 +950,24 @@ return SMFIS_CONTINUE; } +sfsistat mlfi_helo(SMFICTX * ctx, char *helohost) +{ + mlfiPriv &priv = *MLFIPRIV; + priv.helo = strdup(helohost); + return SMFIS_CONTINUE; +} + sfsistat mlfi_envfrom(SMFICTX *ctx, char **from) { mlfiPriv &priv = *MLFIPRIV; priv.mailaddr = to_lower_string(from[0]); + priv.queueid = strdup(smfi_getsymval(ctx, "i")); priv.authenticated = smfi_getsymval(ctx, "{auth_authen}"); if (priv.authenticated) priv.authenticated = strdup(priv.authenticated); + priv.assassin = new SpamAssassin; + priv.assassin->mlfi_connect(&priv, priv.ip); + priv.assassin->mlfi_helo(priv.helo); + priv.assassin->mlfi_envfrom(priv.mailaddr, priv.queueid); return SMFIS_CONTINUE; } @@ -949,9 +976,9 @@ DNSBLP rejectlist = NULL; // list that caused the reject mlfiPriv &priv = *MLFIPRIV; CONFIG &dc = *priv.pc; - if (!priv.queueid) priv.queueid = strdup(smfi_getsymval(ctx, "i")); char *rcptaddr = rcpt[0]; char *loto = to_lower_string(rcptaddr); + priv.assassin->mlfi_envrcpt(ctx, loto); // priv.mailaddr sending original message to loto CONTEXT &con = *(dc.find_context(loto)->find_context(priv.mailaddr)); VERIFYP ver = con.find_verify(loto); @@ -1050,11 +1077,30 @@ return SMFIS_CONTINUE; } +sfsistat mlfi_header(SMFICTX* ctx, char* headerf, char* headerv) +{ + mlfiPriv &priv = *MLFIPRIV; + if (priv.authenticated) return SMFIS_CONTINUE; + if (priv.only_whites) return SMFIS_CONTINUE; + priv.assassin->mlfi_header(headerf, headerv); + return SMFIS_CONTINUE; +} + +sfsistat mlfi_eoh(SMFICTX* ctx) +{ + mlfiPriv &priv = *MLFIPRIV; + if (priv.authenticated) return SMFIS_CONTINUE; + if (priv.only_whites) return SMFIS_CONTINUE; + priv.assassin->mlfi_eoh(); + return SMFIS_CONTINUE; +} + sfsistat mlfi_body(SMFICTX *ctx, u_char *data, size_t len) { mlfiPriv &priv = *MLFIPRIV; if (priv.authenticated) return SMFIS_CONTINUE; if (priv.only_whites) return SMFIS_CONTINUE; + priv.assassin->mlfi_body(data, len); priv.scanner->scan(data, len); return SMFIS_CONTINUE; } @@ -1070,6 +1116,7 @@ // process end of message if (priv.authenticated || priv.only_whites) rc = SMFIS_CONTINUE; else { + int score = priv.assassin->mlfi_eom(); // assert env_to not empty char buf[maxlen]; char *msg = NULL; @@ -1079,8 +1126,8 @@ for (context_map::iterator i=priv.env_to.begin(); i!=priv.env_to.end(); i++) { char *rcpt = (*i).first; CONTEXT &con = *((*i).second); - if (!con.acceptable_content(*priv.memory, msg)) { - // bad html tags or excessive hosts + if (!con.acceptable_content(*priv.memory, score, msg)) { + // bad html tags or excessive hosts or high spam assassin score smfi_delrcpt(ctx, rcpt); } else { @@ -1152,11 +1199,11 @@ SMFI_VERSION, // version code -- do not change SMFIF_DELRCPT, // flags mlfi_connect, // connection info filter - NULL, // SMTP HELO command filter + mlfi_helo, // SMTP HELO command filter mlfi_envfrom, // envelope sender filter mlfi_envrcpt, // envelope recipient filter - NULL, // header filter - NULL, // end of header + mlfi_header, // header filter + mlfi_eoh, // end of header mlfi_body, // body block filter mlfi_eom, // end of message mlfi_abort, // message aborted @@ -1192,10 +1239,9 @@ // and reload when needed. // we also clear the SMTP AUTH recipient counts hourly // -void* config_loader(void *arg); +extern "C" {void* config_loader(void *arg);} void* config_loader(void *arg) { int loop = 0; - typedef set<CONFIG *> configp_set; while (loader_run) { sleep(180); // look for modifications every 3 minutes if (!loader_run) break; @@ -1268,13 +1314,6 @@ void setup_socket(char *sock); void setup_socket(char *sock) { unlink(sock); - // sockaddr_un addr; - // memset(&addr, '\0', sizeof addr); - // addr.sun_family = AF_UNIX; - // strncpy(addr.sun_path, sock, sizeof(addr.sun_path)-1); - // int s = socket(AF_UNIX, SOCK_STREAM, 0); - // bind(s, (sockaddr*)&addr, sizeof(addr)); - // close(s); }