diff options
Diffstat (limited to 'source4')
-rw-r--r-- | source4/lib/ldb/common/ldb_modules.c | 16 | ||||
-rw-r--r-- | source4/lib/ldb/include/ldb_private.h | 4 | ||||
-rw-r--r-- | source4/lib/ldb/ldb_ldap/ldb_ldap.c | 31 | ||||
-rw-r--r-- | source4/lib/ldb/ldb_tdb/ldb_tdb.c | 50 | ||||
-rw-r--r-- | source4/lib/ldb/modules/skel.c | 14 | ||||
-rw-r--r-- | source4/lib/ldb/modules/timestamps.c | 14 |
6 files changed, 111 insertions, 18 deletions
diff --git a/source4/lib/ldb/common/ldb_modules.c b/source4/lib/ldb/common/ldb_modules.c index 1a6a334b8d..71ec3fdc00 100644 --- a/source4/lib/ldb/common/ldb_modules.c +++ b/source4/lib/ldb/common/ldb_modules.c @@ -250,6 +250,22 @@ int ldb_next_rename_record(struct ldb_module *module, const char *olddn, const c return module->next->ops->rename_record(module->next, olddn, newdn); } +int ldb_next_named_lock(struct ldb_module *module, const char *lockname) +{ + if (!module->next) { + return -1; + } + return module->next->ops->named_lock(module->next, lockname); +} + +int ldb_next_named_unlock(struct ldb_module *module, const char *lockname) +{ + if (!module->next) { + return -1; + } + return module->next->ops->named_unlock(module->next, lockname); +} + const char *ldb_next_errstring(struct ldb_module *module) { if (!module->next) { diff --git a/source4/lib/ldb/include/ldb_private.h b/source4/lib/ldb/include/ldb_private.h index dfd388b8c6..720d8928dd 100644 --- a/source4/lib/ldb/include/ldb_private.h +++ b/source4/lib/ldb/include/ldb_private.h @@ -63,6 +63,8 @@ struct ldb_module_ops { int (*modify_record)(struct ldb_module *, const struct ldb_message *); int (*delete_record)(struct ldb_module *, const char *); int (*rename_record)(struct ldb_module *, const char *, const char *); + int (*named_lock)(struct ldb_module *, const char *); + int (*named_unlock)(struct ldb_module *, const char *); const char * (*errstring)(struct ldb_module *); /* this is called when the alloc ops changes to ensure we @@ -101,6 +103,8 @@ int ldb_next_add_record(struct ldb_module *module, const struct ldb_message *mes int ldb_next_modify_record(struct ldb_module *module, const struct ldb_message *message); int ldb_next_delete_record(struct ldb_module *module, const char *dn); int ldb_next_rename_record(struct ldb_module *module, const char *olddn, const char *newdn); +int ldb_next_named_lock(struct ldb_module *module, const char *lockname); +int ldb_next_named_unlock(struct ldb_module *module, const char *lockname); const char *ldb_next_errstring(struct ldb_module *module); void ldb_next_cache_free(struct ldb_module *module); diff --git a/source4/lib/ldb/ldb_ldap/ldb_ldap.c b/source4/lib/ldb/ldb_ldap/ldb_ldap.c index 85604dfe76..d9640f247a 100644 --- a/source4/lib/ldb/ldb_ldap/ldb_ldap.c +++ b/source4/lib/ldb/ldb_ldap/ldb_ldap.c @@ -496,6 +496,35 @@ static int lldb_modify(struct ldb_module *module, const struct ldb_message *msg) return ret; } +static int lldb_lock(struct ldb_module *module, const char *lockname) +{ + struct ldb_context *ldb = module->ldb; + struct lldb_private *lldb = module->private_data; + int ret = 0; + + if (lockname == NULL) { + return -1; + } + + /* TODO implement a local locking mechanism here */ + + return ret; +} + +static int lldb_unlock(struct ldb_module *module, const char *lockname) +{ + struct ldb_context *ldb = module->ldb; + struct lldb_private *lldb = module->private_data; + int ret = 0; + + if (lockname == NULL) { + return -1; + } + + /* TODO implement a local unlocking mechanism here */ + + return ret; +} /* return extended error information @@ -516,6 +545,8 @@ static const struct ldb_module_ops lldb_ops = { lldb_modify, lldb_delete, lldb_rename, + lldb_lock, + lldb_unlock, lldb_errstring }; diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 5f6af43f94..4049900a23 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -40,6 +40,8 @@ #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 @@ -122,14 +124,18 @@ failed: /* lock the database for write - currently a single lock is used */ -static int ltdb_lock(struct ldb_module *module) +static int ltdb_lock(struct ldb_module *module, const char *lockname) { struct ldb_context *ldb = module->ldb; struct ltdb_private *ltdb = module->private_data; TDB_DATA key; int ret; - key = ltdb_key(module, "LDBLOCK"); + if (lockname == NULL) { + return -1; + } + + key = ltdb_key(module, lockname); if (!key.dptr) { return -1; } @@ -144,20 +150,26 @@ static int ltdb_lock(struct ldb_module *module) /* unlock the database after a ltdb_lock() */ -static void ltdb_unlock(struct ldb_module *module) +static int ltdb_unlock(struct ldb_module *module, const char *lockname) { struct ldb_context *ldb = module->ldb; struct ltdb_private *ltdb = module->private_data; TDB_DATA key; - key = ltdb_key(module, "LDBLOCK"); + if (lockname == NULL) { + return -1; + } + + key = ltdb_key(module, lockname); if (!key.dptr) { - return; + return -1; } tdb_chainunlock(ltdb->tdb, key); ldb_free(ldb, key.dptr); + + return 0; } @@ -231,12 +243,12 @@ static int ltdb_add(struct ldb_module *module, const struct ldb_message *msg) ltdb->last_err_string = NULL; - if (ltdb_lock(module) != 0) { + if (ltdb_lock(module, LDBLOCK) != 0) { return -1; } if (ltdb_cache_load(module) != 0) { - ltdb_unlock(module); + ltdb_unlock(module, LDBLOCK); return -1; } @@ -246,7 +258,7 @@ static int ltdb_add(struct ldb_module *module, const struct ldb_message *msg) ltdb_modified(module, msg->dn); } - ltdb_unlock(module); + ltdb_unlock(module, LDBLOCK); return ret; } @@ -284,12 +296,12 @@ static int ltdb_delete(struct ldb_module *module, const char *dn) ltdb->last_err_string = NULL; - if (ltdb_lock(module) != 0) { + if (ltdb_lock(module, LDBLOCK) != 0) { return -1; } if (ltdb_cache_load(module) != 0) { - ltdb_unlock(module); + ltdb_unlock(module, LDBLOCK); return -1; } @@ -316,11 +328,11 @@ static int ltdb_delete(struct ldb_module *module, const char *dn) ltdb_modified(module, dn); } - ltdb_unlock(module); + ltdb_unlock(module, LDBLOCK); return ret; failed: - ltdb_unlock(module); + ltdb_unlock(module, LDBLOCK); return -1; } @@ -573,12 +585,12 @@ static int ltdb_modify(struct ldb_module *module, const struct ldb_message *msg) ltdb->last_err_string = NULL; - if (ltdb_lock(module) != 0) { + if (ltdb_lock(module, LDBLOCK) != 0) { return -1; } if (ltdb_cache_load(module) != 0) { - ltdb_unlock(module); + ltdb_unlock(module, LDBLOCK); return -1; } @@ -588,7 +600,7 @@ static int ltdb_modify(struct ldb_module *module, const struct ldb_message *msg) ltdb_modified(module, msg->dn); } - ltdb_unlock(module); + ltdb_unlock(module, LDBLOCK); return ret; } @@ -606,7 +618,7 @@ static int ltdb_rename(struct ldb_module *module, const char *olddn, const char ltdb->last_err_string = NULL; - if (ltdb_lock(module) != 0) { + if (ltdb_lock(module, LDBLOCK) != 0) { return -1; } @@ -641,11 +653,11 @@ static int ltdb_rename(struct ldb_module *module, const char *olddn, const char ltdb->last_err_string = error_str; - ltdb_unlock(module); + ltdb_unlock(module, LDBLOCK); return ret; failed: - ltdb_unlock(module); + ltdb_unlock(module, LDBLOCK); return -1; } @@ -692,6 +704,8 @@ static const struct ldb_module_ops ltdb_ops = { ltdb_modify, ltdb_delete, ltdb_rename, + ltdb_lock, + ltdb_unlock, ltdb_errstring, ltdb_cache_free }; diff --git a/source4/lib/ldb/modules/skel.c b/source4/lib/ldb/modules/skel.c index 331a2de5e4..3581969c18 100644 --- a/source4/lib/ldb/modules/skel.c +++ b/source4/lib/ldb/modules/skel.c @@ -80,6 +80,18 @@ static int skel_rename_record(struct ldb_module *module, const char *olddn, cons return ldb_next_rename_record(module, olddn, newdn); } +/* named_lock */ +static const char *skel_named_lock(struct ldb_module *module, const char *lockname) +{ + return ldb_next_named_lock(module, lockname); +} + +/* named_unlock */ +static const char *skel_named_unlock(struct ldb_module *module, const char *lockname) +{ + return ldb_next_named_unlock(module, lockname); +} + /* return extended error information */ static const char *skel_errstring(struct ldb_module *module) { @@ -100,6 +112,8 @@ static const struct ldb_module_ops skel_ops = { skel_modify_record, skel_delete_record, skel_rename_record, + skel_named_lock, + skel_named_unlock, skel_errstring, skel_cache_free }; diff --git a/source4/lib/ldb/modules/timestamps.c b/source4/lib/ldb/modules/timestamps.c index 521c59d241..fde87ef4a6 100644 --- a/source4/lib/ldb/modules/timestamps.c +++ b/source4/lib/ldb/modules/timestamps.c @@ -230,6 +230,18 @@ static int timestamps_rename_record(struct ldb_module *module, const char *olddn return ldb_next_rename_record(module, olddn, newdn); } +static int timestamps_lock(struct ldb_module *module, const char *lockname) +{ + ldb_debug(module->ldb, LDB_DEBUG_TRACE, "timestamps_lock\n"); + return ldb_next_named_lock(module, lockname); +} + +static int timestamps_unlock(struct ldb_module *module, const char *lockname) +{ + ldb_debug(module->ldb, LDB_DEBUG_TRACE, "timestamps_unlock\n"); + return ldb_next_named_unlock(module, lockname); +} + /* return extended error information */ static const char *timestamps_errstring(struct ldb_module *module) { @@ -252,6 +264,8 @@ static const struct ldb_module_ops timestamps_ops = { timestamps_modify_record, timestamps_delete_record, timestamps_rename_record, + timestamps_lock, + timestamps_unlock, timestamps_errstring, timestamps_cache_free }; |