summaryrefslogtreecommitdiff
path: root/source4
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2005-05-01 12:34:12 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:16:25 -0500
commit425350bb618b7168de1d5d808c9ac5a76d84fcf0 (patch)
tree36103a51f2935869225ce7cebeb3f8bd567d54aa /source4
parentd448b73b5c80d73a7bdb3a669d9660c0a67da336 (diff)
downloadsamba-425350bb618b7168de1d5d808c9ac5a76d84fcf0.tar.gz
samba-425350bb618b7168de1d5d808c9ac5a76d84fcf0.tar.bz2
samba-425350bb618b7168de1d5d808c9ac5a76d84fcf0.zip
r6560: added a tdb_chainlock_read() call in ldb_search(). This guarantees
that ldb_search() sees a single consistent view of the database (by blocking writes during a ldb_search) (This used to be commit 917f2a8a073fd501f0626bea4f9deb91b95fdc90)
Diffstat (limited to 'source4')
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_search.c7
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_tdb.c34
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_tdb.h2
3 files changed, 43 insertions, 0 deletions
diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c
index 4f45fdf376..7883ee6e7b 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_search.c
+++ b/source4/lib/ldb/ldb_tdb/ldb_search.c
@@ -472,9 +472,14 @@ int ltdb_search(struct ldb_module *module, const char *base,
struct ldb_parse_tree *tree;
int ret;
+ if (ltdb_lock_read(module) != 0) {
+ return -1;
+ }
+
ltdb->last_err_string = NULL;
if (ltdb_cache_load(module) != 0) {
+ ltdb_unlock_read(module);
return -1;
}
@@ -484,6 +489,7 @@ int ltdb_search(struct ldb_module *module, const char *base,
tree = ldb_parse_tree(ldb, expression);
if (!tree) {
ltdb->last_err_string = "expression parse failed";
+ ltdb_unlock_read(module);
return -1;
}
@@ -501,6 +507,7 @@ int ltdb_search(struct ldb_module *module, const char *base,
}
ldb_parse_tree_free(ldb, tree);
+ ltdb_unlock_read(module);
return ret;
}
diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c
index 87582cf4eb..b47d79de52 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c
+++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c
@@ -249,6 +249,40 @@ static int ltdb_unlock(struct ldb_module *module, const char *lockname)
/*
+ lock the database for read - use by ltdb_search
+*/
+int ltdb_lock_read(struct ldb_module *module)
+{
+ struct ltdb_private *ltdb = module->private_data;
+ TDB_DATA key;
+ int ret;
+ key = ltdb_key(module, LDBLOCK);
+ if (!key.dptr) {
+ return -1;
+ }
+ ret = tdb_chainlock_read(ltdb->tdb, key);
+ talloc_free(key.dptr);
+ return ret;
+}
+
+/*
+ unlock the database after a ltdb_lock_read()
+*/
+int ltdb_unlock_read(struct ldb_module *module)
+{
+ struct ltdb_private *ltdb = module->private_data;
+ TDB_DATA key;
+ key = ltdb_key(module, LDBLOCK);
+ if (!key.dptr) {
+ return -1;
+ }
+ tdb_chainunlock_read(ltdb->tdb, key);
+ talloc_free(key.dptr);
+ return 0;
+}
+
+
+/*
we've made a modification to a dn - possibly reindex and
update sequence number
*/
diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.h b/source4/lib/ldb/ldb_tdb/ldb_tdb.h
index 9fb60b6359..dfb985319e 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_tdb.h
+++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.h
@@ -104,6 +104,8 @@ struct TDB_DATA ltdb_key(struct ldb_module *module, const char *dn);
int ltdb_store(struct ldb_module *module, const struct ldb_message *msg, int flgs);
int ltdb_delete_noindex(struct ldb_module *module, const char *dn);
int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *msg);
+int ltdb_lock_read(struct ldb_module *module);
+int ltdb_unlock_read(struct ldb_module *module);
/* The following definitions come from lib/ldb/ldb_tdb/ldb_match.c */
int ltdb_val_equal(struct ldb_module *module,