r22102: Remove obsoleted SHLIBS_PROGS from {Makefile,configure}.in.
[abartlet/samba.git/.git] / source3 / configure.in
index 81ccbb472285d15c717e3cdb4cf83f52470d57d4..ea6ba6b4f726564f501b873cfe8c77ea06074025 100644 (file)
@@ -4,11 +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_LIBREPLACE_LOCATION_CHECKS
-
-AC_DISABLE_STATIC
-AC_ENABLE_SHARED
+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}"
@@ -18,6 +14,11 @@ if test -n "${SAMBA_VERSION_SVN_REVISION}";then
        echo "BUILD REVISION: ${SAMBA_VERSION_SVN_REVISION}"
 fi
 
+AC_LIBREPLACE_LOCATION_CHECKS
+
+AC_DISABLE_STATIC
+AC_ENABLE_SHARED
+
 #################################################
 # Directory handling stuff to support both the
 # legacy SAMBA directories and FHS compliant
@@ -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-.}/lib/talloc"
 SAMBA_CPPFLAGS="${SAMBA_CPPFLAGS} -I${srcdir-.}/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,7 +294,6 @@ 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)
@@ -298,6 +301,7 @@ AC_SUBST(SMBWRAPPER)
 AC_SUBST(SMBWRAP_OBJS)
 AC_SUBST(SMBWRAP_INC)
 AC_SUBST(EXTRA_BIN_PROGS)
+AC_SUBST(SMBMOUNT_PROGS)
 AC_SUBST(CIFSMOUNT_PROGS)
 AC_SUBST(INSTALL_CIFSMOUNT)
 AC_SUBST(UNINSTALL_CIFSMOUNT)
@@ -306,6 +310,14 @@ AC_SUBST(EXTRA_ALL_TARGETS)
 AC_SUBST(CONFIG_LIBS)
 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, 
+[  --enable-debug          Turn on compiler debugging information (default=no)],
+    [if eval "test x$enable_debug = xyes"; then
+       CFLAGS="${CFLAGS} -g"
+    fi])
+
 # compile with optimization and without debugging by default, but
 # allow people to set their own preference.
 # do this here since AC_CACHE_CHECK apparently sets the CFLAGS to "-g -O2"
@@ -315,41 +327,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
-
-AC_ARG_ENABLE(debug, 
-[  --enable-debug          Turn on compiler debugging information (default=no)],
-    [if eval "test x$enable_debug = xyes"; then
-       CFLAGS="${CFLAGS} -g"
-    fi])
-
 m4_include(lib/socket_wrapper/config.m4)
 
 #################################################
@@ -532,9 +513,41 @@ 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_WARN([c99 structure initializer are not supported])])
+LIBREPLACE_C99_STRUCT_INIT([],[AC_MSG_ERROR([c99 structure initializer are not supported])])
 
 UNAME_S=`(uname -s) 2>/dev/null` || UNAME_S="unknown"
 AC_MSG_CHECKING(uname -s)
@@ -574,10 +587,11 @@ 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_reg rpc_lsa_ds rpc_wks rpc_svcctl rpc_ntsvcs rpc_net rpc_netdfs rpc_srv 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"
@@ -593,7 +607,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.
@@ -799,21 +812,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])
@@ -841,7 +843,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
@@ -849,6 +851,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)
@@ -858,11 +863,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
@@ -908,40 +912,15 @@ case "$host_os" in
                fi
        ;;
 esac
-AC_CHECK_HEADERS(shadow.h netinet/tcp.h netinet/in_systm.h netinet/in_ip.h)
-AC_CHECK_HEADERS(nss.h nss_common.h nsswitch.h ns_api.h sys/security.h security/pam_appl.h)
-AC_CHECK_HEADERS(stropts.h poll.h)
+AC_CHECK_HEADERS(shadow.h)
+AC_CHECK_HEADERS(nss.h nss_common.h nsswitch.h ns_api.h sys/security.h)
 AC_CHECK_HEADERS(syscall.h sys/syscall.h)
 
-AC_CHECK_HEADERS(sys/acl.h sys/attributes.h attr/xattr.h sys/xattr.h sys/extattr.h sys/uio.h)
+AC_CHECK_HEADERS(sys/attributes.h attr/xattr.h sys/xattr.h sys/extattr.h sys/uio.h)
 AC_CHECK_HEADERS(sys/ea.h sys/proplist.h)
 
 AC_CHECK_HEADERS(sys/cdefs.h glob.h)
 
-AC_CHECK_HEADERS(netinet/ip.h,,,[[
-#include <sys/types.h>
-#if HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
-#include <netinet/in.h>
-#if HAVE_NETINET_IN_SYSTM_H
-#include <netinet/in_systm.h>
-#endif
-]])
-
-AC_CHECK_HEADERS(net/if.h,,,[[
-#include <sys/types.h>
-#if HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
-]])
-
-AC_CHECK_HEADERS(security/pam_modules.h,,,[[
-#if HAVE_SECURITY_PAM_APPL_H
-#include <security/pam_appl.h>
-#endif
-]])
-
 # For experimental utmp support (lastlog on some BSD-like systems)
 AC_CHECK_HEADERS(utmp.h utmpx.h lastlog.h)
  
@@ -1002,33 +981,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>],
@@ -1216,6 +1169,13 @@ AC_CHECK_LIB(readline, 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
@@ -1261,9 +1221,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)
@@ -1271,21 +1232,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.
@@ -1615,6 +1593,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* )
@@ -1628,6 +1630,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"
 
@@ -1635,21 +1665,18 @@ 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
@@ -1658,9 +1685,8 @@ if test "$enable_shared" = "yes"; then
                                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])
@@ -1668,18 +1694,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"
+                               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])
@@ -1688,7 +1712,7 @@ 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])
                        ;;
@@ -1697,7 +1721,7 @@ if test "$enable_shared" = "yes"; then
                        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])
                        ;;
@@ -1705,7 +1729,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])
                        ;;
@@ -1719,20 +1743,19 @@ if test "$enable_shared" = "yes"; then
                        SONAMEFLAG="-soname "
                        SHLD="\${LD}"
                        if test "${GCC}" = "yes"; then
-                               PICFLAGS="-fPIC"
+                               PICFLAG="-fPIC"
                        else 
-                               PICFLAGS="-KPIC"
+                               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"
@@ -1744,14 +1767,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"
@@ -1770,7 +1794,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])
                        ;;
@@ -1781,7 +1805,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])
@@ -1819,41 +1843,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_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,[
@@ -2455,36 +2520,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
 
 #################################################
@@ -2664,40 +2749,6 @@ if test x"$samba_cv_HAVE_BROKEN_GETGROUPS" = x"yes"; then
     AC_DEFINE(HAVE_BROKEN_GETGROUPS,1,[Whether getgroups is broken])
 fi
 
-AC_CACHE_CHECK([whether getpass should be replaced],samba_cv_REPLACE_GETPASS,[
-SAVE_CPPFLAGS="$CPPFLAGS"
-CPPFLAGS="$CPPFLAGS ${SAMBA_CONFIGURE_CPPFLAGS}"
-AC_TRY_COMPILE([
-#define REPLACE_GETPASS 1
-#define NO_PROTO_H 1
-#define NO_CONFIG_H 1
-#define main dont_declare_main
-#include "${srcdir-.}/lib/getsmbpass.c"
-#undef main
-],[],samba_cv_REPLACE_GETPASS=yes,samba_cv_REPLACE_GETPASS=no)
-CPPFLAGS="$SAVE_CPPFLAGS"
-])
-if test x"$samba_cv_REPLACE_GETPASS" = x"yes"; then
-       AC_DEFINE(REPLACE_GETPASS,1,[Whether getpass should be replaced])
-fi
-
-AC_CACHE_CHECK([for broken inet_ntoa],samba_cv_REPLACE_INET_NTOA,[
-AC_TRY_RUN([
-#include <stdio.h>
-#include <sys/types.h>
-#include <netinet/in.h>
-#ifdef HAVE_ARPA_INET_H
-#include <arpa/inet.h>
-#endif
-main() { struct in_addr ip; ip.s_addr = 0x12345678;
-if (strcmp(inet_ntoa(ip),"18.52.86.120") &&
-    strcmp(inet_ntoa(ip),"120.86.52.18")) { exit(0); } 
-exit(1);}],
-           samba_cv_REPLACE_INET_NTOA=yes,samba_cv_REPLACE_INET_NTOA=no,samba_cv_REPLACE_INET_NTOA=cross)])
-if test x"$samba_cv_REPLACE_INET_NTOA" = x"yes"; then
-    AC_DEFINE(REPLACE_INET_NTOA,1,[Whether inet_ntoa should be replaced])
-fi
-
 AC_CACHE_CHECK([for secure mkstemp],samba_cv_HAVE_SECURE_MKSTEMP,[
 AC_TRY_RUN([#include <stdlib.h>
 #include <sys/types.h>
@@ -2744,15 +2795,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;
@@ -2934,6 +2976,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,[
@@ -3112,6 +3171,9 @@ SMBLDAP=""
 AC_SUBST(SMBLDAP)
 SMBLDAPUTIL=""
 AC_SUBST(SMBLDAPUTIL)
+LDBLDAP=""
+AC_SUBST(LDBLDAP)
+
 if test x"$with_ldap_support" != x"no"; then
 
   ##################################################################
@@ -3130,16 +3192,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
@@ -3172,7 +3244,7 @@ if test x"$with_ldap_support" != x"no"; then
   
   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])
@@ -3181,6 +3253,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)
@@ -3231,6 +3309,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
@@ -3241,6 +3334,9 @@ else
            with_ads_support=no
        fi
     fi
+    ;;
+esac
+
 
     AC_CHECK_FUNC_EXT(ldap_add_result_entry,$LDAP_LIBS)
 
@@ -3378,11 +3474,14 @@ if test x"$with_ads_support" != x"no"; then
     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
@@ -3400,8 +3499,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
@@ -3411,11 +3509,13 @@ 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)
@@ -3427,20 +3527,18 @@ if test x"$with_ads_support" != x"no"; then
   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_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_c_verify_checksum, $KRB5_LIBS)
   AC_CHECK_FUNC_EXT(krb5_principal_compare_any_realm, $KRB5_LIBS)
@@ -3450,9 +3548,56 @@ 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>], 
@@ -3722,21 +3867,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([
@@ -3784,10 +3914,106 @@ 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
 
 AC_CHECK_LIB_EXT(nscd, NSCD_LIBS, nscd_flush_cache)
+PASSDB_LIBS="$PASSDB_LIBS $NSCD_LIBS"
 
 
 ########################################################
@@ -3830,29 +4056,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"
+  # 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.
   
-  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
+  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
 
 #################################################
@@ -3883,7 +4113,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!)
@@ -3942,33 +4172,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
@@ -3984,14 +4257,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"
@@ -4823,30 +5093,6 @@ 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
 
@@ -4912,54 +5158,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
         ;;
@@ -4988,6 +5264,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,[
@@ -5371,6 +5648,25 @@ 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
+
 
 #################################################
 # Check whether winbind is supported on this platform.  If so we need to
@@ -5388,19 +5684,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"
@@ -5410,6 +5728,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"
@@ -5436,6 +5755,9 @@ AC_SUBST(WINBIND_WINS_NSS)
 AC_SUBST(WINBIND_NSS_LDSHFLAGS)
 AC_SUBST(WINBIND_NSS_EXTRA_OBJS)
 AC_SUBST(WINBIND_NSS_EXTRA_LIBS)
+AC_SUBST(NSSSONAMEVERSIONSUFFIX)
+
+AC_SUBST(SMB_KRB5_LOCATOR)
 
 # Check the setting of --with-winbind
 
@@ -5464,20 +5786,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)
@@ -5542,12 +5865,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)
@@ -5636,11 +5959,15 @@ done
 
 dnl Always built these modules static
 MODULE_rpc_spoolss=STATIC
-MODULE_rpc_srv=STATIC
+MODULE_rpc_srvsvc=STATIC
 MODULE_idmap_tdb=STATIC
+MODULE_idmap_passdb=STATIC
+MODULE_idmap_nss=STATIC
+
+MODULE_nss_info_template=STATIC
 
 AC_ARG_WITH(static-modules,
-[  --with-static-modules=MODULES  Comma-seperated list of names of modules to statically link in],
+[  --with-static-modules=MODULES  Comma-separated list of names of modules to statically link in],
 [ if test $withval; then
        for i in `echo $withval | sed -e 's/,/ /g'`
        do
@@ -5649,7 +5976,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
@@ -5665,26 +5992,33 @@ SMB_SUBSYSTEM(PDB,passdb/pdb_interface.o)
 
 
 SMB_MODULE(rpc_lsa, \$(RPC_LSA_OBJ), "bin/librpc_lsarpc.$SHLIBEXT", RPC)
-SMB_MODULE(rpc_reg, \$(RPC_REG_OBJ), "bin/librpc_winreg.$SHLIBEXT", RPC)
+SMB_MODULE(rpc_winreg, \$(RPC_REG_OBJ), "bin/librpc_winreg.$SHLIBEXT", RPC)
+SMB_MODULE(rpc_initshutdown, \$(RPC_INITSHUTDOWN_OBJ), "bin/librpc_initshutdown.$SHLIBEXT", RPC)
 SMB_MODULE(rpc_lsa_ds, \$(RPC_LSA_DS_OBJ), "bin/librpc_lsa_ds.$SHLIBEXT", RPC)
-SMB_MODULE(rpc_wks, \$(RPC_WKS_OBJ), "bin/librpc_wkssvc.$SHLIBEXT", RPC)
+SMB_MODULE(rpc_wkssvc, \$(RPC_WKS_OBJ), "bin/librpc_wkssvc.$SHLIBEXT", RPC)
 SMB_MODULE(rpc_svcctl, \$(RPC_SVCCTL_OBJ), "bin/librpc_svcctl.$SHLIBEXT", RPC)
 SMB_MODULE(rpc_ntsvcs, \$(RPC_NTSVCS_OBJ), "bin/librpc_ntsvcs.$SHLIBEXT", RPC)
 SMB_MODULE(rpc_net, \$(RPC_NETLOG_OBJ), "bin/librpc_NETLOGON.$SHLIBEXT", RPC)
 SMB_MODULE(rpc_netdfs, \$(RPC_DFS_OBJ), "bin/librpc_netdfs.$SHLIBEXT", RPC)
-SMB_MODULE(rpc_srv, \$(RPC_SVC_OBJ), "bin/librpc_srvsvc.$SHLIBEXT", RPC)
+SMB_MODULE(rpc_srvsvc, \$(RPC_SVC_OBJ), "bin/librpc_srvsvc.$SHLIBEXT", RPC)
 SMB_MODULE(rpc_spoolss, \$(RPC_SPOOLSS_OBJ), "bin/librpc_spoolss.$SHLIBEXT", RPC)
 SMB_MODULE(rpc_eventlog, \$(RPC_EVENTLOG_OBJ), "bin/librpc_eventlog.$SHLIBEXT", RPC)
 SMB_MODULE(rpc_samr, \$(RPC_SAMR_OBJ), "bin/librpc_samr.$SHLIBEXT", RPC)
 SMB_MODULE(rpc_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)
@@ -5725,6 +6059,8 @@ 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_SUBSYSTEM(VFS,smbd/vfs.o)
 
@@ -5820,19 +6156,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])
 
@@ -5853,14 +6198,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)
 
 #################################################