]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
auth: Don't initialize cache key if caching is disabled for the passdb
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Thu, 6 Nov 2025 12:44:35 +0000 (14:44 +0200)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Thu, 13 Nov 2025 22:50:48 +0000 (22:50 +0000)
src/auth/auth.c
src/auth/passdb-bsdauth.c
src/auth/passdb-ldap.c
src/auth/passdb-pam.c
src/auth/passdb-passwd.c
src/auth/passdb-sql.c
src/auth/passdb.c
src/auth/passdb.h
src/auth/test-mock.c

index 781298f12c7f0b9836bc064adf150c564f2a961a..e301e6a344f876f81954ce467a143a3ace65fb9b 100644 (file)
@@ -125,7 +125,8 @@ auth_passdb_preinit(struct auth *auth, const struct auth_passdb_settings *_set,
        for (dest = passdbs; *dest != NULL; dest = &(*dest)->next) ;
        *dest = auth_passdb;
 
-       auth_passdb->passdb = passdb_preinit(auth->pool, event, set);
+       auth_passdb->passdb = passdb_preinit(auth->pool, event, set,
+                                            auth->protocol_set->cache_size > 0);
        if (auth_passdb->passdb->default_cache_key != NULL && set->use_cache) {
                auth_passdb->cache_key = auth_passdb->passdb->default_cache_key;
        } else {
index c4d1bda4e8bd1f0520bebb266d70fc46e8c5c6ea..c2372b6a5621023be4341abb25343eb849860424 100644 (file)
@@ -89,7 +89,7 @@ bsdauth_verify_plain(struct auth_request *request, const char *password,
 
 static int
 bsdauth_preinit(pool_t pool, struct event *event,
-               const struct passdb_parameters *passdb_params ATTR_UNUSED,
+               const struct passdb_parameters *passdb_params,
                struct passdb_module **module_r,
                const char **error_r)
 {
@@ -102,8 +102,9 @@ bsdauth_preinit(pool_t pool, struct event *event,
                         SETTINGS_GET_FLAG_NO_EXPAND,
                         &post_set, error_r) < 0)
                return -1;
-       module->default_cache_key = auth_cache_parse_key_and_fields(
-               pool, AUTH_CACHE_KEY_USER, &post_set->fields, "bsdauth");
+       module->default_cache_key = !passdb_params->use_cache ? NULL :
+               auth_cache_parse_key_and_fields(pool, AUTH_CACHE_KEY_USER,
+                                               &post_set->fields, "bsdauth");
 
        settings_free(post_set);
        *module_r = module;
index bc93b545091e17ebc2954fe3ff2aadcb7bb52d63..a661552e124cc15abb886fd2582fe2cc264fb3ba 100644 (file)
@@ -440,7 +440,7 @@ static void ldap_lookup_credentials(struct auth_request *request,
 
 static int
 passdb_ldap_preinit(pool_t pool, struct event *event,
-                   const struct passdb_parameters *passdb_params ATTR_UNUSED,
+                   const struct passdb_parameters *passdb_params,
                    struct passdb_module **module_r,
                    const char **error_r)
 {
@@ -465,11 +465,12 @@ passdb_ldap_preinit(pool_t pool, struct event *event,
                                    ldap_pre->passdb_ldap_bind ?
                                        "password" : NULL);
 
-       module->module.default_cache_key = auth_cache_parse_key_and_fields(
-               pool, t_strconcat(ldap_pre->ldap_base,
-                                 ldap_pre->passdb_ldap_bind_userdn,
-                                 ldap_pre->passdb_ldap_filter, NULL),
-               &auth_post->fields, NULL);
+       module->module.default_cache_key = !passdb_params->use_cache ? NULL :
+               auth_cache_parse_key_and_fields(pool,
+                       t_strconcat(ldap_pre->ldap_base,
+                                   ldap_pre->passdb_ldap_bind_userdn,
+                                   ldap_pre->passdb_ldap_filter, NULL),
+                       &auth_post->fields, NULL);
 
        *module_r = &module->module;
        ret = 0;
index 87a8863509b514ee13b21beeb9be12ef10304e20..1dffd2abafd63b9cbff82a6758fc20e8c1718c58 100644 (file)
@@ -393,7 +393,7 @@ pam_verify_plain(struct auth_request *request, const char *password,
 
 static int
 pam_preinit(pool_t pool, struct event *event,
-           const struct passdb_parameters *passdb_params ATTR_UNUSED,
+           const struct passdb_parameters *passdb_params,
            struct passdb_module **module_r, const char **error_r)
 {
        const struct auth_pam_settings *set;
@@ -415,7 +415,7 @@ pam_preinit(pool_t pool, struct event *event,
        }
 
        module = p_new(pool, struct pam_passdb_module, 1);
-       module->module.default_cache_key =
+       module->module.default_cache_key = !passdb_params->use_cache ? NULL :
                auth_cache_parse_key_and_fields(pool,
                                                t_strdup_printf("%"AUTH_CACHE_KEY_USER"\t%s",
                                                                set->service_name),
index 99196d1a32f55891cdc18ca91579d48ee22ffa33..4d08de753bc06806a140ab343f9d21ad99f87f6b 100644 (file)
@@ -129,7 +129,7 @@ passwd_lookup_credentials(struct auth_request *request,
 
 static int
 passwd_preinit(pool_t pool, struct event *event,
-              const struct passdb_parameters *passdb_params ATTR_UNUSED,
+              const struct passdb_parameters *passdb_params,
               struct passdb_module **module_r,
               const char **error_r)
 {
@@ -142,10 +142,9 @@ passwd_preinit(pool_t pool, struct event *event,
                         SETTINGS_GET_FLAG_NO_EXPAND,
                         &post_set, error_r) < 0)
                return -1;
-       module->default_cache_key = auth_cache_parse_key_and_fields(pool,
-                                                                   AUTH_CACHE_KEY_USER,
-                                                                   &post_set->fields,
-                                                                   "passwd");
+       module->default_cache_key = !passdb_params->use_cache ? NULL :
+               auth_cache_parse_key_and_fields(pool, AUTH_CACHE_KEY_USER,
+                                               &post_set->fields, "passwd");
        settings_free(post_set);
        *module_r = module;
        return 0;
index 635b6ffe9e86e7062156e79ed31bff2d0ae07cdf..1b31c0bd4063bb89ed3398098f941c7f235ad010 100644 (file)
@@ -278,7 +278,7 @@ static void sql_set_credentials(struct auth_request *request,
 
 static int
 passdb_sql_preinit(pool_t pool, struct event *event,
-                  const struct passdb_parameters *passdb_params ATTR_UNUSED,
+                  const struct passdb_parameters *passdb_params,
                   struct passdb_module **module_r, const char **error_r)
 {
        struct sql_passdb_module *module;
@@ -305,7 +305,7 @@ passdb_sql_preinit(pool_t pool, struct event *event,
                return -1;
        }
 
-       module->module.default_cache_key =
+       module->module.default_cache_key = !passdb_params->use_cache ? NULL :
                auth_cache_parse_key_and_fields(pool, set->query,
                                                &post_set->fields, "sql");
        settings_free(set);
index c8c3bf9dfcfd678ee9c6db05eeb52e4f7c6c2f1d..af7fd43034f4fe6fcb26de1cd758eaed80907a7e 100644 (file)
@@ -166,7 +166,7 @@ void passdb_handle_credentials(enum passdb_result result,
 
 struct passdb_module *
 passdb_preinit(pool_t pool, struct event *event,
-              const struct auth_passdb_settings *set)
+              const struct auth_passdb_settings *set, bool use_cache)
 {
        static unsigned int auth_passdb_id = 0;
        struct passdb_module_interface *iface;
@@ -187,8 +187,9 @@ passdb_preinit(pool_t pool, struct event *event,
        }
 
        if (iface->preinit != NULL) {
-               struct passdb_parameters params;
-               i_zero(&params);
+               struct passdb_parameters params = {
+                       .use_cache = use_cache && set->use_cache,
+               };
                if (iface->preinit(pool, event, &params, &passdb, &error) < 0)
                        i_fatal("passdb %s: %s", set->name, error);
                passdb->default_pass_scheme =
index fe70d33448d0aa9ff01522d5fd5505cd9519b29e..ab3763608963a856d29d2f3954b18694be1a5338 100644 (file)
@@ -35,6 +35,8 @@ typedef void set_credentials_callback_t(bool success,
                                        struct auth_request *request);
 
 struct passdb_parameters {
+       /* Enable cache for the passdb */
+       bool use_cache;
 };
 
 struct passdb_module_interface {
@@ -104,7 +106,7 @@ void passdb_handle_credentials(enum passdb_result result,
 
 struct passdb_module *
 passdb_preinit(pool_t pool, struct event *event,
-              const struct auth_passdb_settings *set);
+              const struct auth_passdb_settings *set, bool use_cache);
 void passdb_init(struct passdb_module *passdb);
 void passdb_deinit(struct passdb_module *passdb);
 
index 1ff1b5e5836b3cf7f0b50e7f3eb507a381e03c07..c061dffe1277d8f5896edcd285eeac97008d148d 100644 (file)
@@ -76,7 +76,7 @@ void passdb_mock_mod_init(void)
                .master = FALSE,
        };
        struct event *event = event_create(NULL);
-       mock_passdb_mod = passdb_preinit(mock_pool, event, &set);
+       mock_passdb_mod = passdb_preinit(mock_pool, event, &set, FALSE);
        event_unref(&event);
        passdb_init(mock_passdb_mod);
 }