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