1 dnl Find the compiler and linker flags for Kerberos v5.
3 dnl Finds the compiler and linker flags for linking with Kerberos v5
4 dnl libraries. Provides the --with-krb5, --with-krb5-include, and
5 dnl --with-krb5-lib configure options to specify non-standard paths to the
6 dnl Kerberos libraries. Uses krb5-config where available unless reduced
7 dnl dependencies is requested.
9 dnl Provides the macro RRA_LIB_KRB5 and sets the substitution variables
10 dnl KRB5_CPPFLAGS, KRB5_LDFLAGS, and KRB5_LIBS. Also provides
11 dnl RRA_LIB_KRB5_SWITCH to set CPPFLAGS, LDFLAGS, and LIBS to include the
12 dnl Kerberos libraries, saving the current values first, and
13 dnl RRA_LIB_KRB5_RESTORE to restore those settings to before the last
14 dnl RRA_LIB_KRB5_SWITCH.
16 dnl If KRB5_CPPFLAGS, KRB5_LDFLAGS, or KRB5_LIBS are set before calling these
17 dnl macros, their values will be added to whatever the macros discover.
19 dnl Provides the RRA_LIB_KRB5_OPTIONAL macro, which should be used if Kerberos
20 dnl support is optional. This macro will still always set the substitution
21 dnl variables, but they'll be empty unless --with-krb5 is given. Also,
22 dnl HAVE_KERBEROS will be defined if --with-krb5 is given and
23 dnl $rra_use_kerberos will be set to "true".
25 dnl Sets the Automake conditional KRB5_USES_COM_ERR saying whether we use
26 dnl com_err, since if we're also linking with AFS libraries, we may have to
27 dnl change library ordering in that case.
29 dnl Depends on RRA_ENABLE_REDUCED_DEPENDS and RRA_SET_LDFLAGS.
31 dnl Written by Russ Allbery <rra@stanford.edu>
32 dnl Copyright 2005, 2006, 2007, 2008, 2009, 2010
33 dnl Board of Trustees, Leland Stanford Jr. University
35 dnl See LICENSE for licensing terms.
37 dnl Save the current CPPFLAGS, LDFLAGS, and LIBS settings and switch to
38 dnl versions that include the Kerberos v5 flags. Used as a wrapper, with
39 dnl RRA_LIB_KRB5_RESTORE, around tests.
40 AC_DEFUN([RRA_LIB_KRB5_SWITCH],
41 [rra_krb5_save_CPPFLAGS="$CPPFLAGS"
42 rra_krb5_save_LDFLAGS="$LDFLAGS"
43 rra_krb5_save_LIBS="$LIBS"
44 CPPFLAGS="$KRB5_CPPFLAGS $CPPFLAGS"
45 LDFLAGS="$KRB5_LDFLAGS $LDFLAGS"
46 LIBS="$KRB5_LIBS $LIBS"])
48 dnl Restore CPPFLAGS, LDFLAGS, and LIBS to their previous values (before
49 dnl RRA_LIB_KRB5_SWITCH was called).
50 AC_DEFUN([RRA_LIB_KRB5_RESTORE],
51 [CPPFLAGS="$rra_krb5_save_CPPFLAGS"
52 LDFLAGS="$rra_krb5_save_LDFLAGS"
53 LIBS="$rra_krb5_save_LIBS"])
55 dnl Set KRB5_CPPFLAGS and KRB5_LDFLAGS based on rra_krb5_root,
56 dnl rra_krb5_libdir, and rra_krb5_includedir.
57 AC_DEFUN([_RRA_LIB_KRB5_PATHS],
58 [AS_IF([test x"$rra_krb5_libdir" != x],
59 [KRB5_LDFLAGS="-L$rra_krb5_libdir"],
60 [AS_IF([test x"$rra_krb5_root" != x],
61 [RRA_SET_LDFLAGS([KRB5_LDFLAGS], [$rra_krb5_root])])])
62 AS_IF([test x"$rra_krb5_includedir" != x],
63 [KRB5_CPPFLAGS="-I$rra_krb5_includedir"],
64 [AS_IF([test x"$rra_krb5_root" != x],
65 [AS_IF([test x"$rra_krb5_root" != x/usr],
66 [KRB5_CPPFLAGS="-I${rra_krb5_root}/include"])])])])
68 dnl Does the appropriate library checks for reduced-dependency Kerberos v5
69 dnl linkage. The single argument, if true, says to fail if Kerberos could not
71 AC_DEFUN([_RRA_LIB_KRB5_REDUCED],
73 AC_CHECK_LIB([krb5], [krb5_init_context], [KRB5_LIBS="-lkrb5"],
74 [AS_IF([test x"$1" = xtrue],
75 [AC_MSG_ERROR([cannot find usable Kerberos v5 library])])])
76 LIBS="$KRB5_LIBS $LIBS"
77 AC_CHECK_FUNCS([krb5_get_error_message],
78 [AC_CHECK_FUNCS([krb5_free_error_message])],
79 [AC_CHECK_FUNCS([krb5_get_error_string], ,
80 [AC_CHECK_FUNCS([krb5_get_err_txt], ,
81 [AC_CHECK_LIB([ksvc], [krb5_svc_get_msg],
82 [KRB5_LIBS="$KRB5_LIBS -lksvc"
83 AC_DEFINE([HAVE_KRB5_SVC_GET_MSG], [1])
84 AC_CHECK_HEADERS([ibm_svc/krb5_svc.h])],
85 [AC_CHECK_LIB([com_err], [com_err],
86 [KRB5_LIBS="$KRB5_LIBS -lcom_err"],
87 [AC_MSG_ERROR([cannot find usable com_err library])])
88 AC_CHECK_HEADERS([et/com_err.h])])])])])
89 RRA_LIB_KRB5_RESTORE])
91 dnl Does the appropriate library checks for Kerberos v5 linkage when we don't
92 dnl have krb5-config or reduced dependencies. The single argument, if true,
93 dnl says to fail if Kerberos could not be found.
94 AC_DEFUN([_RRA_LIB_KRB5_MANUAL],
98 AC_SEARCH_LIBS([res_search], [resolv], ,
99 [AC_SEARCH_LIBS([__res_search], [resolv])])
100 AC_SEARCH_LIBS([gethostbyname], [nsl])
101 AC_SEARCH_LIBS([socket], [socket], ,
102 [AC_CHECK_LIB([nsl], [socket], [LIBS="-lnsl -lsocket $LIBS"], ,
104 AC_SEARCH_LIBS([crypt], [crypt])
105 AC_SEARCH_LIBS([rk_simple_execve], [roken])
106 rra_krb5_extra="$LIBS"
107 LIBS="$rra_krb5_save_LIBS"
108 AC_CHECK_LIB([krb5], [krb5_init_context],
109 [KRB5_LIBS="-lkrb5 -lasn1 -lcom_err -lcrypto $rra_krb5_extra"],
110 [AC_CHECK_LIB([krb5support], [krb5int_getspecific],
111 [rra_krb5_extra="-lkrb5support $rra_krb5_extra"],
112 [AC_CHECK_LIB([pthreads], [pthread_setspecific],
113 [rra_krb5_pthread="-lpthreads"],
114 [AC_CHECK_LIB([pthread], [pthread_setspecific],
115 [rra_krb5_pthread="-lpthread"])])
116 AC_CHECK_LIB([krb5support], [krb5int_setspecific],
117 [rra_krb5_extra="-lkrb5support $rra_krb5_extra $rra_krb5_pthread"],
118 , [$rra_krb5_pthread])])
119 AC_CHECK_LIB([com_err], [error_message],
120 [rra_krb5_extra="-lcom_err $rra_krb5_extra"])
121 AC_CHECK_LIB([ksvc], [krb5_svc_get_msg],
122 [rra_krb5_extra="-lksvc $rra_krb5_extra"])
123 AC_CHECK_LIB([k5crypto], [krb5int_hash_md5],
124 [rra_krb5_extra="-lk5crypto $rra_krb5_extra"])
125 AC_CHECK_LIB([k5profile], [profile_get_values],
126 [rra_krb5_extra="-lk5profile $rra_krb5_extra"])
127 AC_CHECK_LIB([krb5], [krb5_cc_default],
128 [KRB5_LIBS="-lkrb5 $rra_krb5_extra"],
129 [AS_IF([test x"$1" = xtrue],
130 [AC_MSG_ERROR([cannot find usable Kerberos v5 library])])],
132 [-lasn1 -lcom_err -lcrypto $rra_krb5_extra])
133 LIBS="$KRB5_LIBS $LIBS"
134 AC_CHECK_FUNCS([krb5_get_error_message],
135 [AC_CHECK_FUNCS([krb5_free_error_message])],
136 [AC_CHECK_FUNCS([krb5_get_error_string], ,
137 [AC_CHECK_FUNCS([krb5_get_err_txt], ,
138 [AC_CHECK_FUNCS([krb5_svc_get_msg],
139 [AC_CHECK_HEADERS([ibm_svc/krb5_svc.h])],
140 [AC_CHECK_HEADERS([et/com_err.h])])])])])
141 RRA_LIB_KRB5_RESTORE])
143 dnl Sanity-check the results of krb5-config and be sure we can really link a
144 dnl Kerberos program. If that fails, clear KRB5_CPPFLAGS and KRB5_LIBS so
145 dnl that we know we don't have usable flags and fall back on the manual
147 AC_DEFUN([_RRA_LIB_KRB5_CHECK],
149 AC_CHECK_FUNC([krb5_init_context],
150 [RRA_LIB_KRB5_RESTORE],
151 [RRA_LIB_KRB5_RESTORE
155 _RRA_LIB_KRB5_MANUAL([$1])])])
157 dnl The core of the library checking, shared between RRA_LIB_KRB5 and
158 dnl RRA_LIB_KRB5_OPTIONAL. The single argument, if "true", says to fail if
159 dnl Kerberos could not be found.
160 AC_DEFUN([_RRA_LIB_KRB5_INTERNAL],
161 [AC_REQUIRE([RRA_ENABLE_REDUCED_DEPENDS])
162 AS_IF([test x"$rra_reduced_depends" = xtrue],
164 _RRA_LIB_KRB5_REDUCED([$1])],
165 [AC_ARG_VAR([KRB5_CONFIG], [Path to krb5-config])
166 AS_IF([test x"$rra_krb5_root" != x && test -z "$KRB5_CONFIG"],
167 [AS_IF([test -x "${rra_krb5_root}/bin/krb5-config"],
168 [KRB5_CONFIG="${rra_krb5_root}/bin/krb5-config"])],
169 [AC_PATH_PROG([KRB5_CONFIG], [krb5-config])])
170 AS_IF([test x"$KRB5_CONFIG" != x && test -x "$KRB5_CONFIG"],
171 [AC_CACHE_CHECK([for krb5 support in krb5-config],
172 [rra_cv_lib_krb5_config],
173 [AS_IF(["$KRB5_CONFIG" 2>&1 | grep krb5 >/dev/null 2>&1],
174 [rra_cv_lib_krb5_config=yes],
175 [rra_cv_lib_krb5_config=no])])
176 AS_IF([test x"$rra_cv_lib_krb5_config" = xyes],
177 [KRB5_CPPFLAGS=`"$KRB5_CONFIG" --cflags krb5 2>/dev/null`
178 KRB5_LIBS=`"$KRB5_CONFIG" --libs krb5 2>/dev/null`],
179 [KRB5_CPPFLAGS=`"$KRB5_CONFIG" --cflags 2>/dev/null`
180 KRB5_LIBS=`"$KRB5_CONFIG" --libs 2>/dev/null`])
181 KRB5_CPPFLAGS=`echo "$KRB5_CPPFLAGS" | sed 's%-I/usr/include ?%%'`
182 _RRA_LIB_KRB5_CHECK([$1])
184 AC_CHECK_FUNCS([krb5_get_error_message],
185 [AC_CHECK_FUNCS([krb5_free_error_message])],
186 [AC_CHECK_FUNCS([krb5_get_error_string], ,
187 [AC_CHECK_FUNCS([krb5_get_err_txt], ,
188 [AC_CHECK_FUNCS([krb5_svc_get_msg],
189 [AC_CHECK_HEADERS([ibm_svc/krb5_svc.h])],
190 [AC_CHECK_HEADERS([et/com_err.h])])])])])
191 RRA_LIB_KRB5_RESTORE],
193 _RRA_LIB_KRB5_MANUAL([$1])])])
194 rra_krb5_uses_com_err=false
197 rra_krb5_uses_com_err=true
200 AM_CONDITIONAL([KRB5_USES_COM_ERR], [test x"$rra_krb5_uses_com_err" = xtrue])])
202 dnl The main macro for packages with mandatory Kerberos support.
203 AC_DEFUN([RRA_LIB_KRB5],
207 AC_SUBST([KRB5_CPPFLAGS])
208 AC_SUBST([KRB5_LDFLAGS])
209 AC_SUBST([KRB5_LIBS])
212 [AS_HELP_STRING([--with-krb5=DIR],
213 [Location of Kerberos v5 headers and libraries])],
214 [AS_IF([test x"$withval" != xyes && test x"$withval" != xno],
215 [rra_krb5_root="$withval"])])
216 AC_ARG_WITH([krb5-include],
217 [AS_HELP_STRING([--with-krb5-include=DIR],
218 [Location of Kerberos v5 headers])],
219 [AS_IF([test x"$withval" != xyes && test x"$withval" != xno],
220 [rra_krb5_includedir="$withval"])])
221 AC_ARG_WITH([krb5-lib],
222 [AS_HELP_STRING([--with-krb5-lib=DIR],
223 [Location of Kerberos v5 libraries])],
224 [AS_IF([test x"$withval" != xyes && test x"$withval" != xno],
225 [rra_krb5_libdir="$withval"])])
226 _RRA_LIB_KRB5_INTERNAL([true])])
228 dnl The main macro for packages with optional Kerberos support.
229 AC_DEFUN([RRA_LIB_KRB5_OPTIONAL],
234 AC_SUBST([KRB5_CPPFLAGS])
235 AC_SUBST([KRB5_LDFLAGS])
236 AC_SUBST([KRB5_LIBS])
239 [AS_HELP_STRING([--with-krb5@<:@=DIR@:>@],
240 [Location of Kerberos v5 headers and libraries])],
241 [AS_IF([test x"$withval" = xno],
242 [rra_use_kerberos=false],
243 [AS_IF([test x"$withval" != xyes], [rra_krb5_root="$withval"])
244 rra_use_kerberos=true])])
245 AC_ARG_WITH([krb5-include],
246 [AS_HELP_STRING([--with-krb5-include=DIR],
247 [Location of Kerberos v5 headers])],
248 [AS_IF([test x"$withval" != xyes && test x"$withval" != xno],
249 [rra_krb5_includedir="$withval"])])
250 AC_ARG_WITH([krb5-lib],
251 [AS_HELP_STRING([--with-krb5-lib=DIR],
252 [Location of Kerberos v5 libraries])],
253 [AS_IF([test x"$withval" != xyes && test x"$withval" != xno],
254 [rra_krb5_libdir="$withval"])])
256 AS_IF([test x"$rra_use_kerberos" != xfalse],
257 [AS_IF([test x"$rra_use_kerberos" = xtrue],
258 [_RRA_LIB_KRB5_INTERNAL([true])],
259 [_RRA_LIB_KRB5_INTERNAL([false])])])
260 AS_IF([test x"$KRB5_LIBS" != x],
261 [AC_DEFINE([HAVE_KERBEROS], 1, [Define to enable Kerberos features.])])])