# HG changeset patch # User carl # Date 1121838435 25200 # Node ID c1280cd3e2483af81e387dbbef56daea3f80807d # Parent 7e4a90e5f213a4f4a3f33eb8269157370cdddedb add multiple debug syslog levels, remove duplicate dnsbl definitions diff -r 7e4a90e5f213 -r c1280cd3e248 dnsbl.rc --- a/dnsbl.rc Sun Jul 17 08:56:33 2005 -0700 +++ b/dnsbl.rc Tue Jul 19 22:47:15 2005 -0700 @@ -22,7 +22,7 @@ echo -n "Starting dnsbl-milter: " if [ ! -f /var/lock/subsys/dnsbl ]; then cd /etc/dnsbl # conf file is here - /usr/sbin/dnsbl -d -r /var/run/dnsbl/dnsbl.resolver.sock -p local:/var/run/dnsbl/dnsbl.sock + /usr/sbin/dnsbl -d 10 -r /var/run/dnsbl/dnsbl.resolver.sock -p local:/var/run/dnsbl/dnsbl.sock RETVAL=$? pid=`pidof -s /usr/sbin/dnsbl` if [ $pid ] diff -r 7e4a90e5f213 -r c1280cd3e248 src/context.cpp --- a/src/context.cpp Sun Jul 17 08:56:33 2005 -0700 +++ b/src/context.cpp Tue Jul 19 22:47:15 2005 -0700 @@ -52,6 +52,13 @@ } +bool DNSBL::operator==(const DNSBL &rhs) { + return (strcmp(name, rhs.name) == 0) && + (strcmp(suffix, rhs.suffix) == 0) && + (strcmp(message, rhs.message) == 0); +} + + CONFIG::CONFIG() { reference_count = 0; generation = 0; @@ -96,6 +103,7 @@ return; // don't take over user@ entries from your ancestors children } if ((c != con) && (c != con->get_parent())) { + if (debug_syslog) { char oldname[maxlen]; char newname[maxlen]; char *oldn = c->get_full_name(oldname, maxlen); @@ -105,6 +113,7 @@ my_syslog(buf); } } + } env_to[to] = con; } @@ -457,8 +466,14 @@ char *suf = tok.next(); char *msg = tok.next(); if (!tsa(tok, token_semi)) return false; - DNSBLP dns = new DNSBL(name, suf, msg); - me.add_dnsbl(name, dns); + DNSBLP dnsnew = new DNSBL(name, suf, msg); + DNSBLP dnsold = me.find_dnsbl(name); + if (dnsold && (*dnsold == *dnsnew)) { + // duplicate redefinition, ignore it + delete dnsnew; + return true; + } + me.add_dnsbl(name, dnsnew); return true; } diff -r 7e4a90e5f213 -r c1280cd3e248 src/context.h --- a/src/context.h Sun Jul 17 08:56:33 2005 -0700 +++ b/src/context.h Tue Jul 19 22:47:15 2005 -0700 @@ -30,6 +30,7 @@ char *suffix; // blacklist suffix like blackholes.five-ten-sg.com char *message; // error message with one or two %s operators for the ip address replacement DNSBL(char *n, char *s, char *m); + bool operator==(const DNSBL &rhs); }; class CONTEXT { diff -r 7e4a90e5f213 -r c1280cd3e248 src/dnsbl.cpp --- a/src/dnsbl.cpp Sun Jul 17 08:56:33 2005 -0700 +++ b/src/dnsbl.cpp Tue Jul 19 22:47:15 2005 -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 Add debug syslog entries +-d increase debug level -e f|t Print the results of looking up from address f and to address t in the current config @@ -81,7 +81,7 @@ void sig_chld(int signo); } -bool debug_syslog = false; +int debug_syslog = 0; bool syslog_opened = false; bool use_syslog = true; // false to printf bool loader_run = true; // used to stop the config loader thread @@ -673,15 +673,17 @@ if ((cnt > limit) && (limit > 0) && random) { int r = rand() % cnt; if (r >= limit) { + if (debug_syslog > 2) { char buf[maxlen]; snprintf(buf, sizeof(buf), "host %s skipped", host); my_syslog(&priv, buf); + } continue; } } count++; ip = dns_interface(priv, host, true, &nameservers); - if (debug_syslog) { + if (debug_syslog > 2) { char buf[maxlen]; if (ip) { char adr[sizeof "255.255.255.255"]; @@ -714,7 +716,7 @@ host = (*i).first; // a transient reference that needs to be replaced before we return it ip = (*i).second; if (!ip) ip = dns_interface(priv, host, false, NULL); - if (debug_syslog) { + if (debug_syslog > 2) { char buf[maxlen]; if (ip) { char adr[sizeof "255.255.255.255"]; @@ -803,7 +805,7 @@ char *rcptaddr = rcpt[0]; char *loto = to_lower_string(rcptaddr); CONTEXT &con = *(dc.find_context(loto)->find_context(priv.mailaddr)); - if (debug_syslog) { + if (debug_syslog > 1) { char buf[maxlen]; char msg[maxlen]; snprintf(msg, sizeof(msg), "from <%s> to <%s> using context %s", priv.mailaddr, loto, con.get_full_name(buf,maxlen)); @@ -967,9 +969,11 @@ pthread_mutex_lock(&config_mutex); newc->generation = generation++; pthread_mutex_unlock(&config_mutex); + if (debug_syslog) { char buf[maxlen]; snprintf(buf, sizeof(buf), "loading configuration generation %d", newc->generation); my_syslog(buf); + } if (load_conf(*newc, "dnsbl.conf")) { newc->load_time = time(NULL); return newc; @@ -1014,9 +1018,11 @@ for (configp_set::iterator i=old_configs.begin(); i!=old_configs.end(); ) { CONFIG *old = *i; if (!old->reference_count) { + if (debug_syslog) { char buf[maxlen]; snprintf(buf, sizeof(buf), "freeing memory for old configuration generation %d", old->generation); my_syslog(buf); + } delete old; // destructor does all the work old_configs.erase(i++); } @@ -1030,7 +1036,7 @@ void usage(char *prog); void usage(char *prog) { - fprintf(stderr, "Usage: %s [-d] [-c] [-s] [-e from|to] -r port -p sm-sock-addr [-t timeout]\n", prog); + fprintf(stderr, "Usage: %s [-d [level]] [-c] [-s] [-e from|to] -r port -p sm-sock-addr [-t timeout]\n", prog); fprintf(stderr, "where port is for the connection to our own dns resolver processes\n"); fprintf(stderr, " and should be local-domain-socket-file-name\n"); fprintf(stderr, "where sm-sock-addr is for the connection to sendmail\n"); @@ -1040,7 +1046,7 @@ fprintf(stderr, "-c will load and dump the config to stdout\n"); fprintf(stderr, "-s will stress test the config loading code by repeating the load/free cycle\n"); fprintf(stderr, " in an infinte loop.\n"); - fprintf(stderr, "-d will add some syslog debug messages\n"); + fprintf(stderr, "-d will set the syslog message level, currently 0 to 3"); fprintf(stderr, "-e will print the results of looking up the from and to addresses in the\n"); fprintf(stderr, " current config. The | character is used to separate the from and to\n"); fprintf(stderr, " addresses in the argument to the -e switch\n"); @@ -1084,7 +1090,7 @@ bool setreso = false; char *email = NULL; int c; - const char *args = "r:p:t:e:cdhs"; + const char *args = "r:p:t:e:d:chs"; extern char *optarg; // Process command line options @@ -1139,7 +1145,8 @@ break; case 'd': - debug_syslog = true; + if (optarg == NULL || *optarg == '\0') debug_syslog = 1; + else debug_syslog = atoi(optarg); break; case 'h': @@ -1151,7 +1158,7 @@ if (check) { use_syslog = false; - debug_syslog = true; + debug_syslog = 10; CONFIG *conf = new_conf(); if (conf) { conf->dump(); @@ -1313,9 +1320,7 @@ // this is the worker process // child does not need the listening socket close(resolver_socket); - //my_syslog("child forked a worker process"); process_resolver_requests(s); - //my_syslog("child terminated a worker process"); exit(0); } else { diff -r 7e4a90e5f213 -r c1280cd3e248 src/dnsbl.h --- a/src/dnsbl.h Sun Jul 17 08:56:33 2005 -0700 +++ b/src/dnsbl.h Tue Jul 19 22:47:15 2005 -0700 @@ -3,7 +3,7 @@ #include "context.h" -extern bool debug_syslog; +extern int debug_syslog; class recorder; class url_scanner; diff -r 7e4a90e5f213 -r c1280cd3e248 src/scanner.cpp --- a/src/scanner.cpp Sun Jul 17 08:56:33 2005 -0700 +++ b/src/scanner.cpp Tue Jul 19 22:47:15 2005 -0700 @@ -1163,7 +1163,7 @@ string_set::iterator i = html_tags->find(tag); if (i == html_tags->end()) { bad_html_tags++; - if (debug_syslog && (bad_html_tags < 10)) { + if ((debug_syslog > 2) && (bad_html_tags < 10)) { // only log the first 10 bad tags char buf[200]; snprintf(buf, sizeof(buf), "bad html tag %s", tag);