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