From 3725b1817f1e26370015d955622f0705e9121714 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sun, 15 Jan 2006 06:12:29 +0000 Subject: r12941: Add Attribute Scoped Search control want to see what it does ? do aq make test and try: ./bin/ldbsearch -H st/private/sam.ldb --controls=asq:1:member -s base -b 'CN=Administrators,CN=Builtin,DC=samba,DC=example,DC=com' 'objectclass=*' have fun. simo. (This used to be commit 900f4fd3435aacc3351f30afb77d3488d2cb4804) --- source4/lib/ldb/modules/asq.c | 220 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 220 insertions(+) create mode 100644 source4/lib/ldb/modules/asq.c (limited to 'source4/lib/ldb/modules/asq.c') diff --git a/source4/lib/ldb/modules/asq.c b/source4/lib/ldb/modules/asq.c new file mode 100644 index 0000000000..1fbf7521fb --- /dev/null +++ b/source4/lib/ldb/modules/asq.c @@ -0,0 +1,220 @@ +/* + ldb database library + + Copyright (C) Simo Sorce 2005 + + ** NOTE! The following LGPL license applies to the ldb + ** library. This does NOT imply that all of Samba is released + ** under the LGPL + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +/* + * Name: ldb + * + * Component: ldb attribute scoped query control module + * + * Description: this module searches all the the objects pointed + * by the DNs contained in the references attribute + * + * Author: Simo Sorce + */ + +#include "includes.h" +#include "ldb/include/includes.h" + +#define ASQ_CTRL_SUCCESS 0 +#define ASQ_CTRL_INVALID_ATTRIBUTE_SYNTAX 21 +#define ASQ_CTRL_UNWILLING_TO_PERFORM 53 +#define ASQ_CTRL_AFFECTS_MULTIPLE_DSA 71 + +static int build_response(struct ldb_result *res, int result) +{ + struct ldb_asq_control *asq; + int i; + + if (res->controls) { + for (i = 0; res->controls[i]; i++); + res->controls = talloc_realloc(res, res->controls, struct ldb_control *, i + 2); + } else { + i = 0; + res->controls = talloc_array(res, struct ldb_control *, 2); + } + if (res->controls == NULL) + return LDB_ERR_OPERATIONS_ERROR; + + res->controls[i] = talloc(res->controls, struct ldb_control); + if (res->controls[i] == NULL) + return LDB_ERR_OPERATIONS_ERROR; + + res->controls[i]->oid = LDB_CONTROL_ASQ_OID; + res->controls[i]->critical = 0; + + asq = talloc_zero(res->controls[i], struct ldb_asq_control); + if (asq == NULL) + return LDB_ERR_OPERATIONS_ERROR; + + asq->result = result; + + res->controls[i]->data = asq; + + res->controls[i + 1] = NULL; + + return LDB_SUCCESS; +} + +/* search */ +static int asq_search(struct ldb_module *module, struct ldb_request *req) +{ + struct ldb_control *control; + struct ldb_asq_control *asq_ctrl; + struct ldb_request *base_req; + struct ldb_message_element *el; + struct ldb_result *res; + char **base_attrs; + int i, c, 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); + } + + /* pre-allocate a clean result structure */ + req->op.search.res = res = talloc_zero(req, struct ldb_result); + if (res == NULL) + return LDB_ERR_OPERATIONS_ERROR; + + /* check the search is well formed */ + if (req->op.search.scope != LDB_SCOPE_BASE) { + return build_response(res, ASQ_CTRL_UNWILLING_TO_PERFORM); + } + + asq_ctrl = talloc_get_type(control->data, struct ldb_asq_control); + + /* get the object to retrieve the DNs to search */ + base_req = talloc_zero(req, struct ldb_request); + if (base_req == NULL) + return LDB_ERR_OPERATIONS_ERROR; + base_req->operation = LDB_REQ_SEARCH; + base_req->op.search.base = req->op.search.base; + base_req->op.search.scope = LDB_SCOPE_BASE; + base_req->op.search.tree = req->op.search.tree; + base_attrs = talloc_array(base_req, char *, 2); + if (base_attrs == NULL) + return LDB_ERR_OPERATIONS_ERROR; + base_attrs[0] = talloc_strdup(base_attrs, asq_ctrl->source_attribute); + if (base_attrs[0] == NULL) + return LDB_ERR_OPERATIONS_ERROR; + base_attrs[1] = NULL; + base_req->op.search.attrs = (const char * const *)base_attrs; + base_req->creds = req->creds; + + ret = ldb_request(module->ldb, base_req); + + if (ret != LDB_SUCCESS) + return ret; + + /* look up the DNs */ + el = ldb_msg_find_element(base_req->op.search.res->msgs[0], + asq_ctrl->source_attribute); + /* no values found */ + if (el == NULL) { + return build_response(res, ASQ_CTRL_SUCCESS); + } + + for (i = 0, c = 0; i < el->num_values; i++) { + struct ldb_request *exp_req; + + exp_req = talloc_zero(req, struct ldb_request); + if (exp_req == NULL) + return LDB_ERR_OPERATIONS_ERROR; + exp_req->operation = LDB_REQ_SEARCH; + exp_req->op.search.base = ldb_dn_explode(exp_req, el->values[i].data); + if (exp_req->op.search.base == NULL) { + build_response(res, ASQ_CTRL_INVALID_ATTRIBUTE_SYNTAX); + return LDB_ERR_OPERATIONS_ERROR; + } + exp_req->op.search.scope = LDB_SCOPE_BASE; + exp_req->op.search.tree = req->op.search.tree; + exp_req->op.search.attrs = req->op.search.attrs; + exp_req->creds = req->creds; + + ret = ldb_request(module->ldb, exp_req); + + if (ret != LDB_SUCCESS) + return ret; + + if (exp_req->op.search.res && exp_req->op.search.res->count != 0) { + if (res->msgs == NULL) { + res->msgs = talloc_array(res, + struct ldb_message *, 2); + } else { + res->msgs = talloc_realloc(res, res->msgs, + struct ldb_message *, c + 2); + } + if (res->msgs == NULL) + return LDB_ERR_OPERATIONS_ERROR; + + res->msgs[c] = talloc_steal(res->msgs, exp_req->op.search.res->msgs[0]); + c++; + } + + if (res->msgs) { + res->msgs[c] = NULL; + res->count = c; + } + + talloc_free(exp_req); + } + + return build_response(res, ASQ_CTRL_SUCCESS); +} + +static int asq(struct ldb_module *module, struct ldb_request *req) +{ + switch (req->operation) { + + case LDB_REQ_SEARCH: + return asq_search(module, req); + + default: + return ldb_next_request(module, req); + + } +} + +static const struct ldb_module_ops asq_ops = { + .name = "asq", + .request = asq +}; + +struct ldb_module *asq_module_init(struct ldb_context *ldb, const char *options[]) +{ + struct ldb_module *ctx; + + ctx = talloc(ldb, struct ldb_module); + if (!ctx) + return NULL; + + ctx->ldb = ldb; + ctx->prev = ctx->next = NULL; + ctx->ops = &asq_ops; + ctx->private_data = NULL; + + return ctx; +} -- cgit From 491a720354a53b2828454a92e3f4bd8f5bd28f1c Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sun, 15 Jan 2006 06:43:43 +0000 Subject: r12942: this way is better (This used to be commit 982576d2489c9ac3f7d854f598a64a8c4d91a485) --- source4/lib/ldb/modules/asq.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source4/lib/ldb/modules/asq.c') diff --git a/source4/lib/ldb/modules/asq.c b/source4/lib/ldb/modules/asq.c index 1fbf7521fb..70bb019074 100644 --- a/source4/lib/ldb/modules/asq.c +++ b/source4/lib/ldb/modules/asq.c @@ -146,8 +146,7 @@ static int asq_search(struct ldb_module *module, struct ldb_request *req) exp_req->operation = LDB_REQ_SEARCH; exp_req->op.search.base = ldb_dn_explode(exp_req, el->values[i].data); if (exp_req->op.search.base == NULL) { - build_response(res, ASQ_CTRL_INVALID_ATTRIBUTE_SYNTAX); - return LDB_ERR_OPERATIONS_ERROR; + return build_response(res, ASQ_CTRL_INVALID_ATTRIBUTE_SYNTAX); } exp_req->op.search.scope = LDB_SCOPE_BASE; exp_req->op.search.tree = req->op.search.tree; -- cgit From a45b4b7b99ed1fd93393ec770edace58502c6810 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Sun, 15 Jan 2006 19:04:51 +0000 Subject: r12948: fix compiler warning metze (This used to be commit 157fd2734dfb9b3ac6f6c5ad60bbbd7a50998453) --- source4/lib/ldb/modules/asq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/modules/asq.c') diff --git a/source4/lib/ldb/modules/asq.c b/source4/lib/ldb/modules/asq.c index 70bb019074..5d4a5a3970 100644 --- a/source4/lib/ldb/modules/asq.c +++ b/source4/lib/ldb/modules/asq.c @@ -144,7 +144,7 @@ static int asq_search(struct ldb_module *module, struct ldb_request *req) if (exp_req == NULL) return LDB_ERR_OPERATIONS_ERROR; exp_req->operation = LDB_REQ_SEARCH; - exp_req->op.search.base = ldb_dn_explode(exp_req, el->values[i].data); + exp_req->op.search.base = ldb_dn_explode(exp_req, (const char *)el->values[i].data); if (exp_req->op.search.base == NULL) { return build_response(res, ASQ_CTRL_INVALID_ATTRIBUTE_SYNTAX); } -- cgit From 3721bca79dc6ff409085a2fc40cbd060d25191d4 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sun, 5 Feb 2006 20:48:27 +0000 Subject: r13354: Add tests to check that controls work properly Fix asq module, add a second_stage_init to register with rootdse Fix asq control ldap parsing routines (this was nasty to find out) (This used to be commit 933a80397d137f7d5b79c82a068d62bb6928ef47) --- source4/lib/ldb/modules/asq.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'source4/lib/ldb/modules/asq.c') diff --git a/source4/lib/ldb/modules/asq.c b/source4/lib/ldb/modules/asq.c index 5d4a5a3970..7e6bbdf29e 100644 --- a/source4/lib/ldb/modules/asq.c +++ b/source4/lib/ldb/modules/asq.c @@ -197,9 +197,29 @@ static int asq(struct ldb_module *module, struct ldb_request *req) } } +static int asq_init_2(struct ldb_module *module) +{ + struct ldb_request request; + int ret; + + request.operation = LDB_REQ_REGISTER; + request.op.reg.oid = LDB_CONTROL_ASQ_OID; + request.controls = NULL; + + ret = ldb_request(module->ldb, &request); + if (ret != LDB_SUCCESS) { + ldb_debug(module->ldb, LDB_DEBUG_ERROR, "asq: Unable to register control with rootdse!\n"); + return LDB_ERR_OTHER; + } + + return ldb_next_second_stage_init(module); +} + + static const struct ldb_module_ops asq_ops = { .name = "asq", - .request = asq + .request = asq, + .second_stage_init = asq_init_2 }; struct ldb_module *asq_module_init(struct ldb_context *ldb, const char *options[]) -- cgit From 6addde849f3317fc6671477202ce9a0b712c28a3 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 6 Feb 2006 00:39:05 +0000 Subject: r13360: Fix crash bug when 0 results are returned on the internal base search (This used to be commit fbee725ae87efbcf5887c923d55d7cb0d05476a6) --- source4/lib/ldb/modules/asq.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'source4/lib/ldb/modules/asq.c') diff --git a/source4/lib/ldb/modules/asq.c b/source4/lib/ldb/modules/asq.c index 7e6bbdf29e..905bab480a 100644 --- a/source4/lib/ldb/modules/asq.c +++ b/source4/lib/ldb/modules/asq.c @@ -126,14 +126,22 @@ static int asq_search(struct ldb_module *module, struct ldb_request *req) ret = ldb_request(module->ldb, base_req); - if (ret != LDB_SUCCESS) + if (ret != LDB_SUCCESS) { + talloc_free(base_req); return ret; + } + if (base_req->op.search.res->count == 0) { + talloc_free(base_req); + return build_response(res, ASQ_CTRL_SUCCESS); + } + /* look up the DNs */ el = ldb_msg_find_element(base_req->op.search.res->msgs[0], asq_ctrl->source_attribute); /* no values found */ if (el == NULL) { + talloc_free(base_req); return build_response(res, ASQ_CTRL_SUCCESS); } @@ -181,6 +189,8 @@ static int asq_search(struct ldb_module *module, struct ldb_request *req) talloc_free(exp_req); } + talloc_free(base_req); + return build_response(res, ASQ_CTRL_SUCCESS); } -- cgit From 37bd0b655f2483b2a04fa4a53d55abcc7c9705bb Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 15 Feb 2006 15:13:05 +0000 Subject: r13507: the 'data' element of LDAP controls is optional. (prepare the next commit) metze (This used to be commit a1bbf7f2982185cb6cd544b65b4709ab33a850c5) --- source4/lib/ldb/modules/asq.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source4/lib/ldb/modules/asq.c') diff --git a/source4/lib/ldb/modules/asq.c b/source4/lib/ldb/modules/asq.c index 905bab480a..2975f4d832 100644 --- a/source4/lib/ldb/modules/asq.c +++ b/source4/lib/ldb/modules/asq.c @@ -105,6 +105,9 @@ static int asq_search(struct ldb_module *module, struct ldb_request *req) } asq_ctrl = talloc_get_type(control->data, struct ldb_asq_control); + if (!asq_ctrl) { + return LDB_ERR_PROTOCOL_ERROR; + } /* get the object to retrieve the DNs to search */ base_req = talloc_zero(req, struct ldb_request); -- cgit From 26af14c39b88b0e7eb53657b89be65d865804688 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 2 Mar 2006 16:32:53 +0000 Subject: r13786: [merge] Add registration functions for LDB modules Applications that use LDB modules will now have to run ldb_global_init() before they can use LDB. The next step will be adding support for loading LDB modules from .so files. This will also allow us to use one LDB without difference between the standalone and the Samba-specific build (This used to be commit 52a235650514039bf8ffee99a784bbc1b6ae6b92) --- source4/lib/ldb/modules/asq.c | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) (limited to 'source4/lib/ldb/modules/asq.c') diff --git a/source4/lib/ldb/modules/asq.c b/source4/lib/ldb/modules/asq.c index 2975f4d832..33ba9bed04 100644 --- a/source4/lib/ldb/modules/asq.c +++ b/source4/lib/ldb/modules/asq.c @@ -210,7 +210,7 @@ static int asq(struct ldb_module *module, struct ldb_request *req) } } -static int asq_init_2(struct ldb_module *module) +static int asq_init(struct ldb_module *module) { struct ldb_request request; int ret; @@ -225,28 +225,17 @@ static int asq_init_2(struct ldb_module *module) return LDB_ERR_OTHER; } - return ldb_next_second_stage_init(module); + return ldb_next_init(module); } static const struct ldb_module_ops asq_ops = { .name = "asq", .request = asq, - .second_stage_init = asq_init_2 + .init_context = asq_init }; -struct ldb_module *asq_module_init(struct ldb_context *ldb, const char *options[]) +int ldb_asq_init(void) { - struct ldb_module *ctx; - - ctx = talloc(ldb, struct ldb_module); - if (!ctx) - return NULL; - - ctx->ldb = ldb; - ctx->prev = ctx->next = NULL; - ctx->ops = &asq_ops; - ctx->private_data = NULL; - - return ctx; + return ldb_register_module(&asq_ops); } -- cgit From b1bf44a4e1190fe41440e731adaab9db14881508 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 13 Mar 2006 21:05:55 +0000 Subject: r14344: More helpful messages on error for command line specified controls fixes in paged_results asq -> async (This used to be commit fbd347544001da9e46246eb0b4a8d165ccab15c9) --- source4/lib/ldb/modules/asq.c | 388 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 377 insertions(+), 11 deletions(-) (limited to 'source4/lib/ldb/modules/asq.c') diff --git a/source4/lib/ldb/modules/asq.c b/source4/lib/ldb/modules/asq.c index 33ba9bed04..1449ece975 100644 --- a/source4/lib/ldb/modules/asq.c +++ b/source4/lib/ldb/modules/asq.c @@ -77,9 +77,8 @@ static int build_response(struct ldb_result *res, int result) } /* search */ -static int asq_search(struct ldb_module *module, struct ldb_request *req) +static int asq_search(struct ldb_module *module, struct ldb_control *control, struct ldb_request *req) { - struct ldb_control *control; struct ldb_asq_control *asq_ctrl; struct ldb_request *base_req; struct ldb_message_element *el; @@ -87,13 +86,6 @@ static int asq_search(struct ldb_module *module, struct ldb_request *req) char **base_attrs; int i, c, 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); - } - /* pre-allocate a clean result structure */ req->op.search.res = res = talloc_zero(req, struct ldb_result); if (res == NULL) @@ -197,15 +189,388 @@ static int asq_search(struct ldb_module *module, struct ldb_request *req) return build_response(res, ASQ_CTRL_SUCCESS); } +struct asq_async_context { + struct ldb_module *module; + void *up_context; + int (*up_callback)(struct ldb_context *, void *, struct ldb_async_result *); + int timeout; + + const char * const *req_attrs; + char *req_attribute; + int asq_ret; + + struct ldb_request *base_req; + struct ldb_async_result *base_res; + + struct ldb_request **reqs; + int num_reqs; + int cur_req; + + struct ldb_control **controls; +}; + +static struct ldb_async_handle *init_handle(void *mem_ctx, struct ldb_module *module, + void *context, + int (*callback)(struct ldb_context *, void *, struct ldb_async_result *), + int timeout) +{ + struct asq_async_context *ac; + struct ldb_async_handle *h; + + h = talloc_zero(mem_ctx, struct ldb_async_handle); + if (h == NULL) { + ldb_set_errstring(module->ldb, talloc_asprintf(module, "Out of Memory")); + return NULL; + } + + h->module = module; + + ac = talloc_zero(h, struct asq_async_context); + if (ac == NULL) { + ldb_set_errstring(module->ldb, talloc_asprintf(module, "Out of Memory")); + talloc_free(h); + return NULL; + } + + h->private_data = (void *)ac; + + h->state = LDB_ASYNC_INIT; + h->status = LDB_SUCCESS; + + ac->module = module; + ac->up_context = context; + ac->up_callback = callback; + ac->timeout = timeout; + + return h; +} + +static int asq_terminate(struct ldb_async_handle *handle) +{ + struct asq_async_context *ac; + struct ldb_async_result *ares; + struct ldb_asq_control *asq; + int i; + + ac = talloc_get_type(handle->private_data, struct asq_async_context); + + handle->status = LDB_SUCCESS; + handle->state = LDB_ASYNC_DONE; + + ares = talloc_zero(ac, struct ldb_async_result); + if (ares == NULL) + return LDB_ERR_OPERATIONS_ERROR; + + ares->type = LDB_REPLY_DONE; + + if (ac->controls) { + for (i = 0; ac->controls[i]; i++); + ares->controls = talloc_steal(ares, ac->controls); + } else { + i = 0; + } + + ares->controls = talloc_realloc(ares, ares->controls, struct ldb_control *, i + 2); + + if (ares->controls == NULL) + return LDB_ERR_OPERATIONS_ERROR; + + ares->controls[i] = talloc(ares->controls, struct ldb_control); + if (ares->controls[i] == NULL) + return LDB_ERR_OPERATIONS_ERROR; + + ares->controls[i]->oid = LDB_CONTROL_ASQ_OID; + ares->controls[i]->critical = 0; + + asq = talloc_zero(ares->controls[i], struct ldb_asq_control); + if (asq == NULL) + return LDB_ERR_OPERATIONS_ERROR; + + asq->result = ac->asq_ret; + + ares->controls[i]->data = asq; + + ares->controls[i + 1] = NULL; + + ac->up_callback(ac->module->ldb, ac->up_context, ares); + + return LDB_SUCCESS; +} + +static int asq_base_callback(struct ldb_context *ldb, void *context, struct ldb_async_result *ares) +{ + struct asq_async_context *ac; + + if (!context || !ares) { + ldb_set_errstring(ldb, talloc_asprintf(ldb, "NULL Context or Result in callback")); + goto error; + } + + ac = talloc_get_type(context, struct asq_async_context); + + /* we are interested only in the single reply (base search) we receive here */ + if (ares->type == LDB_REPLY_ENTRY) { + ac->base_res = talloc_steal(ac, ares); + } else { + talloc_free(ares); + } + + return LDB_SUCCESS; +error: + talloc_free(ares); + return LDB_ERR_OPERATIONS_ERROR; +} + +static int asq_reqs_callback(struct ldb_context *ldb, void *context, struct ldb_async_result *ares) +{ + struct asq_async_context *ac; + + if (!context || !ares) { + ldb_set_errstring(ldb, talloc_asprintf(ldb, "NULL Context or Result in callback")); + goto error; + } + + ac = talloc_get_type(context, struct asq_async_context); + + /* we are interested only in the single reply (base search) we receive here */ + if (ares->type == LDB_REPLY_ENTRY) { + + /* pass the message up to the original callback as we + * do not have to elaborate on it any further */ + return ac->up_callback(ac->module->ldb, ac->up_context, ares); + + } else { /* ignore any REFERRAL or DONE reply */ + talloc_free(ares); + } + + return LDB_SUCCESS; +error: + talloc_free(ares); + return LDB_ERR_OPERATIONS_ERROR; +} + +static int asq_search_async(struct ldb_module *module, struct ldb_control *control, struct ldb_request *req) +{ + struct ldb_asq_control *asq_ctrl; + struct asq_async_context *ac; + struct ldb_async_handle *h; + char **base_attrs; + int ret; + + req->async.handle = NULL; + + 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; + } + + asq_ctrl = talloc_get_type(control->data, struct ldb_asq_control); + if (!asq_ctrl) { + return LDB_ERR_PROTOCOL_ERROR; + } + + h = init_handle(req, module, req->async.context, req->async.callback, req->async.timeout); + if (!h) { + return LDB_ERR_OPERATIONS_ERROR; + } + ac = talloc_get_type(h->private_data, struct asq_async_context); + + req->async.handle = h; + + /* check the search is well formed */ + if (req->op.search.scope != LDB_SCOPE_BASE) { + ac->asq_ret = ASQ_CTRL_UNWILLING_TO_PERFORM; + return asq_terminate(h); + } + + ac->req_attrs = req->op.search.attrs; + ac->req_attribute = talloc_strdup(ac, asq_ctrl->source_attribute); + if (ac->req_attribute == NULL) + return LDB_ERR_OPERATIONS_ERROR; + + /* get the object to retrieve the DNs to search */ + ac->base_req = talloc_zero(req, struct ldb_request); + if (ac->base_req == NULL) + return LDB_ERR_OPERATIONS_ERROR; + ac->base_req->operation = req->operation; + ac->base_req->op.search.base = req->op.search.base; + ac->base_req->op.search.scope = LDB_SCOPE_BASE; + ac->base_req->op.search.tree = req->op.search.tree; + base_attrs = talloc_array(ac->base_req, char *, 2); + if (base_attrs == NULL) + return LDB_ERR_OPERATIONS_ERROR; + base_attrs[0] = talloc_strdup(base_attrs, asq_ctrl->source_attribute); + if (base_attrs[0] == NULL) + return LDB_ERR_OPERATIONS_ERROR; + base_attrs[1] = NULL; + ac->base_req->op.search.attrs = (const char * const *)base_attrs; + ac->base_req->creds = req->creds; + + ac->base_req->async.context = ac; + ac->base_req->async.callback = asq_base_callback; + ac->base_req->async.timeout = req->async.timeout; + + ret = ldb_request(module->ldb, ac->base_req); + + if (ret != LDB_SUCCESS) { + return ret; + } + + return LDB_SUCCESS; +} + +static int asq_async_requests(struct ldb_async_handle *handle) { + struct asq_async_context *ac; + struct ldb_message_element *el; + int i; + + ac = talloc_get_type(handle->private_data, struct asq_async_context); + + /* look up the DNs */ + el = ldb_msg_find_element(ac->base_res->message, ac->req_attribute); + /* no values found */ + if (el == NULL) { + ac->asq_ret = ASQ_CTRL_SUCCESS; + return asq_terminate(handle); + } + + /* build up the requests call chain */ + ac->num_reqs = el->num_values; + ac->cur_req = 0; + ac->reqs = talloc_array(ac, struct ldb_request *, ac->num_reqs); + if (ac->reqs == NULL) { + return LDB_ERR_OPERATIONS_ERROR; + } + + for (i = 0; i < el->num_values; i++) { + + ac->reqs[i] = talloc_zero(ac->reqs, struct ldb_request); + if (ac->reqs[i] == NULL) + return LDB_ERR_OPERATIONS_ERROR; + ac->reqs[i]->operation = LDB_ASYNC_SEARCH; + ac->reqs[i]->op.search.base = ldb_dn_explode(ac->reqs[i], (const char *)el->values[i].data); + if (ac->reqs[i]->op.search.base == NULL) { + ac->asq_ret = ASQ_CTRL_INVALID_ATTRIBUTE_SYNTAX; + return asq_terminate(handle); + } + ac->reqs[i]->op.search.scope = LDB_SCOPE_BASE; + ac->reqs[i]->op.search.tree = ac->base_req->op.search.tree; + ac->reqs[i]->op.search.attrs = ac->req_attrs; + ac->reqs[i]->creds = ac->base_req->creds; + + ac->reqs[i]->async.context = ac; + ac->reqs[i]->async.callback = asq_reqs_callback; + ac->reqs[i]->async.timeout = ac->base_req->async.timeout; + } + + return LDB_SUCCESS; +} + +static int asq_async_wait(struct ldb_async_handle *handle, enum ldb_async_wait_type type) +{ + struct asq_async_context *ac; + int ret; + + if (!handle || !handle->private_data) { + return LDB_ERR_OPERATIONS_ERROR; + } + + if (handle->state == LDB_ASYNC_DONE) { + return handle->status; + } + + handle->state = LDB_ASYNC_PENDING; + + ac = talloc_get_type(handle->private_data, struct asq_async_context); + + if (type == LDB_WAIT_ALL) { + while (ac->base_req->async.handle->state != LDB_ASYNC_DONE) { + ret = ldb_async_wait(ac->base_req->async.handle, type); + if (ret != LDB_SUCCESS) goto error; + } + + ret = asq_async_requests(handle); + if (ret != LDB_SUCCESS) goto error; + + for (; ac->cur_req < ac->num_reqs; ac->cur_req++) { + ret = ldb_request(ac->module->ldb, ac->reqs[ac->cur_req]); + if (ret != LDB_SUCCESS) goto error; + + while (ac->reqs[ac->cur_req]->async.handle->state != LDB_ASYNC_DONE) { + ret = ldb_async_wait(ac->reqs[ac->cur_req]->async.handle, type); + if (ret != LDB_SUCCESS) goto error; + } + } + + return asq_terminate(handle); + } + + /* type == LDB_WAIT_NONE */ + + if (ac->base_req->async.handle->state != LDB_ASYNC_DONE) { + ret = ldb_async_wait(ac->base_req->async.handle, type); + if (ret != LDB_SUCCESS) goto error; + + if (ac->base_req->async.handle->state != LDB_ASYNC_DONE) { + return ret; + } + } + + if (ac->reqs == NULL) { + /* need to build up the reqs array before calling out */ + ret = asq_async_requests(handle); + if (ret != LDB_SUCCESS) goto error; + } + + if (ac->cur_req < ac->num_reqs) { + + if (ac->reqs[ac->cur_req]->async.handle == NULL) { + ret = ldb_request(ac->module->ldb, ac->reqs[ac->cur_req]); + if (ret != LDB_SUCCESS) goto error; + } + + if (ac->reqs[ac->cur_req]->async.handle->state != LDB_ASYNC_DONE) { + ret = ldb_async_wait(ac->reqs[ac->cur_req]->async.handle, type); + if (ret != LDB_SUCCESS) goto error; + } + + if (ac->reqs[ac->cur_req]->async.handle->state == LDB_ASYNC_DONE) { + ac->cur_req++; + } + + return handle->status; + } + + return asq_terminate(handle); + +error: + handle->state = LDB_ASYNC_DONE; + handle->status = ret; + return ret; +} + static int asq(struct ldb_module *module, struct ldb_request *req) { + struct ldb_control *control; + + /* 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); + } + switch (req->operation) { case LDB_REQ_SEARCH: - return asq_search(module, req); + return asq_search(module, control, req); + + case LDB_ASYNC_SEARCH: + return asq_search_async(module, control, req); default: - return ldb_next_request(module, req); + return LDB_ERR_PROTOCOL_ERROR; } } @@ -232,6 +597,7 @@ static int asq_init(struct ldb_module *module) static const struct ldb_module_ops asq_ops = { .name = "asq", .request = asq, + .async_wait = asq_async_wait, .init_context = asq_init }; -- cgit From 90a5e19e03842b77fd7811965fb2603e552261bc Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sun, 28 May 2006 02:10:44 +0000 Subject: r15913: Error passing in the async code is not in agood shape Start enhancing it and fix some problems with incorrect evalutaion of the codes Implement rdn rename (async only) (This used to be commit 6af1d738b9668d4f0eb6194ac0f84af9e73f8c2e) --- source4/lib/ldb/modules/asq.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source4/lib/ldb/modules/asq.c') diff --git a/source4/lib/ldb/modules/asq.c b/source4/lib/ldb/modules/asq.c index 1449ece975..c682bd6359 100644 --- a/source4/lib/ldb/modules/asq.c +++ b/source4/lib/ldb/modules/asq.c @@ -481,9 +481,12 @@ static int asq_async_wait(struct ldb_async_handle *handle, enum ldb_async_wait_t } handle->state = LDB_ASYNC_PENDING; + handle->status = LDB_SUCCESS; ac = talloc_get_type(handle->private_data, struct asq_async_context); +/* TODO: make this like password_hash */ + if (type == LDB_WAIT_ALL) { while (ac->base_req->async.handle->state != LDB_ASYNC_DONE) { ret = ldb_async_wait(ac->base_req->async.handle, type); -- cgit From 3308a23850e5a61952e73b57800ad2b39e25d541 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sun, 28 May 2006 15:20:53 +0000 Subject: r15922: password_hash.c has proven to be a good way to research how to build an async module change asq.c to be more readble (This used to be commit 9197187c4290847721432db09bdfb2f1d06e51ba) --- source4/lib/ldb/modules/asq.c | 107 +++++++++++++++++++++++++----------------- 1 file changed, 65 insertions(+), 42 deletions(-) (limited to 'source4/lib/ldb/modules/asq.c') diff --git a/source4/lib/ldb/modules/asq.c b/source4/lib/ldb/modules/asq.c index c682bd6359..de5a0e34b7 100644 --- a/source4/lib/ldb/modules/asq.c +++ b/source4/lib/ldb/modules/asq.c @@ -190,6 +190,9 @@ static int asq_search(struct ldb_module *module, struct ldb_control *control, st } struct asq_async_context { + + enum {ASQ_SEARCH_BASE, ASQ_SEARCH_MULTI} step; + struct ldb_module *module; void *up_context; int (*up_callback)(struct ldb_context *, void *, struct ldb_async_result *); @@ -411,6 +414,8 @@ static int asq_search_async(struct ldb_module *module, struct ldb_control *contr ac->base_req->async.callback = asq_base_callback; ac->base_req->async.timeout = req->async.timeout; + ac->step = ASQ_SEARCH_BASE; + ret = ldb_request(module->ldb, ac->base_req); if (ret != LDB_SUCCESS) { @@ -464,10 +469,12 @@ static int asq_async_requests(struct ldb_async_handle *handle) { ac->reqs[i]->async.timeout = ac->base_req->async.timeout; } + ac->step = ASQ_SEARCH_MULTI; + return LDB_SUCCESS; } -static int asq_async_wait(struct ldb_async_handle *handle, enum ldb_async_wait_type type) +static int asq_async_wait_none(struct ldb_async_handle *handle) { struct asq_async_context *ac; int ret; @@ -485,74 +492,90 @@ static int asq_async_wait(struct ldb_async_handle *handle, enum ldb_async_wait_t ac = talloc_get_type(handle->private_data, struct asq_async_context); -/* TODO: make this like password_hash */ - if (type == LDB_WAIT_ALL) { - while (ac->base_req->async.handle->state != LDB_ASYNC_DONE) { - ret = ldb_async_wait(ac->base_req->async.handle, type); - if (ret != LDB_SUCCESS) goto error; + switch (ac->step) { + case ASQ_SEARCH_BASE: + ret = ldb_async_wait(ac->base_req->async.handle, LDB_WAIT_NONE); + + if (ret != LDB_SUCCESS) { + handle->status = ret; + goto done; } - ret = asq_async_requests(handle); - if (ret != LDB_SUCCESS) goto error; - - for (; ac->cur_req < ac->num_reqs; ac->cur_req++) { - ret = ldb_request(ac->module->ldb, ac->reqs[ac->cur_req]); - if (ret != LDB_SUCCESS) goto error; - - while (ac->reqs[ac->cur_req]->async.handle->state != LDB_ASYNC_DONE) { - ret = ldb_async_wait(ac->reqs[ac->cur_req]->async.handle, type); - if (ret != LDB_SUCCESS) goto error; - } + if (ac->base_req->async.handle->status != LDB_SUCCESS) { + handle->status = ac->base_req->async.handle->status; + goto done; } - - return asq_terminate(handle); - } - - /* type == LDB_WAIT_NONE */ - - if (ac->base_req->async.handle->state != LDB_ASYNC_DONE) { - ret = ldb_async_wait(ac->base_req->async.handle, type); - if (ret != LDB_SUCCESS) goto error; - if (ac->base_req->async.handle->state != LDB_ASYNC_DONE) { - return ret; + return LDB_SUCCESS; } - } - if (ac->reqs == NULL) { - /* need to build up the reqs array before calling out */ ret = asq_async_requests(handle); - if (ret != LDB_SUCCESS) goto error; - } - if (ac->cur_req < ac->num_reqs) { + case ASQ_SEARCH_MULTI: if (ac->reqs[ac->cur_req]->async.handle == NULL) { ret = ldb_request(ac->module->ldb, ac->reqs[ac->cur_req]); - if (ret != LDB_SUCCESS) goto error; + if (ret != LDB_SUCCESS) { + return ret; + } } - if (ac->reqs[ac->cur_req]->async.handle->state != LDB_ASYNC_DONE) { - ret = ldb_async_wait(ac->reqs[ac->cur_req]->async.handle, type); - if (ret != LDB_SUCCESS) goto error; + ret = ldb_async_wait(ac->reqs[ac->cur_req]->async.handle, LDB_WAIT_NONE); + + if (ret != LDB_SUCCESS) { + handle->status = ret; + goto done; + } + if (ac->reqs[ac->cur_req]->async.handle->status != LDB_SUCCESS) { + handle->status = ac->reqs[ac->cur_req]->async.handle->status; } if (ac->reqs[ac->cur_req]->async.handle->state == LDB_ASYNC_DONE) { ac->cur_req++; } - return handle->status; + if (ac->cur_req < ac->num_reqs) { + return LDB_SUCCESS; + } + + return asq_terminate(handle); + + default: + ret = LDB_ERR_OPERATIONS_ERROR; + goto done; } - return asq_terminate(handle); + ret = LDB_SUCCESS; -error: +done: handle->state = LDB_ASYNC_DONE; - handle->status = ret; return ret; } +static int asq_async_wait_all(struct ldb_async_handle *handle) +{ + int ret; + + while (handle->state != LDB_ASYNC_DONE) { + ret = asq_async_wait_none(handle); + if (ret != LDB_SUCCESS) { + return ret; + } + } + + return handle->status; +} + +static int asq_async_wait(struct ldb_async_handle *handle, enum ldb_async_wait_type type) +{ + if (type == LDB_WAIT_ALL) { + return asq_async_wait_all(handle); + } else { + return asq_async_wait_none(handle); + } +} + static int asq(struct ldb_module *module, struct ldb_request *req) { struct ldb_control *control; -- cgit From 3a4d7eb2c08a06fac89c34d132f1c32751ce7ad5 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 29 May 2006 01:30:02 +0000 Subject: 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) --- source4/lib/ldb/modules/asq.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'source4/lib/ldb/modules/asq.c') 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 -- cgit From 03703a58d7fe441ec5dcbe1814cea3f55544de55 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 29 May 2006 11:57:09 +0000 Subject: r15932: Remove per request creds They have never benn used and make little sense too imo (This used to be commit f0c1d08d50f8a3e25650ac85b178ec7a43e433d9) --- source4/lib/ldb/modules/asq.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'source4/lib/ldb/modules/asq.c') diff --git a/source4/lib/ldb/modules/asq.c b/source4/lib/ldb/modules/asq.c index 3a29d3f266..884616abdd 100644 --- a/source4/lib/ldb/modules/asq.c +++ b/source4/lib/ldb/modules/asq.c @@ -117,7 +117,6 @@ static int asq_search_sync(struct ldb_module *module, struct ldb_control *contro return LDB_ERR_OPERATIONS_ERROR; base_attrs[1] = NULL; base_req->op.search.attrs = (const char * const *)base_attrs; - base_req->creds = req->creds; ret = ldb_request(module->ldb, base_req); @@ -154,7 +153,6 @@ static int asq_search_sync(struct ldb_module *module, struct ldb_control *contro exp_req->op.search.scope = LDB_SCOPE_BASE; exp_req->op.search.tree = req->op.search.tree; exp_req->op.search.attrs = req->op.search.attrs; - exp_req->creds = req->creds; ret = ldb_request(module->ldb, exp_req); @@ -416,7 +414,6 @@ static int asq_search(struct ldb_module *module, struct ldb_request *req) return LDB_ERR_OPERATIONS_ERROR; base_attrs[1] = NULL; ac->base_req->op.search.attrs = (const char * const *)base_attrs; - ac->base_req->creds = req->creds; ac->base_req->async.context = ac; ac->base_req->async.callback = asq_base_callback; @@ -470,7 +467,6 @@ static int asq_async_requests(struct ldb_async_handle *handle) { ac->reqs[i]->op.search.scope = LDB_SCOPE_BASE; ac->reqs[i]->op.search.tree = ac->base_req->op.search.tree; ac->reqs[i]->op.search.attrs = ac->req_attrs; - ac->reqs[i]->creds = ac->base_req->creds; ac->reqs[i]->async.context = ac; ac->reqs[i]->async.callback = asq_reqs_callback; -- cgit 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/modules/asq.c | 169 ------------------------------------------ 1 file changed, 169 deletions(-) (limited to 'source4/lib/ldb/modules/asq.c') diff --git a/source4/lib/ldb/modules/asq.c b/source4/lib/ldb/modules/asq.c index 884616abdd..005d1e41b0 100644 --- a/source4/lib/ldb/modules/asq.c +++ b/source4/lib/ldb/modules/asq.c @@ -41,152 +41,6 @@ #define ASQ_CTRL_UNWILLING_TO_PERFORM 53 #define ASQ_CTRL_AFFECTS_MULTIPLE_DSA 71 -static int build_response(struct ldb_result *res, int result) -{ - struct ldb_asq_control *asq; - int i; - - if (res->controls) { - for (i = 0; res->controls[i]; i++); - res->controls = talloc_realloc(res, res->controls, struct ldb_control *, i + 2); - } else { - i = 0; - res->controls = talloc_array(res, struct ldb_control *, 2); - } - if (res->controls == NULL) - return LDB_ERR_OPERATIONS_ERROR; - - res->controls[i] = talloc(res->controls, struct ldb_control); - if (res->controls[i] == NULL) - return LDB_ERR_OPERATIONS_ERROR; - - res->controls[i]->oid = LDB_CONTROL_ASQ_OID; - res->controls[i]->critical = 0; - - asq = talloc_zero(res->controls[i], struct ldb_asq_control); - if (asq == NULL) - return LDB_ERR_OPERATIONS_ERROR; - - asq->result = result; - - res->controls[i]->data = asq; - - res->controls[i + 1] = NULL; - - return LDB_SUCCESS; -} - -/* search */ -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; - struct ldb_message_element *el; - struct ldb_result *res; - char **base_attrs; - int i, c, ret; - - /* pre-allocate a clean result structure */ - req->op.search.res = res = talloc_zero(req, struct ldb_result); - if (res == NULL) - return LDB_ERR_OPERATIONS_ERROR; - - /* check the search is well formed */ - if (req->op.search.scope != LDB_SCOPE_BASE) { - return build_response(res, ASQ_CTRL_UNWILLING_TO_PERFORM); - } - - asq_ctrl = talloc_get_type(control->data, struct ldb_asq_control); - if (!asq_ctrl) { - return LDB_ERR_PROTOCOL_ERROR; - } - - /* get the object to retrieve the DNs to search */ - base_req = talloc_zero(req, struct ldb_request); - if (base_req == NULL) - return LDB_ERR_OPERATIONS_ERROR; - base_req->operation = LDB_REQ_SEARCH; - base_req->op.search.base = req->op.search.base; - base_req->op.search.scope = LDB_SCOPE_BASE; - base_req->op.search.tree = req->op.search.tree; - base_attrs = talloc_array(base_req, char *, 2); - if (base_attrs == NULL) - return LDB_ERR_OPERATIONS_ERROR; - base_attrs[0] = talloc_strdup(base_attrs, asq_ctrl->source_attribute); - if (base_attrs[0] == NULL) - return LDB_ERR_OPERATIONS_ERROR; - base_attrs[1] = NULL; - base_req->op.search.attrs = (const char * const *)base_attrs; - - ret = ldb_request(module->ldb, base_req); - - if (ret != LDB_SUCCESS) { - talloc_free(base_req); - return ret; - } - - if (base_req->op.search.res->count == 0) { - talloc_free(base_req); - return build_response(res, ASQ_CTRL_SUCCESS); - } - - /* look up the DNs */ - el = ldb_msg_find_element(base_req->op.search.res->msgs[0], - asq_ctrl->source_attribute); - /* no values found */ - if (el == NULL) { - talloc_free(base_req); - return build_response(res, ASQ_CTRL_SUCCESS); - } - - for (i = 0, c = 0; i < el->num_values; i++) { - struct ldb_request *exp_req; - - exp_req = talloc_zero(req, struct ldb_request); - if (exp_req == NULL) - return LDB_ERR_OPERATIONS_ERROR; - exp_req->operation = LDB_REQ_SEARCH; - exp_req->op.search.base = ldb_dn_explode(exp_req, (const char *)el->values[i].data); - if (exp_req->op.search.base == NULL) { - return build_response(res, ASQ_CTRL_INVALID_ATTRIBUTE_SYNTAX); - } - exp_req->op.search.scope = LDB_SCOPE_BASE; - exp_req->op.search.tree = req->op.search.tree; - exp_req->op.search.attrs = req->op.search.attrs; - - ret = ldb_request(module->ldb, exp_req); - - if (ret != LDB_SUCCESS) - return ret; - - if (exp_req->op.search.res && exp_req->op.search.res->count != 0) { - if (res->msgs == NULL) { - res->msgs = talloc_array(res, - struct ldb_message *, 2); - } else { - res->msgs = talloc_realloc(res, res->msgs, - struct ldb_message *, c + 2); - } - if (res->msgs == NULL) - return LDB_ERR_OPERATIONS_ERROR; - - res->msgs[c] = talloc_steal(res->msgs, exp_req->op.search.res->msgs[0]); - c++; - } - - if (res->msgs) { - res->msgs[c] = NULL; - res->count = c; - } - - talloc_free(exp_req); - } - - talloc_free(base_req); - - return build_response(res, ASQ_CTRL_SUCCESS); -} - struct asq_async_context { enum {ASQ_SEARCH_BASE, ASQ_SEARCH_MULTI} step; @@ -580,28 +434,6 @@ static int asq_async_wait(struct ldb_async_handle *handle, enum ldb_async_wait_t } } -static int asq(struct ldb_module *module, struct ldb_request *req) -{ - struct ldb_control *control; - - /* 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); - } - - switch (req->operation) { - - case LDB_REQ_SEARCH: - return asq_search_sync(module, control, req); - - default: - return LDB_ERR_PROTOCOL_ERROR; - - } -} - static int asq_init(struct ldb_module *module) { struct ldb_request request; @@ -624,7 +456,6 @@ 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 }; -- cgit From 2d19dca9c80a5e3990296dde67163fce36ac883d Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Tue, 30 May 2006 00:33:52 +0000 Subject: r15944: rename LDB_ASYNC_ADD -> LDB_ADD, LDB_ASYNC_MODIFY -> LDB_MODIFY, etc... (This used to be commit 55d97ef88f377ef1dbf7b1774a15cf9035e2f320) --- source4/lib/ldb/modules/asq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/modules/asq.c') diff --git a/source4/lib/ldb/modules/asq.c b/source4/lib/ldb/modules/asq.c index 005d1e41b0..396a2346df 100644 --- a/source4/lib/ldb/modules/asq.c +++ b/source4/lib/ldb/modules/asq.c @@ -312,7 +312,7 @@ static int asq_async_requests(struct ldb_async_handle *handle) { ac->reqs[i] = talloc_zero(ac->reqs, struct ldb_request); if (ac->reqs[i] == NULL) return LDB_ERR_OPERATIONS_ERROR; - ac->reqs[i]->operation = LDB_ASYNC_SEARCH; + ac->reqs[i]->operation = LDB_SEARCH; ac->reqs[i]->op.search.base = ldb_dn_explode(ac->reqs[i], (const char *)el->values[i].data); if (ac->reqs[i]->op.search.base == NULL) { ac->asq_ret = ASQ_CTRL_INVALID_ATTRIBUTE_SYNTAX; -- cgit From ca5accf224dc3ef998235603797b519866b57b1c Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sun, 4 Jun 2006 05:28:13 +0000 Subject: r16036: Add a couple of new functions to corretly deal with timeouts. Check timeouts are correctly verified. Some minor fixed and removal of unused code. (This used to be commit b52e5d6a0cb1a32e62759eaa49ce3e4cc804cc92) --- source4/lib/ldb/modules/asq.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'source4/lib/ldb/modules/asq.c') diff --git a/source4/lib/ldb/modules/asq.c b/source4/lib/ldb/modules/asq.c index 396a2346df..75ef4a487e 100644 --- a/source4/lib/ldb/modules/asq.c +++ b/source4/lib/ldb/modules/asq.c @@ -48,7 +48,6 @@ struct asq_async_context { struct ldb_module *module; void *up_context; int (*up_callback)(struct ldb_context *, void *, struct ldb_async_result *); - int timeout; const char * const *req_attrs; char *req_attribute; @@ -66,8 +65,7 @@ struct asq_async_context { static struct ldb_async_handle *init_handle(void *mem_ctx, struct ldb_module *module, void *context, - int (*callback)(struct ldb_context *, void *, struct ldb_async_result *), - int timeout) + int (*callback)(struct ldb_context *, void *, struct ldb_async_result *)) { struct asq_async_context *ac; struct ldb_async_handle *h; @@ -95,7 +93,6 @@ static struct ldb_async_handle *init_handle(void *mem_ctx, struct ldb_module *mo ac->module = module; ac->up_context = context; ac->up_callback = callback; - ac->timeout = timeout; return h; } @@ -233,7 +230,7 @@ static int asq_search(struct ldb_module *module, struct ldb_request *req) return LDB_ERR_PROTOCOL_ERROR; } - h = init_handle(req, module, req->async.context, req->async.callback, req->async.timeout); + h = init_handle(req, module, req->async.context, req->async.callback); if (!h) { return LDB_ERR_OPERATIONS_ERROR; } @@ -271,7 +268,7 @@ static int asq_search(struct ldb_module *module, struct ldb_request *req) ac->base_req->async.context = ac; ac->base_req->async.callback = asq_base_callback; - ac->base_req->async.timeout = req->async.timeout; + ldb_set_timeout_from_prev_req(module->ldb, req, ac->base_req); ac->step = ASQ_SEARCH_BASE; @@ -324,7 +321,7 @@ static int asq_async_requests(struct ldb_async_handle *handle) { ac->reqs[i]->async.context = ac; ac->reqs[i]->async.callback = asq_reqs_callback; - ac->reqs[i]->async.timeout = ac->base_req->async.timeout; + ldb_set_timeout_from_prev_req(ac->module->ldb, ac->base_req, ac->reqs[i]); } ac->step = ASQ_SEARCH_MULTI; @@ -436,14 +433,19 @@ static int asq_async_wait(struct ldb_async_handle *handle, enum ldb_async_wait_t static int asq_init(struct ldb_module *module) { - struct ldb_request request; + struct ldb_request *req; int ret; - request.operation = LDB_REQ_REGISTER; - request.op.reg.oid = LDB_CONTROL_ASQ_OID; - request.controls = NULL; + req = talloc_zero(module, struct ldb_request); + if (req == NULL) { + ldb_debug(module->ldb, LDB_DEBUG_ERROR, "asq: Out of memory!\n"); + return LDB_ERR_OPERATIONS_ERROR; + } + + req->operation = LDB_REQ_REGISTER; + req->op.reg.oid = LDB_CONTROL_ASQ_OID; - ret = ldb_request(module->ldb, &request); + ret = ldb_request(module->ldb, req); if (ret != LDB_SUCCESS) { ldb_debug(module->ldb, LDB_DEBUG_ERROR, "asq: Unable to register control with rootdse!\n"); return LDB_ERR_OTHER; -- cgit From f77c4100842f8c5357fa90822e04319810a04b8d Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Thu, 15 Jun 2006 18:04:24 +0000 Subject: r16264: Add, but do not yet enable, the partitions module. This required changes to the rootDSE module, to allow registration of partitions. In doing so I renamed the 'register' operation to 'register_control' and 'register_partition', which changed a few more modules. Due to the behaviour of certain LDAP servers, we create the baseDN entry in two parts: Firstly, we allow the admin to export a simple LDIF file to add to their server. Then we perform a modify to add the remaining attributes. To delete all users in partitions, we must now search and delete all objects in the partition, rather than a simple search from the root. Against LDAP, this might not delete all objects, so we allow this to fail. In testing, we found that the 'Domain Controllers' container was misnamed, and should be 'CN=', rather than 'OU='. To avoid the Templates being found in default searches, they have been moved to CN=Templates from CN=Templates,${BASEDN}. Andrew Bartlett (This used to be commit b49a4fbb57f10726bd288fdc9fc95c0cbbe9094a) --- source4/lib/ldb/modules/asq.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib/ldb/modules/asq.c') diff --git a/source4/lib/ldb/modules/asq.c b/source4/lib/ldb/modules/asq.c index 75ef4a487e..2c0baa6827 100644 --- a/source4/lib/ldb/modules/asq.c +++ b/source4/lib/ldb/modules/asq.c @@ -442,8 +442,8 @@ static int asq_init(struct ldb_module *module) return LDB_ERR_OPERATIONS_ERROR; } - req->operation = LDB_REQ_REGISTER; - req->op.reg.oid = LDB_CONTROL_ASQ_OID; + req->operation = LDB_REQ_REGISTER_CONTROL; + req->op.reg_control.oid = LDB_CONTROL_ASQ_OID; ret = ldb_request(module->ldb, req); if (ret != LDB_SUCCESS) { -- cgit From c93817b36d3ff7f44cb7b3e1d1a29e37ec12affe Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sat, 22 Jul 2006 16:56:33 +0000 Subject: r17185: Oh, I wanted to do this for sooo long time. Finally acknowledge that ldb is inherently async and does not have a dual personality anymore Rename all ldb_async_XXX functions to ldb_XXX except for ldb_async_result, it is now ldb_reply to reflect the real function of this structure. Simo. (This used to be commit 25fc7354049d62efeba17681ef1cdd326bc3f2ef) --- source4/lib/ldb/modules/asq.c | 76 +++++++++++++++++++++---------------------- 1 file changed, 38 insertions(+), 38 deletions(-) (limited to 'source4/lib/ldb/modules/asq.c') diff --git a/source4/lib/ldb/modules/asq.c b/source4/lib/ldb/modules/asq.c index 2c0baa6827..466286e8cd 100644 --- a/source4/lib/ldb/modules/asq.c +++ b/source4/lib/ldb/modules/asq.c @@ -41,20 +41,20 @@ #define ASQ_CTRL_UNWILLING_TO_PERFORM 53 #define ASQ_CTRL_AFFECTS_MULTIPLE_DSA 71 -struct asq_async_context { +struct asq_context { enum {ASQ_SEARCH_BASE, ASQ_SEARCH_MULTI} step; struct ldb_module *module; void *up_context; - int (*up_callback)(struct ldb_context *, void *, struct ldb_async_result *); + int (*up_callback)(struct ldb_context *, void *, struct ldb_reply *); const char * const *req_attrs; char *req_attribute; int asq_ret; struct ldb_request *base_req; - struct ldb_async_result *base_res; + struct ldb_reply *base_res; struct ldb_request **reqs; int num_reqs; @@ -63,14 +63,14 @@ struct asq_async_context { struct ldb_control **controls; }; -static struct ldb_async_handle *init_handle(void *mem_ctx, struct ldb_module *module, +static struct ldb_handle *init_handle(void *mem_ctx, struct ldb_module *module, void *context, - int (*callback)(struct ldb_context *, void *, struct ldb_async_result *)) + int (*callback)(struct ldb_context *, void *, struct ldb_reply *)) { - struct asq_async_context *ac; - struct ldb_async_handle *h; + struct asq_context *ac; + struct ldb_handle *h; - h = talloc_zero(mem_ctx, struct ldb_async_handle); + h = talloc_zero(mem_ctx, struct ldb_handle); if (h == NULL) { ldb_set_errstring(module->ldb, talloc_asprintf(module, "Out of Memory")); return NULL; @@ -78,7 +78,7 @@ static struct ldb_async_handle *init_handle(void *mem_ctx, struct ldb_module *mo h->module = module; - ac = talloc_zero(h, struct asq_async_context); + ac = talloc_zero(h, struct asq_context); if (ac == NULL) { ldb_set_errstring(module->ldb, talloc_asprintf(module, "Out of Memory")); talloc_free(h); @@ -97,19 +97,19 @@ static struct ldb_async_handle *init_handle(void *mem_ctx, struct ldb_module *mo return h; } -static int asq_terminate(struct ldb_async_handle *handle) +static int asq_terminate(struct ldb_handle *handle) { - struct asq_async_context *ac; - struct ldb_async_result *ares; + struct asq_context *ac; + struct ldb_reply *ares; struct ldb_asq_control *asq; int i; - ac = talloc_get_type(handle->private_data, struct asq_async_context); + ac = talloc_get_type(handle->private_data, struct asq_context); handle->status = LDB_SUCCESS; handle->state = LDB_ASYNC_DONE; - ares = talloc_zero(ac, struct ldb_async_result); + ares = talloc_zero(ac, struct ldb_reply); if (ares == NULL) return LDB_ERR_OPERATIONS_ERROR; @@ -149,16 +149,16 @@ static int asq_terminate(struct ldb_async_handle *handle) return LDB_SUCCESS; } -static int asq_base_callback(struct ldb_context *ldb, void *context, struct ldb_async_result *ares) +static int asq_base_callback(struct ldb_context *ldb, void *context, struct ldb_reply *ares) { - struct asq_async_context *ac; + struct asq_context *ac; if (!context || !ares) { ldb_set_errstring(ldb, talloc_asprintf(ldb, "NULL Context or Result in callback")); goto error; } - ac = talloc_get_type(context, struct asq_async_context); + ac = talloc_get_type(context, struct asq_context); /* we are interested only in the single reply (base search) we receive here */ if (ares->type == LDB_REPLY_ENTRY) { @@ -173,16 +173,16 @@ error: return LDB_ERR_OPERATIONS_ERROR; } -static int asq_reqs_callback(struct ldb_context *ldb, void *context, struct ldb_async_result *ares) +static int asq_reqs_callback(struct ldb_context *ldb, void *context, struct ldb_reply *ares) { - struct asq_async_context *ac; + struct asq_context *ac; if (!context || !ares) { ldb_set_errstring(ldb, talloc_asprintf(ldb, "NULL Context or Result in callback")); goto error; } - ac = talloc_get_type(context, struct asq_async_context); + ac = talloc_get_type(context, struct asq_context); /* we are interested only in the single reply (base search) we receive here */ if (ares->type == LDB_REPLY_ENTRY) { @@ -205,8 +205,8 @@ 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; + struct asq_context *ac; + struct ldb_handle *h; char **base_attrs; int ret; @@ -234,7 +234,7 @@ static int asq_search(struct ldb_module *module, struct ldb_request *req) if (!h) { return LDB_ERR_OPERATIONS_ERROR; } - ac = talloc_get_type(h->private_data, struct asq_async_context); + ac = talloc_get_type(h->private_data, struct asq_context); req->async.handle = h; @@ -281,12 +281,12 @@ static int asq_search(struct ldb_module *module, struct ldb_request *req) return LDB_SUCCESS; } -static int asq_async_requests(struct ldb_async_handle *handle) { - struct asq_async_context *ac; +static int asq_requests(struct ldb_handle *handle) { + struct asq_context *ac; struct ldb_message_element *el; int i; - ac = talloc_get_type(handle->private_data, struct asq_async_context); + ac = talloc_get_type(handle->private_data, struct asq_context); /* look up the DNs */ el = ldb_msg_find_element(ac->base_res->message, ac->req_attribute); @@ -329,9 +329,9 @@ static int asq_async_requests(struct ldb_async_handle *handle) { return LDB_SUCCESS; } -static int asq_async_wait_none(struct ldb_async_handle *handle) +static int asq_wait_none(struct ldb_handle *handle) { - struct asq_async_context *ac; + struct asq_context *ac; int ret; if (!handle || !handle->private_data) { @@ -345,12 +345,12 @@ static int asq_async_wait_none(struct ldb_async_handle *handle) handle->state = LDB_ASYNC_PENDING; handle->status = LDB_SUCCESS; - ac = talloc_get_type(handle->private_data, struct asq_async_context); + ac = talloc_get_type(handle->private_data, struct asq_context); switch (ac->step) { case ASQ_SEARCH_BASE: - ret = ldb_async_wait(ac->base_req->async.handle, LDB_WAIT_NONE); + ret = ldb_wait(ac->base_req->async.handle, LDB_WAIT_NONE); if (ret != LDB_SUCCESS) { handle->status = ret; @@ -365,7 +365,7 @@ static int asq_async_wait_none(struct ldb_async_handle *handle) return LDB_SUCCESS; } - ret = asq_async_requests(handle); + ret = asq_requests(handle); case ASQ_SEARCH_MULTI: @@ -376,7 +376,7 @@ static int asq_async_wait_none(struct ldb_async_handle *handle) } } - ret = ldb_async_wait(ac->reqs[ac->cur_req]->async.handle, LDB_WAIT_NONE); + ret = ldb_wait(ac->reqs[ac->cur_req]->async.handle, LDB_WAIT_NONE); if (ret != LDB_SUCCESS) { handle->status = ret; @@ -408,12 +408,12 @@ done: return ret; } -static int asq_async_wait_all(struct ldb_async_handle *handle) +static int asq_wait_all(struct ldb_handle *handle) { int ret; while (handle->state != LDB_ASYNC_DONE) { - ret = asq_async_wait_none(handle); + ret = asq_wait_none(handle); if (ret != LDB_SUCCESS) { return ret; } @@ -422,12 +422,12 @@ static int asq_async_wait_all(struct ldb_async_handle *handle) return handle->status; } -static int asq_async_wait(struct ldb_async_handle *handle, enum ldb_async_wait_type type) +static int asq_wait(struct ldb_handle *handle, enum ldb_wait_type type) { if (type == LDB_WAIT_ALL) { - return asq_async_wait_all(handle); + return asq_wait_all(handle); } else { - return asq_async_wait_none(handle); + return asq_wait_none(handle); } } @@ -458,7 +458,7 @@ static int asq_init(struct ldb_module *module) static const struct ldb_module_ops asq_ops = { .name = "asq", .search = asq_search, - .async_wait = asq_async_wait, + .wait = asq_wait, .init_context = asq_init }; -- cgit From 49f68caed20d2a7d1850e493005bdf85929d6365 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sat, 22 Jul 2006 17:21:59 +0000 Subject: r17186: "async" word abuse clean-up part 2 (This used to be commit c6aa60c7e69abf1f83efc150b1c3ed02751c45fc) --- source4/lib/ldb/modules/asq.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'source4/lib/ldb/modules/asq.c') diff --git a/source4/lib/ldb/modules/asq.c b/source4/lib/ldb/modules/asq.c index 466286e8cd..110470c8bb 100644 --- a/source4/lib/ldb/modules/asq.c +++ b/source4/lib/ldb/modules/asq.c @@ -217,9 +217,9 @@ static int asq_search(struct ldb_module *module, struct ldb_request *req) return ldb_next_request(module, req); } - req->async.handle = NULL; + req->handle = NULL; - if (!req->async.callback || !req->async.context) { + if (!req->callback || !req->context) { ldb_set_errstring(module->ldb, talloc_asprintf(module, "Async interface called with NULL callback function or NULL context")); return LDB_ERR_OPERATIONS_ERROR; @@ -230,13 +230,13 @@ static int asq_search(struct ldb_module *module, struct ldb_request *req) return LDB_ERR_PROTOCOL_ERROR; } - h = init_handle(req, module, req->async.context, req->async.callback); + h = init_handle(req, module, req->context, req->callback); if (!h) { return LDB_ERR_OPERATIONS_ERROR; } ac = talloc_get_type(h->private_data, struct asq_context); - req->async.handle = h; + req->handle = h; /* check the search is well formed */ if (req->op.search.scope != LDB_SCOPE_BASE) { @@ -266,8 +266,8 @@ static int asq_search(struct ldb_module *module, struct ldb_request *req) base_attrs[1] = NULL; ac->base_req->op.search.attrs = (const char * const *)base_attrs; - ac->base_req->async.context = ac; - ac->base_req->async.callback = asq_base_callback; + ac->base_req->context = ac; + ac->base_req->callback = asq_base_callback; ldb_set_timeout_from_prev_req(module->ldb, req, ac->base_req); ac->step = ASQ_SEARCH_BASE; @@ -319,8 +319,8 @@ static int asq_requests(struct ldb_handle *handle) { ac->reqs[i]->op.search.tree = ac->base_req->op.search.tree; ac->reqs[i]->op.search.attrs = ac->req_attrs; - ac->reqs[i]->async.context = ac; - ac->reqs[i]->async.callback = asq_reqs_callback; + ac->reqs[i]->context = ac; + ac->reqs[i]->callback = asq_reqs_callback; ldb_set_timeout_from_prev_req(ac->module->ldb, ac->base_req, ac->reqs[i]); } @@ -350,18 +350,18 @@ static int asq_wait_none(struct ldb_handle *handle) switch (ac->step) { case ASQ_SEARCH_BASE: - ret = ldb_wait(ac->base_req->async.handle, LDB_WAIT_NONE); + ret = ldb_wait(ac->base_req->handle, LDB_WAIT_NONE); if (ret != LDB_SUCCESS) { handle->status = ret; goto done; } - if (ac->base_req->async.handle->status != LDB_SUCCESS) { - handle->status = ac->base_req->async.handle->status; + if (ac->base_req->handle->status != LDB_SUCCESS) { + handle->status = ac->base_req->handle->status; goto done; } - if (ac->base_req->async.handle->state != LDB_ASYNC_DONE) { + if (ac->base_req->handle->state != LDB_ASYNC_DONE) { return LDB_SUCCESS; } @@ -369,24 +369,24 @@ static int asq_wait_none(struct ldb_handle *handle) case ASQ_SEARCH_MULTI: - if (ac->reqs[ac->cur_req]->async.handle == NULL) { + if (ac->reqs[ac->cur_req]->handle == NULL) { ret = ldb_request(ac->module->ldb, ac->reqs[ac->cur_req]); if (ret != LDB_SUCCESS) { return ret; } } - ret = ldb_wait(ac->reqs[ac->cur_req]->async.handle, LDB_WAIT_NONE); + ret = ldb_wait(ac->reqs[ac->cur_req]->handle, LDB_WAIT_NONE); if (ret != LDB_SUCCESS) { handle->status = ret; goto done; } - if (ac->reqs[ac->cur_req]->async.handle->status != LDB_SUCCESS) { - handle->status = ac->reqs[ac->cur_req]->async.handle->status; + if (ac->reqs[ac->cur_req]->handle->status != LDB_SUCCESS) { + handle->status = ac->reqs[ac->cur_req]->handle->status; } - if (ac->reqs[ac->cur_req]->async.handle->state == LDB_ASYNC_DONE) { + if (ac->reqs[ac->cur_req]->handle->state == LDB_ASYNC_DONE) { ac->cur_req++; } -- cgit From faed8175063b16df94d5332581baf1af0562bb09 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sun, 13 Aug 2006 07:33:57 +0000 Subject: r17514: Simplify the way to set ldb errors and add another helper function to set them. (This used to be commit 260868bae56194fcb98d55afc22fc66d96a303df) --- source4/lib/ldb/modules/asq.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source4/lib/ldb/modules/asq.c') diff --git a/source4/lib/ldb/modules/asq.c b/source4/lib/ldb/modules/asq.c index 110470c8bb..1185cd8dac 100644 --- a/source4/lib/ldb/modules/asq.c +++ b/source4/lib/ldb/modules/asq.c @@ -72,7 +72,7 @@ static struct ldb_handle *init_handle(void *mem_ctx, struct ldb_module *module, h = talloc_zero(mem_ctx, struct ldb_handle); if (h == NULL) { - ldb_set_errstring(module->ldb, talloc_asprintf(module, "Out of Memory")); + ldb_set_errstring(module->ldb, "Out of Memory"); return NULL; } @@ -80,7 +80,7 @@ static struct ldb_handle *init_handle(void *mem_ctx, struct ldb_module *module, ac = talloc_zero(h, struct asq_context); if (ac == NULL) { - ldb_set_errstring(module->ldb, talloc_asprintf(module, "Out of Memory")); + ldb_set_errstring(module->ldb, "Out of Memory"); talloc_free(h); return NULL; } @@ -154,7 +154,7 @@ static int asq_base_callback(struct ldb_context *ldb, void *context, struct ldb_ struct asq_context *ac; if (!context || !ares) { - ldb_set_errstring(ldb, talloc_asprintf(ldb, "NULL Context or Result in callback")); + ldb_set_errstring(ldb, "NULL Context or Result in callback"); goto error; } @@ -178,7 +178,7 @@ static int asq_reqs_callback(struct ldb_context *ldb, void *context, struct ldb_ struct asq_context *ac; if (!context || !ares) { - ldb_set_errstring(ldb, talloc_asprintf(ldb, "NULL Context or Result in callback")); + ldb_set_errstring(ldb, "NULL Context or Result in callback"); goto error; } @@ -220,8 +220,8 @@ static int asq_search(struct ldb_module *module, struct ldb_request *req) req->handle = NULL; if (!req->callback || !req->context) { - ldb_set_errstring(module->ldb, talloc_asprintf(module, - "Async interface called with NULL callback function or NULL context")); + ldb_set_errstring(module->ldb, + "Async interface called with NULL callback function or NULL context"); return LDB_ERR_OPERATIONS_ERROR; } -- cgit From 47479df22e14354883655534063e97b2f37441b0 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 24 Aug 2006 08:32:57 +0000 Subject: r17775: use an enum to get rid of compiler warnings metze (This used to be commit c66cf31afd99d537b1f4dfc8ff1502dfa6accfd3) --- source4/lib/ldb/modules/asq.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source4/lib/ldb/modules/asq.c') diff --git a/source4/lib/ldb/modules/asq.c b/source4/lib/ldb/modules/asq.c index 1185cd8dac..2ab04afe59 100644 --- a/source4/lib/ldb/modules/asq.c +++ b/source4/lib/ldb/modules/asq.c @@ -36,11 +36,6 @@ #include "includes.h" #include "ldb/include/includes.h" -#define ASQ_CTRL_SUCCESS 0 -#define ASQ_CTRL_INVALID_ATTRIBUTE_SYNTAX 21 -#define ASQ_CTRL_UNWILLING_TO_PERFORM 53 -#define ASQ_CTRL_AFFECTS_MULTIPLE_DSA 71 - struct asq_context { enum {ASQ_SEARCH_BASE, ASQ_SEARCH_MULTI} step; @@ -51,7 +46,12 @@ struct asq_context { const char * const *req_attrs; char *req_attribute; - int asq_ret; + enum { + ASQ_CTRL_SUCCESS = 0, + ASQ_CTRL_INVALID_ATTRIBUTE_SYNTAX = 21, + ASQ_CTRL_UNWILLING_TO_PERFORM = 53, + ASQ_CTRL_AFFECTS_MULTIPLE_DSA = 71 + } asq_ret; struct ldb_request *base_req; struct ldb_reply *base_res; -- cgit From fb15300c60ee92addc7664ed96d3d21e634b2d0b Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sun, 10 Sep 2006 03:11:03 +0000 Subject: r18317: Make sure we actually have a valid reply or fail (This used to be commit 41cb3a9258012e628a2d87959cc066f6c5d92255) --- source4/lib/ldb/modules/asq.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source4/lib/ldb/modules/asq.c') diff --git a/source4/lib/ldb/modules/asq.c b/source4/lib/ldb/modules/asq.c index 2ab04afe59..a06dd5391a 100644 --- a/source4/lib/ldb/modules/asq.c +++ b/source4/lib/ldb/modules/asq.c @@ -289,6 +289,9 @@ static int asq_requests(struct ldb_handle *handle) { ac = talloc_get_type(handle->private_data, struct asq_context); /* look up the DNs */ + if (ac->base_res == NULL) { + return LDB_ERR_NO_SUCH_OBJECT; + } el = ldb_msg_find_element(ac->base_res->message, ac->req_attribute); /* no values found */ if (el == NULL) { -- cgit From 7f63cebd331793d059b1dbfd2f7d7ce38105c4fe Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 13 Sep 2006 00:10:38 +0000 Subject: r18436: converted ldb to use talloc_move() instead of talloc_steal() when appropriate. Note that I also removed the error checks that were being done on the result of talloc_steal(). They are pointless as talloc_steal() doesn't have any failure modes that wouldn't cause a segv anyway, and they tend to clutter the code (This used to be commit c0d9e7d473b8e3eb2524a9fc29cf88680f994b36) --- source4/lib/ldb/modules/asq.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib/ldb/modules/asq.c') diff --git a/source4/lib/ldb/modules/asq.c b/source4/lib/ldb/modules/asq.c index a06dd5391a..75afae2c7e 100644 --- a/source4/lib/ldb/modules/asq.c +++ b/source4/lib/ldb/modules/asq.c @@ -117,7 +117,7 @@ static int asq_terminate(struct ldb_handle *handle) if (ac->controls) { for (i = 0; ac->controls[i]; i++); - ares->controls = talloc_steal(ares, ac->controls); + ares->controls = talloc_move(ares, ac->controls); } else { i = 0; } @@ -162,7 +162,7 @@ static int asq_base_callback(struct ldb_context *ldb, void *context, struct ldb_ /* we are interested only in the single reply (base search) we receive here */ if (ares->type == LDB_REPLY_ENTRY) { - ac->base_res = talloc_steal(ac, ares); + ac->base_res = talloc_move(ac, ares); } else { talloc_free(ares); } -- cgit From 05cdd9ccafeeb384792b9ce7ca044bcec1bfc839 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 13 Sep 2006 02:33:51 +0000 Subject: r18439: 2nd try at a talloc_move() api. This type with the ** ptr interface exposed. Unfortunately this generates a large number of type punning warnings. We'll have to find some magic to hide those. (This used to be commit 254cbf09dee5a1e20c47e47a298f1a8d172b41b9) --- source4/lib/ldb/modules/asq.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib/ldb/modules/asq.c') diff --git a/source4/lib/ldb/modules/asq.c b/source4/lib/ldb/modules/asq.c index 75afae2c7e..229a6eacd9 100644 --- a/source4/lib/ldb/modules/asq.c +++ b/source4/lib/ldb/modules/asq.c @@ -117,7 +117,7 @@ static int asq_terminate(struct ldb_handle *handle) if (ac->controls) { for (i = 0; ac->controls[i]; i++); - ares->controls = talloc_move(ares, ac->controls); + ares->controls = talloc_move(ares, &ac->controls); } else { i = 0; } @@ -162,7 +162,7 @@ static int asq_base_callback(struct ldb_context *ldb, void *context, struct ldb_ /* we are interested only in the single reply (base search) we receive here */ if (ares->type == LDB_REPLY_ENTRY) { - ac->base_res = talloc_move(ac, ares); + ac->base_res = talloc_move(ac, &ares); } else { talloc_free(ares); } -- cgit From f7005d48d22e8833897a4ebbad237996860a6cba Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Fri, 6 Oct 2006 13:47:52 +0000 Subject: r19129: Add comment to clarify behavior (This used to be commit 7180f38e9e436ca7a7c49f2d4b315ec5eb9c7631) --- source4/lib/ldb/modules/asq.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source4/lib/ldb/modules/asq.c') diff --git a/source4/lib/ldb/modules/asq.c b/source4/lib/ldb/modules/asq.c index 229a6eacd9..354bbf2bc8 100644 --- a/source4/lib/ldb/modules/asq.c +++ b/source4/lib/ldb/modules/asq.c @@ -370,6 +370,10 @@ static int asq_wait_none(struct ldb_handle *handle) ret = asq_requests(handle); + /* no break nor return, + * the set of requests is performed in ASQ_SEARCH_MULTI + */ + case ASQ_SEARCH_MULTI: if (ac->reqs[ac->cur_req]->handle == NULL) { -- cgit From 52030310076002bfa94fd3332f28f38b5a185890 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sun, 22 Oct 2006 21:15:30 +0000 Subject: r19452: Warn but don't die if registering against the rootdse is not possible (This used to be commit 4ad2eba2aa7711d480a844766e2dd3da938b3413) --- source4/lib/ldb/modules/asq.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source4/lib/ldb/modules/asq.c') diff --git a/source4/lib/ldb/modules/asq.c b/source4/lib/ldb/modules/asq.c index 354bbf2bc8..2fed6aac50 100644 --- a/source4/lib/ldb/modules/asq.c +++ b/source4/lib/ldb/modules/asq.c @@ -454,8 +454,7 @@ static int asq_init(struct ldb_module *module) ret = ldb_request(module->ldb, req); if (ret != LDB_SUCCESS) { - ldb_debug(module->ldb, LDB_DEBUG_ERROR, "asq: Unable to register control with rootdse!\n"); - return LDB_ERR_OTHER; + ldb_debug(module->ldb, LDB_DEBUG_WARNING, "asq: Unable to register control with rootdse!\n"); } return ldb_next_init(module); -- cgit From 4889eb9f7aae9349e426d0f6d2217adff67eaebd Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Wed, 22 Nov 2006 00:59:34 +0000 Subject: r19831: Big ldb_dn optimization and interfaces enhancement patch This patch changes a lot of the code in ldb_dn.c, and also removes and add a number of manipulation functions around. The aim is to avoid validating a dn if not necessary as the validation code is necessarily slow. This is mainly to speed up internal operations where input is not user generated and so we can assume the DNs need no validation. The code is designed to keep the data as a string if possible. The code is not yet 100% perfect, but pass all the tests so far. A memleak is certainly present, I'll work on that next. Simo. (This used to be commit a580c871d3784602a9cce32d33419e63c8236e63) --- source4/lib/ldb/modules/asq.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib/ldb/modules/asq.c') diff --git a/source4/lib/ldb/modules/asq.c b/source4/lib/ldb/modules/asq.c index 2fed6aac50..7d10a31b34 100644 --- a/source4/lib/ldb/modules/asq.c +++ b/source4/lib/ldb/modules/asq.c @@ -313,8 +313,8 @@ static int asq_requests(struct ldb_handle *handle) { if (ac->reqs[i] == NULL) return LDB_ERR_OPERATIONS_ERROR; ac->reqs[i]->operation = LDB_SEARCH; - ac->reqs[i]->op.search.base = ldb_dn_explode(ac->reqs[i], (const char *)el->values[i].data); - if (ac->reqs[i]->op.search.base == NULL) { + ac->reqs[i]->op.search.base = ldb_dn_new(ac->reqs[i], ac->module->ldb, (const char *)el->values[i].data); + if ( ! ldb_dn_validate(ac->reqs[i]->op.search.base)) { ac->asq_ret = ASQ_CTRL_INVALID_ATTRIBUTE_SYNTAX; return asq_terminate(handle); } -- cgit From 5bbe9101cfca7ee4bce1e6e2615e783908375817 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sat, 25 Nov 2006 19:28:09 +0000 Subject: r19904: port fies from samba3 (This used to be commit 49d1559d3670de4a4f9eace99600c37cf039bae2) --- source4/lib/ldb/modules/asq.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'source4/lib/ldb/modules/asq.c') diff --git a/source4/lib/ldb/modules/asq.c b/source4/lib/ldb/modules/asq.c index 7d10a31b34..e95135145e 100644 --- a/source4/lib/ldb/modules/asq.c +++ b/source4/lib/ldb/modules/asq.c @@ -105,6 +105,9 @@ static int asq_terminate(struct ldb_handle *handle) int i; ac = talloc_get_type(handle->private_data, struct asq_context); + if (ac == NULL) { + return LDB_ERR_OPERATIONS_ERROR; + } handle->status = LDB_SUCCESS; handle->state = LDB_ASYNC_DONE; @@ -159,6 +162,9 @@ static int asq_base_callback(struct ldb_context *ldb, void *context, struct ldb_ } ac = talloc_get_type(context, struct asq_context); + if (ac == NULL) { + goto error; + } /* we are interested only in the single reply (base search) we receive here */ if (ares->type == LDB_REPLY_ENTRY) { @@ -183,6 +189,9 @@ static int asq_reqs_callback(struct ldb_context *ldb, void *context, struct ldb_ } ac = talloc_get_type(context, struct asq_context); + if (ac == NULL) { + goto error; + } /* we are interested only in the single reply (base search) we receive here */ if (ares->type == LDB_REPLY_ENTRY) { @@ -287,6 +296,9 @@ static int asq_requests(struct ldb_handle *handle) { int i; ac = talloc_get_type(handle->private_data, struct asq_context); + if (ac == NULL) { + return LDB_ERR_OPERATIONS_ERROR; + } /* look up the DNs */ if (ac->base_res == NULL) { @@ -349,7 +361,9 @@ static int asq_wait_none(struct ldb_handle *handle) handle->status = LDB_SUCCESS; ac = talloc_get_type(handle->private_data, struct asq_context); - + if (ac == NULL) { + return LDB_ERR_OPERATIONS_ERROR; + } switch (ac->step) { case ASQ_SEARCH_BASE: -- cgit From 0e2ebecf18270c1650a61a3054a830d3009ef985 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 15 Dec 2006 23:00:24 +0000 Subject: r20198: let the IBM checker ignore the warning about a missing break statement... metze (This used to be commit 6b20123c10b8812759b0876990766adc207bc5b4) --- source4/lib/ldb/modules/asq.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source4/lib/ldb/modules/asq.c') diff --git a/source4/lib/ldb/modules/asq.c b/source4/lib/ldb/modules/asq.c index e95135145e..f361b801ea 100644 --- a/source4/lib/ldb/modules/asq.c +++ b/source4/lib/ldb/modules/asq.c @@ -387,7 +387,8 @@ static int asq_wait_none(struct ldb_handle *handle) /* no break nor return, * the set of requests is performed in ASQ_SEARCH_MULTI */ - + /* fall through */ + case ASQ_SEARCH_MULTI: if (ac->reqs[ac->cur_req]->handle == NULL) { -- cgit From a1a5d12c13a6cceb6815d4eaf5c1ca78ca3bacbc Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Wed, 10 Jan 2007 18:18:13 +0000 Subject: r20656: This way the process flow should be much more readable. We need to make it easier, but this should be a step in the right direction. (This used to be commit ad58177ee46a4f02ee2e2d97882b851226bd3af2) --- source4/lib/ldb/modules/asq.c | 235 +++++++++++++++++++++++------------------- 1 file changed, 131 insertions(+), 104 deletions(-) (limited to 'source4/lib/ldb/modules/asq.c') diff --git a/source4/lib/ldb/modules/asq.c b/source4/lib/ldb/modules/asq.c index f361b801ea..92e2fc5294 100644 --- a/source4/lib/ldb/modules/asq.c +++ b/source4/lib/ldb/modules/asq.c @@ -38,11 +38,12 @@ struct asq_context { - enum {ASQ_SEARCH_BASE, ASQ_SEARCH_MULTI} step; + enum {ASQ_INIT, ASQ_SEARCH_BASE, ASQ_SEARCH_MULTI} step; struct ldb_module *module; - void *up_context; - int (*up_callback)(struct ldb_context *, void *, struct ldb_reply *); + struct ldb_request *orig_req; + + struct ldb_asq_control *asq_ctrl; const char * const *req_attrs; char *req_attribute; @@ -63,14 +64,12 @@ struct asq_context { struct ldb_control **controls; }; -static struct ldb_handle *init_handle(void *mem_ctx, struct ldb_module *module, - void *context, - int (*callback)(struct ldb_context *, void *, struct ldb_reply *)) +static struct ldb_handle *init_handle(struct ldb_request *req, struct ldb_module *module) { struct asq_context *ac; struct ldb_handle *h; - h = talloc_zero(mem_ctx, struct ldb_handle); + h = talloc_zero(req, struct ldb_handle); if (h == NULL) { ldb_set_errstring(module->ldb, "Out of Memory"); return NULL; @@ -90,9 +89,9 @@ static struct ldb_handle *init_handle(void *mem_ctx, struct ldb_module *module, h->state = LDB_ASYNC_INIT; h->status = LDB_SUCCESS; + ac->step = ASQ_INIT; ac->module = module; - ac->up_context = context; - ac->up_callback = callback; + ac->orig_req = req; return h; } @@ -147,7 +146,7 @@ static int asq_terminate(struct ldb_handle *handle) ares->controls[i + 1] = NULL; - ac->up_callback(ac->module->ldb, ac->up_context, ares); + ac->orig_req->callback(ac->module->ldb, ac->orig_req->context, ares); return LDB_SUCCESS; } @@ -198,7 +197,7 @@ static int asq_reqs_callback(struct ldb_context *ldb, void *context, struct ldb_ /* pass the message up to the original callback as we * do not have to elaborate on it any further */ - return ac->up_callback(ac->module->ldb, ac->up_context, ares); + return ac->orig_req->callback(ac->module->ldb, ac->orig_req->context, ares); } else { /* ignore any REFERRAL or DONE reply */ talloc_free(ares); @@ -210,96 +209,38 @@ error: return LDB_ERR_OPERATIONS_ERROR; } -static int asq_search(struct ldb_module *module, struct ldb_request *req) +static int asq_build_first_request(struct asq_context *ac) { - struct ldb_control *control; - struct ldb_asq_control *asq_ctrl; - struct asq_context *ac; - struct ldb_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->handle = NULL; - - if (!req->callback || !req->context) { - ldb_set_errstring(module->ldb, - "Async interface called with NULL callback function or NULL context"); - return LDB_ERR_OPERATIONS_ERROR; - } - - asq_ctrl = talloc_get_type(control->data, struct ldb_asq_control); - if (!asq_ctrl) { - return LDB_ERR_PROTOCOL_ERROR; - } - - h = init_handle(req, module, req->context, req->callback); - if (!h) { - return LDB_ERR_OPERATIONS_ERROR; - } - ac = talloc_get_type(h->private_data, struct asq_context); - req->handle = h; - - /* check the search is well formed */ - if (req->op.search.scope != LDB_SCOPE_BASE) { - ac->asq_ret = ASQ_CTRL_UNWILLING_TO_PERFORM; - return asq_terminate(h); - } - - ac->req_attrs = req->op.search.attrs; - ac->req_attribute = talloc_strdup(ac, asq_ctrl->source_attribute); - if (ac->req_attribute == NULL) - return LDB_ERR_OPERATIONS_ERROR; + ac->base_req = talloc_zero(ac, struct ldb_request); + if (ac->base_req == NULL) return LDB_ERR_OPERATIONS_ERROR; - /* get the object to retrieve the DNs to search */ - ac->base_req = talloc_zero(req, struct ldb_request); - if (ac->base_req == NULL) - return LDB_ERR_OPERATIONS_ERROR; - ac->base_req->operation = req->operation; - ac->base_req->op.search.base = req->op.search.base; + ac->base_req->operation = ac->orig_req->operation; + ac->base_req->op.search.base = ac->orig_req->op.search.base; ac->base_req->op.search.scope = LDB_SCOPE_BASE; - ac->base_req->op.search.tree = req->op.search.tree; + ac->base_req->op.search.tree = ac->orig_req->op.search.tree; base_attrs = talloc_array(ac->base_req, char *, 2); - if (base_attrs == NULL) - return LDB_ERR_OPERATIONS_ERROR; - base_attrs[0] = talloc_strdup(base_attrs, asq_ctrl->source_attribute); - if (base_attrs[0] == NULL) - return LDB_ERR_OPERATIONS_ERROR; + if (base_attrs == NULL) return LDB_ERR_OPERATIONS_ERROR; + + base_attrs[0] = talloc_strdup(base_attrs, ac->asq_ctrl->source_attribute); + if (base_attrs[0] == NULL) return LDB_ERR_OPERATIONS_ERROR; + base_attrs[1] = NULL; ac->base_req->op.search.attrs = (const char * const *)base_attrs; ac->base_req->context = ac; ac->base_req->callback = asq_base_callback; - ldb_set_timeout_from_prev_req(module->ldb, req, ac->base_req); - - ac->step = ASQ_SEARCH_BASE; - - ret = ldb_request(module->ldb, ac->base_req); - - if (ret != LDB_SUCCESS) { - return ret; - } + ldb_set_timeout_from_prev_req(ac->module->ldb, ac->orig_req, ac->base_req); return LDB_SUCCESS; } -static int asq_requests(struct ldb_handle *handle) { - struct asq_context *ac; +static int asq_build_multiple_requests(struct asq_context *ac, struct ldb_handle *handle) +{ struct ldb_message_element *el; int i; - ac = talloc_get_type(handle->private_data, struct asq_context); - if (ac == NULL) { - return LDB_ERR_OPERATIONS_ERROR; - } - /* look up the DNs */ if (ac->base_res == NULL) { return LDB_ERR_NO_SUCH_OBJECT; @@ -311,7 +252,6 @@ static int asq_requests(struct ldb_handle *handle) { return asq_terminate(handle); } - /* build up the requests call chain */ ac->num_reqs = el->num_values; ac->cur_req = 0; ac->reqs = talloc_array(ac, struct ldb_request *, ac->num_reqs); @@ -339,11 +279,114 @@ static int asq_requests(struct ldb_handle *handle) { ldb_set_timeout_from_prev_req(ac->module->ldb, ac->base_req, ac->reqs[i]); } - ac->step = ASQ_SEARCH_MULTI; - return LDB_SUCCESS; } +static int asq_search_continue(struct ldb_handle *h) +{ + struct asq_context *ac; + int ret; + + ac = talloc_get_type(h->private_data, struct asq_context); + + switch (ac->step) { + case ASQ_INIT: + /* check the search is well formed */ + if (ac->orig_req->op.search.scope != LDB_SCOPE_BASE) { + ac->asq_ret = ASQ_CTRL_UNWILLING_TO_PERFORM; + return asq_terminate(h); + } + + ac->req_attrs = ac->orig_req->op.search.attrs; + ac->req_attribute = talloc_strdup(ac, ac->asq_ctrl->source_attribute); + if (ac->req_attribute == NULL) + return LDB_ERR_OPERATIONS_ERROR; + + /* get the object to retrieve the DNs to search */ + ret = asq_build_first_request(ac); + if (ret != LDB_SUCCESS) { + return ret; + } + + ac->step = ASQ_SEARCH_BASE; + + return ldb_request(ac->module->ldb, ac->base_req); + + case ASQ_SEARCH_BASE: + + /* build up the requests call chain */ + ret = asq_build_multiple_requests(ac, h); + if (ret != LDB_SUCCESS) { + return ret; + } + if (h->state == LDB_ASYNC_DONE) { + return LDB_SUCCESS; + } + + ac->step = ASQ_SEARCH_MULTI; + + /* no break nor return, + * the set of requests is performed in ASQ_SEARCH_MULTI + */ + /* fall through */ + + case ASQ_SEARCH_MULTI: + + if (ac->cur_req >= ac->num_reqs) { + return asq_terminate(h); + } + + return ldb_request(ac->module->ldb, ac->reqs[ac->cur_req]); + + default: + ret = LDB_ERR_OPERATIONS_ERROR; + break; + } + + /* this is reached only in case of error */ + /* FIXME: fire an async reply ? */ + h->status = ret; + h->state = LDB_ASYNC_DONE; + return ret; +} + +static int asq_search(struct ldb_module *module, struct ldb_request *req) +{ + struct ldb_control *control; + struct asq_context *ac; + struct ldb_handle *h; + + /* 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->handle = NULL; + + if (!req->callback || !req->context) { + ldb_set_errstring(module->ldb, + "Async interface called with NULL callback function or NULL context"); + return LDB_ERR_OPERATIONS_ERROR; + } + + h = init_handle(req, module); + if (!h) { + return LDB_ERR_OPERATIONS_ERROR; + } + ac = talloc_get_type(h->private_data, struct asq_context); + + ac->asq_ctrl = talloc_get_type(control->data, struct ldb_asq_control); + if (!ac->asq_ctrl) { + return LDB_ERR_PROTOCOL_ERROR; + } + + req->handle = h; + + return asq_search_continue(h); +} + static int asq_wait_none(struct ldb_handle *handle) { struct asq_context *ac; @@ -382,22 +425,10 @@ static int asq_wait_none(struct ldb_handle *handle) return LDB_SUCCESS; } - ret = asq_requests(handle); - - /* no break nor return, - * the set of requests is performed in ASQ_SEARCH_MULTI - */ - /* fall through */ + return asq_search_continue(handle); case ASQ_SEARCH_MULTI: - if (ac->reqs[ac->cur_req]->handle == NULL) { - ret = ldb_request(ac->module->ldb, ac->reqs[ac->cur_req]); - if (ret != LDB_SUCCESS) { - return ret; - } - } - ret = ldb_wait(ac->reqs[ac->cur_req]->handle, LDB_WAIT_NONE); if (ret != LDB_SUCCESS) { @@ -412,11 +443,7 @@ static int asq_wait_none(struct ldb_handle *handle) ac->cur_req++; } - if (ac->cur_req < ac->num_reqs) { - return LDB_SUCCESS; - } - - return asq_terminate(handle); + return asq_search_continue(handle); default: ret = LDB_ERR_OPERATIONS_ERROR; -- cgit From f400fc4d0d8c110bf0077899d26f38283acaad7d Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Wed, 10 Jan 2007 22:22:28 +0000 Subject: r20669: Simplifing more (This used to be commit 03de577059cb71bb6d5df7a65b5f5ba30bdea746) --- source4/lib/ldb/modules/asq.c | 144 ++++++++++++++++-------------------------- 1 file changed, 56 insertions(+), 88 deletions(-) (limited to 'source4/lib/ldb/modules/asq.c') diff --git a/source4/lib/ldb/modules/asq.c b/source4/lib/ldb/modules/asq.c index 92e2fc5294..0c7cd7f0d4 100644 --- a/source4/lib/ldb/modules/asq.c +++ b/source4/lib/ldb/modules/asq.c @@ -282,19 +282,30 @@ static int asq_build_multiple_requests(struct asq_context *ac, struct ldb_handle return LDB_SUCCESS; } -static int asq_search_continue(struct ldb_handle *h) +static int asq_search_continue(struct ldb_handle *handle) { struct asq_context *ac; int ret; + + if (!handle || !handle->private_data) { + return LDB_ERR_OPERATIONS_ERROR; + } - ac = talloc_get_type(h->private_data, struct asq_context); + if (handle->state == LDB_ASYNC_DONE) { + return handle->status; + } + + ac = talloc_get_type(handle->private_data, struct asq_context); + if (ac == NULL) { + return LDB_ERR_OPERATIONS_ERROR; + } switch (ac->step) { case ASQ_INIT: /* check the search is well formed */ if (ac->orig_req->op.search.scope != LDB_SCOPE_BASE) { ac->asq_ret = ASQ_CTRL_UNWILLING_TO_PERFORM; - return asq_terminate(h); + return asq_terminate(handle); } ac->req_attrs = ac->orig_req->op.search.attrs; @@ -310,43 +321,70 @@ static int asq_search_continue(struct ldb_handle *h) ac->step = ASQ_SEARCH_BASE; + handle->state = LDB_ASYNC_PENDING; + handle->status = LDB_SUCCESS; + return ldb_request(ac->module->ldb, ac->base_req); case ASQ_SEARCH_BASE: + ret = ldb_wait(ac->base_req->handle, LDB_WAIT_NONE); + + if (ret != LDB_SUCCESS) { + handle->status = ret; + goto done; + } + + if (ac->base_req->handle->status != LDB_SUCCESS) { + handle->status = ac->base_req->handle->status; + goto done; + } + if (ac->base_req->handle->state != LDB_ASYNC_DONE) { + return LDB_SUCCESS; + } + /* build up the requests call chain */ - ret = asq_build_multiple_requests(ac, h); + ret = asq_build_multiple_requests(ac, handle); if (ret != LDB_SUCCESS) { return ret; } - if (h->state == LDB_ASYNC_DONE) { + if (handle->state == LDB_ASYNC_DONE) { return LDB_SUCCESS; } ac->step = ASQ_SEARCH_MULTI; - /* no break nor return, - * the set of requests is performed in ASQ_SEARCH_MULTI - */ - /* fall through */ + return ldb_request(ac->module->ldb, ac->reqs[ac->cur_req]); case ASQ_SEARCH_MULTI: - if (ac->cur_req >= ac->num_reqs) { - return asq_terminate(h); + ret = ldb_wait(ac->reqs[ac->cur_req]->handle, LDB_WAIT_NONE); + + if (ret != LDB_SUCCESS) { + handle->status = ret; + goto done; + } + if (ac->reqs[ac->cur_req]->handle->status != LDB_SUCCESS) { + handle->status = ac->reqs[ac->cur_req]->handle->status; } - return ldb_request(ac->module->ldb, ac->reqs[ac->cur_req]); + if (ac->reqs[ac->cur_req]->handle->state == LDB_ASYNC_DONE) { + ac->cur_req++; + + if (ac->cur_req >= ac->num_reqs) { + return asq_terminate(handle); + } + + return ldb_request(ac->module->ldb, ac->reqs[ac->cur_req]); + } default: ret = LDB_ERR_OPERATIONS_ERROR; break; } - /* this is reached only in case of error */ - /* FIXME: fire an async reply ? */ - h->status = ret; - h->state = LDB_ASYNC_DONE; +done: + handle->state = LDB_ASYNC_DONE; return ret; } @@ -387,82 +425,12 @@ static int asq_search(struct ldb_module *module, struct ldb_request *req) return asq_search_continue(h); } -static int asq_wait_none(struct ldb_handle *handle) -{ - struct asq_context *ac; - int ret; - - if (!handle || !handle->private_data) { - return LDB_ERR_OPERATIONS_ERROR; - } - - if (handle->state == LDB_ASYNC_DONE) { - return handle->status; - } - - handle->state = LDB_ASYNC_PENDING; - handle->status = LDB_SUCCESS; - - ac = talloc_get_type(handle->private_data, struct asq_context); - if (ac == NULL) { - return LDB_ERR_OPERATIONS_ERROR; - } - - switch (ac->step) { - case ASQ_SEARCH_BASE: - ret = ldb_wait(ac->base_req->handle, LDB_WAIT_NONE); - - if (ret != LDB_SUCCESS) { - handle->status = ret; - goto done; - } - - if (ac->base_req->handle->status != LDB_SUCCESS) { - handle->status = ac->base_req->handle->status; - goto done; - } - if (ac->base_req->handle->state != LDB_ASYNC_DONE) { - return LDB_SUCCESS; - } - - return asq_search_continue(handle); - - case ASQ_SEARCH_MULTI: - - ret = ldb_wait(ac->reqs[ac->cur_req]->handle, LDB_WAIT_NONE); - - if (ret != LDB_SUCCESS) { - handle->status = ret; - goto done; - } - if (ac->reqs[ac->cur_req]->handle->status != LDB_SUCCESS) { - handle->status = ac->reqs[ac->cur_req]->handle->status; - } - - if (ac->reqs[ac->cur_req]->handle->state == LDB_ASYNC_DONE) { - ac->cur_req++; - } - - return asq_search_continue(handle); - - default: - ret = LDB_ERR_OPERATIONS_ERROR; - goto done; - } - - ret = LDB_SUCCESS; - -done: - handle->state = LDB_ASYNC_DONE; - return ret; -} - static int asq_wait_all(struct ldb_handle *handle) { int ret; while (handle->state != LDB_ASYNC_DONE) { - ret = asq_wait_none(handle); + ret = asq_search_continue(handle); if (ret != LDB_SUCCESS) { return ret; } @@ -476,7 +444,7 @@ static int asq_wait(struct ldb_handle *handle, enum ldb_wait_type type) if (type == LDB_WAIT_ALL) { return asq_wait_all(handle); } else { - return asq_wait_none(handle); + return asq_search_continue(handle); } } -- cgit From d38a7a39fa10a2567b5906480aa85fa0c5c8310a Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Wed, 10 Jan 2007 22:31:42 +0000 Subject: r20670: Make the logic more clear (This used to be commit 906630f18e5fab4be6c40018aafe67df1e27c92e) --- source4/lib/ldb/modules/asq.c | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) (limited to 'source4/lib/ldb/modules/asq.c') diff --git a/source4/lib/ldb/modules/asq.c b/source4/lib/ldb/modules/asq.c index 0c7cd7f0d4..413f6732ac 100644 --- a/source4/lib/ldb/modules/asq.c +++ b/source4/lib/ldb/modules/asq.c @@ -339,22 +339,25 @@ static int asq_search_continue(struct ldb_handle *handle) handle->status = ac->base_req->handle->status; goto done; } - if (ac->base_req->handle->state != LDB_ASYNC_DONE) { - return LDB_SUCCESS; - } - /* build up the requests call chain */ - ret = asq_build_multiple_requests(ac, handle); - if (ret != LDB_SUCCESS) { - return ret; - } - if (handle->state == LDB_ASYNC_DONE) { - return LDB_SUCCESS; - } + if (ac->base_req->handle->state == LDB_ASYNC_DONE) { + + /* build up the requests call chain */ + ret = asq_build_multiple_requests(ac, handle); + if (ret != LDB_SUCCESS) { + return ret; + } + if (handle->state == LDB_ASYNC_DONE) { + return LDB_SUCCESS; + } + + ac->step = ASQ_SEARCH_MULTI; - ac->step = ASQ_SEARCH_MULTI; + return ldb_request(ac->module->ldb, ac->reqs[ac->cur_req]); + } - return ldb_request(ac->module->ldb, ac->reqs[ac->cur_req]); + /* request still pending, return to cycle again */ + return LDB_SUCCESS; case ASQ_SEARCH_MULTI: @@ -371,13 +374,16 @@ static int asq_search_continue(struct ldb_handle *handle) if (ac->reqs[ac->cur_req]->handle->state == LDB_ASYNC_DONE) { ac->cur_req++; - if (ac->cur_req >= ac->num_reqs) { - return asq_terminate(handle); + if (ac->cur_req < ac->num_reqs) { + return ldb_request(ac->module->ldb, ac->reqs[ac->cur_req]); } - return ldb_request(ac->module->ldb, ac->reqs[ac->cur_req]); + return asq_terminate(handle); } + /* request still pending, return to cycle again */ + return LDB_SUCCESS; + default: ret = LDB_ERR_OPERATIONS_ERROR; break; -- cgit From 7dc7156bd76425df129102a42dd29a85fd8c7ebc Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Thu, 22 Feb 2007 01:54:40 +0000 Subject: r21496: A number of ldb control and LDAP changes, surrounding the 'phantom_root' flag in the search_options control - Add in support for LDB controls to the js layer - Test the behaviour - Implement support for the 'phantom_root' flag in the partitions module - Make the LDAP server set the 'phantom_root' flag in the search_options control - This replaces the global_catalog flag passed down as an opaque pointer - Rework the string-format control parsing function into ldb_parse_control_strings(), returning errors by ldb_errorstring() method, rather than with printf to stderr - Rework some of the ldb_control handling logic Andrew Bartlett (This used to be commit 2b3df7f38d7790358dbb4de1b8609bf794a351fb) --- source4/lib/ldb/modules/asq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/modules/asq.c') diff --git a/source4/lib/ldb/modules/asq.c b/source4/lib/ldb/modules/asq.c index 413f6732ac..0c31727909 100644 --- a/source4/lib/ldb/modules/asq.c +++ b/source4/lib/ldb/modules/asq.c @@ -401,7 +401,7 @@ static int asq_search(struct ldb_module *module, struct ldb_request *req) struct ldb_handle *h; /* check if there's a paged request control */ - control = get_control_from_list(req->controls, LDB_CONTROL_ASQ_OID); + control = ldb_request_get_control(req, LDB_CONTROL_ASQ_OID); if (control == NULL) { /* not found go on */ return ldb_next_request(module, req); -- cgit From 52fb06edc25e8538c413df1aaabba18c859a00cf Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 5 May 2007 18:50:56 +0000 Subject: r22681: Fix standalone ldb build when parent directory name != ldb. (This used to be commit 1093875d59f1ea9b8bd82277d4f9d8366e584952) --- source4/lib/ldb/modules/asq.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source4/lib/ldb/modules/asq.c') diff --git a/source4/lib/ldb/modules/asq.c b/source4/lib/ldb/modules/asq.c index 0c31727909..f8438d98b8 100644 --- a/source4/lib/ldb/modules/asq.c +++ b/source4/lib/ldb/modules/asq.c @@ -33,8 +33,7 @@ * Author: Simo Sorce */ -#include "includes.h" -#include "ldb/include/includes.h" +#include "ldb_includes.h" struct asq_context { -- cgit From b8d69a7ea2505b706ff7c74d7c97bc89d82dfa07 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 02:46:15 +0000 Subject: r23795: more v2->v3 conversion (This used to be commit 84b468b2f8f2dffda89593f816e8bc6a8b6d42ac) --- source4/lib/ldb/modules/asq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/modules/asq.c') diff --git a/source4/lib/ldb/modules/asq.c b/source4/lib/ldb/modules/asq.c index f8438d98b8..cbc1075612 100644 --- a/source4/lib/ldb/modules/asq.c +++ b/source4/lib/ldb/modules/asq.c @@ -10,7 +10,7 @@ This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. + version 3 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of -- cgit From 6c973f4e8ccbcb6c9275f8a54e26abb19df7e15a Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 03:42:26 +0000 Subject: r23798: updated old Temple Place FSF addresses to new URL (This used to be commit 40c0919aaa9c1b14bbaebb95ecce53eb0380fdbb) --- source4/lib/ldb/modules/asq.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source4/lib/ldb/modules/asq.c') diff --git a/source4/lib/ldb/modules/asq.c b/source4/lib/ldb/modules/asq.c index cbc1075612..c0d6a7c18c 100644 --- a/source4/lib/ldb/modules/asq.c +++ b/source4/lib/ldb/modules/asq.c @@ -18,8 +18,7 @@ Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + License along with this library; if not, see . */ /* -- cgit From 5a1433cae7bafe01371663aed8520ce29175cac7 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 24 Dec 2007 01:38:37 -0600 Subject: r26581: Make ldb_wait uniform, so that it is easy to remove it completely from modules later on. (This used to be commit f75ce8c20aa2b466e9ee86fdf1702b2ffda10ddf) --- source4/lib/ldb/modules/asq.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'source4/lib/ldb/modules/asq.c') diff --git a/source4/lib/ldb/modules/asq.c b/source4/lib/ldb/modules/asq.c index c0d6a7c18c..b6a8594166 100644 --- a/source4/lib/ldb/modules/asq.c +++ b/source4/lib/ldb/modules/asq.c @@ -429,27 +429,26 @@ static int asq_search(struct ldb_module *module, struct ldb_request *req) return asq_search_continue(h); } -static int asq_wait_all(struct ldb_handle *handle) +static int asq_wait(struct ldb_handle *handle, enum ldb_wait_type type) { int ret; - while (handle->state != LDB_ASYNC_DONE) { - ret = asq_search_continue(handle); - if (ret != LDB_SUCCESS) { - return ret; - } + if (!handle || !handle->private_data) { + return LDB_ERR_OPERATIONS_ERROR; } - return handle->status; -} - -static int asq_wait(struct ldb_handle *handle, enum ldb_wait_type type) -{ if (type == LDB_WAIT_ALL) { - return asq_wait_all(handle); - } else { - return asq_search_continue(handle); + while (handle->state != LDB_ASYNC_DONE) { + ret = asq_search_continue(handle); + if (ret != LDB_SUCCESS) { + return ret; + } + } + + return handle->status; } + + return asq_search_continue(handle); } static int asq_init(struct ldb_module *module) -- cgit From 16109a40c0abd8c30a5eb9bf9ef692bfae9dfc7d Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 20 Feb 2008 01:54:32 +0100 Subject: Use struct-based rather than function-based initialization for ldb modules everywhere. (This used to be commit 85c96a325867f7bcdb412ebc53f8a47dbf7cd89b) --- source4/lib/ldb/modules/asq.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'source4/lib/ldb/modules/asq.c') diff --git a/source4/lib/ldb/modules/asq.c b/source4/lib/ldb/modules/asq.c index b6a8594166..eb27263b16 100644 --- a/source4/lib/ldb/modules/asq.c +++ b/source4/lib/ldb/modules/asq.c @@ -473,15 +473,9 @@ static int asq_init(struct ldb_module *module) return ldb_next_init(module); } - -static const struct ldb_module_ops asq_ops = { +const struct ldb_module_ops ldb_asq_module_ops = { .name = "asq", .search = asq_search, .wait = asq_wait, .init_context = asq_init }; - -int ldb_asq_init(void) -{ - return ldb_register_module(&asq_ops); -} -- cgit