Check-in [32d54df268]
Overview
SHA1:32d54df268595cb500796eff56f2fa044a73fe5b
Date: 2016-02-26 18:28:32
User: rkeene
Comment:Started working on improving slot reset mechanism
Timelines: family | ancestors | improve-session-and-slot-reset
Downloads: Tarball | ZIP archive
Other Links: files | file ages | folders | manifest
Tags And Properties
Context
2016-02-26
18:28
[32d54df268] Leaf: Started working on improving slot reset mechanism (user: rkeene, tags: improve-session-and-slot-reset)
18:25
[356ac541c7] Create new branch named "improve-session-and-slot-reset" (user: rkeene, tags: improve-session-and-slot-reset)
Changes

Modified cackey.c from [6db8eb96eb] to [96360137ab].

  4822   4822   	int pcsc_connect_ret;
  4823   4823   	CK_ULONG count, slot_count = 0, currslot, slot_idx;
  4824   4824   	char *pcsc_readers, *pcsc_readers_s, *pcsc_readers_e;
  4825   4825   	char *reader_check_pattern;
  4826   4826   	DWORD pcsc_readers_len;
  4827   4827   	LONG scard_listreaders_ret;
  4828   4828   	size_t curr_reader_len;
  4829         -	int slot_reset;
  4830   4829   	int include_reader;
  4831   4830   
  4832   4831   	CACKEY_DEBUG_PRINTF("Called.");
  4833   4832   
  4834   4833   	if (pulCount == NULL) {
  4835   4834   		CACKEY_DEBUG_PRINTF("Error. pulCount is NULL.");
  4836   4835   
................................................................................
  4847   4846   	if (mutex_retval != 0) {
  4848   4847   		CACKEY_DEBUG_PRINTF("Error.  Locking failed.");
  4849   4848   
  4850   4849   		return(CKR_GENERAL_ERROR);
  4851   4850   	}
  4852   4851   
  4853   4852   	/* Clear list of slots */
  4854         -	slot_reset = 0;
  4855   4853   	if (pSlotList) {
  4856         -		if (first_call) {
  4857         -			first_call = 0;
         4854  +		CACKEY_DEBUG_PRINTF("Purging all slot information.");
  4858   4855   
  4859         -			slot_reset = 1;
  4860         -		}
         4856  +		/* Only update the list of slots if we are actually being supply the slot information */
         4857  +		cackey_slots_disconnect_all(1);
  4861   4858   
  4862         -		/* If any of the slots have been reset then purge all information and check again */
  4863   4859   		for (currslot = 0; currslot < (sizeof(cackey_slots) / sizeof(cackey_slots[0])); currslot++) {
  4864   4860   			if (cackey_slots[currslot].internal) {
  4865   4861   				continue;
  4866   4862   			}
  4867   4863   
  4868         -			if (!cackey_slots[currslot].active) {
  4869         -				continue;
  4870         -			}
  4871         -
  4872         -			if (cackey_slots[currslot].slot_reset) {
  4873         -				slot_reset = 1;
  4874         -
  4875         -				break;
  4876         -			}
  4877         -		}
  4878         -
  4879         -		if (slot_reset) {
  4880         -			CACKEY_DEBUG_PRINTF("Purging all slot information.");
  4881         -
  4882         -			/* Only update the list of slots if we are actually being supply the slot information */
  4883         -			cackey_slots_disconnect_all(1);
  4884         -
  4885         -			for (currslot = 0; currslot < (sizeof(cackey_slots) / sizeof(cackey_slots[0])); currslot++) {
  4886         -				if (cackey_slots[currslot].internal) {
  4887         -					continue;
  4888         -				}
  4889         -
  4890         -				cackey_slots[currslot].active = 0;
  4891         -			}
         4864  +			cackey_slots[currslot].active = 0;
  4892   4865   		}
  4893   4866   	}
  4894   4867   
  4895   4868   	/* Determine list of readers */
  4896   4869   	pcsc_connect_ret = cackey_pcsc_connect();
  4897   4870   	if (pcsc_connect_ret != CACKEY_PCSC_S_OK) {
  4898   4871   		CACKEY_DEBUG_PRINTF("Connection to PC/SC failed, assuming no hardware slots");
................................................................................
  4984   4957   						pcsc_readers += curr_reader_len + 1;
  4985   4958   
  4986   4959   						continue;
  4987   4960   					}
  4988   4961   
  4989   4962   					/* Only update the list of slots if we are actually being asked supply the slot information */
  4990   4963   					if (pSlotList) {
  4991         -						if (slot_reset) {
  4992         -							cackey_slots[currslot].active = 1;
  4993         -							cackey_slots[currslot].internal = 0;
  4994         -							cackey_slots[currslot].pcsc_reader = strdup(pcsc_readers);
  4995         -							cackey_slots[currslot].pcsc_card_connected = 0;
  4996         -							cackey_slots[currslot].transaction_depth = 0;
  4997         -							cackey_slots[currslot].transaction_need_hw_lock = 0;
  4998         -							if (cackey_pin_command == NULL) {
  4999         -								cackey_slots[currslot].token_flags = CKF_LOGIN_REQUIRED;
  5000         -							} else {
  5001         -								cackey_slots[currslot].token_flags = 0;
  5002         -							}
  5003         -							cackey_slots[currslot].label = NULL;
  5004         -
  5005         -							cackey_mark_slot_reset(&cackey_slots[currslot]);
         4964  +						cackey_slots[currslot].active = 1;
         4965  +						cackey_slots[currslot].internal = 0;
         4966  +						cackey_slots[currslot].pcsc_reader = strdup(pcsc_readers);
         4967  +						cackey_slots[currslot].pcsc_card_connected = 0;
         4968  +						cackey_slots[currslot].transaction_depth = 0;
         4969  +						cackey_slots[currslot].transaction_need_hw_lock = 0;
         4970  +						if (cackey_pin_command == NULL) {
         4971  +							cackey_slots[currslot].token_flags = CKF_LOGIN_REQUIRED;
         4972  +						} else {
         4973  +							cackey_slots[currslot].token_flags = 0;
  5006   4974   						}
         4975  +						cackey_slots[currslot].label = NULL;
         4976  +
         4977  +						cackey_mark_slot_reset(&cackey_slots[currslot]);
  5007   4978   					} else {
  5008   4979   						if (!cackey_slots[currslot].active) {
  5009   4980   							/* Artificially increase the number of active slots by what will become active */
  5010   4981   							CACKEY_DEBUG_PRINTF("Found in-active slot %lu, but it will be active after a reset -- marking as active for accounting purposes", (unsigned long) currslot);
  5011   4982   
  5012   4983   							slot_count++;
  5013   4984   						}