In some case readers can be wired to always return
CKF_TOKEN_PRESENT even when there's no card (Because there's no
mechanical contacts for card insertion, like some SIMcard readers).
This patch fix the issue of PKCS11_enumerate_slots() failing because
one of the readers reported a token present but pkcs11_check_token
failed.
diff --git a/src/p11_slot.c b/src/p11_slot.c
index 35a8cd1..d14a16a 100644
--- a/src/p11_slot.c
+++ b/src/p11_slot.c
@@ -309,19 +309,27 @@ static int pkcs11_init_slot(PKCS11_CTX * ctx, PKCS11_SLOT * slot, CK_SLOT_ID id)
int rv;
rv = CRYPTOKI_call(ctx, C_GetSlotInfo(id, &info));
- CRYPTOKI_checkerr(PKCS11_F_PKCS11_ENUM_SLOTS, rv);
priv = PKCS11_NEW(PKCS11_SLOT_private);
priv->parent = ctx;
priv->id = id;
- slot->description = PKCS11_DUP(info.slotDescription);
- slot->manufacturer = PKCS11_DUP(info.manufacturerID);
- slot->removable = (info.flags & CKF_REMOVABLE_DEVICE) ? 1 : 0;
slot->_private = priv;
-
- if ((info.flags & CKF_TOKEN_PRESENT) && pkcs11_check_token(ctx, slot))
- return -1;
+ if (!rv) {
+ slot->description = PKCS11_DUP(info.slotDescription);
+ slot->manufacturer = PKCS11_DUP(info.manufacturerID);
+ slot->removable = (info.flags & CKF_REMOVABLE_DEVICE) ? 1 : 0;
+ if ((info.flags & CKF_TOKEN_PRESENT) && pkcs11_check_token(ctx, slot))
+ slot->token = NULL;
+ }
+ else {
+ char desc[64];
+ snprintf(desc, sizeof(desc), "(GetSlotInfo failed, error %d)", rv);
+ slot->description = PKCS11_DUP(desc);
+ slot->manufacturer = PKCS11_DUP("Unknown");
+ slot->removable = 0;
+ slot->token = NULL;
+ }
return 0;
}
_______________________________________________
opensc-devel mailing list
opensc-devel@lists.opensc-project.org
http://www.opensc-project.org/mailman/listinfo/opensc-devel