summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStef Walter <stefw@collabora.co.uk>2011-08-24 15:34:13 +0200
committerStef Walter <stefw@collabora.co.uk>2011-08-24 15:34:13 +0200
commit25512ca5a03d723a84d6de67a7036188d08ec21b (patch)
treef43fe722944257497be4dfd2edfe1ef535979bf2
parent61c925fda7385392b3961f0b44049b9ff7a68093 (diff)
downloadp11-kit-25512ca5a03d723a84d6de67a7036188d08ec21b.tar.gz
Fix bugs in the p11-kit proxy module.
* Initialize the mappings properly * Lookup session handles correctly * Debug initialization and finalization
-rw-r--r--p11-kit/debug.c1
-rw-r--r--p11-kit/debug.h3
-rw-r--r--p11-kit/proxy.c42
3 files changed, 31 insertions, 15 deletions
diff --git a/p11-kit/debug.c b/p11-kit/debug.c
index eb7eef0..e4b39f0 100644
--- a/p11-kit/debug.c
+++ b/p11-kit/debug.c
@@ -54,6 +54,7 @@ static struct DebugKey debug_keys[] = {
{ "lib", DEBUG_LIB },
{ "conf", DEBUG_CONF },
{ "uri", DEBUG_URI },
+ { "proxy", DEBUG_PROXY },
{ 0, }
};
diff --git a/p11-kit/debug.h b/p11-kit/debug.h
index acc9ca6..2d6a226 100644
--- a/p11-kit/debug.h
+++ b/p11-kit/debug.h
@@ -39,7 +39,8 @@
typedef enum {
DEBUG_LIB = 1 << 1,
DEBUG_CONF = 1 << 2,
- DEBUG_URI = 1 << 3
+ DEBUG_URI = 1 << 3,
+ DEBUG_PROXY = 1 << 4,
} DebugFlags;
extern int debug_current_flags;
diff --git a/p11-kit/proxy.c b/p11-kit/proxy.c
index c3c7e80..0f0fc42 100644
--- a/p11-kit/proxy.c
+++ b/p11-kit/proxy.c
@@ -35,6 +35,8 @@
#include "config.h"
+#define DEBUG_FLAG DEBUG_PROXY
+#include "debug.h"
#include "hashmap.h"
#include "pkcs11.h"
#include "p11-kit.h"
@@ -145,7 +147,7 @@ map_session_to_real (CK_SESSION_HANDLE_PTR handle, Mapping *mapping, Session *se
rv = CKR_CRYPTOKI_NOT_INITIALIZED;
} else {
assert (gl.sessions);
- sess = hash_get (gl.sessions, &handle);
+ sess = hash_get (gl.sessions, handle);
if (sess != NULL) {
*handle = sess->real_session;
rv = map_slot_unlocked (sess->wrap_slot, mapping);
@@ -202,25 +204,30 @@ proxy_C_Finalize (CK_VOID_PTR reserved)
{
CK_RV rv;
+ debug ("in");
+
/* WARNING: This function must be reentrant */
- if (reserved)
- return CKR_ARGUMENTS_BAD;
+ if (reserved) {
+ rv = CKR_ARGUMENTS_BAD;
- _p11_lock ();
+ } else {
+ _p11_lock ();
- /* WARNING: Reentrancy can occur here */
- rv = _p11_kit_finalize_registered_unlocked_reentrant ();
+ /* WARNING: Reentrancy can occur here */
+ rv = _p11_kit_finalize_registered_unlocked_reentrant ();
- /*
- * If modules are all gone, then this was the last
- * finalize, so cleanup our mappings
- */
- if (gl.mappings_refs)
- finalize_mappings_unlocked ();
+ /*
+ * If modules are all gone, then this was the last
+ * finalize, so cleanup our mappings
+ */
+ if (gl.mappings_refs)
+ finalize_mappings_unlocked ();
- _p11_unlock ();
+ _p11_unlock ();
+ }
+ debug ("out: %lu", rv);
return rv;
}
@@ -288,6 +295,8 @@ initialize_mappings_unlocked_reentrant (void)
}
assert (!gl.sessions);
+ gl.mappings = mappings;
+ gl.n_mappings = n_mappings;
gl.sessions = hash_create (hash_ulongptr_hash, hash_ulongptr_equal, NULL, free);
++gl.mappings_refs;
@@ -302,20 +311,25 @@ proxy_C_Initialize (CK_VOID_PTR init_args)
/* WARNING: This function must be reentrant */
+ debug ("in");
+
_p11_lock ();
/* WARNING: Reentrancy can occur here */
rv = _p11_kit_initialize_registered_unlocked_reentrant ();
/* WARNING: Reentrancy can occur here */
- if (rv == CKR_OK && !gl.mappings_refs == 0)
+ if (rv == CKR_OK && gl.mappings_refs == 0)
rv = initialize_mappings_unlocked_reentrant ();
_p11_unlock ();
+ debug ("here");
+
if (rv != CKR_OK)
proxy_C_Finalize (NULL);
+ debug ("out: %lu", rv);
return rv;
}