diff options
Diffstat (limited to 'source4/lib/ldb/ldb_tdb')
-rw-r--r-- | source4/lib/ldb/ldb_tdb/ldb_search.c | 36 | ||||
-rw-r--r-- | source4/lib/ldb/ldb_tdb/ldb_tdb.c | 164 | ||||
-rw-r--r-- | source4/lib/ldb/ldb_tdb/ldb_tdb.h | 2 |
3 files changed, 36 insertions, 166 deletions
diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index fc864ac2ea..83079eab81 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -242,6 +242,42 @@ int ltdb_search_dn1(struct ldb_module *module, const struct ldb_dn *dn, struct l return 1; } +/* the lock key for search locking. Note that this is not a DN, its + just an arbitrary key to give to tdb. Also note that as we and + using transactions for all write operations and transactions take + care of their own locks, we don't need to do any locking anywhere + other than in ldb_search() */ +#define LDBLOCK "INT_LDBLOCK" + +/* + lock the database for read - use by ltdb_search +*/ +static int ltdb_lock_read(struct ldb_module *module) +{ + struct ltdb_private *ltdb = module->private_data; + TDB_DATA key; + + key.dptr = discard_const(LDBLOCK); + key.dsize = strlen(LDBLOCK); + + return tdb_chainlock_read(ltdb->tdb, key); +} + +/* + unlock the database after a ltdb_lock_read() +*/ +static int ltdb_unlock_read(struct ldb_module *module) +{ + struct ltdb_private *ltdb = module->private_data; + TDB_DATA key; + + key.dptr = discard_const(LDBLOCK); + key.dsize = strlen(LDBLOCK); + + return tdb_chainunlock_read(ltdb->tdb, key); +} + + /* search the database for a single simple dn diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index a2faaa805f..d8a03c3f55 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -41,9 +41,6 @@ #include "ldb/include/ldb_private.h" #include "ldb/ldb_tdb/ldb_tdb.h" -#define LDBLOCK "@INT_LDBLOCK" - - /* form a TDB_DATA for a record key caller frees @@ -96,141 +93,6 @@ failed: } /* - lock the database for write - currently a single lock is used -*/ -static int ltdb_lock(struct ldb_module *module, const char *lockname) -{ - struct ltdb_private *ltdb = module->private_data; - struct ldb_dn *lock_dn; - char *ldn; - TDB_DATA key; - int ret; - - if (lockname == NULL) { - return -1; - } - - ldn = talloc_asprintf(module->ldb, "%s_%s", LDBLOCK, lockname); - if (ldn == NULL) { - return -1; - } - - lock_dn = ldb_dn_explode(module->ldb, ldn); - if (lock_dn == NULL) { - talloc_free(ldn); - return -1; - } - talloc_free(ldn); - - key = ltdb_key(module, lock_dn); - if (!key.dptr) { - talloc_free(lock_dn); - return -1; - } - - ret = tdb_chainlock(ltdb->tdb, key); - - talloc_free(key.dptr); - talloc_free(lock_dn); - - return ret; -} - -/* - unlock the database after a ltdb_lock() -*/ -static int ltdb_unlock(struct ldb_module *module, const char *lockname) -{ - struct ltdb_private *ltdb = module->private_data; - struct ldb_dn *lock_dn; - char *ldn; - TDB_DATA key; - - if (lockname == NULL) { - return -1; - } - - ldn = talloc_asprintf(module->ldb, "%s_%s", LDBLOCK, lockname); - if (ldn == NULL) { - return -1; - } - - lock_dn = ldb_dn_explode(module->ldb, ldn); - if (lock_dn == NULL) { - talloc_free(ldn); - return -1; - } - talloc_free(ldn); - - key = ltdb_key(module, lock_dn); - if (!key.dptr) { - talloc_free(lock_dn); - return -1; - } - - tdb_chainunlock(ltdb->tdb, key); - - talloc_free(key.dptr); - talloc_free(lock_dn); - - return 0; -} - - -/* - 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; - struct ldb_dn *lock_dn; - int ret; - - lock_dn = ldb_dn_explode(module, LDBLOCK); - if (lock_dn == NULL) { - return -1; - } - - key = ltdb_key(module, lock_dn); - if (!key.dptr) { - talloc_free(lock_dn); - return -1; - } - talloc_free(lock_dn); - - 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; - struct ldb_dn *lock_dn; - TDB_DATA key; - - lock_dn = ldb_dn_explode(module, LDBLOCK); - if (lock_dn == NULL) { - return -1; - } - - key = ltdb_key(module, lock_dn); - if (!key.dptr) { - talloc_free(lock_dn); - return -1; - } - talloc_free(lock_dn); - - tdb_chainunlock_read(ltdb->tdb, key); - talloc_free(key.dptr); - return 0; -} - -/* check special dn's have valid attributes currently only @ATTRIBUTES is checked */ @@ -335,12 +197,7 @@ static int ltdb_add(struct ldb_module *module, const struct ldb_message *msg) return ret; } - if (ltdb_lock(module, LDBLOCK) != 0) { - return LDB_ERR_OTHER; - } - if (ltdb_cache_load(module) != 0) { - ltdb_unlock(module, LDBLOCK); return LDB_ERR_OTHER; } @@ -350,7 +207,6 @@ static int ltdb_add(struct ldb_module *module, const struct ldb_message *msg) ltdb_modified(module, msg->dn); } - ltdb_unlock(module, LDBLOCK); return ret; } @@ -386,10 +242,6 @@ static int ltdb_delete(struct ldb_module *module, const struct ldb_dn *dn) struct ldb_message *msg = NULL; int ret = LDB_ERR_OTHER; - if (ltdb_lock(module, LDBLOCK) != 0) { - return ret; - } - if (ltdb_cache_load(module) != 0) { goto failed; } @@ -421,12 +273,10 @@ static int ltdb_delete(struct ldb_module *module, const struct ldb_dn *dn) ret = LDB_ERR_OTHER; talloc_free(msg); - ltdb_unlock(module, LDBLOCK); return ret; failed: talloc_free(msg); - ltdb_unlock(module, LDBLOCK); return ret; } @@ -749,12 +599,7 @@ static int ltdb_modify(struct ldb_module *module, const struct ldb_message *msg) return ret; } - if (ltdb_lock(module, LDBLOCK) != 0) { - return -1; - } - if (ltdb_cache_load(module) != 0) { - ltdb_unlock(module, LDBLOCK); return -1; } @@ -764,8 +609,6 @@ static int ltdb_modify(struct ldb_module *module, const struct ldb_message *msg) ltdb_modified(module, msg->dn); } - ltdb_unlock(module, LDBLOCK); - return ret; } @@ -778,12 +621,7 @@ static int ltdb_rename(struct ldb_module *module, const struct ldb_dn *olddn, co char *error_str; int ret = LDB_ERR_OTHER; - if (ltdb_lock(module, LDBLOCK) != 0) { - return ret; - } - if (ltdb_cache_load(module) != 0) { - ltdb_unlock(module, LDBLOCK); return ret; } @@ -821,13 +659,11 @@ static int ltdb_rename(struct ldb_module *module, const struct ldb_dn *olddn, co ldb_set_errstring(module, error_str); talloc_free(msg); - ltdb_unlock(module, LDBLOCK); return ret; failed: talloc_free(msg); - ltdb_unlock(module, LDBLOCK); return ret; } diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.h b/source4/lib/ldb/ldb_tdb/ldb_tdb.h index f1da556f99..c16db67e1f 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.h +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.h @@ -96,8 +96,6 @@ struct TDB_DATA ltdb_key(struct ldb_module *module, const struct ldb_dn *dn); int ltdb_store(struct ldb_module *module, const struct ldb_message *msg, int flgs); int ltdb_delete_noindex(struct ldb_module *module, const struct ldb_dn *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); int ltdb_index_del_value(struct ldb_module *module, const char *dn, struct ldb_message_element *el, int v_idx); |