CVE-2019-3824 ldb: Release ldb 1.2.4
[Samba.git] / lib / ldb / wscript
blob438cb5a01310330be6ebfa15a998ee22649eec02
1 #!/usr/bin/env python
3 APPNAME = 'ldb'
4 VERSION = '1.2.4'
6 blddir = 'bin'
8 import sys, os
10 # find the buildtools directory
11 srcdir = '.'
12 while not os.path.exists(srcdir+'/buildtools') and len(srcdir.split('/')) < 5:
13 srcdir = srcdir + '/..'
14 sys.path.insert(0, srcdir + '/buildtools/wafsamba')
16 import wafsamba, samba_dist, Utils
18 samba_dist.DIST_DIRS('''lib/ldb:. lib/replace:lib/replace lib/talloc:lib/talloc
19 lib/tdb:lib/tdb lib/tdb:lib/tdb lib/tevent:lib/tevent
20 third_party/popt:third_party/popt
21 third_party/cmocka:third_party/cmocka
22 buildtools:buildtools third_party/waf:third_party/waf''')
25 def set_options(opt):
26 opt.BUILTIN_DEFAULT('replace')
27 opt.PRIVATE_EXTENSION_DEFAULT('ldb', noextension='ldb')
28 opt.RECURSE('lib/tdb')
29 opt.RECURSE('lib/tevent')
30 opt.RECURSE('lib/replace')
31 opt.tool_options('python') # options for disabling pyc or pyo compilation
33 def configure(conf):
34 conf.RECURSE('lib/tdb')
35 conf.RECURSE('lib/tevent')
37 if conf.CHECK_FOR_THIRD_PARTY():
38 conf.RECURSE('third_party/popt')
39 conf.RECURSE('third_party/cmocka')
40 else:
41 if not conf.CHECK_POPT():
42 raise Utils.WafError('popt development packages have not been found.\nIf third_party is installed, check that it is in the proper place.')
43 else:
44 conf.define('USING_SYSTEM_POPT', 1)
46 if not conf.CHECK_CMOCKA():
47 raise Utils.WafError('cmocka development package have not been found.\nIf third_party is installed, check that it is in the proper place.')
48 else:
49 conf.define('USING_SYSTEM_CMOCKA', 1)
51 conf.RECURSE('lib/replace')
52 conf.find_program('python', var='PYTHON')
53 conf.find_program('xsltproc', var='XSLTPROC')
54 conf.check_tool('python')
55 conf.check_python_version((2,4,2))
56 conf.SAMBA_CHECK_PYTHON_HEADERS(mandatory=not conf.env.disable_python)
58 # where does the default LIBDIR end up? in conf.env somewhere?
60 conf.CONFIG_PATH('LDB_MODULESDIR', conf.SUBST_ENV_VAR('MODULESDIR') + '/ldb')
62 conf.env.standalone_ldb = conf.IN_LAUNCH_DIR()
64 if not conf.env.standalone_ldb:
65 max_ldb_version = [int(x) for x in VERSION.split(".")]
66 max_ldb_version[2] = 999
67 max_ldb_version_dots = "%d.%d.%d" % tuple(max_ldb_version)
69 if conf.env.disable_python:
70 if conf.CHECK_BUNDLED_SYSTEM_PKG('ldb',
71 minversion=VERSION,
72 maxversion=max_ldb_version_dots,
73 onlyif='talloc tdb tevent',
74 implied_deps='replace talloc tdb tevent'):
75 conf.define('USING_SYSTEM_LDB', 1)
76 else:
77 using_system_pyldb_util = True
78 if not conf.CHECK_BUNDLED_SYSTEM_PKG('pyldb-util',
79 minversion=VERSION,
80 maxversion=max_ldb_version_dots,
81 onlyif='talloc tdb tevent',
82 implied_deps='replace talloc tdb tevent ldb'):
83 using_system_pyldb_util = False
85 # We need to get a pyldb-util for all the python versions
86 # we are building for
87 if conf.env['EXTRA_PYTHON']:
88 name = 'pyldb-util' + conf.all_envs['extrapython']['PYTHON_SO_ABI_FLAG']
89 if not conf.CHECK_BUNDLED_SYSTEM_PKG(name,
90 minversion=VERSION,
91 maxversion=max_ldb_version_dots,
92 onlyif='talloc tdb tevent',
93 implied_deps='replace talloc tdb tevent ldb'):
94 using_system_pyldb_util = False
96 if using_system_pyldb_util:
97 conf.define('USING_SYSTEM_PYLDB_UTIL', 1)
99 if conf.CHECK_BUNDLED_SYSTEM_PKG('ldb',
100 minversion=VERSION,
101 maxversion=max_ldb_version_dots,
102 onlyif='talloc tdb tevent pyldb-util',
103 implied_deps='replace talloc tdb tevent'):
104 conf.define('USING_SYSTEM_LDB', 1)
106 if conf.CONFIG_SET('USING_SYSTEM_LDB'):
107 v = VERSION.split('.')
108 conf.DEFINE('EXPECTED_SYSTEM_LDB_VERSION_MAJOR', int(v[0]))
109 conf.DEFINE('EXPECTED_SYSTEM_LDB_VERSION_MINOR', int(v[1]))
110 conf.DEFINE('EXPECTED_SYSTEM_LDB_VERSION_RELEASE', int(v[2]))
112 if conf.env.standalone_ldb:
113 conf.CHECK_XSLTPROC_MANPAGES()
115 # we need this for the ldap backend
116 if conf.CHECK_FUNCS_IN('ber_flush ldap_open ldap_initialize', 'lber ldap', headers='lber.h ldap.h'):
117 conf.env.ENABLE_LDAP_BACKEND = True
119 # we don't want any libraries or modules to rely on runtime
120 # resolution of symbols
121 if not sys.platform.startswith("openbsd"):
122 conf.ADD_LDFLAGS('-Wl,-no-undefined', testflags=True)
124 conf.DEFINE('HAVE_CONFIG_H', 1, add_to_cflags=True)
126 conf.SAMBA_CONFIG_H()
128 conf.SAMBA_CHECK_UNDEFINED_SYMBOL_FLAGS()
130 def build(bld):
131 bld.RECURSE('lib/tevent')
133 if bld.CHECK_FOR_THIRD_PARTY():
134 bld.RECURSE('third_party/popt')
135 bld.RECURSE('third_party/cmocka')
137 bld.RECURSE('lib/replace')
138 bld.RECURSE('lib/tdb')
140 if bld.env.standalone_ldb:
141 private_library = False
142 else:
143 private_library = True
145 LDB_MAP_SRC = bld.SUBDIR('ldb_map',
146 'ldb_map.c ldb_map_inbound.c ldb_map_outbound.c')
148 COMMON_SRC = bld.SUBDIR('common',
149 '''ldb_modules.c ldb_ldif.c ldb_parse.c ldb_msg.c ldb_utf8.c
150 ldb_debug.c ldb_dn.c ldb_match.c ldb_options.c ldb_pack.c
151 ldb_attributes.c attrib_handlers.c ldb_controls.c qsort.c''')
153 bld.SAMBA_MODULE('ldb_ldap', 'ldb_ldap/ldb_ldap.c',
154 init_function='ldb_ldap_init',
155 module_init_name='ldb_init_module',
156 deps='talloc lber ldap ldb',
157 enabled=bld.env.ENABLE_LDAP_BACKEND,
158 internal_module=False,
159 subsystem='ldb')
161 if bld.PYTHON_BUILD_IS_ENABLED():
162 if not bld.CONFIG_SET('USING_SYSTEM_PYLDB_UTIL'):
163 for env in bld.gen_python_environments(['PKGCONFIGDIR']):
164 # we're not currently linking against the ldap libs, but ldb.pc.in
165 # has @LDAP_LIBS@
166 bld.env.LDAP_LIBS = ''
168 if not 'PACKAGE_VERSION' in bld.env:
169 bld.env.PACKAGE_VERSION = VERSION
170 bld.env.PKGCONFIGDIR = '${LIBDIR}/pkgconfig'
172 name = bld.pyembed_libname('pyldb-util')
173 bld.SAMBA_LIBRARY(name,
174 deps='ldb',
175 source='pyldb_util.c',
176 public_headers=('' if private_library else 'pyldb.h'),
177 public_headers_install=not private_library,
178 vnum=VERSION,
179 private_library=private_library,
180 pc_files='pyldb-util.pc',
181 pyembed=True,
182 enabled=bld.PYTHON_BUILD_IS_ENABLED(),
183 abi_directory='ABI',
184 abi_match='pyldb_*')
186 if not bld.CONFIG_SET('USING_SYSTEM_LDB'):
187 bld.SAMBA_PYTHON('pyldb', 'pyldb.c',
188 deps='ldb ' + name,
189 realname='ldb.so',
190 cflags='-DPACKAGE_VERSION=\"%s\"' % VERSION)
192 # Do only install this file as part of the Samba build if we do not
193 # use the system libldb!
194 if not bld.CONFIG_SET('USING_SYSTEM_PYLDB_UTIL'):
195 for env in bld.gen_python_environments(['PKGCONFIGDIR']):
196 bld.SAMBA_SCRIPT('_ldb_text.py',
197 pattern='_ldb_text.py',
198 installdir='python')
200 bld.INSTALL_FILES('${PYTHONARCHDIR}', '_ldb_text.py')
202 if not bld.CONFIG_SET('USING_SYSTEM_LDB'):
203 if bld.is_install:
204 modules_dir = bld.EXPAND_VARIABLES('${LDB_MODULESDIR}')
205 else:
206 # when we run from the source directory, we want to use
207 # the current modules, not the installed ones
208 modules_dir = os.path.join(os.getcwd(), 'bin/modules/ldb')
210 abi_match = '!ldb_*module_ops !ldb_*backend_ops ldb_*'
212 ldb_headers = ('include/ldb.h include/ldb_errors.h '
213 'include/ldb_module.h include/ldb_handlers.h')
215 bld.SAMBA_LIBRARY('ldb',
216 COMMON_SRC + ' ' + LDB_MAP_SRC,
217 deps='tevent LIBLDB_MAIN replace',
218 includes='include',
219 public_headers=('' if private_library else ldb_headers),
220 public_headers_install=not private_library,
221 pc_files='ldb.pc',
222 vnum=VERSION,
223 private_library=private_library,
224 manpages='man/ldb.3',
225 abi_directory='ABI',
226 abi_match = abi_match)
228 # generate a include/ldb_version.h
229 def generate_ldb_version_h(t):
230 '''generate a vscript file for our public libraries'''
232 tgt = t.outputs[0].bldpath(t.env)
234 v = t.env.LDB_VERSION.split('.')
236 f = open(tgt, mode='w')
237 try:
238 f.write('#define LDB_VERSION "%s"\n' % t.env.LDB_VERSION)
239 f.write('#define LDB_VERSION_MAJOR %d\n' % int(v[0]))
240 f.write('#define LDB_VERSION_MINOR %d\n' % int(v[1]))
241 f.write('#define LDB_VERSION_RELEASE %d\n' % int(v[2]))
242 finally:
243 f.close()
244 return
245 t = bld.SAMBA_GENERATOR('ldb_version.h',
246 rule=generate_ldb_version_h,
247 dep_vars=['LDB_VERSION'],
248 target='include/ldb_version.h',
249 public_headers='include/ldb_version.h',
250 public_headers_install=not private_library)
251 t.env.LDB_VERSION = VERSION
254 bld.SAMBA_MODULE('ldb_paged_results',
255 'modules/paged_results.c',
256 init_function='ldb_paged_results_init',
257 module_init_name='ldb_init_module',
258 internal_module=False,
259 deps='ldb',
260 subsystem='ldb')
262 bld.SAMBA_MODULE('ldb_asq',
263 'modules/asq.c',
264 init_function='ldb_asq_init',
265 module_init_name='ldb_init_module',
266 internal_module=False,
267 deps='ldb',
268 subsystem='ldb')
270 bld.SAMBA_MODULE('ldb_server_sort',
271 'modules/sort.c',
272 init_function='ldb_server_sort_init',
273 internal_module=False,
274 module_init_name='ldb_init_module',
275 deps='ldb',
276 subsystem='ldb')
278 bld.SAMBA_MODULE('ldb_paged_searches',
279 'modules/paged_searches.c',
280 init_function='ldb_paged_searches_init',
281 internal_module=False,
282 module_init_name='ldb_init_module',
283 deps='ldb',
284 subsystem='ldb')
286 bld.SAMBA_MODULE('ldb_rdn_name',
287 'modules/rdn_name.c',
288 init_function='ldb_rdn_name_init',
289 internal_module=False,
290 module_init_name='ldb_init_module',
291 deps='ldb',
292 subsystem='ldb')
294 bld.SAMBA_MODULE('ldb_sample',
295 'tests/sample_module.c',
296 init_function='ldb_sample_init',
297 internal_module=False,
298 module_init_name='ldb_init_module',
299 deps='ldb',
300 subsystem='ldb')
302 bld.SAMBA_MODULE('ldb_skel',
303 'modules/skel.c',
304 init_function='ldb_skel_init',
305 internal_module=False,
306 module_init_name='ldb_init_module',
307 deps='ldb',
308 subsystem='ldb')
310 bld.SAMBA_MODULE('ldb_sqlite3',
311 'sqlite3/ldb_sqlite3.c',
312 init_function='ldb_sqlite3_init',
313 internal_module=False,
314 module_init_name='ldb_init_module',
315 enabled=False,
316 deps='ldb',
317 subsystem='ldb')
319 bld.SAMBA_MODULE('ldb_tdb',
320 bld.SUBDIR('ldb_tdb',
321 '''ldb_tdb.c ldb_search.c ldb_index.c
322 ldb_cache.c ldb_tdb_wrap.c'''),
323 init_function='ldb_tdb_init',
324 module_init_name='ldb_init_module',
325 internal_module=False,
326 deps='tdb ldb',
327 subsystem='ldb')
329 # have a separate subsystem for common/ldb.c, so it can rebuild
330 # for install with a different -DLDB_MODULESDIR=
331 bld.SAMBA_SUBSYSTEM('LIBLDB_MAIN',
332 'common/ldb.c',
333 deps='tevent tdb',
334 includes='include',
335 cflags=['-DLDB_MODULESDIR=\"%s\"' % modules_dir])
337 LDB_TOOLS='ldbadd ldbsearch ldbdel ldbmodify ldbedit ldbrename'
338 for t in LDB_TOOLS.split():
339 bld.SAMBA_BINARY(t, 'tools/%s.c' % t, deps='ldb-cmdline ldb',
340 manpages='man/%s.1' % t)
342 # ldbtest doesn't get installed
343 bld.SAMBA_BINARY('ldbtest', 'tools/ldbtest.c', deps='ldb-cmdline ldb',
344 install=False)
346 # ldbdump doesn't get installed
347 bld.SAMBA_BINARY('ldbdump', 'tools/ldbdump.c', deps='ldb-cmdline ldb',
348 install=False)
350 bld.SAMBA_LIBRARY('ldb-cmdline',
351 source='tools/ldbutil.c tools/cmdline.c',
352 deps='ldb dl popt',
353 private_library=True)
355 bld.SAMBA_BINARY('ldb_tdb_mod_op_test',
356 source='tests/ldb_mod_op_test.c',
357 cflags='-DTEST_BE=\"tdb\"',
358 deps='cmocka ldb',
359 install=False)
361 bld.SAMBA_BINARY('ldb_msg_test',
362 source='tests/ldb_msg.c',
363 deps='cmocka ldb',
364 install=False)
366 bld.SAMBA_BINARY('ldb_match_test',
367 source='tests/ldb_match_test.c',
368 deps='cmocka ldb',
369 install=False)
371 def test(ctx):
372 '''run ldb testsuite'''
373 import Utils, samba_utils, shutil
374 env = samba_utils.LOAD_ENVIRONMENT()
375 ctx.env = env
377 test_prefix = "%s/st" % (Utils.g_module.blddir)
378 shutil.rmtree(test_prefix, ignore_errors=True)
379 os.makedirs(test_prefix)
380 os.environ['TEST_DATA_PREFIX'] = test_prefix
381 os.environ['LDB_MODULES_PATH'] = Utils.g_module.blddir + "/modules/ldb"
382 samba_utils.ADD_LD_LIBRARY_PATH('bin/shared')
383 samba_utils.ADD_LD_LIBRARY_PATH('bin/shared/private')
385 cmd = 'tests/test-tdb.sh %s' % Utils.g_module.blddir
386 ret = samba_utils.RUN_COMMAND(cmd)
387 print("testsuite returned %d" % ret)
389 tmp_dir = os.path.join(test_prefix, 'tmp')
390 if not os.path.exists(tmp_dir):
391 os.mkdir(tmp_dir)
392 pyret = samba_utils.RUN_PYTHON_TESTS(
393 ['tests/python/api.py'],
394 extra_env={'SELFTEST_PREFIX': test_prefix})
395 print("Python testsuite returned %d" % pyret)
397 cmocka_ret = 0
398 for test_exe in ['ldb_tdb_mod_op_test',
399 'ldb_msg_test',
400 'ldb_match_test']:
401 cmd = os.path.join(Utils.g_module.blddir, test_exe)
402 cmocka_ret = cmocka_ret or samba_utils.RUN_COMMAND(cmd)
404 sys.exit(ret or pyret or cmocka_ret)
406 def dist():
407 '''makes a tarball for distribution'''
408 samba_dist.dist()
410 def reconfigure(ctx):
411 '''reconfigure if config scripts have changed'''
412 import samba_utils
413 samba_utils.reconfigure(ctx)