s3-waf: fix configure check for HAVE_POSIX_FADVISE.
[kai/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     opt.add_option('--enable-selftest',
25                   help=("enable options necessary for selftest"),
26                   action="store_true", dest='enable_selftest', default=False)
27
28     opt.SAMBA3_ADD_OPTION('winbind')
29     opt.SAMBA3_ADD_OPTION('swat')
30     opt.SAMBA3_ADD_OPTION('ads')
31     opt.SAMBA3_ADD_OPTION('mit-krb5-checks', default=False)
32     opt.SAMBA3_ADD_OPTION('ldap')
33     opt.SAMBA3_ADD_OPTION('cups', with_name="enable", without_name="disable")
34     opt.SAMBA3_ADD_OPTION('iprint', with_name="enable", without_name="disable")
35     opt.SAMBA3_ADD_OPTION('pam')
36     opt.SAMBA3_ADD_OPTION('pam_smbpass')
37     opt.SAMBA3_ADD_OPTION('quotas')
38     opt.SAMBA3_ADD_OPTION('sys-quotas')
39     opt.SAMBA3_ADD_OPTION('sendfile-support')
40     opt.SAMBA3_ADD_OPTION('utmp')
41     opt.SAMBA3_ADD_OPTION('pthreadpool', with_name="enable", without_name="disable")
42     opt.SAMBA3_ADD_OPTION('avahi', with_name="enable", without_name="disable")
43     opt.SAMBA3_ADD_OPTION('iconv')
44     opt.SAMBA3_ADD_OPTION('acl-support')
45     opt.SAMBA3_ADD_OPTION('dnsupdate')
46     opt.SAMBA3_ADD_OPTION('syslog')
47     opt.SAMBA3_ADD_OPTION('automount')
48     opt.SAMBA3_ADD_OPTION('aio-support')
49     opt.SAMBA3_ADD_OPTION('profiling-data', default=False)
50
51     opt.SAMBA3_ADD_OPTION('cluster-support')
52
53     opt.add_option('--with-ctdb-dir',
54                    help=("Directory under which ctdb is installed"),
55                    action="store", dest='ctdb_dir', default=None)
56     opt.add_option('--enable-old-ctdb',
57                   help=("enable building against (too) old version of ctdb (default=false)"),
58                   action="store_true", dest='enable_old_ctdb', default=False)
59
60
61
62 def configure(conf):
63     from samba_utils import TO_LIST
64
65     if Options.options.developer:
66         conf.ADD_CFLAGS('-DDEVELOPER -DDEBUG_PASSWORD')
67         conf.env.developer = True
68
69     if Options.options.with_swat:
70         conf.env['build_swat'] = True
71
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 mknod64')
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 sysconf stat64 fstat64')
84     conf.CHECK_FUNCS('lstat64 fopen64 atexit grantpt lseek64 ftruncate64 fallocate fallocate64 posix_fallocate posix_fallocate64')
85     conf.CHECK_FUNCS('fseek64 fseeko64 ftell64 ftello64 setluid')
86     conf.CHECK_FUNCS('getpwnam', headers='sys/types.h pwd.h')
87     conf.CHECK_FUNCS('opendir64 readdir64 seekdir64 telldir64 rewinddir64 closedir64')
88     conf.CHECK_FUNCS('fdopendir fdopendir64')
89     conf.CHECK_FUNCS('getpwent_r getdents64 setenv strcasecmp fcvt fcvtl')
90     conf.CHECK_FUNCS('syslog vsyslog timegm setlocale')
91     conf.CHECK_FUNCS_IN('nanosleep', 'rt')
92     conf.CHECK_FUNCS('lutimes futimes utimensat futimens')
93     conf.CHECK_FUNCS('mlock munlock mlockall munlockall')
94     conf.CHECK_FUNCS('memalign posix_memalign hstrerror')
95     conf.CHECK_FUNCS('shmget')
96     conf.CHECK_FUNCS_IN('shm_open', 'rt', checklibc=True)
97     conf.CHECK_FUNCS('gettext dgettext bindtextdomain textdomain bind_textdomain_codeset')
98     #FIXME: for some reason this one still fails
99     conf.CHECK_FUNCS_IN('yp_get_default_domain', 'nsl')
100     conf.CHECK_FUNCS_IN('dn_expand _dn_expand __dn_expand', 'resolv')
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,0);
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('linux/inotify.h asm/unistd.h sys/inotify.h')
119     conf.CHECK_FUNCS('inotify_init')
120     if "HAVE_LINUX_INOTIFY_H" in conf.env and "HAVE_INOTIFY_INIT" in conf.env:
121         conf.DEFINE('HAVE_INOTIFY', 1)
122
123     # Check for kernel change notify support
124     conf.CHECK_CODE('''
125 #ifndef F_NOTIFY
126 #define F_NOTIFY 1026
127 #endif
128 main() {
129         exit(fcntl(open("/tmp", O_RDONLY), F_NOTIFY, 0) == -1 ?  1 : 0);
130 }''', 'HAVE_KERNEL_CHANGE_NOTIFY', addmain=False, execute=True,
131         headers='fcntl.h signal.h',
132         msg="Checking for kernel change notify support")
133
134     # Check for Linux kernel oplocks
135     conf.CHECK_CODE('''
136 #include <sys/types.h>
137 #include <fcntl.h>
138 #include <signal.h>
139 #ifndef F_NOTIFY
140 #define F_NOTIFY 1026
141 #endif
142 main() {
143         exit(fcntl(open("/tmp", O_RDONLY), F_NOTIFY, 0) == -1 ?  1 : 0);
144 }''', 'HAVE_KERNEL_OPLOCKS_LINUX', addmain=False, execute=True,
145         msg="Checking for Linux kernel oplocks")
146
147     # Check for IRIX kernel oplock types
148     conf.CHECK_CODE('oplock_stat_t t; t.os_state = OP_REVOKE; t.os_dev = 1; t.os_ino = 1;',
149                     'HAVE_KERNEL_OPLOCKS_IRIX', headers='fcntl.h',
150                     msg="Checking for IRIX kernel oplock types")
151
152     # Check for kernel share modes
153     conf.CHECK_CODE('''
154 #include <sys/types.h>
155 #include <fcntl.h>
156 #include <signal.h>
157 #include <sys/file.h>
158 #ifndef LOCK_MAND
159 #define LOCK_MAND       32
160 #define LOCK_READ       64
161 #endif
162 main() {
163         exit(flock(open("/dev/null", O_RDWR), LOCK_MAND|LOCK_READ) != 0);
164 }''', 'HAVE_KERNEL_SHARE_MODES', addmain=False, execute=True,
165         msg="Checking for krenel share modes")
166
167     # Check for various members of the stat structure
168     conf.CHECK_TYPES('blksize_t blkcnt_t')
169     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_blocks', define='HAVE_STAT_ST_BLOCKS',
170                                 headers='sys/stat.h')
171     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_blksize', define='HAVE_STAT_ST_BLKSIZE',
172                                 headers='sys/stat.h')
173     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_flags', define='HAVE_STAT_ST_FLAGS',
174                                 headers='sys/types.h sys/stat.h unistd.h')
175
176     # Check for POSIX capability support
177     conf.CHECK_FUNCS_IN('cap_get_proc', 'cap', headers='sys/capability.h')
178
179     if "HAVE_SYS_CAPABILITY_H" in conf.env:
180         conf.CHECK_CODE('''
181         cap_t cap;
182         cap_value_t vals[1];
183         if (!(cap = cap_get_proc())) exit(1);
184         vals[0] = CAP_CHOWN;
185         cap_set_flag(cap, CAP_INHERITABLE, 1, vals, CAP_CLEAR);
186         cap_set_proc(cap);''',
187                         'HAVE_POSIX_CAPABILITIES', execute=True, lib="cap",
188                         headers='sys/capability.h',
189                         msg="Checking whether POSIX capabilities are available")
190
191     # Check for int16, uint16, int32 and uint32 in rpc/types.h included from
192     # rpc/rpc.h. This is *really* broken but some systems (DEC OSF1) do this.
193     # -- JRA.
194     if conf.CONFIG_SET("HAVE_RPC_RPC_H"):
195         conf.CHECK_TYPE('int16', headers='rpc/rpc.h',
196                         define='HAVE_INT16_FROM_RPC_RPC_H',
197                         msg="Checking for int16 typedef included by rpc/rpc.h")
198         conf.CHECK_CODE('uint16 testvar;', 'HAVE_INT16_FROM_RPC_RPC_H',
199                         headers='sys/types.h rpc/rpc.h',
200                         msg="Checking for uint16 typedef included by rpc/rpc.h")
201         conf.CHECK_CODE('int32 testvar;', 'HAVE_INT16_FROM_RPC_RPC_H',
202                         headers='sys/types.h rpc/rpc.h',
203                         msg="Checking for int32 typedef included by rpc/rpc.h")
204         conf.CHECK_CODE('uint32 testvar;', 'HAVE_INT16_FROM_RPC_RPC_H',
205                         headers='sys/types.h rpc/rpc.h',
206                         msg="Checking for uint32 typedef included by rpc/rpc.h")
207     conf.CHECK_CODE('int i;', 'BROKEN_NISPLUS_INCLUDE_FILES',
208                     headers='sys/types.h sys/acl.h rpcsvc/nis.h',
209                     msg="Checking for broken nisplus include files")
210
211     # Check if the compiler will optimize out functions
212     conf.CHECK_CODE('''
213 if (0) {
214     this_function_does_not_exist();
215 } else {
216     return 1;
217 }''', 'HAVE_COMPILER_WILL_OPTIMIZE_OUT_FNS',
218         msg="Checking if the compiler will optimize out functions")
219
220     # Check if the compiler supports the LL suffix on long long integers
221     # AIX needs this
222     conf.CHECK_CODE('long long i = 0x8000000000LL', 'COMPILER_SUPPORTS_LL',
223                     headers='stdio.h',
224                     msg="Checking for LL suffix on long long integers")
225
226     conf.CHECK_FUNCS('''
227 _acl __acl add_proplist_entry atexit attr_getf attr_list attr_listf
228 attropen attr_remove attr_removef attr_set attr_setf backtrace_symbols
229 bindtextdomain _chdir __chdir chflags chmod _close __close _closedir
230 __closedir closedir64 creat64 crypt16 delproplist devnm dgettext dirfd
231 DNSServiceRegister _dup __dup _dup2 __dup2 endmntent execl
232 extattr_delete_fd extattr_delete_link extattr_get_fd extattr_get_file
233 extattr_get_link extattr_list_fd extattr_list_file extattr_list_link
234 extattr_set_fd extattr_set_file extattr_set_link _facl __facl _fchdir
235 __fchdir fchmod fchown _fcntl __fcntl fcvt fcvtl fdatasync
236 fdelproplist fgetea fgetproplist fgetxattr flistea flistxattr fopen64
237 _fork __fork fremoveea fremovexattr fseek64 fseeko64 fsetea
238 fsetproplist fsetxattr _fstat __fstat fstat64 _fstat64 __fstat64 fsync
239 ftell64 ftello64 ftruncate64 futimens futimes __fxstat getauthuid
240 getcwd _getcwd __getcwd getdents __getdents getdents64 getdirentries
241 getgrent getgrnam getgrouplist getgrset getmntent getpagesize
242 getproplist get_proplist_entry getpwanam getpwent_r getrlimit gettext
243 glob grantpt hstrerror initgroups innetgr
244 inotify_init lgetea lgetxattr listea listxattr llistea llistxattr
245 llseek _llseek __llseek lremoveea lremovexattr _lseek __lseek lseek64
246 lsetea lsetxattr _lstat __lstat lstat64 _lstat64 __lstat64 lutimes
247 __lxstat memalign mknod mknod64 mlock mlockall munlock munlockall
248 _open __open open64 _open64 __open64 _opendir __opendir
249 opendir64 pathconf poll posix_fallocate posix_fallocate64
250 posix_memalign prctl pread _pread __pread pread64 _pread64 __pread64
251 pwrite _pwrite __pwrite pwrite64 _pwrite64
252 __pwrite64 rdchk _read __read _readdir __readdir readdir64 _readdir64
253 __readdir64 removeea removexattr rewinddir64 _seekdir __seekdir
254 seekdir64 select setea setenv setgidx setgroups setlocale setluid
255 setmntent setpgid setpriv setproplist setsid setuidx
256 setxattr shmget shm_open sigaction sigblock sigprocmask sigset
257 sizeof_proplist_entry _stat __stat stat64 _stat64 __stat64 statvfs
258 strcasecmp strchr strpbrk strsignal strtol strupr sysconf sysctlbyname
259 __sys_llseek syslog _telldir __telldir telldir64 textdomain timegm
260 utimensat vsyslog _write __write __xstat
261 ''')
262
263     conf.CHECK_SAMBA3_CHARSET() # see build/charset.py
264
265     # FIXME: these should be tests for features, but the old build system just
266     # checks for OSes.
267     host_os = sys.platform
268     Logs.info("building on %s" % host_os)
269
270     # Python doesn't have case switches... :/
271     # FIXME: original was *linux* | gnu* | k*bsd*-gnu | kopensolaris*-gnu | *qnx*)
272     # the search for .rfind('gnu') covers gnu* and *-gnu is that too broad?
273
274     conf.SET_TARGET_TYPE('sunacl', 'EMPTY')
275     if (host_os.rfind('linux') > -1) or (host_os.rfind('gnu') > -1) or (host_os.rfind('qnx') > -1):
276         if host_os.rfind('linux') > -1:
277             conf.DEFINE('LINUX', '1')
278         elif host_os.rfind('qnx') > -1:
279             conf.DEFINE('QNX', '1')
280         conf.DEFINE('STAT_ST_BLOCKSIZE', '512')
281     elif (host_os.rfind('darwin') > -1):
282         conf.DEFINE('DARWINOS', 1)
283         conf.DEFINE('STAT_ST_BLOCKSIZE', '512')
284         conf.ADD_CFLAGS('-fno-common')
285     elif (host_os.rfind('freebsd') > -1):
286         if conf.CHECK_HEADERS('sunacl.h'):
287             conf.DEFINE('HAVE_FREEBSD_SUNACL_H', '1')
288             conf.CHECK_FUNCS_IN('acl', 'sunacl')
289         conf.DEFINE('STAT_ST_BLOCKSIZE', '512')
290     elif (host_os.rfind('netbsd') > -1):
291         conf.DEFINE('STAT_ST_BLOCKSIZE', '512')
292     elif (host_os.rfind('openbsd') > -1):
293         conf.DEFINE('STAT_ST_BLOCKSIZE', '512')
294     elif (host_os.rfind('sunos') > -1):
295         conf.DEFINE('STAT_ST_BLOCKSIZE', '512')
296     # FIXME: Add more checks here.
297     else:
298         Logs.warn("Unknown host_os '%s', please report this to samba-technical@samba.org" % host_os)
299
300     #FIXME: add more checks
301     if Options.options.with_acl_support:
302         if host_os.rfind('linux') > -1:
303             conf.CHECK_FUNCS_IN('acl_get_file', 'acl')
304             conf.CHECK_FUNCS_IN('getxattr', 'attr')
305             if conf.CHECK_CODE('''
306 acl_t acl;
307 int entry_id;
308 acl_entry_t *entry_p;
309 return acl_get_entry(acl, entry_id, entry_p);
310 ''',
311                         'HAVE_POSIX_ACLS',
312                         headers='sys/types.h sys/acl.h', link=False,
313                         msg="Checking for POSIX ACL support") :
314                 conf.CHECK_CODE('''
315 acl_permset_t permset_d;
316 acl_perm_t perm;
317 return acl_get_perm_np(permset_d, perm);
318 ''',
319                         'HAVE_ACL_GET_PERM_NP',
320                         headers='sys/types.h sys/acl.h', link=True,
321                         msg="Checking whether acl_get_perm_np() is available")
322         else:
323             conf.DEFINE('HAVE_NO_ACLS', 1)
324             conf.SET_TARGET_TYPE('acl', 'EMPTY')
325     else:
326         conf.DEFINE('HAVE_NO_ACLS', 1)
327         conf.SET_TARGET_TYPE('acl', 'EMPTY')
328
329     if conf.CHECK_FUNCS('dirfd'):
330         conf.DEFINE('HAVE_DIRFD_DECL', 1)
331
332     conf.CHECK_CODE('struct statfs fsd; fsid_t fsid = fsd.f_fsid; return statfs(".", &fsd);',
333                     'HAVE_STATFS_F_FSID',
334                     msg="vfs_fileid: checking for statfs() and struct statfs.f_fsid",
335                     headers='sys/types.h sys/statfs.h',
336                     execute=True)
337
338     if conf.CONFIG_SET('HAVE_FALLOCATE'):
339         conf.CHECK_CODE('''
340                 #if defined(HAVE_UNISTD_H)
341                 #include <unistd.h>
342                 #endif
343                 #include <sys/types.h>
344                 #define _GNU_SOURCE
345                 #include <fcntl.h>
346                 #if defined(HAVE_LINUX_FALLOC_H)
347                 #include <linux/falloc.h>
348                 #endif
349                 int ret = fallocate(0, FALLOC_FL_KEEP_SIZE, 0, 10);''',
350                 'HAVE_LINUX_FALLOCATE',
351                 msg="Checking whether the Linux 'fallocate' function is available")
352     if conf.CONFIG_SET('HAVE_FALLOCATE64'):
353         conf.CHECK_CODE('''
354                 #if defined(HAVE_UNISTD_H)
355                 #include <unistd.h>
356                 #endif
357                 #include <sys/types.h>
358                 #define _GNU_SOURCE
359                 #include <fcntl.h>
360                 #if defined(HAVE_LINUX_FALLOC_H)
361                 #include <linux/falloc.h>
362                 #endif
363                 int ret = fallocate64(0, FALLOC_FL_KEEP_SIZE, 0, 10);''',
364                 'HAVE_LINUX_FALLOCATE64',
365                 msg="Checking whether the Linux 'fallocate64' function is available")
366     conf.CHECK_CODE('''
367                 #if defined(HAVE_UNISTD_H)
368                 #include <unistd.h>
369                 #endif
370                 #include <fcntl.h>
371                 ssize_t err = readahead(0,0,0x80000);''',
372                 'HAVE_LINUX_READAHEAD',
373                 msg="Checking whether Linux readahead is available")
374     conf.CHECK_DECLS('readahead', headers='fcntl.h', always=True)
375
376     conf.CHECK_CODE('''
377                 struct ucred cred;
378                 socklen_t cred_len;
379                 int ret = getsockopt(0, SOL_SOCKET, SO_PEERCRED, &cred, &cred_len);''',
380                 'HAVE_PEERCRED',
381                 msg="Checking whether we can use SO_PEERCRED to get socket credentials",
382                 headers='sys/types.h sys/socket.h')
383
384     conf.CHECK_CODE('''
385                 #if defined(HAVE_LONGLONG) && (defined(HAVE_OFF64_T) || (defined(SIZEOF_OFF_T) && (SIZEOF_OFF_T == 8)))
386                 #include <sys/types.h>
387                 #else
388                 __COMPILE_ERROR_
389                 #endif
390                 int i;''',
391                 'HAVE_EXPLICIT_LARGEFILE_SUPPORT',
392                 msg="Checking whether large file support can be enabled")
393
394     if Options.options.with_aio_support:
395         conf.CHECK_FUNCS_IN('aio_read', 'aio')
396         conf.CHECK_FUNCS_IN('aio_read', 'rt')
397         conf.CHECK_CODE('struct aiocb a; return aio_read(&a);',
398                         'HAVE_AIO',
399                         msg='Checking for asynchronous io support',
400                         headers='sys/types.h aio.h',
401                         lib='aio rt')
402         conf.CHECK_CODE('struct aiocb64 a; return aio_read64(&a);',
403                         'HAVE_AIO64',
404                         msg='Checking for 64-bit asynchronous io support',
405                         headers='sys/types.h aio.h',
406                         lib='aio rt')
407         if conf.CONFIG_SET('HAVE_AIO64'):
408             conf.DEFINE('HAVE_AIOCB64', '1')
409             conf.DEFINE('WITH_AIO', '1')
410         elif conf.CONFIG_SET('HAVE_AIO'):
411             conf.DEFINE('WITH_AIO', '1')
412         if conf.CONFIG_SET('HAVE_AIO'):
413             conf.CHECK_CODE('struct aiocb a; return aio_read(&a);', 'HAVE_AIO_READ', msg='Checking for aio_read', headers='aio.h', lib='aio rt')
414             conf.CHECK_CODE('struct aiocb a; return aio_write(&a);', 'HAVE_AIO_WRITE', msg='Checking for aio_write', headers='aio.h', lib='aio rt')
415             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')
416             conf.CHECK_CODE('struct aiocb a; return aio_return(&a);', 'HAVE_AIO_RETURN', msg='Checking for aio_return', headers='aio.h', lib='aio rt')
417             conf.CHECK_CODE('struct aiocb a; return aio_error(&a);', 'HAVE_AIO_ERROR', msg='Checking for aio_error', headers='aio.h', lib='aio rt')
418             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')
419             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')
420         if conf.CONFIG_SET('HAVE_AIO64'):
421             conf.CHECK_CODE('struct aiocb a; return aio_read64(&a);', 'HAVE_AIO_READ64', msg='Checking for aio_read64', headers='aio.h', lib='aio rt')
422             conf.CHECK_CODE('struct aiocb a; return aio_write64(&a);', 'HAVE_AIO_WRITE64', msg='Checking for aio_write64', headers='aio.h', lib='aio rt')
423             conf.CHECK_CODE('struct aiocb a; return aio_fsync64(1, &a);', 'HAVE_AIO_FSYNC64', msg='Checking for aio_fsync64', headers='aio.h', lib='aio rt')
424             conf.CHECK_CODE('struct aiocb a; return aio_return64(&a);', 'HAVE_AIO_RETURN64', msg='Checking for aio_return64', headers='aio.h', lib='aio rt')
425             conf.CHECK_CODE('struct aiocb a; return aio_error64(&a);', 'HAVE_AIO_ERROR64', msg='Checking for aio_error64', headers='aio.h', lib='aio rt')
426             conf.CHECK_CODE('struct aiocb a; return aio_cancel64(1, &a);', 'HAVE_AIO_CANCEL64', msg='Checking for aio_cancel64', headers='aio.h', lib='aio rt')
427             conf.CHECK_CODE('struct aiocb a; return aio_suspend64(&a, 1, NULL);', 'HAVE_AIO_SUSPEND64', msg='Checking for aio_suspend64', headers='aio.h', lib='aio rt')
428         if not conf.CONFIG_SET('HAVE_AIO'):
429             conf.DEFINE('HAVE_NO_AIO', '1')
430     else:
431         conf.DEFINE('HAVE_NO_AIO', '1')
432
433     conf.CHECK_CODE('''
434 struct msghdr msg;
435 union {
436         struct cmsghdr cm;
437         char control[CMSG_SPACE(sizeof(int))];
438 } control_un;
439 msg.msg_control = control_un.control;
440 msg.msg_controllen = sizeof(control_un.control);
441 ''',
442         'HAVE_MSGHDR_MSG_CONTROL',
443         msg='Checking if we can use msg_control for passing file descriptors',
444         headers='sys/types.h stdlib.h stddef.h sys/socket.h sys/un.h')
445     conf.CHECK_CODE('''
446 struct msghdr msg;
447 int fd;
448 msg.msg_acctrights = (caddr_t) &fd;
449 msg.msg_acctrightslen = sizeof(fd);
450 ''',
451         'HAVE_MSGHDR_MSG_ACCTRIGHTS',
452         msg='Checking if we can use msg_acctrights for passing file descriptors',
453         headers='sys/types.h stdlib.h stddef.h sys/socket.h sys/un.h')
454
455     if Options.options.with_winbind:
456         conf.env.build_winbind = True
457         conf.DEFINE('WITH_WINBIND', '1')
458
459     conf.find_program('awk', var='AWK')
460     conf.find_program('perl', var='PERL')
461
462     # Darwin has extra options to xattr-family functions
463     conf.CHECK_CODE('getxattr(0, 0, 0, 0, 0, 0);',
464                     'XATTR_ADD_OPT',
465                     msg="Checking whether xattr interface takes additional options",
466                     headers='sys/types.h attr/xattr.h sys/xattr.h')
467
468     conf.CHECK_HEADERS('asm/types.h')
469
470     conf.CHECK_CODE('dev_t dev; int i = major(dev); return 0', "HAVE_DEVICE_MAJOR_FN",
471                     headers='unistd.h sys/types.h',
472                     msg="Checking for major macro")
473
474     conf.CHECK_CODE('dev_t dev; int i = minor(dev); return 0', "HAVE_DEVICE_MINOR_FN",
475                     headers='unistd.h sys/types.h',
476                     msg="Checking for minor macro")
477
478     conf.CHECK_STRUCTURE_MEMBER('struct dirent', 'd_off',
479                                 headers='unistd.h sys/types.h dirent.h',
480                                 define='HAVE_DIRENT_D_OFF')
481
482     conf.CHECK_FUNCS('setnetgrent getnetgrent endnetgrent')
483     if conf.CHECK_CFLAGS('-Werror-implicit-function-declaration'):
484         netgrent_cflags = '-Werror-implicit-function-declaration'
485     else:
486         netgrent_cflags = ''
487     conf.CHECK_CODE('setnetgrent("foo")', 'HAVE_SETNETGRENT_PROTOTYPE',
488                     msg="Checking for setnetgrent prototype",
489                     headers='netdb.h netgroup.h',
490                     cflags=netgrent_cflags)
491     conf.CHECK_CODE('getnetgrent', 'HAVE_GETNETGRENT_PROTOTYPE',
492                     msg="Checking for getnetgrent prototype",
493                     headers='netdb.h netgroup.h',
494                     cflags=netgrent_cflags)
495     conf.CHECK_CODE('endnetgrent', 'HAVE_ENDNETGRENT_PROTOTYPE',
496                     msg="Checking for endnetgrent prototype",
497                     headers='netdb.h netgroup.h',
498                     cflags=netgrent_cflags)
499
500
501     # Look for CUPS
502     if Options.options.with_cups:
503         conf.find_program('cups-config', var='CUPS_CONFIG')
504         if conf.env.CUPS_CONFIG:
505             # we would normally use --libs here, but cups-config incorrectly adds
506             # gssapi_krb5 and other libraries to its --libs output. That breaks the use
507             # of an in-tree heimdal kerberos
508             conf.check_cfg(path=conf.env.CUPS_CONFIG, args="--cflags --ldflags",
509                            package="", uselib_store="cups")
510         conf.CHECK_HEADERS('cups/cups.h cups/language.h', lib='cups')
511         conf.CHECK_FUNCS_IN('httpConnect httpConnectEncrypt', 'cups')
512         if conf.CONFIG_SET('HAVE_CUPS_CUPS_H') and conf.CONFIG_SET('HAVE_CUPS_LANGUAGE_H'):
513             conf.DEFINE('HAVE_CUPS', '1')
514         else:
515             conf.undefine('HAVE_CUPS')
516             conf.SET_TARGET_TYPE('cups', 'EMPTY')
517     else:
518         # define an empty subsystem for cups, to allow it to be used as an empty dependency
519         conf.SET_TARGET_TYPE('cups', 'EMPTY')
520
521     if Options.options.with_iprint:
522         if conf.CONFIG_SET('HAVE_CUPS'):
523             conf.DEFINE('HAVE_IPRINT', '1')
524         else:
525             Logs.warn("--enable-iprint=yes but cups support not sufficient")
526     if Options.options.with_syslog:
527         conf.DEFINE('WITH_SYSLOG', '1')
528     if Options.options.with_automount:
529         conf.DEFINE('WITH_AUTOMOUNT', '1')
530
531     # Check for LDAP
532     if Options.options.with_ldap:
533         conf.CHECK_HEADERS('ldap.h lber.h ldap_pvt.h')
534         conf.CHECK_TYPE('ber_tag_t', 'unsigned int', headers='ldap.h lber.h')
535         conf.CHECK_FUNCS_IN('ber_scanf ber_sockbuf_add_io', 'lber')
536         conf.CHECK_VARIABLE('LDAP_OPT_SOCKBUF', headers='ldap.h')
537
538         # if we LBER_OPT_LOG_PRINT_FN we can intercept ldap logging and print it out
539         # for the samba logs
540         conf.CHECK_VARIABLE('LBER_OPT_LOG_PRINT_FN',
541                             define='HAVE_LBER_LOG_PRINT_FN', headers='lber.h')
542
543         conf.CHECK_FUNCS_IN('ldap_init ldap_init_fd ldap_initialize ldap_set_rebind_proc', 'ldap')
544         conf.CHECK_FUNCS_IN('ldap_add_result_entry', 'ldap')
545
546         # Check if ldap_set_rebind_proc() takes three arguments
547         if conf.CHECK_CODE('ldap_set_rebind_proc(0, 0, 0)',
548                            'LDAP_SET_REBIND_PROC_ARGS',
549                            msg="Checking whether ldap_set_rebind_proc takes 3 arguments",
550                            headers='ldap.h lber.h', link=False):
551             conf.DEFINE('LDAP_SET_REBIND_PROC_ARGS', '3')
552         else:
553             conf.DEFINE('LDAP_SET_REBIND_PROC_ARGS', '2')
554
555         # last but not least, if ldap_init() exists, we want to use ldap
556         if conf.CONFIG_SET('HAVE_LDAP_INIT'):
557             conf.DEFINE('HAVE_LDAP', '1')
558             conf.DEFINE('LDAP_DEPRECATED', '1')
559             conf.env['HAVE_LDAP'] = '1'
560             # if ber_sockbuf_add_io() and LDAP_OPT_SOCKBUF are available, we can add
561             # SASL wrapping hooks
562             if conf.CONFIG_SET('HAVE_BER_SOCKBUF_ADD_IO') and \
563                     conf.CONFIG_SET('HAVE_LDAP_OPT_SOCKBUF'):
564                 conf.DEFINE('HAVE_LDAP_SASL_WRAPPING', '1')
565     else:
566         conf.SET_TARGET_TYPE('ldap', 'EMPTY')
567         conf.SET_TARGET_TYPE('lber', 'EMPTY')
568
569     # Check for kerberos
570     have_gssapi=False
571     if Options.options.with_mit_krb5_checks and conf.env.developer:
572         Logs.info("Looking for kerberos features")
573         conf.find_program('krb5-config', var='KRB5_CONFIG')
574         if conf.env.KRB5_CONFIG:
575             conf.check_cfg(path="krb5-config", args="--cflags --libs",
576                        package="gssapi", uselib_store="krb5")
577         conf.CHECK_HEADERS('krb5.h krb5/locate_plugin.h', lib='krb5')
578         conf.CHECK_HEADERS('gssapi.h gssapi/gssapi_generic.h gssapi/gssapi.h gssapi/gssapi_ext.h gssapi/gssapi_krb5.h com_err.h', lib='krb5')
579
580         if conf.CONFIG_SET('HAVE_KRB5_LOCATE_PLUGIN_H'):
581             conf.env['WINBIND_KRB5_LOCATOR'] = 'bin/winbind_krb5_locator.so'
582
583         conf.CHECK_FUNCS_IN('_et_list', 'com_err')
584         conf.CHECK_FUNCS_IN('krb5_encrypt_data', 'k5crypto')
585         conf.CHECK_FUNCS_IN('des_set_key','crypto')
586         conf.CHECK_FUNCS_IN('copy_Authenticator', 'asn1')
587         conf.CHECK_FUNCS_IN('roken_getaddrinfo_hostspec', 'roken')
588         if conf.CHECK_FUNCS_IN('gss_display_status', 'gssapi') or \
589            conf.CHECK_FUNCS_IN('gss_display_status', 'gssapi_krb5'):
590             have_gssapi=True
591         conf.CHECK_FUNCS_IN('gss_wrap_iov gss_krb5_import_cred gss_get_name_attribute gss_mech_krb5 gss_oid_equal gss_inquire_sec_context_by_oid', 'gssapi gssapi_krb5 krb5')
592         conf.CHECK_FUNCS_IN('krb5_mk_req_extended krb5_kt_compare', 'krb5')
593         conf.CHECK_FUNCS('''
594 krb5_set_real_time krb5_set_default_in_tkt_etypes krb5_set_default_tgs_enctypes
595 krb5_set_default_tgs_ktypes krb5_principal2salt krb5_use_enctype
596 krb5_string_to_key krb5_get_pw_salt krb5_string_to_key_salt krb5_auth_con_setkey
597 krb5_auth_con_setuseruserkey krb5_locate_kdc krb5_get_permitted_enctypes
598 krb5_get_default_in_tkt_etypes krb5_free_data_contents
599 krb5_principal_get_comp_string krb5_free_unparsed_name
600 krb5_free_keytab_entry_contents krb5_kt_free_entry krb5_krbhst_init
601 krb5_krbhst_get_addrinfo krb5_c_enctype_compare krb5_enctypes_compatible_keys
602 krb5_crypto_init krb5_crypto_destroy krb5_decode_ap_req free_AP_REQ
603 krb5_verify_checksum krb5_c_verify_checksum krb5_principal_compare_any_realm
604 krb5_parse_name_norealm krb5_princ_size krb5_get_init_creds_opt_set_pac_request
605 krb5_get_renewed_creds krb5_get_kdc_cred krb5_free_error_contents
606 initialize_krb5_error_table krb5_get_init_creds_opt_alloc
607 krb5_get_init_creds_opt_free krb5_get_init_creds_opt_get_error
608 krb5_enctype_to_string krb5_fwd_tgt_creds krb5_auth_con_set_req_cksumtype
609 krb5_get_creds_opt_alloc krb5_get_creds_opt_set_impersonate krb5_get_creds
610 krb5_get_credentials_for_user krb5_get_host_realm krb5_free_host_realm''',
611                          lib='krb5 k5crypto')
612         conf.CHECK_DECLS('''krb5_get_credentials_for_user
613                             krb5_auth_con_set_req_cksumtype''',
614                             headers='krb5.h', always=True)
615         conf.CHECK_VARIABLE('AP_OPTS_USE_SUBKEY', headers='krb5.h')
616         conf.CHECK_VARIABLE('KV5M_KEYTAB', headers='krb5.h')
617         conf.CHECK_VARIABLE('KRB5_KU_OTHER_CKSUM', headers='krb5.h')
618         conf.CHECK_VARIABLE('KRB5_KEYUSAGE_APP_DATA_CKSUM', headers='krb5.h')
619         conf.CHECK_STRUCTURE_MEMBER('krb5_keytab_entry', 'key', headers='krb5.h',
620                                     define='HAVE_KRB5_KEYTAB_ENTRY_KEY')
621         conf.CHECK_STRUCTURE_MEMBER('krb5_keytab_entry', 'keyblock', headers='krb5.h',
622                                     define='HAVE_KRB5_KEYTAB_ENTRY_KEYBLOCK')
623         conf.CHECK_STRUCTURE_MEMBER('krb5_address', 'magic', headers='krb5.h',
624                                     define='HAVE_MAGIC_IN_KRB5_ADDRESS')
625         conf.CHECK_STRUCTURE_MEMBER('krb5_address', 'addrtype', headers='krb5.h',
626                                     define='HAVE_ADDRTYPE_IN_KRB5_ADDRESS')
627         conf.CHECK_STRUCTURE_MEMBER('krb5_ticket', 'enc_part2', headers='krb5.h',
628                                     define='HAVE_KRB5_TKT_ENC_PART2')
629         conf.CHECK_STRUCTURE_MEMBER('krb5_creds', 'keyblock', headers='krb5.h',
630                                     define='HAVE_KRB5_KEYBLOCK_IN_CREDS')
631         conf.CHECK_STRUCTURE_MEMBER('krb5_creds', 'session', headers='krb5.h',
632                                     define='HAVE_KRB5_SESSION_IN_CREDS')
633         conf.CHECK_STRUCTURE_MEMBER('krb5_ap_req', 'ticket', headers='krb5.h',
634                                     define='HAVE_TICKET_POINTER_IN_KRB5_AP_REQ')
635
636         conf.CHECK_TYPE('krb5_encrypt_block', headers='krb5.h')
637
638         conf.CHECK_CODE('''
639 krb5_ticket ticket;
640 krb5_kvno kvno;
641 krb5_enctype enctype;
642 enctype = ticket.enc_part.enctype;
643 kvno = ticket.enc_part.kvno;
644 ''',
645                         'KRB5_TICKET_HAS_KEYINFO',
646                         headers='krb5.h', link=False,
647                         msg="Checking whether the krb5_ticket structure contains the kvno and enctype")
648         conf.CHECK_CODE('''
649 krb5_context ctx;
650 krb5_get_init_creds_opt *opt = NULL;
651 krb5_get_init_creds_opt_free(ctx, opt);
652 ''',
653                         'KRB5_CREDS_OPT_FREE_REQUIRES_CONTEXT',
654                         headers='krb5.h', link=False,
655                         msg="Checking whether krb5_get_init_creds_opt_free takes a context argument")
656         conf.CHECK_CODE('krb5_mk_error(0,0,0)',
657                         'HAVE_SHORT_KRB5_MK_ERROR_INTERFACE',
658                         headers='krb5.h', link=False,
659                         msg="Checking whether krb5_mk_error takes 3 arguments MIT or 9 Heimdal")
660         conf.CHECK_CODE('''
661 const krb5_data *pkdata;
662 krb5_context context;
663 krb5_principal principal;
664 pkdata = krb5_princ_component(context, principal, 0);
665 ''',
666                         'HAVE_KRB5_PRINC_COMPONENT',
667                         headers='krb5.h', lib='krb5',
668                         msg="Checking whether krb5_princ_component is available")
669
670         conf.CHECK_CODE('''
671 int main(void) {
672 char buf[256];
673 krb5_enctype_to_string(1, buf, 256);
674 return 0;
675 }''',
676                         'HAVE_KRB5_ENCTYPE_TO_STRING_WITH_SIZE_T_ARG',
677                         headers='krb5.h', lib='krb5 k5crypto',
678                         addmain=False, cflags='-Werror',
679                         msg="Checking whether krb5_enctype_to_string takes size_t argument")
680
681         conf.CHECK_CODE('''
682 int main(void) {
683 krb5_context context = NULL;
684 char *str = NULL;
685 krb5_enctype_to_string(context, 1, &str);
686 if (str) free (str);
687 return 0;
688 }''',
689                         'HAVE_KRB5_ENCTYPE_TO_STRING_WITH_KRB5_CONTEXT_ARG',
690                         headers='krb5.h stdlib.h', lib='krb5',
691                         addmain=False, cflags='-Werror',
692                         msg="Checking whether krb5_enctype_to_string takes krb5_context argument")
693         conf.CHECK_CODE('''
694 int main(void) {
695 krb5_context ctx = NULL;
696 krb5_principal princ = NULL;
697 const char *str = krb5_princ_realm(ctx, princ)->data;
698 return 0;
699 }''',
700                         'HAVE_KRB5_PRINC_REALM',
701                         headers='krb5.h', lib='krb5',
702                         addmain=False,
703                         msg="Checking whether the macro krb5_princ_realm is defined")
704         conf.CHECK_CODE('''
705 int main(void) {
706     krb5_context context;
707     krb5_principal principal;
708     const char *realm; realm = krb5_principal_get_realm(context, principal);
709     return 0;
710 }''',
711                         'HAVE_KRB5_PRINCIPAL_GET_REALM',
712                         headers='krb5.h', lib='krb5',
713                         addmain=False,
714                         msg="Checking whether krb5_principal_get_realm is defined")
715         if conf.CHECK_CODE('''krb5_verify_checksum(0, 0, 0, 0, 0, 0, 0);''',
716                         'KRB5_VERIFY_CHECKSUM_ARGS',
717                         headers='krb5.h', lib='krb5',
718                         msg="Checking whether krb5_verify_checksum takes 7 arguments"):
719             conf.DEFINE('KRB5_VERIFY_CHECKSUM_ARGS', '7')
720         else:
721             conf.DEFINE('KRB5_VERIFY_CHECKSUM_ARGS', '6')
722
723         conf.CHECK_CODE('''
724 krb5_enctype enctype;
725 enctype = ENCTYPE_ARCFOUR_HMAC_MD5;
726 ''',
727             '_HAVE_ENCTYPE_ARCFOUR_HMAC_MD5',
728             headers='krb5.h', lib='krb5',
729             msg="Checking whether the ENCTYPE_ARCFOUR_HMAC_MD5 key type definition is available");
730         conf.CHECK_CODE('''
731 krb5_keytype keytype;
732 keytype = KEYTYPE_ARCFOUR_56;
733 ''',
734             '_HAVE_KEYTYPE_ARCFOUR_56',
735             headers='krb5.h', lib='krb5',
736             msg="Checking whether the HAVE_KEYTYPE_ARCFOUR_56 key type definition is available");
737         if conf.CONFIG_SET('_HAVE_ENCTYPE_ARCFOUR_HMAC_MD5') and conf.CONFIG_SET('_HAVE_KEYTYPE_ARCFOUR_56'):
738             conf.DEFINE('HAVE_ENCTYPE_ARCFOUR_HMAC_MD5', '1')
739
740         conf.CHECK_CODE('''
741 krb5_enctype enctype;
742 enctype = ENCTYPE_ARCFOUR_HMAC;
743 ''',
744             'HAVE_ENCTYPE_ARCFOUR_HMAC',
745             headers='krb5.h', lib='krb5',
746             msg="Checking whether the ENCTYPE_ARCFOUR_HMAC key type definition is available");
747
748         conf.CHECK_CODE('''
749 krb5_context context;
750 krb5_keytab keytab;
751 krb5_init_context(&context);
752 return krb5_kt_resolve(context, "WRFILE:api", &keytab);
753 ''',
754             'HAVE_WRFILE_KEYTAB',
755             headers='krb5.h', lib='krb5', execute=True,
756             msg="Checking whether the WRFILE:-keytab is supported");
757
758         # Check for KRB5_DEPRECATED handling
759         conf.CHECK_CODE('''#define KRB5_DEPRECATED 1
760 #include <krb5.h>''',
761         'HAVE_KRB5_DEPRECATED_WITH_IDENTIFIER', addmain=False,
762         link=False,
763         msg="Checking for KRB5_DEPRECATED define taking an identifier")
764
765     if Options.options.with_ads:
766         use_ads=True
767         if not conf.CONFIG_SET('HAVE_ENCTYPE_ARCFOUR_HMAC_MD5') and \
768            not conf.CONFIG_SET('HAVE_ENCTYPE_ARCFOUR_HMAC'):
769             Logs.warn("arcfour-hmac-md5 encryption type not found in -lkrb5")
770             use_ads=False
771         if not conf.CONFIG_SET('HAVE_KRB5_MK_REQ_EXTENDED'):
772             Logs.warn("krb5_mk_req_extended not found in -lkrb5")
773             use_ads=False
774         if not conf.CONFIG_SET('HAVE_KRB5_PRINCIPAL2SALT') and \
775            not conf.CONFIG_SET('HAVE_KRB5_GET_PW_SALT'):
776             Logs.warn("no CREATE_KEY_FUNCTIONS detected")
777             use_ads=False
778         if not conf.CONFIG_SET('HAVE_KRB5_GET_PERMITTED_ENCTYPES') and \
779            not conf.CONFIG_SET('HAVE_KRB5_GET_DEFAULT_IN_TKT_ETYPES'):
780             Logs.warn("no GET_ENCTYPES_FUNCTIONS detected")
781             use_ads=False
782         if not conf.CONFIG_SET('HAVE_KRB5_KT_FREE_ENTRY') and \
783            not conf.CONFIG_SET('HAVE_KRB5_FREE_KEYTAB_ENTRY_CONTENTS'):
784             Logs.warn("no KT_FREE_FUNCTION detected")
785             use_ads=False
786         if not conf.CONFIG_SET('HAVE_KRB5_C_VERIFY_CHECKSUM') and \
787            not conf.CONFIG_SET('HAVE_KRB5_VERIFY_CHECKSUM'):
788             Logs.warn("no KRB5_VERIFY_CHECKSUM_FUNCTION detected")
789             use_ads=False
790         if not conf.CONFIG_SET('KRB5_TICKET_HAS_KEYINFO'):
791             # We only need the following functions if we can't get the enctype
792             # and kvno out of the ticket directly (ie. on Heimdal).
793             if not conf.CONFIG_SET('HAVE_FREE_AP_REQ'):
794                 Logs.warn("no KRB5_AP_REQ_FREE_FUNCTION detected")
795                 use_ads=False
796             if not conf.CONFIG_SET('HAVE_KRB5_DECODE_AP_REQ'):
797                 Logs.warn("no KRB5_AP_REQ_DECODING_FUNCTION detected")
798                 use_ads=False
799         if use_ads:
800             conf.DEFINE('WITH_ADS', '1')
801             conf.DEFINE('HAVE_KRB5', '1')
802             if have_gssapi:
803                 conf.DEFINE('HAVE_GSSAPI', '1')
804             if conf.CONFIG_SET('HAVE_LDAP'):
805                 conf.env['HAVE_ADS'] = '1'
806         else:
807             Logs.warn("krb5 libs don't have all features required for Active Directory support")
808             conf.undefine('HAVE_KRB5_H')
809             conf.undefine('HAVE_GSSAPI_H')
810             conf.undefine('HAVE_GSSAPI_GSSAPI_GENERIC_H')
811             conf.undefine('HAVE_GSSAPI_GSSAPI_H')
812
813     if Options.options.with_utmp:
814         conf.CHECK_FUNCS('pututline pututxline updwtmp updwtmpx getutmpx getutxent')
815         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_name', headers='utmp.h',
816                                     define='HAVE_UT_UT_NAME')
817         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_user', headers='utmp.h',
818                                     define='HAVE_UT_UT_USER')
819         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_id', headers='utmp.h',
820                                     define='HAVE_UT_UT_ID')
821         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_host', headers='utmp.h',
822                                     define='HAVE_UT_UT_HOST')
823         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_time', headers='utmp.h',
824                                     define='HAVE_UT_UT_TIME')
825         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_tv', headers='utmp.h',
826                                     define='HAVE_UT_UT_TV')
827         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_type', headers='utmp.h',
828                                     define='HAVE_UT_UT_TYPE')
829         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_pid', headers='utmp.h',
830                                     define='HAVE_UT_UT_PID')
831         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_exit.e_exit', headers='utmp.h',
832                                     define='HAVE_UT_UT_EXIT')
833         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_addr_v6', headers='utmp.h',
834                                     define='HAVE_UT_UT_ADDR_V6')
835         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_addr', headers='utmp.h',
836                                     define='HAVE_UT_UT_ADDR')
837         conf.CHECK_STRUCTURE_MEMBER('struct utmpx', 'ut_syslen', headers='utmpx.h',
838                                     define='HAVE_UX_UT_SYSLEN')
839         conf.CHECK_CODE('struct utmp utarg; struct utmp *utreturn; utreturn = pututline(&utarg);',
840                         'PUTUTLINE_RETURNS_UTMP', headers='utmp.h',
841                         msg="Checking whether pututline returns pointer")
842         conf.DEFINE('WITH_UTMP', 1)
843
844     if Options.options.with_avahi:
845         conf.env.with_avahi = True
846         if not conf.CHECK_HEADERS('avahi-common/watch.h avahi-client/client.h'): conf.env.with_avahi = False
847         if not conf.CHECK_FUNCS_IN('avahi_client_new', 'avahi-client'): conf.env.with_avahi = False
848         if not conf.CHECK_FUNCS_IN('avahi_strerror', 'avahi-common'): conf.env.with_avahi = False
849         if conf.env.with_avahi:
850             conf.DEFINE('WITH_AVAHI_SUPPORT', 1)
851     else:
852         conf.SET_TARGET_TYPE('avahi-common', 'EMPTY')
853         conf.SET_TARGET_TYPE('avahi-client', 'EMPTY')
854
855     if Options.options.with_iconv:
856         conf.env.with_iconv = True
857         if not conf.CHECK_FUNCS_IN('iconv_open', 'iconv', headers='iconv.h'):
858             conf.env.with_iconv = False
859         if conf.env.with_iconv:
860             conf.DEFINE('HAVE_ICONV', 1)
861
862     if Options.options.with_pam:
863         use_pam=True
864         conf.CHECK_HEADERS('security/pam_appl.h pam/pam_appl.h')
865         if not conf.CONFIG_SET('HAVE_SECURITY_PAM_APPL_H') and not conf.CONFIG_SET('HAVE_PAM_PAM_APPL_H'):
866             Logs.warn("--with-pam=yes but pam_appl.h not found")
867             use_pam=False
868         conf.CHECK_FUNCS_IN('pam_get_data', 'pam')
869         conf.CHECK_HEADERS('security/pam_modules.h pam/pam_modules.h')
870         if not conf.CONFIG_SET('HAVE_SECURITY_PAM_MODULES_H') and not conf.CONFIG_SET('HAVE_PAM_PAM_MODULES_H'):
871             Logs.warn("--with-pam=yes but pam_modules.h not found")
872             use_pam=False
873         conf.CHECK_HEADERS('security/pam_ext.h security/_pam_macros.h')
874         conf.CHECK_HEADERS('pam/pam_ext.h pam/_pam_macros.h')
875         conf.CHECK_FUNCS_IN('pam_vsyslog', 'pam')
876         conf.CHECK_CODE('''
877 #if defined(HAVE_SECURITY_PAM_APPL_H)
878 #include <security/pam_appl.h>
879 #elif defined(HAVE_PAM_PAM_APPL_H)
880 #include <pam/pam_appl.h>
881 #endif
882 pam_set_item(0, PAM_RHOST, 0);
883 ''',
884             'HAVE_PAM_RHOST',
885             lib='pam',
886             msg="Checking whether PAM_RHOST is available");
887         conf.CHECK_CODE('''
888 #if defined(HAVE_SECURITY_PAM_APPL_H)
889 #include <security/pam_appl.h>
890 #elif defined(HAVE_PAM_PAM_APPL_H)
891 #include <pam/pam_appl.h>
892 #endif
893 pam_set_item(0, PAM_TTY, 0);
894 ''',
895             'HAVE_PAM_TTY',
896             lib='pam',
897             msg="Checking whether PAM_TTY is available");
898         conf.CHECK_CODE('''
899 #if (!defined(LINUX))
900
901 #define PAM_EXTERN extern
902 #if defined(HAVE_SECURITY_PAM_APPL_H)
903 #include <security/pam_appl.h>
904 #elif defined(HAVE_PAM_PAM_APPL_H)
905 #include <pam/pam_appl.h>
906 #endif
907
908 #endif
909
910 #if defined(HAVE_SECURITY_PAM_MODULES_H)
911 #include <security/pam_modules.h>
912 #elif defined(HAVE_PAM_PAM_MODULES_H)
913 #include <pam/pam_modules.h>
914 #endif
915
916 #if defined(HAVE_SECURITY__PAM_MACROS_H)
917 #include <security/_pam_macros.h>
918 #elif defined(HAVE_PAM__PAM_MACROS_H)
919 #include <pam/_pam_macros.h>
920 #endif
921
922 #ifdef HAVE_SECURITY_PAM_EXT_H
923 #include <security/pam_ext.h>
924 #endif
925
926 int i; i = PAM_RADIO_TYPE;
927 ''',
928             'HAVE_PAM_RADIO_TYPE',
929             lib='pam',
930             msg="Checking whether PAM_RADIO_TYPE is available");
931         if use_pam:
932             conf.DEFINE('WITH_PAM', 1)
933             conf.DEFINE('WITH_PAM_MODULES', 1)
934
935     seteuid = False
936     if not seteuid:
937         seteuid = conf.CHECK_CODE('''
938                                 #define AUTOCONF_TEST 1
939                                 #define USE_SETREUID 1
940                                 #include "./lib/util_sec.c"
941                                 ''',
942                                 'USE_SETREUID',
943                                 addmain=False,
944                                 execute=True,
945                                 msg="Checking whether setreuid is available")
946     if not seteuid:
947         seteuid = conf.CHECK_CODE('''
948                                 #define AUTOCONF_TEST 1
949                                 #define USE_SETRESUID 1
950                                 #include "./lib/util_sec.c"
951                                 ''',
952                                 'USE_SETRESUID',
953                                 addmain=False,
954                                 execute=True,
955                                 msg="Checking whether setresuid is available")
956     if not seteuid:
957         seteuid = conf.CHECK_CODE('''
958                                 #define AUTOCONF_TEST 1
959                                 #define USE_SETEUID 1
960                                 #include "./lib/util_sec.c"
961                                 ''',
962                                 'USE_SETEUID',
963                                 addmain=False,
964                                 execute=True,
965                                 msg="Checking whether seteuid is available")
966     if not seteuid:
967         seteuid = conf.CHECK_CODE('''
968                                 #define AUTOCONF_TEST 1
969                                 #define USE_SETUIDX 1
970                                 #include "./lib/util_sec.c"
971                                 ''',
972                                 'USE_SETUIDX',
973                                 addmain=False,
974                                 execute=True,
975                                 mandatory=True,
976                                 msg="Checking whether setuidx is available")
977     if Options.options.with_dnsupdate:
978         conf.CHECK_HEADERS('uuid/uuid.h')
979         conf.CHECK_FUNCS_IN('uuid_generate', 'uuid')
980         if not conf.CONFIG_SET('HAVE_UUID_UUID_H') and not conf.CONFIG_SET('HAVE_UUID_GENERATE'):
981             Logs.warn("--with-dnsupdate=yes but uuid support not sufficient")
982         elif not conf.CONFIG_SET('HAVE_GSSAPI'):
983             Logs.warn("--with-dnsupdate=yes but gssapi support not sufficient")
984         else:
985             conf.DEFINE('WITH_DNS_UPDATES', 1)
986     else:
987         conf.SET_TARGET_TYPE('uuid', 'EMPTY')
988     conf.CHECK_HEADERS('valgrind.h valgrind/valgrind.h valgrind/memcheck.h')
989     if Options.options.developer:
990         if conf.CONFIG_SET('HAVE_VALGRIND_H') or conf.CONFIG_SET('HAVE_VALGRIND_VALGRIND_H'):
991             conf.DEFINE('VALGRIND', '1')
992
993     if conf.CHECK_CODE('''
994 #include <bits/sockaddr.h>
995 #include <linux/netlink.h>
996 ''',
997                 'HAVE_LINUX_NETLINK_H',
998                 msg="Checking whether Linux netlink is available"):
999         conf.CHECK_CODE('''
1000 #include <bits/sockaddr.h>
1001 #include <linux/netlink.h>
1002 #include <linux/rtnetlink.h>
1003 ''',
1004                 'HAVE_LINUX_RTNETLINK_H',
1005                 msg='Checking whether Linux rtnetlink is available')
1006     if conf.CHECK_TYPE('struct dirent64', headers='sys/types.h dirent.h') and conf.CONFIG_SET('HAVE_READDIR64'):
1007         conf.DEFINE('HAVE_STRUCT_DIRENT64', '1')
1008     else:
1009         conf.undefine('HAVE_STRUCT_DIRENT64')
1010
1011     conf.CHECK_CODE('''
1012 #include "../tests/fcntl_lock.c"
1013 ''',
1014                 'HAVE_FCNTL_LOCK',
1015                 addmain=False,
1016                 execute=True,
1017                 msg='Checking whether fcntl locking is available')
1018
1019     conf.CHECK_CODE('''
1020 #include "../tests/fcntl_lock64.c"
1021 ''',
1022                 'HAVE_BROKEN_FCNTL64_LOCKS',
1023                 addmain=False,
1024                 execute=True,
1025                 msg='Checking whether fcntl64 locks are broken')
1026
1027     if not conf.CONFIG_SET('HAVE_BROKEN_FCNTL64_LOCKS'):
1028         conf.CHECK_CODE('''
1029 #if defined(HAVE_UNISTD_H)
1030 #include <unistd.h>
1031 #endif
1032 #include <stdio.h>
1033 #include <stdlib.h>
1034
1035 #ifdef HAVE_FCNTL_H
1036 #include <fcntl.h>
1037 #endif
1038
1039 #ifdef HAVE_SYS_FCNTL_H
1040 #include <sys/fcntl.h>
1041 #endif
1042 main() { struct flock64 fl64;
1043 #if defined(F_SETLKW64) && defined(F_SETLK64) && defined(F_GETLK64)
1044 exit(0);
1045 #else
1046 exit(1);
1047 #endif
1048 }
1049 ''',
1050                 'HAVE_STRUCT_FLOCK64',
1051                 addmain=False,
1052                 execute=True,
1053                 msg="Checking whether the flock64 struct is available")
1054
1055     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_mtim.tv_nsec',
1056                                 define='HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC') # Linux, Solaris
1057     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_mtimensec',
1058                                 define='HAVE_STRUCT_STAT_ST_MTIMENSEC') # BSD, if defined _POSIX_SOURCE
1059     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_mtimespec.tv_nsec',
1060                                 define='HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC') # BSD, if not defined _POSIX_SOURCE
1061     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_mtime_n',
1062                                 define='HAVE_STRUCT_STAT_ST_MTIME_N') # AIX
1063     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_umtime',
1064                                 define='HAVE_STRUCT_STAT_ST_UMTIME') # Tru64
1065     if conf.CONFIG_SET('HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC') or \
1066        conf.CONFIG_SET('HAVE_STRUCT_STAT_ST_MTIMENSEC') or \
1067        conf.CONFIG_SET('HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC') or \
1068        conf.CONFIG_SET('HAVE_STRUCT_STAT_ST_MTIME_N') or \
1069        conf.CONFIG_SET('HAVE_STRUCT_STAT_ST_UMTIME'):
1070         conf.DEFINE('HAVE_STAT_HIRES_TIMESTAMPS', '1')
1071
1072     # recent FreeBSD, NetBSD have creation timestamps called birthtime:
1073     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_birthtime',
1074                                 define='HAVE_STRUCT_STAT_ST_BIRTHTIME')
1075     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_birthtimespec.tv_nsec',
1076                                 define='HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC')
1077     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_birthtimensec',
1078                                 define='HAVE_STRUCT_STAT_ST_BIRTHTIMENSEC')
1079
1080     conf.CHECK_CODE('''
1081 ssize_t err = posix_fadvise(0,0,0x80000,POSIX_FADV_WILLNEED);
1082 ''',
1083                 'HAVE_POSIX_FADVISE',
1084                 msg='Checking whether posix_fadvise is available',
1085                 headers='unistd.h fcntl.h')
1086
1087     for v in ['_SC_NGROUPS_MAX', '_SC_NPROC_ONLN', '_SC_NPROCESSORS_ONLN', '_SC_PAGESIZE' ]:
1088         conf.CHECK_CODE('''
1089                         #include <unistd.h>
1090                         return sysconf(%s) == -1 ? 1 : 0;
1091                         ''' % v,
1092                         'SYSCONF%s' % v,
1093                         msg='Checking whether sysconf(%s) is available' % v)
1094
1095     conf.CHECK_DECLS('__NR_inotify_init', reverse=True, headers='asm/unistd.h')
1096
1097     conf.CHECK_CODE('''
1098 #include <sys/syscall.h>
1099 #include <unistd.h>
1100 syscall(SYS_initgroups, 16, NULL, NULL, 0);
1101                     ''',
1102                     'HAVE_DARWIN_INITGROUPS',
1103                     msg='Checking whether to use the Darwin-specific initgroups system call')
1104
1105     conf.CHECK_CODE('''struct utimbuf tbuf;  tbuf.actime = 0; tbuf.modtime = 1; exit(utime("foo.c",&tbuf));''',
1106                     'HAVE_UTIMBUF',
1107                     headers='sys/types.h utime.h',
1108                     msg='Checking whether struct utimbuf is available')
1109
1110     if conf.CHECK_CODE('''struct sigevent s;''',
1111                     'HAVE_STRUCT_SIGEVENT',
1112                     headers='sys/types.h stdlib.h stddef.h signal.h',
1113                     msg='Checking whether we have the struct sigevent'):
1114         conf.CHECK_STRUCTURE_MEMBER('struct sigevent', 'sigev_value.sival_ptr',
1115                                     define='HAVE_STRUCT_SIGEVENT_SIGEV_VALUE_SIVAL_PTR',
1116                                     headers='signal.h');
1117         conf.CHECK_STRUCTURE_MEMBER('struct sigevent', 'sigev_value.sigval_ptr',
1118                                     define='HAVE_STRUCT_SIGEVENT_SIGEV_VALUE_SIGVAL_PTR',
1119                                     headers='signal.h');
1120
1121     if os.path.exists('/proc/sys/kernel/core_pattern'):
1122         conf.DEFINE('HAVE_SYS_KERNEL_PROC_CORE_PATTERN', '1')
1123
1124     if conf.CHECK_CODE('''
1125 #include <time.h>
1126 main() {
1127         struct tm *tm;
1128         if (sizeof(time_t) == 8) {
1129                 time_t max_time = 0x7fffffffffffffffll;
1130                 tm = gmtime(&max_time);
1131                 /* This should fail with 32-bit tm_year. */
1132                 if (tm == NULL) {
1133                         /* Max time_t that works with 32-bit int tm_year in struct tm. */
1134                         max_time = 67768036191676799ll;
1135                         tm = gmtime(&max_time);
1136                         if (tm) {
1137                                 exit(0);
1138                         }
1139                 }
1140         }
1141         exit(1);
1142 }''',
1143         '__TIME_T_MAX',
1144         addmain=False,
1145         execute=True,
1146         msg="Checking for the maximum value of the 'time_t' type"):
1147             conf.DEFINE('TIME_T_MAX', '67768036191676799ll')
1148
1149     conf.CHECK_CODE('''
1150 #if defined(HAVE_UNISTD_H)
1151 #include <unistd.h>
1152 #endif
1153 #include <sys/types.h>
1154 main() { dev_t dev = makedev(1,2); return 0; }
1155 ''',
1156         'HAVE_MAKEDEV',
1157         addmain=False,
1158         msg='Checking whether the macro for makedev is available')
1159
1160     conf.CHECK_CODE('''
1161 #include <stdio.h>
1162 #include <limits.h>
1163 #include <signal.h>
1164
1165 void exit_on_core(int ignored) {
1166         exit(1);
1167 }
1168
1169 main() {
1170         char *newpath;
1171         signal(SIGSEGV, exit_on_core);
1172         newpath = realpath("/tmp", NULL);
1173         exit((newpath != NULL) ? 0 : 1);
1174 }
1175 ''',
1176         'REALPATH_TAKES_NULL',
1177         addmain=False,
1178         execute=True,
1179         msg='Checking whether the realpath function allows a NULL argument')
1180
1181     conf.CHECK_CODE('''#include "../tests/ftruncate.c"''',
1182                     'HAVE_FTRUNCATE_EXTEND',
1183                     msg='Checking for ftruncate extend',
1184                     addmain=False,
1185                     execute=True)
1186     if os.getenv('RUN_FROM_BUILD_FARM'):
1187         Logs.info("enabling buildfarm hacks")
1188         conf.DEFINE('ENABLE_BUILD_FARM_HACKS', '1')
1189
1190     if Options.options.with_sendfile_support:
1191         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):
1192             conf.CHECK_CODE('''
1193                             int tofd, fromfd;
1194                             off64_t offset;
1195                             size_t total;
1196                             ssize_t nwritten = sendfile64(tofd, fromfd, &offset, total);
1197                             ''',
1198                             '_HAVE_SENDFILE64',
1199                             headers='sys/sendfile',
1200                             msg='Checking for linux sendfile64 support')
1201             conf.CHECK_CODE('''
1202                             int tofd, fromfd;
1203                             off_t offset;
1204                             size_t total;
1205                             ssize_t nwritten = sendfile(tofd, fromfd, &offset, total);
1206                             ''',
1207                             '_HAVE_SENDFILE',
1208                             headers='sys/sendfile',
1209                             msg='Checking for linux sendfile support')
1210
1211             # Try and cope with broken Linux sendfile....
1212             conf.CHECK_CODE('''#if defined(_FILE_OFFSET_BITS) && (_FILE_OFFSET_BITS == 64)
1213                             #undef _FILE_OFFSET_BITS
1214                             #endif
1215                             #include <sys/sendfile.h>
1216                             int tofd, fromfd;
1217                             off_t offset;
1218                             size_t total;
1219                             ssize_t nwritten = sendfile(tofd, fromfd, &offset, total);
1220                             ''',
1221                             '_HAVE_BROKEN_LINUX_SENDFILE',
1222                             msg='Checking for broken linux sendfile support')
1223             if conf.CONFIG_SET('_HAVE_SENDFILE64'):
1224                 conf.DEFINE('HAVE_SENDFILE64', '1')
1225                 conf.DEFINE('LINUX_SENDFILE_API', '1')
1226                 conf.DEFINE('WITH_SENDFILE', '1')
1227             elif conf.CONFIG_SET('_HAVE_SENDFILE'):
1228                 conf.DEFINE('HAVE_SENDFILE', '1')
1229                 conf.DEFINE('LINUX_SENDFILE_API', '1')
1230                 conf.DEFINE('WITH_SENDFILE', '1')
1231             elif conf.CONFIG_SET('_HAVE_BROKEN_LINUX_SENDFILE'):
1232                 conf.DEFINE('LINUX_BROKEN_SENDFILE_API', '1')
1233                 conf.DEFINE('WITH_SENDFILE', '1')
1234         elif (host_os.rfind('freebsd') > -1) or (host_os.rfind('dragonfly') > -1):
1235             conf.CHECK_CODE('''
1236                             #include <sys/types.h>
1237                             #include <unistd.h>
1238                             #include <sys/socket.h>
1239                             #include <sys/uio.h>
1240                             int fromfd, tofd, ret, total=0;
1241                             off_t offset, nwritten;
1242                             struct sf_hdtr hdr;
1243                             struct iovec hdtrl;
1244                             hdr.headers = &hdtrl;
1245                             hdr.hdr_cnt = 1;
1246                             hdr.trailers = NULL;
1247                             hdr.trl_cnt = 0;
1248                             hdtrl.iov_base = NULL;
1249                             hdtrl.iov_len = 0;
1250                             ret = sendfile(fromfd, tofd, offset, total, &hdr, &nwritten, 0)
1251                             ''',
1252                             '_HAVE_SENDFILE',
1253                             msg='Checking for freebsd sendfile support')
1254             if conf.CONFIG_SET('_HAVE_SENDFILE'):
1255                 conf.DEFINE('HAVE_SENDFILE', '1')
1256                 conf.DEFINE('FREEBSD_SENDFILE_API', '1')
1257                 conf.DEFINE('WITH_SENDFILE', '1')
1258         elif (host_os.rfind('hpux') > -1):
1259             conf.CHECK_CODE('''
1260                             #include <sys/socket.h>
1261                             #include <sys/uio.h>
1262                             int fromfd, tofd;
1263                             size_t total=0;
1264                             struct iovec hdtrl[2];
1265                             ssize_t nwritten;
1266                             off64_t offset;
1267                             hdtrl[0].iov_base = 0;
1268                             hdtrl[0].iov_len = 0;
1269                             nwritten = sendfile64(tofd, fromfd, offset, total, &hdtrl[0], 0);
1270                             ''',
1271                             '_HAVE_SENDFILE64',
1272                             msg='Checking for hpux sendfile64 support')
1273             conf.CHECK_CODE('''
1274                             #include <sys/socket.h>
1275                             #include <sys/uio.h>
1276                             int fromfd, tofd;
1277                             size_t total=0;
1278                             struct iovec hdtrl[2];
1279                             ssize_t nwritten;
1280                             off_t offset;
1281                             hdtrl[0].iov_base = 0;
1282                             hdtrl[0].iov_len = 0;
1283                             nwritten = sendfile(tofd, fromfd, offset, total, &hdtrl[0], 0);
1284                             ''',
1285                             '_HAVE_SENDFILE',
1286                             msg='Checking for hpux sendfile support')
1287             if conf.CONFIG_SET('_HAVE_SENDFILE64'):
1288                 conf.DEFINE('HAVE_SENDFILE64', '1')
1289                 conf.DEFINE('HPUX_SENDFILE_API', '1')
1290                 conf.DEFINE('WITH_SENDFILE', '1')
1291             elif conf.CONFIG_SET('_HAVE_SENDFILE'):
1292                 conf.DEFINE('HAVE_SENDFILE', '1')
1293                 conf.DEFINE('HPUX_SENDFILE_API', '1')
1294                 conf.DEFINE('WITH_SENDFILE', '1')
1295         elif (host_os.rfind('solaris') > -1):
1296             conf.CHECK_FUNCS_IN('sendfile', 'sendfilev')
1297             conf.CHECK_CODE('''
1298                             #include <sys/sendfile.h>
1299                             int sfvcnt;
1300                             size_t xferred;
1301                             struct sendfilevec vec[2];
1302                             ssize_t nwritten;
1303                             int tofd;
1304                             sfvcnt = 2;
1305                             vec[0].sfv_fd = SFV_FD_SELF;
1306                             vec[0].sfv_flag = 0;
1307                             vec[0].sfv_off = 0;
1308                             vec[0].sfv_len = 0;
1309                             vec[1].sfv_fd = 0;
1310                             vec[1].sfv_flag = 0;
1311                             vec[1].sfv_off = 0;
1312                             vec[1].sfv_len = 0;
1313                             nwritten = sendfilev64(tofd, vec, sfvcnt, &xferred);
1314                             ''',
1315                             '_HAVE_SENDFILEV64',
1316                             msg='Checking for solaris sendfilev64 support')
1317             conf.CHECK_CODE('''
1318                             #include <sys/sendfile.h>,
1319                             int sfvcnt;
1320                             size_t xferred;
1321                             struct sendfilevec vec[2];
1322                             ssize_t nwritten;
1323                             int tofd;
1324                             sfvcnt = 2;
1325                             vec[0].sfv_fd = SFV_FD_SELF;
1326                             vec[0].sfv_flag = 0;
1327                             vec[0].sfv_off = 0;
1328                             vec[0].sfv_len = 0;
1329                             vec[1].sfv_fd = 0;
1330                             vec[1].sfv_flag = 0;
1331                             vec[1].sfv_off = 0;
1332                             vec[1].sfv_len = 0;
1333                             nwritten = sendfilev(tofd, vec, sfvcnt, &xferred);
1334                             ''',
1335                             '_HAVE_SENDFILEV',
1336                             msg='Checking for solaris sendfilev support')
1337             if conf.CONFIG_SET('_HAVE_SENDFILEV64'):
1338                 conf.DEFINE('HAVE_SENDFILEV64', '1')
1339                 conf.DEFINE('SOLARIS_SENDFILE_API', '1')
1340                 conf.DEFINE('WITH_SENDFILE', '1')
1341             elif conf.CONFIG_SET('_HAVE_SENDFILEV'):
1342                 conf.DEFINE('HAVE_SENDFILEV', '1')
1343                 conf.DEFINE('SOLARIS_SENDFILE_API', '1')
1344                 conf.DEFINE('WITH_SENDFILE', '1')
1345         elif (host_os.rfind('aix') > -1):
1346             conf.CHECK_CODE('''
1347                             #include <sys/socket.h>
1348                             int fromfd, tofd;
1349                             size_t total=0;
1350                             struct sf_parms hdtrl;
1351                             ssize_t nwritten;
1352                             off64_t offset;
1353                             hdtrl.header_data = 0;
1354                             hdtrl.header_length = 0;
1355                             hdtrl.file_descriptor = fromfd;
1356                             hdtrl.file_offset = 0;
1357                             hdtrl.file_bytes = 0;
1358                             hdtrl.trailer_data = 0;
1359                             hdtrl.trailer_length = 0;
1360                             nwritten = send_file(&tofd, &hdtrl, 0);
1361                             ''',
1362                             '_HAVE_SENDFILE',
1363                             msg='Checking for AIX send_file support')
1364             if conf.CONFIG_SET('_HAVE_SENDFILE'):
1365                 conf.DEFINE('HAVE_SENDFILE', '1')
1366                 conf.DEFINE('AIX_SENDFILE_API', '1')
1367                 conf.DEFINE('WITH_SENDFILE', '1')
1368
1369     # Check for getcwd allowing a NULL arg.
1370     conf.CHECK_CODE('''
1371 #include <unistd.h>
1372 main() {
1373         char *s = getcwd(NULL,0);
1374         exit(s != NULL ?  0 : 1);
1375 }''', 'GETCWD_TAKES_NULL', addmain=False, execute=True,
1376         msg="getcwd takes a NULL argument")
1377
1378
1379     conf.CHECK_CODE('''enum TDB_ERROR err = TDB_ERR_NESTING''',
1380                     'HAVE_TDB_ERR_NESTING',
1381                     headers='tdb.h',
1382                     msg='Checking whether we have TDB_ERR_NESTING')
1383
1384     # UnixWare 7.x has its getspnam in -lgen
1385     conf.CHECK_FUNCS_IN('getspnam', 'gen')
1386     conf.CHECK_FUNCS_IN('getspnam', 'security')
1387     conf.CHECK_FUNCS_IN('getspnam', 'sec')
1388
1389     if Options.options.with_quotas:
1390         # For quotas on Veritas VxFS filesystems
1391         conf.CHECK_HEADERS('sys/fs/vx_quota.h')
1392         # For quotas on Linux XFS filesystems
1393         conf.CHECK_HEADERS('linux/dqblk_xfs.h')
1394         # For sys/quota.h and linux/quota.h
1395         conf.CHECK_HEADERS('sys/quota.h')
1396
1397
1398     #
1399     # checking for clustering extensions (CTDB)
1400     #
1401     if not Options.options.with_cluster_support:
1402         have_cluster_support = False
1403
1404     else:
1405
1406         if Options.options.ctdb_dir:
1407             conf.ADD_EXTRA_INCLUDES(Options.options.ctdb_dir + '/include')
1408
1409         srcdir = os.path.realpath(conf.srcdir)
1410         if 'EXTRA_INCLUDES' in conf.env:
1411             includes = ' '.join(conf.env['EXTRA_INCLUDES']).replace('#', srcdir + '/')
1412         else:
1413             includes = ''
1414
1415         have_cluster_support = True
1416         ctdb_broken = ""
1417
1418         conf.CHECK_CODE('''
1419             #define NO_CONFIG_H
1420             #include "replace.h"
1421             #include "system/wait.h"
1422             #include "system/network.h"
1423             #define private #error __USED_RESERVED_WORD_private__
1424             #include <talloc.h>
1425             #include <tdb.h>
1426             #include <ctdb.h>
1427
1428             int main(void)
1429             {
1430                 return 0;
1431             }
1432             ''',
1433             'HAVE_CTDB_H',
1434             addmain=False,
1435             includes=includes,
1436             msg='Checking for header ctdb.h')
1437
1438         if not conf.CONFIG_SET('HAVE_CTDB_H'):
1439             have_cluster_support = False
1440             ctdb_broken = "ctdb.h is required for cluster support"
1441
1442         if have_cluster_support:
1443             conf.CHECK_CODE('''
1444                 #define NO_CONFIG_H
1445                 #include "replace.h"
1446                 #include "system/wait.h"
1447                 #include "system/network.h"
1448                 #define private #error __USED_RESERVED_WORD_private__
1449                 #include <talloc.h>
1450                 #include <tdb.h>
1451                 #include <ctdb.h>
1452                 #include <ctdb_private.h>
1453
1454                 int main(void)
1455                 {
1456                     return 0;
1457                 }
1458                 ''',
1459                 'HAVE_CTDB_PRIVATE_H',
1460                 addmain=False,
1461                 includes=includes,
1462                 msg='Checking for header ctdb_private.h')
1463
1464             if not conf.CONFIG_SET('HAVE_CTDB_PRIVATE_H'):
1465                 have_cluster_support = False
1466                 ctdb_broken = "ctdb_private.h is required for cluster support"
1467
1468         if have_cluster_support:
1469             conf.CHECK_CODE('''
1470                 #define NO_CONFIG_H
1471                 #include "replace.h"
1472                 #include "system/wait.h"
1473                 #include "system/network.h"
1474                 #include <talloc.h>
1475                 #include <tdb.h>
1476                 #include <ctdb.h>
1477                 #include <ctdb_private.h>
1478
1479                 int main(void)
1480                 {
1481                    int i = (int)CTDB_CONTROL_TRANS3_COMMIT;
1482                    return 0;
1483                 }
1484                 ''',
1485                 'HAVE_CTDB_CONTROL_TRANS3_COMMIT_DECL',
1486                 addmain=False,
1487                 includes=includes,
1488                 msg='Checking for transaction support (TRANS3_COMMIT control)')
1489
1490             if not conf.CONFIG_SET('HAVE_CTDB_CONTROL_TRANS3_COMMIT_DECL'):
1491                 have_cluster_support = False
1492                 ctdb_broken = "ctdb transaction support missing or too old"
1493
1494         if have_cluster_support:
1495             conf.CHECK_CODE('''
1496                 #define NO_CONFIG_H
1497                 #include "replace.h"
1498                 #include "system/wait.h"
1499                 #include "system/network.h"
1500                 #include <talloc.h>
1501                 #include <tdb.h>
1502                 #include <ctdb.h>
1503                 #include <ctdb_private.h>
1504
1505                 int main(void)
1506                 {
1507                     int i = (int)CTDB_CONTROL_SCHEDULE_FOR_DELETION;
1508                     return 0;
1509                 }
1510                 ''',
1511                 'HAVE_CTDB_CONTROL_SCHEDULE_FOR_DELETION_DECL',
1512                 addmain=False,
1513                 includes=includes,
1514                 msg='Checking for SCHEDULE_FOR_DELETION control')
1515
1516             if not conf.CONFIG_SET('HAVE_CTDB_CONTROL_SCHEDULE_FOR_DELETION_DECL'):
1517                 if not Options.options.enable_old_ctdb:
1518                     have_cluster_support = False
1519                     ctdb_broken = "SCHEDULE_FOR_DELETION control missing"
1520                 else:
1521                     Logs.warn("ignoring missing SCHEDULE_FOR_DELETION control (--enable-old-ctdb)")
1522
1523         if have_cluster_support:
1524             conf.CHECK_CODE('''
1525                 #define NO_CONFIG_H
1526                 #include "replace.h"
1527                 #include "system/wait.h"
1528                 #include "system/network.h"
1529                 #include <talloc.h>
1530                 #include <tdb.h>
1531                 #include <ctdb.h>
1532                 #include <ctdb_private.h>
1533
1534                 int main(void)
1535                 {
1536                     struct ctdb_control_tcp _x;
1537                     return 0;
1538                 }
1539                 ''',
1540                 'HAVE_STRUCT_CTDB_CONTROL_TCP',
1541                 addmain=False,
1542                 includes=includes,
1543                 msg='Checking for ctdb ipv4 support')
1544
1545             if not conf.CONFIG_SET('HAVE_STRUCT_CTDB_CONTROL_TCP'):
1546                 have_cluster_support = False
1547                 ctdb_broken = "missing struct ctdb_control_tcp"
1548
1549         if have_cluster_support:
1550             conf.CHECK_CODE('''
1551                 #define NO_CONFIG_H
1552                 #include "replace.h"
1553                 #include "system/wait.h"
1554                 #include "system/network.h"
1555                 #include <talloc.h>
1556                 #include <tdb.h>
1557                 #include <ctdb.h>
1558                 #include <ctdb_private.h>
1559
1560                 int main(void)
1561                 {
1562                     struct ctdb_control_tcp_addr _x;
1563                     return 0;
1564                 }
1565                 ''',
1566                 'HAVE_STRUCT_CTDB_CONTROL_TCP_ADDR',
1567                 addmain=False,
1568                 includes=includes,
1569                 msg='Checking for ctdb ipv6 support')
1570
1571     if have_cluster_support:
1572         Logs.info("building with cluster support")
1573         conf.DEFINE('CLUSTER_SUPPORT', 1);
1574     else:
1575         if not Options.options.with_cluster_support:
1576             Logs.info("building without cluster support")
1577         else:
1578             Logs.warn("building without cluster support: " + ctdb_broken)
1579         conf.undefine('CLUSTER_SUPPORT')
1580
1581
1582
1583     conf.CHECK_CODE('__attribute__((destructor)) static void cleanup(void) { }',
1584                     'HAVE_FUNCTION_ATTRIBUTE_DESTRUCTOR',
1585                     addmain=False,
1586                     link=False,
1587                     msg='Checking whether we can compile with __attribute__((destructor))')
1588
1589     conf.CHECK_CODE('void seekdir(DIR *d, long loc) { return; }',
1590                     'SEEKDIR_RETURNS_VOID',
1591                     headers='sys/types.h dirent.h',
1592                     msg='Checking whether seekdir returns void')
1593
1594     if Options.options.with_profiling_data:
1595         conf.DEFINE('WITH_PROFILE', 1);
1596
1597     PTHREAD_CFLAGS='error'
1598     PTHREAD_LDFLAGS='error'
1599
1600     if PTHREAD_LDFLAGS == 'error':
1601         if conf.CHECK_FUNCS_IN('pthread_attr_init', 'pthread'):
1602             PTHREAD_CFLAGS='-D_REENTRANT -D_POSIX_PTHREAD_SEMANTICS'
1603             PTHREAD_LDFLAGS='-lpthread'
1604     if PTHREAD_LDFLAGS == 'error':
1605         if conf.CHECK_FUNCS_IN('pthread_attr_init', 'pthreads'):
1606             PTHREAD_CFLAGS='-D_THREAD_SAFE'
1607             PTHREAD_LDFLAGS='-lpthreads'
1608     if PTHREAD_LDFLAGS == 'error':
1609         if conf.CHECK_FUNCS_IN('pthread_attr_init', 'c_r'):
1610             PTHREAD_CFLAGS='-D_THREAD_SAFE -pthread'
1611             PTHREAD_LDFLAGS='-pthread'
1612     if PTHREAD_LDFLAGS == 'error':
1613         if conf.CHECK_FUNC('pthread_attr_init'):
1614             PTHREAD_CFLAGS='-D_REENTRANT'
1615             PTHREAD_LDFLAGS='-lpthread'
1616     # especially for HP-UX, where the CHECK_FUNC macro fails to test for
1617     # pthread_attr_init. On pthread_mutex_lock it works there...
1618     if PTHREAD_LDFLAGS == 'error':
1619         if conf.CHECK_FUNCS_IN('pthread_mutex_lock', 'pthread'):
1620             PTHREAD_CFLAGS='-D_REENTRANT'
1621             PTHREAD_LDFLAGS='-lpthread'
1622
1623     if PTHREAD_CFLAGS != 'error' and PTHREAD_LDFLAGS != 'error':
1624         conf.ADD_CFLAGS(PTHREAD_CFLAGS)
1625         conf.ADD_LDFLAGS(PTHREAD_LDFLAGS)
1626         conf.CHECK_HEADERS('pthread.h')
1627         conf.DEFINE('HAVE_PTHREAD', '1')
1628
1629     if Options.options.with_pthreadpool:
1630         if conf.CONFIG_SET('HAVE_PTHREAD'):
1631             conf.DEFINE('WITH_PTHREADPOOL', '1')
1632         else:
1633             Logs.warn("pthreadpool support cannot be enabled when pthread support was not found")
1634             conf.undefine('WITH_PTHREADPOOL')
1635
1636     if conf.CHECK_HEADERS('gpfs_gpl.h'):
1637         conf.DEFINE('HAVE_GPFS', '1')
1638
1639     # Note that all charset 'modules' must actually be static, due to dependency loop issues 
1640     # if we include the module loader in iconv
1641
1642     default_static_modules=TO_LIST('''pdb_smbpasswd pdb_tdbsam pdb_wbc_sam
1643                                       auth_sam auth_unix auth_winbind auth_wbc auth_server
1644                                       auth_domain auth_builtin vfs_default
1645                                       nss_info_template idmap_tdb idmap_passdb
1646                                       idmap_nss''')
1647
1648     default_shared_modules=TO_LIST('''vfs_recycle vfs_audit vfs_extd_audit vfs_full_audit vfs_netatalk
1649                                       vfs_fake_perms vfs_default_quota vfs_readonly vfs_cap
1650                                       vfs_expand_msdfs vfs_shadow_copy vfs_shadow_copy2 
1651                                       auth_script vfs_readahead vfs_xattr_tdb
1652                                       vfs_streams_xattr vfs_streams_depot vfs_acl_xattr vfs_acl_tdb
1653                                       vfs_smb_traffic_analyzer vfs_preopen vfs_catia vfs_scannedonly
1654                                       vfs_crossrename vfs_linux_xfs_sgid
1655                                       vfs_time_audit idmap_autorid''')
1656
1657     if Options.options.developer:
1658         default_static_modules.extend(TO_LIST('pdb_ads auth_netlogond charset_weird'))
1659         default_shared_modules.extend(TO_LIST('perfcount_test'))
1660
1661     default_static_modules.extend(TO_LIST('pdb_samba4 auth_samba4 vfs_dfs_samba4'))
1662
1663     if Options.options.with_acl_support and conf.CONFIG_SET('HAVE_POSIX_ACLS'):
1664         default_static_modules.extend(TO_LIST('vfs_posixacl'))
1665
1666     if conf.CONFIG_SET('HAVE_FREEBSD_SUNACL_H'):
1667         default_shared_modules.extend(TO_LIST('vfs_zfsacl'))
1668
1669     if conf.CONFIG_SET('HAVE_DIRFD_DECL'):
1670         default_shared_modules.extend(TO_LIST('vfs_syncops vfs_dirsort'))
1671
1672     if conf.CONFIG_SET('HAVE_STATFS_F_FSID'):
1673         default_shared_modules.extend(TO_LIST('vfs_fileid'))
1674
1675     if conf.CONFIG_SET('HAVE_AIO') and (conf.CONFIG_SET('HAVE_MSGHDR_MSG_CONTROL') or conf.CONFIG_SET('HAVE_MSGHDR_MSG_ACCTRIGHTS')):
1676         default_shared_modules.extend(TO_LIST('vfs_aio_fork'))
1677
1678     if conf.CONFIG_SET('HAVE_LDAP'):
1679         default_static_modules.extend(TO_LIST('pdb_ldap idmap_ldap'))
1680
1681     if conf.CONFIG_SET('DARWINOS'):
1682         default_static_modules.extend(TO_LIST('charset_macosxfs'))
1683
1684     if conf.CONFIG_SET('HAVE_GPFS'):
1685         default_shared_modules.extend(TO_LIST('vfs_gpfs vfs_gpfs_hsm_notify'))
1686
1687     explicit_shared_modules = TO_LIST(Options.options.shared_modules, delimiter=',')
1688     explicit_static_modules = TO_LIST(Options.options.static_modules, delimiter=',')
1689
1690     final_static_modules = default_static_modules
1691     final_shared_modules = default_shared_modules
1692
1693     for m in explicit_static_modules:
1694         if m in final_shared_modules:
1695             final_shared_modules.remove(m)
1696         final_static_modules.append(m)
1697     for m in explicit_shared_modules:
1698         if m in final_static_modules:
1699             final_static_modules.remove(m)
1700         final_shared_modules.append(m)
1701
1702     conf.env['static_modules'] = final_static_modules
1703     conf.env['shared_modules'] = final_shared_modules
1704
1705     conf.DEFINE('STRING_STATIC_MODULES', ' '.join(final_static_modules), quote=True)
1706
1707     static_list = {}
1708     shared_list = {}
1709
1710     prefixes = ['vfs', 'pdb', 'auth', 'nss_info', 'charset', 'idmap', 'gpext', 'perfcount']
1711     conf.env['MODULE_PREFIXES'] = prefixes
1712     for p in prefixes:
1713         for m in final_static_modules:
1714             if m.find(p) == 0:
1715                 if not p in static_list:
1716                     static_list[p] = []
1717                 static_list[p].append(m)
1718         for m in final_shared_modules:
1719             if m.find(p) == 0:
1720                 if not p in shared_list:
1721                     shared_list[p] = []
1722                 shared_list[p].append(m)
1723
1724     for p in prefixes:
1725         static_env = "%s_STATIC" % p.upper()
1726         shared_env = "%s_SHARED" % p.upper()
1727         conf.env[static_env] = []
1728         conf.env[shared_env] = []
1729         if p in static_list:
1730             decl_list=""
1731             for entry in static_list[p]:
1732                 decl_list += "extern NTSTATUS %s_init(void); " % entry
1733                 conf.env[static_env].append('%s' % entry)
1734             decl_list = decl_list.rstrip()
1735             conf.DEFINE('static_decl_%s' % p, decl_list)
1736             conf.DEFINE('static_init_%s' % p, '{ %s_init(); }' % '_init();  '.join(static_list[p]))
1737         else:
1738             conf.DEFINE('static_decl_%s' % p, '')
1739             conf.DEFINE('static_init_%s' % p, '{}')
1740         if p in shared_list:
1741             for entry in shared_list[p]:
1742                 conf.DEFINE('%s_init' % entry, 'samba_init_module')
1743                 conf.env[shared_env].append('%s' % entry)
1744
1745     conf.SAMBA_CONFIG_H('include/config.h')
1746
1747 def ctags(ctx):
1748     "build 'tags' file using ctags"
1749     import Utils
1750     source_root = os.path.dirname(Utils.g_module.root_path)
1751     cmd = 'ctags $(find %s/.. -name "*.[ch]" | grep -v "*_proto\.h")' % source_root
1752     print("Running: %s" % cmd)
1753     os.system(cmd)
1754