summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgilles <gilles@openbsd.org>2013-02-14 12:30:49 +0000
committergilles <gilles@openbsd.org>2013-02-14 12:30:49 +0000
commit59a46edca4c34283d600e8075a5b55bccc3ea27d (patch)
tree55eb7e4b6687cc25b6c16a32a17afd5242f6ee34
parentsimplify markup for the "table" keyword; ok gilles (diff)
downloadwireguard-openbsd-59a46edca4c34283d600e8075a5b55bccc3ea27d.tar.xz
wireguard-openbsd-59a46edca4c34283d600e8075a5b55bccc3ea27d.zip
- smtpctl trace expand, enables tracing of aliases expansion
- replace "users" keyword with "userbase" when providing alternate userbase - disambiguise expansion nodes when expanding across domains and userbases - allow use of '=' instead of '=>' when declaring a mapping ok eric@
-rw-r--r--usr.sbin/smtpd/aliases.c30
-rw-r--r--usr.sbin/smtpd/expand.c82
-rw-r--r--usr.sbin/smtpd/lka.c6
-rw-r--r--usr.sbin/smtpd/lka_session.c56
-rw-r--r--usr.sbin/smtpd/parse.y22
-rw-r--r--usr.sbin/smtpd/parser.c4
-rw-r--r--usr.sbin/smtpd/parser.h4
-rw-r--r--usr.sbin/smtpd/smtpctl.c10
-rw-r--r--usr.sbin/smtpd/smtpd.c10
-rw-r--r--usr.sbin/smtpd/smtpd.conf.54
-rw-r--r--usr.sbin/smtpd/smtpd.h13
-rw-r--r--usr.sbin/smtpd/to.c21
12 files changed, 197 insertions, 65 deletions
diff --git a/usr.sbin/smtpd/aliases.c b/usr.sbin/smtpd/aliases.c
index 002b0be7eb3..8aa57493e42 100644
--- a/usr.sbin/smtpd/aliases.c
+++ b/usr.sbin/smtpd/aliases.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: aliases.c,v 1.60 2013/01/31 18:34:43 eric Exp $ */
+/* $OpenBSD: aliases.c,v 1.61 2013/02/14 12:30:49 gilles Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@poolp.org>
@@ -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_userbase;
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_userbase;
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/usr.sbin/smtpd/expand.c b/usr.sbin/smtpd/expand.c
index 06c525a3a5b..7c37c04c4bc 100644
--- a/usr.sbin/smtpd/expand.c
+++ b/usr.sbin/smtpd/expand.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: expand.c,v 1.20 2013/01/31 18:34:43 eric Exp $ */
+/* $OpenBSD: expand.c,v 1.21 2013/02/14 12:30:49 gilles Exp $ */
/*
* Copyright (c) 2009 Gilles Chehade <gilles@poolp.org>
@@ -33,6 +33,8 @@
#include "smtpd.h"
#include "log.h"
+static const char *expandnode_info(struct expandnode *);
+
struct expandnode *
expand_lookup(struct expand *expand, struct expandnode *key)
{
@@ -44,15 +46,24 @@ expand_insert(struct expand *expand, struct expandnode *node)
{
struct expandnode *xn;
+ log_trace(TRACE_EXPAND, "expand: %p: expand_insert() called for %s",
+ expand, expandnode_info(node));
if (node->type == EXPAND_USERNAME &&
expand->parent &&
expand->parent->type == EXPAND_USERNAME &&
- !strcmp(expand->parent->u.user, node->u.user))
+ !strcmp(expand->parent->u.user, node->u.user)) {
+ log_trace(TRACE_EXPAND, "expand: %p: setting sameuser = 1",
+ expand);
node->sameuser = 1;
+ }
- if (expand_lookup(expand, node))
+ if (expand_lookup(expand, node)) {
+ log_trace(TRACE_EXPAND, "expand: %p: node found, discarding",
+ expand);
return;
+ }
+ log_trace(TRACE_EXPAND, "expand: %p: inserting node", expand);
xn = xmemdup(node, sizeof *xn, "expand_insert");
xn->rule = expand->rule;
xn->parent = expand->parent;
@@ -72,6 +83,7 @@ expand_clear(struct expand *expand)
{
struct expandnode *xn;
+ log_trace(TRACE_EXPAND, "expand: %p: clearing expand tree", expand);
if (expand->queue)
while ((xn = TAILQ_FIRST(expand->queue)))
TAILQ_REMOVE(expand->queue, xn, tq_entry);
@@ -86,6 +98,8 @@ void
expand_free(struct expand *expand)
{
expand_clear(expand);
+
+ log_trace(TRACE_EXPAND, "expand: %p: freeing expand tree", expand);
free(expand);
}
@@ -100,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));
}
@@ -178,4 +200,58 @@ expand_line(struct expand *expand, const char *s, int do_includes)
return 0;
}
+static const char *
+expandnode_info(struct expandnode *e)
+{
+ static char buffer[1024];
+ const char *type = NULL;
+ const char *value = NULL;
+
+ switch (e->type) {
+ case EXPAND_FILTER:
+ type = "filter";
+ break;
+ case EXPAND_FILENAME:
+ type = "filename";
+ break;
+ case EXPAND_INCLUDE:
+ type = "include";
+ break;
+ case EXPAND_USERNAME:
+ type = "username";
+ break;
+ case EXPAND_ADDRESS:
+ type = "address";
+ break;
+ case EXPAND_INVALID:
+ default:
+ return NULL;
+ }
+
+ if ((value = expandnode_to_text(e)) == NULL)
+ return NULL;
+
+ 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;
+}
+
RB_GENERATE(expandtree, expandnode, entry, expand_cmp);
diff --git a/usr.sbin/smtpd/lka.c b/usr.sbin/smtpd/lka.c
index 1c0800fc9e9..de6e8deadf9 100644
--- a/usr.sbin/smtpd/lka.c
+++ b/usr.sbin/smtpd/lka.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: lka.c,v 1.149 2013/02/05 11:45:18 gilles Exp $ */
+/* $OpenBSD: lka.c,v 1.150 2013/02/14 12:30:49 gilles Exp $ */
/*
* Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -472,8 +472,8 @@ lka_imsg(struct mproc *p, struct imsg *imsg)
rule = TAILQ_LAST(env->sc_rules_reload, rulelist);
tmp = env->sc_tables_dict;
env->sc_tables_dict = tables_dict;
- rule->r_users = table_findbyname(imsg->data);
- if (rule->r_users == NULL)
+ rule->r_userbase = table_findbyname(imsg->data);
+ if (rule->r_userbase == NULL)
fatalx("lka: tables inconsistency");
env->sc_tables_dict = tmp;
return;
diff --git a/usr.sbin/smtpd/lka_session.c b/usr.sbin/smtpd/lka_session.c
index bc9238ee0d8..cfb1fc592cf 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.54 2013/02/05 11:45:18 gilles Exp $ */
+/* $OpenBSD: lka_session.c,v 1.55 2013/02/14 12:30:49 gilles Exp $ */
/*
* Copyright (c) 2011 Gilles Chehade <gilles@poolp.org>
@@ -114,13 +114,13 @@ lka_session_forward_reply(struct forward_req *fwreq, int fd)
switch (fwreq->status) {
case 0:
/* permanent failure while lookup ~/.forward */
- log_trace(TRACE_LOOKUP, "lookup: ~/.forward failed for user %s",
+ log_trace(TRACE_EXPAND, "expand: ~/.forward failed for user %s",
fwreq->user);
lks->error = LKA_PERMFAIL;
break;
case 1:
if (fd == -1) {
- log_trace(TRACE_LOOKUP, "lookup: no .forward for "
+ log_trace(TRACE_EXPAND, "expand: no .forward for "
"user %s, just deliver", fwreq->user);
lka_submit(lks, rule, xn);
}
@@ -129,10 +129,11 @@ 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_userbase;
/* forwards_get() will close the descriptor no matter what */
if (! forwards_get(fd, &lks->expand)) {
- log_trace(TRACE_LOOKUP, "lookup: temporary "
+ log_trace(TRACE_EXPAND, "expand: temporary "
"forward error for user %s", fwreq->user);
lks->error = LKA_TEMPFAIL;
}
@@ -167,7 +168,7 @@ lka_resume(struct lka_session *lks)
/* delivery list is empty, reject */
if (TAILQ_FIRST(&lks->deliverylist) == NULL) {
- log_trace(TRACE_LOOKUP, "lookup: lka_done: expanded to empty "
+ log_trace(TRACE_EXPAND, "expand: lka_done: expanded to empty "
"delivery list");
lks->error = LKA_PERMFAIL;
}
@@ -214,7 +215,7 @@ lka_expand(struct lka_session *lks, struct rule *rule, struct expandnode *xn)
struct userinfo *tu = NULL;
if (xn->depth >= EXPAND_DEPTH) {
- log_trace(TRACE_LOOKUP, "lookup: lka_expand: node too deep.");
+ log_trace(TRACE_EXPAND, "expand: lka_expand: node too deep.");
lks->error = LKA_PERMFAIL;
return;
}
@@ -227,7 +228,7 @@ lka_expand(struct lka_session *lks, struct rule *rule, struct expandnode *xn)
case EXPAND_ADDRESS:
- log_trace(TRACE_LOOKUP, "lookup: lka_expand: address: %s@%s "
+ log_trace(TRACE_EXPAND, "expand: lka_expand: address: %s@%s "
"[depth=%d]",
xn->u.mailaddr.user, xn->u.mailaddr.domain, xn->depth);
@@ -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_userbase;
+
if (rule->r_action == A_RELAY || rule->r_action == A_RELAYVIA) {
lka_submit(lks, rule, xn);
}
@@ -251,16 +255,15 @@ 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_LOOKUP, "lookup: lka_expand: "
+ log_trace(TRACE_EXPAND, "expand: lka_expand: "
"error in virtual alias lookup");
}
else if (r == 0) {
lks->error = LKA_PERMFAIL;
- log_trace(TRACE_LOOKUP, "lookup: lka_expand: "
+ log_trace(TRACE_EXPAND, "expand: lka_expand: "
"no aliases for virtual");
}
}
@@ -272,16 +275,18 @@ 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_userbase;
expand_insert(&lks->expand, &node);
}
break;
case EXPAND_USERNAME:
- log_trace(TRACE_LOOKUP, "lookup: lka_expand: username: %s "
+ log_trace(TRACE_EXPAND, "expand: lka_expand: username: %s "
"[depth=%d]", xn->u.user, xn->depth);
if (xn->sameuser) {
- log_trace(TRACE_LOOKUP, "lookup: lka_expand: same "
+ log_trace(TRACE_EXPAND, "expand: lka_expand: same "
"user, submitting");
lka_submit(lks, rule, xn);
break;
@@ -291,11 +296,12 @@ 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_userbase;
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_LOOKUP, "lookup: lka_expand: "
+ log_trace(TRACE_EXPAND, "expand: lka_expand: "
"error in alias lookup");
lks->error = LKA_TEMPFAIL;
}
@@ -305,21 +311,21 @@ lka_expand(struct lka_session *lks, struct rule *rule, struct expandnode *xn)
/* A username should not exceed the size of a system user */
if (strlen(xn->u.user) >= sizeof fwreq.user) {
- log_trace(TRACE_LOOKUP, "lookup: lka_expand: "
+ log_trace(TRACE_EXPAND, "expand: lka_expand: "
"user-part too long to be a system user");
lks->error = LKA_PERMFAIL;
break;
}
- r = table_lookup(rule->r_users, xn->u.user, K_USERINFO, (void **)&tu);
+ r = table_lookup(rule->r_userbase, xn->u.user, K_USERINFO, (void **)&tu);
if (r == -1) {
- log_trace(TRACE_LOOKUP, "lookup: lka_expand: "
+ log_trace(TRACE_EXPAND, "expand: lka_expand: "
"backend error while searching user");
lks->error = LKA_TEMPFAIL;
break;
}
if (r == 0) {
- log_trace(TRACE_LOOKUP, "lookup: lka_expand: "
+ log_trace(TRACE_EXPAND, "expand: lka_expand: "
"user-part does not match system user");
lks->error = LKA_PERMFAIL;
break;
@@ -340,13 +346,13 @@ lka_expand(struct lka_session *lks, struct rule *rule, struct expandnode *xn)
break;
case EXPAND_FILENAME:
- log_trace(TRACE_LOOKUP, "lookup: lka_expand: filename: %s "
+ log_trace(TRACE_EXPAND, "expand: lka_expand: filename: %s "
"[depth=%d]", xn->u.buffer, xn->depth);
lka_submit(lks, rule, xn);
break;
case EXPAND_FILTER:
- log_trace(TRACE_LOOKUP, "lookup: lka_expand: filter: %s "
+ log_trace(TRACE_EXPAND, "expand: lka_expand: filter: %s "
"[depth=%d]", xn->u.buffer, xn->depth);
lka_submit(lks, rule, xn);
break;
@@ -412,14 +418,14 @@ lka_submit(struct lka_session *lks, struct rule *rule, struct expandnode *xn)
sizeof(ep->agent.mda.username));
}
- r = table_lookup(rule->r_users, ep->agent.mda.username, K_USERINFO,
+ r = table_lookup(rule->r_userbase, ep->agent.mda.username, K_USERINFO,
(void **)&tu);
if (r <= 0) {
lks->error = (r == -1) ? LKA_TEMPFAIL : LKA_PERMFAIL;
free(ep);
return;
}
- strlcpy(ep->agent.mda.usertable, rule->r_users->t_name,
+ strlcpy(ep->agent.mda.usertable, rule->r_userbase->t_name,
sizeof ep->agent.mda.usertable);
strlcpy(ep->agent.mda.username, tu->username,
sizeof ep->agent.mda.username);
diff --git a/usr.sbin/smtpd/parse.y b/usr.sbin/smtpd/parse.y
index a8ea2b3f241..36d7538cc92 100644
--- a/usr.sbin/smtpd/parse.y
+++ b/usr.sbin/smtpd/parse.y
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.y,v 1.113 2013/02/05 15:30:59 gilles Exp $ */
+/* $OpenBSD: parse.y,v 1.114 2013/02/14 12:30:49 gilles Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@poolp.org>
@@ -122,7 +122,7 @@ typedef struct {
%token RELAY BACKUP VIA DELIVER TO MAILDIR MBOX HOSTNAME HELO
%token ACCEPT REJECT INCLUDE ERROR MDA FROM FOR SOURCE
%token ARROW AUTH TLS LOCAL VIRTUAL TAG TAGGED ALIAS FILTER KEY
-%token AUTH_OPTIONAL TLS_REQUIRE USERS SENDER
+%token AUTH_OPTIONAL TLS_REQUIRE USERBASE SENDER
%token <v.string> STRING
%token <v.number> NUMBER
%type <v.table> table
@@ -525,7 +525,9 @@ table : TABLE STRING STRING {
}
;
-keyval : STRING ARROW STRING {
+assign : '=' | ARROW;
+
+keyval : STRING assign STRING {
table->t_type = T_HASH;
table_add(table, $1, $3);
free($1);
@@ -626,11 +628,11 @@ usermapping : alias {
}
;
-userbase : USERS tables {
+userbase : USERBASE tables {
struct table *t = table_find($2);
if (! table_check_use(t, T_DYNAMIC|T_HASH, K_USERINFO)) {
- yyerror("invalid use of table \"%s\" as USERS parameter",
+ yyerror("invalid use of table \"%s\" as USERBASE parameter",
t->t_name);
YYERROR;
}
@@ -715,7 +717,7 @@ relay_as : AS STRING {
;
action : userbase DELIVER TO MAILDIR {
- rule->r_users = table_find($1);
+ rule->r_userbase = table_find($1);
rule->r_action = A_MAILDIR;
if (strlcpy(rule->r_value.buffer, "~/Maildir",
sizeof(rule->r_value.buffer)) >=
@@ -723,7 +725,7 @@ action : userbase DELIVER TO MAILDIR {
fatal("pathname too long");
}
| userbase DELIVER TO MAILDIR STRING {
- rule->r_users = table_find($1);
+ rule->r_userbase = table_find($1);
rule->r_action = A_MAILDIR;
if (strlcpy(rule->r_value.buffer, $5,
sizeof(rule->r_value.buffer)) >=
@@ -732,7 +734,7 @@ action : userbase DELIVER TO MAILDIR {
free($5);
}
| userbase DELIVER TO MBOX {
- rule->r_users = table_find($1);
+ rule->r_userbase = table_find($1);
rule->r_action = A_MBOX;
if (strlcpy(rule->r_value.buffer, _PATH_MAILDIR "/%u",
sizeof(rule->r_value.buffer))
@@ -740,7 +742,7 @@ action : userbase DELIVER TO MAILDIR {
fatal("pathname too long");
}
| userbase DELIVER TO MDA STRING {
- rule->r_users = table_find($1);
+ rule->r_userbase = table_find($1);
rule->r_action = A_MDA;
if (strlcpy(rule->r_value.buffer, $5,
sizeof(rule->r_value.buffer))
@@ -1008,7 +1010,7 @@ lookup(char *s)
{ "tls", TLS },
{ "tls-require", TLS_REQUIRE },
{ "to", TO },
- { "users", USERS },
+ { "userbase", USERBASE },
{ "via", VIA },
{ "virtual", VIRTUAL },
};
diff --git a/usr.sbin/smtpd/parser.c b/usr.sbin/smtpd/parser.c
index 5ed8250638d..0e1922c251d 100644
--- a/usr.sbin/smtpd/parser.c
+++ b/usr.sbin/smtpd/parser.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: parser.c,v 1.32 2013/01/28 11:09:53 gilles Exp $ */
+/* $OpenBSD: parser.c,v 1.33 2013/02/14 12:30:49 gilles Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -150,6 +150,7 @@ static const struct token t_trace[] = {
{KEYWORD, "stat", LOG_TRACE_STAT, NULL},
{KEYWORD, "rules", LOG_TRACE_RULES, NULL},
{KEYWORD, "msg-size", LOG_TRACE_IMSG_SIZE, NULL},
+ {KEYWORD, "expand", LOG_TRACE_EXPAND, NULL},
{KEYWORD, "all", LOG_TRACE_ALL, NULL},
{ENDTOKEN, "", NONE, NULL}
};
@@ -166,6 +167,7 @@ static const struct token t_untrace[] = {
{KEYWORD, "stat", LOG_UNTRACE_STAT, NULL},
{KEYWORD, "rules", LOG_UNTRACE_RULES, NULL},
{KEYWORD, "msg-size", LOG_UNTRACE_IMSG_SIZE, NULL},
+ {KEYWORD, "expand", LOG_UNTRACE_EXPAND, NULL},
{KEYWORD, "all", LOG_UNTRACE_ALL, NULL},
{ENDTOKEN, "", NONE, NULL}
};
diff --git a/usr.sbin/smtpd/parser.h b/usr.sbin/smtpd/parser.h
index 3d90d02ea56..a6d5ad00385 100644
--- a/usr.sbin/smtpd/parser.h
+++ b/usr.sbin/smtpd/parser.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: parser.h,v 1.25 2013/01/28 11:09:53 gilles Exp $ */
+/* $OpenBSD: parser.h,v 1.26 2013/02/14 12:30:49 gilles Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -47,6 +47,7 @@ enum actions {
LOG_TRACE_STAT,
LOG_TRACE_RULES,
LOG_TRACE_IMSG_SIZE,
+ LOG_TRACE_EXPAND,
LOG_TRACE_ALL,
LOG_UNTRACE_IMSG,
LOG_UNTRACE_IO,
@@ -59,6 +60,7 @@ enum actions {
LOG_UNTRACE_STAT,
LOG_UNTRACE_RULES,
LOG_UNTRACE_IMSG_SIZE,
+ LOG_UNTRACE_EXPAND,
LOG_UNTRACE_ALL,
LOG_PROFILE_IMSG,
LOG_PROFILE_QUEUE,
diff --git a/usr.sbin/smtpd/smtpctl.c b/usr.sbin/smtpd/smtpctl.c
index cc218ee9155..43c82372509 100644
--- a/usr.sbin/smtpd/smtpctl.c
+++ b/usr.sbin/smtpd/smtpctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtpctl.c,v 1.100 2013/01/28 11:09:53 gilles Exp $ */
+/* $OpenBSD: smtpctl.c,v 1.101 2013/02/14 12:30:49 gilles Exp $ */
/*
* Copyright (c) 2006 Gilles Chehade <gilles@poolp.org>
@@ -310,6 +310,7 @@ main(int argc, char *argv[])
case LOG_TRACE_STAT:
case LOG_TRACE_RULES:
case LOG_TRACE_IMSG_SIZE:
+ case LOG_TRACE_EXPAND:
case LOG_TRACE_ALL:
verb = trace_convert(action);
imsg_compose(ibuf, IMSG_CTL_TRACE, 0, 0, -1, &verb,
@@ -328,6 +329,7 @@ main(int argc, char *argv[])
case LOG_UNTRACE_STAT:
case LOG_UNTRACE_RULES:
case LOG_UNTRACE_IMSG_SIZE:
+ case LOG_UNTRACE_EXPAND:
case LOG_UNTRACE_ALL:
verb = trace_convert(action);
imsg_compose(ibuf, IMSG_CTL_UNTRACE, 0, 0, -1, &verb,
@@ -382,6 +384,7 @@ main(int argc, char *argv[])
case LOG_TRACE_STAT:
case LOG_TRACE_RULES:
case LOG_TRACE_IMSG_SIZE:
+ case LOG_TRACE_EXPAND:
case LOG_TRACE_ALL:
case LOG_UNTRACE_IMSG:
case LOG_UNTRACE_IO:
@@ -394,6 +397,7 @@ main(int argc, char *argv[])
case LOG_UNTRACE_STAT:
case LOG_UNTRACE_RULES:
case LOG_UNTRACE_IMSG_SIZE:
+ case LOG_UNTRACE_EXPAND:
case LOG_UNTRACE_ALL:
case LOG_PROFILE_IMSG:
case LOG_PROFILE_QUEUE:
@@ -866,6 +870,10 @@ trace_convert(uint32_t trace)
case LOG_UNTRACE_IMSG_SIZE:
return TRACE_IMSGSIZE;
+ case LOG_TRACE_EXPAND:
+ case LOG_UNTRACE_EXPAND:
+ return TRACE_EXPAND;
+
case LOG_TRACE_ALL:
case LOG_UNTRACE_ALL:
return ~TRACE_VERBOSE;
diff --git a/usr.sbin/smtpd/smtpd.c b/usr.sbin/smtpd/smtpd.c
index 636307e90c3..ff62cbcc13d 100644
--- a/usr.sbin/smtpd/smtpd.c
+++ b/usr.sbin/smtpd/smtpd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtpd.c,v 1.186 2013/01/31 18:34:43 eric Exp $ */
+/* $OpenBSD: smtpd.c,v 1.187 2013/02/14 12:30:49 gilles Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@poolp.org>
@@ -470,10 +470,10 @@ parent_send_config_lka()
&r->r_mapping->t_name,
sizeof(r->r_mapping->t_name));
}
- if (r->r_users) {
+ if (r->r_userbase) {
m_compose(p_lka, IMSG_CONF_RULE_USERS, 0, 0, -1,
- &r->r_users->t_name,
- sizeof(r->r_users->t_name));
+ &r->r_userbase->t_name,
+ sizeof(r->r_userbase->t_name));
}
}
@@ -664,6 +664,8 @@ main(int argc, char *argv[])
verbose |= TRACE_RULES;
else if (!strcmp(optarg, "imsg-size"))
verbose |= TRACE_IMSGSIZE;
+ else if (!strcmp(optarg, "expand"))
+ verbose |= TRACE_EXPAND;
else if (!strcmp(optarg, "all"))
verbose |= ~TRACE_VERBOSE;
else if (!strcmp(optarg, "profstat"))
diff --git a/usr.sbin/smtpd/smtpd.conf.5 b/usr.sbin/smtpd/smtpd.conf.5
index 9f4488128f0..b771cdb3469 100644
--- a/usr.sbin/smtpd/smtpd.conf.5
+++ b/usr.sbin/smtpd/smtpd.conf.5
@@ -1,4 +1,4 @@
-.\" $OpenBSD: smtpd.conf.5,v 1.87 2013/02/14 07:42:49 jmc Exp $
+.\" $OpenBSD: smtpd.conf.5,v 1.88 2013/02/14 12:30:49 gilles Exp $
.\"
.\" Copyright (c) 2008 Janne Johansson <jj@openbsd.org>
.\" Copyright (c) 2009 Jacek Masiulaniec <jacekm@dobremiasto.net>
@@ -231,7 +231,7 @@ table will be used as the virtual domain mapping.
If the method of delivery is local, a user database may be
specified to override the system database:
.Bl -tag -width Ds
-.It Op Ic users Aq Ar table
+.It Op Ic userbase Aq Ar table
Look up users in the table
.Ar table
instead of performing system lookups using the
diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h
index 21d795d95d1..724caf7ef82 100644
--- a/usr.sbin/smtpd/smtpd.h
+++ b/usr.sbin/smtpd/smtpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtpd.h,v 1.404 2013/02/10 15:01:16 eric Exp $ */
+/* $OpenBSD: smtpd.h,v 1.405 2013/02/14 12:30:49 gilles Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@poolp.org>
@@ -359,7 +359,7 @@ struct rule {
struct mailaddr *r_as;
struct table *r_mapping;
- struct table *r_users;
+ struct table *r_userbase;
time_t r_qexpire;
};
@@ -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
@@ -581,6 +583,7 @@ struct smtpd {
#define TRACE_STAT 0x0200
#define TRACE_RULES 0x0400
#define TRACE_IMSGSIZE 0x0800
+#define TRACE_EXPAND 0x1000
#define PROFILE_TOSTAT 0x0001
#define PROFILE_IMSG 0x0002
@@ -1021,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 *);
@@ -1338,7 +1341,7 @@ const char *relayhost_to_text(const struct relayhost *);
const char *rule_to_text(struct rule *);
const char *sockaddr_to_text(struct sockaddr *);
const char *mailaddr_to_text(const struct mailaddr *);
-
+const char *expandnode_to_text(struct expandnode *);
/* util.c */
typedef struct arglist arglist;
diff --git a/usr.sbin/smtpd/to.c b/usr.sbin/smtpd/to.c
index e93a6fa50ea..1c00364307b 100644
--- a/usr.sbin/smtpd/to.c
+++ b/usr.sbin/smtpd/to.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: to.c,v 1.2 2013/01/31 18:34:43 eric Exp $ */
+/* $OpenBSD: to.c,v 1.3 2013/02/14 12:30:49 gilles Exp $ */
/*
* Copyright (c) 2009 Jacek Masiulaniec <jacekm@dobremiasto.net>
@@ -662,6 +662,25 @@ text_to_expandnode(struct expandnode *expandnode, const char *s)
return (0);
}
+const char *
+expandnode_to_text(struct expandnode *expandnode)
+{
+ switch (expandnode->type) {
+ case EXPAND_FILTER:
+ case EXPAND_FILENAME:
+ case EXPAND_INCLUDE:
+ return expandnode->u.buffer;
+ case EXPAND_USERNAME:
+ return expandnode->u.user;
+ case EXPAND_ADDRESS:
+ return mailaddr_to_text(&expandnode->u.mailaddr);
+ case EXPAND_INVALID:
+ break;
+ }
+
+ return NULL;
+}
+
/******/
static int