From c1e30395d8f4551a5f0fa253eefeefc9a9154f7e Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Mon, 8 Dec 2008 20:34:49 +0000 Subject: Support the concept of read-write and read-only sessions. --- ckcapi-session.c | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) (limited to 'ckcapi-session.c') diff --git a/ckcapi-session.c b/ckcapi-session.c index 1fdb07e..f4f00aa 100644 --- a/ckcapi-session.c +++ b/ckcapi-session.c @@ -214,7 +214,7 @@ ckcapi_session_destroy(CkCapiSession* sess) static CK_RV lock_ref_internal(CkCapiArray* sessions, CK_SESSION_HANDLE id, - int remove, CkCapiSession** sess_ret) + BOOL remove, BOOL writable, CkCapiSession** sess_ret) { CkCapiSession *sess; DWORD r; @@ -238,6 +238,10 @@ lock_ref_internal(CkCapiArray* sessions, CK_SESSION_HANDLE id, return CKR_SESSION_HANDLE_INVALID; } + /* Make sure it's the right kind of session */ + if(writable && !sess->read_write) + return CKR_SESSION_READ_ONLY; + ASSERT(sess->id == id); /* Closing takes precedence over active operations */ @@ -297,7 +301,31 @@ lock_ref_internal(CkCapiArray* sessions, CK_SESSION_HANDLE id, } CK_RV -ckcapi_session_get_lock_ref(CK_ULONG id, int remove, CkCapiSession **sess) +ckcapi_session_get_lock_ref(CK_ULONG id, BOOL writable, CkCapiSession **sess) +{ + /* This must be called without any locks held */ + + CK_RV ret = CKR_OK; + + ASSERT(sess); + + if(id <= 0) + { + DBG(("invalid session id passed: %d", id)); + return CKR_ARGUMENTS_BAD; + } + + ckcapi_lock_global(); + + ret = lock_ref_internal (all_sessions, id, FALSE, writable, sess); + + ckcapi_unlock_global(); + + return ret; +} + +CK_RV +ckcapi_session_remove_lock_ref(CK_ULONG id, CkCapiSession **sess) { /* This must be called without any locks held */ @@ -313,7 +341,7 @@ ckcapi_session_get_lock_ref(CK_ULONG id, int remove, CkCapiSession **sess) ckcapi_lock_global(); - ret = lock_ref_internal (all_sessions, id, remove, sess); + ret = lock_ref_internal (all_sessions, id, TRUE, FALSE, sess); ckcapi_unlock_global(); @@ -414,7 +442,7 @@ ckcapi_session_close_all(CK_SLOT_ID slot) continue; /* We need any calls in other threads to finish, so wait here */ - if(lock_ref_internal(sessions, i, 1, &sess) == CKR_OK) + if(lock_ref_internal(sessions, i, TRUE, FALSE, &sess) == CKR_OK) ckcapi_session_unref_unlock(sess); } -- cgit v1.2.3