diff options
author | Stef Walter <stef@memberwebs.com> | 2007-05-06 14:27:39 +0000 |
---|---|---|
committer | Stef Walter <stef@memberwebs.com> | 2007-05-06 14:27:39 +0000 |
commit | 8ddd21cad4109c44a388acaab72507b8f54e4c35 (patch) | |
tree | 203961770737cdcdd598204c12b0f64c22a6b7cc | |
parent | 80ca168a6b656dfc7bcc0cc32e90391b66b6bf4c (diff) |
Fix problem with objects going away due to duplicates.
-rw-r--r-- | ckcapi-builtin.c | 2 | ||||
-rw-r--r-- | ckcapi-cert.c | 4 | ||||
-rw-r--r-- | ckcapi-session.c | 13 | ||||
-rw-r--r-- | ckcapi-trust.c | 10 |
4 files changed, 17 insertions, 12 deletions
diff --git a/ckcapi-builtin.c b/ckcapi-builtin.c index b4a7e3f..0694d15 100644 --- a/ckcapi-builtin.c +++ b/ckcapi-builtin.c @@ -181,7 +181,7 @@ ckcapi_builtin_find(CkCapiSession* sess, CK_OBJECT_CLASS cls, CK_ATTRIBUTE_PTR m if(ret != CKR_OK) break; - ckcapi_array_append(arr, obj); + ckcapi_array_append(arr, obj->id); } } diff --git a/ckcapi-cert.c b/ckcapi-cert.c index 501f2a2..064c5f5 100644 --- a/ckcapi-cert.c +++ b/ckcapi-cert.c @@ -538,7 +538,7 @@ find_in_store(CkCapiSession* sess, const char* store_name, CertFreeCertificateContext((PCCERT_CONTEXT)objdata.data); } - ckcapi_array_append(arr, obj); + ckcapi_array_append(arr, obj->id); } } @@ -597,7 +597,7 @@ match_in_store(CkCapiSession* sess, const char* store_name, PCERT_INFO info, /* Store away the object data for performance reasons */ ret = ckcapi_session_set_object_data(sess, obj, &objdata); if(ret == CKR_OK) - ckcapi_array_append(arr, obj); + ckcapi_array_append(arr, obj->id); } } diff --git a/ckcapi-session.c b/ckcapi-session.c index dc35ce0..5daae6e 100644 --- a/ckcapi-session.c +++ b/ckcapi-session.c @@ -550,7 +550,7 @@ void purge_duplicate_objects(CkCapiArray* arr) { CkCapiHash* checks; - CkCapiObject* v; + CK_OBJECT_HANDLE* v; size_t i; checks = ckcapi_hash_new(); @@ -559,15 +559,15 @@ purge_duplicate_objects(CkCapiArray* arr) for(i = 0; i < arr->len; ) { - v = ckcapi_array_index(arr, CkCapiObject*, i); - if(ckcapi_hash_get(checks, &v, sizeof(CkCapiObject*))) + v = &ckcapi_array_index(arr, CK_OBJECT_HANDLE, i); + if(ckcapi_hash_get(checks, v, sizeof(CK_OBJECT_HANDLE))) { ckcapi_array_remove_index(arr, i); /* Look at same i again */ } else { - if(!ckcapi_hash_set(checks, &v, sizeof(CkCapiObject*), &v)) + if(!ckcapi_hash_set(checks, v, sizeof(CK_OBJECT_HANDLE), v)) break; ++i; } @@ -589,7 +589,7 @@ ckcapi_session_find_init(CkCapiSession* sess, CK_ATTRIBUTE_PTR match, if(sess->operation_type != OPERATION_NONE) return CKR_OPERATION_ACTIVE; - arr = ckcapi_array_new(0, 1, sizeof(CkCapiObject*)); + arr = ckcapi_array_new(0, 1, sizeof(CK_OBJECT_HANDLE)); if(!arr) return CKR_HOST_MEMORY; @@ -633,7 +633,8 @@ ckcapi_session_find(CkCapiSession* sess, CK_OBJECT_HANDLE_PTR objects, arr = (CkCapiArray*)sess->operation_data; *object_count = (max_object_count > arr->len ? arr->len : max_object_count); for(i = 0; i < *object_count; ++i) - objects[i] = ckcapi_array_index(arr, CkCapiObject*, i)->id; + objects[i] = ckcapi_array_index(arr, CK_OBJECT_HANDLE, i); + ckcapi_array_remove_range(arr, 0, *object_count); return CKR_OK; diff --git a/ckcapi-trust.c b/ckcapi-trust.c index db543a7..aa8475a 100644 --- a/ckcapi-trust.c +++ b/ckcapi-trust.c @@ -411,6 +411,7 @@ CK_RV ckcapi_trust_find(CkCapiSession* sess, CK_OBJECT_CLASS cls, CK_ATTRIBUTE_PTR match, CK_ULONG count, CkCapiArray* arr) { + CK_OBJECT_HANDLE id; CkCapiObject* obj; CkCapiObject* certobj; CkCapiObjectData* objdata; @@ -422,7 +423,7 @@ ckcapi_trust_find(CkCapiSession* sess, CK_OBJECT_CLASS cls, return CKR_OK; /* Get a list of all certificates */ - certarr = ckcapi_array_new(0, 1, sizeof(CkCapiObject*)); + certarr = ckcapi_array_new(0, 1, sizeof(CK_OBJECT_HANDLE)); if(!certarr) return CKR_HOST_MEMORY; ret = list_matching_certificates(sess, match, count, certarr); @@ -432,7 +433,10 @@ ckcapi_trust_find(CkCapiSession* sess, CK_OBJECT_CLASS cls, { for(i = 0; i < certarr->len; ++i) { - certobj = ckcapi_array_index(certarr, CkCapiObject*, i); + id = ckcapi_array_index(certarr, CK_OBJECT_HANDLE, i); + ASSERT(id); + + certobj = ckcapi_object_lookup (sess, id); ASSERT(certobj); /* We'll register a trust object for any loaded certificate */ @@ -448,7 +452,7 @@ ckcapi_trust_find(CkCapiSession* sess, CK_OBJECT_CLASS cls, /* Only return new object if it matches */ if(ckcapi_object_data_match(objdata, match, count)) - ckcapi_array_append(arr, obj); + ckcapi_array_append(arr, obj->id); } } |