From c908d0b2aa111659e57a73efb8c33c413965c846 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Fri, 6 Jan 2006 04:01:23 +0000 Subject: r12733: Merge ldap/ldb controls into main tree There's still lot of work to do but the patch is stable enough to be pushed into the main samba4 tree. Simo. (This used to be commit 77125feaff252cab44d26593093a9c211c846ce8) --- source4/lib/ldb/modules/paged_results.c | 296 ++++++++++++++++++++++++++++++++ 1 file changed, 296 insertions(+) create mode 100644 source4/lib/ldb/modules/paged_results.c (limited to 'source4/lib/ldb/modules/paged_results.c') diff --git a/source4/lib/ldb/modules/paged_results.c b/source4/lib/ldb/modules/paged_results.c new file mode 100644 index 0000000000..31b73d2ae4 --- /dev/null +++ b/source4/lib/ldb/modules/paged_results.c @@ -0,0 +1,296 @@ +/* + 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 paged results control module + * + * Description: this module caches a complete search and sends back + * results in chunks as asked by the client + * + * Author: Simo Sorce + */ + +#include "includes.h" +#include "ldb/include/ldb.h" +#include "ldb/include/ldb_errors.h" +#include "ldb/include/ldb_private.h" + +#include + +struct results_store { + char *cookie; + time_t timestamp; + int num_sent; + struct ldb_result *result; + struct results_store *prev; + struct results_store *next; +}; + +struct private_data { + + int next_free_id; + struct results_store *store; + +}; + + +static struct results_store *new_store(struct private_data *priv) +{ + struct results_store *new; + int new_id = priv->next_free_id++; + + /* TODO: we should have a limit on the number of + * outstanding paged searches + */ + + new = talloc(priv, struct results_store); + if (!new) return NULL; + + new->cookie = talloc_asprintf(new, "%d", new_id); + if (!new->cookie) { + talloc_free(new); + return NULL; + } + + new->timestamp = time(NULL); + + new->num_sent = 0; + new->result = NULL; + + /* put this entry as first */ + new->prev = NULL; + new->next = priv->store; + if (priv->store != NULL) priv->store->prev = new; + priv->store = new; + + return new; +} + +static void remove_store(struct results_store *store) +{ + if (store->prev) { + store->prev->next = store->next; + } + if (store->next) { + store->next->prev = store->prev; + } + talloc_free(store); +} + +/* search */ +static int paged_search(struct ldb_module *module, struct ldb_request *req) +{ + struct private_data *private_data = talloc_get_type(module->private_data, struct private_data); + struct results_store *current = NULL; + struct ldb_result *paged_result; + struct ldb_control **saved_controls; + struct ldb_control *control; + struct ldb_paged_control *paged_ctrl; + struct ldb_paged_control *paged_ret; + int i, ret; + + /* check if there's a paged request control */ + control = get_control_from_list(req->controls, LDB_CONTROL_PAGED_RESULTS_OID); + + if (control == NULL) { + /* not found go on */ + return ldb_next_request(module, req); + } + + paged_ctrl = talloc_get_type(control->data, struct ldb_paged_control); + + /* check if it is a continuation search the store */ + if (paged_ctrl->cookie_len != 0) { + for (current = private_data->store; current; current = current->next) { + if (strcmp(current->cookie, paged_ctrl->cookie) == 0) { + current->timestamp = time(NULL); + break; + } + } + if (current == NULL) { + return LDB_ERR_UNWILLING_TO_PERFORM; + } + } + + /* is this a brand new paged request ? */ + if (current == NULL) { + + /* save controls list and remove this one from the list */ + if (!save_controls(control, req, &saved_controls)) { + return LDB_ERR_OTHER; + } + + /* perform the search */ + ret = ldb_next_request(module, req); + + /* restore original controls list */ + if (req->controls) talloc_free(req->controls); + req->controls = saved_controls; + + if (ret != LDB_SUCCESS) { + return ret; + } + + /* create a new entry in the cache */ + current = new_store(private_data); + if (!current) { + return LDB_ERR_OTHER; + } + + /* steal the search result */ + current->result = talloc_steal(current, req->op.search.res); + req->op.search.res = NULL; + } + + /* create a container for the next batch of results */ + paged_result = talloc(current, struct ldb_result); + if (!paged_result) { + return LDB_ERR_OTHER; + } + paged_result->count = 0; + paged_result->msgs = NULL; + paged_result->controls = NULL; + + /* check if it is an abandon */ + if (paged_ctrl->size == 0) { + req->op.search.res = talloc_steal(private_data, paged_result); + remove_store(current); + return LDB_SUCCESS; + } + + /* return a batch of results */ + + paged_result->controls = talloc_array(paged_result, struct ldb_control *, 2); + if (!paged_result->controls) { + talloc_free(paged_result); + return LDB_ERR_OTHER; + } + + paged_result->controls[0] = talloc(paged_result->controls, struct ldb_control); + if (!paged_result->controls[0]) { + talloc_free(paged_result); + return LDB_ERR_OTHER; + } + paged_result->controls[0]->oid = talloc_strdup(paged_result->controls[0], LDB_CONTROL_PAGED_RESULTS_OID); + paged_result->controls[0]->critical = 0; + paged_result->controls[1] = NULL; + + paged_ret = talloc(paged_result->controls[0], struct ldb_paged_control); + if (!paged_ret) { + talloc_free(paged_result); + return LDB_ERR_OTHER; + } + paged_result->controls[0]->data = paged_ret; + + if (paged_ctrl->size >= current->result->count) { + paged_ret->size = 0; + paged_ret->cookie = NULL; + paged_ret->cookie_len = 0; + paged_result->count = current->result->count; + current->result->count = 0; + } else { + paged_ret->size = current->result->count; + paged_ret->cookie = talloc_strdup(paged_ret, current->cookie); + paged_ret->cookie_len = strlen(paged_ret->cookie) + 1; + paged_result->count = paged_ctrl->size; + current->result->count -= paged_ctrl->size; + } + + paged_result->msgs = talloc_array(paged_result, struct ldb_message *, paged_result->count + 1); + if (!paged_result->msgs) { + talloc_free(paged_result); + return LDB_ERR_OTHER; + } + for (i = 0; i < paged_result->count; i++) { + paged_result->msgs[i] = talloc_steal(paged_result->msgs, current->result->msgs[current->num_sent + i]); + } + current->num_sent += paged_result->count; + paged_result->msgs[paged_result->count] = NULL; + + req->op.search.res = paged_result; + + return LDB_SUCCESS; +} + +static int paged_request(struct ldb_module *module, struct ldb_request *req) +{ + switch (req->operation) { + + case LDB_REQ_SEARCH: + return paged_search(module, req); + + default: + return ldb_next_request(module, req); + + } +} + +static const struct ldb_module_ops paged_ops = { + .name = "paged_results", + .request = paged_request, +}; + +struct ldb_module *paged_results_module_init(struct ldb_context *ldb, int stage, const char *options[]) +{ + struct ldb_module *ctx; + struct private_data *data; + + if (stage == LDB_MODULES_INIT_STAGE_2) { + struct ldb_request request; + int ret; + + request.operation = LDB_REQ_REGISTER; + request.op.reg.oid = LDB_CONTROL_PAGED_RESULTS_OID; + request.controls = NULL; + + ret = ldb_request(ldb, &request); + if (ret != LDB_SUCCESS) { + ldb_debug(ldb, LDB_DEBUG_ERROR, "paged_request: Unable to register control with rootdse!\n"); + } + + return NULL; + } + + ctx = talloc(ldb, struct ldb_module); + if (!ctx) + return NULL; + + data = talloc(ctx, struct private_data); + if (data == NULL) { + talloc_free(ctx); + return NULL; + } + + data->next_free_id = 1; + data->store = NULL; + ctx->private_data = data; + + ctx->ldb = ldb; + ctx->prev = ctx->next = NULL; + ctx->ops = &paged_ops; + + return ctx; +} -- cgit From dbef4d76de92c3388f4e1819a76d6febf90be290 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Fri, 6 Jan 2006 16:12:45 +0000 Subject: r12743: Remove the ugly way we had to make a second stage init and introduce a second_stage_init private function for modules that need a second stage init. Simo. (This used to be commit 5e8b365fa2d93801a5de1d9ea76ce9d5546bd248) --- source4/lib/ldb/modules/paged_results.c | 37 ++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 17 deletions(-) (limited to 'source4/lib/ldb/modules/paged_results.c') diff --git a/source4/lib/ldb/modules/paged_results.c b/source4/lib/ldb/modules/paged_results.c index 31b73d2ae4..8e9fc28348 100644 --- a/source4/lib/ldb/modules/paged_results.c +++ b/source4/lib/ldb/modules/paged_results.c @@ -248,32 +248,35 @@ static int paged_request(struct ldb_module *module, struct ldb_request *req) } } +static int paged_request_init_2(struct ldb_module *module) +{ + struct ldb_request request; + int ret; + + request.operation = LDB_REQ_REGISTER; + request.op.reg.oid = LDB_CONTROL_PAGED_RESULTS_OID; + request.controls = NULL; + + ret = ldb_request(module->ldb, &request); + if (ret != LDB_SUCCESS) { + ldb_debug(module->ldb, LDB_DEBUG_ERROR, "paged_request: Unable to register control with rootdse!\n"); + return LDB_ERR_OTHER; + } + + return ldb_next_second_stage_init(module); +} + static const struct ldb_module_ops paged_ops = { .name = "paged_results", .request = paged_request, + .second_stage_init = paged_request_init_2 }; -struct ldb_module *paged_results_module_init(struct ldb_context *ldb, int stage, const char *options[]) +struct ldb_module *paged_results_module_init(struct ldb_context *ldb, const char *options[]) { struct ldb_module *ctx; struct private_data *data; - if (stage == LDB_MODULES_INIT_STAGE_2) { - struct ldb_request request; - int ret; - - request.operation = LDB_REQ_REGISTER; - request.op.reg.oid = LDB_CONTROL_PAGED_RESULTS_OID; - request.controls = NULL; - - ret = ldb_request(ldb, &request); - if (ret != LDB_SUCCESS) { - ldb_debug(ldb, LDB_DEBUG_ERROR, "paged_request: Unable to register control with rootdse!\n"); - } - - return NULL; - } - ctx = talloc(ldb, struct ldb_module); if (!ctx) return NULL; -- cgit From 4d1c5a023cf6680474bd8d8be73f576d155cfe81 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 10 Jan 2006 16:48:32 +0000 Subject: r12829: fix ldb headers, to not include '<...>' files in .c files this helps in getting symbol -fvisibility=hidden (GCC 4 feature) working later. metze (This used to be commit 380938e97f31c7860aed1e73cc0110c6e17b472e) --- source4/lib/ldb/modules/paged_results.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'source4/lib/ldb/modules/paged_results.c') diff --git a/source4/lib/ldb/modules/paged_results.c b/source4/lib/ldb/modules/paged_results.c index 8e9fc28348..5e88052990 100644 --- a/source4/lib/ldb/modules/paged_results.c +++ b/source4/lib/ldb/modules/paged_results.c @@ -34,11 +34,7 @@ */ #include "includes.h" -#include "ldb/include/ldb.h" -#include "ldb/include/ldb_errors.h" -#include "ldb/include/ldb_private.h" - -#include +#include "ldb/include/includes.h" struct results_store { char *cookie; -- 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/paged_results.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source4/lib/ldb/modules/paged_results.c') diff --git a/source4/lib/ldb/modules/paged_results.c b/source4/lib/ldb/modules/paged_results.c index 5e88052990..c4aad4500e 100644 --- a/source4/lib/ldb/modules/paged_results.c +++ b/source4/lib/ldb/modules/paged_results.c @@ -117,6 +117,9 @@ static int paged_search(struct ldb_module *module, struct ldb_request *req) } paged_ctrl = talloc_get_type(control->data, struct ldb_paged_control); + if (!paged_ctrl) { + return LDB_ERR_PROTOCOL_ERROR; + } /* check if it is a continuation search the store */ if (paged_ctrl->cookie_len != 0) { -- 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/paged_results.c | 46 +++++++++++++-------------------- 1 file changed, 18 insertions(+), 28 deletions(-) (limited to 'source4/lib/ldb/modules/paged_results.c') diff --git a/source4/lib/ldb/modules/paged_results.c b/source4/lib/ldb/modules/paged_results.c index c4aad4500e..9d6a50e27f 100644 --- a/source4/lib/ldb/modules/paged_results.c +++ b/source4/lib/ldb/modules/paged_results.c @@ -247,10 +247,20 @@ static int paged_request(struct ldb_module *module, struct ldb_request *req) } } -static int paged_request_init_2(struct ldb_module *module) +static int paged_request_init(struct ldb_module *module) { struct ldb_request request; int ret; + struct private_data *data; + + data = talloc(module, struct private_data); + if (data == NULL) { + return LDB_ERR_OTHER; + } + + data->next_free_id = 1; + data->store = NULL; + module->private_data = data; request.operation = LDB_REQ_REGISTER; request.op.reg.oid = LDB_CONTROL_PAGED_RESULTS_OID; @@ -262,37 +272,17 @@ static int paged_request_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 paged_ops = { - .name = "paged_results", - .request = paged_request, - .second_stage_init = paged_request_init_2 + .name = "paged_results", + .request = paged_request, + .init_context = paged_request_init }; -struct ldb_module *paged_results_module_init(struct ldb_context *ldb, const char *options[]) +int ldb_paged_results_init(void) { - struct ldb_module *ctx; - struct private_data *data; - - ctx = talloc(ldb, struct ldb_module); - if (!ctx) - return NULL; - - data = talloc(ctx, struct private_data); - if (data == NULL) { - talloc_free(ctx); - return NULL; - } - - data->next_free_id = 1; - data->store = NULL; - ctx->private_data = data; - - ctx->ldb = ldb; - ctx->prev = ctx->next = NULL; - ctx->ops = &paged_ops; - - return ctx; + return ldb_register_module(&paged_ops); } + -- cgit From 82da2d401e54d0b3124b727fab755d94dd5402d4 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Wed, 8 Mar 2006 01:01:14 +0000 Subject: r13998: From now on ldb_request() will require an alloced request By freeing the request you will be sure everything down the path get freed. this also means you have to steal the results if you want to keep them :) simo. (This used to be commit e8075e6a062ce5edb84485e45d0b841c2ee2af7d) --- source4/lib/ldb/modules/paged_results.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'source4/lib/ldb/modules/paged_results.c') diff --git a/source4/lib/ldb/modules/paged_results.c b/source4/lib/ldb/modules/paged_results.c index 9d6a50e27f..fd0cc7c90b 100644 --- a/source4/lib/ldb/modules/paged_results.c +++ b/source4/lib/ldb/modules/paged_results.c @@ -249,29 +249,36 @@ static int paged_request(struct ldb_module *module, struct ldb_request *req) static int paged_request_init(struct ldb_module *module) { - struct ldb_request request; - int ret; struct private_data *data; + struct ldb_request *req; + int ret; data = talloc(module, struct private_data); if (data == NULL) { return LDB_ERR_OTHER; } - + data->next_free_id = 1; data->store = NULL; module->private_data = data; - request.operation = LDB_REQ_REGISTER; - request.op.reg.oid = LDB_CONTROL_PAGED_RESULTS_OID; - request.controls = NULL; + req = talloc(module, struct ldb_request); + if (req == NULL) { + return LDB_ERR_OPERATIONS_ERROR; + } + + req->operation = LDB_REQ_REGISTER; + req->op.reg.oid = LDB_CONTROL_PAGED_RESULTS_OID; + req->controls = NULL; - ret = ldb_request(module->ldb, &request); + ret = ldb_request(module->ldb, req); if (ret != LDB_SUCCESS) { ldb_debug(module->ldb, LDB_DEBUG_ERROR, "paged_request: Unable to register control with rootdse!\n"); + talloc_free(req); return LDB_ERR_OTHER; } + talloc_free(req); return ldb_next_init(module); } -- cgit From 54f26ea2cf62dd14924b9f32e768061f27329b9d Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Fri, 10 Mar 2006 15:28:25 +0000 Subject: r14162: Minor fixes on sort Initial work on async paged_results (This used to be commit 72523eae7f8925a2c23d3260875345adcf1661bb) --- source4/lib/ldb/modules/paged_results.c | 487 ++++++++++++++++++++++++++++++-- 1 file changed, 457 insertions(+), 30 deletions(-) (limited to 'source4/lib/ldb/modules/paged_results.c') diff --git a/source4/lib/ldb/modules/paged_results.c b/source4/lib/ldb/modules/paged_results.c index fd0cc7c90b..58b066bd14 100644 --- a/source4/lib/ldb/modules/paged_results.c +++ b/source4/lib/ldb/modules/paged_results.c @@ -1,7 +1,7 @@ /* ldb database library - Copyright (C) Simo Sorce 2005 + Copyright (C) Simo Sorce 2005-2006 ** NOTE! The following LGPL license applies to the ldb ** library. This does NOT imply that all of Samba is released @@ -23,7 +23,7 @@ */ /* - * Name: ldb + * Name: paged_result * * Component: ldb paged results control module * @@ -36,13 +36,32 @@ #include "includes.h" #include "ldb/include/includes.h" +struct message_store { + /* keep the whole ldb_async_result as an optimization + * instead of freeing and talloc-ing the container + * on each result */ + struct ldb_async_result *r; + struct message_store *next; +}; + struct results_store { char *cookie; time_t timestamp; - int num_sent; - struct ldb_result *result; + int num_sent; /* To be removed */ + struct ldb_result *result; /* To be removed */ struct results_store *prev; struct results_store *next; + + struct message_store *first; + struct message_store *last; + int num_entries; + + struct message_store *first_ref; + struct message_store *last_ref; + + struct ldb_control **controls; + + struct ldb_request *req; }; struct private_data { @@ -52,6 +71,66 @@ struct private_data { }; +struct paged_async_context { + struct ldb_module *module; + void *up_context; + int (*up_callback)(struct ldb_context *, void *, struct ldb_async_result *); + int timeout; + + int size; + + struct results_store *store; +}; + +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 paged_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 paged_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; +} + +int store_destructor(void *data) +{ + struct results_store *store = talloc_get_type(data, struct results_store); + + if (store->prev) { + store->prev->next = store->next; + } + if (store->next) { + store->next->prev = store->prev; + } + + return 0; +} static struct results_store *new_store(struct private_data *priv) { @@ -73,8 +152,13 @@ static struct results_store *new_store(struct private_data *priv) new->timestamp = time(NULL); - new->num_sent = 0; - new->result = NULL; + new->num_sent = 0; /* To be removed */ + new->result = NULL; /* To be removed */ + + new->first = NULL; + new->num_entries = 0; + new->first_ref = NULL; + new->controls = NULL; /* put this entry as first */ new->prev = NULL; @@ -82,40 +166,22 @@ static struct results_store *new_store(struct private_data *priv) if (priv->store != NULL) priv->store->prev = new; priv->store = new; - return new; -} + talloc_set_destructor(new, store_destructor); -static void remove_store(struct results_store *store) -{ - if (store->prev) { - store->prev->next = store->next; - } - if (store->next) { - store->next->prev = store->prev; - } - talloc_free(store); + return new; } /* search */ -static int paged_search(struct ldb_module *module, struct ldb_request *req) +static int paged_search(struct ldb_module *module, struct ldb_control *control, struct ldb_request *req) { struct private_data *private_data = talloc_get_type(module->private_data, struct private_data); struct results_store *current = NULL; struct ldb_result *paged_result; struct ldb_control **saved_controls; - struct ldb_control *control; struct ldb_paged_control *paged_ctrl; struct ldb_paged_control *paged_ret; int i, ret; - /* check if there's a paged request control */ - control = get_control_from_list(req->controls, LDB_CONTROL_PAGED_RESULTS_OID); - - if (control == NULL) { - /* not found go on */ - return ldb_next_request(module, req); - } - paged_ctrl = talloc_get_type(control->data, struct ldb_paged_control); if (!paged_ctrl) { return LDB_ERR_PROTOCOL_ERROR; @@ -176,7 +242,7 @@ static int paged_search(struct ldb_module *module, struct ldb_request *req) /* check if it is an abandon */ if (paged_ctrl->size == 0) { req->op.search.res = talloc_steal(private_data, paged_result); - remove_store(current); + talloc_free(current); return LDB_SUCCESS; } @@ -234,15 +300,375 @@ static int paged_search(struct ldb_module *module, struct ldb_request *req) return LDB_SUCCESS; } +static int paged_search_async_callback(struct ldb_context *ldb, void *context, struct ldb_async_result *ares) +{ + struct paged_async_context *ac = NULL; + + if (!context || !ares) { + ldb_set_errstring(ldb, talloc_asprintf(ldb, "NULL Context or Result in callback")); + goto error; + } + + ac = talloc_get_type(context, struct paged_async_context); + + if (ares->type == LDB_REPLY_ENTRY) { + if (ac->store->first == NULL) { + ac->store->first = ac->store->last = talloc(ac->store, struct message_store); + } else { + ac->store->last->next = talloc(ac->store, struct message_store); + ac->store->last = ac->store->last->next; + } + if (ac->store->last == NULL) { + goto error; + } + + ac->store->num_entries++; + + ac->store->last->r = talloc_steal(ac->store->last, ares); + if (ac->store->last->r == NULL) { + goto error; + } + ac->store->last->next = NULL; + } + + if (ares->type == LDB_REPLY_REFERRAL) { + if (ac->store->first_ref == NULL) { + ac->store->first_ref = ac->store->last_ref = talloc(ac->store, struct message_store); + } else { + ac->store->last_ref->next = talloc(ac->store, struct message_store); + ac->store->last_ref = ac->store->last_ref->next; + } + if (ac->store->last_ref == NULL) { + goto error; + } + + ac->store->last_ref->r = talloc_steal(ac->store->last, ares); + if (ac->store->last_ref->r == NULL) { + goto error; + } + ac->store->last_ref->next = NULL; + } + + if (ares->type == LDB_REPLY_DONE) { + if (ares->controls) { + ac->store->controls = talloc_steal(ac->store, ares->controls); + if (! ac->store->controls) { + goto error; + } + } + talloc_free(ares); + } + + return LDB_SUCCESS; + +error: + talloc_free(ares); + return LDB_ERR_OPERATIONS_ERROR; +} + +static int paged_search_async(struct ldb_module *module, struct ldb_control *control, struct ldb_request *req) +{ + struct private_data *private_data = talloc_get_type(module->private_data, struct private_data); + struct ldb_paged_control *paged_ctrl; + struct ldb_control **saved_controls; + struct paged_async_context *ac; + struct ldb_async_handle *h; + 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; + } + + paged_ctrl = talloc_get_type(control->data, struct ldb_paged_control); + if (!paged_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 paged_async_context); + + ac->size = paged_ctrl->size; + + /* check if it is a continuation search the store */ + if (paged_ctrl->cookie_len == 0) { + + ac->store = new_store(private_data); + if (ac->store == NULL) { + talloc_free(h); + return LDB_ERR_UNWILLING_TO_PERFORM; + } + + ac->store->req = talloc(ac->store, struct ldb_request); + if (!ac->store->req) + return LDB_ERR_OPERATIONS_ERROR; + + ac->store->req->operation = req->operation; + ac->store->req->op.search.base = req->op.search.base; + ac->store->req->op.search.scope = req->op.search.scope; + ac->store->req->op.search.tree = req->op.search.tree; + ac->store->req->op.search.attrs = req->op.search.attrs; + ac->store->req->controls = req->controls; + + /* save it locally and remove it from the list */ + /* we do not need to replace them later as we + * are keeping the original req intact */ + if (!save_controls(control, ac->store->req, &saved_controls)) { + return LDB_ERR_OPERATIONS_ERROR; + } + + ac->store->req->creds = req->creds; + + ac->store->req->async.context = ac; + ac->store->req->async.callback = paged_search_async_callback; + ac->store->req->async.timeout = req->async.timeout; + + ret = ldb_next_request(module, ac->store->req); + + } else { + struct results_store *current = NULL; + + for (current = private_data->store; current; current = current->next) { + if (strcmp(current->cookie, paged_ctrl->cookie) == 0) { + current->timestamp = time(NULL); + break; + } + } + if (current == NULL) { + talloc_free(h); + return LDB_ERR_UNWILLING_TO_PERFORM; + } + + ac->store = current; + ret = LDB_SUCCESS; + } + + req->async.handle = h; + + /* check if it is an abandon */ + if (ac->size == 0) { + talloc_free(ac->store); + h->status = LDB_SUCCESS; + h->state = LDB_ASYNC_DONE; + return LDB_SUCCESS; + } + + /* TODO: age out old outstanding requests */ + + return ret; + +} + +static int paged_async_results(struct ldb_async_handle *handle) +{ + struct paged_async_context *ac; + struct ldb_paged_control *paged; + struct ldb_async_result *ares; + struct message_store *msg; + int i, num_ctrls, ret; + + ac = talloc_get_type(handle->private_data, struct paged_async_context); + + if (ac->store == NULL) + return LDB_ERR_OPERATIONS_ERROR; + + while (ac->store->num_entries > 0 && ac->size > 0) { + msg = ac->store->first; + ret = ac->up_callback(ac->module->ldb, ac->up_context, msg->r); + if (ret != LDB_SUCCESS) { + handle->status = ret; + handle->state = LDB_ASYNC_DONE; + return ret; + } + + ac->store->first = msg->next; + talloc_free(msg); + ac->store->num_entries--; + ac->size--; + } + + handle->state = LDB_ASYNC_DONE; + + while (ac->store->first_ref != NULL) { + msg = ac->store->first_ref; + ret = ac->up_callback(ac->module->ldb, ac->up_context, msg->r); + if (ret != LDB_SUCCESS) { + handle->status = ret; + handle->state = LDB_ASYNC_DONE; + return ret; + } + + ac->store->first_ref = msg->next; + talloc_free(msg); + } + + ares = talloc_zero(ac->store, struct ldb_async_result); + if (ares == NULL) { + handle->status = LDB_ERR_OPERATIONS_ERROR; + return handle->status; + } + num_ctrls = 2; + i = 0; + + if (ac->store->controls != NULL) { + ares->controls = ac->store->controls; + while (ares->controls[i]) i++; /* counting */ + + ares->controls = talloc_steal(ares, ac->store->controls); + num_ctrls += i; + } + + ares->controls = talloc_realloc(ares, ares->controls, struct ldb_control *, num_ctrls); + if (ares->controls == NULL) { + handle->status = LDB_ERR_OPERATIONS_ERROR; + return handle->status; + } + + ares->controls[i] = talloc(ares->controls, struct ldb_control); + if (ares->controls[i] == NULL) { + handle->status = LDB_ERR_OPERATIONS_ERROR; + return handle->status; + } + + ares->controls[i]->oid = talloc_strdup(ares->controls[i], LDB_CONTROL_PAGED_RESULTS_OID); + if (ares->controls[i]->oid == NULL) { + handle->status = LDB_ERR_OPERATIONS_ERROR; + return handle->status; + } + + ares->controls[i]->critical = 0; + ares->controls[i + 1] = NULL; + + paged = talloc(ares->controls[i], struct ldb_paged_control); + if (paged == NULL) { + handle->status = LDB_ERR_OPERATIONS_ERROR; + return handle->status; + } + + ares->controls[i]->data = paged; + + if (ac->size > 0) { + paged->size = 0; + paged->cookie = NULL; + paged->cookie_len = 0; + } else { + paged->size = ac->store->num_entries; + paged->cookie = talloc_strdup(paged, ac->store->cookie); + paged->cookie_len = strlen(paged->cookie) + 1; + } + + ares->type = LDB_REPLY_DONE; + + ret = ac->up_callback(ac->module->ldb, ac->up_context, ares); + + handle->status = ret; + + return ret; +} + +static int paged_async_wait(struct ldb_async_handle *handle, enum ldb_async_wait_type type) +{ + struct paged_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 paged_async_context); + + if (ac->store->req->async.handle->state == LDB_ASYNC_DONE) { + /* if lower level is finished we do not need to call it anymore */ + /* return all we have until size == 0 or we empty storage */ + ret = paged_async_results(handle); + + /* we are done, if num_entries is zero free the storage + * as that mean we delivered the last batch */ + if (ac->store->num_entries == 0) { + talloc_free(ac->store); + } + + return ret; + } + + if (type == LDB_WAIT_ALL) { + while (ac->store->req->async.handle->state != LDB_ASYNC_DONE) { + ret = ldb_async_wait(ac->store->req->async.handle, type); + if (ret != LDB_SUCCESS) { + handle->state = LDB_ASYNC_DONE; + handle->status = ret; + return ret; + } + } + + ret = paged_async_results(handle); + + /* we are done, if num_entries is zero free the storage + * as that mean we delivered the last batch */ + if (ac->store->num_entries == 0) { + talloc_free(ac->store); + } + + return ret; + } + + ret = ldb_async_wait(ac->store->req->async.handle, type); + if (ret != LDB_SUCCESS) { + handle->state = LDB_ASYNC_DONE; + handle->status = ret; + return ret; + } + + handle->status = ret; + + if (ac->store->num_entries >= ac->size || + ac->store->req->async.handle->state == LDB_ASYNC_DONE) { + + ret = paged_async_results(handle); + + /* we are done, if num_entries is zero free the storage + * as that mean we delivered the last batch */ + if (ac->store->num_entries == 0) { + talloc_free(ac->store); + } + } + + return ret; +} + static int paged_request(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_PAGED_RESULTS_OID); + if (control == NULL) { + /* not found go on */ + return ldb_next_request(module, req); + } + switch (req->operation) { case LDB_REQ_SEARCH: - return paged_search(module, req); + return paged_search(module, control, req); + + case LDB_ASYNC_SEARCH: + return paged_search_async(module, control, req); default: - return ldb_next_request(module, req); + return LDB_ERR_PROTOCOL_ERROR; } } @@ -285,6 +711,7 @@ static int paged_request_init(struct ldb_module *module) static const struct ldb_module_ops paged_ops = { .name = "paged_results", .request = paged_request, + .async_wait = paged_async_wait, .init_context = paged_request_init }; -- 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/paged_results.c | 94 ++++++++++++++++----------------- 1 file changed, 47 insertions(+), 47 deletions(-) (limited to 'source4/lib/ldb/modules/paged_results.c') diff --git a/source4/lib/ldb/modules/paged_results.c b/source4/lib/ldb/modules/paged_results.c index 58b066bd14..5ce062868e 100644 --- a/source4/lib/ldb/modules/paged_results.c +++ b/source4/lib/ldb/modules/paged_results.c @@ -71,53 +71,6 @@ struct private_data { }; -struct paged_async_context { - struct ldb_module *module; - void *up_context; - int (*up_callback)(struct ldb_context *, void *, struct ldb_async_result *); - int timeout; - - int size; - - struct results_store *store; -}; - -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 paged_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 paged_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; -} - int store_destructor(void *data) { struct results_store *store = talloc_get_type(data, struct results_store); @@ -300,6 +253,53 @@ static int paged_search(struct ldb_module *module, struct ldb_control *control, return LDB_SUCCESS; } +struct paged_async_context { + struct ldb_module *module; + void *up_context; + int (*up_callback)(struct ldb_context *, void *, struct ldb_async_result *); + int timeout; + + int size; + + struct results_store *store; +}; + +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 paged_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 paged_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 paged_search_async_callback(struct ldb_context *ldb, void *context, struct ldb_async_result *ares) { struct paged_async_context *ac = NULL; -- cgit From 971d30bb201f5c3faff5f575d26882eb79f7955a Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 24 May 2006 07:34:11 +0000 Subject: r15854: more talloc_set_destructor() typesafe fixes (This used to be commit 61c6100617589ac6df4f527877241464cacbf8b3) --- source4/lib/ldb/modules/paged_results.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'source4/lib/ldb/modules/paged_results.c') diff --git a/source4/lib/ldb/modules/paged_results.c b/source4/lib/ldb/modules/paged_results.c index 5ce062868e..1b002716a5 100644 --- a/source4/lib/ldb/modules/paged_results.c +++ b/source4/lib/ldb/modules/paged_results.c @@ -71,10 +71,8 @@ struct private_data { }; -int store_destructor(void *data) +int store_destructor(struct results_store *store) { - struct results_store *store = talloc_get_type(data, struct results_store); - if (store->prev) { store->prev->next = store->next; } -- 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/paged_results.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) (limited to 'source4/lib/ldb/modules/paged_results.c') diff --git a/source4/lib/ldb/modules/paged_results.c b/source4/lib/ldb/modules/paged_results.c index 1b002716a5..fab1ca5ac1 100644 --- a/source4/lib/ldb/modules/paged_results.c +++ b/source4/lib/ldb/modules/paged_results.c @@ -123,7 +123,7 @@ static struct results_store *new_store(struct private_data *priv) } /* search */ -static int paged_search(struct ldb_module *module, struct ldb_control *control, struct ldb_request *req) +static int paged_search_sync(struct ldb_module *module, struct ldb_control *control, struct ldb_request *req) { struct private_data *private_data = talloc_get_type(module->private_data, struct private_data); struct results_store *current = NULL; @@ -364,15 +364,25 @@ error: return LDB_ERR_OPERATIONS_ERROR; } -static int paged_search_async(struct ldb_module *module, struct ldb_control *control, struct ldb_request *req) +static int paged_search(struct ldb_module *module, struct ldb_request *req) { - struct private_data *private_data = talloc_get_type(module->private_data, struct private_data); + struct ldb_control *control; + struct private_data *private_data; struct ldb_paged_control *paged_ctrl; struct ldb_control **saved_controls; struct paged_async_context *ac; struct ldb_async_handle *h; int ret; + /* check if there's a paged request control */ + control = get_control_from_list(req->controls, LDB_CONTROL_PAGED_RESULTS_OID); + if (control == NULL) { + /* not found go on */ + return ldb_next_request(module, req); + } + + private_data = talloc_get_type(module->private_data, struct private_data); + req->async.handle = NULL; if (!req->async.callback || !req->async.context) { @@ -463,7 +473,7 @@ static int paged_search_async(struct ldb_module *module, struct ldb_control *con } -static int paged_async_results(struct ldb_async_handle *handle) +static int paged_results(struct ldb_async_handle *handle) { struct paged_async_context *ac; struct ldb_paged_control *paged; @@ -590,7 +600,7 @@ static int paged_async_wait(struct ldb_async_handle *handle, enum ldb_async_wait if (ac->store->req->async.handle->state == LDB_ASYNC_DONE) { /* if lower level is finished we do not need to call it anymore */ /* return all we have until size == 0 or we empty storage */ - ret = paged_async_results(handle); + ret = paged_results(handle); /* we are done, if num_entries is zero free the storage * as that mean we delivered the last batch */ @@ -611,7 +621,7 @@ static int paged_async_wait(struct ldb_async_handle *handle, enum ldb_async_wait } } - ret = paged_async_results(handle); + ret = paged_results(handle); /* we are done, if num_entries is zero free the storage * as that mean we delivered the last batch */ @@ -634,7 +644,7 @@ static int paged_async_wait(struct ldb_async_handle *handle, enum ldb_async_wait if (ac->store->num_entries >= ac->size || ac->store->req->async.handle->state == LDB_ASYNC_DONE) { - ret = paged_async_results(handle); + ret = paged_results(handle); /* we are done, if num_entries is zero free the storage * as that mean we delivered the last batch */ @@ -660,10 +670,7 @@ static int paged_request(struct ldb_module *module, struct ldb_request *req) switch (req->operation) { case LDB_REQ_SEARCH: - return paged_search(module, control, req); - - case LDB_ASYNC_SEARCH: - return paged_search_async(module, control, req); + return paged_search_sync(module, control, req); default: return LDB_ERR_PROTOCOL_ERROR; @@ -707,7 +714,8 @@ static int paged_request_init(struct ldb_module *module) } static const struct ldb_module_ops paged_ops = { - .name = "paged_results", + .name = "paged_results", + .search = paged_search, .request = paged_request, .async_wait = paged_async_wait, .init_context = paged_request_init -- 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/paged_results.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'source4/lib/ldb/modules/paged_results.c') diff --git a/source4/lib/ldb/modules/paged_results.c b/source4/lib/ldb/modules/paged_results.c index fab1ca5ac1..71b99184a1 100644 --- a/source4/lib/ldb/modules/paged_results.c +++ b/source4/lib/ldb/modules/paged_results.c @@ -431,8 +431,6 @@ static int paged_search(struct ldb_module *module, struct ldb_request *req) return LDB_ERR_OPERATIONS_ERROR; } - ac->store->req->creds = req->creds; - ac->store->req->async.context = ac; ac->store->req->async.callback = paged_search_async_callback; ac->store->req->async.timeout = req->async.timeout; -- 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/paged_results.c | 152 -------------------------------- 1 file changed, 152 deletions(-) (limited to 'source4/lib/ldb/modules/paged_results.c') diff --git a/source4/lib/ldb/modules/paged_results.c b/source4/lib/ldb/modules/paged_results.c index 71b99184a1..6d864375c6 100644 --- a/source4/lib/ldb/modules/paged_results.c +++ b/source4/lib/ldb/modules/paged_results.c @@ -122,135 +122,6 @@ static struct results_store *new_store(struct private_data *priv) return new; } -/* search */ -static int paged_search_sync(struct ldb_module *module, struct ldb_control *control, struct ldb_request *req) -{ - struct private_data *private_data = talloc_get_type(module->private_data, struct private_data); - struct results_store *current = NULL; - struct ldb_result *paged_result; - struct ldb_control **saved_controls; - struct ldb_paged_control *paged_ctrl; - struct ldb_paged_control *paged_ret; - int i, ret; - - paged_ctrl = talloc_get_type(control->data, struct ldb_paged_control); - if (!paged_ctrl) { - return LDB_ERR_PROTOCOL_ERROR; - } - - /* check if it is a continuation search the store */ - if (paged_ctrl->cookie_len != 0) { - for (current = private_data->store; current; current = current->next) { - if (strcmp(current->cookie, paged_ctrl->cookie) == 0) { - current->timestamp = time(NULL); - break; - } - } - if (current == NULL) { - return LDB_ERR_UNWILLING_TO_PERFORM; - } - } - - /* is this a brand new paged request ? */ - if (current == NULL) { - - /* save controls list and remove this one from the list */ - if (!save_controls(control, req, &saved_controls)) { - return LDB_ERR_OTHER; - } - - /* perform the search */ - ret = ldb_next_request(module, req); - - /* restore original controls list */ - if (req->controls) talloc_free(req->controls); - req->controls = saved_controls; - - if (ret != LDB_SUCCESS) { - return ret; - } - - /* create a new entry in the cache */ - current = new_store(private_data); - if (!current) { - return LDB_ERR_OTHER; - } - - /* steal the search result */ - current->result = talloc_steal(current, req->op.search.res); - req->op.search.res = NULL; - } - - /* create a container for the next batch of results */ - paged_result = talloc(current, struct ldb_result); - if (!paged_result) { - return LDB_ERR_OTHER; - } - paged_result->count = 0; - paged_result->msgs = NULL; - paged_result->controls = NULL; - - /* check if it is an abandon */ - if (paged_ctrl->size == 0) { - req->op.search.res = talloc_steal(private_data, paged_result); - talloc_free(current); - return LDB_SUCCESS; - } - - /* return a batch of results */ - - paged_result->controls = talloc_array(paged_result, struct ldb_control *, 2); - if (!paged_result->controls) { - talloc_free(paged_result); - return LDB_ERR_OTHER; - } - - paged_result->controls[0] = talloc(paged_result->controls, struct ldb_control); - if (!paged_result->controls[0]) { - talloc_free(paged_result); - return LDB_ERR_OTHER; - } - paged_result->controls[0]->oid = talloc_strdup(paged_result->controls[0], LDB_CONTROL_PAGED_RESULTS_OID); - paged_result->controls[0]->critical = 0; - paged_result->controls[1] = NULL; - - paged_ret = talloc(paged_result->controls[0], struct ldb_paged_control); - if (!paged_ret) { - talloc_free(paged_result); - return LDB_ERR_OTHER; - } - paged_result->controls[0]->data = paged_ret; - - if (paged_ctrl->size >= current->result->count) { - paged_ret->size = 0; - paged_ret->cookie = NULL; - paged_ret->cookie_len = 0; - paged_result->count = current->result->count; - current->result->count = 0; - } else { - paged_ret->size = current->result->count; - paged_ret->cookie = talloc_strdup(paged_ret, current->cookie); - paged_ret->cookie_len = strlen(paged_ret->cookie) + 1; - paged_result->count = paged_ctrl->size; - current->result->count -= paged_ctrl->size; - } - - paged_result->msgs = talloc_array(paged_result, struct ldb_message *, paged_result->count + 1); - if (!paged_result->msgs) { - talloc_free(paged_result); - return LDB_ERR_OTHER; - } - for (i = 0; i < paged_result->count; i++) { - paged_result->msgs[i] = talloc_steal(paged_result->msgs, current->result->msgs[current->num_sent + i]); - } - current->num_sent += paged_result->count; - paged_result->msgs[paged_result->count] = NULL; - - req->op.search.res = paged_result; - - return LDB_SUCCESS; -} - struct paged_async_context { struct ldb_module *module; void *up_context; @@ -654,28 +525,6 @@ static int paged_async_wait(struct ldb_async_handle *handle, enum ldb_async_wait return ret; } -static int paged_request(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_PAGED_RESULTS_OID); - if (control == NULL) { - /* not found go on */ - return ldb_next_request(module, req); - } - - switch (req->operation) { - - case LDB_REQ_SEARCH: - return paged_search_sync(module, control, req); - - default: - return LDB_ERR_PROTOCOL_ERROR; - - } -} - static int paged_request_init(struct ldb_module *module) { struct private_data *data; @@ -714,7 +563,6 @@ static int paged_request_init(struct ldb_module *module) static const struct ldb_module_ops paged_ops = { .name = "paged_results", .search = paged_search, - .request = paged_request, .async_wait = paged_async_wait, .init_context = paged_request_init }; -- 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/paged_results.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'source4/lib/ldb/modules/paged_results.c') diff --git a/source4/lib/ldb/modules/paged_results.c b/source4/lib/ldb/modules/paged_results.c index 6d864375c6..bdfaea6d51 100644 --- a/source4/lib/ldb/modules/paged_results.c +++ b/source4/lib/ldb/modules/paged_results.c @@ -126,7 +126,6 @@ struct paged_async_context { struct ldb_module *module; void *up_context; int (*up_callback)(struct ldb_context *, void *, struct ldb_async_result *); - int timeout; int size; @@ -135,8 +134,7 @@ struct paged_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 paged_async_context *ac; struct ldb_async_handle *h; @@ -164,7 +162,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; } @@ -267,7 +264,7 @@ static int paged_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; } @@ -304,7 +301,7 @@ static int paged_search(struct ldb_module *module, struct ldb_request *req) ac->store->req->async.context = ac; ac->store->req->async.callback = paged_search_async_callback; - ac->store->req->async.timeout = req->async.timeout; + ldb_set_timeout_from_prev_req(module->ldb, req, ac->store->req); ret = ldb_next_request(module, ac->store->req); -- 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/paged_results.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib/ldb/modules/paged_results.c') diff --git a/source4/lib/ldb/modules/paged_results.c b/source4/lib/ldb/modules/paged_results.c index bdfaea6d51..c5a1504fa5 100644 --- a/source4/lib/ldb/modules/paged_results.c +++ b/source4/lib/ldb/modules/paged_results.c @@ -542,8 +542,8 @@ static int paged_request_init(struct ldb_module *module) return LDB_ERR_OPERATIONS_ERROR; } - req->operation = LDB_REQ_REGISTER; - req->op.reg.oid = LDB_CONTROL_PAGED_RESULTS_OID; + req->operation = LDB_REQ_REGISTER_CONTROL; + req->op.reg_control.oid = LDB_CONTROL_PAGED_RESULTS_OID; req->controls = NULL; ret = ldb_request(module->ldb, req); -- 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/paged_results.c | 56 ++++++++++++++++----------------- 1 file changed, 28 insertions(+), 28 deletions(-) (limited to 'source4/lib/ldb/modules/paged_results.c') diff --git a/source4/lib/ldb/modules/paged_results.c b/source4/lib/ldb/modules/paged_results.c index c5a1504fa5..3f2ff66b32 100644 --- a/source4/lib/ldb/modules/paged_results.c +++ b/source4/lib/ldb/modules/paged_results.c @@ -37,10 +37,10 @@ #include "ldb/include/includes.h" struct message_store { - /* keep the whole ldb_async_result as an optimization + /* keep the whole ldb_reply as an optimization * instead of freeing and talloc-ing the container * on each result */ - struct ldb_async_result *r; + struct ldb_reply *r; struct message_store *next; }; @@ -122,24 +122,24 @@ static struct results_store *new_store(struct private_data *priv) return new; } -struct paged_async_context { +struct paged_context { 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 *); int size; struct results_store *store; }; -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 paged_async_context *ac; - struct ldb_async_handle *h; + struct paged_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; @@ -147,7 +147,7 @@ static struct ldb_async_handle *init_handle(void *mem_ctx, struct ldb_module *mo h->module = module; - ac = talloc_zero(h, struct paged_async_context); + ac = talloc_zero(h, struct paged_context); if (ac == NULL) { ldb_set_errstring(module->ldb, talloc_asprintf(module, "Out of Memory")); talloc_free(h); @@ -166,16 +166,16 @@ static struct ldb_async_handle *init_handle(void *mem_ctx, struct ldb_module *mo return h; } -static int paged_search_async_callback(struct ldb_context *ldb, void *context, struct ldb_async_result *ares) +static int paged_search_callback(struct ldb_context *ldb, void *context, struct ldb_reply *ares) { - struct paged_async_context *ac = NULL; + struct paged_context *ac = NULL; if (!context || !ares) { ldb_set_errstring(ldb, talloc_asprintf(ldb, "NULL Context or Result in callback")); goto error; } - ac = talloc_get_type(context, struct paged_async_context); + ac = talloc_get_type(context, struct paged_context); if (ares->type == LDB_REPLY_ENTRY) { if (ac->store->first == NULL) { @@ -238,8 +238,8 @@ static int paged_search(struct ldb_module *module, struct ldb_request *req) struct private_data *private_data; struct ldb_paged_control *paged_ctrl; struct ldb_control **saved_controls; - struct paged_async_context *ac; - struct ldb_async_handle *h; + struct paged_context *ac; + struct ldb_handle *h; int ret; /* check if there's a paged request control */ @@ -268,7 +268,7 @@ static int paged_search(struct ldb_module *module, struct ldb_request *req) if (!h) { return LDB_ERR_OPERATIONS_ERROR; } - ac = talloc_get_type(h->private_data, struct paged_async_context); + ac = talloc_get_type(h->private_data, struct paged_context); ac->size = paged_ctrl->size; @@ -300,7 +300,7 @@ static int paged_search(struct ldb_module *module, struct ldb_request *req) } ac->store->req->async.context = ac; - ac->store->req->async.callback = paged_search_async_callback; + ac->store->req->async.callback = paged_search_callback; ldb_set_timeout_from_prev_req(module->ldb, req, ac->store->req); ret = ldb_next_request(module, ac->store->req); @@ -339,15 +339,15 @@ static int paged_search(struct ldb_module *module, struct ldb_request *req) } -static int paged_results(struct ldb_async_handle *handle) +static int paged_results(struct ldb_handle *handle) { - struct paged_async_context *ac; + struct paged_context *ac; struct ldb_paged_control *paged; - struct ldb_async_result *ares; + struct ldb_reply *ares; struct message_store *msg; int i, num_ctrls, ret; - ac = talloc_get_type(handle->private_data, struct paged_async_context); + ac = talloc_get_type(handle->private_data, struct paged_context); if (ac->store == NULL) return LDB_ERR_OPERATIONS_ERROR; @@ -382,7 +382,7 @@ static int paged_results(struct ldb_async_handle *handle) talloc_free(msg); } - ares = talloc_zero(ac->store, struct ldb_async_result); + ares = talloc_zero(ac->store, struct ldb_reply); if (ares == NULL) { handle->status = LDB_ERR_OPERATIONS_ERROR; return handle->status; @@ -446,9 +446,9 @@ static int paged_results(struct ldb_async_handle *handle) return ret; } -static int paged_async_wait(struct ldb_async_handle *handle, enum ldb_async_wait_type type) +static int paged_wait(struct ldb_handle *handle, enum ldb_wait_type type) { - struct paged_async_context *ac; + struct paged_context *ac; int ret; if (!handle || !handle->private_data) { @@ -461,7 +461,7 @@ static int paged_async_wait(struct ldb_async_handle *handle, enum ldb_async_wait handle->state = LDB_ASYNC_PENDING; - ac = talloc_get_type(handle->private_data, struct paged_async_context); + ac = talloc_get_type(handle->private_data, struct paged_context); if (ac->store->req->async.handle->state == LDB_ASYNC_DONE) { /* if lower level is finished we do not need to call it anymore */ @@ -479,7 +479,7 @@ static int paged_async_wait(struct ldb_async_handle *handle, enum ldb_async_wait if (type == LDB_WAIT_ALL) { while (ac->store->req->async.handle->state != LDB_ASYNC_DONE) { - ret = ldb_async_wait(ac->store->req->async.handle, type); + ret = ldb_wait(ac->store->req->async.handle, type); if (ret != LDB_SUCCESS) { handle->state = LDB_ASYNC_DONE; handle->status = ret; @@ -498,7 +498,7 @@ static int paged_async_wait(struct ldb_async_handle *handle, enum ldb_async_wait return ret; } - ret = ldb_async_wait(ac->store->req->async.handle, type); + ret = ldb_wait(ac->store->req->async.handle, type); if (ret != LDB_SUCCESS) { handle->state = LDB_ASYNC_DONE; handle->status = ret; @@ -560,7 +560,7 @@ static int paged_request_init(struct ldb_module *module) static const struct ldb_module_ops paged_ops = { .name = "paged_results", .search = paged_search, - .async_wait = paged_async_wait, + .wait = paged_wait, .init_context = paged_request_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/paged_results.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'source4/lib/ldb/modules/paged_results.c') diff --git a/source4/lib/ldb/modules/paged_results.c b/source4/lib/ldb/modules/paged_results.c index 3f2ff66b32..2d972b7316 100644 --- a/source4/lib/ldb/modules/paged_results.c +++ b/source4/lib/ldb/modules/paged_results.c @@ -251,9 +251,9 @@ static int paged_search(struct ldb_module *module, struct ldb_request *req) private_data = talloc_get_type(module->private_data, struct private_data); - 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; @@ -264,7 +264,7 @@ static int paged_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; } @@ -299,8 +299,8 @@ static int paged_search(struct ldb_module *module, struct ldb_request *req) return LDB_ERR_OPERATIONS_ERROR; } - ac->store->req->async.context = ac; - ac->store->req->async.callback = paged_search_callback; + ac->store->req->context = ac; + ac->store->req->callback = paged_search_callback; ldb_set_timeout_from_prev_req(module->ldb, req, ac->store->req); ret = ldb_next_request(module, ac->store->req); @@ -323,7 +323,7 @@ static int paged_search(struct ldb_module *module, struct ldb_request *req) ret = LDB_SUCCESS; } - req->async.handle = h; + req->handle = h; /* check if it is an abandon */ if (ac->size == 0) { @@ -463,7 +463,7 @@ static int paged_wait(struct ldb_handle *handle, enum ldb_wait_type type) ac = talloc_get_type(handle->private_data, struct paged_context); - if (ac->store->req->async.handle->state == LDB_ASYNC_DONE) { + if (ac->store->req->handle->state == LDB_ASYNC_DONE) { /* if lower level is finished we do not need to call it anymore */ /* return all we have until size == 0 or we empty storage */ ret = paged_results(handle); @@ -478,8 +478,8 @@ static int paged_wait(struct ldb_handle *handle, enum ldb_wait_type type) } if (type == LDB_WAIT_ALL) { - while (ac->store->req->async.handle->state != LDB_ASYNC_DONE) { - ret = ldb_wait(ac->store->req->async.handle, type); + while (ac->store->req->handle->state != LDB_ASYNC_DONE) { + ret = ldb_wait(ac->store->req->handle, type); if (ret != LDB_SUCCESS) { handle->state = LDB_ASYNC_DONE; handle->status = ret; @@ -498,7 +498,7 @@ static int paged_wait(struct ldb_handle *handle, enum ldb_wait_type type) return ret; } - ret = ldb_wait(ac->store->req->async.handle, type); + ret = ldb_wait(ac->store->req->handle, type); if (ret != LDB_SUCCESS) { handle->state = LDB_ASYNC_DONE; handle->status = ret; @@ -508,7 +508,7 @@ static int paged_wait(struct ldb_handle *handle, enum ldb_wait_type type) handle->status = ret; if (ac->store->num_entries >= ac->size || - ac->store->req->async.handle->state == LDB_ASYNC_DONE) { + ac->store->req->handle->state == LDB_ASYNC_DONE) { ret = paged_results(handle); -- 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/paged_results.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'source4/lib/ldb/modules/paged_results.c') diff --git a/source4/lib/ldb/modules/paged_results.c b/source4/lib/ldb/modules/paged_results.c index 2d972b7316..ddaed38fe9 100644 --- a/source4/lib/ldb/modules/paged_results.c +++ b/source4/lib/ldb/modules/paged_results.c @@ -141,7 +141,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; } @@ -149,7 +149,7 @@ static struct ldb_handle *init_handle(void *mem_ctx, struct ldb_module *module, ac = talloc_zero(h, struct paged_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; } @@ -171,7 +171,7 @@ static int paged_search_callback(struct ldb_context *ldb, void *context, struct struct paged_context *ac = NULL; 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; } @@ -254,8 +254,8 @@ static int paged_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 9f7da6fea0bc9a330f8620d100e27d4eabbae253 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 17 Aug 2006 01:52:24 +0000 Subject: r17579: make ldb build g++ friendly (This used to be commit 403cbd335594112e0c58fd68d20f0e3faad7d186) --- source4/lib/ldb/modules/paged_results.c | 38 ++++++++++++++++----------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'source4/lib/ldb/modules/paged_results.c') diff --git a/source4/lib/ldb/modules/paged_results.c b/source4/lib/ldb/modules/paged_results.c index ddaed38fe9..52d26502ee 100644 --- a/source4/lib/ldb/modules/paged_results.c +++ b/source4/lib/ldb/modules/paged_results.c @@ -85,41 +85,41 @@ int store_destructor(struct results_store *store) static struct results_store *new_store(struct private_data *priv) { - struct results_store *new; + struct results_store *newr; int new_id = priv->next_free_id++; /* TODO: we should have a limit on the number of * outstanding paged searches */ - new = talloc(priv, struct results_store); - if (!new) return NULL; + newr = talloc(priv, struct results_store); + if (!newr) return NULL; - new->cookie = talloc_asprintf(new, "%d", new_id); - if (!new->cookie) { - talloc_free(new); + newr->cookie = talloc_asprintf(newr, "%d", new_id); + if (!newr->cookie) { + talloc_free(newr); return NULL; } - new->timestamp = time(NULL); + newr->timestamp = time(NULL); - new->num_sent = 0; /* To be removed */ - new->result = NULL; /* To be removed */ + newr->num_sent = 0; /* To be removed */ + newr->result = NULL; /* To be removed */ - new->first = NULL; - new->num_entries = 0; - new->first_ref = NULL; - new->controls = NULL; + newr->first = NULL; + newr->num_entries = 0; + newr->first_ref = NULL; + newr->controls = NULL; /* put this entry as first */ - new->prev = NULL; - new->next = priv->store; - if (priv->store != NULL) priv->store->prev = new; - priv->store = new; + newr->prev = NULL; + newr->next = priv->store; + if (priv->store != NULL) priv->store->prev = newr; + priv->store = newr; - talloc_set_destructor(new, store_destructor); + talloc_set_destructor(newr, store_destructor); - return new; + return newr; } struct paged_context { -- 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/paged_results.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) (limited to 'source4/lib/ldb/modules/paged_results.c') diff --git a/source4/lib/ldb/modules/paged_results.c b/source4/lib/ldb/modules/paged_results.c index 52d26502ee..43c3fc0246 100644 --- a/source4/lib/ldb/modules/paged_results.c +++ b/source4/lib/ldb/modules/paged_results.c @@ -190,10 +190,7 @@ static int paged_search_callback(struct ldb_context *ldb, void *context, struct ac->store->num_entries++; - ac->store->last->r = talloc_steal(ac->store->last, ares); - if (ac->store->last->r == NULL) { - goto error; - } + ac->store->last->r = talloc_move(ac->store->last, ares); ac->store->last->next = NULL; } @@ -208,19 +205,13 @@ static int paged_search_callback(struct ldb_context *ldb, void *context, struct goto error; } - ac->store->last_ref->r = talloc_steal(ac->store->last, ares); - if (ac->store->last_ref->r == NULL) { - goto error; - } + ac->store->last_ref->r = talloc_move(ac->store->last, ares); ac->store->last_ref->next = NULL; } if (ares->type == LDB_REPLY_DONE) { if (ares->controls) { - ac->store->controls = talloc_steal(ac->store, ares->controls); - if (! ac->store->controls) { - goto error; - } + ac->store->controls = talloc_move(ac->store, ares->controls); } talloc_free(ares); } @@ -394,7 +385,7 @@ static int paged_results(struct ldb_handle *handle) ares->controls = ac->store->controls; while (ares->controls[i]) i++; /* counting */ - ares->controls = talloc_steal(ares, ac->store->controls); + ares->controls = talloc_move(ares, ac->store->controls); num_ctrls += i; } -- cgit From 24fe49a3d10633fa9be5547e89d10be1d5f9ccb1 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 13 Sep 2006 02:03:20 +0000 Subject: r18438: I should have examined these uses of talloc_move() more carefully. Most of them are OK, but a couple were not. (This used to be commit b0de2838829d9750817c31f28c11c6b2be6e7b64) --- source4/lib/ldb/modules/paged_results.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'source4/lib/ldb/modules/paged_results.c') diff --git a/source4/lib/ldb/modules/paged_results.c b/source4/lib/ldb/modules/paged_results.c index 43c3fc0246..6636efcccb 100644 --- a/source4/lib/ldb/modules/paged_results.c +++ b/source4/lib/ldb/modules/paged_results.c @@ -190,7 +190,7 @@ static int paged_search_callback(struct ldb_context *ldb, void *context, struct ac->store->num_entries++; - ac->store->last->r = talloc_move(ac->store->last, ares); + ac->store->last->r = talloc_steal(ac->store->last, ares); ac->store->last->next = NULL; } @@ -205,14 +205,12 @@ static int paged_search_callback(struct ldb_context *ldb, void *context, struct goto error; } - ac->store->last_ref->r = talloc_move(ac->store->last, ares); + ac->store->last_ref->r = talloc_steal(ac->store->last, ares); ac->store->last_ref->next = NULL; } if (ares->type == LDB_REPLY_DONE) { - if (ares->controls) { - ac->store->controls = talloc_move(ac->store, ares->controls); - } + ac->store->controls = talloc_move(ac->store, ares->controls); 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/paged_results.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib/ldb/modules/paged_results.c') diff --git a/source4/lib/ldb/modules/paged_results.c b/source4/lib/ldb/modules/paged_results.c index 6636efcccb..133ee1fb78 100644 --- a/source4/lib/ldb/modules/paged_results.c +++ b/source4/lib/ldb/modules/paged_results.c @@ -210,7 +210,7 @@ static int paged_search_callback(struct ldb_context *ldb, void *context, struct } if (ares->type == LDB_REPLY_DONE) { - ac->store->controls = talloc_move(ac->store, ares->controls); + ac->store->controls = talloc_move(ac->store, &ares->controls); talloc_free(ares); } @@ -383,7 +383,7 @@ static int paged_results(struct ldb_handle *handle) ares->controls = ac->store->controls; while (ares->controls[i]) i++; /* counting */ - ares->controls = talloc_move(ares, ac->store->controls); + ares->controls = talloc_move(ares, &ac->store->controls); num_ctrls += i; } -- cgit From 9dd6cac44a63c20e616cf15815bef61303da56c2 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sun, 17 Sep 2006 03:00:05 +0000 Subject: r18591: Better defaults for share creation Fix logic error in paged_results (This used to be commit 34ce1f8e1bab2debb508aa8bf478231389a77d42) --- source4/lib/ldb/modules/paged_results.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'source4/lib/ldb/modules/paged_results.c') diff --git a/source4/lib/ldb/modules/paged_results.c b/source4/lib/ldb/modules/paged_results.c index 133ee1fb78..3ab575ef6b 100644 --- a/source4/lib/ldb/modules/paged_results.c +++ b/source4/lib/ldb/modules/paged_results.c @@ -44,11 +44,15 @@ struct message_store { struct message_store *next; }; +struct private_data; + struct results_store { + + struct private_data *priv; + char *cookie; time_t timestamp; - int num_sent; /* To be removed */ - struct ldb_result *result; /* To be removed */ + struct results_store *prev; struct results_store *next; @@ -79,7 +83,11 @@ int store_destructor(struct results_store *store) if (store->next) { store->next->prev = store->prev; } - + + if (store == store->priv->store) { + store->priv->store = NULL; + } + return 0; } @@ -95,6 +103,8 @@ static struct results_store *new_store(struct private_data *priv) newr = talloc(priv, struct results_store); if (!newr) return NULL; + newr->priv = priv; + newr->cookie = talloc_asprintf(newr, "%d", new_id); if (!newr->cookie) { talloc_free(newr); @@ -103,9 +113,6 @@ static struct results_store *new_store(struct private_data *priv) newr->timestamp = time(NULL); - newr->num_sent = 0; /* To be removed */ - newr->result = NULL; /* To be removed */ - newr->first = NULL; newr->num_entries = 0; newr->first_ref = 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/paged_results.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'source4/lib/ldb/modules/paged_results.c') diff --git a/source4/lib/ldb/modules/paged_results.c b/source4/lib/ldb/modules/paged_results.c index 3ab575ef6b..c4b1ecf26b 100644 --- a/source4/lib/ldb/modules/paged_results.c +++ b/source4/lib/ldb/modules/paged_results.c @@ -544,9 +544,7 @@ static int paged_request_init(struct ldb_module *module) ret = ldb_request(module->ldb, req); if (ret != LDB_SUCCESS) { - ldb_debug(module->ldb, LDB_DEBUG_ERROR, "paged_request: Unable to register control with rootdse!\n"); - talloc_free(req); - return LDB_ERR_OTHER; + ldb_debug(module->ldb, LDB_DEBUG_WARNING, "paged_request: Unable to register control with rootdse!\n"); } talloc_free(req); -- 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/paged_results.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/modules/paged_results.c') diff --git a/source4/lib/ldb/modules/paged_results.c b/source4/lib/ldb/modules/paged_results.c index c4b1ecf26b..8ad1f01c8c 100644 --- a/source4/lib/ldb/modules/paged_results.c +++ b/source4/lib/ldb/modules/paged_results.c @@ -239,7 +239,7 @@ static int paged_search(struct ldb_module *module, struct ldb_request *req) int ret; /* check if there's a paged request control */ - control = get_control_from_list(req->controls, LDB_CONTROL_PAGED_RESULTS_OID); + control = ldb_request_get_control(req, LDB_CONTROL_PAGED_RESULTS_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/paged_results.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source4/lib/ldb/modules/paged_results.c') diff --git a/source4/lib/ldb/modules/paged_results.c b/source4/lib/ldb/modules/paged_results.c index 8ad1f01c8c..2f54d9bf8c 100644 --- a/source4/lib/ldb/modules/paged_results.c +++ b/source4/lib/ldb/modules/paged_results.c @@ -33,8 +33,7 @@ * Author: Simo Sorce */ -#include "includes.h" -#include "ldb/include/includes.h" +#include "ldb_includes.h" struct message_store { /* keep the whole ldb_reply as an optimization -- 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/paged_results.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/modules/paged_results.c') diff --git a/source4/lib/ldb/modules/paged_results.c b/source4/lib/ldb/modules/paged_results.c index 2f54d9bf8c..7df853e404 100644 --- a/source4/lib/ldb/modules/paged_results.c +++ b/source4/lib/ldb/modules/paged_results.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/paged_results.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source4/lib/ldb/modules/paged_results.c') diff --git a/source4/lib/ldb/modules/paged_results.c b/source4/lib/ldb/modules/paged_results.c index 7df853e404..61fce2125f 100644 --- a/source4/lib/ldb/modules/paged_results.c +++ b/source4/lib/ldb/modules/paged_results.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/paged_results.c | 48 ++++++++++++++++----------------- 1 file changed, 24 insertions(+), 24 deletions(-) (limited to 'source4/lib/ldb/modules/paged_results.c') diff --git a/source4/lib/ldb/modules/paged_results.c b/source4/lib/ldb/modules/paged_results.c index 61fce2125f..ee1bbe0335 100644 --- a/source4/lib/ldb/modules/paged_results.c +++ b/source4/lib/ldb/modules/paged_results.c @@ -440,8 +440,7 @@ static int paged_results(struct ldb_handle *handle) return ret; } -static int paged_wait(struct ldb_handle *handle, enum ldb_wait_type type) -{ +static int paged_wait_once(struct ldb_handle *handle) { struct paged_context *ac; int ret; @@ -471,28 +470,7 @@ static int paged_wait(struct ldb_handle *handle, enum ldb_wait_type type) return ret; } - if (type == LDB_WAIT_ALL) { - while (ac->store->req->handle->state != LDB_ASYNC_DONE) { - ret = ldb_wait(ac->store->req->handle, type); - if (ret != LDB_SUCCESS) { - handle->state = LDB_ASYNC_DONE; - handle->status = ret; - return ret; - } - } - - ret = paged_results(handle); - - /* we are done, if num_entries is zero free the storage - * as that mean we delivered the last batch */ - if (ac->store->num_entries == 0) { - talloc_free(ac->store); - } - - return ret; - } - - ret = ldb_wait(ac->store->req->handle, type); + ret = ldb_wait(ac->store->req->handle, LDB_WAIT_NONE); if (ret != LDB_SUCCESS) { handle->state = LDB_ASYNC_DONE; handle->status = ret; @@ -516,6 +494,28 @@ static int paged_wait(struct ldb_handle *handle, enum ldb_wait_type type) return ret; } +static int paged_wait(struct ldb_handle *handle, enum ldb_wait_type type) +{ + int ret; + + if (!handle || !handle->private_data) { + return LDB_ERR_OPERATIONS_ERROR; + } + + if (type == LDB_WAIT_ALL) { + while (handle->state != LDB_ASYNC_DONE) { + ret = paged_wait_once(handle); + if (ret != LDB_SUCCESS) { + return ret; + } + } + + return handle->status; + } + + return paged_wait_once(handle); +} + static int paged_request_init(struct ldb_module *module) { struct private_data *data; -- 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/paged_results.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'source4/lib/ldb/modules/paged_results.c') diff --git a/source4/lib/ldb/modules/paged_results.c b/source4/lib/ldb/modules/paged_results.c index ee1bbe0335..b62b1f92cb 100644 --- a/source4/lib/ldb/modules/paged_results.c +++ b/source4/lib/ldb/modules/paged_results.c @@ -549,15 +549,9 @@ static int paged_request_init(struct ldb_module *module) return ldb_next_init(module); } -static const struct ldb_module_ops paged_ops = { +const struct ldb_module_ops ldb_paged_results_module_ops = { .name = "paged_results", .search = paged_search, .wait = paged_wait, .init_context = paged_request_init }; - -int ldb_paged_results_init(void) -{ - return ldb_register_module(&paged_ops); -} - -- cgit