Import Upstream version 1.8.5
[hcoop/debian/openafs.git] / src / external / rra-c-util / m4 / krb5.m4
1 dnl Find the compiler and linker flags for Kerberos.
2 dnl
3 dnl Finds the compiler and linker flags for linking with Kerberos libraries.
4 dnl Provides the --with-krb5, --with-krb5-include, and --with-krb5-lib
5 dnl configure options to specify non-standard paths to the Kerberos libraries.
6 dnl Uses krb5-config where available unless reduced dependencies is requested
7 dnl or --with-krb5-include or --with-krb5-lib are given.
8 dnl
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. HAVE_KERBEROS will always be defined if RRA_LIB_KRB5
15 dnl is used.
16 dnl
17 dnl If KRB5_CPPFLAGS, KRB5_LDFLAGS, or KRB5_LIBS are set before calling these
18 dnl macros, their values will be added to whatever the macros discover.
19 dnl
20 dnl Provides the RRA_LIB_KRB5_OPTIONAL macro, which should be used if Kerberos
21 dnl support is optional. This macro will still always set the substitution
22 dnl variables, but they'll be empty unless --with-krb5 is given. Also,
23 dnl HAVE_KERBEROS will be defined if --with-krb5 is given and
24 dnl $rra_use_kerberos will be set to "true".
25 dnl
26 dnl Sets the Automake conditional KRB5_USES_COM_ERR saying whether we use
27 dnl com_err, since if we're also linking with AFS libraries, we may have to
28 dnl change library ordering in that case.
29 dnl
30 dnl Depends on RRA_ENABLE_REDUCED_DEPENDS and RRA_SET_LDFLAGS.
31 dnl
32 dnl Also provides RRA_FUNC_KRB5_GET_INIT_CREDS_OPT_FREE_ARGS, which checks
33 dnl whether krb5_get_init_creds_opt_free takes one argument or two. Defines
34 dnl HAVE_KRB5_GET_INIT_CREDS_OPT_FREE_2_ARGS if it takes two arguments.
35 dnl
36 dnl Also provides RRA_INCLUDES_KRB5, which are the headers to include when
37 dnl probing the Kerberos library properties.
38 dnl
39 dnl The canonical version of this file is maintained in the rra-c-util
40 dnl package, available at <http://www.eyrie.org/~eagle/software/rra-c-util/>.
41 dnl
42 dnl Written by Russ Allbery <rra@stanford.edu>
43 dnl Copyright 2005, 2006, 2007, 2008, 2009, 2010, 2011
44 dnl The Board of Trustees of the Leland Stanford Junior University
45 dnl
46 dnl This file is free software; the authors give unlimited permission to copy
47 dnl and/or distribute it, with or without modifications, as long as this
48 dnl notice is preserved.
49
50 dnl Headers to include when probing for Kerberos library properties.
51 AC_DEFUN([RRA_INCLUDES_KRB5], [[
52 #if HAVE_KRB5_H
53 # include <krb5.h>
54 #else
55 # include <krb5/krb5.h>
56 #endif
57 ]])
58
59 dnl Save the current CPPFLAGS, LDFLAGS, and LIBS settings and switch to
60 dnl versions that include the Kerberos flags. Used as a wrapper, with
61 dnl RRA_LIB_KRB5_RESTORE, around tests.
62 AC_DEFUN([RRA_LIB_KRB5_SWITCH],
63 [rra_krb5_save_CPPFLAGS="$CPPFLAGS"
64 rra_krb5_save_LDFLAGS="$LDFLAGS"
65 rra_krb5_save_LIBS="$LIBS"
66 CPPFLAGS="$KRB5_CPPFLAGS $CPPFLAGS"
67 LDFLAGS="$KRB5_LDFLAGS $LDFLAGS"
68 LIBS="$KRB5_LIBS $LIBS"])
69
70 dnl Restore CPPFLAGS, LDFLAGS, and LIBS to their previous values (before
71 dnl RRA_LIB_KRB5_SWITCH was called).
72 AC_DEFUN([RRA_LIB_KRB5_RESTORE],
73 [CPPFLAGS="$rra_krb5_save_CPPFLAGS"
74 LDFLAGS="$rra_krb5_save_LDFLAGS"
75 LIBS="$rra_krb5_save_LIBS"])
76
77 dnl Set KRB5_CPPFLAGS and KRB5_LDFLAGS based on rra_krb5_root,
78 dnl rra_krb5_libdir, and rra_krb5_includedir.
79 AC_DEFUN([_RRA_LIB_KRB5_PATHS],
80 [AS_IF([test x"$rra_krb5_libdir" != x],
81 [KRB5_LDFLAGS="-L$rra_krb5_libdir"],
82 [AS_IF([test x"$rra_krb5_root" != x],
83 [RRA_SET_LDFLAGS([KRB5_LDFLAGS], [$rra_krb5_root])])])
84 AS_IF([test x"$rra_krb5_includedir" != x],
85 [KRB5_CPPFLAGS="-I$rra_krb5_includedir"],
86 [AS_IF([test x"$rra_krb5_root" != x],
87 [AS_IF([test x"$rra_krb5_root" != x/usr],
88 [KRB5_CPPFLAGS="-I${rra_krb5_root}/include"])])])])
89
90 dnl Does the appropriate library checks for reduced-dependency Kerberos
91 dnl linkage. The single argument, if true, says to fail if Kerberos could not
92 dnl be found.
93 AC_DEFUN([_RRA_LIB_KRB5_REDUCED],
94 [RRA_LIB_KRB5_SWITCH
95 AC_CHECK_LIB([krb5], [krb5_init_context], [KRB5_LIBS="-lkrb5"],
96 [AS_IF([test x"$1" = xtrue],
97 [AC_MSG_ERROR([cannot find usable Kerberos library])])])
98 LIBS="$KRB5_LIBS $LIBS"
99 AC_CHECK_HEADERS([krb5.h krb5/krb5.h])
100 AC_CHECK_FUNCS([krb5_get_error_message],
101 [AC_CHECK_FUNCS([krb5_free_error_message])],
102 [AC_CHECK_FUNCS([krb5_get_error_string], [],
103 [AC_CHECK_FUNCS([krb5_get_err_txt], [],
104 [AC_CHECK_LIB([ksvc], [krb5_svc_get_msg],
105 [KRB5_LIBS="$KRB5_LIBS -lksvc"
106 AC_DEFINE([HAVE_KRB5_SVC_GET_MSG], [1])
107 AC_CHECK_HEADERS([ibm_svc/krb5_svc.h], [], [],
108 [RRA_INCLUDES_KRB5])],
109 [AC_CHECK_LIB([com_err], [com_err],
110 [KRB5_LIBS="$KRB5_LIBS -lcom_err"],
111 [AC_MSG_ERROR([cannot find usable com_err library])])
112 AC_CHECK_HEADERS([et/com_err.h])])])])])
113 RRA_LIB_KRB5_RESTORE])
114
115 dnl Does the appropriate library checks for Kerberos linkage when we don't
116 dnl have krb5-config or reduced dependencies. The single argument, if true,
117 dnl says to fail if Kerberos could not be found.
118 AC_DEFUN([_RRA_LIB_KRB5_MANUAL],
119 [RRA_LIB_KRB5_SWITCH
120 rra_krb5_extra=
121 LIBS=
122 AC_SEARCH_LIBS([res_search], [resolv], [],
123 [AC_SEARCH_LIBS([__res_search], [resolv])])
124 AC_SEARCH_LIBS([gethostbyname], [nsl])
125 AC_SEARCH_LIBS([socket], [socket], [],
126 [AC_CHECK_LIB([nsl], [socket], [LIBS="-lnsl -lsocket $LIBS"], [],
127 [-lsocket])])
128 AC_SEARCH_LIBS([crypt], [crypt])
129 AC_SEARCH_LIBS([rk_simple_execve], [roken])
130 rra_krb5_extra="$LIBS"
131 LIBS="$rra_krb5_save_LIBS"
132 AC_CHECK_LIB([krb5], [krb5_init_context],
133 [KRB5_LIBS="-lkrb5 -lasn1 -lcom_err -lcrypto $rra_krb5_extra"],
134 [AC_CHECK_LIB([krb5support], [krb5int_getspecific],
135 [rra_krb5_extra="-lkrb5support $rra_krb5_extra"],
136 [AC_CHECK_LIB([pthreads], [pthread_setspecific],
137 [rra_krb5_pthread="-lpthreads"],
138 [AC_CHECK_LIB([pthread], [pthread_setspecific],
139 [rra_krb5_pthread="-lpthread"])])
140 AC_CHECK_LIB([krb5support], [krb5int_setspecific],
141 [rra_krb5_extra="-lkrb5support $rra_krb5_extra $rra_krb5_pthread"],
142 [], [$rra_krb5_pthread $rra_krb5_extra])],
143 [$rra_krb5_extra])
144 AC_CHECK_LIB([com_err], [error_message],
145 [rra_krb5_extra="-lcom_err $rra_krb5_extra"], [], [$rra_krb5_extra])
146 AC_CHECK_LIB([ksvc], [krb5_svc_get_msg],
147 [rra_krb5_extra="-lksvc $rra_krb5_extra"], [], [$rra_krb5_extra])
148 AC_CHECK_LIB([k5crypto], [krb5int_hash_md5],
149 [rra_krb5_extra="-lk5crypto $rra_krb5_extra"], [], [$rra_krb5_extra])
150 AC_CHECK_LIB([k5profile], [profile_get_values],
151 [rra_krb5_extra="-lk5profile $rra_krb5_extra"], [], [$rra_krb5_extra])
152 AC_CHECK_LIB([krb5], [krb5_cc_default],
153 [KRB5_LIBS="-lkrb5 $rra_krb5_extra"],
154 [AS_IF([test x"$1" = xtrue],
155 [AC_MSG_ERROR([cannot find usable Kerberos library])])],
156 [$rra_krb5_extra])],
157 [-lasn1 -lcom_err -lcrypto $rra_krb5_extra])
158 LIBS="$KRB5_LIBS $LIBS"
159 AC_CHECK_HEADERS([krb5.h krb5/krb5.h])
160 AC_CHECK_FUNCS([krb5_get_error_message],
161 [AC_CHECK_FUNCS([krb5_free_error_message])],
162 [AC_CHECK_FUNCS([krb5_get_error_string], [],
163 [AC_CHECK_FUNCS([krb5_get_err_txt], [],
164 [AC_CHECK_FUNCS([krb5_svc_get_msg],
165 [AC_CHECK_HEADERS([ibm_svc/krb5_svc.h], [], [],
166 [RRA_INCLUDES_KRB5])],
167 [AC_CHECK_HEADERS([et/com_err.h])])])])])
168 RRA_LIB_KRB5_RESTORE])
169
170 dnl Sanity-check the results of krb5-config and be sure we can really link a
171 dnl Kerberos program. If that fails, clear KRB5_CPPFLAGS and KRB5_LIBS so
172 dnl that we know we don't have usable flags and fall back on the manual
173 dnl check.
174 AC_DEFUN([_RRA_LIB_KRB5_CHECK],
175 [RRA_LIB_KRB5_SWITCH
176 AC_CHECK_FUNC([krb5_init_context],
177 [RRA_LIB_KRB5_RESTORE],
178 [RRA_LIB_KRB5_RESTORE
179 KRB5_CPPFLAGS=
180 KRB5_LIBS=
181 _RRA_LIB_KRB5_PATHS
182 _RRA_LIB_KRB5_MANUAL([$1])])])
183
184 dnl Determine Kerberos compiler and linker flags from krb5-config. Does the
185 dnl additional probing we need to do to uncover error handling features, and
186 dnl falls back on the manual checks.
187 AC_DEFUN([_RRA_LIB_KRB5_CONFIG],
188 [RRA_KRB5_CONFIG([${rra_krb5_root}], [krb5], [KRB5],
189 [_RRA_LIB_KRB5_CHECK([$1])
190 RRA_LIB_KRB5_SWITCH
191 AC_CHECK_HEADERS([krb5.h krb5/krb5.h])
192 AC_CHECK_FUNCS([krb5_get_error_message],
193 [AC_CHECK_FUNCS([krb5_free_error_message])],
194 [AC_CHECK_FUNCS([krb5_get_error_string], [],
195 [AC_CHECK_FUNCS([krb5_get_err_txt], [],
196 [AC_CHECK_FUNCS([krb5_svc_get_msg],
197 [AC_CHECK_HEADERS([ibm_svc/krb5_svc.h], [], [],
198 [RRA_INCLUDES_KRB5])],
199 [AC_CHECK_HEADERS([et/com_err.h])])])])])
200 RRA_LIB_KRB5_RESTORE],
201 [_RRA_LIB_KRB5_PATHS
202 _RRA_LIB_KRB5_MANUAL([$1])])])
203
204 dnl The core of the library checking, shared between RRA_LIB_KRB5 and
205 dnl RRA_LIB_KRB5_OPTIONAL. The single argument, if "true", says to fail if
206 dnl Kerberos could not be found.
207 AC_DEFUN([_RRA_LIB_KRB5_INTERNAL],
208 [AC_REQUIRE([RRA_ENABLE_REDUCED_DEPENDS])
209 AS_IF([test x"$rra_reduced_depends" = xtrue],
210 [_RRA_LIB_KRB5_PATHS
211 _RRA_LIB_KRB5_REDUCED([$1])],
212 [AS_IF([test x"$rra_krb5_includedir" = x && test x"$rra_krb5_libdir" = x],
213 [_RRA_LIB_KRB5_CONFIG([$1])],
214 [_RRA_LIB_KRB5_PATHS
215 _RRA_LIB_KRB5_MANUAL([$1])])])
216 rra_krb5_uses_com_err=false
217 AS_CASE([$LIBS], [*-lcom_err*], [rra_krb5_uses_com_err=true])
218 AM_CONDITIONAL([KRB5_USES_COM_ERR], [test x"$rra_krb5_uses_com_err" = xtrue])])
219
220 dnl The main macro for packages with mandatory Kerberos support.
221 AC_DEFUN([RRA_LIB_KRB5],
222 [rra_krb5_root=
223 rra_krb5_libdir=
224 rra_krb5_includedir=
225 rra_use_kerberos=true
226 AC_SUBST([KRB5_CPPFLAGS])
227 AC_SUBST([KRB5_LDFLAGS])
228 AC_SUBST([KRB5_LIBS])
229
230 AC_ARG_WITH([krb5],
231 [AS_HELP_STRING([--with-krb5=DIR],
232 [Location of Kerberos headers and libraries])],
233 [AS_IF([test x"$withval" != xyes && test x"$withval" != xno],
234 [rra_krb5_root="$withval"])])
235 AC_ARG_WITH([krb5-include],
236 [AS_HELP_STRING([--with-krb5-include=DIR],
237 [Location of Kerberos headers])],
238 [AS_IF([test x"$withval" != xyes && test x"$withval" != xno],
239 [rra_krb5_includedir="$withval"])])
240 AC_ARG_WITH([krb5-lib],
241 [AS_HELP_STRING([--with-krb5-lib=DIR],
242 [Location of Kerberos libraries])],
243 [AS_IF([test x"$withval" != xyes && test x"$withval" != xno],
244 [rra_krb5_libdir="$withval"])])
245 _RRA_LIB_KRB5_INTERNAL([true])
246 AC_DEFINE([HAVE_KERBEROS], 1, [Define to enable Kerberos features.])])
247
248 dnl The main macro for packages with optional Kerberos support.
249 AC_DEFUN([RRA_LIB_KRB5_OPTIONAL],
250 [rra_krb5_root=
251 rra_krb5_libdir=
252 rra_krb5_includedir=
253 rra_use_kerberos=
254 AC_SUBST([KRB5_CPPFLAGS])
255 AC_SUBST([KRB5_LDFLAGS])
256 AC_SUBST([KRB5_LIBS])
257
258 AC_ARG_WITH([krb5],
259 [AS_HELP_STRING([--with-krb5@<:@=DIR@:>@],
260 [Location of Kerberos headers and libraries])],
261 [AS_IF([test x"$withval" = xno],
262 [rra_use_kerberos=false],
263 [AS_IF([test x"$withval" != xyes], [rra_krb5_root="$withval"])
264 rra_use_kerberos=true])])
265 AC_ARG_WITH([krb5-include],
266 [AS_HELP_STRING([--with-krb5-include=DIR],
267 [Location of Kerberos headers])],
268 [AS_IF([test x"$withval" != xyes && test x"$withval" != xno],
269 [rra_krb5_includedir="$withval"])])
270 AC_ARG_WITH([krb5-lib],
271 [AS_HELP_STRING([--with-krb5-lib=DIR],
272 [Location of Kerberos libraries])],
273 [AS_IF([test x"$withval" != xyes && test x"$withval" != xno],
274 [rra_krb5_libdir="$withval"])])
275
276 AS_IF([test x"$rra_use_kerberos" != xfalse],
277 [AS_IF([test x"$rra_use_kerberos" = xtrue],
278 [_RRA_LIB_KRB5_INTERNAL([true])],
279 [_RRA_LIB_KRB5_INTERNAL([false])])],
280 [AM_CONDITIONAL([KRB5_USES_COM_ERR], [false])])
281 AS_IF([test x"$KRB5_LIBS" != x],
282 [AC_DEFINE([HAVE_KERBEROS], 1, [Define to enable Kerberos features.])])])
283
284 dnl Source used by RRA_FUNC_KRB5_GET_INIT_CREDS_OPT_FREE_ARGS.
285 AC_DEFUN([_RRA_FUNC_KRB5_OPT_FREE_ARGS_SOURCE], [RRA_INCLUDES_KRB5] [[
286 int
287 main(void)
288 {
289 krb5_get_init_creds_opt *opts;
290 krb5_context c;
291 krb5_get_init_creds_opt_free(c, opts);
292 }
293 ]])
294
295 dnl Check whether krb5_get_init_creds_opt_free takes one argument or two.
296 dnl Early Heimdal used to take a single argument. Defines
297 dnl HAVE_KRB5_GET_INIT_CREDS_OPT_FREE_2_ARGS if it takes two arguments.
298 dnl
299 dnl Should be called with RRA_LIB_KRB5_SWITCH active.
300 AC_DEFUN([RRA_FUNC_KRB5_GET_INIT_CREDS_OPT_FREE_ARGS],
301 [AC_CACHE_CHECK([if krb5_get_init_creds_opt_free takes two arguments],
302 [rra_cv_func_krb5_get_init_creds_opt_free_args],
303 [AC_COMPILE_IFELSE([AC_LANG_SOURCE([_RRA_FUNC_KRB5_OPT_FREE_ARGS_SOURCE])],
304 [rra_cv_func_krb5_get_init_creds_opt_free_args=yes],
305 [rra_cv_func_krb5_get_init_creds_opt_free_args=no])])
306 AS_IF([test $rra_cv_func_krb5_get_init_creds_opt_free_args = yes],
307 [AC_DEFINE([HAVE_KRB5_GET_INIT_CREDS_OPT_FREE_2_ARGS], 1,
308 [Define if krb5_get_init_creds_opt_free takes two arguments.])])])