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