diff options
author | Alon Levy <alevy@redhat.com> | 2011-01-31 19:26:38 +0200 |
---|---|---|
committer | Alon Levy <alevy@redhat.com> | 2011-02-03 16:54:27 +0200 |
commit | c9823c549f7dd2853423fa970551cfce31865916 (patch) | |
tree | 9035398acf6173298fef0ad3361fc5beaf8d840a | |
parent | fdb2ecf456e3ff23a8a9d0f5a6091778088375f5 (diff) |
vcard_emul_nss: load coolkey in more situations
Previously we didn't load coolkey if there was a module with a removal
slot, possibly virtuals. Fix this to only accept hw removable slots.
This would be a problem for users that did not request adding the coolkey
provider specifically, since they would get no provider and not see the
hw slots.
-rw-r--r-- | vcard_emul_nss.c | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/vcard_emul_nss.c b/vcard_emul_nss.c index 10f29da..6887cf6 100644 --- a/vcard_emul_nss.c +++ b/vcard_emul_nss.c @@ -29,7 +29,6 @@ #include <stdlib.h> #include <string.h> - struct VCardKeyStruct { CERTCertificate *cert; PK11SlotInfo *slot; @@ -718,6 +717,30 @@ vcard_emul_force_card_insert(VReader *vreader) return VCARD_EMUL_OK; } + +static PRBool +module_has_removable_hw_slots(SECMODModule *mod) +{ + int i; + PRBool ret = PR_FALSE; + SECMODListLock *moduleLock = SECMOD_GetDefaultModuleListLock(); + + if (!moduleLock) { + PORT_SetError(SEC_ERROR_NOT_INITIALIZED); + return ret; + } + SECMOD_GetReadLock(moduleLock); + for (i=0; i < mod->slotCount; i++) { + PK11SlotInfo *slot = mod->slots[i]; + if (PK11_IsRemovable(slot) && PK11_IsHW(slot)) { + ret = PR_TRUE; + break; + } + } + SECMOD_ReleaseReadLock(moduleLock); + return ret; +} + /* Previously we returned FAIL if no readers found. This makes * no sense when using hardware, since there may be no readers connected * at the time vcard_emul_init is called, but they will be properly @@ -730,7 +753,7 @@ VCardEmulError vcard_emul_init(const VCardEmulOptions *options) { SECStatus rv; - PRBool ret, has_readers=PR_FALSE, need_module; + PRBool ret, has_readers=PR_FALSE, need_coolkey_module; VReader *vreader; VReaderEmul *vreader_emul; SECMODListLock *module_lock; @@ -826,18 +849,18 @@ vcard_emul_init(const VCardEmulOptions *options) /* make sure we have some PKCS #11 module loaded */ module_lock = SECMOD_GetDefaultModuleListLock(); module_list = SECMOD_GetDefaultModuleList(); - need_module = !has_readers; + need_coolkey_module = !has_readers; SECMOD_GetReadLock(module_lock); for (mlp = module_list; mlp; mlp = mlp->next) { SECMODModule * module = mlp->module; - if (SECMOD_HasRemovableSlots(module)) { - need_module = PR_FALSE; + if (module_has_removable_hw_slots(module)) { + need_coolkey_module = PR_FALSE; break; } } SECMOD_ReleaseReadLock(module_lock); - if (need_module) { + if (need_coolkey_module) { SECMODModule *module; module = SECMOD_LoadUserModule( (char*)"library=libcoolkeypk11.so name=Coolkey", |