]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
auth: mech-otp - Merge mech-otp-common.c into mech-otp.c
authorStephan Bosch <stephan.bosch@open-xchange.com>
Sat, 4 Mar 2023 16:46:21 +0000 (17:46 +0100)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Thu, 9 Oct 2025 08:41:22 +0000 (08:41 +0000)
Separate file is not useful and structure is confusing.

src/auth/Makefile.am
src/auth/main.c
src/auth/mech-otp-common.c [deleted file]
src/auth/mech-otp-common.h [deleted file]
src/auth/mech-otp.c
src/auth/mech-otp.h [new file with mode: 0644]
src/auth/test-auth.c

index f0fdd91373ccd55683e6384437130001868fbf4a..dc06918f228cd504df3876934864b14d641efb2e 100644 (file)
@@ -84,7 +84,6 @@ auth_common_sources = \
        auth-client-connection.c \
        auth-master-connection.c \
        auth-policy.c \
-       mech-otp-common.c \
        mech-plain-common.c \
        auth-penalty.c \
        auth-request.c \
@@ -139,7 +138,7 @@ headers = \
        auth-client-connection.h \
        auth-common.h \
        auth-master-connection.h \
-       mech-otp-common.h \
+       mech-otp.h \
        mech-plain-common.h \
        mech-digest-md5-private.h \
        mech-scram.h \
index 99e78d87108589aaab925a85a55e911ae2745bd7..6151eb521a6f046f618b2a6b297844fa55e29081 100644 (file)
@@ -21,7 +21,7 @@
 #include "passdb-cache.h"
 #include "mech.h"
 #include "otp.h"
-#include "mech-otp-common.h"
+#include "mech-otp.h"
 #include "auth.h"
 #include "auth-penalty.h"
 #include "auth-token.h"
diff --git a/src/auth/mech-otp-common.c b/src/auth/mech-otp-common.c
deleted file mode 100644 (file)
index 753fcbb..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Common code for OTP authentication mechanisms.
- *
- * Copyright (c) 2006 Andrey Panin <pazke@donpac.ru>
- *
- * This software is released under the MIT license.
- */
-
-#include "auth-common.h"
-#include "hash.h"
-#include "mech.h"
-
-#include "otp.h"
-#include "mech-otp-common.h"
-
-static HASH_TABLE(char *, struct auth_request *) otp_lock_table;
-
-void otp_lock_init(void)
-{
-       if (hash_table_is_created(otp_lock_table))
-               return;
-
-       hash_table_create(&otp_lock_table, default_pool, 128,
-                         strcase_hash, strcasecmp);
-}
-
-bool otp_try_lock(struct auth_request *auth_request)
-{
-       if (hash_table_lookup(otp_lock_table, auth_request->fields.user) != NULL)
-               return FALSE;
-
-       hash_table_insert(otp_lock_table, auth_request->fields.user, auth_request);
-       return TRUE;
-}
-
-void otp_unlock(struct auth_request *auth_request)
-{
-       struct otp_auth_request *request =
-               (struct otp_auth_request *)auth_request;
-
-       if (!request->lock)
-               return;
-
-       hash_table_remove(otp_lock_table, auth_request->fields.user);
-       request->lock = FALSE;
-}
-
-void otp_set_credentials_callback(bool success,
-                                 struct auth_request *auth_request)
-{
-       if (success)
-               auth_request_success(auth_request, "", 0);
-       else {
-               auth_request_internal_failure(auth_request);
-               otp_unlock(auth_request);
-       }
-
-       otp_unlock(auth_request);
-}
-
-void mech_otp_auth_free(struct auth_request *auth_request)
-{
-       otp_unlock(auth_request);
-
-       pool_unref(&auth_request->pool);
-}
-
-void mech_otp_deinit(void)
-{
-       hash_table_destroy(&otp_lock_table);
-}
diff --git a/src/auth/mech-otp-common.h b/src/auth/mech-otp-common.h
deleted file mode 100644 (file)
index 37a6551..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-#ifndef MECH_OTP_COMMON_H
-#define MECH_OTP_COMMON_H
-
-struct otp_auth_request {
-       struct auth_request auth_request;
-
-       pool_t pool;
-
-       bool lock;
-
-       struct otp_state state;
-};
-
-void otp_lock_init(void);
-bool otp_try_lock(struct auth_request *auth_request);
-void otp_unlock(struct auth_request *auth_request);
-
-void otp_set_credentials_callback(bool success,
-                                 struct auth_request *auth_request);
-void mech_otp_auth_free(struct auth_request *auth_request);
-void mech_otp_deinit(void);
-
-#endif
index 165db609b148be883b95ca955bfb89ec3fc2372f..99bcd0cb20bde11bcaf6a093a427e9610bb312c9 100644 (file)
 #include "passdb.h"
 #include "hex-binary.h"
 #include "otp.h"
-#include "mech-otp-common.h"
+
+#include "mech-otp.h"
+
+struct otp_auth_request {
+       struct auth_request auth_request;
+
+       pool_t pool;
+
+       bool lock;
+
+       struct otp_state state;
+};
+
+static HASH_TABLE(char *, struct auth_request *) otp_lock_table;
+
+/*
+ * Locking
+ */
+
+static void otp_lock_init(void)
+{
+       if (hash_table_is_created(otp_lock_table))
+               return;
+
+       hash_table_create(&otp_lock_table, default_pool, 128,
+                         strcase_hash, strcasecmp);
+}
+
+static void otp_lock_deinit(void)
+{
+       hash_table_destroy(&otp_lock_table);
+}
+
+static bool otp_try_lock(struct auth_request *auth_request)
+{
+       if (hash_table_lookup(otp_lock_table,
+                             auth_request->fields.user) != NULL)
+               return FALSE;
+
+       hash_table_insert(otp_lock_table, auth_request->fields.user,
+                         auth_request);
+       return TRUE;
+}
+
+static void otp_unlock(struct auth_request *auth_request)
+{
+       struct otp_auth_request *request =
+               (struct otp_auth_request *)auth_request;
+
+       if (!request->lock)
+               return;
+
+       hash_table_remove(otp_lock_table, auth_request->fields.user);
+       request->lock = FALSE;
+}
+
+/*
+ * Authentication
+ */
 
 static void
 otp_send_challenge(struct auth_request *auth_request,
@@ -110,6 +168,19 @@ mech_otp_auth_phase1(struct auth_request *auth_request,
                                        otp_credentials_callback);
 }
 
+static void
+otp_set_credentials_callback(bool success, struct auth_request *auth_request)
+{
+       if (success)
+               auth_request_success(auth_request, "", 0);
+       else {
+               auth_request_internal_failure(auth_request);
+               otp_unlock(auth_request);
+       }
+
+       otp_unlock(auth_request);
+}
+
 static void
 mech_otp_verify(struct auth_request *auth_request, const char *data, bool hex)
 {
@@ -227,6 +298,17 @@ static struct auth_request *mech_otp_auth_new(void)
        return &request->auth_request;
 }
 
+static void mech_otp_auth_free(struct auth_request *auth_request)
+{
+       otp_unlock(auth_request);
+
+       pool_unref(&auth_request->pool);
+}
+
+/*
+ * Mechanism
+ */
+
 const struct mech_module mech_otp = {
        "OTP",
 
@@ -238,3 +320,8 @@ const struct mech_module mech_otp = {
        mech_otp_auth_continue,
        mech_otp_auth_free
 };
+
+void mech_otp_deinit(void)
+{
+       otp_lock_deinit();
+}
diff --git a/src/auth/mech-otp.h b/src/auth/mech-otp.h
new file mode 100644 (file)
index 0000000..fa534d4
--- /dev/null
@@ -0,0 +1,6 @@
+#ifndef MECH_OTP_COMMON_H
+#define MECH_OTP_COMMON_H
+
+void mech_otp_deinit(void);
+
+#endif
index 91bd4228757052dc2dbcd48659f5d599ef74b247..be8b42ebc6ceb1c3fc3a7f36cdf2c550fe4cacdd 100644 (file)
@@ -8,7 +8,7 @@
 #include "auth-penalty.h"
 #include "mech.h"
 #include "otp.h"
-#include "mech-otp-common.h"
+#include "mech-otp.h"
 #include "db-oauth2.h"
 #include "passdb.h"
 #include "userdb.h"