s3: smbd: SGI IRIX is officially dead. Remove the kernel oplock code for IRIX.
[sfrench/samba-autobuild/.git] / source3 / wscript
1 #!/usr/bin/env python
2
3 srcdir=".."
4
5 import sys, os
6 from optparse import SUPPRESS_HELP
7 sys.path.insert(0, srcdir+"/buildtools/wafsamba")
8 sys.path.insert(0, "source3")
9 import wafsamba, Options, Logs, Utils, Scripting
10 import build.charset
11 import samba_utils, samba_version
12 import samba3
13 import bison, flex
14
15 default_prefix = Options.default_prefix = '/usr/local/samba'
16
17 def set_options(opt):
18
19     opt.add_option('--with-static-modules',
20                    help=("Comma-separated list of names of modules to statically link in. "+
21                          "May include !module to disable 'module'. "+
22                          "Can be '!FORCED' to disable all non-required static only modules. "+
23                          "Can be '!DEFAULT' to disable all modules defaulting to a static build. "+
24                          "Can be 'ALL' to build all default shared modules static. "+
25                          "The most specific one wins, while the order is ignored "+
26                          "and --with-static-modules is evaluated before "+
27                          "--with-shared-modules"),
28                    action="store", dest='static_modules', default=None)
29     opt.add_option('--with-shared-modules',
30                    help=("Comma-separated list of names of modules to build shared. "+
31                          "May include !module to disable 'module'. "+
32                          "Can be '!FORCED' to disable all non-required shared only modules. "+
33                          "Can be '!DEFAULT' to disable all modules defaulting to a shared build. "+
34                          "Can be 'ALL' to build all default static modules shared. "+
35                          "The most specific one wins, while the order is ignored "+
36                          "and --with-static-modules is evaluated before "+
37                          "--with-shared-modules"),
38                    action="store", dest='shared_modules', default=None)
39
40     opt.SAMBA3_ADD_OPTION('winbind')
41     opt.SAMBA3_ADD_OPTION('ads')
42     opt.SAMBA3_ADD_OPTION('ldap')
43     opt.SAMBA3_ADD_OPTION('cups', with_name="enable", without_name="disable")
44     opt.SAMBA3_ADD_OPTION('iprint', with_name="enable", without_name="disable")
45     opt.SAMBA3_ADD_OPTION('pam')
46     opt.SAMBA3_ADD_OPTION('quotas')
47     opt.SAMBA3_ADD_OPTION('sendfile-support')
48     opt.SAMBA3_ADD_OPTION('utmp')
49     opt.SAMBA3_ADD_OPTION('avahi', with_name="enable", without_name="disable")
50     opt.SAMBA3_ADD_OPTION('iconv')
51     opt.SAMBA3_ADD_OPTION('acl-support')
52     opt.SAMBA3_ADD_OPTION('dnsupdate')
53     opt.SAMBA3_ADD_OPTION('syslog')
54     opt.SAMBA3_ADD_OPTION('automount')
55     opt.SAMBA3_ADD_OPTION('dmapi', default=None) # None means autodetection
56     opt.SAMBA3_ADD_OPTION('fam', default=None) # None means autodetection
57     opt.SAMBA3_ADD_OPTION('profiling-data', default=False)
58     opt.SAMBA3_ADD_OPTION('libarchive', default=True)
59
60     opt.SAMBA3_ADD_OPTION('cluster-support', default=False)
61
62     opt.SAMBA3_ADD_OPTION('regedit', default=None)
63
64     opt.SAMBA3_ADD_OPTION('fake-kaserver',
65                           help=("Include AFS fake-kaserver support"), default=False)
66
67     opt.add_option('--with-libcephfs',
68                    help=("Directory under which libcephfs is installed"),
69                    action="store", dest='libcephfs_dir', default=None)
70
71     opt.SAMBA3_ADD_OPTION('glusterfs', with_name="enable", without_name="disable", default=True)
72     opt.SAMBA3_ADD_OPTION('cephfs', with_name="enable", without_name="disable", default=True)
73
74     opt.add_option('--enable-vxfs',
75                   help=("enable support for VxFS (default=no)"),
76                   action="store_true", dest='enable_vxfs', default=False)
77
78     opt.SAMBA3_ADD_OPTION('spotlight', with_name="enable", without_name="disable", default=False)
79
80 def configure(conf):
81     from samba_utils import TO_LIST
82
83     default_static_modules = []
84     default_shared_modules = []
85     required_static_modules = []
86     forced_static_modules = []
87     forced_shared_modules = []
88
89     if Options.options.developer:
90         conf.ADD_CFLAGS('-DDEVELOPER -DDEBUG_PASSWORD')
91         conf.env.developer = True
92
93     if sys.platform != 'openbsd5':
94         conf.ADD_LDFLAGS("-Wl,--export-dynamic", testflags=True)
95
96     # We crash without vfs_default
97     required_static_modules.extend(TO_LIST('vfs_default'))
98
99     conf.CHECK_HEADERS('netdb.h')
100     conf.CHECK_HEADERS('linux/falloc.h linux/ioctl.h')
101
102     conf.CHECK_FUNCS('getcwd fchown chmod fchmod mknod')
103     conf.CHECK_FUNCS('strtol strchr strupr chflags')
104     conf.CHECK_FUNCS('getrlimit fsync fdatasync setpgid')
105     conf.CHECK_FUNCS('setsid glob strpbrk crypt16 getauthuid')
106     conf.CHECK_FUNCS('innetgr')
107     conf.CHECK_FUNCS('initgroups select poll rdchk getgrnam getgrent pathconf')
108     conf.CHECK_FUNCS('setpriv setgidx setuidx setgroups syscall sysconf')
109     conf.CHECK_FUNCS('atexit grantpt posix_openpt fallocate')
110     conf.CHECK_FUNCS('fseeko setluid')
111     conf.CHECK_FUNCS('getpwnam', headers='sys/types.h pwd.h')
112     conf.CHECK_FUNCS('fdopendir')
113     conf.CHECK_FUNCS('fstatat')
114     conf.CHECK_FUNCS('getpwent_r setenv clearenv strcasecmp fcvt fcvtl')
115     conf.CHECK_FUNCS('syslog vsyslog timegm setlocale')
116     conf.CHECK_FUNCS_IN('nanosleep', 'rt')
117     conf.CHECK_FUNCS('lutimes futimes utimensat futimens')
118     conf.CHECK_FUNCS('mlock munlock mlockall munlockall')
119     conf.CHECK_FUNCS('memalign posix_memalign hstrerror')
120     conf.CHECK_FUNCS('shmget')
121     conf.CHECK_FUNCS_IN('shm_open', 'rt', checklibc=True)
122     conf.CHECK_FUNCS_IN('yp_get_default_domain', 'nsl')
123     conf.CHECK_FUNCS_IN('dn_expand _dn_expand __dn_expand', 'resolv')
124     conf.CHECK_FUNCS_IN('dn_expand', 'inet')
125     conf.CHECK_DECLS('fdatasync', reverse=True)
126     conf.CHECK_DECLS('readahead', reverse=True, headers='fcntl.h')
127
128     if conf.CHECK_CODE('''
129 #if defined(HAVE_UNISTD_H)
130 #include <unistd.h>
131 #endif
132 long ret = splice(0,0,1,0,400,SPLICE_F_MOVE);
133 ''',
134         'HAVE_LINUX_SPLICE',
135         headers='fcntl.h'):
136         conf.CHECK_DECLS('splice', reverse=True, headers='fcntl.h')
137
138     # Check for inotify support (Skip if we are SunOS)
139     #NOTE: illumos provides sys/inotify.h but is not an exact match for linux
140     host_os = sys.platform
141     if host_os.rfind('sunos') == -1:
142         conf.CHECK_HEADERS('sys/inotify.h')
143         if conf.env.HAVE_SYS_INOTIFY_H:
144            conf.DEFINE('HAVE_INOTIFY', 1)
145
146     # Check for kernel change notify support
147     conf.CHECK_CODE('''
148 #ifndef F_NOTIFY
149 #define F_NOTIFY 1026
150 #endif
151 main() {
152         exit(fcntl(open("/tmp", O_RDONLY), F_NOTIFY, 0) == -1 ?  1 : 0);
153 }''', 'HAVE_KERNEL_CHANGE_NOTIFY', addmain=False, execute=True,
154         headers='fcntl.h signal.h',
155         msg="Checking for kernel change notify support")
156
157     # Check for Linux kernel oplocks
158     conf.CHECK_CODE('''
159 #include <sys/types.h>
160 #include <fcntl.h>
161 #include <signal.h>
162 #ifndef F_GETLEASE
163 #define F_GETLEASE 1025
164 #endif
165 main() {
166         exit(fcntl(open("/tmp", O_RDONLY), F_GETLEASE, 0) == -1 ?  1 : 0);
167 }''', 'HAVE_KERNEL_OPLOCKS_LINUX', addmain=False, execute=True,
168         msg="Checking for Linux kernel oplocks")
169
170     # Check for kernel share modes
171     conf.CHECK_CODE('''
172 #include <sys/types.h>
173 #include <fcntl.h>
174 #include <signal.h>
175 #include <sys/file.h>
176 #ifndef LOCK_MAND
177 #define LOCK_MAND        32
178 #define LOCK_READ        64
179 #endif
180 main() {
181         exit(flock(open("/dev/null", O_RDWR), LOCK_MAND|LOCK_READ) != 0);
182 }''', 'HAVE_KERNEL_SHARE_MODES', addmain=False, execute=True,
183         msg="Checking for kernel share modes")
184
185     # check for fam libs
186     samba_fam_libs=None
187     check_for_fam=False
188     if Options.options.with_fam is None:
189         check_for_fam=True
190     elif Options.options.with_fam == True:
191         check_for_fam=True
192
193     if check_for_fam and conf.CHECK_HEADERS('fam.h'):
194         if conf.CHECK_FUNCS_IN('FAMOpen2', 'fam'):
195             samba_fam_libs='fam'
196         elif conf.CHECK_FUNCS_IN('FAMOpen2', 'fam C'):
197             samba_fam_libs='fam C'
198         conf.CHECK_TYPE('enum FAMCodes', headers='fam.h',
199             define='HAVE_FAM_H_FAMCODES_TYPEDEF',
200             msg='Checking whether enum FAMCodes is available')
201         conf.CHECK_FUNCS_IN('FAMNoExists', 'fam')
202
203     if samba_fam_libs is not None:
204         conf.DEFINE('SAMBA_FAM_LIBS', samba_fam_libs)
205         conf.DEFINE('HAVE_FAM', 1)
206     else:
207         if Options.options.with_fam == True:
208             conf.fatal('FAM support requested, but no suitable FAM library found')
209         elif check_for_fam:
210             Logs.warn('no suitable FAM library found')
211
212     # check for libarchive (tar command in smbclient)
213     # None means autodetect, True/False means enable/disable
214     conf.SET_TARGET_TYPE('archive', 'EMPTY')
215     if Options.options.with_libarchive is not False:
216         Logs.info("Checking for libarchive existence")
217         if conf.CHECK_HEADERS('archive.h') and conf.CHECK_LIB('archive', shlib=True):
218             conf.CHECK_FUNCS_IN('archive_read_support_filter_all archive_read_free', 'archive')
219         else:
220             conf.fatal("libarchive support not found. "
221                        "Try installing libarchive-dev or libarchive-devel. "
222                        "Otherwise, use --without-libarchive to "
223                        "build without libarchive support. "
224                        "libarchive support is required for the smbclient "
225                        "tar-file mode")
226     elif conf.CONFIG_GET('ENABLE_SELFTEST'):
227         raise Utils.WafError('libarchive library required for '
228                              '--enable-selftest')
229
230
231     # check for DMAPI libs
232     if Options.options.with_dmapi == False:
233         have_dmapi = False
234     else:
235         have_dmapi = True
236         Logs.info("Checking for DMAPI library existence")
237         samba_dmapi_lib = ''
238         if conf.CHECK_FUNCS_IN('dm_get_eventlist', 'dm'):
239             samba_dmapi_lib = 'dm'
240         else:
241             if conf.CHECK_FUNCS_IN('dm_get_eventlist', 'jfsdm'):
242                 samba_dmapi_lib = 'jfsdm'
243             else:
244                 if conf.CHECK_FUNCS_IN('dm_get_eventlist', 'dmapi'):
245                     samba_dmapi_lib = 'dmapi'
246                 else:
247                     if conf.CHECK_FUNCS_IN('dm_get_eventlist', 'xdsm'):
248                         samba_dmapi_lib = 'xdsm'
249         # only bother to test headers and compilation when a candidate
250         # library has been found
251         if samba_dmapi_lib == '':
252             have_dmapi = False
253             broken_dmapi = "no suitable DMAPI library found"
254
255         if have_dmapi:
256             conf.CHECK_HEADERS('sys/dmi.h xfs/dmapi.h sys/jfsdmapi.h sys/dmapi.h dmapi.h')
257             conf.CHECK_CODE('''
258 #include <time.h>      /* needed by Tru64 */
259 #include <sys/types.h> /* needed by AIX */
260 #ifdef HAVE_XFS_DMAPI_H
261 #include <xfs/dmapi.h>
262 #elif defined(HAVE_SYS_DMI_H)
263 #include <sys/dmi.h>
264 #elif defined(HAVE_SYS_JFSDMAPI_H)
265 #include <sys/jfsdmapi.h>
266 #elif defined(HAVE_SYS_DMAPI_H)
267 #include <sys/dmapi.h>
268 #elif defined(HAVE_DMAPI_H)
269 #include <dmapi.h>
270 #endif
271
272 /* This link test is designed to fail on IRI 6.4, but should
273  * succeed on Linux, IRIX 6.5 and AIX.
274  */
275 int main(int argc, char **argv)
276 {
277         char * version;
278         dm_eventset_t events;
279         /* This doesn't take an argument on IRIX 6.4. */
280         dm_init_service(&version);
281         /* IRIX 6.4 expects events to be a pointer. */
282         DMEV_ISSET(DM_EVENT_READ, events);
283
284         return 0;
285 }
286 ''',
287             'USEABLE_DMAPI_LIBRARY',
288             addmain=False,
289             execute=False,
290             lib=samba_dmapi_lib,
291             msg='Checking whether DMAPI lib '+samba_dmapi_lib+' can be used')
292             if not conf.CONFIG_SET('USEABLE_DMAPI_LIBRARY'):
293                 have_dmapi = False
294                 broken_dmapi = "no usable DMAPI library found"
295
296     if have_dmapi:
297         Logs.info("Building with DMAPI support.")
298         conf.env['dmapi_lib'] = samba_dmapi_lib
299         conf.DEFINE('USE_DMAPI', 1)
300     else:
301         if Options.options.with_dmapi == False:
302             Logs.info("Building without DMAPI support (--without-dmapi).")
303         elif Options.options.with_dmapi == True:
304             Logs.error("DMAPI support not available: " + broken_dmapi)
305             conf.fatal('DMAPI support requested but not found.');
306         else:
307             Logs.warn("Building without DMAPI support: " + broken_dmapi)
308         conf.env['dmapi_lib'] = ''
309
310     # Check for various members of the stat structure
311     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_blocks', define='HAVE_STAT_ST_BLOCKS',
312                                 headers='sys/stat.h')
313     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_blksize', define='HAVE_STAT_ST_BLKSIZE',
314                                 headers='sys/stat.h')
315     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_flags', define='HAVE_STAT_ST_FLAGS',
316                                 headers='sys/types.h sys/stat.h unistd.h')
317
318     if conf.env.HAVE_BLKCNT_T:
319         conf.CHECK_CODE('''
320         static int test_array[1 - 2 * !(((long int)(sizeof(blkcnt_t))) <= 4)];''',
321                 'SIZEOF_BLKCNT_T_4',
322                 headers='replace.h sys/types.h sys/stat.h unistd.h',
323                 msg="Checking whether blkcnt_t is 32 bit")
324
325     # If sizeof is 4 it can't be 8
326     if conf.env.HAVE_BLKCNT_T:
327         if not conf.CONFIG_SET('SIZEOF_BLKCNT_T_4'):
328             conf.CHECK_CODE('''
329             static int test_array[1 - 2 * !(((long int)(sizeof(blkcnt_t))) <= 8)];''',
330                     'SIZEOF_BLKCNT_T_8',
331                     headers='replace.h sys/types.h sys/stat.h unistd.h',
332                     msg="Checking whether blkcnt_t is 64 bit")
333
334     # Check for POSIX capability support
335     conf.CHECK_FUNCS_IN('cap_get_proc', 'cap', headers='sys/capability.h')
336
337     if conf.env.HAVE_SYS_CAPABILITY_H:
338         conf.CHECK_CODE('''
339         cap_t cap;
340         cap_value_t vals[1];
341         if (!(cap = cap_get_proc())) exit(1);
342         vals[0] = CAP_CHOWN;
343         cap_set_flag(cap, CAP_INHERITABLE, 1, vals, CAP_CLEAR);
344         cap_set_proc(cap);''',
345                         'HAVE_POSIX_CAPABILITIES', execute=True, lib="cap",
346                         headers='sys/capability.h',
347                         msg="Checking whether POSIX capabilities are available")
348
349     conf.CHECK_CODE('int i;', 'BROKEN_NISPLUS_INCLUDE_FILES',
350                     headers='sys/types.h sys/acl.h rpcsvc/nis.h',
351                     msg="Checking for broken nisplus include files")
352
353     # Check if the compiler will optimize out functions
354     conf.CHECK_CODE('''
355 #include <sys/types.h>
356 size_t __unsafe_string_function_usage_here_size_t__(void);
357 #define CHECK_STRING_SIZE(d, len) (sizeof(d) != (len) && sizeof(d) != sizeof(char *))
358 static size_t push_string_check_fn(void *dest, const char *src, size_t dest_len) {
359         return 0;
360 }
361
362 #define push_string_check(dest, src, dest_len) \
363     (CHECK_STRING_SIZE(dest, dest_len) \
364     ? __unsafe_string_function_usage_here_size_t__()    \
365     : push_string_check_fn(dest, src, dest_len))
366
367 int main(int argc, char **argv) {
368     char outbuf[1024];
369     char *p = outbuf;
370     const char *foo = "bar";
371     p += 31 + push_string_check(p + 31, foo, sizeof(outbuf) - (p + 31 - outbuf));
372     return 0;
373 }''', 'HAVE_COMPILER_WILL_OPTIMIZE_OUT_FNS',
374             addmain=False,
375             add_headers=False,
376             msg="Checking if the compiler will optimize out functions")
377
378     # Check if the compiler supports the LL suffix on long long integers
379     # AIX needs this
380     conf.CHECK_CODE('long long i = 0x8000000000LL', 'COMPILER_SUPPORTS_LL',
381                     headers='stdio.h',
382                     msg="Checking for LL suffix on long long integers")
383
384     conf.CHECK_FUNCS('''
385 _acl __acl atexit
386  _chdir __chdir chflags chmod _close __close _closedir
387 __closedir crypt16 devnm dirfd
388 DNSServiceRegister _dup __dup _dup2 __dup2 endmntent execl
389 _facl __facl _fchdir
390 __fchdir fchmod fchown _fcntl __fcntl fcvt fcvtl fdatasync
391 _fork __fork fseeko
392 _fstat __fstat fsync
393 futimens futimes __fxstat getauthuid
394 getcwd _getcwd __getcwd getdents __getdents getdirentries
395 getgrent getgrnam getgrouplist getgrset getmntent getpagesize
396 getpwanam getpwent_r getrlimit
397 glob grantpt hstrerror initgroups innetgr
398 llseek _llseek __llseek _lseek __lseek
399 _lstat __lstat lutimes
400 __lxstat memalign mknod mlock mlockall munlock munlockall
401 _open __open _opendir __opendir
402 pathconf poll
403 posix_memalign pread _pread __pread
404 pwrite _pwrite __pwrite
405 rdchk _read __read _readdir __readdir
406 _seekdir __seekdir
407 select setenv setgidx setgroups setlocale setluid
408 setmntent setpgid setpriv setsid setuidx
409 shmget shm_open
410 _stat __stat statvfs
411 strcasecmp strchr strpbrk strsignal strtol strupr sysconf sysctl sysctlbyname
412 __sys_llseek syslog _telldir __telldir timegm
413 utimensat vsyslog _write __write __xstat
414 ''')
415
416     conf.CHECK_SAMBA3_CHARSET() # see build/charset.py
417
418     # FIXME: these should be tests for features, but the old build system just
419     # checks for OSes.
420     host_os = sys.platform
421     Logs.info("building on %s" % host_os)
422
423     # Python doesn't have case switches... :/
424     # FIXME: original was *linux* | gnu* | k*bsd*-gnu | kopensolaris*-gnu | *qnx*)
425     # the search for .rfind('gnu') covers gnu* and *-gnu is that too broad?
426
427     conf.SET_TARGET_TYPE('sunacl', 'EMPTY')
428     if (host_os.rfind('linux') > -1) or (host_os.rfind('gnu') > -1) or (host_os.rfind('qnx') > -1):
429         if host_os.rfind('linux') > -1:
430             conf.DEFINE('LINUX', '1')
431         elif host_os.rfind('qnx') > -1:
432             conf.DEFINE('QNX', '1')
433         conf.DEFINE('STAT_ST_BLOCKSIZE', '512')
434     elif (host_os.rfind('darwin') > -1):
435         conf.DEFINE('DARWINOS', 1)
436         conf.ADD_CFLAGS('-fno-common')
437         conf.DEFINE('STAT_ST_BLOCKSIZE', '512')
438     elif (host_os.rfind('freebsd') > -1):
439         conf.DEFINE('FREEBSD', 1)
440         if conf.CHECK_HEADERS('sunacl.h'):
441             conf.DEFINE('HAVE_FREEBSD_SUNACL_H', '1')
442             conf.CHECK_FUNCS_IN(['acl'], 'sunacl')
443         conf.DEFINE('STAT_ST_BLOCKSIZE', '512')
444     elif (host_os.rfind('irix') > -1):
445         conf.DEFINE('IRIX', 1)
446         conf.DEFINE('STAT_ST_BLOCKSIZE', '512')
447     elif (host_os.rfind('aix') > -1):
448         conf.DEFINE('AIX', 1)
449         conf.DEFINE('STAT_ST_BLOCKSIZE', 'DEV_BSIZE')
450     elif (host_os.rfind('hpux') > -1):
451         conf.DEFINE('HPUX', 1)
452         conf.DEFINE('STAT_ST_BLOCKSIZE', '8192')
453     elif (host_os.rfind('osf') > -1):
454         conf.DEFINE('OSF1', 1)
455         conf.DEFINE('STAT_ST_BLOCKSIZE', '512')
456
457     # FIXME: Add more checks here.
458     else:
459         conf.DEFINE('STAT_ST_BLOCKSIZE', '512')
460
461     if Options.options.with_acl_support:
462         if (host_os.rfind('hpux') > -1):
463                 Logs.info('Using HPUX ACLs')
464                 conf.DEFINE('HAVE_HPUX_ACLS',1)
465                 conf.DEFINE('POSIX_ACL_NEEDS_MASK',1)
466                 default_static_modules.extend(TO_LIST('vfs_hpuxacl'))
467         elif (host_os.rfind('aix') > -1):
468                 Logs.info('Using AIX ACLs')
469                 conf.DEFINE('HAVE_AIX_ACLS',1)
470                 default_static_modules.extend(TO_LIST('vfs_aixacl vfs_aixacl2'))
471         elif (host_os.rfind('darwin') > -1):
472             Logs.warn('ACLs on Darwin currently not supported')
473             conf.fatal("ACL support not available on Darwin/MacOS. "
474                        "Use --without-acl-support for building without "
475                        "ACL support. "
476                        "ACL support is required to change permissions "
477                        "from Windows clients.")
478         else:
479             conf.CHECK_FUNCS_IN(['acl_get_file'], 'acl')
480             if conf.CHECK_CODE('''
481 acl_t acl;
482 int entry_id;
483 acl_entry_t *entry_p;
484 return acl_get_entry(acl, entry_id, entry_p);
485 ''',
486                         'HAVE_POSIX_ACLS',
487                         headers='sys/types.h sys/acl.h', link=False,
488                         msg="Checking for POSIX ACL support") :
489                 conf.CHECK_CODE('''
490 acl_permset_t permset_d;
491 acl_perm_t perm;
492 return acl_get_perm_np(permset_d, perm);
493 ''',
494                         'HAVE_ACL_GET_PERM_NP',
495                         headers='sys/types.h sys/acl.h', link=True,
496                         msg="Checking whether acl_get_perm_np() is available")
497                 # source3/lib/sysacls.c calls posixacl_sys_acl_get_file()
498                 required_static_modules.extend(TO_LIST('vfs_posixacl'))
499                 conf.CHECK_VARIABLE('ACL_EVERYONE', headers='sys/acl.h')
500             elif conf.CHECK_FUNCS_IN(['facl'], 'sec'):
501                 Logs.info('Using solaris or UnixWare ACLs')
502                 conf.DEFINE('HAVE_SOLARIS_UNIXWARE_ACLS',1)
503                 default_static_modules.extend(TO_LIST('vfs_solarisacl'))
504             elif conf.CHECK_FUNCS_IN(['acl_get_fd'], 'pacl'):
505                 Logs.info('Using Tru64 ACLs')
506                 conf.DEFINE('HAVE_TRU64_ACLS',1)
507                 default_static_modules.extend(TO_LIST('vfs_tru64acl'))
508             else:
509                 conf.fatal("ACL support not found. Try installing libacl1-dev "
510                            "or libacl-devel.  "
511                            "Otherwise, use --without-acl-support to build "
512                            "without ACL support. "
513                            "ACL support is required to change permissions from "
514                            "Windows clients.")
515
516     if conf.CHECK_FUNCS('dirfd'):
517         conf.DEFINE('HAVE_DIRFD_DECL', 1)
518
519     conf.CHECK_CODE('struct statfs fsd; fsid_t fsid = fsd.f_fsid; return statfs(".", &fsd);',
520                     'HAVE_STATFS_F_FSID',
521                     msg="vfs_fileid checking for statfs() and struct statfs.f_fsid",
522                     headers='sys/types.h sys/statfs.h',
523                     execute=True)
524
525     if conf.CONFIG_SET('HAVE_FALLOCATE'):
526         conf.CHECK_CODE('''
527                 int ret = fallocate(0, FALLOC_FL_KEEP_SIZE, 0, 10);''',
528                 'HAVE_LINUX_FALLOCATE',
529                 msg="Checking whether the Linux 'fallocate' function is available",
530                 headers='unistd.h sys/types.h fcntl.h linux/falloc.h')
531         conf.CHECK_CODE('''
532                 int ret = fallocate(0, FALLOC_FL_PUNCH_HOLE, 0, 10);''',
533                 'HAVE_FALLOC_FL_PUNCH_HOLE',
534                 msg="Checking whether Linux 'fallocate' supports hole-punching",
535                 headers='unistd.h sys/types.h fcntl.h linux/falloc.h')
536
537     conf.CHECK_CODE('''
538             int ret = lseek(0, 0, SEEK_HOLE);
539             ret = lseek(0, 0, SEEK_DATA);''',
540             'HAVE_LSEEK_HOLE_DATA',
541             msg="Checking whether lseek supports hole/data seeking",
542             headers='unistd.h sys/types.h')
543
544     conf.CHECK_CODE('''
545                 ssize_t err = readahead(0,0,0x80000);''',
546                 'HAVE_LINUX_READAHEAD',
547                 msg="Checking whether Linux readahead is available",
548                 headers='unistd.h fcntl.h')
549     conf.CHECK_DECLS('readahead', headers='fcntl.h', always=True)
550
551     conf.CHECK_CODE('int fd = openat(AT_FDCWD, ".", O_RDONLY);',
552                 'HAVE_OPENAT',
553                 msg='Checking for openat',
554                 headers='fcntl.h')
555
556     conf.CHECK_CODE('''
557 struct msghdr msg;
558 union {
559         struct cmsghdr cm;
560         char control[CMSG_SPACE(sizeof(int))];
561 } control_un;
562 msg.msg_control = control_un.control;
563 msg.msg_controllen = sizeof(control_un.control);
564 ''',
565         'HAVE_STRUCT_MSGHDR_MSG_CONTROL',
566         msg='Checking if we can use msg_control for passing file descriptors',
567         headers='sys/types.h stdlib.h stddef.h sys/socket.h sys/un.h')
568     conf.CHECK_CODE('''
569 struct msghdr msg;
570 int fd;
571 msg.msg_accrights = (caddr_t) &fd;
572 msg.msg_accrightslen = sizeof(fd);
573 ''',
574         'HAVE_STRUCT_MSGHDR_MSG_ACCRIGHTS',
575         msg='Checking if we can use msg_accrights for passing file descriptors',
576         headers='sys/types.h stdlib.h stddef.h sys/socket.h sys/un.h')
577
578     if Options.options.with_winbind:
579         conf.env.build_winbind = True
580         conf.DEFINE('WITH_WINBIND', '1')
581
582     conf.find_program('awk', var='AWK')
583
584     conf.CHECK_HEADERS('asm/types.h')
585
586     conf.CHECK_CODE('dev_t dev; int i = major(dev); return 0', "HAVE_DEVICE_MAJOR_FN",
587                     headers='unistd.h sys/types.h',
588                     msg="Checking for major macro")
589
590     conf.CHECK_CODE('dev_t dev; int i = minor(dev); return 0', "HAVE_DEVICE_MINOR_FN",
591                     headers='unistd.h sys/types.h',
592                     msg="Checking for minor macro")
593
594     conf.CHECK_STRUCTURE_MEMBER('struct dirent', 'd_off',
595                                 headers='unistd.h sys/types.h dirent.h',
596                                 define='HAVE_DIRENT_D_OFF')
597
598     if (conf.CONFIG_SET('HAVE_YP_GET_DEFAULT_DOMAIN')):
599            conf.DEFINE('HAVE_NETGROUP', '1')
600
601     # Look for CUPS
602     if Options.options.with_cups:
603         conf.find_program('cups-config', var='CUPS_CONFIG')
604         if conf.env.CUPS_CONFIG:
605             # we would normally use --libs here, but cups-config incorrectly adds
606             # gssapi_krb5 and other libraries to its --libs output. That breaks the use
607             # of an in-tree heimdal kerberos
608             conf.CHECK_CFG(path=conf.env.CUPS_CONFIG, args="--cflags --ldflags",
609                            package="", uselib_store="CUPS")
610         conf.CHECK_HEADERS('cups/cups.h cups/language.h', lib='cups')
611         conf.CHECK_FUNCS_IN('httpConnect httpConnectEncrypt', 'cups')
612         if conf.CONFIG_SET('HAVE_CUPS_CUPS_H') and conf.CONFIG_SET('HAVE_CUPS_LANGUAGE_H'):
613             conf.DEFINE('HAVE_CUPS', '1')
614         else:
615             conf.undefine('HAVE_CUPS')
616             conf.SET_TARGET_TYPE('cups', 'EMPTY')
617     else:
618         # define an empty subsystem for cups, to allow it to be used as an empty dependency
619         conf.SET_TARGET_TYPE('cups', 'EMPTY')
620
621     if Options.options.with_iprint:
622         if conf.CONFIG_SET('HAVE_CUPS'):
623             conf.DEFINE('HAVE_IPRINT', '1')
624         else:
625             Logs.warn("--enable-iprint=yes but cups support not sufficient")
626     if Options.options.with_syslog:
627         conf.DEFINE('WITH_SYSLOG', '1')
628     if Options.options.with_automount:
629         conf.DEFINE('WITH_AUTOMOUNT', '1')
630
631     # Check for LDAP
632     if Options.options.with_ldap:
633         conf.CHECK_HEADERS('ldap.h lber.h ldap_pvt.h')
634         conf.CHECK_TYPE('ber_tag_t', 'unsigned int', headers='ldap.h lber.h')
635         conf.CHECK_FUNCS_IN('ber_scanf ber_sockbuf_add_io', 'lber')
636         conf.CHECK_VARIABLE('LDAP_OPT_SOCKBUF', headers='ldap.h')
637
638         # if we LBER_OPT_LOG_PRINT_FN we can intercept ldap logging and print it out
639         # for the samba logs
640         conf.CHECK_VARIABLE('LBER_OPT_LOG_PRINT_FN',
641                             define='HAVE_LBER_LOG_PRINT_FN', headers='lber.h')
642
643         conf.CHECK_FUNCS_IN('ldap_init ldap_init_fd ldap_initialize ldap_set_rebind_proc', 'ldap')
644         conf.CHECK_FUNCS_IN('ldap_add_result_entry', 'ldap')
645
646         # Check if ldap_set_rebind_proc() takes three arguments
647         if conf.CHECK_CODE('ldap_set_rebind_proc(0, 0, 0)',
648                            'LDAP_SET_REBIND_PROC_ARGS',
649                            msg="Checking whether ldap_set_rebind_proc takes 3 arguments",
650                            headers='ldap.h lber.h', link=False):
651             conf.DEFINE('LDAP_SET_REBIND_PROC_ARGS', '3')
652         else:
653             conf.DEFINE('LDAP_SET_REBIND_PROC_ARGS', '2')
654
655         # last but not least, if ldap_init() exists, we want to use ldap
656         if conf.CONFIG_SET('HAVE_LDAP_INIT') and conf.CONFIG_SET('HAVE_LDAP_H'):
657             conf.DEFINE('HAVE_LDAP', '1')
658             conf.DEFINE('LDAP_DEPRECATED', '1')
659             conf.env['HAVE_LDAP'] = '1'
660             # if ber_sockbuf_add_io() and LDAP_OPT_SOCKBUF are available, we can add
661             # SASL wrapping hooks
662             if conf.CONFIG_SET('HAVE_BER_SOCKBUF_ADD_IO') and \
663                     conf.CONFIG_SET('HAVE_LDAP_OPT_SOCKBUF'):
664                 conf.DEFINE('HAVE_LDAP_SASL_WRAPPING', '1')
665         else:
666             conf.fatal("LDAP support not found. "
667                        "Try installing libldap2-dev or openldap-devel. "
668                        "Otherwise, use --without-ldap to build without "
669                        "LDAP support. "
670                        "LDAP support is required for the LDAP passdb backend, "
671                        "LDAP idmap backends and ADS. "
672                        "ADS support improves communication with "
673                        "Active Directory domain controllers.")
674     else:
675         conf.SET_TARGET_TYPE('ldap', 'EMPTY')
676         conf.SET_TARGET_TYPE('lber', 'EMPTY')
677
678     if Options.options.with_ads == False:
679         use_ads = False
680         use_ads_krb5 = False
681         use_ads_ldap = False
682     else:
683         use_ads = True
684         use_ads_krb5 = True
685         use_ads_ldap = True
686         if not conf.CONFIG_SET('HAVE_ENCTYPE_ARCFOUR_HMAC_MD5') and \
687            not conf.CONFIG_SET('HAVE_ENCTYPE_ARCFOUR_HMAC'):
688             Logs.warn("arcfour-hmac-md5 encryption type not found in -lkrb5")
689             use_ads_krb5 = False
690         if not conf.CONFIG_SET('HAVE_KRB5_MK_REQ_EXTENDED'):
691             Logs.warn("krb5_mk_req_extended not found in -lkrb5")
692             use_ads_krb5 = False
693         if not conf.CONFIG_SET('HAVE_KRB5_GET_HOST_REALM'):
694             Logs.warn("krb5_get_host_realm not found in -lkrb5")
695             use_ads_krb5 = False
696         if not conf.CONFIG_SET('HAVE_KRB5_FREE_HOST_REALM'):
697             Logs.warn("krb5_free_host_realm not found in -lkrb5")
698             use_ads_krb5 = False
699         if not conf.CONFIG_SET('HAVE_KRB5_FWD_TGT_CREDS'):
700             Logs.warn("krb5_fwd_tgt_creds found in -lkrb5")
701             use_ads_krb5 = False
702         if not conf.CONFIG_SET('HAVE_KRB5_GET_INIT_CREDS_OPT_ALLOC'):
703             Logs.warn("krb5_get_init_creds_opt_alloc not found in -lkrb5")
704             use_ads_krb5 = False
705         if not conf.CONFIG_SET('KRB5_CREDS_OPT_FREE_REQUIRES_CONTEXT'):
706             Logs.warn("krb5_get_init_creds_opt_free was not found or was too old in -lkrb5")
707             use_ads_krb5 = False
708         if not conf.CONFIG_SET('HAVE_KRB5_GET_RENEWED_CREDS'):
709             Logs.warn("krb5_get_renewed_creds not found in -lkrb5")
710             use_ads_krb5 = False
711         if not conf.CONFIG_SET('HAVE_KRB5_PRINCIPAL_COMPARE_ANY_REALM'):
712             Logs.warn("krb5_principal_compare_any_realm not found in -lkrb5")
713             use_ads_krb5 = False
714         if not conf.CONFIG_SET('HAVE_KRB5_C_STRING_TO_KEY') and \
715            not conf.CONFIG_SET('HAVE_KRB5_STRING_TO_KEY_SALT'):
716             Logs.warn("krb5_c_string_to_key not found in -lkrb5")
717             use_ads_krb5 = False
718         if not conf.CONFIG_SET('HAVE_KRB5_PRINCIPAL2SALT') and \
719            not conf.CONFIG_SET('HAVE_KRB5_GET_PW_SALT'):
720             Logs.warn("no CREATE_KEY_FUNCTIONS detected")
721             use_ads_krb5 = False
722         if not conf.CONFIG_SET('HAVE_KRB5_GET_PERMITTED_ENCTYPES') and \
723            not conf.CONFIG_SET('HAVE_KRB5_GET_DEFAULT_IN_TKT_ETYPES'):
724             Logs.warn("no GET_ENCTYPES_FUNCTIONS detected")
725             use_ads_krb5 = False
726         if not conf.CONFIG_SET('HAVE_KRB5_KT_FREE_ENTRY') and \
727            not conf.CONFIG_SET('HAVE_KRB5_FREE_KEYTAB_ENTRY_CONTENTS'):
728             Logs.warn("no KT_FREE_FUNCTION detected")
729             use_ads_krb5 = False
730         if not conf.CONFIG_SET('HAVE_KRB5_C_VERIFY_CHECKSUM'):
731             Logs.warn("krb5_c_verify_checksum_compare not found in -lkrb5")
732             use_ads_krb5 = False
733
734         # We don't actually use
735         # gsskrb5_extract_authz_data_from_sec_context, but it is a
736         # clue that this Heimdal, which does the PAC processing we
737         # need on the standard gss_inquire_sec_context_by_oid
738         if not conf.CONFIG_SET('HAVE_GSS_GET_NAME_ATTRIBUTE') and \
739             not (conf.CONFIG_SET('HAVE_GSSKRB5_EXTRACT_AUTHZ_DATA_FROM_SEC_CONTEXT') and \
740                      conf.CONFIG_SET('HAVE_GSS_INQUIRE_SEC_CONTEXT_BY_OID')):
741             Logs.warn("need either gss_get_name_attribute or gsskrb5_extract_authz_data_from_sec_context and gss_inquire_sec_context_by_oid in -lgssapi for PAC support")
742             use_ads_krb5 = False
743
744         if not conf.CONFIG_SET('HAVE_GSS_KRB5_EXPORT_LUCID_SEC_CONTEXT'):
745             Logs.warn("need gss_krb5_export_lucid_sec_context for SPNEGO and gss_wrap support")
746             use_ads_krb5 = False
747
748         if use_ads_krb5:
749             conf.DEFINE('HAVE_KRB5', '1')
750             conf.env['HAVE_KRB5'] = '1'
751         else:
752             conf.undefine('HAVE_KRB5_H')
753             conf.undefine('HAVE_GSSAPI_H')
754             conf.undefine('HAVE_GSSAPI_GSSAPI_GENERIC_H')
755             conf.undefine('HAVE_GSSAPI_GSSAPI_H')
756             use_ads = False
757
758         if not conf.CONFIG_SET('HAVE_LDAP'):
759             use_ads = False
760             use_ads_ldap = False
761
762     if use_ads:
763         conf.DEFINE('WITH_ADS', '1')
764         conf.env['HAVE_ADS'] = '1'
765         Logs.info("Building with Active Directory support.")
766         # these have broken dependencies
767         forced_shared_modules.extend(TO_LIST('idmap_ad idmap_rfc2307'))
768     elif Options.options.with_ads == False:
769         Logs.info("Building without Active Directory support (--without-ads).")
770     else:
771         if not use_ads_krb5:
772             Logs.warn("Active Directory support not available: krb5 libs don't have all required features")
773         if not use_ads_ldap:
774             Logs.warn("Active Directory support not available: LDAP support is not available.")
775         if Options.options.with_ads:
776             conf.fatal("Active Directory support not found. Use --without-ads "
777                        "for building without Active Directory support. "
778                        "ADS support improves communication with "
779                        "Active Directory domain controllers.")
780         else:
781             # this is the auto-mode case
782             Logs.warn("Building without Active Directory support.")
783
784
785     if Options.options.with_utmp:
786         conf.env.with_utmp = True
787         if not conf.CHECK_HEADERS('utmp.h'): conf.env.with_utmp = False
788         conf.CHECK_FUNCS('pututline pututxline updwtmp updwtmpx getutmpx getutxent')
789         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_name', headers='utmp.h',
790                                     define='HAVE_UT_UT_NAME')
791         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_user', headers='utmp.h',
792                                     define='HAVE_UT_UT_USER')
793         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_id', headers='utmp.h',
794                                     define='HAVE_UT_UT_ID')
795         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_host', headers='utmp.h',
796                                     define='HAVE_UT_UT_HOST')
797         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_time', headers='utmp.h',
798                                     define='HAVE_UT_UT_TIME')
799         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_tv', headers='utmp.h',
800                                     define='HAVE_UT_UT_TV')
801         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_type', headers='utmp.h',
802                                     define='HAVE_UT_UT_TYPE')
803         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_pid', headers='utmp.h',
804                                     define='HAVE_UT_UT_PID')
805         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_exit.e_exit', headers='utmp.h',
806                                     define='HAVE_UT_UT_EXIT')
807         conf.CHECK_STRUCTURE_MEMBER('struct utmpx', 'ut_syslen', headers='utmpx.h',
808                                     define='HAVE_UX_UT_SYSLEN')
809         conf.CHECK_CODE('struct utmp utarg; struct utmp *utreturn; utreturn = pututline(&utarg);',
810                         'PUTUTLINE_RETURNS_UTMP', headers='utmp.h',
811                         msg="Checking whether pututline returns pointer")
812         conf.CHECK_SIZEOF(['((struct utmp *)NULL)->ut_line'], headers='utmp.h',
813                           define='SIZEOF_UTMP_UT_LINE', critical=False)
814         if not conf.CONFIG_SET('SIZEOF_UTMP_UT_LINE'):
815             conf.env.with_utmp = False
816         elif int(conf.env.SIZEOF_UTMP_UT_LINE) < 15:
817             conf.env.with_utmp = False
818         if conf.env.with_utmp:
819             conf.DEFINE('WITH_UTMP', 1)
820         else:
821             Logs.warn("--with-utmp but utmp support not sufficient")
822
823     if Options.options.with_avahi:
824         conf.env.with_avahi = True
825         if not conf.CHECK_HEADERS('avahi-common/watch.h avahi-client/client.h'): conf.env.with_avahi = False
826         if not conf.CHECK_FUNCS_IN('avahi_client_new', 'avahi-client'): conf.env.with_avahi = False
827         if not conf.CHECK_FUNCS_IN('avahi_strerror', 'avahi-common'): conf.env.with_avahi = False
828         if conf.env.with_avahi:
829             conf.DEFINE('WITH_AVAHI_SUPPORT', 1)
830     else:
831         conf.SET_TARGET_TYPE('avahi-common', 'EMPTY')
832         conf.SET_TARGET_TYPE('avahi-client', 'EMPTY')
833
834     if Options.options.with_iconv:
835         conf.env.with_iconv = True
836         if not conf.CHECK_FUNCS_IN('iconv_open', 'iconv', headers='iconv.h'):
837             conf.env.with_iconv = False
838         if conf.env.with_iconv:
839             conf.DEFINE('HAVE_ICONV', 1)
840
841     if Options.options.with_pam:
842         use_pam=True
843         conf.CHECK_HEADERS('security/pam_appl.h pam/pam_appl.h')
844         if not conf.CONFIG_SET('HAVE_SECURITY_PAM_APPL_H') and not conf.CONFIG_SET('HAVE_PAM_PAM_APPL_H'):
845             Logs.warn("--with-pam=yes but pam_appl.h not found")
846             use_pam=False
847         conf.CHECK_FUNCS_IN('pam_get_data', 'pam')
848         conf.CHECK_HEADERS('security/pam_modules.h pam/pam_modules.h')
849         if not conf.CONFIG_SET('HAVE_SECURITY_PAM_MODULES_H') and not conf.CONFIG_SET('HAVE_PAM_PAM_MODULES_H'):
850             Logs.warn("--with-pam=yes but pam_modules.h not found")
851             use_pam=False
852         conf.CHECK_HEADERS('security/pam_ext.h security/_pam_macros.h')
853         conf.CHECK_HEADERS('pam/pam_ext.h pam/_pam_macros.h')
854         conf.CHECK_FUNCS_IN('pam_vsyslog', 'pam')
855         conf.CHECK_CODE('''
856 #if defined(HAVE_SECURITY_PAM_APPL_H)
857 #include <security/pam_appl.h>
858 #elif defined(HAVE_PAM_PAM_APPL_H)
859 #include <pam/pam_appl.h>
860 #endif
861 pam_set_item(0, PAM_RHOST, 0);
862 ''',
863             'HAVE_PAM_RHOST',
864             lib='pam',
865             msg="Checking whether PAM_RHOST is available");
866         conf.CHECK_CODE('''
867 #if defined(HAVE_SECURITY_PAM_APPL_H)
868 #include <security/pam_appl.h>
869 #elif defined(HAVE_PAM_PAM_APPL_H)
870 #include <pam/pam_appl.h>
871 #endif
872 pam_set_item(0, PAM_TTY, 0);
873 ''',
874             'HAVE_PAM_TTY',
875             lib='pam',
876             msg="Checking whether PAM_TTY is available");
877         conf.CHECK_CODE('''
878 #if (!defined(LINUX))
879
880 #define PAM_EXTERN extern
881 #if defined(HAVE_SECURITY_PAM_APPL_H)
882 #include <security/pam_appl.h>
883 #elif defined(HAVE_PAM_PAM_APPL_H)
884 #include <pam/pam_appl.h>
885 #endif
886
887 #endif
888
889 #if defined(HAVE_SECURITY_PAM_MODULES_H)
890 #include <security/pam_modules.h>
891 #elif defined(HAVE_PAM_PAM_MODULES_H)
892 #include <pam/pam_modules.h>
893 #endif
894
895 #if defined(HAVE_SECURITY__PAM_MACROS_H)
896 #include <security/_pam_macros.h>
897 #elif defined(HAVE_PAM__PAM_MACROS_H)
898 #include <pam/_pam_macros.h>
899 #endif
900
901 #ifdef HAVE_SECURITY_PAM_EXT_H
902 #include <security/pam_ext.h>
903 #endif
904
905 int i; i = PAM_RADIO_TYPE;
906 ''',
907             'HAVE_PAM_RADIO_TYPE',
908             lib='pam',
909             msg="Checking whether PAM_RADIO_TYPE is available");
910         if use_pam:
911             conf.DEFINE('WITH_PAM', 1)
912             conf.DEFINE('WITH_PAM_MODULES', 1)
913         else:
914             conf.fatal("PAM support is enabled but prerequisite libraries "
915                        "or headers not found. Use --without-pam to disable "
916                        "PAM support.");
917
918     seteuid = False
919
920 #
921 # Ensure we select the correct set of system calls on Linux.
922 #
923     if (host_os.rfind('linux') > -1):
924         conf.CHECK_CODE('''
925 #if defined(HAVE_UNISTD_H)
926 #include <unistd.h>
927 #endif
928 #include <stdlib.h>
929 #include <stdio.h>
930 #include <sys/types.h>
931 #include <errno.h>
932
933 #ifdef HAVE_SYS_PRIV_H
934 #include <sys/priv.h>
935 #endif
936 #ifdef HAVE_SYS_ID_H
937 #include <sys/id.h>
938 #endif
939
940 #if defined(HAVE_SYSCALL_H)
941 #include <syscall.h>
942 #endif
943
944 #if defined(HAVE_SYS_SYSCALL_H)
945 #include <sys/syscall.h>
946 #endif
947
948 syscall(SYS_setresuid32, -1, -1, -1);
949 syscall(SYS_setresgid32, -1, -1, -1);
950 syscall(SYS_setreuid32, -1, -1);
951 syscall(SYS_setregid32, -1, -1);
952 syscall(SYS_setuid32, -1);
953 syscall(SYS_setgid32, -1);
954 syscall(SYS_setgroups32, 0, NULL);
955 ''',
956             'USE_LINUX_32BIT_SYSCALLS',
957             msg="Checking whether Linux should use 32-bit credential calls");
958
959         if (conf.CONFIG_SET('USE_LINUX_32BIT_SYSCALLS')):
960             seteuid = conf.CHECK_CODE('''
961                                 #define AUTOCONF_TEST 1
962                                 #define HAVE_LINUX_THREAD_CREDENTIALS 1
963                                 #define USE_LINUX_32BIT_SYSCALLS 1
964                                 #include "../lib/util/setid.c"
965                                 #include "./lib/util_sec.c"
966                                 ''',
967                                 'HAVE_LINUX_THREAD_CREDENTIALS',
968                                 addmain=False,
969                                 execute=True,
970                                 msg="Checking whether we can use Linux thread-specific credentials with 32-bit system calls")
971         else:
972             seteuid = conf.CHECK_CODE('''
973                                 #define AUTOCONF_TEST 1
974                                 #define HAVE_LINUX_THREAD_CREDENTIALS 1
975                                 #include "../lib/util/setid.c"
976                                 #include "./lib/util_sec.c"
977                                 ''',
978                                 'HAVE_LINUX_THREAD_CREDENTIALS',
979                                 addmain=False,
980                                 execute=True,
981                                 msg="Checking whether we can use Linux thread-specific credentials")
982     if not seteuid:
983         seteuid = conf.CHECK_CODE('''
984                                 #define AUTOCONF_TEST 1
985                                 #define USE_SETREUID 1
986                                 #include "../lib/util/setid.c"
987                                 #include "./lib/util_sec.c"
988                                 ''',
989                                 'USE_SETREUID',
990                                 addmain=False,
991                                 execute=True,
992                                 msg="Checking whether setreuid is available")
993     if not seteuid:
994         seteuid = conf.CHECK_CODE('''
995                                 #define AUTOCONF_TEST 1
996                                 #define USE_SETRESUID 1
997                                 #include "../lib/util/setid.c"
998                                 #include "./lib/util_sec.c"
999                                 ''',
1000                                 'USE_SETRESUID',
1001                                 addmain=False,
1002                                 execute=True,
1003                                 msg="Checking whether setresuid is available")
1004     if not seteuid:
1005         seteuid = conf.CHECK_CODE('''
1006                                 #define AUTOCONF_TEST 1
1007                                 #define USE_SETEUID 1
1008                                 #include "../lib/util/setid.c"
1009                                 #include "./lib/util_sec.c"
1010                                 ''',
1011                                 'USE_SETEUID',
1012                                 addmain=False,
1013                                 execute=True,
1014                                 msg="Checking whether seteuid is available")
1015     if not seteuid:
1016         seteuid = conf.CHECK_CODE('''
1017                                 #define AUTOCONF_TEST 1
1018                                 #define USE_SETUIDX 1
1019                                 #include "../lib/util/setid.c"
1020                                 #include "./lib/util_sec.c"
1021                                 ''',
1022                                 'USE_SETUIDX',
1023                                 addmain=False,
1024                                 execute=True,
1025                                 mandatory=True,
1026                                 msg="Checking whether setuidx is available")
1027     if Options.options.with_dnsupdate:
1028         if not conf.CONFIG_SET('HAVE_KRB5'):
1029             Logs.warn("--with-dnsupdate=yes but gssapi support not sufficient")
1030         else:
1031             conf.DEFINE('WITH_DNS_UPDATES', 1)
1032     # valgrind.h or valgrind/valgrind.h is checked in lib/replace/wscript
1033     if Options.options.developer:
1034         if conf.CONFIG_SET('HAVE_VALGRIND_H') or conf.CONFIG_SET('HAVE_VALGRIND_VALGRIND_H'):
1035             conf.DEFINE('VALGRIND', '1')
1036
1037     if conf.CHECK_CODE('''
1038 #include <bits/sockaddr.h>
1039 #include <linux/netlink.h>
1040 ''',
1041                 'HAVE_LINUX_NETLINK_H',
1042                 msg="Checking whether Linux netlink is available"):
1043
1044         conf.CHECK_CODE('''
1045 #include <bits/sockaddr.h>
1046 #include <linux/netlink.h>
1047 #include <linux/rtnetlink.h>
1048 ''',
1049                 'HAVE_LINUX_RTNETLINK_H',
1050                 msg='Checking whether Linux rtnetlink is available')
1051
1052     conf.CHECK_CODE('''
1053 #include "../tests/fcntl_lock.c"
1054 ''',
1055                 'HAVE_FCNTL_LOCK',
1056                 addmain=False,
1057                 execute=True,
1058                 msg='Checking whether fcntl locking is available')
1059
1060     conf.CHECK_CODE('''
1061 #include <unistd.h>
1062 #include <sys/types.h>
1063 #include <sys/stat.h>
1064 #include <fcntl.h>
1065 #include <errno.h>
1066
1067 #define DATA "ofdtest.fcntl"
1068
1069 int main() {
1070         struct flock lck = {
1071            .l_whence = SEEK_SET,
1072            .l_type = F_WRLCK,
1073            .l_start = 0,
1074            .l_len = 1,
1075            .l_pid = 0,
1076         };
1077         int ret;
1078         int fd1;
1079         int fd2;
1080         char *testdir = getenv("TESTDIR");
1081
1082         if (testdir) {
1083            if (chdir(testdir) != 0) {
1084               goto err;
1085            }
1086         }
1087
1088         unlink(DATA);
1089         fd1 = open(DATA, O_RDWR|O_CREAT|O_EXCL, 0600);
1090         fd2 = open(DATA, O_RDWR);
1091         if (fd1 == -1 || fd2 == -1) {
1092            goto err;
1093         }
1094         ret = fcntl(fd1,F_OFD_SETLKW,&lck);
1095         if (ret == -1) {
1096           goto err;
1097         }
1098         ret = fcntl(fd2,F_OFD_SETLK,&lck);
1099         if (ret != -1) {
1100           goto err;
1101         }
1102         if (errno != EAGAIN) {
1103           goto err;
1104         }
1105         ret = fcntl(fd2,F_OFD_GETLK,&lck);
1106         if (ret == -1) {
1107           goto err;
1108         }
1109         unlink(DATA);
1110         exit(0);
1111 err:
1112         unlink(DATA);
1113         exit(1);
1114 }''',
1115             'HAVE_OFD_LOCKS',
1116             addmain=False,
1117             execute=True,
1118             msg="Checking whether fcntl lock supports open file description locks")
1119
1120     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_mtim.tv_nsec',
1121                                 define='HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC') # Linux, Solaris
1122     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_mtimensec',
1123                                 define='HAVE_STRUCT_STAT_ST_MTIMENSEC') # BSD, if defined _POSIX_SOURCE
1124     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_mtimespec.tv_nsec',
1125                                 define='HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC') # BSD, if not defined _POSIX_SOURCE
1126     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_mtime_n',
1127                                 define='HAVE_STRUCT_STAT_ST_MTIME_N') # AIX
1128     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_umtime',
1129                                 define='HAVE_STRUCT_STAT_ST_UMTIME') # Tru64
1130     if conf.CONFIG_SET('HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC') or \
1131        conf.CONFIG_SET('HAVE_STRUCT_STAT_ST_MTIMENSEC') or \
1132        conf.CONFIG_SET('HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC') or \
1133        conf.CONFIG_SET('HAVE_STRUCT_STAT_ST_MTIME_N') or \
1134        conf.CONFIG_SET('HAVE_STRUCT_STAT_ST_UMTIME'):
1135         conf.DEFINE('HAVE_STAT_HIRES_TIMESTAMPS', '1')
1136
1137     # recent FreeBSD, NetBSD have creation timestamps called birthtime:
1138     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_birthtime',
1139                                 define='HAVE_STRUCT_STAT_ST_BIRTHTIME')
1140     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_birthtimespec.tv_nsec',
1141                                 define='HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC')
1142     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_birthtimensec',
1143                                 define='HAVE_STRUCT_STAT_ST_BIRTHTIMENSEC')
1144
1145     conf.CHECK_CODE('''
1146 ssize_t err = posix_fadvise(0,0,0x80000,POSIX_FADV_WILLNEED);
1147 ''',
1148                 'HAVE_POSIX_FADVISE',
1149                 msg='Checking whether posix_fadvise is available',
1150                 headers='unistd.h fcntl.h')
1151
1152     for v in ['_SC_NGROUPS_MAX', '_SC_NPROC_ONLN', '_SC_NPROCESSORS_ONLN', '_SC_PAGESIZE' ]:
1153         conf.CHECK_CODE('''
1154                         #include <unistd.h>
1155                         return sysconf(%s) == -1 ? 1 : 0;
1156                         ''' % v,
1157                         'SYSCONF%s' % v,
1158                         msg='Checking whether sysconf(%s) is available' % v)
1159
1160     conf.CHECK_CODE('''
1161 #include <sys/syscall.h>
1162 #include <unistd.h>
1163 syscall(SYS_initgroups, 16, NULL, NULL, 0);
1164                     ''',
1165                     'HAVE_DARWIN_INITGROUPS',
1166                     msg='Checking whether to use the Darwin-specific initgroups system call')
1167
1168     conf.CHECK_CODE('''struct utimbuf tbuf;  tbuf.actime = 0; tbuf.modtime = 1; exit(utime("foo.c",&tbuf));''',
1169                     'HAVE_UTIMBUF',
1170                     headers='sys/types.h utime.h',
1171                     msg='Checking whether struct utimbuf is available')
1172
1173     if conf.CHECK_CODE('''struct sigevent s;''',
1174                     'HAVE_STRUCT_SIGEVENT',
1175                     headers='sys/types.h stdlib.h stddef.h signal.h',
1176                     msg='Checking whether we have the struct sigevent'):
1177         conf.CHECK_STRUCTURE_MEMBER('struct sigevent', 'sigev_value.sival_ptr',
1178                                     define='HAVE_STRUCT_SIGEVENT_SIGEV_VALUE_SIVAL_PTR',
1179                                     headers='signal.h');
1180         conf.CHECK_STRUCTURE_MEMBER('struct sigevent', 'sigev_value.sigval_ptr',
1181                                     define='HAVE_STRUCT_SIGEVENT_SIGEV_VALUE_SIGVAL_PTR',
1182                                     headers='signal.h');
1183
1184     if os.path.exists('/proc/sys/kernel/core_pattern'):
1185         conf.DEFINE('HAVE_SYS_KERNEL_PROC_CORE_PATTERN', '1')
1186
1187     if conf.CHECK_CODE('''
1188 #include <time.h>
1189 main() {
1190         struct tm *tm;
1191         if (sizeof(time_t) == 8) {
1192                 time_t max_time = 0x7fffffffffffffffll;
1193                 tm = gmtime(&max_time);
1194                 /* This should fail with 32-bit tm_year. */
1195                 if (tm == NULL) {
1196                         /* Max time_t that works with 32-bit int tm_year in struct tm. */
1197                         max_time = 67768036191676799ll;
1198                         tm = gmtime(&max_time);
1199                         if (tm) {
1200                                 exit(0);
1201                         }
1202                 }
1203         }
1204         exit(1);
1205 }''',
1206         '__TIME_T_MAX',
1207         addmain=False,
1208         execute=True,
1209         msg="Checking for the maximum value of the 'time_t' type"):
1210             conf.DEFINE('TIME_T_MAX', '67768036191676799ll')
1211
1212     conf.CHECK_CODE('''
1213 #if defined(HAVE_UNISTD_H)
1214 #include <unistd.h>
1215 #endif
1216 #include <sys/types.h>
1217 main() { dev_t dev = makedev(1,2); return 0; }
1218 ''',
1219         'HAVE_MAKEDEV',
1220         addmain=False,
1221         msg='Checking whether the macro for makedev is available')
1222
1223     conf.CHECK_CODE('''
1224 #include <stdio.h>
1225 #include <limits.h>
1226 #include <signal.h>
1227
1228 void exit_on_core(int ignored) {
1229         exit(1);
1230 }
1231
1232 main() {
1233         char *newpath;
1234         signal(SIGSEGV, exit_on_core);
1235         newpath = realpath("/tmp", NULL);
1236         exit((newpath != NULL) ? 0 : 1);
1237 }
1238 ''',
1239         'REALPATH_TAKES_NULL',
1240         addmain=False,
1241         execute=True,
1242         msg='Checking whether the realpath function allows a NULL argument')
1243
1244     conf.CHECK_CODE('''#include "../tests/ftruncate.c"''',
1245                     'HAVE_FTRUNCATE_EXTEND',
1246                     msg='Checking for ftruncate extend',
1247                     addmain=False,
1248                     execute=True)
1249
1250     if Options.options.with_sendfile_support:
1251         if (host_os.rfind('linux') > -1) or (host_os.rfind('gnu') > -1) or (host_os.rfind('k*bsd*-gnu') > -1) or (host_os.rfind('kopensolaris*-gnu') > -1):
1252             conf.CHECK_CODE('''
1253                             int tofd, fromfd;
1254                             off_t offset;
1255                             size_t total;
1256                             ssize_t nwritten = sendfile(tofd, fromfd, &offset, total);
1257                             ''',
1258                             '_HAVE_SENDFILE',
1259                             headers='sys/sendfile.h',
1260                             msg='Checking for linux sendfile support')
1261
1262             if conf.CONFIG_SET('_HAVE_SENDFILE'):
1263                 conf.DEFINE('HAVE_SENDFILE', '1')
1264                 conf.DEFINE('LINUX_SENDFILE_API', '1')
1265                 conf.DEFINE('WITH_SENDFILE', '1')
1266         elif (host_os.rfind('freebsd') > -1) or (host_os.rfind('dragonfly') > -1):
1267             conf.CHECK_CODE('''
1268                             #include <sys/types.h>
1269                             #include <unistd.h>
1270                             #include <sys/socket.h>
1271                             #include <sys/uio.h>
1272                             int fromfd, tofd, ret, total=0;
1273                             off_t offset, nwritten;
1274                             struct sf_hdtr hdr;
1275                             struct iovec hdtrl;
1276                             hdr.headers = &hdtrl;
1277                             hdr.hdr_cnt = 1;
1278                             hdr.trailers = NULL;
1279                             hdr.trl_cnt = 0;
1280                             hdtrl.iov_base = NULL;
1281                             hdtrl.iov_len = 0;
1282                             ret = sendfile(fromfd, tofd, offset, total, &hdr, &nwritten, 0)
1283                             ''',
1284                             '_HAVE_SENDFILE',
1285                             msg='Checking for freebsd sendfile support')
1286             if conf.CONFIG_SET('_HAVE_SENDFILE'):
1287                 conf.DEFINE('HAVE_SENDFILE', '1')
1288                 conf.DEFINE('FREEBSD_SENDFILE_API', '1')
1289                 conf.DEFINE('WITH_SENDFILE', '1')
1290         elif (host_os.rfind('darwin') > -1):
1291             conf.CHECK_CODE('''
1292                             #include <sys/types.h>
1293                             #include <sys/socket.h>
1294                             #include <sys/uio.h>
1295                             int fromfd, tofd, ret;
1296                             off_t offset, nwritten;
1297                             struct sf_hdtr hdr;
1298                             struct iovec hdtrl;
1299                             hdr.headers = &hdtrl;
1300                             hdr.hdr_cnt = 1;
1301                             hdr.trailers = (void *)0;
1302                             hdr.trl_cnt = 0;
1303                             hdtrl.iov_base = (void *)0;
1304                             hdtrl.iov_len = 0;
1305                             ret = sendfile(fromfd, tofd, offset, &nwritten, &hdr, 0);
1306                             ''',
1307                             '_HAVE_SENDFILE',
1308                             msg='Checking for darwin sendfile support')
1309             if conf.CONFIG_SET('_HAVE_SENDFILE'):
1310                 conf.DEFINE('HAVE_SENDFILE', '1')
1311                 conf.DEFINE('DARWIN_SENDFILE_API', '1')
1312                 conf.DEFINE('WITH_SENDFILE', '1')
1313         elif (host_os.rfind('hpux') > -1) or (host_os.rfind('osf') > -1):
1314             conf.CHECK_CODE('''
1315                             #include <sys/socket.h>
1316                             #include <sys/uio.h>
1317                             int fromfd, tofd;
1318                             size_t total=0;
1319                             struct iovec hdtrl[2];
1320                             ssize_t nwritten;
1321                             off_t offset;
1322                             hdtrl[0].iov_base = 0;
1323                             hdtrl[0].iov_len = 0;
1324                             nwritten = sendfile(tofd, fromfd, offset, total, &hdtrl[0], 0);
1325                             ''',
1326                             '_HAVE_SENDFILE',
1327                             msg='Checking for osf/hpux sendfile support')
1328             if conf.CONFIG_SET('_HAVE_SENDFILE'):
1329                 conf.DEFINE('HAVE_SENDFILE', '1')
1330                 conf.DEFINE('HPUX_SENDFILE_API', '1')
1331                 conf.DEFINE('WITH_SENDFILE', '1')
1332         elif (host_os.rfind('solaris') > -1):
1333             conf.CHECK_FUNCS_IN('sendfile', 'sendfilev')
1334             conf.CHECK_CODE('''
1335                             #include <sys/sendfile.h>,
1336                             int sfvcnt;
1337                             size_t xferred;
1338                             struct sendfilevec vec[2];
1339                             ssize_t nwritten;
1340                             int tofd;
1341                             sfvcnt = 2;
1342                             vec[0].sfv_fd = SFV_FD_SELF;
1343                             vec[0].sfv_flag = 0;
1344                             vec[0].sfv_off = 0;
1345                             vec[0].sfv_len = 0;
1346                             vec[1].sfv_fd = 0;
1347                             vec[1].sfv_flag = 0;
1348                             vec[1].sfv_off = 0;
1349                             vec[1].sfv_len = 0;
1350                             nwritten = sendfilev(tofd, vec, sfvcnt, &xferred);
1351                             ''',
1352                             '_HAVE_SENDFILEV',
1353                             msg='Checking for solaris sendfilev support')
1354             if conf.CONFIG_SET('_HAVE_SENDFILEV'):
1355                 conf.DEFINE('HAVE_SENDFILEV', '1')
1356                 conf.DEFINE('SOLARIS_SENDFILE_API', '1')
1357                 conf.DEFINE('WITH_SENDFILE', '1')
1358         elif (host_os.rfind('aix') > -1):
1359             conf.CHECK_CODE('''
1360                             #include <sys/socket.h>
1361                             int fromfd, tofd;
1362                             size_t total=0;
1363                             struct sf_parms hdtrl;
1364                             ssize_t nwritten;
1365                             hdtrl.header_data = 0;
1366                             hdtrl.header_length = 0;
1367                             hdtrl.file_descriptor = fromfd;
1368                             hdtrl.file_offset = 0;
1369                             hdtrl.file_bytes = 0;
1370                             hdtrl.trailer_data = 0;
1371                             hdtrl.trailer_length = 0;
1372                             nwritten = send_file(&tofd, &hdtrl, 0);
1373                             ''',
1374                             '_HAVE_SENDFILE',
1375                             msg='Checking for AIX send_file support')
1376             if conf.CONFIG_SET('_HAVE_SENDFILE'):
1377                 conf.DEFINE('HAVE_SENDFILE', '1')
1378                 conf.DEFINE('AIX_SENDFILE_API', '1')
1379                 conf.DEFINE('WITH_SENDFILE', '1')
1380
1381     # Check for getcwd allowing a NULL arg.
1382     conf.CHECK_CODE('''
1383 #include <unistd.h>
1384 main() {
1385         char *s = getcwd(NULL,0);
1386         exit(s != NULL ?  0 : 1);
1387 }''', 'GETCWD_TAKES_NULL', addmain=False, execute=True,
1388         msg="getcwd takes a NULL argument")
1389
1390
1391     # UnixWare 7.x has its getspnam in -lgen
1392     conf.CHECK_FUNCS_IN('getspnam', 'gen')
1393     conf.CHECK_FUNCS_IN('getspnam', 'security')
1394     conf.CHECK_FUNCS_IN('getspnam', 'sec')
1395
1396     legacy_quota_libs = ''
1397     if Options.options.with_quotas:
1398         # For quotas on Veritas VxFS filesystems
1399         conf.CHECK_HEADERS('sys/fs/vx_quota.h')
1400         # For sys/quota.h and linux/quota.h
1401         conf.CHECK_HEADERS('sys/quota.h')
1402         # For quotas on BSD systems
1403         conf.CHECK_HEADERS('ufs/ufs/quota.h')
1404         # For quotas on Linux XFS filesystems
1405         if conf.CHECK_HEADERS('xfs/xqm.h'):
1406             conf.DEFINE('HAVE_XFS_QUOTAS', '1')
1407         else:
1408             # For Irix XFS
1409             conf.CHECK_CODE('''
1410                 #include "confdefs.h"
1411                 #ifdef HAVE_SYS_TYPES_H
1412                 #include <sys/types.h>
1413                 #endif
1414                 #ifdef HAVE_ASM_TYPES_H
1415                 #include <asm/types.h>
1416                 #endif
1417                 #include <sys/quota.h>
1418                 int i = Q_XGETQUOTA;''',
1419                 define='HAVE_XFS_QUOTAS',
1420                 msg='for XFS QUOTA in <sys/quota.h>',
1421                 execute=False,
1422                 local_include=False)
1423
1424         # For IRIX like dqb_isoftlimit instead of dqb_fsoftlimit in struc dqblk
1425         conf.CHECK_STRUCTURE_MEMBER('struct dqblk', 'dqb_fsoftlimit', define='HAVE_DQB_FSOFTLIMIT',
1426                                 headers='sys/quota.h')
1427         #darwin style quota bytecount
1428         conf.CHECK_STRUCTURE_MEMBER('struct dqblk', 'dqb_curbytes', define='HAVE_STRUCT_DQBLK_DQB_CURBYTES',
1429                                 headers='sys/quota.h')
1430         if conf.CHECK_HEADERS('rpcsvc/rquota.h', lib='tirpc'):
1431             # Optional structure member
1432             conf.CHECK_STRUCTURE_MEMBER('struct getquota_rslt', 'getquota_rslt_u',
1433                                         define='HAVE_GETQUOTA_RSLT_GETQUOTA_RSLT_U',
1434                                         headers='rpcsvc/rquota.h',
1435                                         lib='tirpc')
1436
1437             # Required fucntion for NFS quote support
1438             conf.CHECK_CODE('''
1439                             clnt_create("", RQUOTAPROG, RQUOTAVERS, "udp");
1440                             ''',
1441                             headers="rpc/rpc.h rpc/types.h rpcsvc/rquota.h rpc/nettype.h rpc/xdr.h",
1442                             define='HAVE_NFS_QUOTAS',
1443                             msg='checking for clnt_create()',
1444                             execute=True,
1445                             local_include=False,
1446                             lib='tirpc')
1447
1448         if (host_os.rfind('linux') > -1):
1449             conf.DEFINE('HAVE_QUOTACTL_LINUX', '1')
1450         elif not conf.CONFIG_SET("HAVE_XFS_QUOTAS"):
1451             if not conf.CHECK_CODE('''
1452                 #define HAVE_QUOTACTL_4A 1
1453                 #define AUTOCONF_TEST 1
1454                 #include "../tests/sysquotas.c"
1455                 ''',
1456                                    cflags=conf.env['WERROR_CFLAGS'],
1457                                    define='HAVE_QUOTACTL_4A',
1458                                    msg='for QUOTACTL_4A: long quotactl(int cmd, char *special, qid_t id, caddr_t addr)',
1459                                    execute=True,
1460                                    addmain=False):
1461
1462                 conf.CHECK_CODE('''
1463                 #define HAVE_QUOTACTL_4B 1
1464                 #define AUTOCONF_TEST 1
1465                 #include "../tests/sysquotas.c"
1466                 ''',
1467                                 cflags=conf.env['WERROR_CFLAGS'],
1468                                 define='HAVE_QUOTACTL_4B',
1469                                 msg='for QUOTACTL_4B:  int quotactl(const char *path, int cmd, int id, char *addr)',
1470                                 execute=True,
1471                                 addmain=False)
1472
1473         if conf.CONFIG_SET('HAVE_QUOTACTL_LINUX') or \
1474            conf.CONFIG_SET('HAVE_QUOTACTL_4A') or \
1475            conf.CONFIG_SET('HAVE_QUOTACTL_4B') or \
1476            conf.CONFIG_SET('HAVE_XFS_QUOTAS'):
1477             conf.DEFINE('HAVE_SYS_QUOTAS', '1')
1478             conf.DEFINE('WITH_QUOTAS', '1')
1479
1480         #
1481         # check if Legacy quota code can be brought in
1482         # if standard interfaces are not supported
1483         #
1484         if not conf.CONFIG_SET('WITH_QUOTAS'):
1485             if host_os.rfind('sunos5') > -1:
1486                 conf.DEFINE('SUNOS5', '1')
1487                 legacy_quota_libs = 'nsl'
1488             conf.CHECK_CODE('''
1489             #define WITH_QUOTAS 1
1490             #define AUTOCONF_TEST 1
1491             #include "../tests/oldquotas.c"
1492             ''',
1493                             cflags=conf.env['WERROR_CFLAGS'],
1494                             define='WITH_QUOTAS',
1495                             lib=legacy_quota_libs,
1496                             msg='Checking whether legacy quota code can be used',
1497                             execute=False,
1498                             addmain=False)
1499             if not conf.CONFIG_SET('WITH_QUOTAS'):
1500                 legacy_quota_libs = ''
1501     conf.env['legacy_quota_libs'] = legacy_quota_libs
1502
1503     conf.CHECK_CODE('(void)unshare(CLONE_FS);',
1504                     headers='sched.h',
1505                     define='HAVE_UNSHARE_CLONE_FS',
1506                     msg='for Linux unshare(CLONE_FS)')
1507
1508     #
1509     # cluster support (CTDB)
1510     #
1511     if not Options.options.with_cluster_support:
1512         Logs.info("building without cluster support (--without-cluster-support)")
1513         conf.env.with_ctdb = False
1514     else:
1515         Logs.info("building with cluster support")
1516         conf.env.with_ctdb = True
1517         conf.DEFINE('CLUSTER_SUPPORT', 1)
1518
1519     conf.CHECK_CODE('void seekdir(DIR *d, long loc) { return; }',
1520                     'SEEKDIR_RETURNS_VOID',
1521                     headers='sys/types.h dirent.h',
1522                     msg='Checking whether seekdir returns void')
1523
1524     if Options.options.with_profiling_data:
1525         conf.DEFINE('WITH_PROFILE', 1);
1526         conf.CHECK_FUNCS('getrusage', headers="sys/time.h sys/resource.h")
1527
1528     if (conf.CHECK_HEADERS('linux/ioctl.h sys/ioctl.h linux/fs.h') and
1529         conf.CHECK_DECLS('FS_IOC_GETFLAGS FS_COMPR_FL', headers='linux/fs.h')):
1530             conf.DEFINE('HAVE_LINUX_IOCTL', '1')
1531
1532     conf.env['CCFLAGS_CEPHFS'] = "-D_FILE_OFFSET_BITS=64"
1533     if Options.options.libcephfs_dir:
1534         conf.env['CPPPATH_CEPHFS'] = Options.options.libcephfs_dir + '/include'
1535         conf.env['LIBPATH_CEPHFS'] = Options.options.libcephfs_dir + '/lib'
1536         conf.env['LIBPATH_CEPH-COMMON'] = Options.options.libcephfs_dir + '/lib/ceph'
1537     else:
1538         conf.env['LIBPATH_CEPH-COMMON'] = Options.options.LIBDIR + '/ceph'
1539
1540     if (Options.options.with_cephfs and
1541         conf.CHECK_HEADERS('cephfs/libcephfs.h', False, False, 'cephfs') and
1542         conf.CHECK_LIB('cephfs', shlib=True)):
1543         conf.CHECK_LIB('ceph-common', shlib=True)
1544         if Options.options.with_acl_support:
1545             conf.DEFINE('HAVE_CEPH', '1')
1546             if conf.CHECK_FUNCS_IN('ceph_statx', 'cephfs ceph-common',
1547                                    headers='cephfs/libcephfs.h'):
1548                 conf.DEFINE('HAVE_CEPH_STATX', '1')
1549         else:
1550             Logs.warn("ceph support disabled due to --without-acl-support")
1551             conf.undefine('HAVE_CEPH')
1552
1553     if Options.options.with_glusterfs:
1554         conf.CHECK_CFG(package='glusterfs-api', args='"glusterfs-api >= 4" --cflags --libs',
1555                        msg='Checking for glusterfs-api >= 4', uselib_store="GFAPI")
1556         conf.CHECK_HEADERS('glusterfs/api/glfs.h', lib='gfapi')
1557         conf.CHECK_LIB('gfapi', shlib=True)
1558
1559         if conf.CONFIG_SET('HAVE_GLUSTERFS_API_GLFS_H'):
1560             if Options.options.with_acl_support:
1561                  conf.DEFINE('HAVE_GLUSTERFS', '1')
1562             else:
1563                 Logs.warn("GlusterFS support disabled due to --without-acl-support")
1564                 conf.undefine('HAVE_GLUSTERFS')
1565         else:
1566             conf.undefine('HAVE_GLUSTERFS')
1567
1568         conf.CHECK_CFG(package='glusterfs-api', args='"glusterfs-api >= 6" --cflags --libs',
1569                        msg='Checking for glusterfs-api >= 6',
1570                        uselib_store="GFAPI_VER_6")
1571     else:
1572         conf.SET_TARGET_TYPE('gfapi', 'EMPTY')
1573         conf.undefine('HAVE_GLUSTERFS')
1574
1575     if Options.options.enable_vxfs:
1576         conf.DEFINE('HAVE_VXFS', '1')
1577
1578     if conf.CHECK_CFG(package='dbus-1', args='--cflags --libs',
1579                       msg='Checking for dbus', uselib_store="DBUS-1"):
1580         if (conf.CHECK_HEADERS('dbus/dbus.h', lib='dbus-1')
1581                                       and conf.CHECK_LIB('dbus-1', shlib=True)):
1582             conf.DEFINE('HAVE_DBUS', '1')
1583
1584     conf.env.build_regedit = False
1585     if not Options.options.with_regedit == False:
1586         conf.PROCESS_SEPARATE_RULE('system_ncurses')
1587         if conf.CONFIG_SET('HAVE_NCURSES'):
1588             conf.env.build_regedit = True
1589
1590     if conf.env.build_regedit:
1591         Logs.info("building regedit")
1592     else:
1593         if Options.options.with_regedit == False:
1594             Logs.info("not building regedit (--without-regedit)")
1595         elif Options.options.with_regedit == True:
1596             Logs.error("ncurses not available, cannot build regedit")
1597             conf.fatal("ncurses not available, but --with-regedit was specified")
1598         else:
1599             Logs.info("ncurses not available, not building regedit")
1600
1601     if conf.CHECK_HEADERS('ftw.h') and conf.CHECK_FUNCS('nftw'):
1602         conf.env.build_mvxattr = True
1603
1604     conf.CHECK_FUNCS_IN('DES_pcbc_encrypt', 'crypto')
1605     if Options.options.with_fake_kaserver == True:
1606         conf.CHECK_HEADERS('afs/param.h afs/stds.h', together=True)
1607         conf.CHECK_HEADERS('afs/param.h afs/stds.h', together=True)
1608         if (conf.CONFIG_SET('HAVE_AFS_PARAM_H') and conf.CONFIG_SET('HAVE_AFS_STDS_H') and conf.CONFIG_SET('HAVE_DES_PCBC_ENCRYPT')):
1609             conf.DEFINE('WITH_FAKE_KASERVER', '1')
1610         else:
1611             conf.fatal('AFS headers not available, but --with-fake-kaserver was specified')
1612
1613     conf.env['libtracker']=''
1614     conf.env.with_spotlight = False
1615     if Options.options.with_spotlight:
1616
1617         Logs.info("Requested Spotlight support, checking for bison")
1618         bison.detect(conf)
1619         if not conf.env['BISON']:
1620             conf.fatal("Spotlight support requested but bison missing")
1621         conf.CHECK_COMMAND('%s --version | head -n1' % conf.env['BISON'], msg='Using bison version', define=None, on_target=False)
1622         Logs.info("Requested Spotlight support, checking for flex")
1623         flex.detect(conf)
1624         if not conf.env['FLEX']:
1625             conf.fatal("Spotlight support requested but flex missing")
1626         conf.CHECK_COMMAND('%s --version' % conf.env['FLEX'], msg='Using flex version', define=None, on_target=False)
1627         versions = ['2.0', '1.0', '0.16', '0.14']
1628         for version in versions:
1629             testlib = 'tracker-sparql-' + version
1630             if conf.CHECK_CFG(package=testlib,
1631                               args='--cflags --libs',
1632                               mandatory=False):
1633                 conf.SET_TARGET_TYPE(testlib, 'SYSLIB')
1634                 conf.env['libtracker'] = testlib
1635                 conf.env.with_spotlight = True
1636                 conf.DEFINE('WITH_SPOTLIGHT', '1')
1637                 break
1638
1639         if not conf.env.with_spotlight:
1640             conf.fatal("Spotlight support requested but tracker-sparql library missing")
1641         Logs.info("building with Spotlight support")
1642         default_static_modules.extend(TO_LIST('rpc_mdssvc_module'))
1643
1644     conf.CHECK_HEADERS('rpc/xdr.h', lib='tirpc')
1645
1646     forced_static_modules.extend(TO_LIST('auth_builtin auth_sam auth_winbind'))
1647     default_static_modules.extend(TO_LIST('''pdb_smbpasswd pdb_tdbsam
1648                                       auth_unix
1649                                       nss_info_template idmap_tdb idmap_passdb
1650                                       idmap_nss'''))
1651
1652     default_shared_modules.extend(TO_LIST('''
1653                                       vfs_recycle vfs_audit vfs_extd_audit vfs_full_audit vfs_netatalk
1654                                       vfs_fake_perms vfs_default_quota vfs_readonly vfs_cap
1655                                       vfs_expand_msdfs vfs_shadow_copy vfs_shadow_copy2
1656                                       vfs_readahead vfs_xattr_tdb
1657                                       vfs_streams_xattr vfs_streams_depot vfs_acl_xattr vfs_acl_tdb
1658                                       vfs_preopen vfs_catia
1659                                       vfs_media_harmony vfs_unityed_media vfs_fruit vfs_shell_snap
1660                                       vfs_commit vfs_worm vfs_crossrename vfs_linux_xfs_sgid
1661                                       vfs_time_audit vfs_offline vfs_virusfilter
1662                                   '''))
1663     default_shared_modules.extend(TO_LIST('auth_script idmap_tdb2 idmap_script'))
1664     # these have broken dependencies
1665     forced_shared_modules.extend(TO_LIST('idmap_autorid idmap_rid idmap_hash'))
1666
1667     if Options.options.developer:
1668         default_static_modules.extend(TO_LIST('charset_weird'))
1669         default_shared_modules.extend(TO_LIST('perfcount_test'))
1670         default_shared_modules.extend(TO_LIST('vfs_skel_opaque vfs_skel_transparent vfs_shadow_copy_test'))
1671         default_shared_modules.extend(TO_LIST('auth_skel pdb_test'))
1672         default_shared_modules.extend(TO_LIST('vfs_fake_dfq'))
1673         default_shared_modules.extend(TO_LIST('gpext_security gpext_registry gpext_scripts'))
1674
1675     if Options.options.enable_selftest or Options.options.developer:
1676         default_shared_modules.extend(TO_LIST('vfs_fake_acls vfs_nfs4acl_xattr'))
1677         default_shared_modules.extend(TO_LIST('vfs_error_inject'))
1678
1679     if conf.CONFIG_SET('AD_DC_BUILD_IS_ENABLED'):
1680         default_static_modules.extend(TO_LIST('pdb_samba_dsdb auth_samba4 vfs_dfs_samba4'))
1681         default_shared_modules.extend(TO_LIST('vfs_posix_eadb'))
1682
1683     if conf.CONFIG_SET('HAVE_FREEBSD_SUNACL_H'):
1684         default_shared_modules.extend(TO_LIST('vfs_zfsacl'))
1685
1686     if conf.CONFIG_SET('HAVE_DIRFD_DECL'):
1687         default_shared_modules.extend(TO_LIST('vfs_syncops vfs_dirsort'))
1688
1689     if conf.CONFIG_SET('HAVE_STATFS_F_FSID'):
1690         default_shared_modules.extend(TO_LIST('vfs_fileid'))
1691
1692     if (conf.CONFIG_SET('HAVE_STRUCT_MSGHDR_MSG_CONTROL') or conf.CONFIG_SET('HAVE_STRUCT_MSGHDR_MSG_ACCRIGHTS')):
1693         default_shared_modules.extend(TO_LIST('vfs_aio_fork'))
1694
1695     if Options.options.with_pthreadpool:
1696         default_shared_modules.extend(TO_LIST('vfs_aio_pthread'))
1697
1698     if conf.CONFIG_SET('HAVE_LDAP'):
1699         default_static_modules.extend(TO_LIST('pdb_ldapsam idmap_ldap'))
1700
1701     if conf.CONFIG_SET('DARWINOS'):
1702         default_static_modules.extend(TO_LIST('charset_macosxfs'))
1703
1704     if conf.CONFIG_SET('HAVE_GPFS'):
1705         default_shared_modules.extend(TO_LIST('vfs_gpfs'))
1706
1707     if (conf.CONFIG_SET('HAVE_LINUX_IOCTL')
1708       and conf.CONFIG_SET('HAVE_BASENAME') and conf.CONFIG_SET('HAVE_DIRNAME')):
1709         default_shared_modules.extend(TO_LIST('vfs_btrfs'))
1710
1711     if conf.CONFIG_SET("HAVE_CEPH"):
1712         default_shared_modules.extend(TO_LIST('vfs_ceph'))
1713
1714     if conf.CONFIG_SET('HAVE_GLUSTERFS'):
1715         default_shared_modules.extend(TO_LIST('vfs_glusterfs'))
1716
1717     if conf.CONFIG_SET('HAVE_VXFS'):
1718         default_shared_modules.extend(TO_LIST('vfs_vxfs'))
1719
1720     if conf.CONFIG_SET('HAVE_DBUS'):
1721         default_shared_modules.extend(TO_LIST('vfs_snapper'))
1722
1723     explicit_shared_modules = TO_LIST(Options.options.shared_modules, delimiter=',')
1724     explicit_static_modules = TO_LIST(Options.options.static_modules, delimiter=',')
1725
1726     def replace_list_item(lst, item, value):
1727         try:
1728             idx = lst.index(item)
1729             lst[idx] = value
1730         except:
1731             pass
1732     # PDB module file name should have the same name as module registers itself
1733     # In Autoconf build we export LDAP passdb module as ldapsam but WAF build
1734     # was always exporting pdb_ldap. In order to support existing packages
1735     # allow referring to pdb_ldapsam as pdb_ldap but use proper name internally.
1736     replace_list_item(explicit_shared_modules, 'pdb_ldap', 'pdb_ldapsam')
1737     replace_list_item(explicit_static_modules, 'pdb_ldap', 'pdb_ldapsam')
1738
1739     final_static_modules = []
1740     final_static_modules.extend(TO_LIST(required_static_modules))
1741     final_shared_modules = []
1742
1743     if '!FORCED' not in explicit_static_modules:
1744         final_static_modules.extend(TO_LIST(forced_static_modules))
1745     if '!FORCED' not in explicit_shared_modules:
1746         final_shared_modules.extend(TO_LIST(forced_shared_modules))
1747     if '!DEFAULT' not in explicit_static_modules:
1748         final_static_modules.extend(TO_LIST(default_static_modules))
1749     if '!DEFAULT' not in explicit_shared_modules:
1750         final_shared_modules.extend(TO_LIST(default_shared_modules))
1751
1752     if 'ALL' in explicit_static_modules:
1753         for m in default_shared_modules:
1754             if m in final_shared_modules:
1755                 final_shared_modules.remove(m)
1756             final_static_modules.append(m)
1757     if 'ALL' in explicit_shared_modules:
1758         for m in default_static_modules:
1759             if m in final_static_modules:
1760                 final_static_modules.remove(m)
1761             final_shared_modules.append(m)
1762
1763     for m in explicit_static_modules:
1764         if m in ['ALL','!DEFAULT','!FORCED']:
1765             continue
1766         if m.startswith('!'):
1767             m = m[1:]
1768             if m in required_static_modules:
1769                 raise Utils.WafError('These modules are REQUIRED as static modules: %s' %
1770                                      ' '.join(required_static_modules))
1771             if m in final_static_modules:
1772                 final_static_modules.remove(m)
1773             continue
1774         if m in forced_shared_modules:
1775             raise Utils.WafError('These modules MUST be configured as shared modules: %s' %
1776                                  ' '.join(forced_shared_modules))
1777         if m in final_shared_modules:
1778             final_shared_modules.remove(m)
1779         if m not in final_static_modules:
1780             final_static_modules.append(m)
1781     for m in explicit_shared_modules:
1782         if m in ['ALL','!DEFAULT','!FORCED']:
1783             continue
1784         if m.startswith('!'):
1785             m = m[1:]
1786             if m in final_shared_modules:
1787                 final_shared_modules.remove(m)
1788             continue
1789         if m in required_static_modules:
1790             raise Utils.WafError('These modules are REQUIRED as static modules: %s' %
1791                                  ' '.join(required_static_modules))
1792         if m in forced_static_modules:
1793             raise Utils.WafError('These module MUST be configured as static modules: %s' %
1794                                  ' '.join(forced_static_modules))
1795         if m in final_static_modules:
1796             final_static_modules.remove(m)
1797         if m not in final_shared_modules:
1798             final_shared_modules.append(m)
1799
1800     conf.env['static_modules'] = final_static_modules
1801     conf.env['shared_modules'] = final_shared_modules
1802
1803     conf.DEFINE('STRING_STATIC_MODULES', ' '.join(final_static_modules), quote=True)
1804
1805     static_list = {}
1806     shared_list = {}
1807
1808     prefixes = ['vfs', 'pdb', 'auth', 'nss_info', 'charset', 'idmap', 'gpext', 'perfcount', 'rpc']
1809     conf.env['MODULE_PREFIXES'] = prefixes
1810     for p in prefixes:
1811         for m in final_static_modules:
1812             if m.find(p) == 0:
1813                 if not p in static_list:
1814                     static_list[p] = []
1815                 static_list[p].append(m)
1816         for m in final_shared_modules:
1817             if m.find(p) == 0:
1818                 if not p in shared_list:
1819                     shared_list[p] = []
1820                 shared_list[p].append(m)
1821
1822     for p in prefixes:
1823         static_env = "%s_STATIC" % p.upper()
1824         shared_env = "%s_SHARED" % p.upper()
1825         conf.env[static_env] = []
1826         conf.env[shared_env] = []
1827         if p in static_list:
1828             decl_list=""
1829             for entry in static_list[p]:
1830                 decl_list += "extern NTSTATUS %s_init(TALLOC_CTX *mem_ctx); " % entry
1831                 conf.env[static_env].append('%s' % entry)
1832             decl_list = decl_list.rstrip()
1833             conf.DEFINE('static_decl_%s' % p, decl_list)
1834             conf.DEFINE('static_init_%s(mem_ctx)' % p, '{ %s_init((mem_ctx)); }' % '_init((mem_ctx));  '.join(static_list[p]))
1835         else:
1836             conf.DEFINE('static_decl_%s' % p, '')
1837             conf.DEFINE('static_init_%s(mem_ctx)' % p, '{}')
1838         if p in shared_list:
1839             for entry in shared_list[p]:
1840                 conf.DEFINE('%s_init' % entry, 'samba_init_module')
1841                 conf.env[shared_env].append('%s' % entry)
1842         Logs.info("%s: %s" % (static_env, ','.join(conf.env[static_env])))
1843         Logs.info("%s: %s" % (shared_env, ','.join(conf.env[shared_env])))
1844
1845     conf.SAMBA_CONFIG_H('include/config.h')