MIT's krb5_get_error_message() ignores the context and can
be called with a NULL context. Heimdal's version does not.
Derived from http://gerrit.openafs.org/5508 aka commit
9dd9cfa0e1536e0e75628c84605b3d5b8486d69c
The 1.6 branch is sufficiently different from master.
Change-Id: Ie325705a78b155a04a6a9d44800037b72f5b045c
Reviewed-on: http://gerrit.openafs.org/5569
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Derrick Brashear <shadow@dementix.org>
static krb5_context context = 0;
static krb5_ccache _krb425_ccache = 0;
+static krb5_error_code (KRB5_CALLCONV *pkrb5_init_context)(krb5_context *context) = NULL;
+static krb5_error_code (KRB5_CALLCONV *pkrb5_free_context)(krb5_context context) = NULL;
static char * (KRB5_CALLCONV *pkrb5_get_error_message)(krb5_context context, krb5_error_code code)=NULL;
static void (KRB5_CALLCONV *pkrb5_free_error_message)(krb5_context context, char *s) = NULL;
void
redirect_errors(const char *who, afs_int32 code, const char *fmt, va_list ap)
{
+ krb5_context context;
+
if (who) {
fputs(who, stderr);
fputs(": ", stderr);
int freestr = 0;
char *str = (char *)afs_error_message(code);
if (strncmp(str, "unknown", strlen(str)) == 0) {
- if (pkrb5_get_error_message) {
+ if (pkrb5_init_context &&
+ pkrb5_get_error_message &&
+ !pkrb5_init_context(&context))
+ {
str = pkrb5_get_error_message(NULL, code);
freestr = 1;
- } else
+ } else {
str = (char *)error_message(code);
+ }
}
fputs(str, stderr);
fputs(" ", stderr);
- if (freestr)
+ if (freestr) {
pkrb5_free_error_message(NULL, str);
+ pkrb5_free_context(context);
+ }
}
if (fmt) {
vfprintf(stderr, fmt, ap);
{
HINSTANCE h = LoadLibrary(KRB5LIB);
if (h) {
+ (FARPROC)pkrb5_init_context = GetProcAddress(h, "krb5_init_context");
+ (FARPROC)pkrb5_free_context = GetProcAddress(h, "krb5_free_context");
(FARPROC)pkrb5_get_error_message = GetProcAddress(h, "krb5_get_error_message");
(FARPROC)pkrb5_free_error_message = GetProcAddress(h, "krb5_free_error_message");
}
const char *errText;
int krb5Error = ((int)(rc & 255));
- if (pkrb5_get_error_message)
- errText = pkrb5_get_error_message(rc);
+ if (*ctx && pkrb5_get_error_message)
+ errText = pkrb5_get_error_message(*ctx, rc);
else
errText = perror_message(rc);
_snprintf(message, sizeof(message),
errText,
krb5Error,
FailedFunctionName);
- if (pkrb5_free_error_message)
- pkrb5_free_error_message(errText);
+ if (*ctx && pkrb5_free_error_message)
+ pkrb5_free_error_message(*ctx, errText);
MessageBoxA(NULL, message, "Kerberos Five", MB_OK | MB_ICONERROR |
MB_TASKMODAL |
#include <windows.h>
#include "krb5_nt.h"
+static krb5_error_code (KRB5_CALLCONV *pkrb5_init_context)(krb5_context *context) = NULL;
+static krb5_error_code (KRB5_CALLCONV *pkrb5_free_context)(krb5_context context) = NULL;
static char * (KRB5_CALLCONV *pkrb5_get_error_message)(krb5_context context, krb5_error_code code) = NULL;
static void (KRB5_CALLCONV *pkrb5_free_error_message)(krb5_context context, char *s) = NULL;
*/
HINSTANCE h = LoadLibrary(KRB5LIB);
if (h) {
+ (FARPROC)pkrb5_init_context = GetProcAddress(h, "krb5_init_context");
+ (FARPROC)pkrb5_free_context = GetProcAddress(h, "krb5_free_context");
(FARPROC)pkrb5_get_error_message = GetProcAddress(h, "krb5_get_error_message");
(FARPROC)pkrb5_free_error_message = GetProcAddress(h, "krb5_free_error_message");
}
fetch_krb5_error_message(krb5_context context, krb5_error_code code)
{
static char errorText[1024];
+ char *msg = NULL;
+ int free_context = 0;
- if (pkrb5_get_error_message) {
- char *msg = pkrb5_get_error_message(context, code);
+ if (pkrb5_init_context && pkrb5_get_error_message) {
+
+ if (context == NULL) {
+ if (krb5_init_context(&context) != 0)
+ goto done;
+ free_context = 1;
+ }
+
+ msg = pkrb5_get_error_message(context, code);
if (msg) {
strncpy(errorText, msg, sizeof(errorText));
errorText[sizeof(errorText)-1]='\0';
pkrb5_free_error_message(context, msg);
- return errorText;
+ msg = errorText;
}
+
+ if (free_context)
+ pkrb5_free_context(context);
}
- return NULL;
+ done:
+ return msg;
}