Mercurial > dnsbl
annotate src/context.cpp @ 183:e8a822f9cca0
embedded dcc filtering
author | carl |
---|---|
date | Sun, 07 Oct 2007 09:19:37 -0700 |
parents | 7a722f482bfb |
children | 8f4a9a37d4d9 |
rev | line source |
---|---|
94 | 1 /* |
2 | |
152 | 3 Copyright (c) 2007 Carl Byington - 510 Software Group, released under |
4 the GPL version 3 or any later version at your choice available at | |
5 http://www.gnu.org/licenses/gpl-3.0.txt | |
94 | 6 |
7 */ | |
8 | |
9 #include "includes.h" | |
10 | |
160 | 11 #include <arpa/inet.h> |
94 | 12 #include <net/if.h> |
160 | 13 #include <netdb.h> |
94 | 14 #include <netinet/in.h> |
15 #include <netinet/tcp.h> | |
160 | 16 #include <sys/ioctl.h> |
94 | 17 #include <sys/socket.h> |
160 | 18 #include <sys/stat.h> |
94 | 19 #include <sys/un.h> |
160 | 20 #include <unistd.h> |
94 | 21 |
22 static char* context_version="$Id$"; | |
23 | |
153 | 24 char *token_autowhite; |
94 | 25 char *token_black; |
178 | 26 char *token_cctld; |
94 | 27 char *token_content; |
28 char *token_context; | |
178 | 29 char *token_dccbulk; |
94 | 30 char *token_dccfrom; |
178 | 31 char *token_dccgrey; |
94 | 32 char *token_dccto; |
33 char *token_default; | |
34 char *token_dnsbl; | |
35 char *token_dnsbll; | |
36 char *token_envfrom; | |
37 char *token_envto; | |
38 char *token_filter; | |
168 | 39 char *token_generic; |
94 | 40 char *token_host_limit; |
41 char *token_html_limit; | |
42 char *token_html_tags; | |
43 char *token_ignore; | |
44 char *token_include; | |
45 char *token_inherit; | |
46 char *token_lbrace; | |
47 char *token_mailhost; | |
48 char *token_many; | |
178 | 49 char *token_no; |
94 | 50 char *token_off; |
178 | 51 char *token_ok; |
94 | 52 char *token_ok2; |
53 char *token_on; | |
136 | 54 char *token_rate; |
94 | 55 char *token_rbrace; |
178 | 56 char *token_require; |
94 | 57 char *token_semi; |
58 char *token_soft; | |
163 | 59 char *token_spamassassin; |
94 | 60 char *token_substitute; |
61 char *token_tld; | |
62 char *token_unknown; | |
119 | 63 char *token_uribl; |
94 | 64 char *token_verify; |
65 char *token_white; | |
178 | 66 char *token_yes; |
94 | 67 |
68 char *token_myhostname; | |
96
1edd4e8d3a60
fix missing include, not all systems define HOST_NAME_MAX
carl
parents:
94
diff
changeset
|
69 #ifndef HOST_NAME_MAX |
1edd4e8d3a60
fix missing include, not all systems define HOST_NAME_MAX
carl
parents:
94
diff
changeset
|
70 #define HOST_NAME_MAX 255 |
1edd4e8d3a60
fix missing include, not all systems define HOST_NAME_MAX
carl
parents:
94
diff
changeset
|
71 #endif |
94 | 72 char myhostname[HOST_NAME_MAX+1]; |
73 | |
153 | 74 pthread_mutex_t verifier_mutex; // protect the verifier map |
94 | 75 verify_map verifiers; |
153 | 76 |
173
83fe0be032c1
fix leak, update timestamps when receiving auto-whitelisted sender
carl
parents:
170
diff
changeset
|
77 pthread_mutex_t whitelister_mutex; // protect the whitelisters map |
153 | 78 whitelister_map whitelisters; |
79 | |
94 | 80 string_set all_strings; // owns all the strings, only modified by the config loader thread |
81 const int maxlen = 1000; // used for snprintf buffers | |
178 | 82 const int maxsmtp_age = 60;// smtp verify sockets older than this are ancient |
153 | 83 const int maxauto_age = 600;// auto whitelister delay before flushing to file |
94 | 84 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
|
85 const time_t ERROR_SMTP_SOCKET_TIME = 600; // number of seconds between attempts to open a socket to an smtp server |
94 | 86 |
87 | |
88 int SMTP::writer() { | |
89 #ifdef VERIFY_DEBUG | |
90 log("writer() sees buffer with %s", buffer); | |
91 log("writer() sees error %d", (int)error); | |
92 #endif | |
93 int rs = 0; | |
94 if (!error) { | |
95 int len = strlen(buffer); | |
96 while (rs < len) { | |
97 int ws = write(fd, buffer+rs, len-rs); | |
98 if (ws > 0) { | |
99 rs += ws; | |
100 } | |
101 else { | |
102 // peer closed the socket! | |
103 rs = 0; | |
104 error = true; | |
105 break; | |
106 } | |
107 } | |
108 } | |
109 return rs; | |
110 } | |
111 | |
112 | |
113 int SMTP::reader() { | |
114 // read some bytes terminated by lf or end of buffer. | |
115 // we may have a multi line response or part thereof in the buffer. | |
116 #ifdef VERIFY_DEBUG | |
117 log("reader() sees error %d", (int)error); | |
118 #endif | |
119 if (error) return 0; | |
120 int len = maxlen-1; // room for null terminator | |
121 while (pending < len) { | |
122 int ws = read(fd, buffer+pending, len-pending); | |
123 if (ws > 0) { | |
124 pending += ws; | |
125 if (buffer[pending-1] == '\n') break; | |
126 } | |
127 else { | |
128 // peer closed the socket! | |
129 pending = 0; | |
130 error = true; | |
131 break; | |
132 } | |
133 } | |
134 buffer[pending] = '\0'; | |
135 #ifdef VERIFY_DEBUG | |
136 log("reader() sees buffer with %s", buffer); | |
137 #endif | |
138 return pending; | |
139 } | |
140 | |
141 | |
142 int SMTP::read_line() { | |
143 char *lf = strchr(buffer, '\n'); | |
144 if (!lf) { | |
145 reader(); // get a lf | |
146 lf = strchr(buffer, '\n'); | |
147 if (!lf) lf = buffer + pending - 1; | |
148 } | |
149 return (lf-buffer)+1; // number of bytes in this line | |
150 } | |
151 | |
152 | |
97 | 153 void SMTP::flush_line(int r) { |
94 | 154 if (pending > r) memmove(buffer, buffer+r, pending-r); |
155 pending -= r; | |
156 } | |
157 | |
158 | |
159 int SMTP::read_response() { | |
160 pending = 0; | |
161 buffer[pending] = '\0'; | |
162 while (true) { | |
163 int r = read_line(); | |
164 #ifdef VERIFY_DEBUG | |
165 log("read_response() sees line with %s", buffer); | |
166 log("read_response() sees line length %d", r); | |
167 #endif | |
168 if (r == 0) return 0; // failed to read any bytes | |
169 if ((r > 4) && (buffer[3] == '-')) { | |
170 flush_line(r); | |
171 continue; | |
172 } | |
173 return atoi(buffer); | |
174 } | |
175 return 0; | |
176 } | |
177 | |
178 | |
179 int SMTP::cmd(char *c) { | |
180 if (c) { | |
181 init(); | |
182 append(c); | |
183 } | |
184 append("\r\n"); | |
185 writer(); | |
186 return read_response(); | |
187 } | |
188 | |
189 | |
190 int SMTP::helo() { | |
191 if (read_response() != 220) return 0; | |
192 init(); | |
193 append("HELO "); | |
194 append(token_myhostname); | |
195 return cmd(NULL); | |
196 } | |
197 | |
198 | |
199 int SMTP::rset() { | |
200 int rc = cmd("RSET"); | |
201 efrom[0] = '\0'; | |
202 return rc; | |
203 } | |
204 | |
205 | |
206 int SMTP::from(char *f) { | |
101 | 207 // the mail from address was originally passed in from sendmail enclosed in |
208 // <>. to_lower_string() removed the <> and converted the rest to lowercase, | |
209 // except in the case of an empty return path, which was left as the two | |
210 // character string <>. | |
94 | 211 if (strncmp(efrom, f, maxlen)) { |
212 rset(); | |
213 strncpy(efrom, f, maxlen); | |
214 init(); | |
215 append("MAIL FROM:<"); | |
101 | 216 if (*f != '<') append(f); |
94 | 217 append(">"); |
218 return cmd(NULL); | |
219 } | |
220 return 250; // pretend it worked | |
221 } | |
222 | |
223 | |
224 int SMTP::rcpt(char *t) { | |
225 init(); | |
226 append("RCPT TO:<"); | |
227 append(t); | |
228 append(">"); | |
229 return cmd(NULL); | |
230 } | |
231 | |
232 | |
233 int SMTP::quit() { | |
234 return cmd("QUIT"); | |
235 } | |
236 | |
237 | |
238 void SMTP::closefd() { | |
239 shutdown(fd, SHUT_RDWR); | |
240 close(fd); | |
241 } | |
242 | |
243 | |
244 #ifdef VERIFY_DEBUG | |
245 void SMTP::log(char *m, int v) { | |
246 char buf[maxlen]; | |
247 snprintf(buf, maxlen, m, v); | |
248 my_syslog(buf); | |
249 } | |
250 | |
251 | |
252 void SMTP::log(char *m, char *v) { | |
253 char buf[maxlen]; | |
254 snprintf(buf, maxlen, m, v); | |
255 my_syslog(buf); | |
256 } | |
257 #endif | |
258 | |
259 | |
153 | 260 //////////////////////////////////////////////// |
261 // smtp verifier so backup mx machines can see the valid users | |
262 // | |
94 | 263 VERIFY::VERIFY(char *h) { |
264 host = h; | |
265 last_err = 0; | |
266 pthread_mutex_init(&mutex, 0); | |
267 } | |
268 | |
269 | |
270 void VERIFY::closer() { | |
271 bool ok = true; | |
272 while (ok) { | |
273 SMTP *conn = NULL; | |
274 pthread_mutex_lock(&mutex); | |
275 if (connections.empty()) { | |
276 ok = false; | |
277 } | |
278 else { | |
279 conn = connections.front(); | |
280 time_t now = time(NULL); | |
153 | 281 if ((now - conn->get_stamp()) > maxsmtp_age) { |
94 | 282 // this connection is ancient, remove it |
283 connections.pop_front(); | |
284 } | |
285 else { | |
286 ok = false; | |
287 conn = NULL; | |
288 } | |
289 } | |
290 pthread_mutex_unlock(&mutex); | |
291 // avoid doing this work inside the mutex lock | |
292 if (conn) { | |
293 #ifdef VERIFY_DEBUG | |
294 conn->log("closer() closes ancient %d", conn->get_fd()); | |
295 #endif | |
296 delete conn; | |
297 } | |
298 } | |
299 } | |
300 | |
301 | |
302 SMTP* VERIFY::get_connection() { | |
303 SMTP *conn = NULL; | |
304 pthread_mutex_lock(&mutex); | |
305 if (!connections.empty()) { | |
306 conn = connections.front(); | |
307 connections.pop_front(); | |
308 #ifdef VERIFY_DEBUG | |
309 conn->log("get_connection() %d from cache", conn->get_fd()); | |
310 #endif | |
311 } | |
312 pthread_mutex_unlock(&mutex); | |
313 if (conn) return conn; | |
314 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
|
315 if ((time(NULL) - last_err) > ERROR_SMTP_SOCKET_TIME) { |
94 | 316 // nothing recent, maybe this time it will work |
317 hostent *h = gethostbyname(host); | |
318 if (h) { | |
319 sockaddr_in server; | |
320 server.sin_family = h->h_addrtype; | |
321 server.sin_port = htons(25); | |
322 memcpy(&server.sin_addr, h->h_addr_list[0], h->h_length); | |
323 sock = socket(PF_INET, SOCK_STREAM, 0); | |
324 if (sock != NULL_SOCKET) { | |
325 bool rc = (connect(sock, (sockaddr *)&server, sizeof(server)) == 0); | |
326 if (!rc) { | |
327 shutdown(sock, SHUT_RDWR); | |
328 close(sock); | |
329 sock = NULL_SOCKET; | |
129
c5cd1261394d
ignore smtp connection attempts for 10 minutes when getting connection errors on verify hosts
carl
parents:
119
diff
changeset
|
330 last_err = time(NULL); |
94 | 331 } |
332 } | |
129
c5cd1261394d
ignore smtp connection attempts for 10 minutes when getting connection errors on verify hosts
carl
parents:
119
diff
changeset
|
333 else last_err = time(NULL); |
94 | 334 } |
129
c5cd1261394d
ignore smtp connection attempts for 10 minutes when getting connection errors on verify hosts
carl
parents:
119
diff
changeset
|
335 else last_err = time(NULL); |
94 | 336 } |
337 if (sock != NULL_SOCKET) { | |
338 conn = new SMTP(sock); | |
339 #ifdef VERIFY_DEBUG | |
340 conn->log("get_connection() %d new socket", conn->get_fd()); | |
341 #endif | |
342 if (conn->helo() == 250) return conn; | |
343 delete conn; | |
344 } | |
345 return NULL; | |
346 } | |
347 | |
348 | |
349 void VERIFY::put_connection(SMTP *conn) { | |
350 if (conn->err()) { | |
351 #ifdef VERIFY_DEBUG | |
352 conn->log("put_socket() %d with error, close it", conn->get_fd()); | |
353 #endif | |
354 delete conn; | |
355 last_err = time(NULL); | |
356 } | |
357 else { | |
358 #ifdef VERIFY_DEBUG | |
359 conn->log("put_socket() %d", conn->get_fd()); | |
360 #endif | |
361 conn->now(); | |
362 pthread_mutex_lock(&mutex); | |
363 connections.push_back(conn); | |
364 pthread_mutex_unlock(&mutex); | |
365 } | |
366 } | |
367 | |
368 | |
369 bool VERIFY::ok(char *from, char *to) { | |
370 if (host == token_myhostname) return true; | |
371 SMTP *conn = get_connection(); | |
372 if (!conn) return true; // cannot verify right now, we have socket errors | |
373 int rc; | |
374 rc = conn->from(from); | |
375 #ifdef VERIFY_DEBUG | |
376 conn->log("verify::ok() from sees %d", rc); | |
377 #endif | |
378 if (rc != 250) { | |
379 conn->rset(); | |
380 put_connection(conn); | |
381 return (rc >= 500) ? false : true; | |
382 } | |
383 rc = conn->rcpt(to); | |
384 #ifdef VERIFY_DEBUG | |
385 conn->log("verify::ok() rcpt sees %d", rc); | |
386 #endif | |
387 put_connection(conn); | |
388 return (rc >= 500) ? false : true; | |
389 } | |
390 | |
391 | |
153 | 392 //////////////////////////////////////////////// |
393 // setup a new smtp verify host | |
394 // | |
395 VERIFYP add_verify_host(char *host); | |
396 VERIFYP add_verify_host(char *host) { | |
397 VERIFYP rc = NULL; | |
398 pthread_mutex_lock(&verifier_mutex); | |
399 verify_map::iterator i = verifiers.find(host); | |
400 if (i == verifiers.end()) { | |
401 rc = new VERIFY(host); | |
402 verifiers[host] = rc; | |
403 } | |
404 else rc = (*i).second; | |
405 pthread_mutex_unlock(&verifier_mutex); | |
406 return rc; | |
407 } | |
408 | |
409 | |
410 //////////////////////////////////////////////// | |
411 // thread to check for verify hosts with old sockets that we can close | |
412 // | |
413 void* verify_closer(void *arg) { | |
414 while (true) { | |
415 sleep(maxsmtp_age); | |
416 pthread_mutex_lock(&verifier_mutex); | |
417 for (verify_map::iterator i=verifiers.begin(); i!=verifiers.end(); i++) { | |
418 VERIFYP v = (*i).second; | |
419 v->closer(); | |
420 } | |
421 pthread_mutex_unlock(&verifier_mutex); | |
422 } | |
423 return NULL; | |
424 } | |
425 | |
426 | |
427 //////////////////////////////////////////////// | |
428 // automatic whitelister | |
429 // | |
430 WHITELISTER::WHITELISTER(char *f, int d) { | |
431 fn = f; | |
432 days = d; | |
433 pthread_mutex_init(&mutex, 0); | |
434 need = false; | |
160 | 435 loaded = time(NULL); |
436 merge(); | |
437 } | |
438 | |
439 | |
440 void WHITELISTER::merge() { | |
441 time_t now = time(NULL); | |
154 | 442 ifstream ifs; |
443 ifs.open(fn); | |
444 if (!ifs.fail()) { | |
445 const int maxlen = 1000; | |
446 char buf[maxlen]; | |
447 while (ifs.getline(buf, maxlen)) { | |
448 char *p = strchr(buf, ' '); | |
449 if (p) { | |
450 *p = '\0'; | |
160 | 451 char *who = strdup(buf); |
452 time_t when = atoi(p+1); | |
453 if ((when == 0) || (when > now)) when = now; | |
454 autowhite_sent::iterator i = rcpts.find(who); | |
173
83fe0be032c1
fix leak, update timestamps when receiving auto-whitelisted sender
carl
parents:
170
diff
changeset
|
455 if (i == rcpts.end()) { |
83fe0be032c1
fix leak, update timestamps when receiving auto-whitelisted sender
carl
parents:
170
diff
changeset
|
456 rcpts[who] = when; |
160 | 457 } |
458 else { | |
173
83fe0be032c1
fix leak, update timestamps when receiving auto-whitelisted sender
carl
parents:
170
diff
changeset
|
459 time_t wh = (*i).second; |
175
e726e1a61ef9
allow manual whitelisting with stamp 1 to remove a whitelist entry
carl
parents:
174
diff
changeset
|
460 if ((when == 1) || (when > wh)) (*i).second = when; |
173
83fe0be032c1
fix leak, update timestamps when receiving auto-whitelisted sender
carl
parents:
170
diff
changeset
|
461 free(who); |
160 | 462 } |
154 | 463 } |
464 } | |
465 } | |
466 ifs.close(); | |
153 | 467 } |
468 | |
469 | |
470 void WHITELISTER::writer() { | |
471 pthread_mutex_lock(&mutex); | |
472 time_t limit = time(NULL) - days*86400; | |
160 | 473 |
474 // check for manually modified autowhitelist file | |
475 struct stat st; | |
476 if (stat(fn, &st)) need = true; // file has disappeared | |
477 else if (st.st_mtime > loaded) { | |
478 // file has been manually updated, merge new entries | |
479 merge(); | |
480 need = true; | |
481 } | |
482 | |
483 // purge old entries | |
153 | 484 for (autowhite_sent::iterator i=rcpts.begin(); i!=rcpts.end();) { |
485 time_t when = (*i).second; | |
486 if (when < limit) { | |
154 | 487 char *who = (*i).first; |
488 free(who); | |
153 | 489 autowhite_sent::iterator j = i; |
490 j++; | |
491 rcpts.erase(i); | |
492 i = j; | |
493 need = true; | |
494 } | |
495 else i++; | |
496 } | |
160 | 497 |
153 | 498 if (need) { |
499 // dump the file | |
154 | 500 ofstream ofs; |
501 ofs.open(fn); | |
502 if (!ofs.fail()) { | |
153 | 503 for (autowhite_sent::iterator i=rcpts.begin(); i!=rcpts.end(); i++) { |
504 char *who = (*i).first; | |
505 int when = (*i).second; | |
174 | 506 if (!strchr(who, ' ')) { |
507 ofs << who << " " << when << endl; | |
508 } | |
153 | 509 } |
510 } | |
154 | 511 ofs.close(); |
156 | 512 need = false; |
160 | 513 loaded = time(NULL); // update load time |
153 | 514 } |
515 pthread_mutex_unlock(&mutex); | |
516 } | |
517 | |
518 | |
519 void WHITELISTER::sent(char *to) { | |
154 | 520 // we take ownership of the string |
153 | 521 pthread_mutex_lock(&mutex); |
522 need = true; | |
173
83fe0be032c1
fix leak, update timestamps when receiving auto-whitelisted sender
carl
parents:
170
diff
changeset
|
523 autowhite_sent::iterator i = rcpts.find(to); |
83fe0be032c1
fix leak, update timestamps when receiving auto-whitelisted sender
carl
parents:
170
diff
changeset
|
524 if (i == rcpts.end()) { |
83fe0be032c1
fix leak, update timestamps when receiving auto-whitelisted sender
carl
parents:
170
diff
changeset
|
525 rcpts[to] = time(NULL); |
83fe0be032c1
fix leak, update timestamps when receiving auto-whitelisted sender
carl
parents:
170
diff
changeset
|
526 } |
83fe0be032c1
fix leak, update timestamps when receiving auto-whitelisted sender
carl
parents:
170
diff
changeset
|
527 else { |
83fe0be032c1
fix leak, update timestamps when receiving auto-whitelisted sender
carl
parents:
170
diff
changeset
|
528 (*i).second = time(NULL); |
83fe0be032c1
fix leak, update timestamps when receiving auto-whitelisted sender
carl
parents:
170
diff
changeset
|
529 free(to); |
83fe0be032c1
fix leak, update timestamps when receiving auto-whitelisted sender
carl
parents:
170
diff
changeset
|
530 } |
153 | 531 pthread_mutex_unlock(&mutex); |
532 } | |
533 | |
534 | |
535 bool WHITELISTER::is_white(char *from) { | |
536 pthread_mutex_lock(&mutex); | |
537 autowhite_sent::iterator i = rcpts.find(from); | |
162 | 538 bool rc = (i != rcpts.end()); |
153 | 539 pthread_mutex_unlock(&mutex); |
540 return rc; | |
541 } | |
542 | |
543 | |
544 //////////////////////////////////////////////// | |
545 // setup a new auto whitelister file | |
546 // | |
547 WHITELISTERP add_whitelister_file(char *fn, int days); | |
548 WHITELISTERP add_whitelister_file(char *fn, int days) { | |
549 WHITELISTERP rc = NULL; | |
550 pthread_mutex_lock(&whitelister_mutex); | |
551 whitelister_map::iterator i = whitelisters.find(fn); | |
552 if (i == whitelisters.end()) { | |
553 rc = new WHITELISTER(fn, days); | |
554 whitelisters[fn] = rc; | |
555 } | |
156 | 556 else { |
557 rc = (*i).second; | |
558 rc->set_days(days); | |
559 } | |
153 | 560 pthread_mutex_unlock(&whitelister_mutex); |
561 return rc; | |
562 } | |
563 | |
564 | |
565 //////////////////////////////////////////////// | |
566 // thread to check for whitelister hosts with old sockets that we can close | |
567 // | |
568 void* whitelister_writer(void *arg) { | |
569 while (true) { | |
570 sleep(maxauto_age); | |
571 pthread_mutex_lock(&whitelister_mutex); | |
572 for (whitelister_map::iterator i=whitelisters.begin(); i!=whitelisters.end(); i++) { | |
573 WHITELISTERP v = (*i).second; | |
574 v->writer(); | |
575 } | |
576 pthread_mutex_unlock(&whitelister_mutex); | |
577 } | |
578 return NULL; | |
579 } | |
580 | |
581 | |
94 | 582 DNSBL::DNSBL(char *n, char *s, char *m) { |
583 name = n; | |
584 suffix = s; | |
585 message = m; | |
586 } | |
587 | |
588 | |
589 bool DNSBL::operator==(const DNSBL &rhs) { | |
590 return (strcmp(name, rhs.name) == 0) && | |
591 (strcmp(suffix, rhs.suffix) == 0) && | |
592 (strcmp(message, rhs.message) == 0); | |
593 } | |
594 | |
595 | |
596 CONFIG::CONFIG() { | |
597 reference_count = 0; | |
598 generation = 0; | |
599 load_time = 0; | |
600 default_context = NULL; | |
601 } | |
602 | |
603 | |
604 CONFIG::~CONFIG() { | |
146 | 605 if (debug_syslog) { |
606 char buf[maxlen]; | |
607 snprintf(buf, sizeof(buf), "freeing memory for old configuration generation %d", generation); | |
608 my_syslog(buf); | |
609 } | |
94 | 610 for (context_list::iterator i=contexts.begin(); i!=contexts.end(); i++) { |
611 CONTEXT *c = *i; | |
612 delete c; | |
613 } | |
614 } | |
615 | |
616 | |
617 void CONFIG::add_context(CONTEXTP con) { | |
618 contexts.push_back(con); | |
619 if (!default_context && !con->get_parent()) { | |
620 // first global context | |
621 default_context = con; | |
622 } | |
623 } | |
624 | |
625 | |
626 void CONFIG::add_to(char *to, CONTEXTP con) { | |
627 context_map::iterator i = env_to.find(to); | |
628 if (i != env_to.end()) { | |
629 CONTEXTP c = (*i).second; | |
630 if ((c != con) && (c != con->get_parent())) { | |
631 if (debug_syslog) { | |
632 char oldname[maxlen]; | |
633 char newname[maxlen]; | |
634 char *oldn = c->get_full_name(oldname, maxlen); | |
635 char *newn = con->get_full_name(newname, maxlen); | |
636 char buf[maxlen*3]; | |
637 snprintf(buf, maxlen*3, "both %s and %s claim envelope to %s, the second one wins", oldn, newn, to); | |
638 my_syslog(buf); | |
639 } | |
640 } | |
641 } | |
642 env_to[to] = con; | |
643 } | |
644 | |
645 | |
646 CONTEXTP CONFIG::find_context(char *to) { | |
647 context_map::iterator i = env_to.find(to); | |
117 | 648 if (i != env_to.end()) return (*i).second; // found user@domain key |
94 | 649 char *x = strchr(to, '@'); |
650 if (x) { | |
651 x++; | |
652 i = env_to.find(x); | |
117 | 653 if (i != env_to.end()) return (*i).second; // found domain key |
94 | 654 char y = *x; |
655 *x = '\0'; | |
656 i = env_to.find(to); | |
657 *x = y; | |
658 if (i != env_to.end()) return (*i).second; // found user@ key | |
659 } | |
660 return default_context; | |
661 } | |
662 | |
663 | |
664 void CONFIG::dump() { | |
167
9b129ed78d7d
actually use spamassassin result, allow build without spam assassin, only call it if some recipient needs it.
carl
parents:
164
diff
changeset
|
665 bool spamass = false; |
9b129ed78d7d
actually use spamassassin result, allow build without spam assassin, only call it if some recipient needs it.
carl
parents:
164
diff
changeset
|
666 if (default_context) default_context->dump(true, spamass); |
94 | 667 for (context_list::iterator i=contexts.begin(); i!=contexts.end(); i++) { |
668 CONTEXTP c = *i; | |
669 CONTEXTP p = c->get_parent(); | |
167
9b129ed78d7d
actually use spamassassin result, allow build without spam assassin, only call it if some recipient needs it.
carl
parents:
164
diff
changeset
|
670 if (!p && (c != default_context)) c->dump(false, spamass); |
94 | 671 } |
672 char buf[maxlen]; | |
673 for (context_map::iterator i=env_to.begin(); i!=env_to.end(); i++) { | |
674 char *to = (*i).first; | |
675 CONTEXTP con = (*i).second; | |
676 printf("// envelope to %s \t-> context %s \n", to, con->get_full_name(buf,maxlen)); | |
677 } | |
167
9b129ed78d7d
actually use spamassassin result, allow build without spam assassin, only call it if some recipient needs it.
carl
parents:
164
diff
changeset
|
678 if (spamass && (spamc == spamc_empty)) { |
9b129ed78d7d
actually use spamassassin result, allow build without spam assassin, only call it if some recipient needs it.
carl
parents:
164
diff
changeset
|
679 printf("// *** warning - spamassassin filtering requested, but spamc not found by autoconf.\n"); |
9b129ed78d7d
actually use spamassassin result, allow build without spam assassin, only call it if some recipient needs it.
carl
parents:
164
diff
changeset
|
680 } |
94 | 681 } |
682 | |
683 | |
684 CONTEXT::CONTEXT(CONTEXTP parent_, char *name_) { | |
685 parent = parent_; | |
686 name = name_; | |
687 verify_host = NULL; | |
153 | 688 verifier = NULL; |
168 | 689 generic_regx = NULL; |
690 generic_message = NULL; | |
153 | 691 autowhite_file = NULL; |
692 whitelister = NULL; | |
94 | 693 env_from_default = (parent) ? token_inherit : token_unknown; |
694 content_filtering = (parent) ? parent->content_filtering : false; | |
695 content_suffix = NULL; | |
696 content_message = NULL; | |
119 | 697 uribl_suffix = NULL; |
698 uribl_message = NULL; | |
94 | 699 host_limit = (parent) ? parent->host_limit : 0; |
700 host_limit_message = NULL; | |
701 host_random = (parent) ? parent->host_random : false; | |
702 tag_limit = (parent) ? parent->tag_limit : 0; | |
703 tag_limit_message = NULL; | |
163 | 704 spamassassin_limit = (parent) ? parent->spamassassin_limit : 0; |
178 | 705 require_match = (parent) ? parent->require_match : false; |
706 dcc_greylist = (parent) ? parent->dcc_greylist : false; | |
707 dcc_bulk_threshold = (parent) ? parent->dcc_bulk_threshold : 0; | |
140 | 708 default_rcpt_rate = INT_MAX; |
94 | 709 } |
710 | |
711 | |
712 CONTEXT::~CONTEXT() { | |
713 for (dnsblp_map::iterator i=dnsbl_names.begin(); i!=dnsbl_names.end(); i++) { | |
714 DNSBLP d = (*i).second; | |
715 // delete the underlying DNSBL objects. | |
716 delete d; | |
717 } | |
170 | 718 if (generic_regx) regfree(&generic_pattern); |
94 | 719 } |
720 | |
721 | |
722 bool CONTEXT::is_parent(CONTEXTP p) { | |
723 if (p == parent) return true; | |
724 if (!parent) return false; | |
725 return parent->is_parent(p); | |
726 } | |
727 | |
728 | |
729 char *CONTEXT::get_full_name(char *buffer, int size) { | |
730 if (!parent) return name; | |
731 char buf[maxlen]; | |
732 snprintf(buffer, size, "%s.%s", parent->get_full_name(buf, maxlen), name); | |
733 return buffer; | |
734 } | |
735 | |
736 | |
168 | 737 bool CONTEXT::set_generic(char *regx, char *msg) |
738 { | |
739 int rc = 0; | |
170 | 740 if (generic_regx) regfree(&generic_pattern); |
168 | 741 generic_regx = regx; |
742 generic_message = msg; | |
170 | 743 if (generic_regx) { |
168 | 744 rc = regcomp(&generic_pattern, regx, REG_NOSUB | REG_ICASE | REG_EXTENDED); |
745 } | |
746 return rc; // true iff bad pattern | |
747 } | |
748 | |
749 | |
750 char *CONTEXT::generic_match(char *client) | |
751 { | |
752 if (parent && !generic_regx) return parent->generic_match(client); | |
170 | 753 if (!generic_regx) return NULL; |
168 | 754 if (0 == regexec(&generic_pattern, client, 0, NULL, 0)) { |
755 return generic_message; | |
756 } | |
757 return NULL; | |
758 } | |
759 | |
760 | |
94 | 761 bool CONTEXT::cover_env_to(char *to) { |
762 char buffer[maxlen]; | |
763 char *x = strchr(to, '@'); | |
764 if (x) x++; | |
765 else x = to; | |
144
31ff00ea6bfb
allow parent/child to share a fully qualified env_to address
carl
parents:
143
diff
changeset
|
766 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
|
767 if (!parent && env_to.empty()) return true; // empty env_to at global level covers everything |
94 | 768 string_set::iterator i = env_to.find(x); |
144
31ff00ea6bfb
allow parent/child to share a fully qualified env_to address
carl
parents:
143
diff
changeset
|
769 if (i != env_to.end()) return true; // we cover the entire domain |
31ff00ea6bfb
allow parent/child to share a fully qualified env_to address
carl
parents:
143
diff
changeset
|
770 if (x != to) { |
31ff00ea6bfb
allow parent/child to share a fully qualified env_to address
carl
parents:
143
diff
changeset
|
771 i = env_to.find(to); |
31ff00ea6bfb
allow parent/child to share a fully qualified env_to address
carl
parents:
143
diff
changeset
|
772 if (i != env_to.end()) return true; // we cover the specific email address |
31ff00ea6bfb
allow parent/child to share a fully qualified env_to address
carl
parents:
143
diff
changeset
|
773 } |
94 | 774 return false; |
775 } | |
776 | |
777 | |
778 VERIFYP CONTEXT::find_verify(char *to) { | |
153 | 779 if (verifier && (verify_host != token_myhostname) && cover_env_to(to)) |
780 return verifier; | |
781 else if (parent) | |
782 return parent->find_verify(to); | |
783 else | |
784 return NULL; | |
785 } | |
94 | 786 |
153 | 787 |
162 | 788 WHITELISTERP CONTEXT::find_autowhite(char *from, char *to) { |
789 if (whitelister && cover_env_to(to) && !cover_env_to(from)) | |
153 | 790 return whitelister; |
791 else if (parent) | |
162 | 792 return parent->find_autowhite(from, to); |
153 | 793 else |
794 return NULL; | |
94 | 795 } |
796 | |
797 | |
136 | 798 int CONTEXT::find_rate(char *user) { |
140 | 799 if (rcpt_per_hour.empty()) return default_rcpt_rate; |
136 | 800 rcpt_rates::iterator i = rcpt_per_hour.find(user); |
140 | 801 return (i == rcpt_per_hour.end()) ? default_rcpt_rate : (*i).second; |
136 | 802 } |
803 | |
804 | |
173
83fe0be032c1
fix leak, update timestamps when receiving auto-whitelisted sender
carl
parents:
170
diff
changeset
|
805 char *CONTEXT::find_from(char *from, bool update_white) { |
83fe0be032c1
fix leak, update timestamps when receiving auto-whitelisted sender
carl
parents:
170
diff
changeset
|
806 if (whitelister && whitelister->is_white(from)) { |
83fe0be032c1
fix leak, update timestamps when receiving auto-whitelisted sender
carl
parents:
170
diff
changeset
|
807 if (update_white) { |
83fe0be032c1
fix leak, update timestamps when receiving auto-whitelisted sender
carl
parents:
170
diff
changeset
|
808 // update senders timestamp to extend the whitelisting period |
83fe0be032c1
fix leak, update timestamps when receiving auto-whitelisted sender
carl
parents:
170
diff
changeset
|
809 if (debug_syslog > 1) { |
83fe0be032c1
fix leak, update timestamps when receiving auto-whitelisted sender
carl
parents:
170
diff
changeset
|
810 char buf[maxlen]; |
83fe0be032c1
fix leak, update timestamps when receiving auto-whitelisted sender
carl
parents:
170
diff
changeset
|
811 char msg[maxlen]; |
83fe0be032c1
fix leak, update timestamps when receiving auto-whitelisted sender
carl
parents:
170
diff
changeset
|
812 snprintf(msg, sizeof(msg), "extend whitelist reply from <%s> in context %s", from, get_full_name(buf,maxlen)); |
83fe0be032c1
fix leak, update timestamps when receiving auto-whitelisted sender
carl
parents:
170
diff
changeset
|
813 my_syslog(msg); |
83fe0be032c1
fix leak, update timestamps when receiving auto-whitelisted sender
carl
parents:
170
diff
changeset
|
814 } |
83fe0be032c1
fix leak, update timestamps when receiving auto-whitelisted sender
carl
parents:
170
diff
changeset
|
815 whitelister->sent(strdup(from)); |
83fe0be032c1
fix leak, update timestamps when receiving auto-whitelisted sender
carl
parents:
170
diff
changeset
|
816 } |
83fe0be032c1
fix leak, update timestamps when receiving auto-whitelisted sender
carl
parents:
170
diff
changeset
|
817 return token_white; |
83fe0be032c1
fix leak, update timestamps when receiving auto-whitelisted sender
carl
parents:
170
diff
changeset
|
818 } |
148
9330b8d6a56b
add documentation fixes, allow env_from target of inherit
carl
parents:
146
diff
changeset
|
819 char *rc = env_from_default; |
94 | 820 string_map::iterator i = env_from.find(from); |
117 | 821 if (i != env_from.end()) rc = (*i).second; // found user@domain key |
94 | 822 else { |
823 char *x = strchr(from, '@'); | |
824 if (x) { | |
825 x++; | |
826 i = env_from.find(x); | |
117 | 827 if (i != env_from.end()) rc = (*i).second; // found domain key |
94 | 828 else { |
829 char y = *x; | |
830 *x = '\0'; | |
831 i = env_from.find(from); | |
832 *x = y; | |
833 if (i != env_from.end()) rc = (*i).second; // found user@ key | |
834 } | |
835 } | |
836 } | |
837 if ((rc == token_inherit) && parent) return parent->find_from(from); | |
838 return (rc == token_inherit) ? token_unknown : rc; | |
839 } | |
840 | |
841 | |
842 CONTEXTP CONTEXT::find_context(char *from) { | |
843 context_map::iterator i = env_from_context.find(from); | |
117 | 844 if (i != env_from_context.end()) return (*i).second; // found user@domain key |
94 | 845 char *x = strchr(from, '@'); |
846 if (x) { | |
847 x++; | |
848 i = env_from_context.find(x); | |
117 | 849 if (i != env_from_context.end()) return (*i).second; // found domain key |
94 | 850 char y = *x; |
851 *x = '\0'; | |
852 i = env_from_context.find(from); | |
853 *x = y; | |
854 if (i != env_from_context.end()) return (*i).second; // found user@ key | |
855 } | |
856 return this; | |
857 } | |
858 | |
859 | |
860 CONTEXTP CONTEXT::find_from_context_name(char *name) { | |
861 context_map::iterator i = children.find(name); | |
862 if (i != children.end()) return (*i).second; | |
863 return NULL; | |
864 } | |
865 | |
866 | |
867 DNSBLP CONTEXT::find_dnsbl(char *name) { | |
868 dnsblp_map::iterator i = dnsbl_names.find(name); | |
869 if (i != dnsbl_names.end()) return (*i).second; | |
870 if (parent) return parent->find_dnsbl(name); | |
871 return NULL; | |
872 } | |
873 | |
874 | |
875 char* CONTEXT::get_content_suffix() { | |
876 if (!content_suffix && parent) return parent->get_content_suffix(); | |
877 return content_suffix; | |
878 } | |
879 | |
880 | |
119 | 881 char* CONTEXT::get_uribl_suffix() { |
882 if (!uribl_suffix && parent) return parent->get_uribl_suffix(); | |
883 return uribl_suffix; | |
884 } | |
885 | |
886 | |
94 | 887 char* CONTEXT::get_content_message() { |
888 if (!content_message && parent) return parent->get_content_message(); | |
889 return content_message; | |
890 } | |
891 | |
892 | |
119 | 893 char* CONTEXT::get_uribl_message() { |
894 if (!uribl_message && parent) return parent->get_uribl_message(); | |
895 return uribl_message; | |
896 } | |
897 | |
898 | |
94 | 899 string_set& CONTEXT::get_content_host_ignore() { |
900 if (content_host_ignore.empty() && parent) return parent->get_content_host_ignore(); | |
901 return content_host_ignore; | |
902 } | |
903 | |
904 | |
117 | 905 string_set& CONTEXT::get_content_cctlds() { |
906 if (content_cctlds.empty() && parent) return parent->get_content_cctlds(); | |
907 return content_cctlds; | |
908 } | |
909 | |
94 | 910 string_set& CONTEXT::get_content_tlds() { |
911 if (content_tlds.empty() && parent) return parent->get_content_tlds(); | |
912 return content_tlds; | |
913 } | |
914 | |
915 | |
916 string_set& CONTEXT::get_html_tags() { | |
917 if (html_tags.empty() && parent) return parent->get_html_tags(); | |
918 return html_tags; | |
919 } | |
920 | |
921 | |
922 dnsblp_list& CONTEXT::get_dnsbl_list() { | |
923 if (dnsbl_list.empty() && parent) return parent->get_dnsbl_list(); | |
924 return dnsbl_list; | |
925 } | |
926 | |
927 | |
178 | 928 bool CONTEXT::acceptable_content(recorder &memory, int score, int bulk, string& msg) { |
163 | 929 if (spamassassin_limit && (score > spamassassin_limit)) { |
167
9b129ed78d7d
actually use spamassassin result, allow build without spam assassin, only call it if some recipient needs it.
carl
parents:
164
diff
changeset
|
930 char buf[maxlen]; |
9b129ed78d7d
actually use spamassassin result, allow build without spam assassin, only call it if some recipient needs it.
carl
parents:
164
diff
changeset
|
931 snprintf(buf, sizeof(buf), "Mail rejected - spam assassin score %d", score); |
9b129ed78d7d
actually use spamassassin result, allow build without spam assassin, only call it if some recipient needs it.
carl
parents:
164
diff
changeset
|
932 msg = string(buf); |
9b129ed78d7d
actually use spamassassin result, allow build without spam assassin, only call it if some recipient needs it.
carl
parents:
164
diff
changeset
|
933 return false; |
163 | 934 } |
178 | 935 if (dcc_bulk_threshold && (bulk > dcc_bulk_threshold)) { |
936 char buf[maxlen]; | |
937 snprintf(buf, sizeof(buf), "Mail rejected - dcc score %d", bulk); | |
938 msg = string(buf); | |
939 return false; | |
940 } | |
94 | 941 if (memory.excessive_bad_tags(tag_limit)) { |
167
9b129ed78d7d
actually use spamassassin result, allow build without spam assassin, only call it if some recipient needs it.
carl
parents:
164
diff
changeset
|
942 msg = string(tag_limit_message); |
94 | 943 return false; |
944 } | |
945 if (!host_random && memory.excessive_hosts(host_limit)) { | |
167
9b129ed78d7d
actually use spamassassin result, allow build without spam assassin, only call it if some recipient needs it.
carl
parents:
164
diff
changeset
|
946 msg = string(host_limit_message); |
94 | 947 return false; |
948 } | |
949 return true; | |
950 } | |
951 | |
952 | |
167
9b129ed78d7d
actually use spamassassin result, allow build without spam assassin, only call it if some recipient needs it.
carl
parents:
164
diff
changeset
|
953 void CONTEXT::dump(bool isdefault, bool &spamass, int level) { |
94 | 954 char indent[maxlen]; |
955 int i = min(maxlen-1, level*4); | |
956 memset(indent, ' ', i); | |
957 indent[i] = '\0'; | |
958 char buf[maxlen]; | |
959 char *fullname = get_full_name(buf,maxlen); | |
960 printf("%s context %s { \t// %s\n", indent, name, fullname); | |
961 | |
962 for (dnsblp_map::iterator i=dnsbl_names.begin(); i!=dnsbl_names.end(); i++) { | |
963 char *n = (*i).first; | |
964 DNSBL &d = *(*i).second; | |
965 printf("%s dnsbl %s %s \"%s\"; \n", indent, n, d.suffix, d.message); | |
966 } | |
967 | |
145 | 968 dnsblp_list dl = get_dnsbl_list(); |
969 if (!dl.empty()) { | |
94 | 970 printf("%s dnsbl_list", indent); |
145 | 971 for (dnsblp_list::iterator i=dl.begin(); i!=dl.end(); i++) { |
94 | 972 DNSBL &d = *(*i); |
973 printf(" %s", d.name); | |
974 } | |
975 printf("; \n"); | |
976 } | |
977 | |
978 if (content_filtering) { | |
979 printf("%s content on { \n", indent, env_from_default); | |
980 if (content_suffix) { | |
981 printf("%s filter %s \"%s\"; \n", indent, content_suffix, content_message); | |
982 } | |
119 | 983 if (uribl_suffix) { |
984 printf("%s uribl %s \"%s\"; \n", indent, uribl_suffix, uribl_message); | |
985 } | |
94 | 986 if (!content_host_ignore.empty()) { |
987 printf("%s ignore { \n", indent); | |
988 for (string_set::iterator i=content_host_ignore.begin(); i!=content_host_ignore.end(); i++) { | |
989 printf("%s %s; \n", indent, *i); | |
990 } | |
991 printf("%s }; \n", indent); | |
992 } | |
117 | 993 if (!content_cctlds.empty()) { |
994 printf("%s cctld { \n", indent); | |
995 printf("%s ", indent); | |
996 for (string_set::iterator i=content_cctlds.begin(); i!=content_cctlds.end(); i++) { | |
997 printf("%s; ", *i); | |
998 } | |
999 printf("\n%s }; \n", indent); | |
1000 } | |
94 | 1001 if (!content_tlds.empty()) { |
1002 printf("%s tld { \n", indent); | |
1003 printf("%s ", indent); | |
1004 for (string_set::iterator i=content_tlds.begin(); i!=content_tlds.end(); i++) { | |
1005 printf("%s; ", *i); | |
1006 } | |
1007 printf("\n%s }; \n", indent); | |
1008 } | |
1009 if (!html_tags.empty()) { | |
1010 printf("%s html_tags { \n", indent); | |
1011 printf("%s ", indent); | |
1012 for (string_set::iterator i=html_tags.begin(); i!=html_tags.end(); i++) { | |
1013 printf("%s; ", *i); | |
1014 } | |
1015 printf("\n%s }; \n", indent); | |
1016 } | |
1017 if (host_limit_message) { | |
1018 printf("%s host_limit on %d \"%s\"; \n", indent, host_limit, host_limit_message); | |
1019 } | |
1020 else if (host_random) { | |
1021 printf("%s host_limit soft %d; \n", indent, host_limit); | |
1022 } | |
1023 else { | |
1024 printf("%s host_limit off; \n", indent); | |
1025 } | |
1026 if (tag_limit_message) { | |
1027 printf("%s html_limit on %d \"%s\"; \n", indent, tag_limit, tag_limit_message); | |
1028 } | |
1029 else { | |
1030 printf("%s html_limit off; \n", indent); | |
1031 } | |
163 | 1032 printf("%s spamassassin %d; \n", indent, spamassassin_limit); |
178 | 1033 printf("%s require_match %s; \n", indent, (require_match) ? "yes" : "no"); |
1034 printf("%s dcc_greylist %s; \n", indent, (dcc_greylist) ? "yes" : "no"); | |
1035 if (dcc_bulk_threshold == 0) printf("%s dcc_bulk_threshold off; \n", indent); | |
180 | 1036 else if (dcc_bulk_threshold >= dccbulk) printf("%s dcc_bulk_threshold many; \n", indent); |
178 | 1037 else printf("%s dcc_bulk_threshold %d; \n", indent, dcc_bulk_threshold); |
94 | 1038 printf("%s }; \n", indent); |
167
9b129ed78d7d
actually use spamassassin result, allow build without spam assassin, only call it if some recipient needs it.
carl
parents:
164
diff
changeset
|
1039 spamass |= (spamassassin_limit != 0); |
94 | 1040 } |
1041 else { | |
1042 printf("%s content off {}; \n", indent, env_from_default); | |
1043 } | |
1044 | |
1045 printf("%s env_to { \t// %s\n", indent, fullname); | |
1046 for (string_set::iterator i=env_to.begin(); i!=env_to.end(); i++) { | |
1047 printf("%s %s; \n", indent, *i); | |
1048 } | |
1049 printf("%s }; \n", indent); | |
1050 | |
1051 if (verify_host) { | |
1052 printf("%s verify %s; \n", indent, verify_host); | |
1053 } | |
1054 | |
168 | 1055 if (generic_regx) { |
1056 printf("%s generic \"%s\" \n", indent, generic_regx); | |
1057 printf("%s \"%s\"; \n", indent, generic_message); | |
1058 } | |
1059 | |
153 | 1060 if (autowhite_file && whitelister) { |
1061 printf("%s autowhite %d %s; \n", indent, whitelister->get_days(), autowhite_file); | |
1062 } | |
1063 | |
94 | 1064 for (context_map::iterator i=children.begin(); i!=children.end(); i++) { |
1065 CONTEXTP c = (*i).second; | |
167
9b129ed78d7d
actually use spamassassin result, allow build without spam assassin, only call it if some recipient needs it.
carl
parents:
164
diff
changeset
|
1066 c->dump(false, spamass, level+1); |
94 | 1067 } |
1068 | |
1069 printf("%s env_from %s { \t// %s\n", indent, env_from_default, fullname); | |
1070 if (!env_from.empty()) { | |
1071 printf("%s // white/black/unknown \n", indent); | |
1072 for (string_map::iterator i=env_from.begin(); i!=env_from.end(); i++) { | |
1073 char *f = (*i).first; | |
1074 char *t = (*i).second; | |
1075 printf("%s %s \t%s; \n", indent, f, t); | |
1076 } | |
1077 } | |
1078 if (!env_from_context.empty()) { | |
1079 printf("%s // child contexts \n", indent); | |
1080 for (context_map::iterator j=env_from_context.begin(); j!=env_from_context.end(); j++) { | |
1081 char *f = (*j).first; | |
1082 CONTEXTP t = (*j).second; | |
1083 printf("%s %s \t%s; \n", indent, f, t->name); | |
1084 } | |
1085 } | |
1086 printf("%s }; \n", indent); | |
1087 | |
144
31ff00ea6bfb
allow parent/child to share a fully qualified env_to address
carl
parents:
143
diff
changeset
|
1088 if (isdefault) { |
31ff00ea6bfb
allow parent/child to share a fully qualified env_to address
carl
parents:
143
diff
changeset
|
1089 printf("%s rate_limit %d { \n", indent, default_rcpt_rate); |
31ff00ea6bfb
allow parent/child to share a fully qualified env_to address
carl
parents:
143
diff
changeset
|
1090 for (rcpt_rates::iterator j=rcpt_per_hour.begin(); j!=rcpt_per_hour.end(); j++) { |
31ff00ea6bfb
allow parent/child to share a fully qualified env_to address
carl
parents:
143
diff
changeset
|
1091 char *u = (*j).first; |
31ff00ea6bfb
allow parent/child to share a fully qualified env_to address
carl
parents:
143
diff
changeset
|
1092 int l = (*j).second; |
31ff00ea6bfb
allow parent/child to share a fully qualified env_to address
carl
parents:
143
diff
changeset
|
1093 printf("%s \"%s\" \t%d; \n", indent, u, l); |
31ff00ea6bfb
allow parent/child to share a fully qualified env_to address
carl
parents:
143
diff
changeset
|
1094 } |
31ff00ea6bfb
allow parent/child to share a fully qualified env_to address
carl
parents:
143
diff
changeset
|
1095 printf("%s }; \n", indent); |
136 | 1096 } |
1097 | |
94 | 1098 printf("%s }; \n", indent); |
1099 } | |
1100 | |
1101 | |
1102 //////////////////////////////////////////////// | |
1103 // helper to discard the strings held by a string_set | |
1104 // | |
1105 void discard(string_set &s) { | |
1106 for (string_set::iterator i=s.begin(); i!=s.end(); i++) { | |
1107 free(*i); | |
1108 } | |
1109 s.clear(); | |
1110 } | |
1111 | |
1112 | |
1113 //////////////////////////////////////////////// | |
1114 // helper to register a string in a string set | |
1115 // | |
1116 char* register_string(string_set &s, char *name) { | |
1117 string_set::iterator i = s.find(name); | |
1118 if (i != s.end()) return *i; | |
1119 char *x = strdup(name); | |
1120 s.insert(x); | |
1121 return x; | |
1122 } | |
1123 | |
1124 | |
1125 //////////////////////////////////////////////// | |
1126 // register a global string | |
1127 // | |
1128 char* register_string(char *name) { | |
1129 return register_string(all_strings, name); | |
1130 } | |
1131 | |
1132 | |
1133 //////////////////////////////////////////////// | |
164 | 1134 // clear all global strings, helper for valgrind checking |
1135 // | |
1136 void clear_strings() { | |
1137 discard(all_strings); | |
1138 } | |
1139 | |
1140 | |
1141 //////////////////////////////////////////////// | |
94 | 1142 // |
1143 bool tsa(TOKEN &tok, char *token); | |
1144 bool tsa(TOKEN &tok, char *token) { | |
1145 char *have = tok.next(); | |
1146 if (have == token) return true; | |
1147 tok.token_error(token, have); | |
1148 return false; | |
1149 } | |
1150 | |
1151 | |
1152 //////////////////////////////////////////////// | |
1153 // | |
1154 bool parse_dnsbl(TOKEN &tok, CONFIG &dc, CONTEXT &me); | |
1155 bool parse_dnsbl(TOKEN &tok, CONFIG &dc, CONTEXT &me) { | |
1156 char *name = tok.next(); | |
1157 char *suf = tok.next(); | |
1158 char *msg = tok.next(); | |
1159 if (!tsa(tok, token_semi)) return false; | |
1160 DNSBLP dnsnew = new DNSBL(name, suf, msg); | |
1161 DNSBLP dnsold = me.find_dnsbl(name); | |
1162 if (dnsold && (*dnsold == *dnsnew)) { | |
1163 // duplicate redefinition, ignore it | |
1164 delete dnsnew; | |
1165 return true; | |
1166 } | |
1167 me.add_dnsbl(name, dnsnew); | |
1168 return true; | |
1169 } | |
1170 | |
1171 | |
1172 //////////////////////////////////////////////// | |
1173 // | |
1174 bool parse_dnsbll(TOKEN &tok, CONFIG &dc, CONTEXT &me); | |
1175 bool parse_dnsbll(TOKEN &tok, CONFIG &dc, CONTEXT &me) { | |
1176 while (true) { | |
1177 char *have = tok.next(); | |
1178 if (!have) break; | |
1179 if (have == token_semi) break; | |
1180 DNSBLP dns = me.find_dnsbl(have); | |
1181 if (dns) { | |
1182 me.add_dnsbl(dns); | |
1183 } | |
1184 else { | |
1185 tok.token_error("dnsbl name", have); | |
1186 return false; | |
1187 } | |
1188 } | |
1189 return true; | |
1190 } | |
1191 | |
1192 | |
1193 //////////////////////////////////////////////// | |
1194 // | |
1195 bool parse_content(TOKEN &tok, CONFIG &dc, CONTEXT &me); | |
1196 bool parse_content(TOKEN &tok, CONFIG &dc, CONTEXT &me) { | |
1197 char *setting = tok.next(); | |
1198 if (setting == token_on) { | |
1199 me.set_content_filtering(true); | |
1200 } | |
1201 else if (setting == token_off) { | |
1202 me.set_content_filtering(false); | |
1203 } | |
1204 else { | |
1205 tok.token_error("on/off", setting); | |
1206 return false; | |
1207 } | |
1208 if (!tsa(tok, token_lbrace)) return false; | |
1209 while (true) { | |
1210 char *have = tok.next(); | |
1211 if (!have) break; | |
1212 if (have == token_filter) { | |
1213 char *suffix = tok.next(); | |
1214 char *messag = tok.next(); | |
1215 me.set_content_suffix(suffix); | |
1216 me.set_content_message(messag); | |
1217 if (!tsa(tok, token_semi)) return false; | |
1218 } | |
119 | 1219 else if (have == token_uribl) { |
1220 char *suffix = tok.next(); | |
1221 char *messag = tok.next(); | |
1222 me.set_uribl_suffix(suffix); | |
1223 me.set_uribl_message(messag); | |
1224 if (!tsa(tok, token_semi)) return false; | |
1225 } | |
94 | 1226 else if (have == token_ignore) { |
1227 if (!tsa(tok, token_lbrace)) return false; | |
1228 while (true) { | |
1229 if (!have) break; | |
1230 char *have = tok.next(); | |
1231 if (have == token_rbrace) break; // done | |
1232 me.add_ignore(have); | |
1233 } | |
1234 if (!tsa(tok, token_semi)) return false; | |
1235 } | |
1236 else if (have == token_tld) { | |
1237 if (!tsa(tok, token_lbrace)) return false; | |
1238 while (true) { | |
1239 char *have = tok.next(); | |
1240 if (!have) break; | |
1241 if (have == token_rbrace) break; // done | |
1242 me.add_tld(have); | |
1243 } | |
1244 if (!tsa(tok, token_semi)) return false; | |
1245 } | |
178 | 1246 else if (have == token_cctld) { |
1247 if (!tsa(tok, token_lbrace)) return false; | |
1248 while (true) { | |
1249 char *have = tok.next(); | |
1250 if (!have) break; | |
1251 if (have == token_rbrace) break; // done | |
1252 me.add_cctld(have); | |
94 | 1253 } |
1254 if (!tsa(tok, token_semi)) return false; | |
1255 } | |
1256 else if (have == token_html_tags) { | |
1257 if (!tsa(tok, token_lbrace)) return false; | |
1258 while (true) { | |
1259 char *have = tok.next(); | |
1260 if (!have) break; | |
1261 if (have == token_rbrace) { | |
1262 break; // done | |
1263 } | |
1264 else { | |
1265 me.add_tag(have); // base version | |
1266 char buf[200]; | |
1267 snprintf(buf, sizeof(buf), "/%s", have); | |
1268 me.add_tag(register_string(buf)); // leading / | |
1269 snprintf(buf, sizeof(buf), "%s/", have); | |
1270 me.add_tag(register_string(buf)); // trailing / | |
1271 } | |
1272 } | |
1273 if (!tsa(tok, token_semi)) return false; | |
1274 } | |
178 | 1275 else if (have == token_html_limit) { |
1276 have = tok.next(); | |
1277 if (have == token_on) { | |
1278 me.set_tag_limit(tok.nextint()); | |
1279 me.set_tag_message(tok.next()); | |
1280 } | |
1281 else if (have == token_off) { | |
1282 me.set_tag_limit(0); | |
1283 me.set_tag_message(NULL); | |
1284 } | |
1285 else { | |
1286 tok.token_error("on/off", have); | |
1287 return false; | |
1288 } | |
1289 if (!tsa(tok, token_semi)) return false; | |
1290 } | |
94 | 1291 else if (have == token_host_limit) { |
1292 have = tok.next(); | |
1293 if (have == token_on) { | |
1294 me.set_host_limit(tok.nextint()); | |
1295 me.set_host_message(tok.next()); | |
1296 me.set_host_random(false); | |
1297 } | |
1298 else if (have == token_off) { | |
1299 me.set_host_limit(0); | |
1300 me.set_host_message(NULL); | |
1301 me.set_host_random(false); | |
1302 } | |
1303 else if (have == token_soft) { | |
1304 me.set_host_limit(tok.nextint()); | |
1305 me.set_host_message(NULL); | |
1306 me.set_host_random(true); | |
1307 } | |
1308 else { | |
1309 tok.token_error("on/off/soft", have); | |
1310 return false; | |
1311 } | |
1312 if (!tsa(tok, token_semi)) return false; | |
1313 } | |
163 | 1314 else if (have == token_spamassassin) { |
1315 me.set_spamassassin_limit(tok.nextint()); | |
1316 if (!tsa(tok, token_semi)) return false; | |
1317 } | |
178 | 1318 else if (have == token_require) { |
1319 have = tok.next(); | |
1320 if (have == token_yes) me.set_require(true); | |
1321 else if (have == token_no) me.set_require(false); | |
1322 else { | |
1323 tok.token_error("yes/no", have); | |
1324 return false; | |
1325 } | |
1326 if (!tsa(tok, token_semi)) return false; | |
1327 } | |
1328 else if (have == token_dccgrey) { | |
1329 have = tok.next(); | |
1330 if (have == token_yes) me.set_grey(true); | |
1331 else if (have == token_no) me.set_grey(false); | |
1332 else { | |
1333 tok.token_error("yes/no", have); | |
1334 return false; | |
1335 } | |
1336 if (!tsa(tok, token_semi)) return false; | |
1337 } | |
1338 else if (have == token_dccbulk) { | |
1339 have = tok.next(); | |
1340 if (have == token_off) me.set_bulk(0); | |
180 | 1341 else if (have == token_many) me.set_bulk(dccbulk); |
178 | 1342 else { |
1343 char *e; | |
1344 long i = strtol(have, &e, 10); | |
1345 if (*e != '\0') { | |
1346 tok.token_error("integer", have); | |
1347 return false; | |
1348 } | |
1349 me.set_bulk((int)i); | |
1350 } | |
1351 if (!tsa(tok, token_semi)) return false; | |
1352 } | |
94 | 1353 else if (have == token_rbrace) { |
1354 break; // done | |
1355 } | |
1356 else { | |
1357 tok.token_error("content keyword", have); | |
1358 return false; | |
1359 } | |
1360 } | |
1361 return tsa(tok, token_semi); | |
1362 } | |
1363 | |
1364 | |
1365 //////////////////////////////////////////////// | |
1366 // | |
1367 bool parse_envto(TOKEN &tok, CONFIG &dc, CONTEXT &me); | |
1368 bool parse_envto(TOKEN &tok, CONFIG &dc, CONTEXT &me) { | |
1369 if (!tsa(tok, token_lbrace)) return false; | |
1370 while (true) { | |
1371 char *have = tok.next(); | |
1372 if (!have) break; | |
1373 if (have == token_rbrace) break; | |
1374 if (have == token_semi) { | |
1375 // optional separators | |
1376 } | |
1377 else if (have == token_dccto) { | |
1378 char *flavor = tok.next(); | |
1379 if (!tsa(tok, token_lbrace)) return false; | |
1380 bool keeping = false; | |
1381 while (true) { | |
1382 char *have = tok.next(); | |
1383 if (!have) break; | |
1384 if (have == token_rbrace) break; | |
1385 if (have == flavor) { | |
1386 keeping = true; | |
1387 continue; | |
1388 } | |
1389 else if ((have == token_ok) || (have == token_ok2) || (have == token_many)) { | |
1390 keeping = false; | |
1391 continue; | |
1392 } | |
1393 if (have == token_envto) { | |
1394 have = tok.next(); | |
1395 if (keeping) { | |
1396 if (me.allow_env_to(have)) { | |
1397 me.add_to(have); | |
1398 dc.add_to(have, &me); | |
1399 } | |
1400 } | |
1401 } | |
1402 //else if (have == token_substitute) { | |
1403 // if (tok.next() == token_mailhost) { | |
1404 // have = tok.next(); | |
1405 // if (keeping) { | |
1406 // if (me.allow_env_to(have)) { | |
1407 // me.add_to(have); | |
1408 // dc.add_to(have, &me); | |
1409 // } | |
1410 // } | |
1411 // } | |
1412 //} | |
1413 tok.skipeol(); | |
1414 } | |
1415 } | |
1416 else if (me.allow_env_to(have)) { | |
1417 me.add_to(have); | |
1418 dc.add_to(have, &me); | |
1419 } | |
1420 else { | |
1421 tok.token_error("user@ or user@domain.tld or domain.tld where domain.tld allowed by parent context", have); | |
1422 return false; | |
1423 } | |
1424 } | |
1425 return tsa(tok, token_semi); | |
1426 } | |
1427 | |
1428 | |
1429 //////////////////////////////////////////////// | |
1430 // | |
1431 bool parse_verify(TOKEN &tok, CONFIG &dc, CONTEXT &me); | |
1432 bool parse_verify(TOKEN &tok, CONFIG &dc, CONTEXT &me) { | |
1433 char *host = tok.next(); | |
1434 if (!tsa(tok, token_semi)) return false; | |
1435 me.set_verify(host); | |
153 | 1436 me.set_verifier(add_verify_host(host)); |
1437 return true; | |
1438 } | |
1439 | |
1440 | |
1441 //////////////////////////////////////////////// | |
1442 // | |
168 | 1443 bool parse_generic(TOKEN &tok, CONFIG &dc, CONTEXT &me); |
1444 bool parse_generic(TOKEN &tok, CONFIG &dc, CONTEXT &me) { | |
1445 char *regx = tok.next(); | |
1446 char *msg = tok.next(); | |
1447 if (!tsa(tok, token_semi)) return false; | |
1448 if (me.set_generic(regx, msg)) { | |
1449 tok.token_error("invalid regular expression %s", regx, regx); | |
1450 return false; | |
1451 } | |
1452 return true; | |
1453 } | |
1454 | |
1455 | |
1456 //////////////////////////////////////////////// | |
1457 // | |
153 | 1458 bool parse_autowhite(TOKEN &tok, CONFIG &dc, CONTEXT &me); |
1459 bool parse_autowhite(TOKEN &tok, CONFIG &dc, CONTEXT &me) { | |
1460 int days = tok.nextint(); | |
1461 char *fn = tok.next(); | |
1462 if (!tsa(tok, token_semi)) return false; | |
1463 me.set_autowhite(fn); | |
1464 me.set_whitelister(add_whitelister_file(fn, days)); | |
99 | 1465 return true; |
94 | 1466 } |
1467 | |
1468 | |
1469 //////////////////////////////////////////////// | |
1470 // | |
1471 bool parse_envfrom(TOKEN &tok, CONFIG &dc, CONTEXT &me); | |
1472 bool parse_envfrom(TOKEN &tok, CONFIG &dc, CONTEXT &me) { | |
1473 char *st = tok.next(); | |
1474 if ((st == token_black) || (st == token_white) || (st == token_unknown) || (st == token_inherit)) { | |
1475 me.set_from_default(st); | |
1476 } | |
1477 else { | |
1478 tok.push(st); | |
1479 } | |
1480 if (!tsa(tok, token_lbrace)) return false; | |
1481 while (true) { | |
1482 char *have = tok.next(); | |
1483 if (!have) break; | |
1484 if (have == token_rbrace) break; | |
1485 if (have == token_semi) { | |
1486 // optional separators | |
1487 } | |
1488 else if (have == token_dccfrom) { | |
1489 if (!tsa(tok, token_lbrace)) return false; | |
1490 bool keeping = false; | |
1491 bool many = false; | |
1492 while (true) { | |
1493 char *have = tok.next(); | |
1494 if (!have) break; | |
1495 if (have == token_rbrace) break; | |
1496 if (have == token_ok) { | |
1497 keeping = true; | |
1498 many = false; | |
1499 continue; | |
1500 } | |
1501 else if (have == token_many) { | |
1502 keeping = true; | |
1503 many = true; | |
1504 continue; | |
1505 } | |
1506 else if (have == token_ok2) { | |
1507 keeping = false; | |
1508 continue; | |
1509 } | |
1510 if (have == token_envfrom) { | |
1511 have = tok.next(); | |
1512 if (keeping) { | |
1513 me.add_from(have, (many) ? token_black : token_white); | |
1514 } | |
1515 } | |
1516 else if (have == token_substitute) { | |
1517 if (tok.next() == token_mailhost) { | |
1518 have = tok.next(); | |
1519 me.add_from(have, (many) ? token_black : token_white); | |
1520 } | |
1521 } | |
1522 tok.skipeol(); | |
1523 } | |
1524 } | |
1525 else { | |
1526 // may be a valid email address or domain name | |
1527 char *st = tok.next(); | |
148
9330b8d6a56b
add documentation fixes, allow env_from target of inherit
carl
parents:
146
diff
changeset
|
1528 if ((st == token_white) || (st == token_black) || (st == token_unknown) || (st == token_inherit)) { |
94 | 1529 me.add_from(have, st); |
1530 } | |
1531 else { | |
1532 CONTEXTP con = me.find_from_context_name(st); | |
1533 if (con) { | |
1534 me.add_from_context(have, con); | |
1535 } | |
1536 else { | |
148
9330b8d6a56b
add documentation fixes, allow env_from target of inherit
carl
parents:
146
diff
changeset
|
1537 tok.token_error("white/black/unknown/inherit or child context name", st); |
94 | 1538 return false; |
1539 } | |
1540 } | |
1541 } | |
1542 } | |
1543 return tsa(tok, token_semi); | |
1544 } | |
1545 | |
1546 | |
1547 //////////////////////////////////////////////// | |
1548 // | |
136 | 1549 bool parse_rate(TOKEN &tok, CONFIG &dc, CONTEXT &me); |
1550 bool parse_rate(TOKEN &tok, CONFIG &dc, CONTEXT &me) { | |
140 | 1551 char *def = tok.next(); |
141 | 1552 tok.push(def); |
1553 if (def != token_lbrace) me.set_default_rate(tok.nextint()); | |
136 | 1554 if (!tsa(tok, token_lbrace)) return false; |
1555 while (true) { | |
1556 char *have = tok.next(); | |
1557 if (!have) break; | |
1558 if (have == token_rbrace) break; | |
1559 if (have == token_semi) { | |
1560 // optional separators | |
1561 } | |
1562 else { | |
140 | 1563 me.add_rate(have, tok.nextint()); |
136 | 1564 } |
1565 } | |
1566 return tsa(tok, token_semi); | |
1567 } | |
1568 | |
1569 | |
1570 //////////////////////////////////////////////// | |
1571 // | |
94 | 1572 bool parse_context(TOKEN &tok, CONFIG &dc, CONTEXTP parent); |
1573 bool parse_context(TOKEN &tok, CONFIG &dc, CONTEXTP parent) { | |
1574 char *name = tok.next(); | |
1575 if (!tsa(tok, token_lbrace)) return false; | |
1576 CONTEXTP con = new CONTEXT(parent, name); | |
1577 | |
1578 while (true) { | |
1579 char *have = tok.next(); | |
1580 if (!have) break; | |
1581 if (have == token_rbrace) break; // done | |
1582 if (have == token_dnsbl) { | |
1583 if (!parse_dnsbl(tok, dc, *con)) return false; | |
1584 } | |
1585 else if (have == token_dnsbll) { | |
1586 if (!parse_dnsbll(tok, dc, *con)) return false; | |
1587 } | |
1588 else if (have == token_content) { | |
1589 if (!parse_content(tok, dc, *con)) return false; | |
1590 } | |
1591 else if (have == token_envto) { | |
1592 if (!parse_envto(tok, dc, *con)) return false; | |
1593 } | |
1594 else if (have == token_verify) { | |
1595 if (!parse_verify(tok, dc, *con)) return false; | |
1596 } | |
168 | 1597 else if (have == token_generic) { |
1598 if (!parse_generic(tok, dc, *con)) return false; | |
1599 } | |
153 | 1600 else if (have == token_autowhite) { |
1601 if (!parse_autowhite(tok, dc, *con)) return false; | |
1602 } | |
94 | 1603 else if (have == token_envfrom) { |
1604 if (!parse_envfrom(tok, dc, *con)) return false; | |
1605 } | |
140 | 1606 else if (have == token_rate) { |
1607 if (parent || dc.default_context) tok.token_error("rate limit ignored in non default context"); | |
136 | 1608 if (!parse_rate(tok, dc, *con)) return false; |
1609 } | |
94 | 1610 else if (have == token_context) { |
1611 if (!parse_context(tok, dc, con)) return false; | |
1612 } | |
1613 else { | |
1614 tok.token_error("context keyword", have); | |
1615 return false; | |
1616 } | |
1617 } | |
1618 | |
1619 if (!tsa(tok, token_semi)) { | |
1620 delete con; | |
1621 return false; | |
1622 } | |
1623 dc.add_context(con); | |
1624 if (parent) parent->add_context(con); | |
1625 return true; | |
1626 } | |
1627 | |
1628 | |
1629 //////////////////////////////////////////////// | |
1630 // parse a config file | |
1631 // | |
1632 bool load_conf(CONFIG &dc, char *fn) { | |
99 | 1633 int count = 0; |
94 | 1634 TOKEN tok(fn, &dc.config_files); |
1635 while (true) { | |
1636 char *have = tok.next(); | |
1637 if (!have) break; | |
1638 if (have == token_context) { | |
1639 if (!parse_context(tok, dc, NULL)) { | |
99 | 1640 tok.token_error("load_conf() failed to parse context"); |
94 | 1641 return false; |
1642 } | |
99 | 1643 else count++; |
94 | 1644 } |
1645 else { | |
1646 tok.token_error(token_context, have); | |
1647 return false; | |
1648 } | |
1649 } | |
99 | 1650 tok.token_error("load_conf() found %d contexts in %s", count, fn); |
94 | 1651 return (dc.default_context) ? true : false; |
1652 } | |
1653 | |
1654 | |
1655 //////////////////////////////////////////////// | |
1656 // init the tokens | |
1657 // | |
1658 void token_init() { | |
178 | 1659 token_autowhite = register_string("autowhite"); |
1660 token_black = register_string("black"); | |
1661 token_cctld = register_string("cctld"); | |
1662 token_content = register_string("content"); | |
1663 token_context = register_string("context"); | |
1664 token_dccbulk = register_string("dcc_bulk_threshold"); | |
1665 token_dccfrom = register_string("dcc_from"); | |
1666 token_dccgrey = register_string("dcc_greylist"); | |
1667 token_dccto = register_string("dcc_to"); | |
1668 token_default = register_string("default"); | |
1669 token_dnsbl = register_string("dnsbl"); | |
1670 token_dnsbll = register_string("dnsbl_list"); | |
1671 token_envfrom = register_string("env_from"); | |
1672 token_envto = register_string("env_to"); | |
1673 token_filter = register_string("filter"); | |
1674 token_generic = register_string("generic"); | |
1675 token_host_limit = register_string("host_limit"); | |
1676 token_html_limit = register_string("html_limit"); | |
1677 token_html_tags = register_string("html_tags"); | |
1678 token_ignore = register_string("ignore"); | |
1679 token_include = register_string("include"); | |
1680 token_inherit = register_string("inherit"); | |
1681 token_lbrace = register_string("{"); | |
1682 token_mailhost = register_string("mail_host"); | |
1683 token_many = register_string("many"); | |
1684 token_no = register_string("no"); | |
1685 token_off = register_string("off"); | |
1686 token_ok = register_string("ok"); | |
1687 token_ok2 = register_string("ok2"); | |
1688 token_on = register_string("on"); | |
1689 token_rate = register_string("rate_limit"); | |
1690 token_rbrace = register_string("}"); | |
1691 token_require = register_string("require_match"); | |
1692 token_semi = register_string(";"); | |
1693 token_soft = register_string("soft"); | |
1694 token_spamassassin = register_string("spamassassin"); | |
1695 token_substitute = register_string("substitute"); | |
1696 token_tld = register_string("tld"); | |
1697 token_unknown = register_string("unknown"); | |
1698 token_uribl = register_string("uribl"); | |
1699 token_verify = register_string("verify"); | |
1700 token_white = register_string("white"); | |
1701 token_yes = register_string("yes"); | |
94 | 1702 |
1703 if (gethostname(myhostname, HOST_NAME_MAX+1) != 0) { | |
1704 strncpy(myhostname, "localhost", HOST_NAME_MAX+1); | |
1705 } | |
1706 myhostname[HOST_NAME_MAX] = '\0'; // ensure null termination | |
1707 token_myhostname = register_string(myhostname); | |
1708 } |