s3-waf: fix configure check for HAVE_LINUX_FALLOCATE.
[garming/samba-autobuild/.git] / source3 / wscript
1 #! /usr/bin/env python
2
3 srcdir=".."
4
5 import sys, os
6 from optparse import SUPPRESS_HELP
7 sys.path.insert(0, srcdir+"/buildtools/wafsamba")
8 sys.path.insert(0, "source3")
9 import wafsamba, Options, Logs, Utils, Scripting
10 import build.charset
11 import samba_utils, samba_version
12 import samba3
13
14 Options.default_prefix = '/usr/local/samba'
15
16 def set_options(opt):
17
18     opt.add_option('--with-static-modules',
19                    help=("Comma-separated list of names of modules to statically link in"),
20                    action="store", dest='static_modules', default=None)
21     opt.add_option('--with-shared-modules',
22                    help=("Comma-separated list of names of modules to build shared"),
23                    action="store", dest='shared_modules', default=None)
24     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                 int ret = fallocate(0, FALLOC_FL_KEEP_SIZE, 0, 10);''',
341                 'HAVE_LINUX_FALLOCATE',
342                 msg="Checking whether the Linux 'fallocate' function is available",
343                 headers='unistd.h sys/types.h fcntl.h linux/falloc.h')
344     if conf.CONFIG_SET('HAVE_FALLOCATE64'):
345         conf.CHECK_CODE('''
346                 #if defined(HAVE_UNISTD_H)
347                 #include <unistd.h>
348                 #endif
349                 #include <sys/types.h>
350                 #define _GNU_SOURCE
351                 #include <fcntl.h>
352                 #if defined(HAVE_LINUX_FALLOC_H)
353                 #include <linux/falloc.h>
354                 #endif
355                 int ret = fallocate64(0, FALLOC_FL_KEEP_SIZE, 0, 10);''',
356                 'HAVE_LINUX_FALLOCATE64',
357                 msg="Checking whether the Linux 'fallocate64' function is available")
358     conf.CHECK_CODE('''
359                 #if defined(HAVE_UNISTD_H)
360                 #include <unistd.h>
361                 #endif
362                 #include <fcntl.h>
363                 ssize_t err = readahead(0,0,0x80000);''',
364                 'HAVE_LINUX_READAHEAD',
365                 msg="Checking whether Linux readahead is available")
366     conf.CHECK_DECLS('readahead', headers='fcntl.h', always=True)
367
368     conf.CHECK_CODE('''
369                 struct ucred cred;
370                 socklen_t cred_len;
371                 int ret = getsockopt(0, SOL_SOCKET, SO_PEERCRED, &cred, &cred_len);''',
372                 'HAVE_PEERCRED',
373                 msg="Checking whether we can use SO_PEERCRED to get socket credentials",
374                 headers='sys/types.h sys/socket.h')
375
376     conf.CHECK_CODE('''
377                 #if defined(HAVE_LONGLONG) && (defined(HAVE_OFF64_T) || (defined(SIZEOF_OFF_T) && (SIZEOF_OFF_T == 8)))
378                 #include <sys/types.h>
379                 #else
380                 __COMPILE_ERROR_
381                 #endif
382                 int i;''',
383                 'HAVE_EXPLICIT_LARGEFILE_SUPPORT',
384                 msg="Checking whether large file support can be enabled")
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         conf.CHECK_CODE('struct aiocb64 a; return aio_read64(&a);',
395                         'HAVE_AIO64',
396                         msg='Checking for 64-bit asynchronous io support',
397                         headers='sys/types.h aio.h',
398                         lib='aio rt')
399         if conf.CONFIG_SET('HAVE_AIO64'):
400             conf.DEFINE('HAVE_AIOCB64', '1')
401             conf.DEFINE('WITH_AIO', '1')
402         elif conf.CONFIG_SET('HAVE_AIO'):
403             conf.DEFINE('WITH_AIO', '1')
404         if conf.CONFIG_SET('HAVE_AIO'):
405             conf.CHECK_CODE('struct aiocb a; return aio_read(&a);', 'HAVE_AIO_READ', msg='Checking for aio_read', headers='aio.h', lib='aio rt')
406             conf.CHECK_CODE('struct aiocb a; return aio_write(&a);', 'HAVE_AIO_WRITE', msg='Checking for aio_write', headers='aio.h', lib='aio rt')
407             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')
408             conf.CHECK_CODE('struct aiocb a; return aio_return(&a);', 'HAVE_AIO_RETURN', msg='Checking for aio_return', headers='aio.h', lib='aio rt')
409             conf.CHECK_CODE('struct aiocb a; return aio_error(&a);', 'HAVE_AIO_ERROR', msg='Checking for aio_error', headers='aio.h', lib='aio rt')
410             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')
411             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')
412         if conf.CONFIG_SET('HAVE_AIO64'):
413             conf.CHECK_CODE('struct aiocb a; return aio_read64(&a);', 'HAVE_AIO_READ64', msg='Checking for aio_read64', headers='aio.h', lib='aio rt')
414             conf.CHECK_CODE('struct aiocb a; return aio_write64(&a);', 'HAVE_AIO_WRITE64', msg='Checking for aio_write64', headers='aio.h', lib='aio rt')
415             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')
416             conf.CHECK_CODE('struct aiocb a; return aio_return64(&a);', 'HAVE_AIO_RETURN64', msg='Checking for aio_return64', headers='aio.h', lib='aio rt')
417             conf.CHECK_CODE('struct aiocb a; return aio_error64(&a);', 'HAVE_AIO_ERROR64', msg='Checking for aio_error64', headers='aio.h', lib='aio rt')
418             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')
419             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')
420         if not conf.CONFIG_SET('HAVE_AIO'):
421             conf.DEFINE('HAVE_NO_AIO', '1')
422     else:
423         conf.DEFINE('HAVE_NO_AIO', '1')
424
425     conf.CHECK_CODE('''
426 struct msghdr msg;
427 union {
428         struct cmsghdr cm;
429         char control[CMSG_SPACE(sizeof(int))];
430 } control_un;
431 msg.msg_control = control_un.control;
432 msg.msg_controllen = sizeof(control_un.control);
433 ''',
434         'HAVE_MSGHDR_MSG_CONTROL',
435         msg='Checking if we can use msg_control for passing file descriptors',
436         headers='sys/types.h stdlib.h stddef.h sys/socket.h sys/un.h')
437     conf.CHECK_CODE('''
438 struct msghdr msg;
439 int fd;
440 msg.msg_acctrights = (caddr_t) &fd;
441 msg.msg_acctrightslen = sizeof(fd);
442 ''',
443         'HAVE_MSGHDR_MSG_ACCTRIGHTS',
444         msg='Checking if we can use msg_acctrights for passing file descriptors',
445         headers='sys/types.h stdlib.h stddef.h sys/socket.h sys/un.h')
446
447     if Options.options.with_winbind:
448         conf.env.build_winbind = True
449         conf.DEFINE('WITH_WINBIND', '1')
450
451     conf.find_program('awk', var='AWK')
452     conf.find_program('perl', var='PERL')
453
454     # Darwin has extra options to xattr-family functions
455     conf.CHECK_CODE('getxattr(0, 0, 0, 0, 0, 0);',
456                     'XATTR_ADD_OPT',
457                     msg="Checking whether xattr interface takes additional options",
458                     headers='sys/types.h attr/xattr.h sys/xattr.h')
459
460     conf.CHECK_HEADERS('asm/types.h')
461
462     conf.CHECK_CODE('dev_t dev; int i = major(dev); return 0', "HAVE_DEVICE_MAJOR_FN",
463                     headers='unistd.h sys/types.h',
464                     msg="Checking for major macro")
465
466     conf.CHECK_CODE('dev_t dev; int i = minor(dev); return 0', "HAVE_DEVICE_MINOR_FN",
467                     headers='unistd.h sys/types.h',
468                     msg="Checking for minor macro")
469
470     conf.CHECK_STRUCTURE_MEMBER('struct dirent', 'd_off',
471                                 headers='unistd.h sys/types.h dirent.h',
472                                 define='HAVE_DIRENT_D_OFF')
473
474     conf.CHECK_FUNCS('setnetgrent getnetgrent endnetgrent')
475     if conf.CHECK_CFLAGS('-Werror-implicit-function-declaration'):
476         netgrent_cflags = '-Werror-implicit-function-declaration'
477     else:
478         netgrent_cflags = ''
479     conf.CHECK_CODE('setnetgrent("foo")', 'HAVE_SETNETGRENT_PROTOTYPE',
480                     msg="Checking for setnetgrent prototype",
481                     headers='netdb.h netgroup.h',
482                     cflags=netgrent_cflags)
483     conf.CHECK_CODE('getnetgrent', 'HAVE_GETNETGRENT_PROTOTYPE',
484                     msg="Checking for getnetgrent prototype",
485                     headers='netdb.h netgroup.h',
486                     cflags=netgrent_cflags)
487     conf.CHECK_CODE('endnetgrent', 'HAVE_ENDNETGRENT_PROTOTYPE',
488                     msg="Checking for endnetgrent prototype",
489                     headers='netdb.h netgroup.h',
490                     cflags=netgrent_cflags)
491
492
493     # Look for CUPS
494     if Options.options.with_cups:
495         conf.find_program('cups-config', var='CUPS_CONFIG')
496         if conf.env.CUPS_CONFIG:
497             # we would normally use --libs here, but cups-config incorrectly adds
498             # gssapi_krb5 and other libraries to its --libs output. That breaks the use
499             # of an in-tree heimdal kerberos
500             conf.check_cfg(path=conf.env.CUPS_CONFIG, args="--cflags --ldflags",
501                            package="", uselib_store="cups")
502         conf.CHECK_HEADERS('cups/cups.h cups/language.h', lib='cups')
503         conf.CHECK_FUNCS_IN('httpConnect httpConnectEncrypt', 'cups')
504         if conf.CONFIG_SET('HAVE_CUPS_CUPS_H') and conf.CONFIG_SET('HAVE_CUPS_LANGUAGE_H'):
505             conf.DEFINE('HAVE_CUPS', '1')
506         else:
507             conf.undefine('HAVE_CUPS')
508             conf.SET_TARGET_TYPE('cups', 'EMPTY')
509     else:
510         # define an empty subsystem for cups, to allow it to be used as an empty dependency
511         conf.SET_TARGET_TYPE('cups', 'EMPTY')
512
513     if Options.options.with_iprint:
514         if conf.CONFIG_SET('HAVE_CUPS'):
515             conf.DEFINE('HAVE_IPRINT', '1')
516         else:
517             Logs.warn("--enable-iprint=yes but cups support not sufficient")
518     if Options.options.with_syslog:
519         conf.DEFINE('WITH_SYSLOG', '1')
520     if Options.options.with_automount:
521         conf.DEFINE('WITH_AUTOMOUNT', '1')
522
523     # Check for LDAP
524     if Options.options.with_ldap:
525         conf.CHECK_HEADERS('ldap.h lber.h ldap_pvt.h')
526         conf.CHECK_TYPE('ber_tag_t', 'unsigned int', headers='ldap.h lber.h')
527         conf.CHECK_FUNCS_IN('ber_scanf ber_sockbuf_add_io', 'lber')
528         conf.CHECK_VARIABLE('LDAP_OPT_SOCKBUF', headers='ldap.h')
529
530         # if we LBER_OPT_LOG_PRINT_FN we can intercept ldap logging and print it out
531         # for the samba logs
532         conf.CHECK_VARIABLE('LBER_OPT_LOG_PRINT_FN',
533                             define='HAVE_LBER_LOG_PRINT_FN', headers='lber.h')
534
535         conf.CHECK_FUNCS_IN('ldap_init ldap_init_fd ldap_initialize ldap_set_rebind_proc', 'ldap')
536         conf.CHECK_FUNCS_IN('ldap_add_result_entry', 'ldap')
537
538         # Check if ldap_set_rebind_proc() takes three arguments
539         if conf.CHECK_CODE('ldap_set_rebind_proc(0, 0, 0)',
540                            'LDAP_SET_REBIND_PROC_ARGS',
541                            msg="Checking whether ldap_set_rebind_proc takes 3 arguments",
542                            headers='ldap.h lber.h', link=False):
543             conf.DEFINE('LDAP_SET_REBIND_PROC_ARGS', '3')
544         else:
545             conf.DEFINE('LDAP_SET_REBIND_PROC_ARGS', '2')
546
547         # last but not least, if ldap_init() exists, we want to use ldap
548         if conf.CONFIG_SET('HAVE_LDAP_INIT'):
549             conf.DEFINE('HAVE_LDAP', '1')
550             conf.DEFINE('LDAP_DEPRECATED', '1')
551             conf.env['HAVE_LDAP'] = '1'
552             # if ber_sockbuf_add_io() and LDAP_OPT_SOCKBUF are available, we can add
553             # SASL wrapping hooks
554             if conf.CONFIG_SET('HAVE_BER_SOCKBUF_ADD_IO') and \
555                     conf.CONFIG_SET('HAVE_LDAP_OPT_SOCKBUF'):
556                 conf.DEFINE('HAVE_LDAP_SASL_WRAPPING', '1')
557     else:
558         conf.SET_TARGET_TYPE('ldap', 'EMPTY')
559         conf.SET_TARGET_TYPE('lber', 'EMPTY')
560
561     # Check for kerberos
562     have_gssapi=False
563     if Options.options.with_mit_krb5_checks and conf.env.developer:
564         Logs.info("Looking for kerberos features")
565         conf.find_program('krb5-config', var='KRB5_CONFIG')
566         if conf.env.KRB5_CONFIG:
567             conf.check_cfg(path="krb5-config", args="--cflags --libs",
568                        package="gssapi", uselib_store="krb5")
569         conf.CHECK_HEADERS('krb5.h krb5/locate_plugin.h', lib='krb5')
570         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')
571
572         if conf.CONFIG_SET('HAVE_KRB5_LOCATE_PLUGIN_H'):
573             conf.env['WINBIND_KRB5_LOCATOR'] = 'bin/winbind_krb5_locator.so'
574
575         conf.CHECK_FUNCS_IN('_et_list', 'com_err')
576         conf.CHECK_FUNCS_IN('krb5_encrypt_data', 'k5crypto')
577         conf.CHECK_FUNCS_IN('des_set_key','crypto')
578         conf.CHECK_FUNCS_IN('copy_Authenticator', 'asn1')
579         conf.CHECK_FUNCS_IN('roken_getaddrinfo_hostspec', 'roken')
580         if conf.CHECK_FUNCS_IN('gss_display_status', 'gssapi') or \
581            conf.CHECK_FUNCS_IN('gss_display_status', 'gssapi_krb5'):
582             have_gssapi=True
583         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')
584         conf.CHECK_FUNCS_IN('krb5_mk_req_extended krb5_kt_compare', 'krb5')
585         conf.CHECK_FUNCS('''
586 krb5_set_real_time krb5_set_default_in_tkt_etypes krb5_set_default_tgs_enctypes
587 krb5_set_default_tgs_ktypes krb5_principal2salt krb5_use_enctype
588 krb5_string_to_key krb5_get_pw_salt krb5_string_to_key_salt krb5_auth_con_setkey
589 krb5_auth_con_setuseruserkey krb5_locate_kdc krb5_get_permitted_enctypes
590 krb5_get_default_in_tkt_etypes krb5_free_data_contents
591 krb5_principal_get_comp_string krb5_free_unparsed_name
592 krb5_free_keytab_entry_contents krb5_kt_free_entry krb5_krbhst_init
593 krb5_krbhst_get_addrinfo krb5_c_enctype_compare krb5_enctypes_compatible_keys
594 krb5_crypto_init krb5_crypto_destroy krb5_decode_ap_req free_AP_REQ
595 krb5_verify_checksum krb5_c_verify_checksum krb5_principal_compare_any_realm
596 krb5_parse_name_norealm krb5_princ_size krb5_get_init_creds_opt_set_pac_request
597 krb5_get_renewed_creds krb5_get_kdc_cred krb5_free_error_contents
598 initialize_krb5_error_table krb5_get_init_creds_opt_alloc
599 krb5_get_init_creds_opt_free krb5_get_init_creds_opt_get_error
600 krb5_enctype_to_string krb5_fwd_tgt_creds krb5_auth_con_set_req_cksumtype
601 krb5_get_creds_opt_alloc krb5_get_creds_opt_set_impersonate krb5_get_creds
602 krb5_get_credentials_for_user krb5_get_host_realm krb5_free_host_realm''',
603                          lib='krb5 k5crypto')
604         conf.CHECK_DECLS('''krb5_get_credentials_for_user
605                             krb5_auth_con_set_req_cksumtype''',
606                             headers='krb5.h', always=True)
607         conf.CHECK_VARIABLE('AP_OPTS_USE_SUBKEY', headers='krb5.h')
608         conf.CHECK_VARIABLE('KV5M_KEYTAB', headers='krb5.h')
609         conf.CHECK_VARIABLE('KRB5_KU_OTHER_CKSUM', headers='krb5.h')
610         conf.CHECK_VARIABLE('KRB5_KEYUSAGE_APP_DATA_CKSUM', headers='krb5.h')
611         conf.CHECK_STRUCTURE_MEMBER('krb5_keytab_entry', 'key', headers='krb5.h',
612                                     define='HAVE_KRB5_KEYTAB_ENTRY_KEY')
613         conf.CHECK_STRUCTURE_MEMBER('krb5_keytab_entry', 'keyblock', headers='krb5.h',
614                                     define='HAVE_KRB5_KEYTAB_ENTRY_KEYBLOCK')
615         conf.CHECK_STRUCTURE_MEMBER('krb5_address', 'magic', headers='krb5.h',
616                                     define='HAVE_MAGIC_IN_KRB5_ADDRESS')
617         conf.CHECK_STRUCTURE_MEMBER('krb5_address', 'addrtype', headers='krb5.h',
618                                     define='HAVE_ADDRTYPE_IN_KRB5_ADDRESS')
619         conf.CHECK_STRUCTURE_MEMBER('krb5_ticket', 'enc_part2', headers='krb5.h',
620                                     define='HAVE_KRB5_TKT_ENC_PART2')
621         conf.CHECK_STRUCTURE_MEMBER('krb5_creds', 'keyblock', headers='krb5.h',
622                                     define='HAVE_KRB5_KEYBLOCK_IN_CREDS')
623         conf.CHECK_STRUCTURE_MEMBER('krb5_creds', 'session', headers='krb5.h',
624                                     define='HAVE_KRB5_SESSION_IN_CREDS')
625         conf.CHECK_STRUCTURE_MEMBER('krb5_ap_req', 'ticket', headers='krb5.h',
626                                     define='HAVE_TICKET_POINTER_IN_KRB5_AP_REQ')
627
628         conf.CHECK_TYPE('krb5_encrypt_block', headers='krb5.h')
629
630         conf.CHECK_CODE('''
631 krb5_ticket ticket;
632 krb5_kvno kvno;
633 krb5_enctype enctype;
634 enctype = ticket.enc_part.enctype;
635 kvno = ticket.enc_part.kvno;
636 ''',
637                         'KRB5_TICKET_HAS_KEYINFO',
638                         headers='krb5.h', link=False,
639                         msg="Checking whether the krb5_ticket structure contains the kvno and enctype")
640         conf.CHECK_CODE('''
641 krb5_context ctx;
642 krb5_get_init_creds_opt *opt = NULL;
643 krb5_get_init_creds_opt_free(ctx, opt);
644 ''',
645                         'KRB5_CREDS_OPT_FREE_REQUIRES_CONTEXT',
646                         headers='krb5.h', link=False,
647                         msg="Checking whether krb5_get_init_creds_opt_free takes a context argument")
648         conf.CHECK_CODE('krb5_mk_error(0,0,0)',
649                         'HAVE_SHORT_KRB5_MK_ERROR_INTERFACE',
650                         headers='krb5.h', link=False,
651                         msg="Checking whether krb5_mk_error takes 3 arguments MIT or 9 Heimdal")
652         conf.CHECK_CODE('''
653 const krb5_data *pkdata;
654 krb5_context context;
655 krb5_principal principal;
656 pkdata = krb5_princ_component(context, principal, 0);
657 ''',
658                         'HAVE_KRB5_PRINC_COMPONENT',
659                         headers='krb5.h', lib='krb5',
660                         msg="Checking whether krb5_princ_component is available")
661
662         conf.CHECK_CODE('''
663 int main(void) {
664 char buf[256];
665 krb5_enctype_to_string(1, buf, 256);
666 return 0;
667 }''',
668                         'HAVE_KRB5_ENCTYPE_TO_STRING_WITH_SIZE_T_ARG',
669                         headers='krb5.h', lib='krb5 k5crypto',
670                         addmain=False, cflags='-Werror',
671                         msg="Checking whether krb5_enctype_to_string takes size_t argument")
672
673         conf.CHECK_CODE('''
674 int main(void) {
675 krb5_context context = NULL;
676 char *str = NULL;
677 krb5_enctype_to_string(context, 1, &str);
678 if (str) free (str);
679 return 0;
680 }''',
681                         'HAVE_KRB5_ENCTYPE_TO_STRING_WITH_KRB5_CONTEXT_ARG',
682                         headers='krb5.h stdlib.h', lib='krb5',
683                         addmain=False, cflags='-Werror',
684                         msg="Checking whether krb5_enctype_to_string takes krb5_context argument")
685         conf.CHECK_CODE('''
686 int main(void) {
687 krb5_context ctx = NULL;
688 krb5_principal princ = NULL;
689 const char *str = krb5_princ_realm(ctx, princ)->data;
690 return 0;
691 }''',
692                         'HAVE_KRB5_PRINC_REALM',
693                         headers='krb5.h', lib='krb5',
694                         addmain=False,
695                         msg="Checking whether the macro krb5_princ_realm is defined")
696         conf.CHECK_CODE('''
697 int main(void) {
698     krb5_context context;
699     krb5_principal principal;
700     const char *realm; realm = krb5_principal_get_realm(context, principal);
701     return 0;
702 }''',
703                         'HAVE_KRB5_PRINCIPAL_GET_REALM',
704                         headers='krb5.h', lib='krb5',
705                         addmain=False,
706                         msg="Checking whether krb5_principal_get_realm is defined")
707         if conf.CHECK_CODE('''krb5_verify_checksum(0, 0, 0, 0, 0, 0, 0);''',
708                         'KRB5_VERIFY_CHECKSUM_ARGS',
709                         headers='krb5.h', lib='krb5',
710                         msg="Checking whether krb5_verify_checksum takes 7 arguments"):
711             conf.DEFINE('KRB5_VERIFY_CHECKSUM_ARGS', '7')
712         else:
713             conf.DEFINE('KRB5_VERIFY_CHECKSUM_ARGS', '6')
714
715         conf.CHECK_CODE('''
716 krb5_enctype enctype;
717 enctype = ENCTYPE_ARCFOUR_HMAC_MD5;
718 ''',
719             '_HAVE_ENCTYPE_ARCFOUR_HMAC_MD5',
720             headers='krb5.h', lib='krb5',
721             msg="Checking whether the ENCTYPE_ARCFOUR_HMAC_MD5 key type definition is available");
722         conf.CHECK_CODE('''
723 krb5_keytype keytype;
724 keytype = KEYTYPE_ARCFOUR_56;
725 ''',
726             '_HAVE_KEYTYPE_ARCFOUR_56',
727             headers='krb5.h', lib='krb5',
728             msg="Checking whether the HAVE_KEYTYPE_ARCFOUR_56 key type definition is available");
729         if conf.CONFIG_SET('_HAVE_ENCTYPE_ARCFOUR_HMAC_MD5') and conf.CONFIG_SET('_HAVE_KEYTYPE_ARCFOUR_56'):
730             conf.DEFINE('HAVE_ENCTYPE_ARCFOUR_HMAC_MD5', '1')
731
732         conf.CHECK_CODE('''
733 krb5_enctype enctype;
734 enctype = ENCTYPE_ARCFOUR_HMAC;
735 ''',
736             'HAVE_ENCTYPE_ARCFOUR_HMAC',
737             headers='krb5.h', lib='krb5',
738             msg="Checking whether the ENCTYPE_ARCFOUR_HMAC key type definition is available");
739
740         conf.CHECK_CODE('''
741 krb5_context context;
742 krb5_keytab keytab;
743 krb5_init_context(&context);
744 return krb5_kt_resolve(context, "WRFILE:api", &keytab);
745 ''',
746             'HAVE_WRFILE_KEYTAB',
747             headers='krb5.h', lib='krb5', execute=True,
748             msg="Checking whether the WRFILE:-keytab is supported");
749
750         # Check for KRB5_DEPRECATED handling
751         conf.CHECK_CODE('''#define KRB5_DEPRECATED 1
752 #include <krb5.h>''',
753         'HAVE_KRB5_DEPRECATED_WITH_IDENTIFIER', addmain=False,
754         link=False,
755         msg="Checking for KRB5_DEPRECATED define taking an identifier")
756
757     if Options.options.with_ads:
758         use_ads=True
759         if not conf.CONFIG_SET('HAVE_ENCTYPE_ARCFOUR_HMAC_MD5') and \
760            not conf.CONFIG_SET('HAVE_ENCTYPE_ARCFOUR_HMAC'):
761             Logs.warn("arcfour-hmac-md5 encryption type not found in -lkrb5")
762             use_ads=False
763         if not conf.CONFIG_SET('HAVE_KRB5_MK_REQ_EXTENDED'):
764             Logs.warn("krb5_mk_req_extended not found in -lkrb5")
765             use_ads=False
766         if not conf.CONFIG_SET('HAVE_KRB5_PRINCIPAL2SALT') and \
767            not conf.CONFIG_SET('HAVE_KRB5_GET_PW_SALT'):
768             Logs.warn("no CREATE_KEY_FUNCTIONS detected")
769             use_ads=False
770         if not conf.CONFIG_SET('HAVE_KRB5_GET_PERMITTED_ENCTYPES') and \
771            not conf.CONFIG_SET('HAVE_KRB5_GET_DEFAULT_IN_TKT_ETYPES'):
772             Logs.warn("no GET_ENCTYPES_FUNCTIONS detected")
773             use_ads=False
774         if not conf.CONFIG_SET('HAVE_KRB5_KT_FREE_ENTRY') and \
775            not conf.CONFIG_SET('HAVE_KRB5_FREE_KEYTAB_ENTRY_CONTENTS'):
776             Logs.warn("no KT_FREE_FUNCTION detected")
777             use_ads=False
778         if not conf.CONFIG_SET('HAVE_KRB5_C_VERIFY_CHECKSUM') and \
779            not conf.CONFIG_SET('HAVE_KRB5_VERIFY_CHECKSUM'):
780             Logs.warn("no KRB5_VERIFY_CHECKSUM_FUNCTION detected")
781             use_ads=False
782         if not conf.CONFIG_SET('KRB5_TICKET_HAS_KEYINFO'):
783             # We only need the following functions if we can't get the enctype
784             # and kvno out of the ticket directly (ie. on Heimdal).
785             if not conf.CONFIG_SET('HAVE_FREE_AP_REQ'):
786                 Logs.warn("no KRB5_AP_REQ_FREE_FUNCTION detected")
787                 use_ads=False
788             if not conf.CONFIG_SET('HAVE_KRB5_DECODE_AP_REQ'):
789                 Logs.warn("no KRB5_AP_REQ_DECODING_FUNCTION detected")
790                 use_ads=False
791         if use_ads:
792             conf.DEFINE('WITH_ADS', '1')
793             conf.DEFINE('HAVE_KRB5', '1')
794             if have_gssapi:
795                 conf.DEFINE('HAVE_GSSAPI', '1')
796             if conf.CONFIG_SET('HAVE_LDAP'):
797                 conf.env['HAVE_ADS'] = '1'
798         else:
799             Logs.warn("krb5 libs don't have all features required for Active Directory support")
800             conf.undefine('HAVE_KRB5_H')
801             conf.undefine('HAVE_GSSAPI_H')
802             conf.undefine('HAVE_GSSAPI_GSSAPI_GENERIC_H')
803             conf.undefine('HAVE_GSSAPI_GSSAPI_H')
804
805     if Options.options.with_utmp:
806         conf.CHECK_FUNCS('pututline pututxline updwtmp updwtmpx getutmpx getutxent')
807         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_name', headers='utmp.h',
808                                     define='HAVE_UT_UT_NAME')
809         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_user', headers='utmp.h',
810                                     define='HAVE_UT_UT_USER')
811         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_id', headers='utmp.h',
812                                     define='HAVE_UT_UT_ID')
813         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_host', headers='utmp.h',
814                                     define='HAVE_UT_UT_HOST')
815         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_time', headers='utmp.h',
816                                     define='HAVE_UT_UT_TIME')
817         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_tv', headers='utmp.h',
818                                     define='HAVE_UT_UT_TV')
819         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_type', headers='utmp.h',
820                                     define='HAVE_UT_UT_TYPE')
821         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_pid', headers='utmp.h',
822                                     define='HAVE_UT_UT_PID')
823         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_exit.e_exit', headers='utmp.h',
824                                     define='HAVE_UT_UT_EXIT')
825         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_addr_v6', headers='utmp.h',
826                                     define='HAVE_UT_UT_ADDR_V6')
827         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_addr', headers='utmp.h',
828                                     define='HAVE_UT_UT_ADDR')
829         conf.CHECK_STRUCTURE_MEMBER('struct utmpx', 'ut_syslen', headers='utmpx.h',
830                                     define='HAVE_UX_UT_SYSLEN')
831         conf.CHECK_CODE('struct utmp utarg; struct utmp *utreturn; utreturn = pututline(&utarg);',
832                         'PUTUTLINE_RETURNS_UTMP', headers='utmp.h',
833                         msg="Checking whether pututline returns pointer")
834         conf.DEFINE('WITH_UTMP', 1)
835
836     if Options.options.with_avahi:
837         conf.env.with_avahi = True
838         if not conf.CHECK_HEADERS('avahi-common/watch.h avahi-client/client.h'): conf.env.with_avahi = False
839         if not conf.CHECK_FUNCS_IN('avahi_client_new', 'avahi-client'): conf.env.with_avahi = False
840         if not conf.CHECK_FUNCS_IN('avahi_strerror', 'avahi-common'): conf.env.with_avahi = False
841         if conf.env.with_avahi:
842             conf.DEFINE('WITH_AVAHI_SUPPORT', 1)
843     else:
844         conf.SET_TARGET_TYPE('avahi-common', 'EMPTY')
845         conf.SET_TARGET_TYPE('avahi-client', 'EMPTY')
846
847     if Options.options.with_iconv:
848         conf.env.with_iconv = True
849         if not conf.CHECK_FUNCS_IN('iconv_open', 'iconv', headers='iconv.h'):
850             conf.env.with_iconv = False
851         if conf.env.with_iconv:
852             conf.DEFINE('HAVE_ICONV', 1)
853
854     if Options.options.with_pam:
855         use_pam=True
856         conf.CHECK_HEADERS('security/pam_appl.h pam/pam_appl.h')
857         if not conf.CONFIG_SET('HAVE_SECURITY_PAM_APPL_H') and not conf.CONFIG_SET('HAVE_PAM_PAM_APPL_H'):
858             Logs.warn("--with-pam=yes but pam_appl.h not found")
859             use_pam=False
860         conf.CHECK_FUNCS_IN('pam_get_data', 'pam')
861         conf.CHECK_HEADERS('security/pam_modules.h pam/pam_modules.h')
862         if not conf.CONFIG_SET('HAVE_SECURITY_PAM_MODULES_H') and not conf.CONFIG_SET('HAVE_PAM_PAM_MODULES_H'):
863             Logs.warn("--with-pam=yes but pam_modules.h not found")
864             use_pam=False
865         conf.CHECK_HEADERS('security/pam_ext.h security/_pam_macros.h')
866         conf.CHECK_HEADERS('pam/pam_ext.h pam/_pam_macros.h')
867         conf.CHECK_FUNCS_IN('pam_vsyslog', 'pam')
868         conf.CHECK_CODE('''
869 #if defined(HAVE_SECURITY_PAM_APPL_H)
870 #include <security/pam_appl.h>
871 #elif defined(HAVE_PAM_PAM_APPL_H)
872 #include <pam/pam_appl.h>
873 #endif
874 pam_set_item(0, PAM_RHOST, 0);
875 ''',
876             'HAVE_PAM_RHOST',
877             lib='pam',
878             msg="Checking whether PAM_RHOST is available");
879         conf.CHECK_CODE('''
880 #if defined(HAVE_SECURITY_PAM_APPL_H)
881 #include <security/pam_appl.h>
882 #elif defined(HAVE_PAM_PAM_APPL_H)
883 #include <pam/pam_appl.h>
884 #endif
885 pam_set_item(0, PAM_TTY, 0);
886 ''',
887             'HAVE_PAM_TTY',
888             lib='pam',
889             msg="Checking whether PAM_TTY is available");
890         conf.CHECK_CODE('''
891 #if (!defined(LINUX))
892
893 #define PAM_EXTERN extern
894 #if defined(HAVE_SECURITY_PAM_APPL_H)
895 #include <security/pam_appl.h>
896 #elif defined(HAVE_PAM_PAM_APPL_H)
897 #include <pam/pam_appl.h>
898 #endif
899
900 #endif
901
902 #if defined(HAVE_SECURITY_PAM_MODULES_H)
903 #include <security/pam_modules.h>
904 #elif defined(HAVE_PAM_PAM_MODULES_H)
905 #include <pam/pam_modules.h>
906 #endif
907
908 #if defined(HAVE_SECURITY__PAM_MACROS_H)
909 #include <security/_pam_macros.h>
910 #elif defined(HAVE_PAM__PAM_MACROS_H)
911 #include <pam/_pam_macros.h>
912 #endif
913
914 #ifdef HAVE_SECURITY_PAM_EXT_H
915 #include <security/pam_ext.h>
916 #endif
917
918 int i; i = PAM_RADIO_TYPE;
919 ''',
920             'HAVE_PAM_RADIO_TYPE',
921             lib='pam',
922             msg="Checking whether PAM_RADIO_TYPE is available");
923         if use_pam:
924             conf.DEFINE('WITH_PAM', 1)
925             conf.DEFINE('WITH_PAM_MODULES', 1)
926
927     seteuid = False
928     if not seteuid:
929         seteuid = conf.CHECK_CODE('''
930                                 #define AUTOCONF_TEST 1
931                                 #define USE_SETREUID 1
932                                 #include "./lib/util_sec.c"
933                                 ''',
934                                 'USE_SETREUID',
935                                 addmain=False,
936                                 execute=True,
937                                 msg="Checking whether setreuid is available")
938     if not seteuid:
939         seteuid = conf.CHECK_CODE('''
940                                 #define AUTOCONF_TEST 1
941                                 #define USE_SETRESUID 1
942                                 #include "./lib/util_sec.c"
943                                 ''',
944                                 'USE_SETRESUID',
945                                 addmain=False,
946                                 execute=True,
947                                 msg="Checking whether setresuid is available")
948     if not seteuid:
949         seteuid = conf.CHECK_CODE('''
950                                 #define AUTOCONF_TEST 1
951                                 #define USE_SETEUID 1
952                                 #include "./lib/util_sec.c"
953                                 ''',
954                                 'USE_SETEUID',
955                                 addmain=False,
956                                 execute=True,
957                                 msg="Checking whether seteuid is available")
958     if not seteuid:
959         seteuid = conf.CHECK_CODE('''
960                                 #define AUTOCONF_TEST 1
961                                 #define USE_SETUIDX 1
962                                 #include "./lib/util_sec.c"
963                                 ''',
964                                 'USE_SETUIDX',
965                                 addmain=False,
966                                 execute=True,
967                                 mandatory=True,
968                                 msg="Checking whether setuidx is available")
969     if Options.options.with_dnsupdate:
970         conf.CHECK_HEADERS('uuid/uuid.h')
971         conf.CHECK_FUNCS_IN('uuid_generate', 'uuid')
972         if not conf.CONFIG_SET('HAVE_UUID_UUID_H') and not conf.CONFIG_SET('HAVE_UUID_GENERATE'):
973             Logs.warn("--with-dnsupdate=yes but uuid support not sufficient")
974         elif not conf.CONFIG_SET('HAVE_GSSAPI'):
975             Logs.warn("--with-dnsupdate=yes but gssapi support not sufficient")
976         else:
977             conf.DEFINE('WITH_DNS_UPDATES', 1)
978     else:
979         conf.SET_TARGET_TYPE('uuid', 'EMPTY')
980     conf.CHECK_HEADERS('valgrind.h valgrind/valgrind.h valgrind/memcheck.h')
981     if Options.options.developer:
982         if conf.CONFIG_SET('HAVE_VALGRIND_H') or conf.CONFIG_SET('HAVE_VALGRIND_VALGRIND_H'):
983             conf.DEFINE('VALGRIND', '1')
984
985     if conf.CHECK_CODE('''
986 #include <bits/sockaddr.h>
987 #include <linux/netlink.h>
988 ''',
989                 'HAVE_LINUX_NETLINK_H',
990                 msg="Checking whether Linux netlink is available"):
991         conf.CHECK_CODE('''
992 #include <bits/sockaddr.h>
993 #include <linux/netlink.h>
994 #include <linux/rtnetlink.h>
995 ''',
996                 'HAVE_LINUX_RTNETLINK_H',
997                 msg='Checking whether Linux rtnetlink is available')
998     if conf.CHECK_TYPE('struct dirent64', headers='sys/types.h dirent.h') and conf.CONFIG_SET('HAVE_READDIR64'):
999         conf.DEFINE('HAVE_STRUCT_DIRENT64', '1')
1000     else:
1001         conf.undefine('HAVE_STRUCT_DIRENT64')
1002
1003     conf.CHECK_CODE('''
1004 #include "../tests/fcntl_lock.c"
1005 ''',
1006                 'HAVE_FCNTL_LOCK',
1007                 addmain=False,
1008                 execute=True,
1009                 msg='Checking whether fcntl locking is available')
1010
1011     conf.CHECK_CODE('''
1012 #include "../tests/fcntl_lock64.c"
1013 ''',
1014                 'HAVE_BROKEN_FCNTL64_LOCKS',
1015                 addmain=False,
1016                 execute=True,
1017                 msg='Checking whether fcntl64 locks are broken')
1018
1019     if not conf.CONFIG_SET('HAVE_BROKEN_FCNTL64_LOCKS'):
1020         conf.CHECK_CODE('''
1021 #if defined(HAVE_UNISTD_H)
1022 #include <unistd.h>
1023 #endif
1024 #include <stdio.h>
1025 #include <stdlib.h>
1026
1027 #ifdef HAVE_FCNTL_H
1028 #include <fcntl.h>
1029 #endif
1030
1031 #ifdef HAVE_SYS_FCNTL_H
1032 #include <sys/fcntl.h>
1033 #endif
1034 main() { struct flock64 fl64;
1035 #if defined(F_SETLKW64) && defined(F_SETLK64) && defined(F_GETLK64)
1036 exit(0);
1037 #else
1038 exit(1);
1039 #endif
1040 }
1041 ''',
1042                 'HAVE_STRUCT_FLOCK64',
1043                 addmain=False,
1044                 execute=True,
1045                 msg="Checking whether the flock64 struct is available")
1046
1047     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_mtim.tv_nsec',
1048                                 define='HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC') # Linux, Solaris
1049     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_mtimensec',
1050                                 define='HAVE_STRUCT_STAT_ST_MTIMENSEC') # BSD, if defined _POSIX_SOURCE
1051     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_mtimespec.tv_nsec',
1052                                 define='HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC') # BSD, if not defined _POSIX_SOURCE
1053     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_mtime_n',
1054                                 define='HAVE_STRUCT_STAT_ST_MTIME_N') # AIX
1055     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_umtime',
1056                                 define='HAVE_STRUCT_STAT_ST_UMTIME') # Tru64
1057     if conf.CONFIG_SET('HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC') or \
1058        conf.CONFIG_SET('HAVE_STRUCT_STAT_ST_MTIMENSEC') or \
1059        conf.CONFIG_SET('HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC') or \
1060        conf.CONFIG_SET('HAVE_STRUCT_STAT_ST_MTIME_N') or \
1061        conf.CONFIG_SET('HAVE_STRUCT_STAT_ST_UMTIME'):
1062         conf.DEFINE('HAVE_STAT_HIRES_TIMESTAMPS', '1')
1063
1064     # recent FreeBSD, NetBSD have creation timestamps called birthtime:
1065     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_birthtime',
1066                                 define='HAVE_STRUCT_STAT_ST_BIRTHTIME')
1067     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_birthtimespec.tv_nsec',
1068                                 define='HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC')
1069     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_birthtimensec',
1070                                 define='HAVE_STRUCT_STAT_ST_BIRTHTIMENSEC')
1071
1072     conf.CHECK_CODE('''
1073 ssize_t err = posix_fadvise(0,0,0x80000,POSIX_FADV_WILLNEED);
1074 ''',
1075                 'HAVE_POSIX_FADVISE',
1076                 msg='Checking whether posix_fadvise is available',
1077                 headers='unistd.h fcntl.h')
1078
1079     for v in ['_SC_NGROUPS_MAX', '_SC_NPROC_ONLN', '_SC_NPROCESSORS_ONLN', '_SC_PAGESIZE' ]:
1080         conf.CHECK_CODE('''
1081                         #include <unistd.h>
1082                         return sysconf(%s) == -1 ? 1 : 0;
1083                         ''' % v,
1084                         'SYSCONF%s' % v,
1085                         msg='Checking whether sysconf(%s) is available' % v)
1086
1087     conf.CHECK_DECLS('__NR_inotify_init', reverse=True, headers='asm/unistd.h')
1088
1089     conf.CHECK_CODE('''
1090 #include <sys/syscall.h>
1091 #include <unistd.h>
1092 syscall(SYS_initgroups, 16, NULL, NULL, 0);
1093                     ''',
1094                     'HAVE_DARWIN_INITGROUPS',
1095                     msg='Checking whether to use the Darwin-specific initgroups system call')
1096
1097     conf.CHECK_CODE('''struct utimbuf tbuf;  tbuf.actime = 0; tbuf.modtime = 1; exit(utime("foo.c",&tbuf));''',
1098                     'HAVE_UTIMBUF',
1099                     headers='sys/types.h utime.h',
1100                     msg='Checking whether struct utimbuf is available')
1101
1102     if conf.CHECK_CODE('''struct sigevent s;''',
1103                     'HAVE_STRUCT_SIGEVENT',
1104                     headers='sys/types.h stdlib.h stddef.h signal.h',
1105                     msg='Checking whether we have the struct sigevent'):
1106         conf.CHECK_STRUCTURE_MEMBER('struct sigevent', 'sigev_value.sival_ptr',
1107                                     define='HAVE_STRUCT_SIGEVENT_SIGEV_VALUE_SIVAL_PTR',
1108                                     headers='signal.h');
1109         conf.CHECK_STRUCTURE_MEMBER('struct sigevent', 'sigev_value.sigval_ptr',
1110                                     define='HAVE_STRUCT_SIGEVENT_SIGEV_VALUE_SIGVAL_PTR',
1111                                     headers='signal.h');
1112
1113     if os.path.exists('/proc/sys/kernel/core_pattern'):
1114         conf.DEFINE('HAVE_SYS_KERNEL_PROC_CORE_PATTERN', '1')
1115
1116     if conf.CHECK_CODE('''
1117 #include <time.h>
1118 main() {
1119         struct tm *tm;
1120         if (sizeof(time_t) == 8) {
1121                 time_t max_time = 0x7fffffffffffffffll;
1122                 tm = gmtime(&max_time);
1123                 /* This should fail with 32-bit tm_year. */
1124                 if (tm == NULL) {
1125                         /* Max time_t that works with 32-bit int tm_year in struct tm. */
1126                         max_time = 67768036191676799ll;
1127                         tm = gmtime(&max_time);
1128                         if (tm) {
1129                                 exit(0);
1130                         }
1131                 }
1132         }
1133         exit(1);
1134 }''',
1135         '__TIME_T_MAX',
1136         addmain=False,
1137         execute=True,
1138         msg="Checking for the maximum value of the 'time_t' type"):
1139             conf.DEFINE('TIME_T_MAX', '67768036191676799ll')
1140
1141     conf.CHECK_CODE('''
1142 #if defined(HAVE_UNISTD_H)
1143 #include <unistd.h>
1144 #endif
1145 #include <sys/types.h>
1146 main() { dev_t dev = makedev(1,2); return 0; }
1147 ''',
1148         'HAVE_MAKEDEV',
1149         addmain=False,
1150         msg='Checking whether the macro for makedev is available')
1151
1152     conf.CHECK_CODE('''
1153 #include <stdio.h>
1154 #include <limits.h>
1155 #include <signal.h>
1156
1157 void exit_on_core(int ignored) {
1158         exit(1);
1159 }
1160
1161 main() {
1162         char *newpath;
1163         signal(SIGSEGV, exit_on_core);
1164         newpath = realpath("/tmp", NULL);
1165         exit((newpath != NULL) ? 0 : 1);
1166 }
1167 ''',
1168         'REALPATH_TAKES_NULL',
1169         addmain=False,
1170         execute=True,
1171         msg='Checking whether the realpath function allows a NULL argument')
1172
1173     conf.CHECK_CODE('''#include "../tests/ftruncate.c"''',
1174                     'HAVE_FTRUNCATE_EXTEND',
1175                     msg='Checking for ftruncate extend',
1176                     addmain=False,
1177                     execute=True)
1178     if os.getenv('RUN_FROM_BUILD_FARM'):
1179         Logs.info("enabling buildfarm hacks")
1180         conf.DEFINE('ENABLE_BUILD_FARM_HACKS', '1')
1181
1182     if Options.options.with_sendfile_support:
1183         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):
1184             conf.CHECK_CODE('''
1185                             int tofd, fromfd;
1186                             off64_t offset;
1187                             size_t total;
1188                             ssize_t nwritten = sendfile64(tofd, fromfd, &offset, total);
1189                             ''',
1190                             '_HAVE_SENDFILE64',
1191                             headers='sys/sendfile',
1192                             msg='Checking for linux sendfile64 support')
1193             conf.CHECK_CODE('''
1194                             int tofd, fromfd;
1195                             off_t offset;
1196                             size_t total;
1197                             ssize_t nwritten = sendfile(tofd, fromfd, &offset, total);
1198                             ''',
1199                             '_HAVE_SENDFILE',
1200                             headers='sys/sendfile',
1201                             msg='Checking for linux sendfile support')
1202
1203             # Try and cope with broken Linux sendfile....
1204             conf.CHECK_CODE('''#if defined(_FILE_OFFSET_BITS) && (_FILE_OFFSET_BITS == 64)
1205                             #undef _FILE_OFFSET_BITS
1206                             #endif
1207                             #include <sys/sendfile.h>
1208                             int tofd, fromfd;
1209                             off_t offset;
1210                             size_t total;
1211                             ssize_t nwritten = sendfile(tofd, fromfd, &offset, total);
1212                             ''',
1213                             '_HAVE_BROKEN_LINUX_SENDFILE',
1214                             msg='Checking for broken linux sendfile support')
1215             if conf.CONFIG_SET('_HAVE_SENDFILE64'):
1216                 conf.DEFINE('HAVE_SENDFILE64', '1')
1217                 conf.DEFINE('LINUX_SENDFILE_API', '1')
1218                 conf.DEFINE('WITH_SENDFILE', '1')
1219             elif conf.CONFIG_SET('_HAVE_SENDFILE'):
1220                 conf.DEFINE('HAVE_SENDFILE', '1')
1221                 conf.DEFINE('LINUX_SENDFILE_API', '1')
1222                 conf.DEFINE('WITH_SENDFILE', '1')
1223             elif conf.CONFIG_SET('_HAVE_BROKEN_LINUX_SENDFILE'):
1224                 conf.DEFINE('LINUX_BROKEN_SENDFILE_API', '1')
1225                 conf.DEFINE('WITH_SENDFILE', '1')
1226         elif (host_os.rfind('freebsd') > -1) or (host_os.rfind('dragonfly') > -1):
1227             conf.CHECK_CODE('''
1228                             #include <sys/types.h>
1229                             #include <unistd.h>
1230                             #include <sys/socket.h>
1231                             #include <sys/uio.h>
1232                             int fromfd, tofd, ret, total=0;
1233                             off_t offset, nwritten;
1234                             struct sf_hdtr hdr;
1235                             struct iovec hdtrl;
1236                             hdr.headers = &hdtrl;
1237                             hdr.hdr_cnt = 1;
1238                             hdr.trailers = NULL;
1239                             hdr.trl_cnt = 0;
1240                             hdtrl.iov_base = NULL;
1241                             hdtrl.iov_len = 0;
1242                             ret = sendfile(fromfd, tofd, offset, total, &hdr, &nwritten, 0)
1243                             ''',
1244                             '_HAVE_SENDFILE',
1245                             msg='Checking for freebsd sendfile support')
1246             if conf.CONFIG_SET('_HAVE_SENDFILE'):
1247                 conf.DEFINE('HAVE_SENDFILE', '1')
1248                 conf.DEFINE('FREEBSD_SENDFILE_API', '1')
1249                 conf.DEFINE('WITH_SENDFILE', '1')
1250         elif (host_os.rfind('hpux') > -1):
1251             conf.CHECK_CODE('''
1252                             #include <sys/socket.h>
1253                             #include <sys/uio.h>
1254                             int fromfd, tofd;
1255                             size_t total=0;
1256                             struct iovec hdtrl[2];
1257                             ssize_t nwritten;
1258                             off64_t offset;
1259                             hdtrl[0].iov_base = 0;
1260                             hdtrl[0].iov_len = 0;
1261                             nwritten = sendfile64(tofd, fromfd, offset, total, &hdtrl[0], 0);
1262                             ''',
1263                             '_HAVE_SENDFILE64',
1264                             msg='Checking for hpux sendfile64 support')
1265             conf.CHECK_CODE('''
1266                             #include <sys/socket.h>
1267                             #include <sys/uio.h>
1268                             int fromfd, tofd;
1269                             size_t total=0;
1270                             struct iovec hdtrl[2];
1271                             ssize_t nwritten;
1272                             off_t offset;
1273                             hdtrl[0].iov_base = 0;
1274                             hdtrl[0].iov_len = 0;
1275                             nwritten = sendfile(tofd, fromfd, offset, total, &hdtrl[0], 0);
1276                             ''',
1277                             '_HAVE_SENDFILE',
1278                             msg='Checking for hpux sendfile support')
1279             if conf.CONFIG_SET('_HAVE_SENDFILE64'):
1280                 conf.DEFINE('HAVE_SENDFILE64', '1')
1281                 conf.DEFINE('HPUX_SENDFILE_API', '1')
1282                 conf.DEFINE('WITH_SENDFILE', '1')
1283             elif conf.CONFIG_SET('_HAVE_SENDFILE'):
1284                 conf.DEFINE('HAVE_SENDFILE', '1')
1285                 conf.DEFINE('HPUX_SENDFILE_API', '1')
1286                 conf.DEFINE('WITH_SENDFILE', '1')
1287         elif (host_os.rfind('solaris') > -1):
1288             conf.CHECK_FUNCS_IN('sendfile', 'sendfilev')
1289             conf.CHECK_CODE('''
1290                             #include <sys/sendfile.h>
1291                             int sfvcnt;
1292                             size_t xferred;
1293                             struct sendfilevec vec[2];
1294                             ssize_t nwritten;
1295                             int tofd;
1296                             sfvcnt = 2;
1297                             vec[0].sfv_fd = SFV_FD_SELF;
1298                             vec[0].sfv_flag = 0;
1299                             vec[0].sfv_off = 0;
1300                             vec[0].sfv_len = 0;
1301                             vec[1].sfv_fd = 0;
1302                             vec[1].sfv_flag = 0;
1303                             vec[1].sfv_off = 0;
1304                             vec[1].sfv_len = 0;
1305                             nwritten = sendfilev64(tofd, vec, sfvcnt, &xferred);
1306                             ''',
1307                             '_HAVE_SENDFILEV64',
1308                             msg='Checking for solaris sendfilev64 support')
1309             conf.CHECK_CODE('''
1310                             #include <sys/sendfile.h>,
1311                             int sfvcnt;
1312                             size_t xferred;
1313                             struct sendfilevec vec[2];
1314                             ssize_t nwritten;
1315                             int tofd;
1316                             sfvcnt = 2;
1317                             vec[0].sfv_fd = SFV_FD_SELF;
1318                             vec[0].sfv_flag = 0;
1319                             vec[0].sfv_off = 0;
1320                             vec[0].sfv_len = 0;
1321                             vec[1].sfv_fd = 0;
1322                             vec[1].sfv_flag = 0;
1323                             vec[1].sfv_off = 0;
1324                             vec[1].sfv_len = 0;
1325                             nwritten = sendfilev(tofd, vec, sfvcnt, &xferred);
1326                             ''',
1327                             '_HAVE_SENDFILEV',
1328                             msg='Checking for solaris sendfilev support')
1329             if conf.CONFIG_SET('_HAVE_SENDFILEV64'):
1330                 conf.DEFINE('HAVE_SENDFILEV64', '1')
1331                 conf.DEFINE('SOLARIS_SENDFILE_API', '1')
1332                 conf.DEFINE('WITH_SENDFILE', '1')
1333             elif conf.CONFIG_SET('_HAVE_SENDFILEV'):
1334                 conf.DEFINE('HAVE_SENDFILEV', '1')
1335                 conf.DEFINE('SOLARIS_SENDFILE_API', '1')
1336                 conf.DEFINE('WITH_SENDFILE', '1')
1337         elif (host_os.rfind('aix') > -1):
1338             conf.CHECK_CODE('''
1339                             #include <sys/socket.h>
1340                             int fromfd, tofd;
1341                             size_t total=0;
1342                             struct sf_parms hdtrl;
1343                             ssize_t nwritten;
1344                             off64_t offset;
1345                             hdtrl.header_data = 0;
1346                             hdtrl.header_length = 0;
1347                             hdtrl.file_descriptor = fromfd;
1348                             hdtrl.file_offset = 0;
1349                             hdtrl.file_bytes = 0;
1350                             hdtrl.trailer_data = 0;
1351                             hdtrl.trailer_length = 0;
1352                             nwritten = send_file(&tofd, &hdtrl, 0);
1353                             ''',
1354                             '_HAVE_SENDFILE',
1355                             msg='Checking for AIX send_file support')
1356             if conf.CONFIG_SET('_HAVE_SENDFILE'):
1357                 conf.DEFINE('HAVE_SENDFILE', '1')
1358                 conf.DEFINE('AIX_SENDFILE_API', '1')
1359                 conf.DEFINE('WITH_SENDFILE', '1')
1360
1361     # Check for getcwd allowing a NULL arg.
1362     conf.CHECK_CODE('''
1363 #include <unistd.h>
1364 main() {
1365         char *s = getcwd(NULL,0);
1366         exit(s != NULL ?  0 : 1);
1367 }''', 'GETCWD_TAKES_NULL', addmain=False, execute=True,
1368         msg="getcwd takes a NULL argument")
1369
1370
1371     conf.CHECK_CODE('''enum TDB_ERROR err = TDB_ERR_NESTING''',
1372                     'HAVE_TDB_ERR_NESTING',
1373                     headers='tdb.h',
1374                     msg='Checking whether we have TDB_ERR_NESTING')
1375
1376     # UnixWare 7.x has its getspnam in -lgen
1377     conf.CHECK_FUNCS_IN('getspnam', 'gen')
1378     conf.CHECK_FUNCS_IN('getspnam', 'security')
1379     conf.CHECK_FUNCS_IN('getspnam', 'sec')
1380
1381     if Options.options.with_quotas:
1382         # For quotas on Veritas VxFS filesystems
1383         conf.CHECK_HEADERS('sys/fs/vx_quota.h')
1384         # For quotas on Linux XFS filesystems
1385         conf.CHECK_HEADERS('linux/dqblk_xfs.h')
1386         # For sys/quota.h and linux/quota.h
1387         conf.CHECK_HEADERS('sys/quota.h')
1388
1389
1390     #
1391     # checking for clustering extensions (CTDB)
1392     #
1393     if not Options.options.with_cluster_support:
1394         have_cluster_support = False
1395
1396     else:
1397
1398         if Options.options.ctdb_dir:
1399             conf.ADD_EXTRA_INCLUDES(Options.options.ctdb_dir + '/include')
1400
1401         srcdir = os.path.realpath(conf.srcdir)
1402         if 'EXTRA_INCLUDES' in conf.env:
1403             includes = ' '.join(conf.env['EXTRA_INCLUDES']).replace('#', srcdir + '/')
1404         else:
1405             includes = ''
1406
1407         have_cluster_support = True
1408         ctdb_broken = ""
1409
1410         conf.CHECK_CODE('''
1411             #define NO_CONFIG_H
1412             #include "replace.h"
1413             #include "system/wait.h"
1414             #include "system/network.h"
1415             #define private #error __USED_RESERVED_WORD_private__
1416             #include <talloc.h>
1417             #include <tdb.h>
1418             #include <ctdb.h>
1419
1420             int main(void)
1421             {
1422                 return 0;
1423             }
1424             ''',
1425             'HAVE_CTDB_H',
1426             addmain=False,
1427             includes=includes,
1428             msg='Checking for header ctdb.h')
1429
1430         if not conf.CONFIG_SET('HAVE_CTDB_H'):
1431             have_cluster_support = False
1432             ctdb_broken = "ctdb.h is required for cluster support"
1433
1434         if have_cluster_support:
1435             conf.CHECK_CODE('''
1436                 #define NO_CONFIG_H
1437                 #include "replace.h"
1438                 #include "system/wait.h"
1439                 #include "system/network.h"
1440                 #define private #error __USED_RESERVED_WORD_private__
1441                 #include <talloc.h>
1442                 #include <tdb.h>
1443                 #include <ctdb.h>
1444                 #include <ctdb_private.h>
1445
1446                 int main(void)
1447                 {
1448                     return 0;
1449                 }
1450                 ''',
1451                 'HAVE_CTDB_PRIVATE_H',
1452                 addmain=False,
1453                 includes=includes,
1454                 msg='Checking for header ctdb_private.h')
1455
1456             if not conf.CONFIG_SET('HAVE_CTDB_PRIVATE_H'):
1457                 have_cluster_support = False
1458                 ctdb_broken = "ctdb_private.h is required for cluster support"
1459
1460         if have_cluster_support:
1461             conf.CHECK_CODE('''
1462                 #define NO_CONFIG_H
1463                 #include "replace.h"
1464                 #include "system/wait.h"
1465                 #include "system/network.h"
1466                 #include <talloc.h>
1467                 #include <tdb.h>
1468                 #include <ctdb.h>
1469                 #include <ctdb_private.h>
1470
1471                 int main(void)
1472                 {
1473                    int i = (int)CTDB_CONTROL_TRANS3_COMMIT;
1474                    return 0;
1475                 }
1476                 ''',
1477                 'HAVE_CTDB_CONTROL_TRANS3_COMMIT_DECL',
1478                 addmain=False,
1479                 includes=includes,
1480                 msg='Checking for transaction support (TRANS3_COMMIT control)')
1481
1482             if not conf.CONFIG_SET('HAVE_CTDB_CONTROL_TRANS3_COMMIT_DECL'):
1483                 have_cluster_support = False
1484                 ctdb_broken = "ctdb transaction support missing or too old"
1485
1486         if have_cluster_support:
1487             conf.CHECK_CODE('''
1488                 #define NO_CONFIG_H
1489                 #include "replace.h"
1490                 #include "system/wait.h"
1491                 #include "system/network.h"
1492                 #include <talloc.h>
1493                 #include <tdb.h>
1494                 #include <ctdb.h>
1495                 #include <ctdb_private.h>
1496
1497                 int main(void)
1498                 {
1499                     int i = (int)CTDB_CONTROL_SCHEDULE_FOR_DELETION;
1500                     return 0;
1501                 }
1502                 ''',
1503                 'HAVE_CTDB_CONTROL_SCHEDULE_FOR_DELETION_DECL',
1504                 addmain=False,
1505                 includes=includes,
1506                 msg='Checking for SCHEDULE_FOR_DELETION control')
1507
1508             if not conf.CONFIG_SET('HAVE_CTDB_CONTROL_SCHEDULE_FOR_DELETION_DECL'):
1509                 if not Options.options.enable_old_ctdb:
1510                     have_cluster_support = False
1511                     ctdb_broken = "SCHEDULE_FOR_DELETION control missing"
1512                 else:
1513                     Logs.warn("ignoring missing SCHEDULE_FOR_DELETION control (--enable-old-ctdb)")
1514
1515         if have_cluster_support:
1516             conf.CHECK_CODE('''
1517                 #define NO_CONFIG_H
1518                 #include "replace.h"
1519                 #include "system/wait.h"
1520                 #include "system/network.h"
1521                 #include <talloc.h>
1522                 #include <tdb.h>
1523                 #include <ctdb.h>
1524                 #include <ctdb_private.h>
1525
1526                 int main(void)
1527                 {
1528                     struct ctdb_control_tcp _x;
1529                     return 0;
1530                 }
1531                 ''',
1532                 'HAVE_STRUCT_CTDB_CONTROL_TCP',
1533                 addmain=False,
1534                 includes=includes,
1535                 msg='Checking for ctdb ipv4 support')
1536
1537             if not conf.CONFIG_SET('HAVE_STRUCT_CTDB_CONTROL_TCP'):
1538                 have_cluster_support = False
1539                 ctdb_broken = "missing struct ctdb_control_tcp"
1540
1541         if have_cluster_support:
1542             conf.CHECK_CODE('''
1543                 #define NO_CONFIG_H
1544                 #include "replace.h"
1545                 #include "system/wait.h"
1546                 #include "system/network.h"
1547                 #include <talloc.h>
1548                 #include <tdb.h>
1549                 #include <ctdb.h>
1550                 #include <ctdb_private.h>
1551
1552                 int main(void)
1553                 {
1554                     struct ctdb_control_tcp_addr _x;
1555                     return 0;
1556                 }
1557                 ''',
1558                 'HAVE_STRUCT_CTDB_CONTROL_TCP_ADDR',
1559                 addmain=False,
1560                 includes=includes,
1561                 msg='Checking for ctdb ipv6 support')
1562
1563     if have_cluster_support:
1564         Logs.info("building with cluster support")
1565         conf.DEFINE('CLUSTER_SUPPORT', 1);
1566     else:
1567         if not Options.options.with_cluster_support:
1568             Logs.info("building without cluster support")
1569         else:
1570             Logs.warn("building without cluster support: " + ctdb_broken)
1571         conf.undefine('CLUSTER_SUPPORT')
1572
1573
1574
1575     conf.CHECK_CODE('__attribute__((destructor)) static void cleanup(void) { }',
1576                     'HAVE_FUNCTION_ATTRIBUTE_DESTRUCTOR',
1577                     addmain=False,
1578                     link=False,
1579                     msg='Checking whether we can compile with __attribute__((destructor))')
1580
1581     conf.CHECK_CODE('void seekdir(DIR *d, long loc) { return; }',
1582                     'SEEKDIR_RETURNS_VOID',
1583                     headers='sys/types.h dirent.h',
1584                     msg='Checking whether seekdir returns void')
1585
1586     if Options.options.with_profiling_data:
1587         conf.DEFINE('WITH_PROFILE', 1);
1588
1589     PTHREAD_CFLAGS='error'
1590     PTHREAD_LDFLAGS='error'
1591
1592     if PTHREAD_LDFLAGS == 'error':
1593         if conf.CHECK_FUNCS_IN('pthread_attr_init', 'pthread'):
1594             PTHREAD_CFLAGS='-D_REENTRANT -D_POSIX_PTHREAD_SEMANTICS'
1595             PTHREAD_LDFLAGS='-lpthread'
1596     if PTHREAD_LDFLAGS == 'error':
1597         if conf.CHECK_FUNCS_IN('pthread_attr_init', 'pthreads'):
1598             PTHREAD_CFLAGS='-D_THREAD_SAFE'
1599             PTHREAD_LDFLAGS='-lpthreads'
1600     if PTHREAD_LDFLAGS == 'error':
1601         if conf.CHECK_FUNCS_IN('pthread_attr_init', 'c_r'):
1602             PTHREAD_CFLAGS='-D_THREAD_SAFE -pthread'
1603             PTHREAD_LDFLAGS='-pthread'
1604     if PTHREAD_LDFLAGS == 'error':
1605         if conf.CHECK_FUNC('pthread_attr_init'):
1606             PTHREAD_CFLAGS='-D_REENTRANT'
1607             PTHREAD_LDFLAGS='-lpthread'
1608     # especially for HP-UX, where the CHECK_FUNC macro fails to test for
1609     # pthread_attr_init. On pthread_mutex_lock it works there...
1610     if PTHREAD_LDFLAGS == 'error':
1611         if conf.CHECK_FUNCS_IN('pthread_mutex_lock', 'pthread'):
1612             PTHREAD_CFLAGS='-D_REENTRANT'
1613             PTHREAD_LDFLAGS='-lpthread'
1614
1615     if PTHREAD_CFLAGS != 'error' and PTHREAD_LDFLAGS != 'error':
1616         conf.ADD_CFLAGS(PTHREAD_CFLAGS)
1617         conf.ADD_LDFLAGS(PTHREAD_LDFLAGS)
1618         conf.CHECK_HEADERS('pthread.h')
1619         conf.DEFINE('HAVE_PTHREAD', '1')
1620
1621     if Options.options.with_pthreadpool:
1622         if conf.CONFIG_SET('HAVE_PTHREAD'):
1623             conf.DEFINE('WITH_PTHREADPOOL', '1')
1624         else:
1625             Logs.warn("pthreadpool support cannot be enabled when pthread support was not found")
1626             conf.undefine('WITH_PTHREADPOOL')
1627
1628     if conf.CHECK_HEADERS('gpfs_gpl.h'):
1629         conf.DEFINE('HAVE_GPFS', '1')
1630
1631     # Note that all charset 'modules' must actually be static, due to dependency loop issues 
1632     # if we include the module loader in iconv
1633
1634     default_static_modules=TO_LIST('''pdb_smbpasswd pdb_tdbsam pdb_wbc_sam
1635                                       auth_sam auth_unix auth_winbind auth_wbc auth_server
1636                                       auth_domain auth_builtin vfs_default
1637                                       nss_info_template idmap_tdb idmap_passdb
1638                                       idmap_nss''')
1639
1640     default_shared_modules=TO_LIST('''vfs_recycle vfs_audit vfs_extd_audit vfs_full_audit vfs_netatalk
1641                                       vfs_fake_perms vfs_default_quota vfs_readonly vfs_cap
1642                                       vfs_expand_msdfs vfs_shadow_copy vfs_shadow_copy2 
1643                                       auth_script vfs_readahead vfs_xattr_tdb
1644                                       vfs_streams_xattr vfs_streams_depot vfs_acl_xattr vfs_acl_tdb
1645                                       vfs_smb_traffic_analyzer vfs_preopen vfs_catia vfs_scannedonly
1646                                       vfs_crossrename vfs_linux_xfs_sgid
1647                                       vfs_time_audit idmap_autorid''')
1648
1649     if Options.options.developer:
1650         default_static_modules.extend(TO_LIST('pdb_ads auth_netlogond charset_weird'))
1651         default_shared_modules.extend(TO_LIST('perfcount_test'))
1652
1653     default_static_modules.extend(TO_LIST('pdb_samba4 auth_samba4 vfs_dfs_samba4'))
1654
1655     if Options.options.with_acl_support and conf.CONFIG_SET('HAVE_POSIX_ACLS'):
1656         default_static_modules.extend(TO_LIST('vfs_posixacl'))
1657
1658     if conf.CONFIG_SET('HAVE_FREEBSD_SUNACL_H'):
1659         default_shared_modules.extend(TO_LIST('vfs_zfsacl'))
1660
1661     if conf.CONFIG_SET('HAVE_DIRFD_DECL'):
1662         default_shared_modules.extend(TO_LIST('vfs_syncops vfs_dirsort'))
1663
1664     if conf.CONFIG_SET('HAVE_STATFS_F_FSID'):
1665         default_shared_modules.extend(TO_LIST('vfs_fileid'))
1666
1667     if conf.CONFIG_SET('HAVE_AIO') and (conf.CONFIG_SET('HAVE_MSGHDR_MSG_CONTROL') or conf.CONFIG_SET('HAVE_MSGHDR_MSG_ACCTRIGHTS')):
1668         default_shared_modules.extend(TO_LIST('vfs_aio_fork'))
1669
1670     if conf.CONFIG_SET('HAVE_LDAP'):
1671         default_static_modules.extend(TO_LIST('pdb_ldap idmap_ldap'))
1672
1673     if conf.CONFIG_SET('DARWINOS'):
1674         default_static_modules.extend(TO_LIST('charset_macosxfs'))
1675
1676     if conf.CONFIG_SET('HAVE_GPFS'):
1677         default_shared_modules.extend(TO_LIST('vfs_gpfs vfs_gpfs_hsm_notify'))
1678
1679     explicit_shared_modules = TO_LIST(Options.options.shared_modules, delimiter=',')
1680     explicit_static_modules = TO_LIST(Options.options.static_modules, delimiter=',')
1681
1682     final_static_modules = default_static_modules
1683     final_shared_modules = default_shared_modules
1684
1685     for m in explicit_static_modules:
1686         if m in final_shared_modules:
1687             final_shared_modules.remove(m)
1688         final_static_modules.append(m)
1689     for m in explicit_shared_modules:
1690         if m in final_static_modules:
1691             final_static_modules.remove(m)
1692         final_shared_modules.append(m)
1693
1694     conf.env['static_modules'] = final_static_modules
1695     conf.env['shared_modules'] = final_shared_modules
1696
1697     conf.DEFINE('STRING_STATIC_MODULES', ' '.join(final_static_modules), quote=True)
1698
1699     static_list = {}
1700     shared_list = {}
1701
1702     prefixes = ['vfs', 'pdb', 'auth', 'nss_info', 'charset', 'idmap', 'gpext', 'perfcount']
1703     conf.env['MODULE_PREFIXES'] = prefixes
1704     for p in prefixes:
1705         for m in final_static_modules:
1706             if m.find(p) == 0:
1707                 if not p in static_list:
1708                     static_list[p] = []
1709                 static_list[p].append(m)
1710         for m in final_shared_modules:
1711             if m.find(p) == 0:
1712                 if not p in shared_list:
1713                     shared_list[p] = []
1714                 shared_list[p].append(m)
1715
1716     for p in prefixes:
1717         static_env = "%s_STATIC" % p.upper()
1718         shared_env = "%s_SHARED" % p.upper()
1719         conf.env[static_env] = []
1720         conf.env[shared_env] = []
1721         if p in static_list:
1722             decl_list=""
1723             for entry in static_list[p]:
1724                 decl_list += "extern NTSTATUS %s_init(void); " % entry
1725                 conf.env[static_env].append('%s' % entry)
1726             decl_list = decl_list.rstrip()
1727             conf.DEFINE('static_decl_%s' % p, decl_list)
1728             conf.DEFINE('static_init_%s' % p, '{ %s_init(); }' % '_init();  '.join(static_list[p]))
1729         else:
1730             conf.DEFINE('static_decl_%s' % p, '')
1731             conf.DEFINE('static_init_%s' % p, '{}')
1732         if p in shared_list:
1733             for entry in shared_list[p]:
1734                 conf.DEFINE('%s_init' % entry, 'samba_init_module')
1735                 conf.env[shared_env].append('%s' % entry)
1736
1737     conf.SAMBA_CONFIG_H('include/config.h')
1738
1739 def ctags(ctx):
1740     "build 'tags' file using ctags"
1741     import Utils
1742     source_root = os.path.dirname(Utils.g_module.root_path)
1743     cmd = 'ctags $(find %s/.. -name "*.[ch]" | grep -v "*_proto\.h")' % source_root
1744     print("Running: %s" % cmd)
1745     os.system(cmd)
1746