authtype parameter in libpq
When looking at disallowing SSL compression I found the parameter "authtype"
which was deprecated in commit d5bbe2aca55bc8 on January 26 1998. While I do
think there is a case to be made for the backwards compatibility having run its
course on this one, shouldn't we at least remove the environment variable and
default compiled fallback for it to save us a getenv call when filling in the
option defaults?
--
Daniel Gustafsson https://vmware.com/
Attachments:
0001-Remove-defaults-from-authtype-parameter.patchapplication/octet-stream; name=0001-Remove-defaults-from-authtype-parameter.patch; x-unix-mode=0644Download
From bf89496b4725a48b6e663e055f2c16f23c1d8e81 Mon Sep 17 00:00:00 2001
From: Daniel Gustafsson <daniel@yesql.se>
Date: Fri, 26 Feb 2021 20:53:39 +0100
Subject: [PATCH] Remove defaults from authtype parameter
The authtype parameter was deprecated and made inactive in commit
d5bbe2aca55bc8, but the environment variable is still defined such
that if it would exist it would be copied but never freed. Fix by
removing the env var and default value.
---
src/interfaces/libpq/fe-connect.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c
index db71fea169..7327d28966 100644
--- a/src/interfaces/libpq/fe-connect.c
+++ b/src/interfaces/libpq/fe-connect.c
@@ -122,7 +122,6 @@ static int ldapServiceLookup(const char *purl, PQconninfoOption *options,
#define DefaultHost "localhost"
#define DefaultTty ""
#define DefaultOption ""
-#define DefaultAuthtype ""
#ifdef USE_SSL
#define DefaultChannelBinding "prefer"
#else
@@ -197,7 +196,7 @@ static const internalPQconninfoOption PQconninfoOptions[] = {
* the array so as not to reject conninfo strings from old apps that might
* still try to set it.
*/
- {"authtype", "PGAUTHTYPE", DefaultAuthtype, NULL,
+ {"authtype", NULL, NULL, NULL,
"Database-Authtype", "D", 20, -1},
{"service", "PGSERVICE", NULL, NULL,
--
2.21.1 (Apple Git-122.3)
On 26.02.21 21:02, Daniel Gustafsson wrote:
When looking at disallowing SSL compression I found the parameter "authtype"
which was deprecated in commit d5bbe2aca55bc8 on January 26 1998. While I do
think there is a case to be made for the backwards compatibility having run its
course on this one, shouldn't we at least remove the environment variable and
default compiled fallback for it to save us a getenv call when filling in the
option defaults?
The argument of avoiding unnecessary getenv() calls is sensible. PGTTY
should get the same treatment.
But I tend to think we should remove them both altogether (modulo ABI
and API preservation).
On 3 Mar 2021, at 14:47, Peter Eisentraut <peter@eisentraut.org> wrote:
On 26.02.21 21:02, Daniel Gustafsson wrote:
When looking at disallowing SSL compression I found the parameter "authtype"
which was deprecated in commit d5bbe2aca55bc8 on January 26 1998. While I do
think there is a case to be made for the backwards compatibility having run its
course on this one, shouldn't we at least remove the environment variable and
default compiled fallback for it to save us a getenv call when filling in the
option defaults?The argument of avoiding unnecessary getenv() calls is sensible. PGTTY should get the same treatment.
The reason I left PGTTY alone is that we still have a way to extract the value
set via PQtty(), so removing one or two ways of setting it while at the same
time allowing the value to be read back seemed inconsistent regardless of its
obsolescence.
authtype is completely dead in terms of reading back the value, to the point of
it being a memleak if it indeed was found in as an environment variable.
But I tend to think we should remove them both altogether (modulo ABI and API preservation).
No disagreement from me, the attached takes a stab at that to get an idea what
it would look like. PQtty is left to maintain API stability but the parameters
are removed from the conn object as thats internal to libpq.
--
Daniel Gustafsson https://vmware.com/
Attachments:
v2-0001-Remove-deprecated-parameters-authtype-and-pqtty.patchapplication/octet-stream; name=v2-0001-Remove-deprecated-parameters-authtype-and-pqtty.patch; x-unix-mode=0644Download
From c0fccb72d9889179083c2abcffa10810f8e2a437 Mon Sep 17 00:00:00 2001
From: Daniel Gustafsson <daniel@yesql.se>
Date: Thu, 4 Mar 2021 15:47:31 +0100
Subject: [PATCH v2] Remove deprecated parameters authtype and pqtty
The authtype parameter was deprecated and made inactive in commit
d5bbe2aca55bc8, but the environment variable was left defined and
thus tested with a getenv call even though the value is of no use.
Also, if it would exist it would be copied but never freed as the
cleanup code had been removed.
pgtty was deprecated in commit cb7fb3ca958ec8bd5a14e7 but most of
the infrastructure around it remained in place.
This removes both parameters completely, making PQtty always return
an empty string for non-NULL conn objects to maintain API stability.
Discussion: https://postgr.es/m/DDDF36F3-582A-4C02-8598-9B464CC42B34@yesql.se
---
doc/src/sgml/libpq.sgml | 14 +++++++++----
src/interfaces/libpq/fe-connect.c | 34 +++++--------------------------
src/interfaces/libpq/libpq-fe.h | 4 ++--
src/interfaces/libpq/libpq-int.h | 2 --
src/test/examples/testlibpq4.c | 8 +++-----
5 files changed, 20 insertions(+), 42 deletions(-)
diff --git a/doc/src/sgml/libpq.sgml b/doc/src/sgml/libpq.sgml
index 0553279314..8fb42f1f38 100644
--- a/doc/src/sgml/libpq.sgml
+++ b/doc/src/sgml/libpq.sgml
@@ -232,6 +232,11 @@ PGconn *PQsetdbLogin(const char *pghost,
if it had been passed to <xref linkend="libpq-PQconnectdb"/>, and the remaining
parameters are then applied as specified for <xref linkend="libpq-PQconnectdbParams"/>.
</para>
+
+ <para>
+ <literal>pgtty</literal> is deprecated and any value passed will be
+ discarded, it remains for backwards compatibility.
+ </para>
</listitem>
</varlistentry>
@@ -2136,10 +2141,11 @@ char *PQport(const PGconn *conn);
<listitem>
<para>
- Returns the debug <acronym>TTY</acronym> of the connection.
- (This is obsolete, since the server no longer pays attention
- to the <acronym>TTY</acronym> setting, but the function remains
- for backward compatibility.)
+ This function is deprecated since the server no longer pays
+ attention to the <acronym>TTY</acronym> setting, but the function
+ remains for backwards compatibility. The function always return an
+ empty string, or <symbol>NULL</symbol> if the
+ <parameter>conn</parameter> argument is <symbol>NULL</symbol>.
<synopsis>
char *PQtty(const PGconn *conn);
diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c
index f83af03d0a..4154105426 100644
--- a/src/interfaces/libpq/fe-connect.c
+++ b/src/interfaces/libpq/fe-connect.c
@@ -120,9 +120,7 @@ static int ldapServiceLookup(const char *purl, PQconninfoOption *options,
* by environment variables
*/
#define DefaultHost "localhost"
-#define DefaultTty ""
#define DefaultOption ""
-#define DefaultAuthtype ""
#ifdef USE_SSL
#define DefaultChannelBinding "prefer"
#else
@@ -192,13 +190,6 @@ typedef struct _internalPQconninfoOption
} internalPQconninfoOption;
static const internalPQconninfoOption PQconninfoOptions[] = {
- /*
- * "authtype" is no longer used, so mark it "don't show". We keep it in
- * the array so as not to reject conninfo strings from old apps that might
- * still try to set it.
- */
- {"authtype", "PGAUTHTYPE", DefaultAuthtype, NULL,
- "Database-Authtype", "D", 20, -1},
{"service", "PGSERVICE", NULL, NULL,
"Database-Service", "", 20, -1},
@@ -243,14 +234,6 @@ static const internalPQconninfoOption PQconninfoOptions[] = {
"Client-Encoding", "", 10,
offsetof(struct pg_conn, client_encoding_initial)},
- /*
- * "tty" is no longer used either, but keep it present for backwards
- * compatibility.
- */
- {"tty", "PGTTY", DefaultTty, NULL,
- "Backend-Debug-TTY", "D", 40,
- offsetof(struct pg_conn, pgtty)},
-
{"options", "PGOPTIONS", DefaultOption, NULL,
"Backend-Options", "", 40,
offsetof(struct pg_conn, pgoptions)},
@@ -1578,15 +1561,6 @@ PQsetdbLogin(const char *pghost, const char *pgport, const char *pgoptions,
goto oom_error;
}
- if (pgtty && pgtty[0] != '\0')
- {
- if (conn->pgtty)
- free(conn->pgtty);
- conn->pgtty = strdup(pgtty);
- if (!conn->pgtty)
- goto oom_error;
- }
-
if (login && login[0] != '\0')
{
if (conn->pguser)
@@ -4028,8 +4002,6 @@ freePGconn(PGconn *conn)
free(conn->pghostaddr);
if (conn->pgport)
free(conn->pgport);
- if (conn->pgtty)
- free(conn->pgtty);
if (conn->connect_timeout)
free(conn->connect_timeout);
if (conn->pgtcp_user_timeout)
@@ -6632,12 +6604,16 @@ PQport(const PGconn *conn)
return "";
}
+/*
+ * The pqtty parameter has been removed, but the function remains for API
+ * backwards compatibility.
+ */
char *
PQtty(const PGconn *conn)
{
if (!conn)
return NULL;
- return conn->pgtty;
+ return "";
}
char *
diff --git a/src/interfaces/libpq/libpq-fe.h b/src/interfaces/libpq/libpq-fe.h
index fa9b62a844..fde2e60888 100644
--- a/src/interfaces/libpq/libpq-fe.h
+++ b/src/interfaces/libpq/libpq-fe.h
@@ -268,8 +268,8 @@ extern PGconn *PQsetdbLogin(const char *pghost, const char *pgport,
const char *dbName,
const char *login, const char *pwd);
-#define PQsetdb(M_PGHOST,M_PGPORT,M_PGOPT,M_PGTTY,M_DBNAME) \
- PQsetdbLogin(M_PGHOST, M_PGPORT, M_PGOPT, M_PGTTY, M_DBNAME, NULL, NULL)
+#define PQsetdb(M_PGHOST,M_PGPORT,M_PGOPT,M_UNUSED,M_DBNAME) \
+ PQsetdbLogin(M_PGHOST, M_PGPORT, M_PGOPT, NULL, M_DBNAME, NULL, NULL)
/* close the current connection and free the PGconn data structure */
extern void PQfinish(PGconn *conn);
diff --git a/src/interfaces/libpq/libpq-int.h b/src/interfaces/libpq/libpq-int.h
index 8d51e6ed9f..adf149a76f 100644
--- a/src/interfaces/libpq/libpq-int.h
+++ b/src/interfaces/libpq/libpq-int.h
@@ -338,8 +338,6 @@ struct pg_conn
* precedence over pghost. */
char *pgport; /* the server's communication port number, or
* a comma-separated list of ports */
- char *pgtty; /* tty on which the backend messages is
- * displayed (OBSOLETE, NOT USED) */
char *connect_timeout; /* connection timeout (numeric string) */
char *pgtcp_user_timeout; /* tcp user timeout (numeric string) */
char *client_encoding_initial; /* encoding to use */
diff --git a/src/test/examples/testlibpq4.c b/src/test/examples/testlibpq4.c
index dd11bbc46d..da4443072d 100644
--- a/src/test/examples/testlibpq4.c
+++ b/src/test/examples/testlibpq4.c
@@ -50,8 +50,7 @@ main(int argc, char **argv)
{
char *pghost,
*pgport,
- *pgoptions,
- *pgtty;
+ *pgoptions;
char *dbName1,
*dbName2;
char *tblName;
@@ -88,13 +87,12 @@ main(int argc, char **argv)
pgport = NULL; /* port of the backend */
pgoptions = NULL; /* special options to start up the backend
* server */
- pgtty = NULL; /* debugging tty for the backend */
/* make a connection to the database */
- conn1 = PQsetdb(pghost, pgport, pgoptions, pgtty, dbName1);
+ conn1 = PQsetdb(pghost, pgport, pgoptions, NULL, dbName1);
check_prepare_conn(conn1, dbName1);
- conn2 = PQsetdb(pghost, pgport, pgoptions, pgtty, dbName2);
+ conn2 = PQsetdb(pghost, pgport, pgoptions, NULL, dbName2);
check_prepare_conn(conn2, dbName2);
/* start a transaction block */
--
2.21.1 (Apple Git-122.3)
On 04.03.21 16:06, Daniel Gustafsson wrote:
authtype is completely dead in terms of reading back the value, to the point of
it being a memleak if it indeed was found in as an environment variable.But I tend to think we should remove them both altogether (modulo ABI and API preservation).
No disagreement from me, the attached takes a stab at that to get an idea what
it would look like. PQtty is left to maintain API stability but the parameters
are removed from the conn object as thats internal to libpq.
This looks like this right idea to me.
On 08.03.21 10:57, Peter Eisentraut wrote:
On 04.03.21 16:06, Daniel Gustafsson wrote:
authtype is completely dead in terms of reading back the value, to the
point of
it being a memleak if it indeed was found in as an environment variable.But I tend to think we should remove them both altogether (modulo ABI
and API preservation).No disagreement from me, the attached takes a stab at that to get an
idea what
it would look like.� PQtty is left to maintain API stability but the
parameters
are removed from the conn object as thats internal to libpq.This looks like this right idea to me.
committed, with some tweaks