[SCM] Samba Shared Repository - branch master updated

Andrew Bartlett abartlet at samba.org
Thu May 3 09:09:02 UTC 2018


The branch, master has been updated
       via  8a0c7f3 ldb: Prepare to allow tests to operate on ldb_mdb (by using the GUID index)
       via  910b7be tests/dlz_bind9: support for multiple db types by using ldb://
       via  cfa1c0b tests: Replace some references to tdb with ldb://
       via  c25cec8 ldb-samba: Handle generic ldb:// url scheme in ldb_relative_path()
       via  1bff2ae ldb: Introduce new generic ldb:// prefix to allow backend autodetection
       via  6c8748c dsdb:schema_load: make use of ldb_relative_path() in partition_metadata_open()
       via  7e67df4 dsdb:partition_metadata: make use of ldb_relative_path() in partition_metadata_open()
       via  c8b45a3 ldb tests: add cmocka tests of kv operation interactions with transactions
       via  9ca34b9 ldb tests: api ensure database correctly populated
       via  25e1cfa ldb_tdb: Disallow reads without a transaction or read lock
       via  f04bbd3 ldb_tdb: Disallow TDB nested transactions and use tdb_transaction_active()
       via  501b35f ldb_tdb: Do not make search or DB modifications without a lock
       via  39e5faa ldb: make key/value backends expose if there is an active transaction
       via  705cf71 ldb_tdb: Make sure max_key_length != 0 requires a GUID index mode
       via  e48bd33 ldb/tests: don't use TEVENT_DEPRECATED in ldb_kv_ops_test.c
       via  6784283 gitlab-ci: Run samba-ad-dc-2 in the shared environment
       via  d0d32fc gitlab-ci: Use YAML templates to reduce duplication
       via  c976434 gitlab-ci: split up gitlab-ci file
       via  4365741 autobuild: Extend build combinations tested to include --without-ldap
       via  6124499 selftest: Allow make test to run with --address-sanitizer
       via  7e091e5 s4-lsa: Fix use-after-free in LSA server
      from  2096d13 Fix some incorrect debug messages that look to be copy-paste issues.

https://git.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 8a0c7f39d67d8767d9f203dd5a1dd50b49f00a95
Author: Gary Lockyer <gary at catalyst.net.nz>
Date:   Tue Mar 6 15:30:10 2018 +1300

    ldb: Prepare to allow tests to operate on ldb_mdb (by using the GUID index)
    
    The LMDB backend requires the GUID index mode, so prepare for it
    by setting a unique objectGUID on each record.  Also prepare for the
    index list to be optionally set as an attribute on the test object,
    allowing the GUID index mode to be set later when LMDB is configured.
    
    Signed-off-by: Gary Lockyer <gary at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>
    
    Autobuild-User(master): Andrew Bartlett <abartlet at samba.org>
    Autobuild-Date(master): Thu May  3 11:08:12 CEST 2018 on sn-devel-144

commit 910b7beeb47c08a844c207b396c3fd7db9662a8e
Author: Gary Lockyer <gary at catalyst.net.nz>
Date:   Thu Jan 11 12:40:01 2018 +1300

    tests/dlz_bind9: support for multiple db types by using ldb://
    
    Signed-off-by: Gary Lockyer <gary at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit cfa1c0bcb6d1d2b83939aed8208dc03b626dc8a3
Author: Garming Sam <garming at catalyst.net.nz>
Date:   Fri Jan 5 09:28:54 2018 +1300

    tests: Replace some references to tdb with ldb://
    
    Signed-off-by: Garming Sam <garming at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Gary Lockyer <gary at catalyst.net.nz>

commit c25cec834c13bd1ebdfe7be29ac90e1f17683c4e
Author: Gary Lockyer <gary at catalyst.net.nz>
Date:   Tue Mar 6 13:40:21 2018 +1300

    ldb-samba: Handle generic ldb:// url scheme in ldb_relative_path()
    
    Signed-off-by: Gary Lockyer <gary at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit 1bff2ae12880ea5a22ce53f7e2732af740c04ac3
Author: Gary Lockyer <gary at catalyst.net.nz>
Date:   Tue Mar 6 15:11:23 2018 +1300

    ldb: Introduce new generic ldb:// prefix to allow backend autodetection
    
    Signed-off-by: Gary Lockyer <gary at catalyst.net.nz>
    Signed-off-by: Garming Sam <garming at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit 6c8748c1605bc313f9f0c71f0667fec2bf5ac03d
Author: Gary Lockyer <gary at catalyst.net.nz>
Date:   Tue Mar 6 13:40:21 2018 +1300

    dsdb:schema_load: make use of ldb_relative_path() in partition_metadata_open()
    
    Signed-off-by: Gary Lockyer <gary at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit 7e67df48bc30cf21bd29baeee26e4b8dd792e95d
Author: Gary Lockyer <gary at catalyst.net.nz>
Date:   Tue Mar 6 13:40:21 2018 +1300

    dsdb:partition_metadata: make use of ldb_relative_path() in partition_metadata_open()
    
    Signed-off-by: Gary Lockyer <gary at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit c8b45a3509197d929191fda60324f51b8496b724
Author: Gary Lockyer <gary at catalyst.net.nz>
Date:   Tue Mar 20 12:15:12 2018 +1300

    ldb tests: add cmocka tests of kv operation interactions with transactions
    
    Signed-off-by: Gary Lockyer <gary at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit 9ca34b9c4aca9fa39759181f262ff693a9c6eb5c
Author: Gary Lockyer <gary at catalyst.net.nz>
Date:   Tue Mar 20 12:14:10 2018 +1300

    ldb tests: api ensure database correctly populated
    
    Signed-off-by: Gary Lockyer <gary at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit 25e1cfad3afd936227d8240666c61b2b339a74ba
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Wed Apr 4 17:21:30 2018 +1200

    ldb_tdb: Disallow reads without a transaction or read lock
    
    This will ensure we match LMDB behaviour and avoid a repeat of the per-record locking
    issues (compared with full DB locking) we had before Samba 4.7.
    
    Signed-off-by: Andrew Bartlett <abartlet at samba.org>
    Reviewed-by: Gary Lockyer <gary at catalyst.net.nz>

commit f04bbd3ec39b9d08df7b6b6596823461aa37fedf
Author: Gary Lockyer <gary at catalyst.net.nz>
Date:   Fri Mar 23 11:28:18 2018 +1300

    ldb_tdb: Disallow TDB nested transactions and use tdb_transaction_active()
    
    This avoids keeping a counter, which can be error-prone.
    
    Signed-off-by: Andrew Bartlett <abartlet at samba.org>
    Signed-off-by: Gary Lockyer <gary at catalyst.net.nz>

commit 501b35f86199216c78e38b4e0bc8e985e417f95d
Author: Gary Lockyer <gary at catalyst.net.nz>
Date:   Fri Mar 23 11:27:10 2018 +1300

    ldb_tdb: Do not make search or DB modifications without a lock
    
    The ldb_cache startup code would previously not take a read lock
    nor a sufficiently wide write transaction.
    
    The new code takes a read lock, and if it needs to write takes a
    write lock (transaction) and re-reads before continuing.
    
    Signed-off-by: Gary Lockyer <gary at catalyst.net.nz>
    Signed-off-by: Andrew Bartlett <abartlet at samba.org>

commit 39e5faa77c144b0c548d8afe749c1f08438b7e8f
Author: Gary Lockyer <gary at catalyst.net.nz>
Date:   Tue Mar 20 11:25:28 2018 +1300

    ldb: make key/value backends expose if there is an active transaction
    
    Signed-off-by: Gary Lockyer <gary at catalyst.net.nz>
    Signed-off-by: Andrew Bartlett <abartlet at samba.org>

commit 705cf715f9015e879bb7fe712fffe3a69b805aad
Author: Gary Lockyer <gary at catalyst.net.nz>
Date:   Tue Mar 6 15:27:51 2018 +1300

    ldb_tdb: Make sure max_key_length != 0 requires a GUID index mode
    
    We need to enforce the GUID index mode so end-users do not get a supprise
    in mid-operation and we enforce a max key length of 511 so that the
    index key trunctation is done correctly.
    
    Otherwise the DB will appear to work until a very long key (DN or index)
    is used, after which it will be sad.
    
    Signed-off-by: Gary Lockyer <gary at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit e48bd332dc05d05a0b1e64106a9266d1c5a591f6
Author: Stefan Metzmacher <metze at samba.org>
Date:   Thu Apr 12 14:31:20 2018 +0200

    ldb/tests: don't use TEVENT_DEPRECATED in ldb_kv_ops_test.c
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>
    Reviewed-by: Gary Lockyer <gary at catalyst.net.nz>

commit 6784283844dc231dad428d0c45088c1f7df404b3
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Mon Apr 30 20:38:43 2018 +1200

    gitlab-ci: Run samba-ad-dc-2 in the shared environment
    
    This will allow more AD DC tests to run for those without access
    to a private gitlab runner.
    
    Signed-off-by: Andrew Bartlett <abartlet at samba.org>
    Reviewed-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>

commit d0d32fc04f723dccb298dfb3824c6241e3135a57
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Mon Apr 30 20:31:19 2018 +1200

    gitlab-ci: Use YAML templates to reduce duplication
    
    Inspired by WIP patches by Jamie McClymont
    
    Signed-off-by: Andrew Bartlett <abartlet at samba.org>
    Reviewed-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>

commit c9764342c2f67983a037714110913dafe0dba59e
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Mon Apr 30 20:18:52 2018 +1200

    gitlab-ci: split up gitlab-ci file
    
    The "private" build environments are not available to most users so
    remove this from the default build.  Only developers with access
    to private runners (rather than a shared runner) will have a runner
    tagged as "private".
    
    Signed-off-by: Andrew Bartlett <abartlet at samba.org>
    Reviewed-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>

commit 4365741fe59ac833fe04e4eaa591422fcb51504e
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Wed May 2 09:04:51 2018 +1200

    autobuild: Extend build combinations tested to include --without-ldap
    
    This bumps --without-ads to the samba-nt4 job so that option alone is still covered.
    
    Signed-off-by: Andrew Bartlett <abartlet at samba.org>
    Reviewed-by: Gary Lockyer <gary at catalyst.net.nz>
    Reviewed-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>

commit 61244998048111e2100e7fb535b3c9338853cbed
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Thu May 3 15:47:45 2018 +1200

    selftest: Allow make test to run with --address-sanitizer
    
    Recent GCC versions enforce that the library must be in LD_PRELOAD if linked to a plugin
    (like a python module).
    
    Signed-off-by: Andrew Bartlett <abartlet at samba.org>
    Reviewed-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>

commit 7e091e505156381e385235ab4518b4d133a98497
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Thu May 3 16:22:19 2018 +1200

    s4-lsa: Fix use-after-free in LSA server
    
    This is a regression introduced in ab7988aa2fd1a43f576a4b73a6893c61c7ef1957.
    
    The state variable contains the data to be returned to the client
    and packed into NDR after the function returned.
    
    This memory needs to be kept (on mem_ctx as parent) until that is
    pushed and freed by the caller.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13420
    
    Signed-off-by: Andrew Bartlett <abartlet at samba.org>
    Reviewed-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>

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

Summary of changes:
 .gitlab-ci-private.yml                             |  34 ++++
 .gitlab-ci.yml                                     |  99 ++---------
 lib/ldb-samba/ldb_wrap.c                           |   2 +
 lib/ldb/ldb_ldb/ldb_ldb.c                          |  61 +++++++
 lib/ldb/ldb_tdb/ldb_cache.c                        |  50 ++++--
 lib/ldb/ldb_tdb/ldb_tdb.c                          |  51 ++++--
 lib/ldb/ldb_tdb/ldb_tdb.h                          |   2 +-
 lib/ldb/tests/ldb_kv_ops_test.c                    | 187 ++++++++++++++++++++-
 lib/ldb/tests/python/api.py                        | 179 ++++++++++++++------
 lib/ldb/wscript                                    |   9 +
 python/samba/tests/encrypted_secrets.py            |   2 +-
 script/autobuild.py                                |   4 +-
 selftest/selftest.pl                               |  11 ++
 selftest/wscript                                   |  24 +++
 .../dsdb/samdb/ldb_modules/partition_metadata.c    |  19 +--
 source4/dsdb/samdb/ldb_modules/schema_load.c       |  18 +-
 source4/rpc_server/lsa/lsa_lookup.c                |   3 -
 source4/torture/dns/dlz_bind9.c                    |   2 +-
 source4/torture/drs/python/samba_tool_drs.py       |  10 +-
 19 files changed, 565 insertions(+), 202 deletions(-)
 create mode 100644 .gitlab-ci-private.yml
 create mode 100644 lib/ldb/ldb_ldb/ldb_ldb.c


Changeset truncated at 500 lines:

diff --git a/.gitlab-ci-private.yml b/.gitlab-ci-private.yml
new file mode 100644
index 0000000..6956e71
--- /dev/null
+++ b/.gitlab-ci-private.yml
@@ -0,0 +1,34 @@
+include:
+ - '/.gitlab-ci.yml'
+
+
+.private_template: &private_template
+  stage: build
+  tags:
+    - docker
+    - private
+
+build_samba:
+  <<: *private_template
+  script:
+    # this one takes about 4 hours to finish
+    - python script/autobuild.py samba            --verbose --tail --testbase /tmp/samba-testbase
+
+build_samba_nt4:
+  <<: *private_template
+  script:
+    # this one takes about 1 hours to finish
+    - python script/autobuild.py samba-nt4        --verbose --tail --testbase /tmp/samba-testbase
+
+build_samba_fileserver:
+  <<: *private_template
+  script:
+    # this one takes about 1 hours to finish
+    - python script/autobuild.py samba-fileserver --verbose --tail --testbase /tmp/samba-testbase
+
+build_samba_ad_dc:
+  <<: *private_template
+  script:
+    # this one takes about 1 hours to finish
+    - python script/autobuild.py samba-ad-dc     --verbose --tail --testbase /tmp/samba-testbase
+
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index cde8341..71e44c6 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -14,129 +14,66 @@ before_script:
       sudo swapon /samba-swap;
     fi
 
-build_samba:
+.shared_template: &shared_template
   stage: build
   tags:
     - docker
-    - private
-  script:
-    # this one takes about 4 hours to finish
-    - python script/autobuild.py samba            --verbose --tail --testbase /tmp/samba-testbase
-
-build_samba_nt4:
-  stage: build
-  tags:
-    - docker
-    - private
-  script:
-    # this one takes about 1 hours to finish
-    - python script/autobuild.py samba-nt4        --verbose --tail --testbase /tmp/samba-testbase
-
-build_samba_fileserver:
-  stage: build
-  tags:
-    - docker
-    - private
-  script:
-    # this one takes about 1 hours to finish
-    - python script/autobuild.py samba-fileserver --verbose --tail --testbase /tmp/samba-testbase
-
-build_samba_ad_dc:
-  stage: build
-  tags:
-    - docker
-    - private
-  script:
-    # this one takes about 1 hours to finish
-    - python script/autobuild.py samba-ad-dc     --verbose --tail --testbase /tmp/samba-testbase
-
-build_samba_ad_dc_2:
-  stage: build
-  tags:
-    - docker
-    - private
-  script:
-    # this one takes about 1 hours to finish
-    - python script/autobuild.py samba-ad-dc-2     --verbose --tail --testbase /tmp/samba-testbase
+    - shared
 
 build_samba_none_env:
-  stage: build
-  tags:
-    - docker
-    - shared
+  <<: *shared_template
   script:
     # this one takes about 1 hours to finish
     - python script/autobuild.py samba-none-env    --verbose --tail --testbase /tmp/samba-testbase
 
 build_samba_nopython:
-  stage: build
-  tags:
-    - docker
-    - shared
+  <<: *shared_template
   script:
     - python script/autobuild.py samba-nopython   --verbose --tail --testbase /tmp/samba-testbase
 
 build_samba_systemkrb5:
-  stage: build
-  tags:
-    - docker
-    - shared
+  <<: *shared_template
   script:
     - python script/autobuild.py samba-systemkrb5 --verbose --tail --testbase /tmp/samba-testbase
 
 build_samba_xc:
-  stage: build
-  tags:
-    - docker
-    - shared
+  <<: *shared_template
   script:
     - python script/autobuild.py samba-xc         --verbose --tail --testbase /tmp/samba-testbase
 
 build_samba_o3:
-  stage: build
-  tags:
-    - docker
-    - shared
+  <<: *shared_template
   script:
     - python script/autobuild.py samba-o3         --verbose --tail --testbase /tmp/samba-testbase
 
+build_samba_ad_dc_2:
+  <<: *shared_template
+  script:
+    # this one takes about 1 hours to finish
+    - python script/autobuild.py samba-ad-dc-2     --verbose --tail --testbase /tmp/samba-testbase
+
 build_samba_libs:
-  stage: build
-  tags:
-    - docker
-    - shared
+  <<: *shared_template
   script:
     - python script/autobuild.py samba-libs       --verbose --tail --testbase /tmp/samba-testbase
 
 build_samba_static:
-  stage: build
-  tags:
-    - docker
-    - shared
+  <<: *shared_template
   script:
     - python script/autobuild.py samba-static     --verbose --tail --testbase /tmp/samba-testbase
 
 build_ctdb:
-  stage: build
-  tags:
-    - docker
-    - shared
+  <<: *shared_template
   script:
     - python script/autobuild.py samba-ctdb       --verbose --tail --testbase /tmp/samba-testbase
 
 build_samba_ctdb:
-  stage: build
-  tags:
-    - docker
-    - shared
+  <<: *shared_template
   script:
     - python script/autobuild.py ctdb             --verbose --tail --testbase /tmp/samba-testbase
 
 build_others:
-  stage: build
-  tags:
-    - docker
-    - shared
+  <<: *shared_template
   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-samba/ldb_wrap.c b/lib/ldb-samba/ldb_wrap.c
index 3d3eb8b..da383d2 100644
--- a/lib/ldb-samba/ldb_wrap.c
+++ b/lib/ldb-samba/ldb_wrap.c
@@ -356,6 +356,8 @@ int samba_ldb_connect(struct ldb_context *ldb, struct loadparm_context *lp_ctx,
 	}
 	if (strncmp("tdb://", base_url, 6) == 0) {
 		base_url = base_url+6;
+	} else if (strncmp("ldb://", base_url, 6) == 0) {
+		base_url = base_url+6;
 	}
 	path = talloc_strdup(mem_ctx, base_url);
 	if (path == NULL) {
diff --git a/lib/ldb/ldb_ldb/ldb_ldb.c b/lib/ldb/ldb_ldb/ldb_ldb.c
new file mode 100644
index 0000000..3e4398f
--- /dev/null
+++ b/lib/ldb/ldb_ldb/ldb_ldb.c
@@ -0,0 +1,61 @@
+/*
+ * ldb connection and module initialisation
+ *
+ *  Copyright (C) Andrew Bartlett <abartlet at samba.org> 2018
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+#include "ldb_private.h"
+#include "../ldb_tdb/ldb_tdb.h"
+
+/*
+  connect to the database
+*/
+static int lldb_connect(struct ldb_context *ldb,
+			const char *url,
+			unsigned int flags,
+			const char *options[],
+			struct ldb_module **module)
+{
+	const char *path;
+	int ret;
+
+	/*
+	 * Check and remove the url prefix
+	 */
+	if (strchr(url, ':')) {
+		if (strncmp(url, "ldb://", 6) != 0) {
+			ldb_debug(ldb, LDB_DEBUG_ERROR,
+				  "Invalid ldb URL '%s'", url);
+			return LDB_ERR_OPERATIONS_ERROR;
+		}
+		path = url+6;
+	} else {
+		path = url;
+	}
+
+	/*
+	 * Don't create the database if it's not there
+	 */
+	flags |= LDB_FLG_DONT_CREATE_DB;
+	ret = ltdb_connect(ldb, path, flags, options, module);
+	return ret;
+}
+
+int ldb_ldb_init(const char *version)
+{
+	LDB_MODULE_CHECK_VERSION(version);
+	return ldb_register_backend("ldb", lldb_connect, false);
+}
diff --git a/lib/ldb/ldb_tdb/ldb_cache.c b/lib/ldb/ldb_tdb/ldb_cache.c
index 4790bcd..a9d2113 100644
--- a/lib/ldb/ldb_tdb/ldb_cache.c
+++ b/lib/ldb/ldb_tdb/ldb_cache.c
@@ -386,6 +386,7 @@ int ltdb_cache_load(struct ldb_module *module)
 	uint64_t seq;
 	struct ldb_message *baseinfo = NULL, *options = NULL;
 	const struct ldb_schema_attribute *a;
+	bool have_write_txn = false;
 	int r;
 
 	ldb = ldb_module_get_ctx(module);
@@ -406,29 +407,38 @@ int ltdb_cache_load(struct ldb_module *module)
 	baseinfo_dn = ldb_dn_new(baseinfo, ldb, LTDB_BASEINFO);
 	if (baseinfo_dn == NULL) goto failed;
 
+	r = ltdb->kv_ops->lock_read(module);
+	if (r != LDB_SUCCESS) {
+		goto failed;
+	}
 	r= ltdb_search_dn1(module, baseinfo_dn, baseinfo, 0);
 	if (r != LDB_SUCCESS && r != LDB_ERR_NO_SUCH_OBJECT) {
-		goto failed;
+		goto failed_and_unlock;
 	}
-	
+
 	/* possibly initialise the baseinfo */
 	if (r == LDB_ERR_NO_SUCH_OBJECT) {
 
+		/* Give up the read lock, try again with a write lock */
+		r = ltdb->kv_ops->unlock_read(module);
+		if (r != LDB_SUCCESS) {
+			goto failed;
+		}
+
 		if (ltdb->kv_ops->begin_write(ltdb) != 0) {
 			goto failed;
 		}
 
+		have_write_txn = true;
+
 		/* error handling for ltdb_baseinfo_init() is by
 		   looking for the record again. */
 		ltdb_baseinfo_init(module);
 
-		if (ltdb->kv_ops->finish_write(ltdb) != 0) {
-			goto failed;
-		}
-
 		if (ltdb_search_dn1(module, baseinfo_dn, baseinfo, 0) != LDB_SUCCESS) {
-			goto failed;
+			goto failed_and_unlock;
 		}
+
 	}
 
 	/* Ignore the result, and update the sequence number */
@@ -443,16 +453,17 @@ int ltdb_cache_load(struct ldb_module *module)
 	ltdb->sequence_number = seq;
 
 	/* Read an interpret database options */
+
 	options = ldb_msg_new(ltdb->cache);
-	if (options == NULL) goto failed;
+	if (options == NULL) goto failed_and_unlock;
 
 	options_dn = ldb_dn_new(options, ldb, LTDB_OPTIONS);
-	if (options_dn == NULL) goto failed;
+	if (options_dn == NULL) goto failed_and_unlock;
 
 	r= ltdb_search_dn1(module, options_dn, options, 0);
 	talloc_free(options_dn);
 	if (r != LDB_SUCCESS && r != LDB_ERR_NO_SUCH_OBJECT) {
-		goto failed;
+		goto failed_and_unlock;
 	}
 	
 	/* set flags if they do exist */
@@ -479,7 +490,7 @@ int ltdb_cache_load(struct ldb_module *module)
 	ltdb_attributes_unload(module);
 
 	if (ltdb_index_load(module, ltdb) == -1) {
-		goto failed;
+		goto failed_and_unlock;
 	}
 
 	/*
@@ -488,7 +499,7 @@ int ltdb_cache_load(struct ldb_module *module)
 	 * partition module.
 	 */
 	if (ltdb_attributes_load(module) == -1) {
-		goto failed;
+		goto failed_and_unlock;
 	}
 
 	ltdb->GUID_index_syntax = NULL;
@@ -503,10 +514,25 @@ int ltdb_cache_load(struct ldb_module *module)
 	}
 
 done:
+	if (have_write_txn) {
+		if (ltdb->kv_ops->finish_write(ltdb) != 0) {
+			goto failed;
+		}
+	} else {
+		ltdb->kv_ops->unlock_read(module);
+	}
+
 	talloc_free(options);
 	talloc_free(baseinfo);
 	return 0;
 
+failed_and_unlock:
+	if (have_write_txn) {
+		ltdb->kv_ops->abort_write(ltdb);
+	} else {
+		ltdb->kv_ops->unlock_read(module);
+	}
+
 failed:
 	talloc_free(options);
 	talloc_free(baseinfo);
diff --git a/lib/ldb/ldb_tdb/ldb_tdb.c b/lib/ldb/ldb_tdb/ldb_tdb.c
index 1d06566..0833a4f 100644
--- a/lib/ldb/ldb_tdb/ldb_tdb.c
+++ b/lib/ldb/ldb_tdb/ldb_tdb.c
@@ -101,7 +101,7 @@ static int ltdb_lock_read(struct ldb_module *module)
 	int tdb_ret = 0;
 	int ret;
 
-	if (ltdb->in_transaction == 0 &&
+	if (tdb_transaction_active(ltdb->tdb) == false &&
 	    ltdb->read_lock_count == 0) {
 		tdb_ret = tdb_lockall_read(ltdb->tdb);
 	}
@@ -128,7 +128,7 @@ static int ltdb_unlock_read(struct ldb_module *module)
 {
 	void *data = ldb_module_get_private(module);
 	struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private);
-	if (ltdb->in_transaction == 0 && ltdb->read_lock_count == 1) {
+	if (!tdb_transaction_active(ltdb->tdb) && ltdb->read_lock_count == 1) {
 		tdb_unlockall_read(ltdb->tdb);
 		ltdb->read_lock_count--;
 		return 0;
@@ -379,7 +379,7 @@ static int ltdb_modified(struct ldb_module *module, struct ldb_dn *dn)
 
 	/* only allow modifies inside a transaction, otherwise the
 	 * ldb is unsafe */
-	if (ltdb->in_transaction == 0) {
+	if (ltdb->kv_ops->transaction_active(ltdb) == false) {
 		ldb_set_errstring(ldb_module_get_ctx(module), "ltdb modify without transaction");
 		return LDB_ERR_OPERATIONS_ERROR;
 	}
@@ -651,6 +651,16 @@ static int ltdb_add(struct ltdb_context *ctx)
 	struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private);
 	int ret = LDB_SUCCESS;
 
+	if (ltdb->max_key_length != 0 &&
+	    ltdb->cache->GUID_index_attribute == NULL &&
+	    !ldb_dn_is_special(req->op.add.message->dn))
+	{
+		ldb_set_errstring(ldb_module_get_ctx(module),
+				  "Must operate ldb_mdb in GUID "
+				  "index mode, but " LTDB_IDXGUID " not set.");
+		return LDB_ERR_UNWILLING_TO_PERFORM;
+	}
+
 	ret = ltdb_check_special_dn(module, req->op.add.message);
 	if (ret != LDB_SUCCESS) {
 		return ret;
@@ -1469,7 +1479,6 @@ static int ltdb_start_trans(struct ldb_module *module)
 		return ltdb->kv_ops->error(ltdb);
 	}
 
-	ltdb->in_transaction++;
 
 	ltdb_index_transaction_start(module);
 
@@ -1490,8 +1499,11 @@ static int ltdb_prepare_commit(struct ldb_module *module)
 	void *data = ldb_module_get_private(module);
 	struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private);
 
-	if (ltdb->in_transaction != 1) {
-		return LDB_SUCCESS;
+	if (!ltdb->kv_ops->transaction_active(ltdb)) {
+		ldb_set_errstring(ldb_module_get_ctx(module),
+				  "ltdb_prepare_commit() called "
+				  "without transaction active");
+		return LDB_ERR_OPERATIONS_ERROR;
 	}
 
 	/*
@@ -1515,13 +1527,11 @@ static int ltdb_prepare_commit(struct ldb_module *module)
 	ret = ltdb_index_transaction_commit(module);
 	if (ret != LDB_SUCCESS) {
 		ltdb->kv_ops->abort_write(ltdb);
-		ltdb->in_transaction--;
 		return ret;
 	}
 
 	if (ltdb->kv_ops->prepare_write(ltdb) != 0) {
 		ret = ltdb->kv_ops->error(ltdb);
-		ltdb->in_transaction--;
 		ldb_debug_set(ldb_module_get_ctx(module),
 			      LDB_DEBUG_FATAL,
 			      "Failure during "
@@ -1549,7 +1559,6 @@ static int ltdb_end_trans(struct ldb_module *module)
 		}
 	}
 
-	ltdb->in_transaction--;
 	ltdb->prepared_commit = false;
 
 	if (ltdb->kv_ops->finish_write(ltdb) != 0) {
@@ -1569,7 +1578,6 @@ static int ltdb_del_trans(struct ldb_module *module)
 	void *data = ldb_module_get_private(module);
 	struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private);
 
-	ltdb->in_transaction--;
 
 	if (ltdb_index_transaction_cancel(module) != 0) {
 		ltdb->kv_ops->abort_write(ltdb);
@@ -1799,7 +1807,7 @@ static int ltdb_tdb_traverse_fn(struct ltdb_private *ltdb, ldb_kv_traverse_fn fn
 		.ctx = ctx,
 		.ltdb = ltdb
 	};
-	if (ltdb->in_transaction != 0) {


-- 
Samba Shared Repository



More information about the samba-cvs mailing list