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