CVE-2019-3824 ldb: Improve code style and layout in wildcard processing
[Samba.git] / wscript
blobc9a4de4982b15de07318845ed1dc5face9048a27
1 #!/usr/bin/env python
3 srcdir = '.'
4 blddir = 'bin'
6 APPNAME='samba'
7 VERSION=None
9 import sys, os, tempfile
10 sys.path.insert(0, srcdir+"/buildtools/wafsamba")
11 import wafsamba, Options, samba_dist, samba_git, Scripting, Utils, samba_version
12 import Logs, samba_utils
15 samba_dist.DIST_DIRS('.')
16 samba_dist.DIST_BLACKLIST('.gitignore .bzrignore source4/selftest/provisions')
18 # install in /usr/local/samba by default
19 default_prefix = Options.default_prefix = '/usr/local/samba'
21 # This callback optionally takes a list of paths as arguments:
22 # --with-system_mitkrb5 /path/to/krb5 /another/path
23 def system_mitkrb5_callback(option, opt, value, parser):
24 setattr(parser.values, option.dest, True)
25 value = []
26 for arg in parser.rargs:
27 # stop on --foo like options
28 if arg[:2] == "--" and len(arg) > 2:
29 break
30 value.append(arg)
31 if len(value)>0:
32 del parser.rargs[:len(value)]
33 setattr(parser.values, option.dest, value)
35 def set_options(opt):
36 opt.BUILTIN_DEFAULT('NONE')
37 opt.PRIVATE_EXTENSION_DEFAULT('samba4')
38 opt.RECURSE('lib/replace')
39 opt.RECURSE('dynconfig')
40 opt.RECURSE('lib/ldb')
41 opt.RECURSE('selftest')
42 opt.RECURSE('source4/lib/tls')
43 opt.RECURSE('source4/dsdb/samdb/ldb_modules')
44 opt.RECURSE('pidl')
45 opt.RECURSE('source3')
46 opt.RECURSE('lib/util')
47 opt.RECURSE('lib/crypto')
48 opt.RECURSE('ctdb')
49 opt.samba_add_onoff_option('pthreadpool', with_name="enable", without_name="disable", default=True)
51 opt.add_option('--with-system-mitkrb5',
52 help='build Samba with system MIT Kerberos. ' +
53 'You may specify list of paths where Kerberos is installed (e.g. /usr/local /usr/kerberos) to search krb5-config',
54 action='callback', callback=system_mitkrb5_callback, dest='with_system_mitkrb5', default=False)
56 opt.add_option('--with-experimental-mit-ad-dc',
57 help='Enable the experimental MIT Kerberos-backed AD DC. ' +
58 'Note that security patches are not issued for this configuration',
59 action='store_true',
60 dest='with_experimental_mit_ad_dc',
61 default=False)
63 opt.add_option('--with-system-mitkdc',
64 help=('Specify the path to the krb5kdc binary from MIT Kerberos'),
65 type="string",
66 dest='with_system_mitkdc',
67 default=None)
69 opt.add_option('--without-ad-dc',
70 help='disable AD DC functionality (enables only Samba FS (File Server, Winbind, NMBD) and client utilities.',
71 action='store_true', dest='without_ad_dc', default=False)
73 opt.add_option('--with-ntvfs-fileserver',
74 help='enable the deprecated NTVFS file server from the original Samba4 branch (default if --enable-selftest specified). Conflicts with --with-system-mitkrb5 and --without-ad-dc',
75 action='store_true', dest='with_ntvfs_fileserver')
77 opt.add_option('--without-ntvfs-fileserver',
78 help='disable the deprecated NTVFS file server from the original Samba4 branch',
79 action='store_false', dest='with_ntvfs_fileserver')
81 opt.add_option('--with-pie',
82 help=("Build Position Independent Executables " +
83 "(default if supported by compiler)"),
84 action="store_true", dest='enable_pie')
85 opt.add_option('--without-pie',
86 help=("Disable Position Independent Executable builds"),
87 action="store_false", dest='enable_pie')
89 opt.add_option('--with-relro',
90 help=("Build with full RELocation Read-Only (RELRO)" +
91 "(default if supported by compiler)"),
92 action="store_true", dest='enable_relro')
93 opt.add_option('--without-relro',
94 help=("Disable RELRO builds"),
95 action="store_false", dest='enable_relro')
97 gr = opt.option_group('developer options')
99 opt.tool_options('python') # options for disabling pyc or pyo compilation
100 # enable options related to building python extensions
103 def configure(conf):
104 version = samba_version.load_version(env=conf.env)
106 conf.DEFINE('CONFIG_H_IS_FROM_SAMBA', 1)
107 conf.DEFINE('_SAMBA_BUILD_', version.MAJOR, add_to_cflags=True)
108 conf.DEFINE('HAVE_CONFIG_H', 1, add_to_cflags=True)
110 if Options.options.developer:
111 conf.ADD_CFLAGS('-DDEVELOPER -DDEBUG_PASSWORD')
112 conf.env.DEVELOPER = True
114 conf.ADD_EXTRA_INCLUDES('#include/public #source4 #lib #source4/lib #source4/include #include #lib/replace')
116 conf.env.replace_add_global_pthread = True
117 conf.RECURSE('lib/replace')
119 conf.RECURSE('examples/fuse')
121 conf.SAMBA_CHECK_PERL(mandatory=True)
122 conf.find_program('xsltproc', var='XSLTPROC')
124 if conf.env.disable_python:
125 if not (Options.options.without_ad_dc):
126 raise Utils.WafError('--disable-python requires --without-ad-dc')
128 conf.SAMBA_CHECK_PYTHON(mandatory=True, version=(2, 6, 0))
129 conf.SAMBA_CHECK_PYTHON_HEADERS(mandatory=(not conf.env.disable_python))
131 if sys.platform == 'darwin' and not conf.env['HAVE_ENVIRON_DECL']:
132 # Mac OSX needs to have this and it's also needed that the python is compiled with this
133 # otherwise you face errors about common symbols
134 if not conf.CHECK_SHLIB_W_PYTHON("Checking if -fno-common is needed"):
135 conf.ADD_CFLAGS('-fno-common')
136 if not conf.CHECK_SHLIB_W_PYTHON("Checking if -undefined dynamic_lookup is not need"):
137 conf.env.append_value('shlib_LINKFLAGS', ['-undefined', 'dynamic_lookup'])
139 if sys.platform == 'darwin':
140 conf.ADD_LDFLAGS('-framework CoreFoundation')
142 if int(conf.env['PYTHON_VERSION'][0]) >= 3:
143 raise Utils.WafError('Python version 3.x is not supported by Samba yet')
145 conf.RECURSE('dynconfig')
147 if conf.CHECK_FOR_THIRD_PARTY():
148 conf.RECURSE('third_party')
149 else:
150 if not conf.CHECK_ZLIB():
151 raise Utils.WafError('zlib development packages have not been found.\nIf third_party is installed, check that it is in the proper place.')
152 else:
153 conf.define('USING_SYSTEM_ZLIB',1)
155 if not conf.CHECK_POPT():
156 raise Utils.WafError('popt development packages have not been found.\nIf third_party is installed, check that it is in the proper place.')
157 else:
158 conf.define('USING_SYSTEM_POPT', 1)
160 if not conf.CHECK_CMOCKA():
161 raise Utils.WafError('cmocka development packages has not been found.\nIf third_party is installed, check that it is in the proper place.')
162 else:
163 conf.define('USING_SYSTEM_CMOCKA', 1)
166 conf.RECURSE('lib/ldb')
168 if conf.CHECK_LDFLAGS(['-Wl,--wrap=test']):
169 conf.env['HAVE_LDWRAP'] = True
170 conf.define('HAVE_LDWRAP', 1)
172 if not (Options.options.without_ad_dc):
173 conf.DEFINE('AD_DC_BUILD_IS_ENABLED', 1)
175 if Options.options.with_system_mitkrb5:
176 if not Options.options.with_experimental_mit_ad_dc and \
177 not Options.options.without_ad_dc:
178 raise Utils.WafError('The MIT Kerberos build of Samba as an AD DC ' +
179 'is experimental. Therefore '
180 '--with-system-mitkrb5 requires either ' +
181 '--with-experimental-mit-ad-dc or ' +
182 '--without-ad-dc')
184 conf.PROCESS_SEPARATE_RULE('system_mitkrb5')
186 if not (Options.options.without_ad_dc or Options.options.with_system_mitkrb5):
187 conf.DEFINE('AD_DC_BUILD_IS_ENABLED', 1)
189 # Only process heimdal_build for non-MIT KRB5 builds
190 # When MIT KRB5 checks are done as above, conf.env.KRB5_VENDOR will be set
191 # to the lowcased output of 'krb5-config --vendor'.
192 # If it is not set or the output is 'heimdal', we are dealing with
193 # system-provided or embedded Heimdal build
194 if conf.CONFIG_GET('KRB5_VENDOR') in (None, 'heimdal'):
195 conf.RECURSE('source4/heimdal_build')
196 conf.RECURSE('source4/lib/tls')
197 conf.RECURSE('source4/dsdb/samdb/ldb_modules')
198 conf.RECURSE('source4/ntvfs/sysdep')
199 conf.RECURSE('lib/util')
200 conf.RECURSE('lib/util/charset')
201 conf.RECURSE('source4/auth')
202 conf.RECURSE('nsswitch')
203 conf.RECURSE('libcli/smbreadline')
204 conf.RECURSE('lib/crypto')
205 conf.RECURSE('pidl')
206 conf.RECURSE('selftest')
207 if conf.CONFIG_GET('ENABLE_SELFTEST'):
208 conf.RECURSE('lib/nss_wrapper')
209 conf.RECURSE('lib/resolv_wrapper')
210 conf.RECURSE('lib/socket_wrapper')
211 conf.RECURSE('lib/uid_wrapper')
212 if Options.options.with_pam:
213 conf.RECURSE('lib/pam_wrapper')
214 if Options.options.with_ntvfs_fileserver != False:
215 if not (Options.options.without_ad_dc):
216 conf.DEFINE('WITH_NTVFS_FILESERVER', 1)
217 if Options.options.with_ntvfs_fileserver == False:
218 if not (Options.options.without_ad_dc):
219 raise Utils.WafError('--without-ntvfs-fileserver conflicts with --enable-selftest while building the AD DC')
220 conf.RECURSE('testsuite/unittests')
222 if Options.options.with_ntvfs_fileserver == True:
223 if Options.options.without_ad_dc:
224 raise Utils.WafError('--with-ntvfs-fileserver conflicts with --without-ad-dc')
225 conf.DEFINE('WITH_NTVFS_FILESERVER', 1)
227 if Options.options.with_pthreadpool:
228 if conf.CONFIG_SET('HAVE_PTHREAD'):
229 conf.DEFINE('WITH_PTHREADPOOL', '1')
230 else:
231 Logs.warn("pthreadpool support cannot be enabled when pthread support was not found")
232 conf.undefine('WITH_PTHREADPOOL')
234 conf.RECURSE('source3')
235 conf.RECURSE('lib/texpect')
236 conf.RECURSE('python')
237 if conf.env.with_ctdb:
238 conf.RECURSE('ctdb')
239 conf.RECURSE('lib/socket')
240 conf.RECURSE('auth')
242 conf.SAMBA_CHECK_UNDEFINED_SYMBOL_FLAGS()
244 # gentoo always adds this. We want our normal build to be as
245 # strict as the strictest OS we support, so adding this here
246 # allows us to find problems on our development hosts faster.
247 # It also results in faster load time.
249 conf.env.asneeded_ldflags = conf.ADD_LDFLAGS('-Wl,--as-needed', testflags=True)
251 if not conf.CHECK_NEED_LC("-lc not needed"):
252 conf.ADD_LDFLAGS('-lc', testflags=False)
254 if not conf.CHECK_CODE('#include "tests/summary.c"',
255 define='SUMMARY_PASSES',
256 addmain=False,
257 msg='Checking configure summary'):
258 raise Utils.WafError('configure summary failed')
260 if Options.options.enable_pie != False:
261 if Options.options.enable_pie == True:
262 need_pie = True
263 else:
264 # not specified, only build PIEs if supported by compiler
265 need_pie = False
266 if conf.check_cc(cflags='-fPIE', ldflags='-pie', mandatory=need_pie,
267 msg="Checking compiler for PIE support"):
268 conf.env['ENABLE_PIE'] = True
270 if Options.options.enable_relro != False:
271 if Options.options.enable_relro == True:
272 need_relro = True
273 else:
274 # not specified, only build RELROs if supported by compiler
275 need_relro = False
276 if conf.check_cc(cflags='', ldflags='-Wl,-z,relro,-z,now', mandatory=need_relro,
277 msg="Checking compiler for full RELRO support"):
278 conf.env['ENABLE_RELRO'] = True
280 conf.SAMBA_CONFIG_H('include/config.h')
282 def etags(ctx):
283 '''build TAGS file using etags'''
284 import Utils
285 source_root = os.path.dirname(Utils.g_module.root_path)
286 cmd = 'rm -f %s/TAGS && (find %s -name "*.[ch]" | egrep -v \.inst\. | xargs -n 100 etags -a)' % (source_root, source_root)
287 print("Running: %s" % cmd)
288 status = os.system(cmd)
289 if os.WEXITSTATUS(status):
290 raise Utils.WafError('etags failed')
292 def ctags(ctx):
293 "build 'tags' file using ctags"
294 import Utils
295 source_root = os.path.dirname(Utils.g_module.root_path)
296 cmd = 'ctags --python-kinds=-i $(find %s -name "*.[ch]" | grep -v "*_proto\.h" | egrep -v \.inst\.) $(find %s -name "*.py")' % (source_root, source_root)
297 print("Running: %s" % cmd)
298 status = os.system(cmd)
299 if os.WEXITSTATUS(status):
300 raise Utils.WafError('ctags failed')
303 # putting this here enabled build in the list
304 # of commands in --help
305 def build(bld):
306 '''build all targets'''
307 samba_version.load_version(env=bld.env, is_install=bld.is_install)
310 def pydoctor(ctx):
311 '''build python apidocs'''
312 bp = os.path.abspath('bin/python')
313 mpaths = {}
314 modules = ['talloc', 'tdb', 'ldb']
315 for m in modules:
316 f = os.popen("PYTHONPATH=%s python -c 'import %s; print %s.__file__'" % (bp, m, m), 'r')
317 try:
318 mpaths[m] = f.read().strip()
319 finally:
320 f.close()
321 mpaths['main'] = bp
322 cmd = ('PYTHONPATH=%(main)s pydoctor --introspect-c-modules --project-name=Samba '
323 '--project-url=http://www.samba.org --make-html --docformat=restructuredtext '
324 '--add-package bin/python/samba ' + ''.join('--add-module %s ' % n for n in modules))
325 cmd = cmd % mpaths
326 print("Running: %s" % cmd)
327 status = os.system(cmd)
328 if os.WEXITSTATUS(status):
329 raise Utils.WafError('pydoctor failed')
332 def pep8(ctx):
333 '''run pep8 validator'''
334 cmd='PYTHONPATH=bin/python pep8 -r bin/python/samba'
335 print("Running: %s" % cmd)
336 status = os.system(cmd)
337 if os.WEXITSTATUS(status):
338 raise Utils.WafError('pep8 failed')
341 def wafdocs(ctx):
342 '''build wafsamba apidocs'''
343 from samba_utils import recursive_dirlist
344 os.system('pwd')
345 list = recursive_dirlist('../buildtools/wafsamba', '.', pattern='*.py')
347 cmd='PYTHONPATH=bin/python pydoctor --project-name=wafsamba --project-url=http://www.samba.org --make-html --docformat=restructuredtext'
348 print(list)
349 for f in list:
350 cmd += ' --add-module %s' % f
351 print("Running: %s" % cmd)
352 status = os.system(cmd)
353 if os.WEXITSTATUS(status):
354 raise Utils.WafError('wafdocs failed')
357 def dist():
358 '''makes a tarball for distribution'''
359 sambaversion = samba_version.load_version(env=None)
361 os.system("make -C ctdb manpages")
362 samba_dist.DIST_FILES('ctdb/doc:ctdb/doc', extend=True)
364 os.system(srcdir + "/release-scripts/build-manpages-nogit")
365 samba_dist.DIST_FILES('bin/docs:docs', extend=True)
367 if sambaversion.IS_SNAPSHOT:
368 # write .distversion file and add to tar
369 if not os.path.isdir(blddir):
370 os.makedirs(blddir)
371 distversionf = tempfile.NamedTemporaryFile(mode='w', prefix='.distversion',dir=blddir)
372 for field in sambaversion.vcs_fields:
373 distveroption = field + '=' + str(sambaversion.vcs_fields[field])
374 distversionf.write(distveroption + '\n')
375 distversionf.flush()
376 samba_dist.DIST_FILES('%s:.distversion' % distversionf.name, extend=True)
378 samba_dist.dist()
379 distversionf.close()
380 else:
381 samba_dist.dist()
384 def distcheck():
385 '''test that distribution tarball builds and installs'''
386 samba_version.load_version(env=None)
387 import Scripting
388 d = Scripting.distcheck
391 def wildcard_cmd(cmd):
392 '''called on a unknown command'''
393 from samba_wildcard import run_named_build_task
394 run_named_build_task(cmd)
396 def main():
397 from samba_wildcard import wildcard_main
399 wildcard_main(wildcard_cmd)
400 Scripting.main = main
402 def reconfigure(ctx):
403 '''reconfigure if config scripts have changed'''
404 import samba_utils
405 samba_utils.reconfigure(ctx)
408 if os.path.isdir(os.path.join(srcdir, ".git")):
409 # Check if there are submodules that are checked out but out of date.
410 for submodule, status in samba_git.read_submodule_status(srcdir):
411 if status == "out-of-date":
412 raise Utils.WafError("some submodules are out of date. Please run 'git submodule update'")