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