[pkg-opensc-commit] [libp11] 31/239: remove nslots and slots from PKCS11_CTX. ask user to free slots.
Eric Dorland
eric at moszumanska.debian.org
Sat Oct 17 06:21:05 UTC 2015
This is an automated email from the git hooks/post-receive script.
eric pushed a commit to branch master
in repository libp11.
commit 9bc1f71184f5a4f79a27e283f5a67a2a07bb1999
Author: Andreas Jellinghaus <andreas at ionisiert.de>
Date: Thu Sep 1 14:04:57 2005 +0000
remove nslots and slots from PKCS11_CTX.
ask user to free slots.
---
src/libp11-int.h | 4 ----
src/libp11.h | 11 +++++++--
src/p11_load.c | 6 -----
src/p11_slot.c | 73 ++++++++++++++++++++++++++------------------------------
4 files changed, 43 insertions(+), 51 deletions(-)
diff --git a/src/libp11-int.h b/src/libp11-int.h
index 9b66b49..0398a48 100644
--- a/src/libp11-int.h
+++ b/src/libp11-int.h
@@ -41,8 +41,6 @@ typedef struct pkcs11_ctx_private {
CK_FUNCTION_LIST_PTR method;
CK_SESSION_HANDLE session;
- int nslots;
- PKCS11_SLOT *slots;
} PKCS11_CTX_private;
#define PRIVCTX(ctx) ((PKCS11_CTX_private *) (ctx->_private))
@@ -121,8 +119,6 @@ typedef struct pkcs11_cert_private {
#define PKCS11_DUP(s) \
pkcs11_strdup((char *) s, sizeof(s))
-extern void pkcs11_destroy_all_slots(PKCS11_CTX *);
-extern void pkcs11_destroy_slot(PKCS11_CTX *, PKCS11_SLOT *);
extern void pkcs11_destroy_keys(PKCS11_TOKEN *);
extern void pkcs11_destroy_certs(PKCS11_TOKEN *);
extern void *pkcs11_malloc(size_t);
diff --git a/src/libp11.h b/src/libp11.h
index 67156f3..8d6ff00 100644
--- a/src/libp11.h
+++ b/src/libp11.h
@@ -102,10 +102,17 @@ extern void PKCS11_CTX_free(PKCS11_CTX *);
extern int PKCS11_open_session(PKCS11_SLOT *, int);
/* Get a list of all slots */
-extern int PKCS11_enumerate_slots(PKCS11_CTX *, PKCS11_SLOT **, unsigned int *);
+extern int PKCS11_enumerate_slots(PKCS11_CTX *,
+ PKCS11_SLOT **slotsp, unsigned int *nslotsp);
+
+/* and free them again */
+extern void PKCS11_destroy_all_slots(PKCS11_CTX *,
+ PKCS11_SLOT *slots, unsigned int nslots);
+extern void PKCS11_destroy_slot(PKCS11_CTX *, PKCS11_SLOT *slot);
/* Find the first slot with a token */
-extern PKCS11_SLOT *PKCS11_find_token(PKCS11_CTX *);
+PKCS11_SLOT *PKCS11_find_token(PKCS11_CTX * ctx,
+ PKCS11_SLOT *slots, unsigned int nslots);
/* Authenticate to the card */
extern int PKCS11_login(PKCS11_SLOT *, int so, const char *pin);
diff --git a/src/p11_load.c b/src/p11_load.c
index 222ce9c..5daae3f 100644
--- a/src/p11_load.c
+++ b/src/p11_load.c
@@ -36,9 +36,6 @@ PKCS11_CTX *PKCS11_CTX_new(void)
ctx = PKCS11_NEW(PKCS11_CTX);
ctx->_private = priv;
- /* Mark list of slots as "need to fetch from card" */
- priv->nslots = -1;
-
return ctx;
}
@@ -83,9 +80,6 @@ void PKCS11_CTX_unload(PKCS11_CTX * ctx)
PKCS11_CTX_private *priv;
priv = PRIVCTX(ctx);
- /* Free any slot info we have allocated */
- pkcs11_destroy_all_slots(ctx);
-
/* Tell the PKCS11 library to shut down */
priv->method->C_Finalize(NULL);
diff --git a/src/p11_slot.c b/src/p11_slot.c
index ec880cd..e03867f 100644
--- a/src/p11_slot.c
+++ b/src/p11_slot.c
@@ -32,47 +32,43 @@ PKCS11_enumerate_slots(PKCS11_CTX * ctx, PKCS11_SLOT ** slotp, unsigned int *cou
{
PKCS11_CTX_private *priv = PRIVCTX(ctx);
- if (priv->nslots < 0) {
- CK_SLOT_ID slotid[64];
- CK_ULONG nslots = sizeof(slotid), n;
- PKCS11_SLOT *slots;
- int rv;
-
- rv = priv->method->C_GetSlotList(FALSE, slotid, &nslots);
- CRYPTOKI_checkerr(PKCS11_F_PKCS11_ENUM_SLOTS, rv);
-
- slots = (PKCS11_SLOT *) pkcs11_malloc(nslots * sizeof(PKCS11_SLOT));
- for (n = 0; n < nslots; n++) {
- if (pkcs11_init_slot(ctx, &slots[n], slotid[n])) {
- while (n--)
- pkcs11_destroy_slot(ctx, slots + n);
- OPENSSL_free(slots);
- return -1;
- }
+ CK_SLOT_ID slotid[64];
+ CK_ULONG nslots = sizeof(slotid), n;
+ PKCS11_SLOT *slots;
+ int rv;
+
+ rv = priv->method->C_GetSlotList(FALSE, slotid, &nslots);
+ CRYPTOKI_checkerr(PKCS11_F_PKCS11_ENUM_SLOTS, rv);
+
+ slots = (PKCS11_SLOT *) pkcs11_malloc(nslots * sizeof(PKCS11_SLOT));
+ for (n = 0; n < nslots; n++) {
+ if (pkcs11_init_slot(ctx, &slots[n], slotid[n])) {
+ while (n--)
+ PKCS11_destroy_slot(ctx, slots + n);
+ OPENSSL_free(slots);
+ return -1;
}
- priv->nslots = nslots;
- priv->slots = slots;
}
- *slotp = priv->slots;
- *countp = priv->nslots;
+ *slotp = slots;
+ *countp = nslots;
return 0;
}
/*
* Find a slot with a token that looks "valuable"
*/
-PKCS11_SLOT *PKCS11_find_token(PKCS11_CTX * ctx)
+PKCS11_SLOT *PKCS11_find_token(PKCS11_CTX * ctx, PKCS11_SLOT * slots, unsigned int nslots)
{
- PKCS11_SLOT *slot_list, *slot, *best;
+ PKCS11_SLOT *slot, *best;
PKCS11_TOKEN *tok;
- unsigned int n, nslots;
+ unsigned int n;
- if (PKCS11_enumerate_slots(ctx, &slot_list, &nslots))
+ if (! slots)
return NULL;
best = NULL;
- for (n = 0, slot = slot_list; n < nslots; n++, slot++) {
+ for (n = 0, slot = slots; n < nslots; n++, slot++) {
if ((tok = slot->token) != NULL) {
if (best == NULL
|| (tok->initialized > best->token->initialized
@@ -182,11 +178,13 @@ int PKCS11_init_token(PKCS11_TOKEN * token, const char *pin, const char *label)
(CK_UTF8CHAR *) label));
CRYPTOKI_checkerr(PKCS11_F_PKCS11_INIT_TOKEN, rv);
- cpriv = PRIVCTX(ctx);
- for (n = 0; n < cpriv->nslots; n++) {
- if (pkcs11_check_token(ctx, cpriv->slots + n) < 0)
- return -1;
- }
+ /* FIXME: how to update the token?
+ * cpriv = PRIVCTX(ctx);
+ * for (n = 0; n < cpriv->nslots; n++) {
+ * if (pkcs11_check_token(ctx, cpriv->slots + n) < 0)
+ * return -1;
+ * }
+ */
return 0;
}
@@ -305,18 +303,15 @@ int pkcs11_init_slot(PKCS11_CTX * ctx, PKCS11_SLOT * slot, CK_SLOT_ID id)
return 0;
}
-void pkcs11_destroy_all_slots(PKCS11_CTX * ctx)
+void PKCS11_destroy_all_slots(PKCS11_CTX * ctx, PKCS11_SLOT *slots, unsigned int nslots)
{
- PKCS11_CTX_private *priv = PRIVCTX(ctx);
+ int i;
- while (priv->nslots > 0)
- pkcs11_destroy_slot(ctx, &priv->slots[--(priv->nslots)]);
- OPENSSL_free(priv->slots);
- priv->slots = NULL;
- priv->nslots = -1;
+ for (i=0; i < nslots; i++)
+ PKCS11_destroy_slot(ctx, &slots[i]);
}
-void pkcs11_destroy_slot(PKCS11_CTX * ctx, PKCS11_SLOT * slot)
+void PKCS11_destroy_slot(PKCS11_CTX * ctx, PKCS11_SLOT * slot)
{
PKCS11_SLOT_private *priv = PRIVSLOT(slot);
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-opensc/libp11.git
More information about the pkg-opensc-commit
mailing list