s3:wscript: fix the build without any idmap module
[nivanova/samba-autobuild/.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
25     opt.SAMBA3_ADD_OPTION('winbind')
26     opt.SAMBA3_ADD_OPTION('ads')
27     opt.SAMBA3_ADD_OPTION('ldap')
28     opt.SAMBA3_ADD_OPTION('cups', with_name="enable", without_name="disable")
29     opt.SAMBA3_ADD_OPTION('iprint', with_name="enable", without_name="disable")
30     opt.SAMBA3_ADD_OPTION('pam')
31     opt.SAMBA3_ADD_OPTION('pam_smbpass')
32     opt.SAMBA3_ADD_OPTION('quotas')
33     opt.SAMBA3_ADD_OPTION('sendfile-support')
34     opt.SAMBA3_ADD_OPTION('utmp')
35     opt.SAMBA3_ADD_OPTION('pthreadpool', with_name="enable", without_name="disable", default=True)
36     opt.SAMBA3_ADD_OPTION('avahi', with_name="enable", without_name="disable")
37     opt.SAMBA3_ADD_OPTION('iconv')
38     opt.SAMBA3_ADD_OPTION('acl-support')
39     opt.SAMBA3_ADD_OPTION('dnsupdate')
40     opt.SAMBA3_ADD_OPTION('syslog')
41     opt.SAMBA3_ADD_OPTION('automount')
42     opt.SAMBA3_ADD_OPTION('aio-support')
43     opt.SAMBA3_ADD_OPTION('dmapi', default=None) # None means autodetection
44     opt.SAMBA3_ADD_OPTION('fam', default=None) # None means autodetection
45     opt.SAMBA3_ADD_OPTION('profiling-data', default=False)
46     opt.SAMBA3_ADD_OPTION('libarchive', default=None)
47
48     opt.SAMBA3_ADD_OPTION('cluster-support', default=None)
49
50     opt.SAMBA3_ADD_OPTION('regedit', default=None)
51
52     opt.SAMBA3_ADD_OPTION('fake-kaserver',
53                           help=("Include AFS fake-kaserver support"), default=False)
54
55     opt.add_option('--with-libcephfs',
56                    help=("Directory under which libcephfs is installed"),
57                    action="store", dest='libcephfs_dir', default=None)
58
59     opt.SAMBA3_ADD_OPTION('glusterfs', with_name="enable", without_name="disable", default=True)
60
61     opt.add_option('--enable-vxfs',
62                   help=("enable support for VxFS (default=no)"),
63                   action="store_true", dest='enable_vxfs', default=False)
64
65     opt.SAMBA3_ADD_OPTION('spotlight', with_name="enable", without_name="disable", default=False)
66
67 def configure(conf):
68     from samba_utils import TO_LIST
69
70     default_static_modules = []
71     default_shared_modules = []
72
73     if Options.options.developer:
74         conf.ADD_CFLAGS('-DDEVELOPER -DDEBUG_PASSWORD')
75         conf.env.developer = True
76
77     if sys.platform != 'openbsd5':
78         conf.ADD_LDFLAGS("-Wl,--export-dynamic", testflags=True)
79
80     conf.CHECK_HEADERS('execinfo.h libexc.h libunwind.h netdb.h')
81     conf.CHECK_HEADERS('linux/falloc.h linux/ioctl.h')
82
83     conf.CHECK_FUNCS('getcwd fchown chmod fchmod mknod')
84     conf.CHECK_FUNCS('strtol strchr strupr chflags')
85     conf.CHECK_FUNCS('getrlimit fsync fdatasync setpgid')
86     conf.CHECK_FUNCS('setsid glob strpbrk crypt16 getauthuid')
87     conf.CHECK_FUNCS('innetgr')
88     conf.CHECK_FUNCS('initgroups select poll rdchk getgrnam getgrent pathconf')
89     conf.CHECK_FUNCS('setpriv setgidx setuidx setgroups syscall sysconf')
90     conf.CHECK_FUNCS('atexit grantpt posix_openpt fallocate posix_fallocate')
91     conf.CHECK_FUNCS('fseeko setluid')
92     conf.CHECK_FUNCS('getpwnam', headers='sys/types.h pwd.h')
93     conf.CHECK_FUNCS('fdopendir')
94     conf.CHECK_FUNCS('fstatat')
95     conf.CHECK_FUNCS('getpwent_r setenv strcasecmp fcvt fcvtl')
96     conf.CHECK_FUNCS('syslog vsyslog timegm setlocale')
97     conf.CHECK_FUNCS_IN('nanosleep', 'rt')
98     conf.CHECK_FUNCS('lutimes futimes utimensat futimens')
99     conf.CHECK_FUNCS('mlock munlock mlockall munlockall')
100     conf.CHECK_FUNCS('memalign posix_memalign hstrerror')
101     conf.CHECK_FUNCS('shmget')
102     conf.CHECK_FUNCS_IN('shm_open', 'rt', checklibc=True)
103     #FIXME: for some reason this one still fails
104     conf.CHECK_FUNCS_IN('yp_get_default_domain', 'nsl')
105     conf.CHECK_FUNCS_IN('dn_expand _dn_expand __dn_expand', 'resolv')
106     conf.CHECK_FUNCS_IN('dn_expand', 'inet')
107     conf.CHECK_DECLS('fdatasync', reverse=True)
108     conf.CHECK_DECLS('readahead', reverse=True, headers='fcntl.h')
109
110     if conf.CHECK_CODE('''
111 #if defined(HAVE_UNISTD_H)
112 #include <unistd.h>
113 #endif
114 long ret = splice(0,0,1,0,400,SPLICE_F_MOVE);
115 ''',
116         'HAVE_LINUX_SPLICE',
117         headers='fcntl.h'):
118         conf.CHECK_DECLS('splice', reverse=True, headers='fcntl.h')
119
120     # Check for inotify support
121     conf.CHECK_HEADERS('sys/inotify.h')
122     if "HAVE_SYS_INOTIFY_H" in conf.env:
123         conf.DEFINE('HAVE_INOTIFY', 1)
124
125     # Check for kernel change notify support
126     conf.CHECK_CODE('''
127 #ifndef F_NOTIFY
128 #define F_NOTIFY 1026
129 #endif
130 main() {
131         exit(fcntl(open("/tmp", O_RDONLY), F_NOTIFY, 0) == -1 ?  1 : 0);
132 }''', 'HAVE_KERNEL_CHANGE_NOTIFY', addmain=False, execute=True,
133         headers='fcntl.h signal.h',
134         msg="Checking for kernel change notify support")
135
136     # Check for Linux kernel oplocks
137     conf.CHECK_CODE('''
138 #include <sys/types.h>
139 #include <fcntl.h>
140 #include <signal.h>
141 #ifndef F_NOTIFY
142 #define F_NOTIFY 1026
143 #endif
144 main() {
145         exit(fcntl(open("/tmp", O_RDONLY), F_NOTIFY, 0) == -1 ?  1 : 0);
146 }''', 'HAVE_KERNEL_OPLOCKS_LINUX', addmain=False, execute=True,
147         msg="Checking for Linux kernel oplocks")
148
149     # Check for IRIX kernel oplock types
150     conf.CHECK_CODE('oplock_stat_t t; t.os_state = OP_REVOKE; t.os_dev = 1; t.os_ino = 1;',
151                     'HAVE_KERNEL_OPLOCKS_IRIX', headers='fcntl.h',
152                     msg="Checking for IRIX kernel oplock types")
153
154     # Check for kernel share modes
155     conf.CHECK_CODE('''
156 #include <sys/types.h>
157 #include <fcntl.h>
158 #include <signal.h>
159 #include <sys/file.h>
160 #ifndef LOCK_MAND
161 #define LOCK_MAND        32
162 #define LOCK_READ        64
163 #endif
164 main() {
165         exit(flock(open("/dev/null", O_RDWR), LOCK_MAND|LOCK_READ) != 0);
166 }''', 'HAVE_KERNEL_SHARE_MODES', addmain=False, execute=True,
167         msg="Checking for kernel share modes")
168
169     # check for fam libs
170     samba_fam_libs=None
171     check_for_fam=False
172     if Options.options.with_fam is None:
173         check_for_fam=True
174     elif Options.options.with_fam == True:
175         check_for_fam=True
176
177     if check_for_fam and conf.CHECK_HEADERS('fam.h'):
178         if conf.CHECK_FUNCS_IN('FAMOpen2', 'fam'):
179             samba_fam_libs='fam'
180         elif conf.CHECK_FUNCS_IN('FAMOpen2', 'fam C'):
181             samba_fam_libs='fam C'
182         conf.CHECK_TYPE('enum FAMCodes', headers='fam.h',
183             define='HAVE_FAM_H_FAMCODES_TYPEDEF',
184             msg='Checking whether enum FAMCodes is available')
185         conf.CHECK_FUNCS_IN('FAMNoExists', 'fam')
186
187     if samba_fam_libs is not None:
188         conf.DEFINE('SAMBA_FAM_LIBS', samba_fam_libs)
189     else:
190         if Options.options.with_fam == True:
191             conf.fatal('FAM support requested, but no suitable FAM library found')
192         elif check_for_fam:
193             Logs.warn('no suitable FAM library found')
194
195     # check for libarchive (tar command in smbclient)
196     # None means autodetect, True/False means enable/disable
197     conf.env['archive_lib'] = ''
198     if Options.options.with_libarchive is not False:
199         libarchive_mandatory = Options.options.with_libarchive == True
200         Logs.info("Checking for libarchive existence")
201         if conf.CHECK_BUNDLED_SYSTEM('libarchive', minversion='3.1.2'):
202             conf.env['archive_lib'] = 'libarchive'
203         elif libarchive_mandatory:
204             conf.fatal('libarchive support requested, but no suitable pkgconfig found')
205
206     # check for DMAPI libs
207     if Options.options.with_dmapi == False:
208         have_dmapi = False
209     else:
210         have_dmapi = True
211         Logs.info("Checking for DMAPI library existence")
212         samba_dmapi_lib = ''
213         if conf.CHECK_FUNCS_IN('dm_get_eventlist', 'dm'):
214             samba_dmapi_lib = 'dm'
215         else:
216             if conf.CHECK_FUNCS_IN('dm_get_eventlist', 'jfsdm'):
217                 samba_dmapi_lib = 'jfsdm'
218             else:
219                 if conf.CHECK_FUNCS_IN('dm_get_eventlist', 'dmapi'):
220                     samba_dmapi_lib = 'dmapi'
221                 else:
222                     if conf.CHECK_FUNCS_IN('dm_get_eventlist', 'xdsm'):
223                         samba_dmapi_lib = 'xdsm'
224         # only bother to test headers and compilation when a candidate
225         # library has been found
226         if samba_dmapi_lib == '':
227             have_dmapi = False
228             broken_dmapi = "no suitable DMAPI library found"
229
230         if have_dmapi:
231             conf.CHECK_HEADERS('sys/dmi.h xfs/dmapi.h sys/jfsdmapi.h sys/dmapi.h dmapi.h')
232             conf.CHECK_CODE('''
233 #include <time.h>      /* needed by Tru64 */
234 #include <sys/types.h> /* needed by AIX */
235 #ifdef HAVE_XFS_DMAPI_H
236 #include <xfs/dmapi.h>
237 #elif defined(HAVE_SYS_DMI_H)
238 #include <sys/dmi.h>
239 #elif defined(HAVE_SYS_JFSDMAPI_H)
240 #include <sys/jfsdmapi.h>
241 #elif defined(HAVE_SYS_DMAPI_H)
242 #include <sys/dmapi.h>
243 #elif defined(HAVE_DMAPI_H)
244 #include <dmapi.h>
245 #endif
246
247 /* This link test is designed to fail on IRI 6.4, but should
248  * succeed on Linux, IRIX 6.5 and AIX.
249  */
250 int main(int argc, char **argv)
251 {
252         char * version;
253         dm_eventset_t events;
254         /* This doesn't take an argument on IRIX 6.4. */
255         dm_init_service(&version);
256         /* IRIX 6.4 expects events to be a pointer. */
257         DMEV_ISSET(DM_EVENT_READ, events);
258
259         return 0;
260 }
261 ''',
262             'USEABLE_DMAPI_LIBRARY',
263             addmain=False,
264             execute=False,
265             lib=samba_dmapi_lib,
266             msg='Checking whether DMAPI lib '+samba_dmapi_lib+' can be used')
267             if not conf.CONFIG_SET('USEABLE_DMAPI_LIBRARY'):
268                 have_dmapi = False
269                 broken_dmapi = "no usable DMAPI library found"
270
271     if have_dmapi:
272         Logs.info("Building with DMAPI support.")
273         conf.env['dmapi_lib'] = samba_dmapi_lib
274         conf.DEFINE('USE_DMAPI', 1)
275     else:
276         if Options.options.with_dmapi == False:
277             Logs.info("Building without DMAPI support (--without-dmapi).")
278         elif Options.options.with_dmapi == True:
279             Logs.error("DMAPI support not available: " + broken_dmapi)
280             conf.fatal('DMAPI support requested but not found.');
281         else:
282             Logs.warn("Building without DMAPI support: " + broken_dmapi)
283         conf.env['dmapi_lib'] = ''
284
285     # Check for various members of the stat structure
286     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_blocks', define='HAVE_STAT_ST_BLOCKS',
287                                 headers='sys/stat.h')
288     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_blksize', define='HAVE_STAT_ST_BLKSIZE',
289                                 headers='sys/stat.h')
290     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_flags', define='HAVE_STAT_ST_FLAGS',
291                                 headers='sys/types.h sys/stat.h unistd.h')
292
293     if "HAVE_BLKCNT_T" in conf.env:
294         conf.CHECK_CODE('''
295         static int test_array[1 - 2 * !(((long int)(sizeof(blkcnt_t))) <= 4)];''',
296                 'SIZEOF_BLKCNT_T_4',
297                 headers='replace.h sys/types.h sys/stat.h unistd.h',
298                 msg="Checking whether blkcnt_t is 32 bit")
299
300     # If sizeof is 4 it can't be 8
301     if "HAVE_BLKCNT_T" in conf.env:
302         if not conf.CONFIG_SET('SIZEOF_BLKCNT_T_4'):
303             conf.CHECK_CODE('''
304             static int test_array[1 - 2 * !(((long int)(sizeof(blkcnt_t))) <= 8)];''',
305                     'SIZEOF_BLKCNT_T_8',
306                     headers='replace.h sys/types.h sys/stat.h unistd.h',
307                     msg="Checking whether blkcnt_t is 64 bit")
308
309     # Check for POSIX capability support
310     conf.CHECK_FUNCS_IN('cap_get_proc', 'cap', headers='sys/capability.h')
311
312     if "HAVE_SYS_CAPABILITY_H" in conf.env:
313         conf.CHECK_CODE('''
314         cap_t cap;
315         cap_value_t vals[1];
316         if (!(cap = cap_get_proc())) exit(1);
317         vals[0] = CAP_CHOWN;
318         cap_set_flag(cap, CAP_INHERITABLE, 1, vals, CAP_CLEAR);
319         cap_set_proc(cap);''',
320                         'HAVE_POSIX_CAPABILITIES', execute=True, lib="cap",
321                         headers='sys/capability.h',
322                         msg="Checking whether POSIX capabilities are available")
323
324     conf.CHECK_CODE('int i;', 'BROKEN_NISPLUS_INCLUDE_FILES',
325                     headers='sys/types.h sys/acl.h rpcsvc/nis.h',
326                     msg="Checking for broken nisplus include files")
327
328     # Check if the compiler will optimize out functions
329     conf.CHECK_CODE('''
330 #include <sys/types.h>
331 size_t __unsafe_string_function_usage_here_size_t__(void);
332 #define CHECK_STRING_SIZE(d, len) (sizeof(d) != (len) && sizeof(d) != sizeof(char *))
333 static size_t push_string_check_fn(void *dest, const char *src, size_t dest_len) {
334         return 0;
335 }
336
337 #define push_string_check(dest, src, dest_len) \
338     (CHECK_STRING_SIZE(dest, dest_len) \
339     ? __unsafe_string_function_usage_here_size_t__()    \
340     : push_string_check_fn(dest, src, dest_len))
341
342 int main(int argc, char **argv) {
343     char outbuf[1024];
344     char *p = outbuf;
345     const char *foo = "bar";
346     p += 31 + push_string_check(p + 31, foo, sizeof(outbuf) - (p + 31 - outbuf));
347     return 0;
348 }''', 'HAVE_COMPILER_WILL_OPTIMIZE_OUT_FNS',
349             addmain=False,
350             add_headers=False,
351             msg="Checking if the compiler will optimize out functions")
352
353     # Check if the compiler supports the LL suffix on long long integers
354     # AIX needs this
355     conf.CHECK_CODE('long long i = 0x8000000000LL', 'COMPILER_SUPPORTS_LL',
356                     headers='stdio.h',
357                     msg="Checking for LL suffix on long long integers")
358
359     conf.CHECK_FUNCS('''
360 _acl __acl atexit 
361  _chdir __chdir chflags chmod _close __close _closedir
362 __closedir crypt16 devnm dirfd
363 DNSServiceRegister _dup __dup _dup2 __dup2 endmntent execl
364 _facl __facl _fchdir
365 __fchdir fchmod fchown _fcntl __fcntl fcvt fcvtl fdatasync
366 _fork __fork fseeko
367 fsetxattr _fstat __fstat fsync
368 futimens futimes __fxstat getauthuid
369 getcwd _getcwd __getcwd getdents __getdents getdirentries
370 getgrent getgrnam getgrouplist getgrset getmntent getpagesize
371 getpwanam getpwent_r getrlimit
372 glob grantpt hstrerror initgroups innetgr
373 llseek _llseek __llseek _lseek __lseek
374 _lstat __lstat lutimes
375 __lxstat memalign mknod mlock mlockall munlock munlockall
376 _open __open _opendir __opendir
377 pathconf poll posix_fallocate
378 posix_memalign pread _pread __pread
379 pwrite _pwrite __pwrite
380 rdchk _read __read _readdir __readdir
381 _seekdir __seekdir
382 select setenv setgidx setgroups setlocale setluid
383 setmntent setpgid setpriv setsid setuidx
384 shmget shm_open
385 _stat __stat statvfs
386 strcasecmp strchr strpbrk strsignal strtol strupr sysconf sysctl sysctlbyname
387 __sys_llseek syslog _telldir __telldir timegm
388 utimensat vsyslog _write __write __xstat
389 ''')
390
391     conf.CHECK_SAMBA3_CHARSET() # see build/charset.py
392
393     # FIXME: these should be tests for features, but the old build system just
394     # checks for OSes.
395     host_os = sys.platform
396     Logs.info("building on %s" % host_os)
397
398     # Python doesn't have case switches... :/
399     # FIXME: original was *linux* | gnu* | k*bsd*-gnu | kopensolaris*-gnu | *qnx*)
400     # the search for .rfind('gnu') covers gnu* and *-gnu is that too broad?
401
402     conf.SET_TARGET_TYPE('sunacl', 'EMPTY')
403     if (host_os.rfind('linux') > -1) or (host_os.rfind('gnu') > -1) or (host_os.rfind('qnx') > -1):
404         if host_os.rfind('linux') > -1:
405             conf.DEFINE('LINUX', '1')
406         elif host_os.rfind('qnx') > -1:
407             conf.DEFINE('QNX', '1')
408         conf.DEFINE('STAT_ST_BLOCKSIZE', '512')
409     elif (host_os.rfind('darwin') > -1):
410         conf.DEFINE('DARWINOS', 1)
411         conf.ADD_CFLAGS('-fno-common')
412         conf.DEFINE('STAT_ST_BLOCKSIZE', '512')
413     elif (host_os.rfind('freebsd') > -1):
414         conf.DEFINE('FREEBSD', 1)
415         if conf.CHECK_HEADERS('sunacl.h'):
416             conf.DEFINE('HAVE_FREEBSD_SUNACL_H', '1')
417             conf.CHECK_FUNCS_IN(['acl'], 'sunacl')
418         conf.DEFINE('STAT_ST_BLOCKSIZE', '512')
419     elif (host_os.rfind('irix') > -1):
420         conf.DEFINE('IRIX', 1)
421         conf.DEFINE('STAT_ST_BLOCKSIZE', '512')
422     elif (host_os.rfind('aix') > -1):
423         conf.DEFINE('AIX', 1)
424         conf.DEFINE('STAT_ST_BLOCKSIZE', 'DEV_BSIZE')
425     elif (host_os.rfind('hpux') > -1):
426         conf.DEFINE('HPUX', 1)
427         conf.DEFINE('STAT_ST_BLOCKSIZE', '8192')
428     elif (host_os.rfind('osf') > -1):
429         conf.DEFINE('OSF1', 1)
430         conf.DEFINE('STAT_ST_BLOCKSIZE', '512')
431
432     # FIXME: Add more checks here.
433     else:
434         conf.DEFINE('STAT_ST_BLOCKSIZE', '512')
435
436     if Options.options.with_acl_support:
437         if (host_os.rfind('hpux') > -1):
438                 Logs.info('Using HPUX ACLs')
439                 conf.DEFINE('HAVE_HPUX_ACLS',1)
440                 conf.DEFINE('POSIX_ACL_NEEDS_MASK',1)
441                 default_static_modules.extend(TO_LIST('vfs_hpuxacl'))
442         elif (host_os.rfind('aix') > -1):
443                 Logs.info('Using AIX ACLs')
444                 conf.DEFINE('HAVE_AIX_ACLS',1)
445                 default_static_modules.extend(TO_LIST('vfs_aixacl vfs_aixacl2'))
446         elif (host_os.rfind('darwin') > -1):
447             Logs.warn('ACLs on Darwin currently not supported')
448             conf.fatal("ACL support not available on Darwin/MacOS. "
449                        "Use --without-acl-support for building without "
450                        "ACL support. "
451                        "ACL support is required to change permissions "
452                        "from Windows clients.")
453         else:
454             conf.CHECK_FUNCS_IN(['acl_get_file'], 'acl')
455             if conf.CHECK_CODE('''
456 acl_t acl;
457 int entry_id;
458 acl_entry_t *entry_p;
459 return acl_get_entry(acl, entry_id, entry_p);
460 ''',
461                         'HAVE_POSIX_ACLS',
462                         headers='sys/types.h sys/acl.h', link=False,
463                         msg="Checking for POSIX ACL support") :
464                 conf.CHECK_CODE('''
465 acl_permset_t permset_d;
466 acl_perm_t perm;
467 return acl_get_perm_np(permset_d, perm);
468 ''',
469                         'HAVE_ACL_GET_PERM_NP',
470                         headers='sys/types.h sys/acl.h', link=True,
471                         msg="Checking whether acl_get_perm_np() is available")
472                 default_static_modules.extend(TO_LIST('vfs_posixacl'))
473                 conf.CHECK_VARIABLE('ACL_EVERYONE', headers='sys/acl.h')
474             elif conf.CHECK_FUNCS_IN(['facl'], 'sec'):
475                 Logs.info('Using solaris or UnixWare ACLs')
476                 conf.DEFINE('HAVE_SOLARIS_UNIXWARE_ACLS',1)
477                 default_static_modules.extend(TO_LIST('vfs_solarisacl'))
478             elif conf.CHECK_FUNCS_IN(['acl_get_fd'], 'pacl'):
479                 Logs.info('Using Tru64 ACLs')
480                 conf.DEFINE('HAVE_TRU64_ACLS',1)
481                 default_static_modules.extend(TO_LIST('vfs_tru64acl'))
482             else:
483                 conf.fatal("ACL support not found. Try installing libacl1-dev "
484                            "or libacl-devel.  "
485                            "Otherwise, use --without-acl-support to build "
486                            "without ACL support. "
487                            "ACL support is required to change permissions from "
488                            "Windows clients.")
489
490     if conf.CHECK_FUNCS('dirfd'):
491         conf.DEFINE('HAVE_DIRFD_DECL', 1)
492
493     conf.CHECK_CODE('struct statfs fsd; fsid_t fsid = fsd.f_fsid; return statfs(".", &fsd);',
494                     'HAVE_STATFS_F_FSID',
495                     msg="vfs_fileid checking for statfs() and struct statfs.f_fsid",
496                     headers='sys/types.h sys/statfs.h',
497                     execute=True)
498
499     if conf.CONFIG_SET('HAVE_FALLOCATE'):
500         conf.CHECK_CODE('''
501                 int ret = fallocate(0, FALLOC_FL_KEEP_SIZE, 0, 10);''',
502                 'HAVE_LINUX_FALLOCATE',
503                 msg="Checking whether the Linux 'fallocate' function is available",
504                 headers='unistd.h sys/types.h fcntl.h linux/falloc.h')
505         conf.CHECK_CODE('''
506                 int ret = fallocate(0, FALLOC_FL_PUNCH_HOLE, 0, 10);''',
507                 'HAVE_FALLOC_FL_PUNCH_HOLE',
508                 msg="Checking whether Linux 'fallocate' supports hole-punching",
509                 headers='unistd.h sys/types.h fcntl.h linux/falloc.h')
510
511     conf.CHECK_CODE('''
512             int ret = lseek(0, 0, SEEK_HOLE);
513             ret = lseek(0, 0, SEEK_DATA);''',
514             'HAVE_LSEEK_HOLE_DATA',
515             msg="Checking whether lseek supports hole/data seeking",
516             headers='unistd.h sys/types.h')
517
518     conf.CHECK_CODE('''
519                 ssize_t err = readahead(0,0,0x80000);''',
520                 'HAVE_LINUX_READAHEAD',
521                 msg="Checking whether Linux readahead is available",
522                 headers='unistd.h fcntl.h')
523     conf.CHECK_DECLS('readahead', headers='fcntl.h', always=True)
524
525     conf.CHECK_CODE('int fd = openat(AT_FDCWD, ".", O_RDONLY);',
526                 'HAVE_OPENAT',
527                 msg='Checking for openat',
528                 headers='fcntl.h')
529
530     if Options.options.with_aio_support:
531         conf.CHECK_FUNCS_IN('aio_read', 'aio')
532         conf.CHECK_FUNCS_IN('aio_read', 'rt')
533         conf.CHECK_CODE('struct aiocb a; return aio_read(&a);',
534                         'HAVE_AIO',
535                         msg='Checking for asynchronous io support',
536                         headers='sys/types.h aio.h',
537                         lib='aio rt')
538         if conf.CONFIG_SET('HAVE_AIO'):
539             conf.CHECK_CODE('struct aiocb a; return aio_read(&a);', 'HAVE_AIO_READ', msg='Checking for aio_read', headers='aio.h', lib='aio rt')
540             conf.CHECK_CODE('struct aiocb a; return aio_write(&a);', 'HAVE_AIO_WRITE', msg='Checking for aio_write', headers='aio.h', lib='aio rt')
541             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')
542             conf.CHECK_CODE('struct aiocb a; return aio_return(&a);', 'HAVE_AIO_RETURN', msg='Checking for aio_return', headers='aio.h', lib='aio rt')
543             conf.CHECK_CODE('struct aiocb a; return aio_error(&a);', 'HAVE_AIO_ERROR', msg='Checking for aio_error', headers='aio.h', lib='aio rt')
544             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')
545             conf.CHECK_CODE('const struct aiocb * const a[1]; struct timespec t; return aio_suspend(&a, 1, &t);', 'HAVE_AIO_SUSPEND', msg='Checking for aio_suspend', headers='aio.h', lib='aio rt')
546         if not conf.CONFIG_SET('HAVE_AIO'):
547             conf.DEFINE('HAVE_NO_AIO', '1')
548     else:
549         conf.DEFINE('HAVE_NO_AIO', '1')
550
551     if host_os.rfind('linux') > -1:
552         conf.CHECK_FUNCS_IN('io_submit', 'aio')
553         conf.CHECK_CODE('''
554 struct io_event ioev;
555 struct iocb *ioc;
556 io_context_t ctx;
557 struct timespec ts;
558 int fd;
559 char *buf;
560 fd = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC);
561 io_queue_init(128,&ctx);
562 io_prep_pwrite(ioc, 1, buf, 1, 0);
563 io_prep_pread(ioc, 1, buf, 1, 0);
564 io_set_eventfd(ioc, fd);
565 io_set_callback(ioc, (io_callback_t)(0));
566 io_submit(ctx, 1, &ioc);
567 io_getevents(ctx, 1, 1, &ioev, &ts);
568 ''',
569                         'HAVE_LINUX_KERNEL_AIO',
570                         msg='Checking for linux kernel asynchronous io support',
571                         headers='unistd.h stdlib.h sys/types.h fcntl.h sys/eventfd.h libaio.h',
572                         lib='aio')
573
574     conf.CHECK_CODE('''
575 struct msghdr msg;
576 union {
577         struct cmsghdr cm;
578         char control[CMSG_SPACE(sizeof(int))];
579 } control_un;
580 msg.msg_control = control_un.control;
581 msg.msg_controllen = sizeof(control_un.control);
582 ''',
583         'HAVE_STRUCT_MSGHDR_MSG_CONTROL',
584         msg='Checking if we can use msg_control for passing file descriptors',
585         headers='sys/types.h stdlib.h stddef.h sys/socket.h sys/un.h')
586     conf.CHECK_CODE('''
587 struct msghdr msg;
588 int fd;
589 msg.msg_accrights = (caddr_t) &fd;
590 msg.msg_accrightslen = sizeof(fd);
591 ''',
592         'HAVE_STRUCT_MSGHDR_MSG_ACCRIGHTS',
593         msg='Checking if we can use msg_accrights for passing file descriptors',
594         headers='sys/types.h stdlib.h stddef.h sys/socket.h sys/un.h')
595
596     if Options.options.with_winbind:
597         conf.env.build_winbind = True
598         conf.DEFINE('WITH_WINBIND', '1')
599
600     conf.find_program('awk', var='AWK')
601
602     conf.CHECK_HEADERS('asm/types.h')
603
604     conf.CHECK_CODE('dev_t dev; int i = major(dev); return 0', "HAVE_DEVICE_MAJOR_FN",
605                     headers='unistd.h sys/types.h',
606                     msg="Checking for major macro")
607
608     conf.CHECK_CODE('dev_t dev; int i = minor(dev); return 0', "HAVE_DEVICE_MINOR_FN",
609                     headers='unistd.h sys/types.h',
610                     msg="Checking for minor macro")
611
612     conf.CHECK_STRUCTURE_MEMBER('struct dirent', 'd_off',
613                                 headers='unistd.h sys/types.h dirent.h',
614                                 define='HAVE_DIRENT_D_OFF')
615
616     conf.CHECK_FUNCS('setnetgrent getnetgrent endnetgrent')
617     if conf.CHECK_CFLAGS('-Werror-implicit-function-declaration'):
618         netgrent_cflags = '-Werror-implicit-function-declaration'
619     else:
620         netgrent_cflags = ''
621     conf.CHECK_CODE('setnetgrent("foo")', 'HAVE_SETNETGRENT_PROTOTYPE',
622                     msg="Checking for setnetgrent prototype",
623                     headers='netdb.h netgroup.h',
624                     cflags=netgrent_cflags)
625     conf.CHECK_CODE('getnetgrent', 'HAVE_GETNETGRENT_PROTOTYPE',
626                     msg="Checking for getnetgrent prototype",
627                     headers='netdb.h netgroup.h',
628                     cflags=netgrent_cflags)
629     conf.CHECK_CODE('endnetgrent', 'HAVE_ENDNETGRENT_PROTOTYPE',
630                     msg="Checking for endnetgrent prototype",
631                     headers='netdb.h netgroup.h',
632                     cflags=netgrent_cflags)
633
634
635     # Look for CUPS
636     if Options.options.with_cups:
637         conf.find_program('cups-config', var='CUPS_CONFIG')
638         if conf.env.CUPS_CONFIG:
639             # we would normally use --libs here, but cups-config incorrectly adds
640             # gssapi_krb5 and other libraries to its --libs output. That breaks the use
641             # of an in-tree heimdal kerberos
642             conf.CHECK_CFG(path=conf.env.CUPS_CONFIG, args="--cflags --ldflags",
643                            package="", uselib_store="CUPS")
644         conf.CHECK_HEADERS('cups/cups.h cups/language.h', lib='cups')
645         conf.CHECK_FUNCS_IN('httpConnect httpConnectEncrypt', 'cups')
646         if conf.CONFIG_SET('HAVE_CUPS_CUPS_H') and conf.CONFIG_SET('HAVE_CUPS_LANGUAGE_H'):
647             conf.DEFINE('HAVE_CUPS', '1')
648         else:
649             conf.undefine('HAVE_CUPS')
650             conf.SET_TARGET_TYPE('cups', 'EMPTY')
651     else:
652         # define an empty subsystem for cups, to allow it to be used as an empty dependency
653         conf.SET_TARGET_TYPE('cups', 'EMPTY')
654
655     if Options.options.with_iprint:
656         if conf.CONFIG_SET('HAVE_CUPS'):
657             conf.DEFINE('HAVE_IPRINT', '1')
658         else:
659             Logs.warn("--enable-iprint=yes but cups support not sufficient")
660     if Options.options.with_syslog:
661         conf.DEFINE('WITH_SYSLOG', '1')
662     if Options.options.with_automount:
663         conf.DEFINE('WITH_AUTOMOUNT', '1')
664
665     # Check for LDAP
666     if Options.options.with_ldap:
667         conf.CHECK_HEADERS('ldap.h lber.h ldap_pvt.h')
668         conf.CHECK_TYPE('ber_tag_t', 'unsigned int', headers='ldap.h lber.h')
669         conf.CHECK_FUNCS_IN('ber_scanf ber_sockbuf_add_io', 'lber')
670         conf.CHECK_VARIABLE('LDAP_OPT_SOCKBUF', headers='ldap.h')
671
672         # if we LBER_OPT_LOG_PRINT_FN we can intercept ldap logging and print it out
673         # for the samba logs
674         conf.CHECK_VARIABLE('LBER_OPT_LOG_PRINT_FN',
675                             define='HAVE_LBER_LOG_PRINT_FN', headers='lber.h')
676
677         conf.CHECK_FUNCS_IN('ldap_init ldap_init_fd ldap_initialize ldap_set_rebind_proc', 'ldap')
678         conf.CHECK_FUNCS_IN('ldap_add_result_entry', 'ldap')
679
680         # Check if ldap_set_rebind_proc() takes three arguments
681         if conf.CHECK_CODE('ldap_set_rebind_proc(0, 0, 0)',
682                            'LDAP_SET_REBIND_PROC_ARGS',
683                            msg="Checking whether ldap_set_rebind_proc takes 3 arguments",
684                            headers='ldap.h lber.h', link=False):
685             conf.DEFINE('LDAP_SET_REBIND_PROC_ARGS', '3')
686         else:
687             conf.DEFINE('LDAP_SET_REBIND_PROC_ARGS', '2')
688
689         # last but not least, if ldap_init() exists, we want to use ldap
690         if conf.CONFIG_SET('HAVE_LDAP_INIT') and conf.CONFIG_SET('HAVE_LDAP_H'):
691             conf.DEFINE('HAVE_LDAP', '1')
692             conf.DEFINE('LDAP_DEPRECATED', '1')
693             conf.env['HAVE_LDAP'] = '1'
694             # if ber_sockbuf_add_io() and LDAP_OPT_SOCKBUF are available, we can add
695             # SASL wrapping hooks
696             if conf.CONFIG_SET('HAVE_BER_SOCKBUF_ADD_IO') and \
697                     conf.CONFIG_SET('HAVE_LDAP_OPT_SOCKBUF'):
698                 conf.DEFINE('HAVE_LDAP_SASL_WRAPPING', '1')
699         else:
700             conf.fatal("LDAP support not found. "
701                        "Try installing libldap2-dev or openldap-devel. "
702                        "Otherwise, use --without-ldap to build without "
703                        "LDAP support. "
704                        "LDAP support is required for the LDAP passdb backend, "
705                        "LDAP idmap backends and ADS. "
706                        "ADS support improves communication with "
707                        "Active Directory domain controllers.")
708     else:
709         conf.SET_TARGET_TYPE('ldap', 'EMPTY')
710         conf.SET_TARGET_TYPE('lber', 'EMPTY')
711
712     if Options.options.with_ads == False:
713         use_ads = False
714         use_ads_krb5 = False
715         use_ads_ldap = False
716     else:
717         use_ads = True
718         use_ads_krb5 = True
719         use_ads_ldap = True
720         if not conf.CONFIG_SET('HAVE_ENCTYPE_ARCFOUR_HMAC_MD5') and \
721            not conf.CONFIG_SET('HAVE_ENCTYPE_ARCFOUR_HMAC'):
722             Logs.warn("arcfour-hmac-md5 encryption type not found in -lkrb5")
723             use_ads_krb5 = False
724         if not conf.CONFIG_SET('HAVE_KRB5_MK_REQ_EXTENDED'):
725             Logs.warn("krb5_mk_req_extended not found in -lkrb5")
726             use_ads_krb5 = False
727         if not conf.CONFIG_SET('HAVE_KRB5_GET_HOST_REALM'):
728             Logs.warn("krb5_get_host_realm not found in -lkrb5")
729             use_ads_krb5 = False
730         if not conf.CONFIG_SET('HAVE_KRB5_FREE_HOST_REALM'):
731             Logs.warn("krb5_free_host_realm not found in -lkrb5")
732             use_ads_krb5 = False
733         if not conf.CONFIG_SET('HAVE_KRB5_FWD_TGT_CREDS'):
734             Logs.warn("krb5_fwd_tgt_creds found in -lkrb5")
735             use_ads_krb5 = False
736         if not conf.CONFIG_SET('HAVE_KRB5_GET_INIT_CREDS_OPT_ALLOC'):
737             Logs.warn("krb5_get_init_creds_opt_alloc not found in -lkrb5")
738             use_ads_krb5 = False
739         if not conf.CONFIG_SET('KRB5_CREDS_OPT_FREE_REQUIRES_CONTEXT'):
740             Logs.warn("krb5_get_init_creds_opt_free was not found or was too old in -lkrb5")
741             use_ads_krb5 = False
742         if not conf.CONFIG_SET('HAVE_KRB5_GET_RENEWED_CREDS'):
743             Logs.warn("krb5_get_renewed_creds not found in -lkrb5")
744             use_ads_krb5 = False
745         if not conf.CONFIG_SET('HAVE_KRB5_PRINCIPAL_COMPARE_ANY_REALM'):
746             Logs.warn("krb5_principal_compare_any_realm not found in -lkrb5")
747             use_ads_krb5 = False
748         if not conf.CONFIG_SET('HAVE_KRB5_C_STRING_TO_KEY') and \
749            not conf.CONFIG_SET('HAVE_KRB5_STRING_TO_KEY_SALT'):
750             Logs.warn("krb5_c_string_to_key not found in -lkrb5")
751             use_ads_krb5 = False
752         if not conf.CONFIG_SET('HAVE_KRB5_PRINCIPAL2SALT') and \
753            not conf.CONFIG_SET('HAVE_KRB5_GET_PW_SALT'):
754             Logs.warn("no CREATE_KEY_FUNCTIONS detected")
755             use_ads_krb5 = False
756         if not conf.CONFIG_SET('HAVE_KRB5_GET_PERMITTED_ENCTYPES') and \
757            not conf.CONFIG_SET('HAVE_KRB5_GET_DEFAULT_IN_TKT_ETYPES'):
758             Logs.warn("no GET_ENCTYPES_FUNCTIONS detected")
759             use_ads_krb5 = False
760         if not conf.CONFIG_SET('HAVE_KRB5_KT_FREE_ENTRY') and \
761            not conf.CONFIG_SET('HAVE_KRB5_FREE_KEYTAB_ENTRY_CONTENTS'):
762             Logs.warn("no KT_FREE_FUNCTION detected")
763             use_ads_krb5 = False
764         if not conf.CONFIG_SET('HAVE_KRB5_C_VERIFY_CHECKSUM'):
765             Logs.warn("krb5_c_verify_checksum_compare not found in -lkrb5")
766             use_ads_krb5 = False
767
768         # We don't actually use
769         # gsskrb5_extract_authz_data_from_sec_context, but it is a
770         # clue that this Heimdal, which does the PAC processing we
771         # need on the standard gss_inquire_sec_context_by_oid
772         if not conf.CONFIG_SET('HAVE_GSS_GET_NAME_ATTRIBUTE') and \
773             not (conf.CONFIG_SET('HAVE_GSSKRB5_EXTRACT_AUTHZ_DATA_FROM_SEC_CONTEXT') and \
774                      conf.CONFIG_SET('HAVE_GSS_INQUIRE_SEC_CONTEXT_BY_OID')):
775             Logs.warn("need either gss_get_name_attribute or gsskrb5_extract_authz_data_from_sec_context and gss_inquire_sec_context_by_oid in -lgssapi for PAC support")
776             use_ads_krb5 = False
777
778         if not conf.CONFIG_SET('HAVE_GSS_KRB5_EXPORT_LUCID_SEC_CONTEXT'):
779             Logs.warn("need gss_krb5_export_lucid_sec_context for SPNEGO and gss_wrap support")
780             use_ads_krb5 = False
781
782         if use_ads_krb5:
783             conf.DEFINE('HAVE_KRB5', '1')
784             conf.env['HAVE_KRB5'] = '1'
785         else:
786             conf.undefine('HAVE_KRB5_H')
787             conf.undefine('HAVE_GSSAPI_H')
788             conf.undefine('HAVE_GSSAPI_GSSAPI_GENERIC_H')
789             conf.undefine('HAVE_GSSAPI_GSSAPI_H')
790             use_ads = False
791
792         if not conf.CONFIG_SET('HAVE_LDAP'):
793             use_ads = False
794             use_ads_ldap = False
795
796     if use_ads:
797         conf.DEFINE('WITH_ADS', '1')
798         conf.env['HAVE_ADS'] = '1'
799         Logs.info("Building with Active Directory support.")
800         default_shared_modules.extend(TO_LIST('idmap_ad idmap_rfc2307'))
801     elif Options.options.with_ads == False:
802         Logs.info("Building without Active Directory support (--without-ads).")
803     else:
804         if not use_ads_krb5:
805             Logs.warn("Active Directory support not available: krb5 libs don't have all required features")
806         if not use_ads_ldap:
807             Logs.warn("Active Directory support not available: LDAP support is not available.")
808         if Options.options.with_ads:
809             conf.fatal("Active Directory support not found. Use --without-ads "
810                        "for building without Active Directory support. "
811                        "ADS support improves communication with "
812                        "Active Directory domain controllers.")
813         else:
814             # this is the auto-mode case
815             Logs.warn("Building without Active Directory support.")
816
817
818     if Options.options.with_utmp:
819         conf.env.with_utmp = True
820         if not conf.CHECK_HEADERS('utmp.h'): conf.env.with_utmp = False
821         conf.CHECK_FUNCS('pututline pututxline updwtmp updwtmpx getutmpx getutxent')
822         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_name', headers='utmp.h',
823                                     define='HAVE_UT_UT_NAME')
824         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_user', headers='utmp.h',
825                                     define='HAVE_UT_UT_USER')
826         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_id', headers='utmp.h',
827                                     define='HAVE_UT_UT_ID')
828         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_host', headers='utmp.h',
829                                     define='HAVE_UT_UT_HOST')
830         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_time', headers='utmp.h',
831                                     define='HAVE_UT_UT_TIME')
832         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_tv', headers='utmp.h',
833                                     define='HAVE_UT_UT_TV')
834         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_type', headers='utmp.h',
835                                     define='HAVE_UT_UT_TYPE')
836         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_pid', headers='utmp.h',
837                                     define='HAVE_UT_UT_PID')
838         conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_exit.e_exit', headers='utmp.h',
839                                     define='HAVE_UT_UT_EXIT')
840         conf.CHECK_STRUCTURE_MEMBER('struct utmpx', 'ut_syslen', headers='utmpx.h',
841                                     define='HAVE_UX_UT_SYSLEN')
842         conf.CHECK_CODE('struct utmp utarg; struct utmp *utreturn; utreturn = pututline(&utarg);',
843                         'PUTUTLINE_RETURNS_UTMP', headers='utmp.h',
844                         msg="Checking whether pututline returns pointer")
845         conf.CHECK_SIZEOF(['((struct utmp *)NULL)->ut_line'], headers='utmp.h',
846                           define='SIZEOF_UTMP_UT_LINE', critical=False)
847         if not conf.CONFIG_SET('SIZEOF_UTMP_UT_LINE'):
848             conf.env.with_utmp = False
849         elif int(conf.env.SIZEOF_UTMP_UT_LINE) < 15:
850             conf.env.with_utmp = False
851         if conf.env.with_utmp:
852             conf.DEFINE('WITH_UTMP', 1)
853         else:
854             Logs.warn("--with-utmp but utmp support not sufficient")
855
856     if Options.options.with_avahi:
857         conf.env.with_avahi = True
858         if not conf.CHECK_HEADERS('avahi-common/watch.h avahi-client/client.h'): conf.env.with_avahi = False
859         if not conf.CHECK_FUNCS_IN('avahi_client_new', 'avahi-client'): conf.env.with_avahi = False
860         if not conf.CHECK_FUNCS_IN('avahi_strerror', 'avahi-common'): conf.env.with_avahi = False
861         if conf.env.with_avahi:
862             conf.DEFINE('WITH_AVAHI_SUPPORT', 1)
863     else:
864         conf.SET_TARGET_TYPE('avahi-common', 'EMPTY')
865         conf.SET_TARGET_TYPE('avahi-client', 'EMPTY')
866
867     if Options.options.with_iconv:
868         conf.env.with_iconv = True
869         if not conf.CHECK_FUNCS_IN('iconv_open', 'iconv', headers='iconv.h'):
870             conf.env.with_iconv = False
871         if conf.env.with_iconv:
872             conf.DEFINE('HAVE_ICONV', 1)
873
874     if Options.options.with_pam:
875         use_pam=True
876         conf.CHECK_HEADERS('security/pam_appl.h pam/pam_appl.h')
877         if not conf.CONFIG_SET('HAVE_SECURITY_PAM_APPL_H') and not conf.CONFIG_SET('HAVE_PAM_PAM_APPL_H'):
878             Logs.warn("--with-pam=yes but pam_appl.h not found")
879             use_pam=False
880         conf.CHECK_FUNCS_IN('pam_get_data', 'pam')
881         conf.CHECK_HEADERS('security/pam_modules.h pam/pam_modules.h')
882         if not conf.CONFIG_SET('HAVE_SECURITY_PAM_MODULES_H') and not conf.CONFIG_SET('HAVE_PAM_PAM_MODULES_H'):
883             Logs.warn("--with-pam=yes but pam_modules.h not found")
884             use_pam=False
885         conf.CHECK_HEADERS('security/pam_ext.h security/_pam_macros.h')
886         conf.CHECK_HEADERS('pam/pam_ext.h pam/_pam_macros.h')
887         conf.CHECK_FUNCS_IN('pam_vsyslog', 'pam')
888         conf.CHECK_CODE('''
889 #if defined(HAVE_SECURITY_PAM_APPL_H)
890 #include <security/pam_appl.h>
891 #elif defined(HAVE_PAM_PAM_APPL_H)
892 #include <pam/pam_appl.h>
893 #endif
894 pam_set_item(0, PAM_RHOST, 0);
895 ''',
896             'HAVE_PAM_RHOST',
897             lib='pam',
898             msg="Checking whether PAM_RHOST is available");
899         conf.CHECK_CODE('''
900 #if defined(HAVE_SECURITY_PAM_APPL_H)
901 #include <security/pam_appl.h>
902 #elif defined(HAVE_PAM_PAM_APPL_H)
903 #include <pam/pam_appl.h>
904 #endif
905 pam_set_item(0, PAM_TTY, 0);
906 ''',
907             'HAVE_PAM_TTY',
908             lib='pam',
909             msg="Checking whether PAM_TTY is available");
910         conf.CHECK_CODE('''
911 #if (!defined(LINUX))
912
913 #define PAM_EXTERN extern
914 #if defined(HAVE_SECURITY_PAM_APPL_H)
915 #include <security/pam_appl.h>
916 #elif defined(HAVE_PAM_PAM_APPL_H)
917 #include <pam/pam_appl.h>
918 #endif
919
920 #endif
921
922 #if defined(HAVE_SECURITY_PAM_MODULES_H)
923 #include <security/pam_modules.h>
924 #elif defined(HAVE_PAM_PAM_MODULES_H)
925 #include <pam/pam_modules.h>
926 #endif
927
928 #if defined(HAVE_SECURITY__PAM_MACROS_H)
929 #include <security/_pam_macros.h>
930 #elif defined(HAVE_PAM__PAM_MACROS_H)
931 #include <pam/_pam_macros.h>
932 #endif
933
934 #ifdef HAVE_SECURITY_PAM_EXT_H
935 #include <security/pam_ext.h>
936 #endif
937
938 int i; i = PAM_RADIO_TYPE;
939 ''',
940             'HAVE_PAM_RADIO_TYPE',
941             lib='pam',
942             msg="Checking whether PAM_RADIO_TYPE is available");
943         if use_pam:
944             conf.DEFINE('WITH_PAM', 1)
945             conf.DEFINE('WITH_PAM_MODULES', 1)
946
947     if Options.options.with_pam_smbpass:
948         conf.env.with_pam_smbpass = True
949
950     seteuid = False
951
952 #
953 # Ensure we select the correct set of system calls on Linux.
954 #
955     if (host_os.rfind('linux') > -1):
956         conf.CHECK_CODE('''
957 #if defined(HAVE_UNISTD_H)
958 #include <unistd.h>
959 #endif
960 #include <stdlib.h>
961 #include <stdio.h>
962 #include <sys/types.h>
963 #include <errno.h>
964
965 #ifdef HAVE_SYS_PRIV_H
966 #include <sys/priv.h>
967 #endif
968 #ifdef HAVE_SYS_ID_H
969 #include <sys/id.h>
970 #endif
971
972 #if defined(HAVE_SYSCALL_H)
973 #include <syscall.h>
974 #endif
975
976 #if defined(HAVE_SYS_SYSCALL_H)
977 #include <sys/syscall.h>
978 #endif
979
980 syscall(SYS_setresuid32, -1, -1, -1);
981 syscall(SYS_setresgid32, -1, -1, -1);
982 syscall(SYS_setreuid32, -1, -1);
983 syscall(SYS_setregid32, -1, -1);
984 syscall(SYS_setuid32, -1);
985 syscall(SYS_setgid32, -1);
986 syscall(SYS_setgroups32, 0, NULL);
987 ''',
988             'USE_LINUX_32BIT_SYSCALLS',
989             msg="Checking whether Linux should use 32-bit credential calls");
990
991         if (conf.CONFIG_SET('USE_LINUX_32BIT_SYSCALLS')):
992             seteuid = conf.CHECK_CODE('''
993                                 #define AUTOCONF_TEST 1
994                                 #define USE_LINUX_THREAD_CREDENTIALS 1
995                                 #define USE_LINUX_32BIT_SYSCALLS 1
996                                 #include "../lib/util/setid.c"
997                                 #include "./lib/util_sec.c"
998                                 ''',
999                                 'USE_LINUX_THREAD_CREDENTIALS',
1000                                 addmain=False,
1001                                 execute=True,
1002                                 msg="Checking whether we can use Linux thread-specific credentials with 32-bit system calls")
1003         else:
1004             seteuid = conf.CHECK_CODE('''
1005                                 #define AUTOCONF_TEST 1
1006                                 #define USE_LINUX_THREAD_CREDENTIALS 1
1007                                 #include "../lib/util/setid.c"
1008                                 #include "./lib/util_sec.c"
1009                                 ''',
1010                                 'USE_LINUX_THREAD_CREDENTIALS',
1011                                 addmain=False,
1012                                 execute=True,
1013                                 msg="Checking whether we can use Linux thread-specific credentials")
1014     if not seteuid:
1015         seteuid = conf.CHECK_CODE('''
1016                                 #define AUTOCONF_TEST 1
1017                                 #define USE_SETREUID 1
1018                                 #include "../lib/util/setid.c"
1019                                 #include "./lib/util_sec.c"
1020                                 ''',
1021                                 'USE_SETREUID',
1022                                 addmain=False,
1023                                 execute=True,
1024                                 msg="Checking whether setreuid is available")
1025     if not seteuid:
1026         seteuid = conf.CHECK_CODE('''
1027                                 #define AUTOCONF_TEST 1
1028                                 #define USE_SETRESUID 1
1029                                 #include "../lib/util/setid.c"
1030                                 #include "./lib/util_sec.c"
1031                                 ''',
1032                                 'USE_SETRESUID',
1033                                 addmain=False,
1034                                 execute=True,
1035                                 msg="Checking whether setresuid is available")
1036     if not seteuid:
1037         seteuid = conf.CHECK_CODE('''
1038                                 #define AUTOCONF_TEST 1
1039                                 #define USE_SETEUID 1
1040                                 #include "../lib/util/setid.c"
1041                                 #include "./lib/util_sec.c"
1042                                 ''',
1043                                 'USE_SETEUID',
1044                                 addmain=False,
1045                                 execute=True,
1046                                 msg="Checking whether seteuid is available")
1047     if not seteuid:
1048         seteuid = conf.CHECK_CODE('''
1049                                 #define AUTOCONF_TEST 1
1050                                 #define USE_SETUIDX 1
1051                                 #include "../lib/util/setid.c"
1052                                 #include "./lib/util_sec.c"
1053                                 ''',
1054                                 'USE_SETUIDX',
1055                                 addmain=False,
1056                                 execute=True,
1057                                 mandatory=True,
1058                                 msg="Checking whether setuidx is available")
1059     if Options.options.with_dnsupdate:
1060         if not conf.CONFIG_SET('HAVE_KRB5'):
1061             Logs.warn("--with-dnsupdate=yes but gssapi support not sufficient")
1062         else:
1063             conf.DEFINE('WITH_DNS_UPDATES', 1)
1064     conf.CHECK_HEADERS('valgrind.h valgrind/valgrind.h valgrind/memcheck.h')
1065     if Options.options.developer:
1066         if conf.CONFIG_SET('HAVE_VALGRIND_H') or conf.CONFIG_SET('HAVE_VALGRIND_VALGRIND_H'):
1067             conf.DEFINE('VALGRIND', '1')
1068
1069     if conf.CHECK_CODE('''
1070 #include <bits/sockaddr.h>
1071 #include <linux/netlink.h>
1072 ''',
1073                 'HAVE_LINUX_NETLINK_H',
1074                 msg="Checking whether Linux netlink is available"):
1075
1076         conf.CHECK_CODE('''
1077 #include <bits/sockaddr.h>
1078 #include <linux/netlink.h>
1079 #include <linux/rtnetlink.h>
1080 ''',
1081                 'HAVE_LINUX_RTNETLINK_H',
1082                 msg='Checking whether Linux rtnetlink is available')
1083
1084     conf.CHECK_CODE('''
1085 #include "../tests/fcntl_lock.c"
1086 ''',
1087                 'HAVE_FCNTL_LOCK',
1088                 addmain=False,
1089                 execute=True,
1090                 msg='Checking whether fcntl locking is available')
1091
1092 # glibc up to 2.3.6 had dangerously broken posix_fallocate(). DON'T USE IT.
1093     if not conf.CHECK_CODE('''
1094 #define _XOPEN_SOURCE 600
1095 #include <stdlib.h>
1096 #if defined(__GLIBC__) && ((__GLIBC__ < 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 4))
1097 #error probably broken posix_fallocate
1098 #endif
1099 ''',
1100                            '_HAVE_UNBROKEN_POSIX_FALLOCATE',
1101                            msg='Checking for broken posix_fallocate'):
1102         conf.DEFINE('HAVE_BROKEN_POSIX_FALLOCATE', '1')
1103
1104
1105     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_mtim.tv_nsec',
1106                                 define='HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC') # Linux, Solaris
1107     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_mtimensec',
1108                                 define='HAVE_STRUCT_STAT_ST_MTIMENSEC') # BSD, if defined _POSIX_SOURCE
1109     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_mtimespec.tv_nsec',
1110                                 define='HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC') # BSD, if not defined _POSIX_SOURCE
1111     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_mtime_n',
1112                                 define='HAVE_STRUCT_STAT_ST_MTIME_N') # AIX
1113     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_umtime',
1114                                 define='HAVE_STRUCT_STAT_ST_UMTIME') # Tru64
1115     if conf.CONFIG_SET('HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC') or \
1116        conf.CONFIG_SET('HAVE_STRUCT_STAT_ST_MTIMENSEC') or \
1117        conf.CONFIG_SET('HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC') or \
1118        conf.CONFIG_SET('HAVE_STRUCT_STAT_ST_MTIME_N') or \
1119        conf.CONFIG_SET('HAVE_STRUCT_STAT_ST_UMTIME'):
1120         conf.DEFINE('HAVE_STAT_HIRES_TIMESTAMPS', '1')
1121
1122     # recent FreeBSD, NetBSD have creation timestamps called birthtime:
1123     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_birthtime',
1124                                 define='HAVE_STRUCT_STAT_ST_BIRTHTIME')
1125     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_birthtimespec.tv_nsec',
1126                                 define='HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC')
1127     conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_birthtimensec',
1128                                 define='HAVE_STRUCT_STAT_ST_BIRTHTIMENSEC')
1129
1130     conf.CHECK_CODE('''
1131 ssize_t err = posix_fadvise(0,0,0x80000,POSIX_FADV_WILLNEED);
1132 ''',
1133                 'HAVE_POSIX_FADVISE',
1134                 msg='Checking whether posix_fadvise is available',
1135                 headers='unistd.h fcntl.h')
1136
1137     for v in ['_SC_NGROUPS_MAX', '_SC_NPROC_ONLN', '_SC_NPROCESSORS_ONLN', '_SC_PAGESIZE' ]:
1138         conf.CHECK_CODE('''
1139                         #include <unistd.h>
1140                         return sysconf(%s) == -1 ? 1 : 0;
1141                         ''' % v,
1142                         'SYSCONF%s' % v,
1143                         msg='Checking whether sysconf(%s) is available' % v)
1144
1145     conf.CHECK_CODE('''
1146 #include <sys/syscall.h>
1147 #include <unistd.h>
1148 syscall(SYS_initgroups, 16, NULL, NULL, 0);
1149                     ''',
1150                     'HAVE_DARWIN_INITGROUPS',
1151                     msg='Checking whether to use the Darwin-specific initgroups system call')
1152
1153     conf.CHECK_CODE('''struct utimbuf tbuf;  tbuf.actime = 0; tbuf.modtime = 1; exit(utime("foo.c",&tbuf));''',
1154                     'HAVE_UTIMBUF',
1155                     headers='sys/types.h utime.h',
1156                     msg='Checking whether struct utimbuf is available')
1157
1158     if conf.CHECK_CODE('''struct sigevent s;''',
1159                     'HAVE_STRUCT_SIGEVENT',
1160                     headers='sys/types.h stdlib.h stddef.h signal.h',
1161                     msg='Checking whether we have the struct sigevent'):
1162         conf.CHECK_STRUCTURE_MEMBER('struct sigevent', 'sigev_value.sival_ptr',
1163                                     define='HAVE_STRUCT_SIGEVENT_SIGEV_VALUE_SIVAL_PTR',
1164                                     headers='signal.h');
1165         conf.CHECK_STRUCTURE_MEMBER('struct sigevent', 'sigev_value.sigval_ptr',
1166                                     define='HAVE_STRUCT_SIGEVENT_SIGEV_VALUE_SIGVAL_PTR',
1167                                     headers='signal.h');
1168
1169     if os.path.exists('/proc/sys/kernel/core_pattern'):
1170         conf.DEFINE('HAVE_SYS_KERNEL_PROC_CORE_PATTERN', '1')
1171
1172     if conf.CHECK_CODE('''
1173 #include <time.h>
1174 main() {
1175         struct tm *tm;
1176         if (sizeof(time_t) == 8) {
1177                 time_t max_time = 0x7fffffffffffffffll;
1178                 tm = gmtime(&max_time);
1179                 /* This should fail with 32-bit tm_year. */
1180                 if (tm == NULL) {
1181                         /* Max time_t that works with 32-bit int tm_year in struct tm. */
1182                         max_time = 67768036191676799ll;
1183                         tm = gmtime(&max_time);
1184                         if (tm) {
1185                                 exit(0);
1186                         }
1187                 }
1188         }
1189         exit(1);
1190 }''',
1191         '__TIME_T_MAX',
1192         addmain=False,
1193         execute=True,
1194         msg="Checking for the maximum value of the 'time_t' type"):
1195             conf.DEFINE('TIME_T_MAX', '67768036191676799ll')
1196
1197     conf.CHECK_CODE('''
1198 #if defined(HAVE_UNISTD_H)
1199 #include <unistd.h>
1200 #endif
1201 #include <sys/types.h>
1202 main() { dev_t dev = makedev(1,2); return 0; }
1203 ''',
1204         'HAVE_MAKEDEV',
1205         addmain=False,
1206         msg='Checking whether the macro for makedev is available')
1207
1208     conf.CHECK_CODE('''
1209 #include <stdio.h>
1210 #include <limits.h>
1211 #include <signal.h>
1212
1213 void exit_on_core(int ignored) {
1214         exit(1);
1215 }
1216
1217 main() {
1218         char *newpath;
1219         signal(SIGSEGV, exit_on_core);
1220         newpath = realpath("/tmp", NULL);
1221         exit((newpath != NULL) ? 0 : 1);
1222 }
1223 ''',
1224         'REALPATH_TAKES_NULL',
1225         addmain=False,
1226         execute=True,
1227         msg='Checking whether the realpath function allows a NULL argument')
1228
1229     conf.CHECK_CODE('''#include "../tests/ftruncate.c"''',
1230                     'HAVE_FTRUNCATE_EXTEND',
1231                     msg='Checking for ftruncate extend',
1232                     addmain=False,
1233                     execute=True)
1234
1235     if Options.options.with_sendfile_support:
1236         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):
1237             conf.CHECK_CODE('''
1238                             int tofd, fromfd;
1239                             off_t offset;
1240                             size_t total;
1241                             ssize_t nwritten = sendfile(tofd, fromfd, &offset, total);
1242                             ''',
1243                             '_HAVE_SENDFILE',
1244                             headers='sys/sendfile.h',
1245                             msg='Checking for linux sendfile support')
1246
1247             if conf.CONFIG_SET('_HAVE_SENDFILE'):
1248                 conf.DEFINE('HAVE_SENDFILE', '1')
1249                 conf.DEFINE('LINUX_SENDFILE_API', '1')
1250                 conf.DEFINE('WITH_SENDFILE', '1')
1251         elif (host_os.rfind('freebsd') > -1) or (host_os.rfind('dragonfly') > -1):
1252             conf.CHECK_CODE('''
1253                             #include <sys/types.h>
1254                             #include <unistd.h>
1255                             #include <sys/socket.h>
1256                             #include <sys/uio.h>
1257                             int fromfd, tofd, ret, total=0;
1258                             off_t offset, nwritten;
1259                             struct sf_hdtr hdr;
1260                             struct iovec hdtrl;
1261                             hdr.headers = &hdtrl;
1262                             hdr.hdr_cnt = 1;
1263                             hdr.trailers = NULL;
1264                             hdr.trl_cnt = 0;
1265                             hdtrl.iov_base = NULL;
1266                             hdtrl.iov_len = 0;
1267                             ret = sendfile(fromfd, tofd, offset, total, &hdr, &nwritten, 0)
1268                             ''',
1269                             '_HAVE_SENDFILE',
1270                             msg='Checking for freebsd sendfile support')
1271             if conf.CONFIG_SET('_HAVE_SENDFILE'):
1272                 conf.DEFINE('HAVE_SENDFILE', '1')
1273                 conf.DEFINE('FREEBSD_SENDFILE_API', '1')
1274                 conf.DEFINE('WITH_SENDFILE', '1')
1275         elif (host_os.rfind('darwin') > -1):
1276             conf.CHECK_CODE('''
1277                             #include <sys/types.h>
1278                             #include <sys/socket.h>
1279                             #include <sys/uio.h>
1280                             int fromfd, tofd, ret;
1281                             off_t offset, nwritten;
1282                             struct sf_hdtr hdr;
1283                             struct iovec hdtrl;
1284                             hdr.headers = &hdtrl;
1285                             hdr.hdr_cnt = 1;
1286                             hdr.trailers = (void *)0;
1287                             hdr.trl_cnt = 0;
1288                             hdtrl.iov_base = (void *)0;
1289                             hdtrl.iov_len = 0;
1290                             ret = sendfile(fromfd, tofd, offset, &nwritten, &hdr, 0);
1291                             ''',
1292                             '_HAVE_SENDFILE',
1293                             msg='Checking for darwin sendfile support')
1294             if conf.CONFIG_SET('_HAVE_SENDFILE'):
1295                 conf.DEFINE('HAVE_SENDFILE', '1')
1296                 conf.DEFINE('DARWIN_SENDFILE_API', '1')
1297                 conf.DEFINE('WITH_SENDFILE', '1')
1298         elif (host_os.rfind('hpux') > -1) or (host_os.rfind('osf') > -1):
1299             conf.CHECK_CODE('''
1300                             #include <sys/socket.h>
1301                             #include <sys/uio.h>
1302                             int fromfd, tofd;
1303                             size_t total=0;
1304                             struct iovec hdtrl[2];
1305                             ssize_t nwritten;
1306                             off_t offset;
1307                             hdtrl[0].iov_base = 0;
1308                             hdtrl[0].iov_len = 0;
1309                             nwritten = sendfile(tofd, fromfd, offset, total, &hdtrl[0], 0);
1310                             ''',
1311                             '_HAVE_SENDFILE',
1312                             msg='Checking for osf/hpux sendfile support')
1313             if conf.CONFIG_SET('_HAVE_SENDFILE'):
1314                 conf.DEFINE('HAVE_SENDFILE', '1')
1315                 conf.DEFINE('HPUX_SENDFILE_API', '1')
1316                 conf.DEFINE('WITH_SENDFILE', '1')
1317         elif (host_os.rfind('solaris') > -1):
1318             conf.CHECK_FUNCS_IN('sendfile', 'sendfilev')
1319             conf.CHECK_CODE('''
1320                             #include <sys/sendfile.h>,
1321                             int sfvcnt;
1322                             size_t xferred;
1323                             struct sendfilevec vec[2];
1324                             ssize_t nwritten;
1325                             int tofd;
1326                             sfvcnt = 2;
1327                             vec[0].sfv_fd = SFV_FD_SELF;
1328                             vec[0].sfv_flag = 0;
1329                             vec[0].sfv_off = 0;
1330                             vec[0].sfv_len = 0;
1331                             vec[1].sfv_fd = 0;
1332                             vec[1].sfv_flag = 0;
1333                             vec[1].sfv_off = 0;
1334                             vec[1].sfv_len = 0;
1335                             nwritten = sendfilev(tofd, vec, sfvcnt, &xferred);
1336                             ''',
1337                             '_HAVE_SENDFILEV',
1338                             msg='Checking for solaris sendfilev support')
1339             if conf.CONFIG_SET('_HAVE_SENDFILEV'):
1340                 conf.DEFINE('HAVE_SENDFILEV', '1')
1341                 conf.DEFINE('SOLARIS_SENDFILE_API', '1')
1342                 conf.DEFINE('WITH_SENDFILE', '1')
1343         elif (host_os.rfind('aix') > -1):
1344             conf.CHECK_CODE('''
1345                             #include <sys/socket.h>
1346                             int fromfd, tofd;
1347                             size_t total=0;
1348                             struct sf_parms hdtrl;
1349                             ssize_t nwritten;
1350                             hdtrl.header_data = 0;
1351                             hdtrl.header_length = 0;
1352                             hdtrl.file_descriptor = fromfd;
1353                             hdtrl.file_offset = 0;
1354                             hdtrl.file_bytes = 0;
1355                             hdtrl.trailer_data = 0;
1356                             hdtrl.trailer_length = 0;
1357                             nwritten = send_file(&tofd, &hdtrl, 0);
1358                             ''',
1359                             '_HAVE_SENDFILE',
1360                             msg='Checking for AIX send_file support')
1361             if conf.CONFIG_SET('_HAVE_SENDFILE'):
1362                 conf.DEFINE('HAVE_SENDFILE', '1')
1363                 conf.DEFINE('AIX_SENDFILE_API', '1')
1364                 conf.DEFINE('WITH_SENDFILE', '1')
1365
1366     # Check for getcwd allowing a NULL arg.
1367     conf.CHECK_CODE('''
1368 #include <unistd.h>
1369 main() {
1370         char *s = getcwd(NULL,0);
1371         exit(s != NULL ?  0 : 1);
1372 }''', 'GETCWD_TAKES_NULL', addmain=False, execute=True,
1373         msg="getcwd takes a NULL argument")
1374
1375
1376     # UnixWare 7.x has its getspnam in -lgen
1377     conf.CHECK_FUNCS_IN('getspnam', 'gen')
1378     conf.CHECK_FUNCS_IN('getspnam', 'security')
1379     conf.CHECK_FUNCS_IN('getspnam', 'sec')
1380
1381     if Options.options.with_quotas:
1382         # For quotas on Veritas VxFS filesystems
1383         conf.CHECK_HEADERS('sys/fs/vx_quota.h')
1384         # For sys/quota.h and linux/quota.h
1385         conf.CHECK_HEADERS('sys/quota.h')
1386         # For quotas on BSD systems
1387         conf.CHECK_HEADERS('ufs/ufs/quota.h')
1388         # For quotas on Linux XFS filesystems
1389         if conf.CHECK_HEADERS('xfs/xqm.h'):
1390             conf.DEFINE('HAVE_XFS_QUOTAS', '1')
1391         else:
1392             # For Irix XFS
1393             conf.CHECK_CODE('''
1394                 #include "confdefs.h"
1395                 #ifdef HAVE_SYS_TYPES_H
1396                 #include <sys/types.h>
1397                 #endif
1398                 #ifdef HAVE_ASM_TYPES_H
1399                 #include <asm/types.h>
1400                 #endif
1401                 #include <sys/quota.h>
1402                 int i = Q_XGETQUOTA;''',
1403                 define='HAVE_XFS_QUOTAS',
1404                 msg='for XFS QUOTA in <sys/quota.h>',
1405                 execute=False,
1406                 local_include=False)
1407         
1408         # For IRIX like dqb_isoftlimit instead of dqb_fsoftlimit in struc dqblk
1409         conf.CHECK_STRUCTURE_MEMBER('struct dqblk', 'dqb_fsoftlimit', define='HAVE_DQB_FSOFTLIMIT',
1410                                 headers='sys/quota.h')
1411         #darwin style quota bytecount
1412         conf.CHECK_STRUCTURE_MEMBER('struct dqblk', 'dqb_curbytes', define='HAVE_STRUCT_DQBLK_DQB_CURBYTES',
1413                                 headers='sys/quota.h')
1414         if conf.CHECK_HEADERS('rpcsvc/rquota.h'):
1415             conf.DEFINE('HAVE_NFS_QUOTAS', '1')
1416             conf.CHECK_STRUCTURE_MEMBER('struct getquota_rslt', 'getquota_rslt_u',
1417                                         define='HAVE_GETQUOTA_RSLT_GETQUOTA_RSLT_U',
1418                                         headers='rpcsvc/rquota.h')
1419
1420         if (host_os.rfind('linux') > -1):
1421             conf.DEFINE('HAVE_QUOTACTL_LINUX', '1')
1422         elif not conf.CONFIG_SET("HAVE_XFS_QUOTAS"):
1423             if not conf.CHECK_CODE('''
1424                 #define HAVE_QUOTACTL_4A 1
1425                 #define AUTOCONF_TEST 1
1426                 #include "../tests/sysquotas.c"
1427                 ''',
1428                                    cflags=conf.env['WERROR_CFLAGS'],
1429                                    define='HAVE_QUOTACTL_4A',
1430                                    msg='for QUOTACTL_4A: long quotactl(int cmd, char *special, qid_t id, caddr_t addr)',
1431                                    execute=True,
1432                                    addmain=False):
1433
1434                 conf.CHECK_CODE('''
1435                 #define HAVE_QUOTACTL_4B 1
1436                 #define AUTOCONF_TEST 1
1437                 #include "../tests/sysquotas.c"
1438                 ''',
1439                                 cflags=conf.env['WERROR_CFLAGS'],
1440                                 define='HAVE_QUOTACTL_4B',
1441                                 msg='for QUOTACTL_4B:  int quotactl(const char *path, int cmd, int id, char *addr)',
1442                                 execute=True,
1443                                 addmain=False)
1444
1445         conf.CHECK_CODE('''
1446                      clnt_create("", RQUOTAPROG, RQUOTAVERS, "udp");
1447 ''', 
1448                         headers="rpc/rpc.h rpc/types.h rpcsvc/rquota.h rpc/nettype.h rpc/xdr.h", 
1449                         define='HAVE_NFS_QUOTAS',
1450                         msg='for NFS QUOTAS',
1451                         execute=True,
1452                         local_include=False)
1453
1454         if conf.CONFIG_SET('HAVE_QUOTACTL_LINUX') or \
1455            conf.CONFIG_SET('HAVE_QUOTACTL_4A') or \
1456            conf.CONFIG_SET('HAVE_QUOTACTL_4B') or \
1457            conf.CONFIG_SET('HAVE_XFS_QUOTAS'):
1458             conf.DEFINE('HAVE_SYS_QUOTAS', '1')
1459             conf.DEFINE('WITH_QUOTAS', '1')
1460
1461     #
1462     # cluster support (CTDB)
1463     #
1464     if not Options.options.with_cluster_support:
1465         Logs.info("building without cluster support (--without-cluster-support)")
1466         conf.env.with_ctdb = False
1467     else:
1468         Logs.info("building with cluster support")
1469         conf.env['CTDB_CFLAGS'] = '-DCLUSTER_SUPPORT=1'
1470         conf.env['CTDB_INCLUDE'] = conf.srcdir + '/ctdb/include'
1471         conf.env.with_ctdb = True
1472
1473     conf.CHECK_CODE('__attribute__((destructor)) static void cleanup(void) { }',
1474                     'HAVE_FUNCTION_ATTRIBUTE_DESTRUCTOR',
1475                     addmain=False,
1476                     link=False,
1477                     msg='Checking whether we can compile with __attribute__((destructor))')
1478
1479     conf.CHECK_CODE('void seekdir(DIR *d, long loc) { return; }',
1480                     'SEEKDIR_RETURNS_VOID',
1481                     headers='sys/types.h dirent.h',
1482                     msg='Checking whether seekdir returns void')
1483
1484     if Options.options.with_profiling_data:
1485         conf.DEFINE('WITH_PROFILE', 1);
1486         conf.CHECK_FUNCS('getrusage', headers="sys/time.h sys/resource.h")
1487
1488     if Options.options.with_pthreadpool:
1489         if conf.CONFIG_SET('HAVE_PTHREAD'):
1490             conf.DEFINE('WITH_PTHREADPOOL', '1')
1491         else:
1492             Logs.warn("pthreadpool support cannot be enabled when pthread support was not found")
1493             conf.undefine('WITH_PTHREADPOOL')
1494
1495     if (conf.CHECK_HEADERS('linux/ioctl.h sys/ioctl.h linux/fs.h') and
1496         conf.CHECK_DECLS('FS_IOC_GETFLAGS FS_COMPR_FL', headers='linux/fs.h')):
1497             conf.DEFINE('HAVE_LINUX_IOCTL', '1')
1498
1499     conf.env['CCFLAGS_CEPHFS'] = "-D_FILE_OFFSET_BITS=64"
1500     if Options.options.libcephfs_dir:
1501         conf.env['CPPPATH_CEPHFS'] = Options.options.libcephfs_dir + '/include'
1502         conf.env['LIBPATH_CEPHFS'] = Options.options.libcephfs_dir + '/lib'
1503
1504     if conf.CHECK_HEADERS('cephfs/libcephfs.h', False, False, 'cephfs') and conf.CHECK_LIB('cephfs'):
1505         conf.DEFINE('HAVE_CEPH', '1')
1506
1507     if Options.options.with_glusterfs:
1508         conf.CHECK_CFG(package='glusterfs-api', args='"glusterfs-api >= 4" --cflags --libs',
1509                        msg='Checking for glusterfs-api >= 4', uselib_store="GFAPI")
1510         conf.CHECK_HEADERS('api/glfs.h', lib='gfapi')
1511         conf.CHECK_LIB('gfapi', shlib=True)
1512
1513         if conf.CONFIG_SET('HAVE_API_GLFS_H'):
1514             conf.DEFINE('HAVE_GLUSTERFS', '1')
1515         else:
1516             conf.SET_TARGET_TYPE('gfapi', 'EMPTY')
1517             conf.undefine('HAVE_GLUSTERFS')
1518     else:
1519         conf.SET_TARGET_TYPE('gfapi', 'EMPTY')
1520         conf.undefine('HAVE_GLUSTERFS')
1521
1522     if Options.options.enable_vxfs:
1523         conf.DEFINE('HAVE_VXFS', '1')
1524
1525     if conf.CHECK_CFG(package='dbus-1', args='--cflags --libs',
1526                       msg='Checking for dbus', uselib_store="DBUS-1"):
1527         if (conf.CHECK_HEADERS('dbus/dbus.h', lib='dbus-1')
1528                                       and conf.CHECK_LIB('dbus-1', shlib=True)):
1529             conf.DEFINE('HAVE_DBUS', '1')
1530
1531     conf.env.build_regedit = False
1532     if not Options.options.with_regedit == False:
1533         conf.PROCESS_SEPARATE_RULE('system_ncurses')
1534         if conf.CONFIG_SET('HAVE_NCURSES'):
1535             conf.env.build_regedit = True
1536
1537     if conf.env.build_regedit:
1538         Logs.info("building regedit")
1539     else:
1540         if Options.options.with_regedit == False:
1541             Logs.info("not building regedit (--without-regedit)")
1542         elif Options.options.with_regedit == True:
1543             Logs.error("ncurses not available, cannot build regedit")
1544             conf.fatal("ncurses not available, but --with-regedit was specified")
1545         else:
1546             Logs.info("ncurses not available, not building regedit")
1547
1548     conf.CHECK_FUNCS_IN('DES_pcbc_encrypt', 'crypto')
1549     if Options.options.with_fake_kaserver == True:
1550         conf.CHECK_HEADERS('afs/param.h afs/stds.h', together=True)
1551         conf.CHECK_HEADERS('afs/param.h afs/stds.h', together=True)
1552         if (conf.CONFIG_SET('HAVE_AFS_PARAM_H') and conf.CONFIG_SET('HAVE_AFS_STDS_H') and conf.CONFIG_SET('HAVE_DES_PCBC_ENCRYPT')):
1553             conf.DEFINE('WITH_FAKE_KASERVER', '1')
1554         else:
1555             conf.fatal('AFS headers not available, but --with-fake-kaserver was specified')
1556
1557     conf.env['libtracker']=''
1558     conf.env.with_spotlight = False
1559     if Options.options.with_spotlight:
1560         versions = ['1.0', '0.16', '0.14']
1561         for version in versions:
1562             testlib = 'tracker-sparql-' + version
1563             if conf.check_cfg(package=testlib,
1564                               args='--cflags --libs',
1565                               mandatory=False):
1566                 conf.SET_TARGET_TYPE(testlib, 'SYSLIB')
1567                 conf.env['libtracker'] = testlib
1568                 conf.env.with_spotlight = True
1569                 conf.DEFINE('WITH_SPOTLIGHT', '1')
1570                 break
1571
1572         if not conf.env.with_spotlight:
1573             conf.fatal("Spotlight support requested but tracker-sparql library missing")
1574         Logs.info("building with Spotlight support")
1575
1576     default_static_modules.extend(TO_LIST('''pdb_smbpasswd pdb_tdbsam pdb_wbc_sam
1577                                       auth_sam auth_unix auth_winbind auth_wbc
1578                                       auth_domain auth_builtin vfs_default
1579                                       nss_info_template idmap_tdb idmap_passdb
1580                                       idmap_nss'''))
1581
1582     default_shared_modules.extend(TO_LIST('''vfs_recycle vfs_audit vfs_extd_audit vfs_full_audit vfs_netatalk
1583                                       vfs_fake_perms vfs_default_quota vfs_readonly vfs_cap
1584                                       vfs_expand_msdfs vfs_shadow_copy vfs_shadow_copy2 
1585                                       auth_script vfs_readahead vfs_xattr_tdb vfs_posix_eadb
1586                                       vfs_streams_xattr vfs_streams_depot vfs_acl_xattr vfs_acl_tdb
1587                                       vfs_smb_traffic_analyzer vfs_preopen vfs_catia vfs_scannedonly
1588                                       vfs_media_harmony vfs_unityed_media vfs_fruit vfs_shell_snap
1589                                       vfs_commit
1590                                       vfs_worm
1591                                       vfs_crossrename vfs_linux_xfs_sgid
1592                                       vfs_time_audit idmap_autorid idmap_tdb2
1593                                       idmap_script
1594                                       idmap_rid idmap_hash'''))
1595
1596     if Options.options.developer:
1597         default_static_modules.extend(TO_LIST('charset_weird'))
1598         default_shared_modules.extend(TO_LIST('perfcount_test'))
1599         default_shared_modules.extend(TO_LIST('vfs_skel_opaque vfs_skel_transparent vfs_shadow_copy_test'))
1600         default_shared_modules.extend(TO_LIST('auth_skel pdb_test'))
1601
1602     if Options.options.enable_selftest or Options.options.developer:
1603         default_shared_modules.extend(TO_LIST('vfs_fake_acls vfs_nfs4acl_xattr'))
1604         
1605
1606     if conf.CONFIG_SET('AD_DC_BUILD_IS_ENABLED'):
1607         default_static_modules.extend(TO_LIST('pdb_samba_dsdb auth_samba4 vfs_dfs_samba4'))
1608
1609     if conf.CONFIG_SET('HAVE_FREEBSD_SUNACL_H'):
1610         default_shared_modules.extend(TO_LIST('vfs_zfsacl'))
1611
1612     if conf.CONFIG_SET('HAVE_DIRFD_DECL'):
1613         default_shared_modules.extend(TO_LIST('vfs_syncops vfs_dirsort'))
1614
1615     if conf.CONFIG_SET('HAVE_STATFS_F_FSID'):
1616         default_shared_modules.extend(TO_LIST('vfs_fileid'))
1617
1618     if (conf.CONFIG_SET('HAVE_STRUCT_MSGHDR_MSG_CONTROL') or conf.CONFIG_SET('HAVE_STRUCT_MSGHDR_MSG_ACCRIGHTS')):
1619         default_shared_modules.extend(TO_LIST('vfs_aio_fork'))
1620
1621     if Options.options.with_pthreadpool:
1622         default_shared_modules.extend(TO_LIST('vfs_aio_pthread'))
1623
1624     if conf.CONFIG_SET('HAVE_AIO'):
1625         default_shared_modules.extend(TO_LIST('vfs_aio_posix'))
1626
1627     if conf.CONFIG_SET('HAVE_LINUX_KERNEL_AIO'):
1628         default_shared_modules.extend(TO_LIST('vfs_aio_linux'))
1629
1630     if conf.CONFIG_SET('HAVE_LDAP'):
1631         default_static_modules.extend(TO_LIST('pdb_ldapsam idmap_ldap'))
1632
1633     if conf.CONFIG_SET('DARWINOS'):
1634         default_static_modules.extend(TO_LIST('charset_macosxfs'))
1635
1636     if conf.CONFIG_SET('HAVE_GPFS'):
1637         default_shared_modules.extend(TO_LIST('vfs_gpfs'))
1638
1639     if (conf.CONFIG_SET('HAVE_LINUX_IOCTL')
1640       and conf.CONFIG_SET('HAVE_BASENAME') and conf.CONFIG_SET('HAVE_DIRNAME')):
1641         default_shared_modules.extend(TO_LIST('vfs_btrfs'))
1642
1643     if conf.CONFIG_SET('SAMBA_FAM_LIBS'):
1644         default_shared_modules.extend(TO_LIST('vfs_notify_fam'))
1645
1646     if conf.CONFIG_SET("HAVE_CEPH"):
1647         default_shared_modules.extend(TO_LIST('vfs_ceph'))
1648
1649     if conf.CONFIG_SET('HAVE_GLUSTERFS'):
1650         default_shared_modules.extend(TO_LIST('vfs_glusterfs'))
1651
1652     if conf.CONFIG_SET('HAVE_VXFS'):
1653         default_shared_modules.extend(TO_LIST('vfs_vxfs'))
1654
1655     if conf.CONFIG_SET('HAVE_DBUS'):
1656         default_shared_modules.extend(TO_LIST('vfs_snapper'))
1657
1658     explicit_shared_modules = TO_LIST(Options.options.shared_modules, delimiter=',')
1659     explicit_static_modules = TO_LIST(Options.options.static_modules, delimiter=',')
1660
1661     def replace_list_item(lst, item, value):
1662         try:
1663             idx = lst.index(item)
1664             lst[idx] = value
1665         except:
1666             pass
1667     # PDB module file name should have the same name as module registers itself
1668     # In Autoconf build we export LDAP passdb module as ldapsam but WAF build
1669     # was always exporting pdb_ldap. In order to support existing packages
1670     # allow referring to pdb_ldapsam as pdb_ldap but use proper name internally.
1671     replace_list_item(explicit_shared_modules, 'pdb_ldap', 'pdb_ldapsam')
1672     replace_list_item(explicit_static_modules, 'pdb_ldap', 'pdb_ldapsam')
1673
1674     final_static_modules = default_static_modules
1675     final_shared_modules = default_shared_modules
1676
1677     for m in explicit_static_modules:
1678         if m in final_shared_modules:
1679             final_shared_modules.remove(m)
1680         final_static_modules.append(m)
1681     for m in explicit_shared_modules:
1682         if m in final_static_modules:
1683             final_static_modules.remove(m)
1684         final_shared_modules.append(m)
1685
1686     if ("auth_domain" not in final_static_modules) or \
1687             ("auth_builtin" not in final_static_modules) or \
1688             ("auth_sam" not in final_static_modules) or \
1689             ("auth_winbind" not in final_static_modules):
1690         raise Utils.WafError('These auth modules MUST be configured as static modules: auth_domain, auth_builtin, auth_sam, auth_winbind')
1691
1692     conf.env['static_modules'] = final_static_modules
1693     conf.env['shared_modules'] = final_shared_modules
1694
1695     conf.DEFINE('STRING_STATIC_MODULES', ' '.join(final_static_modules), quote=True)
1696
1697     static_list = {}
1698     shared_list = {}
1699
1700     prefixes = ['vfs', 'pdb', 'auth', 'nss_info', 'charset', 'idmap', 'gpext', 'perfcount']
1701     conf.env['MODULE_PREFIXES'] = prefixes
1702     for p in prefixes:
1703         for m in final_static_modules:
1704             if m.find(p) == 0:
1705                 if not p in static_list:
1706                     static_list[p] = []
1707                 static_list[p].append(m)
1708         for m in final_shared_modules:
1709             if m.find(p) == 0:
1710                 if not p in shared_list:
1711                     shared_list[p] = []
1712                 shared_list[p].append(m)
1713
1714     for p in prefixes:
1715         static_env = "%s_STATIC" % p.upper()
1716         shared_env = "%s_SHARED" % p.upper()
1717         conf.env[static_env] = []
1718         conf.env[shared_env] = []
1719         if p in static_list:
1720             decl_list=""
1721             for entry in static_list[p]:
1722                 decl_list += "extern NTSTATUS %s_init(void); " % entry
1723                 conf.env[static_env].append('%s' % entry)
1724             decl_list = decl_list.rstrip()
1725             conf.DEFINE('static_decl_%s' % p, decl_list)
1726             conf.DEFINE('static_init_%s' % p, '{ %s_init(); }' % '_init();  '.join(static_list[p]))
1727         else:
1728             conf.DEFINE('static_decl_%s' % p, '')
1729             conf.DEFINE('static_init_%s' % p, '{}')
1730         if p in shared_list:
1731             for entry in shared_list[p]:
1732                 conf.DEFINE('%s_init' % entry, 'samba_init_module')
1733                 conf.env[shared_env].append('%s' % entry)
1734
1735     conf.SAMBA_CONFIG_H('include/config.h')
1736
1737 def ctags(ctx):
1738     "build 'tags' file using ctags"
1739     import Utils
1740     source_root = os.path.dirname(Utils.g_module.root_path)
1741     cmd = 'ctags $(find %s/.. -name "*.[ch]" | grep -v "*_proto\.h")' % source_root
1742     print("Running: %s" % cmd)
1743     os.system(cmd)
1744