# HG changeset patch # User carl # Date 1082577149 25200 # Node ID 7e1eb343a8256224837b3f4deec4cb23edf7ef01 # Parent 9bcd5ef112798ceaa2462c83b773c89d3a75e150 updates to use dcc conf files diff -r 9bcd5ef11279 -r 7e1eb343a825 src/dnsbl.cpp --- a/src/dnsbl.cpp Tue Apr 20 22:11:14 2004 -0700 +++ b/src/dnsbl.cpp Wed Apr 21 12:52:29 2004 -0700 @@ -73,12 +73,6 @@ sfsistat mlfi_close(SMFICTX *ctx); } -#ifndef bool -# define bool int -# define TRUE 1 -# define FALSE 0 -#endif /* ! bool */ - struct ltstr { bool operator()(char* s1, char* s2) const { return strcmp(s1, s2) < 0; @@ -153,6 +147,8 @@ #define DEFAULT "default" #define WHITE "white" #define BLACK "black" +#define OK "ok" +#define MANY "many" //////////////////////////////////////////////// @@ -494,23 +490,22 @@ static void dumpit(from_map map); static void dumpit(from_map map) { - fprintf(stderr, "\n"); for (from_map::iterator i=map.begin(); i!=map.end(); i++) { - fprintf(stderr, "envfrom map %s\n", (*i).first); + char buf[2000]; + snprintf(buf, sizeof(buf), "envelope from map for %s", (*i).first); string_map *sm = (*i).second; - dumpit("envelope from", *sm); + dumpit(buf, *sm); } } -static void dumpit(); -static void dumpit() { - CONFIG &dc = *config; - fprintf(stderr, "dnsbls\n"); +static void dumpit(CONFIG &dc); +static void dumpit(CONFIG &dc) { + fprintf(stderr, "\ndnsbls\n"); for (dnsblp_map::iterator i=dc.dnsbls.begin(); i!=dc.dnsbls.end(); i++) { fprintf(stderr, "%s %s %s\n", (*i).first, (*i).second->suffix, (*i).second->message); } - fprintf(stderr, "dnsbl_lists\n"); + fprintf(stderr, "\ndnsbl_lists\n"); for (dnsbllp_map::iterator i=dc.dnsblls.begin(); i!=dc.dnsblls.end(); i++) { char *name = (*i).first; DNSBLL &dl = *((*i).second); @@ -521,22 +516,110 @@ } fprintf(stderr, "\n"); } + fprintf(stderr, "\nfiles\n"); + for (string_list::iterator i=dc.config_files.begin(); i!=dc.config_files.end(); i++) { + char *f = *i; + fprintf(stderr, "config includes %s\n", f); + } +} + + +//////////////////////////////////////////////// +// check for redundant or recursive include files +// +static bool ok_to_include(CONFIG &dc, char *fn); +static bool ok_to_include(CONFIG &dc, char *fn) { + if (!fn) return false; + bool ok = true; + for (string_list::iterator i=dc.config_files.begin(); i!=dc.config_files.end(); i++) { + char *f = *i; + if (strcmp(f, fn) == 0) { + my_syslog("redundant or recursive include file detected"); + ok = false; + break; + } + } + return ok; } //////////////////////////////////////////////// // load a single config file // +static void load_conf_dcc(CONFIG &dc, char *name, char *fn); +static void load_conf_dcc(CONFIG &dc, char *name, char *fn) { + dc.config_files.push_back(fn); + char *list = BLACK; + const int LINE_SIZE = 2000; + ifstream is(fn); + if (is.fail()) return; + char line[LINE_SIZE]; + char *delim = " \t"; + int curline = 0; + while (!is.eof()) { + is.getline(line, LINE_SIZE); + curline++; + int n = strlen(line); + if (!n) continue; + for (int i=0; i commands; - enum {dummy, dnsbl, dnsbll, envfrom, envto, include}; + enum {dummy, dnsbl, dnsbll, envfrom, envto, include, includedcc}; commands["dnsbl" ] = dnsbl; commands["dnsbl_list"] = dnsbll; commands["env_from" ] = envfrom; commands["env_to" ] = envto; commands["include" ] = include; + commands["include_dcc"] = includedcc; const int LINE_SIZE = 2000; ifstream is(fn); if (is.fail()) return; @@ -636,20 +719,19 @@ case include: { char *fn = next_token(delim); - if (fn) { - bool ok = true; - for (string_list::iterator i=dc.config_files.begin(); i!=dc.config_files.end(); i++) { - char *f = *i; - if (strcmp(f, fn) == 0) { - my_syslog("recursive include file detected"); - ok = false; - break; - } - } - if (ok) { + if (ok_to_include(dc, fn)) { load_conf(dc, fn); processed = true; } + } break; + + case includedcc: { + char *name = next_token(delim); + if (!name) break; + char *fn = next_token(delim); + if (ok_to_include(dc, fn)) { + load_conf_dcc(dc, name, fn); + processed = true; } } break; @@ -710,10 +792,6 @@ CONFIG *old = config; config = newc; pthread_mutex_unlock(&config_mutex); - // dumpit(env_from); - // dumpit("envelope to dnsbl", env_to_dnsbl); - // dumpit("envelope to check from", env_to_chkfrom); - // dumpit(); if (old) old_configs.insert(old); } // now look for old configs with zero ref counts @@ -741,9 +819,10 @@ int main(int argc, char**argv) { - bool setconn = FALSE; + bool check = false; + bool setconn = false; int c; - const char *args = "p:s:h"; + const char *args = "p:t:hc"; extern char *optarg; // Process command line options @@ -761,7 +840,7 @@ if (strncasecmp(optarg, "unix:", 5) == 0) unlink(optarg + 5); else if (strncasecmp(optarg, "local:", 6) == 0) unlink(optarg + 6); - setconn = TRUE; + setconn = true; break; case 't': @@ -775,6 +854,10 @@ } break; + case 'c': + check = true; + break; + case 'h': default: usage(argv[0]); @@ -791,6 +874,15 @@ exit(EX_UNAVAILABLE); } + if (check) { + CONFIG &dc = *new_conf(); + dumpit(dc.env_from); + dumpit("envelope to (dnsbl list)", dc.env_to_dnsbll); + dumpit("envelope to (from map)", dc.env_to_chkfrom); + dumpit(dc); + return 0; + } + // switch to background mode if (daemon(1,0) < 0) { fprintf(stderr, "daemon() call failed\n"); @@ -821,5 +913,5 @@ fclose(f); } - int rc = smfi_main(); + return smfi_main(); }