diff options
author | ian.mcgreer%sun.com <devnull@localhost> | 2002-04-19 17:32:22 +0000 |
---|---|---|
committer | ian.mcgreer%sun.com <devnull@localhost> | 2002-04-19 17:32:22 +0000 |
commit | 77b33728f89297b2b7509ea76e07d6d62174c1ad (patch) | |
tree | caed36f393539549f6f085c65f16b9e51e16eaa1 | |
parent | 50a2c75d0e6287e42b8f8cab93212d3eb566ab47 (diff) | |
download | nss-hg-77b33728f89297b2b7509ea76e07d6d62174c1ad.tar.gz |
improve synchronization between the token state and token cache operations
-rw-r--r-- | security/nss/lib/dev/devutil.c | 48 |
1 files changed, 38 insertions, 10 deletions
diff --git a/security/nss/lib/dev/devutil.c b/security/nss/lib/dev/devutil.c index 198ef2c42..49e2a7165 100644 --- a/security/nss/lib/dev/devutil.c +++ b/security/nss/lib/dev/devutil.c @@ -1100,6 +1100,28 @@ finish: return rvObjects; } +static PRBool +cache_available_for_object_type +( + nssTokenObjectCache *cache, + PRUint32 objectType +) +{ + if (!cache->doObjectType[objectType]) { + /* not caching this object kind */ + return PR_FALSE; + } + if (!cache->searchedObjectType[objectType]) { + /* objects are not cached yet */ + return PR_FALSE; + } + if (!search_for_objects(cache)) { + /* not logged in or removed */ + return PR_FALSE; + } + return PR_TRUE; +} + NSS_IMPLEMENT PRStatus nssTokenObjectCache_GetObjectAttributes ( @@ -1116,13 +1138,18 @@ nssTokenObjectCache_GetObjectAttributes nssArenaMark *mark = NULL; nssCryptokiObjectAndAttributes *cachedOA = NULL; nssCryptokiObjectAndAttributes **oa = NULL; + PRUint32 objectType; PZ_Lock(cache->lock); switch (objclass) { - case CKO_CERTIFICATE: oa = cache->objects[cachedCerts]; break; - case CKO_NETSCAPE_TRUST: oa = cache->objects[cachedTrust]; break; - case CKO_NETSCAPE_CRL: oa = cache->objects[cachedCRLs]; break; + case CKO_CERTIFICATE: objectType = cachedCerts; break; + case CKO_NETSCAPE_TRUST: objectType = cachedTrust; break; + case CKO_NETSCAPE_CRL: objectType = cachedCRLs; break; default: goto loser; } + if (!cache_available_for_object_type(cache, objectType)) { + goto loser; + } + oa = cache->objects[objectType]; if (!oa) { goto loser; } @@ -1244,14 +1271,13 @@ nssTokenObjectCache_ImportObject case CKO_CERTIFICATE: objectType = cachedCerts; break; case CKO_NETSCAPE_TRUST: objectType = cachedTrust; break; case CKO_NETSCAPE_CRL: objectType = cachedCRLs; break; - default: status = PR_FAILURE; + default: + PZ_Unlock(cache->lock); + return PR_SUCCESS; /* don't need to import it here */ } - if (status != PR_SUCCESS || /* failed */ - !cache->doObjectType[objectType] || /* not caching this kind */ - !cache->searchedObjectType[objectType]) /* not cached yet anyway */ - { + if (!cache_available_for_object_type(cache, objectType)) { PZ_Unlock(cache->lock); - return status; + return PR_SUCCESS; /* cache not active, ignored */ } count = 0; otype = &cache->objects[objectType]; /* index into array of types */ @@ -1286,7 +1312,9 @@ nssTokenObjectCache_RemoveObject nssCryptokiObjectAndAttributes **oa, **swp = NULL; PZ_Lock(cache->lock); for (oType=0; oType<3; oType++) { - if (!cache->objects[oType]) { + if (!cache_available_for_object_type(cache, oType) || + !cache->objects[oType]) + { continue; } for (oa = cache->objects[oType]; *oa; oa++) { |