From 0c7b82e5f6063de4114de21cf854ac67346e31f6 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 29 May 2006 23:46:43 +0000 Subject: r15942: Remove the sync internal ldb calls altogether. This means that some modules have been disabled as well as they have not been ported to the async interface One of them is the ugly objectclass module. I hope that the change in samldb module will make the MMC happy without the need of this crappy module, we need proper handling in a decent schema module. proxy and ldb_map have also been disabled ldb_sqlite3 need to be ported as well (currenlty just broken). (This used to be commit 51083de795bdcbf649de926e86969adc20239b6d) --- source4/lib/ldb/ldb_tdb/ldb_search.c | 95 +---------- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 313 ++++++++++++----------------------- source4/lib/ldb/ldb_tdb/ldb_tdb.h | 6 +- 3 files changed, 115 insertions(+), 299 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index 9b45697098..529049e36b 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -470,51 +470,11 @@ static int ltdb_search_full(struct ldb_async_handle *handle) return LDB_SUCCESS; } -static int ltdb_search_sync_callback(struct ldb_context *ldb, void *context, struct ldb_async_result *ares) -{ - struct ldb_result *res = NULL; - - if (!context) { - ldb_set_errstring(ldb, talloc_strdup(ldb, "NULL Context in callback")); - goto error; - } - - res = *((struct ldb_result **)context); - - if (!res || !ares) { - goto error; - } - - if (ares->type == LDB_REPLY_ENTRY) { - res->msgs = talloc_realloc(res, res->msgs, struct ldb_message *, res->count + 2); - if (! res->msgs) { - goto error; - } - - res->msgs[res->count + 1] = NULL; - - res->msgs[res->count] = talloc_steal(res->msgs, ares->message); - if (! res->msgs[res->count]) { - goto error; - } - - res->count++; - } else { - ldb_debug(ldb, LDB_DEBUG_ERROR, "unrecognized async reply in ltdb_search_sync_callback!\n"); - goto error; - } - - talloc_free(ares); - return LDB_SUCCESS; - -error: - if (ares) talloc_free(ares); - if (res) talloc_free(res); - if (context) *((struct ldb_result **)context) = NULL; - return LDB_ERR_OPERATIONS_ERROR; -} - -int ltdb_search_async(struct ldb_module *module, struct ldb_request *req) +/* + search the database with a LDAP-like expression. + choses a search method +*/ +int ltdb_search(struct ldb_module *module, struct ldb_request *req) { struct ltdb_private *ltdb = talloc_get_type(module->private_data, struct ltdb_private); struct ltdb_async_context *ltdb_ac; @@ -566,48 +526,3 @@ int ltdb_search_async(struct ldb_module *module, struct ldb_request *req) return LDB_SUCCESS; } -/* - search the database with a LDAP-like expression. - choses a search method -*/ -int ltdb_search_bytree(struct ldb_module *module, const struct ldb_dn *base, - enum ldb_scope scope, struct ldb_parse_tree *tree, - const char * const attrs[], struct ldb_result **res) -{ - struct ldb_request *req; - int ret; - - *res = talloc_zero(module, struct ldb_result); - if (! *res) { - return LDB_ERR_OPERATIONS_ERROR; - } - - req = talloc_zero(module, struct ldb_request); - if (! req) { - return LDB_ERR_OPERATIONS_ERROR; - } - - req->operation = LDB_ASYNC_SEARCH; - req->op.search.base = base; - req->op.search.scope = scope; - req->op.search.tree = tree; - req->op.search.attrs = attrs; - req->controls = NULL; - req->async.context = (void *)res; - req->async.callback = ltdb_search_sync_callback; - - ret = ltdb_search_async(module, req); - - if (ret == LDB_SUCCESS) { - ret = ldb_async_wait(req->async.handle, LDB_WAIT_ALL); - talloc_free(req); - } - - if (ret != LDB_SUCCESS) { - talloc_free(*res); - } - - return ret; -} - - diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index e5b0ca0668..5ea92aa1b1 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -256,41 +256,58 @@ done: } +static int ltdb_add_internal(struct ldb_module *module, struct ldb_message *msg) +{ + int ret; + + ret = ltdb_check_special_dn(module, msg); + if (ret != LDB_SUCCESS) { + return LDB_ERR_OPERATIONS_ERROR; + } + + if (ltdb_cache_load(module) != 0) { + return LDB_ERR_OPERATIONS_ERROR; + } + + ret = ltdb_store(module, msg, TDB_INSERT); + + if (ret != LDB_SUCCESS) { + return LDB_ERR_OPERATIONS_ERROR; + } + + ltdb_modified(module, msg->dn); + + return LDB_SUCCESS; +} + /* add a record to the database */ -static int ltdb_add_async(struct ldb_module *module, struct ldb_request *req) +static int ltdb_add(struct ldb_module *module, struct ldb_request *req) { struct ltdb_private *ltdb = talloc_get_type(module->private_data, struct ltdb_private); struct ltdb_async_context *ltdb_ac; int tret, ret = LDB_SUCCESS; + if (req->controls != NULL) { + ldb_debug(module->ldb, LDB_DEBUG_WARNING, "Controls should not reach the ldb_tdb backend!\n"); + if (check_critical_controls(req->controls)) { + return LDB_ERR_UNSUPPORTED_CRITICAL_EXTENSION; + } + } + req->async.handle = init_ltdb_handle(ltdb, module, req->async.context, req->async.callback); if (req->async.handle == NULL) { return LDB_ERR_OPERATIONS_ERROR; } ltdb_ac = talloc_get_type(req->async.handle->private_data, struct ltdb_async_context); - tret = ltdb_check_special_dn(module, req->op.add.message); + tret = ltdb_add_internal(module, req->op.add.message); if (tret != LDB_SUCCESS) { req->async.handle->status = tret; goto done; } - if (ltdb_cache_load(module) != 0) { - ret = LDB_ERR_OTHER; - goto done; - } - - tret = ltdb_store(module, req->op.add.message, TDB_INSERT); - - if (tret != LDB_SUCCESS) { - req->async.handle->status = tret; - goto done; - } - - ltdb_modified(module, req->op.add.message->dn); - if (ltdb_ac->callback) { ret = ltdb_ac->callback(module->ldb, ltdb_ac->context, NULL); } @@ -300,35 +317,6 @@ done: return ret; } -static int ltdb_add(struct ldb_module *module, const struct ldb_message *msg) -{ - struct ldb_request *req; - int ret; - - req = talloc_zero(module, struct ldb_request); - if (! req) { - return LDB_ERR_OPERATIONS_ERROR; - } - - req->operation = LDB_ASYNC_ADD; - req->op.add.message = msg; - req->controls = NULL; - req->async.context = NULL; - req->async.callback = NULL; - - ret = ltdb_add_async(module, req); - - if (ret != LDB_SUCCESS) { - talloc_free(req); - return ret; - } - - ret = ldb_async_wait(req->async.handle, LDB_WAIT_ALL); - - talloc_free(req); - return ret; -} - /* delete a record from the database, not updating indexes (used for deleting index records) @@ -354,16 +342,59 @@ int ltdb_delete_noindex(struct ldb_module *module, const struct ldb_dn *dn) return ret; } +static int ltdb_delete_internal(struct ldb_module *module, struct ldb_dn *dn) +{ + struct ldb_message *msg; + int ret; + + msg = talloc(module, struct ldb_message); + if (msg == NULL) { + return LDB_ERR_OPERATIONS_ERROR; + } + + /* in case any attribute of the message was indexed, we need + to fetch the old record */ + ret = ltdb_search_dn1(module, dn, msg); + if (ret != 1) { + /* not finding the old record is an error */ + talloc_free(msg); + return LDB_ERR_NO_SUCH_OBJECT; + } + + ret = ltdb_delete_noindex(module, dn); + if (ret != LDB_SUCCESS) { + talloc_free(msg); + return LDB_ERR_NO_SUCH_OBJECT; + } + + /* remove any indexed attributes */ + ret = ltdb_index_del(module, msg); + if (ret != LDB_SUCCESS) { + talloc_free(msg); + return LDB_ERR_OPERATIONS_ERROR; + } + ltdb_modified(module, dn); + + talloc_free(msg); + return LDB_SUCCESS; +} + /* delete a record from the database */ -static int ltdb_delete_async(struct ldb_module *module, struct ldb_request *req) +static int ltdb_delete(struct ldb_module *module, struct ldb_request *req) { struct ltdb_private *ltdb = talloc_get_type(module->private_data, struct ltdb_private); struct ltdb_async_context *ltdb_ac; - struct ldb_message *msg; int tret, ret = LDB_SUCCESS; + if (req->controls != NULL) { + ldb_debug(module->ldb, LDB_DEBUG_WARNING, "Controls should not reach the ldb_tdb backend!\n"); + if (check_critical_controls(req->controls)) { + return LDB_ERR_UNSUPPORTED_CRITICAL_EXTENSION; + } + } + req->async.handle = NULL; if (ltdb_cache_load(module) != 0) { @@ -376,34 +407,11 @@ static int ltdb_delete_async(struct ldb_module *module, struct ldb_request *req) } ltdb_ac = talloc_get_type(req->async.handle->private_data, struct ltdb_async_context); - msg = talloc(ltdb_ac, struct ldb_message); - if (msg == NULL) { - ret = LDB_ERR_OPERATIONS_ERROR; - goto done; - } - - /* in case any attribute of the message was indexed, we need - to fetch the old record */ - tret = ltdb_search_dn1(module, req->op.del.dn, msg); - if (tret != 1) { - /* not finding the old record is an error */ - req->async.handle->status = LDB_ERR_NO_SUCH_OBJECT; - goto done; - } - - tret = ltdb_delete_noindex(module, req->op.del.dn); - if (tret != LDB_SUCCESS) { - req->async.handle->status = LDB_ERR_NO_SUCH_OBJECT; - goto done; - } - - /* remove any indexed attributes */ - tret = ltdb_index_del(module, msg); + tret = ltdb_delete_internal(module, req->op.del.dn); if (tret != LDB_SUCCESS) { - req->async.handle->status = LDB_ERR_NO_SUCH_OBJECT; + req->async.handle->status = tret; goto done; } - ltdb_modified(module, req->op.del.dn); if (ltdb_ac->callback) ret = ltdb_ac->callback(module->ldb, ltdb_ac->context, NULL); @@ -413,36 +421,6 @@ done: return ret; } -static int ltdb_delete(struct ldb_module *module, const struct ldb_dn *dn) -{ - struct ldb_request *req; - int ret; - - req = talloc_zero(module, struct ldb_request); - if (! req) { - return LDB_ERR_OPERATIONS_ERROR; - } - - req->operation = LDB_ASYNC_DELETE; - req->op.del.dn = dn; - req->controls = NULL; - req->async.context = NULL; - req->async.callback = NULL; - - ret = ltdb_delete_async(module, req); - - if (ret != LDB_SUCCESS) { - talloc_free(req); - return ret; - } - - ret = ldb_async_wait(req->async.handle, LDB_WAIT_ALL); - - talloc_free(req); - return ret; -} - - /* find an element by attribute name. At the moment this does a linear search, it should be re-coded to use a binary search once all places that modify records guarantee @@ -754,12 +732,19 @@ failed: /* modify a record */ -static int ltdb_modify_async(struct ldb_module *module, struct ldb_request *req) +static int ltdb_modify(struct ldb_module *module, struct ldb_request *req) { struct ltdb_private *ltdb = talloc_get_type(module->private_data, struct ltdb_private); struct ltdb_async_context *ltdb_ac; int tret, ret = LDB_SUCCESS; + if (req->controls != NULL) { + ldb_debug(module->ldb, LDB_DEBUG_WARNING, "Controls should not reach the ldb_tdb backend!\n"); + if (check_critical_controls(req->controls)) { + return LDB_ERR_UNSUPPORTED_CRITICAL_EXTENSION; + } + } + req->async.handle = NULL; req->async.handle = init_ltdb_handle(ltdb, module, req->async.context, req->async.callback); @@ -796,45 +781,23 @@ done: return ret; } -static int ltdb_modify(struct ldb_module *module, const struct ldb_message *msg) -{ - struct ldb_request *req; - int ret; - - req = talloc_zero(module, struct ldb_request); - if (! req) { - return LDB_ERR_OPERATIONS_ERROR; - } - - req->operation = LDB_ASYNC_MODIFY; - req->op.mod.message = msg; - req->controls = NULL; - req->async.context = NULL; - req->async.callback = NULL; - - ret = ltdb_modify_async(module, req); - - if (ret != LDB_SUCCESS) { - talloc_free(req); - return ret; - } - - ret = ldb_async_wait(req->async.handle, LDB_WAIT_ALL); - - talloc_free(req); - return ret; -} - /* rename a record */ -static int ltdb_rename_async(struct ldb_module *module, struct ldb_request *req) +static int ltdb_rename(struct ldb_module *module, struct ldb_request *req) { struct ltdb_private *ltdb = talloc_get_type(module->private_data, struct ltdb_private); struct ltdb_async_context *ltdb_ac; struct ldb_message *msg; int tret, ret = LDB_SUCCESS; + if (req->controls != NULL) { + ldb_debug(module->ldb, LDB_DEBUG_WARNING, "Controls should not reach the ldb_tdb backend!\n"); + if (check_critical_controls(req->controls)) { + return LDB_ERR_UNSUPPORTED_CRITICAL_EXTENSION; + } + } + req->async.handle = NULL; if (ltdb_cache_load(module) != 0) { @@ -868,15 +831,15 @@ static int ltdb_rename_async(struct ldb_module *module, struct ldb_request *req) goto done; } - tret = ltdb_add(module, msg); + tret = ltdb_add_internal(module, msg); if (tret != LDB_SUCCESS) { ret = LDB_ERR_OPERATIONS_ERROR; goto done; } - tret = ltdb_delete(module, req->op.rename.olddn); + tret = ltdb_delete_internal(module, req->op.rename.olddn); if (tret != LDB_SUCCESS) { - ltdb_delete(module, req->op.rename.newdn); + ltdb_delete_internal(module, req->op.rename.newdn); ret = LDB_ERR_OPERATIONS_ERROR; goto done; } @@ -889,36 +852,6 @@ done: return ret; } -static int ltdb_rename(struct ldb_module *module, const struct ldb_dn *olddn, const struct ldb_dn *newdn) -{ - struct ldb_request *req; - int ret; - - req = talloc_zero(module, struct ldb_request); - if (! req) { - return LDB_ERR_OPERATIONS_ERROR; - } - - req->operation = LDB_ASYNC_RENAME; - req->op.rename.olddn = olddn; - req->op.rename.newdn = newdn; - req->controls = NULL; - req->async.context = NULL; - req->async.callback = NULL; - - ret = ltdb_rename_async(module, req); - - if (ret != LDB_SUCCESS) { - talloc_free(req); - return ret; - } - - ret = ldb_async_wait(req->async.handle, LDB_WAIT_ALL); - - talloc_free(req); - return ret; -} - static int ltdb_start_trans(struct ldb_module *module) { struct ltdb_private *ltdb = module->private_data; @@ -960,43 +893,15 @@ static int ltdb_async_wait(struct ldb_async_handle *handle, enum ldb_async_wait_ static int ltdb_request(struct ldb_module *module, struct ldb_request *req) { /* check for oustanding critical controls and return an error if found */ - if (req->controls != NULL) { ldb_debug(module->ldb, LDB_DEBUG_WARNING, "Controls should not reach the ldb_tdb backend!\n"); - } - - if (check_critical_controls(req->controls)) { - return LDB_ERR_UNSUPPORTED_CRITICAL_EXTENSION; + if (check_critical_controls(req->controls)) { + return LDB_ERR_UNSUPPORTED_CRITICAL_EXTENSION; + } } - switch (req->operation) { - - case LDB_REQ_SEARCH: - return ltdb_search_bytree(module, - req->op.search.base, - req->op.search.scope, - req->op.search.tree, - req->op.search.attrs, - &req->op.search.res); - - case LDB_REQ_ADD: - return ltdb_add(module, req->op.add.message); - - case LDB_REQ_MODIFY: - return ltdb_modify(module, req->op.mod.message); - - case LDB_REQ_DELETE: - return ltdb_delete(module, req->op.del.dn); - - case LDB_REQ_RENAME: - return ltdb_rename(module, - req->op.rename.olddn, - req->op.rename.newdn); - - default: - return LDB_ERR_OPERATIONS_ERROR; - - } + /* search, add, modify, delete, rename are handled by their own, no other op supported */ + return LDB_ERR_OPERATIONS_ERROR; } /* @@ -1026,11 +931,11 @@ static uint64_t ltdb_sequence_number(struct ldb_context *ldb) static const struct ldb_module_ops ltdb_ops = { .name = "tdb", - .search = ltdb_search_async, - .add = ltdb_add_async, - .modify = ltdb_modify_async, - .del = ltdb_delete_async, - .rename = ltdb_rename_async, + .search = ltdb_search, + .add = ltdb_add, + .modify = ltdb_modify, + .del = ltdb_delete, + .rename = ltdb_rename, .request = ltdb_request, .start_transaction = ltdb_start_trans, .end_transaction = ltdb_end_trans, diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.h b/source4/lib/ldb/ldb_tdb/ldb_tdb.h index ad9e5c10c6..0c44a80edd 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.h +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.h @@ -100,11 +100,7 @@ int ltdb_add_attr_results(struct ldb_module *module, unsigned int *count, struct ldb_message ***res); int ltdb_filter_attrs(struct ldb_message *msg, const char * const *attrs); -int ltdb_search_async(struct ldb_module *module, struct ldb_request *req); -int ltdb_search_bytree(struct ldb_module *module, const struct ldb_dn *base, - enum ldb_scope scope, struct ldb_parse_tree *tree, - const char * const attrs[], struct ldb_result **res); - +int ltdb_search(struct ldb_module *module, struct ldb_request *req); /* The following definitions come from lib/ldb/ldb_tdb/ldb_tdb.c */ struct ldb_async_handle *init_ltdb_handle(struct ltdb_private *ltdb, struct ldb_module *module, -- cgit