summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.sbin/smtpd/expand.c3
-rw-r--r--usr.sbin/smtpd/lka_session.c51
-rw-r--r--usr.sbin/smtpd/smtpd.h4
3 files changed, 37 insertions, 21 deletions
diff --git a/usr.sbin/smtpd/expand.c b/usr.sbin/smtpd/expand.c
index 4900157be70..b2b2113c8e4 100644
--- a/usr.sbin/smtpd/expand.c
+++ b/usr.sbin/smtpd/expand.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: expand.c,v 1.17 2012/09/27 18:57:25 eric Exp $ */
+/* $OpenBSD: expand.c,v 1.18 2012/10/10 18:02:37 eric Exp $ */
/*
* Copyright (c) 2009 Gilles Chehade <gilles@openbsd.org>
@@ -55,6 +55,7 @@ expand_insert(struct expand *expand, struct expandnode *node)
xn = xmemdup(node, sizeof *xn, "expand_insert");
xn->rule = expand->rule;
xn->parent = expand->parent;
+ xn->alias = expand->alias;
if (xn->parent)
xn->depth = xn->parent->depth + 1;
else
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,
diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h
index fedc1b5b0f7..eb2953ec413 100644
--- a/usr.sbin/smtpd/smtpd.h
+++ b/usr.sbin/smtpd/smtpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtpd.h,v 1.382 2012/10/09 20:33:02 gilles Exp $ */
+/* $OpenBSD: smtpd.h,v 1.383 2012/10/10 18:02:37 eric Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -367,6 +367,7 @@ struct expandnode {
TAILQ_ENTRY(expandnode) tq_entry;
enum expand_type type;
int sameuser;
+ int alias;
struct rule *rule;
struct expandnode *parent;
unsigned int depth;
@@ -384,6 +385,7 @@ struct expandnode {
struct expand {
RB_HEAD(expandtree, expandnode) tree;
TAILQ_HEAD(xnodes, expandnode) *queue;
+ int alias;
struct rule *rule;
struct expandnode *parent;
};