-/* $OpenBSD: smtpd.h,v 1.610 2018/12/27 09:30:29 eric Exp $ */
+/* $OpenBSD: smtpd.h,v 1.611 2018/12/27 14:23:41 eric Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@poolp.org>
const char *name;
const unsigned int services;
int (*config)(struct table *);
+ int (*add)(struct table *, const char *, const char *);
+ void (*dump)(struct table *);
int (*open)(struct table *);
int (*update)(struct table *);
void (*close)(struct table *);
-/* $OpenBSD: table.c,v 1.41 2018/12/27 09:30:29 eric Exp $ */
+/* $OpenBSD: table.c,v 1.42 2018/12/27 14:23:41 eric Exp $ */
/*
* Copyright (c) 2013 Eric Faurot <eric@openbsd.org>
void
table_add(struct table *t, const char *key, const char *val)
{
- char lkey[1024], *old;
-
- if (t->t_type & T_DYNAMIC)
+ if (t->t_backend->add == NULL)
fatalx("table_add: cannot add to table");
- if (!lowercase(lkey, key, sizeof lkey)) {
- log_warnx("warn: lookup key too long: %s", key);
- return;
- }
-
- old = dict_set(&t->t_dict, lkey, val ? xstrdup(val) : NULL);
- if (old) {
- log_warnx("warn: duplicate key \"%s\" in static table \"%s\"",
- lkey, t->t_name);
- free(old);
- }
+ if (t->t_backend->add(t, key, val) == 0)
+ log_warnx("warn: failed to add \"%s\" in table \"%s\"", key, t->t_name);
}
int
table_dump_all(struct smtpd *conf)
{
struct table *t;
- void *iter, *i2;
- const char *key, *sep;
- char *value;
+ void *iter;
+ const char *sep;
char buf[1024];
iter = NULL;
while (dict_iter(conf->sc_tables_dict, &iter, NULL, (void **)&t)) {
- i2 = NULL;
sep = "";
buf[0] = '\0';
if (t->t_type & T_DYNAMIC) {
}
log_debug("TABLE \"%s\" type=%s config=\"%s\"",
t->t_name, buf, t->t_config);
- while(dict_iter(&t->t_dict, &i2, &key, (void**)&value)) {
- if (value)
- log_debug(" \"%s\" -> \"%s\"", key, value);
- else
- log_debug(" \"%s\"", key);
- }
+ if (t->t_backend->dump)
+ t->t_backend->dump(t);
}
}
-/* $OpenBSD: table_db.c,v 1.17 2018/12/27 09:30:29 eric Exp $ */
+/* $OpenBSD: table_db.c,v 1.18 2018/12/27 14:23:41 eric Exp $ */
/*
* Copyright (c) 2011 Gilles Chehade <gilles@poolp.org>
"db",
K_ALIAS|K_CREDENTIALS|K_DOMAIN|K_NETADDR|K_USERINFO|K_SOURCE|K_MAILADDR|K_ADDRNAME|K_MAILADDRMAP,
table_db_config,
+ NULL,
+ NULL,
table_db_open,
table_db_update,
table_db_close,
-/* $OpenBSD: table_getpwnam.c,v 1.11 2018/12/27 09:30:29 eric Exp $ */
+/* $OpenBSD: table_getpwnam.c,v 1.12 2018/12/27 14:23:41 eric Exp $ */
/*
* Copyright (c) 2012 Gilles Chehade <gilles@poolp.org>
"getpwnam",
K_USERINFO,
table_getpwnam_config,
+ NULL,
+ NULL,
table_getpwnam_open,
table_getpwnam_update,
table_getpwnam_close,
-/* $OpenBSD: table_proc.c,v 1.14 2018/12/27 09:30:29 eric Exp $ */
+/* $OpenBSD: table_proc.c,v 1.15 2018/12/27 14:23:41 eric Exp $ */
/*
* Copyright (c) 2013 Eric Faurot <eric@openbsd.org>
"proc",
K_ANY,
NULL,
+ NULL,
+ NULL,
table_proc_open,
table_proc_update,
table_proc_close,
-/* $OpenBSD: table_static.c,v 1.27 2018/12/27 09:30:29 eric Exp $ */
+/* $OpenBSD: table_static.c,v 1.28 2018/12/27 14:23:41 eric Exp $ */
/*
* Copyright (c) 2013 Eric Faurot <eric@openbsd.org>
/* static backend */
static int table_static_config(struct table *);
+static int table_static_add(struct table *, const char *, const char *);
+static void table_static_dump(struct table *);
static int table_static_update(struct table *);
static int table_static_open(struct table *);
static int table_static_lookup(struct table *, enum table_service, const char *,
K_SOURCE|K_MAILADDR|K_ADDRNAME|K_MAILADDRMAP|K_RELAYHOST|
K_STRING|K_REGEX,
table_static_config,
+ table_static_add,
+ table_static_dump,
table_static_open,
table_static_update,
table_static_close,
return ret;
}
+static int
+table_static_add(struct table *table, const char *key, const char *val)
+{
+ char lkey[1024], *old;
+
+ if (!lowercase(lkey, key, sizeof lkey)) {
+ log_warnx("warn: lookup key too long: %s", key);
+ 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);
+ }
+
+ return 1;
+}
+
+static void
+table_static_dump(struct table *table)
+{
+ const char *key;
+ char *value;
+ void *iter;
+
+ iter = NULL;
+ while (dict_iter(&table->t_dict, &iter, &key, (void**)&value)) {
+ if (value)
+ log_debug(" \"%s\" -> \"%s\"", key, value);
+ else
+ log_debug(" \"%s\"", key);
+ }
+}
+
static int
table_static_update(struct table *table)
{