Skip to content

Commit e92c063

Browse files
Move GSSAPI includes into its own header
Due to a conflict in macro names on Windows between <wincrypt.h> and <openssl/ssl.h> these headers need to be included using a predictable pattern with an undef to handle that. The GSSAPI header <gssapi.h> does include <wincrypt.h> which cause problems with compiling PostgreSQL using MSVC when OpenSSL and GSSAPI are both enabled in the tree. Rather than fixing piecemeal for each file including gssapi headers, move the the includes and undef to a new file which should be used to centralize the logic. This patch is a reworked version of a patch by Imran Zaheer proposed earlier in the thread. Once this has proven effective in master we should look at backporting this as the problem exist at least since v16. Author: Daniel Gustafsson <daniel@yesql.se> Co-authored-by: Imran Zaheer <imran.zhir@gmail.com> Reported-by: Dave Page <dpage@pgadmin.org> Reviewed-by: Andres Freund <andres@anarazel.de> Reviewed-by: vignesh C <vignesh21@gmail.com> Discussion: https://postgr.es/m/20240708173204.3f3xjilglx5wuzx6@awork3.anarazel.de
1 parent 1eb3993 commit e92c063

File tree

5 files changed

+45
-34
lines changed

5 files changed

+45
-34
lines changed

contrib/sslinfo/sslinfo.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,6 @@
1919
#include "miscadmin.h"
2020
#include "utils/builtins.h"
2121

22-
/*
23-
* On Windows, <wincrypt.h> includes a #define for X509_NAME, which breaks our
24-
* ability to use OpenSSL's version of that symbol if <wincrypt.h> is pulled
25-
* in after <openssl/ssl.h> ... and, at least on some builds, it is. We
26-
* can't reliably fix that by re-ordering #includes, because libpq/libpq-be.h
27-
* #includes <openssl/ssl.h>. Instead, just zap the #define again here.
28-
*/
29-
#ifdef X509_NAME
30-
#undef X509_NAME
31-
#endif
32-
3322
PG_MODULE_MAGIC;
3423

3524
static Datum X509_NAME_field_to_text(X509_NAME *name, text *fieldName);

src/include/libpq/be-gssapi-common.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,7 @@
1616

1717
#ifdef ENABLE_GSS
1818

19-
#if defined(HAVE_GSSAPI_H)
20-
#include <gssapi.h>
21-
#include <gssapi_ext.h>
22-
#else
23-
#include <gssapi/gssapi.h>
24-
#include <gssapi/gssapi_ext.h>
25-
#endif
19+
#include "libpq/pg-gssapi.h"
2620

2721
extern void pg_GSS_error(const char *errmsg,
2822
OM_uint32 maj_stat, OM_uint32 min_stat);

src/include/libpq/libpq-be.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,7 @@
2727
#endif
2828
#include <netinet/tcp.h>
2929

30-
#ifdef ENABLE_GSS
31-
#if defined(HAVE_GSSAPI_H)
32-
#include <gssapi.h>
33-
#else
34-
#include <gssapi/gssapi.h>
35-
#endif /* HAVE_GSSAPI_H */
36-
#endif /* ENABLE_GSS */
30+
#include "libpq/pg-gssapi.h"
3731

3832
#ifdef ENABLE_SSPI
3933
#define SECURITY_WIN32

src/include/libpq/pg-gssapi.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* pg-gssapi.h
4+
* Definitions for including GSSAPI headers
5+
*
6+
* Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
7+
* Portions Copyright (c) 1994, Regents of the University of California
8+
*
9+
* src/include/libpq/pg-gssapi.h
10+
*
11+
*-------------------------------------------------------------------------
12+
*/
13+
14+
#ifndef PG_GSSAPI_H
15+
#define PG_GSSAPI_H
16+
17+
#ifdef ENABLE_GSS
18+
19+
/* IWYU pragma: begin_exports */
20+
#if defined(HAVE_GSSAPI_H)
21+
#include <gssapi.h>
22+
#include <gssapi_ext.h>
23+
#else
24+
#include <gssapi/gssapi.h>
25+
#include <gssapi/gssapi_ext.h>
26+
#endif
27+
/* IWYU pragma: end_exports */
28+
29+
/*
30+
* On Windows, <wincrypt.h> includes a #define for X509_NAME, which breaks our
31+
* ability to use OpenSSL's version of that symbol if <wincrypt.h> is pulled
32+
* in after <openssl/ssl.h> ... and, at least on some builds, it is. We
33+
* can't reliably fix that by re-ordering #includes, because libpq/libpq-be.h
34+
* #includes <openssl/ssl.h>. Instead, just zap the #define again here.
35+
*/
36+
#ifdef X509_NAME
37+
#undef X509_NAME
38+
#endif
39+
40+
#endif /* ENABLE_GSS */
41+
42+
#endif /* PG_GSSAPI_H */

src/interfaces/libpq/libpq-int.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,7 @@
4444
#include "fe-auth-sasl.h"
4545
#include "pqexpbuffer.h"
4646

47-
/* IWYU pragma: begin_exports */
48-
#ifdef ENABLE_GSS
49-
#if defined(HAVE_GSSAPI_H)
50-
#include <gssapi.h>
51-
#else
52-
#include <gssapi/gssapi.h>
53-
#endif
54-
#endif
55-
/* IWYU pragma: end_exports */
47+
#include "libpq/pg-gssapi.h"
5648

5749
#ifdef ENABLE_SSPI
5850
#define SECURITY_WIN32

0 commit comments

Comments
 (0)