krb_server_keyfile setting doesn't work on Windows - Mailing list pgsql-hackers

From Hiroshi Inoue
Subject krb_server_keyfile setting doesn't work on Windows
Date
Msg-id 4B3B7171.6000107@tpf.co.jp
Whole thread Raw
Responses Re: krb_server_keyfile setting doesn't work on Windows  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: krb_server_keyfile setting doesn't work on Windows  (Magnus Hagander <magnus@hagander.net>)
List pgsql-hackers
Hi,

As far as I tested, the krb_server_keyfile setting
in postgres.conf doesn't work on Windows.

Because gssapi32.dll(krb5_32.dll) seems to call
getenv("KRB5_KTNAME") in msvcr71, postgres.exe
should call putenv("KRB5_KTNAME=...") in msvcr71.
The attached patch fixes the problem in my test
case.

regards,
Hiroshi Inoue
Index: auth.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/backend/libpq/auth.c,v
retrieving revision 1.188
diff -c -r1.188 auth.c
*** auth.c    12 Dec 2009 21:35:21 -0000    1.188
--- auth.c    30 Dec 2009 15:03:51 -0000
***************
*** 877,882 ****
--- 877,905 ----
               errdetail("%s: %s", msg_major, msg_minor)));
  }

+ #ifdef    WIN32
+ static void
+ msvc_krb5_ktname(const char *kt_path)
+ {
+     typedef int (_cdecl * PUTENVPROC) (const char *);
+     const char *msvcrdll = "msvcr71";
+     static    bool    initialized = false;
+     HMODULE        hmodule;
+     static PUTENVPROC putenvFunc = NULL;
+
+     if (initialized)
+     {
+         if (!putenvFunc)
+             return;
+     }
+     else if (hmodule = GetModuleHandle(msvcrdll), hmodule != NULL)
+         putenvFunc = (PUTENVPROC) GetProcAddress(hmodule, "_putenv");
+     initialized = true;
+     if (putenvFunc != NULL)
+         putenvFunc(kt_path);
+ }
+ #endif /* WIN32 */
+
  static int
  pg_GSS_recvauth(Port *port)
  {
***************
*** 923,928 ****
--- 946,954 ----
                  return STATUS_ERROR;
              }
              snprintf(kt_path, kt_len, "KRB5_KTNAME=%s", pg_krb_server_keyfile);
+ #ifdef    WIN32
+             msvc_krb5_ktname(kt_path);
+ #endif /* WIN32 */
              putenv(kt_path);
          }
      }

pgsql-hackers by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: Stats for inheritance trees
Next
From: Tom Lane
Date:
Subject: Re: test/example does not support win32.