]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
auth: sasl-server - Make mech_module_list use a pointer to mech_module
authorStephan Bosch <stephan.bosch@open-xchange.com>
Tue, 7 Mar 2023 02:03:27 +0000 (03:03 +0100)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Thu, 9 Oct 2025 08:41:22 +0000 (08:41 +0000)
src/auth/auth.c
src/auth/mech.c
src/auth/sasl-server-mech-oauth2.c
src/auth/sasl-server-protected.h

index 5a81fd771f57db626055c176e78ac6eaad359d8d..24b7a488e8cf9fb33700237f445c908a40362dd0 100644 (file)
@@ -241,9 +241,9 @@ static bool auth_passdb_list_have_set_credentials(const struct auth *auth)
 }
 
 static bool
-auth_mech_verify_passdb(const struct auth *auth, const struct mech_module_list *list)
+auth_mech_verify_passdb(const struct auth *auth, const struct mech_module *mech)
 {
-       switch (list->module.passdb_need) {
+       switch (mech->passdb_need) {
        case SASL_MECH_PASSDB_NEED_NOTHING:
                break;
        case SASL_MECH_PASSDB_NEED_VERIFY_PLAIN:
@@ -270,7 +270,7 @@ static void auth_mech_list_verify_passdb(const struct auth *auth)
        const struct mech_module_list *list;
 
        for (list = auth->reg->modules; list != NULL; list = list->next) {
-               if (!auth_mech_verify_passdb(auth, list))
+               if (!auth_mech_verify_passdb(auth, list->module))
                        break;
        }
 
@@ -278,10 +278,10 @@ static void auth_mech_list_verify_passdb(const struct auth *auth)
                if (auth->passdbs == NULL) {
                        i_fatal("No passdbs specified in configuration file. "
                                "%s mechanism needs one",
-                               list->module.mech_name);
+                               list->module->mech_name);
                }
                i_fatal("%s mechanism can't be supported with given passdbs",
-                       list->module.mech_name);
+                       list->module->mech_name);
        }
 }
 
index b2699d6f87519683e39c5b536afa1189a1a5cee3..f7195180b6fd95f24bdfdd42e19c81207a45e5f7 100644 (file)
@@ -18,7 +18,7 @@ void mech_register_module(const struct mech_module *module)
        i_assert(strcmp(module->mech_name, t_str_ucase(module->mech_name)) == 0);
 
        list = i_new(struct mech_module_list, 1);
-       list->module = *module;
+       list->module = module;
 
        list->next = mech_modules;
        mech_modules = list;
@@ -29,7 +29,7 @@ void mech_unregister_module(const struct mech_module *module)
        struct mech_module_list **pos, *list;
 
        for (pos = &mech_modules; *pos != NULL; pos = &(*pos)->next) {
-               if (strcmp((*pos)->module.mech_name, module->mech_name) == 0) {
+               if (strcmp((*pos)->module->mech_name, module->mech_name) == 0) {
                        list = *pos;
                        *pos = (*pos)->next;
                        i_free(list);
@@ -44,8 +44,8 @@ const struct mech_module *mech_module_find(const char *name)
        name = t_str_ucase(name);
 
        for (list = mech_modules; list != NULL; list = list->next) {
-               if (strcmp(list->module.mech_name, name) == 0)
-                       return &list->module;
+               if (strcmp(list->module->mech_name, name) == 0)
+                       return list->module;
        }
        return NULL;
 }
@@ -80,7 +80,7 @@ static void mech_register_add(struct mechanisms_register *reg,
        string_t *handshake;
 
        list = p_new(reg->pool, struct mech_module_list, 1);
-       list->module = *mech;
+       list->module = mech;
 
        if ((mech->flags & SASL_MECH_SEC_CHANNEL_BINDING) != 0)
                handshake = reg->handshake_cbind;
@@ -180,8 +180,8 @@ mech_register_find(const struct mechanisms_register *reg, const char *name)
        name = t_str_ucase(name);
 
        for (list = reg->modules; list != NULL; list = list->next) {
-               if (strcmp(list->module.mech_name, name) == 0)
-                       return &list->module;
+               if (strcmp(list->module->mech_name, name) == 0)
+                       return list->module;
        }
        return NULL;
 }
index a84118d09c4e10340599e8dab11f8f4387ff3923..d4a9186433e9b5ef694f5f6f5546b8a56800c6b1 100644 (file)
@@ -24,6 +24,9 @@ struct oauth2_auth_request {
        bool verifying_token:1;
 };
 
+const struct mech_module mech_oauthbearer;
+const struct mech_module mech_xoauth2;
+
 static struct db_oauth2 *db_oauth2 = NULL;
 
 static void
@@ -42,7 +45,7 @@ oauth2_fail(struct oauth2_auth_request *oauth2_req,
 
        i_assert(failure->status != NULL);
        json_ostream_ndescend_object(joutput, NULL);
-       if (strcmp(request->mech->mech_name, "XOAUTH2") == 0) {
+       if (request->mech == &mech_xoauth2) {
                if (strcmp(failure->status, "invalid_token") == 0)
                        json_ostream_nwrite_string(joutput, "status", "401");
                else if (strcmp(failure->status, "insufficient_scope") == 0)
@@ -51,7 +54,7 @@ oauth2_fail(struct oauth2_auth_request *oauth2_req,
                        json_ostream_nwrite_string(joutput, "status", "400");
                json_ostream_nwrite_string(joutput, "schemes", "bearer");
        } else {
-               i_assert(strcmp(request->mech->mech_name, "OAUTHBEARER") == 0);
+               i_assert(request->mech == &mech_oauthbearer);
                json_ostream_nwrite_string(joutput, "status", failure->status);
        }
        if (failure->scope == NULL)
index 2ba0b6e008f49c7e12f246e3c723e7e8999119df..b44c844c3d1b149c5ed4ccea785f897e7a5e6a0a 100644 (file)
@@ -25,7 +25,7 @@ struct mech_module {
 struct mech_module_list {
        struct mech_module_list *next;
 
-       struct mech_module module;
+       const struct mech_module *module;
 };
 
 struct mechanisms_register {