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