-/* $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>
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;
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
-/* $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>
#include "log.h"
-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)
{
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;
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;
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;
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;
/*
* 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;
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;
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;
-/* $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>
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 *);
-/* $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>
return dict_get(conf->sc_tables_dict, buf);
}
+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)