[pkg-opensc-commit] [libp11] 02/08: Engine config cleanup moved from finish to destroy
Eric Dorland
eric at moszumanska.debian.org
Mon Oct 24 02:08:49 UTC 2016
This is an automated email from the git hooks/post-receive script.
eric pushed a commit to branch master
in repository libp11.
commit 249e09ff476478c84ddc4fcd192ff57caeddb54d
Author: Michał Trojnara <Michal.Trojnara at stunnel.org>
Date: Tue Sep 20 22:09:37 2016 +0200
Engine config cleanup moved from finish to destroy
Fixed a 0.4.0 regression bug causing the engine finish function to remove any configured engine parameters.
fixes #104
---
NEWS | 2 ++
src/eng_back.c | 52 +++++++++++++++++++++++++++++++++++-----------------
src/eng_front.c | 18 +++++++++++-------
src/engine.h | 2 ++
4 files changed, 50 insertions(+), 24 deletions(-)
diff --git a/NEWS b/NEWS
index 99bb180..8a05279 100644
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,8 @@
NEWS for Libp11 -- History of user visible changes
New in 0.4.2; unreleased
+* Fixed a 0.4.0 regression bug causing the engine finish function to
+ remove any configured engine parameters; fixes #104 (Michał Trojnara)
New in 0.4.1; 2016-09-17; Michał Trojnara
* Use enginesdir provided by libcrypto.pc if available (David Woodhouse)
diff --git a/src/eng_back.c b/src/eng_back.c
index 6effe82..9948c8a 100644
--- a/src/eng_back.c
+++ b/src/eng_back.c
@@ -35,14 +35,7 @@
#define MAX_VALUE_LEN 200
struct st_engine_ctx {
- PKCS11_CTX *pkcs11_ctx;
- PKCS11_SLOT *slot_list;
- unsigned int slot_count;
-#if OPENSSL_VERSION_NUMBER >= 0x10100004L
- CRYPTO_RWLOCK *rwlock;
-#else
- int rwlock;
-#endif
+ /* Engine configuration */
/*
* The PIN used for login. Cache for the get_pin function.
* The memory for this PIN is always owned internally,
@@ -54,6 +47,18 @@ struct st_engine_ctx {
int verbose;
char *module;
char *init_args;
+
+ /* Engine initialization mutex */
+#if OPENSSL_VERSION_NUMBER >= 0x10100004L
+ CRYPTO_RWLOCK *rwlock;
+#else
+ int rwlock;
+#endif
+
+ /* Current operations */
+ PKCS11_CTX *pkcs11_ctx;
+ PKCS11_SLOT *slot_list;
+ unsigned int slot_count;
};
/******************************************************************************/
@@ -157,17 +162,11 @@ ENGINE_CTX *pkcs11_new()
return ctx;
}
-int pkcs11_finish(ENGINE_CTX *ctx)
+/* Destroy the context allocated with pkcs11_new() */
+int pkcs11_destroy(ENGINE_CTX *ctx)
{
if (ctx) {
- if (ctx->slot_list) {
- PKCS11_release_all_slots(ctx->pkcs11_ctx,
- ctx->slot_list, ctx->slot_count);
- }
- if (ctx->pkcs11_ctx) {
- PKCS11_CTX_unload(ctx->pkcs11_ctx);
- PKCS11_CTX_free(ctx->pkcs11_ctx);
- }
+ pkcs11_finish(ctx);
destroy_pin(ctx);
OPENSSL_free(ctx->module);
OPENSSL_free(ctx->init_args);
@@ -262,6 +261,25 @@ int pkcs11_init(ENGINE_CTX *ctx)
return 1;
}
+/* Finish engine operations initialized with pkcs11_init() */
+int pkcs11_finish(ENGINE_CTX *ctx)
+{
+ if (ctx) {
+ if (ctx->slot_list) {
+ PKCS11_release_all_slots(ctx->pkcs11_ctx,
+ ctx->slot_list, ctx->slot_count);
+ ctx->slot_list = NULL;
+ ctx->slot_count = 0;
+ }
+ if (ctx->pkcs11_ctx) {
+ PKCS11_CTX_unload(ctx->pkcs11_ctx);
+ PKCS11_CTX_free(ctx->pkcs11_ctx);
+ ctx->pkcs11_ctx = NULL;
+ }
+ }
+ return 1;
+}
+
/******************************************************************************/
/* Certificate handling */
/******************************************************************************/
diff --git a/src/eng_front.c b/src/eng_front.c
index fe515eb..9eae7a1 100644
--- a/src/eng_front.c
+++ b/src/eng_front.c
@@ -133,12 +133,18 @@ static ENGINE_CTX *get_ctx(ENGINE *engine)
return ctx;
}
-/* Destructor */
+/* Destroy the context allocated with pkcs11_new() */
static int engine_destroy(ENGINE *engine)
{
- (void)engine;
+ ENGINE_CTX *ctx;
+ int rv;
- return 1;
+ ctx = get_ctx(engine);
+ if (ctx == NULL)
+ return 0;
+ rv = pkcs11_destroy(ctx);
+ ENGINE_set_ex_data(engine, pkcs11_idx, NULL);
+ return rv;
}
static int engine_init(ENGINE *engine)
@@ -151,17 +157,15 @@ static int engine_init(ENGINE *engine)
return pkcs11_init(ctx);
}
+/* Finish engine operations initialized with pkcs11_init() */
static int engine_finish(ENGINE *engine)
{
ENGINE_CTX *ctx;
- int rv;
ctx = get_ctx(engine);
if (ctx == NULL)
return 0;
- rv = pkcs11_finish(ctx);
- ENGINE_set_ex_data(engine, pkcs11_idx, NULL);
- return rv;
+ return pkcs11_finish(ctx);
}
static EVP_PKEY *load_pubkey(ENGINE *engine, const char *s_key_id,
diff --git a/src/engine.h b/src/engine.h
index bd57479..45a5ccf 100644
--- a/src/engine.h
+++ b/src/engine.h
@@ -53,6 +53,8 @@ typedef struct st_engine_ctx ENGINE_CTX; /* opaque */
ENGINE_CTX *pkcs11_new();
+int pkcs11_destroy(ENGINE_CTX *ctx);
+
int pkcs11_init(ENGINE_CTX *ctx);
int pkcs11_finish(ENGINE_CTX *ctx);
--
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