type static tables on the fly when the first element is added
authoreric <eric@openbsd.org>
Fri, 28 Dec 2018 14:21:02 +0000 (14:21 +0000)
committereric <eric@openbsd.org>
Fri, 28 Dec 2018 14:21:02 +0000 (14:21 +0000)
ok gilles@

usr.sbin/smtpd/config.c
usr.sbin/smtpd/parse.y
usr.sbin/smtpd/table_static.c

index 3fce648..8b8b857 100644 (file)
@@ -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 <pyr@openbsd.org>
@@ -134,7 +134,6 @@ config_default(void)
        set_local(conf, conf->sc_hostname);
 
        t = table_create(conf, "static", "<anydestination>", 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", "<localnames>", NULL);
-       t->t_type = T_LIST;
        table_add(t, "localhost", NULL);
        table_add(t, hostname, NULL);
 
index af69c23..33159de 100644 (file)
@@ -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 <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);
                }
@@ -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;
index 73c1816..f9519cb 100644 (file)
@@ -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 <eric@openbsd.org>
@@ -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;