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