From f27a1daa0f2745ed67eba2bcfdae1341f849128c Mon Sep 17 00:00:00 2001 From: eric Date: Fri, 28 Dec 2018 14:21:02 +0000 Subject: [PATCH] type static tables on the fly when the first element is added ok gilles@ --- usr.sbin/smtpd/config.c | 4 +--- usr.sbin/smtpd/parse.y | 5 +---- usr.sbin/smtpd/table_static.c | 9 ++++++++- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/usr.sbin/smtpd/config.c b/usr.sbin/smtpd/config.c index 3fce648c476..8b8b857096e 100644 --- a/usr.sbin/smtpd/config.c +++ b/usr.sbin/smtpd/config.c @@ -1,4 +1,4 @@ -/* $OpenBSD: config.c,v 1.48 2018/12/28 11:40:29 eric Exp $ */ +/* $OpenBSD: config.c,v 1.49 2018/12/28 14:21:02 eric Exp $ */ /* * Copyright (c) 2008 Pierre-Yves Ritschard @@ -134,7 +134,6 @@ config_default(void) set_local(conf, conf->sc_hostname); t = table_create(conf, "static", "", NULL); - t->t_type = T_LIST; table_add(t, "*", NULL); hostname[strcspn(hostname, ".")] = '\0'; @@ -169,7 +168,6 @@ set_local(struct smtpd *conf, const char *hostname) struct table *t; t = table_create(conf, "static", "", NULL); - t->t_type = T_LIST; table_add(t, "localhost", NULL); table_add(t, hostname, NULL); diff --git a/usr.sbin/smtpd/parse.y b/usr.sbin/smtpd/parse.y index af69c231f26..33159dec095 100644 --- a/usr.sbin/smtpd/parse.y +++ b/usr.sbin/smtpd/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.249 2018/12/28 11:40:29 eric Exp $ */ +/* $OpenBSD: parse.y,v 1.250 2018/12/28 14:21:02 eric Exp $ */ /* * Copyright (c) 2008 Gilles Chehade @@ -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); } @@ -2177,7 +2175,6 @@ tablenew : STRING { struct table *t; t = table_create(conf, "static", NULL, NULL); - t->t_type = T_LIST; table_add(t, $1, NULL); free($1); $$ = t; diff --git a/usr.sbin/smtpd/table_static.c b/usr.sbin/smtpd/table_static.c index 73c18164a42..f9519cb4ab4 100644 --- a/usr.sbin/smtpd/table_static.c +++ b/usr.sbin/smtpd/table_static.c @@ -1,4 +1,4 @@ -/* $OpenBSD: table_static.c,v 1.31 2018/12/28 11:11:36 eric Exp $ */ +/* $OpenBSD: table_static.c,v 1.32 2018/12/28 14:21:02 eric Exp $ */ /* * Copyright (c) 2013 Eric Faurot @@ -260,6 +260,13 @@ table_static_add(struct table *table, const char *key, const char *val) 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; -- 2.20.1