6bfe486dd62f43c3c2ed89a3a9efabc116bc2e61
[samba.git] / source / auth / kerberos / kerberos.m4
1 #################################################
2 # KRB5 support
3 KRB5_CFLAGS=""
4 KRB5_CPPFLAGS=""
5 KRB5_LDFLAGS=""
6 KRB5_LIBS=""
7 with_krb5_support=auto
8 krb5_withval=auto
9 AC_MSG_CHECKING([for KRB5 support])
10
11 # Do no harm to the values of CFLAGS and LIBS while testing for
12 # Kerberos support.
13 AC_ARG_WITH(krb5,
14 [  --with-krb5=base-dir    Locate Kerberos 5 support (default=auto)],
15         [ case "$withval" in
16                 no)
17                         with_krb5_support=no
18                         AC_MSG_RESULT(no)
19                         krb5_withval=no
20                         ;;
21                 yes)
22                         with_krb5_support=yes
23                         AC_MSG_RESULT(yes)
24                         krb5_withval=yes
25                         ;;
26                 auto)
27                         with_krb5_support=auto
28                         AC_MSG_RESULT(auto)
29                         krb5_withval=auto
30                         ;;
31                 *)
32                         with_krb5_support=yes
33                         AC_MSG_RESULT(yes)
34                         krb5_withval=$withval
35                         KRB5CONFIG="$krb5_withval/bin/krb5-config"
36                         ;;
37         esac ],
38         AC_MSG_RESULT($with_krb5_support)
39 )
40
41 if test x$with_krb5_support != x"no"; then
42         FOUND_KRB5=no
43         FOUND_KRB5_VIA_CONFIG=no
44
45         #################################################
46         # check for krb5-config from recent MIT and Heimdal kerberos 5
47         AC_MSG_CHECKING(for working specified location for krb5-config)
48         if test x$KRB5CONFIG != "x"; then
49                 if test -x "$KRB5CONFIG"; then
50                         ac_save_CFLAGS=$CFLAGS
51                         CFLAGS="";export CFLAGS
52                         ac_save_LDFLAGS=$LDFLAGS
53                         LDFLAGS="";export LDFLAGS
54                         KRB5_LIBS="`$KRB5CONFIG --libs gssapi`"
55                         KRB5_CFLAGS="`$KRB5CONFIG --cflags | sed s/@INCLUDE_des@//`" 
56                         KRB5_CPPFLAGS="`$KRB5CONFIG --cflags | sed s/@INCLUDE_des@//`"
57                         CFLAGS=$ac_save_CFLAGS;export CFLAGS
58                         LDFLAGS=$ac_save_LDFLAGS;export LDFLAGS
59                         FOUND_KRB5=yes
60                         FOUND_KRB5_VIA_CONFIG=yes
61                         AC_MSG_RESULT(yes. Found $KRB5CONFIG)
62                 else 
63                         AC_MSG_RESULT(no. Fallback to specified directory)
64                 fi
65         else
66                 AC_MSG_RESULT(no. Fallback to finding krb5-config in path)
67                 #################################################
68                 # check for krb5-config from recent MIT and Heimdal kerberos 5
69                 AC_PATH_PROG(KRB5CONFIG, krb5-config)
70                 AC_MSG_CHECKING(for working krb5-config in path)
71                 if test -x "$KRB5CONFIG"; then
72                         ac_save_CFLAGS=$CFLAGS
73                         CFLAGS="";export CFLAGS
74                         ac_save_LDFLAGS=$LDFLAGS
75                         LDFLAGS="";export LDFLAGS
76                         KRB5_LIBS="`$KRB5CONFIG --libs gssapi`"
77                         KRB5_CFLAGS="`$KRB5CONFIG --cflags | sed s/@INCLUDE_des@//`" 
78                         KRB5_CPPFLAGS="`$KRB5CONFIG --cflags | sed s/@INCLUDE_des@//`"
79                         CFLAGS=$ac_save_CFLAGS;export CFLAGS
80                         LDFLAGS=$ac_save_LDFLAGS;export LDFLAGS
81                         FOUND_KRB5=yes
82                         FOUND_KRB5_VIA_CONFIG=yes
83                         AC_MSG_RESULT(yes. Found $KRB5CONFIG)
84                 else
85                         AC_MSG_RESULT(no. Fallback to previous krb5 detection strategy)
86                 fi
87         fi
88   
89         if test x$FOUND_KRB5 != x"yes"; then
90                 #################################################
91                 # check for location of Kerberos 5 install
92                 AC_MSG_CHECKING(for kerberos 5 install path)
93                 case "$krb5_withval" in
94                         no)
95                                 AC_MSG_RESULT(no krb5-path given)
96                                 ;;
97                         yes)
98                                 AC_MSG_RESULT(/usr)
99                                 FOUND_KRB5=yes
100                                 ;;
101                         *)
102                                 AC_MSG_RESULT($krb5_withval)
103                                 KRB5_CFLAGS="-I$krb5_withval/include"
104                                 KRB5_CPPFLAGS="-I$krb5_withval/include"
105                                 KRB5_LDFLAGS="-L$krb5_withval/lib"
106                                 FOUND_KRB5=yes
107                                 ;;
108                 esac
109         fi
110
111         if test x$FOUND_KRB5 != x"yes"; then
112                 #################################################
113                 # see if this box has the SuSE location for the heimdal krb implementation
114                 AC_MSG_CHECKING(for /usr/include/heimdal)
115                 if test -d /usr/include/heimdal; then
116                         if test -f /usr/lib/heimdal/lib/libkrb5.a; then
117                                 KRB5_CFLAGS="-I/usr/include/heimdal"
118                                 KRB5_CPPFLAGS="-I/usr/include/heimdal"
119                                 KRB5_LDFLAGS="-L/usr/lib/heimdal/lib"
120                                 AC_MSG_RESULT(yes)
121                         else
122                                 KRB5_CFLAGS="-I/usr/include/heimdal"
123                                 KRB5_CPPFLAGS="-I/usr/include/heimdal"
124                                 AC_MSG_RESULT(yes)
125                         fi
126                 else
127                         AC_MSG_RESULT(no)
128                 fi
129         fi
130
131         if test x$FOUND_KRB5 != x"yes"; then
132                 #################################################
133                 # see if this box has the RedHat location for kerberos
134                 AC_MSG_CHECKING(for /usr/kerberos)
135                 if test -d /usr/kerberos -a -f /usr/kerberos/lib/libkrb5.a; then
136                         KRB5_LDFLAGS="-L/usr/kerberos/lib"
137                         KRB5_CFLAGS="-I/usr/kerberos/include"
138                         KRB5_CPPFLAGS="-I/usr/kerberos/include"
139                         AC_MSG_RESULT(yes)
140                 else
141                         AC_MSG_RESULT(no)
142                 fi
143         fi
144
145         ac_save_CFLAGS=$CFLAGS
146         ac_save_CPPFLAGS=$CPPFLAGS
147         ac_save_LDFLAGS=$LDFLAGS
148
149         #MIT needs this, to let us see 'internal' parts of the headers we use
150         KRB5_CFLAGS="${KRB5_CFLAGS} -DKRB5_PRIVATE -DKRB5_DEPRECATED"
151
152         #Heimdal needs this
153         #TODO: we need to parse KRB5_LIBS for -L path
154         #      and set -Wl,-rpath -Wl,path
155
156         CFLAGS="$CFLAGS $KRB5_CFLAGS"
157         CPPFLAGS="$CPPFLAGS $KRB5_CPPFLAGS"
158         LDFLAGS="$LDFLAGS $KRB5_LDFLAGS"
159
160         KRB5_LIBS="$KRB5_LDFLAGS $KRB5_LIBS"
161
162         # now check for krb5.h. Some systems have the libraries without the headers!
163         # note that this check is done here to allow for different kerberos
164         # include paths
165         AC_CHECK_HEADERS(krb5.h)
166
167         if test x"$ac_cv_header_krb5_h" = x"no"; then
168                 # Give a warning if KRB5 support was not explicitly requested,
169                 # i.e with_krb5_support = auto, otherwise die with an error.
170                 if test x"$with_krb5_support" = x"yes"; then
171                         AC_MSG_ERROR([KRB5 cannot be supported without krb5.h])
172                 else
173                         AC_MSG_WARN([KRB5 cannot be supported without krb5.h])
174                 fi
175                 # Turn off AD support and restore CFLAGS and LIBS variables
176                 with_krb5_support="no"
177         fi
178
179         CFLAGS=$ac_save_CFLAGS
180         CPPFLAGS=$ac_save_CPPFLAGS
181         LDFLAGS=$ac_save_LDFLAGS
182 fi
183
184 # Now we have determined whether we really want KRB5 support
185
186 if test x"$with_krb5_support" != x"no"; then
187         ac_save_CFLAGS=$CFLAGS
188         ac_save_CPPFLAGS=$CPPFLAGS
189         ac_save_LDFLAGS=$LDFLAGS
190         ac_save_LIBS=$LIBS
191
192         CFLAGS="$CFLAGS $KRB5_CFLAGS"
193         CPPFLAGS="$CPPFLAGS $KRB5_CPPFLAGS"
194         LDFLAGS="$LDFLAGS $KRB5_LDFLAGS"
195
196         # now check for gssapi headers.  This is also done here to allow for
197         # different kerberos include paths
198         AC_CHECK_HEADERS(gssapi.h gssapi_krb5.h gssapi/gssapi.h gssapi/gssapi_generic.h gssapi/gssapi_krb5.h com_err.h)
199
200         ##################################################################
201         # we might need the k5crypto and com_err libraries on some systems
202         AC_CHECK_LIB_EXT(com_err, KRB5_LIBS, _et_list)
203         AC_CHECK_LIB_EXT(k5crypto, KRB5_LIBS, krb5_encrypt_data)
204
205         # Heimdal checks.
206         # But only if we didn't have a krb5-config to tell us this already
207         if test x"$FOUND_KRB5_VIA_CONFIG" != x"yes"; then
208                 AC_CHECK_LIB_EXT(crypto, KRB5_LIBS, des_set_key)
209                 AC_CHECK_LIB_EXT(asn1, KRB5_LIBS, copy_Authenticator)
210                 AC_CHECK_LIB_EXT(roken, KRB5_LIBS, roken_getaddrinfo_hostspec)
211         fi
212
213         # Heimdal checks. On static Heimdal gssapi must be linked before krb5.
214         AC_CHECK_LIB_EXT(gssapi, KRB5_LIBS, gss_display_status,[],[],
215                                 AC_DEFINE(HAVE_GSSAPI,1,[Whether GSSAPI is available]))
216
217         ########################################################
218         # now see if we can find the krb5 libs in standard paths
219         # or as specified above
220         AC_CHECK_LIB_EXT(krb5, KRB5_LIBS, krb5_mk_req_extended)
221         AC_CHECK_LIB_EXT(krb5, KRB5_LIBS, krb5_kt_compare)
222
223         ########################################################
224         # now see if we can find the gssapi libs in standard paths
225         if test x"$ac_cv_lib_ext_gssapi_gss_display_status" != x"yes"; then
226            AC_CHECK_LIB_EXT(gssapi_krb5, KRB5_LIBS,gss_display_status,[],[],
227                 AC_DEFINE(HAVE_GSSAPI,1,[Whether GSSAPI is available]))
228         fi
229
230         AC_CHECK_FUNC_EXT(krb5_set_real_time, $KRB5_LIBS)
231         AC_CHECK_FUNC_EXT(krb5_set_default_in_tkt_etypes, $KRB5_LIBS)
232         AC_CHECK_FUNC_EXT(krb5_set_default_tgs_ktypes, $KRB5_LIBS)
233         AC_CHECK_FUNC_EXT(krb5_principal2salt, $KRB5_LIBS)
234         AC_CHECK_FUNC_EXT(krb5_use_enctype, $KRB5_LIBS)
235         AC_CHECK_FUNC_EXT(krb5_string_to_key, $KRB5_LIBS) 
236         AC_CHECK_FUNC_EXT(krb5_get_pw_salt, $KRB5_LIBS)
237         AC_CHECK_FUNC_EXT(krb5_string_to_key_salt, $KRB5_LIBS) 
238         AC_CHECK_FUNC_EXT(krb5_auth_con_setkey, $KRB5_LIBS)
239         AC_CHECK_FUNC_EXT(krb5_auth_con_setuseruserkey, $KRB5_LIBS) 
240         AC_CHECK_FUNC_EXT(krb5_locate_kdc, $KRB5_LIBS)
241         AC_CHECK_FUNC_EXT(krb5_get_permitted_enctypes, $KRB5_LIBS) 
242         AC_CHECK_FUNC_EXT(krb5_get_default_in_tkt_etypes, $KRB5_LIBS) 
243         AC_CHECK_FUNC_EXT(krb5_free_ktypes, $KRB5_LIBS)
244         AC_CHECK_FUNC_EXT(krb5_free_data_contents, $KRB5_LIBS)
245         AC_CHECK_FUNC_EXT(krb5_principal_get_comp_string, $KRB5_LIBS)
246         AC_CHECK_FUNC_EXT(krb5_free_unparsed_name, $KRB5_LIBS)
247         AC_CHECK_FUNC_EXT(krb5_free_keytab_entry_contents, $KRB5_LIBS)
248         AC_CHECK_FUNC_EXT(krb5_kt_free_entry, $KRB5_LIBS)
249         AC_CHECK_FUNC_EXT(krb5_krbhst_get_addrinfo, $KRB5_LIBS)
250         AC_CHECK_FUNC_EXT(krb5_verify_checksum, $KRB5_LIBS)
251         AC_CHECK_FUNC_EXT(krb5_c_verify_checksum, $KRB5_LIBS)
252         AC_CHECK_FUNC_EXT(krb5_ticket_get_authorization_data_type, $KRB5_LIBS)
253         AC_CHECK_FUNC_EXT(krb5_krbhst_get_addrinfo, $KRB5_LIBS)
254         AC_CHECK_FUNC_EXT(krb5_c_enctype_compare, $KRB5_LIBS)
255         AC_CHECK_FUNC_EXT(krb5_enctypes_compatible_keys, $KRB5_LIBS)
256         AC_CHECK_FUNC_EXT(krb5_get_error_string, $KRB5_LIBS)
257         AC_CHECK_FUNC_EXT(krb5_free_error_string, $KRB5_LIBS)
258
259         LIBS="$LIBS $KRB5_LIBS"
260   
261         AC_CACHE_CHECK([for krb5_encrypt_block type],
262                 samba_cv_HAVE_KRB5_ENCRYPT_BLOCK,[
263         AC_TRY_COMPILE([#include <krb5.h>],
264                 [krb5_encrypt_block block;],
265                 samba_cv_HAVE_KRB5_ENCRYPT_BLOCK=yes,
266                 samba_cv_HAVE_KRB5_ENCRYPT_BLOCK=no)])
267
268         if test x"$samba_cv_HAVE_KRB5_ENCRYPT_BLOCK" = x"yes"; then
269                 AC_DEFINE(HAVE_KRB5_ENCRYPT_BLOCK,1,
270                 [Whether the type krb5_encrypt_block exists])
271         fi
272
273         AC_CACHE_CHECK([for addrtype in krb5_address],
274                 samba_cv_HAVE_ADDRTYPE_IN_KRB5_ADDRESS,[
275                 AC_TRY_COMPILE([#include <krb5.h>],
276                 [krb5_address kaddr; kaddr.addrtype = ADDRTYPE_INET;],
277                 samba_cv_HAVE_ADDRTYPE_IN_KRB5_ADDRESS=yes,
278                 samba_cv_HAVE_ADDRTYPE_IN_KRB5_ADDRESS=no)])
279         if test x"$samba_cv_HAVE_ADDRTYPE_IN_KRB5_ADDRESS" = x"yes"; then
280                 AC_DEFINE(HAVE_ADDRTYPE_IN_KRB5_ADDRESS,1,
281                 [Whether the krb5_address struct has a addrtype property])
282         fi
283
284         AC_CACHE_CHECK([for addr_type in krb5_address],
285                 samba_cv_HAVE_ADDR_TYPE_IN_KRB5_ADDRESS,[
286                 AC_TRY_COMPILE([#include <krb5.h>],
287                 [krb5_address kaddr; kaddr.addr_type = KRB5_ADDRESS_INET;],
288                 samba_cv_HAVE_ADDR_TYPE_IN_KRB5_ADDRESS=yes,
289                 samba_cv_HAVE_ADDR_TYPE_IN_KRB5_ADDRESS=no)])
290         if test x"$samba_cv_HAVE_ADDR_TYPE_IN_KRB5_ADDRESS" = x"yes"; then
291                 AC_DEFINE(HAVE_ADDR_TYPE_IN_KRB5_ADDRESS,1,
292                 [Whether the krb5_address struct has a addr_type property])
293         fi
294
295         AC_CACHE_CHECK([for enc_part2 in krb5_ticket], 
296                 samba_cv_HAVE_KRB5_TKT_ENC_PART2,[
297                 AC_TRY_COMPILE([#include <krb5.h>],
298                 [krb5_ticket tkt; tkt.enc_part2->authorization_data[0]->contents = NULL;],
299                 samba_cv_HAVE_KRB5_TKT_ENC_PART2=yes,
300                 samba_cv_HAVE_KRB5_TKT_ENC_PART2=no)])
301         if test x"$samba_cv_HAVE_KRB5_TKT_ENC_PART2" = x"yes"; then
302                 AC_DEFINE(HAVE_KRB5_TKT_ENC_PART2,1,
303                 [Whether the krb5_ticket struct has a enc_part2 property])
304         fi
305
306         AC_CACHE_CHECK([for keyblock in krb5_creds],
307                  samba_cv_HAVE_KRB5_KEYBLOCK_IN_CREDS,[
308         AC_TRY_COMPILE([#include <krb5.h>],
309                 [krb5_creds creds; krb5_keyblock kb; creds.keyblock = kb;],
310                 samba_cv_HAVE_KRB5_KEYBLOCK_IN_CREDS=yes,
311                 samba_cv_HAVE_KRB5_KEYBLOCK_IN_CREDS=no)])
312
313         if test x"$samba_cv_HAVE_KRB5_KEYBLOCK_IN_CREDS" = x"yes"; then
314                 AC_DEFINE(HAVE_KRB5_KEYBLOCK_IN_CREDS,1,
315                 [Whether the krb5_creds struct has a keyblock property])
316         fi
317
318         AC_CACHE_CHECK([for session in krb5_creds],
319                  samba_cv_HAVE_KRB5_SESSION_IN_CREDS,[
320         AC_TRY_COMPILE([#include <krb5.h>],
321                 [krb5_creds creds; krb5_keyblock kb; creds.session = kb;],
322                 samba_cv_HAVE_KRB5_SESSION_IN_CREDS=yes,
323                 samba_cv_HAVE_KRB5_SESSION_IN_CREDS=no)])
324
325         if test x"$samba_cv_HAVE_KRB5_SESSION_IN_CREDS" = x"yes"; then
326                 AC_DEFINE(HAVE_KRB5_SESSION_IN_CREDS,1,
327                 [Whether the krb5_creds struct has a session property])
328         fi
329
330         AC_CACHE_CHECK([for keyvalue in krb5_keyblock],
331                 samba_cv_HAVE_KRB5_KEYBLOCK_KEYVALUE,[
332                 AC_TRY_COMPILE([#include <krb5.h>],
333                 [krb5_keyblock key; key.keyvalue.data = NULL;],
334                 samba_cv_HAVE_KRB5_KEYBLOCK_KEYVALUE=yes,
335                 samba_cv_HAVE_KRB5_KEYBLOCK_KEYVALUE=no)])
336         if test x"$samba_cv_HAVE_KRB5_KEYBLOCK_KEYVALUE" = x"yes"; then
337                 AC_DEFINE(HAVE_KRB5_KEYBLOCK_KEYVALUE,1,
338                 [Whether the krb5_keyblock struct has a keyvalue property])
339         fi
340
341         AC_CACHE_CHECK([for ENCTYPE_ARCFOUR_HMAC_MD5],
342                 samba_cv_HAVE_ENCTYPE_ARCFOUR_HMAC_MD5,[
343                 AC_TRY_COMPILE([#include <krb5.h>],
344                 [krb5_enctype enctype; enctype = ENCTYPE_ARCFOUR_HMAC_MD5;],
345                 samba_cv_HAVE_ENCTYPE_ARCFOUR_HMAC_MD5=yes,
346                 samba_cv_HAVE_ENCTYPE_ARCFOUR_HMAC_MD5=no)])
347         AC_CACHE_CHECK([for KEYTYPE_ARCFOUR_56],
348                  samba_cv_HAVE_KEYTYPE_ARCFOUR_56,[
349                 AC_TRY_COMPILE([#include <krb5.h>],
350                 [krb5_keytype keytype; keytype = KEYTYPE_ARCFOUR_56;],
351                 samba_cv_HAVE_KEYTYPE_ARCFOUR_56=yes,
352                 samba_cv_HAVE_KEYTYPE_ARCFOUR_56=no)])
353         # Heimdals with KEYTYPE_ARCFOUR but not KEYTYPE_ARCFOUR_56 are broken
354         # w.r.t. arcfour and windows, so we must not enable it here
355         if test x"$samba_cv_HAVE_ENCTYPE_ARCFOUR_HMAC_MD5" = x"yes" -a\
356            x"$samba_cv_HAVE_KEYTYPE_ARCFOUR_56" = x"yes"; then
357                 AC_DEFINE(HAVE_ENCTYPE_ARCFOUR_HMAC_MD5,1,
358                 [Whether the ENCTYPE_ARCFOUR_HMAC_MD5 key type is available])
359         fi
360
361         AC_CACHE_CHECK([for AP_OPTS_USE_SUBKEY],
362                 samba_cv_HAVE_AP_OPTS_USE_SUBKEY,[
363                 AC_TRY_COMPILE([#include <krb5.h>],
364                 [krb5_flags ap_options; ap_options = AP_OPTS_USE_SUBKEY;],
365                 samba_cv_HAVE_AP_OPTS_USE_SUBKEY=yes,
366                 samba_cv_HAVE_AP_OPTS_USE_SUBKEY=no)])
367         if test x"$samba_cv_HAVE_AP_OPTS_USE_SUBKEY" = x"yes"; then
368                 AC_DEFINE(HAVE_AP_OPTS_USE_SUBKEY,1,
369                 [Whether the AP_OPTS_USE_SUBKEY ap option is available])
370         fi
371
372         AC_CACHE_CHECK([for KV5M_KEYTAB],
373                 samba_cv_HAVE_KV5M_KEYTAB,[
374                 AC_TRY_COMPILE([#include <krb5.h>],
375                 [krb5_keytab_entry entry; entry.magic = KV5M_KEYTAB;],
376                 samba_cv_HAVE_KV5M_KEYTAB=yes,
377                 samba_cv_HAVE_KV5M_KEYTAB=no)])
378         if test x"$samba_cv_HAVE_KV5M_KEYTAB" = x"yes"; then
379                 AC_DEFINE(HAVE_KV5M_KEYTAB,1,
380                 [Whether the KV5M_KEYTAB option is available])
381         fi
382
383         AC_CACHE_CHECK([for the krb5_princ_component macro],
384                 samba_cv_HAVE_KRB5_PRINC_COMPONENT,[
385                 AC_TRY_LINK([#include <krb5.h>],
386                 [const krb5_data *pkdata; krb5_context context; krb5_principal principal; 
387                         pkdata = krb5_princ_component(context, principal, 0);],
388                 samba_cv_HAVE_KRB5_PRINC_COMPONENT=yes,
389                 samba_cv_HAVE_KRB5_PRINC_COMPONENT=no)])
390         if test x"$samba_cv_HAVE_KRB5_PRINC_COMPONENT" = x"yes"; then
391                 AC_DEFINE(HAVE_KRB5_PRINC_COMPONENT,1,
392                [Whether krb5_princ_component is available])
393         fi
394
395         AC_CACHE_CHECK([for key in krb5_keytab_entry],
396                 samba_cv_HAVE_KRB5_KEYTAB_ENTRY_KEY,[
397                 AC_TRY_COMPILE([#include <krb5.h>],
398                 [krb5_keytab_entry entry; krb5_keyblock e; entry.key = e;],
399                 samba_cv_HAVE_KRB5_KEYTAB_ENTRY_KEY=yes,
400                 samba_cv_HAVE_KRB5_KEYTAB_ENTRY_KEY=no)])
401         if test x"$samba_cv_HAVE_KRB5_KEYTAB_ENTRY_KEY" = x"yes"; then
402                 AC_DEFINE(HAVE_KRB5_KEYTAB_ENTRY_KEY,1,
403                 [Whether krb5_keytab_entry has key member])
404         fi
405
406         AC_CACHE_CHECK([for keyblock in krb5_keytab_entry],
407                 samba_cv_HAVE_KRB5_KEYTAB_ENTRY_KEYBLOCK,[
408                 AC_TRY_COMPILE([#include <krb5.h>],
409                 [krb5_keytab_entry entry; entry.keyblock.keytype = 0;],
410                 samba_cv_HAVE_KRB5_KEYTAB_ENTRY_KEYBLOCK=yes,
411                 samba_cv_HAVE_KRB5_KEYTAB_ENTRY_KEYBLOCK=no)])
412         if test x"$samba_cv_HAVE_KRB5_KEYTAB_ENTRY_KEYBLOCK" = x"yes"; then
413                 AC_DEFINE(HAVE_KRB5_KEYTAB_ENTRY_KEYBLOCK,1,
414                 [Whether krb5_keytab_entry has keyblock member])
415         fi
416
417         AC_CACHE_CHECK([for WRFILE: keytab support],
418                 samba_cv_HAVE_WRFILE_KEYTAB,[
419                 AC_TRY_RUN([
420                 #include<krb5.h>
421                 main()
422                 {
423                         krb5_context context;
424                         krb5_keytab keytab;
425                         krb5_init_context(&context);
426                         return krb5_kt_resolve(context, "WRFILE:api", &keytab);
427                 }],
428                 samba_cv_HAVE_WRFILE_KEYTAB=yes,
429                 samba_cv_HAVE_WRFILE_KEYTAB=no)])
430         if test x"$samba_cv_HAVE_WRFILE_KEYTAB" = x"yes"; then
431                 AC_DEFINE(HAVE_WRFILE_KEYTAB,1,
432                 [Whether the WRFILE:-keytab is supported])
433         fi
434
435         AC_CACHE_CHECK([for krb5_princ_realm returns krb5_realm or krb5_data],
436                 samba_cv_KRB5_PRINC_REALM_RETURNS_REALM,[
437                 AC_TRY_COMPILE([#include <krb5.h>],
438                 [krb5_context context;krb5_principal principal;krb5_realm realm;
439                         realm = *krb5_princ_realm(context, principal);],
440                 samba_cv_KRB5_PRINC_REALM_RETURNS_REALM=yes,
441                 samba_cv_KRB5_PRINC_REALM_RETURNS_REALM=no)])
442         if test x"$samba_cv_KRB5_PRINC_REALM_RETURNS_REALM" = x"yes"; then
443                 AC_DEFINE(KRB5_PRINC_REALM_RETURNS_REALM,1,
444                 [Whether krb5_princ_realm returns krb5_realm or krb5_data])
445         fi
446
447         # TODO: check all gssapi headers for this
448         AC_CACHE_CHECK([for GSS_C_DCE_STYLE in gssapi.h],
449                 samba_cv_GSS_C_DCE_STYLE,[
450                 AC_TRY_COMPILE([#include <gssapi.h>],
451                 [int flags = GSS_C_DCE_STYLE;],
452                 samba_cv_GSS_C_DCE_STYLE=yes,
453                 samba_cv_GSS_C_DCE_STYLE=no)])
454
455         AC_CHECK_FUNC_EXT(gsskrb5_get_initiator_subkey, $KRB5_LIBS)
456         AC_CHECK_FUNC_EXT(gsskrb5_extract_authz_data_from_sec_context, $KRB5_LIBS)
457
458         if test x"$ac_cv_lib_ext_krb5_krb5_mk_req_extended" = x"yes"; then
459                 AC_DEFINE(HAVE_KRB5,1,[Whether to have KRB5 support])
460                 AC_MSG_CHECKING(whether KRB5 support is used)
461                 SMB_EXT_LIB_ENABLE(KRB5,YES)
462                 AC_MSG_RESULT(yes)
463                 echo "KRB5_CFLAGS:   ${KRB5_CFLAGS}"
464                 echo "KRB5_CPPFLAGS: ${KRB5_CPPFLAGS}"
465                 echo "KRB5_LDFLAGS:  ${KRB5_LDFLAGS}"
466                 echo "KRB5_LIBS:     ${KRB5_LIBS}"
467         else
468                 if test x"$with_krb5_support" = x"yes"; then
469                         AC_MSG_ERROR(a working krb5 library is needed for KRB5 support)
470                 else
471                         AC_MSG_WARN(a working krb5 library is needed for KRB5 support)
472                 fi
473                 KRB5_CFLAGS=""
474                 KRB5_CPPFLAGS=""
475                 KRB5_LDFLAGS=""
476                 KRB5_LIBS=""
477                 with_krb5_support=no 
478         fi
479
480         CFLAGS=$ac_save_CFLAGS
481         CPPFLAGS=$ac_save_CPPFLAGS
482         LDFLAGS=$ac_save_LDFLAGS
483         LIBS="$ac_save_LIBS"
484
485         # as a nasty hack add the krb5 stuff to the global vars,
486         # at some point this should not be needed anymore when the build system
487         # can handle that alone
488         CFLAGS="$CFLAGS $KRB5_CFLAGS"
489         CPPFLAGS="$CPPFLAGS $KRB5_CPPFLAGS"
490         LDFLAGS="$LDFLAGS $KRB5_LDFLAGS"
491 fi
492
493 SMB_EXT_LIB(KRB5,[${KRB5_LIBS}],[${KRB5_CFLAGS}],[${KRB5_CPPFLAGS}],[${KRB5_LDFLAGS}])