Register manager of pkcs11 plugin as library object
authorMartin Willi <martin@revosec.ch>
Wed, 24 Aug 2011 13:45:59 +0000 (15:45 +0200)
committerMartin Willi <martin@revosec.ch>
Wed, 24 Aug 2011 13:45:59 +0000 (15:45 +0200)
src/libstrongswan/plugins/pkcs11/pkcs11_hasher.c
src/libstrongswan/plugins/pkcs11/pkcs11_manager.c
src/libstrongswan/plugins/pkcs11/pkcs11_manager.h
src/libstrongswan/plugins/pkcs11/pkcs11_plugin.c
src/libstrongswan/plugins/pkcs11/pkcs11_private_key.c
src/libstrongswan/plugins/pkcs11/pkcs11_public_key.c

index 6d327be..5da9700 100644 (file)
@@ -260,7 +260,7 @@ static pkcs11_library_t* find_token(hash_algorithm_t algo,
        {
                return NULL;
        }
-       manager = pkcs11_manager_get();
+       manager = lib->get(lib, "pkcs11-manager");
        if (!manager)
        {
                return NULL;
index 1d6237e..5b321b2 100644 (file)
@@ -323,17 +323,11 @@ METHOD(pkcs11_manager_t, create_token_enumerator, enumerator_t*,
        return &enumerator->public;
 }
 
-/**
- * Singleton instance
- */
-static private_pkcs11_manager_t *singleton = NULL;
-
 METHOD(pkcs11_manager_t, destroy, void,
        private_pkcs11_manager_t *this)
 {
        this->libs->destroy_function(this->libs, (void*)lib_entry_destroy);
        free(this);
-       singleton = NULL;
 }
 
 /**
@@ -386,8 +380,6 @@ pkcs11_manager_t *pkcs11_manager_create(pkcs11_manager_token_event_t cb,
        }
        enumerator->destroy(enumerator);
 
-       singleton = this;
-
        enumerator = this->libs->create_enumerator(this->libs);
        while (enumerator->enumerate(enumerator, &entry))
        {
@@ -401,10 +393,3 @@ pkcs11_manager_t *pkcs11_manager_create(pkcs11_manager_token_event_t cb,
        return &this->public;
 }
 
-/**
- * See header
- */
-pkcs11_manager_t *pkcs11_manager_get()
-{
-       return (pkcs11_manager_t*)singleton;
-}
index 60b13ae..2f51fb3 100644 (file)
@@ -67,12 +67,4 @@ struct pkcs11_manager_t {
 pkcs11_manager_t *pkcs11_manager_create(pkcs11_manager_token_event_t cb,
                                                                                void *data);
 
-
-/**
- * Get the singleton instance of the manager
- *
- * @return                     instance, NULL if none available
- */
-pkcs11_manager_t *pkcs11_manager_get();
-
 #endif /** PKCS11_MANAGER_H_ @}*/
index 7b537cf..7a35a57 100644 (file)
@@ -122,6 +122,7 @@ METHOD(plugin_t, destroy, void,
        lib->crypto->remove_hasher(lib->crypto,
                                                        (hasher_constructor_t)pkcs11_hasher_create);
        this->creds->destroy(this->creds);
+       lib->set(lib, "pkcs11-manager", NULL);
        this->manager->destroy(this->manager);
        this->mutex->destroy(this->mutex);
        free(this);
@@ -151,6 +152,8 @@ plugin_t *pkcs11_plugin_create()
 
        this->manager = pkcs11_manager_create((void*)token_event_cb, this);
 
+       lib->set(lib, "pkcs11-manager", this->manager);
+
        if (lib->settings->get_bool(lib->settings,
                                                        "libstrongswan.plugins.pkcs11.use_hasher", FALSE))
        {
index b4cc7a8..3154460 100644 (file)
@@ -311,7 +311,7 @@ static pkcs11_library_t* find_lib(char *module)
        pkcs11_library_t *p11, *found = NULL;
        CK_SLOT_ID slot;
 
-       manager = pkcs11_manager_get();
+       manager = lib->get(lib, "pkcs11-manager");
        if (!manager)
        {
                return NULL;
@@ -339,7 +339,7 @@ static pkcs11_library_t* find_lib_by_keyid(chunk_t keyid, int *slot)
        pkcs11_library_t *p11, *found = NULL;
        CK_SLOT_ID current;
 
-       manager = pkcs11_manager_get();
+       manager = lib->get(lib, "pkcs11-manager");
        if (!manager)
        {
                return NULL;
index 8d32d9a..73353fa 100644 (file)
@@ -296,7 +296,7 @@ static private_pkcs11_public_key_t* find_rsa_key(chunk_t n, chunk_t e)
        pkcs11_library_t *p11;
        CK_SLOT_ID slot;
 
-       manager = pkcs11_manager_get();
+       manager = lib->get(lib, "pkcs11-manager");
        if (!manager)
        {
                return NULL;
@@ -350,7 +350,7 @@ static private_pkcs11_public_key_t* create_rsa_key(chunk_t n, chunk_t e)
        pkcs11_library_t *p11;
        CK_SLOT_ID slot;
 
-       manager = pkcs11_manager_get();
+       manager = lib->get(lib, "pkcs11-manager");
        if (!manager)
        {
                return NULL;