Refactor check for SSL connection
authorDaniel Gustafsson <daniel@yesql.se>
Tue, 16 Feb 2021 15:01:08 +0000 (16:01 +0100)
committerHiroshi Inoue <h-inoue@dream.email.ne.jp>
Thu, 18 Feb 2021 09:49:36 +0000 (18:49 +0900)
PQgetssl has been discouraged from use since postgres 9.5 since it
will risk false negatives if postgres supports other TLS libraries
than OpenSSL. Refactor to use PQsslInUse which has been available
since 9.5 for just this purpose.

configure.ac
connection.c

index 8453a29bd3508e37ab8ab541590af4ea224a56e9..090972a615b7cf33adfc81ecb708182053a36226 100644 (file)
@@ -258,6 +258,8 @@ AC_C_CONST
 AC_FUNC_STRERROR_R
 AC_CHECK_FUNCS(strtoul strtoll strlcat mbstowcs wcstombs mbrtoc16 c16rtomb)
 
+AC_CHECK_FUNCS(PQsslInUse)
+
 if test "$enable_pthreads" = yes; then
   AC_CHECK_FUNCS(localtime_r strtok_r pthread_mutexattr_settype)
 
index 070e043f23563eac7480767f68c4912ee8fda63a..02794ff2c845ce9fb141850fa95d476b08e51f6a 100644 (file)
@@ -3263,10 +3263,13 @@ DLL_DECLARE int PgDtc_is_recovery_available(void *self, char *reason, int rsize)
    /*
     * Did we use SSL client certificate, SSPI, Kerberos or similar
     * authentication methods?
-    * There seems no way to check it directly.
     */
    doubtCert = FALSE;
+#ifdef HAVE_PQSSLINUSE
+   if (PQsslInUse(conn->pqconn))
+#else
    if (PQgetssl(conn->pqconn) != NULL)
+#endif
        doubtCert = TRUE;
 
    nameSize = sizeof(loginUser);