From 3307dd6f452325721762471689e310f260fc66b5 Mon Sep 17 00:00:00 2001 From: Frank Morgner Date: Sun, 23 Aug 2015 23:41:54 +0200 Subject: [PATCH] implemented sloppy initialization for C_GetSlotInfo Makes things work for Java and closes #523 --- src/pkcs11/pkcs11-global.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/pkcs11/pkcs11-global.c b/src/pkcs11/pkcs11-global.c index 349ee296..8c7959b1 100644 --- a/src/pkcs11/pkcs11-global.c +++ b/src/pkcs11/pkcs11-global.c @@ -485,6 +485,15 @@ CK_RV C_GetSlotInfo(CK_SLOT_ID slotID, CK_SLOT_INFO_PTR pInfo) sc_log(context, "C_GetSlotInfo(0x%lx)", slotID); + if (1 <= list_size(&virtual_slots)) { + /* Most likely virtual_slots only contains the hotplug slot and has not + * been initialized because the caller has *not* called C_GetSlotList + * before C_GetSlotInfo, as required by PKCS#11. Initialize + * virtual_slots to make things work and hope the caller knows what + * it's doing... */ + card_detect_all(); + } + rv = slot_get_slot(slotID, &slot); sc_log(context, "C_GetSlotInfo() get slot rv %i", rv); if (rv == CKR_OK) {