]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
Do not call krb5_get_error_message with NULL context
authorJeffrey Altman <jaltman@your-file-system.com>
Fri, 7 Oct 2011 22:45:08 +0000 (18:45 -0400)
committerDerrick Brashear <shadow@dementix.org>
Sun, 9 Oct 2011 17:20:57 +0000 (10:20 -0700)
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>
src/WINNT/aklog/aklog.c
src/WINNT/netidmgr_plugin/krb5common.c
src/util/krb5_nt.c

index cb9bb414f4366c620839f1a9de47e3874684b476..d9b4fc10d5010b0dd50c02b5631a4489b7e3f31e 100644 (file)
@@ -197,6 +197,8 @@ static int use524 = FALSE;  /* use krb524? */
 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;
 
@@ -217,6 +219,8 @@ void akexit(int exit_code)
 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);
@@ -225,16 +229,22 @@ redirect_errors(const char *who, afs_int32 code, const char *fmt, va_list ap)
         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);
@@ -1416,6 +1426,8 @@ load_krb5_error_message_funcs(void)
 {
     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");
     }
index 3c294e4530b30ee834319067a79236663249ac74..8212c802f7293775e3f74e5bc03fa5907fd6219d 100644 (file)
@@ -53,8 +53,8 @@ khm_krb5_error(krb5_error_code rc, LPCSTR FailedFunctionName,
     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),
@@ -62,8 +62,8 @@ khm_krb5_error(krb5_error_code rc, LPCSTR FailedFunctionName,
         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 |
index 61d6b39be8e3e776209ba734a081203a7accb5a2..093c324bebe08cd7b96e3bd409abccd4c4754ae1 100644 (file)
@@ -30,6 +30,8 @@
 #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;
 
@@ -57,6 +59,8 @@ initialize_krb5(void)
      */
     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");
     }
@@ -66,15 +70,28 @@ const char *
 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;
 }