diff options
author | Simo Sorce <idra@samba.org> | 2006-05-29 01:30:02 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 14:08:41 -0500 |
commit | 3a4d7eb2c08a06fac89c34d132f1c32751ce7ad5 (patch) | |
tree | 7d34281bba70aaa79d7527b823f00f625836dc3a /source4/lib/ldb | |
parent | 0bd3636a1249dd55f7595c06892e2db65af18bfc (diff) | |
download | samba-3a4d7eb2c08a06fac89c34d132f1c32751ce7ad5.tar.gz samba-3a4d7eb2c08a06fac89c34d132f1c32751ce7ad5.tar.bz2 samba-3a4d7eb2c08a06fac89c34d132f1c32751ce7ad5.zip |
r15927: Optimize ldb module traverse while keeping the API intact.
I was sick of jumping inot each module for each request,
even the ones not handle by that module.
(This used to be commit 7d65105e885a28584e8555453b90232c43a92bf7)
Diffstat (limited to 'source4/lib/ldb')
-rw-r--r-- | source4/lib/ldb/common/ldb.c | 44 | ||||
-rw-r--r-- | source4/lib/ldb/common/ldb_modules.c | 23 | ||||
-rw-r--r-- | source4/lib/ldb/include/ldb_private.h | 7 | ||||
-rw-r--r-- | source4/lib/ldb/ldb_ildap/ldb_ildap.c | 287 | ||||
-rw-r--r-- | source4/lib/ldb/ldb_ldap/ldb_ldap.c | 299 | ||||
-rw-r--r-- | source4/lib/ldb/ldb_tdb/ldb_search.c | 59 | ||||
-rw-r--r-- | source4/lib/ldb/ldb_tdb/ldb_tdb.c | 237 | ||||
-rw-r--r-- | source4/lib/ldb/ldb_tdb/ldb_tdb.h | 7 | ||||
-rw-r--r-- | source4/lib/ldb/modules/asq.c | 18 | ||||
-rw-r--r-- | source4/lib/ldb/modules/operational.c | 26 | ||||
-rw-r--r-- | source4/lib/ldb/modules/paged_results.c | 32 | ||||
-rw-r--r-- | source4/lib/ldb/modules/rdn_name.c | 10 | ||||
-rw-r--r-- | source4/lib/ldb/modules/skel.c | 28 | ||||
-rw-r--r-- | source4/lib/ldb/modules/sort.c | 14 |
14 files changed, 564 insertions, 527 deletions
diff --git a/source4/lib/ldb/common/ldb.c b/source4/lib/ldb/common/ldb.c index 3d5f816fe8..f348001456 100644 --- a/source4/lib/ldb/common/ldb.c +++ b/source4/lib/ldb/common/ldb.c @@ -280,7 +280,8 @@ static int ldb_op_finish(struct ldb_context *ldb, int status) */ int ldb_request(struct ldb_context *ldb, struct ldb_request *req) { - int status, started_transaction=0; + struct ldb_module *module; + int ret, started_transaction=0; ldb_reset_err_string(ldb); @@ -288,28 +289,52 @@ int ldb_request(struct ldb_context *ldb, struct ldb_request *req) req->op.search.res = NULL; } - /* start a transaction if not async and not search */ + /* start a transaction if SYNC and not search */ if ((!ldb->transaction_active) && (req->operation == LDB_REQ_ADD || req->operation == LDB_REQ_MODIFY || req->operation == LDB_REQ_DELETE || req->operation == LDB_REQ_RENAME)) { - status = ldb_transaction_start(ldb); - if (status != LDB_SUCCESS) { - talloc_free(req); - return status; + ret = ldb_transaction_start(ldb); + if (ret != LDB_SUCCESS) { + return ret; } started_transaction = 1; } /* call the first module in the chain */ - status = ldb->modules->ops->request(ldb->modules, req); + switch (req->operation) { + case LDB_ASYNC_SEARCH: + FIRST_OP(ldb, search); + ret = module->ops->search(module, req); + break; + case LDB_ASYNC_ADD: + FIRST_OP(ldb, add); + ret = module->ops->add(module, req); + break; + case LDB_ASYNC_MODIFY: + FIRST_OP(ldb, modify); + ret = module->ops->modify(module, req); + break; + case LDB_ASYNC_DELETE: + FIRST_OP(ldb, del); + ret = module->ops->del(module, req); + break; + case LDB_ASYNC_RENAME: + FIRST_OP(ldb, rename); + ret = module->ops->rename(module, req); + break; + default: + FIRST_OP(ldb, request); + ret = module->ops->request(module, req); + break; + } if (started_transaction) { - return ldb_op_finish(ldb, status); + return ldb_op_finish(ldb, ret); } - return status; + return ret; } /* @@ -453,7 +478,6 @@ static int ldb_autotransaction_request(struct ldb_context *ldb, struct ldb_reque } ret = ldb_request(ldb, req); - if (ret == LDB_SUCCESS) { ret = ldb_async_wait(req->async.handle, LDB_WAIT_ALL); } diff --git a/source4/lib/ldb/common/ldb_modules.c b/source4/lib/ldb/common/ldb_modules.c index bc27d1ed1b..4ce404d096 100644 --- a/source4/lib/ldb/common/ldb_modules.c +++ b/source4/lib/ldb/common/ldb_modules.c @@ -347,10 +347,29 @@ int ldb_load_modules(struct ldb_context *ldb, const char *options[]) /* helper functions to call the next module in chain */ + int ldb_next_request(struct ldb_module *module, struct ldb_request *request) { - FIND_OP(module, request); - return module->ops->request(module, request); + switch (request->operation) { + case LDB_ASYNC_SEARCH: + FIND_OP(module, search); + return module->ops->search(module, request); + case LDB_ASYNC_ADD: + FIND_OP(module, add); + return module->ops->add(module, request); + case LDB_ASYNC_MODIFY: + FIND_OP(module, modify); + return module->ops->modify(module, request); + case LDB_ASYNC_DELETE: + FIND_OP(module, del); + return module->ops->del(module, request); + case LDB_ASYNC_RENAME: + FIND_OP(module, rename); + return module->ops->rename(module, request); + default: + FIND_OP(module, request); + return module->ops->request(module, request); + } } int ldb_next_init(struct ldb_module *module) diff --git a/source4/lib/ldb/include/ldb_private.h b/source4/lib/ldb/include/ldb_private.h index 0ea6c4e9de..d8f9aa417d 100644 --- a/source4/lib/ldb/include/ldb_private.h +++ b/source4/lib/ldb/include/ldb_private.h @@ -57,7 +57,12 @@ struct ldb_module { struct ldb_module_ops { const char *name; int (*init_context) (struct ldb_module *); - int (*request)(struct ldb_module *, struct ldb_request *); + int (*search)(struct ldb_module *, struct ldb_request *); /* search */ + int (*add)(struct ldb_module *, struct ldb_request *); /* add */ + int (*modify)(struct ldb_module *, struct ldb_request *); /* modify */ + int (*del)(struct ldb_module *, struct ldb_request *); /* delete */ + int (*rename)(struct ldb_module *, struct ldb_request *); /* rename */ + int (*request)(struct ldb_module *, struct ldb_request *); /* match any other operation */ int (*start_transaction)(struct ldb_module *); int (*end_transaction)(struct ldb_module *); int (*del_transaction)(struct ldb_module *); diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index 0fa7af25ec..1454b565e0 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -385,27 +385,20 @@ static int ildb_request_send(struct ldb_module *module, struct ldap_message *msg /* search for matching records using an asynchronous function */ -static int ildb_search_async(struct ldb_module *module, const struct ldb_dn *base, - enum ldb_scope scope, struct ldb_parse_tree *tree, - const char * const *attrs, - struct ldb_control **control_req, - void *context, - int (*callback)(struct ldb_context *, void *, struct ldb_async_result *), - int timeout, - struct ldb_async_handle **handle) +static int ildb_search_async(struct ldb_module *module, struct ldb_request *req) { struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private); struct ldap_message *msg; int n; - *handle = NULL; + req->async.handle = NULL; - if (!callback || !context) { + if (!req->async.callback || !req->async.context) { ldb_set_errstring(module->ldb, talloc_asprintf(module, "Async interface called with NULL callback function or NULL context")); return LDB_ERR_OPERATIONS_ERROR; } - if (tree == NULL) { + if (req->op.search.tree == NULL) { ldb_set_errstring(module->ldb, talloc_asprintf(module, "Invalid expression parse tree")); return LDB_ERR_OPERATIONS_ERROR; } @@ -418,7 +411,7 @@ static int ildb_search_async(struct ldb_module *module, const struct ldb_dn *bas msg->type = LDAP_TAG_SearchRequest; - if (base == NULL) { + if (req->op.search.base == NULL) { if (ildb->rootDSE != NULL) { msg->r.SearchRequest.basedn = talloc_strdup(msg, ldb_msg_find_string(ildb->rootDSE, "defaultNamingContext", "")); @@ -426,7 +419,7 @@ static int ildb_search_async(struct ldb_module *module, const struct ldb_dn *bas msg->r.SearchRequest.basedn = talloc_strdup(msg, ""); } } else { - msg->r.SearchRequest.basedn = ldb_dn_linearize(msg, base); + msg->r.SearchRequest.basedn = ldb_dn_linearize(msg, req->op.search.base); } if (msg->r.SearchRequest.basedn == NULL) { ldb_set_errstring(module->ldb, talloc_asprintf(module, "Unable to determine baseDN")); @@ -434,24 +427,24 @@ static int ildb_search_async(struct ldb_module *module, const struct ldb_dn *bas return LDB_ERR_OPERATIONS_ERROR; } - if (scope == LDB_SCOPE_DEFAULT) { + if (req->op.search.scope == LDB_SCOPE_DEFAULT) { msg->r.SearchRequest.scope = LDB_SCOPE_SUBTREE; } else { - msg->r.SearchRequest.scope = scope; + msg->r.SearchRequest.scope = req->op.search.scope; } msg->r.SearchRequest.deref = LDAP_DEREFERENCE_NEVER; msg->r.SearchRequest.timelimit = 0; msg->r.SearchRequest.sizelimit = 0; msg->r.SearchRequest.attributesonly = 0; - msg->r.SearchRequest.tree = tree; + msg->r.SearchRequest.tree = req->op.search.tree; - for (n = 0; attrs && attrs[n]; n++) /* noop */ ; + for (n = 0; req->op.search.attrs && req->op.search.attrs[n]; n++) /* noop */ ; msg->r.SearchRequest.num_attributes = n; - msg->r.SearchRequest.attributes = discard_const(attrs); - msg->controls = control_req; + msg->r.SearchRequest.attributes = discard_const(req->op.search.attrs); + msg->controls = req->controls; - return ildb_request_send(module, msg, context, callback, timeout, handle); + return ildb_request_send(module, msg, req->async.context, req->async.callback, req->async.timeout, &(req->async.handle)); } static int ildb_search_sync_callback(struct ldb_context *ldb, void *context, struct ldb_async_result *ares) @@ -529,7 +522,7 @@ static int ildb_search_bytree(struct ldb_module *module, const struct ldb_dn *ba struct ldb_result **res) { struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private); - struct ldb_async_handle *handle; + struct ldb_request *req; int ret; *res = talloc_zero(ildb, struct ldb_result); @@ -537,12 +530,26 @@ static int ildb_search_bytree(struct ldb_module *module, const struct ldb_dn *ba return LDB_ERR_OPERATIONS_ERROR; } - ret = ildb_search_async(module, base, scope, tree, attrs, control_req, - res, &ildb_search_sync_callback, ildb->ldap->timeout, &handle); + req = talloc_zero(ildb, 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 = control_req; + req->async.context = (void *)res; + req->async.callback = ildb_search_sync_callback; + req->async.timeout = ildb->ldap->timeout; + + ret = ildb_search_async(module, req); if (ret == LDB_SUCCESS) { - ret = ldb_async_wait(handle, LDB_WAIT_ALL); - talloc_free(handle); + ret = ldb_async_wait(req->async.handle, LDB_WAIT_ALL); + talloc_free(req); } if (ret != LDB_SUCCESS) { @@ -555,21 +562,17 @@ static int ildb_search_bytree(struct ldb_module *module, const struct ldb_dn *ba /* add a record */ -static int ildb_add_async(struct ldb_module *module, const struct ldb_message *ldb_msg, - void *context, - int (*callback)(struct ldb_context *, void *, struct ldb_async_result *), - int timeout, - struct ldb_async_handle **handle) +static int ildb_add_async(struct ldb_module *module, struct ldb_request *req) { struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private); struct ldap_message *msg; struct ldap_mod **mods; int i,n; - *handle = NULL; + req->async.handle = NULL; /* ignore ltdb specials */ - if (ldb_dn_is_special(ldb_msg->dn)) { + if (ldb_dn_is_special(req->op.add.message->dn)) { return LDB_SUCCESS; } @@ -580,13 +583,13 @@ static int ildb_add_async(struct ldb_module *module, const struct ldb_message *l msg->type = LDAP_TAG_AddRequest; - msg->r.AddRequest.dn = ldb_dn_linearize(msg, ldb_msg->dn); + msg->r.AddRequest.dn = ldb_dn_linearize(msg, req->op.add.message->dn); if (msg->r.AddRequest.dn == NULL) { talloc_free(msg); return LDB_ERR_INVALID_DN_SYNTAX; } - mods = ildb_msg_to_mods(msg, &n, ldb_msg, 0); + mods = ildb_msg_to_mods(msg, &n, req->op.add.message, 0); if (mods == NULL) { talloc_free(msg); return LDB_ERR_OPERATIONS_ERROR; @@ -603,45 +606,54 @@ static int ildb_add_async(struct ldb_module *module, const struct ldb_message *l msg->r.AddRequest.attributes[i] = mods[i]->attrib; } - return ildb_request_send(module, msg, context, callback, timeout, handle); + return ildb_request_send(module, msg, req->async.context, req->async.callback, req->async.timeout, &(req->async.handle)); } static int ildb_add(struct ldb_module *module, const struct ldb_message *msg) { struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private); - struct ldb_async_handle *handle; + struct ldb_request *req; int ret; - ret = ildb_add_async(module, msg, - NULL, NULL, ildb->ldap->timeout, &handle); + req = talloc_zero(ildb, 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; + req->async.timeout = ildb->ldap->timeout; + + ret = ildb_add_async(module, req); - if (ret != LDB_SUCCESS) + if (ret != LDB_SUCCESS) { + talloc_free(req); return ret; + } - ret = ldb_async_wait(handle, LDB_WAIT_ALL); + ret = ldb_async_wait(req->async.handle, LDB_WAIT_ALL); - talloc_free(handle); + talloc_free(req); return ret; } /* modify a record */ -static int ildb_modify_async(struct ldb_module *module, const struct ldb_message *ldb_msg, - void *context, - int (*callback)(struct ldb_context *, void *, struct ldb_async_result *), - int timeout, - struct ldb_async_handle **handle) +static int ildb_modify_async(struct ldb_module *module, struct ldb_request *req) { struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private); struct ldap_message *msg; struct ldap_mod **mods; int i,n; - *handle = NULL; + req->async.handle = NULL; /* ignore ltdb specials */ - if (ldb_dn_is_special(ldb_msg->dn)) { + if (ldb_dn_is_special(req->op.mod.message->dn)) { return LDB_SUCCESS; } @@ -652,13 +664,13 @@ static int ildb_modify_async(struct ldb_module *module, const struct ldb_message msg->type = LDAP_TAG_ModifyRequest; - msg->r.ModifyRequest.dn = ldb_dn_linearize(msg, ldb_msg->dn); + msg->r.ModifyRequest.dn = ldb_dn_linearize(msg, req->op.mod.message->dn); if (msg->r.ModifyRequest.dn == NULL) { talloc_free(msg); return LDB_ERR_INVALID_DN_SYNTAX; } - mods = ildb_msg_to_mods(msg, &n, ldb_msg, 1); + mods = ildb_msg_to_mods(msg, &n, req->op.mod.message, 1); if (mods == NULL) { talloc_free(msg); return LDB_ERR_OPERATIONS_ERROR; @@ -675,43 +687,56 @@ static int ildb_modify_async(struct ldb_module *module, const struct ldb_message msg->r.ModifyRequest.mods[i] = *mods[i]; } - return ildb_request_send(module, msg, context, callback, timeout, handle); + return ildb_request_send(module, msg, + req->async.context, + req->async.callback, + req->async.timeout, + &(req->async.handle)); } static int ildb_modify(struct ldb_module *module, const struct ldb_message *msg) { struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private); - struct ldb_async_handle *handle; + struct ldb_request *req; int ret; - ret = ildb_modify_async(module, msg, - NULL, NULL, ildb->ldap->timeout, &handle); + req = talloc_zero(ildb, 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; + req->async.timeout = ildb->ldap->timeout; + + ret = ildb_modify_async(module, req); - if (ret != LDB_SUCCESS) + if (ret != LDB_SUCCESS) { + talloc_free(req); return ret; + } - ret = ldb_async_wait(handle, LDB_WAIT_ALL); + ret = ldb_async_wait(req->async.handle, LDB_WAIT_ALL); - talloc_free(handle); + talloc_free(req); return ret; } /* delete a record */ -static int ildb_delete_async(struct ldb_module *module, const struct ldb_dn *dn, - void *context, - int (*callback)(struct ldb_context *, void *, struct ldb_async_result *), - int timeout, - struct ldb_async_handle **handle) +static int ildb_delete_async(struct ldb_module *module, struct ldb_request *req) { struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private); struct ldap_message *msg; - *handle = NULL; + req->async.handle = NULL; /* ignore ltdb specials */ - if (ldb_dn_is_special(dn)) { + if (ldb_dn_is_special(req->op.del.dn)) { return LDB_SUCCESS; } @@ -722,50 +747,62 @@ static int ildb_delete_async(struct ldb_module *module, const struct ldb_dn *dn, msg->type = LDAP_TAG_DelRequest; - msg->r.DelRequest.dn = ldb_dn_linearize(msg, dn); + msg->r.DelRequest.dn = ldb_dn_linearize(msg, req->op.del.dn); if (msg->r.DelRequest.dn == NULL) { talloc_free(msg); return LDB_ERR_INVALID_DN_SYNTAX; } - return ildb_request_send(module, msg, context, callback, timeout, handle); + return ildb_request_send(module, msg, + req->async.context, + req->async.callback, + req->async.timeout, + &(req->async.handle)); } static int ildb_delete(struct ldb_module *module, const struct ldb_dn *dn) { struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private); - struct ldb_async_handle *handle; + struct ldb_request *req; int ret; - ret = ildb_delete_async(module, dn, - NULL, NULL, ildb->ldap->timeout, &handle); + req = talloc_zero(ildb, struct ldb_request); + if (! req) { + return LDB_ERR_OPERATIONS_ERROR; + } - if (ret != LDB_SUCCESS) + req->operation = LDB_ASYNC_DELETE; + req->op.del.dn = dn; + req->controls = NULL; + req->async.context = NULL; + req->async.callback = NULL; + req->async.timeout = ildb->ldap->timeout; + + ret = ildb_delete_async(module, req); + + if (ret != LDB_SUCCESS) { + talloc_free(req); return ret; + } - ret = ldb_async_wait(handle, LDB_WAIT_ALL); + ret = ldb_async_wait(req->async.handle, LDB_WAIT_ALL); - talloc_free(handle); + talloc_free(req); return ret; } /* rename a record */ -static int ildb_rename_async(struct ldb_module *module, - const struct ldb_dn *olddn, const struct ldb_dn *newdn, - void *context, - int (*callback)(struct ldb_context *, void *, struct ldb_async_result *), - int timeout, - struct ldb_async_handle **handle) +static int ildb_rename_async(struct ldb_module *module, struct ldb_request *req) { struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private); struct ldap_message *msg; - *handle = NULL; + req->async.handle = NULL; /* ignore ltdb specials */ - if (ldb_dn_is_special(olddn) || ldb_dn_is_special(newdn)) { + if (ldb_dn_is_special(req->op.rename.olddn) || ldb_dn_is_special(req->op.rename.newdn)) { return LDB_SUCCESS; } @@ -775,7 +812,7 @@ static int ildb_rename_async(struct ldb_module *module, } msg->type = LDAP_TAG_ModifyDNRequest; - msg->r.ModifyDNRequest.dn = ldb_dn_linearize(msg, olddn); + msg->r.ModifyDNRequest.dn = ldb_dn_linearize(msg, req->op.rename.olddn); if (msg->r.ModifyDNRequest.dn == NULL) { talloc_free(msg); return LDB_ERR_INVALID_DN_SYNTAX; @@ -783,8 +820,8 @@ static int ildb_rename_async(struct ldb_module *module, msg->r.ModifyDNRequest.newrdn = talloc_asprintf(msg, "%s=%s", - newdn->components[0].name, - ldb_dn_escape_value(msg, newdn->components[0].value)); + req->op.rename.newdn->components[0].name, + ldb_dn_escape_value(msg, req->op.rename.newdn->components[0].value)); if (msg->r.ModifyDNRequest.newrdn == NULL) { talloc_free(msg); return LDB_ERR_OPERATIONS_ERROR; @@ -792,7 +829,7 @@ static int ildb_rename_async(struct ldb_module *module, msg->r.ModifyDNRequest.newsuperior = ldb_dn_linearize(msg, - ldb_dn_get_parent(msg, newdn)); + ldb_dn_get_parent(msg, req->op.rename.newdn)); if (msg->r.ModifyDNRequest.newsuperior == NULL) { talloc_free(msg); return LDB_ERR_INVALID_DN_SYNTAX; @@ -800,24 +837,42 @@ static int ildb_rename_async(struct ldb_module *module, msg->r.ModifyDNRequest.deleteolddn = True; - return ildb_request_send(module, msg, context, callback, timeout, handle); + return ildb_request_send(module, msg, + req->async.context, + req->async.callback, + req->async.timeout, + &(req->async.handle)); } static int ildb_rename(struct ldb_module *module, const struct ldb_dn *olddn, const struct ldb_dn *newdn) { struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private); - struct ldb_async_handle *handle; + struct ldb_request *req; int ret; - ret = ildb_rename_async(module, olddn, newdn, - NULL, NULL, ildb->ldap->timeout, &handle); + req = talloc_zero(ildb, 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; + req->async.timeout = ildb->ldap->timeout; - if (ret != LDB_SUCCESS) + ret = ildb_rename_async(module, req); + + if (ret != LDB_SUCCESS) { + talloc_free(req); return ret; + } - ret = ldb_async_wait(handle, LDB_WAIT_ALL); + ret = ldb_async_wait(req->async.handle, LDB_WAIT_ALL); - talloc_free(handle); + talloc_free(req); return ret; } @@ -869,51 +924,6 @@ static int ildb_request(struct ldb_module *module, struct ldb_request *req) req->op.rename.olddn, req->op.rename.newdn); - case LDB_ASYNC_SEARCH: - return ildb_search_async(module, - req->op.search.base, - req->op.search.scope, - req->op.search.tree, - req->op.search.attrs, - req->controls, - req->async.context, - req->async.callback, - req->async.timeout, - &req->async.handle); - - case LDB_ASYNC_ADD: - return ildb_add_async(module, - req->op.add.message, - req->async.context, - req->async.callback, - req->async.timeout, - &req->async.handle); - - case LDB_ASYNC_MODIFY: - return ildb_modify_async(module, - req->op.mod.message, - req->async.context, - req->async.callback, - req->async.timeout, - &req->async.handle); - - case LDB_ASYNC_DELETE: - return ildb_delete_async(module, - req->op.del.dn, - req->async.context, - req->async.callback, - req->async.timeout, - &req->async.handle); - - case LDB_ASYNC_RENAME: - return ildb_rename_async(module, - req->op.rename.olddn, - req->op.rename.newdn, - req->async.context, - req->async.callback, - req->async.timeout, - &req->async.handle); - default: return -1; @@ -977,6 +987,11 @@ static int ildb_init(struct ldb_module *module) static const struct ldb_module_ops ildb_ops = { .name = "ldap", + .search = ildb_search_async, + .add = ildb_add_async, + .modify = ildb_modify_async, + .del = ildb_delete_async, + .rename = ildb_rename_async, .request = ildb_request, .start_transaction = ildb_start_trans, .end_transaction = ildb_end_trans, diff --git a/source4/lib/ldb/ldb_ldap/ldb_ldap.c b/source4/lib/ldb/ldb_ldap/ldb_ldap.c index c53db1f90c..f372e5fd04 100644 --- a/source4/lib/ldb/ldb_ldap/ldb_ldap.c +++ b/source4/lib/ldb/ldb_ldap/ldb_ldap.c @@ -224,14 +224,7 @@ static int lldb_add_msg_attr(struct ldb_context *ldb, /* search for matching records */ -static int lldb_search_async(struct ldb_module *module, const struct ldb_dn *base, - enum ldb_scope scope, struct ldb_parse_tree *tree, - const char * const *attrs, - struct ldb_control **control_req, - void *context, - int (*callback)(struct ldb_context *, void *, struct ldb_async_result *), - int timeout, - struct ldb_async_handle **handle) +static int lldb_search_async(struct ldb_module *module, struct ldb_request *req) { struct lldb_private *lldb = talloc_get_type(module->private_data, struct lldb_private); struct lldb_async_context *lldb_ac; @@ -241,44 +234,41 @@ static int lldb_search_async(struct ldb_module *module, const struct ldb_dn *bas char *expression; int ret; - if (!callback || !context) { + if (!req->async.callback || !req->async.context) { ldb_set_errstring(module->ldb, talloc_asprintf(module, "Async interface called with NULL callback function or NULL context")); return LDB_ERR_OPERATIONS_ERROR; } - if (tree == NULL) { + if (req->op.search.tree == NULL) { ldb_set_errstring(module->ldb, talloc_asprintf(module, "Invalid expression parse tree")); return LDB_ERR_OPERATIONS_ERROR; } - if (control_req != NULL) { + if (req->controls != NULL) { ldb_debug(module->ldb, LDB_DEBUG_WARNING, "Controls are not yet supported by ldb_ldap backend!\n"); } - *handle = init_handle(lldb, module, context, callback, timeout); - if (*handle == NULL) { - talloc_free(*handle); + req->async.handle = init_handle(lldb, module, req->async.context, req->async.callback, req->async.timeout); + if (req->async.handle == NULL) { return LDB_ERR_OPERATIONS_ERROR; } - lldb_ac = talloc_get_type((*handle)->private_data, struct lldb_async_context); + lldb_ac = talloc_get_type(req->async.handle->private_data, struct lldb_async_context); - search_base = ldb_dn_linearize(lldb_ac, base); - if (base == NULL) { + search_base = ldb_dn_linearize(lldb_ac, req->op.search.base); + if (req->op.search.base == NULL) { search_base = talloc_strdup(lldb_ac, ""); } if (search_base == NULL) { - talloc_free(*handle); return LDB_ERR_OPERATIONS_ERROR; } - expression = ldb_filter_from_tree(lldb_ac, tree); + expression = ldb_filter_from_tree(lldb_ac, req->op.search.tree); if (expression == NULL) { - talloc_free(*handle); return LDB_ERR_OPERATIONS_ERROR; } - switch (scope) { + switch (req->op.search.scope) { case LDB_SCOPE_BASE: ldap_scope = LDAP_SCOPE_BASE; break; @@ -290,12 +280,12 @@ static int lldb_search_async(struct ldb_module *module, const struct ldb_dn *bas break; } - tv.tv_sec = timeout; + tv.tv_sec = req->async.timeout; tv.tv_usec = 0; ret = ldap_search_ext(lldb->ldap, search_base, ldap_scope, expression, - discard_const_p(char *, attrs), + discard_const_p(char *, req->op.search.attrs), 0, NULL, NULL, @@ -305,8 +295,6 @@ static int lldb_search_async(struct ldb_module *module, const struct ldb_dn *bas if (ret != LDAP_SUCCESS) { ldb_set_errstring(module->ldb, talloc_strdup(module, ldap_err2string(ret))); - talloc_free(*handle); - *handle = NULL; } return lldb_ldap_to_ldb(ret); @@ -389,7 +377,7 @@ static int lldb_search_bytree(struct ldb_module *module, const struct ldb_dn *ba struct ldb_result **res) { struct lldb_private *lldb = talloc_get_type(module->private_data, struct lldb_private); - struct ldb_async_handle *handle; + struct ldb_request *req; int ret; *res = talloc_zero(lldb, struct ldb_result); @@ -397,12 +385,26 @@ static int lldb_search_bytree(struct ldb_module *module, const struct ldb_dn *ba return LDB_ERR_OPERATIONS_ERROR; } - ret = lldb_search_async(module, base, scope, tree, attrs, control_req, - res, &lldb_search_sync_callback, lldb->timeout, &handle); + req = talloc_zero(lldb, 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 = control_req; + req->async.context = (void *)res; + req->async.callback = lldb_search_sync_callback; + req->async.timeout = lldb->timeout; + + ret = lldb_search_async(module, req); if (ret == LDB_SUCCESS) { - ret = ldb_async_wait(handle, LDB_WAIT_ALL); - talloc_free(handle); + ret = ldb_async_wait(req->async.handle, LDB_WAIT_ALL); + talloc_free(req); } if (ret != LDB_SUCCESS) { @@ -415,11 +417,7 @@ static int lldb_search_bytree(struct ldb_module *module, const struct ldb_dn *ba /* add a record */ -static int lldb_add_async(struct ldb_module *module, const struct ldb_message *msg, - void *context, - int (*callback)(struct ldb_context *, void *, struct ldb_async_result *), - int timeout, - struct ldb_async_handle **handle) +static int lldb_add_async(struct ldb_module *module, struct ldb_request *req) { struct lldb_private *lldb = talloc_get_type(module->private_data, struct lldb_private); struct lldb_async_context *lldb_ac; @@ -428,26 +426,24 @@ static int lldb_add_async(struct ldb_module *module, const struct ldb_message *m int ret; /* ltdb specials should not reach this point */ - if (ldb_dn_is_special(msg->dn)) { + if (ldb_dn_is_special(req->op.add.message->dn)) { return LDB_ERR_INVALID_DN_SYNTAX; } - *handle = init_handle(lldb, module, context, callback, timeout); - if (*handle == NULL) { + req->async.handle = init_handle(lldb, module, req->async.context, req->async.callback, req->async.timeout); + if (req->async.handle == NULL) { return LDB_ERR_OPERATIONS_ERROR; } - lldb_ac = talloc_get_type((*handle)->private_data, struct lldb_async_context); + lldb_ac = talloc_get_type(req->async.handle->private_data, struct lldb_async_context); - mods = lldb_msg_to_mods(lldb_ac, msg, 0); + mods = lldb_msg_to_mods(lldb_ac, req->op.add.message, 0); if (mods == NULL) { - talloc_free(*handle); return LDB_ERR_OPERATIONS_ERROR; } - dn = ldb_dn_linearize(lldb_ac, msg->dn); + dn = ldb_dn_linearize(lldb_ac, req->op.add.message->dn); if (dn == NULL) { - talloc_free(*handle); return LDB_ERR_OPERATIONS_ERROR; } @@ -458,7 +454,6 @@ static int lldb_add_async(struct ldb_module *module, const struct ldb_message *m if (ret != LDAP_SUCCESS) { ldb_set_errstring(module->ldb, talloc_strdup(module, ldap_err2string(ret))); - talloc_free(*handle); } return lldb_ldap_to_ldb(ret); @@ -467,22 +462,31 @@ static int lldb_add_async(struct ldb_module *module, const struct ldb_message *m static int lldb_add(struct ldb_module *module, const struct ldb_message *msg) { struct lldb_private *lldb = talloc_get_type(module->private_data, struct lldb_private); - struct ldb_async_handle *handle; + struct ldb_request *req; int ret; - /* ldap does not understand ltdb specials */ - if (ldb_dn_is_special(msg->dn)) { - return LDB_SUCCESS; + req = talloc_zero(lldb, struct ldb_request); + if (! req) { + return LDB_ERR_OPERATIONS_ERROR; } - ret = lldb_add_async(module, msg, NULL, NULL, lldb->timeout, &handle); + req->operation = LDB_ASYNC_ADD; + req->op.add.message = msg; + req->controls = NULL; + req->async.context = NULL; + req->async.callback = NULL; + req->async.timeout = lldb->timeout; + + ret = lldb_add_async(module, req); - if (ret != LDB_SUCCESS) + if (ret != LDB_SUCCESS) { + talloc_free(req); return ret; + } - ret = ldb_async_wait(handle, LDB_WAIT_ALL); + ret = ldb_async_wait(req->async.handle, LDB_WAIT_ALL); - talloc_free(handle); + talloc_free(req); return ret; } @@ -490,11 +494,7 @@ static int lldb_add(struct ldb_module *module, const struct ldb_message *msg) /* modify a record */ -static int lldb_modify_async(struct ldb_module *module, const struct ldb_message *msg, - void *context, - int (*callback)(struct ldb_context *, void *, struct ldb_async_result *), - int timeout, - struct ldb_async_handle **handle) +static int lldb_modify_async(struct ldb_module *module, struct ldb_request *req) { struct lldb_private *lldb = talloc_get_type(module->private_data, struct lldb_private); struct lldb_async_context *lldb_ac; @@ -503,26 +503,24 @@ static int lldb_modify_async(struct ldb_module *module, const struct ldb_message int ret; /* ltdb specials should not reach this point */ - if (ldb_dn_is_special(msg->dn)) { + if (ldb_dn_is_special(req->op.mod.message->dn)) { return LDB_ERR_INVALID_DN_SYNTAX; } - *handle = init_handle(lldb, module, context, callback, timeout); - if (*handle == NULL) { + req->async.handle = init_handle(lldb, module, req->async.context, req->async.callback, req->async.timeout); + if (req->async.handle == NULL) { return LDB_ERR_OPERATIONS_ERROR; } - lldb_ac = talloc_get_type((*handle)->private_data, struct lldb_async_context); + lldb_ac = talloc_get_type(req->async.handle->private_data, struct lldb_async_context); - mods = lldb_msg_to_mods(lldb_ac, msg, 1); + mods = lldb_msg_to_mods(lldb_ac, req->op.mod.message, 1); if (mods == NULL) { - talloc_free(*handle); return LDB_ERR_OPERATIONS_ERROR; } - dn = ldb_dn_linearize(lldb_ac, msg->dn); + dn = ldb_dn_linearize(lldb_ac, req->op.mod.message->dn); if (dn == NULL) { - talloc_free(*handle); return LDB_ERR_OPERATIONS_ERROR; } @@ -533,7 +531,6 @@ static int lldb_modify_async(struct ldb_module *module, const struct ldb_message if (ret != LDAP_SUCCESS) { ldb_set_errstring(module->ldb, talloc_strdup(module, ldap_err2string(ret))); - talloc_free(*handle); } return lldb_ldap_to_ldb(ret); @@ -542,33 +539,38 @@ static int lldb_modify_async(struct ldb_module *module, const struct ldb_message static int lldb_modify(struct ldb_module *module, const struct ldb_message *msg) { struct lldb_private *lldb = talloc_get_type(module->private_data, struct lldb_private); - struct ldb_async_handle *handle; + struct ldb_request *req; int ret; - /* ldap does not understand ltdb specials */ - if (ldb_dn_is_special(msg->dn)) { - return LDB_SUCCESS; + req = talloc_zero(lldb, struct ldb_request); + if (! req) { + return LDB_ERR_OPERATIONS_ERROR; } - ret = lldb_modify_async(module, msg, NULL, NULL, lldb->timeout, &handle); + req->operation = LDB_ASYNC_MODIFY; + req->op.mod.message = msg; + req->controls = NULL; + req->async.context = NULL; + req->async.callback = NULL; + req->async.timeout = lldb->timeout; + + ret = lldb_modify_async(module, req); - if (ret != LDB_SUCCESS) + if (ret != LDB_SUCCESS) { + talloc_free(req); return ret; + } - ret = ldb_async_wait(handle, LDB_WAIT_ALL); + ret = ldb_async_wait(req->async.handle, LDB_WAIT_ALL); - talloc_free(handle); + talloc_free(req); return ret; } /* delete a record */ -static int lldb_delete_async(struct ldb_module *module, const struct ldb_dn *dn, - void *context, - int (*callback)(struct ldb_context *, void *, struct ldb_async_result *), - int timeout, - struct ldb_async_handle **handle) +static int lldb_delete_async(struct ldb_module *module, struct ldb_request *req) { struct lldb_private *lldb = talloc_get_type(module->private_data, struct lldb_private); struct lldb_async_context *lldb_ac; @@ -576,18 +578,18 @@ static int lldb_delete_async(struct ldb_module *module, const struct ldb_dn *dn, int ret; /* ltdb specials should not reach this point */ - if (ldb_dn_is_special(dn)) { + if (ldb_dn_is_special(req->op.del.dn)) { return LDB_ERR_INVALID_DN_SYNTAX; } - *handle = init_handle(lldb, module, context, callback, timeout); - if (*handle == NULL) { + req->async.handle = init_handle(lldb, module, req->async.context, req->async.callback, req->async.timeout); + if (req->async.handle == NULL) { return LDB_ERR_OPERATIONS_ERROR; } - lldb_ac = talloc_get_type((*handle)->private_data, struct lldb_async_context); + lldb_ac = talloc_get_type(req->async.handle->private_data, struct lldb_async_context); - dnstr = ldb_dn_linearize(lldb_ac, dn); + dnstr = ldb_dn_linearize(lldb_ac, req->op.del.dn); ret = ldap_delete_ext(lldb->ldap, dnstr, NULL, @@ -596,7 +598,6 @@ static int lldb_delete_async(struct ldb_module *module, const struct ldb_dn *dn, if (ret != LDAP_SUCCESS) { ldb_set_errstring(module->ldb, talloc_strdup(module, ldap_err2string(ret))); - talloc_free(*handle); } return lldb_ldap_to_ldb(ret); @@ -605,34 +606,38 @@ static int lldb_delete_async(struct ldb_module *module, const struct ldb_dn *dn, static int lldb_delete(struct ldb_module *module, const struct ldb_dn *dn) { struct lldb_private *lldb = talloc_get_type(module->private_data, struct lldb_private); - struct ldb_async_handle *handle; + struct ldb_request *req; int ret; - /* ignore ltdb specials */ - if (ldb_dn_is_special(dn)) { - return LDB_SUCCESS; + req = talloc_zero(lldb, struct ldb_request); + if (! req) { + return LDB_ERR_OPERATIONS_ERROR; } - ret = lldb_delete_async(module, dn, NULL, NULL, lldb->timeout, &handle); + req->operation = LDB_ASYNC_DELETE; + req->op.del.dn = dn; + req->controls = NULL; + req->async.context = NULL; + req->async.callback = NULL; + req->async.timeout = lldb->timeout; - if (ret != LDB_SUCCESS) + ret = lldb_delete_async(module, req); + + if (ret != LDB_SUCCESS) { + talloc_free(req); return ret; + } - ret = ldb_async_wait(handle, LDB_WAIT_ALL); + ret = ldb_async_wait(req->async.handle, LDB_WAIT_ALL); - talloc_free(handle); + talloc_free(req); return ret; } /* rename a record */ -static int lldb_rename_async(struct ldb_module *module, - const struct ldb_dn *olddn, const struct ldb_dn *newdn, - void *context, - int (*callback)(struct ldb_context *, void *, struct ldb_async_result *), - int timeout, - struct ldb_async_handle **handle) +static int lldb_rename_async(struct ldb_module *module, struct ldb_request *req) { struct lldb_private *lldb = talloc_get_type(module->private_data, struct lldb_private); struct lldb_async_context *lldb_ac; @@ -642,34 +647,31 @@ static int lldb_rename_async(struct ldb_module *module, int ret; /* ltdb specials should not reach this point */ - if (ldb_dn_is_special(olddn) || ldb_dn_is_special(newdn)) { + if (ldb_dn_is_special(req->op.rename.olddn) || ldb_dn_is_special(req->op.rename.newdn)) { return LDB_ERR_INVALID_DN_SYNTAX; } - *handle = init_handle(lldb, module, context, callback, timeout); - if (*handle == NULL) { + req->async.handle = init_handle(lldb, module, req->async.context, req->async.callback, req->async.timeout); + if (req->async.handle == NULL) { return LDB_ERR_OPERATIONS_ERROR; } - lldb_ac = talloc_get_type((*handle)->private_data, struct lldb_async_context); + lldb_ac = talloc_get_type(req->async.handle->private_data, struct lldb_async_context); - old_dn = ldb_dn_linearize(lldb_ac, olddn); + old_dn = ldb_dn_linearize(lldb_ac, req->op.rename.olddn); if (old_dn == NULL) { - talloc_free(*handle); return LDB_ERR_OPERATIONS_ERROR; } newrdn = talloc_asprintf(lldb_ac, "%s=%s", - newdn->components[0].name, - ldb_dn_escape_value(lldb, newdn->components[0].value)); + req->op.rename.newdn->components[0].name, + ldb_dn_escape_value(lldb, req->op.rename.newdn->components[0].value)); if (!newrdn) { - talloc_free(*handle); return LDB_ERR_OPERATIONS_ERROR; } - parentdn = ldb_dn_linearize(lldb_ac, ldb_dn_get_parent(lldb_ac, newdn)); + parentdn = ldb_dn_linearize(lldb_ac, ldb_dn_get_parent(lldb_ac, req->op.rename.newdn)); if (!parentdn) { - talloc_free(*handle); return LDB_ERR_OPERATIONS_ERROR; } @@ -679,7 +681,6 @@ static int lldb_rename_async(struct ldb_module *module, if (ret != LDAP_SUCCESS) { ldb_set_errstring(module->ldb, talloc_strdup(module, ldap_err2string(ret))); - talloc_free(*handle); } return lldb_ldap_to_ldb(ret); @@ -688,22 +689,32 @@ static int lldb_rename_async(struct ldb_module *module, static int lldb_rename(struct ldb_module *module, const struct ldb_dn *olddn, const struct ldb_dn *newdn) { struct lldb_private *lldb = talloc_get_type(module->private_data, struct lldb_private); - struct ldb_async_handle *handle; + struct ldb_request *req; int ret; - /* ignore ltdb specials */ - if (ldb_dn_is_special(olddn) || ldb_dn_is_special(newdn)) { - return LDB_SUCCESS; + req = talloc_zero(lldb, struct ldb_request); + if (! req) { + return LDB_ERR_OPERATIONS_ERROR; } - ret = lldb_rename_async(module, olddn, newdn, NULL, NULL, lldb->timeout, &handle); + 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; + req->async.timeout = lldb->timeout; + + ret = lldb_rename_async(module, req); - if (ret != LDB_SUCCESS) + if (ret != LDB_SUCCESS) { + talloc_free(req); return ret; + } - ret = ldb_async_wait(handle, LDB_WAIT_ALL); + ret = ldb_async_wait(req->async.handle, LDB_WAIT_ALL); - talloc_free(handle); + talloc_free(req); return ret; } @@ -984,51 +995,6 @@ static int lldb_request(struct ldb_module *module, struct ldb_request *req) req->op.rename.olddn, req->op.rename.newdn); - case LDB_ASYNC_SEARCH: - return lldb_search_async(module, - req->op.search.base, - req->op.search.scope, - req->op.search.tree, - req->op.search.attrs, - req->controls, - req->async.context, - req->async.callback, - req->async.timeout, - &req->async.handle); - - case LDB_ASYNC_ADD: - return lldb_add_async(module, - req->op.add.message, - req->async.context, - req->async.callback, - req->async.timeout, - &req->async.handle); - - case LDB_ASYNC_MODIFY: - return lldb_modify_async(module, - req->op.mod.message, - req->async.context, - req->async.callback, - req->async.timeout, - &req->async.handle); - - case LDB_ASYNC_DELETE: - return lldb_delete_async(module, - req->op.del.dn, - req->async.context, - req->async.callback, - req->async.timeout, - &req->async.handle); - - case LDB_ASYNC_RENAME: - return lldb_rename_async(module, - req->op.rename.olddn, - req->op.rename.newdn, - req->async.context, - req->async.callback, - req->async.timeout, - &req->async.handle); - default: return -1; @@ -1037,6 +1003,11 @@ static int lldb_request(struct ldb_module *module, struct ldb_request *req) static const struct ldb_module_ops lldb_ops = { .name = "ldap", + .search = lldb_search_async, + .add = lldb_add_async, + .modify = lldb_modify_async, + .del = lldb_delete_async, + .rename = lldb_rename_async, .request = lldb_request, .start_transaction = lldb_start_trans, .end_transaction = lldb_end_trans, diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index 0ab1442c2f..9b45697098 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -514,19 +514,14 @@ error: return LDB_ERR_OPERATIONS_ERROR; } -int ltdb_search_async(struct ldb_module *module, const struct ldb_dn *base, - enum ldb_scope scope, struct ldb_parse_tree *tree, - const char * const *attrs, - void *context, - int (*callback)(struct ldb_context *, void *, struct ldb_async_result *), - struct ldb_async_handle **handle) +int ltdb_search_async(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 ret; - if ((base == NULL || base->comp_num == 0) && - (scope == LDB_SCOPE_BASE || scope == LDB_SCOPE_ONELEVEL)) + if ((req->op.search.base == NULL || req->op.search.base->comp_num == 0) && + (req->op.search.scope == LDB_SCOPE_BASE || req->op.search.scope == LDB_SCOPE_ONELEVEL)) return LDB_ERR_OPERATIONS_ERROR; if (ltdb_lock_read(module) != 0) { @@ -538,32 +533,32 @@ int ltdb_search_async(struct ldb_module *module, const struct ldb_dn *base, return LDB_ERR_OPERATIONS_ERROR; } - if (tree == NULL) { + if (req->op.search.tree == NULL) { ltdb_unlock_read(module); return LDB_ERR_OPERATIONS_ERROR; } - *handle = init_ltdb_handle(ltdb, module, context, callback); - if (*handle == NULL) { + req->async.handle = init_ltdb_handle(ltdb, module, req->async.context, req->async.callback); + if (req->async.handle == NULL) { ltdb_unlock_read(module); return LDB_ERR_OPERATIONS_ERROR; } - ltdb_ac = talloc_get_type((*handle)->private_data, struct ltdb_async_context); + ltdb_ac = talloc_get_type(req->async.handle->private_data, struct ltdb_async_context); - ltdb_ac->tree = tree; - ltdb_ac->scope = scope; - ltdb_ac->base = base; - ltdb_ac->attrs = attrs; + ltdb_ac->tree = req->op.search.tree; + ltdb_ac->scope = req->op.search.scope; + ltdb_ac->base = req->op.search.base; + ltdb_ac->attrs = req->op.search.attrs; - ret = ltdb_search_indexed(*handle); + ret = ltdb_search_indexed(req->async.handle); if (ret == -1) { - ret = ltdb_search_full(*handle); + ret = ltdb_search_full(req->async.handle); } if (ret != LDB_SUCCESS) { ldb_set_errstring(module->ldb, talloc_strdup(module->ldb, "Indexed and full searches both failed!\n")); - (*handle)->state = LDB_ASYNC_DONE; - (*handle)->status = ret; + req->async.handle->state = LDB_ASYNC_DONE; + req->async.handle->status = ret; } ltdb_unlock_read(module); @@ -579,7 +574,7 @@ 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_async_handle *handle; + struct ldb_request *req; int ret; *res = talloc_zero(module, struct ldb_result); @@ -587,13 +582,25 @@ int ltdb_search_bytree(struct ldb_module *module, const struct ldb_dn *base, return LDB_ERR_OPERATIONS_ERROR; } - ret = ltdb_search_async(module, base, scope, tree, attrs, - res, <db_search_sync_callback, - &handle); + 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(handle, LDB_WAIT_ALL); - talloc_free(handle); + ret = ldb_async_wait(req->async.handle, LDB_WAIT_ALL); + talloc_free(req); } if (ret != LDB_SUCCESS) { diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index e0465afb30..e5b0ca0668 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -259,24 +259,21 @@ done: /* add a record to the database */ -static int ltdb_add_async(struct ldb_module *module, const struct ldb_message *msg, - void *context, - int (*callback)(struct ldb_context *, void *, struct ldb_async_result *), - struct ldb_async_handle **handle) +static int ltdb_add_async(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; - *handle = init_ltdb_handle(ltdb, module, context, callback); - if (*handle == NULL) { + 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((*handle)->private_data, struct ltdb_async_context); + ltdb_ac = talloc_get_type(req->async.handle->private_data, struct ltdb_async_context); - tret = ltdb_check_special_dn(module, msg); + tret = ltdb_check_special_dn(module, req->op.add.message); if (tret != LDB_SUCCESS) { - (*handle)->status = tret; + req->async.handle->status = tret; goto done; } @@ -285,37 +282,50 @@ static int ltdb_add_async(struct ldb_module *module, const struct ldb_message *m goto done; } - tret = ltdb_store(module, msg, TDB_INSERT); + tret = ltdb_store(module, req->op.add.message, TDB_INSERT); if (tret != LDB_SUCCESS) { - (*handle)->status = tret; + req->async.handle->status = tret; goto done; } - ltdb_modified(module, msg->dn); + ltdb_modified(module, req->op.add.message->dn); if (ltdb_ac->callback) { ret = ltdb_ac->callback(module->ldb, ltdb_ac->context, NULL); } done: - (*handle)->state = LDB_ASYNC_DONE; + req->async.handle->state = LDB_ASYNC_DONE; return ret; } static int ltdb_add(struct ldb_module *module, const struct ldb_message *msg) { - struct ldb_async_handle *handle; + struct ldb_request *req; int ret; - ret = ltdb_add_async(module, msg, NULL, NULL, &handle); + 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; - if (ret != LDB_SUCCESS) + ret = ltdb_add_async(module, req); + + if (ret != LDB_SUCCESS) { + talloc_free(req); return ret; + } - ret = ldb_async_wait(handle, LDB_WAIT_ALL); + ret = ldb_async_wait(req->async.handle, LDB_WAIT_ALL); - talloc_free(handle); + talloc_free(req); return ret; } @@ -347,27 +357,24 @@ int ltdb_delete_noindex(struct ldb_module *module, const struct ldb_dn *dn) /* delete a record from the database */ -static int ltdb_delete_async(struct ldb_module *module, const struct ldb_dn *dn, - void *context, - int (*callback)(struct ldb_context *, void *, struct ldb_async_result *), - struct ldb_async_handle **handle) +static int ltdb_delete_async(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; - *handle = NULL; + req->async.handle = NULL; if (ltdb_cache_load(module) != 0) { return LDB_ERR_OPERATIONS_ERROR; } - *handle = init_ltdb_handle(ltdb, module, context, callback); - if (*handle == NULL) { + 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((*handle)->private_data, struct ltdb_async_context); + ltdb_ac = talloc_get_type(req->async.handle->private_data, struct ltdb_async_context); msg = talloc(ltdb_ac, struct ldb_message); if (msg == NULL) { @@ -377,48 +384,61 @@ static int ltdb_delete_async(struct ldb_module *module, const struct ldb_dn *dn, /* in case any attribute of the message was indexed, we need to fetch the old record */ - tret = ltdb_search_dn1(module, dn, msg); + tret = ltdb_search_dn1(module, req->op.del.dn, msg); if (tret != 1) { /* not finding the old record is an error */ - (*handle)->status = LDB_ERR_NO_SUCH_OBJECT; + req->async.handle->status = LDB_ERR_NO_SUCH_OBJECT; goto done; } - tret = ltdb_delete_noindex(module, dn); + tret = ltdb_delete_noindex(module, req->op.del.dn); if (tret != LDB_SUCCESS) { - (*handle)->status = LDB_ERR_NO_SUCH_OBJECT; + req->async.handle->status = LDB_ERR_NO_SUCH_OBJECT; goto done; } /* remove any indexed attributes */ tret = ltdb_index_del(module, msg); if (tret != LDB_SUCCESS) { - (*handle)->status = LDB_ERR_NO_SUCH_OBJECT; + req->async.handle->status = LDB_ERR_NO_SUCH_OBJECT; goto done; } - ltdb_modified(module, dn); + ltdb_modified(module, req->op.del.dn); if (ltdb_ac->callback) ret = ltdb_ac->callback(module->ldb, ltdb_ac->context, NULL); done: - (*handle)->state = LDB_ASYNC_DONE; + req->async.handle->state = LDB_ASYNC_DONE; return ret; } static int ltdb_delete(struct ldb_module *module, const struct ldb_dn *dn) { - struct ldb_async_handle *handle; + struct ldb_request *req; int ret; - ret = ltdb_delete_async(module, dn, NULL, NULL, &handle); + 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) + if (ret != LDB_SUCCESS) { + talloc_free(req); return ret; + } - ret = ldb_async_wait(handle, LDB_WAIT_ALL); + ret = ldb_async_wait(req->async.handle, LDB_WAIT_ALL); - talloc_free(handle); + talloc_free(req); return ret; } @@ -734,26 +754,23 @@ failed: /* modify a record */ -static int ltdb_modify_async(struct ldb_module *module, const struct ldb_message *msg, - void *context, - int (*callback)(struct ldb_context *, void *, struct ldb_async_result *), - struct ldb_async_handle **handle) +static int ltdb_modify_async(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; - *handle = NULL; + req->async.handle = NULL; - *handle = init_ltdb_handle(ltdb, module, context, callback); - if (*handle == NULL) { + 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((*handle)->private_data, struct ltdb_async_context); + ltdb_ac = talloc_get_type(req->async.handle->private_data, struct ltdb_async_context); - tret = ltdb_check_special_dn(module, msg); + tret = ltdb_check_special_dn(module, req->op.mod.message); if (tret != LDB_SUCCESS) { - (*handle)->status = tret; + req->async.handle->status = tret; goto done; } @@ -762,63 +779,73 @@ static int ltdb_modify_async(struct ldb_module *module, const struct ldb_message goto done; } - tret = ltdb_modify_internal(module, msg); + tret = ltdb_modify_internal(module, req->op.mod.message); if (tret != LDB_SUCCESS) { - (*handle)->status = tret; + req->async.handle->status = tret; goto done; } - ltdb_modified(module, msg->dn); + ltdb_modified(module, req->op.mod.message->dn); if (ltdb_ac->callback) ret = ltdb_ac->callback(module->ldb, ltdb_ac->context, NULL); done: - (*handle)->state = LDB_ASYNC_DONE; + req->async.handle->state = LDB_ASYNC_DONE; return ret; } static int ltdb_modify(struct ldb_module *module, const struct ldb_message *msg) { - struct ldb_async_handle *handle; + struct ldb_request *req; int ret; - ret = ltdb_modify_async(module, msg, NULL, NULL, &handle); + 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) + if (ret != LDB_SUCCESS) { + talloc_free(req); return ret; + } - ret = ldb_async_wait(handle, LDB_WAIT_ALL); + ret = ldb_async_wait(req->async.handle, LDB_WAIT_ALL); - talloc_free(handle); + talloc_free(req); return ret; } /* rename a record */ -static int ltdb_rename_async(struct ldb_module *module, const struct ldb_dn *olddn, const struct ldb_dn *newdn, - void *context, - int (*callback)(struct ldb_context *, void *, struct ldb_async_result *), - struct ldb_async_handle **handle) +static int ltdb_rename_async(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; - *handle = NULL; + req->async.handle = NULL; if (ltdb_cache_load(module) != 0) { return LDB_ERR_OPERATIONS_ERROR; } - *handle = init_ltdb_handle(ltdb, module, context, callback); - if (*handle == NULL) { + 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((*handle)->private_data, struct ltdb_async_context); + ltdb_ac = talloc_get_type(req->async.handle->private_data, struct ltdb_async_context); msg = talloc(ltdb_ac, struct ldb_message); if (msg == NULL) { @@ -828,14 +855,14 @@ static int ltdb_rename_async(struct ldb_module *module, const struct ldb_dn *old /* in case any attribute of the message was indexed, we need to fetch the old record */ - tret = ltdb_search_dn1(module, olddn, msg); + tret = ltdb_search_dn1(module, req->op.rename.olddn, msg); if (tret != 1) { /* not finding the old record is an error */ - (*handle)->status = LDB_ERR_NO_SUCH_OBJECT; + req->async.handle->status = LDB_ERR_NO_SUCH_OBJECT; goto done; } - msg->dn = ldb_dn_copy(msg, newdn); + msg->dn = ldb_dn_copy(msg, req->op.rename.newdn); if (!msg->dn) { ret = LDB_ERR_OPERATIONS_ERROR; goto done; @@ -847,9 +874,9 @@ static int ltdb_rename_async(struct ldb_module *module, const struct ldb_dn *old goto done; } - tret = ltdb_delete(module, olddn); + tret = ltdb_delete(module, req->op.rename.olddn); if (tret != LDB_SUCCESS) { - ltdb_delete(module, newdn); + ltdb_delete(module, req->op.rename.newdn); ret = LDB_ERR_OPERATIONS_ERROR; goto done; } @@ -858,23 +885,37 @@ static int ltdb_rename_async(struct ldb_module *module, const struct ldb_dn *old ret = ltdb_ac->callback(module->ldb, ltdb_ac->context, NULL); done: - (*handle)->state = LDB_ASYNC_DONE; + req->async.handle->state = LDB_ASYNC_DONE; return ret; } static int ltdb_rename(struct ldb_module *module, const struct ldb_dn *olddn, const struct ldb_dn *newdn) { - struct ldb_async_handle *handle; + struct ldb_request *req; int ret; - ret = ltdb_rename_async(module, olddn, newdn, NULL, NULL, &handle); + req = talloc_zero(module, struct ldb_request); + if (! req) { + return LDB_ERR_OPERATIONS_ERROR; + } - if (ret != LDB_SUCCESS) + 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(handle, LDB_WAIT_ALL); + ret = ldb_async_wait(req->async.handle, LDB_WAIT_ALL); - talloc_free(handle); + talloc_free(req); return ret; } @@ -952,45 +993,6 @@ static int ltdb_request(struct ldb_module *module, struct ldb_request *req) req->op.rename.olddn, req->op.rename.newdn); - case LDB_ASYNC_SEARCH: - return ltdb_search_async(module, - req->op.search.base, - req->op.search.scope, - req->op.search.tree, - req->op.search.attrs, - req->async.context, - req->async.callback, - &req->async.handle); - - case LDB_ASYNC_ADD: - return ltdb_add_async(module, - req->op.add.message, - req->async.context, - req->async.callback, - &req->async.handle); - - case LDB_ASYNC_MODIFY: - return ltdb_modify_async(module, - req->op.mod.message, - req->async.context, - req->async.callback, - &req->async.handle); - - case LDB_ASYNC_DELETE: - return ltdb_delete_async(module, - req->op.del.dn, - req->async.context, - req->async.callback, - &req->async.handle); - - case LDB_ASYNC_RENAME: - return ltdb_rename_async(module, - req->op.rename.olddn, - req->op.rename.newdn, - req->async.context, - req->async.callback, - &req->async.handle); - default: return LDB_ERR_OPERATIONS_ERROR; @@ -1024,6 +1026,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, .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 196103ad6b..ad9e5c10c6 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.h +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.h @@ -100,12 +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, const struct ldb_dn *base, - enum ldb_scope scope, struct ldb_parse_tree *tree, - const char * const *attrs, - void *context, - int (*callback)(struct ldb_context *, void *, struct ldb_async_result *), - struct ldb_async_handle **handle); +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); diff --git a/source4/lib/ldb/modules/asq.c b/source4/lib/ldb/modules/asq.c index de5a0e34b7..3a29d3f266 100644 --- a/source4/lib/ldb/modules/asq.c +++ b/source4/lib/ldb/modules/asq.c @@ -77,7 +77,7 @@ static int build_response(struct ldb_result *res, int result) } /* search */ -static int asq_search(struct ldb_module *module, struct ldb_control *control, struct ldb_request *req) +static int asq_search_sync(struct ldb_module *module, struct ldb_control *control, struct ldb_request *req) { struct ldb_asq_control *asq_ctrl; struct ldb_request *base_req; @@ -352,14 +352,22 @@ error: return LDB_ERR_OPERATIONS_ERROR; } -static int asq_search_async(struct ldb_module *module, struct ldb_control *control, struct ldb_request *req) +static int asq_search(struct ldb_module *module, struct ldb_request *req) { + struct ldb_control *control; struct ldb_asq_control *asq_ctrl; struct asq_async_context *ac; struct ldb_async_handle *h; char **base_attrs; int ret; + /* check if there's a paged request control */ + control = get_control_from_list(req->controls, LDB_CONTROL_ASQ_OID); + if (control == NULL) { + /* not found go on */ + return ldb_next_request(module, req); + } + req->async.handle = NULL; if (!req->async.callback || !req->async.context) { @@ -590,11 +598,8 @@ static int asq(struct ldb_module *module, struct ldb_request *req) switch (req->operation) { case LDB_REQ_SEARCH: - return asq_search(module, control, req); + return asq_search_sync(module, control, req); - case LDB_ASYNC_SEARCH: - return asq_search_async(module, control, req); - default: return LDB_ERR_PROTOCOL_ERROR; @@ -622,6 +627,7 @@ static int asq_init(struct ldb_module *module) static const struct ldb_module_ops asq_ops = { .name = "asq", + .search = asq_search, .request = asq, .async_wait = asq_async_wait, .init_context = asq_init diff --git a/source4/lib/ldb/modules/operational.c b/source4/lib/ldb/modules/operational.c index d796e93e54..b47adf0652 100644 --- a/source4/lib/ldb/modules/operational.c +++ b/source4/lib/ldb/modules/operational.c @@ -295,7 +295,7 @@ static int add_uint64_element(struct ldb_message *msg, const char *attr, uint64_ /* hook add record ops */ -static int operational_add(struct ldb_module *module, struct ldb_request *req) +static int operational_add_sync(struct ldb_module *module, struct ldb_request *req) { const struct ldb_message *msg = req->op.add.message; time_t t = time(NULL); @@ -341,7 +341,7 @@ static int operational_add(struct ldb_module *module, struct ldb_request *req) /* hook modify record ops */ -static int operational_modify(struct ldb_module *module, struct ldb_request *req) +static int operational_modify_sync(struct ldb_module *module, struct ldb_request *req) { const struct ldb_message *msg = req->op.mod.message; time_t t = time(NULL); @@ -421,7 +421,7 @@ error: return LDB_ERR_OPERATIONS_ERROR; } -static int operational_search_async(struct ldb_module *module, struct ldb_request *req) +static int operational_search(struct ldb_module *module, struct ldb_request *req) { struct operational_async_context *ac; struct ldb_request *down_req; @@ -506,7 +506,7 @@ static int operational_search_async(struct ldb_module *module, struct ldb_reques /* hook add record ops */ -static int operational_add_async(struct ldb_module *module, struct ldb_request *req) +static int operational_add(struct ldb_module *module, struct ldb_request *req) { struct ldb_request *down_req; struct ldb_message *msg; @@ -560,7 +560,7 @@ static int operational_add_async(struct ldb_module *module, struct ldb_request * /* hook modify record ops */ -static int operational_modify_async(struct ldb_module *module, struct ldb_request *req) +static int operational_modify(struct ldb_module *module, struct ldb_request *req) { struct ldb_request *down_req; struct ldb_message *msg; @@ -617,19 +617,10 @@ static int operational_request(struct ldb_module *module, struct ldb_request *re return operational_search_bytree(module, req); case LDB_REQ_ADD: - return operational_add(module, req); + return operational_add_sync(module, req); case LDB_REQ_MODIFY: - return operational_modify(module, req); - - case LDB_ASYNC_SEARCH: - return operational_search_async(module, req); - - case LDB_ASYNC_ADD: - return operational_add_async(module, req); - - case LDB_ASYNC_MODIFY: - return operational_modify_async(module, req); + return operational_modify_sync(module, req); default: return ldb_next_request(module, req); @@ -650,6 +641,9 @@ static int operational_init(struct ldb_module *ctx) static const struct ldb_module_ops operational_ops = { .name = "operational", + .search = operational_search, + .add = operational_add, + .modify = operational_modify, .request = operational_request, .init_context = operational_init }; diff --git a/source4/lib/ldb/modules/paged_results.c b/source4/lib/ldb/modules/paged_results.c index 1b002716a5..fab1ca5ac1 100644 --- a/source4/lib/ldb/modules/paged_results.c +++ b/source4/lib/ldb/modules/paged_results.c @@ -123,7 +123,7 @@ static struct results_store *new_store(struct private_data *priv) } /* search */ -static int paged_search(struct ldb_module *module, struct ldb_control *control, struct ldb_request *req) +static int paged_search_sync(struct ldb_module *module, struct ldb_control *control, struct ldb_request *req) { struct private_data *private_data = talloc_get_type(module->private_data, struct private_data); struct results_store *current = NULL; @@ -364,15 +364,25 @@ error: return LDB_ERR_OPERATIONS_ERROR; } -static int paged_search_async(struct ldb_module *module, struct ldb_control *control, struct ldb_request *req) +static int paged_search(struct ldb_module *module, struct ldb_request *req) { - struct private_data *private_data = talloc_get_type(module->private_data, struct private_data); + struct ldb_control *control; + struct private_data *private_data; struct ldb_paged_control *paged_ctrl; struct ldb_control **saved_controls; struct paged_async_context *ac; struct ldb_async_handle *h; int ret; + /* check if there's a paged request control */ + control = get_control_from_list(req->controls, LDB_CONTROL_PAGED_RESULTS_OID); + if (control == NULL) { + /* not found go on */ + return ldb_next_request(module, req); + } + + private_data = talloc_get_type(module->private_data, struct private_data); + req->async.handle = NULL; if (!req->async.callback || !req->async.context) { @@ -463,7 +473,7 @@ static int paged_search_async(struct ldb_module *module, struct ldb_control *con } -static int paged_async_results(struct ldb_async_handle *handle) +static int paged_results(struct ldb_async_handle *handle) { struct paged_async_context *ac; struct ldb_paged_control *paged; @@ -590,7 +600,7 @@ static int paged_async_wait(struct ldb_async_handle *handle, enum ldb_async_wait if (ac->store->req->async.handle->state == LDB_ASYNC_DONE) { /* if lower level is finished we do not need to call it anymore */ /* return all we have until size == 0 or we empty storage */ - ret = paged_async_results(handle); + ret = paged_results(handle); /* we are done, if num_entries is zero free the storage * as that mean we delivered the last batch */ @@ -611,7 +621,7 @@ static int paged_async_wait(struct ldb_async_handle *handle, enum ldb_async_wait } } - ret = paged_async_results(handle); + ret = paged_results(handle); /* we are done, if num_entries is zero free the storage * as that mean we delivered the last batch */ @@ -634,7 +644,7 @@ static int paged_async_wait(struct ldb_async_handle *handle, enum ldb_async_wait if (ac->store->num_entries >= ac->size || ac->store->req->async.handle->state == LDB_ASYNC_DONE) { - ret = paged_async_results(handle); + ret = paged_results(handle); /* we are done, if num_entries is zero free the storage * as that mean we delivered the last batch */ @@ -660,10 +670,7 @@ static int paged_request(struct ldb_module *module, struct ldb_request *req) switch (req->operation) { case LDB_REQ_SEARCH: - return paged_search(module, control, req); - - case LDB_ASYNC_SEARCH: - return paged_search_async(module, control, req); + return paged_search_sync(module, control, req); default: return LDB_ERR_PROTOCOL_ERROR; @@ -707,7 +714,8 @@ static int paged_request_init(struct ldb_module *module) } static const struct ldb_module_ops paged_ops = { - .name = "paged_results", + .name = "paged_results", + .search = paged_search, .request = paged_request, .async_wait = paged_async_wait, .init_context = paged_request_init diff --git a/source4/lib/ldb/modules/rdn_name.c b/source4/lib/ldb/modules/rdn_name.c index 7ce6c29691..2004002e38 100644 --- a/source4/lib/ldb/modules/rdn_name.c +++ b/source4/lib/ldb/modules/rdn_name.c @@ -310,7 +310,7 @@ static int rdn_name_rename_do_mod(struct ldb_async_handle *h) { ac->step = RENAME_MODIFY; /* do the mod call */ - return ldb_next_request(h->module, ac->mod_req); + return ldb_request(h->module->ldb, ac->mod_req); } static int rename_async_wait(struct ldb_async_handle *handle) @@ -409,12 +409,6 @@ static int rdn_name_request(struct ldb_module *module, struct ldb_request *req) case LDB_REQ_ADD: return rdn_name_add_sync(module, req); - case LDB_ASYNC_ADD: - return rdn_name_add(module, req); - - case LDB_ASYNC_RENAME: - return rdn_name_rename(module, req); - default: return ldb_next_request(module, req); @@ -423,6 +417,8 @@ static int rdn_name_request(struct ldb_module *module, struct ldb_request *req) static const struct ldb_module_ops rdn_name_ops = { .name = "rdn_name", + .add = rdn_name_add, + .rename = rdn_name_rename, .request = rdn_name_request, .async_wait = rdn_name_async_wait }; diff --git a/source4/lib/ldb/modules/skel.c b/source4/lib/ldb/modules/skel.c index 2f3c2e8b57..2adef580b1 100644 --- a/source4/lib/ldb/modules/skel.c +++ b/source4/lib/ldb/modules/skel.c @@ -97,28 +97,7 @@ static int skel_destructor(struct ldb_module *ctx) static int skel_request(struct ldb_module *module, struct ldb_request *req) { - switch (req->operation) { - - case LDB_REQ_SEARCH: - return skel_search(module, req); - - case LDB_REQ_ADD: - return skel_add(module, req); - - case LDB_REQ_MODIFY: - return skel_modify(module, req); - - case LDB_REQ_DELETE: - return skel_delete(module, req); - - case LDB_REQ_RENAME: - return skel_rename(module, - req); - - default: - return ldb_next_request(module, req); - - } + return ldb_next_request(module, req); } static int skel_init(struct ldb_module *ctx) @@ -141,6 +120,11 @@ static int skel_init(struct ldb_module *ctx) static const struct ldb_module_ops skel_ops = { .name = "skel", .init_context = skel_init, + .search = skel_search, + .add = skel_add, + .modify = skel_modify, + .del = skel_delete, + .rename = skel_rename, .request = skel_request, .start_transaction = skel_start_trans, .end_transaction = skel_end_trans, diff --git a/source4/lib/ldb/modules/sort.c b/source4/lib/ldb/modules/sort.c index 3e1bbe92bd..9f03100dd0 100644 --- a/source4/lib/ldb/modules/sort.c +++ b/source4/lib/ldb/modules/sort.c @@ -340,14 +340,22 @@ error: return LDB_ERR_OPERATIONS_ERROR; } -static int server_sort_search_async(struct ldb_module *module, struct ldb_control *control, struct ldb_request *req) +static int server_sort_search_async(struct ldb_module *module, struct ldb_request *req) { + struct ldb_control *control; struct ldb_server_sort_control **sort_ctrls; struct ldb_control **saved_controls; struct sort_async_context *ac; struct ldb_async_handle *h; int ret; + /* check if there's a paged request control */ + control = get_control_from_list(req->controls, LDB_CONTROL_SERVER_SORT_OID); + if (control == NULL) { + /* not found go on */ + return ldb_next_request(module, req); + } + req->async.handle = NULL; if (!req->async.callback || !req->async.context) { @@ -543,9 +551,6 @@ static int server_sort(struct ldb_module *module, struct ldb_request *req) case LDB_REQ_SEARCH: return server_sort_search(module, control, req); - case LDB_ASYNC_SEARCH: - return server_sort_search_async(module, control, req); - default: return LDB_ERR_PROTOCOL_ERROR; @@ -579,6 +584,7 @@ static int server_sort_init(struct ldb_module *module) static const struct ldb_module_ops server_sort_ops = { .name = "server_sort", + .search = server_sort_search_async, .request = server_sort, .async_wait = server_sort_async_wait, .init_context = server_sort_init |