Separate file is not useful and structure is confusing.
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 \
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 \
#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"
+++ /dev/null
-/*
- * 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);
-}
+++ /dev/null
-#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
#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,
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)
{
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",
mech_otp_auth_continue,
mech_otp_auth_free
};
+
+void mech_otp_deinit(void)
+{
+ otp_lock_deinit();
+}
--- /dev/null
+#ifndef MECH_OTP_COMMON_H
+#define MECH_OTP_COMMON_H
+
+void mech_otp_deinit(void);
+
+#endif
#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"