From b700b1d86abb658af8e7008c1ddf094df8919706 Mon Sep 17 00:00:00 2001 From: eric Date: Thu, 27 Dec 2018 08:08:06 +0000 Subject: [PATCH] Make the backend open method return an int to report success. The implementation is responsible for setting the handle pointer as needed. ok gilles@ --- usr.sbin/smtpd/smtpd.h | 4 ++-- usr.sbin/smtpd/table.c | 8 ++------ usr.sbin/smtpd/table_db.c | 20 +++++++++++++++----- usr.sbin/smtpd/table_getpwnam.c | 8 ++++---- usr.sbin/smtpd/table_proc.c | 8 +++++--- usr.sbin/smtpd/table_static.c | 9 +++++---- 6 files changed, 33 insertions(+), 24 deletions(-) diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h index a3febed00ab..68b710c54e0 100644 --- a/usr.sbin/smtpd/smtpd.h +++ b/usr.sbin/smtpd/smtpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpd.h,v 1.607 2018/12/26 20:13:43 eric Exp $ */ +/* $OpenBSD: smtpd.h,v 1.608 2018/12/27 08:08:06 eric Exp $ */ /* * Copyright (c) 2008 Gilles Chehade @@ -365,7 +365,7 @@ struct table_backend { const char *name; const unsigned int services; int (*config)(struct table *); - void *(*open)(struct table *); + int (*open)(struct table *); int (*update)(struct table *); void (*close)(void *); int (*lookup)(void *, enum table_service, const char *, char **); diff --git a/usr.sbin/smtpd/table.c b/usr.sbin/smtpd/table.c index 8231c09a8f9..0c23f1b14b4 100644 --- a/usr.sbin/smtpd/table.c +++ b/usr.sbin/smtpd/table.c @@ -1,4 +1,4 @@ -/* $OpenBSD: table.c,v 1.38 2018/12/26 20:13:43 eric Exp $ */ +/* $OpenBSD: table.c,v 1.39 2018/12/27 08:08:06 eric Exp $ */ /* * Copyright (c) 2013 Eric Faurot @@ -340,13 +340,9 @@ table_check_use(struct table *t, uint32_t tmask, uint32_t smask) int table_open(struct table *t) { - t->t_handle = NULL; if (t->t_backend->open == NULL) return (1); - t->t_handle = t->t_backend->open(t); - if (t->t_handle == NULL) - return (0); - return (1); + return (t->t_backend->open(t)); } void diff --git a/usr.sbin/smtpd/table_db.c b/usr.sbin/smtpd/table_db.c index c8940616a6c..3d668d0e2ba 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.14 2018/12/26 20:13:43 eric Exp $ */ +/* $OpenBSD: table_db.c,v 1.15 2018/12/27 08:08:06 eric Exp $ */ /* * Copyright (c) 2011 Gilles Chehade @@ -42,7 +42,8 @@ /* db(3) backend */ 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_open(struct table *); +static void *table_db_open2(struct table *); static int table_db_lookup(void *, enum table_service, const char *, char **); static int table_db_fetch(void *, enum table_service, char **); static void table_db_close(void *); @@ -83,7 +84,7 @@ table_db_config(struct table *table) { struct dbhandle *handle; - handle = table_db_open(table); + handle = table_db_open2(table); if (handle == NULL) return 0; @@ -96,7 +97,7 @@ table_db_update(struct table *table) { struct dbhandle *handle; - handle = table_db_open(table); + handle = table_db_open2(table); if (handle == NULL) return 0; @@ -105,8 +106,17 @@ table_db_update(struct table *table) return 1; } -static void * +static int table_db_open(struct table *table) +{ + table->t_handle = table_db_open2(table); + if (table->t_handle == NULL) + return 0; + return 1; +} + +static void * +table_db_open2(struct table *table) { struct dbhandle *handle; struct stat sb; diff --git a/usr.sbin/smtpd/table_getpwnam.c b/usr.sbin/smtpd/table_getpwnam.c index 1907da1545f..9e81e102d43 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.8 2018/12/26 20:13:43 eric Exp $ */ +/* $OpenBSD: table_getpwnam.c,v 1.9 2018/12/27 08:08:06 eric Exp $ */ /* * Copyright (c) 2012 Gilles Chehade @@ -40,7 +40,7 @@ /* getpwnam(3) backend */ static int table_getpwnam_config(struct table *); static int table_getpwnam_update(struct table *); -static void *table_getpwnam_open(struct table *); +static int table_getpwnam_open(struct table *); static int table_getpwnam_lookup(void *, enum table_service, const char *, char **); static void table_getpwnam_close(void *); @@ -70,10 +70,10 @@ table_getpwnam_update(struct table *table) return 1; } -static void * +static int table_getpwnam_open(struct table *table) { - return table; + return 1; } static void diff --git a/usr.sbin/smtpd/table_proc.c b/usr.sbin/smtpd/table_proc.c index e8d915bff36..970419db24f 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.11 2018/12/26 20:13:43 eric Exp $ */ +/* $OpenBSD: table_proc.c,v 1.12 2018/12/27 08:08:06 eric Exp $ */ /* * Copyright (c) 2013 Eric Faurot @@ -116,7 +116,7 @@ table_proc_end(void) * API */ -static void * +static int table_proc_open(struct table *table) { struct table_proc_priv *priv; @@ -139,7 +139,9 @@ table_proc_open(struct table *table) table_proc_call(priv); table_proc_end(); - return (priv); + table->t_handle = priv; + + return (1); } static int diff --git a/usr.sbin/smtpd/table_static.c b/usr.sbin/smtpd/table_static.c index 196713b5918..d8b9da9fc9f 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.24 2018/12/26 20:13:43 eric Exp $ */ +/* $OpenBSD: table_static.c,v 1.25 2018/12/27 08:08:06 eric Exp $ */ /* * Copyright (c) 2013 Eric Faurot @@ -41,7 +41,7 @@ /* static backend */ static int table_static_config(struct table *); static int table_static_update(struct table *); -static void *table_static_open(struct table *); +static int table_static_open(struct table *); static int table_static_lookup(void *, enum table_service, const char *, char **); static int table_static_fetch(void *, enum table_service, char **); @@ -202,10 +202,11 @@ err: return 0; } -static void * +static int table_static_open(struct table *table) { - return table; + table->t_handle = table; + return 1; } static void -- 2.20.1