From 19256d0fbdc444ed1458c1430305fe8f55f19aec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Love=20H=C3=B6rnquist=20=C3=85strand?= Date: Fri, 21 Apr 2006 21:58:09 +0000 Subject: [PATCH] Add support for parsing slot-number. git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@17150 ec53bebd-3082-4978-b11e-865c3cabbd6b --- lib/hx509/ks_p11.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/lib/hx509/ks_p11.c b/lib/hx509/ks_p11.c index 3bbd86aa2..4e03edf7f 100644 --- a/lib/hx509/ks_p11.c +++ b/lib/hx509/ks_p11.c @@ -579,18 +579,39 @@ p11_init(hx509_context context, { CK_C_GetFunctionList getFuncs; struct p11_module *p; + char *list, *str; int ret; *data = NULL; - p = calloc(1, sizeof(*p)); - if (p == NULL) + list = strdup(residue); + if (list == NULL) return ENOMEM; + p = calloc(1, sizeof(*p)); + if (p == NULL) { + free(list); + return ENOMEM; + } + p->selected_slot = 0; p->refcount = 1; - p->dl_handle = dlopen(residue, RTLD_NOW); + str = strchr(list, ','); + if (str) + *str++ = '\0'; + while (str) { + char *strnext; + strnext = strchr(str, ','); + if (strnext) + *strnext++ = '\0'; + if (strncasecmp(str, "slot=", 5) == 0) + p->selected_slot = atoi(str + 5); + str = strnext; + } + + p->dl_handle = dlopen(list, RTLD_NOW); + free(list); if (p->dl_handle == NULL) { ret = EINVAL; /* XXX */ goto out; @@ -620,7 +641,7 @@ p11_init(hx509_context context, goto out; } - if (p->selected_slot > p->num_slots) { + if (p->selected_slot >= p->num_slots) { ret = EINVAL; goto out; }