]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
auth: Remove support for sharing passdb/userdb_module by mutiple auth_passdb/userdb
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Thu, 18 Jan 2024 20:20:29 +0000 (15:20 -0500)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Wed, 12 Feb 2025 10:34:11 +0000 (12:34 +0200)
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
src/auth/passdb.h
src/auth/userdb.c
src/auth/userdb.h

index a9cb8dc03b9092ff7ef5ec54ac57c1c6a6dfc488..32d214a623aca3ed6a31c8fe237d839f2b47c578 100644 (file)
@@ -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);
index 91c8902fd4e5fc8ea922a4efe130adca06d5460a..256fd8b5e9c4636cdbe4ac7081a75e62ba880f7b 100644 (file)
@@ -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;
 };
 
index 72b671cf21f79d632044143a4023a12fe67d8be4..18e901bb10dabbf74d4b58e6b23019f34600921e 100644 (file)
@@ -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);
index d23e0ea6aa383ca2071d592182bfc7f52d63d6ea..dfc637fd12298de45c8c49371b59d245953e10f5 100644 (file)
@@ -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;
 };