meillo@367: /* meillo@367: ** MasqMail meillo@367: ** Copyright (C) 1999-2001 Oliver Kurth meillo@367: ** Copyright (C) 2010 markus schnalke meillo@367: ** meillo@367: ** This program is free software; you can redistribute it and/or modify meillo@367: ** it under the terms of the GNU General Public License as published by meillo@367: ** the Free Software Foundation; either version 2 of the License, or meillo@367: ** (at your option) any later version. meillo@367: ** meillo@367: ** This program is distributed in the hope that it will be useful, meillo@367: ** but WITHOUT ANY WARRANTY; without even the implied warranty of meillo@367: ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the meillo@367: ** GNU General Public License for more details. meillo@367: ** meillo@367: ** You should have received a copy of the GNU General Public License meillo@367: ** along with this program; if not, write to the Free Software meillo@367: ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. meillo@0: */ meillo@0: meillo@13: #include meillo@13: #include meillo@13: meillo@0: #include "masqmail.h" meillo@0: meillo@0: masqmail_conf conf; meillo@0: meillo@10: void meillo@10: init_conf() meillo@0: { meillo@10: struct passwd *passwd; meillo@10: struct group *group; meillo@0: meillo@392: if (!(passwd = getpwnam(DEF_MAIL_USER))) { meillo@392: fprintf(stderr, "user %s not found! (terminating)\n", meillo@392: DEF_MAIL_USER); meillo@392: exit(1); meillo@392: } meillo@392: if (!(group = getgrnam(DEF_MAIL_GROUP))) { meillo@392: fprintf(stderr, "group %s not found! (terminating)\n", meillo@392: DEF_MAIL_GROUP); meillo@392: exit(1); meillo@392: } meillo@10: memset(&conf, 0, sizeof(masqmail_conf)); meillo@10: conf.orig_uid = getuid(); meillo@10: conf.orig_gid = getgid(); meillo@392: conf.mail_uid = passwd->pw_uid; meillo@392: conf.mail_gid = group->gr_gid; meillo@0: } meillo@0: meillo@366: static gchar *true_strings[] = { meillo@10: "yes", "on", "true", NULL meillo@0: }; meillo@0: meillo@10: static gchar *false_strings[] = { meillo@10: "no", "off", "false", NULL meillo@0: }; meillo@0: meillo@10: static gboolean meillo@366: parse_boolean(gchar *rval) meillo@0: { meillo@10: gchar **str; meillo@0: meillo@333: DEBUG(9) fprintf(stderr, "parse_boolean: %s\n", rval); meillo@392: for (str = true_strings; *str; str++) { meillo@392: if (strncasecmp(*str, rval, strlen(*str))==0) { meillo@10: return TRUE; meillo@392: } meillo@10: } meillo@392: for (str = false_strings; *str; str++) { meillo@392: if (strncasecmp(*str, rval, strlen(*str))==0) { meillo@10: return FALSE; meillo@392: } meillo@10: } meillo@10: fprintf(stderr, "cannot parse value '%s'\n", rval); meillo@262: exit(1); meillo@0: } meillo@0: meillo@392: /* meillo@392: ** make a list from the lines of a file meillo@392: */ meillo@10: static GList* meillo@392: parse_list_file(const gchar *fname) meillo@0: { meillo@10: GList *list = NULL; meillo@10: FILE *fptr; meillo@392: gchar buf[256]; meillo@0: meillo@392: if (!(fptr = fopen(fname, "rt"))) { meillo@392: logwrite(LOG_ALERT, "could not open %s for reading: %s\n", meillo@392: fname, strerror(errno)); meillo@262: exit(1); meillo@10: } meillo@428: while (fgets(buf, sizeof buf, fptr)) { meillo@392: g_strstrip(buf); meillo@392: if (!*buf || *buf == '#') { meillo@392: continue; meillo@28: } meillo@392: DEBUG(9) fprintf(stderr, "parse_list_file: item = %s\n", buf); meillo@392: list = g_list_append(list, g_strdup(buf)); meillo@28: } meillo@28: fclose(fptr); meillo@28: meillo@10: return list; meillo@0: } meillo@0: meillo@392: /* meillo@392: ** given a semicolon separated string, this function makes a GList out of it. meillo@392: */ meillo@392: static GList* meillo@366: parse_list(gchar *line, gboolean read_file) meillo@0: { meillo@10: GList *list = NULL; meillo@392: gchar *tok; meillo@0: meillo@392: DEBUG(9) fprintf(stderr, "parsing list %s, file?:%d\n", meillo@392: line, read_file); meillo@392: for (tok = strtok(strdup(line), ";"); tok; tok = strtok(NULL, ";")) { meillo@392: DEBUG(9) fprintf(stderr, "item = %s\n", tok); meillo@392: if (read_file && *tok == '/') { meillo@10: /* item is a filename, include its contents */ meillo@392: list = g_list_concat(list, parse_list_file(tok)); meillo@392: } else { meillo@10: /* just a normal item */ meillo@392: list = g_list_append(list, g_strdup(tok)); meillo@392: } meillo@10: } meillo@10: return list; meillo@0: } meillo@0: meillo@367: /* meillo@367: ** Split the addrs at '@' into local_part and domain. Without an '@' meillo@392: ** everything is local_part. Create and return a list of address structs. meillo@392: ** This funktion is used for lists of addrs containing globbing chars meillo@392: ** (* and ?). We don't need valid RFC821 addresses here, just patterns meillo@392: ** to match against. meillo@317: */ meillo@10: static GList* meillo@392: parse_address_glob_list(gchar *line) meillo@0: { meillo@392: GList *plain_list = parse_list(line, TRUE); meillo@10: GList *node; meillo@10: GList *list = NULL; meillo@0: meillo@10: foreach(plain_list, node) { meillo@10: gchar *item = (gchar *) (node->data); meillo@366: char *at; meillo@402: char *ep; meillo@317: address *addr = calloc(1, sizeof(address)); meillo@317: meillo@402: ep = item + strlen(item) - 1; meillo@402: if (*item == '<' && *ep == '>') { meillo@402: *item = '\0'; meillo@402: *ep = '\0'; meillo@402: g_strstrip(item); meillo@317: } meillo@317: meillo@402: addr->address = strdup(item); meillo@402: at = strrchr(item, '@'); meillo@317: if (at) { meillo@317: *at = '\0'; meillo@402: addr->local_part = strdup(item); meillo@317: addr->domain = strdup(at+1); meillo@317: } else { meillo@402: addr->local_part = strdup(item); meillo@330: /* No `@', thus any domain is okay. */ meillo@330: addr->domain = "*"; meillo@317: } meillo@317: list = g_list_append(list, addr); meillo@392: DEBUG(6) debugf("parse_address_glob_list: " meillo@392: "read pattern `%s' `%s'\n", meillo@317: addr->local_part, addr->domain); meillo@10: g_free(item); meillo@10: } meillo@10: g_list_free(plain_list); meillo@10: return list; meillo@0: } meillo@0: meillo@10: static GList* meillo@366: parse_resolve_list(gchar *line) meillo@0: { meillo@10: GList *list; meillo@10: GList *list_node; meillo@10: GList *res_list = NULL; meillo@392: gchar *item; meillo@0: meillo@392: list = parse_list(line, TRUE); meillo@28: if (!list) { meillo@28: return NULL; meillo@28: } meillo@28: foreach(list, list_node) { meillo@392: item = (gchar *) list_node->data; meillo@392: if (strcmp(item, "byname")==0) { meillo@28: res_list = g_list_append(res_list, resolve_byname); meillo@0: #ifdef ENABLE_RESOLVER meillo@392: } else if (strcmp(item, "dns_a")==0) { meillo@28: res_list = g_list_append(res_list, resolve_dns_a); meillo@392: } else if (strcmp(item, "dns_mx")==0) { meillo@28: res_list = g_list_append(res_list, resolve_dns_mx); meillo@0: #endif meillo@28: } else { meillo@28: logwrite(LOG_ALERT, "unknown resolver %s\n", item); meillo@262: exit(1); meillo@10: } meillo@28: g_free(item); meillo@10: } meillo@28: g_list_free(list); meillo@10: return res_list; meillo@0: } meillo@0: meillo@10: static interface* meillo@366: parse_interface(gchar *line, gint def_port) meillo@0: { meillo@392: gchar *cp; meillo@392: interface *iface = g_malloc(sizeof(interface)); meillo@0: meillo@333: DEBUG(9) fprintf(stderr, "parse_interface: %s\n", line); meillo@392: if ((cp = strchr(line, ':'))) { meillo@392: *cp = '\0'; meillo@392: } meillo@402: g_strstrip(line); meillo@392: iface->address = g_strdup(line); meillo@392: iface->port = (cp) ? atoi(++cp) : def_port; meillo@412: DEBUG(9) fprintf(stderr, "found: address:port=%s:%u\n", meillo@392: iface->address, iface->port); meillo@10: return iface; meillo@0: } meillo@0: meillo@10: static gboolean meillo@366: eat_comments(FILE *in) meillo@0: { meillo@10: gint c; meillo@392: int incomment = 0; meillo@0: meillo@392: while ((c = fgetc(in)) != EOF) { meillo@392: if (incomment) { meillo@392: /* eat until end of line */ meillo@392: if (c == '\n') { meillo@392: incomment = 0; meillo@392: continue; meillo@392: } else { meillo@392: continue; meillo@392: } meillo@392: } else { meillo@392: /* eat whitespace and watch for comments */ meillo@392: if (isspace(c)) { meillo@392: continue; meillo@392: } else if (c == '#') { meillo@392: incomment = 1; meillo@392: continue; meillo@392: } else { meillo@392: /* found something (that's not our business) */ meillo@392: ungetc(c, in); meillo@392: return TRUE; meillo@392: } meillo@10: } meillo@10: } meillo@392: return FALSE; meillo@0: } meillo@0: meillo@10: static gboolean meillo@366: eat_spaces(FILE *in) meillo@0: { meillo@10: gint c; meillo@10: meillo@392: while ((c = fgetc(in)) != EOF) { meillo@392: if (!isspace(c)) { meillo@392: ungetc(c, in); meillo@392: return TRUE; meillo@392: } meillo@28: } meillo@392: return FALSE; meillo@0: } meillo@0: meillo@10: static gboolean meillo@366: read_lval(FILE *in, gchar *buf, gint size) meillo@0: { meillo@10: gint c; meillo@10: gchar *ptr = buf; meillo@0: meillo@333: DEBUG(9) fprintf(stderr, "read_lval()\n"); meillo@392: if (!eat_spaces(in)) { meillo@10: return FALSE; meillo@392: } meillo@0: meillo@333: DEBUG(9) fprintf(stderr, "read_lval() 2\n"); meillo@392: while (1) { meillo@402: c = fgetc(in); meillo@402: if (c == EOF) { meillo@392: fprintf(stderr, "unexpected EOF after %s\n", buf); meillo@392: return FALSE; meillo@392: } meillo@392: if (ptr >= buf+size-1) { meillo@392: fprintf(stderr, "lval too long\n"); meillo@392: break; meillo@392: } meillo@392: if (!isalnum(c) && c != '_' && c != '-' && c != '.') { meillo@392: break; meillo@392: } meillo@392: *ptr++ = c; meillo@10: } meillo@14: *ptr = '\0'; meillo@402: g_strstrip(buf); meillo@10: ungetc(c, in); meillo@10: eat_spaces(in); meillo@333: DEBUG(9) fprintf(stderr, "lval = %s\n", buf); meillo@392: return *buf != '\0'; meillo@0: } meillo@0: meillo@10: static gboolean meillo@366: read_rval(FILE *in, gchar *buf, gint size) meillo@0: { meillo@10: gint c; meillo@10: gchar *ptr = buf; meillo@0: meillo@333: DEBUG(9) fprintf(stderr, "read_rval()\n"); meillo@392: if (!eat_spaces(in)) { meillo@10: return FALSE; meillo@392: } meillo@10: meillo@10: c = fgetc(in); meillo@394: if (c != '"') { meillo@394: /* unquoted rval */ meillo@394: ungetc(c, in); meillo@394: while ((c = fgetc(in)) != EOF) { meillo@394: if (ptr >= buf+size-1) { meillo@394: /* rval too long */ meillo@394: break; meillo@394: } meillo@394: if (!isalnum(c) && c != '_' && c != '-' && meillo@394: c != '.' && c != '/' && c != '@' && meillo@394: c != ';' && c != ':') { meillo@394: break; meillo@394: } meillo@394: *ptr++ = c; meillo@10: } meillo@14: *ptr = '\0'; meillo@10: ungetc(c, in); meillo@10: } else { meillo@394: /* quoted rval */ meillo@10: gboolean escape = FALSE; meillo@394: while ((c = fgetc(in)) != EOF) { meillo@394: if (ptr >= buf+size-1) { meillo@394: /* rval too long */ meillo@394: break; meillo@10: } meillo@394: if (!escape && c == '"') { meillo@394: break; meillo@394: } meillo@394: if (!escape && c == '\\') { meillo@394: escape = TRUE; meillo@394: continue; meillo@394: } meillo@394: *ptr++ = c; meillo@394: escape = FALSE; meillo@10: } meillo@14: *ptr = '\0'; meillo@0: } meillo@402: g_strstrip(buf); meillo@333: DEBUG(9) fprintf(stderr, "rval = %s\n", buf); meillo@394: /* eat trailing of line */ meillo@394: while ((c = fgetc(in)) != EOF && c != '\n') { meillo@394: continue; meillo@394: } meillo@10: meillo@10: return TRUE; meillo@0: } meillo@0: meillo@10: static gboolean meillo@366: read_statement(FILE *in, gchar *lval, gint lsize, gchar *rval, gint rsize) meillo@0: { meillo@10: gint c; meillo@0: meillo@333: DEBUG(9) fprintf(stderr, "read_statement()\n"); meillo@0: meillo@10: /* eat comments and empty lines: */ meillo@393: if (!eat_comments(in)) { meillo@10: return FALSE; meillo@393: } meillo@28: if (!read_lval(in, lval, lsize)) { meillo@28: return FALSE; meillo@28: } meillo@411: g_strstrip(lval); meillo@411: DEBUG(9) fprintf(stderr, " lval = `%s'\n", lval); meillo@393: if ((c = fgetc(in) != '=')) { meillo@393: fprintf(stderr, "'=' expected after %s, char was '%c'\n", meillo@393: lval, c); meillo@10: } meillo@393: if (!read_rval(in, rval, rsize)) { meillo@393: return FALSE; meillo@393: } meillo@411: g_strstrip(rval); meillo@411: DEBUG(9) fprintf(stderr, " rval = `%s'\n", rval); meillo@393: return TRUE; meillo@0: } meillo@0: meillo@10: gboolean meillo@366: read_conf(gchar *filename) meillo@0: { meillo@10: FILE *in; meillo@393: gchar lval[256], rval[2048]; meillo@393: GList *listen_addrs_tmp = NULL; meillo@0: meillo@10: conf.do_relay = TRUE; meillo@244: conf.localpartcmp = strcmp; meillo@10: conf.max_defer_time = 86400 * 4; /* 4 days */ meillo@120: conf.max_msg_size = 0; /* no limit on msg size */ meillo@421: conf.lock_dir = LOCK_DIR; meillo@151: conf.spool_dir = SPOOL_DIR; meillo@152: conf.mail_dir = "/var/mail"; meillo@0: meillo@393: if (!(in = fopen(filename, "r"))) { meillo@393: logwrite(LOG_ALERT, "could not open config file %s: %s\n", meillo@393: filename, strerror(errno)); meillo@28: return FALSE; meillo@28: } meillo@28: meillo@392: while (read_statement(in, lval, sizeof lval, rval, sizeof rval)) { meillo@333: DEBUG(9) fprintf(stderr,"read_conf(): lval=%s\n", lval); meillo@393: if (strcmp(lval, "debug_level")==0) { meillo@28: conf.debug_level = atoi(rval); meillo@393: } else if (strcmp(lval, "run_as_user")==0) { meillo@393: if (!conf.run_as_user) { meillo@393: /* you should not be able to reset that flag */ meillo@28: conf.run_as_user = parse_boolean(rval); meillo@393: } meillo@393: } else if (strcmp(lval, "use_syslog")==0) { meillo@28: conf.use_syslog = parse_boolean(rval); meillo@393: } else if (strcmp(lval, "mail_dir")==0) { meillo@28: conf.mail_dir = g_strdup(rval); meillo@393: } else if (strcmp(lval, "lock_dir")==0) { meillo@28: conf.lock_dir = g_strdup(rval); meillo@393: } else if (strcmp(lval, "spool_dir")==0) { meillo@28: conf.spool_dir = g_strdup(rval); meillo@393: } else if (strcmp(lval, "log_dir")==0) { meillo@28: conf.log_dir = g_strdup(rval); meillo@393: } else if (strcmp(lval, "host_name")==0) { meillo@393: if (rval[0] != '/') { meillo@28: conf.host_name = g_strdup(rval); meillo@393: } else { meillo@28: char buf[256]; meillo@28: FILE *fptr = fopen(rval, "rt"); meillo@307: if (!fptr) { meillo@393: logwrite(LOG_ALERT, "could not open " meillo@393: "%s: %s\n", rval, meillo@393: strerror(errno)); meillo@28: return FALSE; meillo@10: } meillo@393: fgets(buf, sizeof buf, fptr); meillo@393: g_strstrip(buf); meillo@28: conf.host_name = g_strdup(buf); meillo@28: fclose(fptr); meillo@28: } meillo@393: } else if (strcmp(lval, "local_hosts")==0) { meillo@392: conf.local_hosts = parse_list(rval, TRUE); meillo@393: } else if (strcmp(lval, "local_addresses")==0) { meillo@28: conf.local_addresses = parse_list(rval, TRUE); meillo@393: } else if (strcmp(lval, "not_local_addresses")==0) { meillo@28: conf.not_local_addresses = parse_list(rval, TRUE); meillo@393: } else if (strcmp(lval, "do_save_envelope_to")==0) { meillo@28: conf.do_save_envelope_to = parse_boolean(rval); meillo@393: } else if (strcmp(lval, "defer_all")==0) { meillo@28: conf.defer_all = parse_boolean(rval); meillo@393: } else if (strcmp(lval, "do_relay")==0) { meillo@28: conf.do_relay = parse_boolean(rval); meillo@393: } else if (strcmp(lval, "alias_file")==0) { meillo@28: conf.alias_file = g_strdup(rval); meillo@393: } else if (strcmp(lval, "globalias_file")==0) { meillo@387: conf.globalias_file = g_strdup(rval); meillo@393: } else if (strcmp(lval, "caseless_matching")==0) { meillo@393: conf.localpartcmp = parse_boolean(rval) ? meillo@393: strcasecmp : strcmp; meillo@393: } else if (strcmp(lval, "mbox_default")==0) { meillo@28: conf.mbox_default = g_strdup(rval); meillo@393: } else if (strcmp(lval, "mbox_users")==0) { meillo@28: conf.mbox_users = parse_list(rval, TRUE); meillo@393: } else if (strcmp(lval, "mda_users")==0) { meillo@28: conf.mda_users = parse_list(rval, TRUE); meillo@393: } else if (strcmp(lval, "mda")==0) { meillo@28: conf.mda = g_strdup(rval); meillo@393: } else if (strcmp(lval, "mda_fromline")==0) { meillo@28: conf.mda_fromline = parse_boolean(rval); meillo@393: } else if (strcmp(lval, "mda_fromhack")==0) { meillo@28: conf.mda_fromhack = parse_boolean(rval); meillo@393: } else if (strcmp(lval, "pipe_fromline")==0) { meillo@28: conf.pipe_fromline = parse_boolean(rval); meillo@393: } else if (strcmp(lval, "pipe_fromhack")==0) { meillo@28: conf.pipe_fromhack = parse_boolean(rval); meillo@393: } else if (strcmp(lval, "listen_addresses")==0) { meillo@393: listen_addrs_tmp = parse_list(rval, TRUE); meillo@393: } else if (strncmp(lval, "query_routes.", 13)==0) { meillo@28: GList *file_list = parse_list(rval, FALSE); meillo@354: table_pair *pair = create_pair(lval+13, file_list); meillo@393: conf.query_routes = g_list_append(conf.query_routes, meillo@393: pair); meillo@393: } else if (strcmp(lval, "permanent_routes")==0) { meillo@354: conf.perma_routes = parse_list(rval, FALSE); meillo@393: } else if (strcmp(lval, "online_query")==0) { meillo@310: conf.online_query = g_strdup(rval); meillo@393: } else if (strcmp(lval, "do_queue")==0) { meillo@28: conf.do_queue = parse_boolean(rval); meillo@393: } else if (strcmp(lval, "errmsg_file")==0) { meillo@28: conf.errmsg_file = g_strdup(rval); meillo@393: } else if (strcmp(lval, "warnmsg_file")==0) { meillo@28: conf.warnmsg_file = g_strdup(rval); meillo@393: } else if (strcmp(lval, "warn_intervals")==0) { meillo@392: conf.warn_intervals = parse_list(rval, TRUE); meillo@393: } else if (strcmp(lval, "max_defer_time")==0) { meillo@254: gint ival = time_interval(rval); meillo@393: if (ival < 0) { meillo@393: logwrite(LOG_WARNING, "invalid time interval " meillo@393: "for 'max_defer_time': %s\n", meillo@393: rval); meillo@393: } else { meillo@28: conf.max_defer_time = ival; meillo@393: } meillo@393: } else if (strcmp(lval, "log_user")==0) { meillo@28: conf.log_user = g_strdup(rval); meillo@393: } else if(strcmp(lval, "max_msg_size")==0) { meillo@117: conf.max_msg_size = atol(rval); meillo@393: DEBUG(9) fprintf(stderr, meillo@393: "rval=%s, conf.max_msg_size=%ld\n", meillo@117: rval, conf.max_msg_size); meillo@393: } else { meillo@393: logwrite(LOG_WARNING, "var '%s' unknown: ignored\n", meillo@393: lval); meillo@117: } meillo@28: } meillo@28: fclose(in); meillo@0: meillo@156: if (!conf.host_name) { meillo@393: logwrite(LOG_ALERT, "`host_name' MUST be set in " meillo@393: "masqmail.conf. See man page\n"); meillo@156: return FALSE; meillo@156: } meillo@393: if (!conf.errmsg_file) { meillo@28: conf.errmsg_file = g_strdup(DATA_DIR "/tpl/failmsg.tpl"); meillo@393: } meillo@393: if (!conf.warnmsg_file) { meillo@28: conf.warnmsg_file = g_strdup(DATA_DIR "/tpl/warnmsg.tpl"); meillo@393: } meillo@393: if (!conf.mbox_default) { meillo@28: conf.mbox_default = g_strdup("mbox"); meillo@393: } meillo@393: if (!conf.warn_intervals) { meillo@392: conf.warn_intervals = parse_list("1h;4h;8h;1d;2d;3d", TRUE); meillo@393: } meillo@157: if (!conf.local_hosts) { meillo@366: char *shortname = strdup(conf.host_name); meillo@366: char *p = strchr(shortname, '.'); meillo@157: if (p) { meillo@157: *p = '\0'; meillo@157: } meillo@392: /* don't care if shortname and conf.host_name are the same */ meillo@392: char *local_hosts_str = g_strdup_printf("localhost;%s;%s", meillo@392: shortname, conf.host_name); meillo@392: conf.local_hosts = parse_list(local_hosts_str, TRUE); meillo@157: free(shortname); meillo@157: free(local_hosts_str); meillo@157: } meillo@393: if (!listen_addrs_tmp) { meillo@393: conf.listen_addresses = g_list_append(NULL, meillo@412: parse_interface(strdup("localhost"), 25)); meillo@393: } else { meillo@393: GList *node; meillo@157: meillo@393: foreach(listen_addrs_tmp, node) { meillo@393: conf.listen_addresses = meillo@393: g_list_append(conf.listen_addresses, meillo@393: parse_interface((gchar *) node->data, meillo@393: 25)); meillo@393: g_free(node->data); meillo@393: } meillo@393: g_list_free(listen_addrs_tmp); meillo@393: } meillo@157: meillo@28: return TRUE; meillo@0: } meillo@0: meillo@10: connect_route* meillo@366: read_route(gchar *filename, gboolean is_perma) meillo@0: { meillo@10: FILE *in; meillo@393: connect_route *route; meillo@393: gchar lval[256], rval[2048]; meillo@0: meillo@10: DEBUG(5) debugf("read_route, filename = %s\n", filename); meillo@0: meillo@393: if (!(in = fopen(filename, "r"))) { meillo@393: logwrite(LOG_ALERT, "could not open route file %s: %s\n", meillo@393: filename, strerror(errno)); meillo@28: return NULL; meillo@28: } meillo@0: meillo@393: route = g_malloc(sizeof(connect_route)); meillo@393: memset(route, 0, sizeof(connect_route)); meillo@393: route->filename = g_strdup(filename); meillo@393: route->name = route->filename; /* quick hack */ meillo@393: route->expand_h_sender_address = TRUE; meillo@393: route->is_perma = is_perma; meillo@393: route->do_pipelining = TRUE; meillo@393: meillo@392: while (read_statement(in, lval, sizeof lval, rval, sizeof rval)) { meillo@393: if (strcmp(lval, "mail_host")==0) { meillo@178: route->mail_host = parse_interface(rval, 25); meillo@393: } else if (strcmp(lval, "helo_name")==0) { meillo@28: route->helo_name = g_strdup(rval); meillo@393: } else if (strcmp(lval, "wrapper")==0) { meillo@28: route->wrapper = g_strdup(rval); meillo@393: } else if (strcmp(lval, "connect_error_fail")==0) { meillo@28: route->connect_error_fail = parse_boolean(rval); meillo@393: } else if (strcmp(lval, "do_correct_helo")==0) { meillo@28: route->do_correct_helo = parse_boolean(rval); meillo@393: } else if (strcmp(lval, "instant_helo")==0) { meillo@222: route->instant_helo = parse_boolean(rval); meillo@393: } else if (strcmp(lval, "do_pipelining")==0) { meillo@28: route->do_pipelining = parse_boolean(rval); meillo@317: meillo@393: } else if (strcmp(lval, "allowed_senders")==0) { meillo@392: route->allowed_senders = parse_address_glob_list(rval); meillo@393: } else if (strcmp(lval, "denied_senders")==0) { meillo@392: route->denied_senders = parse_address_glob_list(rval); meillo@393: } else if (strcmp(lval, "allowed_recipients")==0) { meillo@392: route->allowed_recipients = parse_address_glob_list(rval); meillo@393: } else if (strcmp(lval, "denied_recipients")==0) { meillo@392: route->denied_recipients = parse_address_glob_list(rval); meillo@429: } else if (strcmp(lval, "allowed_from_hdrs")==0) { meillo@429: route->allowed_from_hdrs = parse_address_glob_list(rval); meillo@429: } else if (strcmp(lval, "denied_from_hdrs")==0) { meillo@429: route->denied_from_hdrs = parse_address_glob_list(rval); meillo@317: meillo@393: } else if (strcmp(lval, "set_h_from_domain")==0) { meillo@28: route->set_h_from_domain = g_strdup(rval); meillo@393: } else if (strcmp(lval, "set_h_reply_to_domain")==0) { meillo@28: route->set_h_reply_to_domain = g_strdup(rval); meillo@393: } else if (strcmp(lval, "set_return_path_domain")==0) { meillo@28: route->set_return_path_domain = g_strdup(rval); meillo@393: } else if (strcmp(lval, "map_return_path_addresses")==0) { meillo@28: GList *node, *list; meillo@10: meillo@28: list = parse_list(rval, TRUE); meillo@28: foreach(list, node) { meillo@28: gchar *item = (gchar *) (node->data); meillo@28: table_pair *pair = parse_table_pair(item, ':'); meillo@393: address *addr = create_address( meillo@393: (gchar *) (pair->value), TRUE); meillo@28: g_free(pair->value); meillo@28: pair->value = (gpointer *) addr; meillo@402: route->map_return_path_addresses = g_list_append(route->map_return_path_addresses, pair); meillo@28: g_free(item); meillo@28: } meillo@28: g_list_free(list); meillo@393: } else if (strcmp(lval, "map_h_from_addresses")==0) { meillo@28: GList *list, *node; meillo@10: meillo@28: list = parse_list(rval, TRUE); meillo@28: foreach(list, node) { meillo@28: gchar *item = (gchar *) (node->data); meillo@28: table_pair *pair = parse_table_pair(item, ':'); meillo@28: route->map_h_from_addresses = g_list_append(route->map_h_from_addresses, pair); meillo@28: g_free(item); meillo@28: } meillo@28: g_list_free(list); meillo@393: } else if (strcmp(lval, "map_h_reply_to_addresses")==0) { meillo@28: GList *list, *node; meillo@10: meillo@28: list = parse_list(rval, TRUE); meillo@28: foreach(list, node) { meillo@28: gchar *item = (gchar *) (node->data); meillo@28: table_pair *pair = parse_table_pair(item, ':'); meillo@28: route->map_h_reply_to_addresses = g_list_append(route->map_h_reply_to_addresses, pair); meillo@28: g_free(item); meillo@10: } meillo@28: g_list_free(list); meillo@393: } else if (strcmp(lval, "map_h_mail_followup_to_addresses")==0) { meillo@28: GList *list, *node; meillo@28: meillo@28: list = parse_list(rval, TRUE); meillo@28: foreach(list, node) { meillo@28: gchar *item = (gchar *) (node->data); meillo@28: table_pair *pair = parse_table_pair(item, ':'); meillo@28: route->map_h_mail_followup_to_addresses = g_list_append(route->map_h_mail_followup_to_addresses, pair); meillo@28: g_free(item); meillo@28: } meillo@28: g_list_free(list); meillo@393: } else if (strcmp(lval, "expand_h_sender_domain")==0) { meillo@28: route->expand_h_sender_domain = parse_boolean(rval); meillo@393: } else if (strcmp(lval, "expand_h_sender_address")==0) { meillo@28: route->expand_h_sender_address = parse_boolean(rval); meillo@393: } else if (strcmp(lval, "resolve_list")==0) { meillo@28: route->resolve_list = parse_resolve_list(rval); meillo@393: } else if (strcmp(lval, "do_ssl")==0) { meillo@28: /* we ignore this. This option is used by sqilconf */ meillo@28: ; meillo@10: #ifdef ENABLE_AUTH meillo@393: } else if (strcmp(lval, "auth_name")==0) { meillo@28: route->auth_name = g_strdup(rval); meillo@393: } else if (strcmp(lval, "auth_login")==0) { meillo@28: route->auth_login = g_strdup(rval); meillo@393: } else if (strcmp(lval, "auth_secret")==0) { meillo@28: route->auth_secret = g_strdup(rval); meillo@10: #else meillo@393: } else if ((strcmp(lval, "auth_name")==0) || meillo@393: (strcmp(lval, "auth_login")==0) || meillo@393: (strcmp(lval, "auth_secret")==0)) { meillo@393: logwrite(LOG_WARNING, "%s ignored: not compiled with " meillo@393: "auth support.\n", lval); meillo@28: } meillo@10: #endif meillo@393: } else if (strcmp(lval, "pipe")==0) { meillo@28: route->pipe = g_strdup(rval); meillo@393: } else if (strcmp(lval, "pipe_fromline")==0) { meillo@28: route->pipe_fromline = parse_boolean(rval); meillo@393: } else if (strcmp(lval, "pipe_fromhack")==0) { meillo@28: route->pipe_fromhack = parse_boolean(rval); meillo@393: } else if (strcmp(lval, "last_route")==0) { meillo@28: route->last_route = parse_boolean(rval); meillo@393: } else { meillo@393: logwrite(LOG_WARNING, "var '%s' unknown: ignored\n", meillo@393: lval); meillo@393: } meillo@28: } meillo@28: meillo@319: if (!route->resolve_list) { meillo@28: #ifdef ENABLE_RESOLVER meillo@393: route->resolve_list = g_list_append(route->resolve_list, meillo@393: resolve_dns_mx); meillo@393: route->resolve_list = g_list_append(route->resolve_list, meillo@393: resolve_dns_a); meillo@28: #endif meillo@393: route->resolve_list = g_list_append(route->resolve_list, meillo@393: resolve_byname); meillo@28: } meillo@28: fclose(in); meillo@10: meillo@393: /* warn user about mis-configurations: */ meillo@393: if (route->map_h_from_addresses && route->set_h_from_domain) { meillo@393: logwrite(LOG_WARNING, "'map_h_from_addresses' overrides " meillo@393: "'set_h_from_domain'\n"); meillo@28: g_free(route->set_h_from_domain); meillo@28: route->set_h_from_domain = NULL; meillo@28: } meillo@393: if (route->map_h_reply_to_addresses && route->set_h_reply_to_domain) { meillo@393: logwrite(LOG_WARNING, "'map_h_reply_to_addresses' overrides " meillo@393: "'set_h_reply_to_domain'\n"); meillo@28: g_free(route->set_h_reply_to_domain); meillo@28: route->set_h_reply_to_domain = NULL; meillo@10: } meillo@10: meillo@10: return route; meillo@10: } meillo@10: meillo@10: static void meillo@366: _g_list_free_all(GList *list) meillo@10: { meillo@10: GList *node; meillo@393: if (!list) { meillo@393: return; meillo@10: } meillo@393: foreach(list, node) { meillo@393: g_free(node->data); meillo@393: } meillo@393: g_list_free(list); meillo@10: } meillo@10: meillo@10: void meillo@366: destroy_route(connect_route *r) meillo@10: { meillo@393: if (r->filename) { meillo@10: g_free(r->filename); meillo@393: } meillo@10: if (r->mail_host) { meillo@10: g_free(r->mail_host->address); meillo@10: g_free(r->mail_host); meillo@10: } meillo@393: if (r->wrapper) { meillo@10: g_free(r->wrapper); meillo@393: } meillo@393: if (r->helo_name) { meillo@10: g_free(r->helo_name); meillo@393: } meillo@317: _g_list_free_all(r->allowed_senders); meillo@317: _g_list_free_all(r->denied_senders); meillo@317: _g_list_free_all(r->allowed_recipients); meillo@317: _g_list_free_all(r->denied_recipients); meillo@393: if (r->set_h_from_domain) { meillo@10: g_free(r->set_h_from_domain); meillo@393: } meillo@393: if (r->set_h_reply_to_domain) { meillo@10: g_free(r->set_h_reply_to_domain); meillo@393: } meillo@393: if (r->set_return_path_domain) { meillo@10: g_free(r->set_return_path_domain); meillo@393: } meillo@393: if (r->map_h_reply_to_addresses) { meillo@10: destroy_table(r->map_h_reply_to_addresses); meillo@393: } meillo@393: if (r->resolve_list) { meillo@10: g_list_free(r->resolve_list); meillo@393: } meillo@10: #ifdef ENABLE_AUTH meillo@393: if (r->auth_name) { meillo@10: g_free(r->auth_name); meillo@393: } meillo@393: if (r->auth_login) { meillo@10: g_free(r->auth_login); meillo@393: } meillo@393: if (r->auth_secret) { meillo@10: g_free(r->auth_secret); meillo@393: } meillo@10: #endif meillo@393: if (r->pipe) { meillo@10: g_free(r->pipe); meillo@393: } meillo@10: g_free(r); meillo@10: } meillo@10: meillo@10: GList* meillo@366: read_route_list(GList *rf_list, gboolean is_perma) meillo@10: { meillo@10: GList *list = NULL; meillo@10: GList *node; meillo@10: uid_t saved_uid, saved_gid; meillo@10: meillo@10: if (!conf.run_as_user) { meillo@10: set_euidgid(0, 0, &saved_uid, &saved_gid); meillo@10: } meillo@10: foreach(rf_list, node) { meillo@10: gchar *fname = (gchar *) (node->data); meillo@354: connect_route *route = read_route(fname, is_perma); meillo@393: if (route) { meillo@10: list = g_list_append(list, route); meillo@393: } else { meillo@393: logwrite(LOG_ALERT, "could not read route " meillo@393: "configuration %s\n", fname); meillo@393: } meillo@10: } meillo@10: /* set uid and gid back */ meillo@10: if (!conf.run_as_user) { meillo@10: set_euidgid(saved_uid, saved_gid, NULL, NULL); meillo@10: } meillo@10: return list; meillo@10: } meillo@10: meillo@10: void meillo@366: destroy_route_list(GList *list) meillo@10: { meillo@10: GList *node; meillo@10: meillo@10: foreach(list, node) { meillo@10: connect_route *route = (connect_route *) (node->data); meillo@10: destroy_route(route); meillo@0: } meillo@0: g_list_free(list); meillo@0: }