- Another go at the empty slot/empty token issue

git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@857 c6295689-39f2-0310-b995-f0e70906c6a9
This commit is contained in:
okir 2003-01-13 21:38:43 +00:00
parent 41ee6a61ba
commit 0af2a35b9c
6 changed files with 34 additions and 29 deletions

View File

@ -289,13 +289,20 @@ static CK_RV pkcs15_create_slot(struct sc_pkcs11_card *p11card,
struct sc_pkcs11_slot **out)
{
struct sc_pkcs15_card *card = (struct sc_pkcs15_card*) p11card->fw_data;
struct sc_pkcs11_slot *slot;
int rv;
rv = slot_allocate(out, p11card);
rv = slot_allocate(&slot, p11card);
if (rv != CKR_OK)
return rv;
pkcs15_init_slot(card, *out, auth);
/* There's a token in this slot */
slot->slot_info.flags |= CKF_TOKEN_PRESENT;
/* Fill in the slot/token info from pkcs15 data */
pkcs15_init_slot(card, slot, auth);
*out = slot;
return CKR_OK;
}
@ -396,8 +403,11 @@ static CK_RV pkcs15_create_tokens(struct sc_pkcs11_card *p11card)
/* Create read/write slots */
while (slot_allocate(&slot, p11card) == CKR_OK) {
pkcs15_init_token_info(card, &slot->token_info);
slot->token_info.flags |= CKF_TOKEN_INITIALIZED;
if (!sc_pkcs11_conf.hide_empty_tokens) {
slot->slot_info.flags |= CKF_TOKEN_PRESENT;
pkcs15_init_token_info(card, &slot->token_info);
slot->token_info.flags |= CKF_TOKEN_INITIALIZED;
}
}
debug(context, "All tokens created\n");

View File

@ -60,6 +60,11 @@ static CK_RV pkcs15init_create_tokens(struct sc_pkcs11_card *p11card)
CK_TOKEN_INFO_PTR pToken = &slot->token_info;
const char *string;
if (sc_pkcs11_conf.hide_empty_tokens)
continue;
slot->slot_info.flags |= CKF_TOKEN_PRESENT;
strcpy_bp(pToken->model, "PKCS #15 SCard", 16);
sc_pkcs15init_get_manufacturer(profile, &string);
if (!string)

View File

@ -305,8 +305,8 @@ void load_pkcs11_parameters(struct sc_pkcs11_config *conf, struct sc_context *ct
int i;
/* Set defaults */
conf->num_slots = SC_PKCS11_MAX_VIRTUAL_SLOTS;
conf->hide_empty_slots = 0;
conf->num_slots = SC_PKCS11_DEF_SLOTS_PER_CARD;
conf->hide_empty_tokens = 0;
conf->lock_login = 1;
conf->cache_pins = 0;
@ -323,7 +323,7 @@ void load_pkcs11_parameters(struct sc_pkcs11_config *conf, struct sc_context *ct
return;
conf->num_slots = scconf_get_int(conf_block, "num_slots", conf->num_slots);
conf->hide_empty_slots = scconf_get_bool(conf_block, "hide_empty_slots", 0);
conf->hide_empty_tokens = scconf_get_bool(conf_block, "hide_empty_tokens", 0);
conf->lock_login = scconf_get_bool(conf_block, "lock_login", 1);
conf->cache_pins = scconf_get_bool(conf_block, "cache_pins", 0);
}

View File

@ -112,16 +112,9 @@ CK_RV C_GetSlotList(CK_BBOOL tokenPresent, /* only slots with token prese
numMatches = 0;
for (i=0; i<SC_PKCS11_MAX_VIRTUAL_SLOTS; i++) {
slot = &virtual_slots[i];
if (!slot->card)
continue;
if (tokenPresent && !(slot->slot_info.flags & CKF_TOKEN_PRESENT))
continue;
/* Hide all empty slots */
if (sc_pkcs11_conf.hide_empty_slots && !slot->fw_data)
continue;
found[numMatches++] = i;
if (!tokenPresent || (slot->slot_info.flags & CKF_TOKEN_PRESENT))
found[numMatches++] = i;
}
if (pSlotList == NULL_PTR) {
@ -152,7 +145,7 @@ CK_RV C_GetSlotInfo(CK_SLOT_ID slotID, CK_SLOT_INFO_PTR pInfo)
if (rv != CKR_OK)
return rv;
if (!(slot->slot_info.flags & CKF_TOKEN_PRESENT)) {
if (!slot->card) {
int i;
for (i=0; i<context->reader_count; i++)
card_detect(i);

View File

@ -51,6 +51,7 @@ extern "C" {
#endif
#define SC_PKCS11_MAX_VIRTUAL_SLOTS 8
#define SC_PKCS11_DEF_SLOTS_PER_CARD 4
#define SC_PKCS11_MAX_READERS SC_MAX_READERS
struct sc_pkcs11_session;
@ -80,7 +81,7 @@ struct sc_pkcs11_pool {
struct sc_pkcs11_config {
unsigned int num_slots;
unsigned char hide_empty_slots;
unsigned char hide_empty_tokens;
unsigned char lock_login;
unsigned char cache_pins;
};

View File

@ -31,7 +31,7 @@ static struct sc_pkcs11_framework_ops *frameworks[] = {
NULL
};
void clear_slot_info(CK_SLOT_INFO_PTR pInfo)
static void init_slot_info(CK_SLOT_INFO_PTR pInfo)
{
strcpy_bp(pInfo->slotDescription, "Virtual slot", 64);
strcpy_bp(pInfo->manufacturerID, "OpenSC project (www.opensc.org)", 32);
@ -80,7 +80,7 @@ CK_RV card_detect(int reader)
card = &card_table[reader];
if (sc_pkcs11_conf.num_slots == 0)
card->max_slots = SC_PKCS11_MAX_VIRTUAL_SLOTS;
card->max_slots = SC_PKCS11_DEF_SLOTS_PER_CARD;
else
card->max_slots = sc_pkcs11_conf.num_slots;
card->num_slots = 0;
@ -140,7 +140,7 @@ CK_RV slot_initialize(int id, struct sc_pkcs11_slot *slot)
memset(slot, 0, sizeof(slot));
slot->id = id;
slot->login_user = -1;
clear_slot_info(&slot->slot_info);
init_slot_info(&slot->slot_info);
pool_initialize(&slot->object_pool, POOL_TYPE_OBJECT);
return CKR_OK;
@ -154,10 +154,9 @@ CK_RV slot_allocate(struct sc_pkcs11_slot **slot, struct sc_pkcs11_card *card)
return CKR_FUNCTION_FAILED;
for (i=0; i<SC_PKCS11_MAX_VIRTUAL_SLOTS; i++) {
if (!(virtual_slots[i].slot_info.flags & CKF_TOKEN_PRESENT)) {
if (!virtual_slots[i].card) {
debug(context, "Allocated slot %d\n", i);
virtual_slots[i].slot_info.flags |= CKF_TOKEN_PRESENT;
virtual_slots[i].card = card;
*slot = &virtual_slots[i];
card->num_slots++;
@ -214,16 +213,13 @@ CK_RV slot_token_removed(int id)
}
/* Release framework stuff */
if (slot->card != NULL && slot->fw_data != NULL) {
if (slot->card != NULL && slot->fw_data != NULL)
slot->card->framework->release_token(slot->card, slot->fw_data);
slot->card = NULL;
slot->fw_data = NULL;
}
/* Zap everything else */
memset(slot, 0, sizeof(*slot));
init_slot_info(&slot->slot_info);
slot->login_user = -1;
clear_slot_info(&slot->slot_info);
return CKR_OK;