Mercurial > dnsbl
annotate src/context.cpp @ 139:003026deaed1 stable-5-21
add smtp auth rate limits
author | carl |
---|---|
date | Tue, 26 Sep 2006 15:21:17 -0700 |
parents | f4746d8a12a3 |
children | 4028de9b46dd |
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; | |
497 } | |
498 | |
499 | |
500 CONTEXT::~CONTEXT() { | |
501 for (dnsblp_map::iterator i=dnsbl_names.begin(); i!=dnsbl_names.end(); i++) { | |
502 DNSBLP d = (*i).second; | |
503 // delete the underlying DNSBL objects. | |
504 delete d; | |
505 } | |
506 } | |
507 | |
508 | |
509 bool CONTEXT::is_parent(CONTEXTP p) { | |
510 if (p == parent) return true; | |
511 if (!parent) return false; | |
512 return parent->is_parent(p); | |
513 } | |
514 | |
515 | |
516 char *CONTEXT::get_full_name(char *buffer, int size) { | |
517 if (!parent) return name; | |
518 char buf[maxlen]; | |
519 snprintf(buffer, size, "%s.%s", parent->get_full_name(buf, maxlen), name); | |
520 return buffer; | |
521 } | |
522 | |
523 | |
524 bool CONTEXT::cover_env_to(char *to) { | |
525 char buffer[maxlen]; | |
526 char *x = strchr(to, '@'); | |
527 if (x) x++; | |
528 else x = to; | |
529 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
|
530 if (!parent && env_to.empty()) return true; // empty env_to at global level covers everything |
94 | 531 string_set::iterator i = env_to.find(x); |
532 if (i != env_to.end()) return true; | |
533 return false; | |
534 } | |
535 | |
536 | |
537 VERIFYP CONTEXT::find_verify(char *to) { | |
538 if (verify_host && (verify_host != token_myhostname) && cover_env_to(to)) { | |
539 verify_map::iterator i = verifiers.find(verify_host); | |
540 if (i == verifiers.end()) { | |
541 if (debug_syslog) { | |
542 char buf[maxlen]; | |
543 snprintf(buf, maxlen, "cannot find struc for %s", verify_host); | |
544 my_syslog(buf); | |
545 } | |
546 return NULL; | |
547 } | |
548 VERIFYP v = (*i).second; | |
549 | |
550 return v; | |
551 } | |
552 else if (parent) return parent->find_verify(to); | |
553 else return NULL; | |
554 } | |
555 | |
556 | |
136 | 557 int CONTEXT::find_rate(char *user) { |
558 if (rcpt_per_hour.empty()) return INT_MAX; | |
559 rcpt_rates::iterator i = rcpt_per_hour.find(user); | |
560 if (i == rcpt_per_hour.end()) i = rcpt_per_hour.find(" "); | |
561 return (i == rcpt_per_hour.end()) ? INT_MAX : (*i).second; | |
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 | |
136 | 807 if (!rcpt_per_hour.empty()) { |
808 printf("%s rate_limit { \n", indent); | |
809 for (rcpt_rates::iterator j=rcpt_per_hour.begin(); j!=rcpt_per_hour.end(); j++) { | |
810 char *u = (*j).first; | |
811 int l = (*j).second; | |
812 printf("%s \"%s\" \t%d; \n", indent, u, l); | |
813 } | |
814 printf("%s }; \n", indent); | |
815 } | |
816 | |
94 | 817 printf("%s }; \n", indent); |
818 } | |
819 | |
820 | |
821 //////////////////////////////////////////////// | |
822 // helper to discard the strings held by a string_set | |
823 // | |
824 void discard(string_set &s) { | |
825 for (string_set::iterator i=s.begin(); i!=s.end(); i++) { | |
826 free(*i); | |
827 } | |
828 s.clear(); | |
829 } | |
830 | |
831 | |
832 //////////////////////////////////////////////// | |
833 // helper to register a string in a string set | |
834 // | |
835 char* register_string(string_set &s, char *name) { | |
836 string_set::iterator i = s.find(name); | |
837 if (i != s.end()) return *i; | |
838 char *x = strdup(name); | |
839 s.insert(x); | |
840 return x; | |
841 } | |
842 | |
843 | |
844 //////////////////////////////////////////////// | |
845 // register a global string | |
846 // | |
847 char* register_string(char *name) { | |
848 return register_string(all_strings, name); | |
849 } | |
850 | |
851 | |
852 //////////////////////////////////////////////// | |
853 // | |
854 bool tsa(TOKEN &tok, char *token); | |
855 bool tsa(TOKEN &tok, char *token) { | |
856 char *have = tok.next(); | |
857 if (have == token) return true; | |
858 tok.token_error(token, have); | |
859 return false; | |
860 } | |
861 | |
862 | |
863 //////////////////////////////////////////////// | |
864 // | |
865 bool parse_dnsbl(TOKEN &tok, CONFIG &dc, CONTEXT &me); | |
866 bool parse_dnsbl(TOKEN &tok, CONFIG &dc, CONTEXT &me) { | |
867 char *name = tok.next(); | |
868 char *suf = tok.next(); | |
869 char *msg = tok.next(); | |
870 if (!tsa(tok, token_semi)) return false; | |
871 DNSBLP dnsnew = new DNSBL(name, suf, msg); | |
872 DNSBLP dnsold = me.find_dnsbl(name); | |
873 if (dnsold && (*dnsold == *dnsnew)) { | |
874 // duplicate redefinition, ignore it | |
875 delete dnsnew; | |
876 return true; | |
877 } | |
878 me.add_dnsbl(name, dnsnew); | |
879 return true; | |
880 } | |
881 | |
882 | |
883 //////////////////////////////////////////////// | |
884 // | |
885 bool parse_dnsbll(TOKEN &tok, CONFIG &dc, CONTEXT &me); | |
886 bool parse_dnsbll(TOKEN &tok, CONFIG &dc, CONTEXT &me) { | |
887 while (true) { | |
888 char *have = tok.next(); | |
889 if (!have) break; | |
890 if (have == token_semi) break; | |
891 DNSBLP dns = me.find_dnsbl(have); | |
892 if (dns) { | |
893 me.add_dnsbl(dns); | |
894 } | |
895 else { | |
896 tok.token_error("dnsbl name", have); | |
897 return false; | |
898 } | |
899 } | |
900 return true; | |
901 } | |
902 | |
903 | |
904 //////////////////////////////////////////////// | |
905 // | |
906 bool parse_content(TOKEN &tok, CONFIG &dc, CONTEXT &me); | |
907 bool parse_content(TOKEN &tok, CONFIG &dc, CONTEXT &me) { | |
908 char *setting = tok.next(); | |
909 if (setting == token_on) { | |
910 me.set_content_filtering(true); | |
911 } | |
912 else if (setting == token_off) { | |
913 me.set_content_filtering(false); | |
914 } | |
915 else { | |
916 tok.token_error("on/off", setting); | |
917 return false; | |
918 } | |
919 if (!tsa(tok, token_lbrace)) return false; | |
920 while (true) { | |
921 char *have = tok.next(); | |
922 if (!have) break; | |
923 if (have == token_filter) { | |
924 char *suffix = tok.next(); | |
925 char *messag = tok.next(); | |
926 me.set_content_suffix(suffix); | |
927 me.set_content_message(messag); | |
928 if (!tsa(tok, token_semi)) return false; | |
929 } | |
119 | 930 else if (have == token_uribl) { |
931 char *suffix = tok.next(); | |
932 char *messag = tok.next(); | |
933 me.set_uribl_suffix(suffix); | |
934 me.set_uribl_message(messag); | |
935 if (!tsa(tok, token_semi)) return false; | |
936 } | |
94 | 937 else if (have == token_ignore) { |
938 if (!tsa(tok, token_lbrace)) return false; | |
939 while (true) { | |
940 if (!have) break; | |
941 char *have = tok.next(); | |
942 if (have == token_rbrace) break; // done | |
943 me.add_ignore(have); | |
944 } | |
945 if (!tsa(tok, token_semi)) return false; | |
946 } | |
117 | 947 else if (have == token_cctld) { |
948 if (!tsa(tok, token_lbrace)) return false; | |
949 while (true) { | |
950 char *have = tok.next(); | |
951 if (!have) break; | |
952 if (have == token_rbrace) break; // done | |
953 me.add_cctld(have); | |
954 } | |
955 if (!tsa(tok, token_semi)) return false; | |
956 } | |
94 | 957 else if (have == token_tld) { |
958 if (!tsa(tok, token_lbrace)) return false; | |
959 while (true) { | |
960 char *have = tok.next(); | |
961 if (!have) break; | |
962 if (have == token_rbrace) break; // done | |
963 me.add_tld(have); | |
964 } | |
965 if (!tsa(tok, token_semi)) return false; | |
966 } | |
967 else if (have == token_html_limit) { | |
968 have = tok.next(); | |
969 if (have == token_on) { | |
970 me.set_tag_limit(tok.nextint()); | |
971 me.set_tag_message(tok.next()); | |
972 } | |
973 else if (have == token_off) { | |
974 me.set_tag_limit(0); | |
975 me.set_tag_message(NULL); | |
976 } | |
977 else { | |
978 tok.token_error("on/off", have); | |
979 return false; | |
980 } | |
981 if (!tsa(tok, token_semi)) return false; | |
982 } | |
983 else if (have == token_html_tags) { | |
984 if (!tsa(tok, token_lbrace)) return false; | |
985 while (true) { | |
986 char *have = tok.next(); | |
987 if (!have) break; | |
988 if (have == token_rbrace) { | |
989 break; // done | |
990 } | |
991 else { | |
992 me.add_tag(have); // base version | |
993 char buf[200]; | |
994 snprintf(buf, sizeof(buf), "/%s", have); | |
995 me.add_tag(register_string(buf)); // leading / | |
996 snprintf(buf, sizeof(buf), "%s/", have); | |
997 me.add_tag(register_string(buf)); // trailing / | |
998 } | |
999 } | |
1000 if (!tsa(tok, token_semi)) return false; | |
1001 } | |
1002 else if (have == token_host_limit) { | |
1003 have = tok.next(); | |
1004 if (have == token_on) { | |
1005 me.set_host_limit(tok.nextint()); | |
1006 me.set_host_message(tok.next()); | |
1007 me.set_host_random(false); | |
1008 } | |
1009 else if (have == token_off) { | |
1010 me.set_host_limit(0); | |
1011 me.set_host_message(NULL); | |
1012 me.set_host_random(false); | |
1013 } | |
1014 else if (have == token_soft) { | |
1015 me.set_host_limit(tok.nextint()); | |
1016 me.set_host_message(NULL); | |
1017 me.set_host_random(true); | |
1018 } | |
1019 else { | |
1020 tok.token_error("on/off/soft", have); | |
1021 return false; | |
1022 } | |
1023 if (!tsa(tok, token_semi)) return false; | |
1024 } | |
1025 else if (have == token_rbrace) { | |
1026 break; // done | |
1027 } | |
1028 else { | |
1029 tok.token_error("content keyword", have); | |
1030 return false; | |
1031 } | |
1032 } | |
1033 return tsa(tok, token_semi); | |
1034 } | |
1035 | |
1036 | |
1037 //////////////////////////////////////////////// | |
1038 // | |
1039 bool parse_envto(TOKEN &tok, CONFIG &dc, CONTEXT &me); | |
1040 bool parse_envto(TOKEN &tok, CONFIG &dc, CONTEXT &me) { | |
1041 if (!tsa(tok, token_lbrace)) return false; | |
1042 while (true) { | |
1043 char *have = tok.next(); | |
1044 if (!have) break; | |
1045 if (have == token_rbrace) break; | |
1046 if (have == token_semi) { | |
1047 // optional separators | |
1048 } | |
1049 else if (have == token_dccto) { | |
1050 char *flavor = tok.next(); | |
1051 if (!tsa(tok, token_lbrace)) return false; | |
1052 bool keeping = false; | |
1053 while (true) { | |
1054 char *have = tok.next(); | |
1055 if (!have) break; | |
1056 if (have == token_rbrace) break; | |
1057 if (have == flavor) { | |
1058 keeping = true; | |
1059 continue; | |
1060 } | |
1061 else if ((have == token_ok) || (have == token_ok2) || (have == token_many)) { | |
1062 keeping = false; | |
1063 continue; | |
1064 } | |
1065 if (have == token_envto) { | |
1066 have = tok.next(); | |
1067 if (keeping) { | |
1068 if (me.allow_env_to(have)) { | |
1069 me.add_to(have); | |
1070 dc.add_to(have, &me); | |
1071 } | |
1072 } | |
1073 } | |
1074 //else if (have == token_substitute) { | |
1075 // if (tok.next() == token_mailhost) { | |
1076 // have = tok.next(); | |
1077 // if (keeping) { | |
1078 // if (me.allow_env_to(have)) { | |
1079 // me.add_to(have); | |
1080 // dc.add_to(have, &me); | |
1081 // } | |
1082 // } | |
1083 // } | |
1084 //} | |
1085 tok.skipeol(); | |
1086 } | |
1087 } | |
1088 else if (me.allow_env_to(have)) { | |
1089 me.add_to(have); | |
1090 dc.add_to(have, &me); | |
1091 } | |
1092 else { | |
1093 tok.token_error("user@ or user@domain.tld or domain.tld where domain.tld allowed by parent context", have); | |
1094 return false; | |
1095 } | |
1096 } | |
1097 return tsa(tok, token_semi); | |
1098 } | |
1099 | |
1100 | |
1101 //////////////////////////////////////////////// | |
1102 // | |
1103 bool parse_verify(TOKEN &tok, CONFIG &dc, CONTEXT &me); | |
1104 bool parse_verify(TOKEN &tok, CONFIG &dc, CONTEXT &me) { | |
1105 char *host = tok.next(); | |
1106 if (!tsa(tok, token_semi)) return false; | |
1107 me.set_verify(host); | |
1108 add_verify_host(host); | |
99 | 1109 return true; |
94 | 1110 } |
1111 | |
1112 | |
1113 //////////////////////////////////////////////// | |
1114 // | |
1115 bool parse_envfrom(TOKEN &tok, CONFIG &dc, CONTEXT &me); | |
1116 bool parse_envfrom(TOKEN &tok, CONFIG &dc, CONTEXT &me) { | |
1117 char *st = tok.next(); | |
1118 if ((st == token_black) || (st == token_white) || (st == token_unknown) || (st == token_inherit)) { | |
1119 me.set_from_default(st); | |
1120 } | |
1121 else { | |
1122 tok.push(st); | |
1123 } | |
1124 if (!tsa(tok, token_lbrace)) return false; | |
1125 while (true) { | |
1126 char *have = tok.next(); | |
1127 if (!have) break; | |
1128 if (have == token_rbrace) break; | |
1129 if (have == token_semi) { | |
1130 // optional separators | |
1131 } | |
1132 else if (have == token_dccfrom) { | |
1133 if (!tsa(tok, token_lbrace)) return false; | |
1134 bool keeping = false; | |
1135 bool many = false; | |
1136 while (true) { | |
1137 char *have = tok.next(); | |
1138 if (!have) break; | |
1139 if (have == token_rbrace) break; | |
1140 if (have == token_ok) { | |
1141 keeping = true; | |
1142 many = false; | |
1143 continue; | |
1144 } | |
1145 else if (have == token_many) { | |
1146 keeping = true; | |
1147 many = true; | |
1148 continue; | |
1149 } | |
1150 else if (have == token_ok2) { | |
1151 keeping = false; | |
1152 continue; | |
1153 } | |
1154 if (have == token_envfrom) { | |
1155 have = tok.next(); | |
1156 if (keeping) { | |
1157 me.add_from(have, (many) ? token_black : token_white); | |
1158 } | |
1159 } | |
1160 else if (have == token_substitute) { | |
1161 if (tok.next() == token_mailhost) { | |
1162 have = tok.next(); | |
1163 me.add_from(have, (many) ? token_black : token_white); | |
1164 } | |
1165 } | |
1166 tok.skipeol(); | |
1167 } | |
1168 } | |
1169 else { | |
1170 // may be a valid email address or domain name | |
1171 char *st = tok.next(); | |
1172 if ((st == token_black) || (st == token_white) || (st == token_unknown)) { | |
1173 me.add_from(have, st); | |
1174 } | |
1175 else { | |
1176 CONTEXTP con = me.find_from_context_name(st); | |
1177 if (con) { | |
1178 me.add_from_context(have, con); | |
1179 } | |
1180 else { | |
1181 tok.token_error("white/black/unknown or child context name", st); | |
1182 return false; | |
1183 } | |
1184 } | |
1185 } | |
1186 } | |
1187 return tsa(tok, token_semi); | |
1188 } | |
1189 | |
1190 | |
1191 //////////////////////////////////////////////// | |
1192 // | |
136 | 1193 bool parse_rate(TOKEN &tok, CONFIG &dc, CONTEXT &me); |
1194 bool parse_rate(TOKEN &tok, CONFIG &dc, CONTEXT &me) { | |
1195 if (!tsa(tok, token_lbrace)) return false; | |
1196 while (true) { | |
1197 char *have = tok.next(); | |
1198 if (!have) break; | |
1199 if (have == token_rbrace) break; | |
1200 if (have == token_semi) { | |
1201 // optional separators | |
1202 } | |
1203 else { | |
1204 char *limit = tok.next(); | |
1205 int lim = (limit) ? atoi(limit) : 0; | |
1206 me.add_rate(have, lim); | |
1207 } | |
1208 } | |
1209 return tsa(tok, token_semi); | |
1210 } | |
1211 | |
1212 | |
1213 //////////////////////////////////////////////// | |
1214 // | |
94 | 1215 bool parse_context(TOKEN &tok, CONFIG &dc, CONTEXTP parent); |
1216 bool parse_context(TOKEN &tok, CONFIG &dc, CONTEXTP parent) { | |
1217 char *name = tok.next(); | |
1218 if (!tsa(tok, token_lbrace)) return false; | |
1219 CONTEXTP con = new CONTEXT(parent, name); | |
1220 | |
1221 while (true) { | |
1222 char *have = tok.next(); | |
1223 if (!have) break; | |
1224 if (have == token_rbrace) break; // done | |
1225 if (have == token_dnsbl) { | |
1226 if (!parse_dnsbl(tok, dc, *con)) return false; | |
1227 } | |
1228 else if (have == token_dnsbll) { | |
1229 if (!parse_dnsbll(tok, dc, *con)) return false; | |
1230 } | |
1231 else if (have == token_content) { | |
1232 if (!parse_content(tok, dc, *con)) return false; | |
1233 } | |
1234 else if (have == token_envto) { | |
1235 if (!parse_envto(tok, dc, *con)) return false; | |
1236 } | |
1237 else if (have == token_verify) { | |
1238 if (!parse_verify(tok, dc, *con)) return false; | |
1239 } | |
1240 else if (have == token_envfrom) { | |
1241 if (!parse_envfrom(tok, dc, *con)) return false; | |
1242 } | |
136 | 1243 else if ((have == token_rate) && (!parent) && (!dc.default_context)) { |
1244 if (!parse_rate(tok, dc, *con)) return false; | |
1245 } | |
94 | 1246 else if (have == token_context) { |
1247 if (!parse_context(tok, dc, con)) return false; | |
1248 } | |
1249 else { | |
1250 tok.token_error("context keyword", have); | |
1251 return false; | |
1252 } | |
1253 } | |
1254 | |
1255 if (!tsa(tok, token_semi)) { | |
1256 delete con; | |
1257 return false; | |
1258 } | |
1259 dc.add_context(con); | |
1260 if (parent) parent->add_context(con); | |
1261 return true; | |
1262 } | |
1263 | |
1264 | |
1265 //////////////////////////////////////////////// | |
1266 // parse a config file | |
1267 // | |
1268 bool load_conf(CONFIG &dc, char *fn) { | |
99 | 1269 int count = 0; |
94 | 1270 TOKEN tok(fn, &dc.config_files); |
1271 while (true) { | |
1272 char *have = tok.next(); | |
1273 if (!have) break; | |
1274 if (have == token_context) { | |
1275 if (!parse_context(tok, dc, NULL)) { | |
99 | 1276 tok.token_error("load_conf() failed to parse context"); |
94 | 1277 return false; |
1278 } | |
99 | 1279 else count++; |
94 | 1280 } |
1281 else { | |
1282 tok.token_error(token_context, have); | |
1283 return false; | |
1284 } | |
1285 } | |
99 | 1286 tok.token_error("load_conf() found %d contexts in %s", count, fn); |
94 | 1287 return (dc.default_context) ? true : false; |
1288 } | |
1289 | |
1290 | |
1291 //////////////////////////////////////////////// | |
1292 // setup a new smtp verify host | |
1293 // | |
1294 void add_verify_host(char *host) { | |
1295 verify_map::iterator i = verifiers.find(host); | |
1296 if (i == verifiers.end()) { | |
1297 VERIFYP v = new VERIFY(host); | |
1298 verifiers[host] = v; | |
1299 } | |
1300 } | |
1301 | |
1302 | |
1303 //////////////////////////////////////////////// | |
1304 // thread to check for verify hosts with old sockets that we can close | |
1305 // | |
1306 void* verify_closer(void *arg) { | |
1307 while (true) { | |
1308 sleep(maxage); | |
1309 for (verify_map::iterator i=verifiers.begin(); i!=verifiers.end(); i++) { | |
1310 VERIFYP v = (*i).second; | |
1311 v->closer(); | |
1312 } | |
1313 } | |
1314 return NULL; | |
1315 } | |
1316 | |
1317 | |
1318 //////////////////////////////////////////////// | |
1319 // init the tokens | |
1320 // | |
1321 void token_init() { | |
1322 token_black = register_string("black"); | |
117 | 1323 token_cctld = register_string("cctld"); |
94 | 1324 token_content = register_string("content"); |
1325 token_context = register_string("context"); | |
1326 token_dccfrom = register_string("dcc_from"); | |
1327 token_dccto = register_string("dcc_to"); | |
1328 token_default = register_string("default"); | |
1329 token_dnsbl = register_string("dnsbl"); | |
1330 token_dnsbll = register_string("dnsbl_list"); | |
1331 token_envfrom = register_string("env_from"); | |
1332 token_envto = register_string("env_to"); | |
1333 token_filter = register_string("filter"); | |
1334 token_host_limit = register_string("host_limit"); | |
1335 token_html_limit = register_string("html_limit"); | |
1336 token_html_tags = register_string("html_tags"); | |
1337 token_ignore = register_string("ignore"); | |
1338 token_include = register_string("include"); | |
1339 token_inherit = register_string("inherit"); | |
1340 token_lbrace = register_string("{"); | |
1341 token_mailhost = register_string("mail_host"); | |
1342 token_many = register_string("many"); | |
1343 token_off = register_string("off"); | |
1344 token_ok = register_string("ok"); | |
1345 token_ok2 = register_string("ok2"); | |
1346 token_on = register_string("on"); | |
136 | 1347 token_rate = register_string("rate_limit"); |
94 | 1348 token_rbrace = register_string("}"); |
1349 token_semi = register_string(";"); | |
1350 token_soft = register_string("soft"); | |
1351 token_substitute = register_string("substitute"); | |
1352 token_tld = register_string("tld"); | |
1353 token_unknown = register_string("unknown"); | |
119 | 1354 token_uribl = register_string("uribl"); |
94 | 1355 token_verify = register_string("verify"); |
1356 token_white = register_string("white"); | |
1357 | |
1358 if (gethostname(myhostname, HOST_NAME_MAX+1) != 0) { | |
1359 strncpy(myhostname, "localhost", HOST_NAME_MAX+1); | |
1360 } | |
1361 myhostname[HOST_NAME_MAX] = '\0'; // ensure null termination | |
1362 token_myhostname = register_string(myhostname); | |
1363 } |