libpq should expose GSS-related parameters even when not implemented.
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 20 Dec 2019 20:34:08 +0000 (15:34 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 20 Dec 2019 20:34:08 +0000 (15:34 -0500)
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 6136e94dc,
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

contrib/postgres_fdw/expected/postgres_fdw.out
contrib/postgres_fdw/sql/postgres_fdw.sql
doc/src/sgml/libpq.sgml
src/interfaces/libpq/fe-connect.c
src/interfaces/libpq/libpq-int.h

index 01f11487ef2e7a2c58eed7932dcf15fe828bf84d..3db68ffa44cfb8521559885504b0ed85e9bbae5b 100644 (file)
@@ -139,8 +139,8 @@ ALTER TABLE ft_pg_type SET WITH OIDS;
 -- ===================================================================
 -- tests for validator
 -- ===================================================================
--- requiressl, krbsrvname and gsslib are omitted because they depend on
--- configure options
+-- requiressl and some other parameters are omitted because
+-- valid values for them depend on configure options
 ALTER SERVER testserver1 OPTIONS (
    use_remote_estimate 'false',
    updatable 'true',
@@ -164,10 +164,10 @@ ALTER SERVER testserver1 OPTIONS (
    sslcert 'value',
    sslkey 'value',
    sslrootcert 'value',
-   sslcrl 'value'
+   sslcrl 'value',
    --requirepeer 'value',
-   -- krbsrvname 'value',
-   -- gsslib 'value',
+   krbsrvname 'value',
+   gsslib 'value'
    --replication 'value'
 );
 -- Error, invalid list syntax
index a87c57df7bf08d7ad732f020fc31112d10959648..e659704ef07f35776e9c93083937f6768c66cb34 100644 (file)
@@ -153,8 +153,8 @@ ALTER TABLE ft_pg_type SET WITH OIDS;
 -- ===================================================================
 -- tests for validator
 -- ===================================================================
--- requiressl, krbsrvname and gsslib are omitted because they depend on
--- configure options
+-- requiressl and some other parameters are omitted because
+-- valid values for them depend on configure options
 ALTER SERVER testserver1 OPTIONS (
    use_remote_estimate 'false',
    updatable 'true',
@@ -178,10 +178,10 @@ ALTER SERVER testserver1 OPTIONS (
    sslcert 'value',
    sslkey 'value',
    sslrootcert 'value',
-   sslcrl 'value'
+   sslcrl 'value',
    --requirepeer 'value',
-   -- krbsrvname 'value',
-   -- gsslib 'value',
+   krbsrvname 'value',
+   gsslib 'value'
    --replication 'value'
 );
 
index b1ab3f8e64ebf5e1cdf59bc8a6d9e3a2d8f1f376..ee3b4e7435f3595ec3d6d48ed1551bccb8a056d2 100644 (file)
@@ -1554,8 +1554,10 @@ postgresql://%2Fvar%2Flib%2Fpostgresql/dbname
       <term><literal>gsslib</literal></term>
       <listitem>
        <para>
-        GSS library to use for GSSAPI authentication. Only used on Windows.
-        Set to <literal>gssapi</literal> to force libpq to use the GSSAPI
+        GSS library to use for GSSAPI authentication.
+        Currently this is disregarded except on Windows builds that include
+        both GSSAPI and SSPI support.  In that case, set
+        this to <literal>gssapi</literal> to cause libpq to use the GSSAPI
         library for authentication instead of the default SSPI.
        </para>
       </listitem>
index b93ed7662b616e34d573e5220944a2a61c2e93f3..c8ea59e5a2aabcf2d5ec8efb2c1ab88740b5b3e6 100644 (file)
@@ -297,23 +297,19 @@ static const internalPQconninfoOption PQconninfoOptions[] = {
        "Require-Peer", "", 10,
    offsetof(struct pg_conn, requirepeer)},
 
-#if defined(ENABLE_GSS) || defined(ENABLE_SSPI)
+   /*
+    * As with SSL, all GSS options are exposed even in builds that don't have
+    * support.
+    */
+
    /* Kerberos and GSSAPI authentication support specifying the service name */
    {"krbsrvname", "PGKRBSRVNAME", PG_KRB_SRVNAM, NULL,
        "Kerberos-service-name", "", 20,
    offsetof(struct pg_conn, krbsrvname)},
-#endif
-
-#if defined(ENABLE_GSS) && defined(ENABLE_SSPI)
 
-   /*
-    * GSSAPI and SSPI both enabled, give a way to override which is used by
-    * default
-    */
    {"gsslib", "PGGSSLIB", NULL, NULL,
        "GSS-library", "", 7,   /* sizeof("gssapi") = 7 */
    offsetof(struct pg_conn, gsslib)},
-#endif
 
    {"replication", NULL, NULL, NULL,
        "Replication", "D", 5,
@@ -3606,14 +3602,10 @@ freePGconn(PGconn *conn)
        free(conn->sslcompression);
    if (conn->requirepeer)
        free(conn->requirepeer);
-#if defined(ENABLE_GSS) || defined(ENABLE_SSPI)
    if (conn->krbsrvname)
        free(conn->krbsrvname);
-#endif
-#if defined(ENABLE_GSS) && defined(ENABLE_SSPI)
    if (conn->gsslib)
        free(conn->gsslib);
-#endif
    /* Note that conn->Pfdebug is not ours to close or free */
    if (conn->last_query)
        free(conn->last_query);
index 4174b6ff17c4d86e1c2f9c253c4ae000636f8a8d..9af7b6e68ce26fcd28ae45cc6ca9f8335191c313 100644 (file)
@@ -357,10 +357,9 @@ struct pg_conn
    char       *sslrootcert;    /* root certificate filename */
    char       *sslcrl;         /* certificate revocation list filename */
    char       *requirepeer;    /* required peer credentials for local sockets */
-
-#if defined(ENABLE_GSS) || defined(ENABLE_SSPI)
    char       *krbsrvname;     /* Kerberos service name */
-#endif
+   char       *gsslib;         /* What GSS library to use ("gssapi" or
+                                * "sspi") */
 
    /* Type of connection to make.  Possible values: any, read-write. */
    char       *target_session_attrs;
@@ -480,10 +479,6 @@ struct pg_conn
 #endif
 
 #ifdef ENABLE_SSPI
-#ifdef ENABLE_GSS
-   char       *gsslib;         /* What GSS library to use ("gssapi" or
-                                * "sspi") */
-#endif
    CredHandle *sspicred;       /* SSPI credentials handle */
    CtxtHandle *sspictx;        /* SSPI context */
    char       *sspitarget;     /* SSPI target name */