From: Stephan Bosch Date: Thu, 3 Oct 2024 00:26:33 +0000 (+0200) Subject: auth: sasl-server-mech-oauth2 - Move mech_oauth2_initialize to auth-sasl-mech-oauth2.c X-Git-Tag: 2.4.2~246 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=29171bfa72ca9cb46c7148dee91acc83ddbc8115;p=thirdparty%2Fdovecot%2Fcore.git auth: sasl-server-mech-oauth2 - Move mech_oauth2_initialize to auth-sasl-mech-oauth2.c --- diff --git a/src/auth/Makefile.am b/src/auth/Makefile.am index 23e111a6e3..9ee3061ba8 100644 --- a/src/auth/Makefile.am +++ b/src/auth/Makefile.am @@ -155,6 +155,7 @@ headers = \ auth-request-handler-private.h \ auth-request-var-expand.h \ auth-sasl.h \ + auth-sasl-oauth2.h \ auth-settings.h \ auth-fields.h \ auth-token.h \ diff --git a/src/auth/auth-sasl-mech-oauth2.c b/src/auth/auth-sasl-mech-oauth2.c index 9e540dfdf5..5b57c5490e 100644 --- a/src/auth/auth-sasl-mech-oauth2.c +++ b/src/auth/auth-sasl-mech-oauth2.c @@ -2,6 +2,7 @@ #include "auth-common.h" #include "auth-sasl.h" +#include "auth-sasl-oauth2.h" #include "auth-request.h" static void @@ -161,3 +162,16 @@ auth_sasl_oauth2_verify_token(struct oauth2_auth_request *oauth2_req, mech_oauth2_verify_token_input_args, oauth2_req); } } + +void mech_oauth2_initialize(void) +{ + const char *mech, *error; + array_foreach_elem(&global_auth_settings->mechanisms, mech) { + if (strcasecmp(mech, mech_xoauth2.mech_name) == 0 || + strcasecmp(mech, mech_oauthbearer.mech_name) == 0) { + if (db_oauth2_init(auth_event, FALSE, + &db_oauth2, &error) < 0) + i_fatal("Cannot initialize oauth2: %s", error); + } + } +} diff --git a/src/auth/auth-sasl-oauth2.h b/src/auth/auth-sasl-oauth2.h new file mode 100644 index 0000000000..73dff0fa91 --- /dev/null +++ b/src/auth/auth-sasl-oauth2.h @@ -0,0 +1,6 @@ +#ifndef AUTH_SASL_OAUTH2_H +#define AUTH_SASL_OAUTH2_H + +void mech_oauth2_initialize(void); + +#endif diff --git a/src/auth/main.c b/src/auth/main.c index a85b8dca39..903a4f17ac 100644 --- a/src/auth/main.c +++ b/src/auth/main.c @@ -31,6 +31,7 @@ #include "auth-master-connection.h" #include "auth-client-connection.h" #include "auth-policy.h" +#include "auth-sasl-oauth2.h" #include "db-oauth2.h" #include @@ -180,6 +181,7 @@ static void main_preinit(void) dict_drivers_register_builtin(); mech_init(global_auth_settings); + mech_oauth2_initialize(); mech_reg = mech_register_init(global_auth_settings); auths_preinit(NULL, global_auth_settings, mech_reg, protocols); diff --git a/src/auth/mech.c b/src/auth/mech.c index 5bc37cf81c..8668c818de 100644 --- a/src/auth/mech.c +++ b/src/auth/mech.c @@ -213,7 +213,6 @@ void mech_init(const struct auth_settings *set) #endif mech_register_module(&mech_oauthbearer); mech_register_module(&mech_xoauth2); - mech_oauth2_initialize(); } void mech_deinit(const struct auth_settings *set) diff --git a/src/auth/sasl-server-mech-oauth2.c b/src/auth/sasl-server-mech-oauth2.c index 17d34b06ee..69a0f1406d 100644 --- a/src/auth/sasl-server-mech-oauth2.c +++ b/src/auth/sasl-server-mech-oauth2.c @@ -334,16 +334,3 @@ const struct sasl_server_mech_def mech_xoauth2 = { .auth_initial = sasl_server_mech_generic_auth_initial, .auth_continue = mech_xoauth2_auth_continue, }; - -void mech_oauth2_initialize(void) -{ - const char *mech, *error; - array_foreach_elem(&global_auth_settings->mechanisms, mech) { - if (strcasecmp(mech, mech_xoauth2.mech_name) == 0 || - strcasecmp(mech, mech_oauthbearer.mech_name) == 0) { - if (db_oauth2_init(auth_event, FALSE, - &db_oauth2, &error) < 0) - i_fatal("Cannot initialize oauth2: %s", error); - } - } -} diff --git a/src/auth/sasl-server-protected.h b/src/auth/sasl-server-protected.h index bf5d94d6b7..24a541a85c 100644 --- a/src/auth/sasl-server-protected.h +++ b/src/auth/sasl-server-protected.h @@ -75,8 +75,6 @@ mech_register_find(const struct mechanisms_register *reg, const char *name); void mech_init(const struct auth_settings *set); void mech_deinit(const struct auth_settings *set); -void mech_oauth2_initialize(void); - /* * Request */