s3/rpc_server/mdssvc: Generate flex/bison files in build
[samba.git] / source3 / wscript
index 271314d723b0d950cf2bf197e8b0e5f0e36328ea..01d52740dafac001d5cc6fb7a77b0a80071a920b 100644 (file)
@@ -10,25 +10,39 @@ import wafsamba, Options, Logs, Utils, Scripting
 import build.charset
 import samba_utils, samba_version
 import samba3
+import bison, flex
 
-Options.default_prefix = '/usr/local/samba'
+default_prefix = Options.default_prefix = '/usr/local/samba'
 
 def set_options(opt):
 
     opt.add_option('--with-static-modules',
-                   help=("Comma-separated list of names of modules to statically link in"),
+                   help=("Comma-separated list of names of modules to statically link in. "+
+                         "May include !module to disable 'module'. "+
+                         "Can be '!FORCED' to disable all non-required static only modules. "+
+                         "Can be '!DEFAULT' to disable all modules defaulting to a static build. "+
+                         "Can be 'ALL' to build all default shared modules static. "+
+                         "The most specific one wins, while the order is ignored "+
+                         "and --with-static-modules is evaluated before "+
+                         "--with-shared-modules"),
                    action="store", dest='static_modules', default=None)
     opt.add_option('--with-shared-modules',
-                   help=("Comma-separated list of names of modules to build shared"),
+                   help=("Comma-separated list of names of modules to build shared. "+
+                         "May include !module to disable 'module'. "+
+                         "Can be '!FORCED' to disable all non-required shared only modules. "+
+                         "Can be '!DEFAULT' to disable all modules defaulting to a shared build. "+
+                         "Can be 'ALL' to build all default static modules shared. "+
+                         "The most specific one wins, while the order is ignored "+
+                         "and --with-static-modules is evaluated before "+
+                         "--with-shared-modules"),
                    action="store", dest='shared_modules', default=None)
 
     opt.SAMBA3_ADD_OPTION('winbind')
-    opt.SAMBA3_ADD_OPTION('ads', default=None) # None means autodetection
+    opt.SAMBA3_ADD_OPTION('ads')
     opt.SAMBA3_ADD_OPTION('ldap')
     opt.SAMBA3_ADD_OPTION('cups', with_name="enable", without_name="disable")
     opt.SAMBA3_ADD_OPTION('iprint', with_name="enable", without_name="disable")
     opt.SAMBA3_ADD_OPTION('pam')
-    opt.SAMBA3_ADD_OPTION('pam_smbpass')
     opt.SAMBA3_ADD_OPTION('quotas')
     opt.SAMBA3_ADD_OPTION('sendfile-support')
     opt.SAMBA3_ADD_OPTION('utmp')
@@ -39,34 +53,39 @@ def set_options(opt):
     opt.SAMBA3_ADD_OPTION('dnsupdate')
     opt.SAMBA3_ADD_OPTION('syslog')
     opt.SAMBA3_ADD_OPTION('automount')
-    opt.SAMBA3_ADD_OPTION('aio-support')
     opt.SAMBA3_ADD_OPTION('dmapi', default=None) # None means autodetection
     opt.SAMBA3_ADD_OPTION('fam', default=None) # None means autodetection
     opt.SAMBA3_ADD_OPTION('profiling-data', default=False)
+    opt.SAMBA3_ADD_OPTION('libarchive', default=None)
 
-    opt.SAMBA3_ADD_OPTION('cluster-support', default=None)
+    opt.SAMBA3_ADD_OPTION('cluster-support', default=False)
 
     opt.SAMBA3_ADD_OPTION('regedit', default=None)
 
-    opt.add_option('--with-ctdb-dir',
-                   help=("Directory under which ctdb is installed"),
-                   action="store", dest='ctdb_dir', default=None)
-    opt.add_option('--enable-old-ctdb',
-                  help=("enable building against (too) old version of ctdb (default=false)"),
-                  action="store_true", dest='enable_old_ctdb', default=False)
+    opt.SAMBA3_ADD_OPTION('fake-kaserver',
+                          help=("Include AFS fake-kaserver support"), default=False)
 
     opt.add_option('--with-libcephfs',
                    help=("Directory under which libcephfs is installed"),
                    action="store", dest='libcephfs_dir', default=None)
 
     opt.SAMBA3_ADD_OPTION('glusterfs', with_name="enable", without_name="disable", default=True)
+    opt.SAMBA3_ADD_OPTION('cephfs', with_name="enable", without_name="disable", default=True)
 
+    opt.add_option('--enable-vxfs',
+                  help=("enable support for VxFS (default=no)"),
+                  action="store_true", dest='enable_vxfs', default=False)
+
+    opt.SAMBA3_ADD_OPTION('spotlight', with_name="enable", without_name="disable", default=False)
 
 def configure(conf):
     from samba_utils import TO_LIST
 
     default_static_modules = []
     default_shared_modules = []
+    required_static_modules = []
+    forced_static_modules = []
+    forced_shared_modules = []
 
     if Options.options.developer:
         conf.ADD_CFLAGS('-DDEVELOPER -DDEBUG_PASSWORD')
@@ -75,14 +94,17 @@ def configure(conf):
     if sys.platform != 'openbsd5':
         conf.ADD_LDFLAGS("-Wl,--export-dynamic", testflags=True)
 
+    # We crash without vfs_default
+    required_static_modules.extend(TO_LIST('vfs_default'))
+
     conf.CHECK_HEADERS('execinfo.h libexc.h libunwind.h netdb.h')
-    conf.CHECK_HEADERS('linux/falloc.h')
+    conf.CHECK_HEADERS('linux/falloc.h linux/ioctl.h')
 
     conf.CHECK_FUNCS('getcwd fchown chmod fchmod mknod')
     conf.CHECK_FUNCS('strtol strchr strupr chflags')
     conf.CHECK_FUNCS('getrlimit fsync fdatasync setpgid')
     conf.CHECK_FUNCS('setsid glob strpbrk crypt16 getauthuid')
-    conf.CHECK_FUNCS('sigprocmask sigblock sigaction sigset innetgr')
+    conf.CHECK_FUNCS('innetgr')
     conf.CHECK_FUNCS('initgroups select poll rdchk getgrnam getgrent pathconf')
     conf.CHECK_FUNCS('setpriv setgidx setuidx setgroups syscall sysconf')
     conf.CHECK_FUNCS('atexit grantpt posix_openpt fallocate posix_fallocate')
@@ -90,7 +112,7 @@ def configure(conf):
     conf.CHECK_FUNCS('getpwnam', headers='sys/types.h pwd.h')
     conf.CHECK_FUNCS('fdopendir')
     conf.CHECK_FUNCS('fstatat')
-    conf.CHECK_FUNCS('getpwent_r setenv strcasecmp fcvt fcvtl')
+    conf.CHECK_FUNCS('getpwent_r setenv clearenv strcasecmp fcvt fcvtl')
     conf.CHECK_FUNCS('syslog vsyslog timegm setlocale')
     conf.CHECK_FUNCS_IN('nanosleep', 'rt')
     conf.CHECK_FUNCS('lutimes futimes utimensat futimens')
@@ -105,9 +127,6 @@ def configure(conf):
     conf.CHECK_DECLS('fdatasync', reverse=True)
     conf.CHECK_DECLS('readahead', reverse=True, headers='fcntl.h')
 
-    if conf.CONFIG_SET('HAVE_LONG_LONG'):
-        conf.DEFINE('HAVE_LONGLONG', 1)
-
     if conf.CHECK_CODE('''
 #if defined(HAVE_UNISTD_H)
 #include <unistd.h>
@@ -118,10 +137,13 @@ long ret = splice(0,0,1,0,400,SPLICE_F_MOVE);
         headers='fcntl.h'):
         conf.CHECK_DECLS('splice', reverse=True, headers='fcntl.h')
 
-    # Check for inotify support
-    conf.CHECK_HEADERS('sys/inotify.h')
-    if "HAVE_SYS_INOTIFY_H" in conf.env:
-        conf.DEFINE('HAVE_INOTIFY', 1)
+    # Check for inotify support (Skip if we are SunOS)
+    #NOTE: illumos provides sys/inotify.h but is not an exact match for linux
+    host_os = sys.platform
+    if host_os.rfind('sunos') == -1:
+        conf.CHECK_HEADERS('sys/inotify.h')
+        if "HAVE_SYS_INOTIFY_H" in conf.env:
+           conf.DEFINE('HAVE_INOTIFY', 1)
 
     # Check for kernel change notify support
     conf.CHECK_CODE('''
@@ -187,34 +209,51 @@ main() {
 
     if samba_fam_libs is not None:
         conf.DEFINE('SAMBA_FAM_LIBS', samba_fam_libs)
+        conf.DEFINE('HAVE_FAM', 1)
     else:
         if Options.options.with_fam == True:
             conf.fatal('FAM support requested, but no suitable FAM library found')
         elif check_for_fam:
             Logs.warn('no suitable FAM library found')
 
+    # check for libarchive (tar command in smbclient)
+    # None means autodetect, True/False means enable/disable
+    conf.SET_TARGET_TYPE('archive', 'EMPTY')
+    if Options.options.with_libarchive is not False:
+        libarchive_mandatory = Options.options.with_libarchive == True
+        Logs.info("Checking for libarchive existence")
+        if conf.CHECK_HEADERS('archive.h') and conf.CHECK_LIB('archive', shlib=True):
+            conf.CHECK_FUNCS_IN('archive_read_support_filter_all archive_read_free', 'archive')
+        elif libarchive_mandatory:
+            conf.fatal('libarchive support requested, but not found')
+
     # check for DMAPI libs
-    Logs.info("Checking for DMAPI library existence")
-    conf.env['dmapi_lib'] = ''
-    samba_dmapi_lib = ''
-    if conf.CHECK_FUNCS_IN('dm_get_eventlist', 'dm'):
-        samba_dmapi_lib = 'dm'
+    if Options.options.with_dmapi == False:
+        have_dmapi = False
     else:
-        if conf.CHECK_FUNCS_IN('dm_get_eventlist', 'jfsdm'):
-            samba_dmapi_lib = 'jfsdm'
+        have_dmapi = True
+        Logs.info("Checking for DMAPI library existence")
+        samba_dmapi_lib = ''
+        if conf.CHECK_FUNCS_IN('dm_get_eventlist', 'dm'):
+            samba_dmapi_lib = 'dm'
         else:
-            if conf.CHECK_FUNCS_IN('dm_get_eventlist', 'dmapi'):
-                samba_dmapi_lib = 'dmapi'
+            if conf.CHECK_FUNCS_IN('dm_get_eventlist', 'jfsdm'):
+                samba_dmapi_lib = 'jfsdm'
             else:
-                if conf.CHECK_FUNCS_IN('dm_get_eventlist', 'xdsm'):
-                    samba_dmapi_lib = 'xdsm'
-    # only bother to test headers and compilation when a candidate
-    # library has been found
-    if Options.options.with_dmapi == True and samba_dmapi_lib == '':
-        conf.fatal('DMAPI support requested, but no suitable DMAPI library found')
-    else:
-        conf.CHECK_HEADERS('sys/dmi.h xfs/dmapi.h sys/jfsdmapi.h sys/dmapi.h dmapi.h')
-        conf.CHECK_CODE('''
+                if conf.CHECK_FUNCS_IN('dm_get_eventlist', 'dmapi'):
+                    samba_dmapi_lib = 'dmapi'
+                else:
+                    if conf.CHECK_FUNCS_IN('dm_get_eventlist', 'xdsm'):
+                        samba_dmapi_lib = 'xdsm'
+        # only bother to test headers and compilation when a candidate
+        # library has been found
+        if samba_dmapi_lib == '':
+            have_dmapi = False
+            broken_dmapi = "no suitable DMAPI library found"
+
+        if have_dmapi:
+            conf.CHECK_HEADERS('sys/dmi.h xfs/dmapi.h sys/jfsdmapi.h sys/dmapi.h dmapi.h')
+            conf.CHECK_CODE('''
 #include <time.h>      /* needed by Tru64 */
 #include <sys/types.h> /* needed by AIX */
 #ifdef HAVE_XFS_DMAPI_H
@@ -244,17 +283,28 @@ int main(int argc, char **argv)
        return 0;
 }
 ''',
-        'USE_DMAPI',
-        addmain=False,
-        execute=False,
-        lib=samba_dmapi_lib,
-        msg='Checking whether DMAPI lib '+samba_dmapi_lib+' can be used')
-
-        if conf.CONFIG_SET('USE_DMAPI'):
-            conf.env['dmapi_lib'] = samba_dmapi_lib
+            'USEABLE_DMAPI_LIBRARY',
+            addmain=False,
+            execute=False,
+            lib=samba_dmapi_lib,
+            msg='Checking whether DMAPI lib '+samba_dmapi_lib+' can be used')
+            if not conf.CONFIG_SET('USEABLE_DMAPI_LIBRARY'):
+                have_dmapi = False
+                broken_dmapi = "no usable DMAPI library found"
+
+    if have_dmapi:
+        Logs.info("Building with DMAPI support.")
+        conf.env['dmapi_lib'] = samba_dmapi_lib
+        conf.DEFINE('USE_DMAPI', 1)
+    else:
+        if Options.options.with_dmapi == False:
+            Logs.info("Building without DMAPI support (--without-dmapi).")
+        elif Options.options.with_dmapi == True:
+            Logs.error("DMAPI support not available: " + broken_dmapi)
+            conf.fatal('DMAPI support requested but not found.');
         else:
-            if Options.options.with_dmapi == True:
-                conf.fatal('DMAPI support requested but not found');
+            Logs.warn("Building without DMAPI support: " + broken_dmapi)
+        conf.env['dmapi_lib'] = ''
 
     # Check for various members of the stat structure
     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_blocks', define='HAVE_STAT_ST_BLOCKS',
@@ -265,18 +315,20 @@ int main(int argc, char **argv)
                                 headers='sys/types.h sys/stat.h unistd.h')
 
     if "HAVE_BLKCNT_T" in conf.env:
-       conf.CHECK_CODE('''
-       return sizeof(blkcnt_t) == 4 ? 0 : 1''',
-               'SIZEOF_BLKCNT_T_4', execute=True,
-               headers='replace.h sys/types.h sys/stat.h unistd.h',
-               msg="Checking whether blkcnt_t is 32 bit")
+        conf.CHECK_CODE('''
+        static int test_array[1 - 2 * !(((long int)(sizeof(blkcnt_t))) <= 4)];''',
+                'SIZEOF_BLKCNT_T_4',
+                headers='replace.h sys/types.h sys/stat.h unistd.h',
+                msg="Checking whether blkcnt_t is 32 bit")
 
+    # If sizeof is 4 it can't be 8
     if "HAVE_BLKCNT_T" in conf.env:
-       conf.CHECK_CODE('''
-       return sizeof(blkcnt_t) == 8 ? 0 : 1''',
-               'SIZEOF_BLKCNT_T_8', execute=True,
-               headers='replace.h sys/types.h sys/stat.h unistd.h',
-               msg="Checking whether blkcnt_t is 64 bit")
+        if not conf.CONFIG_SET('SIZEOF_BLKCNT_T_4'):
+            conf.CHECK_CODE('''
+            static int test_array[1 - 2 * !(((long int)(sizeof(blkcnt_t))) <= 8)];''',
+                    'SIZEOF_BLKCNT_T_8',
+                    headers='replace.h sys/types.h sys/stat.h unistd.h',
+                    msg="Checking whether blkcnt_t is 64 bit")
 
     # Check for POSIX capability support
     conf.CHECK_FUNCS_IN('cap_get_proc', 'cap', headers='sys/capability.h')
@@ -293,34 +345,34 @@ int main(int argc, char **argv)
                         headers='sys/capability.h',
                         msg="Checking whether POSIX capabilities are available")
 
-    # Check for int16, uint16, int32 and uint32 in rpc/types.h included from
-    # rpc/rpc.h. This is *really* broken but some systems (DEC OSF1) do this.
-    # -- JRA.
-    if conf.CONFIG_SET("HAVE_RPC_RPC_H"):
-        conf.CHECK_TYPE('int16', headers='rpc/rpc.h',
-                        define='HAVE_INT16_FROM_RPC_RPC_H',
-                        msg="Checking for int16 typedef included by rpc/rpc.h")
-        conf.CHECK_CODE('uint16 testvar;', 'HAVE_INT16_FROM_RPC_RPC_H',
-                        headers='sys/types.h rpc/rpc.h',
-                        msg="Checking for uint16 typedef included by rpc/rpc.h")
-        conf.CHECK_CODE('int32 testvar;', 'HAVE_INT16_FROM_RPC_RPC_H',
-                        headers='sys/types.h rpc/rpc.h',
-                        msg="Checking for int32 typedef included by rpc/rpc.h")
-        conf.CHECK_CODE('uint32 testvar;', 'HAVE_INT16_FROM_RPC_RPC_H',
-                        headers='sys/types.h rpc/rpc.h',
-                        msg="Checking for uint32 typedef included by rpc/rpc.h")
     conf.CHECK_CODE('int i;', 'BROKEN_NISPLUS_INCLUDE_FILES',
                     headers='sys/types.h sys/acl.h rpcsvc/nis.h',
                     msg="Checking for broken nisplus include files")
 
     # Check if the compiler will optimize out functions
     conf.CHECK_CODE('''
-if (0) {
-    this_function_does_not_exist();
-} else {
-    return 1;
+#include <sys/types.h>
+size_t __unsafe_string_function_usage_here_size_t__(void);
+#define CHECK_STRING_SIZE(d, len) (sizeof(d) != (len) && sizeof(d) != sizeof(char *))
+static size_t push_string_check_fn(void *dest, const char *src, size_t dest_len) {
+       return 0;
+}
+
+#define push_string_check(dest, src, dest_len) \
+    (CHECK_STRING_SIZE(dest, dest_len) \
+    ? __unsafe_string_function_usage_here_size_t__()   \
+    : push_string_check_fn(dest, src, dest_len))
+
+int main(int argc, char **argv) {
+    char outbuf[1024];
+    char *p = outbuf;
+    const char *foo = "bar";
+    p += 31 + push_string_check(p + 31, foo, sizeof(outbuf) - (p + 31 - outbuf));
+    return 0;
 }''', 'HAVE_COMPILER_WILL_OPTIMIZE_OUT_FNS',
-        msg="Checking if the compiler will optimize out functions")
+            addmain=False,
+            add_headers=False,
+            msg="Checking if the compiler will optimize out functions")
 
     # Check if the compiler supports the LL suffix on long long integers
     # AIX needs this
@@ -329,7 +381,7 @@ if (0) {
                     msg="Checking for LL suffix on long long integers")
 
     conf.CHECK_FUNCS('''
-_acl __acl atexit 
+_acl __acl atexit
  _chdir __chdir chflags chmod _close __close _closedir
 __closedir crypt16 devnm dirfd
 DNSServiceRegister _dup __dup _dup2 __dup2 endmntent execl
@@ -353,7 +405,7 @@ rdchk _read __read _readdir __readdir
 _seekdir __seekdir
 select setenv setgidx setgroups setlocale setluid
 setmntent setpgid setpriv setsid setuidx
-shmget shm_open sigaction sigblock sigprocmask sigset
+shmget shm_open
 _stat __stat statvfs
 strcasecmp strchr strpbrk strsignal strtol strupr sysconf sysctl sysctlbyname
 __sys_llseek syslog _telldir __telldir timegm
@@ -386,7 +438,7 @@ utimensat vsyslog _write __write __xstat
         conf.DEFINE('FREEBSD', 1)
         if conf.CHECK_HEADERS('sunacl.h'):
             conf.DEFINE('HAVE_FREEBSD_SUNACL_H', '1')
-            conf.CHECK_FUNCS_IN('acl', 'sunacl')
+            conf.CHECK_FUNCS_IN(['acl'], 'sunacl')
         conf.DEFINE('STAT_ST_BLOCKSIZE', '512')
     elif (host_os.rfind('irix') > -1):
         conf.DEFINE('IRIX', 1)
@@ -406,31 +458,24 @@ utimensat vsyslog _write __write __xstat
         conf.DEFINE('STAT_ST_BLOCKSIZE', '512')
 
     if Options.options.with_acl_support:
-       if (host_os.rfind('sysv5') > -1) and conf.CHECK_FUNCS_IN('sec', 'facl', checklibc=True):
-               Logs.info('Using UnixWare ACLs')
-                conf.DEFINE('HAVE_UNIXWARE_ACLS',1)
-                default_static_modules.extend(TO_LIST('vfs_solarisacl'))
-       elif (host_os.rfind('solaris') > -1) and conf.CHECK_FUNCS_IN('sec', 'facl'):
-               Logs.info('Using solaris ACLs')
-                conf.DEFINE('HAVE_SOLARIS_ACLS',1)
-                default_static_modules.extend(TO_LIST('vfs_solarisacl'))
-       elif (host_os.rfind('hpux') > -1):
-               Logs.info('Using HPUX ACLs')
+        if (host_os.rfind('hpux') > -1):
+                Logs.info('Using HPUX ACLs')
                 conf.DEFINE('HAVE_HPUX_ACLS',1)
                 conf.DEFINE('POSIX_ACL_NEEDS_MASK',1)
                 default_static_modules.extend(TO_LIST('vfs_hpuxacl'))
-       elif (host_os.rfind('aix') > -1):
-               Logs.info('Using AIX ACLs')
+        elif (host_os.rfind('aix') > -1):
+                Logs.info('Using AIX ACLs')
                 conf.DEFINE('HAVE_AIX_ACLS',1)
                 default_static_modules.extend(TO_LIST('vfs_aixacl vfs_aixacl2'))
-       elif (host_os.rfind('osf') > -1) and conf.CHECK_FUNCS_IN('pacl', 'acl_get_fd'):
-               Logs.info('Using Tru64 ACLs')
-                conf.DEFINE('HAVE_TRU64_ACLS',1)
-                default_static_modules.extend(TO_LIST('vfs_tru64acl'))
         elif (host_os.rfind('darwin') > -1):
-            Logs.warn('ACLs on Dwarwin currently not supported')
+            Logs.warn('ACLs on Darwin currently not supported')
+            conf.fatal("ACL support not available on Darwin/MacOS. "
+                       "Use --without-acl-support for building without "
+                       "ACL support. "
+                       "ACL support is required to change permissions "
+                       "from Windows clients.")
         else:
-            conf.CHECK_FUNCS_IN('acl_get_file', 'acl')
+            conf.CHECK_FUNCS_IN(['acl_get_file'], 'acl')
             if conf.CHECK_CODE('''
 acl_t acl;
 int entry_id;
@@ -448,15 +493,31 @@ return acl_get_perm_np(permset_d, perm);
                         'HAVE_ACL_GET_PERM_NP',
                         headers='sys/types.h sys/acl.h', link=True,
                         msg="Checking whether acl_get_perm_np() is available")
-                default_static_modules.extend(TO_LIST('vfs_posixacl'))
-
+                # source3/lib/sysacls.c calls posixacl_sys_acl_get_file()
+                required_static_modules.extend(TO_LIST('vfs_posixacl'))
+                conf.CHECK_VARIABLE('ACL_EVERYONE', headers='sys/acl.h')
+            elif conf.CHECK_FUNCS_IN(['facl'], 'sec'):
+                Logs.info('Using solaris or UnixWare ACLs')
+                conf.DEFINE('HAVE_SOLARIS_UNIXWARE_ACLS',1)
+                default_static_modules.extend(TO_LIST('vfs_solarisacl'))
+            elif conf.CHECK_FUNCS_IN(['acl_get_fd'], 'pacl'):
+                Logs.info('Using Tru64 ACLs')
+                conf.DEFINE('HAVE_TRU64_ACLS',1)
+                default_static_modules.extend(TO_LIST('vfs_tru64acl'))
+            else:
+                conf.fatal("ACL support not found. Try installing libacl1-dev "
+                           "or libacl-devel.  "
+                           "Otherwise, use --without-acl-support to build "
+                           "without ACL support. "
+                           "ACL support is required to change permissions from "
+                           "Windows clients.")
 
     if conf.CHECK_FUNCS('dirfd'):
         conf.DEFINE('HAVE_DIRFD_DECL', 1)
 
     conf.CHECK_CODE('struct statfs fsd; fsid_t fsid = fsd.f_fsid; return statfs(".", &fsd);',
                     'HAVE_STATFS_F_FSID',
-                    msg="vfs_fileid: checking for statfs() and struct statfs.f_fsid",
+                    msg="vfs_fileid checking for statfs() and struct statfs.f_fsid",
                     headers='sys/types.h sys/statfs.h',
                     execute=True)
 
@@ -466,6 +527,19 @@ return acl_get_perm_np(permset_d, perm);
                 'HAVE_LINUX_FALLOCATE',
                 msg="Checking whether the Linux 'fallocate' function is available",
                 headers='unistd.h sys/types.h fcntl.h linux/falloc.h')
+        conf.CHECK_CODE('''
+                int ret = fallocate(0, FALLOC_FL_PUNCH_HOLE, 0, 10);''',
+                'HAVE_FALLOC_FL_PUNCH_HOLE',
+                msg="Checking whether Linux 'fallocate' supports hole-punching",
+                headers='unistd.h sys/types.h fcntl.h linux/falloc.h')
+
+    conf.CHECK_CODE('''
+            int ret = lseek(0, 0, SEEK_HOLE);
+            ret = lseek(0, 0, SEEK_DATA);''',
+            'HAVE_LSEEK_HOLE_DATA',
+            msg="Checking whether lseek supports hole/data seeking",
+            headers='unistd.h sys/types.h')
+
     conf.CHECK_CODE('''
                 ssize_t err = readahead(0,0,0x80000);''',
                 'HAVE_LINUX_READAHEAD',
@@ -474,34 +548,13 @@ return acl_get_perm_np(permset_d, perm);
     conf.CHECK_DECLS('readahead', headers='fcntl.h', always=True)
 
     conf.CHECK_CODE('int fd = openat(AT_FDCWD, ".", O_RDONLY);',
-               'HAVE_OPENAT',
-               msg='Checking for openat',
-               headers='fcntl.h')
-
-    if Options.options.with_aio_support:
-        conf.CHECK_FUNCS_IN('aio_read', 'aio')
-        conf.CHECK_FUNCS_IN('aio_read', 'rt')
-        conf.CHECK_CODE('struct aiocb a; return aio_read(&a);',
-                        'HAVE_AIO',
-                        msg='Checking for asynchronous io support',
-                        headers='sys/types.h aio.h',
-                        lib='aio rt')
-        if conf.CONFIG_SET('HAVE_AIO'):
-            conf.CHECK_CODE('struct aiocb a; return aio_read(&a);', 'HAVE_AIO_READ', msg='Checking for aio_read', headers='aio.h', lib='aio rt')
-            conf.CHECK_CODE('struct aiocb a; return aio_write(&a);', 'HAVE_AIO_WRITE', msg='Checking for aio_write', headers='aio.h', lib='aio rt')
-            conf.CHECK_CODE('struct aiocb a; return aio_fsync(1, &a);', 'HAVE_AIO_FSYNC', msg='Checking for aio_fsync', headers='aio.h', lib='aio rt')
-            conf.CHECK_CODE('struct aiocb a; return aio_return(&a);', 'HAVE_AIO_RETURN', msg='Checking for aio_return', headers='aio.h', lib='aio rt')
-            conf.CHECK_CODE('struct aiocb a; return aio_error(&a);', 'HAVE_AIO_ERROR', msg='Checking for aio_error', headers='aio.h', lib='aio rt')
-            conf.CHECK_CODE('struct aiocb a; return aio_cancel(1, &a);', 'HAVE_AIO_CANCEL', msg='Checking for aio_cancel', headers='aio.h', lib='aio rt')
-            conf.CHECK_CODE('const struct aiocb * const a[1]; struct timespec t; return aio_suspend(&a, 1, &t);', 'HAVE_AIO_SUSPEND', msg='Checking for aio_suspend', headers='aio.h', lib='aio rt')
-        if not conf.CONFIG_SET('HAVE_AIO'):
-            conf.DEFINE('HAVE_NO_AIO', '1')
-    else:
-        conf.DEFINE('HAVE_NO_AIO', '1')
+                'HAVE_OPENAT',
+                msg='Checking for openat',
+                headers='fcntl.h')
 
     if host_os.rfind('linux') > -1:
-       conf.CHECK_FUNCS_IN('io_submit', 'aio')
-       conf.CHECK_CODE('''
+        conf.CHECK_FUNCS_IN('io_submit', 'aio')
+        conf.CHECK_CODE('''
 struct io_event ioev;
 struct iocb *ioc;
 io_context_t ctx;
@@ -517,10 +570,10 @@ io_set_callback(ioc, (io_callback_t)(0));
 io_submit(ctx, 1, &ioc);
 io_getevents(ctx, 1, 1, &ioev, &ts);
 ''',
-                       'HAVE_LINUX_KERNEL_AIO',
-                       msg='Checking for linux kernel asynchronous io support',
-                       headers='unistd.h stdlib.h sys/types.h fcntl.h sys/eventfd.h libaio.h',
-                       lib='aio')
+            'HAVE_LINUX_KERNEL_AIO',
+            msg='Checking for linux kernel asynchronous io support',
+            headers='unistd.h stdlib.h sys/types.h fcntl.h sys/eventfd.h libaio.h',
+            lib='aio')
 
     conf.CHECK_CODE('''
 struct msghdr msg;
@@ -531,17 +584,17 @@ union {
 msg.msg_control = control_un.control;
 msg.msg_controllen = sizeof(control_un.control);
 ''',
-        'HAVE_MSGHDR_MSG_CONTROL',
+        'HAVE_STRUCT_MSGHDR_MSG_CONTROL',
         msg='Checking if we can use msg_control for passing file descriptors',
         headers='sys/types.h stdlib.h stddef.h sys/socket.h sys/un.h')
     conf.CHECK_CODE('''
 struct msghdr msg;
 int fd;
-msg.msg_acctrights = (caddr_t) &fd;
-msg.msg_acctrightslen = sizeof(fd);
+msg.msg_accrights = (caddr_t) &fd;
+msg.msg_accrightslen = sizeof(fd);
 ''',
-        'HAVE_MSGHDR_MSG_ACCTRIGHTS',
-        msg='Checking if we can use msg_acctrights for passing file descriptors',
+        'HAVE_STRUCT_MSGHDR_MSG_ACCRIGHTS',
+        msg='Checking if we can use msg_accrights for passing file descriptors',
         headers='sys/types.h stdlib.h stddef.h sys/socket.h sys/un.h')
 
     if Options.options.with_winbind:
@@ -549,7 +602,6 @@ msg.msg_acctrightslen = sizeof(fd);
         conf.DEFINE('WITH_WINBIND', '1')
 
     conf.find_program('awk', var='AWK')
-    conf.find_program('perl', var='PERL')
 
     conf.CHECK_HEADERS('asm/types.h')
 
@@ -591,7 +643,7 @@ msg.msg_acctrightslen = sizeof(fd);
             # we would normally use --libs here, but cups-config incorrectly adds
             # gssapi_krb5 and other libraries to its --libs output. That breaks the use
             # of an in-tree heimdal kerberos
-            conf.check_cfg(path=conf.env.CUPS_CONFIG, args="--cflags --ldflags",
+            conf.CHECK_CFG(path=conf.env.CUPS_CONFIG, args="--cflags --ldflags",
                            package="", uselib_store="CUPS")
         conf.CHECK_HEADERS('cups/cups.h cups/language.h', lib='cups')
         conf.CHECK_FUNCS_IN('httpConnect httpConnectEncrypt', 'cups')
@@ -648,6 +700,15 @@ msg.msg_acctrightslen = sizeof(fd);
             if conf.CONFIG_SET('HAVE_BER_SOCKBUF_ADD_IO') and \
                     conf.CONFIG_SET('HAVE_LDAP_OPT_SOCKBUF'):
                 conf.DEFINE('HAVE_LDAP_SASL_WRAPPING', '1')
+        else:
+            conf.fatal("LDAP support not found. "
+                       "Try installing libldap2-dev or openldap-devel. "
+                       "Otherwise, use --without-ldap to build without "
+                       "LDAP support. "
+                       "LDAP support is required for the LDAP passdb backend, "
+                       "LDAP idmap backends and ADS. "
+                       "ADS support improves communication with "
+                       "Active Directory domain controllers.")
     else:
         conf.SET_TARGET_TYPE('ldap', 'EMPTY')
         conf.SET_TARGET_TYPE('lber', 'EMPTY')
@@ -740,15 +801,20 @@ msg.msg_acctrightslen = sizeof(fd);
         conf.DEFINE('WITH_ADS', '1')
         conf.env['HAVE_ADS'] = '1'
         Logs.info("Building with Active Directory support.")
+        # these have broken dependencies
+        forced_shared_modules.extend(TO_LIST('idmap_ad idmap_rfc2307'))
     elif Options.options.with_ads == False:
         Logs.info("Building without Active Directory support (--without-ads).")
     else:
         if not use_ads_krb5:
             Logs.warn("Active Directory support not available: krb5 libs don't have all required features")
         if not use_ads_ldap:
-            Logs.warn("Active Directory support not available: LDAP support ist not available.")
+            Logs.warn("Active Directory support not available: LDAP support is not available.")
         if Options.options.with_ads:
-            conf.fatal("Active Directory support not found. Use --without-ads for building without Active Directory support.")
+            conf.fatal("Active Directory support not found. Use --without-ads "
+                       "for building without Active Directory support. "
+                       "ADS support improves communication with "
+                       "Active Directory domain controllers.")
         else:
             # this is the auto-mode case
             Logs.warn("Building without Active Directory support.")
@@ -782,7 +848,7 @@ msg.msg_acctrightslen = sizeof(fd);
                         'PUTUTLINE_RETURNS_UTMP', headers='utmp.h',
                         msg="Checking whether pututline returns pointer")
         conf.CHECK_SIZEOF(['((struct utmp *)NULL)->ut_line'], headers='utmp.h',
-                          define='SIZEOF_UTMP_UT_LINE')
+                          define='SIZEOF_UTMP_UT_LINE', critical=False)
         if not conf.CONFIG_SET('SIZEOF_UTMP_UT_LINE'):
             conf.env.with_utmp = False
         elif int(conf.env.SIZEOF_UTMP_UT_LINE) < 15:
@@ -883,9 +949,6 @@ int i; i = PAM_RADIO_TYPE;
             conf.DEFINE('WITH_PAM', 1)
             conf.DEFINE('WITH_PAM_MODULES', 1)
 
-    if Options.options.with_pam_smbpass:
-        conf.env.with_pam_smbpass = True
-
     seteuid = False
 
 #
@@ -1028,6 +1091,66 @@ syscall(SYS_setgroups32, 0, NULL);
                 execute=True,
                 msg='Checking whether fcntl locking is available')
 
+    conf.CHECK_CODE('''
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#define DATA "ofdtest.fcntl"
+
+int main() {
+        struct flock lck = {
+           .l_whence = SEEK_SET,
+           .l_type = F_WRLCK,
+           .l_start = 0,
+           .l_len = 1,
+           .l_pid = 0,
+        };
+        int ret;
+        int fd1;
+        int fd2;
+        char *testdir = getenv("TESTDIR");
+
+        if (testdir) {
+           if (chdir(testdir) != 0) {
+              goto err;
+           }
+        }
+
+        unlink(DATA);
+        fd1 = open(DATA, O_RDWR|O_CREAT|O_EXCL, 0600);
+        fd2 = open(DATA, O_RDWR);
+        if (fd1 == -1 || fd2 == -1) {
+           goto err;
+        }
+        ret = fcntl(fd1,F_OFD_SETLKW,&lck);
+        if (ret == -1) {
+          goto err;
+        }
+        ret = fcntl(fd2,F_OFD_SETLK,&lck);
+        if (ret != -1) {
+          goto err;
+        }
+        if (errno != EAGAIN) {
+          goto err;
+        }
+        ret = fcntl(fd2,F_OFD_GETLK,&lck);
+        if (ret == -1) {
+          goto err;
+        }
+        unlink(DATA);
+        exit(0);
+err:
+        unlink(DATA);
+        exit(1);
+}''',
+            'HAVE_OFD_LOCKS',
+            addmain=False,
+            execute=True,
+            msg="Checking whether fcntl lock supports open file description locks")
+
 # glibc up to 2.3.6 had dangerously broken posix_fallocate(). DON'T USE IT.
     if not conf.CHECK_CODE('''
 #define _XOPEN_SOURCE 600
@@ -1226,7 +1349,7 @@ main() {
                             hdr.trl_cnt = 0;
                             hdtrl.iov_base = (void *)0;
                             hdtrl.iov_len = 0;
-                           ret = sendfile(fromfd, tofd, offset, &nwritten, &hdr, 0);
+                            ret = sendfile(fromfd, tofd, offset, &nwritten, &hdr, 0);
                             ''',
                             '_HAVE_SENDFILE',
                             msg='Checking for darwin sendfile support')
@@ -1317,6 +1440,7 @@ main() {
     conf.CHECK_FUNCS_IN('getspnam', 'security')
     conf.CHECK_FUNCS_IN('getspnam', 'sec')
 
+    legacy_quota_libs = ''
     if Options.options.with_quotas:
         # For quotas on Veritas VxFS filesystems
         conf.CHECK_HEADERS('sys/fs/vx_quota.h')
@@ -1343,7 +1467,7 @@ main() {
                 msg='for XFS QUOTA in <sys/quota.h>',
                 execute=False,
                 local_include=False)
-        
+
         # For IRIX like dqb_isoftlimit instead of dqb_fsoftlimit in struc dqblk
         conf.CHECK_STRUCTURE_MEMBER('struct dqblk', 'dqb_fsoftlimit', define='HAVE_DQB_FSOFTLIMIT',
                                 headers='sys/quota.h')
@@ -1383,7 +1507,7 @@ main() {
 
         conf.CHECK_CODE('''
                      clnt_create("", RQUOTAPROG, RQUOTAVERS, "udp");
-''', 
+''',
                         headers="rpc/rpc.h rpc/types.h rpcsvc/rquota.h rpc/nettype.h rpc/xdr.h", 
                         define='HAVE_NFS_QUOTAS',
                         msg='for NFS QUOTAS',
@@ -1397,285 +1521,39 @@ main() {
             conf.DEFINE('HAVE_SYS_QUOTAS', '1')
             conf.DEFINE('WITH_QUOTAS', '1')
 
+        #
+        # check if Legacy quota code can be brought in
+        # if standard interfaces are not supported
+        #
+        if not conf.CONFIG_SET('WITH_QUOTAS'):
+            if host_os.rfind('sunos5') > -1:
+                conf.DEFINE('SUNOS5', '1')
+                legacy_quota_libs = 'nsl'
+            conf.CHECK_CODE('''
+            #define WITH_QUOTAS 1
+            #define AUTOCONF_TEST 1
+            #include "../tests/oldquotas.c"
+            ''',
+                            cflags=conf.env['WERROR_CFLAGS'],
+                            define='WITH_QUOTAS',
+                            lib=legacy_quota_libs,
+                            msg='Checking whether legacy quota code can be used',
+                            execute=False,
+                            addmain=False)
+            if not conf.CONFIG_SET('WITH_QUOTAS'):
+                legacy_quota_libs = ''
+    conf.env['legacy_quota_libs'] = legacy_quota_libs
+
     #
-    # checking for clustering extensions (CTDB)
+    # cluster support (CTDB)
     #
-    if Options.options.with_cluster_support == False:
-        # configure is called with --without-cluster-support,
-        # so don't check for and build w/o ctdb support.
-        have_cluster_support = False
-
+    if not Options.options.with_cluster_support:
+        Logs.info("building without cluster support (--without-cluster-support)")
+        conf.env.with_ctdb = False
     else:
-
-        if Options.options.ctdb_dir:
-            conf.ADD_EXTRA_INCLUDES(Options.options.ctdb_dir + '/include')
-
-        srcdir = os.path.realpath(conf.srcdir)
-        if 'EXTRA_INCLUDES' in conf.env:
-            includes = ' '.join(conf.env['EXTRA_INCLUDES']).replace('#', srcdir + '/')
-        else:
-            includes = ''
-
-        if not conf.env.USING_SYSTEM_TDB:
-            includes = includes + ' ' + srcdir + '/lib/tdb/include'
-
-        if not conf.env.USING_SYSTEM_TALLOC:
-            includes = includes + ' ' + srcdir + '/lib/talloc'
-
-        have_cluster_support = True
-        ctdb_broken = ""
-
-        conf.CHECK_CODE('''
-            #define NO_CONFIG_H
-            #include "replace.h"
-            #include "system/wait.h"
-            #include "system/network.h"
-            #define private #error __USED_RESERVED_WORD_private__
-            #include <talloc.h>
-            #include <tdb.h>
-            #include <ctdb.h>
-
-            int main(void)
-            {
-                return 0;
-            }
-            ''',
-            'HAVE_CTDB_H',
-            addmain=False,
-            includes=includes,
-            msg='Checking for header ctdb.h')
-
-        if not conf.CONFIG_SET('HAVE_CTDB_H'):
-            have_cluster_support = False
-            ctdb_broken = "ctdb.h is required for cluster support"
-
-        if have_cluster_support:
-            conf.CHECK_CODE('''
-                #define NO_CONFIG_H
-                #include "replace.h"
-                #include "system/wait.h"
-                #include "system/network.h"
-                #define private #error __USED_RESERVED_WORD_private__
-                #include <talloc.h>
-                #include <tdb.h>
-                #include <ctdb.h>
-                #include <ctdb_private.h>
-
-                int main(void)
-                {
-                    return 0;
-                }
-                ''',
-                'HAVE_CTDB_PRIVATE_H',
-                addmain=False,
-                includes=includes,
-                msg='Checking for header ctdb_private.h')
-
-            if not conf.CONFIG_SET('HAVE_CTDB_PRIVATE_H'):
-                have_cluster_support = False
-                ctdb_broken = "ctdb_private.h is required for cluster support"
-
-        if have_cluster_support:
-            conf.CHECK_CODE('''
-                #define NO_CONFIG_H
-                #include "replace.h"
-                #include "system/wait.h"
-                #include "system/network.h"
-                #define private #error __USED_RESERVED_WORD_private__
-                #include <talloc.h>
-                #include <tdb.h>
-                #include <ctdb.h>
-                #include <ctdb_protocol.h>
-
-                int main(void)
-                {
-                    return 0;
-                }
-                ''',
-                'HAVE_CTDB_PROTOCOL_H',
-                addmain=False,
-                includes=includes,
-                msg='Checking for header ctdb_protocol.h')
-
-        if have_cluster_support:
-            conf.CHECK_CODE('''
-                #define NO_CONFIG_H
-                #include "replace.h"
-                #include "system/wait.h"
-                #include "system/network.h"
-                #include <talloc.h>
-                #include <tdb.h>
-                #include <ctdb.h>
-                #include <ctdb_private.h>
-
-                int main(void)
-                {
-                   int i = (int)CTDB_CONTROL_TRANS3_COMMIT;
-                   return 0;
-                }
-                ''',
-                'HAVE_CTDB_CONTROL_TRANS3_COMMIT_DECL',
-                addmain=False,
-                includes=includes,
-                msg='Checking for transaction support (TRANS3_COMMIT control)')
-
-            if not conf.CONFIG_SET('HAVE_CTDB_CONTROL_TRANS3_COMMIT_DECL'):
-                have_cluster_support = False
-                ctdb_broken = "ctdb transaction support missing or too old"
-
-        if have_cluster_support:
-            conf.CHECK_CODE('''
-                #define NO_CONFIG_H
-                #include "replace.h"
-                #include "system/wait.h"
-                #include "system/network.h"
-                #include <talloc.h>
-                #include <tdb.h>
-                #include <ctdb.h>
-                #include <ctdb_private.h>
-
-                int main(void)
-                {
-                    int i = (int)CTDB_CONTROL_SCHEDULE_FOR_DELETION;
-                    return 0;
-                }
-                ''',
-                'HAVE_CTDB_CONTROL_SCHEDULE_FOR_DELETION_DECL',
-                addmain=False,
-                includes=includes,
-                msg='Checking for SCHEDULE_FOR_DELETION control')
-
-            if not conf.CONFIG_SET('HAVE_CTDB_CONTROL_SCHEDULE_FOR_DELETION_DECL'):
-                if not Options.options.enable_old_ctdb:
-                    have_cluster_support = False
-                    ctdb_broken = "SCHEDULE_FOR_DELETION control missing"
-                else:
-                    Logs.warn("ignoring missing SCHEDULE_FOR_DELETION control (--enable-old-ctdb)")
-
-        if have_cluster_support:
-            conf.CHECK_CODE('''
-               #define NO_CONFIG_H
-               #include "replace.h"
-               #include "system/wait.h"
-               #include "system/network.h"
-               #include <talloc.h>
-               #include <tdb.h>
-               #include <ctdb.h>
-
-               int main(void)
-               {
-                   int i = (int)CTDB_WANT_READONLY;
-                   return 0;
-               }
-               ''',
-               'HAVE_CTDB_WANT_READONLY_DECL',
-               addmain=False,
-               includes=includes,
-               msg='Checking for CTDB readonly records support')
-
-            if not conf.CONFIG_SET('HAVE_CTDB_WANT_READONLY_DECL'):
-                if not Options.options.enable_old_ctdb:
-                    have_cluster_support = False
-                    ctdb_broken = "support for CTDB readonly records missing"
-                else:
-                    Logs.warn("ignoring missing READONLY support (--enable-old-ctdb)")
-
-        if have_cluster_support:
-            conf.CHECK_CODE('''
-                #define NO_CONFIG_H
-                #include "replace.h"
-                #include "system/wait.h"
-                #include "system/network.h"
-                #include <talloc.h>
-                #include <tdb.h>
-                #include <ctdb.h>
-                #include <ctdb_private.h>
-
-                int main(void)
-                {
-                    struct ctdb_control_tcp _x;
-                    return 0;
-                }
-                ''',
-                'HAVE_STRUCT_CTDB_CONTROL_TCP',
-                addmain=False,
-                includes=includes,
-                msg='Checking for ctdb ipv4 support')
-
-            if not conf.CONFIG_SET('HAVE_STRUCT_CTDB_CONTROL_TCP'):
-                have_cluster_support = False
-                ctdb_broken = "missing struct ctdb_control_tcp"
-
-        if have_cluster_support:
-            conf.CHECK_CODE('''
-                #define NO_CONFIG_H
-                #include "replace.h"
-                #include "system/wait.h"
-                #include "system/network.h"
-                #include <talloc.h>
-                #include <tdb.h>
-                #include <ctdb.h>
-                #include <ctdb_private.h>
-
-                int main(void)
-                {
-                    struct ctdb_control_tcp_addr _x;
-                    return 0;
-                }
-                ''',
-                'HAVE_STRUCT_CTDB_CONTROL_TCP_ADDR',
-                addmain=False,
-                includes=includes,
-                msg='Checking for ctdb ipv6 support')
-
-        if have_cluster_support:
-            conf.CHECK_CODE('''
-                #define NO_CONFIG_H
-                #include "replace.h"
-                #include "system/wait.h"
-                #include "system/network.h"
-                #include <talloc.h>
-                #include <tdb.h>
-                #include <ctdb.h>
-                #include <ctdb_private.h>
-
-                int main(void)
-                {
-                    int i = (int)CTDB_CONTROL_CHECK_SRVIDS;
-                    return 0;
-                }
-                ''',
-                'HAVE_CTDB_CONTROL_CHECK_SRVIDS_DECL',
-                addmain=False,
-                includes=includes,
-                msg='Checking for CHECK_SRVIDS control')
-
-            if not conf.CONFIG_SET('HAVE_CTDB_CONTROL_CHECK_SRVIDS_DECL'):
-                if not Options.options.enable_old_ctdb:
-                    have_cluster_support = False
-                    ctdb_broken = "CHECK_SRVIDS control missing"
-                else:
-                    Logs.warn("ignoring missing CHECK_SRVIDS control (--enable-old-ctdb)")
-
-    if have_cluster_support:
         Logs.info("building with cluster support")
-        conf.DEFINE('CLUSTER_SUPPORT', 1);
-    else:
-        if Options.options.with_cluster_support == False:
-            Logs.info("building without cluster support (--without-cluster-support)")
-        elif Options.options.with_cluster_support == True:
-            Logs.error("Cluster support not available: " + ctdb_broken)
-            conf.fatal("Cluster support not found, but --with-cluster-support was specified")
-        else:
-            Logs.info("building without cluster support: " + ctdb_broken)
-        conf.undefine('CLUSTER_SUPPORT')
-
-
-    conf.CHECK_CODE('__attribute__((destructor)) static void cleanup(void) { }',
-                    'HAVE_FUNCTION_ATTRIBUTE_DESTRUCTOR',
-                    addmain=False,
-                    link=False,
-                    msg='Checking whether we can compile with __attribute__((destructor))')
+        conf.env.with_ctdb = True
+        conf.DEFINE('CLUSTER_SUPPORT', 1)
 
     conf.CHECK_CODE('void seekdir(DIR *d, long loc) { return; }',
                     'SEEKDIR_RETURNS_VOID',
@@ -1684,38 +1562,7 @@ main() {
 
     if Options.options.with_profiling_data:
         conf.DEFINE('WITH_PROFILE', 1);
-
-    PTHREAD_CFLAGS='error'
-    PTHREAD_LDFLAGS='error'
-
-    if PTHREAD_LDFLAGS == 'error':
-        if conf.CHECK_FUNCS_IN('pthread_attr_init', 'pthread'):
-            PTHREAD_CFLAGS='-D_REENTRANT -D_POSIX_PTHREAD_SEMANTICS'
-            PTHREAD_LDFLAGS='-lpthread'
-    if PTHREAD_LDFLAGS == 'error':
-        if conf.CHECK_FUNCS_IN('pthread_attr_init', 'pthreads'):
-            PTHREAD_CFLAGS='-D_THREAD_SAFE'
-            PTHREAD_LDFLAGS='-lpthreads'
-    if PTHREAD_LDFLAGS == 'error':
-        if conf.CHECK_FUNCS_IN('pthread_attr_init', 'c_r'):
-            PTHREAD_CFLAGS='-D_THREAD_SAFE -pthread'
-            PTHREAD_LDFLAGS='-pthread'
-    if PTHREAD_LDFLAGS == 'error':
-        if conf.CHECK_FUNCS('pthread_attr_init'):
-            PTHREAD_CFLAGS='-D_REENTRANT'
-            PTHREAD_LDFLAGS='-lpthread'
-    # especially for HP-UX, where the CHECK_FUNC macro fails to test for
-    # pthread_attr_init. On pthread_mutex_lock it works there...
-    if PTHREAD_LDFLAGS == 'error':
-        if conf.CHECK_FUNCS_IN('pthread_mutex_lock', 'pthread'):
-            PTHREAD_CFLAGS='-D_REENTRANT'
-            PTHREAD_LDFLAGS='-lpthread'
-
-    if PTHREAD_CFLAGS != 'error' and PTHREAD_LDFLAGS != 'error':
-        conf.ADD_CFLAGS(PTHREAD_CFLAGS)
-        conf.ADD_LDFLAGS(PTHREAD_LDFLAGS)
-        conf.CHECK_HEADERS('pthread.h')
-        conf.DEFINE('HAVE_PTHREAD', '1')
+        conf.CHECK_FUNCS('getrusage', headers="sys/time.h sys/resource.h")
 
     if Options.options.with_pthreadpool:
         if conf.CONFIG_SET('HAVE_PTHREAD'):
@@ -1724,35 +1571,51 @@ main() {
             Logs.warn("pthreadpool support cannot be enabled when pthread support was not found")
             conf.undefine('WITH_PTHREADPOOL')
 
-    if conf.CHECK_HEADERS('gpfs_gpl.h'):
-        conf.DEFINE('HAVE_GPFS', '1')
-
-    if conf.CHECK_HEADERS('linux/ioctl.h sys/ioctl.h'):
-           conf.DEFINE('HAVE_LINUX_IOCTL', '1')
+    if (conf.CHECK_HEADERS('linux/ioctl.h sys/ioctl.h linux/fs.h') and
+        conf.CHECK_DECLS('FS_IOC_GETFLAGS FS_COMPR_FL', headers='linux/fs.h')):
+            conf.DEFINE('HAVE_LINUX_IOCTL', '1')
 
     conf.env['CCFLAGS_CEPHFS'] = "-D_FILE_OFFSET_BITS=64"
     if Options.options.libcephfs_dir:
         conf.env['CPPPATH_CEPHFS'] = Options.options.libcephfs_dir + '/include'
         conf.env['LIBPATH_CEPHFS'] = Options.options.libcephfs_dir + '/lib'
 
-    if conf.CHECK_HEADERS('cephfs/libcephfs.h', False, False, 'cephfs') and conf.CHECK_LIB('cephfs'):
-        conf.DEFINE('HAVE_CEPH', '1')
+    if conf.CHECK_HEADERS('cephfs/libcephfs.h', False, False, 'cephfs') and conf.CHECK_LIB('cephfs', shlib=True) and Options.options.with_cephfs:
+        if Options.options.with_acl_support:
+            conf.DEFINE('HAVE_CEPH', '1')
+            if conf.CHECK_FUNCS_IN('ceph_statx', 'cephfs', headers='cephfs/libcephfs.h'):
+                conf.DEFINE('HAVE_CEPH_STATX', '1')
+        else:
+            Logs.warn("ceph support disabled due to --without-acl-support")
+            conf.undefine('HAVE_CEPH')
 
     if Options.options.with_glusterfs:
-        conf.check_cfg(package='glusterfs-api', args='"glusterfs-api >= 4" --cflags --libs',
+        conf.CHECK_CFG(package='glusterfs-api', args='"glusterfs-api >= 4" --cflags --libs',
                        msg='Checking for glusterfs-api >= 4', uselib_store="GFAPI")
         conf.CHECK_HEADERS('api/glfs.h', lib='gfapi')
         conf.CHECK_LIB('gfapi', shlib=True)
 
         if conf.CONFIG_SET('HAVE_API_GLFS_H'):
-            conf.DEFINE('HAVE_GLUSTERFS', '1')
+            if Options.options.with_acl_support:
+                 conf.DEFINE('HAVE_GLUSTERFS', '1')
+            else:
+                Logs.warn("GlusterFS support disabled due to --without-acl-support")
+                conf.undefine('HAVE_GLUSTERFS')
         else:
-            conf.SET_TARGET_TYPE('gfapi', 'EMPTY')
             conf.undefine('HAVE_GLUSTERFS')
     else:
         conf.SET_TARGET_TYPE('gfapi', 'EMPTY')
         conf.undefine('HAVE_GLUSTERFS')
 
+    if Options.options.enable_vxfs:
+        conf.DEFINE('HAVE_VXFS', '1')
+
+    if conf.CHECK_CFG(package='dbus-1', args='--cflags --libs',
+                      msg='Checking for dbus', uselib_store="DBUS-1"):
+        if (conf.CHECK_HEADERS('dbus/dbus.h', lib='dbus-1')
+                                      and conf.CHECK_LIB('dbus-1', shlib=True)):
+            conf.DEFINE('HAVE_DBUS', '1')
+
     conf.env.build_regedit = False
     if not Options.options.with_regedit == False:
         conf.PROCESS_SEPARATE_RULE('system_ncurses')
@@ -1770,34 +1633,76 @@ main() {
         else:
             Logs.info("ncurses not available, not building regedit")
 
-
-    default_static_modules.extend(TO_LIST('''pdb_smbpasswd pdb_tdbsam pdb_wbc_sam
-                                      auth_sam auth_unix auth_winbind auth_wbc
-                                      auth_domain auth_builtin vfs_default
+    conf.CHECK_FUNCS_IN('DES_pcbc_encrypt', 'crypto')
+    if Options.options.with_fake_kaserver == True:
+        conf.CHECK_HEADERS('afs/param.h afs/stds.h', together=True)
+        conf.CHECK_HEADERS('afs/param.h afs/stds.h', together=True)
+        if (conf.CONFIG_SET('HAVE_AFS_PARAM_H') and conf.CONFIG_SET('HAVE_AFS_STDS_H') and conf.CONFIG_SET('HAVE_DES_PCBC_ENCRYPT')):
+            conf.DEFINE('WITH_FAKE_KASERVER', '1')
+        else:
+            conf.fatal('AFS headers not available, but --with-fake-kaserver was specified')
+
+    conf.env['libtracker']=''
+    conf.env.with_spotlight = False
+    if Options.options.with_spotlight:
+
+        Logs.info("Requested Spotlight support, checking for bison")
+        bison.detect(conf)
+        if not conf.env['BISON']:
+            conf.fatal("Spotlight support requested but bison missing")
+        conf.CHECK_COMMAND('%s --version | head -n1' % conf.env['BISON'], msg='Using bison version', define=None, on_target=False)
+        Logs.info("Requested Spotlight support, checking for flex")
+        flex.detect(conf)
+        if not conf.env['FLEX']:
+            conf.fatal("Spotlight support requested but flex missing")
+        conf.CHECK_COMMAND('%s --version' % conf.env['FLEX'], msg='Using flex version', define=None, on_target=False)
+        versions = ['1.0', '0.16', '0.14']
+        for version in versions:
+            testlib = 'tracker-sparql-' + version
+            if conf.CHECK_CFG(package=testlib,
+                              args='--cflags --libs',
+                              mandatory=False):
+                conf.SET_TARGET_TYPE(testlib, 'SYSLIB')
+                conf.env['libtracker'] = testlib
+                conf.env.with_spotlight = True
+                conf.DEFINE('WITH_SPOTLIGHT', '1')
+                break
+
+        if not conf.env.with_spotlight:
+            conf.fatal("Spotlight support requested but tracker-sparql library missing")
+        Logs.info("building with Spotlight support")
+        default_static_modules.extend(TO_LIST('rpc_mdssvc_module'))
+
+    forced_static_modules.extend(TO_LIST('auth_domain auth_builtin auth_sam auth_winbind'))
+    default_static_modules.extend(TO_LIST('''pdb_smbpasswd pdb_tdbsam
+                                      auth_unix
                                       nss_info_template idmap_tdb idmap_passdb
                                       idmap_nss'''))
 
-    default_shared_modules.extend(TO_LIST('''vfs_recycle vfs_audit vfs_extd_audit vfs_full_audit vfs_netatalk
+    default_shared_modules.extend(TO_LIST('''
+                                      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 vfs_shadow_copy2 
-                                      auth_script vfs_readahead vfs_xattr_tdb vfs_posix_eadb
+                                      vfs_expand_msdfs vfs_shadow_copy vfs_shadow_copy2
+                                      vfs_readahead vfs_xattr_tdb vfs_posix_eadb
                                       vfs_streams_xattr vfs_streams_depot vfs_acl_xattr vfs_acl_tdb
-                                      vfs_smb_traffic_analyzer vfs_preopen vfs_catia vfs_scannedonly
-                                     vfs_media_harmony
-                                     vfs_commit
-                                      vfs_crossrename vfs_linux_xfs_sgid
-                                      vfs_time_audit idmap_autorid idmap_tdb2
-                                      idmap_rid idmap_hash idmap_rfc2307'''))
+                                      vfs_preopen vfs_catia
+                                      vfs_media_harmony vfs_unityed_media vfs_fruit vfs_shell_snap
+                                      vfs_commit vfs_worm vfs_crossrename vfs_linux_xfs_sgid
+                                      vfs_time_audit vfs_offline
+                                  '''))
+    default_shared_modules.extend(TO_LIST('auth_script idmap_tdb2 idmap_script'))
+    # these have broken dependencies
+    forced_shared_modules.extend(TO_LIST('idmap_autorid idmap_rid idmap_hash'))
 
     if Options.options.developer:
         default_static_modules.extend(TO_LIST('charset_weird'))
         default_shared_modules.extend(TO_LIST('perfcount_test'))
         default_shared_modules.extend(TO_LIST('vfs_skel_opaque vfs_skel_transparent vfs_shadow_copy_test'))
         default_shared_modules.extend(TO_LIST('auth_skel pdb_test'))
+        default_shared_modules.extend(TO_LIST('vfs_fake_dfq'))
 
     if Options.options.enable_selftest or Options.options.developer:
-       default_shared_modules.extend(TO_LIST('vfs_fake_acls vfs_nfs4acl_xattr'))
-        
+        default_shared_modules.extend(TO_LIST('vfs_fake_acls vfs_nfs4acl_xattr'))
 
     if conf.CONFIG_SET('AD_DC_BUILD_IS_ENABLED'):
         default_static_modules.extend(TO_LIST('pdb_samba_dsdb auth_samba4 vfs_dfs_samba4'))
@@ -1811,15 +1716,12 @@ main() {
     if conf.CONFIG_SET('HAVE_STATFS_F_FSID'):
         default_shared_modules.extend(TO_LIST('vfs_fileid'))
 
-    if (conf.CONFIG_SET('HAVE_MSGHDR_MSG_CONTROL') or conf.CONFIG_SET('HAVE_MSGHDR_MSG_ACCTRIGHTS')):
+    if (conf.CONFIG_SET('HAVE_STRUCT_MSGHDR_MSG_CONTROL') or conf.CONFIG_SET('HAVE_STRUCT_MSGHDR_MSG_ACCRIGHTS')):
         default_shared_modules.extend(TO_LIST('vfs_aio_fork'))
 
     if Options.options.with_pthreadpool:
         default_shared_modules.extend(TO_LIST('vfs_aio_pthread'))
 
-    if conf.CONFIG_SET('HAVE_AIO'):
-        default_shared_modules.extend(TO_LIST('vfs_aio_posix'))
-
     if conf.CONFIG_SET('HAVE_LINUX_KERNEL_AIO'):
         default_shared_modules.extend(TO_LIST('vfs_aio_linux'))
 
@@ -1830,13 +1732,11 @@ main() {
         default_static_modules.extend(TO_LIST('charset_macosxfs'))
 
     if conf.CONFIG_SET('HAVE_GPFS'):
-       default_shared_modules.extend(TO_LIST('vfs_gpfs'))
+        default_shared_modules.extend(TO_LIST('vfs_gpfs'))
 
-    if conf.CONFIG_SET('HAVE_LINUX_IOCTL'):
-       default_shared_modules.extend(TO_LIST('vfs_btrfs'))
-
-    if conf.CONFIG_SET('SAMBA_FAM_LIBS'):
-        default_shared_modules.extend(TO_LIST('vfs_notify_fam'))
+    if (conf.CONFIG_SET('HAVE_LINUX_IOCTL')
+      and conf.CONFIG_SET('HAVE_BASENAME') and conf.CONFIG_SET('HAVE_DIRNAME')):
+        default_shared_modules.extend(TO_LIST('vfs_btrfs'))
 
     if conf.CONFIG_SET("HAVE_CEPH"):
         default_shared_modules.extend(TO_LIST('vfs_ceph'))
@@ -1844,6 +1744,12 @@ main() {
     if conf.CONFIG_SET('HAVE_GLUSTERFS'):
         default_shared_modules.extend(TO_LIST('vfs_glusterfs'))
 
+    if conf.CONFIG_SET('HAVE_VXFS'):
+        default_shared_modules.extend(TO_LIST('vfs_vxfs'))
+
+    if conf.CONFIG_SET('HAVE_DBUS'):
+        default_shared_modules.extend(TO_LIST('vfs_snapper'))
+
     explicit_shared_modules = TO_LIST(Options.options.shared_modules, delimiter=',')
     explicit_static_modules = TO_LIST(Options.options.static_modules, delimiter=',')
 
@@ -1860,23 +1766,66 @@ main() {
     replace_list_item(explicit_shared_modules, 'pdb_ldap', 'pdb_ldapsam')
     replace_list_item(explicit_static_modules, 'pdb_ldap', 'pdb_ldapsam')
 
-    final_static_modules = default_static_modules
-    final_shared_modules = default_shared_modules
+    final_static_modules = []
+    final_static_modules.extend(TO_LIST(required_static_modules))
+    final_shared_modules = []
+
+    if '!FORCED' not in explicit_static_modules:
+        final_static_modules.extend(TO_LIST(forced_static_modules))
+    if '!FORCED' not in explicit_shared_modules:
+        final_shared_modules.extend(TO_LIST(forced_shared_modules))
+    if '!DEFAULT' not in explicit_static_modules:
+        final_static_modules.extend(TO_LIST(default_static_modules))
+    if '!DEFAULT' not in explicit_shared_modules:
+        final_shared_modules.extend(TO_LIST(default_shared_modules))
+
+    if 'ALL' in explicit_static_modules:
+        for m in default_shared_modules:
+            if m in final_shared_modules:
+                final_shared_modules.remove(m)
+            final_static_modules.append(m)
+    if 'ALL' in explicit_shared_modules:
+        for m in default_static_modules:
+            if m in final_static_modules:
+                final_static_modules.remove(m)
+            final_shared_modules.append(m)
 
     for m in explicit_static_modules:
+        if m in ['ALL','!DEFAULT','!FORCED']:
+            continue
+        if m.startswith('!'):
+            m = m[1:]
+            if m in required_static_modules:
+                raise Utils.WafError('These modules are REQUIRED as static modules: %s' %
+                                     ' '.join(required_static_modules))
+            if m in final_static_modules:
+                final_static_modules.remove(m)
+            continue
+        if m in forced_shared_modules:
+            raise Utils.WafError('These modules MUST be configured as shared modules: %s' %
+                                 ' '.join(forced_shared_modules))
         if m in final_shared_modules:
             final_shared_modules.remove(m)
-        final_static_modules.append(m)
+        if m not in final_static_modules:
+            final_static_modules.append(m)
     for m in explicit_shared_modules:
+        if m in ['ALL','!DEFAULT','!FORCED']:
+            continue
+        if m.startswith('!'):
+            m = m[1:]
+            if m in final_shared_modules:
+                final_shared_modules.remove(m)
+            continue
+        if m in required_static_modules:
+            raise Utils.WafError('These modules are REQUIRED as static modules: %s' %
+                                 ' '.join(required_static_modules))
+        if m in forced_static_modules:
+            raise Utils.WafError('These module MUST be configured as static modules: %s' %
+                                 ' '.join(forced_static_modules))
         if m in final_static_modules:
             final_static_modules.remove(m)
-        final_shared_modules.append(m)
-
-    if ("auth_domain" not in final_static_modules) or \
-            ("auth_builtin" not in final_static_modules) or \
-            ("auth_sam" not in final_static_modules) or \
-            ("auth_winbind" not in final_static_modules):
-        raise Utils.WafError('These auth modules MUST be configured as static modules: auth_domain, auth_builtin, auth_sam, auth_winbind')
+        if m not in final_shared_modules:
+            final_shared_modules.append(m)
 
     conf.env['static_modules'] = final_static_modules
     conf.env['shared_modules'] = final_shared_modules
@@ -1886,7 +1835,7 @@ main() {
     static_list = {}
     shared_list = {}
 
-    prefixes = ['vfs', 'pdb', 'auth', 'nss_info', 'charset', 'idmap', 'gpext', 'perfcount']
+    prefixes = ['vfs', 'pdb', 'auth', 'nss_info', 'charset', 'idmap', 'gpext', 'perfcount', 'rpc']
     conf.env['MODULE_PREFIXES'] = prefixes
     for p in prefixes:
         for m in final_static_modules:
@@ -1920,6 +1869,8 @@ main() {
             for entry in shared_list[p]:
                 conf.DEFINE('%s_init' % entry, 'samba_init_module')
                 conf.env[shared_env].append('%s' % entry)
+        Logs.info("%s: %s" % (static_env, ','.join(conf.env[static_env])))
+        Logs.info("%s: %s" % (shared_env, ','.join(conf.env[shared_env])))
 
     conf.SAMBA_CONFIG_H('include/config.h')