diff --git a/src/libstrongswan/plugins/pkcs11/pkcs11_manager.c b/src/libstrongswan/plugins/pkcs11/pkcs11_manager.c index f45a17bb6..8869b5583 100644 --- a/src/libstrongswan/plugins/pkcs11/pkcs11_manager.c +++ b/src/libstrongswan/plugins/pkcs11/pkcs11_manager.c @@ -40,6 +40,16 @@ struct private_pkcs11_manager_t { * List of loaded libraries, as lib_entry_t */ linked_list_t *libs; + + /** + * Slot event callback function + */ + pkcs11_manager_token_event_t cb; + + /** + * Slot event user data + */ + void *data; }; /** @@ -170,11 +180,13 @@ static void handle_slot(lib_entry_t *entry, CK_SLOT_ID slot) DBG1(DBG_CFG, " found token in slot '%s':%lu (%s)", entry->name, slot, info.slotDescription); handle_token(entry, slot); + entry->this->cb(entry->this->data, entry->lib, slot, TRUE); } else { DBG1(DBG_CFG, "token removed from slot '%s':%lu (%s)", entry->name, slot, info.slotDescription); + entry->this->cb(entry->this->data, entry->lib, slot, FALSE); } } @@ -250,7 +262,8 @@ METHOD(pkcs11_manager_t, destroy, void, /** * See header */ -pkcs11_manager_t *pkcs11_manager_create() +pkcs11_manager_t *pkcs11_manager_create(pkcs11_manager_token_event_t cb, + void *data) { private_pkcs11_manager_t *this; enumerator_t *enumerator; @@ -262,6 +275,8 @@ pkcs11_manager_t *pkcs11_manager_create() .destroy = _destroy, }, .libs = linked_list_create(), + .cb = cb, + .data = data, ); enumerator = lib->settings->create_section_enumerator(lib->settings, diff --git a/src/libstrongswan/plugins/pkcs11/pkcs11_manager.h b/src/libstrongswan/plugins/pkcs11/pkcs11_manager.h index c89f251e7..c0208234e 100644 --- a/src/libstrongswan/plugins/pkcs11/pkcs11_manager.h +++ b/src/libstrongswan/plugins/pkcs11/pkcs11_manager.h @@ -23,6 +23,22 @@ typedef struct pkcs11_manager_t pkcs11_manager_t; +#include + +#include "pkcs11_library.h" + +/** + * Token event callback function. + * + * @param data user supplied data, as passed to pkcs11_manager_create() + * @param p11 loaded PKCS#11 library token belongs to + * @param slot slot number the event occured in + * @param add TRUE if token was added to the slot, FALSE if removed + */ +typedef void (*pkcs11_manager_token_event_t)(void *data, pkcs11_library_t *p11, + CK_SLOT_ID slot, bool add); + + /** * Manages multiple PKCS#11 libraries with hot pluggable slots */ @@ -37,6 +53,7 @@ struct pkcs11_manager_t { /** * Create a pkcs11_manager instance. */ -pkcs11_manager_t *pkcs11_manager_create(); +pkcs11_manager_t *pkcs11_manager_create(pkcs11_manager_token_event_t cb, + void *data); #endif /** PKCS11_MANAGER_H_ @}*/ diff --git a/src/libstrongswan/plugins/pkcs11/pkcs11_plugin.c b/src/libstrongswan/plugins/pkcs11/pkcs11_plugin.c index 1f682a33e..2d9b286dc 100644 --- a/src/libstrongswan/plugins/pkcs11/pkcs11_plugin.c +++ b/src/libstrongswan/plugins/pkcs11/pkcs11_plugin.c @@ -16,6 +16,7 @@ #include "pkcs11_plugin.h" #include +#include #include "pkcs11_manager.h" @@ -37,6 +38,14 @@ struct private_pkcs11_plugin_t { pkcs11_manager_t *manager; }; +/** + * Token event callback function + */ +static void token_event_cb(private_pkcs11_plugin_t *this, pkcs11_library_t *p11, + CK_SLOT_ID slot, bool add) +{ +} + METHOD(plugin_t, destroy, void, private_pkcs11_plugin_t *this) { @@ -53,8 +62,9 @@ plugin_t *pkcs11_plugin_create() INIT(this, .public.plugin.destroy = _destroy, - .manager = pkcs11_manager_create(), ); + this->manager = pkcs11_manager_create((void*)token_event_cb, this); + return &this->public.plugin; }