]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
auth: Cache master user logins also.
authorTimo Sirainen <tss@iki.fi>
Thu, 24 Oct 2013 11:59:03 +0000 (14:59 +0300)
committerTimo Sirainen <tss@iki.fi>
Thu, 24 Oct 2013 11:59:03 +0000 (14:59 +0300)
src/auth/auth-cache.c
src/auth/auth-request.c
src/auth/auth-request.h
src/auth/passdb-cache.c

index 5d9aea14811c46c6f0772e88d0f09f2574d1059f..56e49a3f059e4299b2c94c139a8d711801ff682f 100644 (file)
@@ -273,19 +273,24 @@ static bool auth_cache_node_is_user(struct auth_cache_node *node,
        const char *data = node->data;
        unsigned int username_len;
 
-       /* The cache nodes begin with "P"/"U", passdb/userdb ID, "/" and
-          then usually followed by the username. It's too much trouble to
-          keep track of all the cache keys, so we'll just match it as if it
-          was the username. If e.g. '%n' is used in the cache key instead of
-          '%u', it means that cache entries can be removed only when @domain
-          isn't in the username parameter. */
+       /* The cache nodes begin with "P"/"U", passdb/userdb ID, optional
+          "+" master user, "\t" and then usually followed by the username.
+          It's too much trouble to keep track of all the cache keys, so we'll
+          just match it as if it was the username. If e.g. '%n' is used in the
+          cache key instead of '%u', it means that cache entries can be
+          removed only when @domain isn't in the username parameter. */
        if (*data != 'P' && *data != 'U')
                return FALSE;
        data++;
 
        while (*data >= '0' && *data <= '9')
                data++;
-       if (*data != '/')
+       if (*data == '+') {
+               /* skip over +master_user */
+               while (*data != '\t' && *data != '\0')
+                       data++;
+       }
+       if (*data != '\t')
                return FALSE;
        data++;
 
@@ -339,7 +344,9 @@ auth_request_expand_cache_key(const struct auth_request *request,
 
        /* Uniquely identify the request's passdb/userdb with the P/U prefix
           and by "%!", which expands to the passdb/userdb ID number. */
-       key = t_strconcat(request->userdb_lookup ? "U" : "P", "%!/", key, NULL);
+       key = t_strconcat(request->userdb_lookup ? "U" : "P", "%!",
+                         request->master_user == NULL ? "" : "+%{master_user}",
+                         "\t", key, NULL);
 
        str = t_str_new(256);
        var_expand(str, key,
@@ -407,7 +414,8 @@ void auth_cache_insert(struct auth_cache *cache, struct auth_request *request,
           a master user login */
        current_username = request->user;
        if (request->translated_username != NULL &&
-           request->requested_login_user == NULL)
+           request->requested_login_user == NULL &&
+           request->master_user == NULL)
                request->user = t_strdup_noconst(request->translated_username);
 
        key = auth_request_expand_cache_key(request, key);
index 06b20b6a89bf948d1895c5d4f2777c9d0e830414..c47f79833867fa93a4b2e26f54de32609e3ae779 100644 (file)
@@ -409,8 +409,7 @@ static void auth_request_save_cache(struct auth_request *request,
                i_unreached();
        }
 
-       if (passdb_cache == NULL || passdb->cache_key == NULL ||
-           request->master_user != NULL)
+       if (passdb_cache == NULL || passdb->cache_key == NULL)
                return;
 
        if (result < 0) {
@@ -923,8 +922,7 @@ static void auth_request_userdb_save_cache(struct auth_request *request,
        string_t *str;
        const char *cache_value;
 
-       if (passdb_cache == NULL || userdb->cache_key == NULL ||
-           request->master_user != NULL)
+       if (passdb_cache == NULL || userdb->cache_key == NULL)
                return;
 
        if (result == USERDB_RESULT_USER_UNKNOWN)
@@ -956,9 +954,6 @@ static bool auth_request_lookup_user_cache(struct auth_request *request,
        struct auth_cache_node *node;
        bool expired, neg_expired;
 
-       if (request->master_user != NULL)
-               return FALSE;
-
        value = auth_cache_lookup(passdb_cache, request, key, &node,
                                  &expired, &neg_expired);
        if (value == NULL || (expired && !use_expired)) {
@@ -1951,6 +1946,7 @@ auth_request_var_expand_static_tab[AUTH_REQUEST_VAR_TAB_COUNT+1] = {
        { '\0', NULL, "real_rport" },
        { '\0', NULL, "domain_first" },
        { '\0', NULL, "domain_last" },
+       { '\0', NULL, "master_user" },
        /* be sure to update AUTH_REQUEST_VAR_TAB_COUNT */
        { '\0', NULL, NULL }
 };
@@ -2036,6 +2032,8 @@ auth_request_get_var_expand_table_full(const struct auth_request *auth_request,
        tab[24].value = strrchr(auth_request->user, '@');
        if (tab[24].value != NULL)
                tab[24].value = escape_func(tab[24].value+1, auth_request);
+       tab[25].value = auth_request->master_user == NULL ? NULL :
+               escape_func(auth_request->master_user, auth_request);
        return ret_tab;
 }
 
index e0fae78ed522ba8d630baf554559f719b7d419b8..6db0532f11d8d830785808a33d1964c292be7fdb 100644 (file)
@@ -143,7 +143,7 @@ extern unsigned int auth_request_state_count[AUTH_REQUEST_STATE_MAX];
 #define AUTH_REQUEST_VAR_TAB_USER_IDX 0
 #define AUTH_REQUEST_VAR_TAB_USERNAME_IDX 1
 #define AUTH_REQUEST_VAR_TAB_DOMAIN_IDX 2
-#define AUTH_REQUEST_VAR_TAB_COUNT 25
+#define AUTH_REQUEST_VAR_TAB_COUNT 26
 extern const struct var_expand_table
 auth_request_var_expand_static_tab[AUTH_REQUEST_VAR_TAB_COUNT+1];
 
index a18f45aad18e205ea346cede0054c8da0ac2c8f0..2e0da5f97dc4089a7e701a50a169d1646ccf6690 100644 (file)
@@ -33,7 +33,7 @@ bool passdb_cache_verify_plain(struct auth_request *request, const char *key,
        int ret;
        bool expired, neg_expired;
 
-       if (passdb_cache == NULL || key == NULL || request->master_user != NULL)
+       if (passdb_cache == NULL || key == NULL)
                return FALSE;
 
        /* value = password \t ... */
@@ -97,7 +97,7 @@ bool passdb_cache_lookup_credentials(struct auth_request *request,
        struct auth_cache_node *node;
        bool expired, neg_expired;
 
-       if (passdb_cache == NULL || request->master_user != NULL)
+       if (passdb_cache == NULL)
                return FALSE;
 
        value = auth_cache_lookup(passdb_cache, request, key, &node,