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