ax_nagios_get_ssl 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  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. try_pkg_config=1
  50. ssl_dir=
  51. ssl_inc_dir=
  52. ssl_lib_dir=
  53. SSL_INC_PREFIX=
  54. SSL_HDR=
  55. SSL_LIB_DIR=
  56. AC_SUBST(HAVE_SSL)
  57. AC_SUBST(SSL_TYPE)
  58. AC_SUBST(SSL_HDR)
  59. AC_SUBST(SSL_INC_PREFIX)
  60. AC_SUBST(SSL_LIB_DIR)
  61. AC_SUBST(SSL_DH_HEADER)
  62. AC_SUBST(SSL_OBJS)
  63. dnl Makefile for generating DH parameters, pre 3.0 and post 3.0
  64. SSL_DH_HEADER_MAKE_OLD="../include/dh.h:
  65. \$(SSLBIN) dhparam -C 2048 | awk '/^-----/ {exit} {print}' > \@S|@@"
  66. SSL_DH_HEADER_MAKE_NEW="../include/dh.h: generate_dh_params
  67. ./generate_dh_params > \@S|@@
  68. generate_dh_params: \$(srcdir)/generate_dh_params.c
  69. \$(CC) \$(CFLAGS) -o \@S|@@ \$(srcdir)/generate_dh_params.c \$(LDFLAGS)"
  70. # gnutls/openssl.h
  71. # nss_compat_ossl/nss_compat_ossl.h
  72. dnl # Which type - openssl, gnutls-openssl, nss
  73. dnl AC_ARG_WITH([ssl-type],
  74. dnl dnl AS_HELP_STRING([--with-ssl-type=TYPE],[replace TYPE with gnutls or nss to use one of these instead of openssl]),
  75. dnl AS_HELP_STRING([--with-ssl-type=TYPE],[replace TYPE with gnutls to use that instead of openssl]),
  76. dnl [SSL_TYPE=$withval])
  77. AC_ARG_WITH([ssl],
  78. AS_HELP_STRING([--with-ssl=DIR],[sets location of the SSL installation]),
  79. [ssl_dir=$withval])
  80. AC_ARG_WITH([ssl-inc],
  81. AS_HELP_STRING([--with-ssl-inc=DIR],
  82. [sets location of the SSL include files]),
  83. [ssl_inc_dir=$withval])
  84. AC_ARG_WITH([ssl-lib],
  85. AS_HELP_STRING([--with-ssl-lib=DIR],[sets location of the SSL libraries]),
  86. [ssl_lib_dir=$withval])
  87. AC_ARG_ENABLE([auto_dh],
  88. AS_HELP_STRING([--disable-auto-dh],[disables using builtin DH parameters (if available) and generates custom parameters]),
  89. auto_dh=no,
  90. auto_dh=yes)
  91. if test x$ssl_inc_dir != x -o x$ssl_lib_dir != x; then
  92. try_pkg_config=0
  93. fi
  94. AC_ARG_WITH([kerberos-inc],
  95. AS_HELP_STRING([--with-kerberos-inc=DIR],
  96. [sets location of the Kerberos include files]),
  97. [kerberos_inc_dir=$withval])
  98. if test x$SSL_TYPE = xyes; then
  99. SSL_TYPE=openssl
  100. fi
  101. dflt_hdrs="$ssl_inc_dir $ssl_dir $ssl_inc_dir/include $ssl_dir/include \
  102. /usr/local/opt/{BBB} /usr/include/{BBB} /usr/local/include/{BBB} \
  103. /usr/local/{AAA} /usr/local/{BBB} /usr/lib/{AAA} /usr/lib/{BBB} \
  104. /usr/{AAA} /usr/pkg /usr/local /usr /usr/freeware/lib/{BBB} \
  105. /usr/sfw /usr/sfw/include /opt/{BBB}"
  106. dflt_libs="$ssl_lib_dir {ssldir} {ssldir}/lib {ssldir}/lib64 /usr/lib64 \
  107. /usr/lib /usr/lib/x86_64-linux-gnu /usr/lib/i386-linux-gnu \
  108. /usr/local/lib /usr/lib/{AAA} /usr/{AAA}/lib /usr/{BBB}/lib \
  109. /usr/pkg/lib /usr/freeware/lib/{BBB} /usr/sfw/lib /opt/freeware/lib \
  110. /opt/{BBB}/lib/hpux64 /opt/{BBB}/lib/pa20_64 /opt/{BBB}/lib/hpux32 \
  111. /opt/{BBB}/lib /opt/{BBB}";
  112. AS_CASE([$SSL_TYPE],
  113. [no], [SSL_TYPE=NONE],
  114. [yes|openssl],
  115. [ssl_hdr_dirs=`echo "$dflt_hdrs" | sed -e 's/{AAA}/ssl/g' | sed -e 's/{BBB}/openssl/g'`
  116. ssl_lib_dirs=`echo "$dflt_libs" | sed -e 's/{AAA}/ssl/g' | sed -e 's/{BBB}/openssl/g'`
  117. SSL_INC_PREFIX=openssl
  118. SSL_HDR=ssl.h
  119. ssl_lib=libssl],
  120. [gnutls],
  121. [ssl_hdr_dirs=`echo "$dflt_hdrs" | sed -e 's/{AAA}/gnutls/g' | sed -e 's/{BBB}/gnutls/g'`
  122. ssl_lib_dirs=`echo "$dflt_libs" | sed -e 's/{AAA}/gnutls/g' | sed -e 's/{BBB}/gnutls/g'`
  123. SSL_INC_PREFIX=gnutls
  124. SSL_TYPE=gnutls_compat
  125. SSL_HDR=compat.h
  126. ssl_lib=libgnutls],
  127. [nss],
  128. [ssl_hdr_dirs=`echo "$dflt_hdrs" | sed -e 's/{AAA}/nss_compat_ossl/g' | sed -e 's/{BBB}/nss_compat_ossl/g'`
  129. ssl_lib_dirs=`echo "$dflt_libs" | sed -e 's/{AAA}/nss_compat_ossl/g' | sed -e 's/{BBB}/nss_compat_ossl/g'`
  130. SSL_HDR=nss_compat_ossl.h
  131. ssl_lib=libnss_compat],
  132. [*], echo >&6; AC_MSG_ERROR(['--with-ssl-type=$SSL_TYPE' is invalid])
  133. )
  134. # Check for SSL support
  135. if test x$SSL_TYPE != xNONE; then
  136. found_ssl=no
  137. # RedHat 8.0 and 9.0 include openssl compiled with kerberos,
  138. # so we must include header file
  139. # Must come before openssl checks for Redhat EL 3
  140. AC_MSG_CHECKING(for Kerberos include files)
  141. found_kerberos=no
  142. for dir in $kerberos_inc_dir /usr/kerberos/include /usr/include/krb5 \
  143. /usr/include; do
  144. kerbdir="$dir"
  145. if test -f "$dir/krb5.h"; then
  146. found_kerberos=yes
  147. CFLAGS="$CFLAGS -I$kerbdir"
  148. AC_DEFINE_UNQUOTED(HAVE_KRB5_H,[1],[Have the krb5.h header file])
  149. break
  150. fi
  151. done
  152. if test x_$found_kerberos != x_yes; then
  153. AC_MSG_WARN(could not find include files)
  154. else
  155. AC_MSG_RESULT(found Kerberos include files in $kerbdir)
  156. fi
  157. # First, try using pkg_config
  158. if test $try_pkg_config -ne 0 ; then
  159. AC_CHECK_TOOL([PKG_CONFIG], [pkg-config])
  160. fi
  161. if test x"$PKG_CONFIG" != x -a $try_pkg_config -ne 0 ; then
  162. cflags=`$PKG_CONFIG $SSL_TYPE --cflags-only-I 2>/dev/null`
  163. if test $? -eq 0; then
  164. CFLAGS="$CFLAGS $cflags"
  165. LDFLAGS="$LDFLAGS `$PKG_CONFIG $SSL_TYPE --libs-only-L 2>/dev/null`"
  166. LIBS="$LIBS `$PKG_CONFIG $SSL_TYPE --libs-only-l 2>/dev/null`"
  167. found_ssl=yes
  168. AC_DEFINE_UNQUOTED(HAVE_SSL,[1],[Have SSL support])
  169. fi
  170. fi
  171. if test x_$found_ssl != x_yes; then
  172. # Find the SSL Headers
  173. AC_MSG_CHECKING(for SSL headers)
  174. for dir in $ssl_hdr_dirs; do
  175. if test "$dir" = "/include"; then
  176. continue
  177. fi
  178. ssldir="$dir"
  179. sslincdir="$dir"
  180. if test -f "$dir/$SSL_INC_PREFIX/$SSL_HDR"; then
  181. found_ssl=yes
  182. CFLAGS="$CFLAGS -I$dir"
  183. ssldir="$dir/.."
  184. break
  185. fi
  186. if test -f "$dir/include/$SSL_INC_PREFIX/$SSL_HDR"; then
  187. found_ssl=yes
  188. CFLAGS="$CFLAGS -I$dir/include"
  189. sslincdir="$dir/include"
  190. break
  191. fi
  192. if test -f "$dir/include/$SSL_HDR"; then
  193. found_ssl=yes
  194. if test "$SSL_HDR" != compat.h ; then
  195. SSL_INC_PREFIX=""
  196. fi
  197. CFLAGS="$CFLAGS -I$dir/include"
  198. sslincdir="$dir/include"
  199. break
  200. fi
  201. if test -f "$dir/$SSL_HDR"; then
  202. found_ssl=yes
  203. SSL_INC_PREFIX=""
  204. CFLAGS="$CFLAGS -I$dir"
  205. break
  206. fi
  207. done
  208. if test x_$found_ssl != x_yes; then
  209. AC_MSG_ERROR(Cannot find ssl headers)
  210. else
  211. AC_MSG_RESULT(found in $sslincdir)
  212. # Now try and find SSL libraries
  213. AC_MSG_CHECKING(for SSL libraries)
  214. found_ssl=no
  215. ssl_lib_dirs=`echo "$ssl_lib_dirs" | sed -e "s|{ssldir}|$ssldir|g"`
  216. if test "`uname -s`" = "Darwin" ; then
  217. soext="dylib"
  218. elif test "`uname -s`" = "HP-UX" ; then
  219. if test x$arch = "xia64"; then
  220. soext="so"
  221. else
  222. soext="sl"
  223. fi
  224. elif test "`uname -s`" = "AIX" ; then
  225. soext="a"
  226. else
  227. soext="so a"
  228. fi
  229. for dir in $ssl_lib_dirs; do
  230. for ext in $soext; do
  231. if test -f "$dir/$ssl_lib.$ext"; then
  232. found_ssl=yes
  233. SSL_LIB_DIR="$dir"
  234. break
  235. fi
  236. done
  237. if test x_$found_ssl == x_yes; then
  238. break
  239. fi
  240. done
  241. if test x_$found_ssl != x_yes; then
  242. AC_MSG_ERROR(Cannot find ssl libraries)
  243. else
  244. AC_MSG_RESULT(found in $SSL_LIB_DIR)
  245. LDFLAGS="$LDFLAGS -L$SSL_LIB_DIR -Wl,-rpath,$SSL_LIB_DIR";
  246. LIBS="$LIBS -l`echo $ssl_lib | sed -e 's/^lib//'` -lcrypto";
  247. AC_DEFINE_UNQUOTED(HAVE_SSL,[1],[Have SSL support])
  248. fi
  249. fi
  250. fi
  251. if test x$found_ssl = xyes ; then
  252. if test -n "$SSL_INC_PREFIX" ; then
  253. SSL_INC_PREFIX="${SSL_INC_PREFIX}/"
  254. fi
  255. # try to compile and link to see if SSL is set up properly
  256. AC_MSG_CHECKING([whether compiling and linking against SSL works])
  257. AC_LINK_IFELSE(
  258. [AC_LANG_PROGRAM([#include <${SSL_INC_PREFIX}${SSL_HDR}>], [SSL_new(NULL)])],
  259. [
  260. AC_MSG_RESULT([yes])
  261. SSL_OBJS="nrpe-ssl.o"
  262. $1
  263. ], [
  264. AC_MSG_ERROR([no])
  265. $2
  266. ])
  267. fi
  268. if test x$found_ssl = xyes -a x$need_dh = xyes; then
  269. AC_LINK_IFELSE([dnl
  270. AC_LANG_PROGRAM(
  271. [
  272. #include <stdio.h>
  273. #include <${SSL_INC_PREFIX}${SSL_HDR}>
  274. ],
  275. [
  276. #ifdef OPENSSL_VERSION_MAJOR
  277. printf("%i %i", OPENSSL_VERSION_MAJOR, OPENSSL_VERSION_MINOR);
  278. #else
  279. printf("%i %i", (int)((OPENSSL_VERSION_NUMBER >> 28) & 0x0f), (int)((OPENSSL_VERSION_NUMBER >> 20) & 0xff));
  280. #endif
  281. ])],
  282. [
  283. nagios_ssl_version=$(./conftest$EXEEXT)
  284. SSL_MAJOR=$(echo $nagios_ssl_version | cut -d' ' -f1)
  285. SSL_MINOR=$(echo $nagios_ssl_version | cut -d' ' -f2)
  286. ],
  287. AC_MSG_ERROR(Failed to detect OpenSSL version!))
  288. if test x$auto_dh = xyes -a $SSL_MAJOR -lt 1 -o \( $SSL_MAJOR -eq 1 -a $SSL_MINOR -lt 1 \); then
  289. # auto_dh not available before v1.1.0
  290. auto_dh=no
  291. fi
  292. if test x$auto_dh = xyes; then
  293. AC_DEFINE(AUTO_SSL_DH)
  294. fi
  295. dnl Do the Makefile rules here to maintain compatibility and not rely on GNU Make
  296. if test x$need_dh = xyes ; then
  297. if test x$auto_dh = xno ; then
  298. if test $SSL_MAJOR -lt 3 ; then
  299. # Find the openssl program
  300. # Only need openssl binary if we're not using auto or using version less than 3.0
  301. AC_PATH_PROG(sslbin,openssl,value-if-not-found,${ssldir}/sbin${PATH_SEPARATOR}${ssldir}/bin${PATH_SEPARATOR}${PATH})
  302. AC_SUBST(SSL_DH_HEADER_MAKE, ${SSL_DH_HEADER_MAKE_OLD})
  303. else
  304. AC_SUBST(SSL_DH_HEADER_MAKE, ${SSL_DH_HEADER_MAKE_NEW})
  305. fi
  306. AC_SUBST(SSL_DH_HEADER,../include/dh.h)
  307. fi
  308. AC_DEFINE(USE_SSL_DH)
  309. fi
  310. fi
  311. fi
  312. ])