From: eric Date: Wed, 26 Dec 2018 11:53:02 +0000 (+0000) Subject: move the table backend name in the backend struct. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=4f15e081281951c9b6cd815af051d459a04df139;p=openbsd move the table backend name in the backend struct. remove unused function. ok gilles@ --- diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h index 47914bd5428..4c81e1cec71 100644 --- a/usr.sbin/smtpd/smtpd.h +++ b/usr.sbin/smtpd/smtpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpd.h,v 1.603 2018/12/23 16:37:53 eric Exp $ */ +/* $OpenBSD: smtpd.h,v 1.604 2018/12/26 11:53:02 eric Exp $ */ /* * Copyright (c) 2008 Gilles Chehade @@ -362,6 +362,7 @@ struct table { }; struct table_backend { + const char *name; const unsigned int services; int (*config)(struct table *); void *(*open)(struct table *); diff --git a/usr.sbin/smtpd/table.c b/usr.sbin/smtpd/table.c index f070ab48a12..5d56b99e63b 100644 --- a/usr.sbin/smtpd/table.c +++ b/usr.sbin/smtpd/table.c @@ -1,4 +1,4 @@ -/* $OpenBSD: table.c,v 1.34 2018/12/23 15:53:24 eric Exp $ */ +/* $OpenBSD: table.c,v 1.35 2018/12/26 11:53:02 eric Exp $ */ /* * Copyright (c) 2013 Eric Faurot @@ -51,40 +51,33 @@ extern struct table_backend table_backend_getpwnam; extern struct table_backend table_backend_proc; static const char * table_service_name(enum table_service); -static const char * table_backend_name(struct table_backend *); -static const char * table_dump_lookup(enum table_service, union lookup *); static int table_parse_lookup(enum table_service, const char *, const char *, union lookup *); static int parse_sockaddr(struct sockaddr *, int, const char *); static unsigned int last_table_id = 0; +static struct table_backend *backends[] = { + &table_backend_static, + &table_backend_db, + &table_backend_getpwnam, + &table_backend_proc, + NULL +}; + struct table_backend * table_backend_lookup(const char *backend) { - if (!strcmp(backend, "static") || !strcmp(backend, "file")) - return &table_backend_static; - if (!strcmp(backend, "db")) - return &table_backend_db; - if (!strcmp(backend, "getpwnam")) - return &table_backend_getpwnam; - if (!strcmp(backend, "proc")) - return &table_backend_proc; - return NULL; -} + int i; -static const char * -table_backend_name(struct table_backend *backend) -{ - if (backend == &table_backend_static) - return "static"; - if (backend == &table_backend_db) - return "db"; - if (backend == &table_backend_getpwnam) - return "getpwnam"; - if (backend == &table_backend_proc) - return "proc"; - return "???"; + if (!strcmp(backend, "file")) + backend = "static"; + + for (i = 0; backends[i]; i++) + if (!strcmp(backends[i]->name, backend)) + return (backends[i]); + + return NULL; } static const char * @@ -144,7 +137,7 @@ table_lookup(struct table *table, struct dict *params, const char *key, enum tab lk ? "lookup" : "check", lkey, table_service_name(kind), - table_backend_name(table->t_backend), + table->t_backend->name, table->t_name, lk ? "\"" : "", (lk) ? buf : "found", @@ -157,7 +150,7 @@ table_lookup(struct table *table, struct dict *params, const char *key, enum tab lk ? "lookup" : "check", lkey, table_service_name(kind), - table_backend_name(table->t_backend), + table->t_backend->name, table->t_name, r); @@ -180,7 +173,7 @@ table_fetch(struct table *table, struct dict *params, enum table_service kind, u if (r == 1) { log_trace(TRACE_LOOKUP, "lookup: fetch %s from table %s:%s -> %s%s%s", table_service_name(kind), - table_backend_name(table->t_backend), + table->t_backend->name, table->t_name, lk ? "\"" : "", (lk) ? buf : "found", @@ -191,7 +184,7 @@ table_fetch(struct table *table, struct dict *params, enum table_service kind, u else log_trace(TRACE_LOOKUP, "lookup: fetch %s from table %s:%s -> %d", table_service_name(kind), - table_backend_name(table->t_backend), + table->t_backend->name, table->t_name, r); @@ -667,90 +660,6 @@ table_parse_lookup(enum table_service service, const char *key, } } -static const char * -table_dump_lookup(enum table_service s, union lookup *lk) -{ - static char buf[LINE_MAX]; - int ret; - - switch (s) { - case K_NONE: - break; - - case K_ALIAS: - expand_to_text(lk->expand, buf, sizeof(buf)); - break; - - case K_DOMAIN: - ret = snprintf(buf, sizeof(buf), "%s", lk->domain.name); - if (ret == -1 || (size_t)ret >= sizeof (buf)) - goto err; - break; - - case K_CREDENTIALS: - ret = snprintf(buf, sizeof(buf), "%s:%s", - lk->creds.username, lk->creds.password); - if (ret == -1 || (size_t)ret >= sizeof (buf)) - goto err; - break; - - case K_NETADDR: - ret = snprintf(buf, sizeof(buf), "%s/%d", - sockaddr_to_text((struct sockaddr *)&lk->netaddr.ss), - lk->netaddr.bits); - if (ret == -1 || (size_t)ret >= sizeof (buf)) - goto err; - break; - - case K_USERINFO: - ret = snprintf(buf, sizeof(buf), "%s:%d:%d:%s", - lk->userinfo.username, - lk->userinfo.uid, - lk->userinfo.gid, - lk->userinfo.directory); - if (ret == -1 || (size_t)ret >= sizeof (buf)) - goto err; - break; - - case K_SOURCE: - ret = snprintf(buf, sizeof(buf), "%s", - ss_to_text(&lk->source.addr)); - if (ret == -1 || (size_t)ret >= sizeof (buf)) - goto err; - break; - - case K_MAILADDR: - ret = snprintf(buf, sizeof(buf), "%s@%s", - lk->mailaddr.user, - lk->mailaddr.domain); - if (ret == -1 || (size_t)ret >= sizeof (buf)) - goto err; - break; - - case K_ADDRNAME: - ret = snprintf(buf, sizeof(buf), "%s", - lk->addrname.name); - if (ret == -1 || (size_t)ret >= sizeof (buf)) - goto err; - break; - - case K_RELAYHOST: - if (strlcpy(buf, lk->relayhost, sizeof(buf)) >= sizeof(buf)) - goto err; - break; - - default: - (void)strlcpy(buf, "???", sizeof(buf)); - break; - } - - return (buf); - -err: - return (NULL); -} - - static int parse_sockaddr(struct sockaddr *sa, int family, const char *str) { diff --git a/usr.sbin/smtpd/table_db.c b/usr.sbin/smtpd/table_db.c index 606c54e90f3..7808ea2405b 100644 --- a/usr.sbin/smtpd/table_db.c +++ b/usr.sbin/smtpd/table_db.c @@ -1,4 +1,4 @@ -/* $OpenBSD: table_db.c,v 1.11 2018/12/23 15:53:24 eric Exp $ */ +/* $OpenBSD: table_db.c,v 1.12 2018/12/26 11:53:02 eric Exp $ */ /* * Copyright (c) 2011 Gilles Chehade @@ -52,6 +52,7 @@ static char *table_db_get_entry_match(void *, const char *, size_t *, int(*)(const char *, const char *)); struct table_backend table_backend_db = { + "db", K_ALIAS|K_CREDENTIALS|K_DOMAIN|K_NETADDR|K_USERINFO|K_SOURCE|K_MAILADDR|K_ADDRNAME|K_MAILADDRMAP, table_db_config, table_db_open, diff --git a/usr.sbin/smtpd/table_getpwnam.c b/usr.sbin/smtpd/table_getpwnam.c index 046eed56966..665df8cafcc 100644 --- a/usr.sbin/smtpd/table_getpwnam.c +++ b/usr.sbin/smtpd/table_getpwnam.c @@ -1,4 +1,4 @@ -/* $OpenBSD: table_getpwnam.c,v 1.5 2018/12/23 15:53:24 eric Exp $ */ +/* $OpenBSD: table_getpwnam.c,v 1.6 2018/12/26 11:53:02 eric Exp $ */ /* * Copyright (c) 2012 Gilles Chehade @@ -46,6 +46,7 @@ static int table_getpwnam_lookup(void *, struct dict *, const char *, enum table static void table_getpwnam_close(void *); struct table_backend table_backend_getpwnam = { + "getpwnam", K_USERINFO, table_getpwnam_config, table_getpwnam_open, diff --git a/usr.sbin/smtpd/table_proc.c b/usr.sbin/smtpd/table_proc.c index ab3f5404a6f..2d20d847c30 100644 --- a/usr.sbin/smtpd/table_proc.c +++ b/usr.sbin/smtpd/table_proc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: table_proc.c,v 1.8 2018/12/23 15:53:24 eric Exp $ */ +/* $OpenBSD: table_proc.c,v 1.9 2018/12/26 11:53:02 eric Exp $ */ /* * Copyright (c) 2013 Eric Faurot @@ -279,6 +279,7 @@ table_proc_fetch(void *arg, struct dict *params, enum table_service s, char **ds } struct table_backend table_backend_proc = { + "proc", K_ANY, NULL, table_proc_open, diff --git a/usr.sbin/smtpd/table_static.c b/usr.sbin/smtpd/table_static.c index 352a0541ab1..bb4328e944e 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.21 2018/12/23 15:53:24 eric Exp $ */ +/* $OpenBSD: table_static.c,v 1.22 2018/12/26 11:53:02 eric Exp $ */ /* * Copyright (c) 2013 Eric Faurot @@ -49,6 +49,7 @@ static int table_static_fetch(void *, struct dict *, enum table_service, static void table_static_close(void *); struct table_backend table_backend_static = { + "static", K_ALIAS|K_CREDENTIALS|K_DOMAIN|K_NETADDR|K_USERINFO| K_SOURCE|K_MAILADDR|K_ADDRNAME|K_MAILADDRMAP|K_RELAYHOST| K_STRING|K_REGEX,