summaryrefslogtreecommitdiff
path: root/common/mock.c
diff options
context:
space:
mode:
authorStef Walter <stefw@gnome.org>2013-02-06 21:57:45 +0100
committerStef Walter <stefw@gnome.org>2013-05-21 10:47:51 +0200
commit5c19f0cf66495f00ccf69eba1d0915f862a88c8d (patch)
treee8ae733062507a0a4cc5c134d1fdd62cf055cddd /common/mock.c
parentff853bd7902e271256cada4a1b20a3d46b519b69 (diff)
p11-kit: Managed PKCS#11 module loading
Support a new managed style module loading for PKCS#11 modules. This allows us to better coordinate between multiple callers of the same PKCS#11 modules and provide hooks into their behavior. This meant redoing the public facing API. The old methods are now deprecated, marked and documented as such.
Diffstat (limited to 'common/mock.c')
-rw-r--r--common/mock.c63
1 files changed, 42 insertions, 21 deletions
diff --git a/common/mock.c b/common/mock.c
index 6176fa9..4dbd674 100644
--- a/common/mock.c
+++ b/common/mock.c
@@ -183,8 +183,8 @@ mock_module_take_object (CK_SLOT_ID slot_id,
return_if_reached ();
}
-void
-mock_module_reset_objects (CK_SLOT_ID slot_id)
+static void
+module_reset_objects (CK_SLOT_ID slot_id)
{
return_if_fail (slot_id == MOCK_SLOT_ONE_ID);
@@ -291,6 +291,44 @@ mock_module_reset_objects (CK_SLOT_ID slot_id)
p11_dict_set (the_objects, handle_to_pointer (MOCK_PUBLIC_KEY_PREFIX), p11_attrs_dup (attrs));
}
+}
+
+static void
+module_finalize (void)
+{
+ p11_mutex_lock (&init_mutex);
+
+ /* This should stop all other calls in */
+ pkcs11_initialized = false;
+ pkcs11_initialized_pid = 0;
+
+ if (the_objects)
+ p11_dict_free (the_objects);
+ the_objects = NULL;
+
+ if (the_sessions)
+ p11_dict_free (the_sessions);
+ the_sessions = NULL;
+ logged_in = false;
+ the_user_type = 0;
+
+ free (the_pin);
+ the_pin = NULL;
+ n_the_pin = 0;
+
+ p11_mutex_unlock (&init_mutex);
+}
+
+bool
+mock_module_initialized (void)
+{
+ return pkcs11_initialized;
+}
+void
+mock_module_reset (void)
+{
+ module_finalize ();
+ module_reset_objects (MOCK_SLOT_ONE_ID);
}
@@ -389,7 +427,7 @@ mock_C_Initialize (CK_VOID_PTR init_args)
p11_dict_direct_equal,
NULL, free_session);
- mock_module_reset_objects (MOCK_SLOT_ONE_ID);
+ module_reset_objects (MOCK_SLOT_ONE_ID);
done:
/* Mark us as officially initialized */
@@ -425,24 +463,7 @@ mock_C_Finalize (CK_VOID_PTR reserved)
return_val_if_fail (pkcs11_initialized, CKR_CRYPTOKI_NOT_INITIALIZED);
return_val_if_fail (reserved == NULL, CKR_ARGUMENTS_BAD);
- p11_mutex_lock (&init_mutex);
-
- /* This should stop all other calls in */
- pkcs11_initialized = false;
- pkcs11_initialized_pid = 0;
-
- p11_dict_free (the_objects);
- the_objects = NULL;
-
- p11_dict_free (the_sessions);
- the_sessions = NULL;
- logged_in = false;
- the_user_type = 0;
-
- free (the_pin);
-
- p11_mutex_unlock (&init_mutex);
-
+ module_finalize ();
return CKR_OK;
}