]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
Added a token add/remove callback function to the manager
authorMartin Willi <martin@revosec.ch>
Wed, 14 Jul 2010 13:09:12 +0000 (15:09 +0200)
committerMartin Willi <martin@revosec.ch>
Wed, 4 Aug 2010 07:26:19 +0000 (09:26 +0200)
src/libstrongswan/plugins/pkcs11/pkcs11_manager.c
src/libstrongswan/plugins/pkcs11/pkcs11_manager.h
src/libstrongswan/plugins/pkcs11/pkcs11_plugin.c

index f45a17bb645d7ebdf77426f454c8b13cc38bd48f..8869b558360576e2b33a0882b549d5e7105302e8 100644 (file)
@@ -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,
index c89f251e781c51a1a33296bbd710e65899bdd44a..c0208234eba160553e751bd3c8174052f2f9db7e 100644 (file)
 
 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
  */
@@ -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_ @}*/
index 1f682a33e3241925f6f4567a26adc2152fd3c1f1..2d9b286dc6d0f6634969f4fd3c0136484b6f2752 100644 (file)
@@ -16,6 +16,7 @@
 #include "pkcs11_plugin.h"
 
 #include <library.h>
+#include <debug.h>
 
 #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;
 }