aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGilles Chehade <gilles@poolp.org>2013-02-14 13:10:17 +0100
committerGilles Chehade <gilles@poolp.org>2013-02-14 13:10:17 +0100
commit52549e3f4a1c949ded3669c93e1c39b55b928c3e (patch)
tree94a23e5d8360c4a05e9d083c8d0dd3a520e0febc
parentrule->r_users -> rule->r_userbase (diff)
parentremove ambiguity for expandnodes across userbases (diff)
downloadOpenSMTPD-52549e3f4a1c949ded3669c93e1c39b55b928c3e.tar.xz
OpenSMTPD-52549e3f4a1c949ded3669c93e1c39b55b928c3e.zip
Merge branch 'fix_aliases'
-rw-r--r--smtpd/aliases.c28
-rw-r--r--smtpd/expand.c29
-rw-r--r--smtpd/lka_session.c16
-rw-r--r--smtpd/smtpd.h6
4 files changed, 63 insertions, 16 deletions
diff --git a/smtpd/aliases.c b/smtpd/aliases.c
index 002b0be7..adb766a2 100644
--- a/smtpd/aliases.c
+++ b/smtpd/aliases.c
@@ -37,17 +37,21 @@
static int aliases_expand_include(struct expand *, const char *);
int
-aliases_get(struct table *table, struct expand *expand, const char *username)
+aliases_get(struct expand *expand, const char *username)
{
struct expandnode *xn;
char buf[MAX_LOCALPART_SIZE];
size_t nbaliases;
int ret;
struct expand *xp = NULL;
+ struct table *mapping = NULL;
+ struct table *userbase = NULL;
+ mapping = expand->rule->r_mapping;
+ userbase = expand->rule->r_users;
xlowercase(buf, username, sizeof(buf));
- ret = table_lookup(table, buf, K_ALIAS, (void **)&xp);
+ ret = table_lookup(mapping, buf, K_ALIAS, (void **)&xp);
if (ret <= 0)
return ret;
@@ -58,6 +62,8 @@ aliases_get(struct table *table, struct expand *expand, const char *username)
nbaliases += aliases_expand_include(expand,
xn->u.buffer);
else {
+ xn->mapping = mapping;
+ xn->userbase = userbase;
expand_insert(expand, xn);
nbaliases++;
}
@@ -114,8 +120,7 @@ aliases_virtual_check(struct table *table, const struct mailaddr *maddr)
}
int
-aliases_virtual_get(struct table *table, struct expand *expand,
- const struct mailaddr *maddr)
+aliases_virtual_get(struct expand *expand, const struct mailaddr *maddr)
{
struct expandnode *xn;
struct expand *xp;
@@ -123,6 +128,11 @@ aliases_virtual_get(struct table *table, struct expand *expand,
char *pbuf;
int nbaliases;
int ret;
+ struct table *mapping = NULL;
+ struct table *userbase = NULL;
+
+ mapping = expand->rule->r_mapping;
+ userbase = expand->rule->r_users;
if (! bsnprintf(buf, sizeof(buf), "%s@%s", maddr->user,
maddr->domain))
@@ -130,7 +140,7 @@ aliases_virtual_get(struct table *table, struct expand *expand,
xlowercase(buf, buf, sizeof(buf));
/* First, we lookup for full entry: user@domain */
- ret = table_lookup(table, buf, K_ALIAS, (void **)&xp);
+ ret = table_lookup(mapping, buf, K_ALIAS, (void **)&xp);
if (ret < 0)
return (-1);
if (ret)
@@ -139,7 +149,7 @@ aliases_virtual_get(struct table *table, struct expand *expand,
/* Failed ? We lookup for username only */
pbuf = strchr(buf, '@');
*pbuf = '\0';
- ret = table_lookup(table, buf, K_ALIAS, (void **)&xp);
+ ret = table_lookup(mapping, buf, K_ALIAS, (void **)&xp);
if (ret < 0)
return (-1);
if (ret)
@@ -147,14 +157,14 @@ aliases_virtual_get(struct table *table, struct expand *expand,
*pbuf = '@';
/* Failed ? We lookup for catch all for virtual domain */
- ret = table_lookup(table, pbuf, K_ALIAS, (void **)&xp);
+ ret = table_lookup(mapping, pbuf, K_ALIAS, (void **)&xp);
if (ret < 0)
return (-1);
if (ret)
goto expand;
/* Failed ? We lookup for a *global* catch all */
- ret = table_lookup(table, "@", K_ALIAS, (void **)&xp);
+ ret = table_lookup(mapping, "@", K_ALIAS, (void **)&xp);
if (ret <= 0)
return (ret);
@@ -166,6 +176,8 @@ expand:
nbaliases += aliases_expand_include(expand,
xn->u.buffer);
else {
+ xn->mapping = mapping;
+ xn->userbase = userbase;
expand_insert(expand, xn);
nbaliases++;
}
diff --git a/smtpd/expand.c b/smtpd/expand.c
index a82114df..f1704305 100644
--- a/smtpd/expand.c
+++ b/smtpd/expand.c
@@ -114,6 +114,14 @@ expand_cmp(struct expandnode *e1, struct expandnode *e2)
return -1;
if (e1->sameuser > e2->sameuser)
return 1;
+ if (e1->mapping < e2->mapping)
+ return -1;
+ if (e1->mapping > e2->mapping)
+ return 1;
+ if (e1->userbase < e2->userbase)
+ return -1;
+ if (e1->userbase > e2->userbase)
+ return 1;
return memcmp(&e1->u, &e2->u, sizeof(e1->u));
}
@@ -222,8 +230,27 @@ expandnode_info(struct expandnode *e)
if ((value = expandnode_to_text(e)) == NULL)
return NULL;
- if (! bsnprintf(buffer, sizeof buffer, "%s:%s", type, value))
+
+ strlcpy(buffer, type, sizeof buffer);
+ strlcat(buffer, ":", sizeof buffer);
+ if (strlcat(buffer, value, sizeof buffer) >= sizeof buffer)
return NULL;
+ if (e->mapping || e->userbase) {
+ strlcat(buffer, " [", sizeof buffer);
+ if (e->mapping) {
+ strlcat(buffer, "mapping=", sizeof buffer);
+ strlcat(buffer, e->mapping->t_name, sizeof buffer);
+ if (e->userbase)
+ strlcat(buffer, ", ", sizeof buffer);
+
+ }
+ if (e->userbase) {
+ strlcat(buffer, "userbase=", sizeof buffer);
+ strlcat(buffer, e->userbase->t_name, sizeof buffer);
+ }
+ if (strlcat(buffer, "]", sizeof buffer) >= sizeof buffer)
+ return NULL;
+ }
return buffer;
}
diff --git a/smtpd/lka_session.c b/smtpd/lka_session.c
index d725bd74..678dcda6 100644
--- a/smtpd/lka_session.c
+++ b/smtpd/lka_session.c
@@ -129,7 +129,8 @@ lka_session_forward_reply(struct forward_req *fwreq, int fd)
lks->expand.rule = rule;
lks->expand.parent = xn;
lks->expand.alias = 0;
-
+ xn->mapping = rule->r_mapping;
+ xn->userbase = rule->r_users;
/* forwards_get() will close the descriptor no matter what */
if (! forwards_get(fd, &lks->expand)) {
log_trace(TRACE_EXPAND, "expand: temporary "
@@ -243,6 +244,9 @@ lka_expand(struct lka_session *lks, struct rule *rule, struct expandnode *xn)
break;
}
+ xn->mapping = rule->r_mapping;
+ xn->userbase = rule->r_users;
+
if (rule->r_action == A_RELAY || rule->r_action == A_RELAYVIA) {
lka_submit(lks, rule, xn);
}
@@ -251,8 +255,7 @@ lka_expand(struct lka_session *lks, struct rule *rule, struct expandnode *xn)
lks->expand.rule = rule;
lks->expand.parent = xn;
lks->expand.alias = 1;
- r = aliases_virtual_get(rule->r_mapping,
- &lks->expand, &xn->u.mailaddr);
+ r = aliases_virtual_get(&lks->expand, &xn->u.mailaddr);
if (r == -1) {
lks->error = LKA_TEMPFAIL;
log_trace(TRACE_EXPAND, "expand: lka_expand: "
@@ -272,6 +275,8 @@ lka_expand(struct lka_session *lks, struct rule *rule, struct expandnode *xn)
node.type = EXPAND_USERNAME;
mailaddr_to_username(&xn->u.mailaddr, node.u.user,
sizeof node.u.user);
+ node.mapping = rule->r_mapping;
+ node.userbase = rule->r_users;
expand_insert(&lks->expand, &node);
}
break;
@@ -291,9 +296,10 @@ lka_expand(struct lka_session *lks, struct rule *rule, struct expandnode *xn)
lks->expand.rule = rule;
lks->expand.parent = xn;
lks->expand.alias = 1;
+ xn->mapping = rule->r_mapping;
+ xn->userbase = rule->r_users;
if (rule->r_mapping) {
- r = aliases_get(rule->r_mapping, &lks->expand,
- xn->u.user);
+ r = aliases_get(&lks->expand, xn->u.user);
if (r == -1) {
log_trace(TRACE_EXPAND, "expand: lka_expand: "
"error in alias lookup");
diff --git a/smtpd/smtpd.h b/smtpd/smtpd.h
index 7e351314..1fdcd8f6 100644
--- a/smtpd/smtpd.h
+++ b/smtpd/smtpd.h
@@ -409,6 +409,8 @@ struct expandnode {
struct rule *rule;
struct expandnode *parent;
unsigned int depth;
+ struct table *mapping;
+ struct table *userbase;
union {
/*
* user field handles both expansion user and system user
@@ -1022,9 +1024,9 @@ struct ca_vrfy_resp_msg {
/* aliases.c */
-int aliases_get(struct table *, struct expand *, const char *);
+int aliases_get(struct expand *, const char *);
int aliases_virtual_check(struct table *, const struct mailaddr *);
-int aliases_virtual_get(struct table *, struct expand *, const struct mailaddr *);
+int aliases_virtual_get(struct expand *, const struct mailaddr *);
int alias_parse(struct expandnode *, const char *);