Added a token add/remove callback function to the manager
This commit is contained in:
@@ -40,6 +40,16 @@ struct private_pkcs11_manager_t {
|
|||||||
* List of loaded libraries, as lib_entry_t
|
* List of loaded libraries, as lib_entry_t
|
||||||
*/
|
*/
|
||||||
linked_list_t *libs;
|
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)",
|
DBG1(DBG_CFG, " found token in slot '%s':%lu (%s)",
|
||||||
entry->name, slot, info.slotDescription);
|
entry->name, slot, info.slotDescription);
|
||||||
handle_token(entry, slot);
|
handle_token(entry, slot);
|
||||||
|
entry->this->cb(entry->this->data, entry->lib, slot, TRUE);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DBG1(DBG_CFG, "token removed from slot '%s':%lu (%s)",
|
DBG1(DBG_CFG, "token removed from slot '%s':%lu (%s)",
|
||||||
entry->name, slot, info.slotDescription);
|
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
|
* 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;
|
private_pkcs11_manager_t *this;
|
||||||
enumerator_t *enumerator;
|
enumerator_t *enumerator;
|
||||||
@@ -262,6 +275,8 @@ pkcs11_manager_t *pkcs11_manager_create()
|
|||||||
.destroy = _destroy,
|
.destroy = _destroy,
|
||||||
},
|
},
|
||||||
.libs = linked_list_create(),
|
.libs = linked_list_create(),
|
||||||
|
.cb = cb,
|
||||||
|
.data = data,
|
||||||
);
|
);
|
||||||
|
|
||||||
enumerator = lib->settings->create_section_enumerator(lib->settings,
|
enumerator = lib->settings->create_section_enumerator(lib->settings,
|
||||||
|
|||||||
@@ -23,6 +23,22 @@
|
|||||||
|
|
||||||
typedef struct pkcs11_manager_t pkcs11_manager_t;
|
typedef struct pkcs11_manager_t pkcs11_manager_t;
|
||||||
|
|
||||||
|
#include <library.h>
|
||||||
|
|
||||||
|
#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
|
* Manages multiple PKCS#11 libraries with hot pluggable slots
|
||||||
*/
|
*/
|
||||||
@@ -37,6 +53,7 @@ struct pkcs11_manager_t {
|
|||||||
/**
|
/**
|
||||||
* Create a pkcs11_manager instance.
|
* 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_ @}*/
|
#endif /** PKCS11_MANAGER_H_ @}*/
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
#include "pkcs11_plugin.h"
|
#include "pkcs11_plugin.h"
|
||||||
|
|
||||||
#include <library.h>
|
#include <library.h>
|
||||||
|
#include <debug.h>
|
||||||
|
|
||||||
#include "pkcs11_manager.h"
|
#include "pkcs11_manager.h"
|
||||||
|
|
||||||
@@ -37,6 +38,14 @@ struct private_pkcs11_plugin_t {
|
|||||||
pkcs11_manager_t *manager;
|
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,
|
METHOD(plugin_t, destroy, void,
|
||||||
private_pkcs11_plugin_t *this)
|
private_pkcs11_plugin_t *this)
|
||||||
{
|
{
|
||||||
@@ -53,8 +62,9 @@ plugin_t *pkcs11_plugin_create()
|
|||||||
|
|
||||||
INIT(this,
|
INIT(this,
|
||||||
.public.plugin.destroy = _destroy,
|
.public.plugin.destroy = _destroy,
|
||||||
.manager = pkcs11_manager_create(),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
this->manager = pkcs11_manager_create((void*)token_event_cb, this);
|
||||||
|
|
||||||
return &this->public.plugin;
|
return &this->public.plugin;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user