ldb: fixed a race in ldb initialisation
authorAndrew Tridgell <tridge@samba.org>
Tue, 18 Oct 2011 00:21:34 +0000 (11:21 +1100)
committerAndrew Tridgell <tridge@samba.org>
Tue, 18 Oct 2011 01:54:42 +0000 (03:54 +0200)
This fixes a race when two processes initialise the same ldb database
at the same time. One of them could fail due to the other creating the
@BASEINFO record first.

Pair-Programmed-With: Andrew Bartlett <abartlet@samba.org>

Autobuild-User: Andrew Tridgell <tridge@samba.org>
Autobuild-Date: Tue Oct 18 03:54:42 CEST 2011 on sn-devel-104

lib/ldb/ldb_tdb/ldb_cache.c

index e54ceaa..0b93021 100644 (file)
@@ -308,9 +308,17 @@ int ltdb_cache_load(struct ldb_module *module)
        
        /* possibly initialise the baseinfo */
        if (r == LDB_ERR_NO_SUCH_OBJECT) {
-               if (ltdb_baseinfo_init(module) != LDB_SUCCESS) {
+
+               if (tdb_transaction_start(ltdb->tdb) != 0) {
                        goto failed;
                }
+
+               /* error handling for ltdb_baseinfo_init() is by
+                  looking for the record again. */
+               ltdb_baseinfo_init(module);
+
+               tdb_transaction_commit(ltdb->tdb);
+
                if (ltdb_search_dn1(module, baseinfo_dn, baseinfo) != LDB_SUCCESS) {
                        goto failed;
                }