From: Stephan Bosch Date: Sat, 18 Mar 2023 14:07:28 +0000 (+0100) Subject: auth: auth-sasl - Copy global mechanism registration code from mech.c X-Git-Tag: 2.4.2~306 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fa3ffbbaacd65589c5a4a6f4a516e2ee0faec9f2;p=thirdparty%2Fdovecot%2Fcore.git auth: auth-sasl - Copy global mechanism registration code from mech.c --- diff --git a/src/auth/auth-sasl.c b/src/auth/auth-sasl.c new file mode 100644 index 0000000000..192efeaba8 --- /dev/null +++ b/src/auth/auth-sasl.c @@ -0,0 +1,56 @@ +/* Copyright (c) 2023 Dovecot authors, see the included COPYING file */ + +#include "lib.h" +#include "auth.h" +#include "auth-common.h" +#include "auth-sasl.h" + +/* + * Mechanisms + */ + +struct mech_module_list { + struct mech_module_list *next; + + struct mech_module module; +}; + +static struct mech_module_list *mech_modules; + +void mech_register_module(const struct mech_module *module) +{ + struct mech_module_list *list; + 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->next = mech_modules; + mech_modules = list; +} + +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) { + list = *pos; + *pos = (*pos)->next; + i_free(list); + break; + } + } +} + +const struct mech_module *mech_module_find(const char *name) +{ + struct mech_module_list *list; + 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; + } + return NULL; +} diff --git a/src/auth/auth-sasl.h b/src/auth/auth-sasl.h new file mode 100644 index 0000000000..397a9125b3 --- /dev/null +++ b/src/auth/auth-sasl.h @@ -0,0 +1,26 @@ +#ifndef AUTH_SASL_H +#define AUTH_SASL_H + +struct mech_module { + const char *mech_name; + + enum mech_security_flags flags; + enum mech_passdb_need passdb_need; + + struct auth_request *(*auth_new)(void); + void (*auth_initial)(struct auth_request *request, + const unsigned char *data, size_t data_size); + void (*auth_continue)(struct auth_request *request, + const unsigned char *data, size_t data_size); + void (*auth_free)(struct auth_request *request); +}; + +/* + * Mechanisms + */ + +void mech_register_module(const struct mech_module *module); +void mech_unregister_module(const struct mech_module *module); +const struct mech_module *mech_module_find(const char *name); + +#endif