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