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/sort.c | 265 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 265 insertions(+) create mode 100644 source4/lib/ldb/modules/sort.c (limited to 'source4/lib/ldb/modules/sort.c') diff --git a/source4/lib/ldb/modules/sort.c b/source4/lib/ldb/modules/sort.c new file mode 100644 index 0000000000..2757647710 --- /dev/null +++ b/source4/lib/ldb/modules/sort.c @@ -0,0 +1,265 @@ +/* + 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 server side sort control module + * + * Description: this module sorts the results of a search + * + * Author: Simo Sorce + */ + +#include "includes.h" +#include "ldb/include/ldb.h" +#include "ldb/include/ldb_errors.h" +#include "ldb/include/ldb_private.h" + +struct opaque { + struct ldb_context *ldb; + const struct ldb_attrib_handler *h; + const char *attribute; + int reverse; + int result; +}; + +static int build_response(struct ldb_result *res, int result, const char *desc) +{ + struct ldb_sort_resp_control *resp; + 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 ) + return LDB_ERR_OPERATIONS_ERROR; + + res->controls[i+1] = NULL; + res->controls[i] = talloc(res->controls, struct ldb_control); + if (! res->controls[i] ) + return LDB_ERR_OPERATIONS_ERROR; + + res->controls[i]->oid = LDB_CONTROL_SORT_RESP_OID; + res->controls[i]->critical = 0; + + resp = talloc(res->controls[i], struct ldb_sort_resp_control); + if (! resp ) + return LDB_ERR_OPERATIONS_ERROR; + + resp->result = result; + resp->attr_desc = talloc_strdup(resp, desc); + + if (! resp->attr_desc ) + return LDB_ERR_OPERATIONS_ERROR; + + res->controls[i]->data = resp; + + return LDB_SUCCESS; +} + +static int sort_compare(struct ldb_message **msg1, struct ldb_message **msg2, void *opaque) +{ + struct opaque *data = (struct opaque *)opaque; + struct ldb_message_element *el1, *el2; + + if (data->result != 0) { + /* an error occurred previously, + * let's exit the sorting by returning always 0 */ + return 0; + } + + el1 = ldb_msg_find_element(*msg1, data->attribute); + el2 = ldb_msg_find_element(*msg2, data->attribute); + + if (!el1 || !el2) { + /* the attribute was not found return and + * set an error */ + data->result = 53; + return 0; + } + + if (data->reverse) + return data->h->comparison_fn(data->ldb, data, &el2->values[0], &el1->values[0]); + + return data->h->comparison_fn(data->ldb, data, &el1->values[0], &el2->values[0]); +} + +/* search */ +static int server_sort_search(struct ldb_module *module, struct ldb_request *req) +{ + struct ldb_result *sort_result = NULL; + struct ldb_control *control; + struct ldb_control **saved_controls; + struct ldb_server_sort_control **sort_ctrls; + int ret, result = 0; + int do_sort = 1; + + /* check if there's a paged request control */ + control = get_control_from_list(req->controls, LDB_CONTROL_SERVER_SORT_OID); + if (control == NULL) { + /* not found go on */ + return ldb_next_request(module, req); + } + + sort_ctrls = talloc_get_type(control->data, struct ldb_server_sort_control *); + + /* FIXME: we do not support more than one attribute for sorting right now */ + /* FIXME: we need to check if the attribute type exist or return an error */ + if (sort_ctrls[1] != NULL) + do_sort = 0; + + if (!do_sort && control->critical) { + sort_result = talloc_zero(req, struct ldb_result); + if (!sort_result) + return LDB_ERR_OPERATIONS_ERROR; + + req->op.search.res = sort_result; + + /* 53 = unwilling to perform */ + if ((ret = build_response(sort_result, 53, "sort control is not complete yet")) != LDB_SUCCESS) { + return ret; + } + + return LDB_ERR_UNSUPPORTED_CRITICAL_EXTENSION; + } + + /* save it locally and remove it from the list */ + if (!save_controls(control, req, &saved_controls)) { + return LDB_ERR_OPERATIONS_ERROR; + } + + ret = ldb_next_request(module, req); + + if (req->controls) talloc_free(req->controls); + req->controls = saved_controls; + + if (ret != LDB_SUCCESS) { + return ret; + } + + /* SORT HERE */ + if (do_sort) { + struct opaque *data; + + data = talloc(module, struct opaque); + if (!data) + return LDB_ERR_OPERATIONS_ERROR; + + data->attribute = sort_ctrls[0]->attributeName; + data->reverse = sort_ctrls[0]->reverse; + data->ldb = module->ldb; + data->h = ldb_attrib_handler(data->ldb, data->attribute); + data->result = 0; + sort_result = req->op.search.res; + + /* FIXME: I don't like to use a static structure like sort_control + * we need to either: + * a) write a qsort function that takes a third void parameter + * or + * b) prepare a structure with all elements pre digested like: + * struct element { + * struct ldb_message_element *el; + * struct ldb_message *msg; + * } + * + * this mean we will have to do a linear scan of + * the msgs array to build the new sort array, and + * then do a linear scan of the resulting array + * to rebuild the msgs array in the original shape. + */ + + ldb_qsort(sort_result->msgs, + sort_result->count, + sizeof(struct ldb_message *), + data, + (ldb_qsort_cmp_fn_t)sort_compare); + + result = data->result; + + talloc_free(data); + } else { + result = 53; + } + + if ((ret = build_response(sort_result, result, "sort control is not complete yet")) != LDB_SUCCESS) { + return ret; + } + + return LDB_SUCCESS; +} + +static int server_sort(struct ldb_module *module, struct ldb_request *req) +{ + switch (req->operation) { + + case LDB_REQ_SEARCH: + return server_sort_search(module, req); + + default: + return ldb_next_request(module, req); + + } +} + +static const struct ldb_module_ops server_sort_ops = { + .name = "server_sort", + .request = server_sort, +}; + +struct ldb_module *server_sort_module_init(struct ldb_context *ldb, int stage, const char *options[]) +{ + struct ldb_module *ctx; + + if (stage == LDB_MODULES_INIT_STAGE_2) { + struct ldb_request request; + int ret; + + request.operation = LDB_REQ_REGISTER; + request.op.reg.oid = LDB_CONTROL_SERVER_SORT_OID; + request.controls = NULL; + + ret = ldb_request(ldb, &request); + if (ret != LDB_SUCCESS) { + ldb_debug(ldb, LDB_DEBUG_ERROR, "server_sort: Unable to register control with rootdse!\n"); + } + + return NULL; + } + + ctx = talloc(ldb, struct ldb_module); + if (!ctx) + return NULL; + + ctx->ldb = ldb; + ctx->prev = ctx->next = NULL; + ctx->ops = &server_sort_ops; + ctx->private_data = NULL; + + 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/sort.c | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) (limited to 'source4/lib/ldb/modules/sort.c') diff --git a/source4/lib/ldb/modules/sort.c b/source4/lib/ldb/modules/sort.c index 2757647710..88b967b276 100644 --- a/source4/lib/ldb/modules/sort.c +++ b/source4/lib/ldb/modules/sort.c @@ -227,31 +227,34 @@ static int server_sort(struct ldb_module *module, struct ldb_request *req) } } +static int server_sort_init_2(struct ldb_module *module) +{ + struct ldb_request request; + int ret; + + request.operation = LDB_REQ_REGISTER; + request.op.reg.oid = LDB_CONTROL_SERVER_SORT_OID; + request.controls = NULL; + + ret = ldb_request(module->ldb, &request); + if (ret != LDB_SUCCESS) { + ldb_debug(module->ldb, LDB_DEBUG_ERROR, "server_sort: Unable to register control with rootdse!\n"); + return LDB_ERR_OTHER; + } + + return ldb_next_second_stage_init(module); +} + static const struct ldb_module_ops server_sort_ops = { .name = "server_sort", .request = server_sort, + .second_stage_init = server_sort_init_2 }; -struct ldb_module *server_sort_module_init(struct ldb_context *ldb, int stage, const char *options[]) +struct ldb_module *server_sort_module_init(struct ldb_context *ldb, const char *options[]) { struct ldb_module *ctx; - if (stage == LDB_MODULES_INIT_STAGE_2) { - struct ldb_request request; - int ret; - - request.operation = LDB_REQ_REGISTER; - request.op.reg.oid = LDB_CONTROL_SERVER_SORT_OID; - request.controls = NULL; - - ret = ldb_request(ldb, &request); - if (ret != LDB_SUCCESS) { - ldb_debug(ldb, LDB_DEBUG_ERROR, "server_sort: 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/sort.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'source4/lib/ldb/modules/sort.c') diff --git a/source4/lib/ldb/modules/sort.c b/source4/lib/ldb/modules/sort.c index 88b967b276..9a0d449cf7 100644 --- a/source4/lib/ldb/modules/sort.c +++ b/source4/lib/ldb/modules/sort.c @@ -33,9 +33,7 @@ */ #include "includes.h" -#include "ldb/include/ldb.h" -#include "ldb/include/ldb_errors.h" -#include "ldb/include/ldb_private.h" +#include "ldb/include/includes.h" struct opaque { struct ldb_context *ldb; -- 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/sort.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source4/lib/ldb/modules/sort.c') diff --git a/source4/lib/ldb/modules/sort.c b/source4/lib/ldb/modules/sort.c index 9a0d449cf7..ac9f1081de 100644 --- a/source4/lib/ldb/modules/sort.c +++ b/source4/lib/ldb/modules/sort.c @@ -126,6 +126,9 @@ static int server_sort_search(struct ldb_module *module, struct ldb_request *req } sort_ctrls = talloc_get_type(control->data, struct ldb_server_sort_control *); + if (!sort_ctrls) { + return LDB_ERR_PROTOCOL_ERROR; + } /* FIXME: we do not support more than one attribute for sorting right now */ /* FIXME: we need to check if the attribute type exist or return an error */ -- 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/sort.c | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) (limited to 'source4/lib/ldb/modules/sort.c') diff --git a/source4/lib/ldb/modules/sort.c b/source4/lib/ldb/modules/sort.c index ac9f1081de..d01e468956 100644 --- a/source4/lib/ldb/modules/sort.c +++ b/source4/lib/ldb/modules/sort.c @@ -228,7 +228,7 @@ static int server_sort(struct ldb_module *module, struct ldb_request *req) } } -static int server_sort_init_2(struct ldb_module *module) +static int server_sort_init(struct ldb_module *module) { struct ldb_request request; int ret; @@ -243,27 +243,16 @@ static int server_sort_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 server_sort_ops = { .name = "server_sort", .request = server_sort, - .second_stage_init = server_sort_init_2 + .init_context = server_sort_init }; -struct ldb_module *server_sort_module_init(struct ldb_context *ldb, const char *options[]) +int ldb_sort_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 = &server_sort_ops; - ctx->private_data = NULL; - - return ctx; + return ldb_register_module(&server_sort_ops); } -- cgit From d2745fe6adb7606ad6fe0f8fd2785b061a58382b Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Tue, 7 Mar 2006 21:09:53 +0000 Subject: r13993: First prototype of how an async module should be built. This is NOT tested yet, just compiles. Committing to share the code and gather comments (This used to be commit 1c8536750fb811c987357cf1223666e1d79b2672) --- source4/lib/ldb/modules/sort.c | 403 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 361 insertions(+), 42 deletions(-) (limited to 'source4/lib/ldb/modules/sort.c') diff --git a/source4/lib/ldb/modules/sort.c b/source4/lib/ldb/modules/sort.c index d01e468956..a37442b41f 100644 --- a/source4/lib/ldb/modules/sort.c +++ b/source4/lib/ldb/modules/sort.c @@ -43,30 +43,88 @@ struct opaque { int result; }; -static int build_response(struct ldb_result *res, int result, const char *desc) +struct sort_async_context { + struct ldb_module *module; + void *up_context; + int (*up_callback)(struct ldb_context *, void *, struct ldb_async_result *); + int timeout; + + char *attributeName; + char *orderingRule; + int reverse; + + struct ldb_request *req; + struct ldb_message **msgs; + char **referrals; + struct ldb_control **controls; + int num_msgs; + int num_refs; + + const struct ldb_attrib_handler *h; + int sort_result; +}; + +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 sort_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 sort_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; + + ac->module = module; + ac->up_context = context; + ac->up_callback = callback; + ac->timeout = timeout; + + return h; +} + +static int build_response(void *mem_ctx, struct ldb_control ***ctrls, int result, const char *desc) +{ + struct ldb_control **controls; struct ldb_sort_resp_control *resp; int i; - if (res->controls) { - for (i = 0; res->controls[i]; i++); - res->controls = talloc_realloc(res, res->controls, struct ldb_control *, i + 2); + if (*ctrls) { + controls = *ctrls; + for (i = 0; controls[i]; i++); + controls = talloc_realloc(mem_ctx, controls, struct ldb_control *, i + 2); } else { i = 0; - res->controls = talloc_array(res, struct ldb_control *, 2); + controls = talloc_array(mem_ctx, struct ldb_control *, 2); } - if (! res->controls ) + if (! controls ) return LDB_ERR_OPERATIONS_ERROR; - res->controls[i+1] = NULL; - res->controls[i] = talloc(res->controls, struct ldb_control); - if (! res->controls[i] ) + *ctrls = controls; + + controls[i+1] = NULL; + controls[i] = talloc(controls, struct ldb_control); + if (! controls[i] ) return LDB_ERR_OPERATIONS_ERROR; - res->controls[i]->oid = LDB_CONTROL_SORT_RESP_OID; - res->controls[i]->critical = 0; + controls[i]->oid = LDB_CONTROL_SORT_RESP_OID; + controls[i]->critical = 0; - resp = talloc(res->controls[i], struct ldb_sort_resp_control); + resp = talloc(controls[i], struct ldb_sort_resp_control); if (! resp ) return LDB_ERR_OPERATIONS_ERROR; @@ -76,7 +134,7 @@ static int build_response(struct ldb_result *res, int result, const char *desc) if (! resp->attr_desc ) return LDB_ERR_OPERATIONS_ERROR; - res->controls[i]->data = resp; + controls[i]->data = resp; return LDB_SUCCESS; } @@ -108,23 +166,42 @@ static int sort_compare(struct ldb_message **msg1, struct ldb_message **msg2, vo return data->h->comparison_fn(data->ldb, data, &el1->values[0], &el2->values[0]); } +static int sort_compare_async(struct ldb_message **msg1, struct ldb_message **msg2, void *opaque) +{ + struct sort_async_context *ac = talloc_get_type(opaque, struct sort_async_context); + struct ldb_message_element *el1, *el2; + + if (ac->sort_result != 0) { + /* an error occurred previously, + * let's exit the sorting by returning always 0 */ + return 0; + } + + el1 = ldb_msg_find_element(*msg1, ac->attributeName); + el2 = ldb_msg_find_element(*msg2, ac->attributeName); + + if (!el1 || !el2) { + /* the attribute was not found return and + * set an error */ + ac->sort_result = 53; + return 0; + } + + if (ac->reverse) + return ac->h->comparison_fn(ac->module->ldb, ac, &el2->values[0], &el1->values[0]); + + return ac->h->comparison_fn(ac->module->ldb, ac, &el1->values[0], &el2->values[0]); +} + /* search */ -static int server_sort_search(struct ldb_module *module, struct ldb_request *req) +static int server_sort_search(struct ldb_module *module, struct ldb_control *control, struct ldb_request *req) { struct ldb_result *sort_result = NULL; - struct ldb_control *control; struct ldb_control **saved_controls; struct ldb_server_sort_control **sort_ctrls; int ret, result = 0; int do_sort = 1; - /* check if there's a paged request control */ - control = get_control_from_list(req->controls, LDB_CONTROL_SERVER_SORT_OID); - if (control == NULL) { - /* not found go on */ - return ldb_next_request(module, req); - } - sort_ctrls = talloc_get_type(control->data, struct ldb_server_sort_control *); if (!sort_ctrls) { return LDB_ERR_PROTOCOL_ERROR; @@ -143,7 +220,7 @@ static int server_sort_search(struct ldb_module *module, struct ldb_request *req req->op.search.res = sort_result; /* 53 = unwilling to perform */ - if ((ret = build_response(sort_result, 53, "sort control is not complete yet")) != LDB_SUCCESS) { + if ((ret = build_response(sort_result, &sort_result->controls, 53, "sort control is not complete yet")) != LDB_SUCCESS) { return ret; } @@ -179,22 +256,6 @@ static int server_sort_search(struct ldb_module *module, struct ldb_request *req data->result = 0; sort_result = req->op.search.res; - /* FIXME: I don't like to use a static structure like sort_control - * we need to either: - * a) write a qsort function that takes a third void parameter - * or - * b) prepare a structure with all elements pre digested like: - * struct element { - * struct ldb_message_element *el; - * struct ldb_message *msg; - * } - * - * this mean we will have to do a linear scan of - * the msgs array to build the new sort array, and - * then do a linear scan of the resulting array - * to rebuild the msgs array in the original shape. - */ - ldb_qsort(sort_result->msgs, sort_result->count, sizeof(struct ldb_message *), @@ -208,24 +269,281 @@ static int server_sort_search(struct ldb_module *module, struct ldb_request *req result = 53; } - if ((ret = build_response(sort_result, result, "sort control is not complete yet")) != LDB_SUCCESS) { + if ((ret = build_response(sort_result, &sort_result->controls, result, "sort control is not complete yet")) != LDB_SUCCESS) { return ret; } return LDB_SUCCESS; } +static int server_sort_search_async_callback(struct ldb_context *ldb, void *context, struct ldb_async_result *ares) +{ + struct sort_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 sort_async_context); + + if (ares->type == LDB_REPLY_ENTRY) { + ac->msgs = talloc_realloc(ac, ac->msgs, struct ldb_message *, ac->num_msgs + 2); + if (! ac->msgs) { + goto error; + } + + ac->msgs[ac->num_msgs + 1] = NULL; + + ac->msgs[ac->num_msgs] = talloc_steal(ac->msgs, ares->message); + if (! ac->msgs[ac->num_msgs]) { + goto error; + } + + ac->num_msgs++; + } + + if (ares->type == LDB_REPLY_REFERRAL) { + ac->referrals = talloc_realloc(ac, ac->referrals, char *, ac->num_refs + 2); + if (! ac->referrals) { + goto error; + } + + ac->referrals[ac->num_refs + 1] = NULL; + + ac->referrals[ac->num_refs] = talloc_steal(ac->referrals, ares->referral); + if (! ac->referrals[ac->num_refs]) { + goto error; + } + + ac->num_refs++; + } + + if (ares->type == LDB_REPLY_DONE) { + if (ares->controls) { + ac->controls = talloc_steal(ac, ares->controls); + if (! ac->controls) { + goto error; + } + } + } + + talloc_free(ares); + return LDB_SUCCESS; + +error: + talloc_free(ares); + return LDB_ERR_OPERATIONS_ERROR; +} + +static int server_sort_search_async(struct ldb_module *module, struct ldb_control *control, struct ldb_request *req) +{ + struct ldb_server_sort_control **sort_ctrls; + struct ldb_control **saved_controls; + struct sort_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; + } + + 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 sort_async_context); + + sort_ctrls = talloc_get_type(control->data, struct ldb_server_sort_control *); + if (!sort_ctrls) { + return LDB_ERR_PROTOCOL_ERROR; + } + + /* FIXME: we do not support more than one attribute for sorting right now */ + /* FIXME: we need to check if the attribute type exist or return an error */ + + if (sort_ctrls[1] != NULL) { + if (control->critical) { + struct ldb_async_result *ares; + + ares = talloc_zero(req, struct ldb_async_result); + if (!ares) + return LDB_ERR_OPERATIONS_ERROR; + + /* 53 = unwilling to perform */ + ares->type = LDB_REPLY_DONE; + if ((ret = build_response(ares, &ares->controls, 53, "sort control is not complete yet")) != LDB_SUCCESS) { + return ret; + } + + h->status = LDB_ERR_UNSUPPORTED_CRITICAL_EXTENSION; + h->state = LDB_ASYNC_DONE; + ret = ac->up_callback(module->ldb, ac->up_context, ares); + + return ret; + } else { + /* just pass the call down and don't do any sorting */ + ldb_next_request(module, req); + } + } + + ac->attributeName = sort_ctrls[0]->attributeName; + ac->orderingRule = sort_ctrls[0]->orderingRule; + ac->reverse = sort_ctrls[0]->reverse; + + ac->req = talloc(req, struct ldb_request); + + ac->req->operation = req->operation; + ac->req->op.search.base = req->op.search.base; + ac->req->op.search.scope = req->op.search.scope; + ac->req->op.search.tree = req->op.search.tree; + ac->req->op.search.attrs = req->op.search.attrs; + ac->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->req, &saved_controls)) { + return LDB_ERR_OPERATIONS_ERROR; + } + + ac->req->creds = req->creds; + + ac->req->async.context = ac; + ac->req->async.callback = server_sort_search_async_callback; + ac->req->async.timeout = req->async.timeout; + + req->async.handle = h; + + return ldb_next_request(module, ac->req); +} + static int server_sort(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_SERVER_SORT_OID); + if (control == NULL) { + /* not found go on */ + return ldb_next_request(module, req); + } + switch (req->operation) { case LDB_REQ_SEARCH: - return server_sort_search(module, req); + return server_sort_search(module, control, req); + + case LDB_ASYNC_SEARCH: + return server_sort_search_async(module, control, req); default: - return ldb_next_request(module, req); + return LDB_ERR_PROTOCOL_ERROR; + + } +} + +static int server_sort_async_results(struct ldb_async_handle *handle) +{ + struct sort_async_context *ac; + struct ldb_async_result *ares; + int i, ret; + + ac = talloc_get_type(handle->private_data, struct sort_async_context); + + ac->h = ldb_attrib_handler(ac->module->ldb, ac->attributeName); + ac->sort_result = 0; + + ldb_qsort(ac->msgs, ac->num_msgs, + sizeof(struct ldb_message *), + ac, (ldb_qsort_cmp_fn_t)sort_compare_async); + + for (i = 0; i < ac->num_msgs; i++) { + ares = talloc_zero(ac, struct ldb_async_result); + if (!ares) { + handle->status = LDB_ERR_OPERATIONS_ERROR; + return handle->status; + } + + ares->type = LDB_REPLY_ENTRY; + ares->message = talloc_steal(ares, ac->msgs[i]); + + handle->status = ac->up_callback(ac->module->ldb, ac->up_context, ares); + if (handle->status != LDB_SUCCESS) { + return handle->status; + } + } + + for (i = 0; i < ac->num_refs; i++) { + ares = talloc_zero(ac, struct ldb_async_result); + if (!ares) { + handle->status = LDB_ERR_OPERATIONS_ERROR; + return handle->status; + } + + ares->type = LDB_REPLY_REFERRAL; + ares->referral = talloc_steal(ares, ac->referrals[i]); + + handle->status = ac->up_callback(ac->module->ldb, ac->up_context, ares); + if (handle->status != LDB_SUCCESS) { + return handle->status; + } + } + + ares = talloc_zero(ac, struct ldb_async_result); + if (!ares) { + handle->status = LDB_ERR_OPERATIONS_ERROR; + return handle->status; + } + + ares->type = LDB_REPLY_DONE; + ares->controls = talloc_steal(ares, ac->controls); + + handle->status = ac->up_callback(ac->module->ldb, ac->up_context, ares); + if (handle->status != LDB_SUCCESS) { + return handle->status; + } + if ((ret = build_response(ac, &ac->controls, ac->sort_result, "sort control is not complete yet")) != LDB_SUCCESS) { + return ret; } + + return LDB_SUCCESS; +} + +static int server_sort_async_wait(struct ldb_async_handle *handle, enum ldb_async_wait_type type) +{ + struct sort_async_context *ac; + int ret; + + if (!handle || !handle->private_data) { + return LDB_ERR_OPERATIONS_ERROR; + } + + ac = talloc_get_type(handle->private_data, struct sort_async_context); + + ret = ldb_async_wait(handle->module->ldb, ac->req->async.handle, type); + + if (ret != LDB_SUCCESS) { + handle->status = ret; + return ret; + } + + handle->state = ac->req->async.handle->state; + handle->status = ac->req->async.handle->status; + + if (handle->status != LDB_SUCCESS) { + return handle->status; + } + + if (handle->state == LDB_ASYNC_DONE) { + ret = server_sort_async_results(handle); + } + + return ret; } static int server_sort_init(struct ldb_module *module) @@ -249,6 +567,7 @@ static int server_sort_init(struct ldb_module *module) static const struct ldb_module_ops server_sort_ops = { .name = "server_sort", .request = server_sort, + .async_wait = server_sort_async_wait, .init_context = server_sort_init }; -- cgit From 257598424e63c2cfa118b5ea84b7dc719d1dc5aa Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Tue, 7 Mar 2006 21:16:35 +0000 Subject: r13996: simplify ldb_async_wait() some more (This used to be commit ef1b3e6368179fe86ae07b8d00e4668090175551) --- source4/lib/ldb/modules/sort.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/modules/sort.c') diff --git a/source4/lib/ldb/modules/sort.c b/source4/lib/ldb/modules/sort.c index a37442b41f..82b589c749 100644 --- a/source4/lib/ldb/modules/sort.c +++ b/source4/lib/ldb/modules/sort.c @@ -525,7 +525,7 @@ static int server_sort_async_wait(struct ldb_async_handle *handle, enum ldb_asyn ac = talloc_get_type(handle->private_data, struct sort_async_context); - ret = ldb_async_wait(handle->module->ldb, ac->req->async.handle, type); + ret = ldb_async_wait(ac->req->async.handle, type); if (ret != LDB_SUCCESS) { handle->status = ret; -- 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/sort.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'source4/lib/ldb/modules/sort.c') diff --git a/source4/lib/ldb/modules/sort.c b/source4/lib/ldb/modules/sort.c index 82b589c749..08047c21f5 100644 --- a/source4/lib/ldb/modules/sort.c +++ b/source4/lib/ldb/modules/sort.c @@ -395,6 +395,8 @@ static int server_sort_search_async(struct ldb_module *module, struct ldb_contro ac->reverse = sort_ctrls[0]->reverse; ac->req = talloc(req, struct ldb_request); + if (!ac->req) + return LDB_ERR_OPERATIONS_ERROR; ac->req->operation = req->operation; ac->req->op.search.base = req->op.search.base; @@ -548,19 +550,26 @@ static int server_sort_async_wait(struct ldb_async_handle *handle, enum ldb_asyn static int server_sort_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_SERVER_SORT_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_SERVER_SORT_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, "server_sort: 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/sort.c | 53 ++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 25 deletions(-) (limited to 'source4/lib/ldb/modules/sort.c') diff --git a/source4/lib/ldb/modules/sort.c b/source4/lib/ldb/modules/sort.c index 08047c21f5..820ba1c1f7 100644 --- a/source4/lib/ldb/modules/sort.c +++ b/source4/lib/ldb/modules/sort.c @@ -89,6 +89,9 @@ static struct ldb_async_handle *init_handle(void *mem_ctx, struct ldb_module *mo 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; @@ -423,31 +426,6 @@ static int server_sort_search_async(struct ldb_module *module, struct ldb_contro return ldb_next_request(module, ac->req); } -static int server_sort(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_SERVER_SORT_OID); - if (control == NULL) { - /* not found go on */ - return ldb_next_request(module, req); - } - - switch (req->operation) { - - case LDB_REQ_SEARCH: - return server_sort_search(module, control, req); - - case LDB_ASYNC_SEARCH: - return server_sort_search_async(module, control, req); - - default: - return LDB_ERR_PROTOCOL_ERROR; - - } -} - static int server_sort_async_results(struct ldb_async_handle *handle) { struct sort_async_context *ac; @@ -548,6 +526,31 @@ static int server_sort_async_wait(struct ldb_async_handle *handle, enum ldb_asyn return ret; } +static int server_sort(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_SERVER_SORT_OID); + if (control == NULL) { + /* not found go on */ + return ldb_next_request(module, req); + } + + switch (req->operation) { + + case LDB_REQ_SEARCH: + return server_sort_search(module, control, req); + + case LDB_ASYNC_SEARCH: + return server_sort_search_async(module, control, req); + + default: + return LDB_ERR_PROTOCOL_ERROR; + + } +} + static int server_sort_init(struct ldb_module *module) { struct ldb_request *req; -- cgit From 90e27768eff17c321cad64fd834bc23f5c74df29 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 15 Mar 2006 05:52:12 +0000 Subject: r14433: sort_result must be initialised when we call do_result (This used to be commit a33f6a9832c7ae03e630d33120cfa048a51089d5) --- source4/lib/ldb/modules/sort.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source4/lib/ldb/modules/sort.c') diff --git a/source4/lib/ldb/modules/sort.c b/source4/lib/ldb/modules/sort.c index 820ba1c1f7..3e1bbe92bd 100644 --- a/source4/lib/ldb/modules/sort.c +++ b/source4/lib/ldb/modules/sort.c @@ -244,6 +244,8 @@ static int server_sort_search(struct ldb_module *module, struct ldb_control *con return ret; } + sort_result = req->op.search.res; + /* SORT HERE */ if (do_sort) { struct opaque *data; @@ -257,7 +259,6 @@ static int server_sort_search(struct ldb_module *module, struct ldb_control *con data->ldb = module->ldb; data->h = ldb_attrib_handler(data->ldb, data->attribute); data->result = 0; - sort_result = req->op.search.res; ldb_qsort(sort_result->msgs, sort_result->count, -- 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/sort.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'source4/lib/ldb/modules/sort.c') diff --git a/source4/lib/ldb/modules/sort.c b/source4/lib/ldb/modules/sort.c index 3e1bbe92bd..9f03100dd0 100644 --- a/source4/lib/ldb/modules/sort.c +++ b/source4/lib/ldb/modules/sort.c @@ -340,14 +340,22 @@ error: return LDB_ERR_OPERATIONS_ERROR; } -static int server_sort_search_async(struct ldb_module *module, struct ldb_control *control, struct ldb_request *req) +static int server_sort_search_async(struct ldb_module *module, struct ldb_request *req) { + struct ldb_control *control; struct ldb_server_sort_control **sort_ctrls; struct ldb_control **saved_controls; struct sort_async_context *ac; struct ldb_async_handle *h; int ret; + /* check if there's a paged request control */ + control = get_control_from_list(req->controls, LDB_CONTROL_SERVER_SORT_OID); + if (control == NULL) { + /* not found go on */ + return ldb_next_request(module, req); + } + req->async.handle = NULL; if (!req->async.callback || !req->async.context) { @@ -543,9 +551,6 @@ static int server_sort(struct ldb_module *module, struct ldb_request *req) case LDB_REQ_SEARCH: return server_sort_search(module, control, req); - case LDB_ASYNC_SEARCH: - return server_sort_search_async(module, control, req); - default: return LDB_ERR_PROTOCOL_ERROR; @@ -579,6 +584,7 @@ static int server_sort_init(struct ldb_module *module) static const struct ldb_module_ops server_sort_ops = { .name = "server_sort", + .search = server_sort_search_async, .request = server_sort, .async_wait = server_sort_async_wait, .init_context = server_sort_init -- 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/sort.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'source4/lib/ldb/modules/sort.c') diff --git a/source4/lib/ldb/modules/sort.c b/source4/lib/ldb/modules/sort.c index 9f03100dd0..6905417e95 100644 --- a/source4/lib/ldb/modules/sort.c +++ b/source4/lib/ldb/modules/sort.c @@ -424,8 +424,6 @@ static int server_sort_search_async(struct ldb_module *module, struct ldb_reques return LDB_ERR_OPERATIONS_ERROR; } - ac->req->creds = req->creds; - ac->req->async.context = ac; ac->req->async.callback = server_sort_search_async_callback; ac->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/sort.c | 119 +++-------------------------------------- 1 file changed, 6 insertions(+), 113 deletions(-) (limited to 'source4/lib/ldb/modules/sort.c') diff --git a/source4/lib/ldb/modules/sort.c b/source4/lib/ldb/modules/sort.c index 6905417e95..2f9d7dfc96 100644 --- a/source4/lib/ldb/modules/sort.c +++ b/source4/lib/ldb/modules/sort.c @@ -196,91 +196,7 @@ static int sort_compare_async(struct ldb_message **msg1, struct ldb_message **ms return ac->h->comparison_fn(ac->module->ldb, ac, &el1->values[0], &el2->values[0]); } -/* search */ -static int server_sort_search(struct ldb_module *module, struct ldb_control *control, struct ldb_request *req) -{ - struct ldb_result *sort_result = NULL; - struct ldb_control **saved_controls; - struct ldb_server_sort_control **sort_ctrls; - int ret, result = 0; - int do_sort = 1; - - sort_ctrls = talloc_get_type(control->data, struct ldb_server_sort_control *); - if (!sort_ctrls) { - return LDB_ERR_PROTOCOL_ERROR; - } - - /* FIXME: we do not support more than one attribute for sorting right now */ - /* FIXME: we need to check if the attribute type exist or return an error */ - if (sort_ctrls[1] != NULL) - do_sort = 0; - - if (!do_sort && control->critical) { - sort_result = talloc_zero(req, struct ldb_result); - if (!sort_result) - return LDB_ERR_OPERATIONS_ERROR; - - req->op.search.res = sort_result; - - /* 53 = unwilling to perform */ - if ((ret = build_response(sort_result, &sort_result->controls, 53, "sort control is not complete yet")) != LDB_SUCCESS) { - return ret; - } - - return LDB_ERR_UNSUPPORTED_CRITICAL_EXTENSION; - } - - /* save it locally and remove it from the list */ - if (!save_controls(control, req, &saved_controls)) { - return LDB_ERR_OPERATIONS_ERROR; - } - - ret = ldb_next_request(module, req); - - if (req->controls) talloc_free(req->controls); - req->controls = saved_controls; - - if (ret != LDB_SUCCESS) { - return ret; - } - - sort_result = req->op.search.res; - - /* SORT HERE */ - if (do_sort) { - struct opaque *data; - - data = talloc(module, struct opaque); - if (!data) - return LDB_ERR_OPERATIONS_ERROR; - - data->attribute = sort_ctrls[0]->attributeName; - data->reverse = sort_ctrls[0]->reverse; - data->ldb = module->ldb; - data->h = ldb_attrib_handler(data->ldb, data->attribute); - data->result = 0; - - ldb_qsort(sort_result->msgs, - sort_result->count, - sizeof(struct ldb_message *), - data, - (ldb_qsort_cmp_fn_t)sort_compare); - - result = data->result; - - talloc_free(data); - } else { - result = 53; - } - - if ((ret = build_response(sort_result, &sort_result->controls, result, "sort control is not complete yet")) != LDB_SUCCESS) { - return ret; - } - - return LDB_SUCCESS; -} - -static int server_sort_search_async_callback(struct ldb_context *ldb, void *context, struct ldb_async_result *ares) +static int server_sort_search_callback(struct ldb_context *ldb, void *context, struct ldb_async_result *ares) { struct sort_async_context *ac = NULL; @@ -340,7 +256,7 @@ error: return LDB_ERR_OPERATIONS_ERROR; } -static int server_sort_search_async(struct ldb_module *module, struct ldb_request *req) +static int server_sort_search(struct ldb_module *module, struct ldb_request *req) { struct ldb_control *control; struct ldb_server_sort_control **sort_ctrls; @@ -425,7 +341,7 @@ static int server_sort_search_async(struct ldb_module *module, struct ldb_reques } ac->req->async.context = ac; - ac->req->async.callback = server_sort_search_async_callback; + ac->req->async.callback = server_sort_search_callback; ac->req->async.timeout = req->async.timeout; req->async.handle = h; @@ -433,7 +349,7 @@ static int server_sort_search_async(struct ldb_module *module, struct ldb_reques return ldb_next_request(module, ac->req); } -static int server_sort_async_results(struct ldb_async_handle *handle) +static int server_sort_results(struct ldb_async_handle *handle) { struct sort_async_context *ac; struct ldb_async_result *ares; @@ -527,34 +443,12 @@ static int server_sort_async_wait(struct ldb_async_handle *handle, enum ldb_asyn } if (handle->state == LDB_ASYNC_DONE) { - ret = server_sort_async_results(handle); + ret = server_sort_results(handle); } return ret; } -static int server_sort(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_SERVER_SORT_OID); - if (control == NULL) { - /* not found go on */ - return ldb_next_request(module, req); - } - - switch (req->operation) { - - case LDB_REQ_SEARCH: - return server_sort_search(module, control, req); - - default: - return LDB_ERR_PROTOCOL_ERROR; - - } -} - static int server_sort_init(struct ldb_module *module) { struct ldb_request *req; @@ -582,8 +476,7 @@ static int server_sort_init(struct ldb_module *module) static const struct ldb_module_ops server_sort_ops = { .name = "server_sort", - .search = server_sort_search_async, - .request = server_sort, + .search = server_sort_search, .async_wait = server_sort_async_wait, .init_context = server_sort_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/sort.c | 38 ++++---------------------------------- 1 file changed, 4 insertions(+), 34 deletions(-) (limited to 'source4/lib/ldb/modules/sort.c') diff --git a/source4/lib/ldb/modules/sort.c b/source4/lib/ldb/modules/sort.c index 2f9d7dfc96..23f4f36478 100644 --- a/source4/lib/ldb/modules/sort.c +++ b/source4/lib/ldb/modules/sort.c @@ -47,7 +47,6 @@ struct sort_async_context { struct ldb_module *module; void *up_context; int (*up_callback)(struct ldb_context *, void *, struct ldb_async_result *); - int timeout; char *attributeName; char *orderingRule; @@ -66,8 +65,7 @@ struct sort_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 sort_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; } @@ -143,33 +140,6 @@ static int build_response(void *mem_ctx, struct ldb_control ***ctrls, int result } static int sort_compare(struct ldb_message **msg1, struct ldb_message **msg2, void *opaque) -{ - struct opaque *data = (struct opaque *)opaque; - struct ldb_message_element *el1, *el2; - - if (data->result != 0) { - /* an error occurred previously, - * let's exit the sorting by returning always 0 */ - return 0; - } - - el1 = ldb_msg_find_element(*msg1, data->attribute); - el2 = ldb_msg_find_element(*msg2, data->attribute); - - if (!el1 || !el2) { - /* the attribute was not found return and - * set an error */ - data->result = 53; - return 0; - } - - if (data->reverse) - return data->h->comparison_fn(data->ldb, data, &el2->values[0], &el1->values[0]); - - return data->h->comparison_fn(data->ldb, data, &el1->values[0], &el2->values[0]); -} - -static int sort_compare_async(struct ldb_message **msg1, struct ldb_message **msg2, void *opaque) { struct sort_async_context *ac = talloc_get_type(opaque, struct sort_async_context); struct ldb_message_element *el1, *el2; @@ -279,7 +249,7 @@ static int server_sort_search(struct ldb_module *module, struct ldb_request *req return LDB_ERR_OPERATIONS_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; } @@ -342,7 +312,7 @@ static int server_sort_search(struct ldb_module *module, struct ldb_request *req ac->req->async.context = ac; ac->req->async.callback = server_sort_search_callback; - ac->req->async.timeout = req->async.timeout; + ldb_set_timeout_from_prev_req(module->ldb, req, ac->req); req->async.handle = h; @@ -362,7 +332,7 @@ static int server_sort_results(struct ldb_async_handle *handle) ldb_qsort(ac->msgs, ac->num_msgs, sizeof(struct ldb_message *), - ac, (ldb_qsort_cmp_fn_t)sort_compare_async); + ac, (ldb_qsort_cmp_fn_t)sort_compare); for (i = 0; i < ac->num_msgs; i++) { ares = talloc_zero(ac, struct ldb_async_result); -- 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/sort.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib/ldb/modules/sort.c') diff --git a/source4/lib/ldb/modules/sort.c b/source4/lib/ldb/modules/sort.c index 23f4f36478..d72647be66 100644 --- a/source4/lib/ldb/modules/sort.c +++ b/source4/lib/ldb/modules/sort.c @@ -429,8 +429,8 @@ static int server_sort_init(struct ldb_module *module) return LDB_ERR_OPERATIONS_ERROR; } - req->operation = LDB_REQ_REGISTER; - req->op.reg.oid = LDB_CONTROL_SERVER_SORT_OID; + req->operation = LDB_REQ_REGISTER_CONTROL; + req->op.reg_control.oid = LDB_CONTROL_SERVER_SORT_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/sort.c | 58 +++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 29 deletions(-) (limited to 'source4/lib/ldb/modules/sort.c') diff --git a/source4/lib/ldb/modules/sort.c b/source4/lib/ldb/modules/sort.c index d72647be66..261bae7e78 100644 --- a/source4/lib/ldb/modules/sort.c +++ b/source4/lib/ldb/modules/sort.c @@ -43,10 +43,10 @@ struct opaque { int result; }; -struct sort_async_context { +struct sort_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 *); char *attributeName; char *orderingRule; @@ -63,14 +63,14 @@ struct sort_async_context { int sort_result; }; -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 sort_async_context *ac; - struct ldb_async_handle *h; + struct sort_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 sort_async_context); + ac = talloc_zero(h, struct sort_context); if (ac == NULL) { ldb_set_errstring(module->ldb, talloc_asprintf(module, "Out of Memory")); talloc_free(h); @@ -141,7 +141,7 @@ static int build_response(void *mem_ctx, struct ldb_control ***ctrls, int result static int sort_compare(struct ldb_message **msg1, struct ldb_message **msg2, void *opaque) { - struct sort_async_context *ac = talloc_get_type(opaque, struct sort_async_context); + struct sort_context *ac = talloc_get_type(opaque, struct sort_context); struct ldb_message_element *el1, *el2; if (ac->sort_result != 0) { @@ -166,16 +166,16 @@ static int sort_compare(struct ldb_message **msg1, struct ldb_message **msg2, vo return ac->h->comparison_fn(ac->module->ldb, ac, &el1->values[0], &el2->values[0]); } -static int server_sort_search_callback(struct ldb_context *ldb, void *context, struct ldb_async_result *ares) +static int server_sort_search_callback(struct ldb_context *ldb, void *context, struct ldb_reply *ares) { - struct sort_async_context *ac = NULL; + struct sort_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 sort_async_context); + ac = talloc_get_type(context, struct sort_context); if (ares->type == LDB_REPLY_ENTRY) { ac->msgs = talloc_realloc(ac, ac->msgs, struct ldb_message *, ac->num_msgs + 2); @@ -231,8 +231,8 @@ static int server_sort_search(struct ldb_module *module, struct ldb_request *req struct ldb_control *control; struct ldb_server_sort_control **sort_ctrls; struct ldb_control **saved_controls; - struct sort_async_context *ac; - struct ldb_async_handle *h; + struct sort_context *ac; + struct ldb_handle *h; int ret; /* check if there's a paged request control */ @@ -253,7 +253,7 @@ static int server_sort_search(struct ldb_module *module, struct ldb_request *req if (!h) { return LDB_ERR_OPERATIONS_ERROR; } - ac = talloc_get_type(h->private_data, struct sort_async_context); + ac = talloc_get_type(h->private_data, struct sort_context); sort_ctrls = talloc_get_type(control->data, struct ldb_server_sort_control *); if (!sort_ctrls) { @@ -265,9 +265,9 @@ static int server_sort_search(struct ldb_module *module, struct ldb_request *req if (sort_ctrls[1] != NULL) { if (control->critical) { - struct ldb_async_result *ares; + struct ldb_reply *ares; - ares = talloc_zero(req, struct ldb_async_result); + ares = talloc_zero(req, struct ldb_reply); if (!ares) return LDB_ERR_OPERATIONS_ERROR; @@ -319,13 +319,13 @@ static int server_sort_search(struct ldb_module *module, struct ldb_request *req return ldb_next_request(module, ac->req); } -static int server_sort_results(struct ldb_async_handle *handle) +static int server_sort_results(struct ldb_handle *handle) { - struct sort_async_context *ac; - struct ldb_async_result *ares; + struct sort_context *ac; + struct ldb_reply *ares; int i, ret; - ac = talloc_get_type(handle->private_data, struct sort_async_context); + ac = talloc_get_type(handle->private_data, struct sort_context); ac->h = ldb_attrib_handler(ac->module->ldb, ac->attributeName); ac->sort_result = 0; @@ -335,7 +335,7 @@ static int server_sort_results(struct ldb_async_handle *handle) ac, (ldb_qsort_cmp_fn_t)sort_compare); for (i = 0; i < ac->num_msgs; i++) { - ares = talloc_zero(ac, struct ldb_async_result); + ares = talloc_zero(ac, struct ldb_reply); if (!ares) { handle->status = LDB_ERR_OPERATIONS_ERROR; return handle->status; @@ -351,7 +351,7 @@ static int server_sort_results(struct ldb_async_handle *handle) } for (i = 0; i < ac->num_refs; i++) { - ares = talloc_zero(ac, struct ldb_async_result); + ares = talloc_zero(ac, struct ldb_reply); if (!ares) { handle->status = LDB_ERR_OPERATIONS_ERROR; return handle->status; @@ -366,7 +366,7 @@ static int server_sort_results(struct ldb_async_handle *handle) } } - ares = talloc_zero(ac, struct ldb_async_result); + ares = talloc_zero(ac, struct ldb_reply); if (!ares) { handle->status = LDB_ERR_OPERATIONS_ERROR; return handle->status; @@ -387,18 +387,18 @@ static int server_sort_results(struct ldb_async_handle *handle) return LDB_SUCCESS; } -static int server_sort_async_wait(struct ldb_async_handle *handle, enum ldb_async_wait_type type) +static int server_sort_wait(struct ldb_handle *handle, enum ldb_wait_type type) { - struct sort_async_context *ac; + struct sort_context *ac; int ret; if (!handle || !handle->private_data) { return LDB_ERR_OPERATIONS_ERROR; } - ac = talloc_get_type(handle->private_data, struct sort_async_context); + ac = talloc_get_type(handle->private_data, struct sort_context); - ret = ldb_async_wait(ac->req->async.handle, type); + ret = ldb_wait(ac->req->async.handle, type); if (ret != LDB_SUCCESS) { handle->status = ret; @@ -447,7 +447,7 @@ static int server_sort_init(struct ldb_module *module) static const struct ldb_module_ops server_sort_ops = { .name = "server_sort", .search = server_sort_search, - .async_wait = server_sort_async_wait, + .wait = server_sort_wait, .init_context = server_sort_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/sort.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'source4/lib/ldb/modules/sort.c') diff --git a/source4/lib/ldb/modules/sort.c b/source4/lib/ldb/modules/sort.c index 261bae7e78..1ab034f4fb 100644 --- a/source4/lib/ldb/modules/sort.c +++ b/source4/lib/ldb/modules/sort.c @@ -242,14 +242,14 @@ static int server_sort_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; } - 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; } @@ -310,11 +310,11 @@ static int server_sort_search(struct ldb_module *module, struct ldb_request *req return LDB_ERR_OPERATIONS_ERROR; } - ac->req->async.context = ac; - ac->req->async.callback = server_sort_search_callback; + ac->req->context = ac; + ac->req->callback = server_sort_search_callback; ldb_set_timeout_from_prev_req(module->ldb, req, ac->req); - req->async.handle = h; + req->handle = h; return ldb_next_request(module, ac->req); } @@ -398,15 +398,15 @@ static int server_sort_wait(struct ldb_handle *handle, enum ldb_wait_type type) ac = talloc_get_type(handle->private_data, struct sort_context); - ret = ldb_wait(ac->req->async.handle, type); + ret = ldb_wait(ac->req->handle, type); if (ret != LDB_SUCCESS) { handle->status = ret; return ret; } - handle->state = ac->req->async.handle->state; - handle->status = ac->req->async.handle->status; + handle->state = ac->req->handle->state; + handle->status = ac->req->handle->status; if (handle->status != LDB_SUCCESS) { return handle->status; -- 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/sort.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'source4/lib/ldb/modules/sort.c') diff --git a/source4/lib/ldb/modules/sort.c b/source4/lib/ldb/modules/sort.c index 1ab034f4fb..0ae16d08ab 100644 --- a/source4/lib/ldb/modules/sort.c +++ b/source4/lib/ldb/modules/sort.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 sort_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 server_sort_search_callback(struct ldb_context *ldb, void *context, s struct sort_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; } @@ -245,7 +245,8 @@ static int server_sort_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 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/sort.c | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) (limited to 'source4/lib/ldb/modules/sort.c') diff --git a/source4/lib/ldb/modules/sort.c b/source4/lib/ldb/modules/sort.c index 0ae16d08ab..acee40833b 100644 --- a/source4/lib/ldb/modules/sort.c +++ b/source4/lib/ldb/modules/sort.c @@ -185,11 +185,7 @@ static int server_sort_search_callback(struct ldb_context *ldb, void *context, s ac->msgs[ac->num_msgs + 1] = NULL; - ac->msgs[ac->num_msgs] = talloc_steal(ac->msgs, ares->message); - if (! ac->msgs[ac->num_msgs]) { - goto error; - } - + ac->msgs[ac->num_msgs] = talloc_move(ac->msgs, ares->message); ac->num_msgs++; } @@ -200,22 +196,13 @@ static int server_sort_search_callback(struct ldb_context *ldb, void *context, s } ac->referrals[ac->num_refs + 1] = NULL; - - ac->referrals[ac->num_refs] = talloc_steal(ac->referrals, ares->referral); - if (! ac->referrals[ac->num_refs]) { - goto error; - } + ac->referrals[ac->num_refs] = talloc_move(ac->referrals, ares->referral); ac->num_refs++; } if (ares->type == LDB_REPLY_DONE) { - if (ares->controls) { - ac->controls = talloc_steal(ac, ares->controls); - if (! ac->controls) { - goto error; - } - } + ac->controls = talloc_move(ac, ares->controls); } talloc_free(ares); @@ -343,7 +330,7 @@ static int server_sort_results(struct ldb_handle *handle) } ares->type = LDB_REPLY_ENTRY; - ares->message = talloc_steal(ares, ac->msgs[i]); + ares->message = talloc_move(ares, ac->msgs[i]); handle->status = ac->up_callback(ac->module->ldb, ac->up_context, ares); if (handle->status != LDB_SUCCESS) { @@ -359,7 +346,7 @@ static int server_sort_results(struct ldb_handle *handle) } ares->type = LDB_REPLY_REFERRAL; - ares->referral = talloc_steal(ares, ac->referrals[i]); + ares->referral = talloc_move(ares, ac->referrals[i]); handle->status = ac->up_callback(ac->module->ldb, ac->up_context, ares); if (handle->status != LDB_SUCCESS) { @@ -374,7 +361,7 @@ static int server_sort_results(struct ldb_handle *handle) } ares->type = LDB_REPLY_DONE; - ares->controls = talloc_steal(ares, ac->controls); + ares->controls = talloc_move(ares, ac->controls); handle->status = ac->up_callback(ac->module->ldb, ac->up_context, ares); if (handle->status != LDB_SUCCESS) { -- 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/sort.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source4/lib/ldb/modules/sort.c') diff --git a/source4/lib/ldb/modules/sort.c b/source4/lib/ldb/modules/sort.c index acee40833b..3a0598c528 100644 --- a/source4/lib/ldb/modules/sort.c +++ b/source4/lib/ldb/modules/sort.c @@ -185,7 +185,7 @@ static int server_sort_search_callback(struct ldb_context *ldb, void *context, s ac->msgs[ac->num_msgs + 1] = NULL; - ac->msgs[ac->num_msgs] = talloc_move(ac->msgs, ares->message); + ac->msgs[ac->num_msgs] = talloc_move(ac->msgs, &ares->message); ac->num_msgs++; } @@ -196,13 +196,13 @@ static int server_sort_search_callback(struct ldb_context *ldb, void *context, s } ac->referrals[ac->num_refs + 1] = NULL; - ac->referrals[ac->num_refs] = talloc_move(ac->referrals, ares->referral); + ac->referrals[ac->num_refs] = talloc_move(ac->referrals, &ares->referral); ac->num_refs++; } if (ares->type == LDB_REPLY_DONE) { - ac->controls = talloc_move(ac, ares->controls); + ac->controls = talloc_move(ac, &ares->controls); } talloc_free(ares); @@ -330,7 +330,7 @@ static int server_sort_results(struct ldb_handle *handle) } ares->type = LDB_REPLY_ENTRY; - ares->message = talloc_move(ares, ac->msgs[i]); + ares->message = talloc_move(ares, &ac->msgs[i]); handle->status = ac->up_callback(ac->module->ldb, ac->up_context, ares); if (handle->status != LDB_SUCCESS) { @@ -346,7 +346,7 @@ static int server_sort_results(struct ldb_handle *handle) } ares->type = LDB_REPLY_REFERRAL; - ares->referral = talloc_move(ares, ac->referrals[i]); + ares->referral = talloc_move(ares, &ac->referrals[i]); handle->status = ac->up_callback(ac->module->ldb, ac->up_context, ares); if (handle->status != LDB_SUCCESS) { @@ -361,7 +361,7 @@ static int server_sort_results(struct ldb_handle *handle) } ares->type = LDB_REPLY_DONE; - ares->controls = talloc_move(ares, ac->controls); + ares->controls = talloc_move(ares, &ac->controls); handle->status = ac->up_callback(ac->module->ldb, ac->up_context, ares); if (handle->status != LDB_SUCCESS) { -- 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/sort.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'source4/lib/ldb/modules/sort.c') diff --git a/source4/lib/ldb/modules/sort.c b/source4/lib/ldb/modules/sort.c index 3a0598c528..4fa03f8bfa 100644 --- a/source4/lib/ldb/modules/sort.c +++ b/source4/lib/ldb/modules/sort.c @@ -423,9 +423,7 @@ static int server_sort_init(struct ldb_module *module) ret = ldb_request(module->ldb, req); if (ret != LDB_SUCCESS) { - ldb_debug(module->ldb, LDB_DEBUG_ERROR, "server_sort: Unable to register control with rootdse!\n"); - talloc_free(req); - return LDB_ERR_OTHER; + ldb_debug(module->ldb, LDB_DEBUG_WARNING, "server_sort: Unable to register control with rootdse!\n"); } talloc_free(req); -- cgit From c69717755abeaf8bf93e76255d0912e3a24b7cb0 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 15 Dec 2006 13:08:57 +0000 Subject: r20184: change ldb_attrib_handler into ldb_schema_attribute, which has a pointer to a ldb_schema_syntax struct. the default attribute handler is now registered dynamicly as "*" attribute, instead of having its own code path. ldb_schema_attribute's can be added to the ldb_schema given a ldb_schema_syntax struct or the syntax name we may also need to introduce a ldb_schema_matching_rule, and add a pointer to a default ldb_schema_matching_rule in the ldb_schema_syntax. metze (This used to be commit b97b8f5dcbce006f005e53ca79df3330e62f117b) --- source4/lib/ldb/modules/sort.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source4/lib/ldb/modules/sort.c') diff --git a/source4/lib/ldb/modules/sort.c b/source4/lib/ldb/modules/sort.c index 4fa03f8bfa..6f34cebdb7 100644 --- a/source4/lib/ldb/modules/sort.c +++ b/source4/lib/ldb/modules/sort.c @@ -59,7 +59,7 @@ struct sort_context { int num_msgs; int num_refs; - const struct ldb_attrib_handler *h; + const struct ldb_schema_attribute *a; int sort_result; }; @@ -161,9 +161,9 @@ static int sort_compare(struct ldb_message **msg1, struct ldb_message **msg2, vo } if (ac->reverse) - return ac->h->comparison_fn(ac->module->ldb, ac, &el2->values[0], &el1->values[0]); + return ac->a->syntax->comparison_fn(ac->module->ldb, ac, &el2->values[0], &el1->values[0]); - return ac->h->comparison_fn(ac->module->ldb, ac, &el1->values[0], &el2->values[0]); + return ac->a->syntax->comparison_fn(ac->module->ldb, ac, &el1->values[0], &el2->values[0]); } static int server_sort_search_callback(struct ldb_context *ldb, void *context, struct ldb_reply *ares) @@ -315,7 +315,7 @@ static int server_sort_results(struct ldb_handle *handle) ac = talloc_get_type(handle->private_data, struct sort_context); - ac->h = ldb_attrib_handler(ac->module->ldb, ac->attributeName); + ac->a = ldb_schema_attribute_by_name(ac->module->ldb, ac->attributeName); ac->sort_result = 0; ldb_qsort(ac->msgs, ac->num_msgs, -- 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/sort.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/modules/sort.c') diff --git a/source4/lib/ldb/modules/sort.c b/source4/lib/ldb/modules/sort.c index 6f34cebdb7..f8ee788d6c 100644 --- a/source4/lib/ldb/modules/sort.c +++ b/source4/lib/ldb/modules/sort.c @@ -223,7 +223,7 @@ static int server_sort_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_SERVER_SORT_OID); + control = ldb_request_get_control(req, LDB_CONTROL_SERVER_SORT_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/sort.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source4/lib/ldb/modules/sort.c') diff --git a/source4/lib/ldb/modules/sort.c b/source4/lib/ldb/modules/sort.c index f8ee788d6c..dcd979fd20 100644 --- a/source4/lib/ldb/modules/sort.c +++ b/source4/lib/ldb/modules/sort.c @@ -32,8 +32,7 @@ * Author: Simo Sorce */ -#include "includes.h" -#include "ldb/include/includes.h" +#include "ldb_includes.h" struct opaque { struct ldb_context *ldb; -- 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/sort.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/modules/sort.c') diff --git a/source4/lib/ldb/modules/sort.c b/source4/lib/ldb/modules/sort.c index dcd979fd20..3646b5ae03 100644 --- a/source4/lib/ldb/modules/sort.c +++ b/source4/lib/ldb/modules/sort.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/sort.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source4/lib/ldb/modules/sort.c') diff --git a/source4/lib/ldb/modules/sort.c b/source4/lib/ldb/modules/sort.c index 3646b5ae03..b13dbe579b 100644 --- a/source4/lib/ldb/modules/sort.c +++ b/source4/lib/ldb/modules/sort.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/sort.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'source4/lib/ldb/modules/sort.c') diff --git a/source4/lib/ldb/modules/sort.c b/source4/lib/ldb/modules/sort.c index b13dbe579b..89b9a4fb19 100644 --- a/source4/lib/ldb/modules/sort.c +++ b/source4/lib/ldb/modules/sort.c @@ -373,7 +373,7 @@ static int server_sort_results(struct ldb_handle *handle) return LDB_SUCCESS; } -static int server_sort_wait(struct ldb_handle *handle, enum ldb_wait_type type) +static int server_sort_wait_once(struct ldb_handle *handle) { struct sort_context *ac; int ret; @@ -384,7 +384,7 @@ static int server_sort_wait(struct ldb_handle *handle, enum ldb_wait_type type) ac = talloc_get_type(handle->private_data, struct sort_context); - ret = ldb_wait(ac->req->handle, type); + ret = ldb_wait(ac->req->handle, LDB_WAIT_NONE); if (ret != LDB_SUCCESS) { handle->status = ret; @@ -405,6 +405,28 @@ static int server_sort_wait(struct ldb_handle *handle, enum ldb_wait_type type) return ret; } +static int server_sort_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 = server_sort_wait_once(handle); + if (ret != LDB_SUCCESS) { + return ret; + } + } + + return handle->status; + } + + return server_sort_wait_once(handle); +} + static int server_sort_init(struct ldb_module *module) { struct ldb_request *req; -- 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/sort.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'source4/lib/ldb/modules/sort.c') diff --git a/source4/lib/ldb/modules/sort.c b/source4/lib/ldb/modules/sort.c index 89b9a4fb19..746befa559 100644 --- a/source4/lib/ldb/modules/sort.c +++ b/source4/lib/ldb/modules/sort.c @@ -450,14 +450,9 @@ static int server_sort_init(struct ldb_module *module) return ldb_next_init(module); } -static const struct ldb_module_ops server_sort_ops = { +const struct ldb_module_ops ldb_server_sort_module_ops = { .name = "server_sort", .search = server_sort_search, .wait = server_sort_wait, .init_context = server_sort_init }; - -int ldb_sort_init(void) -{ - return ldb_register_module(&server_sort_ops); -} -- cgit