pkcs11: (de-) initialize notifications on load

fixes https://github.com/OpenSC/OpenSC/issues/1507
fixes https://github.com/OpenSC/pkcs11-helper/issues/16
This commit is contained in:
Frank Morgner 2019-03-07 13:42:24 +01:00
parent 9ba8f56037
commit 0abe9d11c7
2 changed files with 35 additions and 15 deletions

View File

@ -17,12 +17,12 @@ OPENSC_PKCS11_SRC = pkcs11-global.c pkcs11-session.c pkcs11-object.c misc.c slot
framework-pkcs15init.c debug.c pkcs11.exports \
pkcs11-display.c pkcs11-display.h
OPENSC_PKCS11_CFLAGS = \
$(OPTIONAL_OPENSSL_CFLAGS) $(OPENSC_PKCS11_PTHREAD_CFLAGS)
$(OPENPACE_CFLAGS) $(OPTIONAL_OPENSSL_CFLAGS) $(OPENSC_PKCS11_PTHREAD_CFLAGS)
OPENSC_PKCS11_LIBS = \
$(top_builddir)/src/libopensc/libopensc.la \
$(top_builddir)/src/common/libscdl.la \
$(top_builddir)/src/common/libcompat.la \
$(OPTIONAL_OPENSSL_LIBS) $(PTHREAD_LIBS)
$(OPENPACE_LIBS) $(OPTIONAL_OPENSSL_LIBS) $(PTHREAD_LIBS)
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = opensc-pkcs11.pc

View File

@ -37,6 +37,11 @@
#include "sc-pkcs11.h"
#include "ui/notify.h"
#include "libopensc/sc-ossl-compat.h"
#ifdef ENABLE_OPENPACE
#include <eac/eac.h>
#endif
#ifndef MODULE_APP_NAME
#define MODULE_APP_NAME "opensc-pkcs11"
#endif
@ -210,13 +215,31 @@ static int slot_list_seeker(const void *el, const void *key) {
return 0;
}
#if defined(_WIN32)
#include "libopensc/sc-ossl-compat.h"
#ifdef ENABLE_OPENPACE
#include <eac/eac.h>
#ifndef _WIN32
__attribute__((constructor))
#endif
int module_init()
{
sc_notify_init();
return 1;
}
#ifndef _WIN32
__attribute__((destructor))
#endif
int module_close()
{
sc_notify_close();
#if defined(ENABLE_OPENSSL) && defined(OPENSSL_SECURE_MALLOC_SIZE)
CRYPTO_secure_malloc_done();
#endif
#ifdef ENABLE_OPENPACE
EAC_cleanup();
#endif
return 1;
}
#ifdef _WIN32
BOOL APIENTRY DllMain( HINSTANCE hinstDLL,
DWORD ul_reason_for_call,
LPVOID lpReserved
@ -225,16 +248,13 @@ BOOL APIENTRY DllMain( HINSTANCE hinstDLL,
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
sc_notify_init();
if (!module_init())
return FALSE;
break;
case DLL_PROCESS_DETACH:
sc_notify_close();
if (lpReserved == NULL) {
#if defined(ENABLE_OPENSSL) && defined(OPENSSL_SECURE_MALLOC_SIZE)
CRYPTO_secure_malloc_done();
#endif
#ifdef ENABLE_OPENPACE
EAC_cleanup();
#endif
if (!module_close())
return FALSE;
}
break;
}