summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.sbin/smtpd/config.c7
-rw-r--r--usr.sbin/smtpd/lka.c21
-rw-r--r--usr.sbin/smtpd/parse.y43
-rw-r--r--usr.sbin/smtpd/ruleset.c58
-rw-r--r--usr.sbin/smtpd/smtpd.c7
-rw-r--r--usr.sbin/smtpd/smtpd.h5
6 files changed, 66 insertions, 75 deletions
diff --git a/usr.sbin/smtpd/config.c b/usr.sbin/smtpd/config.c
index 7cdb79def4d..e216e157a4f 100644
--- a/usr.sbin/smtpd/config.c
+++ b/usr.sbin/smtpd/config.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: config.c,v 1.11 2010/05/27 11:17:29 gilles Exp $ */
+/* $OpenBSD: config.c,v 1.12 2010/05/27 15:36:04 gilles Exp $ */
/*
* Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -58,7 +58,6 @@ purge_config(struct smtpd *env, u_int8_t what)
struct listener *l;
struct map *m;
struct rule *r;
- struct cond *c;
struct ssl *s;
struct mapel *me;
@@ -85,10 +84,6 @@ purge_config(struct smtpd *env, u_int8_t what)
if (what & PURGE_RULES) {
while ((r = TAILQ_FIRST(env->sc_rules)) != NULL) {
TAILQ_REMOVE(env->sc_rules, r, r_entry);
- while ((c = TAILQ_FIRST(&r->r_conditions)) != NULL) {
- TAILQ_REMOVE(&r->r_conditions, c, c_entry);
- free(c);
- }
free(r);
}
free(env->sc_rules);
diff --git a/usr.sbin/smtpd/lka.c b/usr.sbin/smtpd/lka.c
index a17af939a2e..38bd521682a 100644
--- a/usr.sbin/smtpd/lka.c
+++ b/usr.sbin/smtpd/lka.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: lka.c,v 1.107 2010/04/27 09:49:23 gilles Exp $ */
+/* $OpenBSD: lka.c,v 1.108 2010/05/27 15:36:04 gilles Exp $ */
/*
* Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -72,7 +72,6 @@ lka_imsg(struct smtpd *env, struct imsgev *iev, struct imsg *imsg)
struct lkasession *s;
struct secret *secret;
struct mapel *mapel;
- struct cond *cond;
struct rule *rule;
struct path *path;
struct map *map;
@@ -168,19 +167,9 @@ lka_imsg(struct smtpd *env, struct imsgev *iev, struct imsg *imsg)
if (rule == NULL)
fatal(NULL);
*rule = *(struct rule *)imsg->data;
- TAILQ_INIT(&rule->r_conditions);
TAILQ_INSERT_TAIL(env->sc_rules_reload, rule, r_entry);
return;
- case IMSG_CONF_CONDITION:
- rule = TAILQ_LAST(env->sc_rules_reload, rulelist);
- cond = calloc(1, sizeof *cond);
- if (cond == NULL)
- fatal(NULL);
- *cond = *(struct cond *)imsg->data;
- TAILQ_INSERT_TAIL(&rule->r_conditions, cond, c_entry);
- return;
-
case IMSG_CONF_MAP:
map = calloc(1, sizeof *map);
if (map == NULL)
@@ -677,14 +666,14 @@ done:
int
lka_resolve_path(struct smtpd *env, struct lkasession *lkasession, struct path *path)
{
- if (IS_RELAY(*path) || path->cond == NULL) {
+ if (IS_RELAY(*path)) {
path = path_dup(path);
path->flags |= F_PATH_RELAY;
TAILQ_INSERT_TAIL(&lkasession->deliverylist, path, entry);
return 1;
}
- switch (path->cond->c_type) {
+ switch (path->rule.r_condition.c_type) {
case C_ALL:
case C_NET:
case C_DOM: {
@@ -725,9 +714,9 @@ lka_resolve_path(struct smtpd *env, struct lkasession *lkasession, struct path *
return 1;
}
case C_VDOM: {
- if (aliases_virtual_exist(env, path->cond->c_map, path)) {
+ if (aliases_virtual_exist(env, path->rule.r_condition.c_map, path)) {
path->flags |= F_PATH_VIRTUAL;
- if (! aliases_virtual_get(env, path->cond->c_map,
+ if (! aliases_virtual_get(env, path->rule.r_condition.c_map,
&lkasession->expandtree, path))
return 0;
return 1;
diff --git a/usr.sbin/smtpd/parse.y b/usr.sbin/smtpd/parse.y
index 64b94fd28d3..5aece32fd7e 100644
--- a/usr.sbin/smtpd/parse.y
+++ b/usr.sbin/smtpd/parse.y
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.y,v 1.58 2010/05/27 11:17:29 gilles Exp $ */
+/* $OpenBSD: parse.y,v 1.59 2010/05/27 15:36:04 gilles Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -89,6 +89,7 @@ static int errors = 0;
objid_t last_map_id = 1;
struct map *map = NULL;
struct rule *rule = NULL;
+TAILQ_HEAD(condlist, cond) *conditions = NULL;
struct mapel_list *contents = NULL;
struct listener *host_v4(const char *, in_port_t);
@@ -785,15 +786,15 @@ condition : NETWORK mapref {
;
condition_list : condition comma condition_list {
- TAILQ_INSERT_TAIL(&rule->r_conditions, $1, c_entry);
+ TAILQ_INSERT_TAIL(conditions, $1, c_entry);
}
| condition {
- TAILQ_INSERT_TAIL(&rule->r_conditions, $1, c_entry);
+ TAILQ_INSERT_TAIL(conditions, $1, c_entry);
}
;
conditions : condition {
- TAILQ_INSERT_TAIL(&rule->r_conditions, $1, c_entry);
+ TAILQ_INSERT_TAIL(conditions, $1, c_entry);
}
| '{' condition_list '}'
;
@@ -968,21 +969,45 @@ on : ON STRING {
| /* empty */ { $$ = NULL; }
rule : decision on from {
- struct rule *r;
- if ((r = calloc(1, sizeof(*r))) == NULL)
+ if ((rule = calloc(1, sizeof(*rule))) == NULL)
fatal("out of memory");
- rule = r;
rule->r_sources = map_find(conf, $3);
+
+ if ((conditions = calloc(1, sizeof(*conditions))) == NULL)
+ fatal("out of memory");
+
if ($2)
(void)strlcpy(rule->r_tag, $2, sizeof(rule->r_tag));
free($2);
- TAILQ_INIT(&rule->r_conditions);
+
+ TAILQ_INIT(conditions);
} FOR conditions action tag {
- TAILQ_INSERT_TAIL(conf->sc_rules, rule, r_entry);
+ struct rule *subr;
+ struct cond *cond;
+
+ while ((cond = TAILQ_FIRST(conditions)) != NULL) {
+
+ if ((subr = calloc(1, sizeof(*subr))) == NULL)
+ fatal("out of memory");
+
+ *subr = *rule;
+
+ subr->r_condition = *cond;
+
+ TAILQ_REMOVE(conditions, cond, c_entry);
+ TAILQ_INSERT_TAIL(conf->sc_rules, subr, r_entry);
+
+ free(cond);
+ }
+
+ free(conditions);
+ free(rule);
+ conditions = NULL;
+ rule = NULL;
}
;
%%
diff --git a/usr.sbin/smtpd/ruleset.c b/usr.sbin/smtpd/ruleset.c
index 16d850f9222..823aeda252b 100644
--- a/usr.sbin/smtpd/ruleset.c
+++ b/usr.sbin/smtpd/ruleset.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ruleset.c,v 1.12 2010/04/21 19:53:16 gilles Exp $ */
+/* $OpenBSD: ruleset.c,v 1.13 2010/05/27 15:36:04 gilles Exp $ */
/*
* Copyright (c) 2009 Gilles Chehade <gilles@openbsd.org>
@@ -45,7 +45,6 @@ struct rule *
ruleset_match(struct smtpd *env, char *tag, struct path *path, struct sockaddr_storage *ss)
{
struct rule *r;
- struct cond *cond;
struct map *map;
struct mapel *me;
@@ -59,45 +58,34 @@ ruleset_match(struct smtpd *env, char *tag, struct path *path, struct sockaddr_s
! ruleset_check_source(r->r_sources, ss)))
continue;
- TAILQ_FOREACH(cond, &r->r_conditions, c_entry) {
- if (cond->c_type == C_ALL) {
- path->cond = cond;
- return r;
- }
+ if (r->r_condition.c_type == C_ALL)
+ return r;
- if (cond->c_type == C_DOM) {
- map = map_find(env, cond->c_map);
- if (map == NULL)
- fatal("failed to lookup map.");
-
- switch (map->m_src) {
- case S_NONE:
- TAILQ_FOREACH(me, &map->m_contents, me_entry) {
- if (hostname_match(path->domain, me->me_key.med_string)) {
- path->cond = cond;
- return r;
- }
- }
- break;
- case S_DB:
- if (map_lookup(env, map->m_id, path->domain, K_VIRTUAL) != NULL) {
- path->cond = cond;
+ if (r->r_condition.c_type == C_DOM) {
+ map = map_find(env, r->r_condition.c_map);
+ if (map == NULL)
+ fatal("failed to lookup map.");
+
+ switch (map->m_src) {
+ case S_NONE:
+ TAILQ_FOREACH(me, &map->m_contents, me_entry) {
+ if (hostname_match(path->domain, me->me_key.med_string))
return r;
- }
- break;
- default:
- log_info("unsupported map source for domain map");
- continue;
}
- }
-
- if (cond->c_type == C_VDOM) {
- if (aliases_vdomain_exists(env, cond->c_map, path->domain)) {
- path->cond = cond;
+ break;
+ case S_DB:
+ if (map_lookup(env, map->m_id, path->domain, K_VIRTUAL) != NULL)
return r;
- }
+ break;
+ default:
+ log_info("unsupported map source for domain map");
+ continue;
}
}
+
+ if (r->r_condition.c_type == C_VDOM)
+ if (aliases_vdomain_exists(env, r->r_condition.c_map, path->domain))
+ return r;
}
return NULL;
diff --git a/usr.sbin/smtpd/smtpd.c b/usr.sbin/smtpd/smtpd.c
index 97c73c658aa..8a15293cafc 100644
--- a/usr.sbin/smtpd/smtpd.c
+++ b/usr.sbin/smtpd/smtpd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtpd.c,v 1.106 2010/05/23 18:44:14 jacekm Exp $ */
+/* $OpenBSD: smtpd.c,v 1.107 2010/05/27 15:36:04 gilles Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -297,7 +297,6 @@ void
parent_send_config_ruleset(struct smtpd *env, int proc)
{
struct rule *r;
- struct cond *cond;
struct map *m;
struct mapel *mapel;
@@ -319,10 +318,6 @@ parent_send_config_ruleset(struct smtpd *env, int proc)
0, 0, -1, r, sizeof(*r));
imsg_compose_event(env->sc_ievs[proc], IMSG_CONF_RULE_SOURCE,
0, 0, -1, &r->r_sources->m_name, sizeof(r->r_sources->m_name));
- TAILQ_FOREACH(cond, &r->r_conditions, c_entry) {
- imsg_compose_event(env->sc_ievs[proc], IMSG_CONF_CONDITION,
- 0, 0, -1, cond, sizeof(*cond));
- }
}
imsg_compose_event(env->sc_ievs[proc], IMSG_CONF_END,
diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h
index 421a38cba2c..2332081ccc1 100644
--- a/usr.sbin/smtpd/smtpd.h
+++ b/usr.sbin/smtpd/smtpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtpd.h,v 1.184 2010/05/27 11:18:34 gilles Exp $ */
+/* $OpenBSD: smtpd.h,v 1.185 2010/05/27 15:36:04 gilles Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -330,7 +330,7 @@ struct rule {
char r_tag[MAX_TAG_SIZE];
int r_accept;
struct map *r_sources;
- TAILQ_HEAD(condlist, cond) r_conditions;
+ struct cond r_condition;
enum action_type r_action;
union rule_dest {
char path[MAXPATHLEN];
@@ -369,7 +369,6 @@ union path_data {
struct path {
TAILQ_ENTRY(path) entry;
struct rule rule;
- struct cond *cond;
enum path_flags flags;
u_int8_t forwardcnt;
char user[MAX_LOCALPART_SIZE];