summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/smtpd/aliases.c10
-rw-r--r--usr.sbin/smtpd/lka.c42
-rw-r--r--usr.sbin/smtpd/parse.y44
-rw-r--r--usr.sbin/smtpd/smtpd.h7
4 files changed, 69 insertions, 34 deletions
diff --git a/usr.sbin/smtpd/aliases.c b/usr.sbin/smtpd/aliases.c
index 965dfbd1006..0285c6cbdfb 100644
--- a/usr.sbin/smtpd/aliases.c
+++ b/usr.sbin/smtpd/aliases.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: aliases.c,v 1.24 2009/11/03 19:13:34 gilles Exp $ */
+/* $OpenBSD: aliases.c,v 1.25 2009/11/03 20:55:23 gilles Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -42,7 +42,7 @@ int alias_is_filename(struct alias *, char *, size_t);
int alias_is_include(struct alias *, char *, size_t);
int
-aliases_exist(struct smtpd *env, char *username)
+aliases_exist(struct smtpd *env, objid_t mapid, char *username)
{
char buf[MAXLOGNAME];
int ret;
@@ -51,7 +51,7 @@ aliases_exist(struct smtpd *env, char *username)
DB *aliasesdb;
struct map *map;
- map = map_findbyname(env, "aliases");
+ map = map_find(env, mapid);
if (map == NULL)
return 0;
@@ -75,7 +75,7 @@ aliases_exist(struct smtpd *env, char *username)
}
int
-aliases_get(struct smtpd *env, struct aliaseslist *aliases, char *username)
+aliases_get(struct smtpd *env, objid_t mapid, struct aliaseslist *aliases, char *username)
{
char buf[MAXLOGNAME];
int ret;
@@ -88,7 +88,7 @@ aliases_get(struct smtpd *env, struct aliaseslist *aliases, char *username)
struct alias *nextalias;
struct map *map;
- map = map_findbyname(env, "aliases");
+ map = map_find(env, mapid);
if (map == NULL)
return 0;
diff --git a/usr.sbin/smtpd/lka.c b/usr.sbin/smtpd/lka.c
index 2a87304dc60..b30801455a2 100644
--- a/usr.sbin/smtpd/lka.c
+++ b/usr.sbin/smtpd/lka.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: lka.c,v 1.74 2009/11/03 19:13:34 gilles Exp $ */
+/* $OpenBSD: lka.c,v 1.75 2009/11/03 20:55:23 gilles Exp $ */
/*
* Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -369,7 +369,10 @@ lka_dispatch_mfa(int sig, short event, void *p)
}
else if (lkasession->path.flags & F_PATH_ALIAS) {
log_debug("F_PATH_ALIAS");
- ret = aliases_get(env, &lkasession->aliaseslist, lkasession->path.user);
+ ret = aliases_get(env,
+ lkasession->path.rule.r_amap,
+ &lkasession->aliaseslist,
+ lkasession->path.user);
log_debug("\tALIASES RESOLVED: %d", ret);
}
else if (lkasession->path.flags & F_PATH_VIRTUAL) {
@@ -946,7 +949,8 @@ lka_expand_rcpt_iteration(struct smtpd *env, struct aliaseslist *aliases, struct
u_int8_t done = 1;
struct alias *rmalias = NULL;
struct alias *alias;
- struct path *lkasessionpath;
+ struct path *lkasessionpath = NULL;
+ struct path *respath = NULL;
lkasessionpath = &lkasession->path;
rmalias = NULL;
@@ -958,21 +962,37 @@ lka_expand_rcpt_iteration(struct smtpd *env, struct aliaseslist *aliases, struct
}
if (alias->type == ALIAS_ADDRESS) {
- lka_rcpt_action(env, lkasession->message.tag, &alias->u.path);
- lka_resolve_path(env, &alias->u.path);
- if (aliases_virtual_get(env, alias->u.path.cond->c_map, aliases, &alias->u.path)) {
- rmalias = alias;
- done = 0;
+ respath = &alias->u.path;
+ lka_rcpt_action(env, lkasession->message.tag, respath);
+ lka_resolve_path(env, respath);
+
+ if (alias->u.path.flags & F_PATH_VIRTUAL) {
+ if (aliases_virtual_get(env,
+ respath->cond->c_map,
+ aliases, respath)) {
+ rmalias = alias;
+ done = 0;
+ }
+ }
+
+ if (alias->u.path.flags & F_PATH_ALIAS) {
+ if (aliases_get(env, lkasessionpath->rule.r_amap,
+ aliases, alias->u.username)) {
+ done = 0;
+ rmalias = alias;
+ }
}
}
else if (alias->type == ALIAS_USERNAME) {
- if (aliases_get(env, aliases, alias->u.username)) {
+ if (aliases_get(env, lkasessionpath->rule.r_amap,
+ aliases, alias->u.username)) {
done = 0;
rmalias = alias;
}
else {
- lka_request_forwardfile(env, lkasession, alias->u.username);
+ lka_request_forwardfile(env, lkasession,
+ alias->u.username);
done = 0;
rmalias = alias;
}
@@ -1007,7 +1027,7 @@ lka_resolve_path(struct smtpd *env, struct path *path){
return 1;
lowercase(username, path->user, sizeof(username));
- if (aliases_exist(env, username)) {
+ if (aliases_exist(env, path->rule.r_amap, username)) {
path->flags |= F_PATH_ALIAS;
return 1;
}
diff --git a/usr.sbin/smtpd/parse.y b/usr.sbin/smtpd/parse.y
index a9668a397ef..814cb312808 100644
--- a/usr.sbin/smtpd/parse.y
+++ b/usr.sbin/smtpd/parse.y
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.y,v 1.43 2009/10/19 21:09:55 gilles Exp $ */
+/* $OpenBSD: parse.y,v 1.44 2009/11/03 20:55:23 gilles Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -119,7 +119,7 @@ typedef struct {
%token DNS DB TFILE EXTERNAL DOMAIN CONFIG SOURCE
%token RELAY VIA DELIVER TO MAILDIR MBOX HOSTNAME
%token ACCEPT REJECT INCLUDE NETWORK ERROR MDA FROM FOR
-%token ARROW ENABLE AUTH TLS LOCAL VIRTUAL USER TAG
+%token ARROW ENABLE AUTH TLS LOCAL VIRTUAL USER TAG ALIAS
%token <v.string> STRING
%token <v.number> NUMBER
%type <v.map> map
@@ -127,7 +127,7 @@ typedef struct {
%type <v.cond> condition
%type <v.tv> interval
%type <v.object> mapref
-%type <v.string> certname user tag on
+%type <v.string> certname user tag on alias
%%
@@ -385,15 +385,6 @@ map : MAP STRING {
map = NULL;
YYERROR;
}
- if (strcmp(map->m_name, "aliases") == 0 ||
- strcmp(map->m_name, "virtual") == 0) {
- if (map->m_src != S_DB) {
- yyerror("map source must be db");
- free(map);
- map = NULL;
- YYERROR;
- }
- }
TAILQ_INSERT_TAIL(conf->sc_maps, map, m_entry);
map = NULL;
}
@@ -645,6 +636,10 @@ decision : ACCEPT { $$ = 1; }
| REJECT { $$ = 0; }
;
+alias : ALIAS STRING { $$ = $2; }
+ | /* empty */ { $$ = NULL; }
+ ;
+
condition : NETWORK mapref {
struct cond *c;
@@ -654,8 +649,18 @@ condition : NETWORK mapref {
c->c_map = $2;
$$ = c;
}
- | DOMAIN mapref {
+ | DOMAIN mapref alias {
struct cond *c;
+ struct map *m;
+
+ if ($3) {
+ if ((m = map_findbyname(conf, $3)) == NULL) {
+ yyerror("no such map: %s", $3);
+ free($3);
+ YYERROR;
+ }
+ rule->r_amap = m->m_id;
+ }
if ((c = calloc(1, sizeof *c)) == NULL)
fatal("out of memory");
@@ -675,18 +680,26 @@ condition : NETWORK mapref {
free($2);
m->m_flags |= F_USED;
-
if ((c = calloc(1, sizeof *c)) == NULL)
fatal("out of memory");
c->c_type = C_VDOM;
c->c_map = m->m_id;
$$ = c;
}
- | LOCAL {
+ | LOCAL alias {
struct cond *c;
struct map *m;
struct mapel *me;
+ if ($2) {
+ if ((m = map_findbyname(conf, $2)) == NULL) {
+ yyerror("no such map: %s", $2);
+ free($2);
+ YYERROR;
+ }
+ rule->r_amap = m->m_id;
+ }
+
if ((m = calloc(1, sizeof(*m))) == NULL)
fatal("out of memory");
m->m_id = last_map_id++;
@@ -970,6 +983,7 @@ lookup(char *s)
/* this has to be sorted always */
static const struct keywords keywords[] = {
{ "accept", ACCEPT },
+ { "alias", ALIAS },
{ "all", ALL },
{ "auth", AUTH },
{ "certificate", CERTIFICATE },
diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h
index a6c2194e9a5..0e0a51047b7 100644
--- a/usr.sbin/smtpd/smtpd.h
+++ b/usr.sbin/smtpd/smtpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtpd.h,v 1.150 2009/11/03 19:13:34 gilles Exp $ */
+/* $OpenBSD: smtpd.h,v 1.151 2009/11/03 20:55:23 gilles Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -335,6 +335,7 @@ struct rule {
TAILQ_HEAD(optlist, opt) r_options;
char *r_user;
+ objid_t r_amap;
};
enum path_flags {
@@ -772,8 +773,8 @@ struct mta_session {
};
/* aliases.c */
-int aliases_exist(struct smtpd *, char *);
-int aliases_get(struct smtpd *, struct aliaseslist *, char *);
+int aliases_exist(struct smtpd *, objid_t, char *);
+int aliases_get(struct smtpd *, objid_t, struct aliaseslist *, char *);
int aliases_vdomain_exists(struct smtpd *, objid_t, char *);
int aliases_virtual_exist(struct smtpd *, objid_t, struct path *);
int aliases_virtual_get(struct smtpd *, objid_t, struct aliaseslist *, struct path *);