From d4340c0da4574d61f25d7ebfba6afb352d1113bf Mon Sep 17 00:00:00 2001 From: Jeffrey Altman Date: Sat, 6 Mar 2010 17:32:22 -0500 Subject: [PATCH] Windows: netidmgr - conditionalize use of krb5_get_error_message for KFW 3.1 and earlier KFW 3.1 is supported by OpenAFS but does not contain krb5_get_error_message or krb5_free_error_message. As a result it must be loaded at run-time and conditionally used. LICENSE MIT Change-Id: Ic2ad16bb5c2d905e30ec814951b5253e2ef888da Reviewed-on: http://gerrit.openafs.org/1530 Tested-by: Jeffrey Altman Reviewed-by: Jeffrey Altman --- src/WINNT/netidmgr_plugin/dynimport.c | 12 ++++++++++++ src/WINNT/netidmgr_plugin/dynimport.h | 4 ++++ src/WINNT/netidmgr_plugin/krb5common.c | 8 ++++++-- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/WINNT/netidmgr_plugin/dynimport.c b/src/WINNT/netidmgr_plugin/dynimport.c index 6e53793..7fec39e 100644 --- a/src/WINNT/netidmgr_plugin/dynimport.c +++ b/src/WINNT/netidmgr_plugin/dynimport.c @@ -31,6 +31,7 @@ HINSTANCE hKrb4 = 0; HINSTANCE hKrb5 = 0; +HINSTANCE hKrb5_KFW_32 = 0; HINSTANCE hKrb524 = 0; HINSTANCE hSecur32 = 0; HINSTANCE hComErr = 0; @@ -143,6 +144,8 @@ DECL_FUNC_PTR(krb5_free_host_realm); DECL_FUNC_PTR(krb5_c_random_make_octets); DECL_FUNC_PTR(krb5_free_addresses); DECL_FUNC_PTR(krb5_free_default_realm); + +// Krb5 (3.2) functions DECL_FUNC_PTR(krb5_get_error_message); DECL_FUNC_PTR(krb5_free_error_message); @@ -289,6 +292,10 @@ FUNC_INFO k5_fi[] = { MAKE_FUNC_INFO(krb5_free_host_realm), MAKE_FUNC_INFO(krb5_c_random_make_octets), MAKE_FUNC_INFO(krb5_free_default_realm), + END_FUNC_INFO +}; + +FUNC_INFO k5_kfw_32_fi[] = { MAKE_FUNC_INFO(krb5_get_error_message), MAKE_FUNC_INFO(krb5_free_error_message), END_FUNC_INFO @@ -394,6 +401,9 @@ khm_int32 init_imports(void) { imp_rv = LoadFuncs(CCAPI_DLL, ccapi_fi, &hCCAPI, 0, 1, 0, 0); /* CCAPI_DLL is optional. No error check. */ + imp_rv = LoadFuncs(KRB5_DLL, k5_kfw_32_fi, &hKrb5_KFW_32, 0, 1, 0, 0); + /* KFW 3.2 krb5 functions are optional. No error check. */ + memset(&osvi, 0, sizeof(OSVERSIONINFO)); osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); GetVersionEx(&osvi); @@ -435,6 +445,8 @@ khm_int32 exit_imports(void) { FreeLibrary(hKrb4); if (hKrb5) FreeLibrary(hKrb5); + if (hKrb5_KFW_32) + FreeLibrary(hKrb5_KFW_32); if (hProfile) FreeLibrary(hProfile); if (hComErr) diff --git a/src/WINNT/netidmgr_plugin/dynimport.h b/src/WINNT/netidmgr_plugin/dynimport.h index fee4d05..12d1ba7 100644 --- a/src/WINNT/netidmgr_plugin/dynimport.h +++ b/src/WINNT/netidmgr_plugin/dynimport.h @@ -280,6 +280,10 @@ extern DECL_FUNC_PTR(krb5_free_host_realm); extern DECL_FUNC_PTR(krb5_c_random_make_octets); extern DECL_FUNC_PTR(krb5_free_default_realm); +// Krb5 (3.2) functions +extern DECL_FUNC_PTR(krb5_get_error_message); +extern DECL_FUNC_PTR(krb5_free_error_message); + // Krb524 functions extern DECL_FUNC_PTR(krb524_init_ets); extern DECL_FUNC_PTR(krb524_convert_creds_kdc); diff --git a/src/WINNT/netidmgr_plugin/krb5common.c b/src/WINNT/netidmgr_plugin/krb5common.c index 4a95046..4b97a69 100644 --- a/src/WINNT/netidmgr_plugin/krb5common.c +++ b/src/WINNT/netidmgr_plugin/krb5common.c @@ -50,13 +50,17 @@ khm_krb5_error(krb5_error_code rc, LPCSTR FailedFunctionName, const char *errText; int krb5Error = ((int)(rc & 255)); - errText = pkrb5_get_error_message(rc); + if (pkrb5_get_error_message) + errText = pkrb5_get_error_message(rc); + else + errText = perror_message(rc); _snprintf(message, sizeof(message), "%s\n(Kerberos error %ld)\n\n%s failed", errText, krb5Error, FailedFunctionName); - pkrb5_free_error_message(errText); + if (pkrb5_free_error_message) + pkrb5_free_error_message(errText); MessageBoxA(NULL, message, "Kerberos Five", MB_OK | MB_ICONERROR | MB_TASKMODAL | -- 1.9.4