summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Faurot <eric@cvs.openbsd.org>2018-12-26 15:55:10 +0000
committerEric Faurot <eric@cvs.openbsd.org>2018-12-26 15:55:10 +0000
commite354dc1750d5e909fcfeb1819c3368790bd4aec4 (patch)
tree1bdbf6f8ce36cfc6f8f983d1e673b041b546c812
parente12d3163209e0951eeb7d3174dcf45e369092016 (diff)
introduce a table_match() function to check for a key in a table
ok gilles@
-rw-r--r--usr.sbin/smtpd/lka_filter.c22
-rw-r--r--usr.sbin/smtpd/ruleset.c33
-rw-r--r--usr.sbin/smtpd/smtpd.h3
-rw-r--r--usr.sbin/smtpd/table.c8
4 files changed, 28 insertions, 38 deletions
diff --git a/usr.sbin/smtpd/lka_filter.c b/usr.sbin/smtpd/lka_filter.c
index 35fc0bc31cc..eeba23e2453 100644
--- a/usr.sbin/smtpd/lka_filter.c
+++ b/usr.sbin/smtpd/lka_filter.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: lka_filter.c,v 1.32 2018/12/26 14:15:12 eric Exp $ */
+/* $OpenBSD: lka_filter.c,v 1.33 2018/12/26 15:55:09 eric Exp $ */
/*
* Copyright (c) 2018 Gilles Chehade <gilles@poolp.org>
@@ -806,7 +806,7 @@ filter_check_rdns_table(struct filter *filter, enum table_service kind, const ch
if (filter->config->rdns_table == NULL)
return 0;
- if (table_lookup(filter->config->rdns_table, key, kind, NULL) > 0)
+ if (table_match(filter->config->rdns_table, kind, key) > 0)
ret = 1;
return filter->config->not_rdns_table < 0 ? !ret : ret;
@@ -820,7 +820,7 @@ filter_check_rdns_regex(struct filter *filter, const char *key)
if (filter->config->rdns_regex == NULL)
return 0;
- if (table_lookup(filter->config->rdns_regex, key, K_REGEX, NULL) > 0)
+ if (table_match(filter->config->rdns_regex, K_REGEX, key) > 0)
ret = 1;
return filter->config->not_rdns_regex < 0 ? !ret : ret;
}
@@ -833,7 +833,7 @@ filter_check_src_table(struct filter *filter, enum table_service kind, const cha
if (filter->config->src_table == NULL)
return 0;
- if (table_lookup(filter->config->src_table, key, kind, NULL) > 0)
+ if (table_match(filter->config->src_table, kind, key) > 0)
ret = 1;
return filter->config->not_src_table < 0 ? !ret : ret;
}
@@ -846,7 +846,7 @@ filter_check_src_regex(struct filter *filter, const char *key)
if (filter->config->src_regex == NULL)
return 0;
- if (table_lookup(filter->config->src_regex, key, K_REGEX, NULL) > 0)
+ if (table_match(filter->config->src_regex, K_REGEX, key) > 0)
ret = 1;
return filter->config->not_src_regex < 0 ? !ret : ret;
}
@@ -859,7 +859,7 @@ filter_check_helo_table(struct filter *filter, enum table_service kind, const ch
if (filter->config->helo_table == NULL)
return 0;
- if (table_lookup(filter->config->helo_table, key, kind, NULL) > 0)
+ if (table_match(filter->config->helo_table, kind, key) > 0)
ret = 1;
return filter->config->not_helo_table < 0 ? !ret : ret;
}
@@ -872,7 +872,7 @@ filter_check_helo_regex(struct filter *filter, const char *key)
if (filter->config->helo_regex == NULL)
return 0;
- if (table_lookup(filter->config->helo_regex, key, K_REGEX, NULL) > 0)
+ if (table_match(filter->config->helo_regex, K_REGEX, key) > 0)
ret = 1;
return filter->config->not_helo_regex < 0 ? !ret : ret;
}
@@ -885,7 +885,7 @@ filter_check_mail_from_table(struct filter *filter, enum table_service kind, con
if (filter->config->mail_from_table == NULL)
return 0;
- if (table_lookup(filter->config->mail_from_table, key, kind, NULL) > 0)
+ if (table_match(filter->config->mail_from_table, kind, key) > 0)
ret = 1;
return filter->config->not_mail_from_table < 0 ? !ret : ret;
}
@@ -898,7 +898,7 @@ filter_check_mail_from_regex(struct filter *filter, const char *key)
if (filter->config->mail_from_regex == NULL)
return 0;
- if (table_lookup(filter->config->mail_from_regex, key, K_REGEX, NULL) > 0)
+ if (table_match(filter->config->mail_from_regex, K_REGEX, key) > 0)
ret = 1;
return filter->config->not_mail_from_regex < 0 ? !ret : ret;
}
@@ -911,7 +911,7 @@ filter_check_rcpt_to_table(struct filter *filter, enum table_service kind, const
if (filter->config->rcpt_to_table == NULL)
return 0;
- if (table_lookup(filter->config->rcpt_to_table, key, kind, NULL) > 0)
+ if (table_match(filter->config->rcpt_to_table, kind, key) > 0)
ret = 1;
return filter->config->not_rcpt_to_table < 0 ? !ret : ret;
}
@@ -924,7 +924,7 @@ filter_check_rcpt_to_regex(struct filter *filter, const char *key)
if (filter->config->rcpt_to_regex == NULL)
return 0;
- if (table_lookup(filter->config->rcpt_to_regex, key, K_REGEX, NULL) > 0)
+ if (table_match(filter->config->rcpt_to_regex, K_REGEX, key) > 0)
ret = 1;
return filter->config->not_rcpt_to_regex < 0 ? !ret : ret;
}
diff --git a/usr.sbin/smtpd/ruleset.c b/usr.sbin/smtpd/ruleset.c
index 1239f927876..5af1b042e9b 100644
--- a/usr.sbin/smtpd/ruleset.c
+++ b/usr.sbin/smtpd/ruleset.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ruleset.c,v 1.39 2018/12/26 14:15:12 eric Exp $ */
+/* $OpenBSD: ruleset.c,v 1.40 2018/12/26 15:55:09 eric Exp $ */
/*
* Copyright (c) 2009 Gilles Chehade <gilles@poolp.org>
@@ -35,22 +35,6 @@
static int
-ruleset_match_table_lookup(struct table *table, const char *key, enum table_service service)
-{
- switch (table_lookup(table, key, service, NULL)) {
- case 1:
- return 1;
- case -1:
- log_warnx("warn: failure to perform a table lookup on table %s",
- table->t_name);
- return -1;
- default:
- break;
- }
- return 0;
-}
-
-static int
ruleset_match_tag(struct rule *r, const struct envelope *evp)
{
int ret;
@@ -64,7 +48,7 @@ ruleset_match_tag(struct rule *r, const struct envelope *evp)
service = K_REGEX;
table = table_find(env, r->table_tag, NULL);
- if ((ret = ruleset_match_table_lookup(table, evp->tag, service)) < 0)
+ if ((ret = table_match(table, service, evp->tag)) < 0)
return ret;
return r->flag_tag < 0 ? !ret : ret;
@@ -100,7 +84,7 @@ ruleset_match_from(struct rule *r, const struct envelope *evp)
service = K_REGEX;
table = table_find(env, r->table_from, NULL);
- if ((ret = ruleset_match_table_lookup(table, key, service)) < 0)
+ if ((ret = table_match(table, service, key)) < 0)
return -1;
return r->flag_from < 0 ? !ret : ret;
@@ -120,8 +104,7 @@ ruleset_match_to(struct rule *r, const struct envelope *evp)
service = K_REGEX;
table = table_find(env, r->table_for, NULL);
- if ((ret = ruleset_match_table_lookup(table, evp->dest.domain,
- service)) < 0)
+ if ((ret = table_match(table, service, evp->dest.domain)) < 0)
return -1;
return r->flag_for < 0 ? !ret : ret;
@@ -141,7 +124,7 @@ ruleset_match_smtp_helo(struct rule *r, const struct envelope *evp)
service = K_REGEX;
table = table_find(env, r->table_smtp_helo, NULL);
- if ((ret = ruleset_match_table_lookup(table, evp->helo, service)) < 0)
+ if ((ret = table_match(table, service, evp->helo)) < 0)
return -1;
return r->flag_smtp_helo < 0 ? !ret : ret;
@@ -172,7 +155,7 @@ ruleset_match_smtp_auth(struct rule *r, const struct envelope *evp)
/*
* table = table_find(m->from_table, NULL);
* key = evp->username;
- * return ruleset_match_table_lookup(table, key, K_CREDENTIALS);
+ * return table_match(table, K_CREDENTIALS, key);
*/
return -1;
@@ -201,7 +184,7 @@ ruleset_match_smtp_mail_from(struct rule *r, const struct envelope *evp)
return -1;
table = table_find(env, r->table_smtp_mail_from, NULL);
- if ((ret = ruleset_match_table_lookup(table, key, service)) < 0)
+ if ((ret = table_match(table, service, key)) < 0)
return -1;
return r->flag_smtp_mail_from < 0 ? !ret : ret;
@@ -225,7 +208,7 @@ ruleset_match_smtp_rcpt_to(struct rule *r, const struct envelope *evp)
return -1;
table = table_find(env, r->table_smtp_rcpt_to, NULL);
- if ((ret = ruleset_match_table_lookup(table, key, service)) < 0)
+ if ((ret = table_match(table, service, key)) < 0)
return -1;
return r->flag_smtp_rcpt_to < 0 ? !ret : ret;
diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h
index 6c1bdbbe0a5..b57f3812c79 100644
--- a/usr.sbin/smtpd/smtpd.h
+++ b/usr.sbin/smtpd/smtpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtpd.h,v 1.605 2018/12/26 14:15:12 eric Exp $ */
+/* $OpenBSD: smtpd.h,v 1.606 2018/12/26 15:55:09 eric Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@poolp.org>
@@ -1604,6 +1604,7 @@ void table_close(struct table *);
int table_check_use(struct table *, uint32_t, uint32_t);
int table_check_type(struct table *, uint32_t);
int table_check_service(struct table *, uint32_t);
+int table_match(struct table *, enum table_service, const char *);
int table_lookup(struct table *, const char *, enum table_service,
union lookup *);
int table_fetch(struct table *, enum table_service, union lookup *);
diff --git a/usr.sbin/smtpd/table.c b/usr.sbin/smtpd/table.c
index e4dc739d573..81f72f0db5c 100644
--- a/usr.sbin/smtpd/table.c
+++ b/usr.sbin/smtpd/table.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: table.c,v 1.36 2018/12/26 14:15:13 eric Exp $ */
+/* $OpenBSD: table.c,v 1.37 2018/12/26 15:55:09 eric Exp $ */
/*
* Copyright (c) 2013 Eric Faurot <eric@openbsd.org>
@@ -116,6 +116,12 @@ table_find(struct smtpd *conf, const char *name, const char *tag)
}
int
+table_match(struct table *table, enum table_service kind, const char *key)
+{
+ return table_lookup(table, key, kind, NULL);
+}
+
+int
table_lookup(struct table *table, const char *key, enum table_service kind,
union lookup *lk)
{