diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 09:51:24 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 09:51:24 +0000 |
commit | f7548d6d28c313cf80e6f3ef89aed16a19815df1 (patch) | |
tree | a3f6f2a3f247293bee59ecd28e8cd8ceb6ca064a /src/auth/mech-otp-common.c | |
parent | Initial commit. (diff) | |
download | dovecot-f7548d6d28c313cf80e6f3ef89aed16a19815df1.tar.xz dovecot-f7548d6d28c313cf80e6f3ef89aed16a19815df1.zip |
Adding upstream version 1:2.3.19.1+dfsg1.upstream/1%2.3.19.1+dfsg1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | src/auth/mech-otp-common.c | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/src/auth/mech-otp-common.c b/src/auth/mech-otp-common.c new file mode 100644 index 0000000..753fcbb --- /dev/null +++ b/src/auth/mech-otp-common.c @@ -0,0 +1,71 @@ +/* + * 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); +} |