mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-30 05:57:52 +00:00
Merged rt43076 (log PKCS#11 provider load failure)
This commit is contained in:
parent
228a095c29
commit
2f08617da9
@ -150,6 +150,8 @@ void pk11_dump_tokens(void);
|
||||
CK_RV
|
||||
pkcs_C_Initialize(CK_VOID_PTR pReserved);
|
||||
|
||||
char *pk11_get_load_error_message(void);
|
||||
|
||||
CK_RV
|
||||
pkcs_C_Finalize(CK_VOID_PTR pReserved);
|
||||
|
||||
|
@ -206,6 +206,8 @@ pk11_initialize(isc_mem_t *mctx, const char *engine) {
|
||||
|
||||
if (rv == 0xfe) {
|
||||
result = PK11_R_NOPROVIDER;
|
||||
fprintf(stderr, "Can't load PKCS#11 provider: %s\n",
|
||||
pk11_get_load_error_message());
|
||||
goto unlock;
|
||||
}
|
||||
if (rv != CKR_OK) {
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include <pk11/internal.h>
|
||||
|
||||
static void *hPK11 = NULL;
|
||||
static char loaderrmsg[1024];
|
||||
|
||||
CK_RV
|
||||
pkcs_C_Initialize(CK_VOID_PTR pReserved) {
|
||||
@ -40,14 +41,22 @@ pkcs_C_Initialize(CK_VOID_PTR pReserved) {
|
||||
|
||||
hPK11 = dlopen(pk11_get_lib_name(), RTLD_NOW);
|
||||
|
||||
if (hPK11 == NULL)
|
||||
if (hPK11 == NULL) {
|
||||
snprintf(loaderrmsg, sizeof(loaderrmsg),
|
||||
"dlopen(\"%s\") failed: %s\n",
|
||||
pk11_get_lib_name(), dlerror());
|
||||
return (CKR_LIBRARY_FAILED_TO_LOAD);
|
||||
}
|
||||
sym = (CK_C_Initialize)dlsym(hPK11, "C_Initialize");
|
||||
if (sym == NULL)
|
||||
return (CKR_SYMBOL_RESOLUTION_FAILED);
|
||||
return (*sym)(pReserved);
|
||||
}
|
||||
|
||||
char *pk11_get_load_error_message(void) {
|
||||
return (loaderrmsg);
|
||||
}
|
||||
|
||||
CK_RV
|
||||
pkcs_C_Finalize(CK_VOID_PTR pReserved) {
|
||||
CK_C_Finalize sym;
|
||||
@ -131,8 +140,12 @@ pkcs_C_OpenSession(CK_SLOT_ID slotID, CK_FLAGS flags,
|
||||
|
||||
if (hPK11 == NULL)
|
||||
hPK11 = dlopen(pk11_get_lib_name(), RTLD_NOW);
|
||||
if (hPK11 == NULL)
|
||||
if (hPK11 == NULL) {
|
||||
snprintf(loaderrmsg, sizeof(loaderrmsg),
|
||||
"dlopen(\"%s\") failed: %s\n",
|
||||
pk11_get_lib_name(), dlerror());
|
||||
return (CKR_LIBRARY_FAILED_TO_LOAD);
|
||||
}
|
||||
if ((sym == NULL) || (hPK11 != pPK11)) {
|
||||
pPK11 = hPK11;
|
||||
sym = (CK_C_OpenSession)dlsym(hPK11, "C_OpenSession");
|
||||
|
@ -747,6 +747,7 @@ pk11_error_fatalcheck
|
||||
pk11_finalize
|
||||
pk11_get_best_token
|
||||
pk11_get_lib_name
|
||||
pk11_get_load_error_message
|
||||
pk11_get_session
|
||||
pk11_initialize
|
||||
pk11_initmsgcat
|
||||
|
@ -63,6 +63,7 @@ getpassphrase(const char *prompt) {
|
||||
/* load PKCS11 DLL */
|
||||
|
||||
static HINSTANCE hPK11 = NULL;
|
||||
static char loaderrmsg[1024];
|
||||
|
||||
CK_RV
|
||||
pkcs_C_Initialize(CK_VOID_PTR pReserved) {
|
||||
@ -80,14 +81,23 @@ pkcs_C_Initialize(CK_VOID_PTR pReserved) {
|
||||
|
||||
hPK11 = LoadLibraryA(lib_name);
|
||||
|
||||
if (hPK11 == NULL)
|
||||
if (hPK11 == NULL) {
|
||||
const DWORD err = GetLastError();
|
||||
snprintf(loaderrmsg, sizeof(loaderrmsg),
|
||||
"LoadLibraryA(\"%s\") failed with 0x%X\n",
|
||||
lib_name, err);
|
||||
return (CKR_LIBRARY_FAILED_TO_LOAD);
|
||||
}
|
||||
sym = (CK_C_Initialize)GetProcAddress(hPK11, "C_Initialize");
|
||||
if (sym == NULL)
|
||||
return (CKR_SYMBOL_RESOLUTION_FAILED);
|
||||
return (*sym)(pReserved);
|
||||
}
|
||||
|
||||
char *pk11_get_load_error_message(void) {
|
||||
return (loaderrmsg);
|
||||
}
|
||||
|
||||
CK_RV
|
||||
pkcs_C_Finalize(CK_VOID_PTR pReserved) {
|
||||
CK_C_Finalize sym;
|
||||
@ -167,8 +177,13 @@ pkcs_C_OpenSession(CK_SLOT_ID slotID,
|
||||
|
||||
if (hPK11 == NULL)
|
||||
hPK11 = LoadLibraryA(pk11_get_lib_name());
|
||||
if (hPK11 == NULL)
|
||||
if (hPK11 == NULL) {
|
||||
const DWORD err = GetLastError();
|
||||
snprintf(loaderrmsg, sizeof(loaderrmsg),
|
||||
"LoadLibraryA(\"%s\") failed with 0x%X\n",
|
||||
pk11_get_lib_name(), err);
|
||||
return (CKR_LIBRARY_FAILED_TO_LOAD);
|
||||
}
|
||||
if (sym == NULL)
|
||||
sym = (CK_C_OpenSession)GetProcAddress(hPK11, "C_OpenSession");
|
||||
if (sym == NULL)
|
||||
|
Loading…
x
Reference in New Issue
Block a user