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