s3-waf: try to deal with underlinked cups libraries.
[ira/wip.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 import wafsamba, Options
13 import build.charset
14 import samba_utils, samba_version
15 import samba3
16
17 def set_options(opt):
18     opt.BUILTIN_DEFAULT('NONE')
19     opt.PRIVATE_EXTENSION_DEFAULT('s3')
20     opt.RECURSE('../lib/replace')
21     opt.RECURSE('build')
22     opt.RECURSE('selftest')
23     opt.RECURSE('../lib/nss_wrapper')
24     opt.RECURSE('../lib/socket_wrapper')
25     opt.RECURSE('../lib/tevent')
26     opt.RECURSE('../lib/tdb')
27
28     opt.add_option('--with-static-modules',
29                    help=("Comma-separated list of names of modules to statically link in"),
30                    action="store", dest='static_modules', default=None)
31     opt.add_option('--with-shared-modules',
32                    help=("Comma-separated list of names of modules to build shared"),
33                    action="store", dest='shared_modules', default=None)
34     opt.add_option('--enable-selftest',
35                   help=("enable options necessary for selftest"),
36                   action="store_true", dest='enable_selftest', default=False)
37
38     opt.SAMBA3_ADD_OPTION('winbind')
39     opt.SAMBA3_ADD_OPTION('swat')
40     opt.SAMBA3_ADD_OPTION('ads')
41     opt.SAMBA3_ADD_OPTION('krb5')
42     opt.SAMBA3_ADD_OPTION('ldap')
43     opt.SAMBA3_ADD_OPTION('cups', with_name="enable", without_name="disable")
44     opt.SAMBA3_ADD_OPTION('iprint', with_name="enable", without_name="disable")
45     opt.SAMBA3_ADD_OPTION('merged-build', with_name="enable", without_name="disable")
46     opt.SAMBA3_ADD_OPTION('pam')
47     opt.SAMBA3_ADD_OPTION('quotas')
48     opt.SAMBA3_ADD_OPTION('sys-quotas')
49     opt.SAMBA3_ADD_OPTION('sendfile-support')
50     opt.SAMBA3_ADD_OPTION('utmp')
51     opt.SAMBA3_ADD_OPTION('pthreadpool', with_name="enable", without_name="disable")
52     opt.SAMBA3_ADD_OPTION('avahi', with_name="enable", without_name="disable")
53     opt.SAMBA3_ADD_OPTION('iconv')
54     opt.SAMBA3_ADD_OPTION('acl-support')
55     opt.SAMBA3_ADD_OPTION('dnsupdate')
56     opt.SAMBA3_ADD_OPTION('syslog')
57     opt.SAMBA3_ADD_OPTION('automount')
58     opt.SAMBA3_ADD_OPTION('aio-support')
59
60
61 def configure(conf):
62     from samba_utils import TO_LIST
63
64     version = samba_version.load_version(env=conf.env)
65
66     conf.DEFINE('CONFIG_H_IS_FROM_SAMBA', 1)
67     conf.DEFINE('_SAMBA_BUILD_', version.MAJOR, add_to_cflags=True)
68     conf.DEFINE('HAVE_CONFIG_H', 1, add_to_cflags=True)
69
70     if Options.options.developer:
71         conf.ADD_CFLAGS('-DDEVELOPER -DDEBUG_PASSWORD')
72         conf.env['developer'] = True
73
74     if Options.options.with_swat:
75         conf.env['build_swat'] = True
76
77     conf.ADD_EXTRA_INCLUDES('''#source3 #source3/include #lib/replace #lib/talloc
78                                #lib/tevent #lib/addns #source3/librpc
79                                #source3/lib #lib/tdb/include #lib/popt''')
80
81     conf.RECURSE('../lib/replace')
82     conf.RECURSE('build')
83     conf.RECURSE('../lib/tdb')
84     conf.RECURSE('../lib/talloc')
85     conf.RECURSE('../lib/tevent')
86     conf.RECURSE('../lib/popt')
87     conf.RECURSE('../lib/nss_wrapper')
88     conf.RECURSE('../lib/socket_wrapper')
89     conf.RECURSE('../lib/zlib')
90     conf.RECURSE('../libcli/smbreadline')
91     conf.RECURSE('../lib/util')
92
93     conf.ADD_LDFLAGS("-Wl,--export-dynamic", testflags=True)
94
95     conf.CHECK_HEADERS('execinfo.h libexc.h libunwind.h netdb.h')
96     conf.CHECK_HEADERS('linux/falloc.h')
97
98     conf.CHECK_FUNCS('getcwd fchown chmod fchmod mknod mknod64')
99     conf.CHECK_FUNCS('strtol strchr strupr chflags')
100     conf.CHECK_FUNCS('getrlimit fsync fdatasync setpgid')
101     conf.CHECK_FUNCS('setsid glob strpbrk crypt16 getauthuid')
102     conf.CHECK_FUNCS('sigprocmask sigblock sigaction sigset innetgr')
103     conf.CHECK_FUNCS('initgroups select poll rdchk getgrnam getgrent pathconf')
104     conf.CHECK_FUNCS('setpriv setgidx setuidx setgroups sysconf stat64 fstat64')
105     conf.CHECK_FUNCS('lstat64 fopen64 atexit grantpt lseek64 ftruncate64 fallocate fallocate64 posix_fallocate posix_fallocate64')
106     conf.CHECK_FUNCS('fseek64 fseeko64 ftell64 ftello64 setluid')
107     conf.CHECK_FUNCS('getpwnam', headers='sys/types.h pwd.h')
108     conf.CHECK_FUNCS('opendir64 readdir64 seekdir64 telldir64 rewinddir64 closedir64')
109     conf.CHECK_FUNCS('fdopendir fdopendir64')
110     conf.CHECK_FUNCS('getpwent_r getdents64 setenv strcasecmp fcvt fcvtl')
111     conf.CHECK_FUNCS('syslog vsyslog timegm setlocale nl_langinfo')
112     conf.CHECK_FUNCS_IN('nanosleep', 'rt')
113     conf.CHECK_FUNCS('lutimes futimes utimensat futimens')
114     conf.CHECK_FUNCS('mlock munlock mlockall munlockall')
115     conf.CHECK_FUNCS('memalign posix_memalign hstrerror')
116     conf.CHECK_FUNCS('shmget')
117     conf.CHECK_FUNCS_IN('shm_open', 'rt', checklibc=True)
118     conf.CHECK_FUNCS('gettext dgettext bindtextdomain textdomain')
119     #FIXME: for some reason this one still fails
120     conf.CHECK_FUNCS_IN('yp_get_default_domain', 'nsl')
121     conf.CHECK_FUNCS_IN('dn_expand _dn_expand __dn_expand', 'resolv')
122     conf.CHECK_DECLS('fdatasync', reverse=True)
123     conf.CHECK_DECLS('readahead', reverse=True, headers='fcntl.h')
124
125     if conf.CONFIG_SET('HAVE_LONG_LONG'):
126         conf.DEFINE('HAVE_LONGLONG', 1)
127
128     if conf.CHECK_CODE('''
129 #if defined(HAVE_UNISTD_H)
130 #include <unistd.h>
131 #endif
132 long ret = splice(0,0,1,0,400,0);
133 ''',
134         'HAVE_LINUX_SPLICE',
135         headers='fcntl.h'):
136         conf.CHECK_DECLS('splice', reverse=True, headers='fcntl.h')
137
138     # Check for inotify support
139     conf.CHECK_HEADERS('linux/inotify.h asm/unistd.h sys/inotify.h')
140     conf.CHECK_FUNCS('inotify_init')
141     if "HAVE_LINUX_INOTIFY_H" in conf.env and "HAVE_INOTIFY_INIT" in conf.env:
142         conf.DEFINE('HAVE_INOTIFY', 1)
143
144     # Check for kernel change notify support
145     conf.CHECK_CODE('''
146 #ifndef F_NOTIFY
147 #define F_NOTIFY 1026
148 #endif
149 main() {
150         exit(fcntl(open("/tmp", O_RDONLY), F_NOTIFY, 0) == -1 ?  1 : 0);
151 }''', 'HAVE_KERNEL_CHANGE_NOTIFY', addmain=False, execute=True,
152         headers='fcntl.h signal.h',
153         msg="Checking for kernel change notify support")
154
155     # Check for Linux kernel oplocks
156     conf.CHECK_CODE('''
157 #include <sys/types.h>
158 #include <fcntl.h>
159 #include <signal.h>
160 #ifndef F_NOTIFY
161 #define F_NOTIFY 1026
162 #endif
163 main() {
164         exit(fcntl(open("/tmp", O_RDONLY), F_NOTIFY, 0) == -1 ?  1 : 0);
165 }''', 'HAVE_KERNEL_OPLOCKS_LINUX', addmain=False, execute=True,
166         msg="Checking for Linux kernel oplocks")
167
168     # Check for IRIX kernel oplock types
169     conf.CHECK_CODE('oplock_stat_t t; t.os_state = OP_REVOKE; t.os_dev = 1; t.os_ino = 1;',
170                     'HAVE_KERNEL_OPLOCKS_IRIX', headers='fcntl.h',
171                     msg="Checking for IRIX kernel oplock types")
172
173     # Check for krenel share modes
174     conf.CHECK_CODE('''
175 #include <sys/types.h>
176 #include <fcntl.h>
177 #include <signal.h>
178 #include <sys/file.h>
179 #ifndef LOCK_MAND
180 #define LOCK_MAND       32
181 #define LOCK_READ       64
182 #endif
183 main() {
184         exit(flock(open("/dev/null", O_RDWR), LOCK_MAND|LOCK_READ) != 0);
185 }''', 'HAVE_KERNEL_SHARE_MODES', addmain=False, execute=True,
186         msg="Checking for krenel share modes")
187
188     # Check for various members of the stat structure
189     conf.CHECK_TYPES('blksize_t blkcnt_t')
190     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_blocks', define='HAVE_STAT_ST_BLOCKS',
191                                 headers='sys/stat.h')
192     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_blksize', define='HAVE_STAT_ST_BLKSIZE',
193                                 headers='sys/stat.h')
194
195     # Check for POSIX capability support
196     conf.CHECK_FUNCS_IN('cap_get_proc', 'cap', headers='sys/capability.h')
197
198     if "HAVE_SYS_CAPABILITY_H" in conf.env:
199         conf.CHECK_CODE('''
200         cap_t cap;
201         cap_value_t vals[1];
202         if (!(cap = cap_get_proc())) exit(1);
203         vals[0] = CAP_CHOWN;
204         cap_set_flag(cap, CAP_INHERITABLE, 1, vals, CAP_CLEAR);
205         cap_set_proc(cap);''',
206                         'HAVE_POSIX_CAPABILITIES', execute=True, lib="cap",
207                         headers='sys/capability.h',
208                         msg="Checking whether POSIX capabilities are available")
209
210     # Check for int16, uint16, int32 and uint32 in rpc/types.h included from
211     # rpc/rpc.h. This is *really* broken but some systems (DEC OSF1) do this.
212     # -- JRA.
213     if conf.CONFIG_SET("HAVE_RPC_RPC_H"):
214         conf.CHECK_TYPE('int16', headers='rpc/rpc.h',
215                         define='HAVE_INT16_FROM_RPC_RPC_H',
216                         msg="Checking for int16 typedef included by rpc/rpc.h")
217         conf.CHECK_CODE('uint16 testvar;', 'HAVE_INT16_FROM_RPC_RPC_H',
218                         headers='sys/types.h rpc/rpc.h',
219                         msg="Checking for uint16 typedef included by rpc/rpc.h")
220         conf.CHECK_CODE('int32 testvar;', 'HAVE_INT16_FROM_RPC_RPC_H',
221                         headers='sys/types.h rpc/rpc.h',
222                         msg="Checking for int32 typedef included by rpc/rpc.h")
223         conf.CHECK_CODE('uint32 testvar;', 'HAVE_INT16_FROM_RPC_RPC_H',
224                         headers='sys/types.h rpc/rpc.h',
225                         msg="Checking for uint32 typedef included by rpc/rpc.h")
226     conf.CHECK_CODE('int i;', 'BROKEN_NISPLUS_INCLUDE_FILES',
227                     headers='sys/types.h sys/acl.h rpcsvc/nis.h',
228                     msg="Checking for broken nisplus include files")
229
230     # Check if the compiler will optimize out functions
231     conf.CHECK_CODE('''
232 if (0) {
233     this_function_does_not_exist();
234 } else {
235     return 1;
236 }''', 'HAVE_COMPILER_WILL_OPTIMIZE_OUT_FNS',
237         msg="Checking if the compiler will optimize out functions")
238
239     # Check if the compiler supports the LL suffix on long long integers
240     # AIX needs this
241     conf.CHECK_CODE('long long i = 0x8000000000LL', 'COMPILER_SUPPORTS_LL',
242                     headers='stdio.h',
243                     msg="Checking for LL suffix on long long integers")
244
245     conf.CHECK_FUNCS('''
246 _acl __acl add_proplist_entry atexit attr_getf attr_list attr_listf
247 attropen attr_remove attr_removef attr_set attr_setf backtrace_symbols
248 bindtextdomain _chdir __chdir chflags chmod _close __close _closedir
249 __closedir closedir64 creat64 crypt16 delproplist devnm dgettext dirfd
250 DNSServiceRegister _dup __dup _dup2 __dup2 endmntent execl
251 extattr_delete_fd extattr_delete_link extattr_get_fd extattr_get_file
252 extattr_get_link extattr_list_fd extattr_list_file extattr_list_link
253 extattr_set_fd extattr_set_file extattr_set_link _facl __facl _fchdir
254 __fchdir fchmod fchown _fcntl __fcntl fcvt fcvtl fdatasync
255 fdelproplist fgetea fgetproplist fgetxattr flistea flistxattr fopen64
256 _fork __fork fremoveea fremovexattr fseek64 fseeko64 fsetea
257 fsetproplist fsetxattr _fstat __fstat fstat64 _fstat64 __fstat64 fsync
258 ftell64 ftello64 ftruncate64 futimens futimes __fxstat getauthuid
259 getcwd _getcwd __getcwd getdents __getdents getdents64 getdirentries
260 getgrent getgrnam getgrouplist getmntent getpagesize
261 getproplist get_proplist_entry getpwanam getpwent_r getrlimit gettext
262 glob grantpt hstrerror initgroups innetgr
263 inotify_init lgetea lgetxattr listea listxattr llistea llistxattr
264 llseek _llseek __llseek lremoveea lremovexattr _lseek __lseek lseek64
265 lsetea lsetxattr _lstat __lstat lstat64 _lstat64 __lstat64 lutimes
266 __lxstat memalign mknod mknod64 mlock mlockall munlock munlockall
267 nl_langinfo _open __open open64 _open64 __open64 _opendir __opendir
268 opendir64 pathconf poll posix_fallocate posix_fallocate64
269 posix_memalign prctl pread _pread __pread pread64 _pread64 __pread64
270 pwrite _pwrite __pwrite pwrite64 _pwrite64
271 __pwrite64 rdchk _read __read _readdir __readdir readdir64 _readdir64
272 __readdir64 removeea removexattr rewinddir64 _seekdir __seekdir
273 seekdir64 select setea setenv setgidx setgroups setlocale setluid
274 setmntent setpgid setpriv setproplist setsid setuidx
275 setxattr shmget shm_open sigaction sigblock sigprocmask sigset
276 sizeof_proplist_entry _stat __stat stat64 _stat64 __stat64 statvfs
277 strcasecmp strchr strpbrk strsignal strtol strupr sysconf sysctlbyname
278 __sys_llseek syslog _telldir __telldir telldir64 textdomain timegm
279 utimensat vsyslog _write __write __xstat
280 ''')
281
282     conf.CHECK_TYPE('struct timespec', headers='sys/time.h time.h')
283
284     conf.CHECK_SAMBA3_CHARSET() # see build/charset.py
285
286     # FIXME: these should be tests for features, but the old build system just
287     # checks for OSes.
288     import sys
289     host_os = sys.platform
290     print "building on %s" % host_os
291
292     # Python doesn't have case switches... :/
293     # FIXME: original was *linux* | gnu* | k*bsd*-gnu | kopensolaris*-gnu | *qnx*)
294     # the search for .rfind('gnu') covers gnu* and *-gnu is that too broad?
295
296     conf.SET_TARGET_TYPE('sunacl', 'EMPTY')
297     if (host_os.rfind('linux') > -1) or (host_os.rfind('gnu') > -1) or (host_os.rfind('qnx') > -1):
298         if host_os.rfind('linux') > -1:
299             conf.DEFINE('LINUX', '1')
300         elif host_os.rfind('qnx') > -1:
301             conf.DEFINE('QNX', '1')
302         conf.DEFINE('STAT_ST_BLOCKSIZE', '512')
303     elif (host_os.rfind('darwin') > -1):
304         conf.DEFINE('DARWINOS', 1)
305         conf.DEFINE('STAT_ST_BLOCKSIZE', '512')
306         conf.ADD_CFLAGS('-fno-common')
307     elif (host_os.rfind('freebsd') > -1):
308         if conf.CHECK_HEADERS('sunacl.h'):
309             conf.define('HAVE_FREEBSD_SUNACL_H', '1')
310             conf.CHECK_FUNCS_IN('acl', 'sunacl')
311         conf.DEFINE('STAT_ST_BLOCKSIZE', '512')
312     elif (host_os.rfind('netbsd') > -1):
313         conf.DEFINE('STAT_ST_BLOCKSIZE', '512')
314     elif (host_os.rfind('openbsd') > -1):
315         conf.DEFINE('STAT_ST_BLOCKSIZE', '512')
316     # FIXME: Add more checks here.
317     else:
318         print "Unknown host_os '%s', please report this to samba-technical@samba.org" % host_os
319
320     #FIXME: add more checks
321     if Options.options.with_acl_support:
322         if host_os.rfind('linux') > -1:
323             conf.CHECK_FUNCS_IN('acl_get_file', 'acl')
324             conf.CHECK_FUNCS_IN('getxattr', 'attr')
325             if conf.CHECK_CODE('''
326 acl_t acl;
327 int entry_id;
328 acl_entry_t *entry_p;
329 return acl_get_entry(acl, entry_id, entry_p);
330 ''',
331                         'HAVE_POSIX_ACLS',
332                         headers='sys/types.h sys/acl.h', link=False,
333                         msg="Checking for POSIX ACL support") :
334                 conf.CHECK_CODE('''
335 acl_permset_t permset_d;
336 acl_perm_t perm;
337 return acl_get_perm_np(permset_d, perm);
338 ''',
339                         'HAVE_ACL_GET_PERM_NP',
340                         headers='sys/types.h sys/acl.h', link=True,
341                         msg="Checking whether acl_get_perm_np() is available")
342         else:
343             conf.DEFINE('HAVE_NO_ACLS', 1)
344             conf.SET_TARGET_TYPE('acl', 'EMPTY')
345     else:
346         conf.DEFINE('HAVE_NO_ACLS', 1)
347         conf.SET_TARGET_TYPE('acl', 'EMPTY')
348
349     if conf.CHECK_FUNCS('dirfd'):
350         conf.DEFINE('HAVE_DIRFD_DECL', 1)
351
352     conf.CHECK_CODE('struct statfs fsd; fsid_t fsid = fsd.f_fsid; return statfs(".", &fsd);',
353                     'HAVE_STATFS_F_FSID',
354                     msg="vfs_fileid: checking for statfs() and struct statfs.f_fsid",
355                     headers='sys/types.h sys/statfs.h',
356                     execute=True)
357
358     if conf.CONFIG_SET('HAVE_FALLOCATE'):
359         conf.CHECK_CODE('''
360                 #if defined(HAVE_UNISTD_H)
361                 #include <unistd.h>
362                 #endif
363                 #include <sys/types.h>
364                 #define _GNU_SOURCE
365                 #include <fcntl.h>
366                 #if defined(HAVE_LINUX_FALLOC_H)
367                 #include <linux/falloc.h>
368                 #endif
369                 int ret = fallocate(0, FALLOC_FL_KEEP_SIZE, 0, 10);''',
370                 'HAVE_LINUX_FALLOCATE',
371                 msg="Checking whether the Linux 'fallocate' function is available")
372     if conf.CONFIG_SET('HAVE_FALLOCATE64'):
373         conf.CHECK_CODE('''
374                 #if defined(HAVE_UNISTD_H)
375                 #include <unistd.h>
376                 #endif
377                 #include <sys/types.h>
378                 #define _GNU_SOURCE
379                 #include <fcntl.h>
380                 #if defined(HAVE_LINUX_FALLOC_H)
381                 #include <linux/falloc.h>
382                 #endif
383                 int ret = fallocate64(0, FALLOC_FL_KEEP_SIZE, 0, 10);''',
384                 'HAVE_LINUX_FALLOCATE64',
385                 msg="Checking whether the Linux 'fallocate64' function is available")
386     conf.CHECK_CODE('''
387                 #if defined(HAVE_UNISTD_H)
388                 #include <unistd.h>
389                 #endif
390                 #include <fcntl.h>
391                 ssize_t err = readahead(0,0,0x80000);''',
392                 'HAVE_LINUX_READAHEAD',
393                 msg="Checking whether Linux readahead is available")
394     conf.CHECK_DECLS('readahead', headers='fcntl.h', always=True)
395
396     conf.CHECK_CODE('''
397                 #include <sys/types.h>
398                 #include <sys/socket.h>],
399                 struct ucred cred;
400                 socklen_t cred_len;
401                 int ret = getsockopt(0, SOL_SOCKET, SO_PEERCRED, &cred, &cred_len);''',
402                 'HAVE_PEERCRED',
403                 msg="Checking whether we can use SO_PEERCRED to get socket credentials")
404
405     conf.CHECK_CODE('''
406                 #if defined(HAVE_LONGLONG) && (defined(HAVE_OFF64_T) || (defined(SIZEOF_OFF_T) && (SIZEOF_OFF_T == 8)))
407                 #include <sys/types.h>
408                 #else
409                 __COMPILE_ERROR_
410                 #endif
411                 int i;''',
412                 'HAVE_EXPLICIT_LARGEFILE_SUPPORT',
413                 msg="Checking whether large file support can be enabled")
414
415     if Options.options.with_aio_support:
416         conf.CHECK_FUNCS_IN('aio_read', 'aio')
417         conf.CHECK_FUNCS_IN('aio_read', 'rt')
418         conf.CHECK_CODE('struct aiocb a; return aio_read(&a);',
419                         'HAVE_AIO',
420                         msg='Checking for asynchronous io support',
421                         headers='sys/types.h aio.h',
422                         lib='aio rt')
423         conf.CHECK_CODE('struct aiocb64 a; return aio_read64(&a);',
424                         'HAVE_AIO64',
425                         msg='Checking for 64-bit asynchronous io support',
426                         headers='sys/types.h aio.h',
427                         lib='aio rt')
428         if conf.CONFIG_SET('HAVE_AIO64'):
429             conf.DEFINE('HAVE_AIOCB64', '1')
430             conf.DEFINE('WITH_AIO', '1')
431         elif conf.CONFIG_SET('HAVE_AIO'):
432             conf.DEFINE('WITH_AIO', '1')
433         if conf.CONFIG_SET('HAVE_AIO'):
434             conf.CHECK_CODE('struct aiocb a; return aio_read(&a);', 'HAVE_AIO_READ', msg='Checking for aio_read', headers='aio.h', lib='aio rt')
435             conf.CHECK_CODE('struct aiocb a; return aio_write(&a);', 'HAVE_AIO_WRITE', msg='Checking for aio_write', headers='aio.h', lib='aio rt')
436             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')
437             conf.CHECK_CODE('struct aiocb a; return aio_return(&a);', 'HAVE_AIO_RETURN', msg='Checking for aio_return', headers='aio.h', lib='aio rt')
438             conf.CHECK_CODE('struct aiocb a; return aio_error(&a);', 'HAVE_AIO_ERROR', msg='Checking for aio_error', headers='aio.h', lib='aio rt')
439             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')
440             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')
441         if conf.CONFIG_SET('HAVE_AIO64'):
442             conf.CHECK_CODE('struct aiocb a; return aio_read64(&a);', 'HAVE_AIO_READ64', msg='Checking for aio_read64', headers='aio.h', lib='aio rt')
443             conf.CHECK_CODE('struct aiocb a; return aio_write64(&a);', 'HAVE_AIO_WRITE64', msg='Checking for aio_write64', headers='aio.h', lib='aio rt')
444             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')
445             conf.CHECK_CODE('struct aiocb a; return aio_return64(&a);', 'HAVE_AIO_RETURN64', msg='Checking for aio_return64', headers='aio.h', lib='aio rt')
446             conf.CHECK_CODE('struct aiocb a; return aio_error64(&a);', 'HAVE_AIO_ERROR64', msg='Checking for aio_error64', headers='aio.h', lib='aio rt')
447             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')
448             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')
449     else:
450         conf.DEFINE('HAVE_NO_AIO', '1')
451
452     conf.CHECK_CODE('''
453 struct msghdr msg;
454 union {
455         struct cmsghdr cm;
456         char control[CMSG_SPACE(sizeof(int))];
457 } control_un;
458 msg.msg_control = control_un.control;
459 msg.msg_controllen = sizeof(control_un.control);
460 ''',
461         'HAVE_MSGHDR_MSG_CONTROL',
462         msg='Checking if we can use msg_control for passing file descriptors',
463         headers='sys/types.h stdlib.h stddef.h sys/socket.h sys/un.h')
464     conf.CHECK_CODE('''
465 struct msghdr msg;
466 int fd;
467 msg.msg_acctrights = (caddr_t) &fd;
468 msg.msg_acctrightslen = sizeof(fd);
469 ''',
470         'HAVE_MSGHDR_MSG_ACCTRIGHTS',
471         msg='Checking if we can use msg_acctrights for passing file descriptors',
472         headers='sys/types.h stdlib.h stddef.h sys/socket.h sys/un.h')
473
474     if Options.options.with_winbind:
475         conf.env.build_winbind = True
476         conf.DEFINE('WITH_WINBIND', '1')
477
478     conf.find_program('awk', var='AWK')
479     conf.find_program('perl', var='PERL')
480
481     # Darwin has extra options to xattr-family functions
482     conf.CHECK_CODE('getxattr(0, 0, 0, 0, 0, 0);',
483                     'XATTR_ADD_OPT',
484                     msg="Checking whether xattr interface takes additional options",
485                     headers='sys/types.h attr/xattr.h sys/xattr.h')
486
487     conf.CHECK_HEADERS('asm/types.h')
488
489     conf.CHECK_CODE('dev_t dev; int i = major(dev); return 0', "HAVE_DEVICE_MAJOR_FN",
490                     headers='unistd.h sys/types.h',
491                     msg="Checking for major macro")
492
493     conf.CHECK_CODE('dev_t dev; int i = minor(dev); return 0', "HAVE_DEVICE_MINOR_FN",
494                     headers='unistd.h sys/types.h',
495                     msg="Checking for minor macro")
496
497     conf.CHECK_STRUCTURE_MEMBER('struct dirent', 'd_off',
498                                 headers='unistd.h sys/types.h dirent.h',
499                                 define='HAVE_DIRENT_D_OFF')
500
501     conf.CHECK_FUNCS('setnetgrent getnetgrent endnetgrent')
502     conf.CHECK_CODE('setnetgrent("foo")', 'HAVE_SETNETGRENT_PROTOTYPE',
503                     msg="Checking for setnetgrent prototype",
504                     headers='netdb.h netgroup.h',
505                     cflags="-Werror-implicit-function-declaration")
506     conf.CHECK_CODE('getnetgrent', 'HAVE_GETNETGRENT_PROTOTYPE',
507                     msg="Checking for getnetgrent prototype",
508                     headers='netdb.h netgroup.h',
509                     cflags="-Werror-implicit-function-declaration")
510     conf.CHECK_CODE('endnetgrent', 'HAVE_ENDNETGRENT_PROTOTYPE',
511                     msg="Checking for endnetgrent prototype",
512                     headers='netdb.h netgroup.h',
513                     cflags="-Werror-implicit-function-declaration")
514
515
516     # Look for CUPS
517     if Options.options.with_cups:
518         conf.find_program('cups-config', var='CUPS_CONFIG')
519         if conf.env.CUPS_CONFIG:
520             conf.check_cfg(path=conf.env.CUPS_CONFIG, args="--cflags --ldflags --libs",
521                            package="", uselib_store="cups")
522         conf.CHECK_HEADERS('cups/cups.h cups/language.h', lib='cups')
523         conf.CHECK_FUNCS_IN('httpConnect httpConnectEncrypt', conf.env.LIB_cups)
524         if conf.CONFIG_SET('HAVE_CUPS_CUPS_H') and conf.CONFIG_SET('HAVE_CUPS_LANGUAGE_H'):
525             conf.DEFINE('HAVE_CUPS', '1')
526         else:
527             conf.undefine('HAVE_CUPS')
528     else:
529         # define an empty subsystem for cups, to allow it to be used as an empty dependency
530         conf.SET_TARGET_TYPE('cups', 'EMPTY')
531
532     if Options.options.with_iprint:
533         if conf.CONFIG_SET('HAVE_CUPS'):
534             conf.DEFINE('HAVE_IPRINT', '1')
535         else:
536             print "--enable-iprint=yes but cups support not sufficient"
537     if Options.options.with_syslog:
538         conf.DEFINE('WITH_SYSLOG', '1')
539     if Options.options.with_automount:
540         conf.DEFINE('WITH_AUTOMOUNT', '1')
541
542     # Check for LDAP
543     if Options.options.with_ldap:
544         conf.CHECK_HEADERS('ldap.h lber.h')
545         conf.CHECK_TYPE('ber_tag_t', 'unsigned int', headers='ldap.h lber.h')
546         conf.CHECK_FUNCS_IN('ber_scanf ber_sockbuf_add_io', 'lber')
547         conf.CHECK_VARIABLE('LDAP_OPT_SOCKBUF', headers='ldap.h')
548         # if ber_sockbuf_add_io() and LDAP_OPT_SOCKBUF are available, we can add
549         # SASL wrapping hooks
550         if conf.CONFIG_SET('HAVE_BER_SOCKBUF_ADD_IO') and \
551                 conf.CONFIG_SET('HAVE_LDAP_OPT_SOCKBUF'):
552             conf.DEFINE('HAVE_LDAP_SASL_WRAPPING', '1')
553
554         # if we LBER_OPT_LOG_PRINT_FN we can intercept ldap logging and print it out
555         # for the samba logs
556         conf.CHECK_VARIABLE('LBER_OPT_LOG_PRINT_FN',
557                             define='HAVE_LBER_LOG_PRINT_FN', headers='lber.h')
558
559         conf.CHECK_FUNCS_IN('ldap_init ldap_initialize ldap_set_rebind_proc', 'ldap')
560         conf.CHECK_FUNCS_IN('ldap_add_result_entry', 'ldap')
561
562         # Check if ldap_set_rebind_proc() takes three arguments
563         if conf.CHECK_CODE('ldap_set_rebind_proc(0, 0, 0)',
564                            'LDAP_SET_REBIND_PROC_ARGS',
565                            msg="Checking whether ldap_set_rebind_proc takes 3 arguments",
566                            headers='ldap.h lber.h', link=False):
567             conf.DEFINE('LDAP_SET_REBIND_PROC_ARGS', '3')
568         else:
569             conf.DEFINE('LDAP_SET_REBIND_PROC_ARGS', '2')
570
571         # last but not least, if ldap_init() exists, we want to use ldap
572         if conf.CONFIG_SET('HAVE_LDAP_INIT'):
573             conf.DEFINE('HAVE_LDAP', '1')
574             conf.DEFINE('LDAP_DEPRECATED', '1')
575             conf.env['HAVE_LDAP'] = '1'
576     else:
577         conf.SET_TARGET_TYPE('ldap', 'EMPTY')
578         conf.SET_TARGET_TYPE('lber', 'EMPTY')
579
580     # Check for kerberos
581     have_gssapi=False
582     if Options.options.with_krb5:
583         conf.find_program('krb5-config', var='KRB5_CONFIG')
584         if conf.env.KRB5_CONFIG:
585             conf.check_cfg(path="krb5-config", args="--cflags --libs",
586                        package="gssapi", uselib_store="krb5")
587         conf.CHECK_HEADERS('krb5.h krb5/locate_plugin.h', lib='krb5')
588         conf.CHECK_HEADERS('gssapi.h gssapi/gssapi_generic.h gssapi/gssapi.h gssapi/gssapi_ext.h com_err.h', lib='krb5')
589
590         if conf.CONFIG_SET('HAVE_KRB5_LOCATE_PLUGIN_H'):
591             conf.env['WINBIND_KRB5_LOCATOR'] = 'bin/winbind_krb5_locator.so'
592
593         conf.CHECK_FUNCS_IN('_et_list', 'com_err')
594         conf.CHECK_FUNCS_IN('krb5_encrypt_data', 'k5crypto')
595         conf.CHECK_FUNCS_IN('crypto', 'des_set_key')
596         conf.CHECK_FUNCS_IN('copy_Authenticator', 'asn1')
597         conf.CHECK_FUNCS_IN('roken_getaddrinfo_hostspec', 'roken')
598         if conf.CHECK_FUNCS_IN('gss_display_status', 'gssapi') or \
599            conf.CHECK_FUNCS_IN('gss_display_status', 'gssapi_krb5'):
600             have_gssapi=True
601         conf.CHECK_FUNCS_IN('gss_wrap_iov', 'gssapi gssapi_krb5 krb5')
602         conf.CHECK_FUNCS_IN('krb5_mk_req_extended krb5_kt_compare', 'krb5')
603         conf.CHECK_FUNCS('''
604 krb5_set_real_time krb5_set_default_in_tkt_etypes krb5_set_default_tgs_enctypes
605 krb5_set_default_tgs_ktypes krb5_principal2salt krb5_use_enctype
606 krb5_string_to_key krb5_get_pw_salt krb5_string_to_key_salt krb5_auth_con_setkey
607 krb5_auth_con_setuseruserkey krb5_locate_kdc krb5_get_permitted_enctypes
608 krb5_get_default_in_tkt_etypes krb5_free_data_contents
609 krb5_principal_get_comp_string krb5_free_unparsed_name
610 krb5_free_keytab_entry_contents krb5_kt_free_entry krb5_krbhst_init
611 krb5_krbhst_get_addrinfo krb5_c_enctype_compare krb5_enctypes_compatible_keys
612 krb5_crypto_init krb5_crypto_destroy krb5_decode_ap_req free_AP_REQ
613 krb5_verify_checksum krb5_c_verify_checksum krb5_principal_compare_any_realm
614 krb5_parse_name_norealm krb5_princ_size krb5_get_init_creds_opt_set_pac_request
615 krb5_get_renewed_creds krb5_get_kdc_cred krb5_free_error_contents
616 initialize_krb5_error_table krb5_get_init_creds_opt_alloc
617 krb5_get_init_creds_opt_free krb5_get_init_creds_opt_get_error
618 krb5_enctype_to_string krb5_fwd_tgt_creds krb5_auth_con_set_req_cksumtype
619 krb5_get_creds_opt_alloc krb5_get_creds_opt_set_impersonate krb5_get_creds
620 krb5_get_credentials_for_user krb5_get_host_realm krb5_free_host_realm''',
621                          lib='krb5 k5crypto')
622         conf.CHECK_DECLS('''krb5_get_credentials_for_user
623                             krb5_auth_con_set_req_cksumtype''',
624                             headers='krb5.h', always=True)
625         conf.CHECK_VARIABLE('AP_OPTS_USE_SUBKEY', headers='krb5.h')
626         conf.CHECK_VARIABLE('KV5M_KEYTAB', headers='krb5.h')
627         conf.CHECK_VARIABLE('KRB5_KU_OTHER_CKSUM', headers='krb5.h')
628         conf.CHECK_VARIABLE('KRB5_KEYUSAGE_APP_DATA_CKSUM', headers='krb5.h')
629         conf.CHECK_STRUCTURE_MEMBER('krb5_keytab_entry', 'key', headers='krb5.h',
630                                     define='HAVE_KRB5_KEYTAB_ENTRY_KEY')
631         conf.CHECK_STRUCTURE_MEMBER('krb5_keytab_entry', 'keyblock', headers='krb5.h',
632                                     define='HAVE_KRB5_KEYTAB_ENTRY_KEYBLOCK')
633         conf.CHECK_STRUCTURE_MEMBER('krb5_address', 'magic', headers='krb5.h',
634                                     define='HAVE_MAGIC_IN_KRB5_ADDRESS')
635         conf.CHECK_STRUCTURE_MEMBER('krb5_address', 'addrtype', headers='krb5.h',
636                                     define='HAVE_ADDRTYPE_IN_KRB5_ADDRESS')
637         conf.CHECK_STRUCTURE_MEMBER('krb5_ticket', 'enc_part2', headers='krb5.h',
638                                     define='HAVE_KRB5_TKT_ENC_PART2')
639         conf.CHECK_STRUCTURE_MEMBER('krb5_creds', 'keyblock', headers='krb5.h',
640                                     define='HAVE_KRB5_KEYBLOCK_IN_CREDS')
641         conf.CHECK_STRUCTURE_MEMBER('krb5_creds', 'session', headers='krb5.h',
642                                     define='HAVE_KRB5_SESSION_IN_CREDS')
643         conf.CHECK_STRUCTURE_MEMBER('krb5_ap_req', 'ticket', headers='krb5.h',
644                                     define='HAVE_TICKET_POINTER_IN_KRB5_AP_REQ')
645
646         conf.CHECK_TYPE('krb5_encrypt_block', headers='krb5.h')
647
648         conf.CHECK_CODE('''
649 krb5_ticket ticket;
650 krb5_kvno kvno;
651 krb5_enctype enctype;
652 enctype = ticket.enc_part.enctype;
653 kvno = ticket.enc_part.kvno;
654 ''',
655                         'KRB5_TICKET_HAS_KEYINFO',
656                         headers='krb5.h', link=False,
657                         msg="Checking whether the krb5_ticket structure contains the kvno and enctype")
658         conf.CHECK_CODE('''
659 krb5_context ctx;
660 krb5_get_init_creds_opt *opt = NULL;
661 krb5_get_init_creds_opt_free(ctx, opt);
662 ''',
663                         'KRB5_CREDS_OPT_FREE_REQUIRES_CONTEXT',
664                         headers='krb5.h', link=False,
665                         msg="Checking whether krb5_get_init_creds_opt_free takes a context argument")
666         conf.CHECK_CODE('krb5_mk_error(0,0,0)',
667                         'HAVE_SHORT_KRB5_MK_ERROR_INTERFACE',
668                         headers='krb5.h', link=False,
669                         msg="Checking whether krb5_mk_error takes 3 arguments MIT or 9 Heimdal")
670         conf.CHECK_CODE('''
671 const krb5_data *pkdata;
672 krb5_context context;
673 krb5_principal principal;
674 pkdata = krb5_princ_component(context, principal, 0);
675 ''',
676                         'HAVE_KRB5_PRINC_COMPONENT',
677                         headers='krb5.h', lib='krb5',
678                         msg="Checking whether krb5_princ_component is available")
679
680         conf.CHECK_CODE('''
681 int main(void) {
682 char buf[256];
683 krb5_enctype_to_string(1, buf, 256);
684 return 0;
685 }''',
686                         'HAVE_KRB5_ENCTYPE_TO_STRING_WITH_SIZE_T_ARG',
687                         headers='krb5.h', lib='krb5 k5crypto',
688                         addmain=False, cflags='-Werror',
689                         msg="Checking whether krb5_enctype_to_string takes size_t argument")
690
691         conf.CHECK_CODE('''
692 int main(void) {
693 krb5_context context = NULL;
694 char *str = NULL;
695 krb5_enctype_to_string(context, 1, &str);
696 if (str) free (str);
697 return 0;
698 }''',
699                         'HAVE_KRB5_ENCTYPE_TO_STRING_WITH_KRB5_CONTEXT_ARG',
700                         headers='krb5.h stdlib.h', lib='krb5',
701                         addmain=False, cflags='-Werror',
702                         msg="Checking whether krb5_enctype_to_string takes krb5_context argument")
703         conf.CHECK_CODE('''
704 int main(void) {
705 krb5_context ctx = NULL;
706 krb5_principal princ = NULL;
707 const char *str = krb5_princ_realm(ctx, princ)->data;
708 return 0;
709 }''',
710                         'HAVE_KRB5_PRINC_REALM',
711                         headers='krb5.h', lib='krb5',
712                         addmain=False,
713                         msg="Checking whether the macro krb5_princ_realm is defined")
714         if conf.CHECK_CODE('''krb5_verify_checksum(0, 0, 0, 0, 0, 0, 0);''',
715                         'KRB5_VERIFY_CHECKSUM_ARGS',
716                         headers='krb5.h', lib='krb5',
717                         msg="Checking whether krb5_verify_checksum takes 7 arguments"):
718             conf.DEFINE('KRB5_VERIFY_CHECKSUM_ARGS', '7')
719         else:
720             conf.DEFINE('KRB5_VERIFY_CHECKSUM_ARGS', '6')
721
722         conf.CHECK_CODE('''
723 krb5_enctype enctype;
724 enctype = ENCTYPE_ARCFOUR_HMAC_MD5;
725 ''',
726             '_HAVE_ENCTYPE_ARCFOUR_HMAC_MD5',
727             headers='krb5.h', lib='krb5',
728             msg="Checking whether the ENCTYPE_ARCFOUR_HMAC_MD5 key type definition is available");
729         conf.CHECK_CODE('''
730 krb5_keytype keytype;
731 keytype = KEYTYPE_ARCFOUR_56;
732 ''',
733             '_HAVE_KEYTYPE_ARCFOUR_56',
734             headers='krb5.h', lib='krb5',
735             msg="Checking whether the HAVE_KEYTYPE_ARCFOUR_56 key type definition is available");
736         if conf.CONFIG_SET('_HAVE_ENCTYPE_ARCFOUR_HMAC_MD5') and conf.CONFIG_SET('_HAVE_KEYTYPE_ARCFOUR_56'):
737             conf.DEFINE('HAVE_ENCTYPE_ARCFOUR_HMAC_MD5', '1')
738
739         conf.CHECK_CODE('''
740 krb5_enctype enctype;
741 enctype = ENCTYPE_ARCFOUR_HMAC;
742 ''',
743             'HAVE_ENCTYPE_ARCFOUR_HMAC',
744             headers='krb5.h', lib='krb5',
745             msg="Checking whether the ENCTYPE_ARCFOUR_HMAC key type definition is available");
746
747         conf.CHECK_CODE('''
748 krb5_context context;
749 krb5_keytab keytab;
750 krb5_init_context(&context);
751 return krb5_kt_resolve(context, "WRFILE:api", &keytab);
752 ''',
753             'HAVE_WRFILE_KEYTAB',
754             headers='krb5.h', lib='krb5', execute=True,
755             msg="Checking whether the WRFILE:-keytab is supported");
756
757     else:
758         conf.SET_TARGET_TYPE('krb5', 'EMPTY')
759         conf.SET_TARGET_TYPE('gssapi', 'EMPTY')
760         conf.SET_TARGET_TYPE('gssapi_krb5', 'EMPTY')
761         conf.SET_TARGET_TYPE('com_err', 'EMPTY')
762         conf.SET_TARGET_TYPE('k5crypto', 'EMPTY')
763
764     if Options.options.with_ads:
765         use_ads=True
766         if not conf.CONFIG_SET('HAVE_ENCTYPE_ARCFOUR_HMAC_MD5') and \
767            not conf.CONFIG_SET('HAVE_ENCTYPE_ARCFOUR_HMAC'):
768             print "arcfour-hmac-md5 encryption type not found in -lkrb5"
769             use_ads=False
770         if not conf.CONFIG_SET('HAVE_KRB5_MK_REQ_EXTENDED'):
771             print "krb5_mk_req_extended not found in -lkrb5"
772             use_ads=False
773         if not conf.CONFIG_SET('HAVE_KRB5_PRINCIPAL2SALT') and \
774            not conf.CONFIG_SET('HAVE_KRB5_GET_PW_SALT'):
775             print "no CREATE_KEY_FUNCTIONS detected"
776             use_ads=False
777         if not conf.CONFIG_SET('HAVE_KRB5_GET_PERMITTED_ENCTYPES') and \
778            not conf.CONFIG_SET('HAVE_KRB5_GET_DEFAULT_IN_TKT_ETYPES'):
779             print "no GET_ENCTYPES_FUNCTIONS detected"
780             use_ads=False
781         if not conf.CONFIG_SET('HAVE_KRB5_KT_FREE_ENTRY') and \
782            not conf.CONFIG_SET('HAVE_KRB5_FREE_KEYTAB_ENTRY_CONTENTS'):
783             print "no KT_FREE_FUNCTION detected"
784             use_ads=False
785         if not conf.CONFIG_SET('HAVE_KRB5_C_VERIFY_CHECKSUM') and \
786            not conf.CONFIG_SET('HAVE_KRB5_VERIFY_CHECKSUM'):
787             print "no KRB5_VERIFY_CHECKSUM_FUNCTION detected"
788             use_ads=False
789         if not conf.CONFIG_SET('KRB5_TICKET_HAS_KEYINFO'):
790             # We only need the following functions if we can't get the enctype
791             # and kvno out of the ticket directly (ie. on Heimdal).
792             if not conf.CONFIG_SET('free_AP_REQ'):
793                 print "no KRB5_AP_REQ_FREE_FUNCTION detected"
794                 use_ads=False
795             if not conf.CONFIG_SET('HAVE_KRB5_DECODE_AP_REQ'):
796                 print "no KRB5_AP_REQ_DECODING_FUNCTION detected"
797                 use_ads=False
798         if use_ads:
799             conf.DEFINE('WITH_ADS', '1')
800             conf.DEFINE('HAVE_KRB5', '1')
801             if have_gssapi:
802                 conf.DEFINE('HAVE_GSSAPI', '1')
803         else:
804             print "krb5 libs don't have all features required for Active Directory support"
805             conf.undefine('HAVE_KRB5_H')
806             conf.undefine('HAVE_GSSAPI_H')
807             conf.undefine('HAVE_GSSAPI_GSSAPI_GENERIC_H')
808             conf.undefine('HAVE_GSSAPI_GSSAPI_H')
809
810     if Options.options.with_utmp:
811         conf.CHECK_FUNCS('pututline pututxline updwtmp updwtmpx getutmpx getutxent')
812         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_name', headers='utmp.h',
813                                     define='HAVE_UT_UT_NAME')
814         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_user', headers='utmp.h',
815                                     define='HAVE_UT_UT_USER')
816         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_id', headers='utmp.h',
817                                     define='HAVE_UT_UT_ID')
818         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_host', headers='utmp.h',
819                                     define='HAVE_UT_UT_HOST')
820         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_time', headers='utmp.h',
821                                     define='HAVE_UT_UT_TIME')
822         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_tv', headers='utmp.h',
823                                     define='HAVE_UT_UT_TV')
824         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_type', headers='utmp.h',
825                                     define='HAVE_UT_UT_TYPE')
826         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_pid', headers='utmp.h',
827                                     define='HAVE_UT_UT_PID')
828         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_exit.e_exit', headers='utmp.h',
829                                     define='HAVE_UT_UT_EXIT')
830         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_addr_v6', headers='utmp.h',
831                                     define='HAVE_UT_UT_ADDR_V6')
832         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_addr', headers='utmp.h',
833                                     define='HAVE_UT_UT_ADDR')
834         conf.CHECK_STRUCTURE_MEMBER('struct utmpx', 'ut_syslen', headers='utmpx.h',
835                                     define='HAVE_UX_UT_SYSLEN')
836         conf.CHECK_CODE('struct utmp utarg; struct utmp *utreturn; utreturn = pututline(&utarg);',
837                         'PUTUTLINE_RETURNS_UTMP', headers='utmp.h',
838                         msg="Checking whether pututline returns pointer")
839         conf.DEFINE('WITH_UTMP', 1)
840
841     if Options.options.with_avahi:
842         conf.env.with_avahi = True
843         if not conf.CHECK_HEADERS('avahi-common/watch.h avahi-client/client.h'): conf.env.with_avahi = False
844         if not conf.CHECK_FUNCS_IN('avahi_client_new', 'avahi-client'): conf.env.with_avahi = False
845         if not conf.CHECK_FUNCS_IN('avahi_strerror', 'avahi-common'): conf.env.with_avahi = False
846         if conf.env.with_avahi:
847             conf.DEFINE('WITH_AVAHI_SUPPORT', 1)
848     else:
849         conf.SET_TARGET_TYPE('avahi-common', 'EMPTY')
850         conf.SET_TARGET_TYPE('avahi-client', 'EMPTY')
851
852     if Options.options.with_iconv:
853         conf.env.with_iconv = True
854         if not conf.CHECK_FUNCS_IN('iconv_open', 'iconv', headers='iconv.h'):
855             conf.env.with_iconv = False
856         if conf.env.with_iconv:
857             conf.DEFINE('HAVE_ICONV', 1)
858
859     if Options.options.with_pam:
860         use_pam=True
861         conf.CHECK_HEADERS('security/pam_appl.h pam/pam_appl.h')
862         if not conf.CONFIG_SET('HAVE_SECURITY_PAM_APPL_H') and not conf.CONFIG_SET('HAVE_PAM_PAM_APPL_H'):
863             print "--with-pam=yes but pam_appl.h not found"
864             use_pam=False
865         conf.CHECK_FUNCS_IN('pam_get_data', 'pam')
866         conf.CHECK_HEADERS('security/pam_modules.h pam/pam_modules.h')
867         if not conf.CONFIG_SET('HAVE_SECURITY_PAM_MODULES_H') and not conf.CONFIG_SET('HAVE_PAM_PAM_MODULES_H'):
868             print "--with-pam=yes but pam_modules.h not found"
869             use_pam=False
870         conf.CHECK_HEADERS('security/pam_ext.h security/_pam_macros.h')
871         conf.CHECK_HEADERS('pam/pam_ext.h pam/_pam_macros.h')
872         conf.CHECK_FUNCS_IN('pam_vsyslog', 'pam')
873         conf.CHECK_CODE('''
874 #if defined(HAVE_SECURITY_PAM_APPL_H)
875 #include <security/pam_appl.h>
876 #elif defined(HAVE_PAM_PAM_APPL_H)
877 #include <pam/pam_appl.h>
878 #endif
879 pam_set_item(0, PAM_RHOST, 0);
880 ''',
881             'HAVE_PAM_RHOST',
882             lib='pam',
883             msg="Checking whether PAM_RHOST is available");
884         conf.CHECK_CODE('''
885 #if defined(HAVE_SECURITY_PAM_APPL_H)
886 #include <security/pam_appl.h>
887 #elif defined(HAVE_PAM_PAM_APPL_H)
888 #include <pam/pam_appl.h>
889 #endif
890 pam_set_item(0, PAM_TTY, 0);
891 ''',
892             'HAVE_PAM_TTY',
893             lib='pam',
894             msg="Checking whether PAM_TTY is available");
895         conf.CHECK_CODE('''
896 #if (!defined(LINUX))
897
898 #define PAM_EXTERN extern
899 #if defined(HAVE_SECURITY_PAM_APPL_H)
900 #include <security/pam_appl.h>
901 #elif defined(HAVE_PAM_PAM_APPL_H)
902 #include <pam/pam_appl.h>
903 #endif
904
905 #endif
906
907 #if defined(HAVE_SECURITY_PAM_MODULES_H)
908 #include <security/pam_modules.h>
909 #elif defined(HAVE_PAM_PAM_MODULES_H)
910 #include <pam/pam_modules.h>
911 #endif
912
913 #if defined(HAVE_SECURITY__PAM_MACROS_H)
914 #include <security/_pam_macros.h>
915 #elif defined(HAVE_PAM__PAM_MACROS_H)
916 #include <pam/_pam_macros.h>
917 #endif
918
919 #ifdef HAVE_SECURITY_PAM_EXT_H
920 #include <security/pam_ext.h>
921 #endif
922
923 int i; i = PAM_RADIO_TYPE;
924 ''',
925             'HAVE_PAM_RADIO_TYPE',
926             lib='pam',
927             msg="Checking whether PAM_RADIO_TYPE is available");
928         if use_pam:
929             conf.DEFINE('WITH_PAM', 1)
930             conf.DEFINE('WITH_PAM_MODULES', 1)
931
932     seteuid = False
933     if not seteuid:
934         seteuid = conf.CHECK_CODE('''
935                                 #define AUTOCONF_TEST 1
936                                 #define USE_SETREUID 1
937                                 #include "./lib/util_sec.c"
938                                 ''',
939                                 'USE_SETREUID',
940                                 addmain=False,
941                                 execute=True,
942                                 msg="Checking whether setreuid is available")
943     if not seteuid:
944         seteuid = conf.CHECK_CODE('''
945                                 #define AUTOCONF_TEST 1
946                                 #define USE_SETRESUID 1
947                                 #include "./lib/util_sec.c"
948                                 ''',
949                                 'USE_SETRESUID',
950                                 addmain=False,
951                                 execute=True,
952                                 msg="Checking whether setresuid is available")
953     if not seteuid:
954         seteuid = conf.CHECK_CODE('''
955                                 #define AUTOCONF_TEST 1
956                                 #define USE_SETEUID 1
957                                 #include "./lib/util_sec.c"
958                                 ''',
959                                 'USE_SETEUID',
960                                 addmain=False,
961                                 execute=True,
962                                 msg="Checking whether seteuid is available")
963     if not seteuid:
964         seteuid = conf.CHECK_CODE('''
965                                 #define AUTOCONF_TEST 1
966                                 #define USE_SETUIDX 1
967                                 #include "./lib/util_sec.c"
968                                 ''',
969                                 'USE_SETUIDX',
970                                 addmain=False,
971                                 execute=True,
972                                 mandatory=True,
973                                 msg="Checking whether setuidx is available")
974     if Options.options.with_dnsupdate:
975         conf.CHECK_HEADERS('uuid/uuid.h')
976         conf.CHECK_FUNCS_IN('uuid_generate', 'uuid')
977         if not conf.CONFIG_SET('HAVE_UUID_UUID_H') and not conf.CONFIG_SET('HAVE_UUID_GENERATE'):
978             print "--with-dnsupdate=yes but uuid support not sufficient"
979         elif not conf.CONFIG_SET('HAVE_GSSAPI'):
980             print "--with-dnsupdate=yes but gssapi support not sufficient"
981         else:
982             conf.DEFINE('WITH_DNS_UPDATES', 1)
983     else:
984         conf.SET_TARGET_TYPE('uuid', 'EMPTY')
985     conf.CHECK_HEADERS('valgrind.h valgrind/valgrind.h valgrind/memcheck.h')
986     if Options.options.developer:
987         if conf.CONFIG_SET('HAVE_VALGRIND_H') or conf.CONFIG_SET('HAVE_VALGRIND_VALGRIND_H'):
988             conf.DEFINE('VALGRIND', '1')
989
990     if conf.CHECK_CODE('''
991 #include <bits/sockaddr.h>
992 #include <linux/netlink.h>
993 ''',
994                 'HAVE_LINUX_NETLINK_H',
995                 msg="Checking whether Linux netlink is available"):
996         conf.CHECK_CODE('''
997 #include <bits/sockaddr.h>
998 #include <linux/netlink.h>
999 #include <linux/rtnetlink.h>
1000 ''',
1001                 'HAVE_LINUX_RTNETLINK_H',
1002                 msg='Checking whether Linux rtnetlink is available')
1003
1004     default_static_modules=TO_LIST('''pdb_smbpasswd pdb_tdbsam pdb_wbc_sam
1005                                       auth_sam auth_unix auth_winbind auth_wbc auth_server
1006                                       auth_domain auth_builtin vfs_default
1007                                       nss_info_template idmap_tdb idmap_passdb
1008                                       idmap_nss''')
1009
1010     default_shared_modules=TO_LIST('''vfs_recycle vfs_audit vfs_extd_audit vfs_full_audit vfs_netatalk
1011                                       vfs_fake_perms vfs_default_quota vfs_readonly vfs_cap
1012                                       vfs_expand_msdfs vfs_shadow_copy vfs_shadow_copy2 charset_CP850
1013                                       charset_CP437 auth_script vfs_readahead vfs_xattr_tdb
1014                                       vfs_streams_xattr vfs_streams_depot vfs_acl_xattr vfs_acl_tdb
1015                                       vfs_smb_traffic_analyzer vfs_preopen vfs_catia vfs_scannedonly
1016                                       vfs_crossrename vfs_linux_xfs_sgid
1017                                       vfs_time_audit idmap_autorid''')
1018
1019     if Options.options.developer:
1020         default_static_modules.extend(TO_LIST('pdb_ads auth_netlogond'))
1021         default_shared_modules.extend(TO_LIST('charset_weird perfcount_test'))
1022
1023     if Options.options.with_acl_support and conf.CONFIG_SET('HAVE_POSIX_ACLS'):
1024         default_static_modules.extend(TO_LIST('vfs_posixacl'))
1025
1026     if conf.CONFIG_SET('HAVE_FREEBSD_SUNACL_H'):
1027         default_shared_modules.extend(TO_LIST('vfs_zfsacl'))
1028
1029     if conf.CONFIG_SET('HAVE_DIRFD_DECL'):
1030         default_shared_modules.extend(TO_LIST('vfs_syncops vfs_dirsort'))
1031
1032     if conf.CONFIG_SET('HAVE_STATFS_F_FSID'):
1033         default_shared_modules.extend(TO_LIST('vfs_fileid'))
1034
1035     if conf.CONFIG_SET('HAVE_AIO') and (conf.CONFIG_SET('HAVE_MSGHDR_MSG_CONTROL') or conf.CONFIG_SET('HAVE_MSGHDR_MSG_ACCTRIGHTS')):
1036         default_shared_modules.extend(TO_LIST('vfs_aio_fork'))
1037
1038     if conf.CONFIG_SET('HAVE_LDAP'):
1039         default_static_modules.extend(TO_LIST('pdb_ldap idmap_ldap'))
1040
1041     explicit_shared_modules = TO_LIST(Options.options.shared_modules, delimiter=',')
1042     explicit_static_modules = TO_LIST(Options.options.static_modules, delimiter=',')
1043
1044     final_static_modules = default_static_modules
1045     final_shared_modules = default_shared_modules
1046
1047     for m in explicit_static_modules:
1048         if m in final_shared_modules:
1049             final_shared_modules.remove(m)
1050         final_static_modules.append(m)
1051     for m in explicit_shared_modules:
1052         if m in final_static_modules:
1053             final_static_modules.remove(m)
1054         final_shared_modules.append(m)
1055
1056     conf.env['static_modules'] = final_static_modules
1057     conf.env['shared_modules'] = final_shared_modules
1058
1059     conf.DEFINE('STRING_STATIC_MODULES', ' '.join(final_static_modules), quote=True)
1060
1061     static_list = {}
1062     shared_list = {}
1063
1064     prefixes = ['vfs', 'pdb', 'auth', 'nss_info', 'charset', 'idmap', 'gpext', 'perfcount']
1065     conf.env['MODULE_PREFIXES'] = prefixes
1066     for p in prefixes:
1067         for m in final_static_modules:
1068             if m.find(p) == 0:
1069                 if not p in static_list:
1070                     static_list[p] = []
1071                 static_list[p].append(m)
1072         for m in final_shared_modules:
1073             if m.find(p) == 0:
1074                 if not p in shared_list:
1075                     shared_list[p] = []
1076                 shared_list[p].append(m)
1077
1078     for p in prefixes:
1079         static_env = "%s_STATIC" % p.upper()
1080         shared_env = "%s_SHARED" % p.upper()
1081         conf.env[static_env] = []
1082         conf.env[shared_env] = []
1083         if p in static_list:
1084             decl_list=""
1085             for entry in static_list[p]:
1086                 decl_list += "extern NTSTATUS %s_init(void); " % entry
1087                 conf.env[static_env].append('%s' % entry)
1088             decl_list = decl_list.rstrip()
1089             conf.DEFINE('static_decl_%s' % p, decl_list)
1090             conf.DEFINE('static_init_%s' % p, '{ %s_init(); }' % '_init();  '.join(static_list[p]))
1091         else:
1092             conf.DEFINE('static_decl_%s' % p, '')
1093             conf.DEFINE('static_init_%s' % p, '{}')
1094         if p in shared_list:
1095             for entry in shared_list[p]:
1096                 conf.DEFINE('%s_init' % entry, 'init_samba_module')
1097                 conf.env[shared_env].append('%s' % entry)
1098
1099     conf.SAMBA_CONFIG_H('include/config.h')
1100
1101 def ctags(ctx):
1102     "build 'tags' file using ctags"
1103     import Utils
1104     source_root = os.path.dirname(Utils.g_module.root_path)
1105     cmd = 'ctags $(find %s/.. -name "*.[ch]" | grep -v "*_proto\.h")' % source_root
1106     print("Running: %s" % cmd)
1107     os.system(cmd)