556b8d3aeec41993cd065f7ef71f1205c596cfba
[samba.git] / source3 / configure.in
1 dnl Process this file with autoconf to produce a configure script.
2
3 dnl We must use autotools 2.54 or above
4 AC_PREREQ(2.54)
5
6 AC_INIT([Samba],[3],[samba-technical@samba.org])
7
8 AC_CONFIG_SRCDIR([include/includes.h])
9 AC_CONFIG_HEADER(include/config.h)
10 AC_DEFINE(CONFIG_H_IS_FROM_SAMBA,1,[Marker for samba's config.h])
11
12 case "$PATH" in
13     */usr/ucb*)
14         AC_MSG_WARN([\$PATH contains /usr/ucb - build errors may follow])
15         ;;
16 esac 
17
18 builddir=`pwd`
19 AC_SUBST(builddir)
20
21 m4_include(m4/samba_version.m4)
22 m4_include(m4/check_path.m4)
23 m4_include(pkg.m4)
24
25 AC_LIBREPLACE_CC_CHECKS
26 AC_LIBREPLACE_RUNTIME_LIB_PATH_VAR
27
28 m4_include(../lib/tevent/libtevent.m4)
29
30 LIBTEVENT_OBJ0=""
31 for obj in ${TEVENT_OBJ}; do
32         LIBTEVENT_OBJ0="${LIBTEVENT_OBJ0} ${teventdir}/${obj}"
33 done
34 AC_SUBST(LIBTEVENT_OBJ0)
35 LIBS="${LIBS} ${TEVENT_LIBS}"
36
37 SAMBA_CPPFLAGS="-Iinclude -I${srcdir-.}/include  -I. -I${srcdir-.}"
38 SAMBA_CPPFLAGS="${SAMBA_CPPFLAGS} -I${srcdir-.}/../lib/replace"
39 SAMBA_CPPFLAGS="${SAMBA_CPPFLAGS} ${TEVENT_CFLAGS}"
40 SAMBA_CPPFLAGS="${SAMBA_CPPFLAGS} -I${srcdir-.}/librpc"
41 SAMBA_CPPFLAGS="${SAMBA_CPPFLAGS} -I${srcdir-.}/.."
42
43 SAMBA_CONFIGURE_CPPFLAGS="${SAMBA_CPPFLAGS} -I${srcdir-.}/../lib/popt"
44
45 ## cleanup the $(srcdir) in the Makefile if we are outside of the tree
46 if test "x${srcdir-.}" != "x."; then
47         SAMBA_CPPFLAGS=`echo ${SAMBA_CPPFLAGS} | sed -e "s;${srcdir};\$\(srcdir\);g"`
48 fi
49
50 dnl Unique-to-Samba variables we'll be playing with.
51 AC_SUBST(SAMBA_CPPFLAGS)
52 AC_SUBST(SHELL)
53 AC_SUBST(LDSHFLAGS)
54 AC_SUBST(SONAMEFLAG)
55 AC_SUBST(SHLD)
56 AC_SUBST(MODULE_EXPORTS)
57 AC_SUBST(DSO_EXPORTS)
58 AC_SUBST(HOST_OS)
59 AC_SUBST(PICFLAG)
60 AC_SUBST(PIE_CFLAGS)
61 AC_SUBST(PIE_LDFLAGS)
62 AC_SUBST(RELRO_LDFLAGS)
63 AC_SUBST(SHLIBEXT)
64 AC_SUBST(INSTALLLIBCMD_SH)
65 AC_SUBST(INSTALLLIBCMD_A)
66 AC_SUBST(UNINSTALLLIBCMD_SH)
67 AC_SUBST(UNINSTALLLIBCMD_A)
68
69 AC_SUBST(INSTALL_LIBWBCLIENT)
70 AC_SUBST(UNINSTALL_LIBWBCLIENT)
71 AC_SUBST(LIBWBCLIENT_SHARED_TARGET)
72 AC_SUBST(LIBWBCLIENT_SHARED)
73 AC_SUBST(LIBWBCLIENT_STATIC_TARGET)
74 AC_SUBST(LIBWBCLIENT_STATIC)
75 AC_SUBST(LIBWBCLIENT_SOVER)
76 AC_SUBST(LIBWBCLIENT)
77 AC_SUBST(LIBWBCLIENT_LIBS)
78
79 AC_SUBST(LIBSAMBAUTIL_SHARED)
80
81 AC_SUBST(PRINT_LIBS)
82 AC_SUBST(AUTH_LIBS)
83 AC_SUBST(ACL_LIBS)
84 AC_SUBST(PASSDB_LIBS)
85 AC_SUBST(IDMAP_LIBS)
86 AC_SUBST(KRB5_LIBS)
87 AC_SUBST(UUID_LIBS)
88 AC_SUBST(LDAP_LIBS)
89 AC_SUBST(GPEXT_LIBS)
90 AC_SUBST(PAM_MODULES)
91 AC_SUBST(INSTALL_PAM_MODULES)
92 AC_SUBST(UNINSTALL_PAM_MODULES)
93 AC_SUBST(NSS_MODULES)
94 AC_SUBST(EXTRA_BIN_PROGS)
95 AC_SUBST(CIFSMOUNT_PROGS)
96 AC_SUBST(INSTALL_CIFSMOUNT)
97 AC_SUBST(UNINSTALL_CIFSMOUNT)
98 AC_SUBST(CIFSUMOUNT_PROGS)
99 AC_SUBST(INSTALL_CIFSUMOUNT)
100 AC_SUBST(UNINSTALL_CIFSUMOUNT)
101 AC_SUBST(CIFSUPCALL_PROGS)
102 AC_SUBST(INSTALL_CIFSUPCALL)
103 AC_SUBST(UNINSTALL_CIFSUPCALL)
104 AC_SUBST(EXTRA_SBIN_PROGS)
105 AC_SUBST(EXTRA_ALL_TARGETS)
106 AC_SUBST(CONFIG_LIBS)
107 AC_SUBST(NSCD_LIBS)
108
109 # compile with optimization and without debugging by default, but
110 # allow people to set their own preference.
111 # do this here since AC_CACHE_CHECK apparently sets the CFLAGS to "-g -O2"
112 # if it has no value.  This prevent *very* large debug binaries from occurring
113 # by default.
114 if test "x$debug" = "xyes" ; then
115         CFLAGS="${CFLAGS} -g"
116 fi
117 if test "x$CFLAGS" = x; then
118   CFLAGS="-O"
119 fi
120
121 m4_include(../lib/socket_wrapper/config.m4)
122 m4_include(../lib/nss_wrapper/config.m4)
123
124 m4_include(m4/swat.m4)
125
126 DEVELOPER_CFLAGS="-DDEBUG_PASSWORD -DDEVELOPER"
127
128 # Probe the gcc version for extra CFLAGS. We always stash these in
129 # DEVELOPER_CFLAGS, so that you can turn them on and off with a simple
130 # Makefile edit, avoiding the need to re-run configure.
131 if test x"$ac_cv_prog_gcc" = x"yes" ; then
132         DEVELOPER_CFLAGS="${DEVELOPER_CFLAGS} -g -Wall -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings"
133         # Add -Wdeclaration-after-statement if compiler supports it
134         AC_CACHE_CHECK(
135           [that the C compiler understands -Wdeclaration-after-statement],
136           samba_cv_HAVE_Wdeclaration_after_statement, [
137           AC_TRY_RUN_STRICT([
138             int main(void)
139             {
140                 return 0;
141             }],[$CFLAGS -Wdeclaration-after-statement],[$CPPFLAGS],[$LDFLAGS],
142             samba_cv_HAVE_Wdeclaration_after_statement=yes,
143             samba_cv_HAVE_Wdeclaration_after_statement=no,
144             samba_cv_HAVE_Wdeclaration_after_statement=cross)
145        ])
146
147         if test x"$samba_cv_HAVE_Wdeclaration_after_statement" = x"yes"; then
148             DEVELOPER_CFLAGS="${DEVELOPER_CFLAGS} -Wdeclaration-after-statement"
149         fi
150
151         #-Werror-implicit-function-declaration
152         AC_CACHE_CHECK(
153           [that the C compiler understands -Werror-implicit-function-declaration],
154           samba_cv_HAVE_Werror_implicit_function_declaration, [
155           AC_TRY_RUN_STRICT([
156             int main(void)
157             {
158                 return 0;
159             }],[$CFLAGS -Werror-implicit-function-declaration],[$CPPFLAGS],[$LDFLAGS],
160             samba_cv_HAVE_Werror_implicit_function_declaration=yes,
161             samba_cv_HAVE_Werror_implicit_function_declaration=no,
162             samba_cv_HAVE_Werror_implicit_function_declaration=cross)
163        ])
164        if test x"$samba_cv_HAVE_Werror_implicit_function_declaration" = x"yes"; then
165             DEVELOPER_CFLAGS="${DEVELOPER_CFLAGS} -Werror-implicit-function-declaration"
166        fi
167
168         # krb5developer is like developer, except we don't get
169         # -Wstrict-prototypes.
170        if test x"$krb5_developer" != x"$yes" ; then
171             DEVELOPER_CFLAGS="$DEVELOPER_CFLAGS -Wstrict-prototypes"
172        fi
173
174        if test x"$picky_developer" = x"yes"; then
175             DEVELOPER_CFLAGS="$DEVELOPER_CFLAGS -Werror"
176        fi
177 fi
178
179 #################################################
180 # check for a shared memory profiling support
181 AC_MSG_CHECKING(whether to use profiling)
182 AC_ARG_WITH(profiling-data,
183 [AS_HELP_STRING([--with-profiling-data], [Include gathering source code profile information (default=no)])],
184 [ case "$withval" in
185   yes)
186     AC_MSG_RESULT(yes)
187     AC_DEFINE(WITH_PROFILE,1,[Whether to use profiling])
188     samba_cv_WITH_PROFILE=yes
189     ;;
190   *)
191     AC_MSG_RESULT(no)
192     samba_cv_WITH_PROFILE=no
193     ;;
194   esac ],
195   AC_MSG_RESULT(no)
196 )
197
198 dnl Checks for programs.
199 smbtorture4_possible=yes
200
201 AC_PROG_INSTALL
202 AC_PROG_AWK
203 # Check for GNU make
204 m4_include(../m4/check_make.m4)
205 AC_SAMBA_GNU_MAKE([true], [true])
206
207 # Check for perl
208 m4_include(../m4/check_perl.m4)
209 AC_SAMBA_PERL([true], [smbtorture4_possible=no])
210
211 # Check for python
212 m4_include(../m4/check_python.m4)
213 AC_SAMBA_PYTHON_DEVEL([true], [smbtorture4_possible=no])
214
215 AC_CHECK_TOOL(AR, ar)
216
217 dnl Check if we (actually our C compiler!) use GNU ld
218 AC_PROG_LD_GNU
219
220 dnl Certain versions of GNU ld the default is not to have the
221 dnl --allow-shlib-undefined flag defined.  This causes a stackload of
222 dnl warnings when building modules.
223 if test "$ac_cv_prog_gnu_ld" = "yes"; then
224         ac_cv_gnu_ld_version=`$CC -Wl,-v /dev/null 2>&1 < /dev/null | grep "GNU ld"`
225         AC_MSG_CHECKING(GNU ld release date)
226         changequote(,)dnl
227         ac_cv_gnu_ld_date=`echo $ac_cv_gnu_ld_version | sed -n 's,^.*\([2-9][0-9][0-9][0-9]\)[-]*\([01][0-9]\)[-]*\([0-3][0-9]\).*$,\1\2\3,p'`
228         changequote([,])dnl
229         AC_MSG_RESULT(${ac_cv_gnu_ld_date})
230         if test -n "$ac_cv_gnu_ld_date"; then
231         if test "$ac_cv_gnu_ld_date" -lt 20030217; then
232                 ac_cv_gnu_ld_no_default_allow_shlib_undefined=yes
233         fi
234         if test "$ac_cv_gnu_ld_date" -gt 20030101; then
235                 ac_cv_gnu_ld_version_script=yes
236         fi
237         else
238            AC_MSG_CHECKING(GNU ld release version)
239            changequote(,)dnl
240            ac_cv_gnu_ld_vernr=`echo $ac_cv_gnu_ld_version | awk '{print $NF}' | sed -n 's,\([1-9][0-9]*\.[0-9][0-9]*\).*$,\1,p'`
241            ac_cv_gnu_ld_vernr_major=`echo $ac_cv_gnu_ld_vernr | cut -d '.' -f 1`
242            ac_cv_gnu_ld_vernr_minor=`echo $ac_cv_gnu_ld_vernr | cut -d '.' -f 2`
243            changequote([,])dnl
244            AC_MSG_RESULT(${ac_cv_gnu_ld_vernr})
245            AC_MSG_CHECKING(GNU ld release version major)
246            AC_MSG_RESULT(${ac_cv_gnu_ld_vernr_major})
247            AC_MSG_CHECKING(GNU ld release version minor)
248            AC_MSG_RESULT(${ac_cv_gnu_ld_vernr_minor})
249            if test "$ac_cv_gnu_ld_vernr_major" -lt 2 || test "$ac_cv_gnu_ld_vernr_minor" -lt 14; then
250              ac_cv_gnu_ld_no_default_allow_shlib_undefined=yes
251            fi
252            if test "$ac_cv_gnu_ld_vernr_major" -gt 2 || test "$ac_cv_gnu_ld_vernr_major" = 2 && test "$ac_cv_gnu_ld_vernr_minor" -ge 12; then
253              ac_cv_gnu_ld_version_script=yes
254            fi
255         fi
256 fi
257
258 dnl look for executable suffix
259 AC_EXEEXT
260
261 dnl Check if C compiler understands -c and -o at the same time
262 AC_PROG_CC_C_O
263 if eval "test \"`echo '$ac_cv_prog_cc_'${ac_cc}_c_o`\" = no"; then
264       BROKEN_CC=
265 else
266       BROKEN_CC=#
267 fi
268 AC_SUBST(BROKEN_CC)
269
270 dnl Check if the C compiler understands -Werror (GNU)
271 AC_CACHE_CHECK([that the C compiler understands -Werror],samba_cv_HAVE_Werror, [
272  AC_TRY_RUN_STRICT([
273   int main(void)
274   {
275         return 0;
276   }],[$CFLAGS -Werror],[$CPPFLAGS],[$LDFLAGS],
277   samba_cv_HAVE_Werror=yes,samba_cv_HAVE_Werror=no,samba_cv_HAVE_Werror=cross)])
278 if test x"$samba_cv_HAVE_Werror" = x"yes"; then
279    Werror_FLAGS="-Werror"
280 else
281 dnl Check if the C compiler understands -w2
282 AC_CACHE_CHECK([that the C compiler understands -w2],samba_cv_HAVE_w2, [
283  AC_TRY_RUN_STRICT([
284   int main(void)
285   {
286         return 0;
287   }],[$CFLAGS -w2],[$CPPFLAGS],[$LDFLAGS],
288   samba_cv_HAVE_w2=yes,samba_cv_HAVE_w2=no,samba_cv_HAVE_w2=cross)])
289 if test x"$samba_cv_HAVE_w2" = x"yes"; then
290    Werror_FLAGS="-w2"
291 else
292 dnl Check if the C compiler understands -errwarn (Sun)
293 AC_CACHE_CHECK([that the C compiler understands -errwarn],samba_cv_HAVE_errwarn, [
294   AC_TRY_RUN_STRICT([
295    int main(void)
296    {
297         return 0;
298    }],[$CFLAGS -errwarn=%all],[$CPPFLAGS],[$LDFLAGS],
299    samba_cv_HAVE_errwarn=yes,samba_cv_HAVE_errwarn=no,samba_cv_HAVE_errwarn=cross)])
300 if test x"$samba_cv_HAVE_errwarn" = x"yes"; then
301    Werror_FLAGS="-errwarn=%all"
302 else
303 dnl Check if the C compiler understands -qhalt (IBM)
304 AC_CACHE_CHECK([that the C compiler understands -qhalt],samba_cv_HAVE_qhalt, [
305   AC_TRY_RUN_STRICT([
306    int main(void)
307    {
308         return 0;
309    }],[$CFLAGS -qhalt=w],[$CPPFLAGS],[$LDFLAGS],
310    samba_cv_HAVE_qhalt=yes,samba_cv_HAVE_qhalt=no,samba_cv_HAVE_qhalt=cross)])
311 if test x"$samba_cv_HAVE_qhalt" = x"yes"; then
312    Werror_FLAGS="-qhalt=w"
313 fi
314 fi
315 fi
316 fi
317
318 ############################################
319 # check if the compiler can handle negative enum values
320 # and don't truncate the values to INT_MAX
321 # a runtime test is needed here
322 AC_SUBST(PIDL_ARGS)
323 AC_CACHE_CHECK([that the C compiler understands negative enum values],samba_cv_CC_NEGATIVE_ENUM_VALUES, [
324     AC_TRY_RUN(
325 [
326         #include <stdio.h>
327         enum negative_values { NEGATIVE_VALUE = 0xFFFFFFFF };
328         int main(void) {
329                 enum negative_values v1 = NEGATIVE_VALUE;
330                 unsigned v2 = NEGATIVE_VALUE;
331
332                 if (v1 != 0xFFFFFFFF) {
333                         printf("%u != 0xFFFFFFFF\n", v1);
334                         return 1;
335                 }
336                 if (v2 != 0xFFFFFFFF) {
337                         printf("%u != 0xFFFFFFFF\n", v2);
338                         return 1;
339                 }
340
341                 return 0;
342         }
343 ],
344         samba_cv_CC_NEGATIVE_ENUM_VALUES=yes,samba_cv_CC_NEGATIVE_ENUM_VALUES=no)])
345 if test x"$samba_cv_CC_NEGATIVE_ENUM_VALUES" != x"yes"; then
346         AC_MSG_WARN([using --uint-enums for pidl])
347         PIDL_ARGS="$PIDL_ARGS --uint-enums"
348 fi
349
350 dnl Figure out the flags to support named structure initializers
351
352 LIBREPLACE_C99_STRUCT_INIT([],[AC_MSG_ERROR([c99 structure initializer are not supported])])
353
354 UNAME_S=`(uname -s) 2>/dev/null` || UNAME_S="unknown"
355 AC_MSG_CHECKING(uname -s)
356 AC_MSG_RESULT(${UNAME_S})
357
358 UNAME_R=`(uname -r) 2>/dev/null` || UNAME_R="unknown"
359 AC_MSG_CHECKING(uname -r)
360 AC_MSG_RESULT(${UNAME_R})
361
362 UNAME_M=`(uname -m) 2>/dev/null` || UNAME_M="unknown"
363 AC_MSG_CHECKING(uname -m)
364 AC_MSG_RESULT(${UNAME_M})
365
366 UNAME_P=`(uname -p) 2>/dev/null` || UNAME_P="unknown"
367 AC_MSG_CHECKING(uname -p)
368 AC_MSG_RESULT(${UNAME_P})
369
370 UNAME_I=`(uname -i) 2>/dev/null` || UNAME_I="unknown"
371 AC_MSG_CHECKING(uname -i)
372 AC_MSG_RESULT(${UNAME_I})
373
374 dnl Add #include for broken IRIX header files
375   case "$host_os" in
376         *irix6*)
377                 #TODO add to libreplace
378                 if test x"$ac_cv_prog_gcc" != x"yes" ; then
379                         dnl Fix sensible defaults for MIPSPro compilers. The
380                         dnl error numbers are valid for the 7.3 compilers,
381                         dnl hopefully also valid for the 7.4 series.
382                         dnl
383                         dnl Bugzilla 3801. Force an error on warning 1035
384                         dnl so we don't incorrectly detect stdint.h. This
385                         dnl warning is emitted for #error directives.
386                         CFLAGS="$CFLAGS -diag_error 1035"
387                         dnl 1209: Controlling expression is constant
388                         dnl 1174: Function foo declared but never referenced
389                         dnl 3201: Parameter foo was never referenced
390                         CFLAGS="$CFLAGS -woff 1209,1174,3201"
391                 fi
392         ;;
393 esac
394
395 DYNEXP=
396 AC_SUBST(DYNEXP)
397 LDSHFLAGS_Z_DEFS=
398 AC_SUBST(LDSHFLAGS_Z_DEFS)
399 LDSHFLAGS_Z_NODEFS=
400 AC_SUBST(LDSHFLAGS_Z_NODEFS)
401
402 dnl Add modules that have to be built by default here
403 dnl These have to be built static:
404 default_static_modules=""
405 default_static_modules="$default_static_modules pdb_smbpasswd"
406 default_static_modules="$default_static_modules pdb_tdbsam"
407 default_static_modules="$default_static_modules pdb_wbc_sam"
408 default_static_modules="$default_static_modules rpc_lsarpc"
409 default_static_modules="$default_static_modules rpc_samr"
410 default_static_modules="$default_static_modules rpc_winreg"
411 default_static_modules="$default_static_modules rpc_initshutdown"
412 default_static_modules="$default_static_modules rpc_dssetup"
413 default_static_modules="$default_static_modules rpc_wkssvc"
414 default_static_modules="$default_static_modules rpc_svcctl"
415 default_static_modules="$default_static_modules rpc_ntsvcs"
416 default_static_modules="$default_static_modules rpc_netlogon"
417 default_static_modules="$default_static_modules rpc_netdfs"
418 default_static_modules="$default_static_modules rpc_srvsvc"
419 default_static_modules="$default_static_modules rpc_spoolss"
420 default_static_modules="$default_static_modules rpc_eventlog"
421 default_static_modules="$default_static_modules auth_sam"
422 default_static_modules="$default_static_modules auth_unix"
423 default_static_modules="$default_static_modules auth_winbind"
424 default_static_modules="$default_static_modules auth_wbc"
425 default_static_modules="$default_static_modules auth_server"
426 default_static_modules="$default_static_modules auth_domain"
427 default_static_modules="$default_static_modules auth_builtin"
428 default_static_modules="$default_static_modules vfs_default"
429 default_static_modules="$default_static_modules nss_info_template"
430
431 dnl These are preferably build shared, and static if dlopen() is not available
432 default_shared_modules=""
433 default_shared_modules="$default_shared_modules vfs_recycle"
434 default_shared_modules="$default_shared_modules vfs_audit"
435 default_shared_modules="$default_shared_modules vfs_extd_audit"
436 default_shared_modules="$default_shared_modules vfs_full_audit"
437 default_shared_modules="$default_shared_modules vfs_netatalk"
438 default_shared_modules="$default_shared_modules vfs_fake_perms"
439 default_shared_modules="$default_shared_modules vfs_default_quota"
440 default_shared_modules="$default_shared_modules vfs_readonly"
441 default_shared_modules="$default_shared_modules vfs_cap"
442 default_shared_modules="$default_shared_modules vfs_expand_msdfs"
443 default_shared_modules="$default_shared_modules vfs_shadow_copy"
444 default_shared_modules="$default_shared_modules vfs_shadow_copy2"
445 default_shared_modules="$default_shared_modules charset_CP850"
446 default_shared_modules="$default_shared_modules charset_CP437"
447 default_shared_modules="$default_shared_modules auth_script"
448 default_shared_modules="$default_shared_modules vfs_readahead"
449 default_shared_modules="$default_shared_modules vfs_xattr_tdb"
450 default_shared_modules="$default_shared_modules vfs_streams_xattr"
451 default_shared_modules="$default_shared_modules vfs_streams_depot"
452 default_shared_modules="$default_shared_modules vfs_acl_xattr"
453 default_shared_modules="$default_shared_modules vfs_acl_tdb"
454 default_shared_modules="$default_shared_modules vfs_smb_traffic_analyzer"
455 default_shared_modules="$default_shared_modules vfs_preopen"
456 default_shared_modules="$default_shared_modules vfs_catia"
457 default_shared_modules="$default_shared_modules vfs_scannedonly"
458 default_shared_modules="$default_shared_modules vfs_crossrename"
459 default_shared_modules="$default_shared_modules vfs_linux_xfs_sgid"
460 default_shared_modules="$default_shared_modules vfs_time_audit"
461 default_shared_modules="$default_shared_modules idmap_autorid"
462
463 if test "x$developer" = xyes; then
464    default_static_modules="$default_static_modules rpc_rpcecho pdb_ads"
465    default_static_modules="$default_static_modules auth_netlogond"
466    default_shared_modules="$default_shared_modules charset_weird perfcount_test"
467 fi
468
469 #
470 # Config CPPFLAG settings for strange OS's that must be set
471 # before other tests. Do NOT invoke AC_CHECK_HEADERS within this
472 # case statement; its first reference must be unconditional.
473 #
474 case "$host_os" in
475     *hpux*)
476 #
477 # Defines needed for HPUX support.
478 # HPUX has bigcrypt but (sometimes?) doesn't use it for
479 # password hashing - hence the USE_BOTH_CRYPT_CALLS define.
480 #
481       case `uname -r` in
482                 *9*|*10*|*11)
483                         AC_DEFINE(USE_BOTH_CRYPT_CALLS, 1, [Whether to use both of HPUX' crypt calls])
484                 ;;
485       esac
486       ;;
487
488 #
489 # CRAY Unicos has broken const handling
490        *unicos*)
491           AC_MSG_RESULT([disabling const])
492           CPPFLAGS="$CPPFLAGS -Dconst="
493           ;;
494         
495 #
496 # AIX4.x doesn't even admit to having large
497 # files *at all* unless the -D_LARGE_FILE or -D_LARGE_FILE_API flags are set.
498 #
499     *aix4*)
500           AC_MSG_RESULT([enabling large file support])
501       CPPFLAGS="$CPPFLAGS -D_LARGE_FILES"
502           AC_DEFINE(_LARGE_FILES, 1, [Whether to enable large file support])
503       ;;
504 #
505 # Defines needed for Solaris 2.6/2.7 aka 7.0 to make it admit
506 # to the existance of large files..
507 # Note that -D_LARGEFILE64_SOURCE is different from the Sun
508 # recommendations on large file support, however it makes the
509 # compile work using gcc 2.7 and 2.8, whereas using the Sun
510 # recommendation makes the compile fail on gcc2.7. JRA.
511 #
512 # Solaris uses SYSV printing.  Make sure to set that here.  --jerry
513 #
514         *solaris*)
515                 AC_DEFINE(SYSV, 1, [Whether to enable System V compatibility])
516                 case `uname -r` in
517                         5.0|5.0.*|5.1|5.1.*|5.2|5.2.*|5.3|5.3.*|5.5|5.5.*)
518                                 AC_MSG_RESULT([no large file support])
519                                 ;;
520                         5.*)
521                         AC_MSG_RESULT([enabling large file support])
522                         if test "$ac_cv_prog_gcc" = yes; then
523                                 ${CC-cc} -v >conftest.c 2>&1
524                                 ac_cv_gcc_compiler_version_number=`grep 'gcc version' conftest.c`
525                                 rm -fr conftest.c
526                                 case "$ac_cv_gcc_compiler_version_number" in
527                                         *"gcc version 2.6"*|*"gcc version 2.7"*)
528                                                 CPPFLAGS="$CPPFLAGS -D_LARGEFILE64_SOURCE -D_REENTRANT"
529                                                 LDFLAGS="$LDFLAGS -lthread"
530                                                 AC_DEFINE(_LARGEFILE64_SOURCE, 1, [Whether to enable large file support])
531                                                 ;;
532                                         *)
533                                                 CPPFLAGS="$CPPFLAGS -D_LARGEFILE_SOURCE -D_REENTRANT -D_FILE_OFFSET_BITS=64"
534                                                 LDFLAGS="$LDFLAGS -lthread"
535                                                 AC_DEFINE(_LARGEFILE64_SOURCE, 1, [Whether to enable large file support])
536                                                 AC_DEFINE(_FILE_OFFSET_BITS, 64, [File offset bits])
537                                                 ;;
538                                 esac
539                         else
540                                 CPPFLAGS="$CPPFLAGS -D_LARGEFILE_SOURCE -D_REENTRANT -D_FILE_OFFSET_BITS=64"
541                                 LDFLAGS="$LDFLAGS -lthread"
542                                 AC_DEFINE(_LARGEFILE64_SOURCE, 1, [Whether to enable large file support])
543                                 AC_DEFINE(_FILE_OFFSET_BITS, 64, [File offset bits])
544                         fi
545                         ;;
546                 esac
547                 ;;
548 #
549 # IRIX uses SYSV printing.  Make sure to set that here
550 #
551         *irix*)
552                 AC_DEFINE(SYSV, 1, [Whether to enable System V compatibility])
553                 ;;
554         *freebsd*|*dragonfly*)
555                 AC_DEFINE(FREEBSD, 1, [Whether the host os is FreeBSD])
556                 ;;
557 #
558 # VOS may need to have POSIX support and System V compatibility enabled.
559 #
560     *vos*)
561     case "$CPPFLAGS" in
562           *-D_POSIX_C_SOURCE*)
563                 ;;
564           *)
565                 CPPFLAGS="$CPPFLAGS -D_POSIX_C_SOURCE=200112L"
566                 AC_DEFINE(_POSIX_C_SOURCE, 200112L, [Whether to enable POSIX support])
567                 ;;
568     esac
569     case "$CPPFLAGS" in
570           *-D_SYSV*|*-D_SVID_SOURCE*)
571                 ;;
572           *)
573                 CPPFLAGS="$CPPFLAGS -D_SYSV"
574                 AC_DEFINE(_SYSV, 1, [Whether to enable System V compatibility])
575     esac
576     ;;
577 #
578 # Tests needed for SINIX large file support.
579 #
580     *sysv4*)
581       if test $host = mips-sni-sysv4 ; then
582         AC_MSG_CHECKING([for LFS support])
583         old_CPPFLAGS="$CPPFLAGS"
584         CPPFLAGS="-D_LARGEFILE64_SOURCE $CPPFLAGS"
585         AC_TRY_RUN([
586 #include <unistd.h>
587 main () {
588 #if _LFS64_LARGEFILE == 1
589 exit(0);
590 #else
591 exit(1);
592 #endif
593 }], [SINIX_LFS_SUPPORT=yes], [SINIX_LFS_SUPPORT=no], [SINIX_LFS_SUPPORT=cross])
594         CPPFLAGS="$old_CPPFLAGS"
595         if test x$SINIX_LFS_SUPPORT = xyes ; then
596           CPPFLAGS="-D_LARGEFILE64_SOURCE $CPPFLAGS"
597                   AC_DEFINE(_LARGEFILE64_SOURCE, 1, [Whether to enable large file support])
598           CFLAGS="`getconf LFS64_CFLAGS` $CFLAGS"
599           LDFLAGS="`getconf LFS64_LDFLAGS` $LDFLAGS"
600           LIBS="`getconf LFS64_LIBS` $LIBS"
601         fi
602       AC_MSG_RESULT([$SINIX_LFS_SUPPORT])
603       fi
604     ;;
605
606 # Systems with LFS support.
607 #
608     gnu* | k*bsd*-gnu | kopensolaris*-gnu)
609         CPPFLAGS="-D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE $CPPFLAGS"
610         AC_DEFINE(_LARGEFILE64_SOURCE, 1, [Whether to enable large file support])
611         AC_DEFINE(_FILE_OFFSET_BITS, 64, [File offset bits])
612         AC_DEFINE(_GNU_SOURCE, 1, [Whether to use GNU libc extensions])
613         ;;
614
615 # Tests for linux LFS support. Need kernel 2.4 and glibc2.2 or greater support.
616 #
617     *linux*)
618         AC_MSG_CHECKING([for LFS support])
619         old_CPPFLAGS="$CPPFLAGS"
620         CPPFLAGS="-D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE $CPPFLAGS"
621        AC_TRY_RUN([
622 #include <unistd.h>
623 #include <sys/utsname.h>
624 #include <string.h>
625 #include <stdlib.h>
626 main() {
627 #if _LFS64_LARGEFILE == 1
628        struct utsname uts;
629        char *release;
630        int major, minor;
631
632        /* Ensure this is glibc 2.2 or higher */
633 #if defined(__GLIBC__) && defined(__GLIBC_MINOR__)
634        int libc_major = __GLIBC__;
635        int libc_minor = __GLIBC_MINOR__;
636
637        if (libc_major < 2)
638               exit(1);
639        if (libc_minor < 2)
640               exit(1);
641 #endif
642
643        /* Ensure this is kernel 2.4 or higher */
644
645        uname(&uts);
646        release = strdup(uts.release);
647        major = atoi(strsep(&release, "."));
648        minor = atoi(strsep(&release, "."));
649
650        if (major > 2 || (major == 2 && minor > 3))
651                exit(0);
652        exit(1);
653 #else
654        exit(1);
655 #endif
656 }
657 ], [LINUX_LFS_SUPPORT=yes], [LINUX_LFS_SUPPORT=no], [LINUX_LFS_SUPPORT=cross])
658         CPPFLAGS="$old_CPPFLAGS"
659         if test x$LINUX_LFS_SUPPORT = xyes ; then
660                 CPPFLAGS="-D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE $CPPFLAGS"
661                 AC_DEFINE(_LARGEFILE64_SOURCE, 1, [Whether to enable large file support])
662                 AC_DEFINE(_FILE_OFFSET_BITS, 64, [File offset bits])
663                 AC_DEFINE(_GNU_SOURCE, 1, [Whether to use GNU libc extensions])
664         fi
665         AC_MSG_RESULT([$LINUX_LFS_SUPPORT])
666         ;;
667
668 #
669 # MacOS X is the *only* system that uses compose character in utf8. This
670 # is so horribly broken....
671 #
672     *darwin*)
673         AC_DEFINE(BROKEN_UNICODE_COMPOSE_CHARACTERS, 1, [Does this system use unicode compose characters])
674
675 # Add a system specific charset module.
676         default_shared_modules="$default_shared_modules charset_macosxfs"
677
678         ;;
679     *hurd*)
680         AC_MSG_CHECKING([for LFS support])
681         old_CPPFLAGS="$CPPFLAGS"
682         CPPFLAGS="-D_LARGEFILE64_SOURCE -D_GNU_SOURCE $CPPFLAGS"
683         AC_TRY_RUN([
684 #include <unistd.h>
685 main () {
686 #if _LFS64_LARGEFILE == 1
687 exit(0);
688 #else
689 exit(1);
690 #endif
691 }], [GLIBC_LFS_SUPPORT=yes], [GLIBC_LFS_SUPPORT=no], [GLIBC_LFS_SUPPORT=cross])
692         CPPFLAGS="$old_CPPFLAGS"
693         if test x$GLIBC_LFS_SUPPORT = xyes ; then
694           CPPFLAGS="-D_LARGEFILE64_SOURCE -D_GNU_SOURCE $CPPFLAGS"
695                   AC_DEFINE(_LARGEFILE64_SOURCE, 1, [Whether to enable large file support])
696           AC_DEFINE(_GNU_SOURCE, 1, [Whether to use GNU libc extensions])
697         fi
698       AC_MSG_RESULT([$GLIBC_LFS_SUPPORT])
699     ;;
700     *qnx*)
701         CPPFLAGS="-D_LARGEFILE64_SOURCE $CPPFLAGS"
702         AC_DEFINE(_LARGEFILE64_SOURCE, 1, [Whether to enable large file support])
703         ;;
704
705 esac
706
707 SAVE_CPPFLAGS="${CPPFLAGS}"
708 CPPFLAGS="${CPPFLAGS} ${SAMBA_CONFIGURE_CPPFLAGS}"
709
710 AC_LIBREPLACE_BROKEN_CHECKS
711 AC_CHECK_FUNCS([syslog],[],[AC_MSG_ERROR([Required function not found])])
712 AC_LIBREPLACE_NETWORK_CHECKS
713
714 CPPFLAGS="${SAVE_CPPFLAGS}"
715
716 LIBREPLACE_DIR=`echo ${libreplacedir} | sed -e "s;${srcdir};;" -e "s;^/;;"`
717
718 LIBREPLACE_OBJS="${LIBREPLACEOBJ}"
719 AC_SUBST(LIBREPLACE_OBJS)
720
721 LIBREPLACE_LIBS="${LIBREPLACE_NETWORK_LIBS}"
722 AC_SUBST(LIBREPLACE_LIBS)
723
724
725 # add -ldl to the global LIBS
726 LIBS="${LIBS} ${LIBDL} ${LIBREPLACE_NETWORK_LIBS}"
727 AUTH_LIBS="${AUTH_LIBS} ${CRYPT_LIBS}"
728
729
730 AC_CHECK_HEADERS(aio.h sys/fcntl.h sys/select.h fcntl.h sys/time.h sys/unistd.h rpc/nettype.h)
731 AC_CHECK_HEADERS(unistd.h grp.h sys/id.h memory.h alloca.h)
732 AC_CHECK_HEADERS(limits.h float.h libintl.h)
733 AC_CHECK_HEADERS(rpc/rpc.h rpcsvc/nis.h rpcsvc/ypclnt.h)
734 AC_CHECK_HEADERS(sys/param.h ctype.h sys/wait.h sys/resource.h sys/ioctl.h sys/ipc.h sys/prctl.h sys/sysctl.h)
735 AC_CHECK_HEADERS(sys/mman.h sys/filio.h sys/priv.h sys/shm.h string.h strings.h stdlib.h)
736 AC_CHECK_HEADERS(sys/mount.h sys/vfs.h sys/fs/s5param.h sys/filsys.h termios.h termio.h)
737 AC_CHECK_HEADERS(sys/termio.h sys/statfs.h sys/dustat.h sys/statvfs.h stdarg.h)
738 AC_CHECK_HEADERS(sys/sysmacros.h)
739 AC_CHECK_HEADERS(sys/syslog.h syslog.h)
740 AC_CHECK_HEADERS(langinfo.h locale.h)
741 AC_CHECK_HEADERS(xfs/libxfs.h)
742 AC_CHECK_HEADERS(netgroup.h)
743 AC_CHECK_HEADERS(linux/falloc.h)
744
745 AC_CHECK_HEADERS(rpcsvc/yp_prot.h,,,[[
746 #if HAVE_RPC_RPC_H
747 #include <rpc/rpc.h>
748 #endif
749 ]])
750
751 ## These fail to compile on IRIX so just check for their presence
752 AC_CHECK_HEADERS(sys/mode.h,,,)
753
754 # Look for Darwin headers
755 old_CPPFLAGS="$CPPFLAGS"
756 CPPFLAGS="-Iinclude $CPPFLAGS"
757 AC_CHECK_HEADERS([CoreFoundation/CFStringEncodingConverter.h], [], [AC_CHECK_HEADERS([CFStringEncodingConverter.h])])
758 CPPFLAGS="$old_CPPFLAGS"
759
760 # In valgrind 1.0.x, it's just valgrind.h.  In 1.9.x+ there's a
761 # subdirectory of headers.
762 AC_CHECK_HEADERS(valgrind.h valgrind/valgrind.h valgrind/memcheck.h)
763
764 if test x"$enable_developer" = x"yes" ; then
765    if test x"$ac_cv_header_valgrind_h" = xyes -o \
766            x"$ac_cv_header_valgrind_valgrind_h" = xyes ; then
767       AC_DEFINE(VALGRIND,1,[Whether we have valgrind headers])
768    fi
769 fi
770
771 #
772 # HPUX has a bug in that including shadow.h causes a re-definition of MAXINT.
773 # This causes configure to fail to detect it. Check for shadow separately on HPUX.
774 #
775 case "$host_os" in
776     *hpux*)
777                 AC_TRY_COMPILE([#include <shadow.h>],[struct spwd testme],
778                         ac_cv_header_shadow_h=yes,ac_cv_header_shadow_h=no)
779                 if test x"$ac_cv_header_shadow_h" = x"yes"; then
780                    AC_DEFINE(HAVE_SHADOW_H,1,[Whether we have shadow.h])
781                 fi
782         ;;
783 esac
784 AC_CHECK_HEADERS(shadow.h)
785 AC_CHECK_HEADERS(nss.h nss_common.h nsswitch.h ns_api.h sys/security.h)
786 AC_CHECK_HEADERS(syscall.h sys/syscall.h)
787
788 AC_CHECK_HEADERS(sys/attributes.h attr/xattr.h sys/xattr.h sys/extattr.h sys/uio.h)
789 AC_CHECK_HEADERS(sys/ea.h sys/proplist.h)
790
791 AC_CHECK_HEADERS(sys/cdefs.h glob.h)
792
793 # For experimental utmp support (lastlog on some BSD-like systems)
794 AC_CHECK_HEADERS(utmp.h utmpx.h lastlog.h)
795
796 AC_CHECK_SIZEOF(int,cross)
797 AC_CHECK_SIZEOF(long,cross)
798 AC_CHECK_SIZEOF(long long,cross)
799 AC_CHECK_SIZEOF(short,cross)
800
801 AC_C_CONST
802 AC_C_INLINE
803 AC_C_BIGENDIAN
804 AC_C_CHAR_UNSIGNED
805
806 AC_TYPE_SIGNAL
807 AC_TYPE_UID_T
808 AC_TYPE_MODE_T
809 AC_TYPE_OFF_T
810 AC_TYPE_SIZE_T
811 AC_TYPE_PID_T
812 AC_STRUCT_ST_RDEV
813 AC_DIRENT_D_OFF
814 AC_CHECK_TYPE(ssize_t, int)
815 AC_CHECK_TYPE(wchar_t, unsigned short)
816
817 ############################################
818 # for cups support we need libcups, and a handful of header files
819
820 AC_ARG_ENABLE(cups,
821 [AS_HELP_STRING([--enable-cups], [Turn on CUPS support (default=auto)])])
822
823 if test x$enable_cups != xno; then
824         AC_PATH_PROG(CUPS_CONFIG, cups-config)
825
826         if test "x$CUPS_CONFIG" != x; then
827
828                 ac_save_LDFLAGS=$LDFLAGS
829                 ac_save_PRINT_LIBS=$PRINT_LIBS
830                 AC_CHECK_HEADERS(cups/cups.h cups/language.h)
831
832                 if test x"$ac_cv_header_cups_cups_h" = xyes -a \
833                         x"$ac_cv_header_cups_language_h" = xyes; then
834                         # try linking with -lcups alone first. That should work unless libcups is
835                         # underlinked. With cups-config --libs we pull in unwanted and unneeded
836                         # dendencies including thread libraries - use cups-config only if really
837                         # required. 
838                         AC_CHECK_LIB_EXT(cups, ac_save_PRINT_LIBS , httpConnect,
839                                 [PRINT_LIBS="$ac_save_PRINT_LIBS -lcups"],
840                                 [AC_MSG_WARN([your cups library doesn't link with -lcups alone, it might be underlinked.]) ;
841                                  PRINT_LIBS="$ac_save_PRINT_LIBS `$CUPS_CONFIG --libs`"])
842
843                         AC_DEFINE(HAVE_CUPS,1,[Whether we have CUPS])
844                         samba_cv_HAVE_CUPS=yes
845                         AC_CHECK_LIB_EXT(cups, PRINT_LIBS, httpConnectEncrypt)
846                 else
847                         AC_MSG_WARN([cups-config around but cups-devel not installed])
848                         CFLAGS=$ac_save_CFLAGS
849                         LDFLAGS=$ac_save_LDFLAGS
850                         PRINT_LIBS=$ac_save_PRINT_LIBS
851                 fi
852
853         elif test x"$enable_cups" = x"yes"; then
854                 AC_MSG_ERROR(Cups support required but cups-config not located.  Make sure cups-devel related files are installed.)
855         fi
856 fi
857
858 AC_ARG_ENABLE(iprint,
859 [AS_HELP_STRING([--enable-iprint], [Turn on iPrint support (default=yes if cups is yes)])])
860
861 if test x$enable_iprint != xno; then
862         if test x"$samba_cv_HAVE_CUPS" = xyes; then
863                 AC_DEFINE(HAVE_IPRINT,1,[Whether we have iPrint])
864         elif test x"$enable_iprint" = x"yes"; then
865                 AC_MSG_ERROR(iPrint support required but cups not enabled.  Make sure cups-devel related files are installed and that cups is enabled.)
866         fi
867 fi
868
869 ############################################
870 # check if the compiler will optimize out function calls
871 AC_CACHE_CHECK([if the compiler will optimize out function calls],samba_cv_optimize_out_funcation_calls, [
872     AC_TRY_LINK([
873 #include <stdio.h>],
874 [
875                 if (0) {
876                    this_function_does_not_exist();
877                 } else {
878                   return 1;
879                 }
880
881 ],
882         samba_cv_optimize_out_funcation_calls=yes,samba_cv_optimize_out_funcation_calls=no)])
883 if test x"$samba_cv_optimize_out_funcation_calls" = x"yes"; then
884    AC_DEFINE(HAVE_COMPILER_WILL_OPTIMIZE_OUT_FNS,1,[Whether the compiler will optimize out function calls])
885 fi
886
887 #############################################
888 # check for fd passing struct via msg_control
889 AC_CACHE_CHECK([for fd passing via msg_control],samba_cv_msghdr_msg_control, [
890     AC_TRY_COMPILE([
891 #include <sys/types.h>
892 #include <stdlib.h>
893 #include <stddef.h>
894 #include <sys/socket.h>
895 #include <sys/un.h>],
896 [
897         struct msghdr msg;
898         union {
899               struct cmsghdr cm;
900               char control[CMSG_SPACE(sizeof(int))];
901         } control_un;
902         msg.msg_control = control_un.control;
903         msg.msg_controllen = sizeof(control_un.control);
904 ],
905         samba_cv_msghdr_msg_control=yes,samba_cv_msghdr_msg_control=no)])
906 if test x"$samba_cv_msghdr_msg_control" = x"yes"; then
907    AC_DEFINE(HAVE_MSGHDR_MSG_CONTROL,1,
908              [If we can use msg_control for passing file descriptors])
909 fi
910
911 #############################################
912 # check for fd passing struct via msg_acctrights
913 AC_CACHE_CHECK([for fd passing via msg_acctrights],
914                 samba_cv_msghdr_msg_acctrights, [
915     AC_TRY_COMPILE([
916 #include <sys/types.h>
917 #include <stdlib.h>
918 #include <stddef.h>
919 #include <sys/socket.h>
920 #include <sys/un.h>],
921 [
922         struct msghdr msg;
923         int fd;
924         msg.msg_acctrights = (caddr_t) &fd;
925         msg.msg_acctrightslen = sizeof(fd);
926 ],
927         samba_cv_msghdr_msg_acctrights=yes,samba_cv_msghdr_msg_acctrights=no)])
928 if test x"$samba_cv_msghdr_msg_acctrights" = x"yes"; then
929    AC_DEFINE(HAVE_MSGHDR_MSG_ACCTRIGHTS,1,
930              [If we can use msg_acctrights for passing file descriptors])
931 fi
932
933 AC_CHECK_FUNCS(dirfd)
934 if test x"$ac_cv_func_dirfd" = x"yes"; then
935         default_shared_modules="$default_shared_modules vfs_syncops vfs_dirsort"
936 fi
937
938 AC_CACHE_CHECK([for struct sigevent type],samba_cv_struct_sigevent, [
939     AC_TRY_COMPILE([
940 #include <sys/types.h>
941 #if STDC_HEADERS
942 #include <stdlib.h>
943 #include <stddef.h>
944 #endif
945 #include <signal.h>],[struct sigevent s;],
946         samba_cv_struct_sigevent=yes,samba_cv_struct_sigevent=no)])
947 if test x"$samba_cv_struct_sigevent" = x"yes"; then
948    AC_DEFINE(HAVE_STRUCT_SIGEVENT,1,[Whether we have the struct sigevent])
949    AC_CHECK_MEMBERS([struct sigevent.sigev_value.sival_ptr,struct sigevent.sigev_value.sigval_ptr], , ,
950         [#include <signal.h>])
951 fi
952
953 # and glibc has setresuid under linux but the function does
954 # nothing until kernel 2.1.44! very dumb.
955 AC_CACHE_CHECK([for real setresuid],samba_cv_have_setresuid,[
956     AC_TRY_RUN([#include <errno.h>
957 main() { setresuid(1,1,1); setresuid(2,2,2); exit(errno==EPERM?0:1);}],
958         samba_cv_have_setresuid=yes,samba_cv_have_setresuid=no,samba_cv_have_setresuid=cross)])
959 if test x"$samba_cv_have_setresuid" = x"yes"; then
960     AC_DEFINE(HAVE_SETRESUID,1,[Whether the system has setresuid])
961 fi
962
963 # Do the same check for setresguid...
964 #
965 AC_CACHE_CHECK([for real setresgid],samba_cv_have_setresgid,[
966     AC_TRY_RUN([#include <unistd.h>
967 #include <errno.h>
968 main() { errno = 0; setresgid(1,1,1); exit(errno != 0 ? (errno==EPERM ? 0 : 1) : 0);}],
969         samba_cv_have_setresgid=yes,samba_cv_have_setresgid=no,samba_cv_have_setresgid=cross)])
970 if test x"$samba_cv_have_setresgid" = x"yes"; then
971     AC_DEFINE(HAVE_SETRESGID,1,[Whether the system has setresgid])
972 fi
973
974 AC_FUNC_MEMCMP
975
976 ###############################################
977 # Readline included by default unless explicitly asked not to
978 test "${with_readline+set}" != "set" && with_readline=yes
979
980 # test for where we get readline() from
981 AC_MSG_CHECKING(whether to use readline)
982 AC_ARG_WITH(readline,
983 [AS_HELP_STRING([--with-readline[=DIR]], [Look for readline include/libs in DIR (default=auto)])],
984 [  case "$with_readline" in
985   yes)
986     AC_MSG_RESULT(yes)
987
988     AC_CHECK_HEADERS(readline.h history.h readline/readline.h)
989     AC_CHECK_HEADERS(readline/history.h)
990
991     AC_CHECK_HEADERS(readline.h readline/readline.h,[
992       for termlib in ncurses curses termcap terminfo termlib tinfo; do
993        AC_CHECK_LIB(${termlib}, tgetent, [TERMLIBS="-l${termlib}"; break])
994       done
995       AC_CHECK_LIB(readline, rl_callback_handler_install,
996        [TERMLIBS="-lreadline $TERMLIBS"
997        AC_DEFINE(HAVE_LIBREADLINE,1,[Whether the system has readline])
998        break], [TERMLIBS=], $TERMLIBS)])
999     ;;
1000   no)
1001     AC_MSG_RESULT(no)
1002     ;;
1003   *)
1004     AC_MSG_RESULT(yes)
1005
1006     # Needed for AC_CHECK_HEADERS and AC_CHECK_LIB to look at
1007     # alternate readline path
1008     _ldflags=${LDFLAGS}
1009     _cppflags=${CPPFLAGS}
1010
1011     # Add additional search path
1012     LDFLAGS="-L$with_readline/lib $LDFLAGS"
1013     CPPFLAGS="-I$with_readline/include $CPPFLAGS"
1014
1015     AC_CHECK_HEADERS(readline.h history.h readline/readline.h)
1016     AC_CHECK_HEADERS(readline/history.h)
1017
1018     AC_CHECK_HEADERS(readline.h readline/readline.h,[
1019       for termlib in ncurses curses termcap terminfo termlib; do
1020        AC_CHECK_LIB(${termlib}, tgetent, [TERMLIBS="-l${termlib}"; break])
1021       done
1022       AC_CHECK_LIB(readline, rl_callback_handler_install,
1023        [TERMLDFLAGS="-L$with_readline/lib"
1024        TERMCPPFLAGS="-I$with_readline/include"
1025        CPPFLAGS="-I$with_readline/include $CPPFLAGS"
1026        TERMLIBS="-lreadline $TERMLIBS"
1027        AC_DEFINE(HAVE_LIBREADLINE,1,[Whether the system has readline])
1028        break], [TERMLIBS= CPPFLAGS=$_cppflags], $TERMLIBS)])
1029
1030     LDFLAGS=$_ldflags
1031     ;;
1032   esac],
1033   AC_MSG_RESULT(no)
1034 )
1035 AC_SUBST(TERMLIBS)
1036 AC_SUBST(TERMLDFLAGS)
1037
1038 # The readline API changed slightly from readline3 to readline4, so
1039 # code will generate warnings on one of them unless we have a few
1040 # special cases.
1041 AC_CHECK_LIB(readline, rl_completion_matches,
1042              [AC_DEFINE(HAVE_NEW_LIBREADLINE, 1,
1043                         [Do we have rl_completion_matches?])],
1044              [],
1045              [$TERMLIBS])
1046
1047 # not all readline libs have rl_event_hook or history_list
1048 AC_CHECK_DECLS(rl_event_hook, [], [], [#include <readline/readline.h>])
1049 AC_CHECK_LIB(readline, history_list,
1050              [AC_DEFINE(HAVE_HISTORY_LIST, 1, [Do we have history_list?])],
1051              [],
1052              [$TERMLIBS])
1053
1054 ###############################################
1055 # test for where we get yp_get_default_domain() from
1056 AC_SEARCH_LIBS(yp_get_default_domain, [nsl])
1057 AC_CHECK_FUNCS(yp_get_default_domain)
1058
1059 # Check if we have execl, if not we need to compile smbrun.
1060 AC_CHECK_FUNCS(execl)
1061 if test x"$ac_cv_func_execl" = x"no"; then
1062     EXTRA_BIN_PROGS="$EXTRA_BIN_PROGS bin/smbrun\$(EXEEXT)"
1063 fi
1064
1065 AC_CHECK_FUNCS(getcwd fchown chmod fchmod mknod mknod64)
1066 AC_CHECK_FUNCS(strtol)
1067 AC_CHECK_FUNCS(strchr chflags)
1068 AC_CHECK_FUNCS(getrlimit fsync setpgid)
1069 AC_CHECK_FUNCS(fdatasync,,[AC_CHECK_LIB_EXT(rt, LIBS, fdatasync)])
1070 AC_CHECK_FUNCS(setsid glob strpbrk crypt16 getauthuid)
1071 AC_CHECK_FUNCS(sigprocmask sigblock sigaction sigset innetgr setnetgrent getnetgrent endnetgrent)
1072 AC_CHECK_FUNCS(initgroups select rdchk getgrnam getgrent pathconf)
1073 AC_CHECK_FUNCS(getgrset)
1074 AC_CHECK_FUNCS(setpriv setgidx setuidx setgroups sysconf stat64 fstat64)
1075 AC_CHECK_FUNCS(lstat64 fopen64 atexit grantpt lseek64 ftruncate64 posix_fallocate posix_fallocate64)
1076 AC_CHECK_FUNCS(fallocate fallocate64)
1077 AC_CHECK_FUNCS(fseek64 fseeko64 ftell64 ftello64 setluid getpwanam)
1078 AC_CHECK_FUNCS(opendir64 readdir64 seekdir64 telldir64 rewinddir64 closedir64)
1079 AC_CHECK_FUNCS(fdopendir fdopendir64)
1080 AC_CHECK_FUNCS(getpwent_r)
1081 AC_CHECK_FUNCS(getdents64)
1082 AC_CHECK_FUNCS(setenv strcasecmp fcvt fcvtl)
1083 AC_CHECK_FUNCS(syslog vsyslog timegm)
1084 AC_CHECK_FUNCS(setlocale nl_langinfo)
1085 AC_CHECK_FUNCS(nanosleep,,[AC_CHECK_LIB_EXT(rt, LIBS, nanosleep)])
1086 AC_CHECK_FUNCS(lutimes futimes utimensat futimens)
1087 AC_CHECK_FUNCS(mlock munlock mlockall munlockall)
1088 AC_CHECK_FUNCS(memalign posix_memalign hstrerror)
1089 AC_CHECK_HEADERS(sys/mman.h)
1090 # setbuffer, shmget, shm_open are needed for smbtorture
1091 AC_CHECK_FUNCS(shmget shm_open)
1092 AC_CHECK_FUNCS(gettext dgettext)
1093 AC_CHECK_FUNCS(bindtextdomain textdomain)
1094 AC_CHECK_FUNCS(strupr)
1095
1096 # Find a method of generating a stack trace
1097 AC_CHECK_HEADERS(execinfo.h libexc.h libunwind.h)
1098 # libexecinfo provides backtrace_symbols on FreeBSD
1099 AC_SEARCH_LIBS(backtrace_symbols, [execinfo])
1100 AC_CHECK_FUNCS(backtrace_symbols)
1101 AC_CHECK_LIB(exc, trace_back_stack)
1102
1103 # check for sysctlbyname for BSD systems
1104 AC_CHECK_FUNCS(sysctlbyname)
1105
1106 #################################################
1107 # Check to see if core dump directory is defined in linux
1108 # with /proc/sys/kernel/core_pattern
1109
1110 AC_CHECK_FILE([/proc/sys/kernel/core_pattern],
1111         AC_DEFINE(HAVE_SYS_KERNEL_PROC_CORE_PATTERN, 1,
1112         [Whether Linux kernel uses core_pattern for core files]),
1113          [])
1114
1115 #############################
1116 # check if building with gpfs
1117 AC_CHECK_HEADERS(gpfs_gpl.h)
1118 if test x"$ac_cv_header_gpfs_gpl_h" = x"yes"; then
1119     AC_DEFINE(HAVE_GPFS,1,[Whether GPFS GPL headers are available])
1120     default_shared_modules="$default_shared_modules vfs_gpfs"
1121 fi
1122
1123 #############################################
1124 # check if building on Isilon OneFS
1125 printf "%s" "checking for Isilon OneFS... "
1126 save_LIBS="$LIBS"
1127 LIBS="$LIBS -lisi_version"
1128 AC_TRY_LINK([#include <isi_version/isi_version.h>],
1129           [get_isilon_copyright()],
1130           samba_cv_HAVE_ONEFS=yes,
1131           samba_cv_HAVE_ONEFS=no)
1132 echo $samba_cv_HAVE_ONEFS
1133 if test x"$samba_cv_HAVE_ONEFS" = x"yes"; then
1134     AC_DEFINE(HAVE_ONEFS,1,[Whether building on Isilon OneFS])
1135     default_shared_modules="$default_shared_modules vfs_onefs vfs_onefs_shadow_copy perfcount_onefs"
1136     default_static_modules="$default_static_modules"
1137     ONEFS_LIBS="-lisi_acl -lisi_ecs -lisi_event -lisi_util"
1138     # Need to also add general libs for oplocks support
1139     save_LIBS="$save_LIBS -lisi_ecs -lisi_event -lisi_util -ldevstat"
1140 fi
1141 AC_SUBST(ONEFS_LIBS)
1142 LIBS="$save_LIBS"
1143
1144 # Note that all the libunwind symbols in the API are defined to internal
1145 # platform-specific version, so we must include libunwind.h before checking
1146 # any of them.
1147 AC_MSG_CHECKING([for libunwind])
1148 save_LIBS=$LIBS
1149
1150 UNWIND_ARCH="unknown"
1151 if test x"$UNAME_I" != x"unknown"; then
1152         UNWIND_ARCH="$UNAME_I"
1153 elif test x"$UNAME_M" != x"unknown"; then
1154         UNWIND_ARCH="$UNAME_M"
1155 elif test x"$UNAME_P" != x"unknown"; then
1156         UNWIND_ARCH="$UNAME_P"
1157 fi
1158
1159 case "$UNWIND_ARCH" in
1160         unknown)
1161                 # This probably won't link without
1162                 # the platform-specific libunwind.
1163                 LIBS="$LIBS -lunwind"
1164                 ;;
1165         i386|i586|i686)
1166                 # Add the platform-specific libunwind module.
1167                 LIBS="$LIBS -lunwind -lunwind-x86"
1168                 ;;
1169         *)
1170                 # Add the platform-specific libunwind module.
1171                 # based on uname -i, uname -m or uname -p
1172                 LIBS="$LIBS -lunwind -lunwind-$UNWIND_ARCH"
1173                 ;;
1174 esac
1175
1176 AC_TRY_LINK(
1177     [
1178 #ifdef HAVE_LIBUNWIND_H
1179 #include <libunwind.h>
1180 #endif
1181     ],
1182     [
1183         unw_context_t ctx; unw_cursor_t cur;
1184         char buf[256]; unw_word_t off;
1185         unw_getcontext(&ctx); unw_init_local(&cur, &ctx);
1186         unw_get_proc_name(&cur, buf, sizeof(buf), &off);
1187     ],
1188     [
1189         AC_MSG_RESULT(yes)
1190         AC_DEFINE(HAVE_LIBUNWIND, 1, [Whether libunwind is available])
1191
1192         # If we have libunwind, test whether we also have libunwind-ptrace
1193         # which would let us unwind arbitrary processes.
1194         save_LIBS=$LIBS
1195         AC_CHECK_HEADERS(libunwind-ptrace.h)
1196         AC_CHECK_LIB(unwind-ptrace, _UPT_create,
1197             [
1198                 LIBUNWIND_PTRACE="-lunwind-ptrace";
1199                 AC_DEFINE(HAVE_LIBUNWIND_PTRACE, 1,
1200                     [Whether libunwind-ptrace.a is available.])
1201             ],
1202             [ LIBUNWIND_PTRACE="" ])
1203
1204         LIBS=$save_LIBS
1205     ],
1206     [
1207         AC_MSG_RESULT(no)
1208         LIBS=$save_LIBS
1209     ])
1210
1211 # To use libunwind-ptrace, we also need to make some ptrace system calls.
1212 if test x"$LIBUNWIND_PTRACE" != x"" ; then
1213     AC_CHECK_HEADERS(sys/ptrace.h)
1214     AC_MSG_CHECKING([for the Linux ptrace(2) interface])
1215     AC_TRY_LINK(
1216             [
1217 #if HAVE_SYS_TYPES_H
1218 #include <sys/types.h>
1219 #endif
1220 #if HAVE_SYS_PTRACE_H
1221 #include <sys/ptrace.h>
1222 #endif
1223             ],
1224             [
1225                 pid_t me = (pid_t)-1;
1226                 ptrace(PTRACE_ATTACH, me, 0, 0);
1227                 ptrace(PTRACE_DETACH, me, 0, 0);
1228                 return 0;
1229             ],
1230             [
1231                 AC_MSG_RESULT(yes)
1232                 AC_DEFINE(HAVE_LINUX_PTRACE, 1,
1233                     [Whether the Linux ptrace(2) interface is available.])
1234             ],
1235             [
1236                 AC_MSG_RESULT(no)
1237                 LIBUNWIND_PTRACE=""
1238             ])
1239 fi
1240
1241 AC_SUBST(LIBUNWIND_PTRACE)
1242
1243 AC_CHECK_FUNCS(_dup _dup2 _opendir _readdir _seekdir _telldir _closedir)
1244 AC_CHECK_FUNCS(__dup __dup2 __opendir __readdir __seekdir __telldir __closedir)
1245 AC_CHECK_FUNCS(__getcwd _getcwd)
1246 AC_CHECK_FUNCS(__xstat __fxstat __lxstat)
1247 AC_CHECK_FUNCS(_stat _lstat _fstat __stat __lstat __fstat)
1248 AC_CHECK_FUNCS(_acl __acl _facl __facl _open __open _chdir __chdir)
1249 AC_CHECK_FUNCS(_close __close _fchdir __fchdir _fcntl __fcntl)
1250 AC_CHECK_FUNCS(getdents __getdents _lseek __lseek _read __read)
1251 AC_CHECK_FUNCS(getdirentries _write __write _fork __fork)
1252 AC_CHECK_FUNCS(_stat64 __stat64 _fstat64 __fstat64 _lstat64 __lstat64)
1253 AC_CHECK_FUNCS(__sys_llseek llseek _llseek __llseek readdir64 _readdir64 __readdir64)
1254 AC_CHECK_FUNCS(pread _pread __pread pread64 _pread64 __pread64)
1255 AC_CHECK_FUNCS(pwrite _pwrite __pwrite pwrite64 _pwrite64 __pwrite64)
1256 AC_CHECK_FUNCS(open64 _open64 __open64 creat64)
1257 AC_CHECK_FUNCS(prctl)
1258
1259 AC_TRY_COMPILE([
1260 #ifdef HAVE_SYS_PRCTL_H
1261 #include <sys/prctl.h>
1262 #endif
1263 ],
1264 [int i; i = prtcl(0); ],
1265 AC_DEFINE(HAVE_PRCTL, 1, [Whether prctl is available]),[])
1266
1267 #
1268 #
1269 #
1270 case "$host_os" in
1271     *linux* | gnu* | k*bsd*-gnu | kopensolaris*-gnu)
1272        # glibc <= 2.3.2 has a broken getgrouplist
1273        AC_CACHE_CHECK([for good getgrouplist],samba_cv_linux_getgrouplist_ok,[AC_TRY_RUN([
1274 #include <unistd.h>
1275 #include <sys/utsname.h>
1276 main() {
1277        /* glibc up to 2.3 has a broken getgrouplist */
1278 #if defined(__GLIBC__) && defined(__GLIBC_MINOR__)
1279        int libc_major = __GLIBC__;
1280        int libc_minor = __GLIBC_MINOR__;
1281
1282        if (libc_major < 2)
1283               exit(1);
1284        if ((libc_major == 2) && (libc_minor <= 3))
1285               exit(1);
1286 #endif
1287        exit(0);
1288 }
1289 ], [samba_cv_linux_getgrouplist_ok=yes],
1290    [samba_cv_linux_getgrouplist_ok=no],
1291    [samba_cv_linux_getgrouplist_ok=cross])])
1292        if test x"$samba_cv_linux_getgrouplist_ok" = x"yes"; then
1293           AC_DEFINE(HAVE_GETGROUPLIST, 1, [Have good getgrouplist])
1294        fi
1295        ;;
1296     *)
1297        AC_CHECK_FUNCS(getgrouplist)
1298        ;;
1299 esac
1300
1301 #
1302 # stat64 family may need <sys/stat.h> on some systems, notably ReliantUNIX
1303 #
1304
1305 if test x$ac_cv_func_stat64 = xno ; then
1306   AC_MSG_CHECKING([for stat64 in <sys/stat.h>])
1307   AC_TRY_LINK([
1308 #if defined(HAVE_UNISTD_H)
1309 #include <unistd.h>
1310 #endif
1311 #include <sys/stat.h>
1312 ], [struct stat64 st64; exit(stat64(".",&st64));], [ac_cv_func_stat64=yes])
1313   AC_MSG_RESULT([$ac_cv_func_stat64])
1314   if test x$ac_cv_func_stat64 = xyes ; then
1315     AC_DEFINE(HAVE_STAT64,1,[Whether stat64() is available])
1316   fi
1317 fi
1318
1319 if test x$ac_cv_func_lstat64 = xno ; then
1320   AC_MSG_CHECKING([for lstat64 in <sys/stat.h>])
1321   AC_TRY_LINK([
1322 #if defined(HAVE_UNISTD_H)
1323 #include <unistd.h>
1324 #endif
1325 #include <sys/stat.h>
1326 ], [struct stat64 st64; exit(lstat64(".",&st64));], [ac_cv_func_lstat64=yes])
1327   AC_MSG_RESULT([$ac_cv_func_lstat64])
1328   if test x$ac_cv_func_lstat64 = xyes ; then
1329     AC_DEFINE(HAVE_LSTAT64,[Whether lstat64() is available])
1330   fi
1331 fi
1332
1333 if test x$ac_cv_func_fstat64 = xno ; then
1334   AC_MSG_CHECKING([for fstat64 in <sys/stat.h>])
1335   AC_TRY_LINK([
1336 #if defined(HAVE_UNISTD_H)
1337 #include <unistd.h>
1338 #endif
1339 #include <sys/stat.h>
1340 ], [struct stat64 st64; exit(fstat64(0,&st64));], [ac_cv_func_fstat64=yes])
1341   AC_MSG_RESULT([$ac_cv_func_fstat64])
1342   if test x$ac_cv_func_fstat64 = xyes ; then
1343     AC_DEFINE(HAVE_FSTAT64,1,[Whether fstat64() is available])
1344   fi
1345 fi
1346
1347 #################################################
1348 # Check whether struct stat has timestamps with sub-second resolution.
1349 #
1350
1351 samba_cv_stat_hires=no
1352 AC_CHECK_MEMBERS([struct stat.st_mtim.tv_nsec], # Linux, Solaris
1353         [samba_cv_stat_hires=yes])
1354 AC_CHECK_MEMBERS([struct stat.st_mtimensec], # BSD, if defined _POSIX_SOURCE
1355         [samba_cv_stat_hires=yes])
1356 AC_CHECK_MEMBERS([struct stat.st_mtimespec.tv_nsec], # BSD, if not defined _POSIX_SOURCE
1357         [samba_cv_stat_hires=yes])
1358 AC_CHECK_MEMBERS([struct stat.st_mtime_n], # AIX
1359         [samba_cv_stat_hires=yes])
1360 AC_CHECK_MEMBERS([struct stat.st_umtime], # Tru64
1361         [samba_cv_stat_hires=yes])
1362
1363 if test x"$samba_cv_stat_hires" = x"yes" ; then
1364     AC_DEFINE(HAVE_STAT_HIRES_TIMESTAMPS, 1,
1365             [whether struct stat has sub-second timestamps])
1366 fi
1367
1368 # recent FreeBSD, NetBSD have creation timestamps called birthtime:
1369 AC_CHECK_MEMBERS([struct stat.st_birthtimespec.tv_nsec])
1370 AC_CHECK_MEMBERS([struct stat.st_birthtime], AC_CHECK_MEMBERS([struct stat.st_birthtimensec]))
1371
1372
1373 AC_CACHE_CHECK([whether there is DOS flags support in the stat struct], samba_cv_stat_dos_flags,
1374     [
1375         AC_TRY_COMPILE(
1376             [#include <sys/stat.h>],
1377             [
1378                 int a = UF_DOS_ARCHIVE;
1379                 int h = UF_DOS_HIDDEN;
1380                 int r = UF_DOS_RO;
1381                 int s = UF_DOS_SYSTEM;
1382                 int i = UF_DOS_NOINDEX;
1383                 int f = UF_DOS_FLAGS;
1384             ],
1385             samba_cv_stat_dos_flags=yes, samba_cv_stat_dos_flags=no)
1386     ])
1387
1388 if test x"$samba_cv_stat_dos_flags" = x"yes" ; then
1389     AC_DEFINE(HAVE_STAT_DOS_FLAGS, 1, [whether there is DOS flags support in the stat struct])
1390 fi
1391
1392 AC_CACHE_CHECK([whether we can compile with __attribute__((destructor))],
1393                samba_cv_function_attribute_destructor,
1394                [
1395                  AC_COMPILE_IFELSE(
1396                         [
1397                                 __attribute__((destructor))
1398                                 static void cleanup(void) { }
1399                         ],
1400                         samba_cv_function_attribute_destructor=yes)
1401                 ])
1402
1403 if test x"$samba_cv_function_attribute_destructor" = xyes ; then
1404    AC_DEFINE(HAVE_FUNCTION_ATTRIBUTE_DESTRUCTOR, 1,
1405              [whether we can compile with __attribute__((destructor))])
1406 fi
1407
1408 #####################################
1409 # needed for SRV lookups
1410 AC_CHECK_LIB(resolv, dn_expand)
1411 AC_CHECK_LIB(resolv, _dn_expand)
1412 AC_CHECK_LIB(resolv, __dn_expand)
1413
1414 AC_TRY_COMPILE([#include <resolv.h>],
1415                [struct __res_state s; res_ninit(&s);],
1416                ac_cv_have_res_ninit=yes,ac_cv_have_res_ninit=no)
1417
1418 if test x"$ac_cv_have_res_ninit" = x"yes"; then
1419         AC_DEFINE(HAVE_RES_NINIT, 1, [Whether we have res_ninit])
1420 fi
1421
1422 #
1423 # Check for the functions putprpwnam, set_auth_parameters,
1424 # getspnam, bigcrypt and getprpwnam in -lsec and -lsecurity
1425 # Needed for OSF1 and HPUX.
1426 #
1427
1428 AC_LIBTESTFUNC(security, putprpwnam)
1429 AC_LIBTESTFUNC(sec, putprpwnam)
1430
1431 AC_LIBTESTFUNC(security, set_auth_parameters)
1432 AC_LIBTESTFUNC(sec, set_auth_parameters)
1433
1434 # UnixWare 7.x has its getspnam in -lgen
1435 AC_LIBTESTFUNC(gen, getspnam)
1436
1437 AC_LIBTESTFUNC(security, getspnam)
1438 AC_LIBTESTFUNC(sec, getspnam)
1439
1440 AC_LIBTESTFUNC(security, bigcrypt)
1441 AC_LIBTESTFUNC(sec, bigcrypt)
1442
1443 AC_LIBTESTFUNC(security, getprpwnam)
1444 AC_LIBTESTFUNC(sec, getprpwnam)
1445
1446 AC_CHECK_FUNCS(strsignal)
1447
1448 ############################################
1449 # Check for EA implementations
1450 case "$host_os" in
1451   *osf*)
1452         AC_SEARCH_LIBS(getproplist, [proplist])
1453         AC_CHECK_FUNCS(getproplist fgetproplist setproplist fsetproplist)
1454         AC_CHECK_FUNCS(delproplist fdelproplist add_proplist_entry get_proplist_entry)
1455         AC_CHECK_FUNCS(sizeof_proplist_entry)
1456   ;;
1457   *freebsd4* | *dragonfly* )
1458         AC_DEFINE(BROKEN_EXTATTR, 1, [Does extattr API work])
1459   ;;
1460   *solaris*)
1461         AC_CHECK_FUNCS(attropen)
1462   ;;
1463   *)
1464         AC_SEARCH_LIBS(getxattr, [attr])
1465         AC_CHECK_FUNCS(getxattr,[
1466                 AC_CHECK_FUNCS(lgetxattr fgetxattr listxattr llistxattr flistxattr removexattr lremovexattr fremovexattr setxattr lsetxattr fsetxattr)
1467                 ])
1468         AC_CHECK_FUNCS(getea,[
1469                 AC_CHECK_FUNCS(fgetea lgetea listea flistea llistea removeea fremoveea lremoveea setea fsetea lsetea)
1470                 ])
1471         AC_CHECK_FUNCS(attr_get,[
1472                 AC_CHECK_FUNCS(attr_list attr_set attr_remove attr_getf attr_listf attr_setf attr_removef)
1473                 ])
1474         AC_CHECK_FUNCS(extattr_delete_file,[
1475                 AC_CHECK_FUNCS(extattr_delete_fd extattr_delete_link extattr_get_fd extattr_get_file extattr_get_link extattr_list_fd extattr_list_file extattr_list_link extattr_set_fd extattr_set_file extattr_set_link)
1476                 ])
1477   ;;
1478 esac
1479
1480 ########################################################
1481 # Do xattr functions take additional options like on Darwin?
1482 if test x"$ac_cv_func_getxattr" = x"yes" ; then
1483         AC_CACHE_CHECK([whether xattr interface takes additional options], smb_attr_cv_xattr_add_opt, [
1484                 old_LIBS=$LIBS
1485                 LIBS="$LIBS $ACL_LIBS"
1486                 AC_TRY_COMPILE([
1487                         #include <sys/types.h>
1488                         #if HAVE_ATTR_XATTR_H
1489                         #include <attr/xattr.h>
1490                         #elif HAVE_SYS_XATTR_H
1491                         #include <sys/xattr.h>
1492                         #endif
1493                 ],[
1494                         getxattr(0, 0, 0, 0, 0, 0);
1495                 ],
1496                 [smb_attr_cv_xattr_add_opt=yes],
1497                 [smb_attr_cv_xattr_add_opt=no;LIBS=$old_LIBS])
1498         ])
1499         if test x"$smb_attr_cv_xattr_add_opt" = x"yes"; then
1500                 AC_DEFINE(XATTR_ADD_OPT, 1, [xattr functions have additional options])
1501         fi
1502 fi
1503
1504 AC_DISABLE_STATIC
1505 AC_ENABLE_SHARED
1506
1507 # Set defaults
1508 PIE_CFLAGS=""
1509 PIE_LDFLAGS=""
1510 AC_ARG_ENABLE(pie, [AS_HELP_STRING([--enable-pie], [Turn on pie support if available (default=yes)])])
1511
1512 if test "x$enable_pie" != xno
1513 then
1514         AC_CACHE_CHECK(for -pie and -fPIE, samba_cv_fpie,
1515         [
1516                 cat > conftest.c <<EOF
1517 int foo;
1518 int main () { return 0;}
1519 EOF
1520                 if AC_TRY_COMMAND_NO_STDERR([${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS -pie -fPIE -o conftest conftest.c])
1521                 then
1522                         samba_cv_fpie=yes
1523                 else
1524                         samba_cv_fpie=no
1525                 fi
1526                 rm -f conftest*
1527         ])
1528         if test x"${samba_cv_fpie}" = x"yes"
1529         then
1530                 PIE_CFLAGS="-fPIE"
1531                 PIE_LDFLAGS="-pie"
1532         fi
1533 fi
1534
1535 # Set defaults
1536 RELRO_LDFLAGS=""
1537 AC_ARG_ENABLE(relro, [AS_HELP_STRING([--enable-relro], [Turn on Relocations Read-Only (relro) support if available (default=yes)])])
1538
1539 if test "x$enable_relro" != xno
1540 then
1541         AC_CACHE_CHECK([for -Wl,-z,relro], samba_cv_relro,
1542         [
1543                 cat > conftest.c <<EOF
1544 int foo;
1545 main () { return 0;}
1546 EOF
1547                 if AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS -Wl,-z,relro -o conftest conftest.c 1>&AS_MESSAGE_LOG_FD])
1548                 then
1549                         samba_cv_relro=yes
1550                 else
1551                         samba_cv_relro=no
1552                 fi
1553                 rm -f conftest*
1554         ])
1555         if test x"${samba_cv_relro}" = x"yes"
1556         then
1557                 RELRO_LDFLAGS="-Wl,-z,relro"
1558         fi
1559 fi
1560
1561 # Set defaults
1562 SYMSEXT="syms"
1563 AC_SUBST(SYMSEXT)
1564
1565 # Assume non-shared by default and override below
1566 BLDSHARED="false"
1567
1568 # these are the defaults, good for lots of systems
1569 HOST_OS="$host_os"
1570 LDSHFLAGS="-shared"
1571 MODULE_EXPORTS=""
1572 SONAMEFLAG="#"
1573 SHLD="\${CC} \${CFLAGS}"
1574 PICFLAG="${PIE_CFLAGS}"
1575 SHLIBEXT="so"
1576 DSO_EXPORTS=""
1577
1578 # this bit needs to be modified for each OS that supports share libs
1579 # You need to specify how to create a shared library and
1580   # how to compile C code to produce PIC object files
1581
1582   AC_MSG_CHECKING([ability to build shared libraries])
1583
1584   # and these are for particular systems
1585   case "$host_os" in
1586                 *linux* | gnu* | k*bsd*-gnu | kopensolaris*-gnu | *qnx*)
1587                         case "$host_os" in
1588                                 *linux*) AC_DEFINE(LINUX,1,[Whether the host os is linux]) ;;
1589                                 *qnx*) AC_DEFINE(QNX,1,[Whether the host os is qnx]) ;;
1590                         esac
1591                         BLDSHARED="true"
1592                         LDSHFLAGS="-shared -Wl,-Bsymbolic"
1593                         if test "${ac_cv_gnu_ld_no_default_allow_shlib_undefined}" = "yes"; then
1594                                 LDSHFLAGS_Z_NODEFS="-Wl,--allow-shlib-undefined"
1595                         fi
1596                         DYNEXP="-Wl,--export-dynamic"
1597                         PICFLAG="-fPIC"
1598                         SONAMEFLAG="-Wl,-soname="
1599                         AC_DEFINE(STAT_ST_BLOCKSIZE,512)
1600                         ;;
1601                 *solaris*) AC_DEFINE(SUNOS5,1,[Whether the host os is solaris])
1602                         BLDSHARED="true"
1603                         if test "${GCC}" = "yes"; then
1604                                 PICFLAG="-fPIC"
1605                                 SONAMEFLAG="-Wl,-soname="
1606                                 if test "${ac_cv_prog_gnu_ld}" = "yes"; then
1607                                         DYNEXP="-Wl,-E"
1608                                 fi
1609                                 LDSHFLAGS="-shared"
1610                         else
1611                                 PICFLAG="-KPIC"
1612                                 LDSHFLAGS="-G"
1613                         fi
1614                         if test "$ac_cv_prog_gnu_ld" = "yes"; then
1615                                 SONAMEFLAG="-Wl,-soname="
1616                         else
1617                                 SONAMEFLAG="-Wl,-h,"
1618                         fi
1619                         AC_DEFINE(STAT_ST_BLOCKSIZE,512,[The size of a block])
1620                         AC_DEFINE(BROKEN_GETGRNAM,1,[Does getgrnam work correctly])
1621                         ;;
1622                 *sunos*) AC_DEFINE(SUNOS4,1,[Whether the host os is sunos4])
1623                         BLDSHARED="true"
1624                         LDSHFLAGS="-G"
1625                         SONAMEFLAG="-Wl,-h,"
1626                         PICFLAG="-KPIC"   # Is this correct for SunOS
1627                         AC_DEFINE(STAT_ST_BLOCKSIZE,512)
1628                         AC_DEFINE(BROKEN_GETGRNAM,1,[Does getgrnam work correctly])
1629                         ;;
1630                 *netbsd* | *freebsd* | *dragonfly* )
1631                         BLDSHARED="true"
1632                         LDSHFLAGS="-shared"
1633                         DYNEXP="-Wl,--export-dynamic"
1634                         SONAMEFLAG="-Wl,-soname,"
1635                         PICFLAG="-fPIC -DPIC"
1636                         AC_DEFINE(STAT_ST_BLOCKSIZE,512,[The size of a block])
1637                         AC_DEFINE(BROKEN_GETGRNAM,1,[Does getgrnam work correctly])
1638                         ;;
1639                 *openbsd*)  BLDSHARED="true"
1640                         LDSHFLAGS="-shared"
1641                         DYNEXP="-Wl,-Bdynamic"
1642                         SONAMEFLAG="-Wl,-soname,"
1643                         PICFLAG="-fPIC"
1644                         AC_DEFINE(STAT_ST_BLOCKSIZE,512,[The size of a block])
1645                         AC_DEFINE(BROKEN_GETGRNAM,1,[Does getgrnam work correctly])
1646                         ;;
1647                 *irix*) AC_DEFINE(IRIX,1,[Whether the host os is irix])
1648                         case "$host_os" in
1649                         *irix6*) AC_DEFINE(IRIX6,1,[Whether the host os is irix6])
1650                         ;;
1651                         esac
1652                         BLDSHARED="true"
1653                         LDSHFLAGS="-Wl,-set_version,sgi1.0 -shared"
1654                         SONAMEFLAG="-Wl,-soname,"
1655                         if test "${GCC}" = "yes"; then
1656                                 PICFLAG="-fPIC"
1657                         else
1658                                 PICFLAG="-KPIC"
1659                         fi
1660                         AC_DEFINE(STAT_ST_BLOCKSIZE,512,[The size of a block])
1661                         ;;
1662                 *aix*) AC_DEFINE(AIX,1,[Whether the host os is aix])
1663                         BLDSHARED="true"
1664                         # use expfull to export underscored symbols
1665                         # add rtl to remove /lib/crt0.o warning
1666                         LDSHFLAGS="-Wl,-G,-bexpfull,-bbigtoc,-brtl"
1667                         DYNEXP="-Wl,-brtl,-bexpfull,-bbigtoc"
1668                         PICFLAG="-O2"
1669                         # as AIX code is always position independent...
1670                         # .po will just create compile warnings, use po.o:
1671                         if test "${GCC}" != "yes"; then
1672                                 ## for funky AIX compiler using strncpy()
1673                                 CFLAGS="$CFLAGS -D_LINUX_SOURCE_COMPAT -qmaxmem=32000 -qhalt=e"
1674                         fi
1675
1676                         AC_DEFINE(STAT_ST_BLOCKSIZE,DEV_BSIZE,[The size of a block])
1677                         AC_DEFINE(BROKEN_STRNLEN,1,[Does strnlen work correctly])
1678                         AC_DEFINE(BROKEN_STRNDUP,1,[Does strndup work correctly])
1679                         ;;
1680                 *hpux*) AC_DEFINE(HPUX,1,[Whether the host os is HPUX])
1681                         # ia64: 64bit build using gcc with CFLAGS="-mpl64"
1682                         #       64bit build using HP's cc with CFLAGS="+DD64"
1683                         # hppa: 64bit build unsupported by gcc
1684                         #       64bit build using HP's cc with CFLAGS="+DA2.0w"
1685                         # HP-UX 11.00 ld needs PHSS_33034
1686                         BLDSHARED="true"
1687                         if test "${GCC}" = "yes"; then
1688                                 PICFLAG="-fPIC"
1689                                 LDSHFLAGS="-shared"
1690                         else
1691                                 PICFLAG="+z"
1692                                 LDSHFLAGS="-b"
1693                                 # "Uses depth-first symbol resolution"
1694                                 LDSHFLAGS="$LDSHFLAGS -Wl,-B,symbolic,-b"
1695                                 if test "$host_cpu" != "ia64"; then
1696                                         # "don't store literals in read-only memory" (?):
1697                                         PICFLAG="$PICFLAG +ESnolit"
1698                                 fi
1699                         fi
1700                         if test "$host_cpu" = "ia64"; then
1701                                 SHLIBEXT="so"
1702                                 # TODO: does the linker find the right 32/64 bit version of the libs? :
1703                                 DYNEXP="-Wl,-E,+b/usr/local/lib/hpux32:/usr/lib/hpux32:/usr/local/lib/hpux64:/usr/lib/hpux64"
1704                         else
1705                                 SHLIBEXT="sl"
1706                                 DYNEXP="-Wl,-E,+b/usr/local/lib:/usr/lib"
1707                         fi
1708                         if test "$ac_cv_prog_gnu_ld" = "yes"; then
1709                                 SONAMEFLAG="-Wl,-soname="
1710                         else
1711                                 SONAMEFLAG="-Wl,+h,"
1712                         fi
1713                         # PIE/PIC flags at link time are required on HP-UX because
1714                         # linking requires a temporary source file, which is being
1715                         # compiled with the indicated flags - which need to contain
1716                         # PIC flags when we don't support PIE flags:
1717                         if test "$PIE_LDFLAGS" = "" ; then
1718                                 PIE_LDFLAGS=\${PICFLAG}
1719                         fi
1720                         AC_DEFINE(STAT_ST_BLOCKSIZE,8192,[The size of a block])
1721                         AC_DEFINE(POSIX_ACL_NEEDS_MASK,1,[Does a POSIX ACL need a mask element])
1722                         ;;
1723                 *osf*) AC_DEFINE(OSF1,1,[Whether the host os is osf1])
1724                         BLDSHARED="true"
1725                         LDSHFLAGS="-shared"
1726                         SONAMEFLAG="-Wl,-soname,"
1727                         if test "${GCC}" = "yes"; then
1728                                 PICFLAG="-fPIC"
1729                         fi
1730                         AC_DEFINE(STAT_ST_BLOCKSIZE,512)
1731                         AC_DEFINE(BROKEN_GETGRNAM,1,[Does getgrnam work correctly])
1732                         for flags in "-expect_unresolved '*'" "-Wl,-expect_unresolved,'*'" ; do
1733                                 saved_ldflags="$LDFLAGS"
1734                                 AC_MSG_CHECKING([if $flags works])
1735                                 LDFLAGS="$flags $saved_ldflags"
1736                                 AC_TRY_LINK([],[],
1737                                         [AC_MSG_RESULT([yes])
1738                                         LDSHFLAGS_Z_NODEFS=$flags],
1739                                         AC_MSG_RESULT([no]))
1740                                 LDFLAGS="$saved_ldflags"
1741                                 test x"$LDSHFLAGS_Z_NODEFS" != x && break
1742                         done
1743                         ;;
1744                 *sco*) AC_DEFINE(SCO,1,[Whether the host os is sco unix])
1745                         AC_DEFINE(STAT_ST_BLOCKSIZE,512)
1746                         ;;
1747                 *unixware*) AC_DEFINE(UNIXWARE,1,[Whether the host os is unixware])
1748                         BLDSHARED="true"
1749                         LDSHFLAGS="-shared"
1750                         SONAMEFLAG="-Wl,-soname,"
1751                         PICFLAG="-KPIC"
1752                         AC_DEFINE(STAT_ST_BLOCKSIZE,512)
1753                         ;;
1754                 *next2*) AC_DEFINE(NEXT2,1,[Whether the host os is NeXT v2])
1755                         AC_DEFINE(STAT_ST_BLOCKSIZE,512)
1756                         ;;
1757                 *dgux*) AC_CHECK_PROG( ROFF, groff, [groff -etpsR -Tascii -man])
1758                         AC_DEFINE(STAT_ST_BLOCKSIZE,512)
1759                         ;;
1760                 *sysv4*) AC_DEFINE(SYSV,1,[Whether this is a system V system])
1761                         case "$host" in
1762                                 *-univel-*)     if [ test "$GCC" != yes ]; then
1763                                                 AC_DEFINE(HAVE_MEMSET,1,[Whether memset() is available])
1764                                         fi
1765                                         LDSHFLAGS="-G"
1766                                         DYNEXP="-Bexport"
1767                                 ;;
1768                                 *mips-sni-sysv4*) AC_DEFINE(RELIANTUNIX,1,[Whether the host os is reliantunix]);;
1769                         esac
1770                         AC_DEFINE(STAT_ST_BLOCKSIZE,512)
1771                         ;;
1772
1773                 *sysv5*) AC_DEFINE(SYSV,1,[Whether this is a system V system])
1774                         if [ test "$GCC" != yes ]; then
1775                                 AC_DEFINE(HAVE_MEMSET,1,[Whether memset() is available])
1776                         fi
1777                         LDSHFLAGS="-G"
1778                         AC_DEFINE(STAT_ST_BLOCKSIZE,512)
1779                         ;;
1780                 *vos*) AC_DEFINE(STAT_ST_BLOCKSIZE,4096)
1781                         BLDSHARED="false"
1782                         LDSHFLAGS=""
1783                         ;;
1784
1785                 *darwin*)   AC_DEFINE(DARWINOS,1,[Whether the host os is Darwin/MacOSX])
1786                         BLDSHARED="true"
1787                         LDSHFLAGS="-dynamiclib -flat_namespace -undefined suppress"
1788                         CFLAGS="$CFLAGS -fno-common"
1789                         SHLD="\${CC}"
1790                         SHLIBEXT="dylib"
1791                         MODULE_EXPORTS="-exported_symbols_list \$(srcdir)/exports/modules-darwin.syms"
1792                         SHLIBEXT="dylib"
1793                         # Since gcc doesn't fail on unrecognised options, the
1794                         # PIE test incorrectly succeeds. Darwin gcc does not
1795                         # actually support the PIE stuff.
1796                         PIE_LDFLAGS=
1797                         PIE_CFLAGS=
1798                         AC_DEFINE(STAT_ST_BLOCKSIZE,512)
1799                         ;;
1800
1801                 *)
1802                         AC_DEFINE(STAT_ST_BLOCKSIZE,512)
1803                         ;;
1804   esac
1805
1806 if test "$enable_shared" != "yes"; then
1807         BLDSHARED=false
1808 fi
1809
1810 if test "$enable_shared" = yes -a "${ac_cv_gnu_ld_version_script}" = yes; then
1811         DSO_EXPORTS=\$\(DSO_EXPORTS_CMD\)
1812 fi
1813
1814 if test x"$BLDSHARED" = x"true" ; then
1815         LDFLAGS="$LDFLAGS -L./bin"
1816 fi
1817
1818 AC_MSG_RESULT($BLDSHARED)
1819
1820 if test x"$enable_developer" = x"yes" ; then
1821         default_as_needed=auto
1822 else
1823         default_as_needed=no
1824 fi
1825 AC_ARG_ENABLE(as-needed,
1826         AS_HELP_STRING([--enable-as-needed],
1827         [Turn on as-needed support if available (default=no)]),
1828         [enable_as_needed=$enableval],
1829         [enable_as_needed=$default_as_needed])
1830 if test "x$enable_as_needed" != xno; then
1831     saved_before_as_needed_ldflags="$LDFLAGS"
1832     for flags in "-Wl,--as-needed" "-Wl,-z,ignore" "-z ignore" ; do
1833         saved_ldflags="$LDFLAGS"
1834         AC_MSG_CHECKING([if $flags works])
1835         LDFLAGS="$flags $saved_ldflags"
1836         AC_TRY_LINK([],[],
1837                 [AC_MSG_RESULT([yes])
1838                 LD_AS_NEEDED_FLAG=$flags
1839                 ld_as_needed_flag_found=yes],
1840                 AC_MSG_RESULT([no]))
1841         LDFLAGS="$LD_AS_NEEDED_FLAG $saved_ldflags"
1842         test x"$ld_as_needed_flag_found" = xyes && break
1843     done
1844 fi
1845
1846 if test x$ld_as_needed_flag_found = xyes -a x$enable_as_needed = xauto ; then
1847 # check if ld has bug described in https://bugzilla.samba.org/show_bug.cgi?id=7209#c17
1848         AC_MSG_CHECKING([if $LD_AS_NEEDED_FLAG has explicit external libs bug])
1849 cat > conftest_shb.c <<END
1850 void b() {}
1851 END
1852 cat > conftest_sha.c <<END
1853 extern void b();
1854 void a() {
1855         b();
1856 }
1857 END
1858 cat > conftest.c <<END
1859 extern void a();
1860 int main() {
1861         a();
1862         return 0;
1863 }
1864 END
1865
1866         rm -fr conftest
1867         AC_TRY_COMMAND([$CC $CPPFLAGS $CFLAGS $PICFLAG -c -o conftest_sha.o conftest_sha.c 1>&AS_MESSAGE_LOG_FD 2>&1])
1868         AC_TRY_COMMAND([$CC $CPPFLAGS $CFLAGS $PICFLAG -c -o conftest_shb.o conftest_shb.c 1>&AS_MESSAGE_LOG_FD 2>&1])
1869         TESTCMD="`eval echo \"$SHLD $LDSHFLAGS $PICFLAG\"`"
1870         AC_TRY_COMMAND([$TESTCMD -o libconftest_shb.$SHLIBEXT conftest_shb.o 1>&AS_MESSAGE_LOG_FD 2>&1])
1871         AC_TRY_COMMAND([$TESTCMD -o libconftest_sha.$SHLIBEXT conftest_sha.o 1>&AS_MESSAGE_LOG_FD 2>&1])
1872         AC_TRY_COMMAND([$CC -o conftest conftest.c $LDFLAGS -L. -lconftest_sha -lconftest_shb 1>&AS_MESSAGE_LOG_FD 2>&1])
1873         if AC_TRY_COMMAND([eval "$LIB_PATH_VAR=. ./conftest 1>&AS_MESSAGE_LOG_FD 2>&1"])
1874         then
1875                 AC_MSG_RESULT([no])
1876         else
1877                 ld_as_needed_flag_found=no
1878                 LDFLAGS="$saved_before_as_needed_ldflags"
1879                 AC_MSG_RESULT([yes])
1880         fi
1881         rm conftest* libconftest*
1882 fi
1883
1884 # check if we have to disable LD_AS_NEEDED_FLAG:
1885 # On some systems for a veriety of reasons linking with
1886 # -Wl,--as-needed -lreadline -lncurses fails
1887 # we have to retest, if these combination is detected before.
1888 # Bugzilla #7209
1889
1890 if test x$ac_cv_lib_readline_rl_callback_handler_install = xyes ; then
1891         if test x$ld_as_needed_flag_found = xyes ; then
1892                 AC_MSG_CHECKING([if $LD_AS_NEEDED_FLAG works with readline])
1893                 # try if check no fails
1894                 save_LIBS=$LIBS
1895                 LIBS="$LIBS $TERMLIBS"
1896                 AC_TRY_LINK([], [rl_callback_handler_install();], [AC_MSG_RESULT([yes])],[ AC_MSG_RESULT([no]); LDFLAGS="$saved_before_as_needed_ldflags"])
1897                 LIBS="$save_LIBS"
1898         fi
1899 fi
1900
1901
1902
1903 # for historical reasons almost all linkers don't complain about unresolved
1904 # symbols in shared libs. Except for the internal samba modules we want to get
1905 # errors when we produce a shared lib with unresolved symbols. On some
1906 # platforms unresolved symbols might be intended, so we might have to add
1907 # platform specific exceptions here.
1908
1909 for flags in "-Wl,-z,defs" "-error_unresolved" "-Wl,-error_unresolved" ; do
1910         saved_ldflags="$LDFLAGS"
1911         AC_MSG_CHECKING([if $flags works])
1912         LDFLAGS="$flags $saved_ldflags"
1913         AC_TRY_LINK([],[],
1914         [AC_MSG_RESULT([yes])
1915         LDSHFLAGS_Z_DEFS=$flags
1916         ldshflags_z_defs_found=yes],
1917         AC_MSG_RESULT([no]))
1918         LDFLAGS=$saved_ldflags
1919         test x"$ldshflags_z_defs_found" = xyes && break
1920 done
1921
1922 AC_MSG_CHECKING([LDSHFLAGS_Z_DEFS])
1923 AC_MSG_RESULT([$LDSHFLAGS_Z_DEFS])
1924 AC_MSG_CHECKING([LDFLAGS])
1925 AC_MSG_RESULT([$LDFLAGS])
1926 AC_MSG_CHECKING([DYNEXP])
1927 AC_MSG_RESULT([$DYNEXP])
1928
1929 #######################################################
1930 # test whether building a shared library actually works
1931 if test $BLDSHARED = true; then
1932
1933 AC_MSG_CHECKING([SHLD])
1934 AC_MSG_RESULT([$SHLD])
1935 AC_MSG_CHECKING([LDSHFLAGS])
1936 AC_MSG_RESULT([$LDSHFLAGS])
1937
1938 AC_MSG_CHECKING([SHLIBEXT])
1939 AC_MSG_RESULT([$SHLIBEXT])
1940 AC_MSG_CHECKING([SONAMEFLAG])
1941 AC_MSG_RESULT([$SONAMEFLAG])
1942
1943 AC_MSG_CHECKING([PICFLAG])
1944 AC_MSG_RESULT([$PICFLAG])
1945
1946 AC_MSG_CHECKING([NSSSONAMEVERSIONSUFFIX])
1947 AC_MSG_RESULT([$NSSSONAMEVERSIONSUFFIX])
1948
1949 AC_CACHE_CHECK([whether building shared libraries actually works],
1950                [ac_cv_shlib_works],[
1951    # try building a trivial shared library
1952    ac_cv_shlib_works=no
1953    # The $SHLD and $LDSHFLAGS variables may contain references to other
1954    # variables so they need to be eval'ed.
1955    if AC_TRY_COMMAND([$CC $CPPFLAGS $CFLAGS $PICFLAG -c -o shlib.o ${srcdir-.}/../tests/shlib.c 1>&AS_MESSAGE_LOG_FD])
1956    then
1957      TESTCMD="`eval echo \"$SHLD $LDSHFLAGS $PICFLAG\"`"
1958      TESTCMD="$TESTCMD -o \"shlib.$SHLIBEXT\" shlib.o"
1959      if AC_TRY_COMMAND([eval $TESTCMD 1>&AS_MESSAGE_LOG_FD 2>&1])
1960      then
1961        ac_cv_shlib_works=yes
1962      fi
1963    fi
1964    rm -f "shlib.$SHLIBEXT" shlib.o
1965
1966 ])
1967 if test $ac_cv_shlib_works = no; then
1968    BLDSHARED=false
1969 fi
1970 fi
1971
1972 if test x"$BLDSHARED" != x"true"; then
1973         LDSHFLAGS="shared-libraries-disabled"
1974         SONAMEFLAG="shared-libraries-disabled"
1975         NSSSONAMEVERSIONSUFFIX="shared-libraries-disabled"
1976         SHLD="shared-libraries-disabled"
1977         PICFLAG="${PIE_CFLAGS}"
1978         SHLIBEXT="shared_libraries_disabled"
1979         smbtorture4_possible=no
1980 fi
1981
1982 AC_MSG_CHECKING([used PICFLAG])
1983 AC_MSG_RESULT([$PICFLAG])
1984
1985 AC_DEFINE_UNQUOTED(SHLIBEXT, "$SHLIBEXT", [Shared library extension])
1986
1987
1988
1989 ###########################################################
1990 #
1991 # Configuration of subsystems / libraries
1992 #
1993 ###########################################################
1994
1995 INSTALLLIBCMD_SH=:
1996 INSTALLLIBCMD_A=:
1997 UNINSTALLLIBCMD_SH=:
1998 UNINSTALLLIBCMD_A=:
1999
2000 if test $BLDSHARED = true; then
2001         INSTALLLIBCMD_SH="\$(INSTALLCMD)"
2002         UNINSTALLLIBCMD_SH="rm -f"
2003 fi
2004 if test $enable_static = yes; then
2005         INSTALLLIBCMD_A="\$(INSTALLCMD)"
2006         UNINSTALLLIBCMD_A="rm -f"
2007 fi
2008
2009 #################################################
2010 # --disable-shared-libs
2011 # can be used to disable the internal use of shared libs altogether
2012 # (this only has an effect when building shared libs is enabled)
2013 #
2014 USESHARED=false
2015 AC_SUBST(USESHARED)
2016
2017 AC_MSG_CHECKING(whether to use shared libraries internally)
2018 AC_ARG_ENABLE([shared-libs],
2019         AS_HELP_STRING([--enable-shared-libs],
2020                 [Use shared libraries internally (default=yes)]),
2021         [enable_shared_libs=$enableval],
2022         [enable_shared_libs=yes])
2023
2024 if test x"$enable_shared_libs" != x"no" ; then
2025         USESHARED=$BLDSHARED
2026 fi
2027
2028 AC_MSG_RESULT([$USESHARED])
2029
2030 if test x"$enable_shared_libs" = x"yes" -a x"$BLDSHARED" != x"true" ; then
2031         AC_MSG_WARN([--enable-shared-libs: no support for shared libraries])
2032 fi
2033
2034 #################################################
2035 # --with-static-libs=LIBS:
2036 #   link (internal) libs dynamically or statically?
2037 #
2038 # If a subsystem is built as a library then this controls whether they are
2039 # linked into Samba targets statically or dynamically:
2040 #
2041 # * If we build the shared library at all, we link dynamically by default.
2042 #
2043 # * We only link statically if we don't build shared or if the library
2044 #   appears in the --with-static-libs configure option.
2045 #
2046 # Example:
2047 #   --with-static-libs=libtalloc makes use of libtalloc.a instead
2048 #   of linking the dynamic variant with -ltalloc.
2049 #
2050 # NOTE: This option only affects libraries that we do not only build
2051 # but that samba also links against as libraries (as opposed to linking
2052 # the plain object files. - This has to be configured in Makefile.in.
2053 # So in particular it does not harm to give invalid or unknown names here.
2054 #
2055
2056 AC_ARG_WITH([static-libs],
2057         [AS_HELP_STRING([--with-static-libs=LIBS],
2058                 [Comma-separated list of names of (internal) libraries to link statically (instead of dynamically)])],
2059         [AS_IF([test $withval],
2060                 [for lib in `echo $withval | sed -e 's/,/ /g'` ; do
2061                         [lib=`echo $lib | tr '[a-z]' '[A-Z]'`]
2062                         eval LINK_$lib=STATIC
2063                 done], [])],
2064         [])
2065
2066 #
2067 # WORKAROUND:
2068 #   until we have organized other internal subsystems (as util, registry
2069 #   and smbconf) into shared libraries, we CAN NOT link libnetapi
2070 #   dynamically to samba programs.
2071 #
2072 LINK_LIBNETAPI=STATIC
2073
2074 LINK_LIBSMBCLIENT=STATIC
2075
2076 #
2077 #  The library versions are hardcoded here
2078 #  and filled into the LIBFOO_SOVER variable.
2079 #
2080 #  TODO: for talloc and tdb (at least), these should
2081 #  be extracted from their respective source directories
2082 #
2083 AC_ARG_ENABLE(external_libtalloc, [AS_HELP_STRING([--enable-external-libtalloc], [Enable external talloc [default=auto]])],
2084 [ enable_external_libtalloc=$enableval ], [ enable_external_libtalloc=auto ])
2085
2086 if test "x$enable_external_libtalloc" != xno
2087 then
2088         PKG_CHECK_MODULES(LIBTALLOC, talloc >= 2.0.1,
2089                 [ enable_external_libtalloc=yes ],
2090                 [ if test x$enable_external_libtalloc = xyes; then
2091                         AC_MSG_ERROR([Unable to find libtalloc])
2092                   else
2093                         enable_external_libtalloc=no
2094                   fi
2095                 ])
2096 fi
2097
2098 if test "x$enable_external_libtalloc" = xno
2099 then
2100         m4_include(../lib/talloc/libtalloc.m4)
2101         LINK_LIBTALLOC=STATIC
2102         SMB_LIBRARY(talloc, 2)
2103         LIBTALLOC_OBJ0=""
2104         for obj in ${TALLOC_OBJ}; do
2105                 LIBTALLOC_OBJ0="${LIBTALLOC_OBJ0} ${tallocdir}/${obj}"
2106         done
2107         SAMBA_CPPFLAGS="${SAMBA_CPPFLAGS} ${TALLOC_CFLAGS}"
2108         SAMBA_CONFIGURE_CPPFLAGS="${SAMBA_CONFIGURE_CPPFLAGS} ${TALLOC_CFLAGS}"
2109         AC_SUBST(LIBTALLOC_OBJ0)
2110
2111         TALLOCTORT="bin/talloctort\$(EXEEXT)"
2112         AC_SUBST(TALLOCTORT)
2113 fi
2114
2115
2116 AC_ARG_ENABLE(external_libtdb,
2117         [AS_HELP_STRING([--enable-external-libtdb],
2118                 [Enable external tdb [default=auto]])],
2119                 [ enable_external_libtalloc=$enableval ],
2120                 [ enable_external_libtalloc=auto ])
2121
2122 if test "x$enable_external_libtdb" != xno
2123 then
2124         PKG_CHECK_MODULES(LIBTDB, tdb >= 1.2.6,
2125                 [ enable_external_libtdb=yes ],
2126                 [
2127                 if test x$enable_external_libtdb = xyes; then
2128                         AC_MSG_ERROR([Unable to find libtdb])
2129                 else
2130                         enable_external_libtdb=no
2131                 fi
2132                 ])
2133 fi
2134
2135 AC_SUBST(LIBTDB_OBJ0)
2136 if test "x$enable_external_libtdb" = xno
2137 then
2138         m4_include(../lib/tdb/libtdb.m4)
2139         LINK_LIBTDB=STATIC
2140         SMB_LIBRARY(tdb, 1)
2141         LIBTDB_OBJ0=""
2142         LIBTDB_LIBS="$LIBTDB_LIBS $TDB_DEPS"
2143         for obj in ${TDB_OBJ}; do
2144                 LIBTDB_OBJ0="${LIBTDB_OBJ0} ${tdbdir}/${obj}"
2145         done
2146         AC_SUBST(LIBTDB_OBJ0)
2147         SAMBA_CPPFLAGS="${SAMBA_CPPFLAGS} ${TDB_CFLAGS}"
2148         SAMBA_CONFIGURE_CPPFLAGS="${SAMBA_CONFIGURE_CPPFLAGS} ${TDB_CFLAGS}"
2149
2150         TDBBACKUP="bin/tdbbackup\$(EXEEXT)"
2151         AC_SUBST(TDBBACKUP)
2152         TDBDUMP="bin/tdbdump\$(EXEEXT)"
2153         AC_SUBST(TDBDUMP)
2154         TDBRESTORE="bin/tdbrestore\$(EXEEXT)"
2155         AC_SUBST(TDBRESTORE)
2156         TDBTOOL="bin/tdbtool\$(EXEEXT)"
2157         AC_SUBST(TDBTOOL)
2158         TDBTORTURE="bin/tdbtorture\$(EXEEXT)"
2159         AC_SUBST(TDBTORTURE)
2160         ac_cv_have_tdb_err_nesting=yes
2161 else
2162         AC_TRY_COMPILE([#include <tdb.h>],
2163                        [enum TDB_ERROR err = TDB_ERR_NESTING],
2164                        ac_cv_have_tdb_err_nesting=yes,
2165                        ac_cv_have_tdb_err_nesting=no)
2166 fi
2167
2168 if test x"$ac_cv_have_tdb_err_nesting" = xyes; then
2169    AC_DEFINE(HAVE_TDB_ERR_NESTING, 1, [Whether we have TDB_ERR_NESTING])
2170 fi
2171
2172 SMB_LIBRARY(netapi, 0)
2173 SMB_LIBRARY(smbclient, 0)
2174 SMB_LIBRARY(smbsharemodes, 0)
2175 SMB_LIBRARY(addns, 0, no, [undefined API])
2176
2177
2178
2179 ################
2180
2181 AC_CACHE_CHECK([for long long],samba_cv_have_longlong,[
2182 AC_TRY_RUN([#include <stdio.h>
2183 main() { long long x = 1000000; x *= x; exit(((x/1000000) == 1000000)? 0: 1); }],
2184 samba_cv_have_longlong=yes,samba_cv_have_longlong=no,samba_cv_have_longlong=cross)])
2185 if test x"$samba_cv_have_longlong" = x"yes"; then
2186     AC_DEFINE(HAVE_LONGLONG,1,[Whether the host supports long long's])
2187     AC_CHECK_TYPE(intptr_t, unsigned long long)
2188 else
2189     AC_CHECK_TYPE(intptr_t, unsigned long)
2190 fi
2191
2192 #
2193 # Check if the compiler supports the LL prefix on long long integers.
2194 # AIX needs this.
2195
2196 AC_CACHE_CHECK([for LL suffix on long long integers],samba_cv_compiler_supports_ll, [
2197     AC_TRY_COMPILE([#include <stdio.h>],[long long i = 0x8000000000LL],
2198         samba_cv_compiler_supports_ll=yes,samba_cv_compiler_supports_ll=no)])
2199 if test x"$samba_cv_compiler_supports_ll" = x"yes"; then
2200    AC_DEFINE(COMPILER_SUPPORTS_LL,1,[Whether the compiler supports the LL prefix on long long integers])
2201 fi
2202
2203
2204 AC_CACHE_CHECK([for 64 bit time_t],samba_cv_SIZEOF_TIME_T,[
2205 AC_TRY_RUN([#include <time.h>
2206 main() { exit((sizeof(time_t) == 8) ? 0 : 1); }],
2207 samba_cv_SIZEOF_TIME_T=yes,samba_cv_SIZEOF_TIME_T=no,samba_cv_SIZEOF_TIME_T=cross)])
2208 if test x"$samba_cv_SIZEOF_TIME_T" = x"yes"; then
2209     AC_DEFINE(SIZEOF_TIME_T,8,[The size of the 'time_t' type])
2210 fi
2211
2212 AC_CACHE_CHECK([for TIME_T_MAX],samba_cv_TIME_T_MAX,[
2213 AC_TRY_RUN([#include <time.h>
2214 main() {
2215         struct tm *tm;
2216         if (sizeof(time_t) == 8) {
2217                 time_t max_time = 0x7fffffffffffffffll;
2218                 tm = gmtime(&max_time);
2219                 /* This should fail with 32-bit tm_year. */
2220                 if (tm == NULL) {
2221                         /* Max time_t that works with 32-bit int tm_year in struct tm. */
2222                         max_time = 67768036191676799ll;
2223                         tm = gmtime(&max_time);
2224                         if (tm) {
2225                                 exit(0);
2226                         }
2227                 }
2228         }
2229         exit(1);
2230 }],
2231 samba_cv_TIME_T_MAX=yes,samba_cv_TIME_T_MAX=no,samba_cv_TIME_T_MAX=cross)])
2232 if test x"$samba_cv_TIME_T_MAX" = x"yes"; then
2233     AC_DEFINE(TIME_T_MAX,67768036191676799ll,[The maximum value of the 'time_t' type])
2234 fi
2235
2236
2237 AC_CACHE_CHECK([for 64 bit off_t],samba_cv_SIZEOF_OFF_T,[
2238 AC_TRY_RUN([#include <stdio.h>
2239 #include <sys/stat.h>
2240 main() { exit((sizeof(off_t) == 8) ? 0 : 1); }],
2241 samba_cv_SIZEOF_OFF_T=yes,samba_cv_SIZEOF_OFF_T=no,samba_cv_SIZEOF_OFF_T=cross)])
2242 if test x"$samba_cv_SIZEOF_OFF_T" = x"yes"; then
2243     AC_DEFINE(SIZEOF_OFF_T,8,[The size of the 'off_t' type])
2244 fi
2245
2246 AC_CACHE_CHECK([for off64_t],samba_cv_HAVE_OFF64_T,[
2247 AC_TRY_RUN([
2248 #if defined(HAVE_UNISTD_H)
2249 #include <unistd.h>
2250 #endif
2251 #include <stdio.h>
2252 #include <sys/stat.h>
2253 main() { struct stat64 st; off64_t s; if (sizeof(off_t) == sizeof(off64_t)) exit(1); exit((lstat64("/dev/null", &st)==0)?0:1); }],
2254 samba_cv_HAVE_OFF64_T=yes,samba_cv_HAVE_OFF64_T=no,samba_cv_HAVE_OFF64_T=cross)])
2255 if test x"$samba_cv_HAVE_OFF64_T" = x"yes"; then
2256     AC_DEFINE(HAVE_OFF64_T,1,[Whether off64_t is available])
2257 fi
2258
2259 AC_CACHE_CHECK([for 64 bit ino_t],samba_cv_SIZEOF_INO_T,[
2260 AC_TRY_RUN([
2261 #if defined(HAVE_UNISTD_H)
2262 #include <unistd.h>
2263 #endif
2264 #include <stdio.h>
2265 #include <sys/stat.h>
2266 main() { exit((sizeof(ino_t) == 8) ? 0 : 1); }],
2267 samba_cv_SIZEOF_INO_T=yes,samba_cv_SIZEOF_INO_T=no,samba_cv_SIZEOF_INO_T=cross)])
2268 if test x"$samba_cv_SIZEOF_INO_T" = x"yes"; then
2269     AC_DEFINE(SIZEOF_INO_T,8,[The size of the 'ino_t' type])
2270 fi
2271
2272 AC_CACHE_CHECK([for ino64_t],samba_cv_HAVE_INO64_T,[
2273 AC_TRY_RUN([
2274 #if defined(HAVE_UNISTD_H)
2275 #include <unistd.h>
2276 #endif
2277 #include <stdio.h>
2278 #include <sys/stat.h>
2279 main() { struct stat64 st; ino64_t s; if (sizeof(ino_t) == sizeof(ino64_t)) exit(1); exit((lstat64("/dev/null", &st)==0)?0:1); }],
2280 samba_cv_HAVE_INO64_T=yes,samba_cv_HAVE_INO64_T=no,samba_cv_HAVE_INO64_T=cross)])
2281 if test x"$samba_cv_HAVE_INO64_T" = x"yes"; then
2282     AC_DEFINE(HAVE_INO64_T,1,[Whether the 'ino64_t' type is available])
2283 fi
2284
2285 AC_CACHE_CHECK([for 64 bit dev_t],samba_cv_SIZEOF_DEV_T,[
2286 AC_TRY_RUN([
2287 #if defined(HAVE_UNISTD_H)
2288 #include <unistd.h>
2289 #endif
2290 #include <stdio.h>
2291 #include <sys/stat.h>
2292 main() { exit((sizeof(dev_t) == 8) ? 0 : 1); }],
2293 samba_cv_SIZEOF_DEV_T=yes,samba_cv_SIZEOF_DEV_T=no,samba_cv_SIZEOF_DEV_T=cross)])
2294 if test x"$samba_cv_SIZEOF_DEV_T" = x"yes"; then
2295     AC_DEFINE(SIZEOF_DEV_T,8,[The size of the 'dev_t' type])
2296 fi
2297
2298 AC_CACHE_CHECK([for dev64_t],samba_cv_HAVE_DEV64_T,[
2299 AC_TRY_RUN([
2300 #if defined(HAVE_UNISTD_H)
2301 #include <unistd.h>
2302 #endif
2303 #include <stdio.h>
2304 #include <sys/stat.h>
2305 main() { struct stat64 st; dev64_t s; if (sizeof(dev_t) == sizeof(dev64_t)) exit(1); exit((lstat64("/dev/null", &st)==0)?0:1); }],
2306 samba_cv_HAVE_DEV64_T=yes,samba_cv_HAVE_DEV64_T=no,samba_cv_HAVE_DEV64_T=cross)])
2307 if test x"$samba_cv_HAVE_DEV64_T" = x"yes"; then
2308     AC_DEFINE(HAVE_DEV64_T,1,[Whether the 'dev64_t' type is available])
2309 fi
2310
2311 AC_CACHE_CHECK([for struct dirent64],samba_cv_HAVE_STRUCT_DIR64,[
2312 AC_TRY_COMPILE([
2313 #if defined(HAVE_UNISTD_H)
2314 #include <unistd.h>
2315 #endif
2316 #include <sys/types.h>
2317 #include <dirent.h>],
2318 [DIR64 de;],
2319 samba_cv_HAVE_STRUCT_DIR64=yes,samba_cv_HAVE_STRUCT_DIR64=no)])
2320 if test x"$samba_cv_HAVE_STRUCT_DIR64" = x"yes" && test x"$ac_cv_func_readdir64" = x"yes"; then
2321     AC_DEFINE(HAVE_STRUCT_DIR64,1,[Whether the 'DIR64' abstract data type is available])
2322 fi
2323
2324 AC_CACHE_CHECK([for struct dirent64],samba_cv_HAVE_STRUCT_DIRENT64,[
2325 AC_TRY_COMPILE([
2326 #if defined(HAVE_UNISTD_H)
2327 #include <unistd.h>
2328 #endif
2329 #include <sys/types.h>
2330 #include <dirent.h>],
2331 [struct dirent64 de;],
2332 samba_cv_HAVE_STRUCT_DIRENT64=yes,samba_cv_HAVE_STRUCT_DIRENT64=no)])
2333 if test x"$samba_cv_HAVE_STRUCT_DIRENT64" = x"yes" && test x"$ac_cv_func_readdir64" = x"yes"; then
2334     AC_DEFINE(HAVE_STRUCT_DIRENT64,1,[Whether the 'dirent64' struct is available])
2335 fi
2336
2337 AC_CACHE_CHECK([for major macro],samba_cv_HAVE_DEVICE_MAJOR_FN,[
2338 AC_TRY_RUN([
2339 #if defined(HAVE_UNISTD_H)
2340 #include <unistd.h>
2341 #endif
2342 #include <sys/types.h>
2343 main() { dev_t dev; int i = major(dev); return 0; }],
2344 samba_cv_HAVE_DEVICE_MAJOR_FN=yes,samba_cv_HAVE_DEVICE_MAJOR_FN=no,samba_cv_HAVE_DEVICE_MAJOR_FN=cross)])
2345 if test x"$samba_cv_HAVE_DEVICE_MAJOR_FN" = x"yes"; then
2346     AC_DEFINE(HAVE_DEVICE_MAJOR_FN,1,[Whether the major macro for dev_t is available])
2347 fi
2348
2349 AC_CACHE_CHECK([for minor macro],samba_cv_HAVE_DEVICE_MINOR_FN,[
2350 AC_TRY_RUN([
2351 #if defined(HAVE_UNISTD_H)
2352 #include <unistd.h>
2353 #endif
2354 #include <sys/types.h>
2355 main() { dev_t dev; int i = minor(dev); return 0; }],
2356 samba_cv_HAVE_DEVICE_MINOR_FN=yes,samba_cv_HAVE_DEVICE_MINOR_FN=no,samba_cv_HAVE_DEVICE_MINOR_FN=cross)])
2357 if test x"$samba_cv_HAVE_DEVICE_MINOR_FN" = x"yes"; then
2358     AC_DEFINE(HAVE_DEVICE_MINOR_FN,1,[Whether the minor macro for dev_t is available])
2359 fi
2360
2361 AC_CACHE_CHECK([for makedev macro],samba_cv_HAVE_MAKEDEV,[
2362 AC_TRY_RUN([
2363 #if defined(HAVE_UNISTD_H)
2364 #include <unistd.h>
2365 #endif
2366 #include <sys/types.h>
2367 main() { dev_t dev = makedev(1,2); return 0; }],
2368 samba_cv_HAVE_MAKEDEV=yes,samba_cv_HAVE_MAKEDEV=no,samba_cv_HAVE_MAKEDEV=cross)])
2369 if test x"$samba_cv_HAVE_MAKEDEV" = x"yes"; then
2370     AC_DEFINE(HAVE_MAKEDEV,1,[Whether the macro for makedev is available])
2371 fi
2372
2373 AC_CACHE_CHECK([for unsigned char],samba_cv_HAVE_UNSIGNED_CHAR,[
2374 AC_TRY_RUN([#include <stdio.h>
2375 main() { char c; c=250; exit((c > 0)?0:1); }],
2376 samba_cv_HAVE_UNSIGNED_CHAR=yes,samba_cv_HAVE_UNSIGNED_CHAR=no,samba_cv_HAVE_UNSIGNED_CHAR=cross)])
2377 if test x"$samba_cv_HAVE_UNSIGNED_CHAR" = x"yes"; then
2378     AC_DEFINE(HAVE_UNSIGNED_CHAR,1,[Whether the 'unsigned char' type is available])
2379 fi
2380
2381 AC_CACHE_CHECK([whether seekdir returns void],samba_cv_SEEKDIR_RETURNS_VOID,[
2382 AC_TRY_COMPILE([#include <sys/types.h>
2383 #include <dirent.h>
2384 void seekdir(DIR *d, long loc) { return; }],[return 0;],
2385 samba_cv_SEEKDIR_RETURNS_VOID=yes,samba_cv_SEEKDIR_RETURNS_VOID=no)])
2386 if test x"$samba_cv_SEEKDIR_RETURNS_VOID" = x"yes"; then
2387     AC_DEFINE(SEEKDIR_RETURNS_VOID,1,[Whether seekdir returns void])
2388 fi
2389
2390 AC_CACHE_CHECK([for __FUNCTION__ macro],samba_cv_HAVE_FUNCTION_MACRO,[
2391 AC_TRY_COMPILE([#include <stdio.h>], [printf("%s\n", __FUNCTION__);],
2392 samba_cv_HAVE_FUNCTION_MACRO=yes,samba_cv_HAVE_FUNCTION_MACRO=no)])
2393 if test x"$samba_cv_HAVE_FUNCTION_MACRO" = x"yes"; then
2394     AC_DEFINE(HAVE_FUNCTION_MACRO,1,[Whether there is a __FUNCTION__ macro])
2395 fi
2396
2397 if test x"$libreplace_cv_HAVE_CLOCK_GETTIME_IN_LIBRT" = xyes ; then
2398         LIBS="$LIBS -lrt"
2399 fi
2400
2401 AC_CACHE_CHECK([for broken readdir name],samba_cv_HAVE_BROKEN_READDIR_NAME,[
2402 AC_TRY_RUN([#include <sys/types.h>
2403 #include <dirent.h>
2404 main() { struct dirent *di; DIR *d = opendir("."); di = readdir(d);
2405 if (di && di->d_name[-2] == '.' && di->d_name[-1] == 0 &&
2406 di->d_name[0] == 0) exit(0); exit(1);} ],
2407 samba_cv_HAVE_BROKEN_READDIR_NAME=yes,samba_cv_HAVE_BROKEN_READDIR_NAME=no,samba_cv_HAVE_BROKEN_READDIR_NAME=cross)])
2408 if test x"$samba_cv_HAVE_BROKEN_READDIR_NAME" = x"yes"; then
2409     AC_DEFINE(HAVE_BROKEN_READDIR_NAME,1,[Whether readdir() returns the wrong name offset])
2410 fi
2411
2412 AC_CACHE_CHECK([for utimbuf],samba_cv_HAVE_UTIMBUF,[
2413 AC_TRY_COMPILE([#include <sys/types.h>
2414 #include <utime.h>],
2415 [struct utimbuf tbuf;  tbuf.actime = 0; tbuf.modtime = 1; exit(utime("foo.c",&tbuf));],
2416 samba_cv_HAVE_UTIMBUF=yes,samba_cv_HAVE_UTIMBUF=no,samba_cv_HAVE_UTIMBUF=cross)])
2417 if test x"$samba_cv_HAVE_UTIMBUF" = x"yes"; then
2418     AC_DEFINE(HAVE_UTIMBUF,1,[Whether struct utimbuf is available])
2419 fi
2420
2421 ##############
2422 # Check utmp details, but only if our OS offers utmp.h
2423 if test x"$ac_cv_header_utmp_h" = x"yes"; then
2424 dnl  utmp and utmpx come in many flavours
2425 dnl  We need to check for many of them
2426 dnl  But we don't need to do each and every one, because our code uses
2427 dnl  mostly just the utmp (not utmpx) fields.
2428
2429 AC_CHECK_FUNCS(pututline pututxline updwtmp updwtmpx getutmpx getutxent)
2430
2431 AC_CACHE_CHECK([for ut_name in utmp],samba_cv_HAVE_UT_UT_NAME,[
2432 AC_TRY_COMPILE([#include <sys/types.h>
2433 #include <utmp.h>],
2434 [struct utmp ut;  ut.ut_name[0] = 'a';],
2435 samba_cv_HAVE_UT_UT_NAME=yes,samba_cv_HAVE_UT_UT_NAME=no,samba_cv_HAVE_UT_UT_NAME=cross)])
2436 if test x"$samba_cv_HAVE_UT_UT_NAME" = x"yes"; then
2437     AC_DEFINE(HAVE_UT_UT_NAME,1,[Whether the utmp struct has a property ut_name])
2438 fi
2439
2440 AC_CACHE_CHECK([for ut_user in utmp],samba_cv_HAVE_UT_UT_USER,[
2441 AC_TRY_COMPILE([#include <sys/types.h>
2442 #include <utmp.h>],
2443 [struct utmp ut;  ut.ut_user[0] = 'a';],
2444 samba_cv_HAVE_UT_UT_USER=yes,samba_cv_HAVE_UT_UT_USER=no,samba_cv_HAVE_UT_UT_USER=cross)])
2445 if test x"$samba_cv_HAVE_UT_UT_USER" = x"yes"; then
2446     AC_DEFINE(HAVE_UT_UT_USER,1,[Whether the utmp struct has a property ut_user])
2447 fi
2448
2449 AC_CACHE_CHECK([for ut_id in utmp],samba_cv_HAVE_UT_UT_ID,[
2450 AC_TRY_COMPILE([#include <sys/types.h>
2451 #include <utmp.h>],
2452 [struct utmp ut;  ut.ut_id[0] = 'a';],
2453 samba_cv_HAVE_UT_UT_ID=yes,samba_cv_HAVE_UT_UT_ID=no,samba_cv_HAVE_UT_UT_ID=cross)])
2454 if test x"$samba_cv_HAVE_UT_UT_ID" = x"yes"; then
2455     AC_DEFINE(HAVE_UT_UT_ID,1,[Whether the utmp struct has a property ut_id])
2456 fi
2457
2458 AC_CACHE_CHECK([for ut_host in utmp],samba_cv_HAVE_UT_UT_HOST,[
2459 AC_TRY_COMPILE([#include <sys/types.h>
2460 #include <utmp.h>],
2461 [struct utmp ut;  ut.ut_host[0] = 'a';],
2462 samba_cv_HAVE_UT_UT_HOST=yes,samba_cv_HAVE_UT_UT_HOST=no,samba_cv_HAVE_UT_UT_HOST=cross)])
2463 if test x"$samba_cv_HAVE_UT_UT_HOST" = x"yes"; then
2464     AC_DEFINE(HAVE_UT_UT_HOST,1,[Whether the utmp struct has a property ut_host])
2465 fi
2466
2467 AC_CACHE_CHECK([for ut_time in utmp],samba_cv_HAVE_UT_UT_TIME,[
2468 AC_TRY_COMPILE([#include <sys/types.h>
2469 #include <utmp.h>],
2470 [struct utmp ut;  time_t t; ut.ut_time = t;],
2471 samba_cv_HAVE_UT_UT_TIME=yes,samba_cv_HAVE_UT_UT_TIME=no,samba_cv_HAVE_UT_UT_TIME=cross)])
2472 if test x"$samba_cv_HAVE_UT_UT_TIME" = x"yes"; then
2473     AC_DEFINE(HAVE_UT_UT_TIME,1,[Whether the utmp struct has a property ut_time])
2474 fi
2475
2476 AC_CACHE_CHECK([for ut_tv in utmp],samba_cv_HAVE_UT_UT_TV,[
2477 AC_TRY_COMPILE([#include <sys/types.h>
2478 #include <utmp.h>],
2479 [struct utmp ut;  struct timeval tv; ut.ut_tv = tv;],
2480 samba_cv_HAVE_UT_UT_TV=yes,samba_cv_HAVE_UT_UT_TV=no,samba_cv_HAVE_UT_UT_TV=cross)])
2481 if test x"$samba_cv_HAVE_UT_UT_TV" = x"yes"; then
2482     AC_DEFINE(HAVE_UT_UT_TV,1,[Whether the utmp struct has a property ut_tv])
2483 fi
2484
2485 AC_CACHE_CHECK([for ut_type in utmp],samba_cv_HAVE_UT_UT_TYPE,[
2486 AC_TRY_COMPILE([#include <sys/types.h>
2487 #include <utmp.h>],
2488 [struct utmp ut;  ut.ut_type = 0;],
2489 samba_cv_HAVE_UT_UT_TYPE=yes,samba_cv_HAVE_UT_UT_TYPE=no,samba_cv_HAVE_UT_UT_TYPE=cross)])
2490 if test x"$samba_cv_HAVE_UT_UT_TYPE" = x"yes"; then
2491     AC_DEFINE(HAVE_UT_UT_TYPE,1,[Whether the utmp struct has a property ut_type])
2492 fi
2493
2494 AC_CACHE_CHECK([for ut_pid in utmp],samba_cv_HAVE_UT_UT_PID,[
2495 AC_TRY_COMPILE([#include <sys/types.h>
2496 #include <utmp.h>],
2497 [struct utmp ut;  ut.ut_pid = 0;],
2498 samba_cv_HAVE_UT_UT_PID=yes,samba_cv_HAVE_UT_UT_PID=no,samba_cv_HAVE_UT_UT_PID=cross)])
2499 if test x"$samba_cv_HAVE_UT_UT_PID" = x"yes"; then
2500     AC_DEFINE(HAVE_UT_UT_PID,1,[Whether the utmp struct has a property ut_pid])
2501 fi
2502
2503 AC_CACHE_CHECK([for ut_exit in utmp],samba_cv_HAVE_UT_UT_EXIT,[
2504 AC_TRY_COMPILE([#include <sys/types.h>
2505 #include <utmp.h>],
2506 [struct utmp ut;  ut.ut_exit.e_exit = 0;],
2507 samba_cv_HAVE_UT_UT_EXIT=yes,samba_cv_HAVE_UT_UT_EXIT=no,samba_cv_HAVE_UT_UT_EXIT=cross)])
2508 if test x"$samba_cv_HAVE_UT_UT_EXIT" = x"yes"; then
2509     AC_DEFINE(HAVE_UT_UT_EXIT,1,[Whether the utmp struct has a property ut_exit])
2510 fi
2511
2512 dnl Look for the IPv6 varient by preference. Many systems have both.
2513 AC_CACHE_CHECK([for ut_addr_v6 in utmp],samba_cv_HAVE_UT_UT_ADDR_V6,[
2514 AC_TRY_COMPILE([#include <sys/types.h>
2515 #include <utmp.h>],
2516 [struct utmp ut;  ut.ut_addr_v6[0] = 0;],
2517 samba_cv_HAVE_UT_UT_ADDR_V6=yes,samba_cv_HAVE_UT_UT_ADDR_V6=no,samba_cv_HAVE_UT_UT_ADDR_V6=cross)])
2518 if test x"$samba_cv_HAVE_UT_UT_ADDR_V6" = x"yes"; then
2519     AC_DEFINE(HAVE_UT_UT_ADDR_V6,1,[Whether the utmp struct has a property ut_addr_v6])
2520 fi
2521
2522 AC_CACHE_CHECK([for ut_addr in utmp],samba_cv_HAVE_UT_UT_ADDR,[
2523 AC_TRY_COMPILE([#include <sys/types.h>
2524 #include <utmp.h>],
2525 [struct utmp ut;  ut.ut_addr = 0;],
2526 samba_cv_HAVE_UT_UT_ADDR=yes,samba_cv_HAVE_UT_UT_ADDR=no,samba_cv_HAVE_UT_UT_ADDR=cross)])
2527 if test x"$samba_cv_HAVE_UT_UT_ADDR" = x"yes"; then
2528     AC_DEFINE(HAVE_UT_UT_ADDR,1,[Whether the utmp struct has a property ut_addr])
2529 fi
2530
2531 if test x$ac_cv_func_pututline = xyes ; then
2532   AC_CACHE_CHECK([whether pututline returns pointer],samba_cv_PUTUTLINE_RETURNS_UTMP,[
2533   AC_TRY_COMPILE([#include <sys/types.h>
2534 #include <utmp.h>],
2535   [struct utmp utarg; struct utmp *utreturn; utreturn = pututline(&utarg);],
2536   samba_cv_PUTUTLINE_RETURNS_UTMP=yes,samba_cv_PUTUTLINE_RETURNS_UTMP=no)])
2537   if test x"$samba_cv_PUTUTLINE_RETURNS_UTMP" = x"yes"; then
2538       AC_DEFINE(PUTUTLINE_RETURNS_UTMP,1,[Whether pututline returns pointer])
2539   fi
2540 fi
2541
2542 AC_CACHE_CHECK([for ut_syslen in utmpx],samba_cv_HAVE_UX_UT_SYSLEN,[
2543 AC_TRY_COMPILE([#include <sys/types.h>
2544 #include <utmpx.h>],
2545 [struct utmpx ux;  ux.ut_syslen = 0;],
2546 samba_cv_HAVE_UX_UT_SYSLEN=yes,samba_cv_HAVE_UX_UT_SYSLEN=no,samba_cv_HAVE_UX_UT_SYSLEN=cross)])
2547 if test x"$samba_cv_HAVE_UX_UT_SYSLEN" = x"yes"; then
2548     AC_DEFINE(HAVE_UX_UT_SYSLEN,1,[Whether the utmpx struct has a property ut_syslen])
2549 fi
2550
2551 fi
2552 # end utmp details
2553
2554 AC_CACHE_CHECK([for linux fallocate],samba_cv_HAVE_LINUX_FALLOCATE,[
2555 AC_TRY_COMPILE([
2556 #if defined(HAVE_UNISTD_H)
2557 #include <unistd.h>
2558 #endif
2559 #include <sys/types.h>
2560 #define _GNU_SOURCE
2561 #include <fcntl.h>
2562 #if defined(HAVE_LINUX_FALLOC_H)
2563 #include <linux/falloc.h>
2564 #endif],
2565 [int ret = fallocate(0, FALLOC_FL_KEEP_SIZE, 0, 10);],
2566 samba_cv_HAVE_LINUX_FALLOCATE=yes,samba_cv_HAVE_LINUX_FALLOCATE=no)])
2567 if test x"$samba_cv_HAVE_LINUX_FALLOCATE" = x"yes" && test x"$ac_cv_func_fallocate" = x"yes"; then
2568     AC_DEFINE(HAVE_LINUX_FALLOCATE,1,[Whether the Linux 'fallocate' function is available])
2569 fi
2570
2571 AC_CACHE_CHECK([for linux fallocate64],samba_cv_HAVE_LINUX_FALLOCATE64,[
2572 AC_TRY_COMPILE([
2573 #if defined(HAVE_UNISTD_H)
2574 #include <unistd.h>
2575 #endif
2576 #include <sys/types.h>
2577 #define _GNU_SOURCE
2578 #include <fcntl.h>
2579 #if defined(HAVE_LINUX_FALLOC_H)
2580 #include <linux/falloc.h>
2581 #endif],
2582 [int ret = fallocate64(0, FALLOC_FL_KEEP_SIZE, 0, 10);],
2583 samba_cv_HAVE_LINUX_FALLOCATE64=yes,samba_cv_HAVE_LINUX_FALLOCATE64=no)])
2584 if test x"$samba_cv_HAVE_LINUX_FALLOCATE64" = x"yes" && test x"$ac_cv_func_fallocate64" = x"yes"; then
2585     AC_DEFINE(HAVE_LINUX_FALLOCATE64,1,[Whether the Linux 'fallocate64' function is available])
2586 fi
2587
2588 ICONV_LOOK_DIRS="/usr /usr/local /sw /opt"
2589 AC_ARG_WITH(libiconv,
2590 [AS_HELP_STRING([--with-libiconv=BASEDIR], [Use libiconv in BASEDIR/lib and BASEDIR/include (default=auto)])],
2591 [
2592   if test "$withval" = "no" ; then
2593     AC_MSG_ERROR([argument to --with-libiconv must be a directory])
2594   else
2595      if test "$withval" != "yes" ; then
2596         ICONV_PATH_SPEC=yes
2597         ICONV_LOOK_DIRS="$withval"
2598      fi
2599   fi
2600 ])
2601
2602 for i in $ICONV_LOOK_DIRS ; do
2603
2604     save_LIBS="$LIBS"
2605     save_LDFLAGS="$LDFLAGS"
2606     save_CPPFLAGS="$CPPFLAGS"
2607
2608     iconv_current_LIBS=""
2609     iconv_current_LDFLAGS=""
2610     iconv_current_CPPFLAGS=""
2611
2612     ICONV_FOUND="no"
2613     unset libext
2614
2615     #  This is here to handle -withval stuff for --with-libiconv
2616     #  Perhaps we should always add a -L
2617     CPPFLAGS="$save_CPPFLAGS -I$i/include"
2618
2619     # Check lib and lib32 library variants to cater for IRIX ABI-specific
2620     # installation paths. This gets a little tricky since we might have iconv
2621     # in both libiconv and in libc. In this case the jm_ICONV test will always
2622     # succeed when the header is found. To counter this, make sure the
2623     # library directory is there and check the ABI directory first (which
2624     # should be harmless on other systems, but causes tons of linker warnings on
2625     # 64bit Ubuntu systems).
2626     # As the build farm doesn't seem to have any IRIX machines with iconv.h
2627     # installed, I've decided to fix the linker warnings.
2628     # -- Kai
2629     # For IA64 HPUX systems, the libs are located in lib/hpux32 instead of lib.
2630     for l in "lib" "lib32" "lib/hpux32"; do
2631         if test -d "$i/$l" ; then
2632                 LDFLAGS="$save_LDFLAGS -L$i/$l"
2633                 LIBS=
2634                 export LDFLAGS LIBS CPPFLAGS
2635                 # Try to find iconv(3)
2636                 jm_ICONV($i/$l)
2637                 if test x"$ICONV_FOUND" = "xyes" ; then
2638                     libext="$l"
2639                     break
2640                 fi
2641         fi
2642     done
2643
2644     if test x"$ICONV_FOUND" = "xyes" ; then
2645         iconv_current_LDFLAGS="-L$i/$libext"
2646         iconv_current_CPPFLAGS="-I$i/include"
2647
2648         if test x"$jm_cv_lib_iconv" != x; then
2649             iconv_current_LIBS="$LIBS -l$jm_cv_lib_iconv"
2650         else
2651             # We found iconv in libc.
2652             iconv_current_LIBS=""
2653         fi
2654
2655     fi
2656
2657     if test x"$ICONV_FOUND" = "xyes" ; then
2658
2659         LDFLAGS="$save_LDFLAGS $iconv_current_LDFLAGS"
2660         CPPFLAGS="$save_CPPFLAGS $iconv_current_CPPFLAGS"
2661         LIBS="$save_LIBS $iconv_current_LIBS"
2662         export LDFLAGS LIBS CPPFLAGS
2663
2664         default_dos_charset=no
2665         default_display_charset=no
2666         default_unix_charset=no
2667
2668         # check for default dos charset name
2669         for j in CP850 IBM850 ; do
2670             rjs_CHARSET($j)
2671             default_dos_charset="$ICONV_CHARSET"
2672             if test x"$default_dos_charset" = x"$j"; then
2673                 break
2674             fi
2675         done
2676
2677         # check for default display charset name
2678         for j in ASCII 646 ; do
2679             rjs_CHARSET($j)
2680             default_display_charset="$ICONV_CHARSET"
2681             if test x"$default_display_charset" = x"$j"; then
2682                 break
2683             fi
2684         done
2685
2686         # check for default unix charset name
2687         for j in UTF-8 UTF8 ; do
2688             rjs_CHARSET($j)
2689             default_unix_charset="$ICONV_CHARSET"
2690             if test x"$default_unix_charset" = x"$j"; then
2691                 break
2692             fi
2693         done
2694
2695         if test "$default_dos_charset" != "no" -a \
2696                 "$default_dos_charset" != "cross" -a \
2697                 "$default_display_charset" != "no" -a \
2698                 "$default_display_charset" != "cross" -a \
2699                 "$default_unix_charset" != "no" -a \
2700                 "$default_unix_charset" != "cross"
2701         then
2702                 samba_cv_HAVE_NATIVE_ICONV=yes
2703         else
2704             if test "$default_dos_charset" = "cross" -o \
2705                      "$default_display_charset" = "cross" -o \
2706                      "$default_unix_charset" = "cross"
2707             then
2708                     samba_cv_HAVE_NATIVE_ICONV=cross
2709             else
2710                     samba_cv_HAVE_NATIVE_ICONV=no
2711             fi
2712         fi
2713
2714         # At this point, we have a libiconv candidate. We know that
2715         # we have the right headers and libraries, but we don't know
2716         # whether it does the conversions we want. We can't test this
2717         # because we are cross-compiling. This is not necessarily a big
2718         # deal, since we can't guarantee that the results we get now will
2719         # match the results we get at runtime anyway.
2720         if test x"$samba_cv_HAVE_NATIVE_ICONV" = x"cross" ; then
2721             default_dos_charset="CP850"
2722             default_display_charset="ASCII"
2723             default_unix_charset="UTF-8"
2724             samba_cv_HAVE_NATIVE_ICONV=yes
2725             AC_MSG_WARN(assuming the libiconv in $iconv_current_LDFLAGS can convert)
2726             AC_MSG_WARN([$default_dos_charset, $default_display_charset and $default_unix_charset to UCS-16LE])
2727         fi
2728
2729         if test x"$samba_cv_HAVE_NATIVE_ICONV" = x"yes" ; then
2730
2731             CPPFLAGS=$save_CPPFLAGS
2732             LDFLAGS=$save_LDFLAGS
2733             LIBS=$save_LIBS
2734
2735             if test x"$iconv_current_LIBS" != x; then
2736                 LIBS="$LIBS $iconv_current_LIBS"
2737             fi
2738
2739             # Add the flags we need to CPPFLAGS and LDFLAGS
2740             CPPFLAGS="$CPPFLAGS $iconv_current_CPPFLAGS"
2741             LDFLAGS="$LDFLAGS $iconv_current_LDFLAGS"
2742
2743             # Turn the #defines into string literals
2744             default_dos_charset="\"$default_dos_charset\""
2745             default_display_charset="\"$default_display_charset\""
2746             default_unix_charset="\"$default_unix_charset\""
2747
2748             AC_DEFINE(HAVE_NATIVE_ICONV,1,[Whether to use native iconv])
2749             AC_DEFINE_UNQUOTED(DEFAULT_DOS_CHARSET,$default_dos_charset,[Default dos charset name])
2750             AC_DEFINE_UNQUOTED(DEFAULT_DISPLAY_CHARSET,$default_display_charset,[Default display charset name])
2751             AC_DEFINE_UNQUOTED(DEFAULT_UNIX_CHARSET,$default_unix_charset,[Default unix charset name])
2752
2753            break
2754         fi
2755
2756     # We didn't find a working iconv, so keep going
2757     fi
2758
2759     #  We only need to clean these up here for the next pass through the loop
2760     CPPFLAGS=$save_CPPFLAGS
2761     LDFLAGS=$save_LDFLAGS
2762     LIBS=$save_LIBS
2763     export LDFLAGS LIBS CPPFLAGS
2764 done
2765 unset libext
2766
2767
2768 if test x"$ICONV_FOUND" = x"no" -o x"$samba_cv_HAVE_NATIVE_ICONV" != x"yes" ; then
2769     AC_MSG_WARN([Sufficient support for iconv function was not found.
2770     Install libiconv from http://freshmeat.net/projects/libiconv/ for better charset compatibility!])
2771    AC_DEFINE_UNQUOTED(DEFAULT_DOS_CHARSET,"ASCII",[Default dos charset name])
2772    AC_DEFINE_UNQUOTED(DEFAULT_DISPLAY_CHARSET,"ASCII",[Default display charset name])
2773    AC_DEFINE_UNQUOTED(DEFAULT_UNIX_CHARSET,"UTF8",[Default unix charset name])
2774 fi
2775
2776
2777 AC_CACHE_CHECK([for Linux kernel oplocks],samba_cv_HAVE_KERNEL_OPLOCKS_LINUX,[
2778 AC_TRY_RUN([
2779 #include <sys/types.h>
2780 #include <fcntl.h>
2781 #ifndef F_GETLEASE
2782 #define F_GETLEASE      1025
2783 #endif
2784 main() {
2785        int fd = open("/dev/null", O_RDONLY);
2786        return fcntl(fd, F_GETLEASE, 0) == -1;
2787 }
2788 ],
2789 samba_cv_HAVE_KERNEL_OPLOCKS_LINUX=yes,samba_cv_HAVE_KERNEL_OPLOCKS_LINUX=no,samba_cv_HAVE_KERNEL_OPLOCKS_LINUX=cross)])
2790 if test x"$samba_cv_HAVE_KERNEL_OPLOCKS_LINUX" = x"yes"; then
2791     AC_DEFINE(HAVE_KERNEL_OPLOCKS_LINUX,1,[Whether to use linux kernel oplocks])
2792 fi
2793
2794 AC_CACHE_CHECK([for kernel change notify support],samba_cv_HAVE_KERNEL_CHANGE_NOTIFY,[
2795 AC_TRY_RUN([
2796 #include <sys/types.h>
2797 #include <fcntl.h>
2798 #include <signal.h>
2799 #ifndef F_NOTIFY
2800 #define F_NOTIFY 1026
2801 #endif
2802 main() {
2803         exit(fcntl(open("/tmp", O_RDONLY), F_NOTIFY, 0) == -1 ?  1 : 0);
2804 }
2805 ],
2806 samba_cv_HAVE_KERNEL_CHANGE_NOTIFY=yes,samba_cv_HAVE_KERNEL_CHANGE_NOTIFY=no,samba_cv_HAVE_KERNEL_CHANGE_NOTIFY=cross)])
2807 if test x"$samba_cv_HAVE_KERNEL_CHANGE_NOTIFY" = x"yes"; then
2808     AC_DEFINE(HAVE_KERNEL_CHANGE_NOTIFY,1,[Whether kernel notifies changes])
2809 fi
2810
2811 AC_CACHE_CHECK([for inotify support],samba_cv_HAVE_INOTIFY,[
2812 AC_CHECK_HEADERS(linux/inotify.h asm/unistd.h sys/inotify.h)
2813 AC_CHECK_FUNCS(inotify_init)
2814 AC_HAVE_DECL(__NR_inotify_init, [#include <asm/unistd.h>])
2815 ],
2816 samba_cv_HAVE_INOTIFY=yes,
2817 samba_cv_HAVE_INOTIFY=no,
2818 samba_cv_HAVE_INOTIFY=cross)
2819
2820 if test x"$ac_cv_func_inotify_init" = x"yes" -a x"$ac_cv_header_linux_inotify_h" = x"yes"; then
2821     AC_DEFINE(HAVE_INOTIFY,1,[Whether kernel has inotify support])
2822 fi
2823
2824 #################################################
2825 # Check if FAM notifications are available. For FAM info, see
2826 #       http://oss.sgi.com/projects/fam/
2827 #       http://savannah.nongnu.org/projects/fam/
2828 AC_ARG_ENABLE(fam,
2829 [AS_HELP_STRING([--enable-fam], [Turn on FAM support (default=auto)])])
2830
2831 if test x$enable_fam != xno; then
2832     AC_CHECK_HEADERS(fam.h, [samba_cv_HAVE_FAM_H=yes], [samba_cv_HAVE_FAM_H=no])
2833     if test x"$samba_cv_HAVE_FAM_H" = x"yes"; then
2834         # On IRIX, libfam requires libC, but other FAM implementations
2835         # might not need it.
2836         AC_CHECK_LIB(fam, FAMOpen2,
2837             [samba_cv_HAVE_LIBFAM=yes; SMB_FAM_LIBS="-lfam";
2838             AC_DEFINE(HAVE_FAMOPEN2, 1, Define to 1 if there is support for FAMOpen2)],
2839             [samba_cv_HAVE_LIBFAM=no])
2840
2841         if test x"$samba_cv_HAVE_LIBFAM" = x"no" ; then
2842             samba_fam_xtra=-lC
2843             AC_CHECK_LIB_EXT(fam, samba_fam_xtra, FAMOpen2,
2844                 [samba_cv_HAVE_LIBFAM=yes; SMB_FAM_LIBS="-lfam -lC";
2845                 AC_DEFINE(HAVE_FAMOPEN2, 1, Define to 1 if there is support for FAMOpen2)],
2846                 [samba_cv_HAVE_LIBFAM=no])
2847             unset samba_fam_xtra
2848         fi
2849     fi
2850     if test x"$samba_cv_HAVE_LIBFAM" = x"yes" ; then
2851         default_shared_modules="$default_shared_modules vfs_notify_fam"
2852         AC_TRY_COMPILE([#include <fam.h>],
2853                     [enum FAMCodes code = FAMChanged;],
2854                     AC_DEFINE(HAVE_FAM_H_FAMCODES_TYPEDEF, 1,
2855                         [Whether fam.h contains a typedef for enum FAMCodes]),
2856                     [])
2857     fi
2858
2859     if test x"$samba_cv_HAVE_LIBFAM" = x"yes" ; then
2860         AC_CHECK_LIB(fam, FAMNoExists,
2861             [AC_DEFINE(HAVE_FAMNOEXISTS, 1, Define to 1 if there is support for FAMNoExists)])
2862     fi
2863
2864     if test x$enable_fam = xyes && test x"$samba_cv_HAVE_LIBFAM" != xyes ; then
2865         AC_MSG_ERROR(FAM support requested but FAM library not available )
2866     fi
2867 fi
2868
2869 AC_SUBST(SMB_FAM_LIBS)
2870
2871 #################################################
2872 # Check for DMAPI interfaces in libdm/libjfsdm/libxsdm
2873
2874
2875 with_dmapi_support=auto
2876 AC_MSG_CHECKING(whether to use DMAPI support)
2877 AC_ARG_WITH(dmapi,
2878 [AS_HELP_STRING([--with-dmapi], [Include DMAPI/XDSM support (default=auto)])],
2879 [ case "$withval" in
2880   yes|no)
2881     with_dmapi_support=$withval
2882     ;;
2883   esac ]
2884 )
2885 AC_MSG_RESULT([$with_dmapi_support])
2886
2887 if test x"$with_dmapi_support" != xno ; then
2888         SMB_CHECK_DMAPI([], [
2889                 AC_MSG_NOTICE(DMAPI support not present)
2890                 if test x"$with_dmapi_support" = xyes ; then
2891                         AC_MSG_ERROR(no DMAPI support found but requested!)
2892                 fi
2893                 ]
2894         )
2895 fi
2896
2897 # Add TSM SM VFS module only if there are both GPFS and DMAPI support
2898 # Theoretically it should work with AIX JFS2 too but this needs testing
2899 if test x"$ac_cv_header_gpfs_gpl_h" = x"yes" && test x"$samba_dmapi_libs" != x"" ; then
2900     default_shared_modules="$default_shared_modules vfs_tsmsm"
2901 fi
2902
2903 AC_CACHE_CHECK([for kernel share modes],samba_cv_HAVE_KERNEL_SHARE_MODES,[
2904 AC_TRY_RUN([
2905 #include <sys/types.h>
2906 #include <fcntl.h>
2907 #include <signal.h>
2908 #include <sys/file.h>
2909 #ifndef LOCK_MAND
2910 #define LOCK_MAND       32
2911 #define LOCK_READ       64
2912 #endif
2913 main() {
2914         exit(flock(open("/dev/null", O_RDWR), LOCK_MAND|LOCK_READ) != 0);
2915 }
2916 ],
2917 samba_cv_HAVE_KERNEL_SHARE_MODES=yes,samba_cv_HAVE_KERNEL_SHARE_MODES=no,samba_cv_HAVE_KERNEL_SHARE_MODES=cross)])
2918 if test x"$samba_cv_HAVE_KERNEL_SHARE_MODES" = x"yes"; then
2919     AC_DEFINE(HAVE_KERNEL_SHARE_MODES,1,[Whether the kernel supports share modes])
2920 fi
2921
2922
2923 AC_CACHE_CHECK([for IRIX kernel oplock type definitions],samba_cv_HAVE_KERNEL_OPLOCKS_IRIX,[
2924 AC_TRY_COMPILE([#include <sys/types.h>
2925 #include <fcntl.h>],
2926 [oplock_stat_t t; t.os_state = OP_REVOKE; t.os_dev = 1; t.os_ino = 1;],
2927 samba_cv_HAVE_KERNEL_OPLOCKS_IRIX=yes,samba_cv_HAVE_KERNEL_OPLOCKS_IRIX=no)])
2928 if test x"$samba_cv_HAVE_KERNEL_OPLOCKS_IRIX" = x"yes"; then
2929     AC_DEFINE(HAVE_KERNEL_OPLOCKS_IRIX,1,[Whether IRIX kernel oplock type definitions are available])
2930 fi
2931
2932 #################################################
2933 # Check for POSIX capability support
2934
2935 AC_CHECK_HEADER(sys/capability.h, [samba_cv_HAVE_SYS_CAPABILITY_H=yes;
2936     AC_DEFINE(HAVE_SYS_CAPABILITY_H, 1, Whether sys/capability.h is present)],
2937     [], [])
2938
2939 if test x"$samba_cv_HAVE_SYS_CAPABILITY_H" = x"yes"; then
2940
2941     ac_save_LIBS=$LIBS
2942     AC_LIBTESTFUNC(cap, cap_get_proc)
2943
2944     AC_CACHE_CHECK([for POSIX capabilities],
2945             samba_cv_HAVE_POSIX_CAPABILITIES,
2946             [
2947                 AC_TRY_RUN([
2948 #include <sys/types.h>
2949 #include <sys/capability.h>
2950 main() {
2951  cap_t cap;
2952  cap_value_t vals[1];
2953  if (!(cap = cap_get_proc()))
2954    exit(1);
2955  vals[0] = CAP_CHOWN;
2956  cap_set_flag(cap, CAP_INHERITABLE, 1, vals, CAP_CLEAR);
2957  cap_set_proc(cap);
2958  exit(0);
2959 }],
2960                 samba_cv_HAVE_POSIX_CAPABILITIES=yes,
2961                 samba_cv_HAVE_POSIX_CAPABILITIES=no,
2962                 samba_cv_HAVE_POSIX_CAPABILITIES=cross)
2963             ])
2964
2965 if test x"$samba_cv_HAVE_POSIX_CAPABILITIES" = x"yes"; then
2966     AC_DEFINE(HAVE_POSIX_CAPABILITIES, 1,
2967             [Whether POSIX capabilities are available])
2968 else
2969     LIBS=$ac_save_LIBS
2970 fi
2971
2972 fi
2973
2974 #
2975 # Check for int16, uint16, int32 and uint32 in rpc/types.h included from rpc/rpc.h
2976 # This is *really* broken but some systems (DEC OSF1) do this.... JRA.
2977 #
2978
2979 AC_CACHE_CHECK([for int16 typedef included by rpc/rpc.h],samba_cv_HAVE_INT16_FROM_RPC_RPC_H,[
2980 AC_TRY_COMPILE([#include <sys/types.h>
2981 #if defined(HAVE_RPC_RPC_H)
2982 #include <rpc/rpc.h>
2983 #endif],
2984 [int16 testvar;],
2985 samba_cv_HAVE_INT16_FROM_RPC_RPC_H=yes,samba_cv_HAVE_INT16_FROM_RPC_RPC_H=no)])
2986 if test x"$samba_cv_HAVE_INT16_FROM_RPC_RPC_H" = x"yes"; then
2987     AC_DEFINE(HAVE_INT16_FROM_RPC_RPC_H,1,[Whether int16 typedef is included by rpc/rpc.h])
2988 fi
2989
2990 AC_CACHE_CHECK([for uint16 typedef included by rpc/rpc.h],samba_cv_HAVE_UINT16_FROM_RPC_RPC_H,[
2991 AC_TRY_COMPILE([#include <sys/types.h>
2992 #if defined(HAVE_RPC_RPC_H)
2993 #include <rpc/rpc.h>
2994 #endif],
2995 [uint16 testvar;],
2996 samba_cv_HAVE_UINT16_FROM_RPC_RPC_H=yes,samba_cv_HAVE_UINT16_FROM_RPC_RPC_H=no)])
2997 if test x"$samba_cv_HAVE_UINT16_FROM_RPC_RPC_H" = x"yes"; then
2998     AC_DEFINE(HAVE_UINT16_FROM_RPC_RPC_H,1,[Whether uint16 typedef is included by rpc/rpc.h])
2999 fi
3000
3001 AC_CACHE_CHECK([for int32 typedef included by rpc/rpc.h],samba_cv_HAVE_INT32_FROM_RPC_RPC_H,[
3002 AC_TRY_COMPILE([#include <sys/types.h>
3003 #if defined(HAVE_RPC_RPC_H)
3004 #include <rpc/rpc.h>
3005 #endif],
3006 [int32 testvar;],
3007 samba_cv_HAVE_INT32_FROM_RPC_RPC_H=yes,samba_cv_HAVE_INT32_FROM_RPC_RPC_H=no)])
3008 if test x"$samba_cv_HAVE_INT32_FROM_RPC_RPC_H" = x"yes"; then
3009     AC_DEFINE(HAVE_INT32_FROM_RPC_RPC_H,1,[Whether int32 typedef is included by rpc/rpc.h])
3010 fi
3011
3012 AC_CACHE_CHECK([for uint32 typedef included by rpc/rpc.h],samba_cv_HAVE_UINT32_FROM_RPC_RPC_H,[
3013 AC_TRY_COMPILE([#include <sys/types.h>
3014 #if defined(HAVE_RPC_RPC_H)
3015 #include <rpc/rpc.h>
3016 #endif],
3017 [uint32 testvar;],
3018 samba_cv_HAVE_UINT32_FROM_RPC_RPC_H=yes,samba_cv_HAVE_UINT32_FROM_RPC_RPC_H=no)])
3019 if test x"$samba_cv_HAVE_UINT32_FROM_RPC_RPC_H" = x"yes"; then
3020     AC_DEFINE(HAVE_UINT32_FROM_RPC_RPC_H,1,[Whether uint32 typedef is included by rpc/rpc.h])
3021 fi
3022
3023 dnl
3024 dnl Some systems (SCO) have a problem including
3025 dnl <prot.h> and <rpc/rpc.h> due to AUTH_ERROR being defined
3026 dnl as a #define in <prot.h> and as part of an enum
3027 dnl in <rpc/rpc.h>.
3028 dnl
3029
3030 AC_CACHE_CHECK([for conflicting AUTH_ERROR define in rpc/rpc.h],samba_cv_HAVE_RPC_AUTH_ERROR_CONFLICT,[
3031 AC_TRY_COMPILE([#include <sys/types.h>
3032 #ifdef HAVE_SYS_SECURITY_H
3033 #include <sys/security.h>
3034 #include <prot.h>
3035 #endif  /* HAVE_SYS_SECURITY_H */
3036 #if defined(HAVE_RPC_RPC_H)
3037 #include <rpc/rpc.h>
3038 #endif],
3039 [int testvar;],
3040 samba_cv_HAVE_RPC_AUTH_ERROR_CONFLICT=no,samba_cv_HAVE_RPC_AUTH_ERROR_CONFLICT=yes)])
3041 if test x"$samba_cv_HAVE_RPC_AUTH_ERROR_CONFLICT" = x"yes"; then
3042     AC_DEFINE(HAVE_RPC_AUTH_ERROR_CONFLICT,1,[Whether there is a conflicting AUTH_ERROR define in rpc/rpc.h])
3043 fi
3044
3045 AC_MSG_CHECKING([for test routines])
3046 AC_TRY_RUN([#include "${srcdir-.}/../tests/trivial.c"],
3047            AC_MSG_RESULT(yes),
3048            AC_MSG_ERROR([cant find test code. Aborting config]),
3049            AC_MSG_WARN([cannot run when cross-compiling]))
3050
3051 AC_CACHE_CHECK([for ftruncate extend],samba_cv_HAVE_FTRUNCATE_EXTEND,[
3052 AC_TRY_RUN([#include "${srcdir-.}/../tests/ftruncate.c"],
3053            samba_cv_HAVE_FTRUNCATE_EXTEND=yes,samba_cv_HAVE_FTRUNCATE_EXTEND=no,samba_cv_HAVE_FTRUNCATE_EXTEND=cross)])
3054 if test x"$samba_cv_HAVE_FTRUNCATE_EXTEND" = x"yes"; then
3055     AC_DEFINE(HAVE_FTRUNCATE_EXTEND,1,[Truncate extend])
3056 fi
3057
3058 AC_CACHE_CHECK([for broken getgroups],samba_cv_HAVE_BROKEN_GETGROUPS,[
3059 AC_TRY_RUN([#include "${srcdir-.}/../tests/getgroups.c"],
3060            samba_cv_HAVE_BROKEN_GETGROUPS=yes,samba_cv_HAVE_BROKEN_GETGROUPS=no,samba_cv_HAVE_BROKEN_GETGROUPS=cross)])
3061 if test x"$samba_cv_HAVE_BROKEN_GETGROUPS" = x"yes"; then
3062     AC_DEFINE(HAVE_BROKEN_GETGROUPS,1,[Whether getgroups is broken])
3063 fi
3064
3065 SMB_CHECK_SYSCONF(_SC_NGROUPS_MAX)
3066 SMB_CHECK_SYSCONF(_SC_NPROC_ONLN)
3067 SMB_CHECK_SYSCONF(_SC_NPROCESSORS_ONLN)
3068 SMB_CHECK_SYSCONF(_SC_PAGESIZE)
3069 AC_CHECK_FUNCS(getpagesize)
3070
3071 ################################################
3072 # look for a method of setting the effective uid
3073 seteuid=no;
3074
3075 if test $seteuid = no; then
3076 AC_CACHE_CHECK([for setreuid],samba_cv_USE_SETREUID,[
3077 AC_TRY_RUN([
3078 #define AUTOCONF_TEST 1
3079 #define USE_SETREUID 1
3080 #include "confdefs.h"
3081 #include "${srcdir-.}/lib/util_sec.c"],
3082            samba_cv_USE_SETREUID=yes,samba_cv_USE_SETREUID=no,samba_cv_USE_SETREUID=cross)])
3083 if test x"$samba_cv_USE_SETREUID" = x"yes"; then
3084     seteuid=yes;AC_DEFINE(USE_SETREUID,1,[Whether setreuid() is available])
3085 fi
3086 fi
3087
3088 # we check for setresuid second as it conflicts with AIO on Linux. 
3089 # see http://samba.org/~tridge/junkcode/aio_uid.c
3090 if test $seteuid = no; then
3091 AC_CACHE_CHECK([for setresuid],samba_cv_USE_SETRESUID,[
3092 AC_TRY_RUN([
3093 #define AUTOCONF_TEST 1
3094 #define USE_SETRESUID 1
3095 #include "confdefs.h"
3096 #include "${srcdir-.}/lib/util_sec.c"],
3097            samba_cv_USE_SETRESUID=yes,samba_cv_USE_SETRESUID=no,samba_cv_USE_SETRESUID=cross)])
3098 if test x"$samba_cv_USE_SETRESUID" = x"yes"; then
3099     seteuid=yes;AC_DEFINE(USE_SETRESUID,1,[Whether setresuid() is available])
3100 fi
3101 fi
3102
3103 if test $seteuid = no; then
3104 AC_CACHE_CHECK([for seteuid],samba_cv_USE_SETEUID,[
3105 AC_TRY_RUN([
3106 #define AUTOCONF_TEST 1
3107 #define USE_SETEUID 1
3108 #include "confdefs.h"
3109 #include "${srcdir-.}/lib/util_sec.c"],
3110            samba_cv_USE_SETEUID=yes,samba_cv_USE_SETEUID=no,samba_cv_USE_SETEUID=cross)])
3111 if test x"$samba_cv_USE_SETEUID" = x"yes"; then
3112     seteuid=yes;AC_DEFINE(USE_SETEUID,1,[Whether seteuid() is available])
3113 fi
3114 fi
3115
3116 if test $seteuid = no; then
3117 AC_CACHE_CHECK([for setuidx],samba_cv_USE_SETUIDX,[
3118 AC_TRY_RUN([
3119 #define AUTOCONF_TEST 1
3120 #define USE_SETUIDX 1
3121 #include "confdefs.h"
3122 #include "${srcdir-.}/lib/util_sec.c"],
3123            samba_cv_USE_SETUIDX=yes,samba_cv_USE_SETUIDX=no,samba_cv_USE_SETUIDX=cross)])
3124 if test x"$samba_cv_USE_SETUIDX" = x"yes"; then
3125     seteuid=yes;AC_DEFINE(USE_SETUIDX,1,[Whether setuidx() is available])
3126 fi
3127 fi
3128
3129 AC_CACHE_CHECK([for the Darwin initgroups system call],
3130         samba_cv_DARWIN_INITGROUPS,
3131         AC_TRY_LINK([
3132 #include <sys/syscall.h>
3133 #include <unistd.h>
3134         ],
3135         [ syscall(SYS_initgroups, 16, NULL, NULL, 0); ],
3136         samba_cv_DARWIN_INITGROUPS=yes,
3137         samba_cv_DARWIN_INITGROUPS=no)
3138 )
3139
3140 if test x"$samba_cv_DARWIN_INITGROUPS" = x"yes" ; then
3141     AC_DEFINE(HAVE_DARWIN_INITGROUPS, 1,
3142         [Whether to use the Darwin-specific initgroups system call])
3143 fi
3144
3145 AC_CACHE_CHECK([for fcntl locking],samba_cv_HAVE_FCNTL_LOCK,[
3146 AC_TRY_RUN([#include "${srcdir-.}/../tests/fcntl_lock.c"],
3147            samba_cv_HAVE_FCNTL_LOCK=yes,samba_cv_HAVE_FCNTL_LOCK=no,samba_cv_HAVE_FCNTL_LOCK=cross)])
3148 if test x"$samba_cv_HAVE_FCNTL_LOCK" = x"yes"; then
3149     AC_DEFINE(HAVE_FCNTL_LOCK,1,[Whether fcntl locking is available])
3150 fi
3151
3152 AC_CACHE_CHECK([for broken (glibc2.1/x86) 64 bit fcntl locking],samba_cv_HAVE_BROKEN_FCNTL64_LOCKS,[
3153 AC_TRY_RUN([#include "${srcdir-.}/../tests/fcntl_lock64.c"],
3154            samba_cv_HAVE_BROKEN_FCNTL64_LOCKS=yes,samba_cv_HAVE_BROKEN_FCNTL64_LOCKS=no,samba_cv_HAVE_BROKEN_FCNTL64_LOCKS=cross)])
3155 if test x"$samba_cv_HAVE_BROKEN_FCNTL64_LOCKS" = x"yes"; then
3156     AC_DEFINE(HAVE_BROKEN_FCNTL64_LOCKS,1,[Whether fcntl64 locks are broken])
3157
3158 else
3159
3160 dnl
3161 dnl Don't check for 64 bit fcntl locking if we know that the
3162 dnl glibc2.1 broken check has succeeded.
3163 dnl
3164
3165   AC_CACHE_CHECK([for 64 bit fcntl locking],samba_cv_HAVE_STRUCT_FLOCK64,[
3166   AC_TRY_RUN([
3167 #if defined(HAVE_UNISTD_H)
3168 #include <unistd.h>
3169 #endif
3170 #include <stdio.h>
3171 #include <stdlib.h>
3172
3173 #ifdef HAVE_FCNTL_H
3174 #include <fcntl.h>
3175 #endif
3176
3177 #ifdef HAVE_SYS_FCNTL_H
3178 #include <sys/fcntl.h>
3179 #endif
3180 main() { struct flock64 fl64;
3181 #if defined(F_SETLKW64) && defined(F_SETLK64) && defined(F_GETLK64)
3182 exit(0);
3183 #else
3184 exit(1);
3185 #endif
3186 }],
3187        samba_cv_HAVE_STRUCT_FLOCK64=yes,samba_cv_HAVE_STRUCT_FLOCK64=no,samba_cv_HAVE_STRUCT_FLOCK64=cross)])
3188
3189   if test x"$samba_cv_HAVE_STRUCT_FLOCK64" = x"yes"; then
3190       AC_DEFINE(HAVE_STRUCT_FLOCK64,1,[Whether the flock64 struct is available])
3191   fi
3192 fi
3193
3194 # glibc up to 2.3.6 had dangerously broken posix_fallocate(). DON'T USE IT.
3195 AC_CACHE_CHECK([for broken posix_fallocate],samba_cv_HAVE_BROKEN_POSIX_FALLOCATE,[
3196 AC_TRY_COMPILE([
3197   #define _XOPEN_SOURCE 600
3198   #include <stdlib.h>
3199   #if defined(__GLIBC__) && ((__GLIBC__ < 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 4))
3200     probably broken posix_fallocate
3201   #endif
3202 ], [
3203 ], 
3204 samba_cv_HAVE_BROKEN_POSIX_FALLOCATE=no,samba_cv_HAVE_BROKEN_POSIX_FALLOCATE=yes)])
3205 if test x"$samba_cv_HAVE_BROKEN_POSIX_FALLOCATE" = xyes; then
3206         AC_DEFINE(HAVE_BROKEN_POSIX_FALLOCATE,, Whether we have a broken posix_fallocate)
3207 fi
3208
3209
3210 AC_CACHE_CHECK([for st_blocks in struct stat],samba_cv_HAVE_STAT_ST_BLOCKS,[
3211 AC_TRY_COMPILE([#include <sys/types.h>
3212 #include <sys/stat.h>
3213 #include <unistd.h>],
3214 [struct stat st;  st.st_blocks = 0;],
3215 samba_cv_HAVE_STAT_ST_BLOCKS=yes,samba_cv_HAVE_STAT_ST_BLOCKS=no,samba_cv_HAVE_STAT_ST_BLOCKS=cross)])
3216 if test x"$samba_cv_HAVE_STAT_ST_BLOCKS" = x"yes"; then
3217     AC_DEFINE(HAVE_STAT_ST_BLOCKS,1,[Whether the stat struct has a st_block property])
3218 fi
3219
3220 AC_CHECK_TYPES([blksize_t, blkcnt_t], [], [], [[#include <sys/stat.h>]])
3221
3222 AC_CACHE_CHECK([for st_blksize in struct stat],samba_cv_HAVE_STAT_ST_BLKSIZE,[
3223 AC_TRY_COMPILE([#include <sys/types.h>
3224 #include <sys/stat.h>
3225 #include <unistd.h>],
3226 [struct stat st;  st.st_blksize = 0;],
3227 samba_cv_HAVE_STAT_ST_BLKSIZE=yes,samba_cv_HAVE_STAT_ST_BLKSIZE=no,samba_cv_HAVE_STAT_ST_BLKSIZE=cross)])
3228 if test x"$samba_cv_HAVE_STAT_ST_BLKSIZE" = x"yes"; then
3229     AC_DEFINE(HAVE_STAT_ST_BLKSIZE,1,[Whether the stat struct has a st_blksize property])
3230 fi
3231
3232 AC_CACHE_CHECK([for st_flags in struct stat],
3233         samba_cv_HAVE_STAT_ST_FLAGS,
3234         [
3235             AC_TRY_COMPILE([#include <sys/types.h>
3236 #include <sys/stat.h>
3237 #include <unistd.h>],
3238             [struct stat st;  st.st_flags = 0;],
3239             samba_cv_HAVE_STAT_ST_FLAGS=yes,
3240             samba_cv_HAVE_STAT_ST_FLAGS=no,
3241             samba_cv_HAVE_STAT_ST_FLAGS=cross)
3242         ])
3243
3244 if test x"$samba_cv_HAVE_STAT_ST_FLAGS" = x"yes"; then
3245     AC_DEFINE(HAVE_STAT_ST_FLAGS, 1,
3246                 [Whether the stat struct has a st_flags member])
3247 fi
3248
3249 AC_CACHE_CHECK([for broken nisplus include files],samba_cv_BROKEN_NISPLUS_INCLUDE_FILES,[
3250 AC_TRY_COMPILE([
3251 #include <sys/types.h>
3252 #include <sys/acl.h>
3253 #if defined(HAVE_RPCSVC_NIS_H)
3254 #include <rpcsvc/nis.h>
3255 #endif],
3256 [int i;],
3257 samba_cv_BROKEN_NISPLUS_INCLUDE_FILES=no,samba_cv_BROKEN_NISPLUS_INCLUDE_FILES=yes)])
3258 if test x"$samba_cv_BROKEN_NISPLUS_INCLUDE_FILES" = x"yes"; then
3259         AC_DEFINE(BROKEN_NISPLUS_INCLUDE_FILES,1,[Whether the nisplus include files are broken])
3260 fi
3261
3262 AC_CACHE_CHECK([if the realpath function allows a NULL argument],samba_cv_REALPATH_TAKES_NULL,[
3263 AC_TRY_RUN([
3264 #include <stdio.h>
3265 #include <limits.h>
3266 #include <signal.h>
3267
3268 void exit_on_core(int ignored) {
3269         exit(1);
3270 }
3271
3272 main() {
3273         char *newpath;
3274         signal(SIGSEGV, exit_on_core);
3275         newpath = realpath("/tmp", NULL);
3276         exit((newpath != NULL) ? 0 : 1);
3277 }
3278 ],
3279 samba_cv_REALPATH_TAKES_NULL=yes,samba_cv_REALPATH_TAKES_NULL=no,samba_cv_REALPATH_TAKES_NULL=cross)])
3280 if test x"$samba_cv_REALPATH_TAKES_NULL" = x"yes"; then
3281     AC_DEFINE(REALPATH_TAKES_NULL,1,[Whether the realpath function allows NULL])
3282 fi
3283
3284 #################################################
3285 # check for AFS clear-text auth support
3286 samba_cv_WITH_AFS=no
3287 AC_MSG_CHECKING(whether to use AFS clear-text auth)
3288 AC_ARG_WITH(afs,
3289 [AS_HELP_STRING([--with-afs], [Include AFS clear-text auth support (default=no)])],
3290 [ case "$withval" in
3291   yes|auto)
3292     AC_MSG_RESULT($withval)
3293     samba_cv_WITH_AFS=$withval
3294     ;;
3295   *)
3296     AC_MSG_RESULT(no)
3297     ;;
3298   esac ],
3299   AC_MSG_RESULT(no)
3300 )
3301
3302 ####################################################
3303 # check for Linux-specific AFS fake-kaserver support
3304 samba_cv_WITH_FAKE_KASERVER=no
3305 AC_MSG_CHECKING(whether to use AFS fake-kaserver)
3306 AC_ARG_WITH(fake-kaserver,
3307 [AS_HELP_STRING([--with-fake-kaserver], [Include AFS fake-kaserver support (default=no)])],
3308 [ case "$withval" in
3309   yes|auto)
3310     AC_MSG_RESULT($withval)
3311     samba_cv_WITH_FAKE_KASERVER=$withval
3312     ;;
3313   *)
3314     AC_MSG_RESULT(no)
3315     ;;
3316   esac ],
3317   AC_MSG_RESULT(no)
3318 )
3319
3320 #################################################
3321 # decide whether we can support WITH_AFS and / or WITH_FAKE_KASERVER
3322 if test x"$samba_cv_WITH_AFS" != x"no" ||
3323    test x"$samba_cv_WITH_FAKE_KASERVER" != x"no"; then
3324
3325     # see if this box has the OpenSSL DES libraries
3326     AC_CHECK_LIB( crypto, DES_pcbc_encrypt, LIBS="$LIBS -lcrypto" , [AC_ERROR(OpenSSL library: libcrypto ot found!)] )
3327
3328     # see if this box has the afs-headers in /usr/include/afs
3329     AC_MSG_CHECKING(for /usr/include/afs)
3330     if test -d /usr/include/afs; then
3331           AC_MSG_RESULT(yes)
3332     else
3333       AC_MSG_RESULT(no)
3334     fi
3335
3336     # check for afs.h
3337     have_afs_headers=no
3338     AC_CHECK_HEADERS(afs.h afs/afs.h)
3339     if test x"$ac_cv_header_afs_h" = x"no" && test x"$ac_cv_header_afs_afs_h" = x"no"; then
3340         if test x"$samba_cv_WITH_FAKE_KASERVER" = x"auto" ||
3341            test x"$samba_cv_WITH_AFS" = x"auto"; then
3342                 AC_MSG_WARN([AFS cannot be supported without afs.h])
3343         else
3344                 AC_MSG_ERROR([AFS cannot be supported without afs.h])
3345         fi
3346     else
3347         have_afs_headers=yes
3348     fi
3349 fi
3350
3351 FAKE_KASERVER_OBJ=""
3352 if test x"$samba_cv_WITH_FAKE_KASERVER" != x"no" && test x"$have_afs_headers" = x"yes"; then
3353     AC_DEFINE(WITH_FAKE_KASERVER,1,[Whether to include AFS fake-kaserver support])
3354     FAKE_KASERVER_OBJ="utils/net_afs.o"
3355 fi
3356 AC_SUBST(FAKE_KASERVER_OBJ)
3357
3358 #################################################
3359 # check whether to compile AFS/NT ACL mapping module
3360 samba_cv_WITH_VFS_AFSACL=no
3361 AC_MSG_CHECKING(whether to use AFS ACL mapping module)
3362 AC_ARG_WITH(vfs-afsacl,
3363 [AS_HELP_STRING([--with-vfs-afsacl], [Include AFS to NT ACL mapping module (default=no)])],
3364 [ case "$withval" in
3365   yes|auto)
3366     AC_MSG_RESULT($withval)
3367     samba_cv_WITH_VFS_AFSACL=yes
3368     ;;
3369   *)
3370     AC_MSG_RESULT(no)
3371     ;;
3372   esac ],
3373   AC_MSG_RESULT(no)
3374 )
3375
3376 if test x"$samba_cv_WITH_VFS_AFSACL" = x"yes"; then
3377    default_shared_modules="$default_shared_modules vfs_afsacl"
3378 fi
3379         
3380 if test x"$samba_cv_WITH_AFS" != x"no" && test x"$have_afs_headers" = x"yes"; then
3381     AC_DEFINE(WITH_AFS,1,[Whether to include AFS clear-text auth support])
3382 fi
3383
3384 #################################################
3385 # check for the DFS clear-text auth system
3386 AC_MSG_CHECKING(whether to use DFS clear-text auth)
3387 AC_ARG_WITH(dfs,
3388 [AS_HELP_STRING([--with-dce-dfs], [Include DCE/DFS clear-text auth support (default=no)])],
3389 [ case "$withval" in
3390   yes)
3391     AC_MSG_RESULT(yes)
3392     AC_DEFINE(WITH_DFS,1,[Whether to include DFS support])
3393     ;;
3394   *)
3395     AC_MSG_RESULT(no)
3396     ;;
3397   esac ],
3398   AC_MSG_RESULT(no)
3399 )
3400
3401 ########################################################
3402 # Compile with LDAP support?
3403
3404 with_ldap_support=auto
3405 AC_MSG_CHECKING([for LDAP support])
3406
3407 AC_ARG_WITH(ldap,
3408 [AS_HELP_STRING([--with-ldap], [LDAP support (default=auto)])],
3409 [ case "$withval" in
3410     yes|no)
3411         with_ldap_support=$withval
3412         ;;
3413   esac ])
3414
3415 AC_MSG_RESULT($with_ldap_support)
3416
3417 SMBLDAP=""
3418 AC_SUBST(SMBLDAP)
3419 SMBLDAPUTIL=""
3420 AC_SUBST(SMBLDAPUTIL)
3421
3422 if test x"$with_ldap_support" != x"no"; then
3423
3424   ##################################################################
3425   # first test for ldap.h and lber.h
3426   # (ldap.h is required for this test)
3427   AC_CHECK_HEADERS(ldap.h lber.h)
3428
3429   if test x"$ac_cv_header_ldap_h" != x"yes"; then
3430         if test x"$with_ldap_support" = x"yes"; then
3431          AC_MSG_ERROR(ldap.h is needed for LDAP support)
3432         else
3433          AC_MSG_WARN(ldap.h is needed for LDAP support)
3434         fi
3435         
3436         with_ldap_support=no
3437   fi
3438
3439   ##################################################################
3440   # HP/UX does not have ber_tag_t in lber.h - it must be configured as
3441   # unsigned int in include/includes.h
3442   case $host_os in
3443         *hpux*)
3444          AC_MSG_WARN(ber_tag_t is needed for LDAP support)
3445          AC_MSG_WARN(ber_tag_t must be configured in includes.h for hpux)
3446         with_ldap_support=yes
3447         ;;
3448         *)
3449         AC_CHECK_TYPE(ber_tag_t,,,[#include <lber.h>])
3450         if test x"$ac_cv_type_ber_tag_t" != x"yes"; then
3451                 if test x"$with_ldap_support" = x"yes"; then
3452                 AC_MSG_ERROR(ber_tag_t is needed for LDAP support)
3453                 else
3454                 AC_MSG_WARN(ber_tag_t is needed for LDAP support)
3455                 fi
3456                 with_ldap_support=no
3457         fi
3458         ;;
3459   esac
3460 fi
3461
3462 if test x"$with_ldap_support" != x"no"; then
3463   ac_save_LIBS=$LIBS
3464
3465   ##################################################################
3466   # we might need the lber lib on some systems. To avoid link errors
3467   # this test must be before the libldap test
3468   AC_CHECK_LIB_EXT(lber, LDAP_LIBS, ber_scanf)
3469
3470   ########################################################
3471   # If ber_sockbuf_add_io() is available we can add
3472   # SASL wrapping hooks
3473   AC_CHECK_FUNC_EXT(ber_sockbuf_add_io,$LDAP_LIBS)
3474
3475   AC_CACHE_CHECK([for LDAP_OPT_SOCKBUF],samba_cv_HAVE_LDAP_OPT_SOCKBUF,[
3476                  AC_TRY_COMPILE([#include <ldap.h>],
3477                                 [int val = LDAP_OPT_SOCKBUF;],
3478                         samba_cv_HAVE_LDAP_OPT_SOCKBUF=yes,
3479                         samba_cv_HAVE_LDAP_OPT_SOCKBUF=no)])
3480
3481   if test x"$ac_cv_func_ext_ber_sockbuf_add_io" = x"yes" -a \
3482           x"$samba_cv_HAVE_LDAP_OPT_SOCKBUF" = x"yes"; then
3483         AC_DEFINE(HAVE_LDAP_SASL_WRAPPING, 1, [Support for SASL wrapping])
3484   fi
3485
3486   #######################################################
3487   # if we have LBER_OPT_LOG_PRINT_FN, we can intercept
3488   # ldap logging and print it out in the samba logs
3489   AC_CACHE_CHECK([for LBER_OPT_LOG_PRINT_FN],
3490                  samba_cv_HAVE_LBER_OPT_LOG_PRINT_FN,
3491                  [AC_TRY_COMPILE([#include <lber.h>],
3492                                  [int val = LBER_OPT_LOG_PRINT_FN;],
3493                                  samba_cv_HAVE_LBER_OPT_LOG_PRINT_FN=yes,
3494                                  samba_cv_HAVE_LBER_OPT_LOG_PRINT_FN=no)])
3495
3496   if test x"$samba_cv_HAVE_LBER_OPT_LOG_PRINT_FN" = x"yes"; then
3497         AC_DEFINE(HAVE_LBER_LOG_PRINT_FN, 1,
3498                   [Support for LDAP/LBER logging interception])
3499   fi
3500
3501   ########################################################
3502   # now see if we can find the ldap libs in standard paths
3503   AC_CHECK_LIB_EXT(ldap, LDAP_LIBS, ldap_init)
3504
3505   ########################################################
3506   # If we have LDAP, does it's rebind procedure take 2 or 3 arguments?
3507   # Check found in pam_ldap 145.
3508   AC_CHECK_FUNC_EXT(ldap_set_rebind_proc,$LDAP_LIBS)
3509
3510   LIBS="$LIBS $LDAP_LIBS"
3511   AC_CACHE_CHECK(whether ldap_set_rebind_proc takes 3 arguments, smb_ldap_cv_ldap_set_rebind_proc, [
3512     AC_TRY_COMPILE([
3513         #include <lber.h>
3514         #include <ldap.h>],
3515         [ldap_set_rebind_proc(0, 0, 0);],
3516         [smb_ldap_cv_ldap_set_rebind_proc=3],
3517         [smb_ldap_cv_ldap_set_rebind_proc=2]
3518     )
3519   ])
3520
3521   AC_DEFINE_UNQUOTED(LDAP_SET_REBIND_PROC_ARGS, $smb_ldap_cv_ldap_set_rebind_proc, [Number of arguments to ldap_set_rebind_proc])
3522
3523   AC_CHECK_FUNC_EXT(ldap_initialize,$LDAP_LIBS)
3524
3525   if test x"$ac_cv_lib_ext_ldap_ldap_init" = x"yes"; then
3526     AC_DEFINE(HAVE_LDAP,1,[Whether ldap is available])
3527     CPPFLAGS="$CPPFLAGS -DLDAP_DEPRECATED"
3528     default_static_modules="$default_static_modules pdb_ldap idmap_ldap";
3529     default_shared_modules="$default_shared_modules";
3530     SMBLDAP="lib/smbldap.o"
3531     SMBLDAPUTIL="lib/smbldap_util.o"
3532     with_ldap_support=yes
3533     AC_MSG_CHECKING(whether LDAP support is used)
3534     AC_MSG_RESULT(yes)
3535   else
3536     if test x"$with_ldap_support" = x"yes"; then
3537         AC_MSG_ERROR(libldap is needed for LDAP support)
3538     else
3539         AC_MSG_WARN(libldap is needed for LDAP support)
3540     fi
3541
3542     LDAP_LIBS=""
3543     with_ldap_support=no
3544   fi
3545   LIBS=$ac_save_LIBS
3546 fi
3547
3548
3549 #################################################
3550 # active directory support
3551
3552 with_ads_support=auto
3553 AC_MSG_CHECKING([for Active Directory and krb5 support])
3554
3555 AC_ARG_WITH(ads,
3556 [AS_HELP_STRING([--with-ads], [Active Directory support (default=auto)])],
3557 [ case "$withval" in
3558     yes|no)
3559         with_ads_support="$withval"
3560         ;;
3561   esac ])
3562
3563 AC_MSG_RESULT($with_ads_support)
3564
3565 FOUND_KRB5=no
3566 KRB5_LIBS=""
3567
3568 if test x"$with_ldap_support" != x"yes"; then
3569
3570     if test x"$with_ads_support" = x"yes"; then
3571         AC_MSG_ERROR(Active Directory Support requires LDAP support)
3572     elif test x"$with_ads_support" = x"auto"; then
3573         AC_MSG_WARN(Disabling Active Directory support (requires LDAP support))
3574         with_ads_support=no
3575     fi
3576
3577 else
3578
3579     # Check to see whether there is enough LDAP functionality to be able
3580     # to build AD support.
3581
3582 # HPUX only has ldap_init; ok, we take care of this in smbldap.c
3583 case "$host_os" in
3584         *hpux*)
3585     AC_CHECK_FUNC_EXT(ldap_init,$LDAP_LIBS)
3586
3587     if test x"$ac_cv_func_ext_ldap_init" != x"yes"; then
3588         if test x"$with_ads_support" = x"yes"; then
3589             AC_MSG_ERROR(Active Directory support on HPUX requires ldap_init)
3590         elif test x"$with_ads_support" = x"auto"; then
3591             AC_MSG_WARN(Disabling Active Directory support (requires ldap_init on HPUX))
3592             with_ads_support=no
3593         fi
3594     fi
3595     ;;
3596         *)
3597     AC_CHECK_FUNC_EXT(ldap_initialize,$LDAP_LIBS)
3598
3599     if test x"$ac_cv_func_ext_ldap_initialize" != x"yes"; then
3600         if test x"$with_ads_support" = x"yes"; then
3601             AC_MSG_ERROR(Active Directory support requires ldap_initialize)
3602         elif test x"$with_ads_support" = x"auto"; then
3603             AC_MSG_WARN(Disabling Active Directory support (requires ldap_initialize))
3604             with_ads_support=no
3605         fi
3606     fi
3607     ;;
3608 esac
3609
3610
3611     AC_CHECK_FUNC_EXT(ldap_add_result_entry,$LDAP_LIBS)
3612
3613     if test x"$ac_cv_func_ext_ldap_add_result_entry" != x"yes"; then
3614         if test x"$with_ads_support" = x"yes"; then
3615             AC_MSG_ERROR(Active Directory support requires ldap_add_result_entry)
3616         elif test x"$with_ads_support" = x"auto"; then
3617             AC_MSG_WARN(Disabling Active Directory support (requires ldap_add_result_entry))
3618             with_ads_support=no
3619         fi
3620     fi
3621
3622 fi
3623
3624 if test x"$with_ads_support" != x"no"; then
3625
3626   # Do no harm to the values of CFLAGS and LIBS while testing for
3627   # Kerberos support.
3628
3629   if test x$FOUND_KRB5 = x"no"; then
3630     #################################################
3631     # check for location of Kerberos 5 install
3632     AC_MSG_CHECKING(for kerberos 5 install path)
3633     AC_ARG_WITH(krb5,
3634     [AS_HELP_STRING([--with-krb5=base-dir], [Locate Kerberos 5 support (default=/usr)])],
3635     [ case "$withval" in
3636       no)
3637         AC_MSG_RESULT(no krb5-path given)
3638         ;;
3639       yes)
3640         AC_MSG_RESULT(/usr)
3641         FOUND_KRB5=yes
3642         ;;
3643       *)
3644         AC_MSG_RESULT($withval)
3645         KRB5_CFLAGS="-I$withval/include"
3646         KRB5_CPPFLAGS="-I$withval/include"
3647         KRB5_LDFLAGS="-L$withval/lib"
3648         FOUND_KRB5=yes
3649         if test -x "$withval/bin/krb5-config"; then
3650                 KRB5CONFIG=$withval/bin/krb5-config
3651         fi
3652         ;;
3653       esac ],
3654       AC_MSG_RESULT(no krb5-path given)
3655     )
3656   fi
3657
3658   #################################################
3659   # check for krb5-config from recent MIT and Heimdal kerberos 5
3660   AC_PATH_PROG(KRB5CONFIG, krb5-config)
3661   AC_MSG_CHECKING(for working krb5-config)
3662   if test -x "$KRB5CONFIG" && $KRB5CONFIG --libs gssapi > /dev/null ; then
3663     ac_save_CFLAGS=$CFLAGS
3664     CFLAGS="";export CFLAGS
3665     ac_save_LDFLAGS=$LDFLAGS
3666     LDFLAGS="";export LDFLAGS
3667     KRB5_LIBS="`$KRB5CONFIG --libs gssapi`"
3668     KRB5_LDFLAGS="`$KRB5CONFIG --libs gssapi | sed s/-lgss.*//`"
3669     KRB5_CFLAGS="`$KRB5CONFIG --cflags | sed s/@INCLUDE_des@//`"
3670     KRB5_CPPFLAGS="`$KRB5CONFIG --cflags | sed s/@INCLUDE_des@//`"
3671     CFLAGS=$ac_save_CFLAGS;export CFLAGS
3672     LDFLAGS=$ac_save_LDFLAGS;export LDFLAGS
3673     FOUND_KRB5=yes
3674     AC_MSG_RESULT(yes)
3675   else
3676     AC_MSG_RESULT(no. Fallback to previous krb5 detection strategy)
3677   fi
3678
3679   if test x$FOUND_KRB5 = x"no"; then
3680     #################################################
3681     # see if this box has the SuSE location for the heimdal krb implementation
3682     AC_MSG_CHECKING(for /usr/include/heimdal)
3683     if test -d /usr/include/heimdal; then
3684       if test -f /usr/lib/heimdal/lib/libkrb5.a; then
3685           KRB5_CFLAGS="-I/usr/include/heimdal"
3686           KRB5_CPPFLAGS="-I/usr/include/heimdal"
3687           KRB5_LDFLAGS="-L/usr/lib/heimdal/lib"
3688           FOUND_KRB5=yes
3689           AC_MSG_RESULT(yes)
3690       else
3691           KRB5_CFLAGS="-I/usr/include/heimdal"
3692           KRB5_CPPFLAGS="-I/usr/include/heimdal"
3693           FOUND_KRB5=yes
3694           AC_MSG_RESULT(yes)
3695       fi
3696     else
3697       AC_MSG_RESULT(no)
3698     fi
3699   fi
3700
3701   if test x$FOUND_KRB5 = x"no"; then
3702     #################################################
3703     # see if this box has the RedHat location for kerberos
3704     AC_MSG_CHECKING(for /usr/kerberos)
3705     if test -d /usr/kerberos -a -f /usr/kerberos/lib/libkrb5.a; then
3706       KRB5_LDFLAGS="-L/usr/kerberos/lib"
3707       KRB5_CFLAGS="-I/usr/kerberos/include"
3708       KRB5_CPPFLAGS="-I/usr/kerberos/include"
3709       FOUND_KRB5=yes
3710       AC_MSG_RESULT(yes)
3711     else
3712       AC_MSG_RESULT(no)
3713     fi
3714   fi
3715
3716   if test x$FOUND_KRB5 = x"no"; then
3717     #################################################
3718     # see if this box has the OpenBSD location for heimdal krb5
3719     AC_MSG_CHECKING(for /usr/include/kerberosV)
3720     if test -d /usr/include/kerberosV; then
3721       KRB5_CPPFLAGS="-I/usr/include/kerberosV"
3722       KRB5_LIBS="-lcrypto"
3723       FOUND_KRB5=yes
3724       AC_MSG_RESULT(yes)
3725     else
3726       AC_MSG_RESULT(no)
3727     fi
3728   fi
3729
3730   ac_save_CFLAGS=$CFLAGS
3731   ac_save_CPPFLAGS=$CPPFLAGS
3732   ac_save_LDFLAGS=$LDFLAGS
3733
3734   # remove needless evil rpath stuff as early as possible:
3735   LIB_REMOVE_USR_LIB(KRB5_LIBS)
3736   LIB_REMOVE_USR_LIB(KRB5_LDFLAGS)
3737   CFLAGS="$KRB5_CFLAGS $CFLAGS"
3738   CPPFLAGS="$KRB5_CPPFLAGS $CPPFLAGS"
3739   LDFLAGS="$KRB5_LDFLAGS $LDFLAGS"
3740
3741   KRB5_LIBS="$KRB5_LDFLAGS $KRB5_LIBS"
3742
3743   # now check for krb5.h. Some systems have the libraries without the headers!
3744   # note that this check is done here to allow for different kerberos
3745   # include paths
3746   AC_CHECK_HEADERS(krb5.h)
3747
3748   if test x"$ac_cv_header_krb5_h" = x"no"; then
3749
3750     # Give a warning if AD support was not explicitly requested,
3751     # i.e with_ads_support = auto, otherwise die with an error.
3752
3753     if test x"$with_ads_support" = x"yes"; then
3754       AC_MSG_ERROR([Active Directory cannot be supported without krb5.h])
3755     else
3756       AC_MSG_WARN([Active Directory cannot be supported without krb5.h])
3757     fi
3758
3759     # Turn off AD support and restore CFLAGS and LIBS variables
3760
3761     with_ads_support="no"
3762
3763     CFLAGS=$ac_save_CFLAGS
3764     CPPFLAGS=$ac_save_CPPFLAGS
3765     LDFLAGS=$ac_save_LDFLAGS
3766   fi
3767
3768   # check for new heimdal KRB5_DEPRECATED handling
3769
3770   AC_CACHE_CHECK([for KRB5_DEPRECATED define taking an identifier],
3771                 samba_cv_HAVE_KRB5_DEPRECATED_WITH_IDENTIFIER,[
3772     AC_TRY_COMPILE(
3773       [#define KRB5_DEPRECATED 1
3774       #include <krb5.h>],
3775       [],
3776       samba_cv_HAVE_KRB5_DEPRECATED_WITH_IDENTIFIER=yes,
3777       samba_cv_HAVE_KRB5_DEPRECATED_WITH_IDENTIFIER=no)])
3778
3779   if test x"$samba_cv_HAVE_KRB5_DEPRECATED_WITH_IDENTIFIER" = x"yes"; then
3780     AC_DEFINE(HAVE_KRB5_DEPRECATED_WITH_IDENTIFIER, 1,
3781                [Whether to use deprecated krb5 interfaces])
3782   fi
3783 fi
3784
3785 # Now we have determined whether we really want ADS support
3786 use_ads=no
3787 if test x"$with_ads_support" != x"no"; then
3788   use_ads=yes
3789   have_gssapi=no
3790   ac_save_LIBS=$LIBS
3791
3792   # now check for gssapi headers.  This is also done here to allow for
3793   # different kerberos include paths
3794   AC_CHECK_HEADERS(gssapi.h gssapi/gssapi_generic.h gssapi/gssapi.h gssapi/gssapi_ext.h com_err.h)
3795
3796   ##################################################################
3797   # we might need the k5crypto and com_err libraries on some systems
3798   AC_CHECK_LIB_EXT(com_err, KRB5_LIBS, _et_list)
3799   AC_CHECK_LIB_EXT(k5crypto, KRB5_LIBS, krb5_encrypt_data)
3800
3801   # Heimdal checks.
3802   AC_CHECK_LIB_EXT(crypto, KRB5_LIBS, des_set_key)
3803   AC_CHECK_LIB_EXT(asn1, KRB5_LIBS, copy_Authenticator)
3804   AC_CHECK_LIB_EXT(roken, KRB5_LIBS, roken_getaddrinfo_hostspec)
3805
3806   # Heimdal checks. On static Heimdal gssapi must be linked before krb5.
3807   AC_CHECK_LIB_EXT(gssapi, KRB5_LIBS, gss_display_status,[],[],have_gssapi=yes)
3808
3809   ########################################################
3810   # now see if we can find the krb5 libs in standard paths
3811   # or as specified above
3812   AC_CHECK_LIB_EXT(krb5, KRB5_LIBS, krb5_mk_req_extended)
3813   AC_CHECK_LIB_EXT(krb5, KRB5_LIBS, krb5_kt_compare)
3814
3815   ########################################################
3816   # now see if we can find the gssapi libs in standard paths
3817   if test x"$have_gssapi" != x"yes"; then
3818      AC_CHECK_LIB_EXT(gssapi_krb5, KRB5_LIBS,gss_display_status,[],[],have_gssapi=yes)
3819      AC_CHECK_FUNC_EXT(gss_wrap_iov, $KRB5_LIBS)
3820   fi
3821
3822   AC_CHECK_FUNC_EXT(krb5_set_real_time, $KRB5_LIBS)
3823   AC_CHECK_FUNC_EXT(krb5_set_default_in_tkt_etypes, $KRB5_LIBS)
3824   AC_CHECK_FUNC_EXT(krb5_set_default_tgs_enctypes, $KRB5_LIBS)
3825   AC_CHECK_FUNC_EXT(krb5_set_default_tgs_ktypes, $KRB5_LIBS)
3826   AC_CHECK_FUNC_EXT(krb5_principal2salt, $KRB5_LIBS)
3827   AC_CHECK_FUNC_EXT(krb5_use_enctype, $KRB5_LIBS)
3828   AC_CHECK_FUNC_EXT(krb5_string_to_key, $KRB5_LIBS)
3829   AC_CHECK_FUNC_EXT(krb5_get_pw_salt, $KRB5_LIBS)
3830   AC_CHECK_FUNC_EXT(krb5_string_to_key_salt, $KRB5_LIBS)
3831   AC_CHECK_FUNC_EXT(krb5_auth_con_setkey, $KRB5_LIBS)
3832   AC_CHECK_FUNC_EXT(krb5_auth_con_setuseruserkey, $KRB5_LIBS)
3833   AC_CHECK_FUNC_EXT(krb5_locate_kdc, $KRB5_LIBS)
3834   AC_CHECK_FUNC_EXT(krb5_get_permitted_enctypes, $KRB5_LIBS)
3835   AC_CHECK_FUNC_EXT(krb5_get_default_in_tkt_etypes, $KRB5_LIBS)
3836   AC_CHECK_FUNC_EXT(krb5_free_data_contents, $KRB5_LIBS)
3837   AC_CHECK_FUNC_EXT(krb5_principal_get_comp_string, $KRB5_LIBS)
3838   AC_CHECK_FUNC_EXT(krb5_free_unparsed_name, $KRB5_LIBS)
3839   AC_CHECK_FUNC_EXT(krb5_free_keytab_entry_contents, $KRB5_LIBS)
3840   AC_CHECK_FUNC_EXT(krb5_kt_free_entry, $KRB5_LIBS)
3841   AC_CHECK_FUNC_EXT(krb5_krbhst_init, $KRB5_LIBS)
3842   AC_CHECK_FUNC_EXT(krb5_krbhst_get_addrinfo, $KRB5_LIBS)
3843   AC_CHECK_FUNC_EXT(krb5_c_enctype_compare, $KRB5_LIBS)
3844   AC_CHECK_FUNC_EXT(krb5_enctypes_compatible_keys, $KRB5_LIBS)
3845   AC_CHECK_FUNC_EXT(krb5_crypto_init, $KRB5_LIBS)
3846   AC_CHECK_FUNC_EXT(krb5_crypto_destroy, $KRB5_LIBS)
3847   AC_CHECK_FUNC_EXT(krb5_decode_ap_req, $KRB5_LIBS)
3848   AC_CHECK_FUNC_EXT(free_AP_REQ, $KRB5_LIBS)
3849   AC_CHECK_FUNC_EXT(krb5_verify_checksum, $KRB5_LIBS)
3850   AC_CHECK_FUNC_EXT(krb5_c_verify_checksum, $KRB5_LIBS)
3851   AC_CHECK_FUNC_EXT(krb5_principal_compare_any_realm, $KRB5_LIBS)
3852   AC_CHECK_FUNC_EXT(krb5_parse_name_norealm, $KRB5_LIBS)
3853   AC_CHECK_FUNC_EXT(krb5_princ_size, $KRB5_LIBS)
3854   AC_CHECK_FUNC_EXT(krb5_get_init_creds_opt_set_pac_request, $KRB5_LIBS)
3855   AC_CHECK_FUNC_EXT(krb5_get_renewed_creds, $KRB5_LIBS)
3856   AC_CHECK_FUNC_EXT(krb5_get_kdc_cred, $KRB5_LIBS)
3857   AC_CHECK_FUNC_EXT(krb5_free_error_contents, $KRB5_LIBS)
3858   AC_CHECK_FUNC_EXT(initialize_krb5_error_table, $KRB5_LIBS)
3859   AC_CHECK_FUNC_EXT(krb5_get_init_creds_opt_alloc, $KRB5_LIBS)
3860   AC_CHECK_FUNC_EXT(krb5_get_init_creds_opt_free, $KRB5_LIBS)
3861   AC_CHECK_FUNC_EXT(krb5_get_init_creds_opt_get_error, $KRB5_LIBS)
3862   AC_CHECK_FUNC_EXT(krb5_enctype_to_string, $KRB5_LIBS)
3863   AC_CHECK_FUNC_EXT(krb5_fwd_tgt_creds, $KRB5_LIBS)
3864   AC_CHECK_FUNC_EXT(krb5_auth_con_set_req_cksumtype, $KRB5_LIBS)
3865   AC_CHECK_FUNC_EXT(krb5_get_creds_opt_alloc, $KRB5_LIBS)
3866   AC_CHECK_FUNC_EXT(krb5_get_creds_opt_set_impersonate, $KRB5_LIBS)
3867   AC_CHECK_FUNC_EXT(krb5_get_creds, $KRB5_LIBS)
3868   AC_CHECK_FUNC_EXT(krb5_get_credentials_for_user, $KRB5_LIBS)
3869   AC_CHECK_FUNC_EXT(krb5_get_host_realm, $KRB5_LIBS)
3870   AC_CHECK_FUNC_EXT(krb5_free_host_realm, $KRB5_LIBS)
3871   AC_CHECK_FUNC_EXT(gss_krb5_import_cred, $KRB5_LIBS)
3872
3873   # MIT krb5 1.8 does not expose this call (yet)
3874   AC_CHECK_DECLS(krb5_get_credentials_for_user, [], [], [#include <krb5.h>])
3875
3876   # MIT krb5 1.7beta3 (in Ubuntu Karmic) does not have this declaration
3877   # but does have the symbol
3878   AC_CHECK_DECLS(krb5_auth_con_set_req_cksumtype, [], [], [#include <krb5.h>])
3879
3880   LIBS="$KRB5_LIBS $LIBS"
3881
3882   AC_CACHE_CHECK(whether krb5_ticket contains kvno and enctype,
3883         smb_krb5_cv_ticket_has_keyinfo,
3884         [
3885             AC_TRY_COMPILE(
3886             [
3887                 #include <krb5.h>
3888             ],
3889             [
3890                 krb5_ticket ticket;
3891                 krb5_kvno kvno;
3892                 krb5_enctype enctype;
3893
3894                 enctype = ticket.enc_part.enctype;
3895                 kvno = ticket.enc_part.kvno;
3896             ],
3897             [ smb_krb5_cv_ticket_has_keyinfo=yes ],
3898             [ smb_krb5_cv_ticket_has_keyinfo=no ])
3899         ])
3900
3901   if test x"$smb_krb5_cv_ticket_has_keyinfo" = x"yes" ; then
3902         AC_DEFINE(KRB5_TICKET_HAS_KEYINFO, 1,
3903             [Whether the krb5_ticket structure contains the kvno and enctype])
3904   fi
3905
3906   AC_CACHE_CHECK(whether krb5_get_init_creds_opt_free takes a context argument,
3907           smb_krb5_cv_creds_opt_free_context,
3908           [
3909                 AC_TRY_COMPILE([
3910                     #include <krb5.h>],
3911                     [
3912                         krb5_context ctx;
3913                         krb5_get_init_creds_opt *opt = NULL;
3914                         krb5_get_init_creds_opt_free(ctx, opt);
3915                     ],
3916                     [smb_krb5_cv_creds_opt_free_context=yes],
3917                     [smb_krb5_cv_creds_opt_free_context=no]
3918                 )
3919           ])
3920
3921   if test x"$smb_krb5_cv_creds_opt_free_context" = x"yes" ; then
3922         AC_DEFINE(KRB5_CREDS_OPT_FREE_REQUIRES_CONTEXT, 1,
3923             [Whether krb5_get_init_creds_opt_free takes a context argument])
3924   fi
3925
3926   AC_CACHE_CHECK(whether krb5_verify_checksum takes 7 arguments, smb_krb5_cv_verify_checksum, [
3927     AC_TRY_COMPILE([
3928         #include <krb5.h>],
3929         [krb5_verify_checksum(0, 0, 0, 0, 0, 0, 0);],
3930         [smb_krb5_cv_verify_checksum=7],
3931         [smb_krb5_cv_verify_checksum=6],
3932     )
3933   ])
3934   AC_DEFINE_UNQUOTED(KRB5_VERIFY_CHECKSUM_ARGS, $smb_krb5_cv_verify_checksum, [Number of arguments to krb5_verify_checksum])
3935
3936   AC_CACHE_CHECK([for checksum in krb5_checksum],
3937                 samba_cv_HAVE_CHECKSUM_IN_KRB5_CHECKSUM,[
3938     AC_TRY_COMPILE([#include <krb5.h>],
3939       [krb5_checksum cksum; cksum.checksum.length = 0;],
3940       samba_cv_HAVE_CHECKSUM_IN_KRB5_CHECKSUM=yes,
3941       samba_cv_HAVE_CHECKSUM_IN_KRB5_CHECKSUM=no)])
3942
3943   if test x"$samba_cv_HAVE_CHECKSUM_IN_KRB5_CHECKSUM" = x"yes"; then
3944     AC_DEFINE(HAVE_CHECKSUM_IN_KRB5_CHECKSUM,1,
3945                [Whether the krb5_checksum struct has a checksum property])
3946   fi
3947
3948   AC_CACHE_CHECK([for etype in EncryptedData],
3949                 samba_cv_HAVE_ETYPE_IN_ENCRYPTEDDATA,[
3950     AC_TRY_COMPILE([#include <krb5.h>],
3951       [EncryptedData edata; edata.etype = 0;],
3952       samba_cv_HAVE_ETYPE_IN_ENCRYPTEDDATA=yes,
3953       samba_cv_HAVE_ETYPE_IN_ENCRYPTEDDATA=no)])
3954
3955   if test x"$samba_cv_HAVE_ETYPE_IN_ENCRYPTEDDATA" = x"yes"; then
3956     AC_DEFINE(HAVE_ETYPE_IN_ENCRYPTEDDATA,1,
3957                [Whether the EncryptedData struct has a etype property])
3958   fi
3959
3960   AC_CACHE_CHECK([for ticket pointer in krb5_ap_req],
3961                 samba_cv_HAVE_TICKET_POINTER_IN_KRB5_AP_REQ,[
3962     AC_TRY_COMPILE([#include <krb5.h>],
3963       [krb5_ap_req *ap_req; ap_req->ticket = NULL;],
3964       samba_cv_HAVE_TICKET_POINTER_IN_KRB5_AP_REQ=yes,
3965       samba_cv_HAVE_TICKET_POINTER_IN_KRB5_AP_REQ=no)])
3966
3967   if test x"$samba_cv_HAVE_TICKET_POINTER_IN_KRB5_AP_REQ" = x"yes"; then
3968     AC_DEFINE(HAVE_TICKET_POINTER_IN_KRB5_AP_REQ,1,
3969                [Whether the krb5_ap_req struct has a ticket pointer])
3970   fi
3971
3972   AC_CACHE_CHECK([for e_data pointer in krb5_error],
3973                 samba_cv_HAVE_E_DATA_POINTER_IN_KRB5_ERROR,[
3974     AC_TRY_COMPILE([#include <krb5.h>],
3975       [krb5_error err; err.e_data = NULL;],
3976       samba_cv_HAVE_E_DATA_POINTER_IN_KRB5_ERROR=yes,
3977       samba_cv_HAVE_E_DATA_POINTER_IN_KRB5_ERROR=no)])
3978
3979   if test x"$samba_cv_HAVE_E_DATA_POINTER_IN_KRB5_ERROR" = x"yes"; then
3980     AC_DEFINE(HAVE_E_DATA_POINTER_IN_KRB5_ERROR,1,
3981                [Whether the krb5_error struct has a e_data pointer])
3982   fi
3983
3984   AC_CACHE_CHECK([for krb5_crypto type],
3985                 samba_cv_HAVE_KRB5_CRYPTO,[
3986     AC_TRY_COMPILE([#include <krb5.h>],
3987       [krb5_crypto crypto;],
3988       samba_cv_HAVE_KRB5_CRYPTO=yes,
3989       samba_cv_HAVE_KRB5_CRYPTO=no)])
3990
3991   if test x"$samba_cv_HAVE_KRB5_CRYPTO" = x"yes"; then
3992     AC_DEFINE(HAVE_KRB5_CRYPTO,1,
3993                [Whether the type krb5_crypto exists])
3994   fi
3995
3996   AC_CACHE_CHECK([for krb5_encrypt_block type],
3997                 samba_cv_HAVE_KRB5_ENCRYPT_BLOCK,[
3998     AC_TRY_COMPILE([#include <krb5.h>],
3999       [krb5_encrypt_block block;],
4000       samba_cv_HAVE_KRB5_ENCRYPT_BLOCK=yes,
4001       samba_cv_HAVE_KRB5_ENCRYPT_BLOCK=no)])
4002
4003   if test x"$samba_cv_HAVE_KRB5_ENCRYPT_BLOCK" = x"yes"; then
4004     AC_DEFINE(HAVE_KRB5_ENCRYPT_BLOCK,1,
4005                [Whether the type krb5_encrypt_block exists])
4006   fi
4007
4008   AC_CACHE_CHECK([for addrtype in krb5_address],
4009                 samba_cv_HAVE_ADDRTYPE_IN_KRB5_ADDRESS,[
4010     AC_TRY_COMPILE([#include <krb5.h>],
4011       [krb5_address kaddr; kaddr.addrtype = ADDRTYPE_INET;],
4012       samba_cv_HAVE_ADDRTYPE_IN_KRB5_ADDRESS=yes,
4013       samba_cv_HAVE_ADDRTYPE_IN_KRB5_ADDRESS=no)])
4014
4015   if test x"$samba_cv_HAVE_ADDRTYPE_IN_KRB5_ADDRESS" = x"yes"; then
4016     AC_DEFINE(HAVE_ADDRTYPE_IN_KRB5_ADDRESS,1,
4017                [Whether the krb5_address struct has a addrtype property])
4018   fi
4019
4020   AC_CACHE_CHECK([for addr_type in krb5_address],
4021                  samba_cv_HAVE_ADDR_TYPE_IN_KRB5_ADDRESS,[
4022     AC_TRY_COMPILE([#include <krb5.h>],
4023       [krb5_address kaddr; kaddr.addr_type = KRB5_ADDRESS_INET;],
4024       samba_cv_HAVE_ADDR_TYPE_IN_KRB5_ADDRESS=yes,
4025       samba_cv_HAVE_ADDR_TYPE_IN_KRB5_ADDRESS=no)])
4026
4027   if test x"$samba_cv_HAVE_ADDR_TYPE_IN_KRB5_ADDRESS" = x"yes"; then
4028     AC_DEFINE(HAVE_ADDR_TYPE_IN_KRB5_ADDRESS,1,
4029               [Whether the krb5_address struct has a addr_type property])
4030   fi
4031
4032   AC_CACHE_CHECK([for enc_part2 in krb5_ticket],
4033                  samba_cv_HAVE_KRB5_TKT_ENC_PART2,
4034                  [AC_TRY_COMPILE([#include <krb5.h>],
4035     [krb5_ticket tkt; tkt.enc_part2->authorization_data[0]->contents = NULL;],
4036     samba_cv_HAVE_KRB5_TKT_ENC_PART2=yes,samba_cv_HAVE_KRB5_TKT_ENC_PART2=no)])
4037
4038   if test x"$samba_cv_HAVE_KRB5_TKT_ENC_PART2" = x"yes"; then
4039     AC_DEFINE(HAVE_KRB5_TKT_ENC_PART2,1,
4040               [Whether the krb5_ticket struct has a enc_part2 property])
4041   fi
4042
4043   AC_CACHE_CHECK([for keyblock in krb5_creds],
4044                  samba_cv_HAVE_KRB5_KEYBLOCK_IN_CREDS,[
4045     AC_TRY_COMPILE([#include <krb5.h>],
4046       [krb5_creds creds; krb5_keyblock kb; creds.keyblock = kb;],
4047       samba_cv_HAVE_KRB5_KEYBLOCK_IN_CREDS=yes,
4048       samba_cv_HAVE_KRB5_KEYBLOCK_IN_CREDS=no)])
4049
4050   if test x"$samba_cv_HAVE_KRB5_KEYBLOCK_IN_CREDS" = x"yes"; then
4051     AC_DEFINE(HAVE_KRB5_KEYBLOCK_IN_CREDS,1,
4052               [Whether the krb5_creds struct has a keyblock property])
4053   fi
4054
4055   AC_CACHE_CHECK([for session in krb5_creds],
4056                  samba_cv_HAVE_KRB5_SESSION_IN_CREDS,[
4057     AC_TRY_COMPILE([#include <krb5.h>],
4058       [krb5_creds creds; krb5_keyblock kb; creds.session = kb;],
4059       samba_cv_HAVE_KRB5_SESSION_IN_CREDS=yes,
4060       samba_cv_HAVE_KRB5_SESSION_IN_CREDS=no)])
4061
4062   if test x"$samba_cv_HAVE_KRB5_SESSION_IN_CREDS" = x"yes"; then
4063     AC_DEFINE(HAVE_KRB5_SESSION_IN_CREDS,1,
4064               [Whether the krb5_creds struct has a session property])
4065   fi
4066
4067   AC_CACHE_CHECK([for keyvalue in krb5_keyblock],
4068                  samba_cv_HAVE_KRB5_KEYBLOCK_KEYVALUE,[
4069     AC_TRY_COMPILE([#include <krb5.h>],
4070       [krb5_keyblock key; key.keyvalue.data = NULL;],
4071       samba_cv_HAVE_KRB5_KEYBLOCK_KEYVALUE=yes,
4072       samba_cv_HAVE_KRB5_KEYBLOCK_KEYVALUE=no)])
4073
4074   if test x"$samba_cv_HAVE_KRB5_KEYBLOCK_KEYVALUE" = x"yes"; then
4075     AC_DEFINE(HAVE_KRB5_KEYBLOCK_KEYVALUE,1,
4076               [Whether the krb5_keyblock struct has a keyvalue property])
4077   fi
4078
4079   found_arcfour_hmac=no
4080   AC_CACHE_CHECK([for ENCTYPE_ARCFOUR_HMAC_MD5],
4081                  samba_cv_HAVE_ENCTYPE_ARCFOUR_HMAC_MD5,[
4082     AC_TRY_COMPILE([#include <krb5.h>],
4083       [krb5_enctype enctype; enctype = ENCTYPE_ARCFOUR_HMAC_MD5;],
4084       samba_cv_HAVE_ENCTYPE_ARCFOUR_HMAC_MD5=yes,
4085       samba_cv_HAVE_ENCTYPE_ARCFOUR_HMAC_MD5=no)])
4086   AC_CACHE_CHECK([for KEYTYPE_ARCFOUR_56],
4087                  samba_cv_HAVE_KEYTYPE_ARCFOUR_56,[
4088     AC_TRY_COMPILE([#include <krb5.h>],
4089       [krb5_keytype keytype; keytype = KEYTYPE_ARCFOUR_56;],
4090       samba_cv_HAVE_KEYTYPE_ARCFOUR_56=yes,
4091       samba_cv_HAVE_KEYTYPE_ARCFOUR_56=no)])
4092 # Heimdals with KEYTYPE_ARCFOUR but not KEYTYPE_ARCFOUR_56 are broken
4093 # w.r.t. arcfour and windows, so we must not enable it here
4094   if test x"$samba_cv_HAVE_ENCTYPE_ARCFOUR_HMAC_MD5" = x"yes" -a\
4095           x"$samba_cv_HAVE_KEYTYPE_ARCFOUR_56" = x"yes"; then
4096     AC_DEFINE(HAVE_ENCTYPE_ARCFOUR_HMAC_MD5,1,
4097               [Whether the ENCTYPE_ARCFOUR_HMAC_MD5 key type definition is available])
4098     found_arcfour_hmac=yes
4099   fi
4100   AC_CACHE_CHECK([for ENCTYPE_ARCFOUR_HMAC],
4101                  samba_cv_HAVE_ENCTYPE_ARCFOUR_HMAC,[
4102     AC_TRY_COMPILE([#include <krb5.h>],
4103       [krb5_enctype enctype; enctype = ENCTYPE_ARCFOUR_HMAC;],
4104       samba_cv_HAVE_ENCTYPE_ARCFOUR_HMAC=yes,
4105       samba_cv_HAVE_ENCTYPE_ARCFOUR_HMAC=no)])
4106   if test x"$samba_cv_HAVE_ENCTYPE_ARCFOUR_HMAC" = x"yes"; then
4107     AC_DEFINE(HAVE_ENCTYPE_ARCFOUR_HMAC,1,
4108               [Whether the ENCTYPE_ARCFOUR_HMAC key type definition is available])
4109     found_arcfour_hmac=yes
4110   fi
4111
4112   AC_CACHE_CHECK([for AP_OPTS_USE_SUBKEY],
4113                  samba_cv_HAVE_AP_OPTS_USE_SUBKEY,[
4114     AC_TRY_COMPILE([#include <krb5.h>],
4115       [krb5_flags ap_options; ap_options = AP_OPTS_USE_SUBKEY;],
4116       samba_cv_HAVE_AP_OPTS_USE_SUBKEY=yes,
4117       samba_cv_HAVE_AP_OPTS_USE_SUBKEY=no)])
4118
4119   if test x"$samba_cv_HAVE_AP_OPTS_USE_SUBKEY" = x"yes"; then
4120     AC_DEFINE(HAVE_AP_OPTS_USE_SUBKEY,1,
4121               [Whether the AP_OPTS_USE_SUBKEY ap option is available])
4122   fi
4123
4124   AC_CACHE_CHECK([for KV5M_KEYTAB],
4125                  samba_cv_HAVE_KV5M_KEYTAB,[
4126     AC_TRY_COMPILE([#include <krb5.h>],
4127       [krb5_keytab_entry entry; entry.magic = KV5M_KEYTAB;],
4128       samba_cv_HAVE_KV5M_KEYTAB=yes,
4129       samba_cv_HAVE_KV5M_KEYTAB=no)])
4130
4131   if test x"$samba_cv_HAVE_KV5M_KEYTAB" = x"yes"; then
4132       AC_DEFINE(HAVE_KV5M_KEYTAB,1,
4133              [Whether the KV5M_KEYTAB option is available])
4134   fi
4135
4136   AC_CACHE_CHECK([for KRB5_KU_OTHER_CKSUM],
4137                  samba_cv_HAVE_KRB5_KU_OTHER_CKSUM,[
4138     AC_TRY_COMPILE([#include <krb5.h>],
4139       [krb5_keyusage usage = KRB5_KU_OTHER_CKSUM;],
4140       samba_cv_HAVE_KRB5_KU_OTHER_CKSUM=yes,
4141       samba_cv_HAVE_KRB5_KU_OTHER_CKSUM=no)])
4142
4143   if test x"$samba_cv_HAVE_KRB5_KU_OTHER_CKSUM" = x"yes"; then
4144     AC_DEFINE(HAVE_KRB5_KU_OTHER_CKSUM,1,
4145               [Whether KRB5_KU_OTHER_CKSUM is available])
4146   fi
4147
4148   AC_CACHE_CHECK([for KRB5_KEYUSAGE_APP_DATA_CKSUM],
4149                  samba_cv_HAVE_KRB5_KEYUSAGE_APP_DATA_CKSUM,[
4150     AC_TRY_COMPILE([#include <krb5.h>],
4151       [krb5_keyusage usage = KRB5_KEYUSAGE_APP_DATA_CKSUM;],
4152       samba_cv_HAVE_KRB5_KEYUSAGE_APP_DATA_CKSUM=yes,
4153       samba_cv_HAVE_KRB5_KEYUSAGE_APP_DATA_CKSUM=no)])
4154
4155   if test x"$samba_cv_HAVE_KRB5_KEYUSAGE_APP_DATA_CKSUM" = x"yes"; then
4156     AC_DEFINE(HAVE_KRB5_KEYUSAGE_APP_DATA_CKSUM,1,
4157               [Whether KRB5_KEYUSAGE_APP_DATA_CKSUM is available])
4158   fi
4159
4160   AC_CACHE_CHECK([for the krb5_princ_component macro],
4161                 samba_cv_HAVE_KRB5_PRINC_COMPONENT,[
4162     AC_TRY_LINK([#include <krb5.h>],
4163       [const krb5_data *pkdata; krb5_context context; krb5_principal principal; pkdata = krb5_princ_component(context, principal, 0);],
4164       samba_cv_HAVE_KRB5_PRINC_COMPONENT=yes,
4165       samba_cv_HAVE_KRB5_PRINC_COMPONENT=no)])
4166
4167   if test x"$samba_cv_HAVE_KRB5_PRINC_COMPONENT" = x"yes"; then
4168     AC_DEFINE(HAVE_KRB5_PRINC_COMPONENT,1,
4169                [Whether krb5_princ_component is available])
4170   fi
4171
4172   AC_CACHE_CHECK([for key in krb5_keytab_entry],
4173                  samba_cv_HAVE_KRB5_KEYTAB_ENTRY_KEY,[
4174     AC_TRY_COMPILE([#include <krb5.h>],
4175       [krb5_keytab_entry entry; krb5_keyblock e; entry.key = e;],
4176       samba_cv_HAVE_KRB5_KEYTAB_ENTRY_KEY=yes,
4177       samba_cv_HAVE_KRB5_KEYTAB_ENTRY_KEY=no)])
4178
4179   if test x"$samba_cv_HAVE_KRB5_KEYTAB_ENTRY_KEY" = x"yes"; then
4180     AC_DEFINE(HAVE_KRB5_KEYTAB_ENTRY_KEY,1,
4181               [Whether krb5_keytab_entry has key member])
4182   fi
4183
4184   AC_CACHE_CHECK([for keyblock in krb5_keytab_entry],
4185                  samba_cv_HAVE_KRB5_KEYTAB_ENTRY_KEYBLOCK,[
4186     AC_TRY_COMPILE([#include <krb5.h>],
4187       [krb5_keytab_entry entry; entry.keyblock.keytype = 0;],
4188       samba_cv_HAVE_KRB5_KEYTAB_ENTRY_KEYBLOCK=yes,
4189       samba_cv_HAVE_KRB5_KEYTAB_ENTRY_KEYBLOCK=no)])
4190
4191   if test x"$samba_cv_HAVE_KRB5_KEYTAB_ENTRY_KEYBLOCK" = x"yes"; then
4192     AC_DEFINE(HAVE_KRB5_KEYTAB_ENTRY_KEYBLOCK,1,
4193               [Whether krb5_keytab_entry has keyblock member])
4194   fi
4195
4196   AC_CACHE_CHECK([for magic in krb5_address],
4197                  samba_cv_HAVE_MAGIC_IN_KRB5_ADDRESS,[
4198     AC_TRY_COMPILE([#include <krb5.h>],
4199       [krb5_address addr; addr.magic = 0;],
4200       samba_cv_HAVE_MAGIC_IN_KRB5_ADDRESS=yes,
4201       samba_cv_HAVE_MAGIC_IN_KRB5_ADDRESS=no)])
4202
4203   if test x"$samba_cv_HAVE_MAGIC_IN_KRB5_ADDRESS" = x"yes"; then
4204     AC_DEFINE(HAVE_MAGIC_IN_KRB5_ADDRESS,1,
4205               [Whether the krb5_address struct has a magic property])
4206   fi
4207
4208   AC_CACHE_CHECK([for WRFILE: keytab support],
4209                 samba_cv_HAVE_WRFILE_KEYTAB,[
4210     AC_TRY_RUN([
4211 #include<krb5.h>
4212   main()
4213   {
4214     krb5_context context;
4215     krb5_keytab keytab;
4216
4217     krb5_init_context(&context);
4218     return krb5_kt_resolve(context, "WRFILE:api", &keytab);
4219   }],
4220   samba_cv_HAVE_WRFILE_KEYTAB=yes,
4221   samba_cv_HAVE_WRFILE_KEYTAB=no)])
4222
4223   if test x"$samba_cv_HAVE_WRFILE_KEYTAB" = x"yes"; then
4224       AC_DEFINE(HAVE_WRFILE_KEYTAB,1,
4225                [Whether the WRFILE:-keytab is supported])
4226   fi
4227
4228   AC_CACHE_CHECK([for krb5_realm type],
4229                 samba_cv_HAVE_KRB5_REALM_TYPE,[
4230     AC_TRY_COMPILE([#include <krb5.h>],
4231       [krb5_realm realm;],
4232       samba_cv_HAVE_KRB5_REALM_TYPE=yes,
4233       samba_cv_HAVE_KRB5_REALM_TYPE=no)])
4234
4235   if test x"$samba_cv_HAVE_KRB5_REALM_TYPE" = x"yes"; then
4236     AC_DEFINE(HAVE_KRB5_REALM_TYPE,1,
4237                [Whether the type krb5_realm exists])
4238   fi
4239
4240   AC_CACHE_CHECK([for krb5_princ_realm returns krb5_realm or krb5_data],
4241                samba_cv_KRB5_PRINC_REALM_RETURNS_REALM,[
4242     AC_TRY_COMPILE([#include <krb5.h>],
4243     [
4244     krb5_context context;
4245     krb5_principal principal;
4246     krb5_realm realm; realm = *krb5_princ_realm(context, principal);],
4247     samba_cv_KRB5_PRINC_REALM_RETURNS_REALM=yes,
4248     samba_cv_KRB5_PRINC_REALM_RETURNS_REALM=no)])
4249
4250   if test x"$samba_cv_KRB5_PRINC_REALM_RETURNS_REALM" = x"yes"; then
4251     AC_DEFINE(KRB5_PRINC_REALM_RETURNS_REALM,1,
4252               [Whether krb5_princ_realm returns krb5_realm or krb5_data])
4253   fi
4254
4255   AC_CACHE_CHECK([for krb5_addresses type],
4256                 samba_cv_HAVE_KRB5_ADDRESSES,[
4257     AC_TRY_COMPILE([#include <krb5.h>],
4258       [krb5_addresses addr;],
4259       samba_cv_HAVE_KRB5_ADDRESSES=yes,
4260       samba_cv_HAVE_KRB5_ADDRESSES=no)])
4261
4262   if test x"$samba_cv_HAVE_KRB5_ADDRESSES" = x"yes"; then
4263     AC_DEFINE(HAVE_KRB5_ADDRESSES,1,
4264                [Whether the type krb5_addresses type exists])
4265   fi
4266
4267   AC_CACHE_CHECK([whether krb5_mk_error takes 3 arguments MIT or 9 Heimdal],
4268                 samba_cv_HAVE_SHORT_KRB5_MK_ERROR_INTERFACE, [
4269     AC_TRY_COMPILE([#include <krb5.h>],
4270     [
4271     krb5_mk_error(0,0,0);],
4272     samba_cv_HAVE_SHORT_KRB5_MK_ERROR_INTERFACE=yes,
4273     samba_cv_HAVE_SHORT_KRB5_MK_ERROR_INTERFACE=no)])
4274
4275   if test x"$samba_cv_HAVE_SHORT_KRB5_MK_ERROR_INTERFACE" = x"yes"; then
4276     AC_DEFINE(HAVE_SHORT_KRB5_MK_ERROR_INTERFACE,1,
4277               [whether krb5_mk_error takes 3 arguments MIT or 9 Heimdal])
4278   fi
4279
4280   if test x"$ac_cv_func_ext_krb5_enctype_to_string" = x"yes"; then
4281     AC_CACHE_CHECK([for krb5_error_code krb5_enctype_to_string(krb5_context context, krb5_enctype enctype, char **str)],
4282         smb_krb5_cv_enctype_to_string_takes_krb5_context_arg,[
4283         AC_TRY_RUN_STRICT([
4284                 #include <stdlib.h>
4285                 #include <krb5.h>
4286                 int main(void) {
4287                         krb5_context context = NULL;
4288                         char *str = NULL;
4289                         krb5_enctype_to_string(context, 1, &str);
4290                         if (str) free (str); 
4291                         return 0;
4292                 }
4293                 ],[$CFLAGS $Werror_FLAGS],[$CPPFLAGS],[$LDFLAGS],
4294                 smb_krb5_cv_enctype_to_string_takes_krb5_context_arg=yes,
4295                 smb_krb5_cv_enctype_to_string_takes_krb5_context_arg=no)])
4296
4297     if test x"$smb_krb5_cv_enctype_to_string_takes_krb5_context_arg" = x"yes"; then
4298       AC_DEFINE(HAVE_KRB5_ENCTYPE_TO_STRING_WITH_KRB5_CONTEXT_ARG,1,
4299                 [whether krb5_enctype_to_string takes krb5_context argument])
4300     fi
4301
4302     AC_CACHE_CHECK([for krb5_error_code krb5_enctype_to_string(krb5_enctype enctype, char *str, size_t len)],
4303         smb_krb5_cv_enctype_to_string_takes_size_t_arg,[
4304         AC_TRY_RUN_STRICT([
4305                 #include <krb5.h>
4306                 int main(void) {
4307                         char buf[256];
4308                         krb5_enctype_to_string(1, buf, 256);
4309                         return 0;
4310                 }
4311                 ],[$CFLAGS $Werror_FLAGS],[$CPPFLAGS],[$LDFLAGS],
4312                 smb_krb5_cv_enctype_to_string_takes_size_t_arg=yes,
4313                 smb_krb5_cv_enctype_to_string_takes_size_t_arg=no)])
4314
4315     if test x"$smb_krb5_cv_enctype_to_string_takes_size_t_arg" = x"yes"; then
4316       AC_DEFINE(HAVE_KRB5_ENCTYPE_TO_STRING_WITH_SIZE_T_ARG,1,
4317                 [whether krb5_enctype_to_string takes size_t argument])
4318     fi
4319   fi
4320
4321   AC_CACHE_CHECK([for krb5_principal_get_realm],
4322                 samba_cv_HAVE_KRB5_PRINCIPAL_GET_REALM,[
4323     AC_TRY_LINK([#include <krb5.h>],
4324       [krb5_context ctx = NULL; krb5_principal princ = NULL; const char *str = krb5_principal_get_realm(ctx, princ);],
4325       samba_cv_HAVE_KRB5_PRINCIPAL_GET_REALM=yes,
4326       samba_cv_HAVE_KRB5_PRINCIPAL_GET_REALM=no)])
4327
4328   if test x"$samba_cv_HAVE_KRB5_PRINCIPAL_GET_REALM" = x"yes"; then
4329     AC_DEFINE(HAVE_KRB5_PRINCIPAL_GET_REALM,1,
4330                [Whether the function krb5_principal_get_realm is defined])
4331   fi
4332
4333   AC_CACHE_CHECK([for krb5_princ_realm],
4334                 samba_cv_HAVE_KRB5_PRINC_REALM,[
4335     AC_TRY_LINK([#include <krb5.h>],
4336       [krb5_context ctx = NULL; krb5_principal princ = NULL; const char *str = krb5_princ_realm(ctx, princ)->data;],
4337       samba_cv_HAVE_KRB5_PRINC_REALM=yes,
4338       samba_cv_HAVE_KRB5_PRINC_REALM=no)])
4339
4340   if test x"$samba_cv_HAVE_KRB5_PRINC_REALM" = x"yes"; then
4341     AC_DEFINE(HAVE_KRB5_PRINC_REALM,1,
4342                [Whether the macro krb5_princ_realm is defined])
4343   fi
4344
4345   #
4346   #
4347   # Now the decisions whether we can support krb5
4348   #
4349   # NOTE: all tests should be done before this block!
4350   #
4351   #
4352   if test x"$found_arcfour_hmac" != x"yes"; then
4353     AC_MSG_WARN(arcfour-hmac-md5 encryption type not found in -lkrb5)
4354     use_ads=no
4355   fi
4356
4357   if test x"$ac_cv_lib_ext_krb5_krb5_mk_req_extended" != x"yes"; then
4358     AC_MSG_WARN(krb5_mk_req_extended not found in -lkrb5)
4359     use_ads=no
4360   fi
4361
4362   if test x"$ac_cv_func_ext_krb5_principal2salt" != x"yes" -a \
4363           x"$ac_cv_func_ext_krb5_get_pw_salt" != x"yes"
4364   then
4365     AC_MSG_WARN(no CREATE_KEY_FUNCTIONS detected)
4366     use_ads=no
4367   fi
4368
4369   if test x"$ac_cv_func_ext_krb5_get_permitted_enctypes" != x"yes" -a \
4370           x"$ac_cv_func_ext_krb5_get_default_in_tkt_etypes" != x"yes"
4371   then
4372     AC_MSG_WARN(no GET_ENCTYPES_FUNCTIONS detected)
4373     use_ads=no
4374   fi
4375
4376   if test x"$ac_cv_func_ext_krb5_kt_free_entry" != x"yes" -a \
4377           x"$ac_cv_func_ext_krb5_free_keytab_entry_contents" != x"yes"
4378   then
4379     AC_MSG_WARN(no KT_FREE_FUNCTION detected)
4380     use_ads=no
4381   fi
4382
4383   if test x"$ac_cv_func_ext_krb5_c_verify_checksum" != x"yes" -a \
4384           x"$ac_cv_func_ext_krb5_verify_checksum" != x"yes"
4385   then
4386     AC_MSG_WARN(no KRB5_VERIFY_CHECKSUM_FUNCTION detected)
4387     use_ads=no
4388   fi
4389
4390   if test x"$smb_krb5_cv_ticket_has_keyinfo" != x"yes" ; then
4391
4392       # We only need the following functions if we can't get the enctype
4393       # and kvno out of the ticket directly (ie. on Heimdal).
4394
4395       if test x"$ac_cv_func_ext_free_AP_REQ" != x"yes"
4396       then
4397         AC_MSG_WARN(no KRB5_AP_REQ_FREE_FUNCTION detected)
4398         use_ads=no
4399       fi
4400
4401       if test x"$ac_cv_func_ext_krb5_decode_ap_req" != x"yes"
4402       then
4403         AC_MSG_WARN(no KRB5_AP_REQ_DECODING_FUNCTION detected)
4404         use_ads=no
4405       fi
4406
4407   fi
4408
4409   if test x"$use_ads" = x"yes"; then
4410     AC_DEFINE(WITH_ADS,1,[Whether to include Active Directory support])
4411     AC_DEFINE(HAVE_KRB5,1,[Whether to have KRB5 support])
4412     if test x"$have_gssapi" = x"yes"; then
4413       AC_DEFINE(HAVE_GSSAPI,1,[Whether GSSAPI is available])
4414     fi
4415   else
4416     if test x"$with_ads_support" = x"yes"; then
4417         AC_MSG_ERROR(krb5 libs don't have all features required for Active Directory support)
4418     else
4419         AC_MSG_WARN(krb5 libs don't have all features required for Active Directory support)
4420     fi
4421     AC_REMOVE_DEFINE(HAVE_KRB5_H)
4422     AC_REMOVE_DEFINE(HAVE_GSSAPI_H)
4423     AC_REMOVE_DEFINE(HAVE_GSSAPI_GSSAPI_GENERIC_H)
4424     AC_REMOVE_DEFINE(HAVE_GSSAPI_GSSAPI_H)
4425     KRB5_LIBS=""
4426     with_ads_support=no
4427   fi
4428   AC_MSG_CHECKING(whether Active Directory and krb5