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