masqmail

view src/conf.c @ 402:eedc23877cd5

Ensure lval and rval are always stripped. Plus minor refactoring.
author markus schnalke <meillo@marmaro.de>
date Tue, 21 Feb 2012 16:11:28 +0100
parents 6f2a8113a79e
children 9b93c0a3bd8c
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 }
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 DEBUG(9) fprintf(stderr, " rval = %s\n", rval);
393 return TRUE;
394 }
396 gboolean
397 read_conf(gchar *filename)
398 {
399 FILE *in;
400 gchar lval[256], rval[2048];
401 GList *listen_addrs_tmp = NULL;
403 conf.do_relay = TRUE;
404 conf.localpartcmp = strcmp;
405 conf.max_defer_time = 86400 * 4; /* 4 days */
406 conf.max_msg_size = 0; /* no limit on msg size */
407 conf.spool_dir = SPOOL_DIR;
408 conf.mail_dir = "/var/mail";
410 if (!(in = fopen(filename, "r"))) {
411 logwrite(LOG_ALERT, "could not open config file %s: %s\n",
412 filename, strerror(errno));
413 return FALSE;
414 }
416 while (read_statement(in, lval, sizeof lval, rval, sizeof rval)) {
417 DEBUG(9) fprintf(stderr,"read_conf(): lval=%s\n", lval);
418 if (strcmp(lval, "debug_level")==0) {
419 conf.debug_level = atoi(rval);
420 } else if (strcmp(lval, "run_as_user")==0) {
421 if (!conf.run_as_user) {
422 /* you should not be able to reset that flag */
423 conf.run_as_user = parse_boolean(rval);
424 }
425 } else if (strcmp(lval, "use_syslog")==0) {
426 conf.use_syslog = parse_boolean(rval);
427 } else if (strcmp(lval, "mail_dir")==0) {
428 conf.mail_dir = g_strdup(rval);
429 } else if (strcmp(lval, "lock_dir")==0) {
430 conf.lock_dir = g_strdup(rval);
431 } else if (strcmp(lval, "spool_dir")==0) {
432 conf.spool_dir = g_strdup(rval);
433 } else if (strcmp(lval, "log_dir")==0) {
434 conf.log_dir = g_strdup(rval);
435 } else if (strcmp(lval, "host_name")==0) {
436 if (rval[0] != '/') {
437 conf.host_name = g_strdup(rval);
438 } else {
439 char buf[256];
440 FILE *fptr = fopen(rval, "rt");
441 if (!fptr) {
442 logwrite(LOG_ALERT, "could not open "
443 "%s: %s\n", rval,
444 strerror(errno));
445 return FALSE;
446 }
447 fgets(buf, sizeof buf, fptr);
448 g_strstrip(buf);
449 conf.host_name = g_strdup(buf);
450 fclose(fptr);
451 }
452 } else if (strcmp(lval, "local_hosts")==0) {
453 conf.local_hosts = parse_list(rval, TRUE);
454 } else if (strcmp(lval, "local_addresses")==0) {
455 conf.local_addresses = parse_list(rval, TRUE);
456 } else if (strcmp(lval, "not_local_addresses")==0) {
457 conf.not_local_addresses = parse_list(rval, TRUE);
458 } else if (strcmp(lval, "do_save_envelope_to")==0) {
459 conf.do_save_envelope_to = parse_boolean(rval);
460 } else if (strcmp(lval, "defer_all")==0) {
461 conf.defer_all = parse_boolean(rval);
462 } else if (strcmp(lval, "do_relay")==0) {
463 conf.do_relay = parse_boolean(rval);
464 } else if (strcmp(lval, "alias_file")==0) {
465 conf.alias_file = g_strdup(rval);
466 } else if (strcmp(lval, "globalias_file")==0) {
467 conf.globalias_file = g_strdup(rval);
468 } else if (strcmp(lval, "caseless_matching")==0) {
469 conf.localpartcmp = parse_boolean(rval) ?
470 strcasecmp : strcmp;
471 } else if (strcmp(lval, "mbox_default")==0) {
472 conf.mbox_default = g_strdup(rval);
473 } else if (strcmp(lval, "mbox_users")==0) {
474 conf.mbox_users = parse_list(rval, TRUE);
475 } else if (strcmp(lval, "mda_users")==0) {
476 conf.mda_users = parse_list(rval, TRUE);
477 } else if (strcmp(lval, "mda")==0) {
478 conf.mda = g_strdup(rval);
479 } else if (strcmp(lval, "mda_fromline")==0) {
480 conf.mda_fromline = parse_boolean(rval);
481 } else if (strcmp(lval, "mda_fromhack")==0) {
482 conf.mda_fromhack = parse_boolean(rval);
483 } else if (strcmp(lval, "pipe_fromline")==0) {
484 conf.pipe_fromline = parse_boolean(rval);
485 } else if (strcmp(lval, "pipe_fromhack")==0) {
486 conf.pipe_fromhack = parse_boolean(rval);
487 } else if (strcmp(lval, "listen_addresses")==0) {
488 listen_addrs_tmp = parse_list(rval, TRUE);
489 } else if (strncmp(lval, "query_routes.", 13)==0) {
490 GList *file_list = parse_list(rval, FALSE);
491 table_pair *pair = create_pair(lval+13, file_list);
492 conf.query_routes = g_list_append(conf.query_routes,
493 pair);
494 } else if (strcmp(lval, "permanent_routes")==0) {
495 conf.perma_routes = parse_list(rval, FALSE);
496 } else if (strcmp(lval, "online_query")==0) {
497 conf.online_query = g_strdup(rval);
498 } else if (strcmp(lval, "do_queue")==0) {
499 conf.do_queue = parse_boolean(rval);
500 } else if (strcmp(lval, "errmsg_file")==0) {
501 conf.errmsg_file = g_strdup(rval);
502 } else if (strcmp(lval, "warnmsg_file")==0) {
503 conf.warnmsg_file = g_strdup(rval);
504 } else if (strcmp(lval, "warn_intervals")==0) {
505 conf.warn_intervals = parse_list(rval, TRUE);
506 } else if (strcmp(lval, "max_defer_time")==0) {
507 gint ival = time_interval(rval);
508 if (ival < 0) {
509 logwrite(LOG_WARNING, "invalid time interval "
510 "for 'max_defer_time': %s\n",
511 rval);
512 } else {
513 conf.max_defer_time = ival;
514 }
515 } else if (strcmp(lval, "log_user")==0) {
516 conf.log_user = g_strdup(rval);
517 } else if(strcmp(lval, "max_msg_size")==0) {
518 conf.max_msg_size = atol(rval);
519 DEBUG(9) fprintf(stderr,
520 "rval=%s, conf.max_msg_size=%ld\n",
521 rval, conf.max_msg_size);
522 } else {
523 logwrite(LOG_WARNING, "var '%s' unknown: ignored\n",
524 lval);
525 }
526 }
527 fclose(in);
529 if (!conf.host_name) {
530 logwrite(LOG_ALERT, "`host_name' MUST be set in "
531 "masqmail.conf. See man page\n");
532 return FALSE;
533 }
534 if (!conf.errmsg_file) {
535 conf.errmsg_file = g_strdup(DATA_DIR "/tpl/failmsg.tpl");
536 }
537 if (!conf.warnmsg_file) {
538 conf.warnmsg_file = g_strdup(DATA_DIR "/tpl/warnmsg.tpl");
539 }
540 if (!conf.lock_dir) {
541 conf.lock_dir = g_strdup_printf("%s/lock/", conf.spool_dir);
542 }
543 if (!conf.mbox_default) {
544 conf.mbox_default = g_strdup("mbox");
545 }
546 if (!conf.warn_intervals) {
547 conf.warn_intervals = parse_list("1h;4h;8h;1d;2d;3d", TRUE);
548 }
549 if (!conf.local_hosts) {
550 char *shortname = strdup(conf.host_name);
551 char *p = strchr(shortname, '.');
552 if (p) {
553 *p = '\0';
554 }
555 /* don't care if shortname and conf.host_name are the same */
556 char *local_hosts_str = g_strdup_printf("localhost;%s;%s",
557 shortname, conf.host_name);
558 conf.local_hosts = parse_list(local_hosts_str, TRUE);
559 free(shortname);
560 free(local_hosts_str);
561 }
562 if (!listen_addrs_tmp) {
563 conf.listen_addresses = g_list_append(NULL,
564 parse_interface("localhost", 25));
565 } else {
566 GList *node;
568 foreach(listen_addrs_tmp, node) {
569 conf.listen_addresses =
570 g_list_append(conf.listen_addresses,
571 parse_interface((gchar *) node->data,
572 25));
573 g_free(node->data);
574 }
575 g_list_free(listen_addrs_tmp);
576 }
578 return TRUE;
579 }
581 connect_route*
582 read_route(gchar *filename, gboolean is_perma)
583 {
584 FILE *in;
585 connect_route *route;
586 gchar lval[256], rval[2048];
588 DEBUG(5) debugf("read_route, filename = %s\n", filename);
590 if (!(in = fopen(filename, "r"))) {
591 logwrite(LOG_ALERT, "could not open route file %s: %s\n",
592 filename, strerror(errno));
593 return NULL;
594 }
596 route = g_malloc(sizeof(connect_route));
597 memset(route, 0, sizeof(connect_route));
598 route->filename = g_strdup(filename);
599 route->name = route->filename; /* quick hack */
600 route->expand_h_sender_address = TRUE;
601 route->is_perma = is_perma;
602 route->do_pipelining = TRUE;
604 while (read_statement(in, lval, sizeof lval, rval, sizeof rval)) {
605 if (strcmp(lval, "mail_host")==0) {
606 route->mail_host = parse_interface(rval, 25);
607 } else if (strcmp(lval, "helo_name")==0) {
608 route->helo_name = g_strdup(rval);
609 } else if (strcmp(lval, "wrapper")==0) {
610 route->wrapper = g_strdup(rval);
611 } else if (strcmp(lval, "connect_error_fail")==0) {
612 route->connect_error_fail = parse_boolean(rval);
613 } else if (strcmp(lval, "do_correct_helo")==0) {
614 route->do_correct_helo = parse_boolean(rval);
615 } else if (strcmp(lval, "instant_helo")==0) {
616 route->instant_helo = parse_boolean(rval);
617 } else if (strcmp(lval, "do_pipelining")==0) {
618 route->do_pipelining = parse_boolean(rval);
620 } else if (strcmp(lval, "allowed_senders")==0) {
621 route->allowed_senders = parse_address_glob_list(rval);
622 } else if (strcmp(lval, "denied_senders")==0) {
623 route->denied_senders = parse_address_glob_list(rval);
624 } else if (strcmp(lval, "allowed_recipients")==0) {
625 route->allowed_recipients = parse_address_glob_list(rval);
626 } else if (strcmp(lval, "denied_recipients")==0) {
627 route->denied_recipients = parse_address_glob_list(rval);
629 } else if (strcmp(lval, "set_h_from_domain")==0) {
630 route->set_h_from_domain = g_strdup(rval);
631 } else if (strcmp(lval, "set_h_reply_to_domain")==0) {
632 route->set_h_reply_to_domain = g_strdup(rval);
633 } else if (strcmp(lval, "set_return_path_domain")==0) {
634 route->set_return_path_domain = g_strdup(rval);
635 } else if (strcmp(lval, "map_return_path_addresses")==0) {
636 GList *node, *list;
638 list = parse_list(rval, TRUE);
639 foreach(list, node) {
640 gchar *item = (gchar *) (node->data);
641 table_pair *pair = parse_table_pair(item, ':');
642 address *addr = create_address(
643 (gchar *) (pair->value), TRUE);
644 g_free(pair->value);
645 pair->value = (gpointer *) addr;
646 route->map_return_path_addresses = g_list_append(route->map_return_path_addresses, pair);
647 g_free(item);
648 }
649 g_list_free(list);
650 } else if (strcmp(lval, "map_h_from_addresses")==0) {
651 GList *list, *node;
653 list = parse_list(rval, TRUE);
654 foreach(list, node) {
655 gchar *item = (gchar *) (node->data);
656 table_pair *pair = parse_table_pair(item, ':');
657 route->map_h_from_addresses = g_list_append(route->map_h_from_addresses, pair);
658 g_free(item);
659 }
660 g_list_free(list);
661 } else if (strcmp(lval, "map_h_reply_to_addresses")==0) {
662 GList *list, *node;
664 list = parse_list(rval, TRUE);
665 foreach(list, node) {
666 gchar *item = (gchar *) (node->data);
667 table_pair *pair = parse_table_pair(item, ':');
668 route->map_h_reply_to_addresses = g_list_append(route->map_h_reply_to_addresses, pair);
669 g_free(item);
670 }
671 g_list_free(list);
672 } else if (strcmp(lval, "map_h_mail_followup_to_addresses")==0) {
673 GList *list, *node;
675 list = parse_list(rval, TRUE);
676 foreach(list, node) {
677 gchar *item = (gchar *) (node->data);
678 table_pair *pair = parse_table_pair(item, ':');
679 route->map_h_mail_followup_to_addresses = g_list_append(route->map_h_mail_followup_to_addresses, pair);
680 g_free(item);
681 }
682 g_list_free(list);
683 } else if (strcmp(lval, "expand_h_sender_domain")==0) {
684 route->expand_h_sender_domain = parse_boolean(rval);
685 } else if (strcmp(lval, "expand_h_sender_address")==0) {
686 route->expand_h_sender_address = parse_boolean(rval);
687 } else if (strcmp(lval, "resolve_list")==0) {
688 route->resolve_list = parse_resolve_list(rval);
689 } else if (strcmp(lval, "do_ssl")==0) {
690 /* we ignore this. This option is used by sqilconf */
691 ;
692 #ifdef ENABLE_AUTH
693 } else if (strcmp(lval, "auth_name")==0) {
694 route->auth_name = g_strdup(rval);
695 } else if (strcmp(lval, "auth_login")==0) {
696 route->auth_login = g_strdup(rval);
697 } else if (strcmp(lval, "auth_secret")==0) {
698 route->auth_secret = g_strdup(rval);
699 #else
700 } else if ((strcmp(lval, "auth_name")==0) ||
701 (strcmp(lval, "auth_login")==0) ||
702 (strcmp(lval, "auth_secret")==0)) {
703 logwrite(LOG_WARNING, "%s ignored: not compiled with "
704 "auth support.\n", lval);
705 }
706 #endif
707 } else if (strcmp(lval, "pipe")==0) {
708 route->pipe = g_strdup(rval);
709 } else if (strcmp(lval, "pipe_fromline")==0) {
710 route->pipe_fromline = parse_boolean(rval);
711 } else if (strcmp(lval, "pipe_fromhack")==0) {
712 route->pipe_fromhack = parse_boolean(rval);
713 } else if (strcmp(lval, "last_route")==0) {
714 route->last_route = parse_boolean(rval);
715 } else {
716 logwrite(LOG_WARNING, "var '%s' unknown: ignored\n",
717 lval);
718 }
719 }
721 if (!route->resolve_list) {
722 #ifdef ENABLE_RESOLVER
723 route->resolve_list = g_list_append(route->resolve_list,
724 resolve_dns_mx);
725 route->resolve_list = g_list_append(route->resolve_list,
726 resolve_dns_a);
727 #endif
728 route->resolve_list = g_list_append(route->resolve_list,
729 resolve_byname);
730 }
731 fclose(in);
733 /* warn user about mis-configurations: */
734 if (route->map_h_from_addresses && route->set_h_from_domain) {
735 logwrite(LOG_WARNING, "'map_h_from_addresses' overrides "
736 "'set_h_from_domain'\n");
737 g_free(route->set_h_from_domain);
738 route->set_h_from_domain = NULL;
739 }
740 if (route->map_h_reply_to_addresses && route->set_h_reply_to_domain) {
741 logwrite(LOG_WARNING, "'map_h_reply_to_addresses' overrides "
742 "'set_h_reply_to_domain'\n");
743 g_free(route->set_h_reply_to_domain);
744 route->set_h_reply_to_domain = NULL;
745 }
747 return route;
748 }
750 static void
751 _g_list_free_all(GList *list)
752 {
753 GList *node;
754 if (!list) {
755 return;
756 }
757 foreach(list, node) {
758 g_free(node->data);
759 }
760 g_list_free(list);
761 }
763 void
764 destroy_route(connect_route *r)
765 {
766 if (r->filename) {
767 g_free(r->filename);
768 }
769 if (r->mail_host) {
770 g_free(r->mail_host->address);
771 g_free(r->mail_host);
772 }
773 if (r->wrapper) {
774 g_free(r->wrapper);
775 }
776 if (r->helo_name) {
777 g_free(r->helo_name);
778 }
779 _g_list_free_all(r->allowed_senders);
780 _g_list_free_all(r->denied_senders);
781 _g_list_free_all(r->allowed_recipients);
782 _g_list_free_all(r->denied_recipients);
783 if (r->set_h_from_domain) {
784 g_free(r->set_h_from_domain);
785 }
786 if (r->set_h_reply_to_domain) {
787 g_free(r->set_h_reply_to_domain);
788 }
789 if (r->set_return_path_domain) {
790 g_free(r->set_return_path_domain);
791 }
792 if (r->map_h_reply_to_addresses) {
793 destroy_table(r->map_h_reply_to_addresses);
794 }
795 if (r->resolve_list) {
796 g_list_free(r->resolve_list);
797 }
798 #ifdef ENABLE_AUTH
799 if (r->auth_name) {
800 g_free(r->auth_name);
801 }
802 if (r->auth_login) {
803 g_free(r->auth_login);
804 }
805 if (r->auth_secret) {
806 g_free(r->auth_secret);
807 }
808 #endif
809 if (r->pipe) {
810 g_free(r->pipe);
811 }
812 g_free(r);
813 }
815 GList*
816 read_route_list(GList *rf_list, gboolean is_perma)
817 {
818 GList *list = NULL;
819 GList *node;
820 uid_t saved_uid, saved_gid;
822 if (!conf.run_as_user) {
823 set_euidgid(0, 0, &saved_uid, &saved_gid);
824 }
825 foreach(rf_list, node) {
826 gchar *fname = (gchar *) (node->data);
827 connect_route *route = read_route(fname, is_perma);
828 if (route) {
829 list = g_list_append(list, route);
830 } else {
831 logwrite(LOG_ALERT, "could not read route "
832 "configuration %s\n", fname);
833 }
834 }
835 /* set uid and gid back */
836 if (!conf.run_as_user) {
837 set_euidgid(saved_uid, saved_gid, NULL, NULL);
838 }
839 return list;
840 }
842 void
843 destroy_route_list(GList *list)
844 {
845 GList *node;
847 foreach(list, node) {
848 connect_route *route = (connect_route *) (node->data);
849 destroy_route(route);
850 }
851 g_list_free(list);
852 }