Index: cackey.c ================================================================== --- cackey.c +++ cackey.c @@ -924,10 +924,14 @@ return(retval); } /* PC/SC Related Functions */ +static cackey_ret cackey_login_required(struct cackey_slot *slot) { + return(CACKEY_PCSC_E_NEEDLOGIN); +} + /* * SYNPOSIS * void cackey_slots_disconnect_all(void); * * ARGUMENTS @@ -1098,11 +1102,11 @@ /* * SYNPOSIS * void cackey_mark_slot_reset(struct cackey_slot *slot); * * ARGUMENTS - * None + * ... * * RETURN VALUE * None * * NOTES @@ -1109,10 +1113,12 @@ * This function marks a slot has having been reset, to later be cleaned up. * Cleanup only happens when a PKCS#11 client calls C_FindObjectsInit. * */ static void cackey_mark_slot_reset(struct cackey_slot *slot) { + int login_required = -1; + if (slot == NULL) { return; } CACKEY_DEBUG_PRINTF("Called."); @@ -1121,14 +1127,26 @@ SCardDisconnect(slot->pcsc_card, SCARD_LEAVE_CARD); } slot->slot_reset = 1; slot->pcsc_card_connected = 0; + slot->token_flags = 0; + if (cackey_pin_command == NULL) { - slot->token_flags = CKF_LOGIN_REQUIRED; - } else { - slot->token_flags = 0; + login_required = 0; + } + + if (login_required == -1) { + if (cackey_login_required(slot) != CACKEY_PCSC_S_OK) { + login_required = 1; + } else { + login_required = 0; + } + } + + if (login_required) { + slot->token_flags |= CKF_LOGIN_REQUIRED; } CACKEY_DEBUG_PRINTF("Returning."); return; @@ -2973,12 +2991,10 @@ CACKEY_DEBUG_PRINTF("Security status not satisified (respcode = 0x%04x). Returning NEEDLOGIN", (int) respcode); } cackey_mark_slot_reset(slot); - slot->token_flags = CKF_LOGIN_REQUIRED; - return(CACKEY_PCSC_E_NEEDLOGIN); } if (send_ret == CACKEY_PCSC_E_TOKENABSENT) { CACKEY_DEBUG_PRINTF("Token absent. Returning TOKENABSENT"); @@ -4685,15 +4701,11 @@ cackey_slots[currslot].internal = 0; cackey_slots[currslot].pcsc_reader = strdup(pcsc_readers); cackey_slots[currslot].pcsc_card_connected = 0; cackey_slots[currslot].transaction_depth = 0; cackey_slots[currslot].transaction_need_hw_lock = 0; - if (cackey_pin_command == NULL) { - cackey_slots[currslot].token_flags = CKF_LOGIN_REQUIRED; - } else { - cackey_slots[currslot].token_flags = 0; - } + cackey_slots[currslot].token_flags = 0; cackey_slots[currslot].label = NULL; cackey_mark_slot_reset(&cackey_slots[currslot]); } } else { @@ -5769,16 +5781,10 @@ return(CKR_GENERAL_ERROR); } cackey_sessions[hSession].state = CKS_RO_PUBLIC_SESSION; - if (cackey_pin_command == NULL) { - cackey_slots[slotID].token_flags = CKF_LOGIN_REQUIRED; - } else { - cackey_slots[slotID].token_flags = 0; - } - mutex_retval = cackey_mutex_unlock(cackey_biglock); if (mutex_retval != 0) { CACKEY_DEBUG_PRINTF("Error. Unlocking failed."); return(CKR_GENERAL_ERROR);