]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
auth: auth-sasl - Copy global mechanism registration code from mech.c
authorStephan Bosch <stephan.bosch@open-xchange.com>
Sat, 18 Mar 2023 14:07:28 +0000 (15:07 +0100)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Thu, 9 Oct 2025 08:41:22 +0000 (08:41 +0000)
src/auth/auth-sasl.c [new file with mode: 0644]
src/auth/auth-sasl.h [new file with mode: 0644]

diff --git a/src/auth/auth-sasl.c b/src/auth/auth-sasl.c
new file mode 100644 (file)
index 0000000..192efea
--- /dev/null
@@ -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 (file)
index 0000000..397a912
--- /dev/null
@@ -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