Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 4e4f7b9

Browse files
committed
Adjust PQsslAttributeNames() to match PQsslAttribute().
Currently, PQsslAttributeNames() returns the same list of attribute names regardless of its conn parameter. This patch changes it to have behavior parallel to what 80a0567 installed for PQsslAttribute: you get OpenSSL's attributes if conn is NULL or is an SSL-encrypted connection, or an empty list if conn is a non-encrypted connection. The point of this is to have sensible connection-dependent behavior in case we ever support multiple SSL libraries. The behavior for NULL can be defined as "the attributes for the default SSL library", parallel to what PQsslAttribute(NULL, "library") does. Since this is mostly just future-proofing, no back-patch. Discussion: https://postgr.es/m/17625-fc47c78b7d71b534@postgresql.org
1 parent 69298db commit 4e4f7b9

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

doc/src/sgml/libpq.sgml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2590,12 +2590,22 @@ const char *PQsslAttribute(const PGconn *conn, const char *attribute_name);
25902590
<term><function>PQsslAttributeNames</function><indexterm><primary>PQsslAttributeNames</primary></indexterm></term>
25912591
<listitem>
25922592
<para>
2593-
Returns an array of SSL attribute names available.
2593+
Returns an array of SSL attribute names that can be used
2594+
in <function>PQsslAttribute()</function>.
25942595
The array is terminated by a NULL pointer.
25952596
<synopsis>
25962597
const char * const * PQsslAttributeNames(const PGconn *conn);
25972598
</synopsis>
25982599
</para>
2600+
2601+
<para>
2602+
If <literal>conn</literal> is NULL, the attributes available for the
2603+
default SSL library are returned, or an empty list
2604+
if <application>libpq</application> was compiled without any SSL
2605+
support. If <literal>conn</literal> is not NULL, the attributes
2606+
available for the SSL library in use for the connection are returned,
2607+
or an empty list if the connection is not encrypted.
2608+
</para>
25992609
</listitem>
26002610
</varlistentry>
26012611

src/interfaces/libpq/fe-secure-openssl.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1730,16 +1730,27 @@ PQsslStruct(PGconn *conn, const char *struct_name)
17301730
const char *const *
17311731
PQsslAttributeNames(PGconn *conn)
17321732
{
1733-
static const char *const result[] = {
1733+
static const char *const openssl_attrs[] = {
17341734
"library",
17351735
"key_bits",
17361736
"cipher",
17371737
"compression",
17381738
"protocol",
17391739
NULL
17401740
};
1741+
static const char *const empty_attrs[] = {NULL};
17411742

1742-
return result;
1743+
if (!conn)
1744+
{
1745+
/* Return attributes of default SSL library */
1746+
return openssl_attrs;
1747+
}
1748+
1749+
/* No attrs for unencrypted connection */
1750+
if (conn->ssl == NULL)
1751+
return empty_attrs;
1752+
1753+
return openssl_attrs;
17431754
}
17441755

17451756
const char *

0 commit comments

Comments
 (0)