Enable SSPI on cygwin

Started by Reini Urbanover 16 years ago3 messages
#1Reini Urban
rurban@x-ray.at
1 attachment(s)

Attached is my patch to enable SSPI on cygwin.

--
Reini Urban
http://phpwiki.org/ http://murbreak.at/

Attachments:

sspi-cygwin.patchtext/x-patch; name=sspi-cygwin.patchDownload
--- origsrc/postgresql-8.4.0/configure.in	2009-06-27 02:14:47.000000000 +0200
+++ src/postgresql-8.4.0/configure.in	2009-07-02 09:02:25.921875000 +0200
@@ -907,7 +907,11 @@ if test "$with_gssapi" = yes ; then
     AC_SEARCH_LIBS(gss_init_sec_context, [gssapi_krb5 gss 'gssapi -lkrb5 -lcrypto'], [],
 		 		  [AC_MSG_ERROR([could not find function 'gss_init_sec_context' required for GSSAPI])])
   else
-    LIBS="$LIBS -lgssapi32"
+    if test "$PORTNAME" = "cygwin"; then
+      LIBS="$LIBS -lsecur32"
+    else
+      LIBS="$LIBS -lgssapi32"
+    fi
   fi
 fi
 
--- origsrc/postgresql-8.4.0/src/backend/libpq/auth.c	2009-06-25 13:30:08.000000000 +0200
+++ src/postgresql-8.4.0/src/backend/libpq/auth.c	2009-07-02 09:07:55.937500000 +0200
@@ -159,6 +159,9 @@ static krb5_principal pg_krb5_server;
  *----------------------------------------------------------------
  */
 #ifdef ENABLE_GSS
+#ifdef __CYGWIN__
+#define WIN32
+#endif
 #if defined(HAVE_GSSAPI_H)
 #include <gssapi.h>
 #else
--- origsrc/postgresql-8.4.0/src/backend/postmaster/postmaster.c	2009-06-26 22:29:04.000000000 +0200
+++ src/postgresql-8.4.0/src/backend/postmaster/postmaster.c	2009-07-02 09:02:26.421875000 +0200
@@ -371,6 +371,9 @@ typedef struct
 HANDLE		PostmasterHandle;
 #endif
 
+#endif
+#ifdef EXEC_BACKEND
+
 static pid_t backend_forkexec(Port *port);
 static pid_t internal_forkexec(int argc, char *argv[], Port *port);
 
@@ -442,6 +445,7 @@ static void ShmemBackendArrayAdd(Backend
 static void ShmemBackendArrayRemove(Backend *bn);
 #endif   /* EXEC_BACKEND */
 
+
 #define StartupDataBase()		StartChildProcess(StartupProcess)
 #define StartBackgroundWriter() StartChildProcess(BgWriterProcess)
 #define StartWalWriter()		StartChildProcess(WalWriterProcess)
@@ -1142,7 +1146,7 @@ checkDataDir(void)
 	 *
 	 * XXX can we safely enable this check on Windows?
 	 */
-#if !defined(WIN32) && !defined(__CYGWIN__)
+#ifndef WIN32
 	if (stat_buf.st_uid != geteuid())
 		ereport(FATAL,
 				(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
@@ -1164,7 +1168,7 @@ checkDataDir(void)
 	 * be proper support for Unix-y file permissions.  Need to think of a
 	 * reasonable check to apply on Windows.
 	 */
-#if !defined(WIN32) && !defined(__CYGWIN__)
+#ifndef WIN32
 	if (stat_buf.st_mode & (S_IRWXG | S_IRWXO))
 		ereport(FATAL,
 				(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
--- origsrc/postgresql-8.4.0/src/include/libpq/libpq-be.h	2009-06-11 16:49:11.000000000 +0200
+++ src/postgresql-8.4.0/src/include/libpq/libpq-be.h	2009-07-02 09:12:54.203125000 +0200
@@ -47,6 +47,9 @@
 
 #ifdef ENABLE_SSPI
 #define SECURITY_WIN32
+#ifdef __CYGWIN__
+#include <windows.h>
+#endif
 #if defined(WIN32) && !defined(WIN32_ONLY_COMPILER)
 #include <ntsecapi.h>
 #endif
--- origsrc/postgresql-8.4.0/src/include/libpq/libpq.h	2009-01-01 18:23:59.000000000 +0100
+++ src/postgresql-8.4.0/src/include/libpq/libpq.h	2009-07-02 09:02:26.703125000 +0200
@@ -20,6 +20,10 @@
 #include "lib/stringinfo.h"
 #include "libpq/libpq-be.h"
 
+#ifdef __CYGWIN__
+#undef WIN32
+#endif
+
 /* ----------------
  * PQArgBlock
  *		Information (pointer to array of this structure) required
--- origsrc/postgresql-8.4.0/src/include/miscadmin.h	2009-06-11 16:49:08.000000000 +0200
+++ src/postgresql-8.4.0/src/include/miscadmin.h	2009-07-02 09:02:26.765625000 +0200
@@ -78,7 +78,7 @@ extern PGDLLIMPORT volatile uint32 CritS
 /* in tcop/postgres.c */
 extern void ProcessInterrupts(void);
 
-#ifndef WIN32
+#if !defined(WIN32) || defined(__CYGWIN__)
 
 #define CHECK_FOR_INTERRUPTS() \
 do { \
--- origsrc/postgresql-8.4.0/src/include/port/cygwin.h	2007-07-25 14:22:53.000000000 +0200
+++ src/postgresql-8.4.0/src/include/port/cygwin.h	2009-07-02 09:02:26.843750000 +0200
@@ -19,3 +19,10 @@
 #define PGDLLIMPORT __declspec (dllimport)
 
 #endif
+
+/*
+ * Always build with SSPI support. Keep it as a #define in case
+ * we want a switch to disable it sometime in the future.
+ */
+#define ENABLE_SSPI 1
+
--- origsrc/postgresql-8.4.0/src/interfaces/libpq/Makefile	2009-01-05 10:27:19.000000000 +0100
+++ src/postgresql-8.4.0/src/interfaces/libpq/Makefile	2009-07-20 13:18:59.296875000 +0200
@@ -63,6 +63,9 @@ endif
 ifeq ($(PORTNAME), win32)
 SHLIB_LINK += -lshfolder -lwsock32 -lws2_32 -lsecur32 $(filter -leay32 -lssleay32 -lcomerr32 -lkrb5_32, $(LIBS))
 endif
+ifeq ($(PORTNAME), cygwin)
+SHLIB_LINK += -lsecur32
+endif
 
 SHLIB_EXPORTS = exports.txt
 
--- origsrc/postgresql-8.4.0/src/interfaces/libpq/fe-connect.c	2009-06-11 16:49:13.000000000 +0200
+++ src/postgresql-8.4.0/src/interfaces/libpq/fe-connect.c	2009-07-20 13:14:11.218750000 +0200
@@ -22,12 +22,16 @@
 #include <time.h>
 #include <unistd.h>
 
+#ifdef __CYGWIN__
+#undef WIN32
+#endif
+
 #include "libpq-fe.h"
 #include "libpq-int.h"
 #include "fe-auth.h"
 #include "pg_config_paths.h"
 
-#ifdef WIN32
+#if defined(WIN32) && !defined(__CYGWIN__)
 #include "win32.h"
 #ifdef _WIN32_IE
 #undef _WIN32_IE
--- origsrc/postgresql-8.4.0/src/interfaces/libpq/libpq-int.h	2009-06-23 20:13:23.000000000 +0200
+++ src/postgresql-8.4.0/src/interfaces/libpq/libpq-int.h	2009-07-20 13:17:36.984375000 +0200
@@ -54,6 +54,22 @@
 #endif
 
 #ifdef ENABLE_SSPI
+#ifdef __CYGWIN__
+#include <windows.h>
+#undef WIN32
+int PASCAL WSAGetLastError(void);
+#define WSADESCRIPTION_LEN	256
+#define WSASYS_STATUS_LEN	128
+typedef struct WSAData {
+	WORD	wVersion;
+	WORD	wHighVersion;
+	char	szDescription[WSADESCRIPTION_LEN+1];
+	char	szSystemStatus[WSASYS_STATUS_LEN+1];
+	unsigned short	iMaxSockets;
+	unsigned short	iMaxUdpDg;
+	char * 	lpVendorInfo;
+} WSADATA;
+#endif
 #define SECURITY_WIN32
 #if defined(WIN32) && !defined(WIN32_ONLY_COMPILER)
 #include <ntsecapi.h>
@@ -586,7 +602,7 @@ __attribute__((format_arg(1)));
  * These macros are needed to let error-handling code be portable between
  * Unix and Windows.  (ugh)
  */
-#ifdef WIN32
+#if defined(WIN32) && !defined(__CYGWIN__)
 #define SOCK_ERRNO (WSAGetLastError())
 #define SOCK_STRERROR winsock_strerror
 #define SOCK_ERRNO_SET(e) WSASetLastError(e)
#2Magnus Hagander
magnus@hagander.net
In reply to: Reini Urban (#1)
Re: Enable SSPI on cygwin

On Fri, Jul 24, 2009 at 23:47, Reini Urban<rurban@x-ray.at> wrote:

Attached is my patch to enable SSPI on cygwin.

Is it really such a good idea to keep doing #define WIN32 and #undef
WIN32 in multiple places? It seems very fragile to me - we should keep
the defines for cygwin and win32 separate. Even if that means that the
patch changes a bunch of places into (win32 or cygwin). Either that,
or we need to declare a global define somewhere that is
WIN32_OR_CYGWIN. Doing it this way makes it much harder to spot what
the defines actually mean.

IIRC, we discussed that before, and came to a similar conclusion, but
I could be wrong.

--
Magnus Hagander
Self: http://www.hagander.net/
Work: http://www.redpill-linpro.com/

#3Andrew Dunstan
andrew@dunslane.net
In reply to: Reini Urban (#1)
Re: Enable SSPI on cygwin

Reini,

the style of this patch has previously been criticized by both Magnus
and me.

We do not define WIN32 *anywhere* in our sources, and we don't want to
start. In fact, IIRC we carefully removed all such code years ago,
because it caused us lots of grief.

Please find a way to code your patch that doesn't involve defining and
undefining WIN32.

cheers

andrew

Reini Urban wrote:

Show quoted text

Attached is my patch to enable SSPI on cygwin.

------------------------------------------------------------------------

--- origsrc/postgresql-8.4.0/configure.in	2009-06-27 02:14:47.000000000 +0200
+++ src/postgresql-8.4.0/configure.in	2009-07-02 09:02:25.921875000 +0200
@@ -907,7 +907,11 @@ if test "$with_gssapi" = yes ; then
AC_SEARCH_LIBS(gss_init_sec_context, [gssapi_krb5 gss 'gssapi -lkrb5 -lcrypto'], [],
[AC_MSG_ERROR([could not find function 'gss_init_sec_context' required for GSSAPI])])
else
-    LIBS="$LIBS -lgssapi32"
+    if test "$PORTNAME" = "cygwin"; then
+      LIBS="$LIBS -lsecur32"
+    else
+      LIBS="$LIBS -lgssapi32"
+    fi
fi
fi
--- origsrc/postgresql-8.4.0/src/backend/libpq/auth.c	2009-06-25 13:30:08.000000000 +0200
+++ src/postgresql-8.4.0/src/backend/libpq/auth.c	2009-07-02 09:07:55.937500000 +0200
@@ -159,6 +159,9 @@ static krb5_principal pg_krb5_server;
*----------------------------------------------------------------
*/
#ifdef ENABLE_GSS
+#ifdef __CYGWIN__
+#define WIN32
+#endif
#if defined(HAVE_GSSAPI_H)
#include <gssapi.h>
#else
--- origsrc/postgresql-8.4.0/src/backend/postmaster/postmaster.c	2009-06-26 22:29:04.000000000 +0200
+++ src/postgresql-8.4.0/src/backend/postmaster/postmaster.c	2009-07-02 09:02:26.421875000 +0200
@@ -371,6 +371,9 @@ typedef struct
HANDLE		PostmasterHandle;
#endif
+#endif
+#ifdef EXEC_BACKEND
+
static pid_t backend_forkexec(Port *port);
static pid_t internal_forkexec(int argc, char *argv[], Port *port);

@@ -442,6 +445,7 @@ static void ShmemBackendArrayAdd(Backend
static void ShmemBackendArrayRemove(Backend *bn);
#endif /* EXEC_BACKEND */

+
#define StartupDataBase()		StartChildProcess(StartupProcess)
#define StartBackgroundWriter() StartChildProcess(BgWriterProcess)
#define StartWalWriter()		StartChildProcess(WalWriterProcess)
@@ -1142,7 +1146,7 @@ checkDataDir(void)
*
* XXX can we safely enable this check on Windows?
*/
-#if !defined(WIN32) && !defined(__CYGWIN__)
+#ifndef WIN32
if (stat_buf.st_uid != geteuid())
ereport(FATAL,
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
@@ -1164,7 +1168,7 @@ checkDataDir(void)
* be proper support for Unix-y file permissions.  Need to think of a
* reasonable check to apply on Windows.
*/
-#if !defined(WIN32) && !defined(__CYGWIN__)
+#ifndef WIN32
if (stat_buf.st_mode & (S_IRWXG | S_IRWXO))
ereport(FATAL,
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
--- origsrc/postgresql-8.4.0/src/include/libpq/libpq-be.h	2009-06-11 16:49:11.000000000 +0200
+++ src/postgresql-8.4.0/src/include/libpq/libpq-be.h	2009-07-02 09:12:54.203125000 +0200
@@ -47,6 +47,9 @@
#ifdef ENABLE_SSPI
#define SECURITY_WIN32
+#ifdef __CYGWIN__
+#include <windows.h>
+#endif
#if defined(WIN32) && !defined(WIN32_ONLY_COMPILER)
#include <ntsecapi.h>
#endif
--- origsrc/postgresql-8.4.0/src/include/libpq/libpq.h	2009-01-01 18:23:59.000000000 +0100
+++ src/postgresql-8.4.0/src/include/libpq/libpq.h	2009-07-02 09:02:26.703125000 +0200
@@ -20,6 +20,10 @@
#include "lib/stringinfo.h"
#include "libpq/libpq-be.h"
+#ifdef __CYGWIN__
+#undef WIN32
+#endif
+
/* ----------------
* PQArgBlock
*		Information (pointer to array of this structure) required
--- origsrc/postgresql-8.4.0/src/include/miscadmin.h	2009-06-11 16:49:08.000000000 +0200
+++ src/postgresql-8.4.0/src/include/miscadmin.h	2009-07-02 09:02:26.765625000 +0200
@@ -78,7 +78,7 @@ extern PGDLLIMPORT volatile uint32 CritS
/* in tcop/postgres.c */
extern void ProcessInterrupts(void);
-#ifndef WIN32
+#if !defined(WIN32) || defined(__CYGWIN__)
#define CHECK_FOR_INTERRUPTS() \
do { \
--- origsrc/postgresql-8.4.0/src/include/port/cygwin.h	2007-07-25 14:22:53.000000000 +0200
+++ src/postgresql-8.4.0/src/include/port/cygwin.h	2009-07-02 09:02:26.843750000 +0200
@@ -19,3 +19,10 @@
#define PGDLLIMPORT __declspec (dllimport)
#endif
+
+/*
+ * Always build with SSPI support. Keep it as a #define in case
+ * we want a switch to disable it sometime in the future.
+ */
+#define ENABLE_SSPI 1
+
--- origsrc/postgresql-8.4.0/src/interfaces/libpq/Makefile	2009-01-05 10:27:19.000000000 +0100
+++ src/postgresql-8.4.0/src/interfaces/libpq/Makefile	2009-07-20 13:18:59.296875000 +0200
@@ -63,6 +63,9 @@ endif
ifeq ($(PORTNAME), win32)
SHLIB_LINK += -lshfolder -lwsock32 -lws2_32 -lsecur32 $(filter -leay32 -lssleay32 -lcomerr32 -lkrb5_32, $(LIBS))
endif
+ifeq ($(PORTNAME), cygwin)
+SHLIB_LINK += -lsecur32
+endif

SHLIB_EXPORTS = exports.txt

--- origsrc/postgresql-8.4.0/src/interfaces/libpq/fe-connect.c	2009-06-11 16:49:13.000000000 +0200
+++ src/postgresql-8.4.0/src/interfaces/libpq/fe-connect.c	2009-07-20 13:14:11.218750000 +0200
@@ -22,12 +22,16 @@
#include <time.h>
#include <unistd.h>
+#ifdef __CYGWIN__
+#undef WIN32
+#endif
+
#include "libpq-fe.h"
#include "libpq-int.h"
#include "fe-auth.h"
#include "pg_config_paths.h"
-#ifdef WIN32
+#if defined(WIN32) && !defined(__CYGWIN__)
#include "win32.h"
#ifdef _WIN32_IE
#undef _WIN32_IE
--- origsrc/postgresql-8.4.0/src/interfaces/libpq/libpq-int.h	2009-06-23 20:13:23.000000000 +0200
+++ src/postgresql-8.4.0/src/interfaces/libpq/libpq-int.h	2009-07-20 13:17:36.984375000 +0200
@@ -54,6 +54,22 @@
#endif
#ifdef ENABLE_SSPI
+#ifdef __CYGWIN__
+#include <windows.h>
+#undef WIN32
+int PASCAL WSAGetLastError(void);
+#define WSADESCRIPTION_LEN	256
+#define WSASYS_STATUS_LEN	128
+typedef struct WSAData {
+	WORD	wVersion;
+	WORD	wHighVersion;
+	char	szDescription[WSADESCRIPTION_LEN+1];
+	char	szSystemStatus[WSASYS_STATUS_LEN+1];
+	unsigned short	iMaxSockets;
+	unsigned short	iMaxUdpDg;
+	char * 	lpVendorInfo;
+} WSADATA;
+#endif
#define SECURITY_WIN32
#if defined(WIN32) && !defined(WIN32_ONLY_COMPILER)
#include <ntsecapi.h>
@@ -586,7 +602,7 @@ __attribute__((format_arg(1)));
* These macros are needed to let error-handling code be portable between
* Unix and Windows.  (ugh)
*/
-#ifdef WIN32
+#if defined(WIN32) && !defined(__CYGWIN__)
#define SOCK_ERRNO (WSAGetLastError())
#define SOCK_STRERROR winsock_strerror
#define SOCK_ERRNO_SET(e) WSASetLastError(e)

------------------------------------------------------------------------