From b6a6d29dbff2538c2faddbfb6cb176548a02e6cc Mon Sep 17 00:00:00 2001
From: Daniel Gustafsson <daniel@yesql.se>
Date: Thu, 5 Dec 2019 23:25:22 +0100
Subject: [PATCH] Fix autoconf check for SSL_clear_options

SSL_clear_options was implemented as a macro up until OpenSSL 1.1.0,
which means it cannot be reliably tested for with AC_CHECK_FUNCS as
that will only work for 1.1.0 and later.  Reimplement the check with
a test that compiles to ensure the signature is present.
---
 configure.in | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/configure.in b/configure.in
index a2cb20b5e3..37b59a2de4 100644
--- a/configure.in
+++ b/configure.in
@@ -1186,7 +1186,7 @@ if test "$with_openssl" = yes ; then
      AC_SEARCH_LIBS(CRYPTO_new_ex_data, [eay32 crypto], [], [AC_MSG_ERROR([library 'eay32' or 'crypto' is required for OpenSSL])])
      AC_SEARCH_LIBS(SSL_new, [ssleay32 ssl], [], [AC_MSG_ERROR([library 'ssleay32' or 'ssl' is required for OpenSSL])])
   fi
-  AC_CHECK_FUNCS([SSL_clear_options SSL_get_current_compression X509_get_signature_nid])
+  AC_CHECK_FUNCS([SSL_get_current_compression X509_get_signature_nid])
   # Functions introduced in OpenSSL 1.1.0. We used to check for
   # OPENSSL_VERSION_NUMBER, but that didn't work with 1.1.0, because LibreSSL
   # defines OPENSSL_VERSION_NUMBER to claim version 2.0.0, even though it
@@ -1197,6 +1197,20 @@ if test "$with_openssl" = yes ; then
   # thread-safety. In 1.1.0, it's no longer required, and CRYPTO_lock()
   # function was removed.
   AC_CHECK_FUNCS([CRYPTO_lock])
+  # SSL_clear_options is a macro in OpenSSL from 0.9.8 up until 1.0.2, so we
+  # can't test for it with AC_CHECK_FUNCS
+  AC_CACHE_CHECK([for SSL_clear_options], ac_cv_func_ssl_clear_options,
+  [AC_LINK_IFELSE([AC_LANG_PROGRAM([
+  #include <openssl/ssl.h>
+  #include <openssl/bio.h>
+  SSL *ssl;
+  ],
+  [return SSL_clear_options(ssl, 0);])],
+  [ac_cv_func_ssl_clear_options=yes],
+  [ac_cv_func_ssl_clear_options=no])])
+  if test $ac_cv_func_ssl_clear_options = yes ; then
+    AC_DEFINE(HAVE_SSL_CLEAR_OPTIONS, 1, [Define to 1 if you have SSL_clear_options()])
+  fi
 fi
 
 if test "$with_pam" = yes ; then
-- 
2.21.0 (Apple Git-122.2)

