masqmail

view src/conf.c @ 396:6f2a8113a79e

Fixed conf.c: read_lval().
author markus schnalke <meillo@marmaro.de>
date Sat, 18 Feb 2012 19:57:39 +0100
parents 5f0829f8e6c7
children eedc23877cd5
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 DEBUG(9) fprintf(stderr, "read_lval() 2\n");
285 while (1) {
286 if ((c = fgetc(in)) == EOF) {
287 fprintf(stderr, "unexpected EOF after %s\n", buf);
288 return FALSE;
289 }
290 if (ptr >= buf+size-1) {
291 fprintf(stderr, "lval too long\n");
292 break;
293 }
294 if (!isalnum(c) && c != '_' && c != '-' && c != '.') {
295 break;
296 }
297 *ptr++ = c;
298 }
299 *ptr = '\0';
300 ungetc(c, in);
301 eat_spaces(in);
302 DEBUG(9) fprintf(stderr, "lval = %s\n", buf);
303 return *buf != '\0';
304 }
306 static gboolean
307 read_rval(FILE *in, gchar *buf, gint size)
308 {
309 gint c;
310 gchar *ptr = buf;
312 DEBUG(9) fprintf(stderr, "read_rval()\n");
313 if (!eat_spaces(in)) {
314 return FALSE;
315 }
317 c = fgetc(in);
318 if (c != '"') {
319 /* unquoted rval */
320 ungetc(c, in);
321 while ((c = fgetc(in)) != EOF) {
322 if (ptr >= buf+size-1) {
323 /* rval too long */
324 break;
325 }
326 if (!isalnum(c) && c != '_' && c != '-' &&
327 c != '.' && c != '/' && c != '@' &&
328 c != ';' && c != ':') {
329 break;
330 }
331 *ptr++ = c;
332 }
333 *ptr = '\0';
334 ungetc(c, in);
335 } else {
336 /* quoted rval */
337 gboolean escape = FALSE;
338 while ((c = fgetc(in)) != EOF) {
339 if (ptr >= buf+size-1) {
340 /* rval too long */
341 break;
342 }
343 if (!escape && c == '"') {
344 break;
345 }
346 if (!escape && c == '\\') {
347 escape = TRUE;
348 continue;
349 }
350 *ptr++ = c;
351 escape = FALSE;
352 }
353 *ptr = '\0';
354 }
355 DEBUG(9) fprintf(stderr, "rval = %s\n", buf);
356 /* eat trailing of line */
357 while ((c = fgetc(in)) != EOF && c != '\n') {
358 continue;
359 }
361 return TRUE;
362 }
364 static gboolean
365 read_statement(FILE *in, gchar *lval, gint lsize, gchar *rval, gint rsize)
366 {
367 gint c;
369 DEBUG(9) fprintf(stderr, "read_statement()\n");
371 /* eat comments and empty lines: */
372 if (!eat_comments(in)) {
373 return FALSE;
374 }
375 if (!read_lval(in, lval, lsize)) {
376 return FALSE;
377 }
379 DEBUG(9) fprintf(stderr, " lval = %s\n", lval);
380 if ((c = fgetc(in) != '=')) {
381 fprintf(stderr, "'=' expected after %s, char was '%c'\n",
382 lval, c);
383 }
384 if (!read_rval(in, rval, rsize)) {
385 return FALSE;
386 }
387 DEBUG(9) fprintf(stderr, " rval = %s\n", rval);
388 return TRUE;
389 }
391 gboolean
392 read_conf(gchar *filename)
393 {
394 FILE *in;
395 gchar lval[256], rval[2048];
396 GList *listen_addrs_tmp = NULL;
398 conf.do_relay = TRUE;
399 conf.localpartcmp = strcmp;
400 conf.max_defer_time = 86400 * 4; /* 4 days */
401 conf.max_msg_size = 0; /* no limit on msg size */
402 conf.spool_dir = SPOOL_DIR;
403 conf.mail_dir = "/var/mail";
405 if (!(in = fopen(filename, "r"))) {
406 logwrite(LOG_ALERT, "could not open config file %s: %s\n",
407 filename, strerror(errno));
408 return FALSE;
409 }
411 while (read_statement(in, lval, sizeof lval, rval, sizeof rval)) {
412 DEBUG(9) fprintf(stderr,"read_conf(): lval=%s\n", lval);
413 if (strcmp(lval, "debug_level")==0) {
414 conf.debug_level = atoi(rval);
415 } else if (strcmp(lval, "run_as_user")==0) {
416 if (!conf.run_as_user) {
417 /* you should not be able to reset that flag */
418 conf.run_as_user = parse_boolean(rval);
419 }
420 } else if (strcmp(lval, "use_syslog")==0) {
421 conf.use_syslog = parse_boolean(rval);
422 } else if (strcmp(lval, "mail_dir")==0) {
423 conf.mail_dir = g_strdup(rval);
424 } else if (strcmp(lval, "lock_dir")==0) {
425 conf.lock_dir = g_strdup(rval);
426 } else if (strcmp(lval, "spool_dir")==0) {
427 conf.spool_dir = g_strdup(rval);
428 } else if (strcmp(lval, "log_dir")==0) {
429 conf.log_dir = g_strdup(rval);
430 } else if (strcmp(lval, "host_name")==0) {
431 if (rval[0] != '/') {
432 conf.host_name = g_strdup(rval);
433 } else {
434 char buf[256];
435 FILE *fptr = fopen(rval, "rt");
436 if (!fptr) {
437 logwrite(LOG_ALERT, "could not open "
438 "%s: %s\n", rval,
439 strerror(errno));
440 return FALSE;
441 }
442 fgets(buf, sizeof buf, fptr);
443 g_strstrip(buf);
444 conf.host_name = g_strdup(buf);
445 fclose(fptr);
446 }
447 } else if (strcmp(lval, "local_hosts")==0) {
448 conf.local_hosts = parse_list(rval, TRUE);
449 } else if (strcmp(lval, "local_addresses")==0) {
450 conf.local_addresses = parse_list(rval, TRUE);
451 } else if (strcmp(lval, "not_local_addresses")==0) {
452 conf.not_local_addresses = parse_list(rval, TRUE);
453 } else if (strcmp(lval, "do_save_envelope_to")==0) {
454 conf.do_save_envelope_to = parse_boolean(rval);
455 } else if (strcmp(lval, "defer_all")==0) {
456 conf.defer_all = parse_boolean(rval);
457 } else if (strcmp(lval, "do_relay")==0) {
458 conf.do_relay = parse_boolean(rval);
459 } else if (strcmp(lval, "alias_file")==0) {
460 conf.alias_file = g_strdup(rval);
461 } else if (strcmp(lval, "globalias_file")==0) {
462 conf.globalias_file = g_strdup(rval);
463 } else if (strcmp(lval, "caseless_matching")==0) {
464 conf.localpartcmp = parse_boolean(rval) ?
465 strcasecmp : strcmp;
466 } else if (strcmp(lval, "mbox_default")==0) {
467 conf.mbox_default = g_strdup(rval);
468 } else if (strcmp(lval, "mbox_users")==0) {
469 conf.mbox_users = parse_list(rval, TRUE);
470 } else if (strcmp(lval, "mda_users")==0) {
471 conf.mda_users = parse_list(rval, TRUE);
472 } else if (strcmp(lval, "mda")==0) {
473 conf.mda = g_strdup(rval);
474 } else if (strcmp(lval, "mda_fromline")==0) {
475 conf.mda_fromline = parse_boolean(rval);
476 } else if (strcmp(lval, "mda_fromhack")==0) {
477 conf.mda_fromhack = parse_boolean(rval);
478 } else if (strcmp(lval, "pipe_fromline")==0) {
479 conf.pipe_fromline = parse_boolean(rval);
480 } else if (strcmp(lval, "pipe_fromhack")==0) {
481 conf.pipe_fromhack = parse_boolean(rval);
482 } else if (strcmp(lval, "listen_addresses")==0) {
483 listen_addrs_tmp = parse_list(rval, TRUE);
484 } else if (strncmp(lval, "query_routes.", 13)==0) {
485 GList *file_list = parse_list(rval, FALSE);
486 table_pair *pair = create_pair(lval+13, file_list);
487 conf.query_routes = g_list_append(conf.query_routes,
488 pair);
489 } else if (strcmp(lval, "permanent_routes")==0) {
490 conf.perma_routes = parse_list(rval, FALSE);
491 } else if (strcmp(lval, "online_query")==0) {
492 conf.online_query = g_strdup(rval);
493 } else if (strcmp(lval, "do_queue")==0) {
494 conf.do_queue = parse_boolean(rval);
495 } else if (strcmp(lval, "errmsg_file")==0) {
496 conf.errmsg_file = g_strdup(rval);
497 } else if (strcmp(lval, "warnmsg_file")==0) {
498 conf.warnmsg_file = g_strdup(rval);
499 } else if (strcmp(lval, "warn_intervals")==0) {
500 conf.warn_intervals = parse_list(rval, TRUE);
501 } else if (strcmp(lval, "max_defer_time")==0) {
502 gint ival = time_interval(rval);
503 if (ival < 0) {
504 logwrite(LOG_WARNING, "invalid time interval "
505 "for 'max_defer_time': %s\n",
506 rval);
507 } else {
508 conf.max_defer_time = ival;
509 }
510 } else if (strcmp(lval, "log_user")==0) {
511 conf.log_user = g_strdup(rval);
512 } else if(strcmp(lval, "max_msg_size")==0) {
513 conf.max_msg_size = atol(rval);
514 DEBUG(9) fprintf(stderr,
515 "rval=%s, conf.max_msg_size=%ld\n",
516 rval, conf.max_msg_size);
517 } else {
518 logwrite(LOG_WARNING, "var '%s' unknown: ignored\n",
519 lval);
520 }
521 }
522 fclose(in);
524 if (!conf.host_name) {
525 logwrite(LOG_ALERT, "`host_name' MUST be set in "
526 "masqmail.conf. See man page\n");
527 return FALSE;
528 }
529 if (!conf.errmsg_file) {
530 conf.errmsg_file = g_strdup(DATA_DIR "/tpl/failmsg.tpl");
531 }
532 if (!conf.warnmsg_file) {
533 conf.warnmsg_file = g_strdup(DATA_DIR "/tpl/warnmsg.tpl");
534 }
535 if (!conf.lock_dir) {
536 conf.lock_dir = g_strdup_printf("%s/lock/", conf.spool_dir);
537 }
538 if (!conf.mbox_default) {
539 conf.mbox_default = g_strdup("mbox");
540 }
541 if (!conf.warn_intervals) {
542 conf.warn_intervals = parse_list("1h;4h;8h;1d;2d;3d", TRUE);
543 }
544 if (!conf.local_hosts) {
545 char *shortname = strdup(conf.host_name);
546 char *p = strchr(shortname, '.');
547 if (p) {
548 *p = '\0';
549 }
550 /* don't care if shortname and conf.host_name are the same */
551 char *local_hosts_str = g_strdup_printf("localhost;%s;%s",
552 shortname, conf.host_name);
553 conf.local_hosts = parse_list(local_hosts_str, TRUE);
554 free(shortname);
555 free(local_hosts_str);
556 }
557 if (!listen_addrs_tmp) {
558 conf.listen_addresses = g_list_append(NULL,
559 parse_interface("localhost", 25));
560 } else {
561 GList *node;
563 foreach(listen_addrs_tmp, node) {
564 conf.listen_addresses =
565 g_list_append(conf.listen_addresses,
566 parse_interface((gchar *) node->data,
567 25));
568 g_free(node->data);
569 }
570 g_list_free(listen_addrs_tmp);
571 }
573 return TRUE;
574 }
576 connect_route*
577 read_route(gchar *filename, gboolean is_perma)
578 {
579 FILE *in;
580 connect_route *route;
581 gchar lval[256], rval[2048];
583 DEBUG(5) debugf("read_route, filename = %s\n", filename);
585 if (!(in = fopen(filename, "r"))) {
586 logwrite(LOG_ALERT, "could not open route file %s: %s\n",
587 filename, strerror(errno));
588 return NULL;
589 }
591 route = g_malloc(sizeof(connect_route));
592 memset(route, 0, sizeof(connect_route));
593 route->filename = g_strdup(filename);
594 route->name = route->filename; /* quick hack */
595 route->expand_h_sender_address = TRUE;
596 route->is_perma = is_perma;
597 route->do_pipelining = TRUE;
599 while (read_statement(in, lval, sizeof lval, rval, sizeof rval)) {
600 if (strcmp(lval, "mail_host")==0) {
601 route->mail_host = parse_interface(rval, 25);
602 } else if (strcmp(lval, "helo_name")==0) {
603 route->helo_name = g_strdup(rval);
604 } else if (strcmp(lval, "wrapper")==0) {
605 route->wrapper = g_strdup(rval);
606 } else if (strcmp(lval, "connect_error_fail")==0) {
607 route->connect_error_fail = parse_boolean(rval);
608 } else if (strcmp(lval, "do_correct_helo")==0) {
609 route->do_correct_helo = parse_boolean(rval);
610 } else if (strcmp(lval, "instant_helo")==0) {
611 route->instant_helo = parse_boolean(rval);
612 } else if (strcmp(lval, "do_pipelining")==0) {
613 route->do_pipelining = parse_boolean(rval);
615 } else if (strcmp(lval, "allowed_senders")==0) {
616 route->allowed_senders = parse_address_glob_list(rval);
617 } else if (strcmp(lval, "denied_senders")==0) {
618 route->denied_senders = parse_address_glob_list(rval);
619 } else if (strcmp(lval, "allowed_recipients")==0) {
620 route->allowed_recipients = parse_address_glob_list(rval);
621 } else if (strcmp(lval, "denied_recipients")==0) {
622 route->denied_recipients = parse_address_glob_list(rval);
624 } else if (strcmp(lval, "set_h_from_domain")==0) {
625 route->set_h_from_domain = g_strdup(rval);
626 } else if (strcmp(lval, "set_h_reply_to_domain")==0) {
627 route->set_h_reply_to_domain = g_strdup(rval);
628 } else if (strcmp(lval, "set_return_path_domain")==0) {
629 route->set_return_path_domain = g_strdup(rval);
630 } else if (strcmp(lval, "map_return_path_addresses")==0) {
631 GList *node, *list;
633 list = parse_list(rval, TRUE);
634 foreach(list, node) {
635 gchar *item = (gchar *) (node->data);
636 table_pair *pair = parse_table_pair(item, ':');
637 address *addr = create_address(
638 (gchar *) (pair->value), TRUE);
639 g_free(pair->value);
640 pair->value = (gpointer *) addr;
641 route->map_return_path_addresses = g_list_append( route->map_return_path_addresses, pair);
642 g_free(item);
643 }
644 g_list_free(list);
645 } else if (strcmp(lval, "map_h_from_addresses")==0) {
646 GList *list, *node;
648 list = parse_list(rval, TRUE);
649 foreach(list, node) {
650 gchar *item = (gchar *) (node->data);
651 table_pair *pair = parse_table_pair(item, ':');
652 route->map_h_from_addresses = g_list_append(route->map_h_from_addresses, pair);
653 g_free(item);
654 }
655 g_list_free(list);
656 } else if (strcmp(lval, "map_h_reply_to_addresses")==0) {
657 GList *list, *node;
659 list = parse_list(rval, TRUE);
660 foreach(list, node) {
661 gchar *item = (gchar *) (node->data);
662 table_pair *pair = parse_table_pair(item, ':');
663 route->map_h_reply_to_addresses = g_list_append(route->map_h_reply_to_addresses, pair);
664 g_free(item);
665 }
666 g_list_free(list);
667 } else if (strcmp(lval, "map_h_mail_followup_to_addresses")==0) {
668 GList *list, *node;
670 list = parse_list(rval, TRUE);
671 foreach(list, node) {
672 gchar *item = (gchar *) (node->data);
673 table_pair *pair = parse_table_pair(item, ':');
674 route->map_h_mail_followup_to_addresses = g_list_append(route->map_h_mail_followup_to_addresses, pair);
675 g_free(item);
676 }
677 g_list_free(list);
678 } else if (strcmp(lval, "expand_h_sender_domain")==0) {
679 route->expand_h_sender_domain = parse_boolean(rval);
680 } else if (strcmp(lval, "expand_h_sender_address")==0) {
681 route->expand_h_sender_address = parse_boolean(rval);
682 } else if (strcmp(lval, "resolve_list")==0) {
683 route->resolve_list = parse_resolve_list(rval);
684 } else if (strcmp(lval, "do_ssl")==0) {
685 /* we ignore this. This option is used by sqilconf */
686 ;
687 #ifdef ENABLE_AUTH
688 } else if (strcmp(lval, "auth_name")==0) {
689 route->auth_name = g_strdup(rval);
690 } else if (strcmp(lval, "auth_login")==0) {
691 route->auth_login = g_strdup(rval);
692 } else if (strcmp(lval, "auth_secret")==0) {
693 route->auth_secret = g_strdup(rval);
694 #else
695 } else if ((strcmp(lval, "auth_name")==0) ||
696 (strcmp(lval, "auth_login")==0) ||
697 (strcmp(lval, "auth_secret")==0)) {
698 logwrite(LOG_WARNING, "%s ignored: not compiled with "
699 "auth support.\n", lval);
700 }
701 #endif
702 } else if (strcmp(lval, "pipe")==0) {
703 route->pipe = g_strdup(rval);
704 } else if (strcmp(lval, "pipe_fromline")==0) {
705 route->pipe_fromline = parse_boolean(rval);
706 } else if (strcmp(lval, "pipe_fromhack")==0) {
707 route->pipe_fromhack = parse_boolean(rval);
708 } else if (strcmp(lval, "last_route")==0) {
709 route->last_route = parse_boolean(rval);
710 } else {
711 logwrite(LOG_WARNING, "var '%s' unknown: ignored\n",
712 lval);
713 }
714 }
716 if (!route->resolve_list) {
717 #ifdef ENABLE_RESOLVER
718 route->resolve_list = g_list_append(route->resolve_list,
719 resolve_dns_mx);
720 route->resolve_list = g_list_append(route->resolve_list,
721 resolve_dns_a);
722 #endif
723 route->resolve_list = g_list_append(route->resolve_list,
724 resolve_byname);
725 }
726 fclose(in);
728 /* warn user about mis-configurations: */
729 if (route->map_h_from_addresses && route->set_h_from_domain) {
730 logwrite(LOG_WARNING, "'map_h_from_addresses' overrides "
731 "'set_h_from_domain'\n");
732 g_free(route->set_h_from_domain);
733 route->set_h_from_domain = NULL;
734 }
735 if (route->map_h_reply_to_addresses && route->set_h_reply_to_domain) {
736 logwrite(LOG_WARNING, "'map_h_reply_to_addresses' overrides "
737 "'set_h_reply_to_domain'\n");
738 g_free(route->set_h_reply_to_domain);
739 route->set_h_reply_to_domain = NULL;
740 }
742 return route;
743 }
745 static void
746 _g_list_free_all(GList *list)
747 {
748 GList *node;
749 if (!list) {
750 return;
751 }
752 foreach(list, node) {
753 g_free(node->data);
754 }
755 g_list_free(list);
756 }
758 void
759 destroy_route(connect_route *r)
760 {
761 if (r->filename) {
762 g_free(r->filename);
763 }
764 if (r->mail_host) {
765 g_free(r->mail_host->address);
766 g_free(r->mail_host);
767 }
768 if (r->wrapper) {
769 g_free(r->wrapper);
770 }
771 if (r->helo_name) {
772 g_free(r->helo_name);
773 }
774 _g_list_free_all(r->allowed_senders);
775 _g_list_free_all(r->denied_senders);
776 _g_list_free_all(r->allowed_recipients);
777 _g_list_free_all(r->denied_recipients);
778 if (r->set_h_from_domain) {
779 g_free(r->set_h_from_domain);
780 }
781 if (r->set_h_reply_to_domain) {
782 g_free(r->set_h_reply_to_domain);
783 }
784 if (r->set_return_path_domain) {
785 g_free(r->set_return_path_domain);
786 }
787 if (r->map_h_reply_to_addresses) {
788 destroy_table(r->map_h_reply_to_addresses);
789 }
790 if (r->resolve_list) {
791 g_list_free(r->resolve_list);
792 }
793 #ifdef ENABLE_AUTH
794 if (r->auth_name) {
795 g_free(r->auth_name);
796 }
797 if (r->auth_login) {
798 g_free(r->auth_login);
799 }
800 if (r->auth_secret) {
801 g_free(r->auth_secret);
802 }
803 #endif
804 if (r->pipe) {
805 g_free(r->pipe);
806 }
807 g_free(r);
808 }
810 GList*
811 read_route_list(GList *rf_list, gboolean is_perma)
812 {
813 GList *list = NULL;
814 GList *node;
815 uid_t saved_uid, saved_gid;
817 if (!conf.run_as_user) {
818 set_euidgid(0, 0, &saved_uid, &saved_gid);
819 }
820 foreach(rf_list, node) {
821 gchar *fname = (gchar *) (node->data);
822 connect_route *route = read_route(fname, is_perma);
823 if (route) {
824 list = g_list_append(list, route);
825 } else {
826 logwrite(LOG_ALERT, "could not read route "
827 "configuration %s\n", fname);
828 }
829 }
830 /* set uid and gid back */
831 if (!conf.run_as_user) {
832 set_euidgid(saved_uid, saved_gid, NULL, NULL);
833 }
834 return list;
835 }
837 void
838 destroy_route_list(GList *list)
839 {
840 GList *node;
842 foreach(list, node) {
843 connect_route *route = (connect_route *) (node->data);
844 destroy_route(route);
845 }
846 g_list_free(list);
847 }