diff options
author | Eric Faurot <eric@cvs.openbsd.org> | 2012-10-10 18:02:38 +0000 |
---|---|---|
committer | Eric Faurot <eric@cvs.openbsd.org> | 2012-10-10 18:02:38 +0000 |
commit | d206b820072d5c6650e115823681678f37232cc2 (patch) | |
tree | e42959ad66167230e37adae97acad7db9617c808 /usr.sbin/smtpd/lka_session.c | |
parent | 72dffe3754f92adefba1fd73c49c423ebbed554a (diff) |
For each alias node, mark if it has been expanded from an alias map or
from a .forward file. Local deliveries for files and filters expanded
from an alias map are run as user _smtpd.
issue reported by tood@
ok gilles@ todd@
Diffstat (limited to 'usr.sbin/smtpd/lka_session.c')
-rw-r--r-- | usr.sbin/smtpd/lka_session.c | 51 |
1 files changed, 32 insertions, 19 deletions
diff --git a/usr.sbin/smtpd/lka_session.c b/usr.sbin/smtpd/lka_session.c index 1c00b983162..beee051f798 100644 --- a/usr.sbin/smtpd/lka_session.c +++ b/usr.sbin/smtpd/lka_session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lka_session.c,v 1.41 2012/10/09 21:33:38 eric Exp $ */ +/* $OpenBSD: lka_session.c,v 1.42 2012/10/10 18:02:37 eric Exp $ */ /* * Copyright (c) 2011 Gilles Chehade <gilles@openbsd.org> @@ -126,6 +126,7 @@ lka_session_forward_reply(struct forward_req *fwreq, int fd) /* expand for the current user and rule */ lks->expand.rule = rule; lks->expand.parent = xn; + lks->expand.alias = 0; if (forwards_get(fd, &lks->expand) == 0) { /* no aliases */ lks->ss.code = 530; @@ -231,6 +232,7 @@ lka_expand(struct lka_session *lks, struct rule *rule, struct expandnode *xn) /* expand */ lks->expand.rule = rule; lks->expand.parent = xn; + lks->expand.alias = 1; if (aliases_virtual_get(rule->r_condition.c_map, &lks->expand, &xn->u.mailaddr) == 0) { log_debug("lka_expand: no aliases for virtual"); @@ -241,6 +243,7 @@ lka_expand(struct lka_session *lks, struct rule *rule, struct expandnode *xn) else { lks->expand.rule = rule; lks->expand.parent = xn; + lks->expand.alias = 1; node.type = EXPAND_USERNAME; mailaddr_to_username(&xn->u.mailaddr, node.u.user, sizeof node.u.user); @@ -260,6 +263,7 @@ lka_expand(struct lka_session *lks, struct rule *rule, struct expandnode *xn) /* expand aliases with the given rule */ lks->expand.rule = rule; lks->expand.parent = xn; + lks->expand.alias = 1; if (rule->r_amap && aliases_get(rule->r_amap, &lks->expand, xn->u.user)) break; @@ -294,6 +298,18 @@ lka_expand(struct lka_session *lks, struct rule *rule, struct expandnode *xn) } } +static struct expandnode * +lka_find_ancestor(struct expandnode *xn, enum expand_type type) +{ + while(xn && (xn->type != type)) + xn = xn->parent; + if (xn == NULL) { + log_warnx("lka_find_ancestor: no ancestors of type %i", type); + fatalx(NULL); + } + return (xn); +} + static void lka_submit(struct lka_session *lks, struct rule *rule, struct expandnode *xn) { @@ -307,11 +323,11 @@ lka_submit(struct lka_session *lks, struct rule *rule, struct expandnode *xn) switch (rule->r_action) { case A_RELAY: case A_RELAYVIA: - ep->type = D_MTA; - ep->agent.mta.relay = rule->r_value.relayhost; if (xn->type != EXPAND_ADDRESS) fatalx("lka_deliver: expect address"); + ep->type = D_MTA; ep->dest = xn->u.mailaddr; + ep->agent.mta.relay = rule->r_value.relayhost; if (rule->r_as && rule->r_as->user[0]) strlcpy(ep->sender.user, rule->r_as->user, sizeof ep->sender.user); @@ -324,23 +340,19 @@ lka_submit(struct lka_session *lks, struct rule *rule, struct expandnode *xn) case A_FILENAME: case A_MDA: ep->type = D_MDA; + ep->dest = lka_find_ancestor(xn, EXPAND_ADDRESS)->u.mailaddr; /* set username */ - xn2 = xn; - while(xn2 && (xn2->type != EXPAND_USERNAME)) - xn2 = xn2->parent; - if (xn2 == NULL) - fatalx("no user in node ancestry"); - (void)strlcpy(ep->agent.mda.user, xn2->u.user, - sizeof (ep->agent.mda.user)); - - /* set dest */ - xn2 = xn; - while(xn2 && (xn2->type != EXPAND_ADDRESS)) - xn2 = xn2->parent; - if (xn2 == NULL) - fatalx("no address in node ancestry"); - ep->dest = xn2->u.mailaddr; + if ((xn->type == EXPAND_FILTER || xn->type == EXPAND_FILENAME) + && xn->alias) { + strlcpy(ep->agent.mda.user, SMTPD_USER, + sizeof (ep->agent.mda.user)); + } + else { + xn2 = lka_find_ancestor(xn, EXPAND_USERNAME); + strlcpy(ep->agent.mda.user, xn2->u.user, + sizeof (ep->agent.mda.user)); + } if (xn->type == EXPAND_FILENAME) { ep->agent.mda.method = A_FILENAME; @@ -363,7 +375,8 @@ lka_submit(struct lka_session *lks, struct rule *rule, struct expandnode *xn) strlcat(ep->agent.mda.buffer, tag, sizeof (ep->agent.mda.buffer)); } - } else + } + else fatalx("lka_deliver: bad node type"); lka_expand_format(ep->agent.mda.buffer, |