masqmail

view src/conf.c @ 395:5f0829f8e6c7

Removed log_max_pri limit. It makes no sense.
author markus schnalke <meillo@marmaro.de>
date Sat, 18 Feb 2012 19:39:11 +0100
parents c8e3d1a79313
children 6f2a8113a79e
line source
1 /*
2 ** MasqMail
3 ** Copyright (C) 1999-2001 Oliver Kurth
4 ** Copyright (C) 2010 markus schnalke <meillo@marmaro.de>
5 **
6 ** This program is free software; you can redistribute it and/or modify
7 ** it under the terms of the GNU General Public License as published by
8 ** the Free Software Foundation; either version 2 of the License, or
9 ** (at your option) any later version.
10 **
11 ** This program is distributed in the hope that it will be useful,
12 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ** GNU General Public License for more details.
15 **
16 ** You should have received a copy of the GNU General Public License
17 ** along with this program; if not, write to the Free Software
18 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
21 #include <pwd.h>
22 #include <grp.h>
24 #include "masqmail.h"
26 masqmail_conf conf;
28 void
29 init_conf()
30 {
31 struct passwd *passwd;
32 struct group *group;
34 if (!(passwd = getpwnam(DEF_MAIL_USER))) {
35 fprintf(stderr, "user %s not found! (terminating)\n",
36 DEF_MAIL_USER);
37 exit(1);
38 }
39 if (!(group = getgrnam(DEF_MAIL_GROUP))) {
40 fprintf(stderr, "group %s not found! (terminating)\n",
41 DEF_MAIL_GROUP);
42 exit(1);
43 }
44 memset(&conf, 0, sizeof(masqmail_conf));
45 conf.orig_uid = getuid();
46 conf.orig_gid = getgid();
47 conf.mail_uid = passwd->pw_uid;
48 conf.mail_gid = group->gr_gid;
49 }
51 static gchar *true_strings[] = {
52 "yes", "on", "true", NULL
53 };
55 static gchar *false_strings[] = {
56 "no", "off", "false", NULL
57 };
59 static gboolean
60 parse_boolean(gchar *rval)
61 {
62 gchar **str;
64 DEBUG(9) fprintf(stderr, "parse_boolean: %s\n", rval);
65 for (str = true_strings; *str; str++) {
66 if (strncasecmp(*str, rval, strlen(*str))==0) {
67 return TRUE;
68 }
69 }
70 for (str = false_strings; *str; str++) {
71 if (strncasecmp(*str, rval, strlen(*str))==0) {
72 return FALSE;
73 }
74 }
75 fprintf(stderr, "cannot parse value '%s'\n", rval);
76 exit(1);
77 }
79 /*
80 ** make a list from the lines of a file
81 */
82 static GList*
83 parse_list_file(const gchar *fname)
84 {
85 GList *list = NULL;
86 FILE *fptr;
87 gchar buf[256];
89 if (!(fptr = fopen(fname, "rt"))) {
90 logwrite(LOG_ALERT, "could not open %s for reading: %s\n",
91 fname, strerror(errno));
92 exit(1);
93 }
94 while (!fgets(buf, sizeof buf, fptr)) {
95 g_strstrip(buf);
96 if (!*buf || *buf == '#') {
97 continue;
98 }
99 DEBUG(9) fprintf(stderr, "parse_list_file: item = %s\n", buf);
100 list = g_list_append(list, g_strdup(buf));
101 }
102 fclose(fptr);
104 return list;
105 }
107 /*
108 ** given a semicolon separated string, this function makes a GList out of it.
109 */
110 static GList*
111 parse_list(gchar *line, gboolean read_file)
112 {
113 GList *list = NULL;
114 gchar *tok;
116 DEBUG(9) fprintf(stderr, "parsing list %s, file?:%d\n",
117 line, read_file);
118 for (tok = strtok(strdup(line), ";"); tok; tok = strtok(NULL, ";")) {
119 DEBUG(9) fprintf(stderr, "item = %s\n", tok);
120 if (read_file && *tok == '/') {
121 /* item is a filename, include its contents */
122 list = g_list_concat(list, parse_list_file(tok));
123 } else {
124 /* just a normal item */
125 list = g_list_append(list, g_strdup(tok));
126 }
127 }
128 return list;
129 }
131 /*
132 ** Split the addrs at '@' into local_part and domain. Without an '@'
133 ** everything is local_part. Create and return a list of address structs.
134 ** This funktion is used for lists of addrs containing globbing chars
135 ** (* and ?). We don't need valid RFC821 addresses here, just patterns
136 ** to match against.
137 */
138 static GList*
139 parse_address_glob_list(gchar *line)
140 {
141 GList *plain_list = parse_list(line, TRUE);
142 GList *node;
143 GList *list = NULL;
145 foreach(plain_list, node) {
146 gchar *item = (gchar *) (node->data);
147 char *at;
148 char *p;
149 address *addr = calloc(1, sizeof(address));
151 for (p=item+strlen(item)-1; isspace(*p) || *p=='>'; p--) {
152 *p = '\0';
153 }
154 for (p=item; isspace(*p) || *p=='<'; p++) {
155 }
157 addr->address = strdup(p);
158 at = strrchr(p, '@');
159 if (at) {
160 *at = '\0';
161 addr->local_part = strdup(p);
162 addr->domain = strdup(at+1);
163 } else {
164 addr->local_part = strdup(p);
165 /* No `@', thus any domain is okay. */
166 addr->domain = "*";
167 }
168 list = g_list_append(list, addr);
169 DEBUG(6) debugf("parse_address_glob_list: "
170 "read pattern `%s' `%s'\n",
171 addr->local_part, addr->domain);
172 g_free(item);
173 }
174 g_list_free(plain_list);
175 return list;
176 }
178 static GList*
179 parse_resolve_list(gchar *line)
180 {
181 GList *list;
182 GList *list_node;
183 GList *res_list = NULL;
184 gchar *item;
186 list = parse_list(line, TRUE);
187 if (!list) {
188 return NULL;
189 }
190 foreach(list, list_node) {
191 item = (gchar *) list_node->data;
192 if (strcmp(item, "byname")==0) {
193 res_list = g_list_append(res_list, resolve_byname);
194 #ifdef ENABLE_RESOLVER
195 } else if (strcmp(item, "dns_a")==0) {
196 res_list = g_list_append(res_list, resolve_dns_a);
197 } else if (strcmp(item, "dns_mx")==0) {
198 res_list = g_list_append(res_list, resolve_dns_mx);
199 #endif
200 } else {
201 logwrite(LOG_ALERT, "unknown resolver %s\n", item);
202 exit(1);
203 }
204 g_free(item);
205 }
206 g_list_free(list);
207 return res_list;
208 }
210 static interface*
211 parse_interface(gchar *line, gint def_port)
212 {
213 gchar *cp;
214 interface *iface = g_malloc(sizeof(interface));
216 DEBUG(9) fprintf(stderr, "parse_interface: %s\n", line);
217 if ((cp = strchr(line, ':'))) {
218 *cp = '\0';
219 }
220 iface->address = g_strdup(line);
221 iface->port = (cp) ? atoi(++cp) : def_port;
222 DEBUG(9) fprintf(stderr,"found: address:port=%s:%u\n",
223 iface->address, iface->port);
224 return iface;
225 }
227 static gboolean
228 eat_comments(FILE *in)
229 {
230 gint c;
231 int incomment = 0;
233 while ((c = fgetc(in)) != EOF) {
234 if (incomment) {
235 /* eat until end of line */
236 if (c == '\n') {
237 incomment = 0;
238 continue;
239 } else {
240 continue;
241 }
242 } else {
243 /* eat whitespace and watch for comments */
244 if (isspace(c)) {
245 continue;
246 } else if (c == '#') {
247 incomment = 1;
248 continue;
249 } else {
250 /* found something (that's not our business) */
251 ungetc(c, in);
252 return TRUE;
253 }
254 }
255 }
256 return FALSE;
257 }
259 static gboolean
260 eat_spaces(FILE *in)
261 {
262 gint c;
264 while ((c = fgetc(in)) != EOF) {
265 if (!isspace(c)) {
266 ungetc(c, in);
267 return TRUE;
268 }
269 }
270 return FALSE;
271 }
273 static gboolean
274 read_lval(FILE *in, gchar *buf, gint size)
275 {
276 gint c;
277 gchar *ptr = buf;
279 DEBUG(9) fprintf(stderr, "read_lval()\n");
280 if (!eat_spaces(in)) {
281 return FALSE;
282 }
284 c = fgetc(in);
285 DEBUG(9) fprintf(stderr, "read_lval() 2\n");
286 while (1) {
287 if ((c = fgetc(in)) == EOF) {
288 fprintf(stderr, "unexpected EOF after %s\n", buf);
289 return FALSE;
290 }
291 if (ptr >= buf+size-1) {
292 fprintf(stderr, "lval too long\n");
293 break;
294 }
295 if (!isalnum(c) && c != '_' && c != '-' && c != '.') {
296 break;
297 }
298 *ptr++ = c;
299 }
300 *ptr = '\0';
301 ungetc(c, in);
302 eat_spaces(in);
303 DEBUG(9) fprintf(stderr, "lval = %s\n", buf);
304 return *buf != '\0';
305 }
307 static gboolean
308 read_rval(FILE *in, gchar *buf, gint size)
309 {
310 gint c;
311 gchar *ptr = buf;
313 DEBUG(9) fprintf(stderr, "read_rval()\n");
314 if (!eat_spaces(in)) {
315 return FALSE;
316 }
318 c = fgetc(in);
319 if (c != '"') {
320 /* unquoted rval */
321 ungetc(c, in);
322 while ((c = fgetc(in)) != EOF) {
323 if (ptr >= buf+size-1) {
324 /* rval too long */
325 break;
326 }
327 if (!isalnum(c) && c != '_' && c != '-' &&
328 c != '.' && c != '/' && c != '@' &&
329 c != ';' && c != ':') {
330 break;
331 }
332 *ptr++ = c;
333 }
334 *ptr = '\0';
335 ungetc(c, in);
336 } else {
337 /* quoted rval */
338 gboolean escape = FALSE;
339 while ((c = fgetc(in)) != EOF) {
340 if (ptr >= buf+size-1) {
341 /* rval too long */
342 break;
343 }
344 if (!escape && c == '"') {
345 break;
346 }
347 if (!escape && c == '\\') {
348 escape = TRUE;
349 continue;
350 }
351 *ptr++ = c;
352 escape = FALSE;
353 }
354 *ptr = '\0';
355 }
356 DEBUG(9) fprintf(stderr, "rval = %s\n", buf);
357 /* eat trailing of line */
358 while ((c = fgetc(in)) != EOF && c != '\n') {
359 continue;
360 }
362 return TRUE;
363 }
365 static gboolean
366 read_statement(FILE *in, gchar *lval, gint lsize, gchar *rval, gint rsize)
367 {
368 gint c;
370 DEBUG(9) fprintf(stderr, "read_statement()\n");
372 /* eat comments and empty lines: */
373 if (!eat_comments(in)) {
374 return FALSE;
375 }
376 if (!read_lval(in, lval, lsize)) {
377 return FALSE;
378 }
380 DEBUG(9) fprintf(stderr, " lval = %s\n", lval);
381 if ((c = fgetc(in) != '=')) {
382 fprintf(stderr, "'=' expected after %s, char was '%c'\n",
383 lval, c);
384 }
385 if (!read_rval(in, rval, rsize)) {
386 return FALSE;
387 }
388 DEBUG(9) fprintf(stderr, " rval = %s\n", rval);
389 return TRUE;
390 }
392 gboolean
393 read_conf(gchar *filename)
394 {
395 FILE *in;
396 gchar lval[256], rval[2048];
397 GList *listen_addrs_tmp = NULL;
399 conf.do_relay = TRUE;
400 conf.localpartcmp = strcmp;
401 conf.max_defer_time = 86400 * 4; /* 4 days */
402 conf.max_msg_size = 0; /* no limit on msg size */
403 conf.spool_dir = SPOOL_DIR;
404 conf.mail_dir = "/var/mail";
406 if (!(in = fopen(filename, "r"))) {
407 logwrite(LOG_ALERT, "could not open config file %s: %s\n",
408 filename, strerror(errno));
409 return FALSE;
410 }
412 while (read_statement(in, lval, sizeof lval, rval, sizeof rval)) {
413 DEBUG(9) fprintf(stderr,"read_conf(): lval=%s\n", lval);
414 if (strcmp(lval, "debug_level")==0) {
415 conf.debug_level = atoi(rval);
416 } else if (strcmp(lval, "run_as_user")==0) {
417 if (!conf.run_as_user) {
418 /* you should not be able to reset that flag */
419 conf.run_as_user = parse_boolean(rval);
420 }
421 } else if (strcmp(lval, "use_syslog")==0) {
422 conf.use_syslog = parse_boolean(rval);
423 } else if (strcmp(lval, "mail_dir")==0) {
424 conf.mail_dir = g_strdup(rval);
425 } else if (strcmp(lval, "lock_dir")==0) {
426 conf.lock_dir = g_strdup(rval);
427 } else if (strcmp(lval, "spool_dir")==0) {
428 conf.spool_dir = g_strdup(rval);
429 } else if (strcmp(lval, "log_dir")==0) {
430 conf.log_dir = g_strdup(rval);
431 } else if (strcmp(lval, "host_name")==0) {
432 if (rval[0] != '/') {
433 conf.host_name = g_strdup(rval);
434 } else {
435 char buf[256];
436 FILE *fptr = fopen(rval, "rt");
437 if (!fptr) {
438 logwrite(LOG_ALERT, "could not open "
439 "%s: %s\n", rval,
440 strerror(errno));
441 return FALSE;
442 }
443 fgets(buf, sizeof buf, fptr);
444 g_strstrip(buf);
445 conf.host_name = g_strdup(buf);
446 fclose(fptr);
447 }
448 } else if (strcmp(lval, "local_hosts")==0) {
449 conf.local_hosts = parse_list(rval, TRUE);
450 } else if (strcmp(lval, "local_addresses")==0) {
451 conf.local_addresses = parse_list(rval, TRUE);
452 } else if (strcmp(lval, "not_local_addresses")==0) {
453 conf.not_local_addresses = parse_list(rval, TRUE);
454 } else if (strcmp(lval, "do_save_envelope_to")==0) {
455 conf.do_save_envelope_to = parse_boolean(rval);
456 } else if (strcmp(lval, "defer_all")==0) {
457 conf.defer_all = parse_boolean(rval);
458 } else if (strcmp(lval, "do_relay")==0) {
459 conf.do_relay = parse_boolean(rval);
460 } else if (strcmp(lval, "alias_file")==0) {
461 conf.alias_file = g_strdup(rval);
462 } else if (strcmp(lval, "globalias_file")==0) {
463 conf.globalias_file = g_strdup(rval);
464 } else if (strcmp(lval, "caseless_matching")==0) {
465 conf.localpartcmp = parse_boolean(rval) ?
466 strcasecmp : strcmp;
467 } else if (strcmp(lval, "mbox_default")==0) {
468 conf.mbox_default = g_strdup(rval);
469 } else if (strcmp(lval, "mbox_users")==0) {
470 conf.mbox_users = parse_list(rval, TRUE);
471 } else if (strcmp(lval, "mda_users")==0) {
472 conf.mda_users = parse_list(rval, TRUE);
473 } else if (strcmp(lval, "mda")==0) {
474 conf.mda = g_strdup(rval);
475 } else if (strcmp(lval, "mda_fromline")==0) {
476 conf.mda_fromline = parse_boolean(rval);
477 } else if (strcmp(lval, "mda_fromhack")==0) {
478 conf.mda_fromhack = parse_boolean(rval);
479 } else if (strcmp(lval, "pipe_fromline")==0) {
480 conf.pipe_fromline = parse_boolean(rval);
481 } else if (strcmp(lval, "pipe_fromhack")==0) {
482 conf.pipe_fromhack = parse_boolean(rval);
483 } else if (strcmp(lval, "listen_addresses")==0) {
484 listen_addrs_tmp = parse_list(rval, TRUE);
485 } else if (strncmp(lval, "query_routes.", 13)==0) {
486 GList *file_list = parse_list(rval, FALSE);
487 table_pair *pair = create_pair(lval+13, file_list);
488 conf.query_routes = g_list_append(conf.query_routes,
489 pair);
490 } else if (strcmp(lval, "permanent_routes")==0) {
491 conf.perma_routes = parse_list(rval, FALSE);
492 } else if (strcmp(lval, "online_query")==0) {
493 conf.online_query = g_strdup(rval);
494 } else if (strcmp(lval, "do_queue")==0) {
495 conf.do_queue = parse_boolean(rval);
496 } else if (strcmp(lval, "errmsg_file")==0) {
497 conf.errmsg_file = g_strdup(rval);
498 } else if (strcmp(lval, "warnmsg_file")==0) {
499 conf.warnmsg_file = g_strdup(rval);
500 } else if (strcmp(lval, "warn_intervals")==0) {
501 conf.warn_intervals = parse_list(rval, TRUE);
502 } else if (strcmp(lval, "max_defer_time")==0) {
503 gint ival = time_interval(rval);
504 if (ival < 0) {
505 logwrite(LOG_WARNING, "invalid time interval "
506 "for 'max_defer_time': %s\n",
507 rval);
508 } else {
509 conf.max_defer_time = ival;
510 }
511 } else if (strcmp(lval, "log_user")==0) {
512 conf.log_user = g_strdup(rval);
513 } else if(strcmp(lval, "max_msg_size")==0) {
514 conf.max_msg_size = atol(rval);
515 DEBUG(9) fprintf(stderr,
516 "rval=%s, conf.max_msg_size=%ld\n",
517 rval, conf.max_msg_size);
518 } else {
519 logwrite(LOG_WARNING, "var '%s' unknown: ignored\n",
520 lval);
521 }
522 }
523 fclose(in);
525 if (!conf.host_name) {
526 logwrite(LOG_ALERT, "`host_name' MUST be set in "
527 "masqmail.conf. See man page\n");
528 return FALSE;
529 }
530 if (!conf.errmsg_file) {
531 conf.errmsg_file = g_strdup(DATA_DIR "/tpl/failmsg.tpl");
532 }
533 if (!conf.warnmsg_file) {
534 conf.warnmsg_file = g_strdup(DATA_DIR "/tpl/warnmsg.tpl");
535 }
536 if (!conf.lock_dir) {
537 conf.lock_dir = g_strdup_printf("%s/lock/", conf.spool_dir);
538 }
539 if (!conf.mbox_default) {
540 conf.mbox_default = g_strdup("mbox");
541 }
542 if (!conf.warn_intervals) {
543 conf.warn_intervals = parse_list("1h;4h;8h;1d;2d;3d", TRUE);
544 }
545 if (!conf.local_hosts) {
546 char *shortname = strdup(conf.host_name);
547 char *p = strchr(shortname, '.');
548 if (p) {
549 *p = '\0';
550 }
551 /* don't care if shortname and conf.host_name are the same */
552 char *local_hosts_str = g_strdup_printf("localhost;%s;%s",
553 shortname, conf.host_name);
554 conf.local_hosts = parse_list(local_hosts_str, TRUE);
555 free(shortname);
556 free(local_hosts_str);
557 }
558 if (!listen_addrs_tmp) {
559 conf.listen_addresses = g_list_append(NULL,
560 parse_interface("localhost", 25));
561 } else {
562 GList *node;
564 foreach(listen_addrs_tmp, node) {
565 conf.listen_addresses =
566 g_list_append(conf.listen_addresses,
567 parse_interface((gchar *) node->data,
568 25));
569 g_free(node->data);
570 }
571 g_list_free(listen_addrs_tmp);
572 }
574 return TRUE;
575 }
577 connect_route*
578 read_route(gchar *filename, gboolean is_perma)
579 {
580 FILE *in;
581 connect_route *route;
582 gchar lval[256], rval[2048];
584 DEBUG(5) debugf("read_route, filename = %s\n", filename);
586 if (!(in = fopen(filename, "r"))) {
587 logwrite(LOG_ALERT, "could not open route file %s: %s\n",
588 filename, strerror(errno));
589 return NULL;
590 }
592 route = g_malloc(sizeof(connect_route));
593 memset(route, 0, sizeof(connect_route));
594 route->filename = g_strdup(filename);
595 route->name = route->filename; /* quick hack */
596 route->expand_h_sender_address = TRUE;
597 route->is_perma = is_perma;
598 route->do_pipelining = TRUE;
600 while (read_statement(in, lval, sizeof lval, rval, sizeof rval)) {
601 if (strcmp(lval, "mail_host")==0) {
602 route->mail_host = parse_interface(rval, 25);
603 } else if (strcmp(lval, "helo_name")==0) {
604 route->helo_name = g_strdup(rval);
605 } else if (strcmp(lval, "wrapper")==0) {
606 route->wrapper = g_strdup(rval);
607 } else if (strcmp(lval, "connect_error_fail")==0) {
608 route->connect_error_fail = parse_boolean(rval);
609 } else if (strcmp(lval, "do_correct_helo")==0) {
610 route->do_correct_helo = parse_boolean(rval);
611 } else if (strcmp(lval, "instant_helo")==0) {
612 route->instant_helo = parse_boolean(rval);
613 } else if (strcmp(lval, "do_pipelining")==0) {
614 route->do_pipelining = parse_boolean(rval);
616 } else if (strcmp(lval, "allowed_senders")==0) {
617 route->allowed_senders = parse_address_glob_list(rval);
618 } else if (strcmp(lval, "denied_senders")==0) {
619 route->denied_senders = parse_address_glob_list(rval);
620 } else if (strcmp(lval, "allowed_recipients")==0) {
621 route->allowed_recipients = parse_address_glob_list(rval);
622 } else if (strcmp(lval, "denied_recipients")==0) {
623 route->denied_recipients = parse_address_glob_list(rval);
625 } else if (strcmp(lval, "set_h_from_domain")==0) {
626 route->set_h_from_domain = g_strdup(rval);
627 } else if (strcmp(lval, "set_h_reply_to_domain")==0) {
628 route->set_h_reply_to_domain = g_strdup(rval);
629 } else if (strcmp(lval, "set_return_path_domain")==0) {
630 route->set_return_path_domain = g_strdup(rval);
631 } else if (strcmp(lval, "map_return_path_addresses")==0) {
632 GList *node, *list;
634 list = parse_list(rval, TRUE);
635 foreach(list, node) {
636 gchar *item = (gchar *) (node->data);
637 table_pair *pair = parse_table_pair(item, ':');
638 address *addr = create_address(
639 (gchar *) (pair->value), TRUE);
640 g_free(pair->value);
641 pair->value = (gpointer *) addr;
642 route->map_return_path_addresses = g_list_append( route->map_return_path_addresses, pair);
643 g_free(item);
644 }
645 g_list_free(list);
646 } else if (strcmp(lval, "map_h_from_addresses")==0) {
647 GList *list, *node;
649 list = parse_list(rval, TRUE);
650 foreach(list, node) {
651 gchar *item = (gchar *) (node->data);
652 table_pair *pair = parse_table_pair(item, ':');
653 route->map_h_from_addresses = g_list_append(route->map_h_from_addresses, pair);
654 g_free(item);
655 }
656 g_list_free(list);
657 } else if (strcmp(lval, "map_h_reply_to_addresses")==0) {
658 GList *list, *node;
660 list = parse_list(rval, TRUE);
661 foreach(list, node) {
662 gchar *item = (gchar *) (node->data);
663 table_pair *pair = parse_table_pair(item, ':');
664 route->map_h_reply_to_addresses = g_list_append(route->map_h_reply_to_addresses, pair);
665 g_free(item);
666 }
667 g_list_free(list);
668 } else if (strcmp(lval, "map_h_mail_followup_to_addresses")==0) {
669 GList *list, *node;
671 list = parse_list(rval, TRUE);
672 foreach(list, node) {
673 gchar *item = (gchar *) (node->data);
674 table_pair *pair = parse_table_pair(item, ':');
675 route->map_h_mail_followup_to_addresses = g_list_append(route->map_h_mail_followup_to_addresses, pair);
676 g_free(item);
677 }
678 g_list_free(list);
679 } else if (strcmp(lval, "expand_h_sender_domain")==0) {
680 route->expand_h_sender_domain = parse_boolean(rval);
681 } else if (strcmp(lval, "expand_h_sender_address")==0) {
682 route->expand_h_sender_address = parse_boolean(rval);
683 } else if (strcmp(lval, "resolve_list")==0) {
684 route->resolve_list = parse_resolve_list(rval);
685 } else if (strcmp(lval, "do_ssl")==0) {
686 /* we ignore this. This option is used by sqilconf */
687 ;
688 #ifdef ENABLE_AUTH
689 } else if (strcmp(lval, "auth_name")==0) {
690 route->auth_name = g_strdup(rval);
691 } else if (strcmp(lval, "auth_login")==0) {
692 route->auth_login = g_strdup(rval);
693 } else if (strcmp(lval, "auth_secret")==0) {
694 route->auth_secret = g_strdup(rval);
695 #else
696 } else if ((strcmp(lval, "auth_name")==0) ||
697 (strcmp(lval, "auth_login")==0) ||
698 (strcmp(lval, "auth_secret")==0)) {
699 logwrite(LOG_WARNING, "%s ignored: not compiled with "
700 "auth support.\n", lval);
701 }
702 #endif
703 } else if (strcmp(lval, "pipe")==0) {
704 route->pipe = g_strdup(rval);
705 } else if (strcmp(lval, "pipe_fromline")==0) {
706 route->pipe_fromline = parse_boolean(rval);
707 } else if (strcmp(lval, "pipe_fromhack")==0) {
708 route->pipe_fromhack = parse_boolean(rval);
709 } else if (strcmp(lval, "last_route")==0) {
710 route->last_route = parse_boolean(rval);
711 } else {
712 logwrite(LOG_WARNING, "var '%s' unknown: ignored\n",
713 lval);
714 }
715 }
717 if (!route->resolve_list) {
718 #ifdef ENABLE_RESOLVER
719 route->resolve_list = g_list_append(route->resolve_list,
720 resolve_dns_mx);
721 route->resolve_list = g_list_append(route->resolve_list,
722 resolve_dns_a);
723 #endif
724 route->resolve_list = g_list_append(route->resolve_list,
725 resolve_byname);
726 }
727 fclose(in);
729 /* warn user about mis-configurations: */
730 if (route->map_h_from_addresses && route->set_h_from_domain) {
731 logwrite(LOG_WARNING, "'map_h_from_addresses' overrides "
732 "'set_h_from_domain'\n");
733 g_free(route->set_h_from_domain);
734 route->set_h_from_domain = NULL;
735 }
736 if (route->map_h_reply_to_addresses && route->set_h_reply_to_domain) {
737 logwrite(LOG_WARNING, "'map_h_reply_to_addresses' overrides "
738 "'set_h_reply_to_domain'\n");
739 g_free(route->set_h_reply_to_domain);
740 route->set_h_reply_to_domain = NULL;
741 }
743 return route;
744 }
746 static void
747 _g_list_free_all(GList *list)
748 {
749 GList *node;
750 if (!list) {
751 return;
752 }
753 foreach(list, node) {
754 g_free(node->data);
755 }
756 g_list_free(list);
757 }
759 void
760 destroy_route(connect_route *r)
761 {
762 if (r->filename) {
763 g_free(r->filename);
764 }
765 if (r->mail_host) {
766 g_free(r->mail_host->address);
767 g_free(r->mail_host);
768 }
769 if (r->wrapper) {
770 g_free(r->wrapper);
771 }
772 if (r->helo_name) {
773 g_free(r->helo_name);
774 }
775 _g_list_free_all(r->allowed_senders);
776 _g_list_free_all(r->denied_senders);
777 _g_list_free_all(r->allowed_recipients);
778 _g_list_free_all(r->denied_recipients);
779 if (r->set_h_from_domain) {
780 g_free(r->set_h_from_domain);
781 }
782 if (r->set_h_reply_to_domain) {
783 g_free(r->set_h_reply_to_domain);
784 }
785 if (r->set_return_path_domain) {
786 g_free(r->set_return_path_domain);
787 }
788 if (r->map_h_reply_to_addresses) {
789 destroy_table(r->map_h_reply_to_addresses);
790 }
791 if (r->resolve_list) {
792 g_list_free(r->resolve_list);
793 }
794 #ifdef ENABLE_AUTH
795 if (r->auth_name) {
796 g_free(r->auth_name);
797 }
798 if (r->auth_login) {
799 g_free(r->auth_login);
800 }
801 if (r->auth_secret) {
802 g_free(r->auth_secret);
803 }
804 #endif
805 if (r->pipe) {
806 g_free(r->pipe);
807 }
808 g_free(r);
809 }
811 GList*
812 read_route_list(GList *rf_list, gboolean is_perma)
813 {
814 GList *list = NULL;
815 GList *node;
816 uid_t saved_uid, saved_gid;
818 if (!conf.run_as_user) {
819 set_euidgid(0, 0, &saved_uid, &saved_gid);
820 }
821 foreach(rf_list, node) {
822 gchar *fname = (gchar *) (node->data);
823 connect_route *route = read_route(fname, is_perma);
824 if (route) {
825 list = g_list_append(list, route);
826 } else {
827 logwrite(LOG_ALERT, "could not read route "
828 "configuration %s\n", fname);
829 }
830 }
831 /* set uid and gid back */
832 if (!conf.run_as_user) {
833 set_euidgid(saved_uid, saved_gid, NULL, NULL);
834 }
835 return list;
836 }
838 void
839 destroy_route_list(GList *list)
840 {
841 GList *node;
843 foreach(list, node) {
844 connect_route *route = (connect_route *) (node->data);
845 destroy_route(route);
846 }
847 g_list_free(list);
848 }