From: Stephan Bosch Date: Tue, 7 Mar 2023 02:03:27 +0000 (+0100) Subject: auth: sasl-server - Make mech_module_list use a pointer to mech_module X-Git-Tag: 2.4.2~257 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=faff9574e0539a6b80e1191b43f76b4cff7ee14f;p=thirdparty%2Fdovecot%2Fcore.git auth: sasl-server - Make mech_module_list use a pointer to mech_module --- diff --git a/src/auth/auth.c b/src/auth/auth.c index 5a81fd771f..24b7a488e8 100644 --- a/src/auth/auth.c +++ b/src/auth/auth.c @@ -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); } } diff --git a/src/auth/mech.c b/src/auth/mech.c index b2699d6f87..f7195180b6 100644 --- a/src/auth/mech.c +++ b/src/auth/mech.c @@ -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; } diff --git a/src/auth/sasl-server-mech-oauth2.c b/src/auth/sasl-server-mech-oauth2.c index a84118d09c..d4a9186433 100644 --- a/src/auth/sasl-server-mech-oauth2.c +++ b/src/auth/sasl-server-mech-oauth2.c @@ -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) diff --git a/src/auth/sasl-server-protected.h b/src/auth/sasl-server-protected.h index 2ba0b6e008..b44c844c3d 100644 --- a/src/auth/sasl-server-protected.h +++ b/src/auth/sasl-server-protected.h @@ -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 {