]> eyrie.org Git - kerberos/krb5-strength.git/blob - m4/krb5.m4
Add NEWS entry for cdbmake-wordlist improvements
[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_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 <eagle@eyrie.org>
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 Check for a header using a file existence check rather than using
91 dnl AC_CHECK_HEADERS.  This is used if there were arguments to configure
92 dnl specifying the Kerberos header path, since we may have one header in the
93 dnl default include path and another under our explicitly-configured Kerberos
94 dnl location.
95 AC_DEFUN([_RRA_LIB_KRB5_CHECK_HEADER],
96 [AC_MSG_CHECKING([for $1])
97  AS_IF([test -f "${rra_krb5_incroot}/$1"],
98     [AC_DEFINE_UNQUOTED(AS_TR_CPP([HAVE_$1]), [1],
99         [Define to 1 if you have the <$1> header file.])
100      AC_MSG_RESULT([yes])],
101     [AC_MSG_RESULT([no])])])
102
103 dnl Does the appropriate library checks for reduced-dependency Kerberos
104 dnl linkage.  The single argument, if true, says to fail if Kerberos could not
105 dnl be found.
106 AC_DEFUN([_RRA_LIB_KRB5_REDUCED],
107 [RRA_LIB_KRB5_SWITCH
108  AC_CHECK_LIB([krb5], [krb5_init_context], [KRB5_LIBS="-lkrb5"],
109      [AS_IF([test x"$1" = xtrue],
110          [AC_MSG_ERROR([cannot find usable Kerberos library])])])
111  LIBS="$KRB5_LIBS $LIBS"
112  AS_IF([test x"$rra_krb5_incroot" = x],
113      [AC_CHECK_HEADERS([krb5.h krb5/krb5.h])],
114      [_RRA_LIB_KRB5_CHECK_HEADER([krb5.h])
115       _RRA_LIB_KRB5_CHECK_HEADER([krb5/krb5.h])])
116  AC_CHECK_FUNCS([krb5_get_error_message],
117      [AC_CHECK_FUNCS([krb5_free_error_message])],
118      [AC_CHECK_FUNCS([krb5_get_error_string], [],
119          [AC_CHECK_FUNCS([krb5_get_err_txt], [],
120              [AC_CHECK_LIB([ksvc], [krb5_svc_get_msg],
121                  [KRB5_LIBS="$KRB5_LIBS -lksvc"
122                   AC_DEFINE([HAVE_KRB5_SVC_GET_MSG], [1])
123                   AC_CHECK_HEADERS([ibm_svc/krb5_svc.h], [], [],
124                      [RRA_INCLUDES_KRB5])],
125                  [AC_CHECK_LIB([com_err], [com_err],
126                      [KRB5_LIBS="$KRB5_LIBS -lcom_err"],
127                      [AC_MSG_ERROR([cannot find usable com_err library])])
128                   AC_CHECK_HEADERS([et/com_err.h])])])])])
129  RRA_LIB_KRB5_RESTORE])
130
131 dnl Does the appropriate library checks for Kerberos linkage when we don't
132 dnl have krb5-config or reduced dependencies.  The single argument, if true,
133 dnl says to fail if Kerberos could not be found.
134 AC_DEFUN([_RRA_LIB_KRB5_MANUAL],
135 [RRA_LIB_KRB5_SWITCH
136  rra_krb5_extra=
137  LIBS=
138  AC_SEARCH_LIBS([res_search], [resolv], [],
139     [AC_SEARCH_LIBS([__res_search], [resolv])])
140  AC_SEARCH_LIBS([gethostbyname], [nsl])
141  AC_SEARCH_LIBS([socket], [socket], [],
142     [AC_CHECK_LIB([nsl], [socket], [LIBS="-lnsl -lsocket $LIBS"], [],
143         [-lsocket])])
144  AC_SEARCH_LIBS([crypt], [crypt])
145  AC_SEARCH_LIBS([roken_concat], [roken])
146  rra_krb5_extra="$LIBS"
147  LIBS="$rra_krb5_save_LIBS"
148  AC_CHECK_LIB([krb5], [krb5_init_context],
149     [KRB5_LIBS="-lkrb5 -lasn1 -lcom_err -lcrypto $rra_krb5_extra"],
150     [AC_CHECK_LIB([krb5support], [krb5int_getspecific],
151         [rra_krb5_extra="-lkrb5support $rra_krb5_extra"],
152         [AC_CHECK_LIB([pthreads], [pthread_setspecific],
153             [rra_krb5_pthread="-lpthreads"],
154             [AC_CHECK_LIB([pthread], [pthread_setspecific],
155                 [rra_krb5_pthread="-lpthread"])])
156          AC_CHECK_LIB([krb5support], [krb5int_setspecific],
157             [rra_krb5_extra="-lkrb5support $rra_krb5_extra $rra_krb5_pthread"],
158             [], [$rra_krb5_pthread $rra_krb5_extra])],
159         [$rra_krb5_extra])
160      AC_CHECK_LIB([com_err], [error_message],
161         [rra_krb5_extra="-lcom_err $rra_krb5_extra"], [], [$rra_krb5_extra])
162      AC_CHECK_LIB([ksvc], [krb5_svc_get_msg],
163         [rra_krb5_extra="-lksvc $rra_krb5_extra"], [], [$rra_krb5_extra])
164      AC_CHECK_LIB([k5crypto], [krb5int_hash_md5],
165         [rra_krb5_extra="-lk5crypto $rra_krb5_extra"], [], [$rra_krb5_extra])
166      AC_CHECK_LIB([k5profile], [profile_get_values],
167         [rra_krb5_extra="-lk5profile $rra_krb5_extra"], [], [$rra_krb5_extra])
168      AC_CHECK_LIB([krb5], [krb5_cc_default],
169         [KRB5_LIBS="-lkrb5 $rra_krb5_extra"],
170         [AS_IF([test x"$1" = xtrue],
171             [AC_MSG_ERROR([cannot find usable Kerberos library])])],
172         [$rra_krb5_extra])],
173     [-lasn1 -lcom_err -lcrypto $rra_krb5_extra])
174  LIBS="$KRB5_LIBS $LIBS"
175  AS_IF([test x"$rra_krb5_incroot" = x],
176      [AC_CHECK_HEADERS([krb5.h krb5/krb5.h])],
177      [_RRA_LIB_KRB5_CHECK_HEADER([krb5.h])
178       _RRA_LIB_KRB5_CHECK_HEADER([krb5/krb5.h])])
179  AC_CHECK_FUNCS([krb5_get_error_message],
180      [AC_CHECK_FUNCS([krb5_free_error_message])],
181      [AC_CHECK_FUNCS([krb5_get_error_string], [],
182          [AC_CHECK_FUNCS([krb5_get_err_txt], [],
183              [AC_CHECK_FUNCS([krb5_svc_get_msg],
184                  [AC_CHECK_HEADERS([ibm_svc/krb5_svc.h], [], [],
185                      [RRA_INCLUDES_KRB5])],
186                  [AC_CHECK_HEADERS([et/com_err.h])])])])])
187  RRA_LIB_KRB5_RESTORE])
188
189 dnl Sanity-check the results of krb5-config and be sure we can really link a
190 dnl Kerberos program.  If that fails, clear KRB5_CPPFLAGS and KRB5_LIBS so
191 dnl that we know we don't have usable flags and fall back on the manual
192 dnl check.
193 AC_DEFUN([_RRA_LIB_KRB5_CHECK],
194 [RRA_LIB_KRB5_SWITCH
195  AC_CHECK_FUNC([krb5_init_context],
196     [RRA_LIB_KRB5_RESTORE],
197     [RRA_LIB_KRB5_RESTORE
198      KRB5_CPPFLAGS=
199      KRB5_LIBS=
200      _RRA_LIB_KRB5_PATHS
201      _RRA_LIB_KRB5_MANUAL([$1])])])
202
203 dnl Determine Kerberos compiler and linker flags from krb5-config.  Does the
204 dnl additional probing we need to do to uncover error handling features, and
205 dnl falls back on the manual checks.
206 AC_DEFUN([_RRA_LIB_KRB5_CONFIG],
207 [RRA_KRB5_CONFIG([${rra_krb5_root}], [krb5], [KRB5],
208     [_RRA_LIB_KRB5_CHECK([$1])
209      RRA_LIB_KRB5_SWITCH
210      AS_IF([test x"$rra_krb5_incroot" = x],
211          [AC_CHECK_HEADERS([krb5.h krb5/krb5.h])],
212          [_RRA_LIB_KRB5_CHECK_HEADER([krb5.h])
213           _RRA_LIB_KRB5_CHECK_HEADER([krb5/krb5.h])])
214      AC_CHECK_FUNCS([krb5_get_error_message],
215          [AC_CHECK_FUNCS([krb5_free_error_message])],
216          [AC_CHECK_FUNCS([krb5_get_error_string], [],
217              [AC_CHECK_FUNCS([krb5_get_err_txt], [],
218                  [AC_CHECK_FUNCS([krb5_svc_get_msg],
219                      [AC_CHECK_HEADERS([ibm_svc/krb5_svc.h], [], [],
220                          [RRA_INCLUDES_KRB5])],
221                      [AC_CHECK_HEADERS([et/com_err.h])])])])])
222      RRA_LIB_KRB5_RESTORE],
223     [_RRA_LIB_KRB5_PATHS
224      _RRA_LIB_KRB5_MANUAL([$1])])])
225
226 dnl The core of the library checking, shared between RRA_LIB_KRB5 and
227 dnl RRA_LIB_KRB5_OPTIONAL.  The single argument, if "true", says to fail if
228 dnl Kerberos could not be found.  Set up rra_krb5_incroot for later header
229 dnl checking.
230 AC_DEFUN([_RRA_LIB_KRB5_INTERNAL],
231 [AC_REQUIRE([RRA_ENABLE_REDUCED_DEPENDS])
232  rra_krb5_incroot=
233  AS_IF([test x"$rra_krb5_includedir" != x],
234     [rra_krb5_incroot="$rra_krb5_includedir"],
235     [AS_IF([test x"$rra_krb5_root" != x],
236         [rra_krb5_incroot="${rra_krb5_root}/include"])])
237  AS_IF([test x"$rra_reduced_depends" = xtrue],
238     [_RRA_LIB_KRB5_PATHS
239      _RRA_LIB_KRB5_REDUCED([$1])],
240     [AS_IF([test x"$rra_krb5_includedir" = x && test x"$rra_krb5_libdir" = x],
241         [_RRA_LIB_KRB5_CONFIG([$1])],
242         [_RRA_LIB_KRB5_PATHS
243          _RRA_LIB_KRB5_MANUAL([$1])])])
244  rra_krb5_uses_com_err=false
245  AS_CASE([$LIBS], [*-lcom_err*], [rra_krb5_uses_com_err=true])
246  AM_CONDITIONAL([KRB5_USES_COM_ERR], [test x"$rra_krb5_uses_com_err" = xtrue])])
247
248 dnl The main macro for packages with mandatory Kerberos support.
249 AC_DEFUN([RRA_LIB_KRB5],
250 [rra_krb5_root=
251  rra_krb5_libdir=
252  rra_krb5_includedir=
253  rra_use_kerberos=true
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" != xyes && test x"$withval" != xno],
262         [rra_krb5_root="$withval"])])
263  AC_ARG_WITH([krb5-include],
264     [AS_HELP_STRING([--with-krb5-include=DIR],
265         [Location of Kerberos headers])],
266     [AS_IF([test x"$withval" != xyes && test x"$withval" != xno],
267         [rra_krb5_includedir="$withval"])])
268  AC_ARG_WITH([krb5-lib],
269     [AS_HELP_STRING([--with-krb5-lib=DIR],
270         [Location of Kerberos libraries])],
271     [AS_IF([test x"$withval" != xyes && test x"$withval" != xno],
272         [rra_krb5_libdir="$withval"])])
273  _RRA_LIB_KRB5_INTERNAL([true])
274  AC_DEFINE([HAVE_KERBEROS], 1, [Define to enable Kerberos features.])])
275
276 dnl The main macro for packages with optional Kerberos support.
277 AC_DEFUN([RRA_LIB_KRB5_OPTIONAL],
278 [rra_krb5_root=
279  rra_krb5_libdir=
280  rra_krb5_includedir=
281  rra_use_kerberos=
282  AC_SUBST([KRB5_CPPFLAGS])
283  AC_SUBST([KRB5_LDFLAGS])
284  AC_SUBST([KRB5_LIBS])
285
286  AC_ARG_WITH([krb5],
287     [AS_HELP_STRING([--with-krb5@<:@=DIR@:>@],
288         [Location of Kerberos headers and libraries])],
289     [AS_IF([test x"$withval" = xno],
290         [rra_use_kerberos=false],
291         [AS_IF([test x"$withval" != xyes], [rra_krb5_root="$withval"])
292          rra_use_kerberos=true])])
293  AC_ARG_WITH([krb5-include],
294     [AS_HELP_STRING([--with-krb5-include=DIR],
295         [Location of Kerberos headers])],
296     [AS_IF([test x"$withval" != xyes && test x"$withval" != xno],
297         [rra_krb5_includedir="$withval"])])
298  AC_ARG_WITH([krb5-lib],
299     [AS_HELP_STRING([--with-krb5-lib=DIR],
300         [Location of Kerberos libraries])],
301     [AS_IF([test x"$withval" != xyes && test x"$withval" != xno],
302         [rra_krb5_libdir="$withval"])])
303
304  AS_IF([test x"$rra_use_kerberos" != xfalse],
305      [AS_IF([test x"$rra_use_kerberos" = xtrue],
306          [_RRA_LIB_KRB5_INTERNAL([true])],
307          [_RRA_LIB_KRB5_INTERNAL([false])])],
308      [AM_CONDITIONAL([KRB5_USES_COM_ERR], [false])])
309  AS_IF([test x"$KRB5_LIBS" != x],
310     [AC_DEFINE([HAVE_KERBEROS], 1, [Define to enable Kerberos features.])])])
311
312 dnl Source used by RRA_FUNC_KRB5_GET_INIT_CREDS_OPT_FREE_ARGS.
313 AC_DEFUN([_RRA_FUNC_KRB5_OPT_FREE_ARGS_SOURCE], [RRA_INCLUDES_KRB5] [[
314 int
315 main(void)
316 {
317     krb5_get_init_creds_opt *opts;
318     krb5_context c;
319     krb5_get_init_creds_opt_free(c, opts);
320 }
321 ]])
322
323 dnl Check whether krb5_get_init_creds_opt_free takes one argument or two.
324 dnl Early Heimdal used to take a single argument.  Defines
325 dnl HAVE_KRB5_GET_INIT_CREDS_OPT_FREE_2_ARGS if it takes two arguments.
326 dnl
327 dnl Should be called with RRA_LIB_KRB5_SWITCH active.
328 AC_DEFUN([RRA_FUNC_KRB5_GET_INIT_CREDS_OPT_FREE_ARGS],
329 [AC_CACHE_CHECK([if krb5_get_init_creds_opt_free takes two arguments],
330     [rra_cv_func_krb5_get_init_creds_opt_free_args],
331     [AC_COMPILE_IFELSE([AC_LANG_SOURCE([_RRA_FUNC_KRB5_OPT_FREE_ARGS_SOURCE])],
332         [rra_cv_func_krb5_get_init_creds_opt_free_args=yes],
333         [rra_cv_func_krb5_get_init_creds_opt_free_args=no])])
334  AS_IF([test $rra_cv_func_krb5_get_init_creds_opt_free_args = yes],
335     [AC_DEFINE([HAVE_KRB5_GET_INIT_CREDS_OPT_FREE_2_ARGS], 1,
336         [Define if krb5_get_init_creds_opt_free takes two arguments.])])])