diff options
author | Gilles Chehade <gilles@cvs.openbsd.org> | 2009-01-07 00:26:31 +0000 |
---|---|---|
committer | Gilles Chehade <gilles@cvs.openbsd.org> | 2009-01-07 00:26:31 +0000 |
commit | 6a6816a1f3e5d7de10de80d1dcaf5cf964f400ba (patch) | |
tree | ef72e6c36aaa69ec73225265935590a73a02c029 /usr.sbin/smtpd | |
parent | 4d7169faddcbb9191d6921755ec0f97468b0bf7b (diff) |
- when performing aliases expansion, do not forget to set an action to each
expanded envelope, orelse they will use the default action and be passed to
MTA no matter if recipient is local or not.
bug reported by Nicholas Marriott <nicholas.marriott@gmail.com>,
fixed by me and okayd by jacekm@, collaborative work ;-)
Diffstat (limited to 'usr.sbin/smtpd')
-rw-r--r-- | usr.sbin/smtpd/aliases.c | 14 | ||||
-rw-r--r-- | usr.sbin/smtpd/forward.c | 6 | ||||
-rw-r--r-- | usr.sbin/smtpd/lka.c | 48 |
3 files changed, 57 insertions, 11 deletions
diff --git a/usr.sbin/smtpd/aliases.c b/usr.sbin/smtpd/aliases.c index 9d58c0d7740..4301549657a 100644 --- a/usr.sbin/smtpd/aliases.c +++ b/usr.sbin/smtpd/aliases.c @@ -1,4 +1,4 @@ -/* $OpenBSD: aliases.c,v 1.13 2009/01/01 16:15:47 jacekm Exp $ */ +/* $OpenBSD: aliases.c,v 1.14 2009/01/07 00:26:30 gilles Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -77,7 +77,7 @@ aliases_get(struct smtpd *env, struct aliaseslist *aliases, char *username) DBT key; DBT val; DB *aliasesdb; - size_t nbaliases; + size_t nbaliases, nbsave; struct alias alias; struct alias *aliasp; struct alias *nextalias; @@ -99,7 +99,7 @@ aliases_get(struct smtpd *env, struct aliaseslist *aliases, char *username) return 0; } - nbaliases = val.size / sizeof(struct alias); + nbsave = nbaliases = val.size / sizeof(struct alias); if (nbaliases == 0) { aliasesdb->close(aliasesdb); return 0; @@ -121,7 +121,7 @@ aliases_get(struct smtpd *env, struct aliaseslist *aliases, char *username) } } while (--nbaliases); aliasesdb->close(aliasesdb); - return 1; + return nbsave; } int @@ -179,7 +179,7 @@ aliases_virtual_get(struct smtpd *env, struct aliaseslist *aliases, DBT key; DBT val; DB *aliasesdb; - size_t nbaliases; + size_t nbaliases, nbsave; struct alias alias; struct alias *aliasp; struct alias *nextalias; @@ -219,7 +219,7 @@ aliases_virtual_get(struct smtpd *env, struct aliaseslist *aliases, } } - nbaliases = val.size / sizeof(struct alias); + nbsave = nbaliases = val.size / sizeof(struct alias); if (nbaliases == 0) { aliasesdb->close(aliasesdb); return 0; @@ -241,7 +241,7 @@ aliases_virtual_get(struct smtpd *env, struct aliaseslist *aliases, } } while (--nbaliases); aliasesdb->close(aliasesdb); - return 1; + return nbsave; } int diff --git a/usr.sbin/smtpd/forward.c b/usr.sbin/smtpd/forward.c index 7613f729940..146e3333d9c 100644 --- a/usr.sbin/smtpd/forward.c +++ b/usr.sbin/smtpd/forward.c @@ -1,4 +1,4 @@ -/* $OpenBSD: forward.c,v 1.8 2009/01/04 00:58:59 gilles Exp $ */ +/* $OpenBSD: forward.c,v 1.9 2009/01/07 00:26:30 gilles Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -45,6 +45,7 @@ forwards_get(struct aliaseslist *aliases, char *username) size_t len; struct stat sb; struct passwd *pw; + size_t nbaliases = 0; pw = getpwnam(username); if (pw == NULL) @@ -99,11 +100,12 @@ forwards_get(struct aliaseslist *aliases, char *username) fatal("calloc"); *aliasp = alias; TAILQ_INSERT_HEAD(aliases, aliasp, entry); + nbaliases++; } free(lbuf); fclose(fp); - return 1; + return nbaliases; bad: log_debug("+ forward file error, probably bad perms/mode"); diff --git a/usr.sbin/smtpd/lka.c b/usr.sbin/smtpd/lka.c index ae51bca8eba..4c0556004d2 100644 --- a/usr.sbin/smtpd/lka.c +++ b/usr.sbin/smtpd/lka.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lka.c,v 1.16 2009/01/06 23:12:28 gilles Exp $ */ +/* $OpenBSD: lka.c,v 1.17 2009/01/07 00:26:30 gilles Exp $ */ /* * Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -63,6 +63,7 @@ int aliases_virtual_get(struct smtpd *, struct aliaseslist *, struct path *); int aliases_virtual_exist(struct smtpd *, struct path *); int lka_resolve_path(struct smtpd *, struct path *); int lka_expand_aliases(struct smtpd *, struct aliaseslist *, struct path *); +void lka_rcpt_action(struct smtpd *, struct path *); void lka_sig_handler(int sig, short event, void *p) @@ -236,7 +237,10 @@ lka_dispatch_mfa(int sig, short event, void *p) message = ss->msg; while ((alias = TAILQ_FIRST(&aliases)) != NULL) { bzero(&message.recipient, sizeof (struct path)); + lka_resolve_alias(&message.recipient, alias); + lka_rcpt_action(env, &message.recipient); + imsg_compose(env->sc_ibufs[PROC_QUEUE], IMSG_QUEUE_SUBMIT_ENVELOPE, 0, 0, -1, &message, sizeof (struct message)); @@ -880,8 +884,8 @@ lka_expand_aliases(struct smtpd *env, struct aliaseslist *aliases, struct path * else if (alias->type == ALIAS_USERNAME) { if (aliases_get(env, aliases, alias->u.username) || forwards_get(aliases, alias->u.username)) { - done = 0; rmalias = alias; + done = 0; } } } @@ -937,3 +941,43 @@ lka_resolve_path(struct smtpd *env, struct path *path) return 1; } + +void +lka_rcpt_action(struct smtpd *env, struct path *path) +{ + struct rule *r; + struct cond *cond; + struct map *map; + struct mapel *me; + + if (path->domain[0] == '\0') + (void)strlcpy(path->domain, "localhost", sizeof (path->domain)); + + TAILQ_FOREACH(r, env->sc_rules, r_entry) { + + TAILQ_FOREACH(cond, &r->r_conditions, c_entry) { + if (cond->c_type == C_ALL) { + path->rule = *r; + return; + } + + if (cond->c_type == C_DOM) { + cond->c_match = map_find(env, cond->c_map); + if (cond->c_match == NULL) + fatal("mfa failed to lookup map."); + + map = cond->c_match; + TAILQ_FOREACH(me, &map->m_contents, me_entry) { + log_debug("trying to match [%s] with [%s]", + path->domain, me->me_key.med_string); + if (hostname_match(path->domain, me->me_key.med_string)) { + path->rule = *r; + return; + } + } + } + } + } + path->rule.r_action = A_RELAY; + return; +} |