Mercurial > dnsbl
comparison src/dnsbl.cpp @ 29:4dfdf33f1db0 stable-2-4
add syslog msg freeing memory, use bare tld names without leading period
author | carl |
---|---|
date | Thu, 27 May 2004 16:17:48 -0700 |
parents | 33e1e3910506 |
children | fc7f8f3ea90f |
comparison
equal
deleted
inserted
replaced
28:33e1e3910506 | 29:4dfdf33f1db0 |
---|---|
116 | 116 |
117 struct CONFIG { | 117 struct CONFIG { |
118 // the only mutable stuff once it has been loaded from the config file | 118 // the only mutable stuff once it has been loaded from the config file |
119 int reference_count; // protected by the global config_mutex | 119 int reference_count; // protected by the global config_mutex |
120 // all the rest is constant after loading from the config file | 120 // all the rest is constant after loading from the config file |
121 int generation; | |
121 time_t load_time; | 122 time_t load_time; |
122 string_list config_files; | 123 string_list config_files; |
123 dnsblp_map dnsbls; | 124 dnsblp_map dnsbls; |
124 dnsbllp_map dnsblls; | 125 dnsbllp_map dnsblls; |
125 from_map env_from; | 126 from_map env_from; |
136 CONFIG(); | 137 CONFIG(); |
137 ~CONFIG(); | 138 ~CONFIG(); |
138 }; | 139 }; |
139 CONFIG::CONFIG() { | 140 CONFIG::CONFIG() { |
140 reference_count = 0; | 141 reference_count = 0; |
142 generation = 0; | |
141 load_time = 0; | 143 load_time = 0; |
142 content_suffix = NULL; | 144 content_suffix = NULL; |
143 content_message = NULL; | 145 content_message = NULL; |
144 host_limit_message = NULL; | 146 host_limit_message = NULL; |
145 host_limit = 0; | 147 host_limit = 0; |
166 | 168 |
167 static bool debug_syslog = false; | 169 static bool debug_syslog = false; |
168 static bool loader_run = true; // used to stop the config loader thread | 170 static bool loader_run = true; // used to stop the config loader thread |
169 static string_set all_strings; // owns all the strings, only modified by the config loader thread | 171 static string_set all_strings; // owns all the strings, only modified by the config loader thread |
170 static CONFIG * config = NULL; // protected by the config_mutex | 172 static CONFIG * config = NULL; // protected by the config_mutex |
173 static int generation = 0; // protected by the config_mutex | |
171 | 174 |
172 static pthread_mutex_t config_mutex; | 175 static pthread_mutex_t config_mutex; |
173 static pthread_mutex_t syslog_mutex; | 176 static pthread_mutex_t syslog_mutex; |
174 static pthread_mutex_t resolve_mutex; | 177 static pthread_mutex_t resolve_mutex; |
175 | 178 |
491 for (string_set::iterator i=priv.memory->hosts.begin(); i!=priv.memory->hosts.end(); i++) { | 494 for (string_set::iterator i=priv.memory->hosts.begin(); i!=priv.memory->hosts.end(); i++) { |
492 count++; | 495 count++; |
493 int lim = priv.pc->host_limit; | 496 int lim = priv.pc->host_limit; |
494 if ((count > lim) && (lim > 0)) return reject_host; | 497 if ((count > lim) && (lim > 0)) return reject_host; |
495 host = *i; | 498 host = *i; |
499 ip = protected_dns_interface(host, true); | |
496 if (debug_syslog) { | 500 if (debug_syslog) { |
497 char buf[200]; | 501 char buf[200]; |
498 snprintf(buf, sizeof(buf), "looking for host %s", host); | 502 if (ip) { |
503 char adr[sizeof "255.255.255.255"]; | |
504 adr[0] = '\0'; | |
505 inet_ntop(AF_INET, (const u_char *)&ip, adr, sizeof(adr)); | |
506 snprintf(buf, sizeof(buf), "host %s found at %s", host, adr); | |
507 } | |
508 else { | |
509 snprintf(buf, sizeof(buf), "host %s not found", host); | |
510 } | |
499 my_syslog(buf); | 511 my_syslog(buf); |
500 } | 512 } |
501 ip = protected_dns_interface(host, true); | |
502 if (ip) { | 513 if (ip) { |
503 // if (debug_syslog) { | |
504 // char adr[sizeof "255.255.255.255"]; | |
505 // adr[0] = '\0'; | |
506 // inet_ntop(AF_INET, (const u_char *)&ip, adr, sizeof(adr)); | |
507 // char buf[200]; | |
508 // snprintf(buf, sizeof(buf), "found host %s at %s", host, adr); | |
509 // my_syslog(buf); | |
510 // } | |
511 status st = check_single(ip, dc.content_suffix); | 514 status st = check_single(ip, dc.content_suffix); |
512 if (st == reject) return st; | 515 if (st == reject) return st; |
513 } | 516 } |
514 } | 517 } |
515 host = NULL; | 518 host = NULL; |
875 if (cmd && (cmd[0] != '#') && (cmd[0] != '\0')) { | 878 if (cmd && (cmd[0] != '#') && (cmd[0] != '\0')) { |
876 // have a decent command | 879 // have a decent command |
877 bool processed = false; | 880 bool processed = false; |
878 switch (commands[cmd]) { | 881 switch (commands[cmd]) { |
879 case tld: { | 882 case tld: { |
880 char *tld = strtok(NULL, delim); | 883 char *tld = next_token(delim); |
881 if (!tld) break; // no tld value | 884 if (!tld) break; // no tld value |
882 char buf[200]; | 885 dc.tlds.insert(tld); |
883 snprintf(buf, sizeof(buf), ".%s", tld); | |
884 dc.tlds.insert(register_string(buf)); // leading . | |
885 processed = true; | 886 processed = true; |
886 } break; | 887 } break; |
887 | 888 |
888 case content: { | 889 case content: { |
889 char *suff = strtok(NULL, delim); | 890 char *suff = strtok(NULL, delim); |
1064 //////////////////////////////////////////////// | 1065 //////////////////////////////////////////////// |
1065 // reload the config | 1066 // reload the config |
1066 // | 1067 // |
1067 static CONFIG* new_conf(); | 1068 static CONFIG* new_conf(); |
1068 static CONFIG* new_conf() { | 1069 static CONFIG* new_conf() { |
1069 my_syslog("loading new configuration"); | |
1070 CONFIG *newc = new CONFIG; | 1070 CONFIG *newc = new CONFIG; |
1071 pthread_mutex_lock(&config_mutex); | |
1072 newc->generation = generation++; | |
1073 pthread_mutex_unlock(&config_mutex); | |
1074 char buf[200]; | |
1075 snprintf(buf, sizeof(buf), "loading configuration generation %d", newc->generation); | |
1076 my_syslog(buf); | |
1071 load_conf(*newc, "dnsbl.conf"); | 1077 load_conf(*newc, "dnsbl.conf"); |
1072 newc->load_time = time(NULL); | 1078 newc->load_time = time(NULL); |
1073 return newc; | 1079 return newc; |
1074 } | 1080 } |
1075 | 1081 |
1107 } | 1113 } |
1108 // now look for old configs with zero ref counts | 1114 // now look for old configs with zero ref counts |
1109 for (configp_set::iterator i=old_configs.begin(); i!=old_configs.end(); ) { | 1115 for (configp_set::iterator i=old_configs.begin(); i!=old_configs.end(); ) { |
1110 CONFIG *old = *i; | 1116 CONFIG *old = *i; |
1111 if (!old->reference_count) { | 1117 if (!old->reference_count) { |
1118 char buf[200]; | |
1119 snprintf(buf, sizeof(buf), "freeing memory for old configuration generation %d", old->generation); | |
1120 my_syslog(buf); | |
1112 delete old; // destructor does all the work | 1121 delete old; // destructor does all the work |
1113 old_configs.erase(i++); | 1122 old_configs.erase(i++); |
1114 } | 1123 } |
1115 else i++; | 1124 else i++; |
1116 } | 1125 } |