CVE-2019-3824 ldb: Release ldb 1.4.6
[Samba.git] / lib / ldb / wscript
blob5c5ca15f86a784367e853cb626e6d82b44d1ad4e
1 #!/usr/bin/env python
3 APPNAME = 'ldb'
4 VERSION = '1.4.6'
6 blddir = 'bin'
8 import sys, os
9 import Logs
11 # find the buildtools directory
12 srcdir = '.'
13 while not os.path.exists(srcdir+'/buildtools') and len(srcdir.split('/')) < 5:
14 srcdir = srcdir + '/..'
15 sys.path.insert(0, srcdir + '/buildtools/wafsamba')
17 import wafsamba, samba_dist, Utils, Options
19 samba_dist.DIST_DIRS('''lib/ldb:. lib/replace:lib/replace lib/talloc:lib/talloc
20 lib/tdb:lib/tdb lib/tdb:lib/tdb lib/tevent:lib/tevent
21 third_party/popt:third_party/popt
22 third_party/cmocka:third_party/cmocka
23 buildtools:buildtools third_party/waf:third_party/waf''')
25 samba_dist.DIST_FILES('''lib/util/binsearch.h:lib/util/binsearch.h''')
27 def set_options(opt):
28 opt.BUILTIN_DEFAULT('replace')
29 opt.PRIVATE_EXTENSION_DEFAULT('ldb', noextension='ldb')
30 opt.RECURSE('lib/tdb')
31 opt.RECURSE('lib/tevent')
32 opt.RECURSE('lib/replace')
33 opt.tool_options('python') # options for disabling pyc or pyo compilation
35 opt.add_option('--without-ldb-lmdb',
36 help='disable new LMDB backend for LDB',
37 action='store_true', dest='without_ldb_lmdb', default=False)
40 def configure(conf):
41 conf.RECURSE('lib/tdb')
42 conf.RECURSE('lib/tevent')
44 if conf.CHECK_FOR_THIRD_PARTY():
45 conf.RECURSE('third_party/popt')
46 conf.RECURSE('third_party/cmocka')
47 else:
48 if not conf.CHECK_POPT():
49 raise Utils.WafError('popt development packages have not been found.\nIf third_party is installed, check that it is in the proper place.')
50 else:
51 conf.define('USING_SYSTEM_POPT', 1)
53 if not conf.CHECK_CMOCKA():
54 raise Utils.WafError('cmocka development package have not been found.\nIf third_party is installed, check that it is in the proper place.')
55 else:
56 conf.define('USING_SYSTEM_CMOCKA', 1)
58 conf.RECURSE('lib/replace')
59 conf.find_program('python', var='PYTHON')
60 conf.find_program('xsltproc', var='XSLTPROC')
61 conf.check_tool('python')
62 conf.check_python_version((2,4,2))
63 conf.SAMBA_CHECK_PYTHON_HEADERS(mandatory=not conf.env.disable_python)
65 # where does the default LIBDIR end up? in conf.env somewhere?
67 conf.CONFIG_PATH('LDB_MODULESDIR', conf.SUBST_ENV_VAR('MODULESDIR') + '/ldb')
69 conf.env.standalone_ldb = conf.IN_LAUNCH_DIR()
71 if not conf.env.standalone_ldb:
72 max_ldb_version = [int(x) for x in VERSION.split(".")]
73 max_ldb_version[2] = 999
74 max_ldb_version_dots = "%d.%d.%d" % tuple(max_ldb_version)
76 if conf.env.disable_python:
77 if conf.CHECK_BUNDLED_SYSTEM_PKG('ldb',
78 minversion=VERSION,
79 maxversion=max_ldb_version_dots,
80 onlyif='talloc tdb tevent',
81 implied_deps='replace talloc tdb tevent'):
82 conf.define('USING_SYSTEM_LDB', 1)
83 else:
84 using_system_pyldb_util = True
85 if not conf.CHECK_BUNDLED_SYSTEM_PKG('pyldb-util',
86 minversion=VERSION,
87 maxversion=max_ldb_version_dots,
88 onlyif='talloc tdb tevent',
89 implied_deps='replace talloc tdb tevent ldb'):
90 using_system_pyldb_util = False
92 # We need to get a pyldb-util for all the python versions
93 # we are building for
94 if conf.env['EXTRA_PYTHON']:
95 name = 'pyldb-util' + conf.all_envs['extrapython']['PYTHON_SO_ABI_FLAG']
96 if not conf.CHECK_BUNDLED_SYSTEM_PKG(name,
97 minversion=VERSION,
98 maxversion=max_ldb_version_dots,
99 onlyif='talloc tdb tevent',
100 implied_deps='replace talloc tdb tevent ldb'):
101 using_system_pyldb_util = False
103 if using_system_pyldb_util:
104 conf.define('USING_SYSTEM_PYLDB_UTIL', 1)
106 if conf.CHECK_BUNDLED_SYSTEM_PKG('ldb',
107 minversion=VERSION,
108 maxversion=max_ldb_version_dots,
109 onlyif='talloc tdb tevent pyldb-util',
110 implied_deps='replace talloc tdb tevent'):
111 conf.define('USING_SYSTEM_LDB', 1)
113 if not conf.CHECK_CODE('return !(sizeof(size_t) >= 8)',
114 "HAVE_64_BIT_SIZE_T_FOR_LMDB",
115 execute=True,
116 msg='Checking for a 64-bit host to '
117 'support lmdb'):
118 Logs.warn("--without-ldb-lmdb implied as this "
119 "host is not 64-bit")
121 if not conf.env.standalone_ldb and \
122 not Options.options.without_ad_dc and \
123 conf.CONFIG_GET('ENABLE_SELFTEST'):
124 Logs.warn("NOTE: Some AD DC parts of selftest will fail")
126 conf.env.REQUIRE_LMDB = False
127 else:
128 if conf.env.standalone_ldb:
129 if Options.options.without_ldb_lmdb:
130 conf.env.REQUIRE_LMDB = False
131 else:
132 conf.env.REQUIRE_LMDB = True
133 elif Options.options.without_ad_dc:
134 conf.env.REQUIRE_LMDB = False
135 else:
136 if Options.options.without_ldb_lmdb:
137 if not Options.options.without_ad_dc and \
138 conf.CONFIG_GET('ENABLE_SELFTEST'):
139 raise Utils.WafError('--without-ldb-lmdb conflicts '
140 'with --enable-selftest while '
141 'building the AD DC')
143 conf.env.REQUIRE_LMDB = False
144 else:
145 conf.env.REQUIRE_LMDB = True
148 if conf.CONFIG_SET('USING_SYSTEM_LDB'):
149 v = VERSION.split('.')
150 conf.DEFINE('EXPECTED_SYSTEM_LDB_VERSION_MAJOR', int(v[0]))
151 conf.DEFINE('EXPECTED_SYSTEM_LDB_VERSION_MINOR', int(v[1]))
152 conf.DEFINE('EXPECTED_SYSTEM_LDB_VERSION_RELEASE', int(v[2]))
154 if conf.env.standalone_ldb:
155 conf.CHECK_XSLTPROC_MANPAGES()
157 # we need this for the ldap backend
158 if conf.CHECK_FUNCS_IN('ber_flush ldap_open ldap_initialize', 'lber ldap', headers='lber.h ldap.h'):
159 conf.env.ENABLE_LDAP_BACKEND = True
161 # we don't want any libraries or modules to rely on runtime
162 # resolution of symbols
163 if not sys.platform.startswith("openbsd"):
164 conf.ADD_LDFLAGS('-Wl,-no-undefined', testflags=True)
166 # if lmdb support is enabled then we require lmdb
167 # is present, build the mdb back end and enable lmdb support in
168 # the tools.
169 if conf.env.REQUIRE_LMDB and \
170 not conf.CONFIG_SET('USING_SYSTEM_LDB'):
171 if not conf.CHECK_CFG(package='lmdb',
172 args='"lmdb >= 0.9.16" --cflags --libs',
173 msg='Checking for lmdb >= 0.9.16',
174 mandatory=False):
175 if not conf.CHECK_CODE('''
176 #if MDB_VERSION_MAJOR == 0 \
177 && MDB_VERSION_MINOR <= 9 \
178 && MDB_VERSION_PATCH < 16
179 #error LMDB too old
180 #endif
181 ''',
182 'HAVE_GOOD_LMDB_VERSION',
183 headers='lmdb.h',
184 msg='Checking for lmdb >= 0.9.16 via header check'):
186 if conf.env.standalone_ldb:
187 raise Utils.WafError('ldb build (unless --without-ldb-lmdb) '
188 'requires '
189 'lmdb 0.9.16 or later')
190 elif not Options.options.without_ad_dc:
191 raise Utils.WafError('Samba AD DC and --enable-selftest '
192 'requires '
193 'lmdb 0.9.16 or later')
195 if conf.CHECK_FUNCS_IN('mdb_env_create', 'lmdb', headers='lmdb.h'):
196 conf.DEFINE('HAVE_LMDB', '1')
199 conf.DEFINE('HAVE_CONFIG_H', 1, add_to_cflags=True)
201 conf.SAMBA_CONFIG_H()
203 conf.SAMBA_CHECK_UNDEFINED_SYMBOL_FLAGS()
205 def build(bld):
206 bld.RECURSE('lib/tevent')
208 if bld.CHECK_FOR_THIRD_PARTY():
209 bld.RECURSE('third_party/popt')
210 bld.RECURSE('third_party/cmocka')
212 bld.RECURSE('lib/replace')
213 bld.RECURSE('lib/tdb')
215 if bld.env.standalone_ldb:
216 if not 'PACKAGE_VERSION' in bld.env:
217 bld.env.PACKAGE_VERSION = VERSION
218 bld.env.PKGCONFIGDIR = '${LIBDIR}/pkgconfig'
219 private_library = False
220 else:
221 private_library = True
222 # we're not currently linking against the ldap libs, but ldb.pc.in
223 # has @LDAP_LIBS@
224 bld.env.LDAP_LIBS = ''
226 LDB_MAP_SRC = bld.SUBDIR('ldb_map',
227 'ldb_map.c ldb_map_inbound.c ldb_map_outbound.c')
229 COMMON_SRC = bld.SUBDIR('common',
230 '''ldb_modules.c ldb_ldif.c ldb_parse.c ldb_msg.c ldb_utf8.c
231 ldb_debug.c ldb_dn.c ldb_match.c ldb_options.c ldb_pack.c
232 ldb_attributes.c attrib_handlers.c ldb_controls.c qsort.c''')
234 bld.SAMBA_MODULE('ldb_ldap', 'ldb_ldap/ldb_ldap.c',
235 init_function='ldb_ldap_init',
236 module_init_name='ldb_init_module',
237 deps='talloc lber ldap ldb',
238 enabled=bld.env.ENABLE_LDAP_BACKEND,
239 internal_module=False,
240 subsystem='ldb')
242 if bld.PYTHON_BUILD_IS_ENABLED():
243 if not bld.CONFIG_SET('USING_SYSTEM_PYLDB_UTIL'):
244 for env in bld.gen_python_environments(['PKGCONFIGDIR']):
246 name = bld.pyembed_libname('pyldb-util')
247 bld.SAMBA_LIBRARY(name,
248 deps='ldb',
249 source='pyldb_util.c',
250 public_headers=('' if private_library else 'pyldb.h'),
251 public_headers_install=not private_library,
252 vnum=VERSION,
253 private_library=private_library,
254 pc_files='pyldb-util.pc',
255 pyembed=True,
256 enabled=bld.PYTHON_BUILD_IS_ENABLED(),
257 abi_directory='ABI',
258 abi_match='pyldb_*')
260 if not bld.CONFIG_SET('USING_SYSTEM_LDB'):
261 bld.SAMBA_PYTHON('pyldb', 'pyldb.c',
262 deps='ldb ' + name,
263 realname='ldb.so',
264 cflags='-DPACKAGE_VERSION=\"%s\"' % VERSION)
266 # Do only install this file as part of the Samba build if we do not
267 # use the system libldb!
268 if not bld.CONFIG_SET('USING_SYSTEM_PYLDB_UTIL'):
269 for env in bld.gen_python_environments(['PKGCONFIGDIR']):
270 bld.SAMBA_SCRIPT('_ldb_text.py',
271 pattern='_ldb_text.py',
272 installdir='python')
274 bld.INSTALL_FILES('${PYTHONARCHDIR}', '_ldb_text.py')
276 if not bld.CONFIG_SET('USING_SYSTEM_LDB'):
277 if bld.is_install:
278 modules_dir = bld.EXPAND_VARIABLES('${LDB_MODULESDIR}')
279 else:
280 # when we run from the source directory, we want to use
281 # the current modules, not the installed ones
282 modules_dir = os.path.join(os.getcwd(), 'bin/modules/ldb')
284 abi_match = '!ldb_*module_ops !ldb_*backend_ops ldb_*'
286 ldb_headers = ('include/ldb.h include/ldb_errors.h '
287 'include/ldb_module.h include/ldb_handlers.h')
289 bld.SAMBA_LIBRARY('ldb',
290 COMMON_SRC + ' ' + LDB_MAP_SRC,
291 deps='tevent LIBLDB_MAIN replace',
292 includes='include',
293 public_headers=('' if private_library else ldb_headers),
294 public_headers_install=not private_library,
295 pc_files='ldb.pc',
296 vnum=VERSION,
297 private_library=private_library,
298 manpages='man/ldb.3',
299 abi_directory='ABI',
300 abi_match = abi_match)
302 # generate a include/ldb_version.h
303 def generate_ldb_version_h(t):
304 '''generate a vscript file for our public libraries'''
306 tgt = t.outputs[0].bldpath(t.env)
308 v = t.env.LDB_VERSION.split('.')
310 f = open(tgt, mode='w')
311 try:
312 f.write('#define LDB_VERSION "%s"\n' % t.env.LDB_VERSION)
313 f.write('#define LDB_VERSION_MAJOR %d\n' % int(v[0]))
314 f.write('#define LDB_VERSION_MINOR %d\n' % int(v[1]))
315 f.write('#define LDB_VERSION_RELEASE %d\n' % int(v[2]))
316 finally:
317 f.close()
318 return
319 t = bld.SAMBA_GENERATOR('ldb_version.h',
320 rule=generate_ldb_version_h,
321 dep_vars=['LDB_VERSION'],
322 target='include/ldb_version.h',
323 public_headers='include/ldb_version.h',
324 public_headers_install=not private_library)
325 t.env.LDB_VERSION = VERSION
328 bld.SAMBA_MODULE('ldb_paged_results',
329 'modules/paged_results.c',
330 init_function='ldb_paged_results_init',
331 module_init_name='ldb_init_module',
332 internal_module=False,
333 deps='ldb',
334 subsystem='ldb')
336 bld.SAMBA_MODULE('ldb_asq',
337 'modules/asq.c',
338 init_function='ldb_asq_init',
339 module_init_name='ldb_init_module',
340 internal_module=False,
341 deps='ldb',
342 subsystem='ldb')
344 bld.SAMBA_MODULE('ldb_server_sort',
345 'modules/sort.c',
346 init_function='ldb_server_sort_init',
347 internal_module=False,
348 module_init_name='ldb_init_module',
349 deps='ldb',
350 subsystem='ldb')
352 bld.SAMBA_MODULE('ldb_paged_searches',
353 'modules/paged_searches.c',
354 init_function='ldb_paged_searches_init',
355 internal_module=False,
356 module_init_name='ldb_init_module',
357 deps='ldb',
358 subsystem='ldb')
360 bld.SAMBA_MODULE('ldb_rdn_name',
361 'modules/rdn_name.c',
362 init_function='ldb_rdn_name_init',
363 internal_module=False,
364 module_init_name='ldb_init_module',
365 deps='ldb',
366 subsystem='ldb')
368 bld.SAMBA_MODULE('ldb_sample',
369 'tests/sample_module.c',
370 init_function='ldb_sample_init',
371 internal_module=False,
372 module_init_name='ldb_init_module',
373 deps='ldb',
374 subsystem='ldb')
376 bld.SAMBA_MODULE('ldb_skel',
377 'modules/skel.c',
378 init_function='ldb_skel_init',
379 internal_module=False,
380 module_init_name='ldb_init_module',
381 deps='ldb',
382 subsystem='ldb')
384 bld.SAMBA_MODULE('ldb_sqlite3',
385 'sqlite3/ldb_sqlite3.c',
386 init_function='ldb_sqlite3_init',
387 internal_module=False,
388 module_init_name='ldb_init_module',
389 enabled=False,
390 deps='ldb',
391 subsystem='ldb')
393 bld.SAMBA_MODULE('ldb_tdb',
394 bld.SUBDIR('ldb_tdb',
395 '''ldb_tdb_init.c'''),
396 init_function='ldb_tdb_init',
397 module_init_name='ldb_init_module',
398 internal_module=False,
399 deps='tdb ldb ldb_key_value',
400 subsystem='ldb')
402 bld.SAMBA_LIBRARY('ldb_key_value',
403 bld.SUBDIR('ldb_tdb',
404 '''ldb_tdb.c ldb_search.c ldb_index.c
405 ldb_cache.c ldb_tdb_wrap.c'''),
406 private_library=True,
407 deps='tdb ldb')
409 if bld.CONFIG_SET('HAVE_LMDB'):
410 bld.SAMBA_MODULE('ldb_mdb',
411 bld.SUBDIR('ldb_mdb',
412 '''ldb_mdb_init.c'''),
413 init_function='ldb_mdb_init',
414 module_init_name='ldb_init_module',
415 internal_module=False,
416 deps='ldb ldb_key_value ldb_mdb_int',
417 subsystem='ldb')
419 bld.SAMBA_LIBRARY('ldb_mdb_int',
420 bld.SUBDIR('ldb_mdb',
421 '''ldb_mdb.c '''),
422 private_library=True,
423 deps='ldb lmdb ldb_key_value')
424 lmdb_deps = ' ldb_mdb_int'
425 else:
426 lmdb_deps = ''
429 bld.SAMBA_MODULE('ldb_ldb',
430 bld.SUBDIR('ldb_ldb',
431 '''ldb_ldb.c'''),
432 init_function='ldb_ldb_init',
433 module_init_name='ldb_init_module',
434 internal_module=False,
435 deps='ldb ldb_key_value' + lmdb_deps,
436 subsystem='ldb')
438 # have a separate subsystem for common/ldb.c, so it can rebuild
439 # for install with a different -DLDB_MODULESDIR=
440 bld.SAMBA_SUBSYSTEM('LIBLDB_MAIN',
441 'common/ldb.c',
442 deps='tevent tdb',
443 includes='include',
444 cflags=['-DLDB_MODULESDIR=\"%s\"' % modules_dir])
446 LDB_TOOLS='ldbadd ldbsearch ldbdel ldbmodify ldbedit ldbrename'
447 for t in LDB_TOOLS.split():
448 bld.SAMBA_BINARY(t, 'tools/%s.c' % t, deps='ldb-cmdline ldb',
449 manpages='man/%s.1' % t)
451 # ldbtest doesn't get installed
452 bld.SAMBA_BINARY('ldbtest', 'tools/ldbtest.c', deps='ldb-cmdline ldb',
453 install=False)
455 if bld.CONFIG_SET('HAVE_LMDB'):
456 lmdb_deps = ' lmdb'
457 else:
458 lmdb_deps = ''
459 # ldbdump doesn't get installed
460 bld.SAMBA_BINARY('ldbdump',
461 'tools/ldbdump.c',
462 deps='ldb-cmdline ldb' + lmdb_deps,
463 install=False)
465 bld.SAMBA_LIBRARY('ldb-cmdline',
466 source='tools/ldbutil.c tools/cmdline.c',
467 deps='ldb dl popt',
468 private_library=True)
470 bld.SAMBA_BINARY('ldb_tdb_mod_op_test',
471 source='tests/ldb_mod_op_test.c',
472 cflags='-DTEST_BE=\"tdb\"',
473 deps='cmocka ldb',
474 install=False)
476 bld.SAMBA_BINARY('ldb_tdb_guid_mod_op_test',
477 source='tests/ldb_mod_op_test.c',
478 cflags='-DTEST_BE=\"tdb\" -DGUID_IDX=1',
479 deps='cmocka ldb',
480 install=False)
482 bld.SAMBA_BINARY('ldb_tdb_kv_ops_test',
483 source='tests/ldb_kv_ops_test.c',
484 cflags='-DTEST_BE=\"tdb\"',
485 deps='cmocka ldb',
486 install=False)
488 bld.SAMBA_BINARY('ldb_tdb_test',
489 source='tests/ldb_tdb_test.c',
490 deps='cmocka ldb',
491 install=False)
493 bld.SAMBA_BINARY('ldb_msg_test',
494 source='tests/ldb_msg.c',
495 deps='cmocka ldb',
496 install=False)
498 bld.SAMBA_BINARY('test_ldb_qsort',
499 source='tests/test_ldb_qsort.c',
500 deps='cmocka ldb',
501 install=False)
503 bld.SAMBA_BINARY('ldb_match_test',
504 source='tests/ldb_match_test.c',
505 deps='cmocka ldb',
506 install=False)
508 if bld.CONFIG_SET('HAVE_LMDB'):
509 bld.SAMBA_BINARY('ldb_mdb_mod_op_test',
510 source='tests/ldb_mod_op_test.c',
511 cflags='-DTEST_BE=\"mdb\" -DGUID_IDX=1 '
512 + '-DTEST_LMDB=1',
513 deps='cmocka ldb lmdb',
514 install=False)
516 bld.SAMBA_BINARY('ldb_lmdb_test',
517 source='tests/ldb_lmdb_test.c',
518 deps='cmocka ldb',
519 install=False)
521 bld.SAMBA_BINARY('ldb_lmdb_size_test',
522 source='tests/ldb_lmdb_size_test.c',
523 deps='cmocka ldb',
524 install=False)
526 bld.SAMBA_BINARY('ldb_mdb_kv_ops_test',
527 source='tests/ldb_kv_ops_test.c',
528 cflags='-DTEST_BE=\"mdb\"',
529 deps='cmocka ldb',
530 install=False)
532 def test(ctx):
533 '''run ldb testsuite'''
534 import Utils, samba_utils, shutil
535 env = samba_utils.LOAD_ENVIRONMENT()
536 ctx.env = env
538 if not env.HAVE_LMDB:
539 raise Utils.WafError('make test called, but ldb was built '
540 '--without-ldb-lmdb')
542 test_prefix = "%s/st" % (Utils.g_module.blddir)
543 shutil.rmtree(test_prefix, ignore_errors=True)
544 os.makedirs(test_prefix)
545 os.environ['TEST_DATA_PREFIX'] = test_prefix
546 os.environ['LDB_MODULES_PATH'] = Utils.g_module.blddir + "/modules/ldb"
547 samba_utils.ADD_LD_LIBRARY_PATH('bin/shared')
548 samba_utils.ADD_LD_LIBRARY_PATH('bin/shared/private')
550 cmd = 'tests/test-tdb.sh %s' % Utils.g_module.blddir
551 ret = samba_utils.RUN_COMMAND(cmd)
552 print("testsuite returned %d" % ret)
554 tmp_dir = os.path.join(test_prefix, 'tmp')
555 if not os.path.exists(tmp_dir):
556 os.mkdir(tmp_dir)
557 pyret = samba_utils.RUN_PYTHON_TESTS(
558 ['tests/python/api.py', 'tests/python/index.py'],
559 extra_env={'SELFTEST_PREFIX': test_prefix})
560 print("Python testsuite returned %d" % pyret)
562 cmocka_ret = 0
563 test_exes = ['test_ldb_qsort',
564 'ldb_msg_test',
565 'ldb_tdb_mod_op_test',
566 'ldb_tdb_guid_mod_op_test',
567 'ldb_msg_test',
568 'ldb_tdb_kv_ops_test',
569 'ldb_tdb_test',
570 'ldb_mdb_mod_op_test',
571 'ldb_lmdb_test',
572 # we don't want to run ldb_lmdb_size_test (which proves we can
573 # fit > 4G of data into the DB), it would fill up the disk on
574 # many of our test instances
575 'ldb_mdb_kv_ops_test',
576 'ldb_match_test']
578 for test_exe in test_exes:
579 cmd = os.path.join(Utils.g_module.blddir, test_exe)
580 cmocka_ret = cmocka_ret or samba_utils.RUN_COMMAND(cmd)
582 sys.exit(ret or pyret or cmocka_ret)
584 def dist():
585 '''makes a tarball for distribution'''
586 samba_dist.dist()
588 def reconfigure(ctx):
589 '''reconfigure if config scripts have changed'''
590 import samba_utils
591 samba_utils.reconfigure(ctx)