r22919: Fix build on Tru64.
[sfrench/samba-autobuild/.git] / source / configure.in
index f21ee2faa87a3721c472806a5369d129ed008bd4..26fdba0dfb0dab7bf50a2ba607bed0f81889639b 100644 (file)
@@ -4,9 +4,13 @@ dnl We must use autotools 2.53 or above
 AC_PREREQ(2.53)
 AC_INIT(include/includes.h)
 AC_CONFIG_HEADER(include/config.h)
+AC_DEFINE(CONFIG_H_IS_FROM_SAMBA,1,[Marker for samba's config.h])
 
-AC_DISABLE_STATIC
-AC_ENABLE_SHARED
+case "$PATH" in
+    */usr/ucb*)
+       AC_MSG_WARN([\$PATH contains /usr/ucb - build errors may follow])
+       ;;
+esac 
 
 SMB_VERSION_STRING=`cat $srcdir/include/version.h | grep 'SAMBA_VERSION_OFFICIAL_STRING' | cut -d '"' -f2`
 echo "SAMBA VERSION: ${SMB_VERSION_STRING}"
@@ -16,6 +20,11 @@ if test -n "${SAMBA_VERSION_SVN_REVISION}";then
        echo "BUILD REVISION: ${SAMBA_VERSION_SVN_REVISION}"
 fi
 
+AC_LIBREPLACE_LOCATION_CHECKS
+
+AC_DISABLE_STATIC
+AC_ENABLE_SHARED
+
 #################################################
 # Directory handling stuff to support both the
 # legacy SAMBA directories and FHS compliant
@@ -33,7 +42,7 @@ pammodulesdir="\${LIBDIR}/security"
 configdir="\${LIBDIR}"
 swatdir="\${prefix}/swat"
 
-AC_ARG_WITH(fhs, 
+AC_ARG_WITH(fhs,
 [  --with-fhs              Use FHS-compliant paths (default=no)],
 [ case "$withval" in
   yes)
@@ -43,7 +52,7 @@ AC_ARG_WITH(fhs,
     logfilebase="\${VARDIR}/log/samba"
     privatedir="\${CONFIGDIR}/private"
     libdir="\${prefix}/lib/samba"
-    configdir="${sysconfdir}/samba"
+    configdir="\${sysconfdir}/samba"
     swatdir="\${DATADIR}/samba/swat"
     ;;
   esac])
@@ -227,6 +236,20 @@ do
 done
 ])
 
+SAMBA_CPPFLAGS="-Iinclude -I${srcdir-.}/include  -I. -I${srcdir-.}"
+SAMBA_CPPFLAGS="${SAMBA_CPPFLAGS} -I${srcdir-.}/lib/replace"
+SAMBA_CPPFLAGS="${SAMBA_CPPFLAGS} -I${srcdir-.}/lib/talloc"
+SAMBA_CPPFLAGS="${SAMBA_CPPFLAGS} -I${srcdir-.}/lib/tdb/include"
+SAMBA_CPPFLAGS="${SAMBA_CPPFLAGS} -I${srcdir-.}/libaddns"
+SAMBA_CPPFLAGS="${SAMBA_CPPFLAGS} -I${srcdir-.}/librpc"
+
+SAMBA_CONFIGURE_CPPFLAGS="${SAMBA_CPPFLAGS} -I${srcdir-.}/popt"
+
+## cleanup the $(srcdir) in the Makefile if we are outside of the tree
+if test "x${srcdir-.}" != "x."; then
+       SAMBA_CPPFLAGS=`echo ${SAMBA_CPPFLAGS} | sed -e "s;${srcdir};\$\(srcdir\);g"`
+fi
+
 AC_SUBST(configdir)
 AC_SUBST(lockdir)
 AC_SUBST(piddir)
@@ -239,15 +262,14 @@ AC_SUBST(rootsbindir)
 AC_SUBST(pammodulesdir)
 
 dnl Unique-to-Samba variables we'll be playing with.
+AC_SUBST(SAMBA_CPPFLAGS)
 AC_SUBST(SHELL)
 AC_SUBST(LDSHFLAGS)
+AC_SUBST(MODULE_EXPORTS)
 AC_SUBST(SONAMEFLAG)
-AC_SUBST(NSSSONAMEVERSIONSUFFIX)
 AC_SUBST(SHLD)
 AC_SUBST(HOST_OS)
-AC_SUBST(PICFLAGS)
-AC_SUBST(PICSUFFIX)
-AC_SUBST(libc_cv_fpie)
+AC_SUBST(PICFLAG)
 AC_SUBST(PIE_CFLAGS)
 AC_SUBST(PIE_LDFLAGS)
 AC_SUBST(SHLIBEXT)
@@ -259,11 +281,16 @@ AC_SUBST(INSTALL_LIBMSRPC)
 AC_SUBST(UNINSTALL_LIBMSRPC)
 AC_SUBST(LIBMSRPC_SHARED)
 AC_SUBST(LIBMSRPC)
+AC_SUBST(INSTALL_LIBADDNS)
+AC_SUBST(UNINSTALL_LIBADDNS)
+AC_SUBST(LIBADDNS_SHARED)
+AC_SUBST(LIBADDNS)
 AC_SUBST(INSTALL_LIBSMBCLIENT)
 AC_SUBST(UNINSTALL_LIBSMBCLIENT)
 AC_SUBST(LIBSMBCLIENT_SHARED)
 AC_SUBST(LIBSMBCLIENT)
 AC_SUBST(INSTALL_LIBSMBSHAREMODES)
+AC_SUBST(UNINSTALL_LIBSMBSHAREMODES)
 AC_SUBST(LIBSMBSHAREMODES_SHARED)
 AC_SUBST(LIBSMBSHAREMODES)
 AC_SUBST(PRINT_LIBS)
@@ -272,15 +299,14 @@ AC_SUBST(ACL_LIBS)
 AC_SUBST(PASSDB_LIBS)
 AC_SUBST(IDMAP_LIBS)
 AC_SUBST(KRB5_LIBS)
+AC_SUBST(UUID_LIBS)
 AC_SUBST(LDAP_LIBS)
-AC_SUBST(SHLIB_PROGS)
 AC_SUBST(PAM_MODULES)
 AC_SUBST(INSTALL_PAM_MODULES)
 AC_SUBST(UNINSTALL_PAM_MODULES)
-AC_SUBST(SMBWRAPPER)
-AC_SUBST(SMBWRAP_OBJS)
-AC_SUBST(SMBWRAP_INC)
+AC_SUBST(NSS_MODULES)
 AC_SUBST(EXTRA_BIN_PROGS)
+AC_SUBST(SMBMOUNT_PROGS)
 AC_SUBST(CIFSMOUNT_PROGS)
 AC_SUBST(INSTALL_CIFSMOUNT)
 AC_SUBST(UNINSTALL_CIFSMOUNT)
@@ -289,44 +315,28 @@ AC_SUBST(EXTRA_ALL_TARGETS)
 AC_SUBST(CONFIG_LIBS)
 AC_SUBST(NSCD_LIBS)
 
-# Set defaults
-PIE_CFLAGS=""
-PIE_LDFLAGS=""
-AC_ARG_ENABLE(pie, [  --enable-pie            Turn on pie support if available (default=yes)])
-
-if test "x$enable_pie" != xno
-then
-       AC_CACHE_CHECK(for -fPIE, libc_cv_fpie, [dnl
-               cat > conftest.c <<EOF
-int foo;
-main () { return 0;}
-EOF
-               if AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS -pie -fPIE -o conftest conftest.c 1>&AS_MESSAGE_LOG_FD])
-               then
-                       libc_cv_fpie=yes
-                       PIE_CFLAGS="-fPIE"
-                       PIE_LDFLAGS="-pie"
-               fi
-               rm -f conftest*])
-fi
-if test "x$PIE_CFLAGS" = x
-then
-       libc_cv_fpie=no
-fi
-
-AC_ARG_ENABLE(debug, 
+## check for --enable-debug first before checking CFLAGS before
+## so that we don't mix -O and -g
+AC_ARG_ENABLE(debug,
 [  --enable-debug          Turn on compiler debugging information (default=no)],
     [if eval "test x$enable_debug = xyes"; then
        CFLAGS="${CFLAGS} -g"
     fi])
 
-AC_SUBST(SOCKWRAP)
-AC_ARG_ENABLE(socket-wrapper, 
-[  --enable-socket-wrapper         Turn on socket wrapper library (default=no)],
-    [if eval "test x$enable_socket_wrapper = xyes"; then
-        AC_DEFINE(SOCKET_WRAPPER,1,[Use socket wrapper library])
-       SOCKWRAP="\$(SOCKET_WRAPPER_OBJ)"
-    fi])
+# compile with optimization and without debugging by default, but
+# allow people to set their own preference.
+# do this here since AC_CACHE_CHECK apparently sets the CFLAGS to "-g -O2"
+# if it has no value.  This prevent *very* large debug binaries from occurring
+# by default.
+if test "x$CFLAGS" = x; then
+  CFLAGS="-O"
+fi
+
+CFLAGS="${CFLAGS} -D_SAMBA_BUILD_=3"
+
+AC_LIBREPLACE_CC_CHECKS
+
+m4_include(lib/socket_wrapper/config.m4)
 
 #################################################
 # set prefix for 'make test'
@@ -344,6 +354,35 @@ AC_ARG_WITH(selftest-prefix,
   esac
 ])
 
+AC_ARG_ENABLE(launchd,
+[  --enable-launchd        Support running under launchd (default=auto)])
+
+if test x"$enable_launchd" != x"no" ; then
+    AC_CACHE_CHECK([whether to include launchd support],
+       samba_cv_launchd_support,
+       [
+           AC_TRY_COMPILE(
+           [
+#include <launch.h>
+           ],
+           [
+               launchd_msg(NULL);
+               launchd_data_get_fd(NULL);
+           ],
+           samba_cv_launchd_support=yes,
+           samba_cv_launchd_support=no)
+       ])
+
+    if test x"$samba_cv_launchd_support" = x"yes" ; then
+       AC_DEFINE(WITH_LAUNCHD_SUPPORT, 1,
+                   [Whether launchd support should be enabled])
+    else
+       if test x"$enable_launchd" = x"yes" ; then
+           AC_ERROR(launchd support is not available)
+       fi
+    fi
+fi
+
 #################################################
 # set path of samba4's smbtorture
 smbtorture4_path=""
@@ -357,27 +396,16 @@ AC_ARG_WITH(smbtorture4_path,
   * )
     smbtorture4_path="$withval"
     if test -z "$smbtorture4_path" -a ! -f $smbtorture4_path; then
-       AC_MSG_ERROR(['$smbtorture_path' does not  exist!]) 
+       AC_MSG_ERROR(['$smbtorture_path' does not  exist!])
     fi
   ;;
  esac
 ])
 
-# compile with optimization and without debugging by default, but
-# allow people to set their own preference.
-# do this here since AC_CACHE_CHECK apparently sets the CFLAGS to "-g -O2"
-# if it has no value.  This prevent *very* large debug binaries from occurring
-# by default.
-if test "x$CFLAGS" = x; then
-  CFLAGS="-O"
-fi
-
-CFLAGS="${CFLAGS} -D_SAMBA_BUILD_"
-
 AC_ARG_ENABLE(developer, [  --enable-developer      Turn on developer warnings and debugging (default=no)],
     [if eval "test x$enable_developer = xyes"; then
         developer=yes
-       CFLAGS="${CFLAGS} -gstabs -Wall -Wshadow -Wstrict-prototypes -Wpointer-arith -Wcast-align -Wwrite-strings -DDEBUG_PASSWORD -DDEVELOPER"
+       DEVELOPER_CFLAGS="-gstabs -Wall -Wshadow -Wstrict-prototypes -Wpointer-arith -Wcast-align -Wwrite-strings -DDEBUG_PASSWORD -DDEVELOPER"
        # Add -Wdeclaration-after-statement if compiler supports it
        AC_CACHE_CHECK(
           [that the C compiler understands -Wdeclaration-after-statement],
@@ -390,9 +418,27 @@ AC_ARG_ENABLE(developer, [  --enable-developer      Turn on developer warnings a
            samba_cv_HAVE_Wdeclaration_after_statement=yes,
            samba_cv_HAVE_Wdeclaration_after_statement=no,
            samba_cv_HAVE_Wdeclaration_after_statement=cross)
+
        ])
        if test x"$samba_cv_HAVE_Wdeclaration_after_statement" = x"yes"; then
-           CFLAGS="${CFLAGS} -Wdeclaration-after-statement"
+           DEVELOPER_CFLAGS="${DEVELOPER_CFLAGS} -Wdeclaration-after-statement"
+       fi
+       # here
+       #-Werror-implicit-function-declaration
+       AC_CACHE_CHECK(
+          [that the C compiler understands -Werror-implicit-function-declaration],
+          samba_cv_HAVE_Werror_implicit_function_declaration, [
+         AC_TRY_RUN_STRICT([
+           int main(void)
+           {
+               return 0;
+           }],[-Werror-implicit-function-declaration],[$CPPFLAGS],[$LDFLAGS],
+           samba_cv_HAVE_Werror_implicit_function_declaration=yes,
+           samba_cv_HAVE_Werror_implicit_function_declaration=no,
+           samba_cv_HAVE_Werror_implicit_function_declaration=cross)
+       ])
+       if test x"$samba_cv_HAVE_Werror_implicit_function_declaration" = x"yes"; then
+           DEVELOPER_CFLAGS="${DEVELOPER_CFLAGS} -Werror-implicit-function-declaration"
        fi
     fi])
 
@@ -407,24 +453,31 @@ AC_ARG_ENABLE(dmalloc, [  --enable-dmalloc        Enable heap debugging [default
 if test "x$enable_dmalloc" = xyes
 then
        AC_DEFINE(ENABLE_DMALLOC, 1, [Define to turn on dmalloc debugging])
-       AC_DEFINE(DMALLOC_FUNC_CHECK, 1, 
+       AC_DEFINE(DMALLOC_FUNC_CHECK, 1,
                   [Define to check invariants around some common functions])
        LIBS="$LIBS -ldmalloc"  
 fi
 
-dnl Checks for programs.
-
-##
-## for some reason this macro resets the CFLAGS
-## so save and restore
-##
-OLD_CFLAGS=${CFLAGS}
-AC_PROG_CC
-CFLAGS=${OLD_CFLAGS}
+#################################################
+# check for a shared memory profiling support
+AC_MSG_CHECKING(whether to use profiling)
+AC_ARG_WITH(profiling-data,
+[  --with-profiling-data   Include gathering source code profile information (default=no)],
+[ case "$withval" in
+  yes)
+    AC_MSG_RESULT(yes)
+    AC_DEFINE(WITH_PROFILE,1,[Whether to use profiling])
+    samba_cv_WITH_PROFILE=yes
+    ;;
+  *)
+    AC_MSG_RESULT(no)
+    samba_cv_WITH_PROFILE=no
+    ;;
+  esac ],
+  AC_MSG_RESULT(no)
+)
 
-OLD_CFLAGS=${CFLAGS}
-AC_PROG_CPP
-CFLAGS=${OLD_CFLAGS}
+dnl Checks for programs.
 
 AC_PROG_INSTALL
 AC_PROG_AWK
@@ -436,7 +489,7 @@ dnl Check if we use GNU ld
 LD=ld
 AC_PROG_LD_GNU
 
-dnl Certain versions of GNU ld the default is not to have the 
+dnl Certain versions of GNU ld the default is not to have the
 dnl --allow-shlib-undefined flag defined.  This causes a stackload of
 dnl warnings when building modules.
 if test "$ac_cv_prog_gnu_ld" = "yes"; then
@@ -468,9 +521,6 @@ if test "$ac_cv_prog_gnu_ld" = "yes"; then
         fi
 fi
 
-dnl needed before AC_TRY_COMPILE
-AC_ISC_POSIX
-
 dnl look for executable suffix
 AC_EXEEXT
 
@@ -493,7 +543,7 @@ AC_CACHE_CHECK([that the C compiler understands -Werror],samba_cv_HAVE_Werror, [
   samba_cv_HAVE_Werror=yes,samba_cv_HAVE_Werror=no,samba_cv_HAVE_Werror=cross)])
 if test x"$samba_cv_HAVE_Werror" = x"yes"; then
    Werror_FLAGS="-Werror"
-else 
+else
 dnl Check if the C compiler understands -w2
 AC_CACHE_CHECK([that the C compiler understands -w2],samba_cv_HAVE_w2, [
  AC_TRY_RUN_STRICT([
@@ -515,6 +565,70 @@ if test x"$samba_cv_volatile" = x"yes"; then
    AC_DEFINE(HAVE_VOLATILE, 1, [Whether the C compiler understands volatile])
 fi
 
+############################################
+# check if the compiler can handle negative enum values
+# and don't truncate the values to INT_MAX
+# a runtime test is needed here
+AC_SUBST(PIDL_ARGS)
+AC_CACHE_CHECK([that the C compiler understands negative enum values],SMB_BUILD_CC_NEGATIVE_ENUM_VALUES, [
+    AC_TRY_RUN(
+[
+       #include <stdio.h>
+       enum negative_values { NEGATIVE_VALUE = 0xFFFFFFFF };
+       int main(void) {
+               enum negative_values v1 = NEGATIVE_VALUE;
+               unsigned v2 = NEGATIVE_VALUE;
+
+               if (v1 != 0xFFFFFFFF) {
+                       printf("%u != 0xFFFFFFFF\n", v1);
+                       return 1;
+               }
+               if (v2 != 0xFFFFFFFF) {
+                       printf("%u != 0xFFFFFFFF\n", v2);
+                       return 1;
+               }
+
+               return 0;
+       }
+],
+       SMB_BUILD_CC_NEGATIVE_ENUM_VALUES=yes,SMB_BUILD_CC_NEGATIVE_ENUM_VALUES=no)])
+if test x"$SMB_BUILD_CC_NEGATIVE_ENUM_VALUES" != x"yes"; then
+       AC_MSG_WARN([using --unit-enums for pidl])
+       PIDL_ARGS="$PIDL_ARGS --uint-enums"
+fi
+
+############################################
+# Check whether we can do automatic dependency tracking
+
+m4_include(m4/substnot.m4)
+m4_include(m4/cond.m4)
+m4_include(m4/make.m4)
+m4_include(m4/depout.m4)
+m4_include(m4/lead-dot.m4)
+m4_include(m4/check_gnu_make.m4)
+m4_include(m4/depend.m4)
+
+# Using the dependency files requires GNU make until someone adds support
+# for Makefile includes for other make implementations. Note that
+# CHECK_GNU_MAKE() can find a non-default make.
+CHECK_GNU_MAKE()
+if test "x$_cv_gnu_make_command" != "x" -a \
+    x`which make` = x`which "$_cv_gnu_make_command"` ; then
+    AC_SUBST(MAKE, $_cv_gnu_make_command)
+else
+    # If GNU make is not the default, don't enable GNU-isms because we can't
+    # guarantee that GNU make will actually be the make that is invoked.
+    ifGNUmake='#'
+fi
+
+AM_DEP_TRACK()
+_AM_DEPENDENCIES(CC)
+
+############################################
+# Figure out the flags to support named structure initializers
+
+LIBREPLACE_C99_STRUCT_INIT([],[AC_MSG_ERROR([c99 structure initializer are not supported])])
+
 UNAME_S=`(uname -s) 2>/dev/null` || UNAME_S="unknown"
 AC_MSG_CHECKING(uname -s)
 AC_MSG_RESULT(${UNAME_S})
@@ -531,27 +645,39 @@ UNAME_P=`(uname -p) 2>/dev/null` || UNAME_P="unknown"
 AC_MSG_CHECKING(uname -p)
 AC_MSG_RESULT(${UNAME_P})
 
-AC_CANONICAL_SYSTEM
-
 dnl Add #include for broken IRIX header files
   case "$host_os" in
-       *irix6*) AC_ADD_INCLUDE(<standards.h>)
+       *irix6*)
+               #TODO add to libreplace
+               if test x"$ac_cv_prog_gcc" != x"yes" ; then
+                       dnl Fix sensible defaults for MIPSPro compilers. The
+                       dnl error numbers are valid for the 7.3 compilers,
+                       dnl hopefully also valid for the 7.4 series.
+                       dnl
+                       dnl Bugzilla 3801. Force an error on warning 1035
+                       dnl so we don't incorrectly detect stdint.h. This
+                       dnl warning is emitted for #error directives.
+                       CFLAGS="$CFLAGS -diag_error 1035"
+                       dnl 1209: Controlling expression is constant
+                       dnl 1174: Function foo declared but never referenced
+                       dnl 3201: Parameter foo was never referenced
+                       CFLAGS="$CFLAGS -woff 1209,1174,3201"
+               fi
        ;;
 esac
 
-AC_VALIDATE_CACHE_SYSTEM_TYPE
-
 DYNEXP=
+AC_SUBST(DYNEXP)
 
 dnl Add modules that have to be built by default here
 dnl These have to be built static:
-default_static_modules="pdb_smbpasswd pdb_tdbsam rpc_lsa rpc_samr rpc_reg rpc_lsa_ds rpc_wks rpc_svcctl rpc_ntsvcs rpc_net rpc_netdfs rpc_srv rpc_spoolss rpc_eventlog auth_rhosts auth_sam auth_unix auth_winbind auth_server auth_domain auth_builtin"
+default_static_modules="pdb_smbpasswd pdb_tdbsam rpc_lsa rpc_samr rpc_winreg rpc_initshutdown rpc_lsa_ds rpc_wkssvc rpc_svcctl rpc_ntsvcs rpc_net rpc_netdfs rpc_srvsvc rpc_spoolss rpc_eventlog rpc_unixinfo rpc_epmapper auth_sam auth_unix auth_winbind auth_server auth_domain auth_builtin vfs_default nss_info_template"
 
 dnl These are preferably build shared, and static if dlopen() is not available
-default_shared_modules="vfs_recycle vfs_audit vfs_extd_audit vfs_full_audit vfs_netatalk vfs_fake_perms vfs_default_quota vfs_readonly vfs_cap vfs_expand_msdfs vfs_shadow_copy charset_CP850 charset_CP437 auth_script"
+default_shared_modules="vfs_recycle vfs_audit vfs_extd_audit vfs_full_audit vfs_netatalk vfs_fake_perms vfs_default_quota vfs_readonly vfs_cap vfs_expand_msdfs vfs_shadow_copy charset_CP850 charset_CP437 auth_script vfs_readahead"
 
 if test "x$developer" = xyes; then
-   default_static_modules="$default_static_modules rpc_echo"
+   default_static_modules="$default_static_modules rpc_rpcecho"
    default_shared_modules="$default_shared_modules charset_weird"
 fi
 
@@ -561,15 +687,7 @@ fi
 # case statement; its first reference must be unconditional.
 #
 case "$host_os" in
-# Try to work out if this is the native HPUX compiler that uses the -Ae flag.
     *hpux*)
-    
-      AC_PROG_CC_FLAG(Ae)
-      # mmap on HPUX is completely broken...
-      AC_DEFINE(MMAP_BLACKLIST, 1, [Whether MMAP is broken])
-      if test $ac_cv_prog_cc_Ae = yes; then
-        CPPFLAGS="$CPPFLAGS -Ae"
-      fi
 #
 # Defines needed for HPUX support.
 # HPUX has bigcrypt but (sometimes?) doesn't use it for
@@ -592,6 +710,7 @@ case "$host_os" in
                                AC_DEFINE(_LARGEFILE64_SOURCE, 1, [Whether to use large file support])
                                AC_DEFINE(_ALIGNMENT_REQUIRED, 1, [Required alignment])
                                AC_DEFINE(_MAX_ALIGNMENT, 4, [Maximum alignment])
+                               AC_DEFINE(_XOPEN_SOURCE_EXTENDED, 1, [Unix 98 sources -- needed for socklen_t in getsockopt on HP/UX 11])
                                ;;
       esac
       ;;
@@ -611,7 +730,7 @@ case "$host_os" in
          AC_MSG_RESULT([enabling large file support])
       CPPFLAGS="$CPPFLAGS -D_LARGE_FILES"
          AC_DEFINE(_LARGE_FILES, 1, [Whether to enable large file support])
-      ;;    
+      ;;
 #
 # Defines needed for Solaris 2.6/2.7 aka 7.0 to make it admit
 # to the existance of large files..
@@ -695,11 +814,11 @@ case "$host_os" in
         CPPFLAGS="-D_LARGEFILE64_SOURCE $CPPFLAGS"
         AC_TRY_RUN([
 #include <unistd.h>
-main () {
+int main () {
 #if _LFS64_LARGEFILE == 1
-exit(0);
+return 0;
 #else
-exit(1);
+return 1;
 #endif
 }], [SINIX_LFS_SUPPORT=yes], [SINIX_LFS_SUPPORT=no], [SINIX_LFS_SUPPORT=cross])
         CPPFLAGS="$old_CPPFLAGS"
@@ -714,6 +833,15 @@ exit(1);
       fi
     ;;
 
+# Systems with LFS support.
+#
+    gnu* | k*bsd*-gnu)
+       CPPFLAGS="-D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE $CPPFLAGS"
+       AC_DEFINE(_LARGEFILE64_SOURCE, 1, [Whether to enable large file support])
+       AC_DEFINE(_FILE_OFFSET_BITS, 64, [File offset bits])
+       AC_DEFINE(_GNU_SOURCE, 1, [Whether to use GNU libc extensions])
+       ;;
+
 # Tests for linux LFS support. Need kernel 2.4 and glibc2.2 or greater support.
 #
     *linux*)
@@ -725,7 +853,7 @@ exit(1);
 #include <sys/utsname.h>
 #include <string.h>
 #include <stdlib.h>
-main() {
+int main() {
 #if _LFS64_LARGEFILE == 1
        struct utsname uts;
        char *release;
@@ -737,9 +865,9 @@ main() {
        int libc_minor = __GLIBC_MINOR__;
 
        if (libc_major < 2)
-              exit(1);
+              return 1;
        if (libc_minor < 2)
-              exit(1);
+              return 1;
 #endif
 
        /* Ensure this is kernel 2.4 or higher */
@@ -750,10 +878,10 @@ main() {
        minor = atoi(strsep(&release, "."));
 
        if (major > 2 || (major == 2 && minor > 3))
-               exit(0);
-       exit(1);
+               return 0;
+       return 1;
 #else
-       exit(1);
+       return 1;
 #endif
 }
 ], [LINUX_LFS_SUPPORT=yes], [LINUX_LFS_SUPPORT=no], [LINUX_LFS_SUPPORT=cross])
@@ -773,21 +901,10 @@ main() {
 #
     *darwin*)
        AC_DEFINE(BROKEN_UNICODE_COMPOSE_CHARACTERS, 1, [Does this system use unicode compose characters])
-# Add Fink directories for various packages, like dlcompat.
-# Note: iconv does that explicitly below, but other packages
-# don't.
-       CPPFLAGS="$CPPFLAGS -I/sw/include"
-       LDFLAGS="$LDFLAGS -L/sw/lib"
-
-# If we have dlsym_prepend_underscore (from Fink's dlcompat),
-# use that instead of plain dlsym.
-
-       AC_CHECK_LIB(dl,dlopen)
-       AC_CHECK_FUNCS(dlsym_prepend_underscore,[CPPFLAGS="$CPPFLAGS -Ddlsym=dlsym_prepend_underscore"])
-
-# Add a system specific charset module.
 
+       # Add a system specific charset module.
        default_shared_modules="$default_shared_modules charset_macosxfs"
+
        ;;
     *hurd*)
         AC_MSG_CHECKING([for LFS support])
@@ -797,9 +914,9 @@ main() {
 #include <unistd.h>
 main () {
 #if _LFS64_LARGEFILE == 1
-exit(0);
+return 0;
 #else
-exit(1);
+return 1;
 #endif
 }], [GLIBC_LFS_SUPPORT=yes], [GLIBC_LFS_SUPPORT=no], [GLIBC_LFS_SUPPORT=cross])
         CPPFLAGS="$old_CPPFLAGS"
@@ -813,23 +930,32 @@ exit(1);
 
 esac
 
-AC_INLINE
-AC_HEADER_STDC
-AC_HEADER_DIRENT
-AC_HEADER_TIME
-AC_HEADER_SYS_WAIT
+AC_LIBREPLACE_BROKEN_CHECKS
+
+LIBREPLACE_DIR=`echo ${libreplacedir} | sed -e "s;${srcdir};;" -e "s;^/;;"`
+
+LIBREPLACE_OBJS=""
+for obj in ${LIBREPLACEOBJ}; do
+       LIBREPLACE_OBJS="${LIBREPLACE_OBJS} ${LIBREPLACE_DIR}/${obj}"
+done
+AC_SUBST(LIBREPLACE_OBJS)
+
+# add -ldl to the global LIBS
+LIBS="${LIBS} ${LIBDL}"
+
 AC_CHECK_HEADERS(aio.h arpa/inet.h sys/fcntl.h sys/select.h fcntl.h sys/time.h sys/unistd.h rpc/nettype.h)
-AC_CHECK_HEADERS(unistd.h utime.h grp.h sys/id.h limits.h memory.h alloca.h)
+AC_CHECK_HEADERS(unistd.h utime.h grp.h sys/id.h memory.h alloca.h)
+AC_CHECK_HEADERS(limits.h float.h)
 AC_CHECK_HEADERS(rpc/rpc.h rpcsvc/nis.h rpcsvc/ypclnt.h)
 AC_CHECK_HEADERS(sys/param.h ctype.h sys/wait.h sys/resource.h sys/ioctl.h sys/ipc.h sys/prctl.h)
 AC_CHECK_HEADERS(sys/mman.h sys/filio.h sys/priv.h sys/shm.h string.h strings.h stdlib.h sys/socket.h)
 AC_CHECK_HEADERS(sys/un.h)
 AC_CHECK_HEADERS(sys/mount.h sys/vfs.h sys/fs/s5param.h sys/filsys.h termios.h termio.h)
 AC_CHECK_HEADERS(sys/termio.h sys/statfs.h sys/dustat.h sys/statvfs.h stdarg.h sys/sockio.h)
-AC_CHECK_HEADERS(sys/sysmacros.h security/_pam_macros.h dlfcn.h)
-AC_CHECK_HEADERS(sys/syslog.h syslog.h execinfo.h)
+AC_CHECK_HEADERS(sys/sysmacros.h)
+AC_CHECK_HEADERS(sys/syslog.h syslog.h)
 AC_CHECK_HEADERS(langinfo.h locale.h)
-AC_CHECK_HEADERS(sys/dmi.h xfs/dmapi.h sys/jfsdmapi.h sys/dmapi.h)
+AC_CHECK_HEADERS(xfs/libxfs.h)
 
 AC_CHECK_HEADERS(rpcsvc/yp_prot.h,,,[[
 #if HAVE_RPC_RPC_H
@@ -875,45 +1001,21 @@ case "$host_os" in
                fi
        ;;
 esac
-AC_CHECK_HEADERS(shadow.h netinet/tcp.h netinet/in_systm.h netinet/in_ip.h)
-AC_CHECK_HEADERS(nss.h nss_common.h nsswitch.h ns_api.h sys/security.h security/pam_appl.h)
-AC_CHECK_HEADERS(stropts.h poll.h)
+AC_CHECK_HEADERS(shadow.h)
+AC_CHECK_HEADERS(nss.h nss_common.h nsswitch.h ns_api.h sys/security.h)
 AC_CHECK_HEADERS(syscall.h sys/syscall.h)
 
-AC_CHECK_HEADERS(sys/acl.h sys/attributes.h attr/xattr.h sys/xattr.h sys/extattr.h sys/uio.h)
+AC_CHECK_HEADERS(sys/attributes.h attr/xattr.h sys/xattr.h sys/extattr.h sys/uio.h)
 AC_CHECK_HEADERS(sys/ea.h sys/proplist.h)
 
 AC_CHECK_HEADERS(sys/cdefs.h glob.h)
 
-AC_CHECK_HEADERS(netinet/ip.h,,,[[
-#include <sys/types.h>
-#if HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
-#include <netinet/in.h>
-#if HAVE_NETINET_IN_SYSTM_H
-#include <netinet/in_systm.h>
-#endif
-]])
-
-AC_CHECK_HEADERS(net/if.h,,,[[
-#include <sys/types.h>
-#if HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
-]])
-
-AC_CHECK_HEADERS(security/pam_modules.h,,,[[
-#if HAVE_SECURITY_PAM_APPL_H
-#include <security/pam_appl.h>
-#endif
-]])
-
 # For experimental utmp support (lastlog on some BSD-like systems)
 AC_CHECK_HEADERS(utmp.h utmpx.h lastlog.h)
+
 AC_CHECK_SIZEOF(int,cross)
 AC_CHECK_SIZEOF(long,cross)
+AC_CHECK_SIZEOF(long long,cross)
 AC_CHECK_SIZEOF(short,cross)
 
 AC_C_CONST
@@ -934,6 +1036,8 @@ AC_CHECK_TYPE(loff_t,off_t)
 AC_CHECK_TYPE(offset_t,loff_t)
 AC_CHECK_TYPE(ssize_t, int)
 AC_CHECK_TYPE(wchar_t, unsigned short)
+AC_CHECK_TYPE(comparison_fn_t,
+[AC_DEFINE(HAVE_COMPARISON_FN_T, 1,[Whether or not we have comparison_fn_t])])
 
 ############################################
 # for cups support we need libcups, and a handful of header files
@@ -966,33 +1070,7 @@ if test x$enable_iprint != xno; then
 fi
 
 ############################################
-# we need dlopen/dlclose/dlsym/dlerror for PAM, the password database plugins and the plugin loading code
-AC_SEARCH_LIBS(dlopen, [dl])
-# dlopen/dlclose/dlsym/dlerror will be checked again later and defines will be set then
-
-############################################
-# check if the compiler can do immediate structures
-AC_CACHE_CHECK([for immediate structures],samba_cv_immediate_structures, [
-    AC_TRY_COMPILE([
-#include <stdio.h>],
-[
-   typedef struct {unsigned x;} FOOBAR;
-   #define X_FOOBAR(x) ((FOOBAR) { x })
-   #define FOO_ONE X_FOOBAR(1)
-   FOOBAR f = FOO_ONE;   
-   static struct {
-       FOOBAR y; 
-       } f2[] = {
-               {FOO_ONE}
-       };   
-],
-       samba_cv_immediate_structures=yes,samba_cv_immediate_structures=no)])
-if test x"$samba_cv_immediate_structures" = x"yes"; then
-   AC_DEFINE(HAVE_IMMEDIATE_STRUCTURES,1,[Whether the compiler supports immediate structures])
-fi
-
-############################################
-# check if the compiler can do immediate structures
+# check if the compiler will optimize out function calls
 AC_CACHE_CHECK([if the compiler will optimize out function calls],samba_cv_optimize_out_funcation_calls, [
     AC_TRY_LINK([
 #include <stdio.h>],
@@ -1019,7 +1097,7 @@ AC_CACHE_CHECK([for unix domain sockets],samba_cv_unixsocket, [
 #include <sys/socket.h>
 #include <sys/un.h>],
 [
-  struct sockaddr_un sunaddr; 
+  struct sockaddr_un sunaddr;
   sunaddr.sun_family = AF_UNIX;
 ],
        samba_cv_unixsocket=yes,samba_cv_unixsocket=no)])
@@ -1071,9 +1149,6 @@ AC_CACHE_CHECK([for struct timespec type],samba_cv_struct_timespec, [
 #  include <time.h>
 # endif
 #endif
-#if HAVE_AIO_H
-#include <aio.h>
-#endif
 ],[struct timespec ts;],
        samba_cv_struct_timespec=yes,samba_cv_struct_timespec=no)])
 if test x"$samba_cv_struct_timespec" = x"yes"; then
@@ -1093,7 +1168,7 @@ AC_HAVE_DECL(snprintf, [#include <stdio.h>])
 # nothing until kernel 2.1.44! very dumb.
 AC_CACHE_CHECK([for real setresuid],samba_cv_have_setresuid,[
     AC_TRY_RUN([#include <errno.h>
-main() { setresuid(1,1,1); setresuid(2,2,2); exit(errno==EPERM?0:1);}],
+int main() { setresuid(1,1,1); setresuid(2,2,2); return errno==EPERM?0:1;}],
        samba_cv_have_setresuid=yes,samba_cv_have_setresuid=no,samba_cv_have_setresuid=cross)])
 if test x"$samba_cv_have_setresuid" = x"yes"; then
     AC_DEFINE(HAVE_SETRESUID,1,[Whether the system has setresuid])
@@ -1104,7 +1179,7 @@ fi
 AC_CACHE_CHECK([for real setresgid],samba_cv_have_setresgid,[
     AC_TRY_RUN([#include <unistd.h>
 #include <errno.h>
-main() { errno = 0; setresgid(1,1,1); exit(errno != 0 ? (errno==EPERM ? 0 : 1) : 0);}],
+int main() { errno = 0; setresgid(1,1,1); return errno != 0 ? (errno==EPERM ? 0 : 1) : 0;}],
        samba_cv_have_setresgid=yes,samba_cv_have_setresgid=no,samba_cv_have_setresgid=cross)])
 if test x"$samba_cv_have_setresgid" = x"yes"; then
     AC_DEFINE(HAVE_SETRESGID,1,[Whether the system has setresgid])
@@ -1178,11 +1253,18 @@ AC_SUBST(TERMLDFLAGS)
 # code will generate warnings on one of them unless we have a few
 # special cases.
 AC_CHECK_LIB(readline, rl_completion_matches,
-            [AC_DEFINE(HAVE_NEW_LIBREADLINE, 1, 
+            [AC_DEFINE(HAVE_NEW_LIBREADLINE, 1,
                        [Do we have rl_completion_matches?])],
             [],
             [$TERMLIBS])
 
+# not all readline libs have rl_event_hook or history_list
+AC_CHECK_DECLS(rl_event_hook, [], [], [#include <readline/readline.h>])
+AC_CHECK_LIB(readline, history_list,
+            [AC_DEFINE(HAVE_HISTORY_LIST, 1, [Do we have history_list?])],
+            [],
+            [$TERMLIBS])
+
 # The following test taken from the cvs sources
 # If we can't find connect, try looking in -lsocket, -lnsl, and -linet.
 # The Irix 5 libc.so has connect and gethostbyname, but Irix 5 also has
@@ -1209,7 +1291,7 @@ if test x"$ac_cv_func_connect" = x"no"; then
     esac
     dnl We can't just call AC_CHECK_FUNCS(connect) here, because the value
     dnl has been cached.
-    if test x"$ac_cv_lib_socket_connect" = x"yes" || 
+    if test x"$ac_cv_lib_socket_connect" = x"yes" ||
        test x"$ac_cv_lib_inet_connect" = x"yes"; then
         # ac_cv_func_connect=yes
         # don't!  it would cause AC_CHECK_FUNC to succeed next time configure is run
@@ -1228,8 +1310,10 @@ if test x"$ac_cv_func_execl" = x"no"; then
     EXTRA_BIN_PROGS="$EXTRA_BIN_PROGS bin/smbrun\$(EXEEXT)"
 fi
 
-AC_CHECK_FUNCS(dlopen dlclose dlsym dlerror waitpid getcwd strdup strndup strnlen strtoul strerror chown fchown chmod fchmod chroot link mknod mknod64)
-AC_CHECK_FUNCS(fstat strchr utime utimes getrlimit fsync memset strlcpy strlcat setpgid)
+AC_CHECK_FUNCS(waitpid getcwd strdup strndup strnlen strerror chown fchown chmod fchmod chroot link mknod mknod64)
+AC_CHECK_FUNCS(strtol strtoll strtoul strtoull strtouq __strtoull)
+AC_CHECK_FUNCS(fstat strchr utime utimes chflags)
+AC_CHECK_FUNCS(getrlimit fsync memset strlcpy strlcat setpgid)
 AC_CHECK_FUNCS(memmove vsnprintf snprintf asprintf vasprintf setsid glob strpbrk pipe crypt16 getauthuid)
 AC_CHECK_FUNCS(strftime sigprocmask sigblock sigaction sigset innetgr setnetgrent getnetgrent endnetgrent)
 AC_CHECK_FUNCS(initgroups select poll rdchk getgrnam getgrent pathconf realpath)
@@ -1237,18 +1321,121 @@ AC_CHECK_FUNCS(setpriv setgidx setuidx setgroups sysconf mktime rename ftruncate
 AC_CHECK_FUNCS(lstat64 fopen64 atexit grantpt dup2 lseek64 ftruncate64)
 AC_CHECK_FUNCS(fseek64 fseeko64 ftell64 ftello64 setluid getpwanam setlinebuf)
 AC_CHECK_FUNCS(opendir64 readdir64 seekdir64 telldir64 rewinddir64 closedir64)
+AC_CHECK_FUNCS(getpwent_r)
 AC_CHECK_FUNCS(getdents getdents64)
 AC_CHECK_FUNCS(srandom random srand rand setenv usleep strcasecmp fcvt fcvtl symlink readlink)
 AC_CHECK_FUNCS(syslog vsyslog timegm)
 AC_CHECK_FUNCS(setlocale nl_langinfo)
 AC_CHECK_FUNCS(nanosleep)
+AC_CHECK_FUNCS(mlock munlock mlockall munlockall)
+AC_CHECK_FUNCS(memalign posix_memalign)
+AC_CHECK_HEADERS(sys/mman.h)
 # setbuffer, shmget, shm_open are needed for smbtorture
-AC_CHECK_FUNCS(setbuffer shmget shm_open backtrace_symbols)
-AC_CHECK_HEADERS(libexc.h)
+AC_CHECK_FUNCS(setbuffer shmget shm_open)
+AC_CHECK_FUNCS(makecontext getcontext setcontext swapcontext)
+
+# Find a method of generating a stack trace
+AC_CHECK_HEADERS(execinfo.h libexc.h libunwind.h)
+AC_CHECK_FUNCS(backtrace_symbols)
 AC_CHECK_LIB(exc, trace_back_stack)
 
-# syscall() is needed for smbwrapper.
-AC_CHECK_FUNCS(syscall)
+echo -n "checking for GPFS GPL libs... "
+save_LIBS="$LIBS"
+LIBS="$LIBS -lgpfs_gpl"
+AC_TRY_LINK([#include <gpfs_gpl.h>],
+          [gpfs_set_share(0,GPFS_SHARE_READ,GPFS_DENY_NONE)],
+          samba_cv_HAVE_GPFS=yes,
+          samba_cv_HAVE_GPFS=no)
+echo $samba_cv_HAVE_GPFS
+if test x"$samba_cv_HAVE_GPFS" = x"yes"; then
+    AC_DEFINE(HAVE_GPFS,1,[Whether GPFS GPL libs are available])
+    default_shared_modules="$default_shared_modules vfs_gpfs"
+fi
+LIBS="$save_LIBS"
+
+# Note that all the libunwind symbols in the API are defined to internal
+# platform-specific version, so we must include libunwind.h before checking
+# any of them.
+AC_MSG_CHECKING([for libunwind])
+save_LIBS=$LIBS
+if test x"$UNAME_P" = xunknown ; then
+    # This probably won't link without the platform-specific libunwind.
+    LIBS="$LIBS -lunwind"
+else
+    # Add the platform-specific libunwind module. uname -p seems the most
+    # plausible option and works for ia64, where libunwind is most useful.
+    LIBS="$LIBS -lunwind -lunwind-$UNAME_P"
+fi
+
+AC_TRY_LINK(
+    [
+#ifdef HAVE_LIBUNWIND_H
+#include <libunwind.h>
+#endif
+    ],
+    [
+       unw_context_t ctx; unw_cursor_t cur;
+       char buf[256]; unw_word_t off;
+       unw_getcontext(&ctx); unw_init_local(&cur, &ctx);
+       unw_get_proc_name(&cur, buf, sizeof(buf), &off);
+    ],
+    [
+       AC_MSG_RESULT(yes)
+       AC_DEFINE(HAVE_LIBUNWIND, 1, [Whether libunwind is available])
+
+       # If we have libunwind, test whether we also have libunwind-ptrace
+       # which would let us unwind arbitrary processes.
+       save_LIBS=$LIBS
+       AC_CHECK_HEADERS(libunwind-ptrace.h)
+       AC_CHECK_LIB(unwind-ptrace, _UPT_create,
+           [
+               LIBUNWIND_PTRACE="-lunwind-ptrace";
+               AC_DEFINE(HAVE_LIBUNWIND_PTRACE, 1,
+                   [Whether libunwind-ptrace.a is available.])
+           ],
+           [ LIBUNWIND_PTRACE="" ])
+
+       LIBS=$save_LIBS
+    ],
+    [
+       AC_MSG_RESULT(no)
+       LIBS=$save_LIBS
+    ])
+
+# To use libunwind-ptrace, we also need to make some ptrace system calls.
+if test x"$LIBUNWIND_PTRACE" != x"" ; then
+    AC_CHECK_HEADERS(sys/ptrace.h)
+    AC_MSG_CHECKING([for the Linux ptrace(2) interface])
+    AC_TRY_LINK(
+           [
+#if HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#if HAVE_SYS_PTRACE_H
+#include <sys/ptrace.h>
+#endif
+           ],
+           [
+               int main(int argc, const char ** argv)
+               {
+                       pid_t me = (pid_t)-1;
+                       ptrace(PTRACE_ATTACH, me, 0, 0);
+                       ptrace(PTRACE_DETACH, me, 0, 0);
+                       return 0;
+               }
+           ],
+           [
+               AC_MSG_RESULT(yes)
+               AC_DEFINE(HAVE_LINUX_PTRACE, 1,
+                   [Whether the Linux ptrace(2) interface is available.])
+           ],
+           [
+               AC_MSG_RESULT(no)
+               LIBUNWIND_PTRACE=""
+           ])
+fi
+
+AC_SUBST(LIBUNWIND_PTRACE)
 
 AC_CHECK_FUNCS(_dup _dup2 _opendir _readdir _seekdir _telldir _closedir)
 AC_CHECK_FUNCS(__dup __dup2 __opendir __readdir __seekdir __telldir __closedir)
@@ -1275,28 +1462,38 @@ AC_TRY_COMPILE([
 AC_DEFINE(HAVE_PRCTL, 1, [Whether prctl is available]),[])
 
 #
-# 
+#
 #
 case "$host_os" in
-    *linux*)
+    linux*-gnu* | gnu* | k*bsd*-gnu)
        # glibc <= 2.3.2 has a broken getgrouplist
-       AC_TRY_RUN([
+    AC_CACHE_CHECK([for a broken Linux getgrouplist API],
+           linux_getgrouplist_ok,
+           [
+               AC_TRY_RUN([
 #include <unistd.h>
 #include <sys/utsname.h>
-main() {
-       /* glibc up to 2.3 has a broken getgrouplist */
+
+                   int main() {
+                          /* glibc up to 2.3 has a broken getgrouplist */
 #if defined(__GLIBC__) && defined(__GLIBC_MINOR__)
-       int libc_major = __GLIBC__;
-       int libc_minor = __GLIBC_MINOR__;
+                          int libc_major = __GLIBC__;
+                          int libc_minor = __GLIBC_MINOR__;
 
-       if (libc_major < 2)
-              exit(1);
-       if ((libc_major == 2) && (libc_minor <= 3))
-              exit(1);
+                          if (libc_major < 2)
+                                 return 1;
+                          if ((libc_major == 2) && (libc_minor <= 3))
+                                 return 1;
 #endif
-       exit(0);
-}
-], [linux_getgrouplist_ok=yes], [linux_getgrouplist_ok=no])
+                          return 0;
+                   }
+
+               ],
+               [linux_getgrouplist_ok=yes],
+               [linux_getgrouplist_ok=no],
+               [linux_getgrouplist_ok=cross])
+       ])
+
        if test x"$linux_getgrouplist_ok" = x"yes"; then
           AC_DEFINE(HAVE_GETGROUPLIST, 1, [Have good getgrouplist])
        fi
@@ -1317,7 +1514,7 @@ if test x$ac_cv_func_stat64 = xno ; then
 #include <unistd.h>
 #endif
 #include <sys/stat.h>
-], [struct stat64 st64; exit(stat64(".",&st64));], [ac_cv_func_stat64=yes])
+], [struct stat64 st64; return stat64(".",&st64);], [ac_cv_func_stat64=yes])
   AC_MSG_RESULT([$ac_cv_func_stat64])
   if test x$ac_cv_func_stat64 = xyes ; then
     AC_DEFINE(HAVE_STAT64,1,[Whether stat64() is available])
@@ -1331,7 +1528,7 @@ if test x$ac_cv_func_lstat64 = xno ; then
 #include <unistd.h>
 #endif
 #include <sys/stat.h>
-], [struct stat64 st64; exit(lstat64(".",&st64));], [ac_cv_func_lstat64=yes])
+], [struct stat64 st64; return lstat64(".",&st64);], [ac_cv_func_lstat64=yes])
   AC_MSG_RESULT([$ac_cv_func_lstat64])
   if test x$ac_cv_func_lstat64 = xyes ; then
     AC_DEFINE(HAVE_LSTAT64,[Whether lstat64() is available])
@@ -1345,7 +1542,7 @@ if test x$ac_cv_func_fstat64 = xno ; then
 #include <unistd.h>
 #endif
 #include <sys/stat.h>
-], [struct stat64 st64; exit(fstat64(0,&st64));], [ac_cv_func_fstat64=yes])
+], [struct stat64 st64; return fstat64(0,&st64);], [ac_cv_func_fstat64=yes])
   AC_MSG_RESULT([$ac_cv_func_fstat64])
   if test x$ac_cv_func_fstat64 = xyes ; then
     AC_DEFINE(HAVE_FSTAT64,1,[Whether fstat64() is available])
@@ -1356,7 +1553,7 @@ fi
 # Check whether struct stat has timestamps with sub-second resolution.
 # At least IRIX and Solaris have these.
 #
-# We check that 
+# We check that
 #      all of st_mtim, st_atim and st_ctim exist
 #      all of the members are in fact of type struct timespec
 #
@@ -1443,8 +1640,10 @@ if test x"$samba_stat_hires_notimespec" = x"yes" ; then
 fi
 
 #####################################
-# we might need the resolv library on some systems
+# needed for SRV lookups
 AC_CHECK_LIB(resolv, dn_expand)
+AC_CHECK_LIB(resolv, _dn_expand)
+AC_CHECK_LIB(resolv, __dn_expand)
 
 #
 # Check for the functions putprpwnam, set_auth_parameters,
@@ -1493,6 +1692,30 @@ case "$host_os" in
   ;;
 esac
 
+########################################################
+# Do xattr functions take additional options like on Darwin?
+if test x"$ac_cv_func_getxattr" = x"yes" ; then
+       AC_CACHE_CHECK([whether xattr interface takes additional options], smb_attr_cv_xattr_add_opt, [
+               old_LIBS=$LIBS
+               LIBS="$LIBS $ACL_LIBS"
+               AC_TRY_COMPILE([
+                       #include <sys/types.h>
+                       #if HAVE_ATTR_XATTR_H
+                       #include <attr/xattr.h>
+                       #elif HAVE_SYS_XATTR_H
+                       #include <sys/xattr.h>
+                       #endif
+               ],[
+                       getxattr(0, 0, 0, 0, 0, 0);
+               ],
+               [smb_attr_cv_xattr_add_opt=yes],
+               [smb_attr_cv_xattr_add_opt=no;LIBS=$old_LIBS])
+       ])
+       if test x"$smb_attr_cv_xattr_add_opt" = x"yes"; then
+               AC_DEFINE(XATTR_ADD_OPT, 1, [xattr functions have additional options])
+       fi
+fi
+
 # Check if we have extattr
 case "$host_os" in
   *freebsd4* | *dragonfly* )
@@ -1506,39 +1729,68 @@ case "$host_os" in
     ;;
 esac
 
+# Set defaults
+PIE_CFLAGS=""
+PIE_LDFLAGS=""
+AC_ARG_ENABLE(pie, [  --enable-pie            Turn on pie support if available (default=yes)])
+
+if test "x$enable_pie" != xno
+then
+       AC_CACHE_CHECK(for -pie and -fPIE, samba_cv_fpie,
+       [
+               cat > conftest.c <<EOF
+int foo;
+main () { return 0;}
+EOF
+               if AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS -pie -fPIE -o conftest conftest.c 1>&AS_MESSAGE_LOG_FD])
+               then
+                       samba_cv_fpie=yes
+               else
+                       samba_cv_fpie=no
+               fi
+               rm -f conftest*
+       ])
+       if test x"${samba_cv_fpie}" = x"yes"
+       then
+               PIE_CFLAGS="-fPIE"
+               PIE_LDFLAGS="-pie"
+       fi
+fi
+
 # Assume non-shared by default and override below
 BLDSHARED="false"
 
 # these are the defaults, good for lots of systems
 HOST_OS="$host_os"
 LDSHFLAGS="-shared"
+MODULE_EXPORTS=""
 SONAMEFLAG="#"
-NSSSONAMEVERSIONSUFFIX=""
 SHLD="\${CC} \${CFLAGS}"
-PICFLAGS=""
-PICSUFFIX="po"
+PICFLAG="${PIE_CFLAGS}"
 SHLIBEXT="so"
 
-if test "$enable_shared" = "yes"; then
-  # this bit needs to be modified for each OS that is suported by
-  # smbwrapper. You need to specify how to create a shared library and
-  # how to compile C code to produce PIC object files
 
-  AC_MSG_CHECKING([ability to build shared libraries])
+# this bit needs to be modified for each OS that supports share libs
+# You need to specify how to create a shared library and
+# how to compile C code to produce PIC object files
 
-  # and these are for particular systems
-  case "$host_os" in
-               *linux*)   AC_DEFINE(LINUX,1,[Whether the host os is linux])
+AC_MSG_CHECKING([ability to build shared libraries])
+
+# and these are for particular systems
+case "$host_os" in
+               linux*-gnu* | gnu* | k*bsd*-gnu)
+                       case "$host_os" in 
+                               linux*)   AC_DEFINE(LINUX,1,[Whether the host os is linux]) ;;
+                       esac
                        BLDSHARED="true"
                        if test "${ac_cv_gnu_ld_no_default_allow_shlib_undefined}" = "yes"; then
-                               LDSHFLAGS="-shared -Wl,-Bsymbolic -Wl,--allow-shlib-undefined" 
+                               LDSHFLAGS="-shared -Wl,-Bsymbolic -Wl,--allow-shlib-undefined"
                        else
-                               LDSHFLAGS="-shared -Wl,-Bsymbolic" 
+                               LDSHFLAGS="-shared -Wl,-Bsymbolic"
                        fi
                        DYNEXP="-Wl,--export-dynamic"
-                       PICFLAGS="-fPIC"
+                       PICFLAG="-fPIC"
                        SONAMEFLAG="-Wl,-soname="
-                       NSSSONAMEVERSIONSUFFIX=".2"
                        AC_DEFINE(STAT_ST_BLOCKSIZE,512)
                        ;;
                *solaris*) AC_DEFINE(SUNOS5,1,[Whether the host os is solaris])
@@ -1546,18 +1798,16 @@ if test "$enable_shared" = "yes"; then
                        LDSHFLAGS="-G"
                        SONAMEFLAG="-h "
                        if test "${GCC}" = "yes"; then
-                               PICFLAGS="-fPIC"
+                               PICFLAG="-fPIC"
                                SONAMEFLAG="-Wl,-soname="
-                               NSSSONAMEVERSIONSUFFIX=".1"
                                if test "${ac_cv_prog_gnu_ld}" = "yes"; then
                                        DYNEXP="-Wl,-E"
                                fi
                        else
-                               PICFLAGS="-KPIC"
-                               ## ${CFLAGS} added for building 64-bit shared 
+                               PICFLAG="-KPIC"
+                               ## ${CFLAGS} added for building 64-bit shared
                                ## libs using Sun's Compiler
                                LDSHFLAGS="-G \${CFLAGS}"
-                               PICSUFFIX="po.o"
                        fi
                        AC_DEFINE(STAT_ST_BLOCKSIZE,512,[The size of a block])
                        AC_DEFINE(BROKEN_GETGRNAM,1,[Does getgrnam work correctly])
@@ -1566,16 +1816,16 @@ if test "$enable_shared" = "yes"; then
                        BLDSHARED="true"
                        LDSHFLAGS="-G"
                        SONAMEFLAG="-Wl,-h,"
-                       PICFLAGS="-KPIC"   # Is this correct for SunOS
+                       PICFLAG="-KPIC"   # Is this correct for SunOS
                        AC_DEFINE(STAT_ST_BLOCKSIZE,512)
                        AC_DEFINE(BROKEN_GETGRNAM,1,[Does getgrnam work correctly])
                        ;;
-               *netbsd* | *freebsd* | *dragonfly* )  
+               *netbsd* | *freebsd* | *dragonfly* )
                        BLDSHARED="true"
                        LDSHFLAGS="-shared"
                        DYNEXP="-Wl,--export-dynamic"
                        SONAMEFLAG="-Wl,-soname,"
-                       PICFLAGS="-fPIC -DPIC"
+                       PICFLAG="-fPIC -DPIC"
                        AC_DEFINE(STAT_ST_BLOCKSIZE,512,[The size of a block])
                        AC_DEFINE(BROKEN_GETGRNAM,1,[Does getgrnam work correctly])
                        ;;
@@ -1583,7 +1833,7 @@ if test "$enable_shared" = "yes"; then
                        LDSHFLAGS="-shared"
                        DYNEXP="-Wl,-Bdynamic"
                        SONAMEFLAG="-Wl,-soname,"
-                       PICFLAGS="-fPIC"
+                       PICFLAG="-fPIC"
                        AC_DEFINE(STAT_ST_BLOCKSIZE,512,[The size of a block])
                        AC_DEFINE(BROKEN_GETGRNAM,1,[Does getgrnam work correctly])
                        ;;
@@ -1597,17 +1847,19 @@ if test "$enable_shared" = "yes"; then
                        SONAMEFLAG="-soname "
                        SHLD="\${LD}"
                        if test "${GCC}" = "yes"; then
-                               PICFLAGS="-fPIC"
-                       else 
-                               PICFLAGS="-KPIC"
+                               PICFLAG="-fPIC"
+                       else
+                               PICFLAG="-KPIC"
                        fi
                        AC_DEFINE(STAT_ST_BLOCKSIZE,512,[The size of a block])
                        ;;
                *aix*) AC_DEFINE(AIX,1,[Whether the host os is aix])
                        BLDSHARED="true"
-                       LDSHFLAGS="-Wl,-G,-bexpall"
+                       LDSHFLAGS="-Wl,-G,-bexpall,-bbigtoc"
                        DYNEXP="-Wl,-brtl,-bexpall,-bbigtoc"
-                       PICFLAGS="-O2"
+                       PICFLAG="-O2"
+                       # as AIX code is always position independent...
+                       # .po will just create compile warnings, use po.o:
                        if test "${GCC}" != "yes"; then
                                ## for funky AIX compiler using strncpy()
                                CFLAGS="$CFLAGS -D_LINUX_SOURCE_COMPAT -qmaxmem=32000"
@@ -1619,14 +1871,15 @@ if test "$enable_shared" = "yes"; then
                        ;;
                *hpux*) AC_DEFINE(HPUX,1,[Whether the host os is HPUX])
                        # Use special PIC flags for the native HP-UX compiler.
-                       if test $ac_cv_prog_cc_Ae = yes; then
                                BLDSHARED="true"
                                SHLD="cc"
                                LDSHFLAGS="-b -Wl,-B,symbolic,-b,-z"
                                SONAMEFLAG="-Wl,+h "
-                               PICFLAGS="+z"
-                       elif test "${GCC}" = "yes"; then
-                               PICFLAGS="-fPIC"
+                               PICFLAG="+z"
+                       if test "${GCC}" = "yes"; then
+                               PICFLAG="-fPIC"
+                       else
+                               PICFLAG="+z"
                        fi
                        if test "$host_cpu" = "ia64"; then
                                SHLIBEXT="so"
@@ -1645,7 +1898,7 @@ if test "$enable_shared" = "yes"; then
                        BLDSHARED="true"
                        LDSHFLAGS="-shared"
                        SONAMEFLAG="-Wl,-soname,"
-                       PICFLAGS="-fPIC"
+                       PICFLAG="-fPIC"
                        AC_DEFINE(STAT_ST_BLOCKSIZE,512)
                        AC_DEFINE(BROKEN_GETGRNAM,1,[Does getgrnam work correctly])
                        ;;
@@ -1656,7 +1909,7 @@ if test "$enable_shared" = "yes"; then
                        BLDSHARED="true"
                        LDSHFLAGS="-shared"
                        SONAMEFLAG="-Wl,-soname,"
-                       PICFLAGS="-KPIC"
+                       PICFLAG="-KPIC"
                        AC_DEFINE(STAT_ST_BLOCKSIZE,512)
                        ;;
                *next2*) AC_DEFINE(NEXT2,1,[Whether the host os is NeXT v2])
@@ -1693,50 +1946,95 @@ if test "$enable_shared" = "yes"; then
                *darwin*)   AC_DEFINE(DARWINOS,1,[Whether the host os is Darwin/MacOSX])
                        BLDSHARED="true"
                        LDSHFLAGS="-bundle -flat_namespace -undefined suppress"
+                       MODULE_EXPORTS="-exported_symbols_list \$(srcdir)/modules/exports.darwin"
                        SHLIBEXT="dylib"
+                       # Since gcc doesn't fail on unrecognised options, the
+                       # PIE test incorrectly succeeds. Darwin gcc does not
+                       # actually support the PIE stuff.
+                       PIE_LDFLAGS=
+                       PIE_CFLAGS=
                        AC_DEFINE(STAT_ST_BLOCKSIZE,512)
                        ;;
 
                *)
                        AC_DEFINE(STAT_ST_BLOCKSIZE,512)
                        ;;
-  esac
-  AC_SUBST(DYNEXP)
-  AC_MSG_RESULT($BLDSHARED)
-  AC_MSG_CHECKING([linker flags for shared libraries])
-  AC_MSG_RESULT([$LDSHFLAGS])
-  AC_MSG_CHECKING([compiler flags for position-independent code])
-  AC_MSG_RESULT([$PICFLAGS])
+esac
+
+if test "$enable_shared" != "yes"; then
+       BLDSHARED=false
 fi
 
+AC_MSG_RESULT($BLDSHARED)
+
+AC_MSG_CHECKING([LDFLAGS])
+AC_MSG_RESULT([$LDFLAGS])
+AC_MSG_CHECKING([DYNEXP])
+AC_MSG_RESULT([$DYNEXP])
+
 #######################################################
 # test whether building a shared library actually works
 if test $BLDSHARED = true; then
-AC_CACHE_CHECK([whether building shared libraries actually works], 
+
+AC_MSG_CHECKING([SHLD])
+AC_MSG_RESULT([$SHLD])
+AC_MSG_CHECKING([LDSHFLAGS])
+AC_MSG_RESULT([$LDSHFLAGS])
+
+AC_MSG_CHECKING([SHLIBEXT])
+AC_MSG_RESULT([$SHLIBEXT])
+AC_MSG_CHECKING([SONAMEFLAG])
+AC_MSG_RESULT([$SONAMEFLAG])
+
+AC_MSG_CHECKING([PICFLAG])
+AC_MSG_RESULT([$PICFLAG])
+
+AC_MSG_CHECKING([NSSSONAMEVERSIONSUFFIX])
+AC_MSG_RESULT([$NSSSONAMEVERSIONSUFFIX])
+
+AC_CACHE_CHECK([whether building shared libraries actually works],
                [ac_cv_shlib_works],[
    # try building a trivial shared library
    ac_cv_shlib_works=no
    # The $SHLD and $LDSHFLAGS variables may contain references to other
    # variables so they need to be eval'ed.
-   $CC $CPPFLAGS $CFLAGS $PICFLAGS -c -o \
-       shlib.$PICSUFFIX ${srcdir-.}/tests/shlib.c && \
+   $CC $CPPFLAGS $CFLAGS $PICFLAG -c -o \
+       shlib.o ${srcdir-.}/tests/shlib.c && \
    `eval echo $SHLD` `eval echo $LDSHFLAGS` -o "shlib.$SHLIBEXT" \
-        shlib.$PICSUFFIX && ac_cv_shlib_works=yes
-   rm -f "shlib.$SHLIBEXT" shlib.$PICSUFFIX
+        shlib.o && ac_cv_shlib_works=yes
+   rm -f "shlib.$SHLIBEXT" shlib.o
+
 ])
 if test $ac_cv_shlib_works = no; then
    BLDSHARED=false
 fi
 fi
 
+if test x"$BLDSHARED" != x"true"; then
+       LDSHFLAGS="shared-libraries-disabled"
+       SONAMEFLAG="shared-libraries-disabled"
+       NSSSONAMEVERSIONSUFFIX="shared-libraries-disabled"
+       SHLD="shared-libraries-disabled"
+       PICFLAG="${PIE_CFLAGS}"
+       SHLIBEXT="shared_libraries_disabled"
+fi
+
+AC_MSG_CHECKING([used PICFLAG])
+AC_MSG_RESULT([$PICFLAG])
+
+AC_DEFINE_UNQUOTED(SHLIBEXT, "$SHLIBEXT", [Shared library extension])
+
 ################
 
 AC_CACHE_CHECK([for long long],samba_cv_have_longlong,[
 AC_TRY_RUN([#include <stdio.h>
-main() { long long x = 1000000; x *= x; exit(((x/1000000) == 1000000)? 0: 1); }],
+int main() { long long x = 1000000; x *= x; return ((x/1000000) == 1000000)? 0: 1; }],
 samba_cv_have_longlong=yes,samba_cv_have_longlong=no,samba_cv_have_longlong=cross)])
 if test x"$samba_cv_have_longlong" = x"yes"; then
     AC_DEFINE(HAVE_LONGLONG,1,[Whether the host supports long long's])
+    AC_CHECK_TYPE(intptr_t, unsigned long long)
+else
+    AC_CHECK_TYPE(intptr_t, unsigned long)
 fi
 
 #
@@ -1750,11 +2048,11 @@ if test x"$samba_cv_compiler_supports_ll" = x"yes"; then
    AC_DEFINE(COMPILER_SUPPORTS_LL,1,[Whether the compiler supports the LL prefix on long long integers])
 fi
 
-  
+
 AC_CACHE_CHECK([for 64 bit off_t],samba_cv_SIZEOF_OFF_T,[
 AC_TRY_RUN([#include <stdio.h>
 #include <sys/stat.h>
-main() { exit((sizeof(off_t) == 8) ? 0 : 1); }],
+int main() { return (sizeof(off_t) == 8) ? 0 : 1; }],
 samba_cv_SIZEOF_OFF_T=yes,samba_cv_SIZEOF_OFF_T=no,samba_cv_SIZEOF_OFF_T=cross)])
 if test x"$samba_cv_SIZEOF_OFF_T" = x"yes"; then
     AC_DEFINE(SIZEOF_OFF_T,8,[The size of the 'off_t' type])
@@ -1767,7 +2065,7 @@ AC_TRY_RUN([
 #endif
 #include <stdio.h>
 #include <sys/stat.h>
-main() { struct stat64 st; off64_t s; if (sizeof(off_t) == sizeof(off64_t)) exit(1); exit((lstat64("/dev/null", &st)==0)?0:1); }],
+int main() { struct stat64 st; off64_t s; if (sizeof(off_t) == sizeof(off64_t)) return 1; return (lstat64("/dev/null", &st)==0)?0:1; }],
 samba_cv_HAVE_OFF64_T=yes,samba_cv_HAVE_OFF64_T=no,samba_cv_HAVE_OFF64_T=cross)])
 if test x"$samba_cv_HAVE_OFF64_T" = x"yes"; then
     AC_DEFINE(HAVE_OFF64_T,1,[Whether off64_t is available])
@@ -1780,7 +2078,7 @@ AC_TRY_RUN([
 #endif
 #include <stdio.h>
 #include <sys/stat.h>
-main() { exit((sizeof(ino_t) == 8) ? 0 : 1); }],
+int main() { return (sizeof(ino_t) == 8) ? 0 : 1; }],
 samba_cv_SIZEOF_INO_T=yes,samba_cv_SIZEOF_INO_T=no,samba_cv_SIZEOF_INO_T=cross)])
 if test x"$samba_cv_SIZEOF_INO_T" = x"yes"; then
     AC_DEFINE(SIZEOF_INO_T,8,[The size of the 'ino_t' type])
@@ -1793,7 +2091,7 @@ AC_TRY_RUN([
 #endif
 #include <stdio.h>
 #include <sys/stat.h>
-main() { struct stat64 st; ino64_t s; if (sizeof(ino_t) == sizeof(ino64_t)) exit(1); exit((lstat64("/dev/null", &st)==0)?0:1); }],
+int main() { struct stat64 st; ino64_t s; if (sizeof(ino_t) == sizeof(ino64_t)) return 1; return (lstat64("/dev/null", &st)==0)?0:1; }],
 samba_cv_HAVE_INO64_T=yes,samba_cv_HAVE_INO64_T=no,samba_cv_HAVE_INO64_T=cross)])
 if test x"$samba_cv_HAVE_INO64_T" = x"yes"; then
     AC_DEFINE(HAVE_INO64_T,1,[Whether the 'ino64_t' type is available])
@@ -1806,7 +2104,7 @@ AC_TRY_RUN([
 #endif
 #include <stdio.h>
 #include <sys/stat.h>
-main() { exit((sizeof(dev_t) == 8) ? 0 : 1); }],
+int main() { return (sizeof(dev_t) == 8) ? 0 : 1; }],
 samba_cv_SIZEOF_DEV_T=yes,samba_cv_SIZEOF_DEV_T=no,samba_cv_SIZEOF_DEV_T=cross)])
 if test x"$samba_cv_SIZEOF_DEV_T" = x"yes"; then
     AC_DEFINE(SIZEOF_DEV_T,8,[The size of the 'dev_t' type])
@@ -1819,7 +2117,7 @@ AC_TRY_RUN([
 #endif
 #include <stdio.h>
 #include <sys/stat.h>
-main() { struct stat64 st; dev64_t s; if (sizeof(dev_t) == sizeof(dev64_t)) exit(1); exit((lstat64("/dev/null", &st)==0)?0:1); }],
+int main() { struct stat64 st; dev64_t s; if (sizeof(dev_t) == sizeof(dev64_t)) return 1; return (lstat64("/dev/null", &st)==0)?0:1; }],
 samba_cv_HAVE_DEV64_T=yes,samba_cv_HAVE_DEV64_T=no,samba_cv_HAVE_DEV64_T=cross)])
 if test x"$samba_cv_HAVE_DEV64_T" = x"yes"; then
     AC_DEFINE(HAVE_DEV64_T,1,[Whether the 'dev64_t' type is available])
@@ -1857,7 +2155,7 @@ AC_TRY_RUN([
 #include <unistd.h>
 #endif
 #include <sys/types.h>
-main() { dev_t dev; int i = major(dev); return 0; }],
+int main() { dev_t dev; int i = major(dev); return 0; }],
 samba_cv_HAVE_DEVICE_MAJOR_FN=yes,samba_cv_HAVE_DEVICE_MAJOR_FN=no,samba_cv_HAVE_DEVICE_MAJOR_FN=cross)])
 if test x"$samba_cv_HAVE_DEVICE_MAJOR_FN" = x"yes"; then
     AC_DEFINE(HAVE_DEVICE_MAJOR_FN,1,[Whether the major macro for dev_t is available])
@@ -1869,7 +2167,7 @@ AC_TRY_RUN([
 #include <unistd.h>
 #endif
 #include <sys/types.h>
-main() { dev_t dev; int i = minor(dev); return 0; }],
+int main() { dev_t dev; int i = minor(dev); return 0; }],
 samba_cv_HAVE_DEVICE_MINOR_FN=yes,samba_cv_HAVE_DEVICE_MINOR_FN=no,samba_cv_HAVE_DEVICE_MINOR_FN=cross)])
 if test x"$samba_cv_HAVE_DEVICE_MINOR_FN" = x"yes"; then
     AC_DEFINE(HAVE_DEVICE_MINOR_FN,1,[Whether the minor macro for dev_t is available])
@@ -1881,7 +2179,7 @@ AC_TRY_RUN([
 #include <unistd.h>
 #endif
 #include <sys/types.h>
-main() { dev_t dev = makedev(1,2); return 0; }],
+int main() { dev_t dev = makedev(1,2); return 0; }],
 samba_cv_HAVE_MAKEDEV=yes,samba_cv_HAVE_MAKEDEV=no,samba_cv_HAVE_MAKEDEV=cross)])
 if test x"$samba_cv_HAVE_MAKEDEV" = x"yes"; then
     AC_DEFINE(HAVE_MAKEDEV,1,[Whether the macro for makedev is available])
@@ -1889,7 +2187,7 @@ fi
 
 AC_CACHE_CHECK([for unsigned char],samba_cv_HAVE_UNSIGNED_CHAR,[
 AC_TRY_RUN([#include <stdio.h>
-main() { char c; c=250; exit((c > 0)?0:1); }],
+int main() { char c; c=250; return (c > 0)?0:1; }],
 samba_cv_HAVE_UNSIGNED_CHAR=yes,samba_cv_HAVE_UNSIGNED_CHAR=no,samba_cv_HAVE_UNSIGNED_CHAR=cross)])
 if test x"$samba_cv_HAVE_UNSIGNED_CHAR" = x"yes"; then
     AC_DEFINE(HAVE_UNSIGNED_CHAR,1,[Whether the 'unsigned char' type is available])
@@ -1922,21 +2220,39 @@ if test x"$samba_cv_HAVE_FUNCTION_MACRO" = x"yes"; then
 fi
 
 AC_CACHE_CHECK([if gettimeofday takes tz argument],samba_cv_HAVE_GETTIMEOFDAY_TZ,[
-AC_TRY_RUN([
+AC_TRY_LINK([
 #include <sys/time.h>
-#include <unistd.h>
-main() { struct timeval tv; exit(gettimeofday(&tv, NULL));}],
-           samba_cv_HAVE_GETTIMEOFDAY_TZ=yes,samba_cv_HAVE_GETTIMEOFDAY_TZ=no,samba_cv_HAVE_GETTIMEOFDAY_TZ=cross)])
+#include <unistd.h>], [struct timeval tv; return gettimeofday(&tv, NULL);],
+           samba_cv_HAVE_GETTIMEOFDAY_TZ=yes,
+          samba_cv_HAVE_GETTIMEOFDAY_TZ=no)])
 if test x"$samba_cv_HAVE_GETTIMEOFDAY_TZ" = x"yes"; then
-    AC_DEFINE(HAVE_GETTIMEOFDAY_TZ,1,[Whether gettimeofday() is available])
+    AC_DEFINE(HAVE_GETTIMEOFDAY_TZ,1,[Whether gettimeofday takes a tz argument])
 fi
 
-AC_CACHE_CHECK([for va_copy],samba_cv_HAVE_VA_COPY,[
-AC_TRY_LINK([#include <stdarg.h>
-va_list ap1,ap2;], [va_copy(ap1,ap2);],
-samba_cv_HAVE_VA_COPY=yes,
-samba_cv_HAVE_VA_COPY=no)])
-if test x"$samba_cv_HAVE_VA_COPY" = x"yes"; then
+if test x"$samba_cv_WITH_PROFILE" = x"yes"; then
+
+    # On some systems (eg. Linux) librt can pull in libpthread. We
+    # don't want this to happen because libpthreads changes signal delivery
+    # semantics in ways we are not prepared for. This breaks Linux oplocks
+    # which rely on signals.
+
+    AC_LIBTESTFUNC(rt, clock_gettime,
+           [
+               AC_DEFINE(HAVE_CLOCK_GETTIME, 1,
+                   [Whether clock_gettime is available])
+               SMB_CHECK_CLOCK_ID(CLOCK_MONOTONIC)
+               SMB_CHECK_CLOCK_ID(CLOCK_PROCESS_CPUTIME_ID)
+               SMB_CHECK_CLOCK_ID(CLOCK_REALTIME)
+           ])
+
+fi
+
+AC_CACHE_CHECK([for va_copy],samba_cv_HAVE_VA_COPY,[
+AC_TRY_LINK([#include <stdarg.h>
+va_list ap1,ap2;], [va_copy(ap1,ap2);],
+samba_cv_HAVE_VA_COPY=yes,
+samba_cv_HAVE_VA_COPY=no)])
+if test x"$samba_cv_HAVE_VA_COPY" = x"yes"; then
     AC_DEFINE(HAVE_VA_COPY,1,[Whether va_copy() is available])
 else
     AC_CACHE_CHECK([for __va_copy],samba_cv_HAVE___VA_COPY,[
@@ -1953,7 +2269,7 @@ AC_CACHE_CHECK([for C99 vsnprintf],samba_cv_HAVE_C99_VSNPRINTF,[
 AC_TRY_RUN([
 #include <sys/types.h>
 #include <stdarg.h>
-void foo(const char *format, ...) { 
+void foo(const char *format, ...) {
        va_list ap;
        int len;
        char buf[5];
@@ -1961,18 +2277,18 @@ void foo(const char *format, ...) {
        va_start(ap, format);
        len = vsnprintf(buf, 0, format, ap);
        va_end(ap);
-       if (len != 5) exit(1);
+       if (len != 5) return 1;
 
        va_start(ap, format);
        len = vsnprintf(0, 0, format, ap);
        va_end(ap);
-       if (len != 5) exit(1);
+       if (len != 5) return 1;
 
-       if (snprintf(buf, 3, "hello") != 5 || strcmp(buf, "he") != 0) exit(1);
+       if (snprintf(buf, 3, "hello") != 5 || strcmp(buf, "he") != 0) return 1;
 
-       exit(0);
+       return 0;
 }
-main() { foo("hello"); }
+int main() { foo("hello"); }
 ],
 samba_cv_HAVE_C99_VSNPRINTF=yes,samba_cv_HAVE_C99_VSNPRINTF=no,samba_cv_HAVE_C99_VSNPRINTF=cross)])
 if test x"$samba_cv_HAVE_C99_VSNPRINTF" = x"yes"; then
@@ -1982,9 +2298,9 @@ fi
 AC_CACHE_CHECK([for broken readdir name],samba_cv_HAVE_BROKEN_READDIR_NAME,[
 AC_TRY_RUN([#include <sys/types.h>
 #include <dirent.h>
-main() { struct dirent *di; DIR *d = opendir("."); di = readdir(d);
+int main() { struct dirent *di; DIR *d = opendir("."); di = readdir(d);
 if (di && di->d_name[-2] == '.' && di->d_name[-1] == 0 &&
-di->d_name[0] == 0) exit(0); exit(1);} ],
+di->d_name[0] == 0) return 0; return 1;} ],
 samba_cv_HAVE_BROKEN_READDIR_NAME=yes,samba_cv_HAVE_BROKEN_READDIR_NAME=no,samba_cv_HAVE_BROKEN_READDIR_NAME=cross)])
 if test x"$samba_cv_HAVE_BROKEN_READDIR_NAME" = x"yes"; then
     AC_DEFINE(HAVE_BROKEN_READDIR_NAME,1,[Whether readdir() returns the wrong name offset])
@@ -1993,7 +2309,7 @@ fi
 AC_CACHE_CHECK([for utimbuf],samba_cv_HAVE_UTIMBUF,[
 AC_TRY_COMPILE([#include <sys/types.h>
 #include <utime.h>],
-[struct utimbuf tbuf;  tbuf.actime = 0; tbuf.modtime = 1; exit(utime("foo.c",&tbuf));],
+[struct utimbuf tbuf;  tbuf.actime = 0; tbuf.modtime = 1; return utime("foo.c",&tbuf);],
 samba_cv_HAVE_UTIMBUF=yes,samba_cv_HAVE_UTIMBUF=no,samba_cv_HAVE_UTIMBUF=cross)])
 if test x"$samba_cv_HAVE_UTIMBUF" = x"yes"; then
     AC_DEFINE(HAVE_UTIMBUF,1,[Whether struct utimbuf is available])
@@ -2016,7 +2332,7 @@ AC_TRY_COMPILE([#include <sys/types.h>
 samba_cv_HAVE_UT_UT_NAME=yes,samba_cv_HAVE_UT_UT_NAME=no,samba_cv_HAVE_UT_UT_NAME=cross)])
 if test x"$samba_cv_HAVE_UT_UT_NAME" = x"yes"; then
     AC_DEFINE(HAVE_UT_UT_NAME,1,[Whether the utmp struct has a property ut_name])
-fi 
+fi
 
 AC_CACHE_CHECK([for ut_user in utmp],samba_cv_HAVE_UT_UT_USER,[
 AC_TRY_COMPILE([#include <sys/types.h>
@@ -2025,7 +2341,7 @@ AC_TRY_COMPILE([#include <sys/types.h>
 samba_cv_HAVE_UT_UT_USER=yes,samba_cv_HAVE_UT_UT_USER=no,samba_cv_HAVE_UT_UT_USER=cross)])
 if test x"$samba_cv_HAVE_UT_UT_USER" = x"yes"; then
     AC_DEFINE(HAVE_UT_UT_USER,1,[Whether the utmp struct has a property ut_user])
-fi 
+fi
 
 AC_CACHE_CHECK([for ut_id in utmp],samba_cv_HAVE_UT_UT_ID,[
 AC_TRY_COMPILE([#include <sys/types.h>
@@ -2034,7 +2350,7 @@ AC_TRY_COMPILE([#include <sys/types.h>
 samba_cv_HAVE_UT_UT_ID=yes,samba_cv_HAVE_UT_UT_ID=no,samba_cv_HAVE_UT_UT_ID=cross)])
 if test x"$samba_cv_HAVE_UT_UT_ID" = x"yes"; then
     AC_DEFINE(HAVE_UT_UT_ID,1,[Whether the utmp struct has a property ut_id])
-fi 
+fi
 
 AC_CACHE_CHECK([for ut_host in utmp],samba_cv_HAVE_UT_UT_HOST,[
 AC_TRY_COMPILE([#include <sys/types.h>
@@ -2043,7 +2359,7 @@ AC_TRY_COMPILE([#include <sys/types.h>
 samba_cv_HAVE_UT_UT_HOST=yes,samba_cv_HAVE_UT_UT_HOST=no,samba_cv_HAVE_UT_UT_HOST=cross)])
 if test x"$samba_cv_HAVE_UT_UT_HOST" = x"yes"; then
     AC_DEFINE(HAVE_UT_UT_HOST,1,[Whether the utmp struct has a property ut_host])
-fi 
+fi
 
 AC_CACHE_CHECK([for ut_time in utmp],samba_cv_HAVE_UT_UT_TIME,[
 AC_TRY_COMPILE([#include <sys/types.h>
@@ -2052,7 +2368,7 @@ AC_TRY_COMPILE([#include <sys/types.h>
 samba_cv_HAVE_UT_UT_TIME=yes,samba_cv_HAVE_UT_UT_TIME=no,samba_cv_HAVE_UT_UT_TIME=cross)])
 if test x"$samba_cv_HAVE_UT_UT_TIME" = x"yes"; then
     AC_DEFINE(HAVE_UT_UT_TIME,1,[Whether the utmp struct has a property ut_time])
-fi 
+fi
 
 AC_CACHE_CHECK([for ut_tv in utmp],samba_cv_HAVE_UT_UT_TV,[
 AC_TRY_COMPILE([#include <sys/types.h>
@@ -2061,7 +2377,7 @@ AC_TRY_COMPILE([#include <sys/types.h>
 samba_cv_HAVE_UT_UT_TV=yes,samba_cv_HAVE_UT_UT_TV=no,samba_cv_HAVE_UT_UT_TV=cross)])
 if test x"$samba_cv_HAVE_UT_UT_TV" = x"yes"; then
     AC_DEFINE(HAVE_UT_UT_TV,1,[Whether the utmp struct has a property ut_tv])
-fi 
+fi
 
 AC_CACHE_CHECK([for ut_type in utmp],samba_cv_HAVE_UT_UT_TYPE,[
 AC_TRY_COMPILE([#include <sys/types.h>
@@ -2070,7 +2386,7 @@ AC_TRY_COMPILE([#include <sys/types.h>
 samba_cv_HAVE_UT_UT_TYPE=yes,samba_cv_HAVE_UT_UT_TYPE=no,samba_cv_HAVE_UT_UT_TYPE=cross)])
 if test x"$samba_cv_HAVE_UT_UT_TYPE" = x"yes"; then
     AC_DEFINE(HAVE_UT_UT_TYPE,1,[Whether the utmp struct has a property ut_type])
-fi 
+fi
 
 AC_CACHE_CHECK([for ut_pid in utmp],samba_cv_HAVE_UT_UT_PID,[
 AC_TRY_COMPILE([#include <sys/types.h>
@@ -2079,7 +2395,7 @@ AC_TRY_COMPILE([#include <sys/types.h>
 samba_cv_HAVE_UT_UT_PID=yes,samba_cv_HAVE_UT_UT_PID=no,samba_cv_HAVE_UT_UT_PID=cross)])
 if test x"$samba_cv_HAVE_UT_UT_PID" = x"yes"; then
     AC_DEFINE(HAVE_UT_UT_PID,1,[Whether the utmp struct has a property ut_pid])
-fi 
+fi
 
 AC_CACHE_CHECK([for ut_exit in utmp],samba_cv_HAVE_UT_UT_EXIT,[
 AC_TRY_COMPILE([#include <sys/types.h>
@@ -2088,7 +2404,7 @@ AC_TRY_COMPILE([#include <sys/types.h>
 samba_cv_HAVE_UT_UT_EXIT=yes,samba_cv_HAVE_UT_UT_EXIT=no,samba_cv_HAVE_UT_UT_EXIT=cross)])
 if test x"$samba_cv_HAVE_UT_UT_EXIT" = x"yes"; then
     AC_DEFINE(HAVE_UT_UT_EXIT,1,[Whether the utmp struct has a property ut_exit])
-fi 
+fi
 
 AC_CACHE_CHECK([for ut_addr in utmp],samba_cv_HAVE_UT_UT_ADDR,[
 AC_TRY_COMPILE([#include <sys/types.h>
@@ -2097,7 +2413,7 @@ AC_TRY_COMPILE([#include <sys/types.h>
 samba_cv_HAVE_UT_UT_ADDR=yes,samba_cv_HAVE_UT_UT_ADDR=no,samba_cv_HAVE_UT_UT_ADDR=cross)])
 if test x"$samba_cv_HAVE_UT_UT_ADDR" = x"yes"; then
     AC_DEFINE(HAVE_UT_UT_ADDR,1,[Whether the utmp struct has a property ut_addr])
-fi 
+fi
 
 if test x$ac_cv_func_pututline = xyes ; then
   AC_CACHE_CHECK([whether pututline returns pointer],samba_cv_PUTUTLINE_RETURNS_UTMP,[
@@ -2117,7 +2433,7 @@ AC_TRY_COMPILE([#include <sys/types.h>
 samba_cv_HAVE_UX_UT_SYSLEN=yes,samba_cv_HAVE_UX_UT_SYSLEN=no,samba_cv_HAVE_UX_UT_SYSLEN=cross)])
 if test x"$samba_cv_HAVE_UX_UT_SYSLEN" = x"yes"; then
     AC_DEFINE(HAVE_UX_UT_SYSLEN,1,[Whether the utmpx struct has a property ut_syslen])
-fi 
+fi
 
 fi
 # end utmp details
@@ -2151,7 +2467,7 @@ dnl Perhaps we should always add a -L
 dnl Check lib and lib32 library variants to cater for IRIX ABI-specific
 dnl installation paths. This gets a little tricky since we might have iconv
 dnl in both libiconv and in libc. In this case the jm_ICONV test will always
-dnl succeed when the header is found. To counter this, make sure the 
+dnl succeed when the header is found. To counter this, make sure the
 dnl library directory is there and check the ABI directory first (which
 dnl should be harmless on other systems.
 dnl For IA64 HPUX systems, the libs are located in lib/hpux32 instead of lib.
@@ -2220,7 +2536,7 @@ dnl        AC_CACHE_CHECK([for working iconv],samba_cv_HAVE_NATIVE_ICONV,[
        
        if test "$default_dos_charset" != "no" -a \
                "$default_dos_charset" != "cross" -a \
-               "$default_display_charset" != "no" -a \ 
+               "$default_display_charset" != "no" -a \
                "$default_display_charset" != "cross" -a \
                "$default_unix_charset" != "no" -a \
                "$default_unix_charset" != "cross"
@@ -2267,7 +2583,7 @@ unset libext
 
 
 if test x"$ICONV_FOUND" = x"no" -o x"$samba_cv_HAVE_NATIVE_ICONV" != x"yes" ; then
-    AC_MSG_WARN([Sufficient support for iconv function was not found. 
+    AC_MSG_WARN([Sufficient support for iconv function was not found.
     Install libiconv from http://freshmeat.net/projects/libiconv/ for better charset compatibility!])
    AC_DEFINE_UNQUOTED(DEFAULT_DOS_CHARSET,"ASCII",[Default dos charset name])
    AC_DEFINE_UNQUOTED(DEFAULT_DISPLAY_CHARSET,"ASCII",[Default display charset name])
@@ -2282,7 +2598,7 @@ AC_TRY_RUN([
 #ifndef F_GETLEASE
 #define F_GETLEASE     1025
 #endif
-main() {
+int main() {
        int fd = open("/dev/null", O_RDONLY);
        return fcntl(fd, F_GETLEASE, 0) == -1;
 }
@@ -2300,8 +2616,8 @@ AC_TRY_RUN([
 #ifndef F_NOTIFY
 #define F_NOTIFY 1026
 #endif
-main() {
-               exit(fcntl(open("/tmp", O_RDONLY), F_NOTIFY, 0) == -1 ?  1 : 0);
+int main() {
+               return fcntl(open("/tmp", O_RDONLY), F_NOTIFY, 0) == -1 ?  1 : 0;
 }
 ],
 samba_cv_HAVE_KERNEL_CHANGE_NOTIFY=yes,samba_cv_HAVE_KERNEL_CHANGE_NOTIFY=no,samba_cv_HAVE_KERNEL_CHANGE_NOTIFY=cross)])
@@ -2309,64 +2625,64 @@ if test x"$samba_cv_HAVE_KERNEL_CHANGE_NOTIFY" = x"yes"; then
     AC_DEFINE(HAVE_KERNEL_CHANGE_NOTIFY,1,[Whether kernel notifies changes])
 fi
 
+AC_CACHE_CHECK([for inotify support],samba_cv_HAVE_INOTIFY,[
+AC_CHECK_HEADERS(linux/inotify.h asm/unistd.h)
+AC_CHECK_FUNC(inotify_init)
+AC_HAVE_DECL(__NR_inotify_init, [#include <asm/unistd.h>])
+],
+samba_cv_HAVE_INOTIFY=yes,
+samba_cv_HAVE_INOTIFY=no,
+samba_cv_HAVE_INOTIFY=cross)
+
+if test x"$ac_cv_func_inotify_init" = x"yes" -a x"$ac_cv_header_linux_inotify_h" = x"yes"; then
+    AC_DEFINE(HAVE_INOTIFY,1,[Whether kernel has inotify support])
+fi
+
 #################################################
 # Check if FAM notifications are available. For FAM info, see
 #      http://oss.sgi.com/projects/fam/
 #      http://savannah.nongnu.org/projects/fam/
+AC_ARG_ENABLE(fam,
+[  --enable-fam            Turn on FAM support (default=auto)])
+
+if test x$enable_fam != xno; then
+    AC_CHECK_HEADERS(fam.h, [samba_cv_HAVE_FAM_H=yes], [samba_cv_HAVE_FAM_H=no])
+    if test x"$samba_cv_HAVE_FAM_H" = x"yes"; then
+        # On IRIX, libfam requires libC, but other FAM implementations
+       # might not need it.
+        AC_CHECK_LIB(fam, FAMOpen2,
+            [samba_cv_HAVE_LIBFAM=yes; SMB_FAM_LIBS="-lfam"],
+            [samba_cv_HAVE_LIBFAM=no])
+
+        if test x"$samba_cv_HAVE_LIBFAM" = x"no" ; then
+            samba_fam_xtra=-lC
+            AC_CHECK_LIB_EXT(fam, samba_fam_xtra, FAMOpen2,
+                [samba_cv_HAVE_LIBFAM=yes; SMB_FAM_LIBS="-lfam -lC"],
+                [samba_cv_HAVE_LIBFAM=no])
+            unset samba_fam_xtra
+        fi
+    fi
 
-AC_CHECK_HEADERS(fam.h, [samba_cv_HAVE_FAM_H=yes], [samba_cv_HAVE_FAM_H=no])
-if test x"$samba_cv_HAVE_FAM_H" = x"yes"; then
-    # On IRIX, libfam requires libC, but other FAM implementations might not
-    # need it.
-    AC_CHECK_LIB(fam, FAMOpen2,
-           [samba_cv_HAVE_LIBFAM=yes; samba_fam_libs="-lfam"],
-           [samba_cv_HAVE_LIBFAM=no])
-
-    if test x"$samba_cv_HAVE_LIBFAM" = x"no" ; then
-       samba_fam_xtra=-lC
-       AC_CHECK_LIB_EXT(fam, samba_fam_xtra, FAMOpen2,
-               [samba_cv_HAVE_LIBFAM=yes; samba_fam_libs="-lfam -lC"],
-               [samba_cv_HAVE_LIBFAM=no])
-       unset samba_fam_xtra
+    if test x"$samba_cv_HAVE_LIBFAM" = x"yes" ; then
+        default_shared_modules="$default_shared_modules vfs_notify_fam"
+        AC_TRY_COMPILE([#include <fam.h>],
+                    [FAMCodes code = FAMChanged;],
+                    AC_DEFINE(HAVE_FAM_H_FAMCODES_TYPEDEF, 1,
+                        [Whether fam.h contains a typedef for enum FAMCodes]),
+                    [])
     fi
-fi
 
-if test x"$samba_cv_HAVE_LIBFAM" = x"yes" ; then
-    AC_DEFINE(HAVE_FAM_CHANGE_NOTIFY, 1,
-           [Whether FAM is file notifications are available])
-    AC_TRY_COMPILE([#include <fam.h>],
-               [FAMCodes code = FAMChanged;],
-               AC_DEFINE(HAVE_FAM_H_FAMCODES_TYPEDEF, 1,
-                   [Whether fam.h contains a typedef for enum FAMCodes]),
-               [])
+    if test x$enable_fam = xyes && test x"$samba_cv_HAVE_LIBFAM" != xyes ; then
+        AC_MSG_ERROR(FAM support requested but FAM library not available )
+    fi
 fi
 
+AC_SUBST(SMB_FAM_LIBS)
+
 #################################################
 # Check for DMAPI interfaces in libdm/libjfsdm/libxsdm
 
-AC_CHECK_LIB(dm, dm_get_eventlist,
-       [samba_cv_HAVE_LIBDM=yes; samba_dmapi_libs="-ldm"],
-       [samba_cv_HAVE_LIBDM=no])
-
-if test x"$samba_cv_HAVE_LIBDM" = x"yes" ; then
-       AC_DEFINE(HAVE_LIBDM, 1, [Whether dmapi libdm is available])
-fi
-
-AC_CHECK_LIB(jfsdm, dm_get_eventlist,
-       [samba_cv_HAVE_LIBJFSDM=yes; samba_dmapi_libs="-ljfsdm"],
-       [samba_cv_HAVE_LIBJFSDM=no])
-
-if test x"$samba_cv_HAVE_LIBJFSDM" = x"yes" ; then
-       AC_DEFINE(HAVE_LIBJFSDM, 1, [Whether dmapi libjfsdm is available])
-fi
-
-AC_CHECK_LIB(xdsm, dm_get_eventlist,
-       [samba_cv_HAVE_LIBXDSM=yes; samba_dmapi_libs="-lxdsm"],
-       [samba_cv_HAVE_LIBXDSM=no])
-
-if test x"$samba_cv_HAVE_LIBXDSM" = x"yes" ; then
-       AC_DEFINE(HAVE_LIBXDSM, 1, [Whether dmapi libxdsm is available])
-fi
+SMB_CHECK_DMAPI([], AC_MSG_NOTICE(DMAPI support not present) )
 
 AC_CACHE_CHECK([for kernel share modes],samba_cv_HAVE_KERNEL_SHARE_MODES,[
 AC_TRY_RUN([
@@ -2378,8 +2694,8 @@ AC_TRY_RUN([
 #define LOCK_MAND      32
 #define LOCK_READ      64
 #endif
-main() {
-               exit(flock(open("/dev/null", O_RDWR), LOCK_MAND|LOCK_READ) != 0);
+int main() {
+               return flock(open("/dev/null", O_RDWR), LOCK_MAND|LOCK_READ) != 0;
 }
 ],
 samba_cv_HAVE_KERNEL_SHARE_MODES=yes,samba_cv_HAVE_KERNEL_SHARE_MODES=no,samba_cv_HAVE_KERNEL_SHARE_MODES=cross)])
@@ -2415,15 +2731,15 @@ if test x"$samba_cv_HAVE_SYS_CAPABILITY_H" = x"yes"; then
                AC_TRY_RUN([
 #include <sys/types.h>
 #include <sys/capability.h>
-main() {
+int main() {
  cap_t cap;
  cap_value_t vals[1];
  if (!(cap = cap_get_proc()))
-   exit(1);
+   return 1;
  vals[0] = CAP_CHOWN;
  cap_set_flag(cap, CAP_INHERITABLE, 1, vals, CAP_CLEAR);
  cap_set_proc(cap);
exit(0);
return 0;
 }],
                samba_cv_HAVE_POSIX_CAPABILITIES=yes,
                samba_cv_HAVE_POSIX_CAPABILITIES=no,
@@ -2540,54 +2856,20 @@ if test x"$samba_cv_HAVE_BROKEN_GETGROUPS" = x"yes"; then
     AC_DEFINE(HAVE_BROKEN_GETGROUPS,1,[Whether getgroups is broken])
 fi
 
-AC_CACHE_CHECK([whether getpass should be replaced],samba_cv_REPLACE_GETPASS,[
-SAVE_CPPFLAGS="$CPPFLAGS"
-CPPFLAGS="$CPPFLAGS -I${srcdir-.}/ -I${srcdir-.}/include -I${srcdir-.}/ubiqx -I${srcdir-.}/popt"
-AC_TRY_COMPILE([
-#define REPLACE_GETPASS 1
-#define NO_PROTO_H 1
-#define NO_CONFIG_H 1
-#define main dont_declare_main
-#include "${srcdir-.}/lib/getsmbpass.c"
-#undef main
-],[],samba_cv_REPLACE_GETPASS=yes,samba_cv_REPLACE_GETPASS=no)
-CPPFLAGS="$SAVE_CPPFLAGS"
-])
-if test x"$samba_cv_REPLACE_GETPASS" = x"yes"; then
-       AC_DEFINE(REPLACE_GETPASS,1,[Whether getpass should be replaced])
-fi
-
-AC_CACHE_CHECK([for broken inet_ntoa],samba_cv_REPLACE_INET_NTOA,[
-AC_TRY_RUN([
-#include <stdio.h>
-#include <sys/types.h>
-#include <netinet/in.h>
-#ifdef HAVE_ARPA_INET_H
-#include <arpa/inet.h>
-#endif
-main() { struct in_addr ip; ip.s_addr = 0x12345678;
-if (strcmp(inet_ntoa(ip),"18.52.86.120") &&
-    strcmp(inet_ntoa(ip),"120.86.52.18")) { exit(0); } 
-exit(1);}],
-           samba_cv_REPLACE_INET_NTOA=yes,samba_cv_REPLACE_INET_NTOA=no,samba_cv_REPLACE_INET_NTOA=cross)])
-if test x"$samba_cv_REPLACE_INET_NTOA" = x"yes"; then
-    AC_DEFINE(REPLACE_INET_NTOA,1,[Whether inet_ntoa should be replaced])
-fi
-
 AC_CACHE_CHECK([for secure mkstemp],samba_cv_HAVE_SECURE_MKSTEMP,[
 AC_TRY_RUN([#include <stdlib.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <unistd.h>
-main() { 
+int main() {
   struct stat st;
-  char tpl[20]="/tmp/test.XXXXXX"; 
-  int fd = mkstemp(tpl); 
-  if (fd == -1) exit(1);
+  char tpl[20]="/tmp/test.XXXXXX";
+  int fd = mkstemp(tpl);
+  if (fd == -1) return 1;
   unlink(tpl);
-  if (fstat(fd, &st) != 0) exit(1);
-  if ((st.st_mode & 0777) != 0600) exit(1);
-  exit(0);
+  if (fstat(fd, &st) != 0) return 1;
+  if ((st.st_mode & 0777) != 0600) return 1;
+  return 0;
 }],
 samba_cv_HAVE_SECURE_MKSTEMP=yes,
 samba_cv_HAVE_SECURE_MKSTEMP=no,
@@ -2597,7 +2879,12 @@ if test x"$samba_cv_HAVE_SECURE_MKSTEMP" = x"yes"; then
 fi
 
 AC_CACHE_CHECK([for broken readdir],samba_cv_HAVE_BROKEN_READDIR,[
-       AC_TRY_RUN([#include "${srcdir-.}/tests/os2_delete.c"],
+       AC_TRY_RUN([
+#include "${srcdir-.}/lib/replace/test/os2_delete.c"
+int main(void) {
+    return test_readdir_os2_delete();
+}
+],
                [samba_cv_HAVE_BROKEN_READDIR=no],
                        [samba_cv_HAVE_BROKEN_READDIR=yes],
                        [samba_cv_HAVE_BROKEN_READDIR="assuming not"])])
@@ -2606,7 +2893,10 @@ if test x"$samba_cv_HAVE_BROKEN_READDIR" = x"yes"; then
 AC_CACHE_CHECK([for replacing readdir],samba_cv_REPLACE_READDIR,[
        AC_TRY_RUN([
 #include "${srcdir-.}/lib/repdir.c"
-#include "${srcdir-.}/tests/os2_delete.c"],
+#include "${srcdir-.}/lib/replace/test/os2_delete.c"
+int main(void) {
+    return test_readdir_os2_delete();
+],
        samba_cv_REPLACE_READDIR=yes,samba_cv_REPLACE_READDIR=no)])
 fi
 
@@ -2614,53 +2904,39 @@ if test x"$samba_cv_REPLACE_READDIR" = x"yes"; then
        AC_DEFINE(REPLACE_READDIR,1,[replace readdir])
 fi
 
-AC_CACHE_CHECK([for sysconf(_SC_NGROUPS_MAX)],samba_cv_SYSCONF_SC_NGROUPS_MAX,[
-AC_TRY_RUN([#include <unistd.h>
-main() { exit(sysconf(_SC_NGROUPS_MAX) == -1 ? 1 : 0); }],
-samba_cv_SYSCONF_SC_NGROUPS_MAX=yes,samba_cv_SYSCONF_SC_NGROUPS_MAX=no,samba_cv_SYSCONF_SC_NGROUPS_MAX=cross)])
-if test x"$samba_cv_SYSCONF_SC_NGROUPS_MAX" = x"yes"; then
-    AC_DEFINE(SYSCONF_SC_NGROUPS_MAX,1,[Whether sysconf(_SC_NGROUPS_MAX) is available])
-fi
-
-AC_CACHE_CHECK([for sysconf(_SC_NPROC_ONLN)],samba_cv_SYSCONF_SC_NPROC_ONLN,[
-AC_TRY_RUN([#include <unistd.h>
-main() { exit(sysconf(_SC_NPROC_ONLN) == -1 ? 1 : 0); }],
-samba_cv_SYSCONF_SC_NPROC_ONLN=yes,samba_cv_SYSCONF_SC_NPROC_ONLN=no,samba_cv_SYSCONF_SC_NPROC_ONLN=cross)])
-if test x"$samba_cv_SYSCONF_SC_NPROC_ONLN" = x"yes"; then
-    AC_DEFINE(SYSCONF_SC_NPROC_ONLN,1,[Whether sysconf(_SC_NPROC_ONLN) is available])
-fi
-
-AC_CACHE_CHECK([for root],samba_cv_HAVE_ROOT,[
-AC_TRY_RUN([main() { exit(getuid() != 0); }],
-           samba_cv_HAVE_ROOT=yes,samba_cv_HAVE_ROOT=no,samba_cv_HAVE_ROOT=cross)])
-if test x"$samba_cv_HAVE_ROOT" = x"yes"; then
-    AC_DEFINE(HAVE_ROOT,1,[Whether current user is root])
-else
-    AC_MSG_WARN(running as non-root will disable some tests)
-fi
+SMB_CHECK_SYSCONF(_SC_NGROUPS_MAX)
+SMB_CHECK_SYSCONF(_SC_NPROC_ONLN)
+SMB_CHECK_SYSCONF(_SC_NPROCESSORS_ONLN)
+SMB_CHECK_SYSCONF(_SC_PAGESIZE)
+AC_CHECK_FUNCS(getpagesize)
 
 ##################
 # look for a method of finding the list of network interfaces
 iface=no;
 AC_CACHE_CHECK([for iface AIX],samba_cv_HAVE_IFACE_AIX,[
+SAVE_CPPFLAGS="$CPPFLAGS"
+CPPFLAGS="$CPPFLAGS ${SAMBA_CONFIGURE_CPPFLAGS}"
 AC_TRY_RUN([
 #define HAVE_IFACE_AIX 1
 #define AUTOCONF_TEST 1
-#include "confdefs.h"
+#undef _XOPEN_SOURCE_EXTENDED
 #include "${srcdir-.}/lib/interfaces.c"],
            samba_cv_HAVE_IFACE_AIX=yes,samba_cv_HAVE_IFACE_AIX=no,samba_cv_HAVE_IFACE_AIX=cross)])
+CPPFLAGS="$SAVE_CPPFLAGS"
 if test x"$samba_cv_HAVE_IFACE_AIX" = x"yes"; then
     iface=yes;AC_DEFINE(HAVE_IFACE_AIX,1,[Whether iface AIX is available])
 fi
 
 if test $iface = no; then
 AC_CACHE_CHECK([for iface ifconf],samba_cv_HAVE_IFACE_IFCONF,[
+SAVE_CPPFLAGS="$CPPFLAGS"
+CPPFLAGS="$CPPFLAGS ${SAMBA_CONFIGURE_CPPFLAGS}"
 AC_TRY_RUN([
 #define HAVE_IFACE_IFCONF 1
 #define AUTOCONF_TEST 1
-#include "confdefs.h"
 #include "${srcdir-.}/lib/interfaces.c"],
            samba_cv_HAVE_IFACE_IFCONF=yes,samba_cv_HAVE_IFACE_IFCONF=no,samba_cv_HAVE_IFACE_IFCONF=cross)])
+CPPFLAGS="$SAVE_CPPFLAGS"
 if test x"$samba_cv_HAVE_IFACE_IFCONF" = x"yes"; then
     iface=yes;AC_DEFINE(HAVE_IFACE_IFCONF,1,[Whether iface ifconf is available])
 fi
@@ -2668,12 +2944,14 @@ fi
 
 if test $iface = no; then
 AC_CACHE_CHECK([for iface ifreq],samba_cv_HAVE_IFACE_IFREQ,[
+SAVE_CPPFLAGS="$CPPFLAGS"
+CPPFLAGS="$CPPFLAGS ${SAMBA_CONFIGURE_CPPFLAGS}"
 AC_TRY_RUN([
 #define HAVE_IFACE_IFREQ 1
 #define AUTOCONF_TEST 1
-#include "confdefs.h"
 #include "${srcdir-.}/lib/interfaces.c"],
            samba_cv_HAVE_IFACE_IFREQ=yes,samba_cv_HAVE_IFACE_IFREQ=no,samba_cv_HAVE_IFACE_IFREQ=cross)])
+CPPFLAGS="$SAVE_CPPFLAGS"
 if test x"$samba_cv_HAVE_IFACE_IFREQ" = x"yes"; then
     iface=yes;AC_DEFINE(HAVE_IFACE_IFREQ,1,[Whether iface ifreq is available])
 fi
@@ -2762,7 +3040,7 @@ else
 dnl
 dnl Don't check for 64 bit fcntl locking if we know that the
 dnl glibc2.1 broken check has succeeded.
-dnl 
+dnl
 
   AC_CACHE_CHECK([for 64 bit fcntl locking],samba_cv_HAVE_STRUCT_FLOCK64,[
   AC_TRY_RUN([
@@ -2779,11 +3057,11 @@ dnl
 #ifdef HAVE_SYS_FCNTL_H
 #include <sys/fcntl.h>
 #endif
-main() { struct flock64 fl64;
+int main() { struct flock64 fl64;
 #if defined(F_SETLKW64) && defined(F_SETLK64) && defined(F_GETLK64)
-exit(0);
+return 0;
 #else
-exit(1);
+return 1;
 #endif
 }],
        samba_cv_HAVE_STRUCT_FLOCK64=yes,samba_cv_HAVE_STRUCT_FLOCK64=no,samba_cv_HAVE_STRUCT_FLOCK64=cross)])
@@ -2801,7 +3079,7 @@ AC_TRY_COMPILE([#include <sys/types.h>
 samba_cv_HAVE_STAT_ST_BLOCKS=yes,samba_cv_HAVE_STAT_ST_BLOCKS=no,samba_cv_HAVE_STAT_ST_BLOCKS=cross)])
 if test x"$samba_cv_HAVE_STAT_ST_BLOCKS" = x"yes"; then
     AC_DEFINE(HAVE_STAT_ST_BLOCKS,1,[Whether the stat struct has a st_block property])
-fi 
+fi
 
 AC_CACHE_CHECK([for st_blksize in struct stat],samba_cv_HAVE_STAT_ST_BLKSIZE,[
 AC_TRY_COMPILE([#include <sys/types.h>
@@ -2813,6 +3091,23 @@ if test x"$samba_cv_HAVE_STAT_ST_BLKSIZE" = x"yes"; then
     AC_DEFINE(HAVE_STAT_ST_BLKSIZE,1,[Whether the stat struct has a st_blksize property])
 fi
 
+AC_CACHE_CHECK([for st_flags in struct stat],
+       samba_cv_HAVE_STAT_ST_FLAGS,
+       [
+           AC_TRY_COMPILE([#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>],
+           [struct stat st;  st.st_flags = 0;],
+           samba_cv_HAVE_STAT_ST_FLAGS=yes,
+           samba_cv_HAVE_STAT_ST_FLAGS=no,
+           samba_cv_HAVE_STAT_ST_FLAGS=cross)
+       ])
+
+if test x"$samba_cv_HAVE_STAT_ST_FLAGS" = x"yes"; then
+    AC_DEFINE(HAVE_STAT_ST_FLAGS, 1,
+               [Whether the stat struct has a st_flags member])
+fi
+
 case "$host_os" in
 *linux*)
 AC_CACHE_CHECK([for broken RedHat 7.2 system header files],samba_cv_BROKEN_REDHAT_7_SYSTEM_HEADERS,[
@@ -2847,10 +3142,11 @@ fi
 AC_CACHE_CHECK([if the realpath function allows a NULL argument],samba_cv_REALPATH_TAKES_NULL,[
 AC_TRY_RUN([
 #include <stdio.h>
+#include <stdlib.h>
 #include <limits.h>
-main() {
+int main() {
        char *newpath = realpath("/tmp", NULL);
-       exit ((newpath != NULL) ? 0 : 1);
+       return (newpath != NULL) ? 0 : 1;
 }
 ],
 samba_cv_REALPATH_TAKES_NULL=yes,samba_cv_REALPATH_TAKES_NULL=no,samba_cv_REALPATH_TAKES_NULL=cross)])
@@ -2858,47 +3154,6 @@ if test x"$samba_cv_REALPATH_TAKES_NULL" = x"yes"; then
     AC_DEFINE(REALPATH_TAKES_NULL,1,[Whether the realpath function allows NULL])
 fi
 
-#################################################
-# check for smbwrapper support
-AC_MSG_CHECKING(whether to use smbwrapper)
-AC_ARG_WITH(smbwrapper,
-[  --with-smbwrapper       Include SMB wrapper support (default=no) ],
-[ case "$withval" in
-  yes)
-    AC_MSG_RESULT(yes)
-    AC_DEFINE(WITH_SMBWRAPPER,1,[Whether to include smbwrapper support])
-       WRAPPROG="bin/smbsh\$(EXEEXT)"
-       WRAP="bin/smbwrapper.$SHLIBEXT"
-       WRAP_OBJS="\$(SMBW_OBJ1) \$(SMBWRAPPER_OBJ1)"
-       WRAP_INC="-I\$(srcdir)/smbwrapper"
-
-# Conditions under which smbwrapper should not be built.
-
-       if test x$PICFLAGS = x; then
-          echo No support for PIC code - disabling smbwrapper and smbsh
-          WRAPPROG=""
-          WRAP=""
-          WRAP_OBJS=""
-          WRAP_INC=""
-       elif test x$ac_cv_func_syscall = xno; then
-          AC_MSG_RESULT([No syscall() -- disabling smbwrapper and smbsh])
-          WRAPPROG=""
-          WRAP=""
-          WRAP_OBJS=""
-          WRAP_INC=""
-       fi
-       EXTRA_ALL_TARGETS="$EXTRA_ALL_TARGETS $WRAPPROG $WRAP"
-       SMBWRAPPER="$WRAPPROG $WRAP"
-       SMBWRAP_OBJS="$WRAP_OBJS"
-       SMBWRAP_INC="$WRAP_INC"
-    ;;
-  *)
-    AC_MSG_RESULT(no)
-    ;;
-  esac ],
-  AC_MSG_RESULT(no)
-)
-
 #################################################
 # check for AFS clear-text auth support
 samba_cv_WITH_AFS=no
@@ -2949,7 +3204,7 @@ if test x"$samba_cv_WITH_AFS" != x"no" ||
     else
       AC_MSG_RESULT(no)
     fi
-   
+
     # check for afs.h
     have_afs_headers=no
     AC_CHECK_HEADERS(afs.h afs/afs.h)
@@ -2972,7 +3227,7 @@ fi
 #################################################
 # check whether to compile AFS/NT ACL mapping module
 samba_cv_WITH_VFS_AFSACL=no
-AC_MSG_CHECKING(whether to use AFS fake-kaserver)
+AC_MSG_CHECKING(whether to use AFS ACL mapping module)
 AC_ARG_WITH(vfs-afsacl,
 [  --with-vfs-afsacl       Include AFS to NT ACL mapping module (default=no) ],
 [ case "$withval" in
@@ -3032,13 +3287,16 @@ SMBLDAP=""
 AC_SUBST(SMBLDAP)
 SMBLDAPUTIL=""
 AC_SUBST(SMBLDAPUTIL)
+LDBLDAP=""
+AC_SUBST(LDBLDAP)
+
 if test x"$with_ldap_support" != x"no"; then
 
   ##################################################################
   # first test for ldap.h and lber.h
   # (ldap.h is required for this test)
   AC_CHECK_HEADERS(ldap.h lber.h)
-  
+
   if test x"$ac_cv_header_ldap_h" != x"yes"; then
        if test x"$with_ldap_support" = x"yes"; then
         AC_MSG_ERROR(ldap.h is needed for LDAP support)
@@ -3048,6 +3306,28 @@ if test x"$with_ldap_support" != x"no"; then
        
        with_ldap_support=no
   fi
+
+  ##################################################################
+  # HP/UX does not have ber_tag_t in lber.h - it must be configured as
+  # unsigned int in include/includes.h
+  case $host_os in
+       *hpux*)
+        AC_MSG_WARN(ber_tag_t is needed for LDAP support)
+        AC_MSG_WARN(ber_tag_t must be configured in includes.h for hpux)
+       with_ldap_support=yes
+       ;;
+       *)
+       AC_CHECK_TYPE(ber_tag_t,,,[#include <lber.h>])
+       if test x"$ac_cv_type_ber_tag_t" != x"yes"; then
+               if test x"$with_ldap_support" = x"yes"; then
+               AC_MSG_ERROR(ber_tag_t is needed for LDAP support)
+               else
+               AC_MSG_WARN(ber_tag_t is needed for LDAP support)
+               fi
+               with_ldap_support=no
+       fi
+       ;;
+  esac
 fi
 
 if test x"$with_ldap_support" != x"no"; then
@@ -3071,17 +3351,17 @@ if test x"$with_ldap_support" != x"no"; then
   AC_CACHE_CHECK(whether ldap_set_rebind_proc takes 3 arguments, smb_ldap_cv_ldap_set_rebind_proc, [
     AC_TRY_COMPILE([
        #include <lber.h>
-       #include <ldap.h>], 
-       [ldap_set_rebind_proc(0, 0, 0);], 
-       [smb_ldap_cv_ldap_set_rebind_proc=3], 
+       #include <ldap.h>],
+       [ldap_set_rebind_proc(0, 0, 0);],
+       [smb_ldap_cv_ldap_set_rebind_proc=3],
        [smb_ldap_cv_ldap_set_rebind_proc=2]
-    ) 
+    )
   ])
-  
+
   AC_DEFINE_UNQUOTED(LDAP_SET_REBIND_PROC_ARGS, $smb_ldap_cv_ldap_set_rebind_proc, [Number of arguments to ldap_set_rebind_proc])
 
-  AC_CHECK_FUNC_EXT(ldap_dn2ad_canonical,$LDAP_LIBS)   
-  
+  AC_CHECK_FUNC_EXT(ldap_initialize,$LDAP_LIBS)
+
   if test x"$ac_cv_lib_ext_ldap_ldap_init" = x"yes"; then
     AC_DEFINE(HAVE_LDAP,1,[Whether ldap is available])
     CPPFLAGS="$CPPFLAGS -DLDAP_DEPRECATED"
@@ -3089,6 +3369,12 @@ if test x"$with_ldap_support" != x"no"; then
     default_shared_modules="$default_shared_modules";
     SMBLDAP="lib/smbldap.o"
     SMBLDAPUTIL="lib/smbldap_util.o"
+    if test x"$ac_cv_func_ext_ldap_initialize" != x"yes"; then
+      AC_MSG_WARN(Disabling ldb_ldap support (requires ldap_initialize))
+    else
+      AC_DEFINE(HAVE_LDB_LDAP,1,[Whether ldb_ldap is available])
+      LDBLDAP="lib/ldb/ldb_ldap/ldb_ldap.o"
+    fi
     with_ldap_support=yes
     AC_MSG_CHECKING(whether LDAP support is used)
     AC_MSG_RESULT(yes)
@@ -3098,7 +3384,7 @@ if test x"$with_ldap_support" != x"no"; then
     else
        AC_MSG_WARN(libldap is needed for LDAP support)
     fi
-    
+
     LDAP_LIBS=""
     with_ldap_support=no
   fi
@@ -3126,49 +3412,66 @@ FOUND_KRB5=no
 KRB5_LIBS=""
 
 if test x"$with_ldap_support" != x"yes"; then
+
     if test x"$with_ads_support" = x"yes"; then
        AC_MSG_ERROR(Active Directory Support requires LDAP support)
-    elif test x"$with_ads_support" != x"no"; then
-       AC_MSG_WARN(Active Directory Support requires LDAP support)
+    elif test x"$with_ads_support" = x"auto"; then
+       AC_MSG_WARN(Disabling Active Directory support (requires LDAP support))
+       with_ads_support=no
     fi
-    with_ads_support=no
-fi
 
-AC_CHECK_FUNC_EXT(ldap_initialize,$LDAP_LIBS)
-
-if test x"$ac_cv_func_ext_ldap_initialize" != x"yes"; then
-    if test x"$with_ads_support" = x"yes"; then
-        AC_MSG_ERROR(Active Directory Support requires ldap_initialize)
-    fi
-    AC_MSG_WARN(Active Directory Support requires ldap_initialize)
-    with_ads_support=no
-fi
+else
 
-AC_CHECK_FUNC_EXT(ldap_domain2hostlist,$LDAP_LIBS)
+    # Check to see whether there is enough LDAP functionality to be able
+    # to build AD support.
 
-if test x"$ac_cv_func_ext_ldap_domain2hostlist" != x"yes"; then
-    if test x"$with_ads_support" = x"yes"; then
-        AC_MSG_ERROR(Active Directory Support requires ldap_domain2hostlist)
+# HPUX only has ldap_init; ok, we take care of this in smbldap.c
+case "$host_os" in
+       *hpux*)
+    AC_CHECK_FUNC_EXT(ldap_init,$LDAP_LIBS)
+
+    if test x"$ac_cv_func_ext_ldap_init" != x"yes"; then
+       if test x"$with_ads_support" = x"yes"; then
+           AC_MSG_ERROR(Active Directory support on HPUX requires ldap_init)
+       elif test x"$with_ads_support" = x"auto"; then
+           AC_MSG_WARN(Disabling Active Directory support (requires ldap_init on HPUX))
+           with_ads_support=no
+       fi
     fi
-    AC_MSG_WARN(Active Directory Support requires ldap_domain2hostlist)
-    with_ads_support=no
-fi
+    ;;
+       *)
+    AC_CHECK_FUNC_EXT(ldap_initialize,$LDAP_LIBS)
+
+    if test x"$ac_cv_func_ext_ldap_initialize" != x"yes"; then
+       if test x"$with_ads_support" = x"yes"; then
+           AC_MSG_ERROR(Active Directory support requires ldap_initialize)
+       elif test x"$with_ads_support" = x"auto"; then
+           AC_MSG_WARN(Disabling Active Directory support (requires ldap_initialize))
+           with_ads_support=no
+       fi
+    fi
+    ;;
+esac
 
-AC_CHECK_FUNC_EXT(ldap_add_result_entry,$LDAP_LIBS)
 
-if test x"$ac_cv_func_ext_ldap_add_result_entry" != x"yes"; then
-    if test x"$with_ads_support" = x"yes"; then
-        AC_MSG_ERROR(Active Directory Support requires ldap_add_result_entry)
+    AC_CHECK_FUNC_EXT(ldap_add_result_entry,$LDAP_LIBS)
+
+    if test x"$ac_cv_func_ext_ldap_add_result_entry" != x"yes"; then
+       if test x"$with_ads_support" = x"yes"; then
+           AC_MSG_ERROR(Active Directory support requires ldap_add_result_entry)
+       elif test x"$with_ads_support" = x"auto"; then
+           AC_MSG_WARN(Disabling Active Directory support (requires ldap_add_result_entry))
+           with_ads_support=no
+       fi
     fi
-    AC_MSG_WARN(Active Directory Support requires ldap_add_result_entry)
-    with_ads_support=no
+
 fi
 
 if test x"$with_ads_support" != x"no"; then
 
   # Do no harm to the values of CFLAGS and LIBS while testing for
   # Kerberos support.
+
   if test x$FOUND_KRB5 = x"no"; then
     #################################################
     # check for location of Kerberos 5 install
@@ -3209,7 +3512,7 @@ if test x"$with_ads_support" != x"no"; then
     LDFLAGS="";export LDFLAGS
     KRB5_LIBS="`$KRB5CONFIG --libs gssapi`"
     KRB5_LDFLAGS="`$KRB5CONFIG --libs gssapi | sed s/-lgss.*//`"
-    KRB5_CFLAGS="`$KRB5CONFIG --cflags | sed s/@INCLUDE_des@//`" 
+    KRB5_CFLAGS="`$KRB5CONFIG --cflags | sed s/@INCLUDE_des@//`"
     KRB5_CPPFLAGS="`$KRB5CONFIG --cflags | sed s/@INCLUDE_des@//`"
     CFLAGS=$ac_save_CFLAGS;export CFLAGS
     LDFLAGS=$ac_save_LDFLAGS;export LDFLAGS
@@ -3218,7 +3521,7 @@ if test x"$with_ads_support" != x"no"; then
   else
     AC_MSG_RESULT(no. Fallback to previous krb5 detection strategy)
   fi
+
   if test x$FOUND_KRB5 = x"no"; then
     #################################################
     # see if this box has the SuSE location for the heimdal krb implementation
@@ -3282,16 +3585,19 @@ if test x"$with_ads_support" != x"no"; then
     # Turn off AD support and restore CFLAGS and LIBS variables
 
     with_ads_support="no"
-    
+
     CFLAGS=$ac_save_CFLAGS
     CPPFLAGS=$ac_save_CPPFLAGS
     LDFLAGS=$ac_save_LDFLAGS
   fi
+  AC_CHECK_HEADERS(krb5/locate_plugin.h)
 fi
 
 # Now we have determined whether we really want ADS support
-
+use_ads=no
 if test x"$with_ads_support" != x"no"; then
+  use_ads=yes
+  have_gssapi=no
   ac_save_LIBS=$LIBS
 
   # now check for gssapi headers.  This is also done here to allow for
@@ -3309,8 +3615,7 @@ if test x"$with_ads_support" != x"no"; then
   AC_CHECK_LIB_EXT(roken, KRB5_LIBS, roken_getaddrinfo_hostspec)
 
   # Heimdal checks. On static Heimdal gssapi must be linked before krb5.
-  AC_CHECK_LIB_EXT(gssapi, KRB5_LIBS, gss_display_status,[],[],
-                               AC_DEFINE(HAVE_GSSAPI,1,[Whether GSSAPI is available]))
+  AC_CHECK_LIB_EXT(gssapi, KRB5_LIBS, gss_display_status,[],[],have_gssapi=yes)
 
   ########################################################
   # now see if we can find the krb5 libs in standard paths
@@ -3320,37 +3625,38 @@ if test x"$with_ads_support" != x"no"; then
 
   ########################################################
   # now see if we can find the gssapi libs in standard paths
-  AC_CHECK_LIB_EXT(gssapi_krb5, KRB5_LIBS,gss_display_status,[],[],
-           AC_DEFINE(HAVE_GSSAPI,1,[Whether GSSAPI is available]))
+  if test x"$have_gssapi" != x"yes"; then
+     AC_CHECK_LIB_EXT(gssapi_krb5, KRB5_LIBS,gss_display_status,[],[],have_gssapi=yes)
+  fi
 
   AC_CHECK_FUNC_EXT(krb5_set_real_time, $KRB5_LIBS)
   AC_CHECK_FUNC_EXT(krb5_set_default_in_tkt_etypes, $KRB5_LIBS)
+  AC_CHECK_FUNC_EXT(krb5_set_default_tgs_enctypes, $KRB5_LIBS)
   AC_CHECK_FUNC_EXT(krb5_set_default_tgs_ktypes, $KRB5_LIBS)
   AC_CHECK_FUNC_EXT(krb5_principal2salt, $KRB5_LIBS)
   AC_CHECK_FUNC_EXT(krb5_use_enctype, $KRB5_LIBS)
-  AC_CHECK_FUNC_EXT(krb5_string_to_key, $KRB5_LIBS) 
+  AC_CHECK_FUNC_EXT(krb5_string_to_key, $KRB5_LIBS)
   AC_CHECK_FUNC_EXT(krb5_get_pw_salt, $KRB5_LIBS)
-  AC_CHECK_FUNC_EXT(krb5_string_to_key_salt, $KRB5_LIBS) 
+  AC_CHECK_FUNC_EXT(krb5_string_to_key_salt, $KRB5_LIBS)
   AC_CHECK_FUNC_EXT(krb5_auth_con_setkey, $KRB5_LIBS)
-  AC_CHECK_FUNC_EXT(krb5_auth_con_setuseruserkey, $KRB5_LIBS) 
+  AC_CHECK_FUNC_EXT(krb5_auth_con_setuseruserkey, $KRB5_LIBS)
   AC_CHECK_FUNC_EXT(krb5_locate_kdc, $KRB5_LIBS)
-  AC_CHECK_FUNC_EXT(krb5_get_permitted_enctypes, $KRB5_LIBS) 
-  AC_CHECK_FUNC_EXT(krb5_get_default_in_tkt_etypes, $KRB5_LIBS) 
-  AC_CHECK_FUNC_EXT(krb5_free_ktypes, $KRB5_LIBS)
+  AC_CHECK_FUNC_EXT(krb5_get_permitted_enctypes, $KRB5_LIBS)
+  AC_CHECK_FUNC_EXT(krb5_get_default_in_tkt_etypes, $KRB5_LIBS)
   AC_CHECK_FUNC_EXT(krb5_free_data_contents, $KRB5_LIBS)
   AC_CHECK_FUNC_EXT(krb5_principal_get_comp_string, $KRB5_LIBS)
   AC_CHECK_FUNC_EXT(krb5_free_unparsed_name, $KRB5_LIBS)
   AC_CHECK_FUNC_EXT(krb5_free_keytab_entry_contents, $KRB5_LIBS)
   AC_CHECK_FUNC_EXT(krb5_kt_free_entry, $KRB5_LIBS)
+  AC_CHECK_FUNC_EXT(krb5_krbhst_init, $KRB5_LIBS)
   AC_CHECK_FUNC_EXT(krb5_krbhst_get_addrinfo, $KRB5_LIBS)
   AC_CHECK_FUNC_EXT(krb5_c_enctype_compare, $KRB5_LIBS)
   AC_CHECK_FUNC_EXT(krb5_enctypes_compatible_keys, $KRB5_LIBS)
   AC_CHECK_FUNC_EXT(krb5_crypto_init, $KRB5_LIBS)
   AC_CHECK_FUNC_EXT(krb5_crypto_destroy, $KRB5_LIBS)
   AC_CHECK_FUNC_EXT(krb5_decode_ap_req, $KRB5_LIBS)
-  AC_CHECK_FUNC_EXT(decode_krb5_ap_req, $KRB5_LIBS)
-  AC_CHECK_FUNC_EXT(krb5_free_ap_req, $KRB5_LIBS)
   AC_CHECK_FUNC_EXT(free_AP_REQ, $KRB5_LIBS)
+  AC_CHECK_FUNC_EXT(krb5_verify_checksum, $KRB5_LIBS)
   AC_CHECK_FUNC_EXT(krb5_c_verify_checksum, $KRB5_LIBS)
   AC_CHECK_FUNC_EXT(krb5_principal_compare_any_realm, $KRB5_LIBS)
   AC_CHECK_FUNC_EXT(krb5_parse_name_norealm, $KRB5_LIBS)
@@ -3358,16 +3664,66 @@ if test x"$with_ads_support" != x"no"; then
   AC_CHECK_FUNC_EXT(krb5_get_init_creds_opt_set_pac_request, $KRB5_LIBS)
   AC_CHECK_FUNC_EXT(krb5_get_renewed_creds, $KRB5_LIBS)
   AC_CHECK_FUNC_EXT(krb5_get_kdc_cred, $KRB5_LIBS)
+  AC_CHECK_FUNC_EXT(krb5_free_error_contents, $KRB5_LIBS)
+  AC_CHECK_FUNC_EXT(initialize_krb5_error_table, $KRB5_LIBS)
+  AC_CHECK_FUNC_EXT(krb5_get_init_creds_opt_alloc, $KRB5_LIBS)
+  AC_CHECK_FUNC_EXT(krb5_get_init_creds_opt_free, $KRB5_LIBS)
+  AC_CHECK_FUNC_EXT(krb5_get_init_creds_opt_get_error, $KRB5_LIBS)
+  AC_CHECK_FUNC_EXT(krb5_enctype_to_string, $KRB5_LIBS)
 
   LIBS="$KRB5_LIBS $LIBS"
 
+  AC_CACHE_CHECK(whether krb5_ticket contains kvno and enctype,
+       smb_krb5_ticket_has_keyinfo,
+       [
+           AC_TRY_COMPILE(
+           [
+               #include <krb5.h>
+           ],
+           [
+               krb5_ticket ticket;
+               krb5_kvno kvno;
+               krb5_enctype enctype;
+
+               enctype = ticket.enc_part.enctype;
+               kvno = ticket.enc_part.kvno;
+           ],
+           [ smb_krb5_ticket_has_keyinfo=yes ],
+           [ smb_krb5_ticket_has_keyinfo=no ])
+       ])
+
+  if test x"$smb_krb5_ticket_has_keyinfo" = x"yes" ; then
+       AC_DEFINE(KRB5_TICKET_HAS_KEYINFO, 1,
+           [Whether the krb5_ticket structure contains the kvno and enctype])
+  fi
+
+  AC_CACHE_CHECK(whether krb5_get_init_creds_opt_free takes a context argument,
+         smb_krb5_creds_opt_free_context,
+         [
+               AC_TRY_COMPILE([
+                   #include <krb5.h>],
+                   [
+                       krb5_context ctx;
+                       krb5_get_init_creds_opt *opt = NULL;
+                       krb5_get_init_creds_opt_free(ctx, opt);
+                   ],
+                   [smb_krb5_creds_opt_free_context=yes],
+                   [smb_krb5_creds_opt_free_context=no]
+               )
+         ])
+
+  if test x"$smb_krb5_creds_opt_free_context" = x"yes" ; then
+       AC_DEFINE(KRB5_CREDS_OPT_FREE_REQUIRES_CONTEXT, 1,
+           [Whether krb5_get_init_creds_opt_free takes a context argument])
+  fi
+
   AC_CACHE_CHECK(whether krb5_verify_checksum takes 7 arguments, smb_krb5_verify_checksum, [
     AC_TRY_COMPILE([
-       #include <krb5.h>], 
-       [krb5_verify_checksum(0, 0, 0, 0, 0, 0, 0);], 
-       [smb_krb5_verify_checksum=7], 
-       [smb_krb5_verify_checksum=6], 
-    ) 
+       #include <krb5.h>],
+       [krb5_verify_checksum(0, 0, 0, 0, 0, 0, 0);],
+       [smb_krb5_verify_checksum=7],
+       [smb_krb5_verify_checksum=6],
+    )
   ])
   AC_DEFINE_UNQUOTED(KRB5_VERIFY_CHECKSUM_ARGS, $smb_krb5_verify_checksum, [Number of arguments to krb5_verify_checksum])
 
@@ -3407,6 +3763,18 @@ if test x"$with_ads_support" != x"no"; then
                [Whether the krb5_ap_req struct has a ticket pointer])
   fi
 
+  AC_CACHE_CHECK([for e_data pointer in krb5_error],
+                samba_cv_HAVE_E_DATA_POINTER_IN_KRB5_ERROR,[
+    AC_TRY_COMPILE([#include <krb5.h>],
+      [krb5_error err; err.e_data = NULL;],
+      samba_cv_HAVE_E_DATA_POINTER_IN_KRB5_ERROR=yes,
+      samba_cv_HAVE_E_DATA_POINTER_IN_KRB5_ERROR=no)])
+
+  if test x"$samba_cv_HAVE_E_DATA_POINTER_IN_KRB5_ERROR" = x"yes"; then
+    AC_DEFINE(HAVE_E_DATA_POINTER_IN_KRB5_ERROR,1,
+               [Whether the krb5_error struct has a e_data pointer])
+  fi
+
   AC_CACHE_CHECK([for krb5_crypto type],
                 samba_cv_HAVE_KRB5_CRYPTO,[
     AC_TRY_COMPILE([#include <krb5.h>],
@@ -3455,7 +3823,7 @@ if test x"$with_ads_support" != x"no"; then
               [Whether the krb5_address struct has a addr_type property])
   fi
 
-  AC_CACHE_CHECK([for enc_part2 in krb5_ticket], 
+  AC_CACHE_CHECK([for enc_part2 in krb5_ticket],
                 samba_cv_HAVE_KRB5_TKT_ENC_PART2,
                  [AC_TRY_COMPILE([#include <krb5.h>],
     [krb5_ticket tkt; tkt.enc_part2->authorization_data[0]->contents = NULL;],
@@ -3557,7 +3925,7 @@ if test x"$with_ads_support" != x"no"; then
     AC_DEFINE(HAVE_KRB5_KU_OTHER_CKSUM,1,
               [Whether KRB5_KU_OTHER_CKSUM is available])
   fi
-  
+
   AC_CACHE_CHECK([for KRB5_KEYUSAGE_APP_DATA_CKSUM],
                  samba_cv_HAVE_KRB5_KEYUSAGE_APP_DATA_CKSUM,[
     AC_TRY_COMPILE([#include <krb5.h>],
@@ -3606,26 +3974,23 @@ if test x"$with_ads_support" != x"no"; then
               [Whether krb5_keytab_entry has keyblock member])
   fi
 
-  if test x"$ac_cv_lib_ext_krb5_krb5_mk_req_extended" = x"yes"; then
-    AC_DEFINE(HAVE_KRB5,1,[Whether to have KRB5 support])
-    AC_DEFINE(WITH_ADS,1,[Whether to include Active Directory support])
-    AC_MSG_CHECKING(whether Active Directory and krb5 support is used)
-    AC_MSG_RESULT(yes)
-  else
-    if test x"$with_ads_support" = x"yes"; then
-       AC_MSG_ERROR(libkrb5 is needed for Active Directory support)
-    else
-       AC_MSG_WARN(libkrb5 is needed for Active Directory support)
-    fi
-    KRB5_LIBS=""
-    with_ads_support=no 
+  AC_CACHE_CHECK([for magic in krb5_address],
+                 samba_cv_HAVE_MAGIC_IN_KRB5_ADDRESS,[
+    AC_TRY_COMPILE([#include <krb5.h>],
+      [krb5_address addr; addr.magic = 0;],
+      samba_cv_HAVE_MAGIC_IN_KRB5_ADDRESS=yes,
+      samba_cv_HAVE_MAGIC_IN_KRB5_ADDRESS=no)])
+
+  if test x"$samba_cv_HAVE_MAGIC_IN_KRB5_ADDRESS" = x"yes"; then
+    AC_DEFINE(HAVE_MAGIC_IN_KRB5_ADDRESS,1,
+              [Whether the krb5_address struct has a magic property])
   fi
 
   AC_CACHE_CHECK([for WRFILE: keytab support],
                 samba_cv_HAVE_WRFILE_KEYTAB,[
     AC_TRY_RUN([
 #include<krb5.h>
-  main()
+  int main()
   {
     krb5_context context;
     krb5_keytab keytab;
@@ -3656,10 +4021,227 @@ if test x"$with_ads_support" != x"no"; then
               [Whether krb5_princ_realm returns krb5_realm or krb5_data])
   fi
 
+  AC_CACHE_CHECK([for krb5_addresses type],
+                samba_cv_HAVE_KRB5_ADDRESSES,[
+    AC_TRY_COMPILE([#include <krb5.h>],
+      [krb5_addresses addr;],
+      samba_cv_HAVE_KRB5_ADDRESSES=yes,
+      samba_cv_HAVE_KRB5_ADDRESSES=no)])
+
+  if test x"$samba_cv_HAVE_KRB5_ADDRESSES" = x"yes"; then
+    AC_DEFINE(HAVE_KRB5_ADDRESSES,1,
+               [Whether the type krb5_addresses type exists])
+  fi
+
+  AC_CACHE_CHECK([whether krb5_mk_error takes 3 arguments MIT or 9 Heimdal],
+               samba_cv_HAVE_SHORT_KRB5_MK_ERROR_INTERFACE, [
+    AC_TRY_COMPILE([#include <krb5.h>],
+    [
+    krb5_mk_error(0,0,0);],
+    samba_cv_HAVE_SHORT_KRB5_MK_ERROR_INTERFACE=yes,
+    samba_cv_HAVE_SHORT_KRB5_MK_ERROR_INTERFACE=no)])
+
+  if test x"$samba_cv_HAVE_SHORT_KRB5_MK_ERROR_INTERFACE" = x"yes"; then
+    AC_DEFINE(HAVE_SHORT_KRB5_MK_ERROR_INTERFACE,1,
+              [whether krb5_mk_error takes 3 arguments MIT or 9 Heimdal])
+  fi
+
+  if test x"$ac_cv_func_ext_krb5_enctype_to_string" = x"yes"; then
+    AC_CACHE_CHECK([for krb5_error_code krb5_enctype_to_string(krb5_context context, krb5_enctype enctype, char **str)],
+        smb_krb5_enctype_to_string_takes_krb5_context_arg,[
+       AC_TRY_RUN_STRICT([
+               #include <krb5.h>
+               int main(void) {
+                       krb5_context context = NULL;
+                       char *str = NULL;
+                       krb5_enctype_to_string(context, 1, &str);
+                       if (str) free (str); 
+                       return 0;
+               }
+               ],[$Werror_FLAGS],[$CPPFLAGS],[$LDFLAGS],
+               smb_krb5_enctype_to_string_takes_krb5_context_arg=yes,
+               smb_krb5_enctype_to_string_takes_krb5_context_arg=no)])
+
+    if test x"$smb_krb5_enctype_to_string_takes_krb5_context_arg" = x"yes"; then
+      AC_DEFINE(HAVE_KRB5_ENCTYPE_TO_STRING_WITH_KRB5_CONTEXT_ARG,1,
+                [whether krb5_enctype_to_string takes krb5_context argument])
+    fi
+
+    AC_CACHE_CHECK([for krb5_error_code krb5_enctype_to_string(krb5_enctype enctype, char *str, size_t len)],
+        smb_krb5_enctype_to_string_takes_size_t_arg,[
+       AC_TRY_RUN_STRICT([
+               #include <krb5.h>
+               int main(void) {
+                       char buf[256];
+                       krb5_enctype_to_string(1, buf, 256);
+                       return 0;
+               }
+               ],[$Werror_FLAGS],[$CPPFLAGS],[$LDFLAGS],
+               smb_krb5_enctype_to_string_takes_size_t_arg=yes,
+               smb_krb5_enctype_to_string_takes_size_t_arg=no)])
+
+    if test x"$smb_krb5_enctype_to_string_takes_size_t_arg" = x"yes"; then
+      AC_DEFINE(HAVE_KRB5_ENCTYPE_TO_STRING_WITH_SIZE_T_ARG,1,
+                [whether krb5_enctype_to_string takes size_t argument])
+    fi
+  fi
+
+  #
+  #
+  # Now the decisions whether we can support krb5
+  #
+  # NOTE: all tests should be done before this block!
+  #
+  #
+  if test x"$ac_cv_lib_ext_krb5_krb5_mk_req_extended" != x"yes"; then
+    AC_MSG_WARN(krb5_mk_req_extended not found in -lkrb5)
+    use_ads=no
+  fi
+
+  if test x"$ac_cv_func_ext_krb5_principal2salt" != x"yes" -a \
+          x"$ac_cv_func_ext_krb5_get_pw_salt" != x"yes"
+  then
+    AC_MSG_WARN(no CREATE_KEY_FUNCTIONS detected)
+    use_ads=no
+  fi
+
+  if test x"$ac_cv_func_ext_krb5_get_permitted_enctypes" != x"yes" -a \
+          x"$ac_cv_func_ext_krb5_get_default_in_tkt_etypes" != x"yes"
+  then
+    AC_MSG_WARN(no GET_ENCTYPES_FUNCTIONS detected)
+    use_ads=no
+  fi
+
+  if test x"$ac_cv_func_ext_krb5_kt_free_entry" != x"yes" -a \
+          x"$ac_cv_func_ext_krb5_free_keytab_entry_contents" != x"yes"
+  then
+    AC_MSG_WARN(no KT_FREE_FUNCTION detected)
+    use_ads=no
+  fi
+
+  if test x"$ac_cv_func_ext_krb5_c_verify_checksum" != x"yes" -a \
+          x"$ac_cv_func_ext_krb5_verify_checksum" != x"yes"
+  then
+    AC_MSG_WARN(no KRB5_VERIFY_CHECKSUM_FUNCTION detected)
+    use_ads=no
+  fi
+
+  if test x"$smb_krb5_ticket_has_keyinfo" != x"yes" ; then
+
+      # We only need the following functions if we can't get the enctype
+      # and kvno out of the ticket directly (ie. on Heimdal).
+
+      if test x"$ac_cv_func_ext_free_AP_REQ" != x"yes"
+      then
+       AC_MSG_WARN(no KRB5_AP_REQ_FREE_FUNCTION detected)
+       use_ads=no
+      fi
+
+      if test x"$ac_cv_func_ext_krb5_decode_ap_req" != x"yes"
+      then
+       AC_MSG_WARN(no KRB5_AP_REQ_DECODING_FUNCTION detected)
+       use_ads=no
+      fi
+
+  fi
+
+  if test x"$use_ads" = x"yes"; then
+    AC_DEFINE(WITH_ADS,1,[Whether to include Active Directory support])
+    AC_DEFINE(HAVE_KRB5,1,[Whether to have KRB5 support])
+    if test x"$have_gssapi" = x"yes"; then
+      AC_DEFINE(HAVE_GSSAPI,1,[Whether GSSAPI is available])
+    fi
+  else
+    if test x"$with_ads_support" = x"yes"; then
+       AC_MSG_ERROR(krb5 libs don't have all features required for Active Directory support)
+    else
+       AC_MSG_WARN(krb5 libs don't have all features required for Active Directory support)
+    fi
+    AC_REMOVE_DEFINE(HAVE_KRB5_H)
+    AC_REMOVE_DEFINE(HAVE_GSSAPI_H)
+    AC_REMOVE_DEFINE(HAVE_GSSAPI_GSSAPI_GENERIC_H)
+    AC_REMOVE_DEFINE(HAVE_GSSAPI_GSSAPI_H)
+    KRB5_LIBS=""
+    with_ads_support=no
+  fi
+  AC_MSG_CHECKING(whether Active Directory and krb5 support is used)
+  AC_MSG_RESULT([$use_ads])
+
 LIBS="$ac_save_LIBS"
 fi
 
 AC_CHECK_LIB_EXT(nscd, NSCD_LIBS, nscd_flush_cache)
+PASSDB_LIBS="$PASSDB_LIBS $NSCD_LIBS"
+
+
+########################################################
+# Compile with DNS Updates support?
+
+with_dnsupdate_support=no
+AC_MSG_CHECKING([whether to enable DNS Updates support])
+
+AC_ARG_WITH(dnsupdate,
+[  --with-dnsupdate        Enable DNS Updates support (default no)],
+[ case "$withval" in
+    yes|no)
+       with_dnsupdate_support=$withval
+       ;;
+  esac ])
+
+AC_MSG_RESULT($with_dnsupdate_support)
+
+if test x"$with_dnsupdate_support" != x"no"; then
+
+  ################################################################
+  # first test for Active Directory support being enabled
+  #if test x"$with_ads_support" = x"no"; then
+  #            AC_MSG_ERROR(Active Directory support is required to enable DNS Update support)
+  #            with_dnsupdate_support=no
+  #fi          
+  ##################################################################
+  # then test for uuid.h (necessary to generate unique DNS keynames
+  # (uuid.h is required for this test)
+  AC_CHECK_HEADERS(uuid/uuid.h)
+
+  if test x"$ac_cv_header_uuid_uuid_h" != x"yes"; then
+       if test x"$with_dnsupdate_support" = x"yes"; then
+        AC_MSG_ERROR(uuid.h is needed to enable DNS Updates support)
+       else
+        AC_MSG_WARN(uuid.h is needed to enable DNS Updates support)
+       fi
+       with_dnsupdate_support=no
+  fi
+fi
+
+if test x"$with_dnsupdate_support" != x"no"; then
+
+  ########################################################
+  # Now see if we can find the uuid libs in standard paths
+  # On some systems, the uuid API is in libc, so we have to
+  # be careful not to insert a spurious -luuid.
+
+  UUID_LIBS=""
+  AC_LIBTESTFUNC(uuid, uuid_generate,
+         [
+           case " $LIBS " in
+               *\ -luuid\ *)
+               UUID_LIBS="-luuid"
+               SMB_REMOVE_LIB(uuid)
+               ;;
+           esac
+
+           with_dnsupdate_support=yes
+           AC_DEFINE(WITH_DNS_UPDATES,1,[Whether to enable DNS Update support])
+       ],
+       [
+           if test x"$with_dnsupdate_support" = x"yes"; then
+               AC_MSG_ERROR(libuuid is needed to enable DNS Updates support)
+           else
+               AC_MSG_WARN(libuuid is needed to enable DNS Updates support)
+           fi
+           with_dnsupdate_support=no
+       ])
+fi
 
 #################################################
 # check for automount support
@@ -3689,7 +4271,7 @@ AC_ARG_WITH(smbmount,
        *linux*)
                AC_MSG_RESULT(yes)
                AC_DEFINE(WITH_SMBMOUNT,1,[Whether to build smbmount])
-               EXTRA_BIN_PROGS="$EXTRA_BIN_PROGS bin/smbmount bin/smbmnt bin/smbumount"
+               SMBMOUNT_PROGS="bin/smbmount bin/smbmnt bin/smbumount"
                ;;
        *)
                AC_MSG_ERROR(not on a linux system!)
@@ -3748,32 +4330,76 @@ AC_ARG_WITH(cifsmount,
 #################################################
 # check for a PAM clear-text auth, accounts, password and session support
 with_pam_for_crypt=no
-AC_MSG_CHECKING(whether to use PAM)
+try_pam=no
+AC_MSG_CHECKING(whether to try PAM support)
 AC_ARG_WITH(pam,
 [  --with-pam              Include PAM support (default=no)],
 [ case "$withval" in
-  yes)
-    AC_MSG_RESULT(yes)
-    if test x"$ac_cv_header_security_pam_appl_h" = x"no"; then
-       if test x"$ac_cv_header_security_pam_modules_h" = x"no"; then
-         if test x"$ac_cv_header_security__pam_macros_h" = x"no"; then
-            AC_MSG_ERROR(--with-pam specified but no PAM headers found)
-         fi
-       fi
-    fi
-    AC_DEFINE(WITH_PAM,1,[Whether to include PAM support])
-    AUTH_LIBS="$AUTH_LIBS -lpam"
-    with_pam_for_crypt=yes
-    ;;
-  *)
-    AC_MSG_RESULT(no)
+  yes|no)
+    try_pam=$withval
     ;;
-  esac ],
-  AC_MSG_RESULT(no)
-)
+  esac
+])
+AC_MSG_RESULT([$try_pam])
+
+use_pam=no
+create_pam_modules=no
+if test x"${try_pam}" != x"no";then
+       use_pam=yes
+       create_pam_modules=yes
+
+       AC_CHECK_HEADERS(security/pam_appl.h)
+       if test x"$ac_cv_header_security_pam_appl_h" != x"yes"; then
+               if test x"${try_pam}" = x"yes";then
+                       AC_MSG_ERROR([--with-pam=yes but security/pam_appl.h not found])
+               fi
+               use_pam=no
+               create_pam_modules=no
+       fi
 
-# we can't build a pam module if we don't have pam.
-AC_CHECK_LIB(pam, pam_get_data, [AC_DEFINE(HAVE_LIBPAM,1,[Whether libpam is available])])
+       AC_CHECK_LIB_EXT(pam, PAM_LIBS, pam_get_data)
+       if test x"$ac_cv_lib_ext_pam_pam_get_data" != x"yes"; then
+               if test x"${try_pam}" = x"yes";then
+                       AC_MSG_ERROR([--with-pam=yes but libpam not found])
+               fi
+               use_pam=no
+               create_pam_modules=no
+       fi
+
+       AC_CHECK_HEADERS(security/pam_modules.h,,,[[
+               #if HAVE_SECURITY_PAM_APPL_H
+               #include <security/pam_appl.h>
+               #endif
+       ]])
+       if test x"$ac_cv_header_security_pam_modules_h" = x"no"; then
+               if test x"${try_pam}" = x"yes";then
+                       AC_MSG_ERROR([--with-pam=yes but security/pam_modules.h not found])
+               fi
+               create_pam_modules=no
+       fi
+
+       if test x"$use_pam" = x"yes"; then
+               AC_DEFINE(WITH_PAM,1,[Whether to include PAM support])
+               AC_DEFINE(HAVE_LIBPAM,1,[Whether libpam is available])
+               AUTH_LIBS="$AUTH_LIBS $PAM_LIBS"
+               with_pam_for_crypt=yes
+
+               if test x"$create_pam_modules" = x"yes"; then
+                       AC_DEFINE(WITH_PAM_MODULES,1,[Whether to include PAM MODULES support])
+                       # this checks are optional,
+                       # we don't care about the results here
+                       AC_CHECK_HEADERS(security/pam_ext.h security/_pam_macros.h)
+                       AC_CHECK_FUNC_EXT(pam_vsyslog,$PAM_LIBS)
+               else
+                       AC_MSG_WARN([PAM support detected but PAM MODULES support is missing])          
+               fi
+       fi
+       AC_MSG_CHECKING(whether to use PAM support)
+       AC_MSG_RESULT([$use_pam])
+
+       AC_MSG_CHECKING(whether to have PAM MODULES support)
+       AC_MSG_RESULT([$create_pam_modules])
+fi # try_pam != no
 
 #################################################
 # check for pam_smbpass support
@@ -3789,14 +4415,11 @@ AC_ARG_WITH(pam_smbpass,
 
        # Conditions under which pam_smbpass should not be built.
 
-       if test x$PICFLAGS = x; then
-          AC_MSG_ERROR([No support for PIC code])
-       elif test x"$ac_cv_header_security_pam_appl_h" = x"no"; then
-         AC_MSG_ERROR([No security/pam_appl.h found])
-       elif test x$ac_cv_lib_pam_pam_get_data = xno; then
-          AC_MSG_ERROR([No libpam found])
+       if test x"$BLDSHARED" != x"true"; then
+          AC_MSG_ERROR([No support for shared modules])
+       elif test x"$create_pam_modules" != x"yes"; then
+         AC_MSG_ERROR([No support for PAM MODULES])
        else
-         AUTH_LIBS="$AUTH_LIBS -lpam"
           PAM_MODULES="pam_smbpass"
           INSTALL_PAM_MODULES="installpammodules"
           UNINSTALL_PAM_MODULES="uninstallpammodules"
@@ -3834,38 +4457,8 @@ if test x"$samba_cv_HAVE_TRUNCATED_SALT" = x"yes"; then
 fi
 fi
 
-
-########################################################################################
-##
-## TESTS FOR SAM BACKENDS.  KEEP THESE GROUPED TOGETHER
-##
-########################################################################################
-
 #################################################
-# check for a LDAP password database configuration backwards compatibility
-AC_MSG_CHECKING(whether to use LDAP SAM 2.2 compatible configuration)
-AC_ARG_WITH(ldapsam,
-[  --with-ldapsam          Include LDAP SAM 2.2 compatible configuration (default=no)],
-[ case "$withval" in
-  yes)
-    AC_MSG_RESULT(yes)
-    AC_DEFINE(WITH_LDAP_SAMCONFIG,1,[Whether to include 2.2 compatible LDAP SAM configuration])
-    ;;
-  *)
-    AC_MSG_RESULT(no)
-    ;;
-  esac ],
-  AC_MSG_RESULT(no)
-)
-
-########################################################################################
-##
-## END OF TESTS FOR SAM BACKENDS.  
-##
-########################################################################################
-
-#################################################
-# check for a NISPLUS_HOME support 
+# check for a NISPLUS_HOME support
 AC_MSG_CHECKING(whether to use NISPLUS_HOME)
 AC_ARG_WITH(nisplus-home,
 [  --with-nisplus-home     Include NISPLUS_HOME support (default=no)],
@@ -3898,24 +4491,6 @@ AC_ARG_WITH(syslog,
   AC_MSG_RESULT(no)
 )
 
-#################################################
-# check for a shared memory profiling support
-AC_MSG_CHECKING(whether to use profiling)
-AC_ARG_WITH(profiling-data,
-[  --with-profiling-data   Include gathering source code profile information (default=no)],
-[ case "$withval" in
-  yes)
-    AC_MSG_RESULT(yes)
-    AC_DEFINE(WITH_PROFILE,1,[Whether to use profiling])
-    ;;
-  *)
-    AC_MSG_RESULT(no)
-    ;;
-  esac ],
-  AC_MSG_RESULT(no)
-)
-
-
 #################################################
 # check for experimental disk-quotas support
 
@@ -4059,7 +4634,7 @@ if test "$samba_cv_HAVE_SYS_QUOTA_XFS"x = "yes"x; then
 fi
 fi
 
-# if we have struct dqblk .dqb_fsoftlimit instead of .dqb_isoftlimit on IRIX 
+# if we have struct dqblk .dqb_fsoftlimit instead of .dqb_isoftlimit on IRIX
 AC_CACHE_CHECK([if struct dqblk has .dqb_fsoftlimit],samba_cv_HAVE_DQB_FSOFTLIMIT, [
 AC_TRY_COMPILE([
 #include "confdefs.h"
@@ -4140,13 +4715,13 @@ AC_CHECK_FUNCS(devnm)
 
 if test x"$samba_cv_WITH_SYS_QUOTAS" = x"yes"; then
     if test x"$samba_cv_SYSQUOTA_FOUND" != x"yes"; then
-       # if --with-sys-quotas=yes then build it 
+       # if --with-sys-quotas=yes then build it
        # you have can use the get/set quota command smb.conf
        # options then
        samba_cv_SYSQUOTA_FOUND=auto
     fi
     if test x"$samba_cv_TRY_SYS_QUOTAS" != x"yes"; then
-       # if --with-sys-quotas=yes then build it 
+       # if --with-sys-quotas=yes then build it
        # you have can use the get/set quota command smb.conf
        # options then
        samba_cv_TRY_SYS_QUOTAS=auto
@@ -4156,7 +4731,7 @@ fi
 if test x"$samba_cv_SYSQUOTA_FOUND" != x"no"; then
 AC_CACHE_CHECK([whether the sys_quota interface works],samba_cv_SYSQUOTA_WORKS,[
 SAVE_CPPFLAGS="$CPPFLAGS"
-CPPFLAGS="$CPPFLAGS -I${srcdir-.}/ -I. -I${srcdir-.}/include -I${srcdir-.}/ubiqx -I${srcdir-.}/popt -I${srcdir-.}/nsswitch"
+CPPFLAGS="$CPPFLAGS ${SAMBA_CONFIGURE_CPPFLAGS}"
 AC_TRY_COMPILE([
 #include "confdefs.h"
 #define NO_PROTO_H 1
@@ -4169,7 +4744,7 @@ CPPFLAGS="$SAVE_CPPFLAGS"
 ])
 if test x"$samba_cv_SYSQUOTA_WORKS" = x"yes"; then
 AC_MSG_CHECKING(whether to use the new lib/sysquotas.c interface)
-    if test x"$samba_cv_TRY_SYS_QUOTAS" != x"no"; then 
+    if test x"$samba_cv_TRY_SYS_QUOTAS" != x"no"; then
        AC_DEFINE(WITH_QUOTAS,1,[Whether to use disk quota support])
        AC_DEFINE(HAVE_SYS_QUOTAS,1,[Whether the new lib/sysquotas.c interface can be used])
        samba_cv_WE_USE_SYS_QUOTAS=yes
@@ -4183,7 +4758,7 @@ fi
 if test x"$samba_cv_SYSQUOTA_FOUND" != x"no" -a x"$samba_cv_found_xfs_header" = x"yes"; then
 AC_CACHE_CHECK([whether the sys_quota interface works with XFS],samba_cv_SYSQUOTA_WORKS_XFS,[
 SAVE_CPPFLAGS="$CPPFLAGS"
-CPPFLAGS="$CPPFLAGS -I${srcdir-.}/ -I. -I${srcdir-.}/include -I${srcdir-.}/ubiqx -I${srcdir-.}/popt -I${srcdir-.}/nsswitch"
+CPPFLAGS="$CPPFLAGS ${SAMBA_CONFIGURE_CPPFLAGS}"
 AC_TRY_COMPILE([
 #include "confdefs.h"
 #define NO_PROTO_H 1
@@ -4203,7 +4778,7 @@ fi
 
 AC_CACHE_CHECK([whether the old quota support works],samba_cv_QUOTA_WORKS,[
 SAVE_CPPFLAGS="$CPPFLAGS"
-CPPFLAGS="$CPPFLAGS -I${srcdir-.}/ -I. -I${srcdir-.}/include -I${srcdir-.}/ubiqx -I${srcdir-.}/popt -I${srcdir-.}/nsswitch -I${srcdir-.}/smbwrapper"
+CPPFLAGS="$CPPFLAGS ${SAMBA_CONFIGURE_CPPFLAGS}"
 AC_TRY_COMPILE([
 #include "confdefs.h"
 #define NO_PROTO_H 1
@@ -4288,7 +4863,7 @@ AC_MSG_CHECKING(whether to build the libmsrpc shared library)
 AC_ARG_WITH(libmsrpc,
 [  --with-libmsrpc         Build the libmsrpc shared library (default=yes if shared libs supported)],
 [ case "$withval" in
-  no) 
+  no)
      AC_MSG_RESULT(no)
      ;;
   *)
@@ -4324,6 +4899,53 @@ AC_ARG_WITH(libmsrpc,
   UNINSTALL_LIBMSRPC=uninstalllibmsrpc
 )
 
+
+#################################################
+# should we build libaddns?
+INSTALL_LIBADDNS=
+UNINSTALL_LIBADDNS=
+LIBADDNS_SHARED=
+LIBADDNS=
+AC_MSG_CHECKING(whether to build the libaddns shared library)
+AC_ARG_WITH(libaddns,
+[  --with-libaddns         Build the libaddns shared library (default=yes if shared libs supported)],
+[ case "$withval" in
+  no)
+     AC_MSG_RESULT(no)
+     ;;
+  *)
+     if test $BLDSHARED = true; then
+        LIBADDNS_SHARED=bin/libaddns.$SHLIBEXT
+        LIBADDNS=libaddns
+        AC_MSG_RESULT(yes)
+     else
+       enable_static=yes
+        AC_MSG_RESULT(no shared library support -- will supply static library)
+     fi
+     if test $enable_static = yes; then
+        LIBADDNS=libaddns
+     fi
+     INSTALL_LIBADDNS=installlibaddns
+     UNINSTALL_LIBADDNS=uninstalllibaddns
+     ;;
+  esac ],
+[
+# if unspecified, default is to built it if possible.
+  if test $BLDSHARED = true; then
+     LIBADDNS_SHARED=bin/libaddns.$SHLIBEXT
+     LIBADDNS=libaddns
+     AC_MSG_RESULT(yes)
+   else
+     enable_static=yes
+     AC_MSG_RESULT(no shared library support -- will supply static library)
+   fi
+   if test $enable_static = yes; then
+     LIBADDNS=libaddns
+  fi]
+  INSTALL_LIBADDNS=installlibaddns
+  UNINSTALL_LIBADDNS=uninstalllibaddns
+)
+
 #################################################
 # should we build libsmbclient?
 INSTALL_LIBSMBCLIENT=
@@ -4334,7 +4956,7 @@ AC_MSG_CHECKING(whether to build the libsmbclient shared library)
 AC_ARG_WITH(libsmbclient,
 [  --with-libsmbclient     Build the libsmbclient shared library (default=yes if shared libs supported)],
 [ case "$withval" in
-  no) 
+  no)
      AC_MSG_RESULT(no)
      ;;
   *)
@@ -4393,6 +5015,7 @@ AC_ARG_WITH(libsmbsharemodes,
         LIBSMBSHAREMODES=libsmbsharemodes
      fi
      INSTALL_LIBSMBSHAREMODES=installlibsmbsharemodes
+     UNINSTALL_LIBSMBSHAREMODES=uninstalllibsmbsharemodes
      ;;
   esac ],
 [
@@ -4429,7 +5052,7 @@ if test $space = no; then
   main ()
   {
     struct statvfs64 fsd;
-    exit (statvfs64 (".", &fsd));
+    return statvfs64 (".", &fsd);
   }],
   fu_cv_sys_stat_statvfs64=yes,
   fu_cv_sys_stat_statvfs64=no,
@@ -4460,6 +5083,16 @@ if test $space = no; then
   fi
 fi
 
+# smbd/statvfs.c assumes that statvfs.f_fsid is an integer.
+# This is not the case on ancient Linux systems.
+
+AC_CACHE_CHECK([that statvfs.f_fsid is an integer],samba_cv_fsid_int, [
+    AC_TRY_COMPILE([#include <sys/statvfs.h>],[struct statvfs buf; buf.f_fsid = 0],
+       samba_cv_fsid_int=yes,samba_cv_fsid_int=no)])
+if test x"$samba_cv_fsid_int" = x"yes"; then
+    AC_DEFINE(HAVE_FSID_INT, 1, [Whether statvfs.f_fsid is an integer])
+fi
+
 if test $space = no; then
   # DEC Alpha running OSF/1
   AC_MSG_CHECKING([for 3-argument statfs function (DEC OSF/1)])
@@ -4472,7 +5105,7 @@ if test $space = no; then
   {
     struct statfs fsd;
     fsd.f_fsize = 0;
-    exit (statfs (".", &fsd, sizeof (struct statfs)));
+    return statfs (".", &fsd, sizeof (struct statfs));
   }],
   fu_cv_sys_stat_statfs3_osf1=yes,
   fu_cv_sys_stat_statfs3_osf1=no,
@@ -4503,7 +5136,7 @@ member (AIX, 4.3BSD)])
   {
   struct statfs fsd;
   fsd.f_bsize = 0;
-  exit (statfs (".", &fsd));
+  return statfs (".", &fsd);
   }],
   fu_cv_sys_stat_statfs2_bsize=yes,
   fu_cv_sys_stat_statfs2_bsize=no,
@@ -4524,7 +5157,7 @@ if test $space = no; then
   main ()
   {
   struct statfs fsd;
-  exit (statfs (".", &fsd, sizeof fsd, 0));
+  return statfs (".", &fsd, sizeof fsd, 0);
   }],
     fu_cv_sys_stat_statfs4=yes,
     fu_cv_sys_stat_statfs4=no,
@@ -4552,7 +5185,7 @@ member (4.4BSD and NetBSD)])
   {
   struct statfs fsd;
   fsd.f_fsize = 0;
-  exit (statfs (".", &fsd));
+  return statfs (".", &fsd);
   }],
   fu_cv_sys_stat_statfs2_fsize=yes,
   fu_cv_sys_stat_statfs2_fsize=no,
@@ -4583,7 +5216,7 @@ if test $space = no; then
   struct fs_data fsd;
   /* Ultrix's statfs returns 1 for success,
      0 for not mounted, -1 for failure.  */
-  exit (statfs (".", &fsd) != 1);
+  return statfs (".", &fsd) != 1;
   }],
   fu_cv_sys_stat_fs_data=yes,
   fu_cv_sys_stat_fs_data=no,
@@ -4618,30 +5251,20 @@ if test x"$samba_cv_HAVE_EXPLICIT_LARGEFILE_SUPPORT" = x"yes"; then
 fi
 AC_MSG_RESULT([$samba_cv_HAVE_EXPLICIT_LARGEFILE_SUPPORT])
 
-AC_ARG_WITH(spinlocks, 
-[  --with-spinlocks        Use spin locks instead of fcntl locks (default=no) ])
-if test "x$with_spinlocks" = "xyes"; then
-    AC_DEFINE(USE_SPINLOCKS,1,[Whether to use spin locks instead of fcntl locks])
-
-    case "$host_cpu" in
-        sparc)
-            AC_DEFINE(SPARC_SPINLOCKS,1,[Whether to use sparc spinlocks])
-            ;;
-
-        i386|i486|i586|i686)
-            AC_DEFINE(INTEL_SPINLOCKS,1,[Whether to use intel spinlocks])
-            ;;
-
-        mips)
-            AC_DEFINE(MIPS_SPINLOCKS,1,[Whether to use mips spinlocks])
-            ;;
+#################################################
+# check for cluster extensions
 
-        powerpc)
-            AC_DEFINE(POWERPC_SPINLOCKS,1,[Whether to use powerpc spinlocks])
-            ;;
-    esac
+AC_MSG_CHECKING(whether to include cluster support)
+AC_ARG_WITH(cluster-support,
+[  --with-cluster-support  Enable cluster extensions (default=no)])
+if test "x$with_cluster_support" = "xyes"; then
+    AC_DEFINE(CLUSTER_SUPPORT,1,[Whether to enable cluster extensions])
+    AC_MSG_RESULT(yes)
+else
+    AC_MSG_RESULT(no)
 fi
 
+
 #################################################
 # check for ACL support
 
@@ -4655,86 +5278,123 @@ AC_ARG_WITH(acl-support,
        *sysv5*)
                AC_MSG_RESULT(Using UnixWare ACLs)
                AC_DEFINE(HAVE_UNIXWARE_ACLS,1,[Whether UnixWare ACLs are available])
+               default_static_modules="$default_static_modules vfs_solarisacl"
                ;;
        *solaris*)
                AC_MSG_RESULT(Using solaris ACLs)
                AC_DEFINE(HAVE_SOLARIS_ACLS,1,[Whether solaris ACLs are available])
                ACL_LIBS="$ACL_LIBS -lsec"
+               default_static_modules="$default_static_modules vfs_solarisacl"
                ;;
        *hpux*)
                AC_MSG_RESULT(Using HPUX ACLs)
                AC_DEFINE(HAVE_HPUX_ACLS,1,[Whether HPUX ACLs are available])
+               default_static_modules="$default_static_modules vfs_hpuxacl"
                ;;
        *irix*)
                AC_MSG_RESULT(Using IRIX ACLs)
                AC_DEFINE(HAVE_IRIX_ACLS,1,[Whether IRIX ACLs are available])
+               default_static_modules="$default_static_modules vfs_irixacl"
                ;;
        *aix*)
                AC_MSG_RESULT(Using AIX ACLs)
                AC_DEFINE(HAVE_AIX_ACLS,1,[Whether AIX ACLs are available])
+               default_static_modules="$default_static_modules vfs_aixacl"
                ;;
        *osf*)
                AC_MSG_RESULT(Using Tru64 ACLs)
                AC_DEFINE(HAVE_TRU64_ACLS,1,[Whether Tru64 ACLs are available])
                ACL_LIBS="$ACL_LIBS -lpacl"
+               default_static_modules="$default_static_modules vfs_tru64acl"
                ;;
        *freebsd[[5-9]]*)
                AC_MSG_RESULT(Using FreeBSD posix ACLs)
                AC_DEFINE(HAVE_POSIX_ACLS,1,[Whether FreeBSD POSIX ACLs are available])
                AC_DEFINE(HAVE_ACL_GET_PERM_NP,1,[Whether acl_get_perm_np() is available])
+               default_static_modules="$default_static_modules vfs_posixacl"
                ;;
        *linux*)
                AC_CHECK_LIB(attr,getxattr,[ACL_LIBS="$ACL_LIBS -lattr"])
                        AC_CHECK_LIB(acl,acl_get_file,[ACL_LIBS="$ACL_LIBS -lacl"])
                AC_CACHE_CHECK([for ACL support],samba_cv_HAVE_POSIX_ACLS,[
-               acl_LIBS=$LIBS
-               LIBS="$LIBS -lacl"
-               AC_TRY_LINK([#include <sys/types.h>
-#include <sys/acl.h>],
-[ acl_t acl; int entry_id; acl_entry_t *entry_p; return acl_get_entry( acl, entry_id, entry_p);],
-samba_cv_HAVE_POSIX_ACLS=yes,samba_cv_HAVE_POSIX_ACLS=no)
-               LIBS=$acl_LIBS])
-                       if test x"$samba_cv_HAVE_POSIX_ACLS" = x"yes"; then
-                               AC_MSG_RESULT(Using posix ACLs)
-                               AC_DEFINE(HAVE_POSIX_ACLS,1,[Whether POSIX ACLs are available])
-                               AC_CACHE_CHECK([for acl_get_perm_np],samba_cv_HAVE_ACL_GET_PERM_NP,[
+                       acl_LIBS=$LIBS
+                       LIBS="$LIBS -lacl"
+                       AC_TRY_LINK([
+                               #include <sys/types.h>
+                               #include <sys/acl.h>
+                       ],[
+                               acl_t acl;
+                               int entry_id;
+                               acl_entry_t *entry_p;
+                               return acl_get_entry(acl, entry_id, entry_p);
+                       ],
+                       [samba_cv_HAVE_POSIX_ACLS=yes],
+                       [samba_cv_HAVE_POSIX_ACLS=no])
+                       LIBS=$acl_LIBS
+               ])
+               if test x"$samba_cv_HAVE_POSIX_ACLS" = x"yes"; then
+                       AC_MSG_RESULT(Using posix ACLs)
+                       AC_DEFINE(HAVE_POSIX_ACLS,1,[Whether POSIX ACLs are available])
+                       AC_CACHE_CHECK([for acl_get_perm_np],samba_cv_HAVE_ACL_GET_PERM_NP,[
                                acl_LIBS=$LIBS
                                LIBS="$LIBS -lacl"
-                               AC_TRY_LINK([#include <sys/types.h>
-#include <sys/acl.h>],
-[ acl_permset_t permset_d; acl_perm_t perm; return acl_get_perm_np( permset_d, perm);],
-samba_cv_HAVE_ACL_GET_PERM_NP=yes,samba_cv_HAVE_ACL_GET_PERM_NP=no)
-                               LIBS=$acl_LIBS])
-                               if test x"$samba_cv_HAVE_ACL_GET_PERM_NP" = x"yes"; then
-                                       AC_DEFINE(HAVE_ACL_GET_PERM_NP,1,[Whether acl_get_perm_np() is available])
-                               fi
+                               AC_TRY_LINK([
+                                       #include <sys/types.h>
+                                       #include <sys/acl.h>
+                               ],[
+                                       acl_permset_t permset_d;
+                                       acl_perm_t perm;
+                                       return acl_get_perm_np(permset_d, perm);
+                               ],
+                               [samba_cv_HAVE_ACL_GET_PERM_NP=yes],
+                               [samba_cv_HAVE_ACL_GET_PERM_NP=no])
+                               LIBS=$acl_LIBS
+                       ])
+                       if test x"$samba_cv_HAVE_ACL_GET_PERM_NP" = x"yes"; then
+                               AC_DEFINE(HAVE_ACL_GET_PERM_NP,1,[Whether acl_get_perm_np() is available])
                        fi
+               fi
             ;;
          *)
                AC_CHECK_LIB(acl,acl_get_file,[ACL_LIBS="$ACL_LIBS -lacl"])
                AC_CACHE_CHECK([for ACL support],samba_cv_HAVE_POSIX_ACLS,[
-               acl_LIBS=$LIBS
-               LIBS="$LIBS -lacl"
-               AC_TRY_LINK([#include <sys/types.h>
-#include <sys/acl.h>],
-[ acl_t acl; int entry_id; acl_entry_t *entry_p; return acl_get_entry( acl, entry_id, entry_p);],
-samba_cv_HAVE_POSIX_ACLS=yes,samba_cv_HAVE_POSIX_ACLS=no)
-               LIBS=$acl_LIBS])
-                       if test x"$samba_cv_HAVE_POSIX_ACLS" = x"yes"; then
-                               AC_MSG_RESULT(Using posix ACLs)
-                               AC_DEFINE(HAVE_POSIX_ACLS,1,[Whether POSIX ACLs are available])
-                               AC_CACHE_CHECK([for acl_get_perm_np],samba_cv_HAVE_ACL_GET_PERM_NP,[
+                       acl_LIBS=$LIBS
+                       LIBS="$LIBS -lacl"
+                       AC_TRY_LINK([
+                               #include <sys/types.h>
+                               #include <sys/acl.h>
+                       ],[
+                               acl_t acl;
+                               int entry_id;
+                               acl_entry_t *entry_p;
+                               return acl_get_entry( acl, entry_id, entry_p);
+                       ],
+                       [samba_cv_HAVE_POSIX_ACLS=yes],
+                       [samba_cv_HAVE_POSIX_ACLS=no])
+                       LIBS=$acl_LIBS
+               ])
+               if test x"$samba_cv_HAVE_POSIX_ACLS" = x"yes"; then
+                       AC_MSG_RESULT(Using posix ACLs)
+                       AC_DEFINE(HAVE_POSIX_ACLS,1,[Whether POSIX ACLs are available])
+                       AC_CACHE_CHECK([for acl_get_perm_np],samba_cv_HAVE_ACL_GET_PERM_NP,[
                                acl_LIBS=$LIBS
                                LIBS="$LIBS -lacl"
-                               AC_TRY_LINK([#include <sys/types.h>
-#include <sys/acl.h>],
-[ acl_permset_t permset_d; acl_perm_t perm; return acl_get_perm_np( permset_d, perm);],
-samba_cv_HAVE_ACL_GET_PERM_NP=yes,samba_cv_HAVE_ACL_GET_PERM_NP=no)
-                               LIBS=$acl_LIBS])
-                               if test x"$samba_cv_HAVE_ACL_GET_PERM_NP" = x"yes"; then
-                                       AC_DEFINE(HAVE_ACL_GET_PERM_NP,1,[Whether acl_get_perm_np() is available])
-                               fi
+                               AC_TRY_LINK([
+                                       #include <sys/types.h>
+                                       #include <sys/acl.h>
+                               ],[
+                                       acl_permset_t permset_d;
+                                       acl_perm_t perm;
+                                       return acl_get_perm_np( permset_d, perm);
+                               ],
+                               [samba_cv_HAVE_ACL_GET_PERM_NP=yes],
+                               [samba_cv_HAVE_ACL_GET_PERM_NP=no])
+                               LIBS=$acl_LIBS
+                       ])
+                       if test x"$samba_cv_HAVE_ACL_GET_PERM_NP" = x"yes"; then
+                               AC_DEFINE(HAVE_ACL_GET_PERM_NP,1,[Whether acl_get_perm_np() is available])
                        fi
+               fi
             ;;
         esac
         ;;
@@ -4747,6 +5407,10 @@ samba_cv_HAVE_ACL_GET_PERM_NP=yes,samba_cv_HAVE_ACL_GET_PERM_NP=no)
   AC_MSG_RESULT(no)
 )
 
+if test x"$samba_cv_HAVE_POSIX_ACLS" = x"yes"; then
+   default_static_modules="$default_static_modules vfs_posixacl"
+fi
+
 #################################################
 # check for AIO support
 
@@ -4759,6 +5423,7 @@ AC_ARG_WITH(aio-support,
        AC_MSG_RESULT(yes)
        case "$host_os" in
        *)
+               AIO_LIBS=$LIBS
                AC_CHECK_LIB(rt,aio_read,[AIO_LIBS="$LIBS -lrt"])
                AC_CHECK_LIB(aio,aio_read,[AIO_LIBS="$LIBS -laio"])
                AC_CACHE_CHECK([for asynchronous io support],samba_cv_HAVE_AIO,[
@@ -4898,7 +5563,7 @@ AC_ARG_WITH(sendfile-support,
        AC_MSG_RESULT(yes);
 
        case "$host_os" in
-       *linux*)
+       linux*-gnu* | gnu* | k*bsd*-gnu)
                AC_CACHE_CHECK([for linux sendfile64 support],samba_cv_HAVE_SENDFILE64,[
                AC_TRY_LINK([#include <sys/sendfile.h>],
 [\
@@ -5142,6 +5807,46 @@ samba_cv_HAVE_SENDFILE=yes,samba_cv_HAVE_SENDFILE=no)])
   AC_MSG_RESULT(yes)
 )
 
+############################################
+# See if we have the Linux readahead syscall.
+
+AC_CACHE_CHECK([for Linux readahead],
+                samba_cv_HAVE_LINUX_READAHEAD,[
+
+    AC_TRY_LINK([
+#if defined(HAVE_UNISTD_H)
+#include <unistd.h>
+#endif
+#include <fcntl.h>],
+    [ssize_t err = readahead(0,0,0x80000);],
+    samba_cv_HAVE_LINUX_READAHEAD=yes,
+    samba_cv_HAVE_LINUX_READAHEAD=no)])
+
+if test x"$samba_cv_HAVE_LINUX_READAHEAD" = x"yes"; then
+  AC_DEFINE(HAVE_LINUX_READAHEAD,1,
+             [Whether Linux readahead is available])
+fi
+
+############################################
+# See if we have the posix_fadvise syscall.
+
+AC_CACHE_CHECK([for posix_fadvise],
+                samba_cv_HAVE_POSIX_FADVISE,[
+    AC_TRY_LINK([
+#if defined(HAVE_UNISTD_H)
+#include <unistd.h>
+#endif
+#include <fcntl.h>],
+    [ssize_t err = posix_fadvise(0,0,0x80000,POSIX_FADV_WILLNEED);],
+    samba_cv_HAVE_POSIX_FADVISE=yes,
+    samba_cv_HAVE_POSIX_FADVISE=no)])
+
+if test x"$samba_cv_HAVE_POSIX_FADVISE" = x"yes"; then
+  AC_DEFINE(HAVE_POSIX_FADVISE,1,
+             [Whether posix_fadvise is available])
+fi
+
+
 
 #################################################
 # Check whether winbind is supported on this platform.  If so we need to
@@ -5159,19 +5864,41 @@ HAVE_WINBIND=yes
 WINBIND_NSS="nsswitch/libnss_winbind.$SHLIBEXT"
 WINBIND_WINS_NSS="nsswitch/libnss_wins.$SHLIBEXT"
 WINBIND_NSS_LDSHFLAGS=$LDSHFLAGS
+NSSSONAMEVERSIONSUFFIX=""
+
+SMB_KRB5_LOCATOR="bin/smb_krb5_locator.$SHLIBEXT"
 
 case "$host_os" in
-       *linux*)
+       linux*-gnu* | gnu* | k*bsd*-gnu)
+               NSSSONAMEVERSIONSUFFIX=".2"
                WINBIND_NSS_EXTRA_OBJS="nsswitch/winbind_nss_linux.o"
                ;;
-       *freebsd[[5-9]]*)
+       freebsd5*|*freebsd[[6-9]]*)
                # FreeBSD winbind client is implemented as a wrapper around
                # the Linux version.
+               NSSSONAMEVERSIONSUFFIX=".1"
                WINBIND_NSS_EXTRA_OBJS="nsswitch/winbind_nss_freebsd.o \
                    nsswitch/winbind_nss_linux.o"
                WINBIND_NSS="nsswitch/nss_winbind.$SHLIBEXT"
                WINBIND_WINS_NSS="nsswitch/nss_wins.$SHLIBEXT"
                ;;
+
+       *netbsd*[[3-9]]*)
+               # NetBSD winbind client is implemented as a wrapper
+               # around the Linux version. It needs getpwent_r() to
+               # indicate libc's use of the correct nsdispatch API.
+               #
+               if test x"$ac_cv_func_getpwent_r" = x"yes"; then
+                       WINBIND_NSS_EXTRA_OBJS="\
+                           nsswitch/winbind_nss_netbsd.o \
+                           nsswitch/winbind_nss_linux.o"
+                       WINBIND_NSS="nsswitch/nss_winbind.$SHLIBEXT"
+                       WINBIND_WINS_NSS="nsswitch/nss_wins.$SHLIBEXT"
+               else
+                       HAVE_WINBIND=no
+                       winbind_no_reason=", getpwent_r is missing on $host_os so winbind is unsupported"
+               fi
+               ;;
        *irix*)
                # IRIX has differently named shared libraries
                WINBIND_NSS_EXTRA_OBJS="nsswitch/winbind_nss_irix.o"
@@ -5181,6 +5908,7 @@ case "$host_os" in
        *solaris*)
                # Solaris winbind client is implemented as a wrapper around
                # the Linux version.
+               NSSSONAMEVERSIONSUFFIX=".1"
                WINBIND_NSS_EXTRA_OBJS="nsswitch/winbind_nss_solaris.o \
                    nsswitch/winbind_nss_linux.o"
                WINBIND_NSS_EXTRA_LIBS="-lsocket"
@@ -5207,12 +5935,15 @@ AC_SUBST(WINBIND_WINS_NSS)
 AC_SUBST(WINBIND_NSS_LDSHFLAGS)
 AC_SUBST(WINBIND_NSS_EXTRA_OBJS)
 AC_SUBST(WINBIND_NSS_EXTRA_LIBS)
+AC_SUBST(NSSSONAMEVERSIONSUFFIX)
+
+AC_SUBST(SMB_KRB5_LOCATOR)
 
 # Check the setting of --with-winbind
 
 AC_ARG_WITH(winbind,
 [  --with-winbind          Build winbind (default, if supported by OS)],
-[ 
+[
   case "$withval" in
        yes)
                HAVE_WINBIND=yes
@@ -5235,20 +5966,25 @@ fi
 
 # Display test results
 
+if test x"$HAVE_WINBIND" = x"no"; then
+       WINBIND_NSS=""
+       WINBIND_WINS_NSS=""
+fi
+
+if test $BLDSHARED = true -a x"$HAVE_WINBIND" = x"yes"; then
+       NSS_MODULES="${WINBIND_NSS} ${WINBIND_WINS_NSS}"
+fi
+
 if test x"$HAVE_WINBIND" = x"yes"; then
         AC_MSG_RESULT(yes)
        AC_DEFINE(WITH_WINBIND,1,[Whether to build winbind])
 
        EXTRA_BIN_PROGS="$EXTRA_BIN_PROGS bin/wbinfo\$(EXEEXT)"
        EXTRA_SBIN_PROGS="$EXTRA_SBIN_PROGS bin/winbindd\$(EXEEXT)"
-        if test $BLDSHARED = true; then
-               SHLIB_PROGS="$SHLIB_PROGS $WINBIND_NSS $WINBIND_WINS_NSS"
-
-               if test x"$with_pam" = x"yes"; then
-                       PAM_MODULES="$PAM_MODULES pam_winbind"
-                       INSTALL_PAM_MODULES="installpammodules"
-                       UNINSTALL_PAM_MODULES="uninstallpammodules"
-               fi
+        if test $BLDSHARED = true -a x"$create_pam_modules" = x"yes"; then
+               PAM_MODULES="$PAM_MODULES pam_winbind"
+               INSTALL_PAM_MODULES="installpammodules"
+               UNINSTALL_PAM_MODULES="uninstallpammodules"
        fi
 else
         AC_MSG_RESULT(no$winbind_no_reason)
@@ -5260,8 +5996,8 @@ AC_CHECK_MEMBER(union nss_XbyY_key.ipnode.af_family,
                [#include <nss_dbdefs.h>])
 
 # Solaris has some extra fields in struct passwd that need to be
-# initialised otherwise nscd crashes.  
+# initialised otherwise nscd crashes.
+
 AC_CHECK_MEMBER(struct passwd.pw_comment,
                AC_DEFINE(HAVE_PASSWD_PW_COMMENT, 1, [Defined if struct passwd has pw_comment field]),,
                [#include <pwd.h>])
@@ -5277,13 +6013,24 @@ AC_CHECK_MEMBERS([struct secmethod_table.method_attrlist], , ,
 AC_CHECK_MEMBERS([struct secmethod_table.method_version], , ,
        [#include <usersec.h>])
 
+AC_CACHE_CHECK([for SO_PEERCRED],samba_cv_HAVE_PEERCRED,[
+AC_TRY_COMPILE([#include <sys/types.h>
+#include <sys/socket.h>],
+[struct ucred cred;
+ socklen_t cred_len;
+ int ret = getsockopt(0, SOL_SOCKET, SO_PEERCRED, &cred, &cred_len);
+],
+samba_cv_HAVE_PEERCRED=yes,samba_cv_HAVE_PEERCRED=no,samba_cv_HAVE_PEERCRED=cross)])
+if test x"$samba_cv_HAVE_PEERCRED" = x"yes"; then
+    AC_DEFINE(HAVE_PEERCRED,1,[Whether we can use SO_PEERCRED to get socket credentials])
+fi
 
 #################################################
-# Check to see if we should use the included popt 
+# Check to see if we should use the included popt
 
 AC_ARG_WITH(included-popt,
 [  --with-included-popt    use bundled popt library, not from system],
-[ 
+[
   case "$withval" in
        yes)
                INCLUDED_POPT=yes
@@ -5301,18 +6048,55 @@ fi
 AC_MSG_CHECKING(whether to use included popt)
 if test x"$INCLUDED_POPT" = x"yes"; then
     AC_MSG_RESULT(yes)
-    BUILD_POPT='$(POPT_OBJS)'
-       POPTLIBS='$(POPT_OBJS)'
-    FLAGS1="-I$srcdir/popt"
+    BUILD_POPT='$(POPT_OBJ)'
+    POPTLIBS='$(POPT_OBJ)'
+    FLAGS1="-I\$(srcdir)/popt"
 else
     AC_MSG_RESULT(no)
-       BUILD_POPT=""
+    BUILD_POPT=""
     POPTLIBS="-lpopt"
 fi
 AC_SUBST(BUILD_POPT)
 AC_SUBST(POPTLIBS)
 AC_SUBST(FLAGS1)
 
+#################################################
+# Check to see if we should use the included iniparser
+
+AC_ARG_WITH(included-iniparser,
+[  --with-included-iniparser    use bundled iniparser library, not from system],
+[
+  case "$withval" in
+       yes)
+               INCLUDED_INIPARSER=yes
+               ;;
+        no)
+               INCLUDED_INIPARSER=no
+                ;;
+  esac ],
+)
+if test x"$INCLUDED_INIPARSER" != x"yes"; then
+    AC_CHECK_LIB(iniparser, iniparser_load,
+                INCLUDED_INIPARSER=no, INCLUDED_INIPARSER=yes)
+fi
+
+AC_MSG_CHECKING(whether to use included iniparser)
+if test x"$INCLUDED_INIPARSER" = x"yes"; then
+    AC_MSG_RESULT(yes)
+    BUILD_INIPARSER='$(INIPARSER_OBJ)'
+       INIPARSERLIBS=""
+    FLAGS1="$FLAGS1 -I\$(srcdir)/iniparser/src"
+else
+    AC_MSG_RESULT(no)
+       BUILD_INIPARSER=""
+    INIPARSERLIBS="-liniparser"
+fi
+AC_SUBST(BUILD_INIPARSER)
+AC_SUBST(INIPARSERLIBS)
+AC_SUBST(FLAGS1)
+
+
+
 #################################################
 # Check if the user wants Python
 
@@ -5358,11 +6142,15 @@ done
 
 dnl Always built these modules static
 MODULE_rpc_spoolss=STATIC
-MODULE_rpc_srv=STATIC
+MODULE_rpc_srvsvc=STATIC
 MODULE_idmap_tdb=STATIC
+MODULE_idmap_passdb=STATIC
+MODULE_idmap_nss=STATIC
+
+MODULE_nss_info_template=STATIC
 
 AC_ARG_WITH(static-modules,
-[  --with-static-modules=MODULES  Comma-seperated list of names of modules to statically link in],
+[  --with-static-modules=MODULES  Comma-separated list of names of modules to statically link in],
 [ if test $withval; then
        for i in `echo $withval | sed -e 's/,/ /g'`
        do
@@ -5371,7 +6159,7 @@ AC_ARG_WITH(static-modules,
 fi ])
 
 AC_ARG_WITH(shared-modules,
-[  --with-shared-modules=MODULES  Comma-seperated list of names of modules to build shared],
+[  --with-shared-modules=MODULES  Comma-separated list of names of modules to build shared],
 [ if test $withval; then
        for i in `echo $withval | sed -e 's/,/ /g'`
        do
@@ -5379,7 +6167,7 @@ AC_ARG_WITH(shared-modules,
        done
 fi ])
 
-SMB_MODULE(pdb_ldap, passdb/pdb_ldap.o passdb/pdb_nds.o, "bin/ldapsam.$SHLIBEXT", PDB, 
+SMB_MODULE(pdb_ldap, passdb/pdb_ldap.o passdb/pdb_nds.o, "bin/ldapsam.$SHLIBEXT", PDB,
                   [ PASSDB_LIBS="$PASSDB_LIBS $LDAP_LIBS" ] )
 SMB_MODULE(pdb_smbpasswd, passdb/pdb_smbpasswd.o, "bin/smbpasswd.$SHLIBEXT", PDB)
 SMB_MODULE(pdb_tdbsam, passdb/pdb_tdb.o, "bin/tdbsam.$SHLIBEXT", PDB)
@@ -5387,25 +6175,33 @@ SMB_SUBSYSTEM(PDB,passdb/pdb_interface.o)
 
 
 SMB_MODULE(rpc_lsa, \$(RPC_LSA_OBJ), "bin/librpc_lsarpc.$SHLIBEXT", RPC)
-SMB_MODULE(rpc_reg, \$(RPC_REG_OBJ), "bin/librpc_winreg.$SHLIBEXT", RPC)
+SMB_MODULE(rpc_winreg, \$(RPC_REG_OBJ), "bin/librpc_winreg.$SHLIBEXT", RPC)
+SMB_MODULE(rpc_initshutdown, \$(RPC_INITSHUTDOWN_OBJ), "bin/librpc_initshutdown.$SHLIBEXT", RPC)
 SMB_MODULE(rpc_lsa_ds, \$(RPC_LSA_DS_OBJ), "bin/librpc_lsa_ds.$SHLIBEXT", RPC)
-SMB_MODULE(rpc_wks, \$(RPC_WKS_OBJ), "bin/librpc_wkssvc.$SHLIBEXT", RPC)
+SMB_MODULE(rpc_wkssvc, \$(RPC_WKS_OBJ), "bin/librpc_wkssvc.$SHLIBEXT", RPC)
 SMB_MODULE(rpc_svcctl, \$(RPC_SVCCTL_OBJ), "bin/librpc_svcctl.$SHLIBEXT", RPC)
 SMB_MODULE(rpc_ntsvcs, \$(RPC_NTSVCS_OBJ), "bin/librpc_ntsvcs.$SHLIBEXT", RPC)
 SMB_MODULE(rpc_net, \$(RPC_NETLOG_OBJ), "bin/librpc_NETLOGON.$SHLIBEXT", RPC)
 SMB_MODULE(rpc_netdfs, \$(RPC_DFS_OBJ), "bin/librpc_netdfs.$SHLIBEXT", RPC)
-SMB_MODULE(rpc_srv, \$(RPC_SVC_OBJ), "bin/librpc_srvsvc.$SHLIBEXT", RPC)
+SMB_MODULE(rpc_srvsvc, \$(RPC_SVC_OBJ), "bin/librpc_srvsvc.$SHLIBEXT", RPC)
 SMB_MODULE(rpc_spoolss, \$(RPC_SPOOLSS_OBJ), "bin/librpc_spoolss.$SHLIBEXT", RPC)
 SMB_MODULE(rpc_eventlog, \$(RPC_EVENTLOG_OBJ), "bin/librpc_eventlog.$SHLIBEXT", RPC)
 SMB_MODULE(rpc_samr, \$(RPC_SAMR_OBJ), "bin/librpc_samr.$SHLIBEXT", RPC)
-SMB_MODULE(rpc_echo, \$(RPC_ECHO_OBJ), "bin/librpc_echo.$SHLIBEXT", RPC)
+SMB_MODULE(rpc_rpcecho, \$(RPC_ECHO_OBJ), "bin/librpc_echo.$SHLIBEXT", RPC)
+SMB_MODULE(rpc_unixinfo, \$(RPC_UNIXINFO_OBJ), "bin/librpc_unixinfo.$SHLIBEXT", RPC)
+SMB_MODULE(rpc_epmapper, \$(RPC_EPMAPPER_OBJ), "bin/librpc_epmapper.$SHLIBEXT", RPC)
 SMB_SUBSYSTEM(RPC,smbd/server.o)
 
-SMB_MODULE(idmap_ldap, sam/idmap_ldap.o, "bin/ldap.$SHLIBEXT", IDMAP)
-SMB_MODULE(idmap_tdb, sam/idmap_tdb.o, "bin/tdb.$SHLIBEXT", IDMAP)
-SMB_MODULE(idmap_rid, sam/idmap_rid.o, "bin/rid.$SHLIBEXT", IDMAP)
-SMB_MODULE(idmap_ad, sam/idmap_ad.o, "bin/ad.$SHLIBEXT", IDMAP)
-SMB_SUBSYSTEM(IDMAP,sam/idmap.o)
+SMB_MODULE(idmap_ldap, nsswitch/idmap_ldap.o, "bin/ldap.$SHLIBEXT", IDMAP)
+SMB_MODULE(idmap_tdb, nsswitch/idmap_tdb.o, "bin/tdb.$SHLIBEXT", IDMAP)
+SMB_MODULE(idmap_passdb, nsswitch/idmap_passdb.o, "bin/passdb.$SHLIBEXT", IDMAP)
+SMB_MODULE(idmap_nss, nsswitch/idmap_nss.o, "bin/nss.$SHLIBEXT", IDMAP)
+SMB_MODULE(idmap_rid, nsswitch/idmap_rid.o, "bin/rid.$SHLIBEXT", IDMAP)
+SMB_MODULE(idmap_ad, nsswitch/idmap_ad.o, "bin/ad.$SHLIBEXT", IDMAP)
+SMB_SUBSYSTEM(IDMAP, nsswitch/idmap.o)
+
+SMB_MODULE(nss_info_template, nsswitch/nss_info_template.o, "bin/template.$SHLIBEXT", NSS_INFO)
+SMB_SUBSYSTEM(NSS_INFO, nsswitch/nss_info.o)
 
 SMB_MODULE(charset_weird, modules/weird.o, "bin/weird.$SHLIBEXT", CHARSET)
 SMB_MODULE(charset_CP850, modules/CP850.o, "bin/CP850.$SHLIBEXT", CHARSET)
@@ -5413,7 +6209,6 @@ SMB_MODULE(charset_CP437, modules/CP437.o, "bin/CP437.$SHLIBEXT", CHARSET)
 SMB_MODULE(charset_macosxfs, modules/charset_macosxfs.o,"bin/macosxfs.$SHLIBEXT", CHARSET)
 SMB_SUBSYSTEM(CHARSET,lib/iconv.o)
 
-SMB_MODULE(auth_rhosts, \$(AUTH_RHOSTS_OBJ), "bin/rhosts.$SHLIBEXT", AUTH)
 SMB_MODULE(auth_sam, \$(AUTH_SAM_OBJ), "bin/sam.$SHLIBEXT", AUTH)
 SMB_MODULE(auth_unix, \$(AUTH_UNIX_OBJ), "bin/unix.$SHLIBEXT", AUTH)
 SMB_MODULE(auth_winbind, \$(AUTH_WINBIND_OBJ), "bin/winbind.$SHLIBEXT", AUTH)
@@ -5423,6 +6218,7 @@ SMB_MODULE(auth_builtin, \$(AUTH_BUILTIN_OBJ), "bin/builtin.$SHLIBEXT", AUTH)
 SMB_MODULE(auth_script, \$(AUTH_SCRIPT_OBJ), "bin/script.$SHLIBEXT", AUTH)
 SMB_SUBSYSTEM(AUTH,auth/auth.o)
 
+SMB_MODULE(vfs_default, \$(VFS_DEFAULT_OBJ), "bin/default.$SHLIBEXT", VFS)
 SMB_MODULE(vfs_recycle, \$(VFS_RECYCLE_OBJ), "bin/recycle.$SHLIBEXT", VFS)
 SMB_MODULE(vfs_audit, \$(VFS_AUDIT_OBJ), "bin/audit.$SHLIBEXT", VFS)
 SMB_MODULE(vfs_extd_audit, \$(VFS_EXTD_AUDIT_OBJ), "bin/extd_audit.$SHLIBEXT", VFS)
@@ -5435,7 +6231,21 @@ SMB_MODULE(vfs_cap, \$(VFS_CAP_OBJ), "bin/cap.$SHLIBEXT", VFS)
 SMB_MODULE(vfs_expand_msdfs, \$(VFS_EXPAND_MSDFS_OBJ), "bin/expand_msdfs.$SHLIBEXT", VFS)
 SMB_MODULE(vfs_shadow_copy, \$(VFS_SHADOW_COPY_OBJ), "bin/shadow_copy.$SHLIBEXT", VFS)
 SMB_MODULE(vfs_afsacl, \$(VFS_AFSACL_OBJ), "bin/afsacl.$SHLIBEXT", VFS)
+SMB_MODULE(vfs_posixacl, \$(VFS_POSIXACL_OBJ), "bin/posixacl.$SHLIBEXT", VFS)
+SMB_MODULE(vfs_aixacl, \$(VFS_AIXACL_OBJ), "bin/aixacl.$SHLIBEXT", VFS)
+SMB_MODULE(vfs_aixacl2, \$(VFS_AIXACL2_OBJ), "bin/aixacl2.$SHLIBEXT", VFS)
+SMB_MODULE(vfs_solarisacl, \$(VFS_SOLARISACL_OBJ), "bin/solarisacl.$SHLIBEXT", VFS)
+SMB_MODULE(vfs_irixacl, \$(VFS_IRIXACL_OBJ), "bin/irixacl.$SHLIBEXT", VFS)
+SMB_MODULE(vfs_hpuxacl, \$(VFS_HPUXACL_OBJ), "bin/hpuxacl.$SHLIBEXT", VFS)
+SMB_MODULE(vfs_tru64acl, \$(VFS_TRU64ACL_OBJ), "bin/tru64acl.$SHLIBEXT", VFS)
 SMB_MODULE(vfs_catia, \$(VFS_CATIA_OBJ), "bin/catia.$SHLIBEXT", VFS)
+SMB_MODULE(vfs_cacheprime, \$(VFS_CACHEPRIME_OBJ), "bin/cacheprime.$SHLIBEXT", VFS)
+SMB_MODULE(vfs_prealloc, \$(VFS_PREALLOC_OBJ), "bin/prealloc.$SHLIBEXT", VFS)
+SMB_MODULE(vfs_commit, \$(VFS_COMMIT_OBJ), "bin/commit.$SHLIBEXT", VFS)
+SMB_MODULE(vfs_gpfs, \$(VFS_GPFS_OBJ), "bin/gpfs.$SHLIBEXT", VFS)
+SMB_MODULE(vfs_notify_fam, \$(VFS_NOTIFY_FAM_OBJ), "bin/notify_fam.$SHLIBEXT", VFS)
+SMB_MODULE(vfs_readahead, \$(VFS_READAHEAD_OBJ), "bin/readahead.$SHLIBEXT", VFS)
+
 SMB_SUBSYSTEM(VFS,smbd/vfs.o)
 
 AC_DEFINE_UNQUOTED(STRING_STATIC_MODULES, "$string_static_modules", [String list of builtin modules])
@@ -5447,16 +6257,111 @@ if test "${ac_cv_prog_CC}" = "insure"; then
        CPPFLAGS="$CPPFLAGS -D__INSURE__"
 fi
 
+#################################################
+# If run from the build farm, enable NASTY hacks
+#################################################
+AC_MSG_CHECKING(whether to enable build farm hacks)
+if test x"$RUN_FROM_BUILD_FARM" = x"yes"; then
+       AC_MSG_RESULT(yes)
+       AC_DEFINE(ENABLE_BUILD_FARM_HACKS, 1, [Defined if running in the build farm])
+else
+       AC_MSG_RESULT(no)
+fi
+
+#################################################
+# check for bad librt/libpthread interactions
+
+if test x"$samba_cv_HAVE_KERNEL_OPLOCKS_LINUX" = x"yes" -o \
+    x"$samba_cv_HAVE_KERNEL_CHANGE_NOTIFY" = x"yes" -o \
+    x"$samba_cv_HAVE_AIO64" = x"yes" -o \
+    x"$samba_cv_HAVE_AIO" = x"yes" ; then
+
+SMB_IF_RTSIGNAL_BUG(
+       [
+           # Have RT_SIGNAL bug, need to check whether the problem will
+           # affect anything we have configured.
+
+           rt_do_error=no
+           if test x"$samba_cv_HAVE_KERNEL_OPLOCKS_LINUX" = x"yes"; then
+               if test x"$rt_signal_lease_ok" = x"no" ; then
+                   rt_do_error=yes
+               fi
+           fi
+
+           if test x"$samba_cv_HAVE_KERNEL_CHANGE_NOTIFY" = x"yes"; then
+               if test x"$rt_signal_notify_ok" = x"no" ; then
+                   rt_do_error=yes
+               fi
+           fi
+
+           if test x"$samba_cv_HAVE_AIO64" = x"yes" -o \
+                   x"$samba_cv_HAVE_AIO" = x"yes" ; then
+               if test x"$rt_signal_aio_ok" = x"no" ; then
+                   rt_do_error=yes
+               fi
+           fi
+
+           if test x"$rt_do_error" = x"yes" ; then
+               SMB_IS_LIBPTHREAD_LINKED(
+                   [
+                       cat<<MSG
+
+*** On this platforms, linking Samba against pthreads causes problems
+*** with the oplock and change notification mechanisms. You may be
+*** using pthreads as a side-effect of using the --with-aio-support
+*** or --with-profiling-data options. Please remove these and try again.
+
+MSG
+                   ],
+                   [
+                       cat<<MSG
+
+*** On this platform, the oplock and change notification mechanisms do not
+*** appear to work. Please report this problem to samba-technical@samba.org
+*** and attach the config.log file from this directory.
+
+MSG
+                   ])
+               AC_MSG_ERROR(unable to use realtime signals on this platform)
+           fi
+       ],
+       [
+           # no RT_SIGNAL bug, we are golden
+           SMB_IS_LIBPTHREAD_LINKED(
+               [
+                   AC_MSG_WARN(using libpthreads - this may degrade performance)
+               ])
+
+       ],
+       [
+           # cross compiling, I hope you know what you are doing
+           true
+       ])
+
+fi
+
+dnl Remove -L/usr/lib/? from LDFLAGS and LIBS
+LIB_REMOVE_USR_LIB(LDFLAGS)
+LIB_REMOVE_USR_LIB(LIBS)
+LIB_REMOVE_USR_LIB(KRB5_LIBS)
+
+dnl Remove -I/usr/include/? from CFLAGS and CPPFLAGS
+CFLAGS_REMOVE_USR_INCLUDE(CFLAGS)
+CFLAGS_REMOVE_USR_INCLUDE(CPPFLAGS)
+
 #################################################
 # Display summary of libraries detected
 
 AC_MSG_RESULT([Using libraries:])
 AC_MSG_RESULT([    LIBS = $LIBS])
 if test x"$with_ads_support" != x"no"; then
-   AC_MSG_RESULT([    KRB5_LIBS = $KRB5_LIBS])
+    AC_MSG_RESULT([    KRB5_LIBS = $KRB5_LIBS])
 fi
 if test x"$with_ldap_support" != x"no"; then
-   AC_MSG_RESULT([    LDAP_LIBS = $LDAP_LIBS])
+    AC_MSG_RESULT([    LDAP_LIBS = $LDAP_LIBS])
+fi
+if test x"$with_dnsupdate_support" != x"no"; then
+    AC_MSG_RESULT([    UUID_LIBS = $UUID_LIBS])
 fi
 AC_MSG_RESULT([    AUTH_LIBS = $AUTH_LIBS])
 
@@ -5469,22 +6374,19 @@ AC_TRY_RUN([#include "${srcdir-.}/tests/summary.c"],
           AC_MSG_ERROR([summary failure. Aborting config]); exit 1;,
           AC_MSG_WARN([cannot run when cross-compiling]))
 
+dnl Merge in developer cflags from now on
+if test x"$developer" = x"yes"; then
+    CFLAGS="${CFLAGS} ${DEVELOPER_CFLAGS}"
+fi
+
 builddir=`pwd`
 AC_SUBST(builddir)
 
 # Stuff the smbd-only libraries at the end of the smbd link
 # path (if we have them).
-SMBD_LIBS="$samba_fam_libs $samba_dmapi_libs"
+SMBD_LIBS="$samba_dmapi_libs"
 AC_SUBST(SMBD_LIBS)
 
-dnl Remove -L/usr/lib/? from LDFLAGS and LIBS
-LIB_REMOVE_USR_LIB(LDFLAGS)
-LIB_REMOVE_USR_LIB(LIBS)
-
-dnl Remove -I/usr/include/? from CFLAGS and CPPFLAGS
-CFLAGS_REMOVE_USR_INCLUDE(CFLAGS)
-CFLAGS_REMOVE_USR_INCLUDE(CPPFLAGS)
-
 AC_OUTPUT(include/stamp-h Makefile script/findsmb smbadduser script/gen-8bit-gap.sh script/installbin.sh script/uninstallbin.sh)
 
 #################################################