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