From 648df97465f68036d820078709d98dc4a4c061da Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Thu, 18 Jan 2024 15:20:29 -0500 Subject: [PATCH] auth: Remove support for sharing passdb/userdb_module by mutiple auth_passdb/userdb This isn't very useful. The sharing of memory/connections is wanted between both passdb and userdb in any case, which is what all the passdbs/userdbs already do. Sharing of passdb_module would reduce memory usage only trivialy, but it makes the more complex, especially after the following API changes. --- src/auth/passdb.c | 40 +++++++++++----------------------------- src/auth/passdb.h | 4 ---- src/auth/userdb.c | 40 +++++++++++----------------------------- src/auth/userdb.h | 4 ---- 4 files changed, 22 insertions(+), 66 deletions(-) diff --git a/src/auth/passdb.c b/src/auth/passdb.c index a9cb8dc03b..32d214a623 100644 --- a/src/auth/passdb.c +++ b/src/auth/passdb.c @@ -170,30 +170,12 @@ void passdb_handle_credentials(enum passdb_result result, callback(result, credentials, size, auth_request); } -static struct passdb_module * -passdb_find(const char *driver, const char *args, unsigned int *idx_r) -{ - struct passdb_module *const *passdbs; - unsigned int i, count; - - passdbs = array_get(&passdb_modules, &count); - for (i = 0; i < count; i++) { - if (strcmp(passdbs[i]->iface.name, driver) == 0 && - strcmp(passdbs[i]->args, args) == 0) { - *idx_r = i; - return passdbs[i]; - } - } - return NULL; -} - struct passdb_module * passdb_preinit(pool_t pool, const struct auth_passdb_settings *set) { static unsigned int auth_passdb_id = 0; struct passdb_module_interface *iface; struct passdb_module *passdb; - unsigned int idx; iface = passdb_interface_find(set->driver); if (iface == NULL || iface->verify_plain == NULL) { @@ -213,10 +195,6 @@ passdb_preinit(pool_t pool, const struct auth_passdb_settings *set) set->driver, set->args); } - passdb = passdb_find(set->driver, set->args, &idx); - if (passdb != NULL) - return passdb; - if (iface->preinit_legacy == NULL) passdb = p_new(pool, struct passdb_module, 1); else @@ -224,8 +202,6 @@ passdb_preinit(pool_t pool, const struct auth_passdb_settings *set) passdb->id = ++auth_passdb_id; passdb->iface = *iface; passdb->args = p_strdup(pool, set->args); - /* NOTE: if anything else than driver & args are added here, - passdb_find() also needs to be updated. */ array_push_back(&passdb_modules, &passdb); return passdb; } @@ -239,16 +215,22 @@ void passdb_init(struct passdb_module *passdb) void passdb_deinit(struct passdb_module *passdb) { - unsigned int idx; - i_assert(passdb->init_refcount > 0); if (--passdb->init_refcount > 0) return; - if (passdb_find(passdb->iface.name, passdb->args, &idx) == NULL) - i_unreached(); - array_delete(&passdb_modules, idx, 1); + struct passdb_module *const *passdbs; + unsigned int i, count; + + passdbs = array_get(&passdb_modules, &count); + for (i = 0; i < count; i++) { + if (passdbs[i] == passdb) { + array_delete(&passdb_modules, i, 1); + break; + } + } + i_assert(i < count); if (passdb->iface.deinit != NULL) passdb->iface.deinit(passdb); diff --git a/src/auth/passdb.h b/src/auth/passdb.h index 91c8902fd4..256fd8b5e9 100644 --- a/src/auth/passdb.h +++ b/src/auth/passdb.h @@ -73,10 +73,6 @@ struct passdb_module { /* number of time init() has been called */ int init_refcount; - /* WARNING: avoid adding anything here that isn't based on args. - if you do, you need to change passdb.c:passdb_find() also to avoid - accidentally merging wrong passdbs. */ - struct passdb_module_interface iface; }; diff --git a/src/auth/userdb.c b/src/auth/userdb.c index 72b671cf21..18e901bb10 100644 --- a/src/auth/userdb.c +++ b/src/auth/userdb.c @@ -104,30 +104,12 @@ gid_t userdb_parse_gid(struct auth_request *request, const char *str) } } -static struct userdb_module * -userdb_find(const char *driver, const char *args, unsigned int *idx_r) -{ - struct userdb_module *const *userdbs; - unsigned int i, count; - - userdbs = array_get(&userdb_modules, &count); - for (i = 0; i < count; i++) { - if (strcmp(userdbs[i]->iface->name, driver) == 0 && - strcmp(userdbs[i]->args, args) == 0) { - *idx_r = i; - return userdbs[i]; - } - } - return NULL; -} - struct userdb_module * userdb_preinit(pool_t pool, const struct auth_userdb_settings *set) { static unsigned int auth_userdb_id = 0; struct userdb_module_interface *iface; struct userdb_module *userdb; - unsigned int idx; iface = userdb_interface_find(set->driver); if (iface == NULL || iface->lookup == NULL) { @@ -147,10 +129,6 @@ userdb_preinit(pool_t pool, const struct auth_userdb_settings *set) set->driver, set->args); } - userdb = userdb_find(set->driver, set->args, &idx); - if (userdb != NULL) - return userdb; - if (iface->preinit_legacy == NULL) userdb = p_new(pool, struct userdb_module, 1); else @@ -158,8 +136,6 @@ userdb_preinit(pool_t pool, const struct auth_userdb_settings *set) userdb->id = ++auth_userdb_id; userdb->iface = iface; userdb->args = p_strdup(pool, set->args); - /* NOTE: if anything else than driver & args are added here, - userdb_find() also needs to be updated. */ array_push_back(&userdb_modules, &userdb); return userdb; } @@ -173,16 +149,22 @@ void userdb_init(struct userdb_module *userdb) void userdb_deinit(struct userdb_module *userdb) { - unsigned int idx; - i_assert(userdb->init_refcount > 0); if (--userdb->init_refcount > 0) return; - if (userdb_find(userdb->iface->name, userdb->args, &idx) == NULL) - i_unreached(); - array_delete(&userdb_modules, idx, 1); + struct userdb_module *const *userdbs; + unsigned int i, count; + + userdbs = array_get(&userdb_modules, &count); + for (i = 0; i < count; i++) { + if (userdbs[i] == userdb) { + array_delete(&userdb_modules, i, 1); + break; + } + } + i_assert(i < count); if (userdb->iface->deinit != NULL) userdb->iface->deinit(userdb); diff --git a/src/auth/userdb.h b/src/auth/userdb.h index d23e0ea6aa..dfc637fd12 100644 --- a/src/auth/userdb.h +++ b/src/auth/userdb.h @@ -35,10 +35,6 @@ struct userdb_module { /* number of time init() has been called */ int init_refcount; - /* WARNING: avoid adding anything here that isn't based on args. - if you do, you need to change userdb.c:userdb_find() also to avoid - accidentally merging wrong userdbs. */ - const struct userdb_module_interface *iface; }; -- 2.47.3