]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
auth: Use AUTH_CACHE_KEY_USER instead of per-database constants
authorAki Tuomi <aki.tuomi@open-xchange.com>
Fri, 25 Jul 2025 05:16:52 +0000 (08:16 +0300)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Fri, 1 Aug 2025 08:18:11 +0000 (08:18 +0000)
Fixes cache key issue where users would end up overwriting
each other in cache due to cache key being essentially static
string because we no longer support %u.

Forgotten in 2e298e7ee98b6df61cf85117f000290d60a473b8

src/auth/auth-settings.h
src/auth/passdb-bsdauth.c
src/auth/passdb-oauth2.c
src/auth/passdb-pam.c
src/auth/passdb-passwd.c
src/auth/userdb-passwd.c

index 1d420eceaaf8b703345672b3f0d3d2341eb6da0f..90aba17ec38c955f0748dea93cb8c2204899c846 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef AUTH_SETTINGS_H
 #define AUTH_SETTINGS_H
 
+#define AUTH_CACHE_KEY_USER "%{user}"
+
 struct master_service;
 struct master_service_settings_output;
 
index 68292679b7fc53daa822f55156c364c9367156b0..1b86da4053c2cdfc5398ebc11f447d1644054b0d 100644 (file)
@@ -14,8 +14,6 @@
 #include <login_cap.h>
 #include <bsd_auth.h>
 
-#define BSDAUTH_CACHE_KEY "%u"
-
 struct passdb_bsdauth_settings {
        pool_t pool;
 };
@@ -104,7 +102,7 @@ bsdauth_preinit(pool_t pool, struct event *event,
                         &post_set, error_r) < 0)
                return -1;
        module->default_cache_key = auth_cache_parse_key_and_fields(
-               pool, BSDAUTH_CACHE_KEY, &post_set->fields, "bsdauth");
+               pool, AUTH_CACHE_KEY_USER, &post_set->fields, "bsdauth");
 
        settings_free(post_set);
        *module_r = module;
index 96d902d323d96dd109d801b93a7fa2d3222eba8b..91fed0601838ea154c6a8fd6667f14e51801cb06 100644 (file)
@@ -53,7 +53,7 @@ oauth2_preinit(pool_t pool, struct event *event, struct passdb_module **module_r
        if (db_oauth2_init(event, TRUE, &module->db, error_r) < 0)
                return -1;
        module->module.default_pass_scheme = "PLAIN";
-       module->module.default_cache_key = "%u";
+       module->module.default_cache_key = AUTH_CACHE_KEY_USER;
        *module_r = &module->module;
        return 0;
 }
index 2acbceb80a39ad70696d0df78a71bd1ca0d738b1..fdf0f573ef4a57f030d0de1d5fc99a1199b928c2 100644 (file)
@@ -415,7 +415,8 @@ static int pam_preinit(pool_t pool, struct event *event,
        module = p_new(pool, struct pam_passdb_module, 1);
        module->module.default_cache_key =
                auth_cache_parse_key_and_fields(pool,
-                                               t_strdup_printf("%%u/%s", set->service_name),
+                                               t_strdup_printf("%"AUTH_CACHE_KEY_USER"\t%s",
+                                                               set->service_name),
                                                &post_set->fields, "pam");
        module->requests_left = set->max_requests;
        module->pam_setcred = set->setcred;
index 13003151f9c409adcc97564bb3331e00029d1b6c..22e2eae7fa3204d7f7aa4eaa5e843b9fb8ac0004 100644 (file)
@@ -10,7 +10,6 @@
 #include "safe-memset.h"
 #include "ipwd.h"
 
-#define PASSWD_CACHE_KEY "%u"
 #define PASSWD_PASS_SCHEME "CRYPT"
 
 #undef DEF
@@ -142,7 +141,7 @@ static int passwd_preinit(pool_t pool, struct event *event,
                         &post_set, error_r) < 0)
                return -1;
        module->default_cache_key = auth_cache_parse_key_and_fields(pool,
-                                                                   PASSWD_CACHE_KEY,
+                                                                   AUTH_CACHE_KEY_USER,
                                                                    &post_set->fields,
                                                                    "passwd");
        settings_free(post_set);
index 5241129a0ccb8c8e861334dcf757538b1f6406fa..14cf90a6d65f65f70e439ede73b603b748045899 100644 (file)
@@ -9,7 +9,6 @@
 #include "ipwd.h"
 #include "time-util.h"
 
-#define USER_CACHE_KEY "%u"
 #define PASSWD_SLOW_WARN_MSECS (10*1000)
 #define PASSWD_SLOW_MASTER_WARN_MSECS 50
 #define PASSDB_SLOW_MASTER_WARN_COUNT_INTERVAL 100
@@ -225,7 +224,7 @@ static int passwd_preinit(pool_t pool, struct event *event ATTR_UNUSED,
        struct passwd_userdb_module *module =
                p_new(pool, struct passwd_userdb_module, 1);
 
-       module->module.default_cache_key = USER_CACHE_KEY;
+       module->module.default_cache_key = AUTH_CACHE_KEY_USER;
        *module_r = &module->module;
        return 0;
 }