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