The branch, master has been updated
via 5ad1a93107a samba-tool: no traceback for unauthenticated rootdse
access
via d8b7712c53d ldb:dn_compare_base: avoid unlikely int overflow
via 4fa67dee9a8 ldb:dn_compare: be a bit more transitive
via 2a7e74898af ldb:kv_cache: s/ltdb/ldb_kv/ in comments and messages
via 781057b3caa ldb:kv: s/ltdb/ldb_kv/ in comments and messages
via 77ad9096d0c ldb:ldb_pack: filter avoids looping over msg when attrs
contain "*"
via df3f7be3262 ldb:dn_casefold_internal: TALLOC_FREE only what we
talloced
via 9754980b03f ldb:tests: add tests ensuring indexes don't change
search results
via 9aefaa9dc9f lib:ldb-samba: use 'ldb' debug class more widely
via 0031a82478c selftest:S4: use PY_DEV_PROVISION for python dev-mode
via 4f57365a1e9 selftest:S4: use RR_PROVISION for rr recording
via 9a332b4febf selftest:S4: do not add 'env python' multiple times'
from 4fcdb01808f libcli/util: let nt_errstr() fallback to
hresult_errstr()
https://git.samba.org/?p=samba.git;a=shortlog;h=master
- Log -----------------------------------------------------------------
commit 5ad1a93107a202d954663f3783c1660c9b6c8957
Author: Douglas Bagnall <[email protected]>
Date: Tue Jul 30 09:53:14 2024 +1200
samba-tool: no traceback for unauthenticated rootdse access
Under some circumstances rootdse returns an operations error with
"Operation unavailable without authentication" instead of insufficient
access rights.
Signed-off-by: Douglas Bagnall <[email protected]>
Reviewed-by: Andreas Schneider <[email protected]>
Autobuild-User(master): Douglas Bagnall <[email protected]>
Autobuild-Date(master): Fri Dec 20 00:00:02 UTC 2024 on atb-devel-224
commit d8b7712c53d52dbf3a16ca2ad8f9e3c994a0f72b
Author: Douglas Bagnall <[email protected]>
Date: Fri Aug 23 10:14:04 2024 +1200
ldb:dn_compare_base: avoid unlikely int overflow
Signed-off-by: Douglas Bagnall <[email protected]>
Reviewed-by: Andreas Schneider <[email protected]>
commit 4fa67dee9a83f0e48e698f990e045395aa734767
Author: Douglas Bagnall <[email protected]>
Date: Fri Aug 23 10:17:17 2024 +1200
ldb:dn_compare: be a bit more transitive
If neither dn can casefold, they should be considered equal. Otherwise
cmp(dn1, dn2) will be inconsistent with cmp(dn2, dn1).
These will still sort to the end of the list, relative to any valid
DNs.
Signed-off-by: Douglas Bagnall <[email protected]>
Reviewed-by: Andreas Schneider <[email protected]>
commit 2a7e74898af9b314dd1564a5e1110c577721f579
Author: Douglas Bagnall <[email protected]>
Date: Thu Aug 22 16:23:09 2024 +1200
ldb:kv_cache: s/ltdb/ldb_kv/ in comments and messages
Signed-off-by: Douglas Bagnall <[email protected]>
Reviewed-by: Andreas Schneider <[email protected]>
commit 781057b3caa7cde4d9dd53c4e20e1ae9bfcb2de7
Author: Douglas Bagnall <[email protected]>
Date: Thu Aug 22 16:22:28 2024 +1200
ldb:kv: s/ltdb/ldb_kv/ in comments and messages
with some subsequent tidy-ups for style.
Signed-off-by: Douglas Bagnall <[email protected]>
Reviewed-by: Andreas Schneider <[email protected]>
commit 77ad9096d0c7a7e5f8257e5fe4ea0bcb12636c43
Author: Douglas Bagnall <[email protected]>
Date: Fri Jul 26 15:47:03 2024 +1200
ldb:ldb_pack: filter avoids looping over msg when attrs contain "*"
Signed-off-by: Douglas Bagnall <[email protected]>
Reviewed-by: Andreas Schneider <[email protected]>
commit df3f7be32627acabc2a937a5b579740eaa63bd2a
Author: Douglas Bagnall <[email protected]>
Date: Thu Aug 22 11:03:13 2024 +1200
ldb:dn_casefold_internal: TALLOC_FREE only what we talloced
If the failure is not on the last component, we would have
TALLOC_FREE()ed some components that we hadn't set.
I think in all pathways we initialise the unset components to zero,
but we should be careful just in case.
Signed-off-by: Douglas Bagnall <[email protected]>
Reviewed-by: Andreas Schneider <[email protected]>
commit 9754980b03fcb740a4bfa7b098b991e53cd67157
Author: Douglas Bagnall <[email protected]>
Date: Sat Aug 17 13:34:01 2024 +1200
ldb:tests: add tests ensuring indexes don't change search results
The index code (lib/ldb_key_value/ldb_kv_index.c) recapitulates LDB
expression logic, and it seemed less than completely obvious that it
would never make a mistake and return a different result than an
unindexed search.
Here we run the same search on an unindexed database and on some that
have been indexed with a variety of options. We assert that the
results are identical over a number of searches.
By default, when run from the command line, that number is 495161,
which takes a couple of minutes. But if the SKIP_SLOW_TESTS
environment variable is set, the number is 33569, which takes 20
seconds or so. In selftest we set the variable and run the smaller
number.
The tests will print the cumulative search time for each database for
each testsuite, like this:
$ python3 lib/ldb/tests/python/index_transparency.py
..........................................................[...]
<class '__main__.SearchTest'>
25.78186821937561 <ldb connection tdb:///tmp/tmpf1x72x7l/tdb-indexed-dn.ldb>
17.73349642753601 <ldb connection
tdb:///tmp/tmpf1x72x7l/tdb-half-indexed.ldb>
15.14864206314087 <ldb connection
tdb:///tmp/tmpf1x72x7l/tdb-indexed-guid.ldb>
13.107165575027466 <ldb connection mdb:///tmp/tmpf1x72x7l/mdb-indexed.ldb>
Like all benchmarks it is interesting but misleading. One caveat here
is that you have (probably) compiled tdb in developer mode without
optimisation, while lmdb is probably a system package compiled with -O2,
though perhaps not tuned to your exact architecture.
Signed-off-by: Douglas Bagnall <[email protected]>
Reviewed-by: Andreas Schneider <[email protected]>
commit 9aefaa9dc9f37c3dadbe66af5ef9f43e205bb18f
Author: Douglas Bagnall <[email protected]>
Date: Thu Oct 17 12:12:46 2024 +1300
lib:ldb-samba: use 'ldb' debug class more widely
Signed-off-by: Douglas Bagnall <[email protected]>
Reviewed-by: Andreas Schneider <[email protected]>
commit 0031a82478c4976815e3a6dec77ff8d3d4f83387
Author: Douglas Bagnall <[email protected]>
Date: Wed Sep 18 13:52:17 2024 +1200
selftest:S4: use PY_DEV_PROVISION for python dev-mode
Maybe we could look also at other -X options and -v.
Signed-off-by: Douglas Bagnall <[email protected]>
Reviewed-by: Andreas Schneider <[email protected]>
commit 4f57365a1e92d5e0eb7943b408a51fef898dcb24
Author: Douglas Bagnall <[email protected]>
Date: Wed Sep 18 13:40:23 2024 +1200
selftest:S4: use RR_PROVISION for rr recording
Signed-off-by: Douglas Bagnall <[email protected]>
Reviewed-by: Andreas Schneider <[email protected]>
commit 9a332b4febfc55341da8f06460baba8ecbb021dd
Author: Douglas Bagnall <[email protected]>
Date: Wed Sep 18 13:38:52 2024 +1200
selftest:S4: do not add 'env python' multiple times'
While we have no sane reason to use
VALGRIND_PROVISION=1 GDB_PROVISION=1 make test...
we will soon gain PY_DEV_PROVISION, which could be useful in tandem
with valgrind, rr, or gdb, and this will allow that.
Signed-off-by: Douglas Bagnall <[email protected]>
Reviewed-by: Andreas Schneider <[email protected]>
-----------------------------------------------------------------------
Summary of changes:
lib/ldb-samba/ldb_matching_rules.c | 3 +
lib/ldb-samba/ldif_handlers.c | 3 +
lib/ldb/common/ldb_dn.c | 48 ++-
lib/ldb/common/ldb_pack.c | 22 +-
lib/ldb/ldb_key_value/ldb_kv.c | 17 +-
lib/ldb/ldb_key_value/ldb_kv_cache.c | 10 +-
lib/ldb/tests/python/index_transparency.py | 478 +++++++++++++++++++++++++++++
python/samba/netcmd/__init__.py | 3 +
selftest/target/Samba4.pm | 29 +-
selftest/tests.py | 6 +
10 files changed, 572 insertions(+), 47 deletions(-)
create mode 100644 lib/ldb/tests/python/index_transparency.py
Changeset truncated at 500 lines:
diff --git a/lib/ldb-samba/ldb_matching_rules.c
b/lib/ldb-samba/ldb_matching_rules.c
index 9520c805558..9a8dba3e18b 100644
--- a/lib/ldb-samba/ldb_matching_rules.c
+++ b/lib/ldb-samba/ldb_matching_rules.c
@@ -31,6 +31,9 @@
#undef strcasecmp
+#undef DBGC_CLASS
+#define DBGC_CLASS DBGC_LDB
+
static int ldb_eval_transitive_filter_helper(TALLOC_CTX *mem_ctx,
struct ldb_context *ldb,
const char *attr,
diff --git a/lib/ldb-samba/ldif_handlers.c b/lib/ldb-samba/ldif_handlers.c
index 35531222611..89bc68e7f4e 100644
--- a/lib/ldb-samba/ldif_handlers.c
+++ b/lib/ldb-samba/ldif_handlers.c
@@ -38,6 +38,9 @@
#include "../lib/util/asn1.h"
#include "lib/util/smb_strtox.h"
+#undef DBGC_CLASS
+#define DBGC_CLASS DBGC_LDB
+
/*
use ndr_print_* to convert a NDR formatted blob to a ldif formatted blob
diff --git a/lib/ldb/common/ldb_dn.c b/lib/ldb/common/ldb_dn.c
index 19350cc610c..0af0d94826a 100644
--- a/lib/ldb/common/ldb_dn.c
+++ b/lib/ldb/common/ldb_dn.c
@@ -926,7 +926,7 @@ char *ldb_dn_alloc_linearized(TALLOC_CTX *mem_ctx, struct
ldb_dn *dn)
static bool ldb_dn_casefold_internal(struct ldb_dn *dn)
{
- unsigned int i;
+ unsigned int i, j;
int ret;
if ( ! dn || dn->invalid) return false;
@@ -954,18 +954,24 @@ static bool ldb_dn_casefold_internal(struct ldb_dn *dn)
&(dn->components[i].value),
&(dn->components[i].cf_value));
if (ret != 0) {
- goto failed;
+ goto failed_1;
}
}
dn->valid_case = true;
return true;
-
-failed:
- for (i = 0; i < dn->comp_num; i++) {
- LDB_FREE(dn->components[i].cf_name);
- LDB_FREE(dn->components[i].cf_value.data);
+ failed_1:
+ /*
+ * Although we try to always initialise .cf_name and .cf.value.data to
+ * NULL, we want to avoid TALLOC_FREEing the values we have not just
+ * set here.
+ */
+ TALLOC_FREE(dn->components[i].cf_name);
+ failed:
+ for (j = 0; j < i; i++) {
+ TALLOC_FREE(dn->components[j].cf_name);
+ TALLOC_FREE(dn->components[j].cf_value.data);
}
return false;
}
@@ -1056,13 +1062,15 @@ int ldb_dn_compare_base(struct ldb_dn *base, struct
ldb_dn *dn)
if (base->linearized && dn->linearized && dn->special ==
base->special) {
/* try with a normal compare first, if we are lucky
* we will avoid exploding and casefolding */
- int dif;
- dif = strlen(dn->linearized) - strlen(base->linearized);
- if (dif < 0) {
- return dif;
+ size_t len_dn = strlen(dn->linearized);
+ size_t len_base = strlen(base->linearized);
+
+ if (len_dn < len_base) {
+ return -1;
}
+
if (strcmp(base->linearized,
- &dn->linearized[dif]) == 0) {
+ &dn->linearized[len_dn - len_base]) == 0) {
return 0;
}
}
@@ -1165,6 +1173,7 @@ int ldb_dn_compare(struct ldb_dn *dn0, struct ldb_dn *dn1)
}
if (( ! dn0->valid_case) || ( ! dn1->valid_case)) {
+ bool ok0, ok1;
if (dn0->linearized && dn1->linearized) {
/* try with a normal compare first, if we are lucky
* we will avoid exploding and casefolding */
@@ -1172,15 +1181,20 @@ int ldb_dn_compare(struct ldb_dn *dn0, struct ldb_dn
*dn1)
return 0;
}
}
-
- if ( ! ldb_dn_casefold_internal(dn0)) {
+ /*
+ * If a DN can't casefold, it goes to the end.
+ */
+ ok0 = ldb_dn_casefold_internal(dn0);
+ ok1 = ldb_dn_casefold_internal(dn1);
+ if (! ok0) {
+ if (! ok1) {
+ return 0;
+ }
return 1;
}
-
- if ( ! ldb_dn_casefold_internal(dn1)) {
+ if (! ok1) {
return -1;
}
-
}
/*
diff --git a/lib/ldb/common/ldb_pack.c b/lib/ldb/common/ldb_pack.c
index 4c2052372be..409be590611 100644
--- a/lib/ldb/common/ldb_pack.c
+++ b/lib/ldb/common/ldb_pack.c
@@ -1294,19 +1294,23 @@ int ldb_filter_attrs_in_place(struct ldb_message *msg,
keep_all = true;
}
+ if (keep_all) {
+ return LDB_SUCCESS;
+ }
+ /*
+ * Find the intersection between the msg elements and attrs.
+ *
+ * TODO, maybe: use a faster algorithm when (n * m) is too large.
+ */
for (i = 0; i < msg->num_elements; i++) {
bool found = false;
unsigned int j;
- if (keep_all) {
- found = true;
- } else {
- for (j = 0; attrs[j]; j++) {
- int cmp = ldb_attr_cmp(msg->elements[i].name,
attrs[j]);
- if (cmp == 0) {
- found = true;
- break;
- }
+ for (j = 0; attrs[j]; j++) {
+ int cmp = ldb_attr_cmp(msg->elements[i].name, attrs[j]);
+ if (cmp == 0) {
+ found = true;
+ break;
}
}
diff --git a/lib/ldb/ldb_key_value/ldb_kv.c b/lib/ldb/ldb_key_value/ldb_kv.c
index ef69e5e5b03..c1376ef691f 100644
--- a/lib/ldb/ldb_key_value/ldb_kv.c
+++ b/lib/ldb/ldb_key_value/ldb_kv.c
@@ -339,7 +339,8 @@ static int ldb_kv_modified(struct ldb_module *module,
struct ldb_dn *dn)
/* only allow modifies inside a transaction, otherwise the
* ldb is unsafe */
if (ldb_kv->kv_ops->transaction_active(ldb_kv) == false) {
- ldb_set_errstring(ldb_module_get_ctx(module), "ltdb modify
without transaction");
+ ldb_set_errstring(ldb_module_get_ctx(module),
+ "ldb_kv modify without transaction");
return LDB_ERR_OPERATIONS_ERROR;
}
@@ -1497,8 +1498,8 @@ static int ldb_kv_rename(struct ldb_kv_context *ctx)
* exists, so we can return this error to the caller with an
* unmodified DB
*
- * Even in GUID index mode we use ltdb_key_dn() as we are
- * trying to figure out if this is just a case rename
+ * Even in GUID index mode we use ldb_kv_key_dn() as we are
+ * trying to figure out if this is just a case rename.
*/
key = ldb_kv_key_dn(msg, req->op.rename.newdn);
if (!key.data) {
@@ -1634,7 +1635,7 @@ static int ldb_kv_prepare_commit(struct ldb_module
*module)
if (!ldb_kv->kv_ops->transaction_active(ldb_kv)) {
ldb_set_errstring(ldb_module_get_ctx(module),
- "ltdb_prepare_commit() called "
+ "ldb_kv_prepare_commit() called "
"without transaction active");
return LDB_ERR_OPERATIONS_ERROR;
}
@@ -2081,8 +2082,10 @@ static int ldb_kv_handle_request(struct ldb_module
*module,
ac->timeout_timeval = tv;
- /* set a spy so that we do not try to use the request context
- * if it is freed before ltdb_callback fires */
+ /*
+ * Set a spy so that we do not try to use the request context
+ * if it is freed before ldb_kv_callback fires.
+ */
ac->spy = talloc(req, struct ldb_kv_req_spy);
if (NULL == ac->spy) {
talloc_free(ac);
@@ -2167,7 +2170,7 @@ int ldb_kv_init_store(struct ldb_kv_private *ldb_kv,
talloc_steal(ldb_kv->module, ldb_kv);
if (ldb_kv_cache_load(ldb_kv->module) != 0) {
- ldb_asprintf_errstring(ldb, "Unable to load ltdb cache "
+ ldb_asprintf_errstring(ldb, "Unable to load ldb_kv cache "
"records for backend '%s'", name);
talloc_free(ldb_kv->module);
return LDB_ERR_OPERATIONS_ERROR;
diff --git a/lib/ldb/ldb_key_value/ldb_kv_cache.c
b/lib/ldb/ldb_key_value/ldb_kv_cache.c
index b1c136d751e..4ce57b37a29 100644
--- a/lib/ldb/ldb_key_value/ldb_kv_cache.c
+++ b/lib/ldb/ldb_key_value/ldb_kv_cache.c
@@ -328,7 +328,7 @@ static int ldb_kv_baseinfo_init(struct ldb_module *module)
struct ldb_val val;
int ret;
/* the initial sequence number must be different from the one
- set in ltdb_cache_free(). Thanks to Jon for pointing this
+ set in ldb_kv_cache_free(). Thanks to Jon for pointing this
out. */
const char *initial_sequence_number = "1";
@@ -476,8 +476,10 @@ int ldb_kv_cache_load(struct ldb_module *module)
ldb_kv->pack_format_version = LDB_PACKING_FORMAT;
ldb_kv->target_pack_format_version = LDB_PACKING_FORMAT;
- /* error handling for ltdb_baseinfo_init() is by
- looking for the record again. */
+ /*
+ * error handling for ldb_kv_baseinfo_init() is by
+ * looking for the record again.
+ */
ldb_kv_baseinfo_init(module);
} else if (r != LDB_SUCCESS) {
@@ -527,7 +529,7 @@ int ldb_kv_cache_load(struct ldb_module *module)
}
/*
- * ltdb_attributes_unload() calls internally talloc_free() on
+ * ldb_kv_attributes_unload() calls internally talloc_free() on
* any non-fixed elements in ldb->schema.attributes.
*
* NOTE WELL: This is per-ldb, not per module, so overwrites
diff --git a/lib/ldb/tests/python/index_transparency.py
b/lib/ldb/tests/python/index_transparency.py
new file mode 100644
index 00000000000..cf90f9946ba
--- /dev/null
+++ b/lib/ldb/tests/python/index_transparency.py
@@ -0,0 +1,478 @@
+#!/usr/bin/env python3
+#
+# Exhaustively test variations of search expressions on LDB database
+# with a variety of backends and index options, asserting that all
+# database variants give the same results.
+#
+# With the SKIP_SLOW_TESTS environment variable set (which is used by
+# `make test`) only unary and binary expressions will be run.
+# Otherwise ternary expressions are also run, which is a lot slower
+# (by unary, binary, ternary, I mean e.g. "(a=1)", "(&(a=1)(b=2))",
+# "(|(&(a=1)(b=2))(c=3))", respectively).
+#
+# These tests also emit some timing information, comparing the
+# performance of the various databases.
+
+import os
+import time
+from itertools import product
+import sys
+import unittest
+sys.path.insert(0, "bin/python")
+import ldb
+import shutil
+
+from api_base import (
+ TDB_PREFIX,
+ MDB_PREFIX,
+ tempdir,
+ LdbBaseTest,
+)
+
+HAVE_LMDB = (os.getenv('HAVE_LMDB') == '1')
+SKIP_SLOW_TESTS = True if os.getenv('SKIP_SLOW_TESTS') else False
+
+
+def DynamicTestCase(cls):
+ """If a class is decorated with @DynamicTestCase, its
+ setUpDynamicTestCases() method will be called *before* the
+ setUpClass() method. At this time it can add test methods to
+ the class (it is too late to do this in setUpClass).
+ """
+ cls.setUpDynamicTestCases()
+ return cls
+
+
+class SearchTestBase(LdbBaseTest):
+ prefix = TDB_PREFIX
+ unary_filters = ()
+ binary_filters = ()
+ ternary_filters = ()
+ non_existent_attrs = ''
+ non_existent_values = ''
+
+ @classmethod
+ def add_index(cls, db, portion=1, guid=True):
+ attrs = ["a", "b", "c", "ou"]
+ attrs = attrs[:int(len(attrs) * portion)]
+ index = {
+ "dn": "@INDEXLIST",
+ "@IDXONE": "1",
+ "@IDXATTR": attrs,
+ }
+
+ if guid:
+ index["@IDXGUID"] = "objectUUID"
+ index["@IDX_DN_GUID"] = "GUID"
+
+ db.add(index)
+
+ @classmethod
+ def add(cls, msg):
+ for db in cls.dbs:
+ db.add(msg)
+
+ @classmethod
+ def tearDownClass(cls):
+ super().tearDownClass()
+ print(f"\n{cls}")
+ for t, db in zip(cls.times, cls.dbs):
+ print(f"{t} {db}")
+ db.disconnect()
+ shutil.rmtree(cls.testdir)
+
+ @classmethod
+ def setUpDynamicTestCases(cls):
+ cls.testdir = tempdir()
+
+ options = ["modules:rdn_name"]
+
+ cls.times = []
+ cls.dbs = []
+ cls.filenames = []
+ for name, prefix, index_args in cls.databases:
+ flags = 0
+ if prefix == MDB_PREFIX:
+ if not HAVE_LMDB:
+ print("skipping MDB test: we have no LMDB")
+ continue
+ flags |= ldb.FLG_NOSYNC
+
+ filename = os.path.join(cls.testdir, f"{name}.ldb")
+ url = prefix + filename
+
+ db = ldb.Ldb(url, flags=flags, options=options)
+ if index_args is not None:
+ cls.add_index(db, *index_args)
+
+ cls.dbs.append(db)
+ cls.times.append(0.0)
+ cls.filenames.append(filename)
+
+ cls.add({"dn": "@ATTRIBUTES", "DC": "CASE_INSENSITIVE"})
+
+ cls.add({"dn": "DC=TOP",
+ "name": b"top",
+ "objectUUID": b" top of dn tower"})
+
+ # what follows will add a number of OUs with a mix of
+ # attributes. The 16 byte GUID of the OU (in the "objectUUID" field,
+ # not objectGUID, which has special handling) is a text string
+ # describing what attributes the OU should have.
+ #
+ # For example, ' 87 aZ bY cXYZ' says this is "ou87" with
+ # attribute 'a' having the values 'Z', attribute 'b' having
+ # the value 'Y' and 'c' having the values 'X', 'Y', and 'Z'.
+ #
+ # 'name' is always unique. Sometimes 'name' will equal 'ou',
+ # but sometimes it will be different ("ou number 87").
+ #
+ # We use a crappy LCG to spread the values around, with each
+ # attribute/value pair having around a 25% chance of occurring
+ # on any particular ou.
+ #
+ # The cls.attr_sets are effectively a python level index that
+ # should behave identically to the LDB index. That is,
+ #
+ # cls.attr_sets['bY'] & cls.attr_sets['cZ']
+ #
+ # should refer to the same OUs as a '(&(b=Y)(c=Z)' search.
+
+ ou = 0
+ cls.guids = []
+
+ # cls.attr_sets are not actually used in the tests, but are
+ # useful if you ever want to debug the tests.
+ cls.attr_sets = {f'{x}{y}': set() for x, y in product(cls.attrs,
+ cls.values)}
+
+ s = 0
+ for ou in range(cls.n_objects):
+ ou_attrs = {}
+ guid = f'{ou:3} '
+ for i in range(len(cls.attrs)):
+ s = (s * 321 + ou + 1) & 0xffff
+ k = cls.attrs[i]
+ b = s & (s // 9)
+ v = []
+ ou_attrs[k] = v
+ for j in range(len(cls.values)):
+ if b & (1 << j):
+ c = cls.values[j]
+ v.append(c)
+ cls.attr_sets[k + c].add(ou)
+ if v:
+ guid += f'{k}{"".join(v):3}'
+ else:
+ guid += ' '
+
+ if len(guid) != 16:
+ # with up to 1000 objects:
+ # 2 attrs -> 12 chars
+ # 3 attrs -> 16 chars
+ # 4 attrs -> 20 chars
+ #
+ # a truncated guid will always be unique because of
+ # the OU number at the start.
+ guid = (guid + '_' * 12)[:16]
+
+ name = (f"ou{ou}" if (ou % 3) else f"OU number {ou}").encode()
+ cls.guids.append(guid)
+
+ guid = guid.encode()
+ if len(guid) != 16:
+ raise ValueError(f"GUID should be 16 bytes, "
+ f"not {len(guid)} ('{guid}')")
+
+ msg = {"dn": f"OU=ou{ou},DC=TOP",
+ "name": name,
+ "objectUUID": guid
+ }
+ for k, v in ou_attrs.items():
+ if v:
+ msg[k] = v
+
+ cls.add(msg)
+
+ # This is how you could see how the attributes are distributed:
+ #
+ # from itertools import pairwise
+ # for a in cls.attr_sets:
+ # print(f"{a}: {len(cls.attr_sets[a])}:
{sorted(cls.attr_sets[a])}")
+ # for a, b in pairwise(cls.attr_sets):
+ # print(f"{a}&{b}: {sorted(cls.attr_sets[a] &cls.attr_sets[b])}")
+
+ # If we wanted to compare the database at the end to the
+ # database at the beginning (i.e. ensuring that search has no
+ # side-effects), we could do something like:
+ #
+ # shutil.copy(cls.filenames[0], cls.filenames[0] + '.initial')
+
+ # add a non-existent attribute or values into some searches
+ attrs = cls.attrs + cls.non_existent_attrs
+ values = cls.values + cls.non_existent_values
+ fn = "test_filter"
+
+ for scope_name, scope in cls.scopes:
+ for base in cls.bases:
+ if scope != ldb.SCOPE_SUBTREE and base is None:
+ continue
+ for f in cls.unary_filters:
+ for k, v in product(attrs, values):
+ filter = f.format(k1=k, v1=v)
+ name = f"{scope_name}-{base}-{filter}"
+ cls.generate_dynamic_test(fn, name, base, scope,
filter)
+
+ for f in cls.binary_filters:
+ for k1, v1, k2, v2 in product(attrs, values,
+ attrs, values):
+ filter = f.format(k1=k1, v1=v1, k2=k2, v2=v2)
+ name = f"{scope_name}-{base}-{filter}"
+ cls.generate_dynamic_test(fn, name, base, scope,
+ filter)
+
+ if SKIP_SLOW_TESTS:
+ # avoiding ternary tests saves a lot of time. in
+ # autobuild we run with --skip-slow-tests, which
+ # sets this variable.
+ continue
+
--
Samba Shared Repository