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