[SCM] Samba Shared Repository - branch v4-8-test updated

Karolin Seeger kseeger at samba.org
Tue Jun 26 11:32:03 UTC 2018


The branch, v4-8-test has been updated
       via  e25631d ldb: version 1.3.4
       via  fb522c1 .gitlab-ci.yml: Adapt to current GitLab CI setup
       via  7ccd1eb Fix several mem leaks in ldb_index ldb_search ldb_tdb
       via  2a3f91e check return value before using key_values
       via  7a1906d ldb: check return values
       via  9b5f368 ldb_tdb: Use mem_ctx and so avoid leak onto long-term memory on duplicated add.
       via  1fb7246 ldb: Fix memory leak on module context
       via  b4331a3 ldb: Add tests for when we should expect a full scan
       via  b8df3cd ldb: One-level search was incorrectly falling back to full DB scan
       via  703ca1a ldb: Explain why an entry can vanish from the index
       via  d1b59c2 ldb: Indicate that the ltdb_dn_list_sort() in list_union is a bit subtle.
       via  5c1d9b0 ldb: Save a copy of the index result before calling the callbacks.
      from  8b32d29 samdb: Fix build error with gcc8

https://git.samba.org/?p=samba.git;a=shortlog;h=v4-8-test


- Log -----------------------------------------------------------------
commit e25631d6be56374b69209afafda0fc4485bc8b54
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Tue Jun 26 15:01:27 2018 +1200

    ldb: version 1.3.4
    
    * Fix memory leaks and missing error checks (bug 13459, 13471, 13475)
    * Fix fallback to full scan (performance regression) on
      one-level search (bug 13448)
    * Fix read corruption (missing results) during writes, particularly
      during a Samba subtree rename (bug 13452)
    
    Autobuild-User(v4-8-test): Karolin Seeger <kseeger at samba.org>
    Autobuild-Date(v4-8-test): Tue Jun 26 13:31:53 CEST 2018 on sn-devel-144

commit fb522c1ba0afa1b2298e66dfde42806cae72e5b9
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Tue Jun 26 14:59:26 2018 +1200

    .gitlab-ci.yml: Adapt to current GitLab CI setup
    
    Signed-off-by: Andrew Bartlett <abartlet at samba.org>

commit 7ccd1eb5393f76642a96db0037d9f4b3bb10709a
Author: Andrej Gessel <Andrej.Gessel at janztec.com>
Date:   Thu Jun 14 12:19:29 2018 +0200

    Fix several mem leaks in ldb_index ldb_search ldb_tdb
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13475
    
    Signed-off-by: Andrej Gessel <Andrej.Gessel at janztec.com>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>
    
    Autobuild-User(master): Andrew Bartlett <abartlet at samba.org>
    Autobuild-Date(master): Fri Jun 15 23:07:25 CEST 2018 on sn-devel-144
    
    (cherry picked from commit 3ca1c09f686fbfa9257cd95710dba4a98c3eeb8f)

commit 2a3f91ea027eb1d24568b96036801d3f9e5a13f2
Author: Andrej Gessel <Andrej.Gessel at janztec.com>
Date:   Tue Jun 19 10:07:51 2018 +0200

    check return value before using key_values
    
    there are also mem leaks in this function
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13475
    
    Signed-off-by: Andrej Gessel <Andrej.Gessel at janztec.com>
    Reviewed-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    (cherry picked from commit f75e8f58cd2390c092631803d333adadb475306a)

commit 7a1906d92412f32a2e481b1ad4178bed0b87d0ca
Author: Andrej Gessel <Andrej.Gessel at janztec.com>
Date:   Fri Jun 15 11:02:15 2018 +0200

    ldb: check return values
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13475
    
    Signed-off-by: Andrej Gessel <Andrej.Gessel at janztec.com>
    Reviewed-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    (cherry picked from commit 6b52d21e6040699a72aff12fd6ebb34534dcb457)

commit 9b5f368a62b644825e6a04ab31d2cbbf72a196ae
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Wed Jun 13 11:20:00 2018 +0200

    ldb_tdb: Use mem_ctx and so avoid leak onto long-term memory on duplicated add.
    
    After a duplicated add a small amount of memory can be leaked onto a
    long-term context.
    
    Found by Andrej Gessel https://github.com/andiges
    
    https://github.com/samba-team/samba/commit/e8fb45125e6a279b918694668e0d4fbddac10aee#commitcomment-29334102
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13471
    Signed-off-by: Andrew Bartlett <abartlet at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    
    Autobuild-User(master): Jeremy Allison <jra at samba.org>
    Autobuild-Date(master): Fri Jun 15 04:39:41 CEST 2018 on sn-devel-144
    
    (cherry picked from commit f4f3abfa0e18bb4968b37b1cac40cd8c185c8d7b)

commit 1fb72464150bb64effa79a2c07b83f7167e1b75b
Author: Lukas Slebodnik <lslebodn at fedoraproject.org>
Date:   Sat Oct 21 15:09:01 2017 +0200

    ldb: Fix memory leak on module context
    
    Introduced in e8cdacc509016d9273d63faf334d9f827585c3eb
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13459
    
    Signed-off-by: Lukas Slebodnik <lslebodn at fedoraproject.org>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>
    Reviewed-by: Garming Sam <garming at catalyst.net.nz>
    
    Autobuild-User(master): Andrew Bartlett <abartlet at samba.org>
    Autobuild-Date(master): Fri Jun  1 11:10:24 CEST 2018 on sn-devel-144
    
    (cherry picked from commit d161aa3522576545d269208426bb0014ee2ab35f)

commit b4331a3a9e1ceb1765a4b6a4ddeae4971b8a41f1
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Wed May 23 17:15:38 2018 +1200

    ldb: Add tests for when we should expect a full scan
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13448
    
    Signed-off-by: Andrew Bartlett <abartlet at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Garming Sam <garming at catalyst.net.nz>
    (cherry picked from commit e99c199d811e607e7867e7b40d82a1642226c647)

commit b8df3cd999c2dd56f77d90fcdc264decc233834e
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Tue May 29 10:04:29 2018 +1200

    ldb: One-level search was incorrectly falling back to full DB scan
    
    When no search filter is specified, the code falls back to using
    '(|(objectClass=*)(distinguishedName=*)'. ltdb_index_dn() then failed
    because matching against '*' is not indexed. The error return then
    caused the code to fallback to a full-scan of the DB, which could have a
    considerable performance hit.
    
    Instead, we want to continue on and do the ltdb_index_filter() over the
    indexed results that were returned.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13448
    
    Signed-off-by: Tim Beale <timbeale at catalyst.net.nz>
    Signed-off-by: Andrew Bartlett <abartlet at samba.org>
    Reviewed-by: Garming Sam <garming at catalyst.net.nz>
    (cherry picked from commit 88ae60ed186c9c479722ad62d65a07d0c2e71469)

commit 703ca1a427a468f763538f1371c388d25745b2dd
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Mon May 28 14:12:52 2018 +1200

    ldb: Explain why an entry can vanish from the index
    
    Signed-off-by: Andrew Bartlett <abartlet at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Garming Sam <garming at catalyst.net.nz>
    (cherry picked from commit 9e143ee9b9f7be53c193cee3153f64c4dedc07e9)

commit d1b59c266b2076a286ff971769b9380c834c29ee
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Mon May 28 13:02:16 2018 +1200

    ldb: Indicate that the ltdb_dn_list_sort() in list_union is a bit subtle.
    
    Signed-off-by: Andrew Bartlett <abartlet at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Garming Sam <garming at catalyst.net.nz>
    (cherry picked from commit 3632775d7ad31e06437ed76b8731d9895930caa1)

commit 5c1d9b0b9acd5f4a1d2030f23829183cbbeb072d
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Mon May 28 13:01:18 2018 +1200

    ldb: Save a copy of the index result before calling the callbacks.
    
    Otherwise Samba modules like subtree_rename can fail as they modify the
    index during the callback.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13452
    
    Signed-off-by: Andrew Bartlett <abartlet at samba.org>
    Reviewed-by: Garming Sam <garming at catalyst.net.nz>
    (cherry picked from commit d02cd236dcbd8a44ecc85d1f7e95a48c95c0a479)

-----------------------------------------------------------------------

Summary of changes:
 .gitlab-ci.yml => .gitlab-ci-private.yml           |  14 +-
 lib/ldb/ABI/{ldb-1.3.3.sigs => ldb-1.3.4.sigs}     |   0
 ...b-util.py3-1.3.3.sigs => pyldb-util-1.3.4.sigs} |   0
 ...il.py3-1.3.3.sigs => pyldb-util.py3-1.3.4.sigs} |   0
 lib/ldb/ldb_tdb/ldb_index.c                        | 134 +++++++---
 lib/ldb/ldb_tdb/ldb_search.c                       |  23 +-
 lib/ldb/ldb_tdb/ldb_tdb.c                          |  20 +-
 lib/ldb/ldb_tdb/ldb_tdb.h                          |   6 +
 lib/ldb/tests/ldb_mod_op_test.c                    | 275 +++++++++++++++++++++
 lib/ldb/tests/python/api.py                        | 104 +++++++-
 lib/ldb/wscript                                    |   2 +-
 11 files changed, 534 insertions(+), 44 deletions(-)
 rename .gitlab-ci.yml => .gitlab-ci-private.yml (92%)
 copy lib/ldb/ABI/{ldb-1.3.3.sigs => ldb-1.3.4.sigs} (100%)
 copy lib/ldb/ABI/{pyldb-util.py3-1.3.3.sigs => pyldb-util-1.3.4.sigs} (100%)
 copy lib/ldb/ABI/{pyldb-util.py3-1.3.3.sigs => pyldb-util.py3-1.3.4.sigs} (100%)


Changeset truncated at 500 lines:

diff --git a/.gitlab-ci.yml b/.gitlab-ci-private.yml
similarity index 92%
rename from .gitlab-ci.yml
rename to .gitlab-ci-private.yml
index 2ae9eb4..584b853 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci-private.yml
@@ -1,12 +1,15 @@
 # see https://docs.gitlab.com/ce/ci/yaml/README.html for all available options
 
+image: registry.gitlab.com/samba-team/samba:latest
+
 before_script:
   - echo "Build starting ..."
 
 build_samba:
   stage: build
   tags:
-    - autobuild
+    - docker
+    - private
   script:
     # this one takes about 4 hours to finish
     - python script/autobuild.py samba            --verbose --tail --testbase /tmp/samba-testbase
@@ -14,7 +17,8 @@ build_samba:
 build_samba_others:
   stage: build
   tags:
-    - autobuild
+    - docker
+    - private
   script:
     - python script/autobuild.py samba-nopython   --verbose --tail --testbase /tmp/samba-testbase
     - python script/autobuild.py samba-systemkrb5 --verbose --tail --testbase /tmp/samba-testbase
@@ -26,7 +30,8 @@ build_samba_others:
 build_ctdb:
   stage: build
   tags:
-    - autobuild
+    - docker
+    - private
   script:
     - python script/autobuild.py samba-ctdb       --verbose --tail --testbase /tmp/samba-testbase
     - python script/autobuild.py ctdb             --verbose --tail --testbase /tmp/samba-testbase
@@ -34,7 +39,8 @@ build_ctdb:
 build_others:
   stage: build
   tags:
-    - autobuild
+    - docker
+    - private
   script:
     - python script/autobuild.py ldb              --verbose --tail --testbase /tmp/samba-testbase
     - python script/autobuild.py pidl             --verbose --tail --testbase /tmp/samba-testbase
diff --git a/lib/ldb/ABI/ldb-1.3.3.sigs b/lib/ldb/ABI/ldb-1.3.4.sigs
similarity index 100%
copy from lib/ldb/ABI/ldb-1.3.3.sigs
copy to lib/ldb/ABI/ldb-1.3.4.sigs
diff --git a/lib/ldb/ABI/pyldb-util.py3-1.3.3.sigs b/lib/ldb/ABI/pyldb-util-1.3.4.sigs
similarity index 100%
copy from lib/ldb/ABI/pyldb-util.py3-1.3.3.sigs
copy to lib/ldb/ABI/pyldb-util-1.3.4.sigs
diff --git a/lib/ldb/ABI/pyldb-util.py3-1.3.3.sigs b/lib/ldb/ABI/pyldb-util.py3-1.3.4.sigs
similarity index 100%
copy from lib/ldb/ABI/pyldb-util.py3-1.3.3.sigs
copy to lib/ldb/ABI/pyldb-util.py3-1.3.4.sigs
diff --git a/lib/ldb/ldb_tdb/ldb_index.c b/lib/ldb/ldb_tdb/ldb_index.c
index ee20273..40baeea 100644
--- a/lib/ldb/ldb_tdb/ldb_index.c
+++ b/lib/ldb/ldb_tdb/ldb_index.c
@@ -403,6 +403,7 @@ normal_index:
 				      "expected %d for %s",
 				      version, LTDB_INDEXING_VERSION,
 				      ldb_dn_get_linearized(dn));
+			talloc_free(msg);
 			return LDB_ERR_OPERATIONS_ERROR;
 		}
 
@@ -420,19 +421,26 @@ normal_index:
 				      "expected %d for %s",
 				      version, LTDB_GUID_INDEXING_VERSION,
 				      ldb_dn_get_linearized(dn));
+			talloc_free(msg);
 			return LDB_ERR_OPERATIONS_ERROR;
 		}
 
 		if (el->num_values != 1) {
+			talloc_free(msg);
 			return LDB_ERR_OPERATIONS_ERROR;
 		}
 
 		if ((el->values[0].length % LTDB_GUID_SIZE) != 0) {
+			talloc_free(msg);
 			return LDB_ERR_OPERATIONS_ERROR;
 		}
 
 		list->count = el->values[0].length / LTDB_GUID_SIZE;
 		list->dn = talloc_array(list, struct ldb_val, list->count);
+		if (list->dn == NULL) {
+			talloc_free(msg);
+			return LDB_ERR_OPERATIONS_ERROR;
+		}
 
 		/*
 		 * The actual data is on msg, due to
@@ -523,9 +531,9 @@ static int ltdb_dn_list_store_full(struct ldb_module *module,
 	if (list->count == 0) {
 		ret = ltdb_delete_noindex(module, msg);
 		if (ret == LDB_ERR_NO_SUCH_OBJECT) {
-			talloc_free(msg);
-			return LDB_SUCCESS;
+			ret = LDB_SUCCESS;
 		}
+		talloc_free(msg);
 		return ret;
 	}
 
@@ -621,6 +629,9 @@ static int ltdb_dn_list_store(struct ldb_module *module, struct ldb_dn *dn,
 	}
 
 	key.dptr = discard_const_p(unsigned char, ldb_dn_get_linearized(dn));
+	if (key.dptr == NULL) {
+		return LDB_ERR_OPERATIONS_ERROR;
+	}
 	key.dsize = strlen((char *)key.dptr);
 
 	rec = tdb_fetch(ltdb->idxptr->itdb, key);
@@ -1120,6 +1131,9 @@ static bool list_union(struct ldb_context *ldb,
 	/*
 	 * Sort the lists (if not in GUID DN mode) so we can do
 	 * the de-duplication during the merge
+	 *
+	 * NOTE: This can sort the in-memory index values, as list or
+	 * list2 might not be a copy!
 	 */
 	ltdb_dn_list_sort(ltdb, list);
 	ltdb_dn_list_sort(ltdb, list2);
@@ -1522,27 +1536,64 @@ static int ltdb_index_filter(struct ltdb_private *ltdb,
 			     struct ltdb_context *ac,
 			     uint32_t *match_count)
 {
-	struct ldb_context *ldb;
+	struct ldb_context *ldb = ldb_module_get_ctx(ac->module);
 	struct ldb_message *msg;
 	struct ldb_message *filtered_msg;
 	unsigned int i;
+	unsigned int num_keys = 0;
 	uint8_t previous_guid_key[LTDB_GUID_KEY_SIZE] = {};
+	TDB_DATA *keys = NULL;
+
+	/*
+	 * We have to allocate the key list (rather than just walk the
+	 * caller supplied list) as the callback could change the list
+	 * (by modifying an indexed attribute hosted in the in-memory
+	 * index cache!)
+	 */
+	keys = talloc_array(ac, TDB_DATA, dn_list->count);
+	if (keys == NULL) {
+		return ldb_module_oom(ac->module);
+	}
+
+	if (ltdb->cache->GUID_index_attribute != NULL) {
+		/*
+		 * We speculate that the keys will be GUID based and so
+		 * pre-fill in enough space for a GUID (avoiding a pile of
+		 * small allocations)
+		 */
+		struct guid_tdb_key {
+			uint8_t guid_key[LTDB_GUID_KEY_SIZE];
+		} *key_values = NULL;
+
+		key_values = talloc_array(keys,
+					  struct guid_tdb_key,
+					  dn_list->count);
 
-	ldb = ldb_module_get_ctx(ac->module);
+		if (key_values == NULL) {
+			talloc_free(keys);
+			return ldb_module_oom(ac->module);
+		}
+		for (i = 0; i < dn_list->count; i++) {
+			keys[i].dptr = key_values[i].guid_key;
+			keys[i].dsize = sizeof(key_values[i].guid_key);
+		}
+	} else {
+		for (i = 0; i < dn_list->count; i++) {
+			keys[i].dptr = NULL;
+			keys[i].dsize = 0;
+		}
+	}
 
 	for (i = 0; i < dn_list->count; i++) {
-		uint8_t guid_key[LTDB_GUID_KEY_SIZE];
-		TDB_DATA tdb_key = {
-			.dptr = guid_key,
-			.dsize = sizeof(guid_key)
-		};
 		int ret;
-		bool matched;
 
-		ret = ltdb_idx_to_key(ac->module, ltdb,
-				      ac, &dn_list->dn[i],
-				      &tdb_key);
+		ret = ltdb_idx_to_key(ac->module,
+				      ltdb,
+				      keys,
+				      &dn_list->dn[i],
+				      &keys[num_keys]);
 		if (ret != LDB_SUCCESS) {
+			talloc_free(keys);
 			return ret;
 		}
 
@@ -1558,36 +1609,50 @@ static int ltdb_index_filter(struct ltdb_private *ltdb,
 			 * LDB_FLAG_INTERNAL_DISABLE_SINGLE_VALUE_CHECK
 			 */
 
-			if (memcmp(previous_guid_key, tdb_key.dptr,
+			if (memcmp(previous_guid_key,
+				   keys[num_keys].dptr,
 				   sizeof(previous_guid_key)) == 0) {
 				continue;
 			}
 
-			memcpy(previous_guid_key, tdb_key.dptr,
+			memcpy(previous_guid_key,
+			       keys[num_keys].dptr,
 			       sizeof(previous_guid_key));
 		}
+		num_keys++;
+	}
 
+
+	/*
+	 * Now that the list is a safe copy, send the callbacks
+	 */
+	for (i = 0; i < num_keys; i++) {
+		int ret;
+		bool matched;
 		msg = ldb_msg_new(ac);
 		if (!msg) {
+			talloc_free(keys);
 			return LDB_ERR_OPERATIONS_ERROR;
 		}
 
-
 		ret = ltdb_search_key(ac->module, ltdb,
-				      tdb_key, msg,
+				      keys[i], msg,
 				      LDB_UNPACK_DATA_FLAG_NO_DATA_ALLOC|
 				      LDB_UNPACK_DATA_FLAG_NO_VALUES_ALLOC);
-		if (tdb_key.dptr != guid_key) {
-			TALLOC_FREE(tdb_key.dptr);
-		}
 		if (ret == LDB_ERR_NO_SUCH_OBJECT) {
-			/* the record has disappeared? yes, this can happen */
+			/*
+			 * the record has disappeared? yes, this can
+			 * happen if the entry is deleted by something
+			 * operating in the callback (not another
+			 * process, as we have a read lock)
+			 */
 			talloc_free(msg);
 			continue;
 		}
 
 		if (ret != LDB_SUCCESS && ret != LDB_ERR_NO_SUCH_OBJECT) {
 			/* an internal error */
+			talloc_free(keys);
 			talloc_free(msg);
 			return LDB_ERR_OPERATIONS_ERROR;
 		}
@@ -1605,6 +1670,7 @@ static int ltdb_index_filter(struct ltdb_private *ltdb,
 		}
 
 		if (ret != LDB_SUCCESS) {
+			talloc_free(keys);
 			talloc_free(msg);
 			return ret;
 		}
@@ -1619,6 +1685,7 @@ static int ltdb_index_filter(struct ltdb_private *ltdb,
 		talloc_free(msg);
 
 		if (ret == -1) {
+			talloc_free(keys);
 			return LDB_ERR_OPERATIONS_ERROR;
 		}
 
@@ -1628,12 +1695,14 @@ static int ltdb_index_filter(struct ltdb_private *ltdb,
 			 * is the callbacks responsiblity, and should
 			 * not be talloc_free()'ed */
 			ac->request_terminated = true;
+			talloc_free(keys);
 			return ret;
 		}
 
 		(*match_count)++;
 	}
 
+	TALLOC_FREE(keys);
 	return LDB_SUCCESS;
 }
 
@@ -1748,20 +1817,21 @@ int ltdb_search_indexed(struct ltdb_context *ac, uint32_t *match_count)
 			}
 			/*
 			 * Here we load the index for the tree.
+			 *
+			 * We only care if this is successful, if the
+			 * index can't trim the result list down then
+			 * the ONELEVEL index is still good enough.
 			 */
 			ret = ltdb_index_dn(ac->module, ltdb, ac->tree,
 					    idx_one_tree_list);
-			if (ret != LDB_SUCCESS) {
-				talloc_free(idx_one_tree_list);
-				talloc_free(dn_list);
-				return ret;
-			}
-
-			if (!list_intersect(ldb, ltdb,
-					    dn_list, idx_one_tree_list)) {
-				talloc_free(idx_one_tree_list);
-				talloc_free(dn_list);
-				return LDB_ERR_OPERATIONS_ERROR;
+			if (ret == LDB_SUCCESS) {
+				if (!list_intersect(ldb, ltdb,
+						    dn_list,
+						    idx_one_tree_list)) {
+					talloc_free(idx_one_tree_list);
+					talloc_free(dn_list);
+					return LDB_ERR_OPERATIONS_ERROR;
+				}
 			}
 		}
 		break;
diff --git a/lib/ldb/ldb_tdb/ldb_search.c b/lib/ldb/ldb_tdb/ldb_search.c
index 0af230f..0289086 100644
--- a/lib/ldb/ldb_tdb/ldb_search.c
+++ b/lib/ldb/ldb_tdb/ldb_search.c
@@ -102,8 +102,11 @@ static int msg_add_distinguished_name(struct ldb_message *msg)
 	el.values = &val;
 	el.flags = 0;
 	val.data = (uint8_t *)ldb_dn_alloc_linearized(msg, msg->dn);
+	if (val.data == NULL) {
+		return -1;
+	}
 	val.length = strlen((char *)val.data);
-	
+
 	ret = msg_add_element(msg, &el, 1);
 	return ret;
 }
@@ -405,7 +408,7 @@ int ltdb_filter_attrs(TALLOC_CTX *mem_ctx,
 	/* Shortcuts for the simple cases */
 	} else if (add_dn && i == 1) {
 		if (msg_add_distinguished_name(msg2) != 0) {
-			return -1;
+			goto failed;
 		}
 		*filtered_msg = msg2;
 		return 0;
@@ -471,7 +474,7 @@ int ltdb_filter_attrs(TALLOC_CTX *mem_ctx,
 
 	if (add_dn) {
 		if (msg_add_distinguished_name(msg2) != 0) {
-			return -1;
+			goto failed;
 		}
 	}
 
@@ -480,7 +483,7 @@ int ltdb_filter_attrs(TALLOC_CTX *mem_ctx,
 						struct ldb_message_element,
 						msg2->num_elements);
 		if (msg2->elements == NULL) {
-			return -1;
+			goto failed;
 		}
 	} else {
 		talloc_free(msg2->elements);
@@ -491,6 +494,7 @@ int ltdb_filter_attrs(TALLOC_CTX *mem_ctx,
 
 	return 0;
 failed:
+	TALLOC_FREE(msg2);
 	return -1;
 }
 
@@ -818,7 +822,7 @@ int ltdb_search(struct ltdb_context *ctx)
 		 * callback error */
 		if ( ! ctx->request_terminated && ret != LDB_SUCCESS) {
 			/* Not indexed, so we need to do a full scan */
-			if (ltdb->warn_unindexed) {
+			if (ltdb->warn_unindexed || ltdb->disable_full_db_scan) {
 				/* useful for debugging when slow performance
 				 * is caused by unindexed searches */
 				char *expression = ldb_filter_from_tree(ctx, ctx->tree);
@@ -831,6 +835,7 @@ int ltdb_search(struct ltdb_context *ctx)
 
 				talloc_free(expression);
 			}
+
 			if (match_count != 0) {
 				/* the indexing code gave an error
 				 * after having returned at least one
@@ -843,6 +848,14 @@ int ltdb_search(struct ltdb_context *ctx)
 				ltdb_unlock_read(module);
 				return LDB_ERR_OPERATIONS_ERROR;
 			}
+
+			if (ltdb->disable_full_db_scan) {
+				ldb_set_errstring(ldb,
+						  "ldb FULL SEARCH disabled");
+				ltdb_unlock_read(module);
+				return LDB_ERR_INAPPROPRIATE_MATCHING;
+			}
+
 			ret = ltdb_search_full(ctx);
 			if (ret != LDB_SUCCESS) {
 				ldb_set_errstring(ldb, "Indexed and full searches both failed!\n");
diff --git a/lib/ldb/ldb_tdb/ldb_tdb.c b/lib/ldb/ldb_tdb/ldb_tdb.c
index a530a45..7014276 100644
--- a/lib/ldb/ldb_tdb/ldb_tdb.c
+++ b/lib/ldb/ldb_tdb/ldb_tdb.c
@@ -434,6 +434,7 @@ int ltdb_store(struct ldb_module *module, const struct ldb_message *msg, int flg
 	}
 
 	if (ltdb->read_only) {
+		talloc_free(tdb_key_ctx);
 		return LDB_ERR_UNWILLING_TO_PERFORM;
 	}
 
@@ -575,7 +576,7 @@ static int ltdb_add_internal(struct ldb_module *module,
 			if (mem_ctx == NULL) {
 				return ldb_module_operr(module);
 			}
-			ret2 = ltdb_search_base(module, module,
+			ret2 = ltdb_search_base(module, mem_ctx,
 						msg->dn, &dn2);
 			TALLOC_FREE(mem_ctx);
 			if (ret2 == LDB_SUCCESS) {
@@ -657,6 +658,7 @@ int ltdb_delete_noindex(struct ldb_module *module,
 	}
 
 	if (ltdb->read_only) {
+		talloc_free(tdb_key_ctx);
 		return LDB_ERR_UNWILLING_TO_PERFORM;
 	}
 
@@ -1965,6 +1967,22 @@ static int ltdb_connect(struct ldb_context *ldb, const char *url,
 
 	ltdb->sequence_number = 0;
 
+	/*
+	 * Override full DB scans
+	 *
+	 * A full DB scan is expensive on a large database.  This
+	 * option is for testing to show that the full DB scan is not
+	 * triggered.
+	 */
+	{
+		const char *len_str =
+			ldb_options_find(ldb, options,
+					 "disable_full_db_scan_for_self_test");
+		if (len_str != NULL) {
+			ltdb->disable_full_db_scan = true;
+		}
+	}
+
 	module = ldb_module_new(ldb, ldb, "ldb_tdb backend", &ltdb_ops);
 	if (!module) {
 		ldb_oom(ldb);
diff --git a/lib/ldb/ldb_tdb/ldb_tdb.h b/lib/ldb/ldb_tdb/ldb_tdb.h
index 9591ee5..6788ab1 100644
--- a/lib/ldb/ldb_tdb/ldb_tdb.h
+++ b/lib/ldb/ldb_tdb/ldb_tdb.h
@@ -40,6 +40,12 @@ struct ltdb_private {
 	bool reindex_failed;
 
 	const struct ldb_schema_syntax *GUID_index_syntax;
+
+	/*
+	 * To allow testing that ensures the DB does not fall back
+	 * to a full scan
+	 */
+	bool disable_full_db_scan;
 };
 
 struct ltdb_context {
diff --git a/lib/ldb/tests/ldb_mod_op_test.c b/lib/ldb/tests/ldb_mod_op_test.c
index 0f8642d..c8b9c1a 100644
--- a/lib/ldb/tests/ldb_mod_op_test.c
+++ b/lib/ldb/tests/ldb_mod_op_test.c
@@ -2384,6 +2384,269 @@ static void test_ldb_modify_before_ldb_wait(void **state)
 	assert_int_equal(res2->count, 1);
 }
 
+/*
+ * This test is also complex.
+ * The purpose is to test if a modify can occur during an ldb_search()


-- 
Samba Shared Repository



More information about the samba-cvs mailing list