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