summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorGilles Chehade <gilles@cvs.openbsd.org>2015-11-30 10:56:26 +0000
committerGilles Chehade <gilles@cvs.openbsd.org>2015-11-30 10:56:26 +0000
commit58cd23f8b673bf068b9e90a5f0b96b137a605dcc (patch)
treec93088d0547c1bcc910dabfb284337e6bada7a46 /usr.sbin
parent671c17c5b086b6ee31f9205767ebe521bd79f5c5 (diff)
teach aliases expansion how to deal with user+tag
ok sunil@, ok jung@
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/smtpd/aliases.c75
-rw-r--r--usr.sbin/smtpd/lka_session.c13
2 files changed, 71 insertions, 17 deletions
diff --git a/usr.sbin/smtpd/aliases.c b/usr.sbin/smtpd/aliases.c
index a01cb73a074..cb60d2cd150 100644
--- a/usr.sbin/smtpd/aliases.c
+++ b/usr.sbin/smtpd/aliases.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: aliases.c,v 1.67 2015/10/27 20:14:19 gilles Exp $ */
+/* $OpenBSD: aliases.c,v 1.68 2015/11/30 10:56:25 gilles Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@poolp.org>
@@ -46,15 +46,30 @@ aliases_get(struct expand *expand, const char *username)
union lookup lk;
struct table *mapping = NULL;
struct table *userbase = NULL;
+ char *pbuf;
mapping = expand->rule->r_mapping;
userbase = expand->rule->r_userbase;
xlowercase(buf, username, sizeof(buf));
+
+ /* first, check if entry has a user-part tag */
+ pbuf = strchr(buf, TAG_CHAR);
+ if (pbuf) {
+ ret = table_lookup(mapping, NULL, buf, K_ALIAS, &lk);
+ if (ret < 0)
+ return (-1);
+ if (ret)
+ goto expand;
+ *pbuf = '\0';
+ }
+
+ /* no user-part tag, try looking up user */
ret = table_lookup(mapping, NULL, buf, K_ALIAS, &lk);
if (ret <= 0)
return ret;
+expand:
/* foreach node in table_alias expandtree, we merge */
nbaliases = 0;
RB_FOREACH(xn, expandtree, &lk.expand->tree) {
@@ -81,6 +96,9 @@ aliases_virtual_get(struct expand *expand, const struct mailaddr *maddr)
struct expandnode *xn;
union lookup lk;
char buf[LINE_MAX];
+ char user[LINE_MAX];
+ char tag[LINE_MAX];
+ char domain[LINE_MAX];
char *pbuf;
int nbaliases;
int ret;
@@ -90,30 +108,67 @@ aliases_virtual_get(struct expand *expand, const struct mailaddr *maddr)
mapping = expand->rule->r_mapping;
userbase = expand->rule->r_userbase;
- if (! bsnprintf(buf, sizeof(buf), "%s@%s", maddr->user,
- maddr->domain))
- return 0;
- xlowercase(buf, buf, sizeof(buf));
+ if (! bsnprintf(user, sizeof(user), "%s", maddr->user))
+ return 0;
+ if (! bsnprintf(domain, sizeof(domain), "%s", maddr->domain))
+ return 0;
+ xlowercase(user, user, sizeof(user));
+ xlowercase(domain, domain, sizeof(domain));
+
+ memset(tag, '\0', sizeof tag);
+ pbuf = strchr(user, TAG_CHAR);
+ if (pbuf) {
+ if (! bsnprintf(tag, sizeof(tag), "%s", pbuf + 1))
+ return 0;
+ xlowercase(tag, tag, sizeof(tag));
+ *pbuf = '\0';
+ }
+
+ /* first, check if entry has a user-part tag */
+ if (tag[0]) {
+ if (! bsnprintf(buf, sizeof(buf), "%s+%s@%s",
+ user, tag, domain))
+ return 0;
+ ret = table_lookup(mapping, NULL, buf, K_ALIAS, &lk);
+ if (ret < 0)
+ return (-1);
+ if (ret)
+ goto expand;
+ }
- /* First, we lookup for full entry: user@domain */
+ /* then, check if entry exists without user-part tag */
+ if (! bsnprintf(buf, sizeof(buf), "%s@%s", user, domain))
+ return 0;
ret = table_lookup(mapping, NULL, buf, K_ALIAS, &lk);
if (ret < 0)
return (-1);
if (ret)
goto expand;
+ if (tag[0]) {
+ /* Failed ? We lookup for username + user-part tag */
+ if (! bsnprintf(buf, sizeof(buf), "%s+%s", user, tag))
+ return 0;
+ ret = table_lookup(mapping, NULL, buf, K_ALIAS, &lk);
+ if (ret < 0)
+ return (-1);
+ if (ret)
+ goto expand;
+ }
+
/* Failed ? We lookup for username only */
- pbuf = strchr(buf, '@');
- *pbuf = '\0';
+ if (! bsnprintf(buf, sizeof(buf), "%s", user))
+ return 0;
ret = table_lookup(mapping, NULL, buf, K_ALIAS, &lk);
if (ret < 0)
return (-1);
if (ret)
goto expand;
- *pbuf = '@';
+ if (! bsnprintf(buf, sizeof(buf), "@%s", domain))
+ return 0;
/* Failed ? We lookup for catch all for virtual domain */
- ret = table_lookup(mapping, NULL, pbuf, K_ALIAS, &lk);
+ ret = table_lookup(mapping, NULL, buf, K_ALIAS, &lk);
if (ret < 0)
return (-1);
if (ret)
diff --git a/usr.sbin/smtpd/lka_session.c b/usr.sbin/smtpd/lka_session.c
index e9ccf447de4..13e409af552 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.73 2015/10/28 07:43:44 gilles Exp $ */
+/* $OpenBSD: lka_session.c,v 1.74 2015/11/30 10:56:25 gilles Exp $ */
/*
* Copyright (c) 2011 Gilles Chehade <gilles@poolp.org>
@@ -274,6 +274,7 @@ lka_expand(struct lka_session *lks, struct rule *rule, struct expandnode *xn)
struct mailaddr maddr;
int r;
union lookup lk;
+ char *tag;
if (xn->depth >= EXPAND_DEPTH) {
log_trace(TRACE_EXPAND, "expand: lka_expand: node too deep.");
@@ -378,6 +379,10 @@ lka_expand(struct lka_session *lks, struct rule *rule, struct expandnode *xn)
break;
}
+ /* gilles+hackers@ -> gilles@ */
+ if ((tag = strchr(xn->u.user, TAG_CHAR)) != NULL)
+ *tag++ = '\0';
+
r = table_lookup(rule->r_userbase, NULL, xn->u.user, K_USERINFO, &lk);
if (r == -1) {
log_trace(TRACE_EXPAND, "expand: lka_expand: "
@@ -839,13 +844,7 @@ lka_expand_format(char *buf, size_t len, const struct envelope *ep,
static void
mailaddr_to_username(const struct mailaddr *maddr, char *dst, size_t len)
{
- char *tag;
-
xlowercase(dst, maddr->user, len);
-
- /* gilles+hackers@ -> gilles@ */
- if ((tag = strchr(dst, TAG_CHAR)) != NULL)
- *tag++ = '\0';
}
static int