Skip to content

Commit 875c7d7

Browse files
committed
libpq should expose GSS-related parameters even when not implemented.
We realized years ago that it's better for libpq to accept all connection parameters syntactically, even if some are ignored or restricted due to lack of the feature in a particular build. However, that lesson from the SSL support was for some reason never applied to the GSSAPI support. This is causing various buildfarm members to have problems with a test case added by commit 6136e94, and it's just a bad idea from a user-experience standpoint anyway, so fix it. While at it, fix some places where parameter-related infrastructure was added with the aid of a dartboard, or perhaps with the aid of the anti-pattern "add new stuff at the end". It should be safe to rearrange the contents of struct pg_conn even in released branches, since that's private to libpq (and we'd have to move some fields in some builds to fix this, anyway). Back-patch to all supported branches. Discussion: https://postgr.es/m/11297.1576868677@sss.pgh.pa.us
1 parent 298d056 commit 875c7d7

File tree

5 files changed

+21
-31
lines changed

5 files changed

+21
-31
lines changed

contrib/postgres_fdw/expected/postgres_fdw.out

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ ALTER FOREIGN TABLE ft2 DROP COLUMN cx;
7575
-- ===================================================================
7676
-- tests for validator
7777
-- ===================================================================
78-
-- requiressl, krbsrvname and gsslib are omitted because they depend on
79-
-- configure options
78+
-- requiressl and some other parameters are omitted because
79+
-- valid values for them depend on configure options
8080
ALTER SERVER testserver1 OPTIONS (
8181
use_remote_estimate 'false',
8282
updatable 'true',
@@ -100,10 +100,10 @@ ALTER SERVER testserver1 OPTIONS (
100100
sslcert 'value',
101101
sslkey 'value',
102102
sslrootcert 'value',
103-
sslcrl 'value'
103+
sslcrl 'value',
104104
--requirepeer 'value',
105-
-- krbsrvname 'value',
106-
-- gsslib 'value',
105+
krbsrvname 'value',
106+
gsslib 'value'
107107
--replication 'value'
108108
);
109109
ALTER USER MAPPING FOR public SERVER testserver1

contrib/postgres_fdw/sql/postgres_fdw.sql

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ ALTER FOREIGN TABLE ft2 DROP COLUMN cx;
8484
-- ===================================================================
8585
-- tests for validator
8686
-- ===================================================================
87-
-- requiressl, krbsrvname and gsslib are omitted because they depend on
88-
-- configure options
87+
-- requiressl and some other parameters are omitted because
88+
-- valid values for them depend on configure options
8989
ALTER SERVER testserver1 OPTIONS (
9090
use_remote_estimate 'false',
9191
updatable 'true',
@@ -109,10 +109,10 @@ ALTER SERVER testserver1 OPTIONS (
109109
sslcert 'value',
110110
sslkey 'value',
111111
sslrootcert 'value',
112-
sslcrl 'value'
112+
sslcrl 'value',
113113
--requirepeer 'value',
114-
-- krbsrvname 'value',
115-
-- gsslib 'value',
114+
krbsrvname 'value',
115+
gsslib 'value'
116116
--replication 'value'
117117
);
118118
ALTER USER MAPPING FOR public SERVER testserver1

doc/src/sgml/libpq.sgml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,8 +1363,10 @@ postgresql://%2Fvar%2Flib%2Fpostgresql/dbname
13631363
<term><literal>gsslib</literal></term>
13641364
<listitem>
13651365
<para>
1366-
GSS library to use for GSSAPI authentication. Only used on Windows.
1367-
Set to <literal>gssapi</literal> to force libpq to use the GSSAPI
1366+
GSS library to use for GSSAPI authentication.
1367+
Currently this is disregarded except on Windows builds that include
1368+
both GSSAPI and SSPI support. In that case, set
1369+
this to <literal>gssapi</literal> to cause libpq to use the GSSAPI
13681370
library for authentication instead of the default SSPI.
13691371
</para>
13701372
</listitem>

src/interfaces/libpq/fe-connect.c

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -297,23 +297,19 @@ static const internalPQconninfoOption PQconninfoOptions[] = {
297297
"Require-Peer", "", 10,
298298
offsetof(struct pg_conn, requirepeer)},
299299

300-
#if defined(ENABLE_GSS) || defined(ENABLE_SSPI)
300+
/*
301+
* As with SSL, all GSS options are exposed even in builds that don't have
302+
* support.
303+
*/
304+
301305
/* Kerberos and GSSAPI authentication support specifying the service name */
302306
{"krbsrvname", "PGKRBSRVNAME", PG_KRB_SRVNAM, NULL,
303307
"Kerberos-service-name", "", 20,
304308
offsetof(struct pg_conn, krbsrvname)},
305-
#endif
306-
307-
#if defined(ENABLE_GSS) && defined(ENABLE_SSPI)
308309

309-
/*
310-
* GSSAPI and SSPI both enabled, give a way to override which is used by
311-
* default
312-
*/
313310
{"gsslib", "PGGSSLIB", NULL, NULL,
314311
"GSS-library", "", 7, /* sizeof("gssapi") = 7 */
315312
offsetof(struct pg_conn, gsslib)},
316-
#endif
317313

318314
{"replication", NULL, NULL, NULL,
319315
"Replication", "D", 5,
@@ -3063,14 +3059,10 @@ freePGconn(PGconn *conn)
30633059
free(conn->sslcompression);
30643060
if (conn->requirepeer)
30653061
free(conn->requirepeer);
3066-
#if defined(ENABLE_GSS) || defined(ENABLE_SSPI)
30673062
if (conn->krbsrvname)
30683063
free(conn->krbsrvname);
3069-
#endif
3070-
#if defined(ENABLE_GSS) && defined(ENABLE_SSPI)
30713064
if (conn->gsslib)
30723065
free(conn->gsslib);
3073-
#endif
30743066
/* Note that conn->Pfdebug is not ours to close or free */
30753067
if (conn->last_query)
30763068
free(conn->last_query);

src/interfaces/libpq/libpq-int.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -330,10 +330,9 @@ struct pg_conn
330330
char *sslrootcert; /* root certificate filename */
331331
char *sslcrl; /* certificate revocation list filename */
332332
char *requirepeer; /* required peer credentials for local sockets */
333-
334-
#if defined(ENABLE_GSS) || defined(ENABLE_SSPI)
335333
char *krbsrvname; /* Kerberos service name */
336-
#endif
334+
char *gsslib; /* What GSS library to use ("gssapi" or
335+
* "sspi") */
337336

338337
/* Optional file to write trace info to */
339338
FILE *Pfdebug;
@@ -449,9 +448,6 @@ struct pg_conn
449448
#ifdef ENABLE_SSPI
450449
#ifndef ENABLE_GSS
451450
gss_buffer_desc ginbuf; /* GSS input token */
452-
#else
453-
char *gsslib; /* What GSS librart to use ("gssapi" or
454-
* "sspi") */
455451
#endif
456452
CredHandle *sspicred; /* SSPI credentials handle */
457453
CtxtHandle *sspictx; /* SSPI context */

0 commit comments

Comments
 (0)