8000 Make it possible, and default, for MingW to build with SSPI support · postgres/postgres@d602592 · GitHub
[go: up one dir, main page]

Skip to content
< 8000 /react-partial>

Commit d602592

Browse files
committed
Make it possible, and default, for MingW to build with SSPI support
by dynamically loading the function that's missing from the MingW headers and library.
1 parent ad42957 commit d602592

File tree

6 files changed

+53
-14
lines changed

6 files changed

+53
-14
lines changed

src/backend/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55
# Copyright (c) 1994, Regents of the University of California
66
#
7-
# $PostgreSQL: pgsql/src/backend/Makefile,v 1.122 2007/02/09 15:55:57 petere Exp $
7+
# $PostgreSQL: pgsql/src/backend/Makefile,v 1.123 2007/07/24 09:00:27 mha Exp $
88
#
99
#-------------------------------------------------------------------------
1010

@@ -64,6 +64,7 @@ libpostgres.a: postgres.def
6464
endif # cygwin
6565

6666
ifeq ($(PORTNAME), win32)
67+
LIBS += -lsecur32
6768

6869
postgres: $(OBJS) postgres.def libpostgres.a $(WIN32RES)
6970
$(DLLTOOL) --dllname $@$(X) --output-exp $@.exp --def postgres.def

src/backend/libpq/auth.c

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/libpq/auth.c,v 1.154 2007/07/23 10:16:53 mha Exp $
11+
* $PostgreSQL: pgsql/src/backend/libpq/auth.c,v 1.155 2007/07/24 09:00:27 mha Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -560,13 +560,16 @@ pg_SSPI_error(int severity, char *errmsg, SECURITY_STATUS r)
560560
if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, r, 0, sysmsg, sizeof(sysmsg), NULL) == 0)
561561
ereport(severity,
562562
(errmsg_internal("%s", errmsg),
563-
errdetail("sspi error %x", r)));
563+
errdetail("sspi error %x", (unsigned int)r)));
564564
else
565565
ereport(severity,
566566
(errmsg_internal("%s", errmsg),
567-
errdetail("%s (%x)", sysmsg, r)));
567+
errdetail("%s (%x)", sysmsg, (unsigned int)r)));
568568
}
569569

570+
typedef SECURITY_STATUS
571+
(WINAPI * QUERY_SECURITY_CONTEXT_TOKEN_FN)(
572+
PCtxtHandle, void **);
570573

571574
static int
572575
pg_SSPI_recvauth(Port *port)
@@ -591,6 +594,8 @@ pg_SSPI_recvauth(Port *port)
591594
DWORD accountnamesize = sizeof(accountname);
592595
DWORD domainnamesize = sizeof(domainname);
593596
SID_NAME_USE accountnameuse;
597+
HMODULE secur32;
598+
QUERY_SECURITY_CONTEXT_TOKEN_FN _QuerySecurityContextToken;
594599

595600

596601
/*
@@ -726,12 +731,36 @@ pg_SSPI_recvauth(Port *port)
726731
*
727732
* Get the name of the user that authenticated, and compare it to the
728733
* pg username that was specified for the connection.
734+
*
735+
* MingW is missing the export for QuerySecurityContextToken in
736+
* the secur32 library, so we have to load it dynamically.
729737
*/
730738

731-
r = QuerySecurityContextToken(sspictx, &token);
739+
secur32 = LoadLibrary("SECUR32.DLL");
740+
if (secur32 == NULL)
741+
ereport(ERROR,
742+
(errmsg_internal("could not load secur32.dll: %d",
743+
(int)GetLastError())));
744+
745+
_QuerySecurityContextToken = (QUERY_SECURITY_CONTEXT_TOKEN_FN)
746+
GetProcAddress(secur32, "QuerySecurityContextToken");
747+
if (_QuerySecurityContextToken == NULL)
748+
{
749+
FreeLibrary(secur32);
750+
ereport(ERROR,
751+
(errmsg_internal("could not locate QuerySecurityContextToken in secur32.dll: %d",
752+
(int)GetLastError())));
753+
}
754+
755+
r = (_QuerySecurityContextToken)(sspictx, &token);
732756
if (r != SEC_E_OK)
757+
{
758+
FreeLibrary(secur32);
733759
pg_SSPI_error(ERROR,
734760
gettext_noop("could not get security token from context"), r);
761+
}
762+
763+
FreeLibrary(secur32);
735764

736765
/*
737766
* No longer need the security context, everything from here on uses the

src/include/port/win32.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1-
/* $PostgreSQL: pgsql/src/include/port/win32.h,v 1.74 2007/04/06 05:36:51 tgl Exp $ */
1+
/* $PostgreSQL: pgsql/src/include/port/win32.h,v 1.75 2007/07/24 09:00:27 mha Exp $ */
22

33
#if defined(_MSC_VER) || defined(__BORLANDC__)
44
#define WIN32_ONLY_COMPILER
55
#endif
66

7+
/*
8+
* Always build with SSPI support. Keep it as a #define in case
9+
* we want a switch to disable it sometime in the future.
10+
*/
11+
#define ENABLE_SSPI 1
12+
13+
714
/* undefine and redefine after #include */
815
#undef mkdir
916

src/interfaces/libpq/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
66
# Portions Copyright (c) 1994, Regents of the University of California
77
#
8-
# $PostgreSQL: pgsql/src/interfaces/libpq/Makefile,v 1.155 2007/07/10 13:14:21 mha Exp $
8+
# $PostgreSQL: pgsql/src/interfaces/libpq/Makefile,v 1.156 2007/07/24 09:00:27 mha Exp $
99
#
1010
#-------------------------------------------------------------------------
1111

@@ -62,7 +62,7 @@ else
6262
SHLIB_LINK += $(filter -lcrypt -ldes -lcom_err -lcrypto -lk5crypto -lkrb5 -lgssapi32 -lssl -lsocket -lnsl -lresolv -lintl $(PTHREAD_LIBS), $(LIBS)) $(LDAP_LIBS_FE)
6363
endif
6464
ifeq ($(PORTNAME), win32)
65-
SHLIB_LINK += -lshfolder -lwsock32 -lws2_32 $(filter -leay32 -lssleay32 -lcomerr32 -lkrb5_32, $(LIBS))
65+
SHLIB_LINK += -lshfolder -lwsock32 -lws2_32 -lsecur32 $(filter -leay32 -lssleay32 -lcomerr32 -lkrb5_32, $(LIBS))
6666
endif
6767

6868

src/interfaces/libpq/fe-auth.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
99
* IDENTIFICATION
10-
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-auth.c,v 1.130 2007/07/23 17:52:06 mha Exp $
10+
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-auth.c,v 1.131 2007/07/24 09:00:27 mha Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -511,10 +511,13 @@ pg_SSPI_error(PGconn *conn, char *mprefix, SECURITY_STATUS r)
511511
{
512512
char sysmsg[256];
513513

514-
if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, r, 0, sysmsg, sizeof(sysmsg), NULL) == 0)
515-
printfPQExpBuffer(&conn->errorMessage, "%s: sspi error %x", mprefix, r);
514+
if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, r, 0,
515+
sysmsg, sizeof(sysmsg), NULL) == 0)
516+
printfPQExpBuffer(&conn->errorMessage, "%s: sspi error %x",
517+
mprefix, (unsigned int)r);
516518
else
517-
printfPQExpBuffer(&conn->errorMessage, "%s: %s (%x)", mprefix, sysmsg, r);
519+
printfPQExpBuffer(&conn->errorMessage, "%s: %s (%x)",
520+
mprefix, sysmsg, (unsigned int)r);
518521
}
519522

520523
/*

src/tools/msvc/Solution.pm

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package Solution;
33
#
44
# Package that encapsulates a Visual C++ solution file generation
55
#
6-
# $PostgreSQL: pgsql/src/tools/msvc/Solution.pm,v 1.30 2007/07/23 10:16:54 mha Exp $
6+
# $PostgreSQL: pgsql/src/tools/msvc/Solution.pm,v 1.31 2007/07/24 09:00:27 mha Exp $
77
#
88
use Carp;
99
use strict;
@@ -126,7 +126,6 @@ s{PG_VERSION_STR "[^"]+"}{__STRINGIFY(x) #x\n#define __STRINGIFY2(z) __STRINGIFY
126126
print O "#define HAVE_KRB5_FREE_UNPARSED_NAME 1\n";
127127
print O "#define ENABLE_GSS 1\n";
128128
}
129-
print O "#define ENABLE_SSPI 1\n";
130129
if (my $port = $self->{options}->{"--with-pgport"})
131130
{
132131
print O "#undef DEF_PGPORT\n";

0 commit comments

Comments
 (0)
0