Mercurial > dnsbl
diff src/context.cpp @ 178:d6531c702be3
embedded dcc filtering
author | carl |
---|---|
date | Thu, 04 Oct 2007 22:45:21 -0700 |
parents | e726e1a61ef9 |
children | 7a722f482bfb |
line wrap: on
line diff
--- a/src/context.cpp Sun Sep 30 10:27:14 2007 -0700 +++ b/src/context.cpp Thu Oct 04 22:45:21 2007 -0700 @@ -23,9 +23,12 @@ char *token_autowhite; char *token_black; +char *token_cctld; char *token_content; char *token_context; +char *token_dccbulk; char *token_dccfrom; +char *token_dccgrey; char *token_dccto; char *token_default; char *token_dnsbl; @@ -43,22 +46,24 @@ char *token_lbrace; char *token_mailhost; char *token_many; +char *token_no; char *token_off; +char *token_ok; char *token_ok2; -char *token_ok; char *token_on; char *token_rate; char *token_rbrace; +char *token_require; char *token_semi; char *token_soft; char *token_spamassassin; char *token_substitute; char *token_tld; -char *token_cctld; char *token_unknown; char *token_uribl; char *token_verify; char *token_white; +char *token_yes; char *token_myhostname; #ifndef HOST_NAME_MAX @@ -74,7 +79,7 @@ string_set all_strings; // owns all the strings, only modified by the config loader thread const int maxlen = 1000; // used for snprintf buffers -const int maxsmtp_age = 120;// smtp verify sockets older than this are ancient +const int maxsmtp_age = 60;// smtp verify sockets older than this are ancient const int maxauto_age = 600;// auto whitelister delay before flushing to file extern int NULL_SOCKET; const time_t ERROR_SMTP_SOCKET_TIME = 600; // number of seconds between attempts to open a socket to an smtp server @@ -697,6 +702,9 @@ tag_limit = (parent) ? parent->tag_limit : 0; tag_limit_message = NULL; spamassassin_limit = (parent) ? parent->spamassassin_limit : 0; + require_match = (parent) ? parent->require_match : false; + dcc_greylist = (parent) ? parent->dcc_greylist : false; + dcc_bulk_threshold = (parent) ? parent->dcc_bulk_threshold : 0; default_rcpt_rate = INT_MAX; } @@ -917,13 +925,19 @@ } -bool CONTEXT::acceptable_content(recorder &memory, int score, string& msg) { +bool CONTEXT::acceptable_content(recorder &memory, int score, int bulk, string& msg) { if (spamassassin_limit && (score > spamassassin_limit)) { char buf[maxlen]; snprintf(buf, sizeof(buf), "Mail rejected - spam assassin score %d", score); msg = string(buf); return false; } + if (dcc_bulk_threshold && (bulk > dcc_bulk_threshold)) { + char buf[maxlen]; + snprintf(buf, sizeof(buf), "Mail rejected - dcc score %d", bulk); + msg = string(buf); + return false; + } if (memory.excessive_bad_tags(tag_limit)) { msg = string(tag_limit_message); return false; @@ -1016,6 +1030,11 @@ printf("%s html_limit off; \n", indent); } printf("%s spamassassin %d; \n", indent, spamassassin_limit); + printf("%s require_match %s; \n", indent, (require_match) ? "yes" : "no"); + printf("%s dcc_greylist %s; \n", indent, (dcc_greylist) ? "yes" : "no"); + if (dcc_bulk_threshold == 0) printf("%s dcc_bulk_threshold off; \n", indent); + else if (dcc_bulk_threshold == 1000) printf("%s dcc_bulk_threshold many; \n", indent); + else printf("%s dcc_bulk_threshold %d; \n", indent, dcc_bulk_threshold); printf("%s }; \n", indent); spamass |= (spamassassin_limit != 0); } @@ -1214,16 +1233,6 @@ } if (!tsa(tok, token_semi)) return false; } - else if (have == token_cctld) { - if (!tsa(tok, token_lbrace)) return false; - while (true) { - char *have = tok.next(); - if (!have) break; - if (have == token_rbrace) break; // done - me.add_cctld(have); - } - if (!tsa(tok, token_semi)) return false; - } else if (have == token_tld) { if (!tsa(tok, token_lbrace)) return false; while (true) { @@ -1234,19 +1243,13 @@ } if (!tsa(tok, token_semi)) return false; } - else if (have == token_html_limit) { - have = tok.next(); - if (have == token_on) { - me.set_tag_limit(tok.nextint()); - me.set_tag_message(tok.next()); - } - else if (have == token_off) { - me.set_tag_limit(0); - me.set_tag_message(NULL); - } - else { - tok.token_error("on/off", have); - return false; + else if (have == token_cctld) { + if (!tsa(tok, token_lbrace)) return false; + while (true) { + char *have = tok.next(); + if (!have) break; + if (have == token_rbrace) break; // done + me.add_cctld(have); } if (!tsa(tok, token_semi)) return false; } @@ -1269,6 +1272,22 @@ } if (!tsa(tok, token_semi)) return false; } + else if (have == token_html_limit) { + have = tok.next(); + if (have == token_on) { + me.set_tag_limit(tok.nextint()); + me.set_tag_message(tok.next()); + } + else if (have == token_off) { + me.set_tag_limit(0); + me.set_tag_message(NULL); + } + else { + tok.token_error("on/off", have); + return false; + } + if (!tsa(tok, token_semi)) return false; + } else if (have == token_host_limit) { have = tok.next(); if (have == token_on) { @@ -1296,6 +1315,41 @@ me.set_spamassassin_limit(tok.nextint()); if (!tsa(tok, token_semi)) return false; } + else if (have == token_require) { + have = tok.next(); + if (have == token_yes) me.set_require(true); + else if (have == token_no) me.set_require(false); + else { + tok.token_error("yes/no", have); + return false; + } + if (!tsa(tok, token_semi)) return false; + } + else if (have == token_dccgrey) { + have = tok.next(); + if (have == token_yes) me.set_grey(true); + else if (have == token_no) me.set_grey(false); + else { + tok.token_error("yes/no", have); + return false; + } + if (!tsa(tok, token_semi)) return false; + } + else if (have == token_dccbulk) { + have = tok.next(); + if (have == token_off) me.set_bulk(0); + else if (have == token_many) me.set_bulk(1000); + else { + char *e; + long i = strtol(have, &e, 10); + if (*e != '\0') { + tok.token_error("integer", have); + return false; + } + me.set_bulk((int)i); + } + if (!tsa(tok, token_semi)) return false; + } else if (have == token_rbrace) { break; // done } @@ -1607,7 +1661,9 @@ token_cctld = register_string("cctld"); token_content = register_string("content"); token_context = register_string("context"); + token_dccbulk = register_string("dcc_bulk_threshold"); token_dccfrom = register_string("dcc_from"); + token_dccgrey = register_string("dcc_greylist"); token_dccto = register_string("dcc_to"); token_default = register_string("default"); token_dnsbl = register_string("dnsbl"); @@ -1625,12 +1681,14 @@ token_lbrace = register_string("{"); token_mailhost = register_string("mail_host"); token_many = register_string("many"); + token_no = register_string("no"); token_off = register_string("off"); token_ok = register_string("ok"); token_ok2 = register_string("ok2"); token_on = register_string("on"); token_rate = register_string("rate_limit"); token_rbrace = register_string("}"); + token_require = register_string("require_match"); token_semi = register_string(";"); token_soft = register_string("soft"); token_spamassassin = register_string("spamassassin"); @@ -1640,6 +1698,7 @@ token_uribl = register_string("uribl"); token_verify = register_string("verify"); token_white = register_string("white"); + token_yes = register_string("yes"); if (gethostname(myhostname, HOST_NAME_MAX+1) != 0) { strncpy(myhostname, "localhost", HOST_NAME_MAX+1);