masqmail
view src/conf.c @ 420:09da6e72cd30
Updated INSTALL to the new --with-piddir option.
author | markus schnalke <meillo@marmaro.de> |
---|---|
date | Tue, 29 May 2012 22:15:55 +0200 |
parents | 9b93c0a3bd8c |
children | f37384470855 |
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 *ep;
149 address *addr = calloc(1, sizeof(address));
151 ep = item + strlen(item) - 1;
152 if (*item == '<' && *ep == '>') {
153 *item = '\0';
154 *ep = '\0';
155 g_strstrip(item);
156 }
158 addr->address = strdup(item);
159 at = strrchr(item, '@');
160 if (at) {
161 *at = '\0';
162 addr->local_part = strdup(item);
163 addr->domain = strdup(at+1);
164 } else {
165 addr->local_part = strdup(item);
166 /* No `@', thus any domain is okay. */
167 addr->domain = "*";
168 }
169 list = g_list_append(list, addr);
170 DEBUG(6) debugf("parse_address_glob_list: "
171 "read pattern `%s' `%s'\n",
172 addr->local_part, addr->domain);
173 g_free(item);
174 }
175 g_list_free(plain_list);
176 return list;
177 }
179 static GList*
180 parse_resolve_list(gchar *line)
181 {
182 GList *list;
183 GList *list_node;
184 GList *res_list = NULL;
185 gchar *item;
187 list = parse_list(line, TRUE);
188 if (!list) {
189 return NULL;
190 }
191 foreach(list, list_node) {
192 item = (gchar *) list_node->data;
193 if (strcmp(item, "byname")==0) {
194 res_list = g_list_append(res_list, resolve_byname);
195 #ifdef ENABLE_RESOLVER
196 } else if (strcmp(item, "dns_a")==0) {
197 res_list = g_list_append(res_list, resolve_dns_a);
198 } else if (strcmp(item, "dns_mx")==0) {
199 res_list = g_list_append(res_list, resolve_dns_mx);
200 #endif
201 } else {
202 logwrite(LOG_ALERT, "unknown resolver %s\n", item);
203 exit(1);
204 }
205 g_free(item);
206 }
207 g_list_free(list);
208 return res_list;
209 }
211 static interface*
212 parse_interface(gchar *line, gint def_port)
213 {
214 gchar *cp;
215 interface *iface = g_malloc(sizeof(interface));
217 DEBUG(9) fprintf(stderr, "parse_interface: %s\n", line);
218 if ((cp = strchr(line, ':'))) {
219 *cp = '\0';
220 }
221 g_strstrip(line);
222 iface->address = g_strdup(line);
223 iface->port = (cp) ? atoi(++cp) : def_port;
224 DEBUG(9) fprintf(stderr, "found: address:port=%s:%u\n",
225 iface->address, iface->port);
226 return iface;
227 }
229 static gboolean
230 eat_comments(FILE *in)
231 {
232 gint c;
233 int incomment = 0;
235 while ((c = fgetc(in)) != EOF) {
236 if (incomment) {
237 /* eat until end of line */
238 if (c == '\n') {
239 incomment = 0;
240 continue;
241 } else {
242 continue;
243 }
244 } else {
245 /* eat whitespace and watch for comments */
246 if (isspace(c)) {
247 continue;
248 } else if (c == '#') {
249 incomment = 1;
250 continue;
251 } else {
252 /* found something (that's not our business) */
253 ungetc(c, in);
254 return TRUE;
255 }
256 }
257 }
258 return FALSE;
259 }
261 static gboolean
262 eat_spaces(FILE *in)
263 {
264 gint c;
266 while ((c = fgetc(in)) != EOF) {
267 if (!isspace(c)) {
268 ungetc(c, in);
269 return TRUE;
270 }
271 }
272 return FALSE;
273 }
275 static gboolean
276 read_lval(FILE *in, gchar *buf, gint size)
277 {
278 gint c;
279 gchar *ptr = buf;
281 DEBUG(9) fprintf(stderr, "read_lval()\n");
282 if (!eat_spaces(in)) {
283 return FALSE;
284 }
286 DEBUG(9) fprintf(stderr, "read_lval() 2\n");
287 while (1) {
288 c = fgetc(in);
289 if (c == EOF) {
290 fprintf(stderr, "unexpected EOF after %s\n", buf);
291 return FALSE;
292 }
293 if (ptr >= buf+size-1) {
294 fprintf(stderr, "lval too long\n");
295 break;
296 }
297 if (!isalnum(c) && c != '_' && c != '-' && c != '.') {
298 break;
299 }
300 *ptr++ = c;
301 }
302 *ptr = '\0';
303 g_strstrip(buf);
304 ungetc(c, in);
305 eat_spaces(in);
306 DEBUG(9) fprintf(stderr, "lval = %s\n", buf);
307 return *buf != '\0';
308 }
310 static gboolean
311 read_rval(FILE *in, gchar *buf, gint size)
312 {
313 gint c;
314 gchar *ptr = buf;
316 DEBUG(9) fprintf(stderr, "read_rval()\n");
317 if (!eat_spaces(in)) {
318 return FALSE;
319 }
321 c = fgetc(in);
322 if (c != '"') {
323 /* unquoted rval */
324 ungetc(c, in);
325 while ((c = fgetc(in)) != EOF) {
326 if (ptr >= buf+size-1) {
327 /* rval too long */
328 break;
329 }
330 if (!isalnum(c) && c != '_' && c != '-' &&
331 c != '.' && c != '/' && c != '@' &&
332 c != ';' && c != ':') {
333 break;
334 }
335 *ptr++ = c;
336 }
337 *ptr = '\0';
338 ungetc(c, in);
339 } else {
340 /* quoted rval */
341 gboolean escape = FALSE;
342 while ((c = fgetc(in)) != EOF) {
343 if (ptr >= buf+size-1) {
344 /* rval too long */
345 break;
346 }
347 if (!escape && c == '"') {
348 break;
349 }
350 if (!escape && c == '\\') {
351 escape = TRUE;
352 continue;
353 }
354 *ptr++ = c;
355 escape = FALSE;
356 }
357 *ptr = '\0';
358 }
359 g_strstrip(buf);
360 DEBUG(9) fprintf(stderr, "rval = %s\n", buf);
361 /* eat trailing of line */
362 while ((c = fgetc(in)) != EOF && c != '\n') {
363 continue;
364 }
366 return TRUE;
367 }
369 static gboolean
370 read_statement(FILE *in, gchar *lval, gint lsize, gchar *rval, gint rsize)
371 {
372 gint c;
374 DEBUG(9) fprintf(stderr, "read_statement()\n");
376 /* eat comments and empty lines: */
377 if (!eat_comments(in)) {
378 return FALSE;
379 }
380 if (!read_lval(in, lval, lsize)) {
381 return FALSE;
382 }
383 g_strstrip(lval);
384 DEBUG(9) fprintf(stderr, " lval = `%s'\n", lval);
385 if ((c = fgetc(in) != '=')) {
386 fprintf(stderr, "'=' expected after %s, char was '%c'\n",
387 lval, c);
388 }
389 if (!read_rval(in, rval, rsize)) {
390 return FALSE;
391 }
392 g_strstrip(rval);
393 DEBUG(9) fprintf(stderr, " rval = `%s'\n", rval);
394 return TRUE;
395 }
397 gboolean
398 read_conf(gchar *filename)
399 {
400 FILE *in;
401 gchar lval[256], rval[2048];
402 GList *listen_addrs_tmp = NULL;
404 conf.do_relay = TRUE;
405 conf.localpartcmp = strcmp;
406 conf.max_defer_time = 86400 * 4; /* 4 days */
407 conf.max_msg_size = 0; /* no limit on msg size */
408 conf.spool_dir = SPOOL_DIR;
409 conf.mail_dir = "/var/mail";
411 if (!(in = fopen(filename, "r"))) {
412 logwrite(LOG_ALERT, "could not open config file %s: %s\n",
413 filename, strerror(errno));
414 return FALSE;
415 }
417 while (read_statement(in, lval, sizeof lval, rval, sizeof rval)) {
418 DEBUG(9) fprintf(stderr,"read_conf(): lval=%s\n", lval);
419 if (strcmp(lval, "debug_level")==0) {
420 conf.debug_level = atoi(rval);
421 } else if (strcmp(lval, "run_as_user")==0) {
422 if (!conf.run_as_user) {
423 /* you should not be able to reset that flag */
424 conf.run_as_user = parse_boolean(rval);
425 }
426 } else if (strcmp(lval, "use_syslog")==0) {
427 conf.use_syslog = parse_boolean(rval);
428 } else if (strcmp(lval, "mail_dir")==0) {
429 conf.mail_dir = g_strdup(rval);
430 } else if (strcmp(lval, "lock_dir")==0) {
431 conf.lock_dir = g_strdup(rval);
432 } else if (strcmp(lval, "spool_dir")==0) {
433 conf.spool_dir = g_strdup(rval);
434 } else if (strcmp(lval, "log_dir")==0) {
435 conf.log_dir = g_strdup(rval);
436 } else if (strcmp(lval, "host_name")==0) {
437 if (rval[0] != '/') {
438 conf.host_name = g_strdup(rval);
439 } else {
440 char buf[256];
441 FILE *fptr = fopen(rval, "rt");
442 if (!fptr) {
443 logwrite(LOG_ALERT, "could not open "
444 "%s: %s\n", rval,
445 strerror(errno));
446 return FALSE;
447 }
448 fgets(buf, sizeof buf, fptr);
449 g_strstrip(buf);
450 conf.host_name = g_strdup(buf);
451 fclose(fptr);
452 }
453 } else if (strcmp(lval, "local_hosts")==0) {
454 conf.local_hosts = parse_list(rval, TRUE);
455 } else if (strcmp(lval, "local_addresses")==0) {
456 conf.local_addresses = parse_list(rval, TRUE);
457 } else if (strcmp(lval, "not_local_addresses")==0) {
458 conf.not_local_addresses = parse_list(rval, TRUE);
459 } else if (strcmp(lval, "do_save_envelope_to")==0) {
460 conf.do_save_envelope_to = parse_boolean(rval);
461 } else if (strcmp(lval, "defer_all")==0) {
462 conf.defer_all = parse_boolean(rval);
463 } else if (strcmp(lval, "do_relay")==0) {
464 conf.do_relay = parse_boolean(rval);
465 } else if (strcmp(lval, "alias_file")==0) {
466 conf.alias_file = g_strdup(rval);
467 } else if (strcmp(lval, "globalias_file")==0) {
468 conf.globalias_file = g_strdup(rval);
469 } else if (strcmp(lval, "caseless_matching")==0) {
470 conf.localpartcmp = parse_boolean(rval) ?
471 strcasecmp : strcmp;
472 } else if (strcmp(lval, "mbox_default")==0) {
473 conf.mbox_default = g_strdup(rval);
474 } else if (strcmp(lval, "mbox_users")==0) {
475 conf.mbox_users = parse_list(rval, TRUE);
476 } else if (strcmp(lval, "mda_users")==0) {
477 conf.mda_users = parse_list(rval, TRUE);
478 } else if (strcmp(lval, "mda")==0) {
479 conf.mda = g_strdup(rval);
480 } else if (strcmp(lval, "mda_fromline")==0) {
481 conf.mda_fromline = parse_boolean(rval);
482 } else if (strcmp(lval, "mda_fromhack")==0) {
483 conf.mda_fromhack = parse_boolean(rval);
484 } else if (strcmp(lval, "pipe_fromline")==0) {
485 conf.pipe_fromline = parse_boolean(rval);
486 } else if (strcmp(lval, "pipe_fromhack")==0) {
487 conf.pipe_fromhack = parse_boolean(rval);
488 } else if (strcmp(lval, "listen_addresses")==0) {
489 listen_addrs_tmp = parse_list(rval, TRUE);
490 } else if (strncmp(lval, "query_routes.", 13)==0) {
491 GList *file_list = parse_list(rval, FALSE);
492 table_pair *pair = create_pair(lval+13, file_list);
493 conf.query_routes = g_list_append(conf.query_routes,
494 pair);
495 } else if (strcmp(lval, "permanent_routes")==0) {
496 conf.perma_routes = parse_list(rval, FALSE);
497 } else if (strcmp(lval, "online_query")==0) {
498 conf.online_query = g_strdup(rval);
499 } else if (strcmp(lval, "do_queue")==0) {
500 conf.do_queue = parse_boolean(rval);
501 } else if (strcmp(lval, "errmsg_file")==0) {
502 conf.errmsg_file = g_strdup(rval);
503 } else if (strcmp(lval, "warnmsg_file")==0) {
504 conf.warnmsg_file = g_strdup(rval);
505 } else if (strcmp(lval, "warn_intervals")==0) {
506 conf.warn_intervals = parse_list(rval, TRUE);
507 } else if (strcmp(lval, "max_defer_time")==0) {
508 gint ival = time_interval(rval);
509 if (ival < 0) {
510 logwrite(LOG_WARNING, "invalid time interval "
511 "for 'max_defer_time': %s\n",
512 rval);
513 } else {
514 conf.max_defer_time = ival;
515 }
516 } else if (strcmp(lval, "log_user")==0) {
517 conf.log_user = g_strdup(rval);
518 } else if(strcmp(lval, "max_msg_size")==0) {
519 conf.max_msg_size = atol(rval);
520 DEBUG(9) fprintf(stderr,
521 "rval=%s, conf.max_msg_size=%ld\n",
522 rval, conf.max_msg_size);
523 } else {
524 logwrite(LOG_WARNING, "var '%s' unknown: ignored\n",
525 lval);
526 }
527 }
528 fclose(in);
530 if (!conf.host_name) {
531 logwrite(LOG_ALERT, "`host_name' MUST be set in "
532 "masqmail.conf. See man page\n");
533 return FALSE;
534 }
535 if (!conf.errmsg_file) {
536 conf.errmsg_file = g_strdup(DATA_DIR "/tpl/failmsg.tpl");
537 }
538 if (!conf.warnmsg_file) {
539 conf.warnmsg_file = g_strdup(DATA_DIR "/tpl/warnmsg.tpl");
540 }
541 if (!conf.lock_dir) {
542 conf.lock_dir = g_strdup_printf("%s/lock/", conf.spool_dir);
543 }
544 if (!conf.mbox_default) {
545 conf.mbox_default = g_strdup("mbox");
546 }
547 if (!conf.warn_intervals) {
548 conf.warn_intervals = parse_list("1h;4h;8h;1d;2d;3d", TRUE);
549 }
550 if (!conf.local_hosts) {
551 char *shortname = strdup(conf.host_name);
552 char *p = strchr(shortname, '.');
553 if (p) {
554 *p = '\0';
555 }
556 /* don't care if shortname and conf.host_name are the same */
557 char *local_hosts_str = g_strdup_printf("localhost;%s;%s",
558 shortname, conf.host_name);
559 conf.local_hosts = parse_list(local_hosts_str, TRUE);
560 free(shortname);
561 free(local_hosts_str);
562 }
563 if (!listen_addrs_tmp) {
564 conf.listen_addresses = g_list_append(NULL,
565 parse_interface(strdup("localhost"), 25));
566 } else {
567 GList *node;
569 foreach(listen_addrs_tmp, node) {
570 conf.listen_addresses =
571 g_list_append(conf.listen_addresses,
572 parse_interface((gchar *) node->data,
573 25));
574 g_free(node->data);
575 }
576 g_list_free(listen_addrs_tmp);
577 }
579 return TRUE;
580 }
582 connect_route*
583 read_route(gchar *filename, gboolean is_perma)
584 {
585 FILE *in;
586 connect_route *route;
587 gchar lval[256], rval[2048];
589 DEBUG(5) debugf("read_route, filename = %s\n", filename);
591 if (!(in = fopen(filename, "r"))) {
592 logwrite(LOG_ALERT, "could not open route file %s: %s\n",
593 filename, strerror(errno));
594 return NULL;
595 }
597 route = g_malloc(sizeof(connect_route));
598 memset(route, 0, sizeof(connect_route));
599 route->filename = g_strdup(filename);
600 route->name = route->filename; /* quick hack */
601 route->expand_h_sender_address = TRUE;
602 route->is_perma = is_perma;
603 route->do_pipelining = TRUE;
605 while (read_statement(in, lval, sizeof lval, rval, sizeof rval)) {
606 if (strcmp(lval, "mail_host")==0) {
607 route->mail_host = parse_interface(rval, 25);
608 } else if (strcmp(lval, "helo_name")==0) {
609 route->helo_name = g_strdup(rval);
610 } else if (strcmp(lval, "wrapper")==0) {
611 route->wrapper = g_strdup(rval);
612 } else if (strcmp(lval, "connect_error_fail")==0) {
613 route->connect_error_fail = parse_boolean(rval);
614 } else if (strcmp(lval, "do_correct_helo")==0) {
615 route->do_correct_helo = parse_boolean(rval);
616 } else if (strcmp(lval, "instant_helo")==0) {
617 route->instant_helo = parse_boolean(rval);
618 } else if (strcmp(lval, "do_pipelining")==0) {
619 route->do_pipelining = parse_boolean(rval);
621 } else if (strcmp(lval, "allowed_senders")==0) {
622 route->allowed_senders = parse_address_glob_list(rval);
623 } else if (strcmp(lval, "denied_senders")==0) {
624 route->denied_senders = parse_address_glob_list(rval);
625 } else if (strcmp(lval, "allowed_recipients")==0) {
626 route->allowed_recipients = parse_address_glob_list(rval);
627 } else if (strcmp(lval, "denied_recipients")==0) {
628 route->denied_recipients = parse_address_glob_list(rval);
630 } else if (strcmp(lval, "set_h_from_domain")==0) {
631 route->set_h_from_domain = g_strdup(rval);
632 } else if (strcmp(lval, "set_h_reply_to_domain")==0) {
633 route->set_h_reply_to_domain = g_strdup(rval);
634 } else if (strcmp(lval, "set_return_path_domain")==0) {
635 route->set_return_path_domain = g_strdup(rval);
636 } else if (strcmp(lval, "map_return_path_addresses")==0) {
637 GList *node, *list;
639 list = parse_list(rval, TRUE);
640 foreach(list, node) {
641 gchar *item = (gchar *) (node->data);
642 table_pair *pair = parse_table_pair(item, ':');
643 address *addr = create_address(
644 (gchar *) (pair->value), TRUE);
645 g_free(pair->value);
646 pair->value = (gpointer *) addr;
647 route->map_return_path_addresses = g_list_append(route->map_return_path_addresses, pair);
648 g_free(item);
649 }
650 g_list_free(list);
651 } else if (strcmp(lval, "map_h_from_addresses")==0) {
652 GList *list, *node;
654 list = parse_list(rval, TRUE);
655 foreach(list, node) {
656 gchar *item = (gchar *) (node->data);
657 table_pair *pair = parse_table_pair(item, ':');
658 route->map_h_from_addresses = g_list_append(route->map_h_from_addresses, pair);
659 g_free(item);
660 }
661 g_list_free(list);
662 } else if (strcmp(lval, "map_h_reply_to_addresses")==0) {
663 GList *list, *node;
665 list = parse_list(rval, TRUE);
666 foreach(list, node) {
667 gchar *item = (gchar *) (node->data);
668 table_pair *pair = parse_table_pair(item, ':');
669 route->map_h_reply_to_addresses = g_list_append(route->map_h_reply_to_addresses, pair);
670 g_free(item);
671 }
672 g_list_free(list);
673 } else if (strcmp(lval, "map_h_mail_followup_to_addresses")==0) {
674 GList *list, *node;
676 list = parse_list(rval, TRUE);
677 foreach(list, node) {
678 gchar *item = (gchar *) (node->data);
679 table_pair *pair = parse_table_pair(item, ':');
680 route->map_h_mail_followup_to_addresses = g_list_append(route->map_h_mail_followup_to_addresses, pair);
681 g_free(item);
682 }
683 g_list_free(list);
684 } else if (strcmp(lval, "expand_h_sender_domain")==0) {
685 route->expand_h_sender_domain = parse_boolean(rval);
686 } else if (strcmp(lval, "expand_h_sender_address")==0) {
687 route->expand_h_sender_address = parse_boolean(rval);
688 } else if (strcmp(lval, "resolve_list")==0) {
689 route->resolve_list = parse_resolve_list(rval);
690 } else if (strcmp(lval, "do_ssl")==0) {
691 /* we ignore this. This option is used by sqilconf */
692 ;
693 #ifdef ENABLE_AUTH
694 } else if (strcmp(lval, "auth_name")==0) {
695 route->auth_name = g_strdup(rval);
696 } else if (strcmp(lval, "auth_login")==0) {
697 route->auth_login = g_strdup(rval);
698 } else if (strcmp(lval, "auth_secret")==0) {
699 route->auth_secret = g_strdup(rval);
700 #else
701 } else if ((strcmp(lval, "auth_name")==0) ||
702 (strcmp(lval, "auth_login")==0) ||
703 (strcmp(lval, "auth_secret")==0)) {
704 logwrite(LOG_WARNING, "%s ignored: not compiled with "
705 "auth support.\n", lval);
706 }
707 #endif
708 } else if (strcmp(lval, "pipe")==0) {
709 route->pipe = g_strdup(rval);
710 } else if (strcmp(lval, "pipe_fromline")==0) {
711 route->pipe_fromline = parse_boolean(rval);
712 } else if (strcmp(lval, "pipe_fromhack")==0) {
713 route->pipe_fromhack = parse_boolean(rval);
714 } else if (strcmp(lval, "last_route")==0) {
715 route->last_route = parse_boolean(rval);
716 } else {
717 logwrite(LOG_WARNING, "var '%s' unknown: ignored\n",
718 lval);
719 }
720 }
722 if (!route->resolve_list) {
723 #ifdef ENABLE_RESOLVER
724 route->resolve_list = g_list_append(route->resolve_list,
725 resolve_dns_mx);
726 route->resolve_list = g_list_append(route->resolve_list,
727 resolve_dns_a);
728 #endif
729 route->resolve_list = g_list_append(route->resolve_list,
730 resolve_byname);
731 }
732 fclose(in);
734 /* warn user about mis-configurations: */
735 if (route->map_h_from_addresses && route->set_h_from_domain) {
736 logwrite(LOG_WARNING, "'map_h_from_addresses' overrides "
737 "'set_h_from_domain'\n");
738 g_free(route->set_h_from_domain);
739 route->set_h_from_domain = NULL;
740 }
741 if (route->map_h_reply_to_addresses && route->set_h_reply_to_domain) {
742 logwrite(LOG_WARNING, "'map_h_reply_to_addresses' overrides "
743 "'set_h_reply_to_domain'\n");
744 g_free(route->set_h_reply_to_domain);
745 route->set_h_reply_to_domain = NULL;
746 }
748 return route;
749 }
751 static void
752 _g_list_free_all(GList *list)
753 {
754 GList *node;
755 if (!list) {
756 return;
757 }
758 foreach(list, node) {
759 g_free(node->data);
760 }
761 g_list_free(list);
762 }
764 void
765 destroy_route(connect_route *r)
766 {
767 if (r->filename) {
768 g_free(r->filename);
769 }
770 if (r->mail_host) {
771 g_free(r->mail_host->address);
772 g_free(r->mail_host);
773 }
774 if (r->wrapper) {
775 g_free(r->wrapper);
776 }
777 if (r->helo_name) {
778 g_free(r->helo_name);
779 }
780 _g_list_free_all(r->allowed_senders);
781 _g_list_free_all(r->denied_senders);
782 _g_list_free_all(r->allowed_recipients);
783 _g_list_free_all(r->denied_recipients);
784 if (r->set_h_from_domain) {
785 g_free(r->set_h_from_domain);
786 }
787 if (r->set_h_reply_to_domain) {
788 g_free(r->set_h_reply_to_domain);
789 }
790 if (r->set_return_path_domain) {
791 g_free(r->set_return_path_domain);
792 }
793 if (r->map_h_reply_to_addresses) {
794 destroy_table(r->map_h_reply_to_addresses);
795 }
796 if (r->resolve_list) {
797 g_list_free(r->resolve_list);
798 }
799 #ifdef ENABLE_AUTH
800 if (r->auth_name) {
801 g_free(r->auth_name);
802 }
803 if (r->auth_login) {
804 g_free(r->auth_login);
805 }
806 if (r->auth_secret) {
807 g_free(r->auth_secret);
808 }
809 #endif
810 if (r->pipe) {
811 g_free(r->pipe);
812 }
813 g_free(r);
814 }
816 GList*
817 read_route_list(GList *rf_list, gboolean is_perma)
818 {
819 GList *list = NULL;
820 GList *node;
821 uid_t saved_uid, saved_gid;
823 if (!conf.run_as_user) {
824 set_euidgid(0, 0, &saved_uid, &saved_gid);
825 }
826 foreach(rf_list, node) {
827 gchar *fname = (gchar *) (node->data);
828 connect_route *route = read_route(fname, is_perma);
829 if (route) {
830 list = g_list_append(list, route);
831 } else {
832 logwrite(LOG_ALERT, "could not read route "
833 "configuration %s\n", fname);
834 }
835 }
836 /* set uid and gid back */
837 if (!conf.run_as_user) {
838 set_euidgid(saved_uid, saved_gid, NULL, NULL);
839 }
840 return list;
841 }
843 void
844 destroy_route_list(GList *list)
845 {
846 GList *node;
848 foreach(list, node) {
849 connect_route *route = (connect_route *) (node->data);
850 destroy_route(route);
851 }
852 g_list_free(list);
853 }