r22376: Make sure we use krb5 when we identify just an older heimdal lib (0.6.x)
[nivanova/samba-autobuild/.git] / source3 / configure.in
index 91796d87af2c2e0a3390308e5953e234390250b7..e652222d1be2b141354da3cf186e48f84cb7852d 100644 (file)
@@ -4,6 +4,7 @@ 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])
 
 SMB_VERSION_STRING=`cat $srcdir/include/version.h | grep 'SAMBA_VERSION_OFFICIAL_STRING' | cut -d '"' -f2`
 echo "SAMBA VERSION: ${SMB_VERSION_STRING}"
@@ -35,7 +36,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)
@@ -45,7 +46,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])
@@ -231,12 +232,18 @@ done
 
 SAMBA_CPPFLAGS="-Iinclude -I${srcdir-.}/include  -I. -I${srcdir-.}"
 SAMBA_CPPFLAGS="${SAMBA_CPPFLAGS} -I${srcdir-.}/lib/replace"
-SAMBA_CPPFLAGS="${SAMBA_CPPFLAGS} -I${srcdir-.}/tdb/include"
+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)
@@ -253,12 +260,9 @@ AC_SUBST(SAMBA_CPPFLAGS)
 AC_SUBST(SHELL)
 AC_SUBST(LDSHFLAGS)
 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)
@@ -290,14 +294,12 @@ 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)
@@ -308,7 +310,7 @@ AC_SUBST(NSCD_LIBS)
 
 ## check for --enable-debug first before checking CFLAGS before
 ## so that we don't mix -O and -g
-AC_ARG_ENABLE(debug, 
+AC_ARG_ENABLE(debug,
 [  --enable-debug          Turn on compiler debugging information (default=no)],
     [if eval "test x$enable_debug = xyes"; then
        CFLAGS="${CFLAGS} -g"
@@ -323,35 +325,10 @@ if test "x$CFLAGS" = x; then
   CFLAGS="-O"
 fi
 
-CFLAGS="${CFLAGS} -D_SAMBA_BUILD_"
+CFLAGS="${CFLAGS} -D_SAMBA_BUILD_=3"
 
 AC_LIBREPLACE_CC_CHECKS
 
-# 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
-
 m4_include(lib/socket_wrapper/config.m4)
 
 #################################################
@@ -383,7 +360,7 @@ 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
@@ -422,7 +399,7 @@ 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
@@ -458,7 +435,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
@@ -512,7 +489,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([
@@ -534,6 +511,38 @@ 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
+
 dnl Figure out the flags to support named structure initializers
 
 LIBREPLACE_C99_STRUCT_INIT([],[AC_MSG_ERROR([c99 structure initializer are not supported])])
@@ -576,13 +585,14 @@ dnl Add #include for broken IRIX header files
 esac
 
 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_winreg rpc_initshutdown rpc_lsa_ds rpc_wkssvc rpc_svcctl rpc_ntsvcs rpc_net rpc_netdfs rpc_srvsvc rpc_spoolss rpc_eventlog rpc_unixinfo auth_sam auth_unix auth_winbind auth_server auth_domain auth_builtin vfs_default"
+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_rpcecho"
@@ -595,7 +605,6 @@ 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*)
 #
 # Defines needed for HPUX support.
@@ -639,7 +648,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..
@@ -801,21 +810,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])
@@ -843,7 +841,7 @@ esac
 
 AC_LIBREPLACE_BROKEN_CHECKS
 
-LIBREPLACE_DIR=`echo ${libreplacedir} |sed -e 's/^\.\///g'`
+LIBREPLACE_DIR=`echo ${libreplacedir} | sed -e "s;${srcdir};;" -e "s;^/;;"`
 
 LIBREPLACE_OBJS=""
 for obj in ${LIBREPLACEOBJ}; do
@@ -851,6 +849,9 @@ for obj in ${LIBREPLACEOBJ}; do
 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 memory.h alloca.h)
 AC_CHECK_HEADERS(limits.h float.h)
@@ -860,11 +861,10 @@ AC_CHECK_HEADERS(sys/mman.h sys/filio.h sys/priv.h sys/shm.h string.h strings.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/sysmacros.h)
 AC_CHECK_HEADERS(sys/syslog.h syslog.h)
 AC_CHECK_HEADERS(langinfo.h locale.h)
 AC_CHECK_HEADERS(xfs/libxfs.h)
-AC_CHECK_HEADERS(security/pam_ext.h)
 
 AC_CHECK_HEADERS(rpcsvc/yp_prot.h,,,[[
 #if HAVE_RPC_RPC_H
@@ -911,24 +911,17 @@ case "$host_os" in
        ;;
 esac
 AC_CHECK_HEADERS(shadow.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(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(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)
@@ -952,7 +945,7 @@ 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_CHECK_TYPE(comparison_fn_t,
 [AC_DEFINE(HAVE_COMPARISON_FN_T, 1,[Whether or not we have comparison_fn_t])])
 
 ############################################
@@ -986,33 +979,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>],
@@ -1039,7 +1006,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)])
@@ -1195,11 +1162,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
@@ -1226,7 +1200,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
@@ -1245,9 +1219,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 strerror chown fchown chmod fchmod chroot link mknod mknod64)
+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 getrlimit fsync memset strlcpy strlcat setpgid)
+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)
@@ -1255,21 +1230,38 @@ 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)
+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)
 
+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.
@@ -1292,7 +1284,7 @@ AC_TRY_LINK(
     ],
     [
        unw_context_t ctx; unw_cursor_t cur;
-       char buf[256]; unw_word_t off; 
+       char buf[256]; unw_word_t off;
        unw_getcontext(&ctx); unw_init_local(&cur, &ctx);
        unw_get_proc_name(&cur, buf, sizeof(buf), &off);
     ],
@@ -1379,28 +1371,38 @@ AC_TRY_COMPILE([
 AC_DEFINE(HAVE_PRCTL, 1, [Whether prctl is available]),[])
 
 #
-# 
+#
 #
 case "$host_os" in
     *linux*)
        # 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 */
+
+                   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)
+                                 exit(1);
+                          if ((libc_major == 2) && (libc_minor <= 3))
+                                 exit(1);
 #endif
-       exit(0);
-}
-], [linux_getgrouplist_ok=yes], [linux_getgrouplist_ok=no])
+                          exit(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
@@ -1460,7 +1462,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
 #
@@ -1599,6 +1601,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* )
@@ -1612,6 +1638,34 @@ 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"
 
@@ -1619,32 +1673,28 @@ BLDSHARED="false"
 HOST_OS="$host_os"
 LDSHFLAGS="-shared"
 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 supports share libs
-  # You need to specify how to create a shared library and
-  # how to compile C code to produce PIC object files
+# 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
 
-  AC_MSG_CHECKING([ability to build shared libraries])
+AC_MSG_CHECKING([ability to build shared libraries])
 
-  # and these are for particular systems
-  case "$host_os" in
+# and these are for particular systems
+case "$host_os" in
                *linux*)   AC_DEFINE(LINUX,1,[Whether the host os is linux])
                        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])
@@ -1652,18 +1702,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])
@@ -1672,16 +1720,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])
                        ;;
@@ -1689,7 +1737,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])
                        ;;
@@ -1703,20 +1751,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:
-                       PICSUFFIX="po.o"
                        if test "${GCC}" != "yes"; then
                                ## for funky AIX compiler using strncpy()
                                CFLAGS="$CFLAGS -D_LINUX_SOURCE_COMPAT -qmaxmem=32000"
@@ -1728,14 +1775,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"
@@ -1754,7 +1802,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])
                        ;;
@@ -1765,7 +1813,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])
@@ -1803,41 +1851,82 @@ if test "$enable_shared" = "yes"; then
                        BLDSHARED="true"
                        LDSHFLAGS="-bundle -flat_namespace -undefined suppress"
                        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,[
@@ -1862,7 +1951,7 @@ 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>
@@ -2083,7 +2172,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];
@@ -2146,7 +2235,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>
@@ -2155,7 +2244,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>
@@ -2164,7 +2253,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>
@@ -2173,7 +2262,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>
@@ -2182,7 +2271,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>
@@ -2191,7 +2280,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>
@@ -2200,7 +2289,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>
@@ -2209,7 +2298,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>
@@ -2218,7 +2307,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>
@@ -2227,7 +2316,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,[
@@ -2247,7 +2336,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
@@ -2281,7 +2370,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.
@@ -2350,7 +2439,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"
@@ -2397,7 +2486,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])
@@ -2439,36 +2528,56 @@ 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; 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
+        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
 
 #################################################
@@ -2653,10 +2762,10 @@ AC_TRY_RUN([#include <stdlib.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <unistd.h>
-main() { 
+main() {
   struct stat st;
-  char tpl[20]="/tmp/test.XXXXXX"; 
-  int fd = mkstemp(tpl); 
+  char tpl[20]="/tmp/test.XXXXXX";
+  int fd = mkstemp(tpl);
   if (fd == -1) exit(1);
   unlink(tpl);
   if (fstat(fd, &st) != 0) exit(1);
@@ -2694,15 +2803,6 @@ SMB_CHECK_SYSCONF(_SC_NPROCESSORS_ONLN)
 SMB_CHECK_SYSCONF(_SC_PAGESIZE)
 AC_CHECK_FUNCS(getpagesize)
 
-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
-
 ##################
 # look for a method of finding the list of network interfaces
 iface=no;
@@ -2833,7 +2933,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([
@@ -2872,7 +2972,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>
@@ -2884,6 +2984,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,[
@@ -2979,7 +3096,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)
@@ -3062,13 +3179,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)
@@ -3080,16 +3200,26 @@ if test x"$with_ldap_support" != x"no"; then
   fi
 
   ##################################################################
-  # HP/UX does not have ber_tag_t, disable LDAP there
-  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
+  # 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)
-       fi
-       with_ldap_support=no
-  fi
+        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
@@ -3113,17 +3243,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"
@@ -3131,6 +3261,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)
@@ -3140,7 +3276,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
@@ -3181,6 +3317,21 @@ else
     # Check to see whether there is enough LDAP functionality to be able
     # to build AD support.
 
+# 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_CHECK_FUNC_EXT(ldap_initialize,$LDAP_LIBS)
 
     if test x"$ac_cv_func_ext_ldap_initialize" != x"yes"; then
@@ -3191,6 +3342,9 @@ else
            with_ads_support=no
        fi
     fi
+    ;;
+esac
+
 
     AC_CHECK_FUNC_EXT(ldap_add_result_entry,$LDAP_LIBS)
 
@@ -3209,7 +3363,7 @@ 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
@@ -3250,7 +3404,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
@@ -3259,7 +3413,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
@@ -3323,16 +3477,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
@@ -3350,8 +3507,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
@@ -3361,37 +3517,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)
@@ -3400,16 +3557,63 @@ if test x"$with_ads_support" != x"no"; then
   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)
 
   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])
 
@@ -3509,7 +3713,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;],
@@ -3611,7 +3815,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>],
@@ -3672,21 +3876,6 @@ if test x"$with_ads_support" != x"no"; then
               [Whether the krb5_address struct has a magic property])
   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 
-  fi
-
   AC_CACHE_CHECK([for WRFILE: keytab support],
                 samba_cv_HAVE_WRFILE_KEYTAB,[
     AC_TRY_RUN([
@@ -3734,6 +3923,101 @@ if test x"$with_ads_support" != x"no"; then
                [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
+
+
+  #
+  #
+  # 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
 
@@ -3769,7 +4053,7 @@ if test x"$with_dnsupdate_support" != x"no"; then
   # 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)
@@ -3781,29 +4065,33 @@ if test x"$with_dnsupdate_support" != x"no"; then
 fi
 
 if test x"$with_dnsupdate_support" != x"no"; then
-  ac_save_LIBS=$LIBS
 
   ########################################################
-  # now see if we can find the uuid libs in standard paths
-  AC_CHECK_LIB_EXT(uuid, UUID_LIBS, uuid_generate)
-
-  LIBS="$LIBS $UUID_LIBS"
-  
-  if test x"$ac_cv_lib_ext_uuid_uuid_generate" = x"yes"; then
-    with_dnsupdate_support=yes
-    AC_DEFINE(WITH_DNS_UPDATES,1,[Whether to enable DNS Update support])
-    AC_MSG_CHECKING(whether UUID support is used)
-    AC_MSG_RESULT(yes)
-  else
-    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
-    UUID_LIBS=""
-    with_dnsupdate_support=no
-  fi
-  LIBS=$ac_save_LIBS
+  # 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
 
 #################################################
@@ -3834,7 +4122,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!)
@@ -3893,33 +4181,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
+
+       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
 
-# 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(pam, pam_vsyslog, [AC_DEFINE(HAVE_PAM_VSYSLOG,1,[Whether pam_vsyslog is available])])
+       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
@@ -3935,14 +4266,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"
@@ -3981,7 +4309,7 @@ fi
 fi
 
 #################################################
-# 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)],
@@ -4157,7 +4485,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"
@@ -4238,13 +4566,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
@@ -4267,7 +4595,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
@@ -4386,7 +4714,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)
      ;;
   *)
@@ -4433,7 +4761,7 @@ 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) 
+  no)
      AC_MSG_RESULT(no)
      ;;
   *)
@@ -4479,7 +4807,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)
      ;;
   *)
@@ -4774,35 +5102,11 @@ 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])
-            ;;
-
-        powerpc)
-            AC_DEFINE(POWERPC_SPINLOCKS,1,[Whether to use powerpc spinlocks])
-            ;;
-    esac
-fi
-
 #################################################
 # check for cluster extensions
 
 AC_MSG_CHECKING(whether to include cluster support)
-AC_ARG_WITH(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])
@@ -4863,54 +5167,84 @@ AC_ARG_WITH(acl-support,
                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
         ;;
@@ -4939,6 +5273,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,[
@@ -5322,6 +5657,45 @@ 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
@@ -5339,19 +5713,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*)
+               NSSSONAMEVERSIONSUFFIX=".2"
                WINBIND_NSS_EXTRA_OBJS="nsswitch/winbind_nss_linux.o"
                ;;
        *freebsd[[5-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"
@@ -5361,6 +5757,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"
@@ -5387,12 +5784,19 @@ 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)
+
+if test $BLDSHARED = true -a x"$HAVE_WINBIND" = x"yes"; then
+       NSS_MODULES="${WINBIND_NSS} ${WINBIND_WINS_NSS}"
+fi
+
+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
@@ -5415,20 +5819,21 @@ fi
 
 # Display test results
 
+if test x"$HAVE_WINBIND" = x"no"; then
+       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)
@@ -5440,8 +5845,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>])
@@ -5471,11 +5876,11 @@ 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
@@ -5493,12 +5898,12 @@ 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)'
+    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)
@@ -5506,11 +5911,11 @@ AC_SUBST(POPTLIBS)
 AC_SUBST(FLAGS1)
 
 #################################################
-# Check to see if we should use the included iniparser 
+# 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
@@ -5589,9 +5994,13 @@ dnl Always built these modules static
 MODULE_rpc_spoolss=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
@@ -5600,7 +6009,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
@@ -5608,7 +6017,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)
@@ -5630,13 +6039,19 @@ SMB_MODULE(rpc_eventlog, \$(RPC_EVENTLOG_OBJ), "bin/librpc_eventlog.$SHLIBEXT",
 SMB_MODULE(rpc_samr, \$(RPC_SAMR_OBJ), "bin/librpc_samr.$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)
@@ -5677,6 +6092,9 @@ 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)
 
@@ -5772,19 +6190,28 @@ MSG
 
 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])
+    AC_MSG_RESULT([    UUID_LIBS = $UUID_LIBS])
 fi
 AC_MSG_RESULT([    AUTH_LIBS = $AUTH_LIBS])
 
@@ -5805,14 +6232,6 @@ AC_SUBST(builddir)
 SMBD_LIBS="$samba_fam_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)
 
 #################################################