Mercurial > dnsbl
annotate src/context.cpp @ 140:4028de9b46dd
cleanup smtp rate limit code
author | carl |
---|---|
date | Wed, 27 Sep 2006 08:00:13 -0700 |
parents | f4746d8a12a3 |
children | 6256cab02248 |
rev | line source |
---|---|
94 | 1 /* |
2 | |
3 Copyright (c) 2004 Carl Byington - 510 Software Group, released under | |
4 the GPL version 2 or any later version at your choice available at | |
5 http://www.fsf.org/licenses/gpl.txt | |
6 | |
7 */ | |
8 | |
9 #include "includes.h" | |
10 | |
11 // needed for socket io | |
96
1edd4e8d3a60
fix missing include, not all systems define HOST_NAME_MAX
carl
parents:
94
diff
changeset
|
12 #include <unistd.h> |
94 | 13 #include <sys/ioctl.h> |
14 #include <net/if.h> | |
15 #include <arpa/inet.h> | |
16 #include <netinet/in.h> | |
17 #include <netinet/tcp.h> | |
18 #include <netdb.h> | |
19 #include <sys/socket.h> | |
20 #include <sys/un.h> | |
21 | |
22 static char* context_version="$Id$"; | |
23 | |
24 char *token_black; | |
25 char *token_content; | |
26 char *token_context; | |
27 char *token_dccfrom; | |
28 char *token_dccto; | |
29 char *token_default; | |
30 char *token_dnsbl; | |
31 char *token_dnsbll; | |
32 char *token_envfrom; | |
33 char *token_envto; | |
34 char *token_filter; | |
35 char *token_host_limit; | |
36 char *token_html_limit; | |
37 char *token_html_tags; | |
38 char *token_ignore; | |
39 char *token_include; | |
40 char *token_inherit; | |
41 char *token_lbrace; | |
42 char *token_mailhost; | |
43 char *token_many; | |
44 char *token_off; | |
45 char *token_ok2; | |
46 char *token_ok; | |
47 char *token_on; | |
136 | 48 char *token_rate; |
94 | 49 char *token_rbrace; |
50 char *token_semi; | |
51 char *token_soft; | |
52 char *token_substitute; | |
53 char *token_tld; | |
117 | 54 char *token_cctld; |
94 | 55 char *token_unknown; |
119 | 56 char *token_uribl; |
94 | 57 char *token_verify; |
58 char *token_white; | |
59 | |
60 char *token_myhostname; | |
96
1edd4e8d3a60
fix missing include, not all systems define HOST_NAME_MAX
carl
parents:
94
diff
changeset
|
61 #ifndef HOST_NAME_MAX |
1edd4e8d3a60
fix missing include, not all systems define HOST_NAME_MAX
carl
parents:
94
diff
changeset
|
62 #define HOST_NAME_MAX 255 |
1edd4e8d3a60
fix missing include, not all systems define HOST_NAME_MAX
carl
parents:
94
diff
changeset
|
63 #endif |
94 | 64 char myhostname[HOST_NAME_MAX+1]; |
65 | |
66 verify_map verifiers; | |
67 string_set all_strings; // owns all the strings, only modified by the config loader thread | |
68 const int maxlen = 1000; // used for snprintf buffers | |
69 const int maxage = 120; // smtp verify sockets older than this are ancient | |
70 extern int NULL_SOCKET; | |
129
c5cd1261394d
ignore smtp connection attempts for 10 minutes when getting connection errors on verify hosts
carl
parents:
119
diff
changeset
|
71 const time_t ERROR_SMTP_SOCKET_TIME = 600; // number of seconds between attempts to open a socket to an smtp server |
94 | 72 |
73 | |
74 int SMTP::writer() { | |
75 #ifdef VERIFY_DEBUG | |
76 log("writer() sees buffer with %s", buffer); | |
77 log("writer() sees error %d", (int)error); | |
78 #endif | |
79 int rs = 0; | |
80 if (!error) { | |
81 int len = strlen(buffer); | |
82 while (rs < len) { | |
83 int ws = write(fd, buffer+rs, len-rs); | |
84 if (ws > 0) { | |
85 rs += ws; | |
86 } | |
87 else { | |
88 // peer closed the socket! | |
89 rs = 0; | |
90 error = true; | |
91 break; | |
92 } | |
93 } | |
94 } | |
95 return rs; | |
96 } | |
97 | |
98 | |
99 int SMTP::reader() { | |
100 // read some bytes terminated by lf or end of buffer. | |
101 // we may have a multi line response or part thereof in the buffer. | |
102 #ifdef VERIFY_DEBUG | |
103 log("reader() sees error %d", (int)error); | |
104 #endif | |
105 if (error) return 0; | |
106 int len = maxlen-1; // room for null terminator | |
107 while (pending < len) { | |
108 int ws = read(fd, buffer+pending, len-pending); | |
109 if (ws > 0) { | |
110 pending += ws; | |
111 if (buffer[pending-1] == '\n') break; | |
112 } | |
113 else { | |
114 // peer closed the socket! | |
115 pending = 0; | |
116 error = true; | |
117 break; | |
118 } | |
119 } | |
120 buffer[pending] = '\0'; | |
121 #ifdef VERIFY_DEBUG | |
122 log("reader() sees buffer with %s", buffer); | |
123 #endif | |
124 return pending; | |
125 } | |
126 | |
127 | |
128 int SMTP::read_line() { | |
129 char *lf = strchr(buffer, '\n'); | |
130 if (!lf) { | |
131 reader(); // get a lf | |
132 lf = strchr(buffer, '\n'); | |
133 if (!lf) lf = buffer + pending - 1; | |
134 } | |
135 return (lf-buffer)+1; // number of bytes in this line | |
136 } | |
137 | |
138 | |
97 | 139 void SMTP::flush_line(int r) { |
94 | 140 if (pending > r) memmove(buffer, buffer+r, pending-r); |
141 pending -= r; | |
142 } | |
143 | |
144 | |
145 int SMTP::read_response() { | |
146 pending = 0; | |
147 buffer[pending] = '\0'; | |
148 while (true) { | |
149 int r = read_line(); | |
150 #ifdef VERIFY_DEBUG | |
151 log("read_response() sees line with %s", buffer); | |
152 log("read_response() sees line length %d", r); | |
153 #endif | |
154 if (r == 0) return 0; // failed to read any bytes | |
155 if ((r > 4) && (buffer[3] == '-')) { | |
156 flush_line(r); | |
157 continue; | |
158 } | |
159 return atoi(buffer); | |
160 } | |
161 return 0; | |
162 } | |
163 | |
164 | |
165 int SMTP::cmd(char *c) { | |
166 if (c) { | |
167 init(); | |
168 append(c); | |
169 } | |
170 append("\r\n"); | |
171 writer(); | |
172 return read_response(); | |
173 } | |
174 | |
175 | |
176 int SMTP::helo() { | |
177 if (read_response() != 220) return 0; | |
178 init(); | |
179 append("HELO "); | |
180 append(token_myhostname); | |
181 return cmd(NULL); | |
182 } | |
183 | |
184 | |
185 int SMTP::rset() { | |
186 int rc = cmd("RSET"); | |
187 efrom[0] = '\0'; | |
188 return rc; | |
189 } | |
190 | |
191 | |
192 int SMTP::from(char *f) { | |
101 | 193 // the mail from address was originally passed in from sendmail enclosed in |
194 // <>. to_lower_string() removed the <> and converted the rest to lowercase, | |
195 // except in the case of an empty return path, which was left as the two | |
196 // character string <>. | |
94 | 197 if (strncmp(efrom, f, maxlen)) { |
198 rset(); | |
199 strncpy(efrom, f, maxlen); | |
200 init(); | |
201 append("MAIL FROM:<"); | |
101 | 202 if (*f != '<') append(f); |
94 | 203 append(">"); |
204 return cmd(NULL); | |
205 } | |
206 return 250; // pretend it worked | |
207 } | |
208 | |
209 | |
210 int SMTP::rcpt(char *t) { | |
211 init(); | |
212 append("RCPT TO:<"); | |
213 append(t); | |
214 append(">"); | |
215 return cmd(NULL); | |
216 } | |
217 | |
218 | |
219 int SMTP::quit() { | |
220 return cmd("QUIT"); | |
221 } | |
222 | |
223 | |
224 void SMTP::closefd() { | |
225 shutdown(fd, SHUT_RDWR); | |
226 close(fd); | |
227 } | |
228 | |
229 | |
230 #ifdef VERIFY_DEBUG | |
231 void SMTP::log(char *m, int v) { | |
232 char buf[maxlen]; | |
233 snprintf(buf, maxlen, m, v); | |
234 my_syslog(buf); | |
235 } | |
236 | |
237 | |
238 void SMTP::log(char *m, char *v) { | |
239 char buf[maxlen]; | |
240 snprintf(buf, maxlen, m, v); | |
241 my_syslog(buf); | |
242 } | |
243 #endif | |
244 | |
245 | |
246 VERIFY::VERIFY(char *h) { | |
247 host = h; | |
248 last_err = 0; | |
249 pthread_mutex_init(&mutex, 0); | |
250 } | |
251 | |
252 | |
253 void VERIFY::closer() { | |
254 bool ok = true; | |
255 while (ok) { | |
256 SMTP *conn = NULL; | |
257 pthread_mutex_lock(&mutex); | |
258 if (connections.empty()) { | |
259 ok = false; | |
260 } | |
261 else { | |
262 conn = connections.front(); | |
263 time_t now = time(NULL); | |
264 if ((now - conn->get_stamp()) > maxage) { | |
265 // this connection is ancient, remove it | |
266 connections.pop_front(); | |
267 } | |
268 else { | |
269 ok = false; | |
270 conn = NULL; | |
271 } | |
272 } | |
273 pthread_mutex_unlock(&mutex); | |
274 // avoid doing this work inside the mutex lock | |
275 if (conn) { | |
276 #ifdef VERIFY_DEBUG | |
277 conn->log("closer() closes ancient %d", conn->get_fd()); | |
278 #endif | |
279 delete conn; | |
280 } | |
281 } | |
282 } | |
283 | |
284 | |
285 SMTP* VERIFY::get_connection() { | |
286 SMTP *conn = NULL; | |
287 pthread_mutex_lock(&mutex); | |
288 if (!connections.empty()) { | |
289 conn = connections.front(); | |
290 connections.pop_front(); | |
291 #ifdef VERIFY_DEBUG | |
292 conn->log("get_connection() %d from cache", conn->get_fd()); | |
293 #endif | |
294 } | |
295 pthread_mutex_unlock(&mutex); | |
296 if (conn) return conn; | |
297 int sock = NULL_SOCKET; | |
129
c5cd1261394d
ignore smtp connection attempts for 10 minutes when getting connection errors on verify hosts
carl
parents:
119
diff
changeset
|
298 if ((time(NULL) - last_err) > ERROR_SMTP_SOCKET_TIME) { |
94 | 299 // nothing recent, maybe this time it will work |
300 hostent *h = gethostbyname(host); | |
301 if (h) { | |
302 sockaddr_in server; | |
303 server.sin_family = h->h_addrtype; | |
304 server.sin_port = htons(25); | |
305 memcpy(&server.sin_addr, h->h_addr_list[0], h->h_length); | |
306 sock = socket(PF_INET, SOCK_STREAM, 0); | |
307 if (sock != NULL_SOCKET) { | |
308 bool rc = (connect(sock, (sockaddr *)&server, sizeof(server)) == 0); | |
309 if (!rc) { | |
310 shutdown(sock, SHUT_RDWR); | |
311 close(sock); | |
312 sock = NULL_SOCKET; | |
129
c5cd1261394d
ignore smtp connection attempts for 10 minutes when getting connection errors on verify hosts
carl
parents:
119
diff
changeset
|
313 last_err = time(NULL); |
94 | 314 } |
315 } | |
129
c5cd1261394d
ignore smtp connection attempts for 10 minutes when getting connection errors on verify hosts
carl
parents:
119
diff
changeset
|
316 else last_err = time(NULL); |
94 | 317 } |
129
c5cd1261394d
ignore smtp connection attempts for 10 minutes when getting connection errors on verify hosts
carl
parents:
119
diff
changeset
|
318 else last_err = time(NULL); |
94 | 319 } |
320 if (sock != NULL_SOCKET) { | |
321 conn = new SMTP(sock); | |
322 #ifdef VERIFY_DEBUG | |
323 conn->log("get_connection() %d new socket", conn->get_fd()); | |
324 #endif | |
325 if (conn->helo() == 250) return conn; | |
326 delete conn; | |
327 } | |
328 return NULL; | |
329 } | |
330 | |
331 | |
332 void VERIFY::put_connection(SMTP *conn) { | |
333 if (conn->err()) { | |
334 #ifdef VERIFY_DEBUG | |
335 conn->log("put_socket() %d with error, close it", conn->get_fd()); | |
336 #endif | |
337 delete conn; | |
338 last_err = time(NULL); | |
339 } | |
340 else { | |
341 #ifdef VERIFY_DEBUG | |
342 conn->log("put_socket() %d", conn->get_fd()); | |
343 #endif | |
344 conn->now(); | |
345 pthread_mutex_lock(&mutex); | |
346 connections.push_back(conn); | |
347 pthread_mutex_unlock(&mutex); | |
348 } | |
349 } | |
350 | |
351 | |
352 bool VERIFY::ok(char *from, char *to) { | |
353 if (host == token_myhostname) return true; | |
354 SMTP *conn = get_connection(); | |
355 if (!conn) return true; // cannot verify right now, we have socket errors | |
356 int rc; | |
357 rc = conn->from(from); | |
358 #ifdef VERIFY_DEBUG | |
359 conn->log("verify::ok() from sees %d", rc); | |
360 #endif | |
361 if (rc != 250) { | |
362 conn->rset(); | |
363 put_connection(conn); | |
364 return (rc >= 500) ? false : true; | |
365 } | |
366 rc = conn->rcpt(to); | |
367 #ifdef VERIFY_DEBUG | |
368 conn->log("verify::ok() rcpt sees %d", rc); | |
369 #endif | |
370 put_connection(conn); | |
371 return (rc >= 500) ? false : true; | |
372 } | |
373 | |
374 | |
375 DNSBL::DNSBL(char *n, char *s, char *m) { | |
376 name = n; | |
377 suffix = s; | |
378 message = m; | |
379 } | |
380 | |
381 | |
382 bool DNSBL::operator==(const DNSBL &rhs) { | |
383 return (strcmp(name, rhs.name) == 0) && | |
384 (strcmp(suffix, rhs.suffix) == 0) && | |
385 (strcmp(message, rhs.message) == 0); | |
386 } | |
387 | |
388 | |
389 CONFIG::CONFIG() { | |
390 reference_count = 0; | |
391 generation = 0; | |
392 load_time = 0; | |
393 default_context = NULL; | |
394 } | |
395 | |
396 | |
397 CONFIG::~CONFIG() { | |
398 for (context_list::iterator i=contexts.begin(); i!=contexts.end(); i++) { | |
399 CONTEXT *c = *i; | |
400 delete c; | |
401 } | |
402 } | |
403 | |
404 | |
405 void CONFIG::add_context(CONTEXTP con) { | |
406 contexts.push_back(con); | |
407 if (!default_context && !con->get_parent()) { | |
408 // first global context | |
409 default_context = con; | |
410 } | |
411 } | |
412 | |
413 | |
414 void CONFIG::add_to(char *to, CONTEXTP con) { | |
415 context_map::iterator i = env_to.find(to); | |
416 if (i != env_to.end()) { | |
417 CONTEXTP c = (*i).second; | |
418 int s = strlen(to); | |
419 bool at = s && (to[s-1] == '@'); | |
420 if (at && con->is_parent(c->get_parent())) { | |
421 if (debug_syslog) { | |
422 char oldname[maxlen]; | |
423 char newname[maxlen]; | |
424 char *oldn = c->get_full_name(oldname, maxlen); | |
425 char *newn = con->get_full_name(newname, maxlen); | |
426 char buf[maxlen*3]; | |
427 snprintf(buf, maxlen*3, "both %s and %s claim envelope to %s, the first one wins", oldn, newn, to); | |
428 my_syslog(buf); | |
429 } | |
430 return; // don't take over user@ entries from your ancestors children | |
431 } | |
432 if ((c != con) && (c != con->get_parent())) { | |
433 if (debug_syslog) { | |
434 char oldname[maxlen]; | |
435 char newname[maxlen]; | |
436 char *oldn = c->get_full_name(oldname, maxlen); | |
437 char *newn = con->get_full_name(newname, maxlen); | |
438 char buf[maxlen*3]; | |
439 snprintf(buf, maxlen*3, "both %s and %s claim envelope to %s, the second one wins", oldn, newn, to); | |
440 my_syslog(buf); | |
441 } | |
442 } | |
443 } | |
444 env_to[to] = con; | |
445 } | |
446 | |
447 | |
448 CONTEXTP CONFIG::find_context(char *to) { | |
449 context_map::iterator i = env_to.find(to); | |
117 | 450 if (i != env_to.end()) return (*i).second; // found user@domain key |
94 | 451 char *x = strchr(to, '@'); |
452 if (x) { | |
453 x++; | |
454 i = env_to.find(x); | |
117 | 455 if (i != env_to.end()) return (*i).second; // found domain key |
94 | 456 char y = *x; |
457 *x = '\0'; | |
458 i = env_to.find(to); | |
459 *x = y; | |
460 if (i != env_to.end()) return (*i).second; // found user@ key | |
461 } | |
462 return default_context; | |
463 } | |
464 | |
465 | |
466 void CONFIG::dump() { | |
467 if (default_context) default_context->dump(); | |
468 for (context_list::iterator i=contexts.begin(); i!=contexts.end(); i++) { | |
469 CONTEXTP c = *i; | |
470 CONTEXTP p = c->get_parent(); | |
471 if (!p && (c != default_context)) c->dump(); | |
472 } | |
473 char buf[maxlen]; | |
474 for (context_map::iterator i=env_to.begin(); i!=env_to.end(); i++) { | |
475 char *to = (*i).first; | |
476 CONTEXTP con = (*i).second; | |
477 printf("// envelope to %s \t-> context %s \n", to, con->get_full_name(buf,maxlen)); | |
478 } | |
479 } | |
480 | |
481 | |
482 CONTEXT::CONTEXT(CONTEXTP parent_, char *name_) { | |
483 parent = parent_; | |
484 name = name_; | |
485 verify_host = NULL; | |
486 env_from_default = (parent) ? token_inherit : token_unknown; | |
487 content_filtering = (parent) ? parent->content_filtering : false; | |
488 content_suffix = NULL; | |
489 content_message = NULL; | |
119 | 490 uribl_suffix = NULL; |
491 uribl_message = NULL; | |
94 | 492 host_limit = (parent) ? parent->host_limit : 0; |
493 host_limit_message = NULL; | |
494 host_random = (parent) ? parent->host_random : false; | |
495 tag_limit = (parent) ? parent->tag_limit : 0; | |
496 tag_limit_message = NULL; | |
140 | 497 default_rcpt_rate = INT_MAX; |
94 | 498 } |
499 | |
500 | |
501 CONTEXT::~CONTEXT() { | |
502 for (dnsblp_map::iterator i=dnsbl_names.begin(); i!=dnsbl_names.end(); i++) { | |
503 DNSBLP d = (*i).second; | |
504 // delete the underlying DNSBL objects. | |
505 delete d; | |
506 } | |
507 } | |
508 | |
509 | |
510 bool CONTEXT::is_parent(CONTEXTP p) { | |
511 if (p == parent) return true; | |
512 if (!parent) return false; | |
513 return parent->is_parent(p); | |
514 } | |
515 | |
516 | |
517 char *CONTEXT::get_full_name(char *buffer, int size) { | |
518 if (!parent) return name; | |
519 char buf[maxlen]; | |
520 snprintf(buffer, size, "%s.%s", parent->get_full_name(buf, maxlen), name); | |
521 return buffer; | |
522 } | |
523 | |
524 | |
525 bool CONTEXT::cover_env_to(char *to) { | |
526 char buffer[maxlen]; | |
527 char *x = strchr(to, '@'); | |
528 if (x) x++; | |
529 else x = to; | |
530 if (*x == '\0') return true; // always allow covering addresses with no domain name, eg abuse@ | |
100
63e8633abc34
allow empty env_to at global context to remove all restrictions on child contexts
carl
parents:
99
diff
changeset
|
531 if (!parent && env_to.empty()) return true; // empty env_to at global level covers everything |
94 | 532 string_set::iterator i = env_to.find(x); |
533 if (i != env_to.end()) return true; | |
534 return false; | |
535 } | |
536 | |
537 | |
538 VERIFYP CONTEXT::find_verify(char *to) { | |
539 if (verify_host && (verify_host != token_myhostname) && cover_env_to(to)) { | |
540 verify_map::iterator i = verifiers.find(verify_host); | |
541 if (i == verifiers.end()) { | |
542 if (debug_syslog) { | |
543 char buf[maxlen]; | |
544 snprintf(buf, maxlen, "cannot find struc for %s", verify_host); | |
545 my_syslog(buf); | |
546 } | |
547 return NULL; | |
548 } | |
549 VERIFYP v = (*i).second; | |
550 | |
551 return v; | |
552 } | |
553 else if (parent) return parent->find_verify(to); | |
554 else return NULL; | |
555 } | |
556 | |
557 | |
136 | 558 int CONTEXT::find_rate(char *user) { |
140 | 559 if (rcpt_per_hour.empty()) return default_rcpt_rate; |
136 | 560 rcpt_rates::iterator i = rcpt_per_hour.find(user); |
140 | 561 return (i == rcpt_per_hour.end()) ? default_rcpt_rate : (*i).second; |
136 | 562 } |
563 | |
564 | |
94 | 565 char *CONTEXT::find_from(char *from) { |
566 char *rc = token_inherit; | |
567 string_map::iterator i = env_from.find(from); | |
117 | 568 if (i != env_from.end()) rc = (*i).second; // found user@domain key |
94 | 569 else { |
570 char *x = strchr(from, '@'); | |
571 if (x) { | |
572 x++; | |
573 i = env_from.find(x); | |
117 | 574 if (i != env_from.end()) rc = (*i).second; // found domain key |
94 | 575 else { |
576 char y = *x; | |
577 *x = '\0'; | |
578 i = env_from.find(from); | |
579 *x = y; | |
580 if (i != env_from.end()) rc = (*i).second; // found user@ key | |
581 } | |
582 } | |
583 } | |
584 if (rc == token_inherit) rc = env_from_default; | |
585 if ((rc == token_inherit) && parent) return parent->find_from(from); | |
586 return (rc == token_inherit) ? token_unknown : rc; | |
587 } | |
588 | |
589 | |
590 CONTEXTP CONTEXT::find_context(char *from) { | |
591 context_map::iterator i = env_from_context.find(from); | |
117 | 592 if (i != env_from_context.end()) return (*i).second; // found user@domain key |
94 | 593 char *x = strchr(from, '@'); |
594 if (x) { | |
595 x++; | |
596 i = env_from_context.find(x); | |
117 | 597 if (i != env_from_context.end()) return (*i).second; // found domain key |
94 | 598 char y = *x; |
599 *x = '\0'; | |
600 i = env_from_context.find(from); | |
601 *x = y; | |
602 if (i != env_from_context.end()) return (*i).second; // found user@ key | |
603 } | |
604 return this; | |
605 } | |
606 | |
607 | |
608 CONTEXTP CONTEXT::find_from_context_name(char *name) { | |
609 context_map::iterator i = children.find(name); | |
610 if (i != children.end()) return (*i).second; | |
611 return NULL; | |
612 } | |
613 | |
614 | |
615 DNSBLP CONTEXT::find_dnsbl(char *name) { | |
616 dnsblp_map::iterator i = dnsbl_names.find(name); | |
617 if (i != dnsbl_names.end()) return (*i).second; | |
618 if (parent) return parent->find_dnsbl(name); | |
619 return NULL; | |
620 } | |
621 | |
622 | |
623 char* CONTEXT::get_content_suffix() { | |
624 if (!content_suffix && parent) return parent->get_content_suffix(); | |
625 return content_suffix; | |
626 } | |
627 | |
628 | |
119 | 629 char* CONTEXT::get_uribl_suffix() { |
630 if (!uribl_suffix && parent) return parent->get_uribl_suffix(); | |
631 return uribl_suffix; | |
632 } | |
633 | |
634 | |
94 | 635 char* CONTEXT::get_content_message() { |
636 if (!content_message && parent) return parent->get_content_message(); | |
637 return content_message; | |
638 } | |
639 | |
640 | |
119 | 641 char* CONTEXT::get_uribl_message() { |
642 if (!uribl_message && parent) return parent->get_uribl_message(); | |
643 return uribl_message; | |
644 } | |
645 | |
646 | |
94 | 647 string_set& CONTEXT::get_content_host_ignore() { |
648 if (content_host_ignore.empty() && parent) return parent->get_content_host_ignore(); | |
649 return content_host_ignore; | |
650 } | |
651 | |
652 | |
117 | 653 string_set& CONTEXT::get_content_cctlds() { |
654 if (content_cctlds.empty() && parent) return parent->get_content_cctlds(); | |
655 return content_cctlds; | |
656 } | |
657 | |
94 | 658 string_set& CONTEXT::get_content_tlds() { |
659 if (content_tlds.empty() && parent) return parent->get_content_tlds(); | |
660 return content_tlds; | |
661 } | |
662 | |
663 | |
664 string_set& CONTEXT::get_html_tags() { | |
665 if (html_tags.empty() && parent) return parent->get_html_tags(); | |
666 return html_tags; | |
667 } | |
668 | |
669 | |
670 dnsblp_list& CONTEXT::get_dnsbl_list() { | |
671 if (dnsbl_list.empty() && parent) return parent->get_dnsbl_list(); | |
672 return dnsbl_list; | |
673 } | |
674 | |
675 | |
676 bool CONTEXT::acceptable_content(recorder &memory, char *&msg) { | |
677 if (memory.excessive_bad_tags(tag_limit)) { | |
678 msg = tag_limit_message; | |
679 return false; | |
680 } | |
681 if (!host_random && memory.excessive_hosts(host_limit)) { | |
682 msg = host_limit_message; | |
683 return false; | |
684 } | |
685 return true; | |
686 } | |
687 | |
688 | |
689 void CONTEXT::dump(int level) { | |
690 char indent[maxlen]; | |
691 int i = min(maxlen-1, level*4); | |
692 memset(indent, ' ', i); | |
693 indent[i] = '\0'; | |
694 char buf[maxlen]; | |
695 char *fullname = get_full_name(buf,maxlen); | |
696 printf("%s context %s { \t// %s\n", indent, name, fullname); | |
697 | |
698 for (dnsblp_map::iterator i=dnsbl_names.begin(); i!=dnsbl_names.end(); i++) { | |
699 char *n = (*i).first; | |
700 DNSBL &d = *(*i).second; | |
701 printf("%s dnsbl %s %s \"%s\"; \n", indent, n, d.suffix, d.message); | |
702 } | |
703 | |
704 if (!dnsbl_list.empty()) { | |
705 printf("%s dnsbl_list", indent); | |
706 for (dnsblp_list::iterator i=dnsbl_list.begin(); i!=dnsbl_list.end(); i++) { | |
707 DNSBL &d = *(*i); | |
708 printf(" %s", d.name); | |
709 } | |
710 printf("; \n"); | |
711 } | |
712 | |
713 if (content_filtering) { | |
714 printf("%s content on { \n", indent, env_from_default); | |
715 if (content_suffix) { | |
716 printf("%s filter %s \"%s\"; \n", indent, content_suffix, content_message); | |
717 } | |
119 | 718 if (uribl_suffix) { |
719 printf("%s uribl %s \"%s\"; \n", indent, uribl_suffix, uribl_message); | |
720 } | |
94 | 721 if (!content_host_ignore.empty()) { |
722 printf("%s ignore { \n", indent); | |
723 for (string_set::iterator i=content_host_ignore.begin(); i!=content_host_ignore.end(); i++) { | |
724 printf("%s %s; \n", indent, *i); | |
725 } | |
726 printf("%s }; \n", indent); | |
727 } | |
117 | 728 if (!content_cctlds.empty()) { |
729 printf("%s cctld { \n", indent); | |
730 printf("%s ", indent); | |
731 for (string_set::iterator i=content_cctlds.begin(); i!=content_cctlds.end(); i++) { | |
732 printf("%s; ", *i); | |
733 } | |
734 printf("\n%s }; \n", indent); | |
735 } | |
94 | 736 if (!content_tlds.empty()) { |
737 printf("%s tld { \n", indent); | |
738 printf("%s ", indent); | |
739 for (string_set::iterator i=content_tlds.begin(); i!=content_tlds.end(); i++) { | |
740 printf("%s; ", *i); | |
741 } | |
742 printf("\n%s }; \n", indent); | |
743 } | |
744 if (!html_tags.empty()) { | |
745 printf("%s html_tags { \n", indent); | |
746 printf("%s ", indent); | |
747 for (string_set::iterator i=html_tags.begin(); i!=html_tags.end(); i++) { | |
748 printf("%s; ", *i); | |
749 } | |
750 printf("\n%s }; \n", indent); | |
751 } | |
752 if (host_limit_message) { | |
753 printf("%s host_limit on %d \"%s\"; \n", indent, host_limit, host_limit_message); | |
754 } | |
755 else if (host_random) { | |
756 printf("%s host_limit soft %d; \n", indent, host_limit); | |
757 } | |
758 else { | |
759 printf("%s host_limit off; \n", indent); | |
760 } | |
761 if (tag_limit_message) { | |
762 printf("%s html_limit on %d \"%s\"; \n", indent, tag_limit, tag_limit_message); | |
763 } | |
764 else { | |
765 printf("%s html_limit off; \n", indent); | |
766 } | |
767 printf("%s }; \n", indent); | |
768 } | |
769 else { | |
770 printf("%s content off {}; \n", indent, env_from_default); | |
771 } | |
772 | |
773 printf("%s env_to { \t// %s\n", indent, fullname); | |
774 for (string_set::iterator i=env_to.begin(); i!=env_to.end(); i++) { | |
775 printf("%s %s; \n", indent, *i); | |
776 } | |
777 printf("%s }; \n", indent); | |
778 | |
779 if (verify_host) { | |
780 printf("%s verify %s; \n", indent, verify_host); | |
781 } | |
782 | |
783 for (context_map::iterator i=children.begin(); i!=children.end(); i++) { | |
784 CONTEXTP c = (*i).second; | |
785 c->dump(level+1); | |
786 } | |
787 | |
788 printf("%s env_from %s { \t// %s\n", indent, env_from_default, fullname); | |
789 if (!env_from.empty()) { | |
790 printf("%s // white/black/unknown \n", indent); | |
791 for (string_map::iterator i=env_from.begin(); i!=env_from.end(); i++) { | |
792 char *f = (*i).first; | |
793 char *t = (*i).second; | |
794 printf("%s %s \t%s; \n", indent, f, t); | |
795 } | |
796 } | |
797 if (!env_from_context.empty()) { | |
798 printf("%s // child contexts \n", indent); | |
799 for (context_map::iterator j=env_from_context.begin(); j!=env_from_context.end(); j++) { | |
800 char *f = (*j).first; | |
801 CONTEXTP t = (*j).second; | |
802 printf("%s %s \t%s; \n", indent, f, t->name); | |
803 } | |
804 } | |
805 printf("%s }; \n", indent); | |
806 | |
140 | 807 printf("%s rate_limit %d { \n", indent, default_rcpt_rate); |
808 for (rcpt_rates::iterator j=rcpt_per_hour.begin(); j!=rcpt_per_hour.end(); j++) { | |
809 char *u = (*j).first; | |
810 int l = (*j).second; | |
811 printf("%s \"%s\" \t%d; \n", indent, u, l); | |
136 | 812 } |
140 | 813 printf("%s }; \n", indent); |
136 | 814 |
94 | 815 printf("%s }; \n", indent); |
816 } | |
817 | |
818 | |
819 //////////////////////////////////////////////// | |
820 // helper to discard the strings held by a string_set | |
821 // | |
822 void discard(string_set &s) { | |
823 for (string_set::iterator i=s.begin(); i!=s.end(); i++) { | |
824 free(*i); | |
825 } | |
826 s.clear(); | |
827 } | |
828 | |
829 | |
830 //////////////////////////////////////////////// | |
831 // helper to register a string in a string set | |
832 // | |
833 char* register_string(string_set &s, char *name) { | |
834 string_set::iterator i = s.find(name); | |
835 if (i != s.end()) return *i; | |
836 char *x = strdup(name); | |
837 s.insert(x); | |
838 return x; | |
839 } | |
840 | |
841 | |
842 //////////////////////////////////////////////// | |
843 // register a global string | |
844 // | |
845 char* register_string(char *name) { | |
846 return register_string(all_strings, name); | |
847 } | |
848 | |
849 | |
850 //////////////////////////////////////////////// | |
851 // | |
852 bool tsa(TOKEN &tok, char *token); | |
853 bool tsa(TOKEN &tok, char *token) { | |
854 char *have = tok.next(); | |
855 if (have == token) return true; | |
856 tok.token_error(token, have); | |
857 return false; | |
858 } | |
859 | |
860 | |
861 //////////////////////////////////////////////// | |
862 // | |
863 bool parse_dnsbl(TOKEN &tok, CONFIG &dc, CONTEXT &me); | |
864 bool parse_dnsbl(TOKEN &tok, CONFIG &dc, CONTEXT &me) { | |
865 char *name = tok.next(); | |
866 char *suf = tok.next(); | |
867 char *msg = tok.next(); | |
868 if (!tsa(tok, token_semi)) return false; | |
869 DNSBLP dnsnew = new DNSBL(name, suf, msg); | |
870 DNSBLP dnsold = me.find_dnsbl(name); | |
871 if (dnsold && (*dnsold == *dnsnew)) { | |
872 // duplicate redefinition, ignore it | |
873 delete dnsnew; | |
874 return true; | |
875 } | |
876 me.add_dnsbl(name, dnsnew); | |
877 return true; | |
878 } | |
879 | |
880 | |
881 //////////////////////////////////////////////// | |
882 // | |
883 bool parse_dnsbll(TOKEN &tok, CONFIG &dc, CONTEXT &me); | |
884 bool parse_dnsbll(TOKEN &tok, CONFIG &dc, CONTEXT &me) { | |
885 while (true) { | |
886 char *have = tok.next(); | |
887 if (!have) break; | |
888 if (have == token_semi) break; | |
889 DNSBLP dns = me.find_dnsbl(have); | |
890 if (dns) { | |
891 me.add_dnsbl(dns); | |
892 } | |
893 else { | |
894 tok.token_error("dnsbl name", have); | |
895 return false; | |
896 } | |
897 } | |
898 return true; | |
899 } | |
900 | |
901 | |
902 //////////////////////////////////////////////// | |
903 // | |
904 bool parse_content(TOKEN &tok, CONFIG &dc, CONTEXT &me); | |
905 bool parse_content(TOKEN &tok, CONFIG &dc, CONTEXT &me) { | |
906 char *setting = tok.next(); | |
907 if (setting == token_on) { | |
908 me.set_content_filtering(true); | |
909 } | |
910 else if (setting == token_off) { | |
911 me.set_content_filtering(false); | |
912 } | |
913 else { | |
914 tok.token_error("on/off", setting); | |
915 return false; | |
916 } | |
917 if (!tsa(tok, token_lbrace)) return false; | |
918 while (true) { | |
919 char *have = tok.next(); | |
920 if (!have) break; | |
921 if (have == token_filter) { | |
922 char *suffix = tok.next(); | |
923 char *messag = tok.next(); | |
924 me.set_content_suffix(suffix); | |
925 me.set_content_message(messag); | |
926 if (!tsa(tok, token_semi)) return false; | |
927 } | |
119 | 928 else if (have == token_uribl) { |
929 char *suffix = tok.next(); | |
930 char *messag = tok.next(); | |
931 me.set_uribl_suffix(suffix); | |
932 me.set_uribl_message(messag); | |
933 if (!tsa(tok, token_semi)) return false; | |
934 } | |
94 | 935 else if (have == token_ignore) { |
936 if (!tsa(tok, token_lbrace)) return false; | |
937 while (true) { | |
938 if (!have) break; | |
939 char *have = tok.next(); | |
940 if (have == token_rbrace) break; // done | |
941 me.add_ignore(have); | |
942 } | |
943 if (!tsa(tok, token_semi)) return false; | |
944 } | |
117 | 945 else if (have == token_cctld) { |
946 if (!tsa(tok, token_lbrace)) return false; | |
947 while (true) { | |
948 char *have = tok.next(); | |
949 if (!have) break; | |
950 if (have == token_rbrace) break; // done | |
951 me.add_cctld(have); | |
952 } | |
953 if (!tsa(tok, token_semi)) return false; | |
954 } | |
94 | 955 else if (have == token_tld) { |
956 if (!tsa(tok, token_lbrace)) return false; | |
957 while (true) { | |
958 char *have = tok.next(); | |
959 if (!have) break; | |
960 if (have == token_rbrace) break; // done | |
961 me.add_tld(have); | |
962 } | |
963 if (!tsa(tok, token_semi)) return false; | |
964 } | |
965 else if (have == token_html_limit) { | |
966 have = tok.next(); | |
967 if (have == token_on) { | |
968 me.set_tag_limit(tok.nextint()); | |
969 me.set_tag_message(tok.next()); | |
970 } | |
971 else if (have == token_off) { | |
972 me.set_tag_limit(0); | |
973 me.set_tag_message(NULL); | |
974 } | |
975 else { | |
976 tok.token_error("on/off", have); | |
977 return false; | |
978 } | |
979 if (!tsa(tok, token_semi)) return false; | |
980 } | |
981 else if (have == token_html_tags) { | |
982 if (!tsa(tok, token_lbrace)) return false; | |
983 while (true) { | |
984 char *have = tok.next(); | |
985 if (!have) break; | |
986 if (have == token_rbrace) { | |
987 break; // done | |
988 } | |
989 else { | |
990 me.add_tag(have); // base version | |
991 char buf[200]; | |
992 snprintf(buf, sizeof(buf), "/%s", have); | |
993 me.add_tag(register_string(buf)); // leading / | |
994 snprintf(buf, sizeof(buf), "%s/", have); | |
995 me.add_tag(register_string(buf)); // trailing / | |
996 } | |
997 } | |
998 if (!tsa(tok, token_semi)) return false; | |
999 } | |
1000 else if (have == token_host_limit) { | |
1001 have = tok.next(); | |
1002 if (have == token_on) { | |
1003 me.set_host_limit(tok.nextint()); | |
1004 me.set_host_message(tok.next()); | |
1005 me.set_host_random(false); | |
1006 } | |
1007 else if (have == token_off) { | |
1008 me.set_host_limit(0); | |
1009 me.set_host_message(NULL); | |
1010 me.set_host_random(false); | |
1011 } | |
1012 else if (have == token_soft) { | |
1013 me.set_host_limit(tok.nextint()); | |
1014 me.set_host_message(NULL); | |
1015 me.set_host_random(true); | |
1016 } | |
1017 else { | |
1018 tok.token_error("on/off/soft", have); | |
1019 return false; | |
1020 } | |
1021 if (!tsa(tok, token_semi)) return false; | |
1022 } | |
1023 else if (have == token_rbrace) { | |
1024 break; // done | |
1025 } | |
1026 else { | |
1027 tok.token_error("content keyword", have); | |
1028 return false; | |
1029 } | |
1030 } | |
1031 return tsa(tok, token_semi); | |
1032 } | |
1033 | |
1034 | |
1035 //////////////////////////////////////////////// | |
1036 // | |
1037 bool parse_envto(TOKEN &tok, CONFIG &dc, CONTEXT &me); | |
1038 bool parse_envto(TOKEN &tok, CONFIG &dc, CONTEXT &me) { | |
1039 if (!tsa(tok, token_lbrace)) return false; | |
1040 while (true) { | |
1041 char *have = tok.next(); | |
1042 if (!have) break; | |
1043 if (have == token_rbrace) break; | |
1044 if (have == token_semi) { | |
1045 // optional separators | |
1046 } | |
1047 else if (have == token_dccto) { | |
1048 char *flavor = tok.next(); | |
1049 if (!tsa(tok, token_lbrace)) return false; | |
1050 bool keeping = false; | |
1051 while (true) { | |
1052 char *have = tok.next(); | |
1053 if (!have) break; | |
1054 if (have == token_rbrace) break; | |
1055 if (have == flavor) { | |
1056 keeping = true; | |
1057 continue; | |
1058 } | |
1059 else if ((have == token_ok) || (have == token_ok2) || (have == token_many)) { | |
1060 keeping = false; | |
1061 continue; | |
1062 } | |
1063 if (have == token_envto) { | |
1064 have = tok.next(); | |
1065 if (keeping) { | |
1066 if (me.allow_env_to(have)) { | |
1067 me.add_to(have); | |
1068 dc.add_to(have, &me); | |
1069 } | |
1070 } | |
1071 } | |
1072 //else if (have == token_substitute) { | |
1073 // if (tok.next() == token_mailhost) { | |
1074 // have = tok.next(); | |
1075 // if (keeping) { | |
1076 // if (me.allow_env_to(have)) { | |
1077 // me.add_to(have); | |
1078 // dc.add_to(have, &me); | |
1079 // } | |
1080 // } | |
1081 // } | |
1082 //} | |
1083 tok.skipeol(); | |
1084 } | |
1085 } | |
1086 else if (me.allow_env_to(have)) { | |
1087 me.add_to(have); | |
1088 dc.add_to(have, &me); | |
1089 } | |
1090 else { | |
1091 tok.token_error("user@ or user@domain.tld or domain.tld where domain.tld allowed by parent context", have); | |
1092 return false; | |
1093 } | |
1094 } | |
1095 return tsa(tok, token_semi); | |
1096 } | |
1097 | |
1098 | |
1099 //////////////////////////////////////////////// | |
1100 // | |
1101 bool parse_verify(TOKEN &tok, CONFIG &dc, CONTEXT &me); | |
1102 bool parse_verify(TOKEN &tok, CONFIG &dc, CONTEXT &me) { | |
1103 char *host = tok.next(); | |
1104 if (!tsa(tok, token_semi)) return false; | |
1105 me.set_verify(host); | |
1106 add_verify_host(host); | |
99 | 1107 return true; |
94 | 1108 } |
1109 | |
1110 | |
1111 //////////////////////////////////////////////// | |
1112 // | |
1113 bool parse_envfrom(TOKEN &tok, CONFIG &dc, CONTEXT &me); | |
1114 bool parse_envfrom(TOKEN &tok, CONFIG &dc, CONTEXT &me) { | |
1115 char *st = tok.next(); | |
1116 if ((st == token_black) || (st == token_white) || (st == token_unknown) || (st == token_inherit)) { | |
1117 me.set_from_default(st); | |
1118 } | |
1119 else { | |
1120 tok.push(st); | |
1121 } | |
1122 if (!tsa(tok, token_lbrace)) return false; | |
1123 while (true) { | |
1124 char *have = tok.next(); | |
1125 if (!have) break; | |
1126 if (have == token_rbrace) break; | |
1127 if (have == token_semi) { | |
1128 // optional separators | |
1129 } | |
1130 else if (have == token_dccfrom) { | |
1131 if (!tsa(tok, token_lbrace)) return false; | |
1132 bool keeping = false; | |
1133 bool many = false; | |
1134 while (true) { | |
1135 char *have = tok.next(); | |
1136 if (!have) break; | |
1137 if (have == token_rbrace) break; | |
1138 if (have == token_ok) { | |
1139 keeping = true; | |
1140 many = false; | |
1141 continue; | |
1142 } | |
1143 else if (have == token_many) { | |
1144 keeping = true; | |
1145 many = true; | |
1146 continue; | |
1147 } | |
1148 else if (have == token_ok2) { | |
1149 keeping = false; | |
1150 continue; | |
1151 } | |
1152 if (have == token_envfrom) { | |
1153 have = tok.next(); | |
1154 if (keeping) { | |
1155 me.add_from(have, (many) ? token_black : token_white); | |
1156 } | |
1157 } | |
1158 else if (have == token_substitute) { | |
1159 if (tok.next() == token_mailhost) { | |
1160 have = tok.next(); | |
1161 me.add_from(have, (many) ? token_black : token_white); | |
1162 } | |
1163 } | |
1164 tok.skipeol(); | |
1165 } | |
1166 } | |
1167 else { | |
1168 // may be a valid email address or domain name | |
1169 char *st = tok.next(); | |
1170 if ((st == token_black) || (st == token_white) || (st == token_unknown)) { | |
1171 me.add_from(have, st); | |
1172 } | |
1173 else { | |
1174 CONTEXTP con = me.find_from_context_name(st); | |
1175 if (con) { | |
1176 me.add_from_context(have, con); | |
1177 } | |
1178 else { | |
1179 tok.token_error("white/black/unknown or child context name", st); | |
1180 return false; | |
1181 } | |
1182 } | |
1183 } | |
1184 } | |
1185 return tsa(tok, token_semi); | |
1186 } | |
1187 | |
1188 | |
1189 //////////////////////////////////////////////// | |
1190 // | |
136 | 1191 bool parse_rate(TOKEN &tok, CONFIG &dc, CONTEXT &me); |
1192 bool parse_rate(TOKEN &tok, CONFIG &dc, CONTEXT &me) { | |
140 | 1193 char *def = tok.next(); |
1194 if (def != token_lbrace) { | |
1195 tok.push(def); | |
1196 me.set_default_rate(tok.nextint()); | |
1197 } | |
136 | 1198 if (!tsa(tok, token_lbrace)) return false; |
1199 while (true) { | |
1200 char *have = tok.next(); | |
1201 if (!have) break; | |
1202 if (have == token_rbrace) break; | |
1203 if (have == token_semi) { | |
1204 // optional separators | |
1205 } | |
1206 else { | |
140 | 1207 me.add_rate(have, tok.nextint()); |
136 | 1208 } |
1209 } | |
1210 return tsa(tok, token_semi); | |
1211 } | |
1212 | |
1213 | |
1214 //////////////////////////////////////////////// | |
1215 // | |
94 | 1216 bool parse_context(TOKEN &tok, CONFIG &dc, CONTEXTP parent); |
1217 bool parse_context(TOKEN &tok, CONFIG &dc, CONTEXTP parent) { | |
1218 char *name = tok.next(); | |
1219 if (!tsa(tok, token_lbrace)) return false; | |
1220 CONTEXTP con = new CONTEXT(parent, name); | |
1221 | |
1222 while (true) { | |
1223 char *have = tok.next(); | |
1224 if (!have) break; | |
1225 if (have == token_rbrace) break; // done | |
1226 if (have == token_dnsbl) { | |
1227 if (!parse_dnsbl(tok, dc, *con)) return false; | |
1228 } | |
1229 else if (have == token_dnsbll) { | |
1230 if (!parse_dnsbll(tok, dc, *con)) return false; | |
1231 } | |
1232 else if (have == token_content) { | |
1233 if (!parse_content(tok, dc, *con)) return false; | |
1234 } | |
1235 else if (have == token_envto) { | |
1236 if (!parse_envto(tok, dc, *con)) return false; | |
1237 } | |
1238 else if (have == token_verify) { | |
1239 if (!parse_verify(tok, dc, *con)) return false; | |
1240 } | |
1241 else if (have == token_envfrom) { | |
1242 if (!parse_envfrom(tok, dc, *con)) return false; | |
1243 } | |
140 | 1244 else if (have == token_rate) { |
1245 if (parent || dc.default_context) tok.token_error("rate limit ignored in non default context"); | |
136 | 1246 if (!parse_rate(tok, dc, *con)) return false; |
1247 } | |
94 | 1248 else if (have == token_context) { |
1249 if (!parse_context(tok, dc, con)) return false; | |
1250 } | |
1251 else { | |
1252 tok.token_error("context keyword", have); | |
1253 return false; | |
1254 } | |
1255 } | |
1256 | |
1257 if (!tsa(tok, token_semi)) { | |
1258 delete con; | |
1259 return false; | |
1260 } | |
1261 dc.add_context(con); | |
1262 if (parent) parent->add_context(con); | |
1263 return true; | |
1264 } | |
1265 | |
1266 | |
1267 //////////////////////////////////////////////// | |
1268 // parse a config file | |
1269 // | |
1270 bool load_conf(CONFIG &dc, char *fn) { | |
99 | 1271 int count = 0; |
94 | 1272 TOKEN tok(fn, &dc.config_files); |
1273 while (true) { | |
1274 char *have = tok.next(); | |
1275 if (!have) break; | |
1276 if (have == token_context) { | |
1277 if (!parse_context(tok, dc, NULL)) { | |
99 | 1278 tok.token_error("load_conf() failed to parse context"); |
94 | 1279 return false; |
1280 } | |
99 | 1281 else count++; |
94 | 1282 } |
1283 else { | |
1284 tok.token_error(token_context, have); | |
1285 return false; | |
1286 } | |
1287 } | |
99 | 1288 tok.token_error("load_conf() found %d contexts in %s", count, fn); |
94 | 1289 return (dc.default_context) ? true : false; |
1290 } | |
1291 | |
1292 | |
1293 //////////////////////////////////////////////// | |
1294 // setup a new smtp verify host | |
1295 // | |
1296 void add_verify_host(char *host) { | |
1297 verify_map::iterator i = verifiers.find(host); | |
1298 if (i == verifiers.end()) { | |
1299 VERIFYP v = new VERIFY(host); | |
1300 verifiers[host] = v; | |
1301 } | |
1302 } | |
1303 | |
1304 | |
1305 //////////////////////////////////////////////// | |
1306 // thread to check for verify hosts with old sockets that we can close | |
1307 // | |
1308 void* verify_closer(void *arg) { | |
1309 while (true) { | |
1310 sleep(maxage); | |
1311 for (verify_map::iterator i=verifiers.begin(); i!=verifiers.end(); i++) { | |
1312 VERIFYP v = (*i).second; | |
1313 v->closer(); | |
1314 } | |
1315 } | |
1316 return NULL; | |
1317 } | |
1318 | |
1319 | |
1320 //////////////////////////////////////////////// | |
1321 // init the tokens | |
1322 // | |
1323 void token_init() { | |
1324 token_black = register_string("black"); | |
117 | 1325 token_cctld = register_string("cctld"); |
94 | 1326 token_content = register_string("content"); |
1327 token_context = register_string("context"); | |
1328 token_dccfrom = register_string("dcc_from"); | |
1329 token_dccto = register_string("dcc_to"); | |
1330 token_default = register_string("default"); | |
1331 token_dnsbl = register_string("dnsbl"); | |
1332 token_dnsbll = register_string("dnsbl_list"); | |
1333 token_envfrom = register_string("env_from"); | |
1334 token_envto = register_string("env_to"); | |
1335 token_filter = register_string("filter"); | |
1336 token_host_limit = register_string("host_limit"); | |
1337 token_html_limit = register_string("html_limit"); | |
1338 token_html_tags = register_string("html_tags"); | |
1339 token_ignore = register_string("ignore"); | |
1340 token_include = register_string("include"); | |
1341 token_inherit = register_string("inherit"); | |
1342 token_lbrace = register_string("{"); | |
1343 token_mailhost = register_string("mail_host"); | |
1344 token_many = register_string("many"); | |
1345 token_off = register_string("off"); | |
1346 token_ok = register_string("ok"); | |
1347 token_ok2 = register_string("ok2"); | |
1348 token_on = register_string("on"); | |
136 | 1349 token_rate = register_string("rate_limit"); |
94 | 1350 token_rbrace = register_string("}"); |
1351 token_semi = register_string(";"); | |
1352 token_soft = register_string("soft"); | |
1353 token_substitute = register_string("substitute"); | |
1354 token_tld = register_string("tld"); | |
1355 token_unknown = register_string("unknown"); | |
119 | 1356 token_uribl = register_string("uribl"); |
94 | 1357 token_verify = register_string("verify"); |
1358 token_white = register_string("white"); | |
1359 | |
1360 if (gethostname(myhostname, HOST_NAME_MAX+1) != 0) { | |
1361 strncpy(myhostname, "localhost", HOST_NAME_MAX+1); | |
1362 } | |
1363 myhostname[HOST_NAME_MAX] = '\0'; // ensure null termination | |
1364 token_myhostname = register_string(myhostname); | |
1365 } |