From dc55351767ec68d92c09ee3278a865a5b8adbee2 Mon Sep 17 00:00:00 2001 From: vtarasov Date: Wed, 4 May 2011 07:17:28 +0000 Subject: [PATCH] pkcs11: hide empty slots ... The list of slots returned by C_GetSlotList() contains: - if present, virtual hotplug slot; - any slot with token; - without token(s), one empty slot per reader; git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5421 c6295689-39f2-0310-b995-f0e70906c6a9 --- src/pkcs11/pkcs11-global.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/pkcs11/pkcs11-global.c b/src/pkcs11/pkcs11-global.c index e3ee81c0..ca7875ef 100644 --- a/src/pkcs11/pkcs11-global.c +++ b/src/pkcs11/pkcs11-global.c @@ -361,6 +361,7 @@ CK_RV C_GetSlotList(CK_BBOOL tokenPresent, /* only slots with token prese unsigned int i; CK_ULONG numMatches; sc_pkcs11_slot_t *slot; + sc_reader_t *prev_reader = NULL; CK_RV rv; if (pulCount == NULL_PTR) @@ -390,11 +391,18 @@ CK_RV C_GetSlotList(CK_BBOOL tokenPresent, /* only slots with token prese goto out; } + prev_reader = NULL; numMatches = 0; for (i=0; islot_info.flags & CKF_TOKEN_PRESENT)) + /* the list of available slots contains: + * - if present, virtual hotplug slot; + * - any slot with token; + * - without token(s), one empty slot per reader; + */ + if (!slot->reader || (!tokenPresent && slot->reader != prev_reader) || (slot->slot_info.flags & CKF_TOKEN_PRESENT)) found[numMatches++] = slot->id; + prev_reader = slot->reader; } if (pSlotList == NULL_PTR) {