diff options
-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", |