abed071102f7090b1cbc60ce28af6bcc1c03b6c0
[freeradius.git] / src / modules / rlm_krb5 / configure.ac
1 AC_PREREQ([2.53])
2 AC_INIT(rlm_krb5.c)
3 AC_REVISION($Revision$)
4 AC_DEFUN(modname,[rlm_krb5])
5
6 if test x$with_[]modname != xno; then
7
8         AC_PROG_CC
9         AC_PROG_CPP
10
11         dnl extra argument: --with-rlm-krb5-dir
12         rlm_krb5_dir=
13         AC_ARG_WITH(rlm-krb5-dir,
14         [  --with-rlm-krb5-dir=DIR       Directory for krb5 files []],
15         [ case "$withval" in
16             no)
17                 AC_MSG_ERROR(Need rlm-krb5-dir)
18                 ;;
19             yes)
20                 ;;
21             *)
22                 rlm_krb5_dir="$withval"
23                 ;;
24           esac ]
25         )
26
27         AC_PATH_PROG(krb5_config, krb5-config, not-found, [${rlm_krb5_dir}/bin:${PATH}:/usr/bin:/usr/local/bin])
28         dnl #
29         dnl # If we can find krb5-config we can get the version of the library and determine
30         dnl # whether it's safe to enable threading.
31         dnl #
32         if test "$krb5_config" != 'not-found'; then
33                 AC_MSG_CHECKING([krb5-config CFLAGS])
34                 SMART_CPPFLAGS=$($krb5_config --cflags)
35                 SMART_CPPFLAGS=[$(echo "$SMART_CPPFLAGS" | sed 's/-I[ ]*/-include /g')]
36                 AC_MSG_RESULT("$SMART_CPPFLAGS")
37
38                 AC_MSG_CHECKING([krb5-config LDFLAGS])
39                 SMART_LIBS=$($krb5_config --libs)
40                 AC_MSG_RESULT(${SMART_LIBS})
41
42                 AC_MSG_CHECKING([krb5-config reported version])
43                 krb5_version_raw=$($krb5_config --version)
44
45                 dnl # AWK originally from from https://github.com/hpc/lustre
46                 krb5_version=$(echo "$krb5_version_raw" | head -n 1 | \
47                         awk '{split($(4),v,"."); if (v@<:@"3"@:>@ == "") v@<:@"3"@:>@ = "0"; print v@<:@"1"@:>@v@<:@"2"@:>@v@<:@"3"@:>@ }')
48                 AC_MSG_RESULT([${krb5_version_raw} ($krb5_version)])
49
50                 AC_MSG_CHECKING([krb5-config reported vendor])
51                 krb5_vendor=$($krb5_config --vendor)
52                 AC_MSG_RESULT([${krb5_vendor}])
53
54                 AC_MSG_CHECKING([canonical API type])
55                 if test "$krb5_vendor" = "Massachusetts Institute of Technology" || \
56                         echo "$krb5_vendor" | grep -i 'MIT' > /dev/null 2>&1 || \
57                         echo "$krb5_version_raw" | grep -i 'MIT' > /dev/null 2>&1 ; then
58                         AC_MSG_RESULT([MIT])
59                         krb5_api_type='mit'
60                 else
61                         AC_MSG_RESULT([HEIMDAL])
62                         krb5_api_type='heimdal'
63                 fi
64         else
65                 smart_try_dir="$rlm_krb5_dir/include"
66                 FR_SMART_CHECK_INCLUDE(krb5.h)
67                 if test "$ac_cv_header_krb5_h" != "yes"; then
68                         fail="$fail krb5.h"
69                 fi
70
71                 krb5libcrypto=
72                 smart_try_dir="$rlm_krb5_dir/lib"
73                 FR_SMART_CHECK_LIB(k5crypto, krb5_encrypt_data)
74                 if test "x$ac_cv_lib_k5crypto_krb5_encrypt_data" = xyes; then
75                         krb5libcrypto="-lk5crypto"
76                 fi
77
78                 if test "x$krb5libcrypto" = x; then
79                         FR_SMART_CHECK_LIB(crypto, DH_new)
80                         if test "x$ac_cv_lib_crypto_DH_new" = xyes; then
81                                 krb5libcrypto="-lcrypto"
82                         fi
83                 fi
84
85                 if test "x$krb5libcrypto" = x; then
86                         AC_MSG_WARN([neither krb5 'k5crypto' nor 'crypto' libraries are found!])
87                 fi
88
89                 FR_SMART_CHECK_LIB(com_err, set_com_err_hook)
90                 if test "x$ac_cv_lib_com_err_set_com_err_hook" != xyes; then
91                         AC_MSG_WARN([the comm_err library isn't found!])
92                 fi
93
94                 dnl #
95                 dnl # Only the heimdal version of the library has this function
96                 dnl #
97                 FR_SMART_CHECK_LIB(krb5, krb5_verify_user_opt)
98                 if test "x$ac_cv_lib_krb5_krb5_verify_user_opt" == xyes; then
99                         krb5_api_type='heimdal'
100                 else
101                         krb5_api_type='mit'
102
103                         FR_SMART_CHECK_LIB(krb5, krb5_get_init_creds_password)
104                         if test "x$ac_cv_lib_krb5_krb5_get_init_creds_password" != xyes; then
105                             fail="$fail krb5"
106                         fi
107                 fi
108
109         fi
110
111         dnl #
112         dnl # Need to ensure the test program(s) link against the right library
113         dnl #
114         LDFLAGS="${LDFLAGS} ${SMART_LIBS}"
115         CFLAGS="${CFLAGS} ${SMART_CFLAGS}"
116
117         dnl #
118         dnl # Check how to free things returned by krb5_get_error_message
119         dnl #
120         AC_CHECK_FUNCS([krb5_get_error_message krb5_free_error_string krb5_free_error_message])
121         if test "x$ac_cv_func_krb5_get_error_message" == xyes; then
122                 krb5mod_cflags="${krb5mod_cflags} -D HAVE_KRB5_GET_ERROR_MESSAGE"
123         fi
124         if test "x$ac_cv_func_krb5_free_error_message" == xyes; then
125                 krb5mod_cflags="${krb5mod_cflags} -D HAVE_KRB5_FREE_ERROR_MESSAGE"
126         fi
127         if test "x$ac_cv_func_krb5_free_error_string" == xyes; then
128                 krb5mod_cflags="${krb5mod_cflags} -D HAVE_KRB5_FREE_ERROR_STRING"
129         fi
130
131         dnl #
132         dnl # Only check if version checks have not found kerberos to be thread unsafe
133         dnl #
134         if test "$krb5threadsafe" != "no"; then
135                 krb5threadsafe=
136
137                 FR_SMART_CHECK_LIB(krb5, krb5_is_thread_safe)
138                 if test "x$ac_cv_lib_krb5_krb5_is_thread_safe" == xyes; then
139                         AC_RUN_IFELSE([AC_LANG_PROGRAM([[#include <krb5.h>]], [[return krb5_is_thread_safe() ? 0 : 1]])],
140                                 [krb5threadsafe="-DKRB5_IS_THREAD_SAFE"], [AC_MSG_WARN([[libkrb5 is not threadsafe]])])
141                 fi
142         else
143                 krb5threadsafe=""
144         fi
145
146         if test "$krb5_api_type" == "mit"; then
147                 dnl #
148                 dnl # This lives in different places depending on the distro
149                 dnl #
150                 FR_SMART_CHECK_INCLUDE([com_err.h])
151                 if test "$ac_cv_header_com_err_h" != "yes"; then
152                         FR_SMART_CHECK_INCLUDE([et/com_err.h])
153                         if test "$ac_cv_header_et_com_err_h" != "yes"; then
154                                 fail="$fail com_err.h"
155                         else
156                                 krb5mod_cflags="$krb5mod_cflags -DET_COMM_ERR "
157                         fi
158                 fi
159         else
160                 krb5mod_cflags="$krb5mod_cflags -DHEIMDAL_KRB5"
161         fi
162         targetname=modname
163 else
164         targetname=
165         echo \*\*\* module modname is disabled.
166 fi
167
168 if test x"$fail" != x""; then
169         if test x"${enable_strict_dependencies}" = x"yes"; then
170                 AC_MSG_ERROR([set --without-]modname[ to disable it explicitly.])
171         else
172                 AC_MSG_WARN([silently not building ]modname[.])
173                 AC_MSG_WARN([FAILURE: ]modname[ requires: $fail.]);
174                 targetname=""
175         fi
176 fi
177
178 mod_ldflags="${krb5mod_ldflags} ${krb5libcrypto} ${SMART_LIBS}"
179 mod_cflags="${krb5mod_cflags} ${krb5threadsafe} ${SMART_CFLAGS}"
180
181 AC_SUBST(mod_ldflags)
182 AC_SUBST(mod_cflags)
183 AC_SUBST(targetname)
184 AC_OUTPUT(all.mk)