Add ability to specifiy PKCS#11 slot number when using hx509

Example usage: kinit -C PKCS11:/usr/lib/opensc-pkcs11.so,slot=3 foo@BAR.TLD
This commit is contained in:
Timothy Pearson
2015-09-24 15:14:45 -05:00
parent c81572ab5d
commit 1d07f08351

View File

@@ -65,6 +65,7 @@ struct p11_module {
CK_FUNCTION_LIST_PTR funcs; CK_FUNCTION_LIST_PTR funcs;
CK_ULONG num_slots; CK_ULONG num_slots;
unsigned int ref; unsigned int ref;
unsigned int selected_slot;
struct p11_slot *slot; struct p11_slot *slot;
}; };
@@ -833,6 +834,7 @@ p11_init(hx509_context context,
} }
p->ref = 1; p->ref = 1;
p->selected_slot = 0;
str = strchr(list, ','); str = strchr(list, ',');
if (str) if (str)
@@ -842,10 +844,8 @@ p11_init(hx509_context context,
strnext = strchr(str, ','); strnext = strchr(str, ',');
if (strnext) if (strnext)
*strnext++ = '\0'; *strnext++ = '\0';
#if 0
if (strncasecmp(str, "slot=", 5) == 0) if (strncasecmp(str, "slot=", 5) == 0)
p->selected_slot = atoi(str + 5); p->selected_slot = atoi(str + 5);
#endif
str = strnext; str = strnext;
} }
@@ -930,6 +930,8 @@ p11_init(hx509_context context,
} }
for (i = 0; i < p->num_slots; i++) { for (i = 0; i < p->num_slots; i++) {
if ((p->selected_slot != 0) && (slot_ids[i] != (p->selected_slot - 1)))
continue;
ret = p11_init_slot(context, p, lock, slot_ids[i], i, &p->slot[i]); ret = p11_init_slot(context, p, lock, slot_ids[i], i, &p->slot[i]);
if (!ret) { if (!ret) {
if (p->slot[i].flags & P11_TOKEN_PRESENT) if (p->slot[i].flags & P11_TOKEN_PRESENT)