as strings, and parsing is handled by the upper layer.
ok gilles@
-/* $OpenBSD: smtpd.h,v 1.601 2018/12/22 13:09:05 gilles Exp $ */
+/* $OpenBSD: smtpd.h,v 1.602 2018/12/23 15:53:24 eric Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@poolp.org>
void *(*open)(struct table *);
int (*update)(struct table *);
void (*close)(void *);
- int (*lookup)(void *, struct dict *, const char *, enum table_service, union lookup *);
- int (*fetch)(void *, struct dict *, enum table_service, union lookup *);
+ int (*lookup)(void *, struct dict *, const char *, enum table_service, char **);
+ int (*fetch)(void *, struct dict *, enum table_service, char **);
};
void table_open_all(struct smtpd *);
void table_dump_all(struct smtpd *);
void table_close_all(struct smtpd *);
-int table_parse_lookup(enum table_service, const char *, const char *,
- union lookup *);
/* to.c */
-/* $OpenBSD: table.c,v 1.33 2018/12/21 21:35:29 gilles Exp $ */
+/* $OpenBSD: table.c,v 1.34 2018/12/23 15:53:24 eric Exp $ */
/*
* Copyright (c) 2013 Eric Faurot <eric@openbsd.org>
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;
union lookup *lk)
{
int r;
- char lkey[1024];
+ char lkey[1024], *buf = NULL;
if (table->t_backend->lookup == NULL)
return (-1);
return -1;
}
- r = table->t_backend->lookup(table->t_handle, params, lkey, kind, lk);
+ r = table->t_backend->lookup(table->t_handle, params, lkey, kind, lk ? &buf : NULL);
- if (r == 1)
+ if (r == 1) {
log_trace(TRACE_LOOKUP, "lookup: %s \"%s\" as %s in table %s:%s -> %s%s%s",
lk ? "lookup" : "check",
lkey,
table_backend_name(table->t_backend),
table->t_name,
lk ? "\"" : "",
- (lk) ? table_dump_lookup(kind, lk): "found",
+ (lk) ? buf : "found",
lk ? "\"" : "");
+ if (buf)
+ r = table_parse_lookup(kind, lkey, buf, lk);
+ }
else
log_trace(TRACE_LOOKUP, "lookup: %s \"%s\" as %s in table %s:%s -> %d",
lk ? "lookup" : "check",
table->t_name,
r);
+ free(buf);
+
return (r);
}
table_fetch(struct table *table, struct dict *params, enum table_service kind, union lookup *lk)
{
int r;
+ char *buf = NULL;
if (table->t_backend->fetch == NULL)
return (-1);
- r = table->t_backend->fetch(table->t_handle, params, kind, lk);
+ r = table->t_backend->fetch(table->t_handle, params, kind, lk ? &buf : NULL);
- if (r == 1)
+ 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_name,
lk ? "\"" : "",
- (lk) ? table_dump_lookup(kind, lk): "found",
+ (lk) ? buf : "found",
lk ? "\"" : "");
+ if (buf)
+ r = table_parse_lookup(kind, NULL, buf, lk);
+ }
else
log_trace(TRACE_LOOKUP, "lookup: fetch %s from table %s:%s -> %d",
table_service_name(kind),
table->t_name,
r);
+ free(buf);
+
return (r);
}
table_close(t);
}
-int
+static int
table_parse_lookup(enum table_service service, const char *key,
const char *line, union lookup *lk)
{
-/* $OpenBSD: table_db.c,v 1.10 2018/05/31 21:06:12 gilles Exp $ */
+/* $OpenBSD: table_db.c,v 1.11 2018/12/23 15:53:24 eric Exp $ */
/*
* Copyright (c) 2011 Gilles Chehade <gilles@poolp.org>
static int table_db_config(struct table *);
static int table_db_update(struct table *);
static void *table_db_open(struct table *);
-static int table_db_lookup(void *, struct dict *, const char *, enum table_service, union lookup *);
-static int table_db_fetch(void *, struct dict *, enum table_service, union lookup *);
+static int table_db_lookup(void *, struct dict *, const char *, enum table_service, char **);
+static int table_db_fetch(void *, struct dict *, enum table_service, char **);
static void table_db_close(void *);
static char *table_db_get_entry(void *, const char *, size_t *);
static int
table_db_lookup(void *hdl, struct dict *params, const char *key, enum table_service service,
- union lookup *lk)
+ char **dst)
{
struct dbhandle *handle = hdl;
struct table *table = NULL;
return 0;
ret = 1;
- if (lk)
- ret = table_parse_lookup(service, key, line, lk);
- free(line);
+ if (dst)
+ *dst = line;
+ else
+ free(line);
return ret;
}
static int
-table_db_fetch(void *hdl, struct dict *params, enum table_service service, union lookup *lk)
+table_db_fetch(void *hdl, struct dict *params, enum table_service service, char **dst)
{
struct dbhandle *handle = hdl;
struct table *table = handle->table;
return 0;
}
- return table_parse_lookup(service, NULL, dbk.data, lk);
+ if (dst) {
+ *dst = strdup(dbk.data);
+ if (*dst == NULL)
+ return -1;
+ }
+
+ return 1;
}
-/* $OpenBSD: table_getpwnam.c,v 1.4 2015/01/20 17:37:54 deraadt Exp $ */
+/* $OpenBSD: table_getpwnam.c,v 1.5 2018/12/23 15:53:24 eric Exp $ */
/*
* Copyright (c) 2012 Gilles Chehade <gilles@poolp.org>
static int table_getpwnam_update(struct table *);
static void *table_getpwnam_open(struct table *);
static int table_getpwnam_lookup(void *, struct dict *, const char *, enum table_service,
- union lookup *);
+ char **);
static void table_getpwnam_close(void *);
struct table_backend table_backend_getpwnam = {
static int
table_getpwnam_lookup(void *hdl, struct dict *params, const char *key, enum table_service kind,
- union lookup *lk)
+ char **dst)
{
struct passwd *pw;
- size_t s;
if (kind != K_USERINFO)
return -1;
return -1;
return 0;
}
- if (lk == NULL)
+ if (dst == NULL)
return 1;
- lk->userinfo.uid = pw->pw_uid;
- lk->userinfo.gid = pw->pw_gid;
- s = strlcpy(lk->userinfo.username, pw->pw_name,
- sizeof(lk->userinfo.username));
- if (s >= sizeof(lk->userinfo.username))
- return (-1);
- s = strlcpy(lk->userinfo.directory, pw->pw_dir,
- sizeof(lk->userinfo.directory));
- if (s >= sizeof(lk->userinfo.directory))
- return (-1);
+ if (asprintf(dst, "%d:%d:%s",
+ pw->pw_uid,
+ pw->pw_gid,
+ pw->pw_dir) == -1) {
+ *dst = NULL;
+ return -1;
+ }
return (1);
}
-/* $OpenBSD: table_proc.c,v 1.7 2018/05/31 21:06:12 gilles Exp $ */
+/* $OpenBSD: table_proc.c,v 1.8 2018/12/23 15:53:24 eric Exp $ */
/*
* Copyright (c) 2013 Eric Faurot <eric@openbsd.org>
}
static int
-table_proc_lookup(void *arg, struct dict *params, const char *k, enum table_service s,
- union lookup *lk)
+table_proc_lookup(void *arg, struct dict *params, const char *k, enum table_service s, char **dst)
{
struct table_proc_priv *priv = arg;
struct ibuf *buf;
int r;
buf = imsg_create(&priv->ibuf,
- lk ? PROC_TABLE_LOOKUP : PROC_TABLE_CHECK, 0, 0,
+ dst ? PROC_TABLE_LOOKUP : PROC_TABLE_CHECK, 0, 0,
sizeof(s) + strlen(k) + 1);
if (buf == NULL)
table_proc_call(priv);
table_proc_read(&r, sizeof(r));
- if (r == 1 && lk) {
+ if (r == 1 && dst) {
if (rlen == 0) {
log_warnx("warn: table-proc: empty response");
fatalx("table-proc: exiting");
log_warnx("warn: table-proc: not NUL-terminated");
fatalx("table-proc: exiting");
}
- r = table_parse_lookup(s, k, rdata, lk);
+ *dst = strdup(rdata);
+ if (*dst == NULL)
+ r = -1;
table_proc_read(NULL, rlen);
}
}
static int
-table_proc_fetch(void *arg, struct dict *params, enum table_service s, union lookup *lk)
+table_proc_fetch(void *arg, struct dict *params, enum table_service s, char **dst)
{
struct table_proc_priv *priv = arg;
struct ibuf *buf;
log_warnx("warn: table-proc: not NUL-terminated");
fatalx("table-proc: exiting");
}
- r = table_parse_lookup(s, NULL, rdata, lk);
+ *dst = strdup(rdata);
+ if (*dst == NULL)
+ r = -1;
table_proc_read(NULL, rlen);
}
-/* $OpenBSD: table_static.c,v 1.20 2018/11/01 10:47:46 gilles Exp $ */
+/* $OpenBSD: table_static.c,v 1.21 2018/12/23 15:53:24 eric Exp $ */
/*
* Copyright (c) 2013 Eric Faurot <eric@openbsd.org>
static int table_static_update(struct table *);
static void *table_static_open(struct table *);
static int table_static_lookup(void *, struct dict *, const char *,
- enum table_service, union lookup *);
+ enum table_service, char **);
static int table_static_fetch(void *, struct dict *, enum table_service,
- union lookup *);
+ char **);
static void table_static_close(void *);
struct table_backend table_backend_static = {
static int
table_static_lookup(void *hdl, struct dict *params, const char *key,
- enum table_service service, union lookup *lk)
+ enum table_service service, char **dst)
{
struct table *m = hdl;
char *line;
break;
}
- if (lk == NULL)
+ if (dst == NULL)
return ret ? 1 : 0;
if (ret == 0)
return 0;
- return table_parse_lookup(service, key, line, lk);
+ *dst = strdup(line);
+ if (*dst == NULL)
+ return -1;
+
+ return 1;
}
static int
table_static_fetch(void *hdl, struct dict *params,
- enum table_service service, union lookup *lk)
+ enum table_service service, char **dst)
{
struct table *t = hdl;
const char *k;
return 0;
}
- if (lk == NULL)
+ if (dst == NULL)
return 1;
- return table_parse_lookup(service, NULL, k, lk);
+ *dst = strdup(k);
+ if (*dst == NULL)
+ return -1;
+
+ return 1;
}