pkcs11: fixed slotIDs when a new slot list is requested
fixes https://github.com/OpenSC/OpenSC/issues/1706
regression of 24b7507a69
This commit is contained in:
parent
e7a8c00566
commit
7fb72ccf7b
|
@ -451,8 +451,13 @@ CK_RV C_GetSlotList(CK_BBOOL tokenPresent, /* only slots with token prese
|
|||
pSlotList==NULL_PTR? "plug-n-play":"refresh");
|
||||
|
||||
/* Slot list can only change in v2.20 */
|
||||
if (pSlotList == NULL_PTR)
|
||||
if (pSlotList == NULL_PTR) {
|
||||
sc_ctx_detect_readers(context);
|
||||
for (i=0; i<list_size(&virtual_slots); i++) {
|
||||
slot = (sc_pkcs11_slot_t *) list_get_at(&virtual_slots, i);
|
||||
slot->flags &= ~SC_PKCS11_SLOT_FLAG_SEEN;
|
||||
}
|
||||
}
|
||||
|
||||
card_detect_all();
|
||||
|
||||
|
@ -483,6 +488,21 @@ CK_RV C_GetSlotList(CK_BBOOL tokenPresent, /* only slots with token prese
|
|||
prev_reader = slot->reader;
|
||||
}
|
||||
|
||||
/* Slot list can only change in v2.20 */
|
||||
if (pSlotList == NULL_PTR) {
|
||||
/* slot->id is derived from its location in the list virtual_slots.
|
||||
* When the slot list changes, so does slot->id, so we reindex the
|
||||
* slots here the same way it is done in `create_slot()`
|
||||
*
|
||||
* TODO use a persistent CK_SLOT_ID, e.g. by using something like
|
||||
* `slot->id = sc_crc32(slot, sizeof *slot);` (this example, however,
|
||||
* is currently not thread safe). */
|
||||
for (i=0; i<list_size(&virtual_slots); i++) {
|
||||
slot = (sc_pkcs11_slot_t *) list_get_at(&virtual_slots, i);
|
||||
slot->id = (CK_SLOT_ID) list_locate(&virtual_slots, slot);
|
||||
}
|
||||
}
|
||||
|
||||
if (pSlotList == NULL_PTR) {
|
||||
sc_log(context, "was only a size inquiry (%lu)\n", numMatches);
|
||||
*pulCount = numMatches;
|
||||
|
|
|
@ -115,7 +115,6 @@ CK_RV create_slot(sc_reader_t *reader)
|
|||
}
|
||||
|
||||
slot->login_user = -1;
|
||||
slot->id = (CK_SLOT_ID) list_locate(&virtual_slots, slot);
|
||||
init_slot_info(&slot->slot_info, reader);
|
||||
sc_log(context, "Initializing slot with id 0x%lx", slot->id);
|
||||
|
||||
|
@ -126,6 +125,7 @@ CK_RV create_slot(sc_reader_t *reader)
|
|||
slot->slot_info.hardwareVersion.major = reader->version_major;
|
||||
slot->slot_info.hardwareVersion.minor = reader->version_minor;
|
||||
}
|
||||
slot->id = (CK_SLOT_ID) list_locate(&virtual_slots, slot);
|
||||
|
||||
return CKR_OK;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue