Skip to content

Commit 36d1087

Browse files
committed
Rename PQsetSSLKeyPassHook and friends
4dc6355 provided a way for libraries and clients to modify how libpq handles client certificate passphrases, by installing a hook. However, these routines are quite specific to how OpenSSL works, so it's misleading and not future-proof to have these names not refer to OpenSSL. Change all the names to add "_OpenSSL" after "Hook", and fix the docs accordingly. Author: Daniel Gustafsson Discussion: https://postgr.es/m/981DE552-E399-45C2-9F60-3F0E3770CC61@yesql.se
1 parent 1cbc143 commit 36d1087

File tree

4 files changed

+21
-21
lines changed

4 files changed

+21
-21
lines changed

doc/src/sgml/libpq.sgml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -777,30 +777,30 @@ PGPing PQping(const char *conninfo);
777777
</varlistentry>
778778

779779
<varlistentry id="libpq-pqsetsslkeypasshook">
780-
<term><function>PQsetSSLKeyPassHook</function><indexterm><primary>PQsetSSLKeyPassHook</primary></indexterm></term>
780+
<term><function>PQsetSSLKeyPassHook_OpenSSL</function><indexterm><primary>PQsetSSLKeyPassHook_OpenSSL</primary></indexterm></term>
781781
<listitem>
782782
<para>
783-
<function>PQsetSSLKeyPassHook</function> lets an application override
783+
<function>PQsetSSLKeyPassHook_OpenSSL</function> lets an application override
784784
<literal>libpq</literal>'s <link linkend="libpq-ssl-clientcert">default
785785
handling of encrypted client certificate key files</link> using
786786
<xref linkend="libpq-connect-sslpassword"/> or interactive prompting.
787787

788788
<synopsis>
789-
void PQsetSSLKeyPassHook(PQsslKeyPassHook_type hook);
789+
void PQsetSSLKeyPassHook_OpenSSL(PQsslKeyPassHook_OpenSSL_type hook);
790790
</synopsis>
791791

792792
The application passes a pointer to a callback function with signature:
793793
<programlisting>
794794
int callback_fn(char *buf, int size, PGconn *conn);
795795
</programlisting>
796796
which <literal>libpq</literal> will then call <emphasis>instead of</emphasis>
797-
its default <function>PQdefaultSSLKeyPassHook</function> handler. The callback
797+
its default <function>PQdefaultSSLKeyPassHook_OpenSSL</function> handler. The callback
798798
should determine the password for the key and copy it to result-buffer
799799
<literal>buf</literal> of size <literal>size</literal>. The string in <literal>
800800
buf</literal> must be null-terminated. The callback must return the length of
801801
the password stored in <literal>buf</literal> excluding the null terminator.
802802
On failure, the callback should set <literal>buf[0] = '\0'</literal> and return 0.
803-
See <function>PQdefaultSSLKeyPassHook</function> in <literal>libpq</literal>'s
803+
See <function>PQdefaultSSLKeyPassHook_OpenSSL</function> in <literal>libpq</literal>'s
804804
source code for an example.
805805
</para>
806806

@@ -814,7 +814,7 @@ int callback_fn(char *buf, int size, PGconn *conn);
814814

815815
<para>
816816
The app callback may choose to delegate unhandled cases to
817-
<function>PQdefaultSSLKeyPassHook</function>,
817+
<function>PQdefaultSSLKeyPassHook_OpenSSL</function>,
818818
or call it first and try something else if it returns 0, or completely override it.
819819
</para>
820820

@@ -835,7 +835,7 @@ int callback_fn(char *buf, int size, PGconn *conn);
835835
if none has been set.
836836

837837
<synopsis>
838-
PQsslKeyPassHook_type PQgetSSLKeyPassHook(void);
838+
PQsslKeyPassHook_OpenSSL_type PQgetSSLKeyPassHook(void);
839839
</synopsis>
840840
</para>
841841

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ static long win32_ssl_create_mutex = 0;
9595
#endif
9696
#endif /* ENABLE_THREAD_SAFETY */
9797

98-
static PQsslKeyPassHook_type PQsslKeyPassHook = NULL;
98+
static PQsslKeyPassHook_OpenSSL_type PQsslKeyPassHook = NULL;
9999
static int ssl_protocol_version_to_openssl(const char *protocol);
100100

101101
/* ------------------------------------------------------------ */
@@ -1669,7 +1669,7 @@ my_SSL_set_fd(PGconn *conn, int fd)
16691669
* prevent openssl from ever prompting on stdin.
16701670
*/
16711671
int
1672-
PQdefaultSSLKeyPassHook(char *buf, int size, PGconn *conn)
1672+
PQdefaultSSLKeyPassHook_OpenSSL(char *buf, int size, PGconn *conn)
16731673
{
16741674
if (conn->sslpassword)
16751675
{
@@ -1686,14 +1686,14 @@ PQdefaultSSLKeyPassHook(char *buf, int size, PGconn *conn)
16861686
}
16871687
}
16881688

1689-
PQsslKeyPassHook_type
1689+
PQsslKeyPassHook_OpenSSL_type
16901690
PQgetSSLKeyPassHook(void)
16911691
{
16921692
return PQsslKeyPassHook;
16931693
}
16941694

16951695
void
1696-
PQsetSSLKeyPassHook(PQsslKeyPassHook_type hook)
1696+
PQsetSSLKeyPassHook_OpenSSL(PQsslKeyPassHook_OpenSSL_type hook)
16971697
{
16981698
PQsslKeyPassHook = hook;
16991699
}
@@ -1711,7 +1711,7 @@ PQssl_passwd_cb(char *buf, int size, int rwflag, void *userdata)
17111711
if (PQsslKeyPassHook)
17121712
return PQsslKeyPassHook(buf, size, conn);
17131713
else
1714-
return PQdefaultSSLKeyPassHook(buf, size, conn);
1714+
return PQdefaultSSLKeyPassHook_OpenSSL(buf, size, conn);
17151715
}
17161716

17171717
/*

src/interfaces/libpq/fe-secure.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -431,20 +431,20 @@ PQsslAttributeNames(PGconn *conn)
431431
return result;
432432
}
433433

434-
PQsslKeyPassHook_type
435-
PQgetSSLKeyPassHook(void)
434+
PQsslKeyPassHook_OpenSSL_type
435+
PQgetSSLKeyPassHook_OpenSSL(void)
436436
{
437437
return NULL;
438438
}
439439

440440
void
441-
PQsetSSLKeyPassHook(PQsslKeyPassHook_type hook)
441+
PQsetSSLKeyPassHook_OpenSSL(PQsslKeyPassHook_OpenSSL_type hook)
442442
{
443443
return;
444444
}
445445

446446
int
447-
PQdefaultSSLKeyPassHook(char *buf, int size, PGconn *conn)
447+
PQdefaultSSLKeyPassHook_OpenSSL(char *buf, int size, PGconn *conn)
448448
{
449449
return 0;
450450
}

src/interfaces/libpq/libpq-fe.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -617,13 +617,13 @@ extern int pg_char_to_encoding(const char *name);
617617
extern const char *pg_encoding_to_char(int encoding);
618618
extern int pg_valid_server_encoding_id(int encoding);
619619

620-
/* == in fe-secure-openssl.c === */
620+
/* === in fe-secure-openssl.c === */
621621

622622
/* Support for overriding sslpassword handling with a callback. */
623-
typedef int (*PQsslKeyPassHook_type) (char *buf, int size, PGconn *conn);
624-
extern PQsslKeyPassHook_type PQgetSSLKeyPassHook(void);
625-
extern void PQsetSSLKeyPassHook(PQsslKeyPassHook_type hook);
626-
extern int PQdefaultSSLKeyPassHook(char *buf, int size, PGconn *conn);
623+
typedef int (*PQsslKeyPassHook_OpenSSL_type) (char *buf, int size, PGconn *conn);
624+
extern PQsslKeyPassHook_OpenSSL_type PQgetSSLKeyPassHook(void);
625+
extern void PQsetSSLKeyPassHook_OpenSSL(PQsslKeyPassHook_OpenSSL_type hook);
626+
extern int PQdefaultSSLKeyPassHook_OpenSSL(char *buf, int size, PGconn *conn);
627627

628628
#ifdef __cplusplus
629629
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy