From: eric Date: Fri, 28 Dec 2018 11:40:29 +0000 (+0000) Subject: remove the tag workaround for table_create() and table_find(), X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=ff18143e86e7718ccc40d101a8e6ff5be63f83f8;p=openbsd remove the tag workaround for table_create() and table_find(), now that static tables handle their updates internally. ok gilles@ --- diff --git a/usr.sbin/smtpd/aliases.c b/usr.sbin/smtpd/aliases.c index 634aa68857e..af7b59aa2cf 100644 --- a/usr.sbin/smtpd/aliases.c +++ b/usr.sbin/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.76 2018/12/28 11:40:29 eric Exp $ */ /* * Copyright (c) 2008 Gilles Chehade @@ -50,8 +50,8 @@ aliases_get(struct expand *expand, const char *username) 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); + userbase = table_find(env, dsp->u.local.table_userbase); + mapping = table_find(env, dsp->u.local.table_alias); xlowercase(buf, username, sizeof(buf)); @@ -107,8 +107,8 @@ aliases_virtual_get(struct expand *expand, const struct mailaddr *maddr) 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); + userbase = table_find(env, dsp->u.local.table_userbase); + mapping = table_find(env, dsp->u.local.table_virtual); if (!bsnprintf(user, sizeof(user), "%s", maddr->user)) return 0; diff --git a/usr.sbin/smtpd/config.c b/usr.sbin/smtpd/config.c index 552803cbcee..3fce648c476 100644 --- a/usr.sbin/smtpd/config.c +++ b/usr.sbin/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.48 2018/12/28 11:40:29 eric Exp $ */ /* * Copyright (c) 2008 Pierre-Yves Ritschard @@ -133,7 +133,7 @@ config_default(void) */ set_local(conf, conf->sc_hostname); - t = table_create(conf, "static", "", NULL, NULL); + t = table_create(conf, "static", "", NULL); t->t_type = T_LIST; table_add(t, "*", NULL); @@ -141,7 +141,7 @@ config_default(void) if (strcmp(conf->sc_hostname, hostname) != 0) table_add(t, hostname, NULL); - table_create(conf, "getpwnam", "", NULL, NULL); + table_create(conf, "getpwnam", "", NULL); return conf; @@ -168,7 +168,7 @@ set_local(struct smtpd *conf, const char *hostname) { struct table *t; - t = table_create(conf, "static", "", NULL, NULL); + t = table_create(conf, "static", "", NULL); t->t_type = T_LIST; table_add(t, "localhost", NULL); table_add(t, hostname, NULL); @@ -186,7 +186,7 @@ set_localaddrs(struct smtpd *conf, struct table *localnames) struct table *t; char buf[NI_MAXHOST + 5]; - t = table_create(conf, "static", "", NULL, NULL); + t = table_create(conf, "static", "", NULL); table_add(t, "local", NULL); table_add(t, "0.0.0.0/0", NULL); table_add(t, "::/0", NULL); @@ -194,7 +194,7 @@ set_localaddrs(struct smtpd *conf, struct table *localnames) if (getifaddrs(&ifap) == -1) fatal("getifaddrs"); - t = table_create(conf, "static", "", NULL, NULL); + t = table_create(conf, "static", "", NULL); table_add(t, "local", NULL); for (p = ifap; p != NULL; p = p->ifa_next) { diff --git a/usr.sbin/smtpd/lka.c b/usr.sbin/smtpd/lka.c index 7a6df074baa..9e4d8dc0d3e 100644 --- a/usr.sbin/smtpd/lka.c +++ b/usr.sbin/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 @@ -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/usr.sbin/smtpd/lka_session.c b/usr.sbin/smtpd/lka_session.c index ea01797101c..ed17adcbb6b 100644 --- a/usr.sbin/smtpd/lka_session.c +++ b/usr.sbin/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 @@ -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/usr.sbin/smtpd/makemap.c b/usr.sbin/smtpd/makemap.c index 51c475e64a1..dd8bc8d300e 100644 --- a/usr.sbin/smtpd/makemap.c +++ b/usr.sbin/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 @@ -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/usr.sbin/smtpd/parse.y b/usr.sbin/smtpd/parse.y index bb88aa37c7a..af69c231f26 100644 --- a/usr.sbin/smtpd/parse.y +++ b/usr.sbin/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.249 2018/12/28 11:40:29 eric Exp $ */ /* * Copyright (c) 2008 Gilles Chehade @@ -1092,7 +1092,7 @@ negation TAG REGEX tables { rule->flag_from_socket = 1; } | negation FROM LOCAL { - struct table *t = table_find(conf, "", NULL); + struct table *t = table_find(conf, ""); if (rule->flag_from) { yyerror("from already specified for this rule"); @@ -1102,7 +1102,7 @@ negation TAG REGEX tables { rule->table_from = strdup(t->t_name); } | negation FROM ANY { - struct table *t = table_find(conf, "", NULL); + struct table *t = table_find(conf, ""); if (rule->flag_from) { yyerror("from already specified for this rule"); @@ -1187,7 +1187,7 @@ negation TAG REGEX tables { | negation FOR LOCAL { - struct table *t = table_find(conf, "", NULL); + struct table *t = table_find(conf, ""); if (rule->flag_for) { yyerror("for already specified for this rule"); @@ -1197,7 +1197,7 @@ negation TAG REGEX tables { rule->table_for = strdup(t->t_name); } | negation FOR ANY { - struct table *t = table_find(conf, "", NULL); + struct table *t = table_find(conf, ""); if (rule->flag_for) { yyerror("for already specified for this rule"); @@ -2153,7 +2153,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 +2166,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 +2176,14 @@ table : TABLE STRING STRING { tablenew : STRING { struct table *t; - t = table_create(conf, "static", NULL, NULL, NULL); + t = table_create(conf, "static", NULL, NULL); t->t_type = T_LIST; 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 +2193,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/usr.sbin/smtpd/ruleset.c b/usr.sbin/smtpd/ruleset.c index 0d16d85dded..237feae1f26 100644 --- a/usr.sbin/smtpd/ruleset.c +++ b/usr.sbin/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 @@ -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/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h index da9fbb4ad59..cea2ed8e51a 100644 --- a/usr.sbin/smtpd/smtpd.h +++ b/usr.sbin/smtpd/smtpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpd.h,v 1.613 2018/12/28 11:13:58 eric Exp $ */ +/* $OpenBSD: smtpd.h,v 1.614 2018/12/28 11:40:29 eric Exp $ */ /* * Copyright (c) 2008 Gilles Chehade @@ -1596,8 +1596,8 @@ 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 *); diff --git a/usr.sbin/smtpd/table.c b/usr.sbin/smtpd/table.c index 5c67d5f2cef..0526faab2f8 100644 --- a/usr.sbin/smtpd/table.c +++ b/usr.sbin/smtpd/table.c @@ -1,4 +1,4 @@ -/* $OpenBSD: table.c,v 1.44 2018/12/28 11:13:58 eric Exp $ */ +/* $OpenBSD: table.c,v 1.45 2018/12/28 11:40:29 eric Exp $ */ /* * Copyright (c) 2013 Eric Faurot @@ -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) {