]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
auth: Extract password mismatch helper
authorFred Morcos <fred.morcos@open-xchange.com>
Thu, 30 Apr 2026 13:20:27 +0000 (15:20 +0200)
committerTimo Sirainen <timo.sirainen@open-xchange.com>
Tue, 5 May 2026 14:44:11 +0000 (17:44 +0300)
src/auth/passdb-cache.c

index c378e538c023c2451a302292cd200516b5acdcea..5718583bf454b177502b7347ad2ac07719304dcc 100644 (file)
@@ -26,6 +26,23 @@ passdb_cache_log_hit(struct auth_request *request, const char *value)
        e_debug(authdb_event(request), "cache hit: %s", value);
 }
 
+static bool
+passdb_cache_use_password_mismatch(enum passdb_result result,
+                                  struct auth_cache_node *node,
+                                  bool neg_expired)
+{
+       if (result == PASSDB_RESULT_PASSWORD_MISMATCH &&
+           (node->last_success || neg_expired)) {
+               /* a) the last authentication was successful. assume
+                  that the password was changed and cache is expired.
+                  b) negative TTL reached, use it for password
+                  mismatches too. */
+               node->last_success = FALSE;
+               return FALSE;
+       }
+       return TRUE;
+}
+
 static bool
 passdb_cache_lookup(struct auth_request *request, const char *key,
                    bool use_expired, struct auth_cache_node **node_r,
@@ -129,15 +146,8 @@ bool passdb_cache_verify_plain(struct auth_request *request, const char *key,
                        request, password, cached_pw, scheme,
                        !(node->last_success || neg_expired));
 
-               if (ret == PASSDB_RESULT_PASSWORD_MISMATCH &&
-                   (node->last_success || neg_expired)) {
-                       /* a) the last authentication was successful. assume
-                          that the password was changed and cache is expired.
-                          b) negative TTL reached, use it for password
-                          mismatches too. */
-                       node->last_success = FALSE;
+               if (!passdb_cache_use_password_mismatch(ret, node, neg_expired))
                        return FALSE;
-               }
        }
        node->last_success = ret == PASSDB_RESULT_OK;