]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
auth: auth-request-handler - Refactor auth_request_handler_find_mech() to reduce...
authorStephan Bosch <stephan.bosch@open-xchange.com>
Sat, 18 Mar 2023 15:12:11 +0000 (16:12 +0100)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Thu, 9 Oct 2025 08:41:22 +0000 (08:41 +0000)
src/auth/auth-request-handler.c

index e415acdc97b1f7e838eae8ebbd584a43c6b42ca9..47d3010977104fc2a35e6c1dc45e415ce6d6ea80 100644 (file)
@@ -576,28 +576,30 @@ auth_request_handler_find_mech(struct auth_request_handler *handler,
 
        if (handler->token_auth) {
                mech = &mech_dovecot_token;
-               if (strcmp(mech_name, mech->mech_name) != 0) {
-                       /* unsupported mechanism */
-                       e_error(handler->conn->conn.event,
-                               "BUG: Authentication client %u requested invalid "
-                               "authentication mechanism %s (DOVECOT-TOKEN required)",
-                               handler->client_pid,
-                               str_sanitize(mech_name, AUTH_SASL_MAX_MECH_NAME_LEN));
-                       return -1;
-               }
-       } else {
-               struct auth *auth_default = auth_default_protocol();
-               mech = mech_register_find(auth_default->reg, mech_name);
-               if (mech == NULL) {
-                       /* unsupported mechanism */
-                       e_error(handler->conn->conn.event,
-                               "BUG: Authentication client %u requested unsupported "
-                               "authentication mechanism %s", handler->client_pid,
-                               str_sanitize(mech_name, AUTH_SASL_MAX_MECH_NAME_LEN));
-                       return -1;
+               if (strcmp(mech_name, mech->mech_name) == 0) {
+                       *mech_r = mech;
+                       return 0;
                }
+               /* unsupported mechanism */
+               e_error(handler->conn->conn.event,
+                       "BUG: Authentication client %u requested invalid "
+                       "authentication mechanism %s (DOVECOT-TOKEN required)",
+                       handler->client_pid,
+                       str_sanitize(mech_name, AUTH_SASL_MAX_MECH_NAME_LEN));
+               return -1;
        }
 
+       struct auth *auth_default = auth_default_protocol();
+
+       mech = mech_register_find(auth_default->reg, mech_name);
+       if (mech == NULL) {
+               /* unsupported mechanism */
+               e_error(handler->conn->conn.event,
+                       "BUG: Authentication client %u requested unsupported "
+                       "authentication mechanism %s", handler->client_pid,
+                       str_sanitize(mech_name, AUTH_SASL_MAX_MECH_NAME_LEN));
+               return -1;
+       }
        *mech_r = mech;
        return 0;
 }