ax_nagios_get_ssl 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. # ===========================================================================
  2. # SYNOPSIS
  3. #
  4. # AX_NAGIOS_GET_SSL
  5. #
  6. # DESCRIPTION
  7. #
  8. # This macro finds the openssl binary, the header files directory and
  9. # the library files directory. It will also search for the gnutls
  10. # compatibility library/headers and the nss compatibility library/headers.
  11. #
  12. # LICENSE
  13. #
  14. # Copyright (c) 2016 Nagios Core Development Team
  15. #
  16. # This program is free software; you can redistribute it and/or modify it
  17. # under the terms of the GNU General Public License as published by the
  18. # Free Software Foundation; either version 2 of the License, or (at your
  19. # option) any later version.
  20. #
  21. # This program is distributed in the hope that it will be useful, but
  22. # WITHOUT ANY WARRANTY; without even the implied warranty of
  23. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
  24. # Public License for more details.
  25. #
  26. # You should have received a copy of the GNU General Public License along
  27. # with this program. If not, see <http://www.gnu.org/licenses/>.
  28. #
  29. # As a special exception, the respective Autoconf Macro's copyright owner
  30. # gives unlimited permission to copy, distribute and modify the configure
  31. # scripts that are the output of Autoconf when processing the Macro. You
  32. # need not follow the terms of the GNU General Public License when using
  33. # or distributing such scripts, even though portions of the text of the
  34. # Macro appear in them. The GNU General Public License (GPL) does govern
  35. # all other use of the material that constitutes the Autoconf Macro.
  36. #
  37. # This special exception to the GPL applies to versions of the Autoconf
  38. # Macro released by the Autoconf Archive. When you make and distribute a
  39. # modified version of the Autoconf Macro, you may extend this special
  40. # exception to the GPL to apply to your modified version as well.
  41. # ===========================================================================
  42. AU_ALIAS([AC_NAGIOS_GET_SSL], [AX_NAGIOS_GET_SSL])
  43. AC_DEFUN([AX_NAGIOS_GET_SSL],
  44. [
  45. # -------------------------------
  46. # SSL library and include paths
  47. # -------------------------------
  48. SSL_TYPE=openssl
  49. ssl_dir=
  50. ssl_inc_dir=
  51. ssl_lib_dir=
  52. SSL_INC_DIR=
  53. SSL_LIB_DIR=
  54. AC_SUBST(HAVE_SSL)
  55. AC_SUBST(SSL_INC_DIR)
  56. AC_SUBST(SSL_LIB_DIR)
  57. # gnutls/openssl.h
  58. # nss_compat_ossl/nss_compat_ossl.h
  59. # Which type - openssl, gnutls-openssl, nss
  60. AC_ARG_WITH([ssl-type],
  61. dnl AS_HELP_STRING([--with-ssl-type=TYPE],[replace TYPE with gnutls or nss to use one of these instead of openssl]),
  62. AS_HELP_STRING([--with-ssl-type=TYPE],[replace TYPE with gnutls to use that instead of openssl]),
  63. [SSL_TYPE=$withval])
  64. AC_ARG_WITH([ssl],
  65. AS_HELP_STRING([--with-ssl=DIR],[sets location of the SSL installation]),
  66. [ssl_dir=$withval])
  67. AC_ARG_WITH([ssl-inc],
  68. AS_HELP_STRING([--with-ssl-inc=DIR],
  69. [sets location of the SSL include files]),
  70. [ssl_inc_dir=$withval])
  71. AC_ARG_WITH([ssl-lib],
  72. AS_HELP_STRING([--with-ssl-lib=DIR],[sets location of the SSL libraries]),
  73. [ssl_lib_dir=$withval])
  74. AC_ARG_WITH([kerberos-inc],
  75. AS_HELP_STRING([--with-kerberos-inc=DIR],
  76. [sets location of the Kerberos include files]),
  77. [kerberos_inc_dir=$withval])
  78. if test x$SSL_TYPE = xyes; then
  79. SSL_TYPE=openssl
  80. fi
  81. dflt_hdrs="$ssl_inc_dir $ssl_dir $ssl_dir/include $ssl_dir/include \
  82. /usr/local/opt/{BBB} /usr/include/{BBB} /usr/local/include{BBB} \
  83. /usr/local/{AAA} /usr/local/{BBB} /usr/lib/{AAA} /usr/lib/{BBB} \
  84. /usr/{AAA} /usr/pkg /usr/local /usr /usr/freeware/lib/{BBB} \
  85. /usr/sfw /usr/sfw/include /opt/{BBB}"
  86. dflt_libs="$ssl_lib_dir {ssldir} {ssldir}/lib {ssldir}/lib64 /usr/lib64 \
  87. /usr/lib /usr/lib/x86_64-linux-gnu /usr/lib/i386-linux-gnu \
  88. /usr/local/lib /usr/lib/{AAA} /usr/{AAA}/lib /usr/{BBB}/lib \
  89. /usr/pkg/lib /usr/freeware/lib/{BBB} /usr/sfw/lib /opt/freeware/lib \
  90. /opt/{BBB}/lib/hpux64 /opt/{BBB}/lib/pa20_64 /opt/{BBB}/lib/hpux32 \
  91. /opt/{BBB}/lib /opt/{BBB}";
  92. AS_CASE([$SSL_TYPE],
  93. [no], [SSL_TYPE=NONE],
  94. [yes|openssl],
  95. [ssl_hdr_dirs=`echo "$dflt_hdrs" | sed -e 's/{AAA}/ssl/g' | sed -e 's/{BBB}/openssl/g'`
  96. ssl_lib_dirs=`echo "$dflt_libs" | sed -e 's/{AAA}/ssl/g' | sed -e 's/{BBB}/openssl/g'`
  97. ssl_hdr=ssl.h
  98. ssl_lib=libssl],
  99. [gnutls],
  100. [ssl_hdr_dirs=`echo "$dflt_hdrs" | sed -e 's/{AAA}/gnutls/g' | sed -e 's/{BBB}/gnutls/g'`
  101. ssl_lib_dirs=`echo "$dflt_libs" | sed -e 's/{AAA}/gnutls/g' | sed -e 's/{BBB}/gnutls/g'`
  102. ssl_hdr=compat.h
  103. ssl_lib=libgnutls],
  104. [nss],
  105. [ssl_hdr_dirs=`echo "$dflt_hdrs" | sed -e 's/{AAA}/nss_compat_ossl/g' | sed -e 's/{BBB}/nss_compat_ossl/g'`
  106. ssl_lib_dirs=`echo "$dflt_libs" | sed -e 's/{AAA}/nss_compat_ossl/g' | sed -e 's/{BBB}/nss_compat_ossl/g'`
  107. ssl_hdr=nss_compat_ossl.h
  108. ssl_lib=libnss_compat],
  109. [*], echo >&6; AC_MSG_ERROR(['--with-ssl-type=$SSL_TYPE' is invalid])
  110. )
  111. # Check for SSL support
  112. if test x$SSL_TYPE != xNONE; then
  113. found_ssl=no
  114. # RedHat 8.0 and 9.0 include openssl compiled with kerberos,
  115. # so we must include header file
  116. # Must come before openssl checks for Redhat EL 3
  117. AC_MSG_CHECKING(for Kerberos include files)
  118. found_kerberos=no
  119. for dir in $kerberos_inc_dir /usr/kerberos/include /usr/include/krb5 \
  120. /usr/include; do
  121. kerbdir="$dir"
  122. if test -f "$dir/krb5.h"; then
  123. found_kerberos=yes
  124. CFLAGS="$CFLAGS -I$kerbdir"
  125. AC_DEFINE_UNQUOTED(HAVE_KRB5_H,[1],[Have the krb5.h header file])
  126. break
  127. fi
  128. done
  129. if test x_$found_kerberos != x_yes; then
  130. AC_MSG_WARN(could not find include files)
  131. else
  132. AC_MSG_RESULT(found Kerberos include files in $kerbdir)
  133. fi
  134. # First, try using pkg_config
  135. # AC_CHECK_TOOL([PKG_CONFIG], [pkg-config])
  136. # if test x"$PKG_CONFIG" != x ; then
  137. # cflags=`$PKG_CONFIG $SSL_TYPE --cflags-only-I 2>/dev/null`
  138. # if test $? = 0; then
  139. # CFLAGS="$CFLAGS $cflags"
  140. # LDFLAGS="$LDFLAGS `$PKG_CONFIG $SSL_TYPE --libs-only-L 2>/dev/null`"
  141. # LIBS="$LIBS `$PKG_CONFIG $SSL_TYPE --libs-only-l 2>/dev/null`"
  142. # found_ssl=yes
  143. # AC_DEFINE_UNQUOTED(HAVE_SSL,[1],[Have SSL support])
  144. # fi
  145. # fi
  146. if test x_$found_ssl != x_yes; then
  147. # Find the SSL Headers
  148. AC_MSG_CHECKING(for SSL headers)
  149. for dir in $ssl_hdr_dirs; do
  150. ssldir="$dir"
  151. if test -f "$dir/include/openssl/$ssl_hdr"; then
  152. found_ssl=yes
  153. CFLAGS="$CFLAGS -I$dir/include/openssl -I$ssldir/include"
  154. SSL_INC_DIR="$dir/include/openssl"
  155. break
  156. fi
  157. if test -f "$dir/include/$ssl_hdr"; then
  158. found_ssl=yes
  159. CFLAGS="$CFLAGS -I$dir/include"
  160. SSL_INC_DIR="$dir/include"
  161. break
  162. fi
  163. if test -f "$dir/$ssl_hdr"; then
  164. found_ssl=yes
  165. CFLAGS="$CFLAGS -I$dir"
  166. SSL_INC_DIR="$dir"
  167. ssldir="$dir/.."
  168. break
  169. fi
  170. if test -f "$dir/openssl/$ssl_hdr"; then
  171. found_ssl=yes
  172. CFLAGS="$CFLAGS -I$dir/openssl"
  173. SSL_INC_DIR="$dir/openssl"
  174. ssldir="$dir/.."
  175. break
  176. fi
  177. done
  178. if test x_$found_ssl != x_yes; then
  179. AC_MSG_ERROR(Cannot find ssl headers)
  180. else
  181. AC_MSG_RESULT(found in $ssldir)
  182. # Now try and find SSL libraries
  183. AC_MSG_CHECKING(for SSL libraries)
  184. found_ssl=no
  185. ssl_lib_dirs=`echo "$ssl_lib_dirs" | sed -e "s|{ssldir}|$ssldir|g"`
  186. if test "`uname -s`" = "Darwin" ; then
  187. soext="dylib"
  188. elif test "`uname -s`" = "HP-UX" ; then
  189. if test x$arch = "xia64"; then
  190. soext="so"
  191. else
  192. soext="sl"
  193. fi
  194. elif test "`uname -s`" = "AIX" ; then
  195. soext="a"
  196. else
  197. soext="so"
  198. fi
  199. for dir in $ssl_lib_dirs; do
  200. if test -f "$dir/$ssl_lib.$soext"; then
  201. found_ssl=yes
  202. SSL_LIB_DIR="$dir"
  203. break
  204. fi
  205. done
  206. if test x_$found_ssl != x_yes; then
  207. AC_MSG_ERROR(Cannot find ssl libraries)
  208. else
  209. AC_MSG_RESULT(found in $SSL_LIB_DIR)
  210. LDFLAGS="$LDFLAGS -L$SSL_LIB_DIR";
  211. LIBS="$LIBS -l`echo $ssl_lib | sed -e 's/^lib//'` -lcrypto";
  212. AC_DEFINE_UNQUOTED(HAVE_SSL,[1],[Have SSL support])
  213. fi
  214. fi
  215. fi
  216. if test x$found_ssl = xyes ; then
  217. # try to compile and link to see if SSL is set up properly
  218. AC_MSG_CHECKING([whether compiling and linking against SSL works])
  219. AC_LINK_IFELSE(
  220. [AC_LANG_PROGRAM([#include <openssl/ssl.h>], [SSL_new(NULL)])],
  221. [
  222. AC_MSG_RESULT([yes])
  223. $1
  224. ], [
  225. AC_MSG_ERROR([no])
  226. $2
  227. ])
  228. fi
  229. if test x$found_ssl = xyes -a x$need_dh = xyes; then
  230. # Find the openssl program
  231. if test x$need_dh = xyes; then
  232. AC_PATH_PROG(sslbin,openssl,value-if-not-found,$ssl_dir/sbin$PATH_SEPARATOR$ssl_dir/bin$PATH_SEPARATOR$PATH)
  233. AC_DEFINE(USE_SSL_DH)
  234. # Generate DH parameters
  235. if test -f "$sslbin"; then
  236. echo ""
  237. echo "*** Generating DH Parameters for SSL/TLS ***"
  238. # awk to strip off meta data at bottom of dhparam output
  239. $sslbin dhparam -C 2048 | awk '/^-----/ {exit} {print}' > include/dh.h
  240. fi
  241. fi
  242. fi
  243. fi
  244. ])