Overview
Comment: | Consolidated slot resetting into a single function.
Updated slot resetting to invalidate slot PC/SC handle. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: | 1edf82bc1640a144a0001d47009d39cda846b4cb |
User & Date: | rkeene on 2010-07-23 21:46:17 |
Other Links: | manifest | tags |
Context
2010-07-23
| ||
21:58 | Updated to call SCardDisconnect if we detect a previously connected slot -- this fixes a regression in the previous commit where a smartcard would not function after being inserted, removed, and reinserted check-in: 84aaf35a0e user: rkeene tags: trunk | |
21:46 |
Consolidated slot resetting into a single function.
Updated slot resetting to invalidate slot PC/SC handle. check-in: 1edf82bc16 user: rkeene tags: trunk | |
21:23 |
Added timing information to debug output
Fixed issue where readers that were removed and readded weren't connected to properly check-in: e4fd58cbb9 user: rkeene tags: trunk | |
Changes
Modified cackey.c from [5667b1108e] to [6b202c653c].
817 817 818 818 if (scard_rel_context_ret != SCARD_S_SUCCESS) { 819 819 return(CACKEY_PCSC_E_GENERIC); 820 820 } 821 821 822 822 return(CACKEY_PCSC_S_OK); 823 823 } 824 + 825 +/* 826 + * SYNPOSIS 827 + * void cackey_mark_slot_reset(struct cackey_slot *slot); 828 + * 829 + * ARGUMENTS 830 + * None 831 + * 832 + * RETURN VALUE 833 + * None 834 + * 835 + * NOTES 836 + * This function marks a slot has having been reset, to later be cleaned up. 837 + * Cleanup only happens when a PKCS#11 client calls C_FindObjectsInit. 838 + * 839 + */ 840 +static void cackey_mark_slot_reset(struct cackey_slot *slot) { 841 + if (slot == NULL) { 842 + return; 843 + } 844 + 845 + CACKEY_DEBUG_PRINTF("Called."); 846 + 847 + slot->slot_reset = 1; 848 + slot->pcsc_card_connected = 0; 849 + slot->token_flags = CKF_LOGIN_REQUIRED; 850 + 851 + CACKEY_DEBUG_PRINTF("Returning."); 852 + 853 + return; 854 +} 824 855 825 856 /* 826 857 * SYNPOSIS 827 858 * LONG cackey_reconnect_card(struct cackey_slot *slot, DWORD default_protocol, LPDWORD selected_protocol); 828 859 * 829 860 * ARGUMENTS 830 861 * cackey_slot *slot ................................................................................ 1213 1244 return(CACKEY_PCSC_E_RETRY); 1214 1245 } 1215 1246 1216 1247 if (scard_xmit_ret != SCARD_S_SUCCESS) { 1217 1248 CACKEY_DEBUG_PRINTF("Failed to send APDU to card (SCardTransmit() = %s/%lx)", CACKEY_DEBUG_FUNC_SCARDERR_TO_STR(scard_xmit_ret), (unsigned long) scard_xmit_ret); 1218 1249 1219 1250 CACKEY_DEBUG_PRINTF("Marking slot as having been reset"); 1220 - slot->slot_reset = 1; 1251 + cackey_mark_slot_reset(slot); 1221 1252 1222 1253 if (scard_xmit_ret == SCARD_W_RESET_CARD) { 1223 1254 CACKEY_DEBUG_PRINTF("Reset required, please hold..."); 1224 1255 1225 1256 scard_reconn_ret = cackey_reconnect_card(slot, SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1, &protocol); 1226 1257 1227 1258 if (scard_reconn_ret == SCARD_S_SUCCESS) { ................................................................................ 2175 2206 2176 2207 /* End transaction */ 2177 2208 cackey_end_transaction(slot); 2178 2209 2179 2210 if (respcode == 0x6982) { 2180 2211 CACKEY_DEBUG_PRINTF("Security status not satisified. Returning NEEDLOGIN"); 2181 2212 2182 - slot->slot_reset = 1; 2213 + cackey_mark_slot_reset(slot); 2183 2214 slot->token_flags = CKF_LOGIN_REQUIRED; 2184 2215 2185 2216 return(CACKEY_PCSC_E_NEEDLOGIN); 2186 2217 } 2187 2218 2188 2219 if (send_ret == CACKEY_PCSC_E_TOKENABSENT) { 2189 2220 CACKEY_DEBUG_PRINTF("Token absent. Returning TOKENABSENT"); 2190 2221 2191 - slot->slot_reset = 1; 2222 + cackey_mark_slot_reset(slot); 2192 2223 slot->token_flags = CKF_LOGIN_REQUIRED; 2193 2224 2194 2225 return(CACKEY_PCSC_E_TOKENABSENT); 2195 2226 } 2196 2227 2197 2228 return(-1); 2198 2229 } ................................................................................ 2397 2428 } 2398 2429 2399 2430 atr_len = sizeof(atr); 2400 2431 status_ret = SCardStatus(slot->pcsc_card, NULL, &reader_len, &state, &protocol, atr, &atr_len); 2401 2432 2402 2433 if (status_ret == SCARD_E_INVALID_HANDLE) { 2403 2434 CACKEY_DEBUG_PRINTF("SCardStatus() returned SCARD_E_INVALID_HANDLE, marking is not already connected and trying again"); 2404 - slot->pcsc_card_connected = 0; 2405 - slot->slot_reset = 1; 2406 - slot->token_flags = CKF_LOGIN_REQUIRED; 2435 + cackey_mark_slot_reset(slot); 2407 2436 2408 2437 pcsc_connect_ret = cackey_connect_card(slot); 2409 2438 if (pcsc_connect_ret != CACKEY_PCSC_S_OK) { 2410 2439 CACKEY_DEBUG_PRINTF("Unable to connect to card, returning token absent"); 2411 2440 2412 2441 return(CACKEY_PCSC_E_TOKENABSENT); 2413 2442 } 2414 2443 2415 2444 atr_len = sizeof(atr); 2416 2445 status_ret = SCardStatus(slot->pcsc_card, NULL, &reader_len, &state, &protocol, atr, &atr_len); 2417 2446 } 2418 2447 2419 2448 if (status_ret != SCARD_S_SUCCESS) { 2420 - slot->slot_reset = 1; 2421 - slot->token_flags = CKF_LOGIN_REQUIRED; 2449 + cackey_mark_slot_reset(slot); 2422 2450 2423 2451 if (status_ret == SCARD_W_RESET_CARD) { 2424 2452 CACKEY_DEBUG_PRINTF("Reset required, please hold..."); 2425 2453 2426 2454 scard_reconn_ret = cackey_reconnect_card(slot, SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1, &protocol); 2427 2455 if (scard_reconn_ret == SCARD_S_SUCCESS) { 2428 2456 /* Update protocol */ ................................................................................ 3391 3419 cackey_slots[currslot].pcsc_reader = strdup(pcsc_readers); 3392 3420 cackey_slots[currslot].pcsc_card_connected = 0; 3393 3421 cackey_slots[currslot].transaction_depth = 0; 3394 3422 cackey_slots[currslot].transaction_need_hw_lock = 0; 3395 3423 cackey_slots[currslot].slot_reset = 1; 3396 3424 cackey_slots[currslot].token_flags = CKF_LOGIN_REQUIRED; 3397 3425 cackey_slots[currslot].label = NULL; 3426 + 3427 + cackey_mark_slot_reset(&cackey_slots[currslot]); 3398 3428 } 3399 3429 currslot++; 3400 3430 3401 3431 pcsc_readers += curr_reader_len + 1; 3402 3432 } 3403 3433 3404 3434 /* Start with Slot ID 1, to avoid a bug in GDM on RHEL */ ................................................................................ 4533 4563 } 4534 4564 4535 4565 if (cackey_slots[slotID].label != NULL) { 4536 4566 free(cackey_slots[slotID].label); 4537 4567 cackey_slots[slotID].label = NULL; 4538 4568 } 4539 4569 4540 - cackey_slots[slotID].slot_reset = 0; 4541 - cackey_slots[slotID].pcsc_card_connected = 0; 4542 - cackey_slots[slotID].token_flags = CKF_LOGIN_REQUIRED; 4570 + cackey_mark_slot_reset(&cackey_slots[slotID]); 4543 4571 } 4544 4572 4545 4573 if (cackey_sessions[hSession].identities == NULL) { 4546 4574 cackey_sessions[hSession].identities = cackey_read_identities(&cackey_slots[slotID], &cackey_sessions[hSession].identities_count); 4547 4575 } 4548 4576 4549 4577 if (pTemplate != NULL) {