aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGilles Chehade <gilles@poolp.org>2019-01-03 14:41:01 +0100
committerGilles Chehade <gilles@poolp.org>2019-01-03 14:41:01 +0100
commita242a26e1295562d3162e3d7b0474026a4f8ad9f (patch)
tree776e7e023487c52a03ea1a5c306bc39b05cac7d8
parentsync (diff)
downloadOpenSMTPD-a242a26e1295562d3162e3d7b0474026a4f8ad9f.tar.xz
OpenSMTPD-a242a26e1295562d3162e3d7b0474026a4f8ad9f.zip
sync
-rw-r--r--smtpd/aliases.c10
-rw-r--r--smtpd/config.c14
-rw-r--r--smtpd/envelope.c3
-rw-r--r--smtpd/lka.c18
-rw-r--r--smtpd/lka_session.c4
-rw-r--r--smtpd/makemap.c4
-rw-r--r--smtpd/parse.y23
-rw-r--r--smtpd/queue.c3
-rw-r--r--smtpd/queue_backend.c3
-rw-r--r--smtpd/queue_fs.c3
-rw-r--r--smtpd/queue_null.c3
-rw-r--r--smtpd/queue_proc.c3
-rw-r--r--smtpd/queue_ram.c3
-rw-r--r--smtpd/ruleset.c16
-rw-r--r--smtpd/scheduler.c3
-rw-r--r--smtpd/smtp_session.c24
-rw-r--r--smtpd/smtpd.h10
-rw-r--r--smtpd/table.c106
-rw-r--r--smtpd/table_api.c348
-rw-r--r--smtpd/table_static.c199
-rw-r--r--smtpd/to.c3
21 files changed, 245 insertions, 558 deletions
diff --git a/smtpd/aliases.c b/smtpd/aliases.c
index 634aa688..884f6963 100644
--- a/smtpd/aliases.c
+++ b/smtpd/aliases.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: aliases.c,v 1.75 2018/12/26 20:13:43 eric Exp $ */
+/* $OpenBSD: aliases.c,v 1.77 2018/12/28 12:47:28 eric Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@poolp.org>
@@ -46,12 +46,10 @@ aliases_get(struct expand *expand, const char *username)
union lookup lk;
struct dispatcher *dsp;
struct table *mapping = NULL;
- struct table *userbase = NULL;
char *pbuf;
dsp = dict_xget(env->sc_dispatchers, expand->rule->dispatcher);
- userbase = table_find(env, dsp->u.local.table_userbase, NULL);
- mapping = table_find(env, dsp->u.local.table_alias, NULL);
+ mapping = table_find(env, dsp->u.local.table_alias);
xlowercase(buf, username, sizeof(buf));
@@ -104,11 +102,9 @@ aliases_virtual_get(struct expand *expand, const struct mailaddr *maddr)
int ret;
struct dispatcher *dsp;
struct table *mapping = NULL;
- struct table *userbase = NULL;
dsp = dict_xget(env->sc_dispatchers, expand->rule->dispatcher);
- userbase = table_find(env, dsp->u.local.table_userbase, NULL);
- mapping = table_find(env, dsp->u.local.table_virtual, NULL);
+ mapping = table_find(env, dsp->u.local.table_virtual);
if (!bsnprintf(user, sizeof(user), "%s", maddr->user))
return 0;
diff --git a/smtpd/config.c b/smtpd/config.c
index 552803cb..8b8b8570 100644
--- a/smtpd/config.c
+++ b/smtpd/config.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: config.c,v 1.47 2018/12/21 14:33:52 gilles Exp $ */
+/* $OpenBSD: config.c,v 1.49 2018/12/28 14:21:02 eric Exp $ */
/*
* Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -133,15 +133,14 @@ config_default(void)
*/
set_local(conf, conf->sc_hostname);
- t = table_create(conf, "static", "<anydestination>", NULL, NULL);
- t->t_type = T_LIST;
+ t = table_create(conf, "static", "<anydestination>", NULL);
table_add(t, "*", NULL);
hostname[strcspn(hostname, ".")] = '\0';
if (strcmp(conf->sc_hostname, hostname) != 0)
table_add(t, hostname, NULL);
- table_create(conf, "getpwnam", "<getpwnam>", NULL, NULL);
+ table_create(conf, "getpwnam", "<getpwnam>", NULL);
return conf;
@@ -168,8 +167,7 @@ set_local(struct smtpd *conf, const char *hostname)
{
struct table *t;
- t = table_create(conf, "static", "<localnames>", NULL, NULL);
- t->t_type = T_LIST;
+ t = table_create(conf, "static", "<localnames>", NULL);
table_add(t, "localhost", NULL);
table_add(t, hostname, NULL);
@@ -186,7 +184,7 @@ set_localaddrs(struct smtpd *conf, struct table *localnames)
struct table *t;
char buf[NI_MAXHOST + 5];
- t = table_create(conf, "static", "<anyhost>", NULL, NULL);
+ t = table_create(conf, "static", "<anyhost>", NULL);
table_add(t, "local", NULL);
table_add(t, "0.0.0.0/0", NULL);
table_add(t, "::/0", NULL);
@@ -194,7 +192,7 @@ set_localaddrs(struct smtpd *conf, struct table *localnames)
if (getifaddrs(&ifap) == -1)
fatal("getifaddrs");
- t = table_create(conf, "static", "<localhost>", NULL, NULL);
+ t = table_create(conf, "static", "<localhost>", NULL);
table_add(t, "local", NULL);
for (p = ifap; p != NULL; p = p->ifa_next) {
diff --git a/smtpd/envelope.c b/smtpd/envelope.c
index 471fade2..cd247a82 100644
--- a/smtpd/envelope.c
+++ b/smtpd/envelope.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: envelope.c,v 1.41 2018/12/27 15:41:50 gilles Exp $ */
+/* $OpenBSD: envelope.c,v 1.42 2018/12/30 23:09:58 guenther Exp $ */
/*
* Copyright (c) 2013 Eric Faurot <eric@openbsd.org>
@@ -33,7 +33,6 @@
#include <fcntl.h>
#include <imsg.h>
#include <inttypes.h>
-#include <libgen.h>
#include <pwd.h>
#include <limits.h>
#include <stdio.h>
diff --git a/smtpd/lka.c b/smtpd/lka.c
index 7a6df074..9e4d8dc0 100644
--- a/smtpd/lka.c
+++ b/smtpd/lka.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: lka.c,v 1.231 2018/12/26 20:13:43 eric Exp $ */
+/* $OpenBSD: lka.c,v 1.232 2018/12/28 11:40:29 eric Exp $ */
/*
* Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -223,7 +223,7 @@ lka_imsg(struct mproc *p, struct imsg *imsg)
m_get_string(&m, &tablename);
m_end(&m);
- table = table_find(env, tablename, NULL);
+ table = table_find(env, tablename);
m_create(p, IMSG_MTA_LOOKUP_SOURCE, 0, 0, -1);
m_add_id(p, reqid);
@@ -272,7 +272,7 @@ lka_imsg(struct mproc *p, struct imsg *imsg)
m_get_string(&m, &tablename);
m_end(&m);
- table = table_find(env, tablename, NULL);
+ table = table_find(env, tablename);
m_create(p, IMSG_MTA_LOOKUP_SMARTHOST, 0, 0, -1);
m_add_id(p, reqid);
@@ -342,7 +342,7 @@ lka_imsg(struct mproc *p, struct imsg *imsg)
case IMSG_CTL_UPDATE_TABLE:
ret = 0;
- table = table_find(env, imsg->data, NULL);
+ table = table_find(env, imsg->data);
if (table == NULL) {
log_warnx("warn: Lookup table not found: "
"\"%s\"", (char *)imsg->data);
@@ -682,7 +682,7 @@ lka_authenticate(const char *tablename, const char *user, const char *password)
union lookup lk;
log_debug("debug: lka: authenticating for %s:%s", tablename, user);
- table = table_find(env, tablename, NULL);
+ table = table_find(env, tablename);
if (table == NULL) {
log_warnx("warn: could not find table %s needed for authentication",
tablename);
@@ -711,7 +711,7 @@ lka_credentials(const char *tablename, const char *label, char *dst, size_t sz)
char *buf;
int buflen, r;
- table = table_find(env, tablename, NULL);
+ table = table_find(env, tablename);
if (table == NULL) {
log_warnx("warn: credentials table %s missing", tablename);
return (LKA_TEMPFAIL);
@@ -754,7 +754,7 @@ lka_userinfo(const char *tablename, const char *username, struct userinfo *res)
union lookup lk;
log_debug("debug: lka: userinfo %s:%s", tablename, username);
- table = table_find(env, tablename, NULL);
+ table = table_find(env, tablename);
if (table == NULL) {
log_warnx("warn: cannot find user table %s", tablename);
return (LKA_TEMPFAIL);
@@ -784,7 +784,7 @@ lka_addrname(const char *tablename, const struct sockaddr *sa,
source = sa_to_text(sa);
log_debug("debug: lka: helo %s:%s", tablename, source);
- table = table_find(env, tablename, NULL);
+ table = table_find(env, tablename);
if (table == NULL) {
log_warnx("warn: cannot find helo table %s", tablename);
return (LKA_TEMPFAIL);
@@ -812,7 +812,7 @@ lka_mailaddrmap(const char *tablename, const char *username, const struct mailad
int found;
log_debug("debug: lka: mailaddrmap %s:%s", tablename, username);
- table = table_find(env, tablename, NULL);
+ table = table_find(env, tablename);
if (table == NULL) {
log_warnx("warn: cannot find mailaddrmap table %s", tablename);
return (LKA_TEMPFAIL);
diff --git a/smtpd/lka_session.c b/smtpd/lka_session.c
index ea017971..ed17adcb 100644
--- a/smtpd/lka_session.c
+++ b/smtpd/lka_session.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: lka_session.c,v 1.91 2018/12/27 15:41:50 gilles Exp $ */
+/* $OpenBSD: lka_session.c,v 1.92 2018/12/28 11:40:29 eric Exp $ */
/*
* Copyright (c) 2011 Gilles Chehade <gilles@poolp.org>
@@ -378,7 +378,7 @@ lka_expand(struct lka_session *lks, struct rule *rule, struct expandnode *xn)
(void)strlcpy(xn->subaddress, tag, sizeof xn->subaddress);
}
- userbase = table_find(env, dsp->u.local.table_userbase, NULL);
+ userbase = table_find(env, dsp->u.local.table_userbase);
r = table_lookup(userbase, K_USERINFO, xn->u.user, &lk);
if (r == -1) {
log_trace(TRACE_EXPAND, "expand: lka_expand: "
diff --git a/smtpd/makemap.c b/smtpd/makemap.c
index 51c475e6..dd8bc8d3 100644
--- a/smtpd/makemap.c
+++ b/smtpd/makemap.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: makemap.c,v 1.71 2018/07/03 01:34:43 mortimer Exp $ */
+/* $OpenBSD: makemap.c,v 1.72 2018/12/28 11:40:29 eric Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@poolp.org>
@@ -444,7 +444,7 @@ conf_aliases(char *cfgpath)
if (parse_config(env, cfgpath, 0))
exit(1);
- table = table_find(env, "aliases", NULL);
+ table = table_find(env, "aliases");
if (table == NULL)
return (PATH_ALIASES);
diff --git a/smtpd/parse.y b/smtpd/parse.y
index bb88aa37..33159dec 100644
--- a/smtpd/parse.y
+++ b/smtpd/parse.y
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.y,v 1.248 2018/12/23 15:49:04 gilles Exp $ */
+/* $OpenBSD: parse.y,v 1.250 2018/12/28 14:21:02 eric Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@poolp.org>
@@ -278,7 +278,6 @@ assign : '=' | ARROW;
keyval : STRING assign STRING {
- table->t_type = T_HASH;
table_add(table, $1, $3);
free($1);
free($3);
@@ -290,7 +289,6 @@ keyval_list : keyval
;
stringel : STRING {
- table->t_type = T_LIST;
table_add(table, $1, NULL);
free($1);
}
@@ -1092,7 +1090,7 @@ negation TAG REGEX tables {
rule->flag_from_socket = 1;
}
| negation FROM LOCAL {
- struct table *t = table_find(conf, "<localhost>", NULL);
+ struct table *t = table_find(conf, "<localhost>");
if (rule->flag_from) {
yyerror("from already specified for this rule");
@@ -1102,7 +1100,7 @@ negation TAG REGEX tables {
rule->table_from = strdup(t->t_name);
}
| negation FROM ANY {
- struct table *t = table_find(conf, "<anyhost>", NULL);
+ struct table *t = table_find(conf, "<anyhost>");
if (rule->flag_from) {
yyerror("from already specified for this rule");
@@ -1187,7 +1185,7 @@ negation TAG REGEX tables {
| negation FOR LOCAL {
- struct table *t = table_find(conf, "<localnames>", NULL);
+ struct table *t = table_find(conf, "<localnames>");
if (rule->flag_for) {
yyerror("for already specified for this rule");
@@ -1197,7 +1195,7 @@ negation TAG REGEX tables {
rule->table_for = strdup(t->t_name);
}
| negation FOR ANY {
- struct table *t = table_find(conf, "<anydestination>", NULL);
+ struct table *t = table_find(conf, "<anydestination>");
if (rule->flag_for) {
yyerror("for already specified for this rule");
@@ -2153,7 +2151,7 @@ table : TABLE STRING STRING {
free($3);
YYERROR;
}
- table = table_create(conf, backend, $2, NULL, config);
+ table = table_create(conf, backend, $2, config);
if (!table_config(table)) {
yyerror("invalid configuration file %s for table %s",
config, table->t_name);
@@ -2166,7 +2164,7 @@ table : TABLE STRING STRING {
free($3);
}
| TABLE STRING {
- table = table_create(conf, "static", $2, NULL, NULL);
+ table = table_create(conf, "static", $2, NULL);
free($2);
} '{' tableval_list '}' {
table = NULL;
@@ -2176,14 +2174,13 @@ table : TABLE STRING STRING {
tablenew : STRING {
struct table *t;
- t = table_create(conf, "static", NULL, NULL, NULL);
- t->t_type = T_LIST;
+ t = table_create(conf, "static", NULL, NULL);
table_add(t, $1, NULL);
free($1);
$$ = t;
}
| '{' {
- table = table_create(conf, "static", NULL, NULL, NULL);
+ table = table_create(conf, "static", NULL, NULL);
} tableval_list '}' {
$$ = table;
table = NULL;
@@ -2193,7 +2190,7 @@ tablenew : STRING {
tableref : '<' STRING '>' {
struct table *t;
- if ((t = table_find(conf, $2, NULL)) == NULL) {
+ if ((t = table_find(conf, $2)) == NULL) {
yyerror("no such table: %s", $2);
free($2);
YYERROR;
diff --git a/smtpd/queue.c b/smtpd/queue.c
index 489069ec..8380c7b5 100644
--- a/smtpd/queue.c
+++ b/smtpd/queue.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: queue.c,v 1.188 2018/12/08 08:01:15 sunil Exp $ */
+/* $OpenBSD: queue.c,v 1.189 2018/12/30 23:09:58 guenther Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@poolp.org>
@@ -28,7 +28,6 @@
#include <event.h>
#include <imsg.h>
#include <inttypes.h>
-#include <libgen.h>
#include <pwd.h>
#include <signal.h>
#include <stdio.h>
diff --git a/smtpd/queue_backend.c b/smtpd/queue_backend.c
index 4337051e..5e7c38fa 100644
--- a/smtpd/queue_backend.c
+++ b/smtpd/queue_backend.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: queue_backend.c,v 1.64 2018/05/31 21:06:12 gilles Exp $ */
+/* $OpenBSD: queue_backend.c,v 1.65 2018/12/30 23:09:58 guenther Exp $ */
/*
* Copyright (c) 2011 Gilles Chehade <gilles@poolp.org>
@@ -31,7 +31,6 @@
#include <imsg.h>
#include <limits.h>
#include <inttypes.h>
-#include <libgen.h>
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
diff --git a/smtpd/queue_fs.c b/smtpd/queue_fs.c
index 5960663f..ecbc53a8 100644
--- a/smtpd/queue_fs.c
+++ b/smtpd/queue_fs.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: queue_fs.c,v 1.17 2018/05/31 21:06:12 gilles Exp $ */
+/* $OpenBSD: queue_fs.c,v 1.18 2018/12/30 23:09:58 guenther Exp $ */
/*
* Copyright (c) 2011 Gilles Chehade <gilles@poolp.org>
@@ -32,7 +32,6 @@
#include <fts.h>
#include <imsg.h>
#include <inttypes.h>
-#include <libgen.h>
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
diff --git a/smtpd/queue_null.c b/smtpd/queue_null.c
index c555e41d..d92f98a7 100644
--- a/smtpd/queue_null.c
+++ b/smtpd/queue_null.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: queue_null.c,v 1.7 2018/05/14 15:23:05 gilles Exp $ */
+/* $OpenBSD: queue_null.c,v 1.8 2018/12/30 23:09:58 guenther Exp $ */
/*
* Copyright (c) 2012 Eric Faurot <eric@openbsd.org>
@@ -29,7 +29,6 @@
#include <fcntl.h>
#include <imsg.h>
#include <inttypes.h>
-#include <libgen.h>
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
diff --git a/smtpd/queue_proc.c b/smtpd/queue_proc.c
index 2c4beb4c..753271c1 100644
--- a/smtpd/queue_proc.c
+++ b/smtpd/queue_proc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: queue_proc.c,v 1.7 2018/05/14 15:23:05 gilles Exp $ */
+/* $OpenBSD: queue_proc.c,v 1.8 2018/12/30 23:09:58 guenther Exp $ */
/*
* Copyright (c) 2013 Eric Faurot <eric@openbsd.org>
@@ -28,7 +28,6 @@
#include <fcntl.h>
#include <imsg.h>
#include <inttypes.h>
-#include <libgen.h>
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
diff --git a/smtpd/queue_ram.c b/smtpd/queue_ram.c
index 81689f7b..56b9fa5b 100644
--- a/smtpd/queue_ram.c
+++ b/smtpd/queue_ram.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: queue_ram.c,v 1.8 2018/05/14 15:23:05 gilles Exp $ */
+/* $OpenBSD: queue_ram.c,v 1.9 2018/12/30 23:09:58 guenther Exp $ */
/*
* Copyright (c) 2012 Eric Faurot <eric@openbsd.org>
@@ -29,7 +29,6 @@
#include <fcntl.h>
#include <imsg.h>
#include <inttypes.h>
-#include <libgen.h>
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
diff --git a/smtpd/ruleset.c b/smtpd/ruleset.c
index 0d16d85d..237feae1 100644
--- a/smtpd/ruleset.c
+++ b/smtpd/ruleset.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ruleset.c,v 1.41 2018/12/26 17:37:15 eric Exp $ */
+/* $OpenBSD: ruleset.c,v 1.42 2018/12/28 11:40:29 eric Exp $ */
/*
* Copyright (c) 2009 Gilles Chehade <gilles@poolp.org>
@@ -48,7 +48,7 @@ ruleset_match_tag(struct rule *r, const struct envelope *evp)
if (r->flag_tag_regex)
service = K_REGEX;
- table = table_find(env, r->table_tag, NULL);
+ table = table_find(env, r->table_tag);
ret = table_match(table, service, evp->tag);
return MATCH_RESULT(ret, r->flag_tag);
@@ -83,7 +83,7 @@ ruleset_match_from(struct rule *r, const struct envelope *evp)
if (r->flag_from_regex)
service = K_REGEX;
- table = table_find(env, r->table_from, NULL);
+ table = table_find(env, r->table_from);
ret = table_match(table, service, key);
return MATCH_RESULT(ret, r->flag_from);
@@ -102,7 +102,7 @@ ruleset_match_to(struct rule *r, const struct envelope *evp)
if (r->flag_for_regex)
service = K_REGEX;
- table = table_find(env, r->table_for, NULL);
+ table = table_find(env, r->table_for);
ret = table_match(table, service, evp->dest.domain);
return MATCH_RESULT(ret, r->flag_for);
@@ -121,7 +121,7 @@ ruleset_match_smtp_helo(struct rule *r, const struct envelope *evp)
if (r->flag_smtp_helo_regex)
service = K_REGEX;
- table = table_find(env, r->table_smtp_helo, NULL);
+ table = table_find(env, r->table_smtp_helo);
ret = table_match(table, service, evp->helo);
return MATCH_RESULT(ret, r->flag_smtp_helo);
@@ -150,7 +150,7 @@ ruleset_match_smtp_auth(struct rule *r, const struct envelope *evp)
else if (r->table_smtp_auth) {
/* XXX - not until smtp_session->username is added to envelope */
/*
- * table = table_find(m->from_table, NULL);
+ * table = table_find(m->from_table);
* key = evp->username;
* return table_match(table, K_CREDENTIALS, key);
*/
@@ -180,7 +180,7 @@ ruleset_match_smtp_mail_from(struct rule *r, const struct envelope *evp)
if ((key = mailaddr_to_text(&evp->sender)) == NULL)
return -1;
- table = table_find(env, r->table_smtp_mail_from, NULL);
+ table = table_find(env, r->table_smtp_mail_from);
ret = table_match(table, service, key);
return MATCH_RESULT(ret, r->flag_smtp_mail_from);
@@ -203,7 +203,7 @@ ruleset_match_smtp_rcpt_to(struct rule *r, const struct envelope *evp)
if ((key = mailaddr_to_text(&evp->dest)) == NULL)
return -1;
- table = table_find(env, r->table_smtp_rcpt_to, NULL);
+ table = table_find(env, r->table_smtp_rcpt_to);
ret = table_match(table, service, key);
return MATCH_RESULT(ret, r->flag_smtp_rcpt_to);
diff --git a/smtpd/scheduler.c b/smtpd/scheduler.c
index de21342e..b3bda175 100644
--- a/smtpd/scheduler.c
+++ b/smtpd/scheduler.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: scheduler.c,v 1.59 2018/12/08 08:01:15 sunil Exp $ */
+/* $OpenBSD: scheduler.c,v 1.60 2018/12/30 23:09:58 guenther Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@poolp.org>
@@ -32,7 +32,6 @@
#include <event.h>
#include <imsg.h>
#include <inttypes.h>
-#include <libgen.h>
#include <pwd.h>
#include <signal.h>
#include <stdio.h>
diff --git a/smtpd/smtp_session.c b/smtpd/smtp_session.c
index 5368a5c4..a8c0e13a 100644
--- a/smtpd/smtp_session.c
+++ b/smtpd/smtp_session.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtp_session.c,v 1.382 2018/12/28 07:29:49 gilles Exp $ */
+/* $OpenBSD: smtp_session.c,v 1.383 2018/12/28 11:35:25 gilles Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@poolp.org>
@@ -134,7 +134,7 @@ struct smtp_session {
struct listener *listener;
void *ssl_ctx;
struct sockaddr_storage ss;
- char hostname[HOST_NAME_MAX+1];
+ char rdns[HOST_NAME_MAX+1];
char smtpname[HOST_NAME_MAX+1];
int fcrdns;
@@ -607,7 +607,7 @@ smtp_session(struct listener *listener, int sock,
/* A bit of a hack */
if (!strcmp(hostname, "localhost"))
s->flags |= SF_BOUNCE;
- (void)strlcpy(s->hostname, hostname, sizeof(s->hostname));
+ (void)strlcpy(s->rdns, hostname, sizeof(s->rdns));
s->fcrdns = 1;
smtp_lookup_servername(s);
} else {
@@ -629,7 +629,7 @@ smtp_getnameinfo_cb(void *arg, int gaierrno, const char *host, const char *serv)
if (gaierrno) {
log_warnx("getnameinfo: %s: %s", ss_to_text(&s->ss),
gai_strerror(gaierrno));
- (void)strlcpy(s->hostname, "<unknown>", sizeof(s->hostname));
+ (void)strlcpy(s->rdns, "<unknown>", sizeof(s->rdns));
if (gaierrno == EAI_NODATA || gaierrno == EAI_NONAME)
s->fcrdns = 0;
@@ -640,12 +640,12 @@ smtp_getnameinfo_cb(void *arg, int gaierrno, const char *host, const char *serv)
return;
}
- (void)strlcpy(s->hostname, host, sizeof(s->hostname));
+ (void)strlcpy(s->rdns, host, sizeof(s->rdns));
memset(&hints, 0, sizeof(hints));
hints.ai_family = s->ss.ss_family;
hints.ai_socktype = SOCK_STREAM;
- resolver_getaddrinfo(s->hostname, NULL, &hints, smtp_getaddrinfo_cb, s);
+ resolver_getaddrinfo(s->rdns, NULL, &hints, smtp_getaddrinfo_cb, s);
}
static void
@@ -656,7 +656,7 @@ smtp_getaddrinfo_cb(void *arg, int gaierrno, struct addrinfo *ai0)
char fwd[64], rev[64];
if (gaierrno) {
- log_warnx("getaddrinfo: %s: %s", s->hostname,
+ log_warnx("getaddrinfo: %s: %s", s->rdns,
gai_strerror(gaierrno));
if (gaierrno == EAI_NODATA || gaierrno == EAI_NONAME)
@@ -1606,7 +1606,7 @@ smtp_filter_begin(struct smtp_session *s)
m_add_string(p_lka, s->listener->filter_name);
m_add_sockaddr(p_lka, (struct sockaddr *)&s->ss);
m_add_sockaddr(p_lka, (struct sockaddr *)&s->listener->ss);
- m_add_string(p_lka, s->hostname);
+ m_add_string(p_lka, s->rdns);
m_add_int(p_lka, s->fcrdns);
m_close(p_lka);
}
@@ -1971,11 +1971,11 @@ smtp_connected(struct smtp_session *s)
smtp_enter_state(s, STATE_CONNECTED);
log_info("%016"PRIx64" smtp connected address=%s host=%s",
- s->id, ss_to_text(&s->ss), s->hostname);
+ s->id, ss_to_text(&s->ss), s->rdns);
smtp_filter_begin(s);
- report_smtp_link_connect("smtp-in", s->id, s->hostname, s->fcrdns, &s->ss,
+ report_smtp_link_connect("smtp-in", s->id, s->rdns, s->fcrdns, &s->ss,
&s->listener->ss);
smtp_filter_phase(FILTER_CONNECT, s, ss_to_text(&s->ss));
@@ -2309,7 +2309,7 @@ smtp_tx(struct smtp_session *s)
tx->evp.ss = s->ss;
(void)strlcpy(tx->evp.tag, s->listener->tag, sizeof(tx->evp.tag));
(void)strlcpy(tx->evp.smtpname, s->smtpname, sizeof(tx->evp.smtpname));
- (void)strlcpy(tx->evp.hostname, s->hostname, sizeof tx->evp.hostname);
+ (void)strlcpy(tx->evp.hostname, s->rdns, sizeof tx->evp.hostname);
(void)strlcpy(tx->evp.helo, s->helo, sizeof(tx->evp.helo));
if (s->flags & SF_BOUNCE)
@@ -2781,7 +2781,7 @@ smtp_message_begin(struct smtp_tx *tx)
if (!(s->listener->flags & F_MASK_SOURCE)) {
m_printf(tx, "from %s (%s [%s])",
s->helo,
- s->hostname,
+ s->rdns,
ss_to_text(&s->ss));
}
m_printf(tx, "\n\tby %s (%s) with %sSMTP%s%s id %08x",
diff --git a/smtpd/smtpd.h b/smtpd/smtpd.h
index 36a8d9fb..71af6b19 100644
--- a/smtpd/smtpd.h
+++ b/smtpd/smtpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtpd.h,v 1.612 2018/12/27 15:41:50 gilles Exp $ */
+/* $OpenBSD: smtpd.h,v 1.615 2018/12/28 15:09:28 eric Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@poolp.org>
@@ -354,11 +354,8 @@ struct table {
enum table_type t_type;
char t_config[PATH_MAX];
- struct dict t_dict;
-
void *t_handle;
struct table_backend *t_backend;
- void *t_iter;
};
struct table_backend {
@@ -1599,13 +1596,14 @@ struct stat_value *stat_timespec(struct timespec *);
/* table.c */
-struct table *table_find(struct smtpd *, const char *, const char *);
-struct table *table_create(struct smtpd *, const char *, const char *, const char *,
+struct table *table_find(struct smtpd *, const char *);
+struct table *table_create(struct smtpd *, const char *, const char *,
const char *);
int table_config(struct table *);
int table_open(struct table *);
int table_update(struct table *);
void table_close(struct table *);
+void table_dump(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);
diff --git a/smtpd/table.c b/smtpd/table.c
index 397d850e..7b1fcd2a 100644
--- a/smtpd/table.c
+++ b/smtpd/table.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: table.c,v 1.43 2018/12/27 15:04:59 eric Exp $ */
+/* $OpenBSD: table.c,v 1.47 2018/12/28 15:09:28 eric Exp $ */
/*
* Copyright (c) 2013 Eric Faurot <eric@openbsd.org>
@@ -100,19 +100,9 @@ table_service_name(enum table_service s)
}
struct table *
-table_find(struct smtpd *conf, const char *name, const char *tag)
+table_find(struct smtpd *conf, const char *name)
{
- char buf[LINE_MAX];
-
- if (tag == NULL)
- return dict_get(conf->sc_tables_dict, name);
-
- if ((size_t)snprintf(buf, sizeof(buf), "%s#%s", name, tag) >= sizeof(buf)) {
- log_warnx("warn: table name too long: %s#%s", name, tag);
- return (NULL);
- }
-
- return dict_get(conf->sc_tables_dict, buf);
+ return dict_get(conf->sc_tables_dict, name);
}
int
@@ -197,25 +187,16 @@ table_fetch(struct table *table, enum table_service kind, union lookup *lk)
}
struct table *
-table_create(struct smtpd *conf, const char *backend, const char *name, const char *tag,
+table_create(struct smtpd *conf, const char *backend, const char *name,
const char *config)
{
struct table *t;
struct table_backend *tb;
- char buf[LINE_MAX];
char path[LINE_MAX];
size_t n;
struct stat sb;
- if (name && tag) {
- if ((size_t)snprintf(buf, sizeof(buf), "%s#%s", name, tag) >=
- sizeof(buf))
- fatalx("table_create: name too long \"%s#%s\"",
- name, tag);
- name = buf;
- }
-
- if (name && table_find(conf, name, NULL))
+ if (name && table_find(conf, name))
fatalx("table_create: table \"%s\" already defined", name);
if ((tb = table_backend_lookup(backend)) == NULL) {
@@ -243,13 +224,6 @@ table_create(struct smtpd *conf, const char *backend, const char *name, const ch
t = xcalloc(1, sizeof(*t));
t->t_backend = tb;
- /* XXX */
- /*
- * until people forget about it, "file" really means "static"
- */
- if (!strcmp(backend, "file"))
- backend = "static";
-
if (config) {
if (strlcpy(t->t_config, config, sizeof t->t_config)
>= sizeof t->t_config)
@@ -257,7 +231,7 @@ table_create(struct smtpd *conf, const char *backend, const char *name, const ch
t->t_config);
}
- if (strcmp(backend, "static") != 0)
+ if (strcmp(tb->name, "static") != 0)
t->t_type = T_DYNAMIC;
if (name == NULL)
@@ -269,7 +243,6 @@ table_create(struct smtpd *conf, const char *backend, const char *name, const ch
fatalx("table_create: table name too long");
}
- dict_init(&t->t_dict);
dict_set(conf->sc_tables_dict, t->t_name, t);
return (t);
@@ -278,11 +251,6 @@ table_create(struct smtpd *conf, const char *backend, const char *name, const ch
void
table_destroy(struct smtpd *conf, struct table *t)
{
- void *p = NULL;
-
- while (dict_poproot(&t->t_dict, (void **)&p))
- free(p);
-
dict_xpop(conf->sc_tables_dict, t->t_name);
free(t);
}
@@ -305,6 +273,42 @@ table_add(struct table *t, const char *key, const char *val)
log_warnx("warn: failed to add \"%s\" in table \"%s\"", key, t->t_name);
}
+void
+table_dump(struct table *t)
+{
+ const char *type;
+ char buf[LINE_MAX];
+
+ switch(t->t_type) {
+ case T_NONE:
+ type = "NONE";
+ break;
+ case T_DYNAMIC:
+ type = "DYNAMIC";
+ break;
+ case T_LIST:
+ type = "LIST";
+ break;
+ case T_HASH:
+ type = "HASH";
+ break;
+ default:
+ type = "???";
+ break;
+ }
+
+ if (t->t_config[0])
+ snprintf(buf, sizeof(buf), " config=\"%s\"", t->t_config);
+ else
+ buf[0] = '\0';
+
+ log_debug("TABLE \"%s\" backend=%s type=%s%s", t->t_name,
+ t->t_backend->name, type, buf);
+
+ if (t->t_backend->dump)
+ t->t_backend->dump(t);
+}
+
int
table_check_type(struct table *t, uint32_t mask)
{
@@ -478,32 +482,10 @@ table_dump_all(struct smtpd *conf)
{
struct table *t;
void *iter;
- const char *sep;
- char buf[1024];
iter = NULL;
- while (dict_iter(conf->sc_tables_dict, &iter, NULL, (void **)&t)) {
- sep = "";
- buf[0] = '\0';
- if (t->t_type & T_DYNAMIC) {
- (void)strlcat(buf, "DYNAMIC", sizeof(buf));
- sep = ",";
- }
- if (t->t_type & T_LIST) {
- (void)strlcat(buf, sep, sizeof(buf));
- (void)strlcat(buf, "LIST", sizeof(buf));
- sep = ",";
- }
- if (t->t_type & T_HASH) {
- (void)strlcat(buf, sep, sizeof(buf));
- (void)strlcat(buf, "HASH", sizeof(buf));
- sep = ",";
- }
- log_debug("TABLE \"%s\" type=%s config=\"%s\"",
- t->t_name, buf, t->t_config);
- if (t->t_backend->dump)
- t->t_backend->dump(t);
- }
+ while (dict_iter(conf->sc_tables_dict, &iter, NULL, (void **)&t))
+ table_dump(t);
}
void
diff --git a/smtpd/table_api.c b/smtpd/table_api.c
deleted file mode 100644
index 2eac4860..00000000
--- a/smtpd/table_api.c
+++ /dev/null
@@ -1,348 +0,0 @@
-/* $OpenBSD: table_api.c,v 1.8 2015/12/05 13:14:21 claudio Exp $ */
-
-/*
- * Copyright (c) 2013 Eric Faurot <eric@openbsd.org>
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/tree.h>
-#include <sys/socket.h>
-
-#include <netinet/in.h>
-#include <netdb.h>
-
-#include <errno.h>
-#include <event.h>
-#include <fcntl.h>
-#include <imsg.h>
-#include <pwd.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <limits.h>
-
-#include "smtpd-defines.h"
-#include "smtpd-api.h"
-#include "log.h"
-
-static int (*handler_update)(void);
-static int (*handler_check)(int, struct dict *, const char *);
-static int (*handler_lookup)(int, struct dict *, const char *, char *, size_t);
-static int (*handler_fetch)(int, struct dict *, char *, size_t);
-
-static int quit;
-static struct imsgbuf ibuf;
-static struct imsg imsg;
-static size_t rlen;
-static char *rdata;
-static struct ibuf *buf;
-static char *name;
-
-#if 0
-static char *rootpath;
-static char *user = SMTPD_USER;
-#endif
-
-static void
-table_msg_get(void *dst, size_t len)
-{
- if (len > rlen) {
- log_warnx("warn: table-proc: bad msg len");
- fatalx("table-proc: exiting");
- }
-
- if (len == 0)
- return;
-
- if (dst)
- memmove(dst, rdata, len);
-
- rlen -= len;
- rdata += len;
-}
-
-static void
-table_msg_end(void)
-{
- if (rlen) {
- log_warnx("warn: table-proc: bogus data");
- fatalx("table-proc: exiting");
- }
- imsg_free(&imsg);
-}
-
-static void
-table_msg_add(const void *data, size_t len)
-{
- if (buf == NULL)
- buf = imsg_create(&ibuf, PROC_TABLE_OK, 0, 0, 1024);
- if (buf == NULL) {
- log_warnx("warn: table-api: imsg_create failed");
- fatalx("table-api: exiting");
- }
- if (imsg_add(buf, data, len) == -1) {
- log_warnx("warn: table-api: imsg_add failed");
- fatalx("table-api: exiting");
- }
-}
-
-static void
-table_msg_close(void)
-{
- imsg_close(&ibuf, buf);
- buf = NULL;
-}
-
-static int
-table_read_params(struct dict *params)
-{
- size_t count;
- char *key;
- char *value;
-
- dict_init(params);
-
- table_msg_get(&count, sizeof(count));
-
- for (;count; count--) {
- key = rdata;
- table_msg_get(NULL, strlen(key) + 1);
- value = rdata;
- table_msg_get(NULL, strlen(value) + 1);
- dict_set(params, key, value);
- }
-
- return (0);
-}
-
-static void
-table_clear_params(struct dict *params)
-{
- while (dict_poproot(params, NULL))
- ;
-}
-
-static void
-table_msg_dispatch(void)
-{
- struct table_open_params op;
- struct dict params;
- char res[4096];
- int type, r;
-
- memset(res, 0, sizeof res);
- switch (imsg.hdr.type) {
- case PROC_TABLE_OPEN:
- table_msg_get(&op, sizeof op);
- table_msg_end();
-
- if (op.version != PROC_TABLE_API_VERSION) {
- log_warnx("warn: table-api: bad API version");
- fatalx("table-api: terminating");
- }
- if ((name = strdup(op.name)) == NULL) {
- log_warn("warn: table-api");
- fatalx("table-api: terminating");
- }
-
- imsg_compose(&ibuf, PROC_TABLE_OK, 0, 0, -1, NULL, 0);
- break;
-
- case PROC_TABLE_UPDATE:
- table_msg_end();
-
- if (handler_update)
- r = handler_update();
- else
- r = 1;
-
- imsg_compose(&ibuf, PROC_TABLE_OK, 0, 0, -1, &r, sizeof(r));
- break;
-
- case PROC_TABLE_CLOSE:
- quit = 1;
- break;
-
- case PROC_TABLE_CHECK:
- table_msg_get(&type, sizeof(type));
- table_read_params(&params);
- if (rlen == 0) {
- log_warnx("warn: table-api: no key");
- fatalx("table-api: exiting");
- }
- if (rdata[rlen - 1] != '\0') {
- log_warnx("warn: table-api: key not NUL-terminated");
- fatalx("table-api: exiting");
- }
-
- if (handler_check)
- r = handler_check(type, &params, rdata);
- else
- r = -1;
- table_clear_params(&params);
- table_msg_get(NULL, rlen);
- table_msg_end();
-
- table_msg_add(&r, sizeof(r));
- table_msg_close();
- break;
-
- case PROC_TABLE_LOOKUP:
- table_msg_get(&type, sizeof(type));
- table_read_params(&params);
- if (rlen == 0) {
- log_warnx("warn: table-api: no key");
- fatalx("table-api: exiting");
- }
- if (rdata[rlen - 1] != '\0') {
- log_warnx("warn: table-api: key not NUL-terminated");
- fatalx("table-api: exiting");
- }
-
- if (handler_lookup)
- r = handler_lookup(type, &params, rdata, res, sizeof(res));
- else
- r = -1;
- table_clear_params(&params);
- table_msg_get(NULL, rlen);
- table_msg_end();
-
- table_msg_add(&r, sizeof(r));
- if (r == 1)
- table_msg_add(res, strlen(res) + 1);
- table_msg_close();
- break;
-
-
- case PROC_TABLE_FETCH:
- table_msg_get(&type, sizeof(type));
- table_read_params(&params);
- if (handler_fetch)
- r = handler_fetch(type, &params, res, sizeof(res));
- else
- r = -1;
- table_clear_params(&params);
- table_msg_end();
-
- table_msg_add(&r, sizeof(r));
- if (r == 1)
- table_msg_add(res, strlen(res) + 1);
- table_msg_close();
- break;
-
- default:
- log_warnx("warn: table-api: bad message %d", imsg.hdr.type);
- fatalx("table-api: exiting");
- }
-}
-
-void
-table_api_on_update(int(*cb)(void))
-{
- handler_update = cb;
-}
-
-void
-table_api_on_check(int(*cb)(int, struct dict *, const char *))
-{
- handler_check = cb;
-}
-
-void
-table_api_on_lookup(int(*cb)(int, struct dict *, const char *, char *, size_t))
-{
- handler_lookup = cb;
-}
-
-void
-table_api_on_fetch(int(*cb)(int, struct dict *, char *, size_t))
-{
- handler_fetch = cb;
-}
-
-const char *
-table_api_get_name(void)
-{
- return name;
-}
-
-int
-table_api_dispatch(void)
-{
-#if 0
- struct passwd *pw;
-#endif
- ssize_t n;
-
-#if 0
- pw = getpwnam(user);
- if (pw == NULL) {
- log_warn("table-api: getpwnam");
- fatalx("table-api: exiting");
- }
-
- if (rootpath) {
- if (chroot(rootpath) == -1) {
- log_warn("table-api: chroot");
- fatalx("table-api: exiting");
- }
- if (chdir("/") == -1) {
- log_warn("table-api: chdir");
- fatalx("table-api: exiting");
- }
- }
-
- if (setgroups(1, &pw->pw_gid) ||
- setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) ||
- setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid)) {
- log_warn("table-api: cannot drop privileges");
- fatalx("table-api: exiting");
- }
-#endif
-
- imsg_init(&ibuf, 0);
-
- while (1) {
- n = imsg_get(&ibuf, &imsg);
- if (n == -1) {
- log_warn("warn: table-api: imsg_get");
- break;
- }
-
- if (n) {
- rdata = imsg.data;
- rlen = imsg.hdr.len - IMSG_HEADER_SIZE;
- table_msg_dispatch();
- if (quit)
- break;
- imsg_flush(&ibuf);
- continue;
- }
-
- n = imsg_read(&ibuf);
- if (n == -1 && errno != EAGAIN) {
- log_warn("warn: table-api: imsg_read");
- break;
- }
- if (n == 0) {
- log_warnx("warn: table-api: pipe closed");
- break;
- }
- }
-
- return (1);
-}
diff --git a/smtpd/table_static.c b/smtpd/table_static.c
index 361be8f4..f9519cb4 100644
--- a/smtpd/table_static.c
+++ b/smtpd/table_static.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: table_static.c,v 1.29 2018/12/27 15:04:59 eric Exp $ */
+/* $OpenBSD: table_static.c,v 1.32 2018/12/28 14:21:02 eric Exp $ */
/*
* Copyright (c) 2013 Eric Faurot <eric@openbsd.org>
@@ -26,7 +26,8 @@
#include <arpa/inet.h>
#include <ctype.h>
-#include <err.h>
+#include <errno.h>
+
#include <event.h>
#include <fcntl.h>
#include <imsg.h>
@@ -38,6 +39,12 @@
#include "smtpd.h"
#include "log.h"
+struct table_static_priv {
+ int type;
+ struct dict dict;
+ void *iter;
+};
+
/* static backend */
static int table_static_config(struct table *);
static int table_static_add(struct table *, const char *, const char *);
@@ -75,8 +82,47 @@ static struct keycmp {
};
+static void
+table_static_priv_free(struct table_static_priv *priv)
+{
+ void *p;
+
+ while (dict_poproot(&priv->dict, (void **)&p))
+ if (p != priv)
+ free(p);
+ free(priv);
+}
+
static int
-table_static_config(struct table *t)
+table_static_priv_add(struct table_static_priv *priv, const char *key, const char *val)
+{
+ char lkey[1024];
+ void *old, *new = NULL;
+
+ if (!lowercase(lkey, key, sizeof lkey)) {
+ errno = ENAMETOOLONG;
+ return (-1);
+ }
+
+ if (val) {
+ new = strdup(val);
+ if (new == NULL)
+ return (-1);
+ }
+
+ /* use priv if value is null, so we can detect duplicate entries */
+ old = dict_set(&priv->dict, lkey, new ? new : priv);
+ if (old) {
+ if (old != priv)
+ free(old);
+ return (1);
+ }
+
+ return (0);
+}
+
+static int
+table_static_priv_load(struct table_static_priv *priv, const char *path)
{
FILE *fp;
char *buf = NULL, *p;
@@ -85,14 +131,10 @@ table_static_config(struct table *t)
ssize_t flen;
char *keyp;
char *valp;
- size_t ret = 0;
-
- /* no config ? ok */
- if (*t->t_config == '\0')
- return 1;
+ int ret = 0;
- if ((fp = fopen(t->t_config, "r")) == NULL) {
- log_warn("warn: Table \"%s\"", t->t_config);
+ if ((fp = fopen(path, "r")) == NULL) {
+ log_warn("%s: fopen", path);
return 0;
}
@@ -111,29 +153,29 @@ table_static_config(struct table *t)
while (isspace((unsigned char)keyp[flen - 1]))
keyp[--flen] = '\0';
if (*keyp == '#') {
- if (t->t_type == T_NONE) {
+ if (priv->type == T_NONE) {
keyp++;
while (isspace((unsigned char)*keyp))
++keyp;
if (!strcmp(keyp, "@list"))
- t->t_type = T_LIST;
+ priv->type = T_LIST;
}
continue;
}
- if (t->t_type == T_NONE) {
+ if (priv->type == T_NONE) {
for (p = keyp; *p; p++) {
if (*p == ' ' || *p == '\t' || *p == ':') {
- t->t_type = T_HASH;
+ priv->type = T_HASH;
break;
}
}
- if (t->t_type == T_NONE)
- t->t_type = T_LIST;
+ if (priv->type == T_NONE)
+ priv->type = T_LIST;
}
- if (t->t_type == T_LIST) {
- table_add(t, keyp, NULL);
+ if (priv->type == T_LIST) {
+ table_static_priv_add(priv, keyp, NULL);
continue;
}
@@ -152,22 +194,22 @@ table_static_config(struct table *t)
valp = NULL;
}
if (valp == NULL) {
- log_warnx("%s: invalid map entry line %d", t->t_config,
- lineno);
+ log_warnx("%s: invalid map entry line %d",
+ path, lineno);
goto end;
}
- table_add(t, keyp, valp);
+ table_static_priv_add(priv, keyp, valp);
}
if (ferror(fp)) {
- log_warn("%s: getline", t->t_config);
+ log_warn("%s: getline", path);
goto end;
}
/* Accept empty alias files; treat them as hashes */
- if (t->t_type == T_NONE && t->t_backend->services & K_ALIAS)
- t->t_type = T_HASH;
+ if (priv->type == T_NONE)
+ priv->type = T_HASH;
ret = 1;
end:
@@ -177,35 +219,77 @@ end:
}
static int
-table_static_add(struct table *table, const char *key, const char *val)
+table_static_config(struct table *t)
{
- char lkey[1024], *old;
+ struct table_static_priv *priv, *old;
- if (!lowercase(lkey, key, sizeof lkey)) {
- log_warnx("warn: lookup key too long: %s", key);
+ /* already up, and no config file? ok */
+ if (t->t_handle && *t->t_config == '\0')
+ return 1;
+
+ /* new config */
+ priv = calloc(1, sizeof(*priv));
+ if (priv == NULL)
return 0;
+ priv->type = t->t_type;
+ dict_init(&priv->dict);
+
+ if (*t->t_config) {
+ /* load the config file */
+ if (table_static_priv_load(priv, t->t_config) == 0) {
+ table_static_priv_free(priv);
+ return 0;
+ }
}
- old = dict_set(&table->t_dict, lkey, val ? xstrdup(val) : NULL);
- if (old) {
- log_warnx("warn: duplicate key \"%s\" in static table \"%s\"",
- lkey, table->t_name);
- free(old);
+ if ((old = t->t_handle))
+ table_static_priv_free(old);
+ t->t_handle = priv;
+ t->t_type = priv->type;
+
+ return 1;
+}
+
+static int
+table_static_add(struct table *table, const char *key, const char *val)
+{
+ struct table_static_priv *priv = table->t_handle;
+ int r;
+
+ /* cannot add to a table read from a file */
+ if (*table->t_config)
+ return 0;
+
+ if (table->t_type == T_NONE)
+ table->t_type = val ? T_HASH : T_LIST;
+ else if (table->t_type == T_LIST && val)
+ return 0;
+ else if (table->t_type == T_HASH && val == NULL)
+ return 0;
+
+ if (priv == NULL) {
+ if (table_static_config(table) == 0)
+ return 0;
+ priv = table->t_handle;
}
+ r = table_static_priv_add(priv, key, val);
+ if (r == -1)
+ return 0;
return 1;
}
static void
table_static_dump(struct table *table)
{
+ struct table_static_priv *priv = table->t_handle;
const char *key;
char *value;
void *iter;
iter = NULL;
- while (dict_iter(&table->t_dict, &iter, &key, (void**)&value)) {
- if (value)
+ while (dict_iter(&priv->dict, &iter, &key, (void**)&value)) {
+ if (value && (void*)value != (void*)priv)
log_debug(" \"%s\" -> \"%s\"", key, value);
else
log_debug(" \"%s\"", key);
@@ -215,29 +299,11 @@ table_static_dump(struct table *table)
static int
table_static_update(struct table *table)
{
- struct table *t;
- void *p = NULL;
-
- /* no config ? ok */
- if (table->t_config[0] == '\0')
- goto ok;
-
- t = table_create(env, "static", table->t_name, "update", table->t_config);
- if (!table_config(t))
- goto err;
-
- /* replace former table, frees t */
- while (dict_poproot(&table->t_dict, (void **)&p))
- free(p);
- dict_merge(&table->t_dict, &t->t_dict);
- table_destroy(env, t);
-
-ok:
- log_info("info: Table \"%s\" successfully updated", table->t_name);
- return 1;
+ if (table_static_config(table) == 1) {
+ log_info("info: Table \"%s\" successfully updated", table->t_name);
+ return 1;
+ }
-err:
- table_destroy(env, t);
log_info("info: Failed to update table \"%s\"", table->t_name);
return 0;
}
@@ -245,20 +311,26 @@ err:
static int
table_static_open(struct table *table)
{
- table->t_handle = table;
+ if (table->t_handle == NULL)
+ return table_static_config(table);
return 1;
}
static void
table_static_close(struct table *table)
{
+ struct table_static_priv *priv = table->t_handle;
+
+ if (priv)
+ table_static_priv_free(priv);
table->t_handle = NULL;
}
static int
-table_static_lookup(struct table *m, enum table_service service, const char *key,
+table_static_lookup(struct table *table, enum table_service service, const char *key,
char **dst)
{
+ struct table_static_priv *priv = table->t_handle;
char *line;
int ret;
int (*match)(const char *, const char *) = NULL;
@@ -274,7 +346,7 @@ table_static_lookup(struct table *m, enum table_service service, const char *key
line = NULL;
iter = NULL;
ret = 0;
- while (dict_iter(&m->t_dict, &iter, &k, (void **)&v)) {
+ while (dict_iter(&priv->dict, &iter, &k, (void **)&v)) {
if (match) {
if (match(key, k)) {
line = v;
@@ -307,11 +379,12 @@ table_static_lookup(struct table *m, enum table_service service, const char *key
static int
table_static_fetch(struct table *t, enum table_service service, char **dst)
{
+ struct table_static_priv *priv = t->t_handle;
const char *k;
- if (!dict_iter(&t->t_dict, &t->t_iter, &k, (void **)NULL)) {
- t->t_iter = NULL;
- if (!dict_iter(&t->t_dict, &t->t_iter, &k, (void **)NULL))
+ if (!dict_iter(&priv->dict, &priv->iter, &k, (void **)NULL)) {
+ priv->iter = NULL;
+ if (!dict_iter(&priv->dict, &priv->iter, &k, (void **)NULL))
return 0;
}
diff --git a/smtpd/to.c b/smtpd/to.c
index f4e1149a..6f8592dc 100644
--- a/smtpd/to.c
+++ b/smtpd/to.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: to.c,v 1.34 2018/10/31 15:14:21 gilles Exp $ */
+/* $OpenBSD: to.c,v 1.35 2018/12/30 23:09:58 guenther Exp $ */
/*
* Copyright (c) 2009 Jacek Masiulaniec <jacekm@dobremiasto.net>
@@ -36,7 +36,6 @@
#include <imsg.h>
#include <limits.h>
#include <inttypes.h>
-#include <libgen.h>
#include <netdb.h>
#include <pwd.h>
#include <stdarg.h>