From c9ff83bfa37e6cfdf9daac013733d0649f66ef94 Mon Sep 17 00:00:00 2001 From: Ondrej Kozina Date: Thu, 5 Mar 2020 12:20:47 +0100 Subject: [PATCH] Implement external tokens unload. --- lib/luks2/luks2.h | 2 ++ lib/luks2/luks2_token.c | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/lib/luks2/luks2.h b/lib/luks2/luks2.h index cb07a7da..412ca62d 100644 --- a/lib/luks2/luks2.h +++ b/lib/luks2/luks2.h @@ -273,6 +273,8 @@ int LUKS2_token_keyring_get(struct crypt_device *cd, int LUKS2_token_keyring_json(char *buffer, size_t buffer_size, const struct crypt_token_params_luks2_keyring *keyring_params); +void crypt_token_unload_external_all(struct crypt_device *cd); + /* * Generic LUKS2 digest */ diff --git a/lib/luks2/luks2_token.c b/lib/luks2/luks2_token.c index f654c31b..b416b6ab 100644 --- a/lib/luks2/luks2_token.c +++ b/lib/luks2/luks2_token.c @@ -131,6 +131,21 @@ int crypt_token_load(const char *name) return crypt_token_load_external(name, &token_handlers[i]); } +void crypt_token_unload_external_all(struct crypt_device *cd) +{ + int i; + + for (i = LUKS2_TOKENS_MAX - 1; i >= 0; i--) { + if (!token_handlers[i].dlhandle) + continue; + + log_dbg(cd, "Unloading %s token handler.", token_handlers[i].h->name); + + if (dlclose(CONST_CAST(void *)token_handlers[i].dlhandle)) + log_dbg(cd, "%s", dlerror()); + } +} + static const crypt_token_handler *LUKS2_token_handler_type(struct crypt_device *cd, const char *type) {