| 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_DIR= |
| 57 |
SSL_INC_PREFIX= |
| 58 |
SSL_HDR= |
| 59 |
SSL_LIB_DIR= |
| 60 |
|
| 61 |
AC_SUBST(HAVE_SSL) |
| 62 |
AC_SUBST(SSL_TYPE) |
| 63 |
AC_SUBST(SSL_INC_DIR) |
| 64 |
AC_SUBST(SSL_HDR) |
| 65 |
AC_SUBST(SSL_INC_PREFIX) |
| 66 |
AC_SUBST(SSL_LIB_DIR) |
| 67 |
|
| 68 |
|
| 69 |
# gnutls/openssl.h |
| 70 |
# nss_compat_ossl/nss_compat_ossl.h |
| 71 |
|
| 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 |
|
| 78 |
AC_ARG_WITH([ssl], |
| 79 |
AS_HELP_STRING([--with-ssl=DIR],[sets location of the SSL installation]), |
| 80 |
[ssl_dir=$withval]) |
| 81 |
AC_ARG_WITH([ssl-inc], |
| 82 |
AS_HELP_STRING([--with-ssl-inc=DIR], |
| 83 |
[sets location of the SSL include files]), |
| 84 |
[ssl_inc_dir=$withval]) |
| 85 |
AC_ARG_WITH([ssl-lib], |
| 86 |
AS_HELP_STRING([--with-ssl-lib=DIR],[sets location of the SSL libraries]), |
| 87 |
[ssl_lib_dir=$withval]) |
| 88 |
|
| 89 |
if test x$ssl_inc_dir != x -o x$ssl_lib_dir != x; then |
| 90 |
try_pkg_config=0 |
| 91 |
fi |
| 92 |
|
| 93 |
AC_ARG_WITH([kerberos-inc], |
| 94 |
AS_HELP_STRING([--with-kerberos-inc=DIR], |
| 95 |
[sets location of the Kerberos include files]), |
| 96 |
[kerberos_inc_dir=$withval]) |
| 97 |
|
| 98 |
if test x$SSL_TYPE = xyes; then |
| 99 |
SSL_TYPE=openssl |
| 100 |
fi |
| 101 |
|
| 102 |
|
| 103 |
dflt_hdrs="$ssl_inc_dir $ssl_dir $ssl_inc_dir/include $ssl_dir/include \ |
| 104 |
/usr/local/opt/{BBB} /usr/include/{BBB} /usr/local/include/{BBB} \ |
| 105 |
/usr/local/{AAA} /usr/local/{BBB} /usr/lib/{AAA} /usr/lib/{BBB} \ |
| 106 |
/usr/{AAA} /usr/pkg /usr/local /usr /usr/freeware/lib/{BBB} \ |
| 107 |
/usr/sfw /usr/sfw/include /opt/{BBB}" |
| 108 |
|
| 109 |
dflt_libs="$ssl_lib_dir {ssldir} {ssldir}/lib {ssldir}/lib64 /usr/lib64 \ |
| 110 |
/usr/lib /usr/lib/x86_64-linux-gnu /usr/lib/i386-linux-gnu \ |
| 111 |
/usr/local/lib /usr/lib/{AAA} /usr/{AAA}/lib /usr/{BBB}/lib \ |
| 112 |
/usr/pkg/lib /usr/freeware/lib/{BBB} /usr/sfw/lib /opt/freeware/lib \ |
| 113 |
/opt/{BBB}/lib/hpux64 /opt/{BBB}/lib/pa20_64 /opt/{BBB}/lib/hpux32 \ |
| 114 |
/opt/{BBB}/lib /opt/{BBB}"; |
| 115 |
|
| 116 |
|
| 117 |
AS_CASE([$SSL_TYPE], |
| 118 |
[no], [SSL_TYPE=NONE], |
| 119 |
[yes|openssl], |
| 120 |
[ssl_hdr_dirs=`echo "$dflt_hdrs" | sed -e 's/{AAA}/ssl/g' | sed -e 's/{BBB}/openssl/g'` |
| 121 |
ssl_lib_dirs=`echo "$dflt_libs" | sed -e 's/{AAA}/ssl/g' | sed -e 's/{BBB}/openssl/g'` |
| 122 |
SSL_INC_PREFIX=openssl |
| 123 |
SSL_HDR=ssl.h |
| 124 |
ssl_lib=libssl], |
| 125 |
[gnutls], |
| 126 |
[ssl_hdr_dirs=`echo "$dflt_hdrs" | sed -e 's/{AAA}/gnutls/g' | sed -e 's/{BBB}/gnutls/g'` |
| 127 |
ssl_lib_dirs=`echo "$dflt_libs" | sed -e 's/{AAA}/gnutls/g' | sed -e 's/{BBB}/gnutls/g'` |
| 128 |
SSL_INC_PREFIX=gnutls |
| 129 |
SSL_TYPE=gnutls_compat |
| 130 |
SSL_HDR=compat.h |
| 131 |
ssl_lib=libgnutls], |
| 132 |
[nss], |
| 133 |
[ssl_hdr_dirs=`echo "$dflt_hdrs" | sed -e 's/{AAA}/nss_compat_ossl/g' | sed -e 's/{BBB}/nss_compat_ossl/g'` |
| 134 |
ssl_lib_dirs=`echo "$dflt_libs" | sed -e 's/{AAA}/nss_compat_ossl/g' | sed -e 's/{BBB}/nss_compat_ossl/g'` |
| 135 |
SSL_HDR=nss_compat_ossl.h |
| 136 |
ssl_lib=libnss_compat], |
| 137 |
[*], echo >&6; AC_MSG_ERROR(['--with-ssl-type=$SSL_TYPE' is invalid]) |
| 138 |
) |
| 139 |
|
| 140 |
|
| 141 |
# Check for SSL support |
| 142 |
|
| 143 |
if test x$SSL_TYPE != xNONE; then |
| 144 |
|
| 145 |
found_ssl=no |
| 146 |
|
| 147 |
# RedHat 8.0 and 9.0 include openssl compiled with kerberos, |
| 148 |
# so we must include header file |
| 149 |
# Must come before openssl checks for Redhat EL 3 |
| 150 |
AC_MSG_CHECKING(for Kerberos include files) |
| 151 |
found_kerberos=no |
| 152 |
for dir in $kerberos_inc_dir /usr/kerberos/include /usr/include/krb5 \ |
| 153 |
/usr/include; do |
| 154 |
kerbdir="$dir" |
| 155 |
if test -f "$dir/krb5.h"; then |
| 156 |
found_kerberos=yes |
| 157 |
CFLAGS="$CFLAGS -I$kerbdir" |
| 158 |
AC_DEFINE_UNQUOTED(HAVE_KRB5_H,[1],[Have the krb5.h header file]) |
| 159 |
break |
| 160 |
fi |
| 161 |
done |
| 162 |
|
| 163 |
if test x_$found_kerberos != x_yes; then |
| 164 |
AC_MSG_WARN(could not find include files) |
| 165 |
else |
| 166 |
AC_MSG_RESULT(found Kerberos include files in $kerbdir) |
| 167 |
fi |
| 168 |
|
| 169 |
# First, try using pkg_config |
| 170 |
AC_CHECK_TOOL([PKG_CONFIG], [pkg-config]) |
| 171 |
if test x"$PKG_CONFIG" != x -a $try_pkg_config -ne 0 ; then |
| 172 |
cflags=`$PKG_CONFIG $SSL_TYPE --cflags-only-I 2>/dev/null` |
| 173 |
if test $? -eq 0; then |
| 174 |
CFLAGS="$CFLAGS $cflags" |
| 175 |
LDFLAGS="$LDFLAGS `$PKG_CONFIG $SSL_TYPE --libs-only-L 2>/dev/null`" |
| 176 |
LIBS="$LIBS `$PKG_CONFIG $SSL_TYPE --libs-only-l 2>/dev/null`" |
| 177 |
found_ssl=yes |
| 178 |
AC_DEFINE_UNQUOTED(HAVE_SSL,[1],[Have SSL support]) |
| 179 |
fi |
| 180 |
fi |
| 181 |
|
| 182 |
if test x_$found_ssl != x_yes; then |
| 183 |
|
| 184 |
# Find the SSL Headers |
| 185 |
AC_MSG_CHECKING(for SSL headers) |
| 186 |
for dir in $ssl_hdr_dirs; do |
| 187 |
if test "$dir" = "/include"; then |
| 188 |
continue |
| 189 |
fi |
| 190 |
ssldir="$dir" |
| 191 |
if test -f "$dir/include/$SSL_INC_PREFIX/$SSL_HDR"; then |
| 192 |
found_ssl=yes |
| 193 |
CFLAGS="$CFLAGS -I$dir/include/$SSL_INC_PREFIX -I$ssldir/include" |
| 194 |
SSL_INC_DIR="$dir/include/$SSL_INC_PREFIX" |
| 195 |
break |
| 196 |
fi |
| 197 |
if test -f "$dir/include/$SSL_HDR"; then |
| 198 |
found_ssl=yes |
| 199 |
if test "$SSL_HDR" != compat.h ; then |
| 200 |
SSL_INC_PREFIX="" |
| 201 |
fi |
| 202 |
CFLAGS="$CFLAGS -I$dir/include" |
| 203 |
SSL_INC_DIR="$dir/include" |
| 204 |
break |
| 205 |
fi |
| 206 |
if test -f "$dir/$SSL_HDR"; then |
| 207 |
found_ssl=yes |
| 208 |
SSL_INC_PREFIX="" |
| 209 |
CFLAGS="$CFLAGS -I$dir" |
| 210 |
SSL_INC_DIR="$dir" |
| 211 |
break |
| 212 |
fi |
| 213 |
if test -f "$dir/$SSL_INC_PREFIX/$SSL_HDR"; then |
| 214 |
found_ssl=yes |
| 215 |
CFLAGS="$CFLAGS -I$dir/$SSL_INC_PREFIX" |
| 216 |
SSL_INC_DIR="$dir/$SSL_INC_PREFIX" |
| 217 |
ssldir="$dir/.." |
| 218 |
break |
| 219 |
fi |
| 220 |
done |
| 221 |
|
| 222 |
if test x_$found_ssl != x_yes; then |
| 223 |
AC_MSG_ERROR(Cannot find ssl headers) |
| 224 |
else |
| 225 |
AC_MSG_RESULT(found in $ssldir) |
| 226 |
|
| 227 |
# Now try and find SSL libraries |
| 228 |
|
| 229 |
AC_MSG_CHECKING(for SSL libraries) |
| 230 |
found_ssl=no |
| 231 |
ssl_lib_dirs=`echo "$ssl_lib_dirs" | sed -e "s|{ssldir}|$ssldir|g"` |
| 232 |
|
| 233 |
if test "`uname -s`" = "Darwin" ; then |
| 234 |
soext="dylib" |
| 235 |
elif test "`uname -s`" = "HP-UX" ; then |
| 236 |
if test x$arch = "xia64"; then |
| 237 |
soext="so" |
| 238 |
else |
| 239 |
soext="sl" |
| 240 |
fi |
| 241 |
elif test "`uname -s`" = "AIX" ; then |
| 242 |
soext="a" |
| 243 |
else |
| 244 |
soext="so" |
| 245 |
fi |
| 246 |
|
| 247 |
for dir in $ssl_lib_dirs; do |
| 248 |
if test -f "$dir/$ssl_lib.$soext"; then |
| 249 |
found_ssl=yes |
| 250 |
SSL_LIB_DIR="$dir" |
| 251 |
break |
| 252 |
fi |
| 253 |
done |
| 254 |
|
| 255 |
if test x_$found_ssl != x_yes; then |
| 256 |
AC_MSG_ERROR(Cannot find ssl libraries) |
| 257 |
else |
| 258 |
AC_MSG_RESULT(found in $SSL_LIB_DIR) |
| 259 |
|
| 260 |
LDFLAGS="$LDFLAGS -L$SSL_LIB_DIR"; |
| 261 |
LIBS="$LIBS -l`echo $ssl_lib | sed -e 's/^lib//'` -lcrypto"; |
| 262 |
AC_DEFINE_UNQUOTED(HAVE_SSL,[1],[Have SSL support]) |
| 263 |
fi |
| 264 |
fi |
| 265 |
fi |
| 266 |
|
| 267 |
if test x$found_ssl = xyes ; then |
| 268 |
if test -n "$SSL_INC_PREFIX" ; then |
| 269 |
SSL_INC_PREFIX="${SSL_INC_PREFIX}/" |
| 270 |
fi |
| 271 |
|
| 272 |
# try to compile and link to see if SSL is set up properly |
| 273 |
AC_MSG_CHECKING([whether compiling and linking against SSL works]) |
| 274 |
|
| 275 |
AC_LINK_IFELSE( |
| 276 |
[AC_LANG_PROGRAM([#include <${SSL_INC_PREFIX}${SSL_HDR}>], [SSL_new(NULL)])], |
| 277 |
[ |
| 278 |
AC_MSG_RESULT([yes]) |
| 279 |
$1 |
| 280 |
], [ |
| 281 |
AC_MSG_ERROR([no]) |
| 282 |
$2 |
| 283 |
]) |
| 284 |
fi |
| 285 |
|
| 286 |
if test x$found_ssl = xyes -a x$need_dh = xyes; then |
| 287 |
|
| 288 |
# Find the openssl program |
| 289 |
|
| 290 |
if test x$need_dh = xyes; then |
| 291 |
AC_PATH_PROG(sslbin,openssl,value-if-not-found,$ssl_dir/sbin$PATH_SEPARATOR$ssl_dir/bin$PATH_SEPARATOR$PATH) |
| 292 |
AC_DEFINE(USE_SSL_DH, [], [Use DH parameters for SSL/TLS]) |
| 293 |
# Generate DH parameters |
| 294 |
if test -f "$sslbin"; then |
| 295 |
echo "" |
| 296 |
echo "*** Generating DH Parameters for SSL/TLS ***" |
| 297 |
# awk to strip off meta data at bottom of dhparam output |
| 298 |
$sslbin dhparam -C 2048 | awk '/^-----/ {exit} {print}' > include/dh.h |
| 299 |
fi |
| 300 |
fi |
| 301 |
fi |
| 302 |
fi |
| 303 |
]) |