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