From 58d50a614f1b4a3fc6b60ad5f777d987263fe54f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 31 Mar 2004 06:45:39 +0000 Subject: make a more recent snapshot of ldb available to interested people. Note that I decided to make it LGPL. ldb is not finished yet, but enough of it is there for people to get an idea of what it does, and quite a few simple tests work (This used to be commit dc6f41f9e777d37f883303ddef0d96840d80f78e) --- source4/lib/ldb/ldb_tdb/ldb_search.c | 482 +++++++++++++++++++++++++++++++++++ 1 file changed, 482 insertions(+) create mode 100644 source4/lib/ldb/ldb_tdb/ldb_search.c (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c new file mode 100644 index 0000000000..952053c920 --- /dev/null +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -0,0 +1,482 @@ +/* + ldb database library + + Copyright (C) Andrew Tridgell 2004 + + ** 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 search functions + * + * Description: functions to search ldb+tdb databases + * + * Author: Andrew Tridgell + */ + +#include "includes.h" +#include "ldb_tdb/ldb_tdb.h" + +/* + free a message that has all parts separately allocated +*/ +static void msg_free_all_parts(struct ldb_message *msg) +{ + int i; + if (msg->dn) free(msg->dn); + for (i=0;inum_elements;i++) { + if (msg->elements[i].name) free(msg->elements[i].name); + if (msg->elements[i].value.data) free(msg->elements[i].value.data); + } + free(msg->elements); + free(msg); +} + + +/* + TODO: this should take advantage of the sorted nature of the message + return index of the attribute, or -1 if not found +*/ +int ldb_msg_find_attr(const struct ldb_message *msg, const char *attr) +{ + int i; + for (i=0;inum_elements;i++) { + if (strcmp(msg->elements[i].name, attr) == 0) { + return i; + } + } + return -1; +} + +/* + duplicate a ldb_val structure +*/ +static struct ldb_val ldb_val_dup(const struct ldb_val *v) +{ + struct ldb_val v2; + v2.length = v->length; + if (v->length == 0) { + v2.data = NULL; + return v2; + } + + /* the +1 is to cope with buggy C library routines like strndup + that look one byte beyond */ + v2.data = malloc(v->length+1); + if (!v2.data) { + v2.length = 0; + return v2; + } + + memcpy(v2.data, v->data, v->length); + ((char *)v2.data)[v->length] = 0; + return v2; +} + + + +/* + add one element to a message +*/ +static int msg_add_element(struct ldb_message *ret, const struct ldb_message_element *el) +{ + struct ldb_message_element *e2; + + e2 = realloc_p(ret->elements, struct ldb_message_element, ret->num_elements+1); + if (!e2) { + return -1; + } + ret->elements = e2; + + e2[ret->num_elements].name = strdup(el->name); + if (!e2[ret->num_elements].name) { + return -1; + } + e2[ret->num_elements].value = ldb_val_dup(&el->value); + if (e2[ret->num_elements].value.length != el->value.length) { + return -1; + } + + ret->num_elements++; + + return 0; +} + +/* + add all elements from one message into another + */ +static int msg_add_all_elements(struct ldb_message *ret, + const struct ldb_message *msg) +{ + int i; + for (i=0;inum_elements;i++) { + if (msg_add_element(ret, &msg->elements[i]) != 0) { + return -1; + } + } + + return 0; +} + + +/* + pull the specified list of attributes from a message + */ +static struct ldb_message *ltdb_pull_attrs(struct ldb_context *ldb, + const struct ldb_message *msg, + const char **attrs) +{ + struct ldb_message *ret; + int i; + + ret = malloc_p(struct ldb_message); + if (!ret) { + return NULL; + } + + ret->dn = strdup(msg->dn); + if (!ret->dn) { + free(ret); + return NULL; + } + + ret->num_elements = 0; + ret->elements = NULL; + ret->private = NULL; + + if (!attrs) { + if (msg_add_all_elements(ret, msg) != 0) { + msg_free_all_parts(ret); + return NULL; + } + return ret; + } + + for (i=0;attrs[i];i++) { + int j; + + if (strcmp(attrs[i], "*") == 0) { + if (msg_add_all_elements(ret, msg) != 0) { + msg_free_all_parts(ret); + return NULL; + } + continue; + } + j = ldb_msg_find_attr(msg, attrs[i]); + if (j == -1) { + continue; + } + do { + if (msg_add_element(ret, &msg->elements[j]) != 0) { + msg_free_all_parts(ret); + return NULL; + } + } while (++j < msg->num_elements && + strcmp(attrs[i], msg->elements[j].name) == 0); + } + + return ret; +} + + + +/* + see if a ldb_val is a wildcard +*/ +int ltdb_has_wildcard(const struct ldb_val *val) +{ + if (val->length == 1 && ((char *)val->data)[0] == '*') { + return 1; + } + return 0; +} + + +/* + free the results of a ltdb_search_dn1 search +*/ +void ltdb_search_dn1_free(struct ldb_context *ldb, struct ldb_message *msg) +{ + free(msg->dn); + free(msg->private); + if (msg->elements) free(msg->elements); +} + + +/* + search the database for a single simple dn, returning all attributes + in a single message + + return 1 on success, 0 on record-not-found and -1 on error +*/ +int ltdb_search_dn1(struct ldb_context *ldb, const char *dn, struct ldb_message *msg) +{ + struct ltdb_private *ltdb = ldb->private; + int ret; + TDB_DATA tdb_key, tdb_data; + + /* form the key */ + tdb_key = ltdb_key(dn); + if (!tdb_key.dptr) { + return -1; + } + + tdb_data = tdb_fetch(ltdb->tdb, tdb_key); + free(tdb_key.dptr); + if (!tdb_data.dptr) { + return 0; + } + + msg->dn = strdup(dn); + if (!msg->dn) { + free(tdb_data.dptr); + return -1; + } + msg->private = tdb_data.dptr; + msg->num_elements = 0; + msg->elements = NULL; + + ret = ltdb_unpack_data(ldb, &tdb_data, msg); + if (ret == -1) { + free(tdb_data.dptr); + return -1; + } + + return 1; +} + + +/* + search the database for a single simple dn +*/ +int ltdb_search_dn(struct ldb_context *ldb, char *dn, + const char *attrs[], struct ldb_message ***res) +{ + int ret; + struct ldb_message msg, *msg2; + + ret = ltdb_search_dn1(ldb, dn, &msg); + if (ret != 1) { + return ret; + } + + msg2 = ltdb_pull_attrs(ldb, &msg, attrs); + + ltdb_search_dn1_free(ldb, &msg); + + if (!msg2) { + return -1; + } + + *res = malloc_array_p(struct ldb_message *, 2); + if (! *res) { + msg_free_all_parts(msg2); + return -1; + } + + (*res)[0] = msg2; + (*res)[1] = NULL; + + return 1; +} + + +/* + add a set of attributes from a record to a set of results + return 0 on success, -1 on failure +*/ +int ltdb_add_attr_results(struct ldb_context *ldb, struct ldb_message *msg, + const char *attrs[], + unsigned int *count, + struct ldb_message ***res) +{ + struct ldb_message *msg2; + struct ldb_message **res2; + + /* pull the attributes that the user wants */ + msg2 = ltdb_pull_attrs(ldb, msg, attrs); + if (!msg2) { + return -1; + } + + /* add to the results list */ + res2 = realloc_p(*res, struct ldb_message *, (*count)+2); + if (!res2) { + msg_free_all_parts(msg2); + return -1; + } + + (*res) = res2; + + (*res)[*count] = msg2; + (*res)[(*count)+1] = NULL; + (*count)++; + + return 0; +} + + +/* + internal search state during a full db search +*/ +struct ltdb_search_info { + struct ldb_context *ldb; + struct ldb_parse_tree *tree; + const char *base; + enum ldb_scope scope; + const char **attrs; + struct ldb_message **msgs; + int failures; + int count; +}; + + +/* + search function for a non-indexed search + */ +static int search_func(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, void *state) +{ + struct ltdb_search_info *sinfo = state; + struct ldb_message msg; + int ret; + + if (key.dsize < 4 || + strncmp(key.dptr, "DN=", 3) != 0) { + return 0; + } + + msg.dn = key.dptr + 3; + + /* unpack the record */ + ret = ltdb_unpack_data(sinfo->ldb, &data, &msg); + if (ret == -1) { + sinfo->failures++; + return 0; + } + + /* see if it matches the given expression */ + if (!ldb_message_match(sinfo->ldb, &msg, sinfo->tree, + sinfo->base, sinfo->scope)) { + if (msg.elements) free(msg.elements); + return 0; + } + + ret = ltdb_add_attr_results(sinfo->ldb, &msg, sinfo->attrs, &sinfo->count, &sinfo->msgs); + + if (ret == -1) { + sinfo->failures++; + } + + if (msg.elements) free(msg.elements); + + return ret; +} + + +/* + free a set of search results +*/ +int ltdb_search_free(struct ldb_context *ldb, struct ldb_message **msgs) +{ + int i; + + if (!msgs) return 0; + + for (i=0;msgs[i];i++) { + msg_free_all_parts(msgs[i]); + } + + free(msgs); + + return 0; +} + +/* + search the database with a LDAP-like expression. + this is the "full search" non-indexed varient +*/ +static int ltdb_search_full(struct ldb_context *ldb, + const char *base, + enum ldb_scope scope, + struct ldb_parse_tree *tree, + const char *attrs[], struct ldb_message ***res) +{ + struct ltdb_private *ltdb = ldb->private; + int ret; + struct ltdb_search_info sinfo; + + sinfo.tree = tree; + sinfo.ldb = ldb; + sinfo.scope = scope; + sinfo.base = base; + sinfo.attrs = attrs; + sinfo.msgs = NULL; + sinfo.count = 0; + sinfo.failures = 0; + + ret = tdb_traverse(ltdb->tdb, search_func, &sinfo); + + if (ret == -1) { + ltdb_search_free(ldb, sinfo.msgs); + return -1; + } + + *res = sinfo.msgs; + return sinfo.count; +} + + +/* + search the database with a LDAP-like expression. + choses a search method +*/ +int ltdb_search(struct ldb_context *ldb, const char *base, + enum ldb_scope scope, const char *expression, + const char *attrs[], struct ldb_message ***res) +{ + struct ldb_parse_tree *tree; + int ret; + + *res = NULL; + + /* form a parse tree for the expression */ + tree = ldb_parse_tree(expression); + if (!tree) { + return -1; + } + + if (tree->operation == LDB_OP_SIMPLE && + strcmp(tree->u.simple.attr, "dn") == 0 && + !ltdb_has_wildcard(&tree->u.simple.value)) { + /* yay! its a nice simple one */ + ret = ltdb_search_dn(ldb, tree->u.simple.value.data, attrs, res); + } else { + ret = ltdb_search_indexed(ldb, base, scope, tree, attrs, res); + if (ret == -1) { + ret = ltdb_search_full(ldb, base, scope, tree, attrs, res); + } + } + + ldb_parse_tree_free(tree); + + return ret; +} + -- cgit From ee44733f94864fb0a1ae15d48e3335c0705a82ae Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 3 Apr 2004 12:29:21 +0000 Subject: added the rest of the ldb_modify() code, which required a fairly large change in the ldb API. The API is now much closer to LDAP. (This used to be commit e9e85c464411c561c5073d262a2e3533fec175ca) --- source4/lib/ldb/ldb_tdb/ldb_search.c | 52 +++++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 13 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index 952053c920..d7a7b7ffbd 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -40,11 +40,15 @@ */ static void msg_free_all_parts(struct ldb_message *msg) { - int i; + int i, j; if (msg->dn) free(msg->dn); for (i=0;inum_elements;i++) { if (msg->elements[i].name) free(msg->elements[i].name); - if (msg->elements[i].value.data) free(msg->elements[i].value.data); + for (j=0;jelements[i].num_values;j++) { + if (msg->elements[i].values[j].data) + free(msg->elements[i].values[j].data); + } + if (msg->elements[i].values) free(msg->elements[i].values); } free(msg->elements); free(msg); @@ -53,6 +57,7 @@ static void msg_free_all_parts(struct ldb_message *msg) /* TODO: this should take advantage of the sorted nature of the message + return index of the attribute, or -1 if not found */ int ldb_msg_find_attr(const struct ldb_message *msg, const char *attr) @@ -69,7 +74,7 @@ int ldb_msg_find_attr(const struct ldb_message *msg, const char *attr) /* duplicate a ldb_val structure */ -static struct ldb_val ldb_val_dup(const struct ldb_val *v) +struct ldb_val ldb_val_dup(const struct ldb_val *v) { struct ldb_val v2; v2.length = v->length; @@ -98,7 +103,8 @@ static struct ldb_val ldb_val_dup(const struct ldb_val *v) */ static int msg_add_element(struct ldb_message *ret, const struct ldb_message_element *el) { - struct ldb_message_element *e2; + int i; + struct ldb_message_element *e2, *elnew; e2 = realloc_p(ret->elements, struct ldb_message_element, ret->num_elements+1); if (!e2) { @@ -106,15 +112,31 @@ static int msg_add_element(struct ldb_message *ret, const struct ldb_message_ele } ret->elements = e2; - e2[ret->num_elements].name = strdup(el->name); - if (!e2[ret->num_elements].name) { + elnew = &e2[ret->num_elements]; + + elnew->name = strdup(el->name); + if (!elnew->name) { return -1; } - e2[ret->num_elements].value = ldb_val_dup(&el->value); - if (e2[ret->num_elements].value.length != el->value.length) { - return -1; + + if (el->num_values) { + elnew->values = malloc_array_p(struct ldb_val, el->num_values); + if (!elnew->values) { + return -1; + } + } else { + elnew->values = NULL; } + for (i=0;inum_values;i++) { + elnew->values[i] = ldb_val_dup(&el->values[i]); + if (elnew->values[i].length != el->values[i].length) { + return -1; + } + } + + elnew->num_values = el->num_values; + ret->num_elements++; return 0; @@ -215,8 +237,12 @@ int ltdb_has_wildcard(const struct ldb_val *val) */ void ltdb_search_dn1_free(struct ldb_context *ldb, struct ldb_message *msg) { - free(msg->dn); - free(msg->private); + int i; + if (msg->dn) free(msg->dn); + if (msg->private) free(msg->private); + for (i=0;inum_elements;i++) { + if (msg->elements[i].values) free(msg->elements[i].values); + } if (msg->elements) free(msg->elements); } @@ -375,7 +401,7 @@ static int search_func(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, voi /* see if it matches the given expression */ if (!ldb_message_match(sinfo->ldb, &msg, sinfo->tree, sinfo->base, sinfo->scope)) { - if (msg.elements) free(msg.elements); + ltdb_unpack_data_free(&msg); return 0; } @@ -385,7 +411,7 @@ static int search_func(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, voi sinfo->failures++; } - if (msg.elements) free(msg.elements); + ltdb_unpack_data_free(&msg); return ret; } -- cgit From 177777b05534c86514f5ee79b67532537bfd99dd Mon Sep 17 00:00:00 2001 From: Richard Sharpe Date: Sat, 10 Apr 2004 06:10:26 +0000 Subject: r141: A number of changes to get things working on FreeBSD and reduce the breakage caused by someone recently ... 1. Add configure check HAVE_COMPARISON_FN_T to see if this is defined. I have not checked this on Linux yet, but will do so soon. 2. Add the definitions of malloc_p, realloc_p etc. 3. Check for LDAP and don't build stuff that depends on LDAP if we don't\ have it. It currently builds on FreeBSD but there is one warning printed out at the end. (This used to be commit 7b34fbe0f2ef175e5504e34e4f3cdf9a0563970f) --- source4/lib/ldb/ldb_tdb/ldb_search.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index d7a7b7ffbd..5905231b32 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -33,7 +33,7 @@ */ #include "includes.h" -#include "ldb_tdb/ldb_tdb.h" +#include "ldb_tdb.h" /* free a message that has all parts separately allocated -- cgit From ac193579e7db00c7a2ea0aadaaf0d34c10dcf1a5 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 10 Apr 2004 20:18:22 +0000 Subject: r152: a quick airport commit .... added ldbedit, a _really_ useful command added ldbadd, ldbdel, ldbsearch and ldbmodify to build solved lots of timezone issues, we now pass the torture tests with client and server in different zones fixed several build issues I know this breaks the no-LDAP build. Wait till I arrive in San Jose for that fix. (This used to be commit af34710d4da1841653624fe304b1c8d812c0fdd9) --- source4/lib/ldb/ldb_tdb/ldb_search.c | 36 +++++++++--------------------------- 1 file changed, 9 insertions(+), 27 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index 5905231b32..9cb5853c94 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -33,7 +33,7 @@ */ #include "includes.h" -#include "ldb_tdb.h" +#include "ldb/ldb_tdb/ldb_tdb.h" /* free a message that has all parts separately allocated @@ -55,22 +55,6 @@ static void msg_free_all_parts(struct ldb_message *msg) } -/* - TODO: this should take advantage of the sorted nature of the message - - return index of the attribute, or -1 if not found -*/ -int ldb_msg_find_attr(const struct ldb_message *msg, const char *attr) -{ - int i; - for (i=0;inum_elements;i++) { - if (strcmp(msg->elements[i].name, attr) == 0) { - return i; - } - } - return -1; -} - /* duplicate a ldb_val structure */ @@ -193,7 +177,7 @@ static struct ldb_message *ltdb_pull_attrs(struct ldb_context *ldb, } for (i=0;attrs[i];i++) { - int j; + struct ldb_message_element *el; if (strcmp(attrs[i], "*") == 0) { if (msg_add_all_elements(ret, msg) != 0) { @@ -202,17 +186,15 @@ static struct ldb_message *ltdb_pull_attrs(struct ldb_context *ldb, } continue; } - j = ldb_msg_find_attr(msg, attrs[i]); - if (j == -1) { + + el = ldb_msg_find_element(msg, attrs[i]); + if (!el) { continue; } - do { - if (msg_add_element(ret, &msg->elements[j]) != 0) { - msg_free_all_parts(ret); - return NULL; - } - } while (++j < msg->num_elements && - strcmp(attrs[i], msg->elements[j].name) == 0); + if (msg_add_element(ret, el) != 0) { + msg_free_all_parts(ret); + return NULL; + } } return ret; -- cgit From 6411aa483f9233af098b4893ad67ebd2fd9d5868 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 28 Apr 2004 07:05:28 +0000 Subject: r381: make the code more C++ friendly (This used to be commit 8acecc7f27e25ab876fffffe43ae75b5f77aff77) --- source4/lib/ldb/ldb_tdb/ldb_search.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index 9cb5853c94..9a2287e20e 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -237,7 +237,7 @@ void ltdb_search_dn1_free(struct ldb_context *ldb, struct ldb_message *msg) */ int ltdb_search_dn1(struct ldb_context *ldb, const char *dn, struct ldb_message *msg) { - struct ltdb_private *ltdb = ldb->private; + struct ltdb_private *ltdb = ldb->private_data; int ret; TDB_DATA tdb_key, tdb_data; @@ -427,7 +427,7 @@ static int ltdb_search_full(struct ldb_context *ldb, struct ldb_parse_tree *tree, const char *attrs[], struct ldb_message ***res) { - struct ltdb_private *ltdb = ldb->private; + struct ltdb_private *ltdb = ldb->private_data; int ret; struct ltdb_search_info sinfo; -- cgit From b0b97592be312b3553ac31cc3f3cb994de06e506 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 28 Apr 2004 07:32:37 +0000 Subject: r382: More C++ friendliness fixes. (This used to be commit e96f3a2005cf6f4da2ecd4670a35eab1b4f250d0) --- source4/lib/ldb/ldb_tdb/ldb_search.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index 9a2287e20e..fe84091303 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -166,7 +166,7 @@ static struct ldb_message *ltdb_pull_attrs(struct ldb_context *ldb, ret->num_elements = 0; ret->elements = NULL; - ret->private = NULL; + ret->private_data = NULL; if (!attrs) { if (msg_add_all_elements(ret, msg) != 0) { @@ -221,7 +221,7 @@ void ltdb_search_dn1_free(struct ldb_context *ldb, struct ldb_message *msg) { int i; if (msg->dn) free(msg->dn); - if (msg->private) free(msg->private); + if (msg->private_data) free(msg->private_data); for (i=0;inum_elements;i++) { if (msg->elements[i].values) free(msg->elements[i].values); } @@ -258,7 +258,7 @@ int ltdb_search_dn1(struct ldb_context *ldb, const char *dn, struct ldb_message free(tdb_data.dptr); return -1; } - msg->private = tdb_data.dptr; + msg->private_data = tdb_data.dptr; msg->num_elements = 0; msg->elements = NULL; -- cgit From 0dad5a34273bf5cadcfd4a36d69bdffbf69eb073 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 1 May 2004 09:45:56 +0000 Subject: r435: a major upgrade for ldb - added the ability to mark record attributes as being CASE_INSENSITIVE, WILDCARD or INTEGER. - added the ability to support objectclass subclasses, and to search by a parent class - added internal support for case insensitive versus case sensitive indexing (not UTF8 compliant yet) - cleaned up a number of const warnings - added a number of helper functions for fetching integers, strings and doubles - added a in-memory cache for important database properties, supported by a database sequence number - changed some variable names to avoid conflicts with C++ (This used to be commit f2bf06f25c2e6c744817711c7bedbd1d3b52f994) --- source4/lib/ldb/ldb_tdb/ldb_search.c | 56 ++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 19 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index fe84091303..7059030212 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -148,7 +148,7 @@ static int msg_add_all_elements(struct ldb_message *ret, */ static struct ldb_message *ltdb_pull_attrs(struct ldb_context *ldb, const struct ldb_message *msg, - const char **attrs) + char * const *attrs) { struct ldb_message *ret; int i; @@ -205,11 +205,20 @@ static struct ldb_message *ltdb_pull_attrs(struct ldb_context *ldb, /* see if a ldb_val is a wildcard */ -int ltdb_has_wildcard(const struct ldb_val *val) +int ltdb_has_wildcard(struct ldb_context *ldb, const char *attr_name, + const struct ldb_val *val) { - if (val->length == 1 && ((char *)val->data)[0] == '*') { + int flags; + + if (strpbrk(val->data, "*?") == NULL) { + return 0; + } + + flags = ltdb_attribute_flags(ldb, attr_name); + if (flags & LTDB_FLAG_WILDCARD) { return 1; } + return 0; } @@ -220,12 +229,12 @@ int ltdb_has_wildcard(const struct ldb_val *val) void ltdb_search_dn1_free(struct ldb_context *ldb, struct ldb_message *msg) { int i; - if (msg->dn) free(msg->dn); if (msg->private_data) free(msg->private_data); for (i=0;inum_elements;i++) { if (msg->elements[i].values) free(msg->elements[i].values); } if (msg->elements) free(msg->elements); + memset(msg, 0, sizeof(*msg)); } @@ -242,7 +251,7 @@ int ltdb_search_dn1(struct ldb_context *ldb, const char *dn, struct ldb_message TDB_DATA tdb_key, tdb_data; /* form the key */ - tdb_key = ltdb_key(dn); + tdb_key = ltdb_key(ldb, dn); if (!tdb_key.dptr) { return -1; } @@ -253,11 +262,6 @@ int ltdb_search_dn1(struct ldb_context *ldb, const char *dn, struct ldb_message return 0; } - msg->dn = strdup(dn); - if (!msg->dn) { - free(tdb_data.dptr); - return -1; - } msg->private_data = tdb_data.dptr; msg->num_elements = 0; msg->elements = NULL; @@ -268,6 +272,14 @@ int ltdb_search_dn1(struct ldb_context *ldb, const char *dn, struct ldb_message return -1; } + if (!msg->dn) { + msg->dn = strdup(dn); + } + if (!msg->dn) { + free(tdb_data.dptr); + return -1; + } + return 1; } @@ -276,7 +288,7 @@ int ltdb_search_dn1(struct ldb_context *ldb, const char *dn, struct ldb_message search the database for a single simple dn */ int ltdb_search_dn(struct ldb_context *ldb, char *dn, - const char *attrs[], struct ldb_message ***res) + char * const attrs[], struct ldb_message ***res) { int ret; struct ldb_message msg, *msg2; @@ -312,7 +324,7 @@ int ltdb_search_dn(struct ldb_context *ldb, char *dn, return 0 on success, -1 on failure */ int ltdb_add_attr_results(struct ldb_context *ldb, struct ldb_message *msg, - const char *attrs[], + char * const attrs[], unsigned int *count, struct ldb_message ***res) { @@ -350,7 +362,7 @@ struct ltdb_search_info { struct ldb_parse_tree *tree; const char *base; enum ldb_scope scope; - const char **attrs; + char * const *attrs; struct ldb_message **msgs; int failures; int count; @@ -371,8 +383,6 @@ static int search_func(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, voi return 0; } - msg.dn = key.dptr + 3; - /* unpack the record */ ret = ltdb_unpack_data(sinfo->ldb, &data, &msg); if (ret == -1) { @@ -380,6 +390,10 @@ static int search_func(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, voi return 0; } + if (!msg.dn) { + msg.dn = key.dptr + 3; + } + /* see if it matches the given expression */ if (!ldb_message_match(sinfo->ldb, &msg, sinfo->tree, sinfo->base, sinfo->scope)) { @@ -425,7 +439,7 @@ static int ltdb_search_full(struct ldb_context *ldb, const char *base, enum ldb_scope scope, struct ldb_parse_tree *tree, - const char *attrs[], struct ldb_message ***res) + char * const attrs[], struct ldb_message ***res) { struct ltdb_private *ltdb = ldb->private_data; int ret; @@ -458,11 +472,15 @@ static int ltdb_search_full(struct ldb_context *ldb, */ int ltdb_search(struct ldb_context *ldb, const char *base, enum ldb_scope scope, const char *expression, - const char *attrs[], struct ldb_message ***res) + char * const attrs[], struct ldb_message ***res) { struct ldb_parse_tree *tree; int ret; + if (ltdb_cache_load(ldb) != 0) { + return -1; + } + *res = NULL; /* form a parse tree for the expression */ @@ -472,8 +490,8 @@ int ltdb_search(struct ldb_context *ldb, const char *base, } if (tree->operation == LDB_OP_SIMPLE && - strcmp(tree->u.simple.attr, "dn") == 0 && - !ltdb_has_wildcard(&tree->u.simple.value)) { + ldb_attr_cmp(tree->u.simple.attr, "dn") == 0 && + !ltdb_has_wildcard(ldb, tree->u.simple.attr, &tree->u.simple.value)) { /* yay! its a nice simple one */ ret = ltdb_search_dn(ldb, tree->u.simple.value.data, attrs, res); } else { -- cgit From 29bc1f5c605b53635eea805cdd3ca6b2873bc792 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 1 May 2004 14:04:33 +0000 Subject: r437: fixed handling of a corner case with multi-valued indexing (This used to be commit b38612185657512419c4b3dc806cf1183e0db0cb) --- source4/lib/ldb/ldb_tdb/ldb_search.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index 7059030212..1dce8f83a2 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -204,12 +204,18 @@ static struct ldb_message *ltdb_pull_attrs(struct ldb_context *ldb, /* see if a ldb_val is a wildcard + return 1 if yes, 0 if no */ int ltdb_has_wildcard(struct ldb_context *ldb, const char *attr_name, const struct ldb_val *val) { int flags; + /* all attribute types recognise the "*" wildcard */ + if (val->length == 1 && strncmp((char *)val->data, "*", 1) == 0) { + return 1; + } + if (strpbrk(val->data, "*?") == NULL) { return 0; } -- cgit From 208e09747c242ab5bd59a658033db49efa8d8696 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 3 May 2004 14:51:26 +0000 Subject: r456: - added -i option to ldbsearch - fixed sorting bug in ldb index handing (This used to be commit cdd48e2b9b3ca6be5503eec401e09db162408ac8) --- source4/lib/ldb/ldb_tdb/ldb_search.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index 1dce8f83a2..cce865e052 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -148,7 +148,7 @@ static int msg_add_all_elements(struct ldb_message *ret, */ static struct ldb_message *ltdb_pull_attrs(struct ldb_context *ldb, const struct ldb_message *msg, - char * const *attrs) + const char * const *attrs) { struct ldb_message *ret; int i; @@ -294,7 +294,7 @@ int ltdb_search_dn1(struct ldb_context *ldb, const char *dn, struct ldb_message search the database for a single simple dn */ int ltdb_search_dn(struct ldb_context *ldb, char *dn, - char * const attrs[], struct ldb_message ***res) + const char * const attrs[], struct ldb_message ***res) { int ret; struct ldb_message msg, *msg2; @@ -330,7 +330,7 @@ int ltdb_search_dn(struct ldb_context *ldb, char *dn, return 0 on success, -1 on failure */ int ltdb_add_attr_results(struct ldb_context *ldb, struct ldb_message *msg, - char * const attrs[], + const char * const attrs[], unsigned int *count, struct ldb_message ***res) { @@ -368,7 +368,7 @@ struct ltdb_search_info { struct ldb_parse_tree *tree; const char *base; enum ldb_scope scope; - char * const *attrs; + const char * const *attrs; struct ldb_message **msgs; int failures; int count; @@ -445,7 +445,7 @@ static int ltdb_search_full(struct ldb_context *ldb, const char *base, enum ldb_scope scope, struct ldb_parse_tree *tree, - char * const attrs[], struct ldb_message ***res) + const char * const attrs[], struct ldb_message ***res) { struct ltdb_private *ltdb = ldb->private_data; int ret; @@ -478,7 +478,7 @@ static int ltdb_search_full(struct ldb_context *ldb, */ int ltdb_search(struct ldb_context *ldb, const char *base, enum ldb_scope scope, const char *expression, - char * const attrs[], struct ldb_message ***res) + const char * const attrs[], struct ldb_message ***res) { struct ldb_parse_tree *tree; int ret; -- cgit From 232bc1503fc0e3f85b4711f077d2566dc0f0c823 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 5 May 2004 04:27:29 +0000 Subject: r490: - expanded the test suite to test modify and delete operations - made yet another attempt to make ldb const clean. - "make test" now runs both the tdb and ldap backend tests, and run the ldbtest utility with and without indexing - added prototypes in ldb.h for ldb_msg_*() public functions (This used to be commit 01e87406768cb5a98ac8530a2f361a4987a36cd3) --- source4/lib/ldb/ldb_tdb/ldb_search.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index cce865e052..1dce8f83a2 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -148,7 +148,7 @@ static int msg_add_all_elements(struct ldb_message *ret, */ static struct ldb_message *ltdb_pull_attrs(struct ldb_context *ldb, const struct ldb_message *msg, - const char * const *attrs) + char * const *attrs) { struct ldb_message *ret; int i; @@ -294,7 +294,7 @@ int ltdb_search_dn1(struct ldb_context *ldb, const char *dn, struct ldb_message search the database for a single simple dn */ int ltdb_search_dn(struct ldb_context *ldb, char *dn, - const char * const attrs[], struct ldb_message ***res) + char * const attrs[], struct ldb_message ***res) { int ret; struct ldb_message msg, *msg2; @@ -330,7 +330,7 @@ int ltdb_search_dn(struct ldb_context *ldb, char *dn, return 0 on success, -1 on failure */ int ltdb_add_attr_results(struct ldb_context *ldb, struct ldb_message *msg, - const char * const attrs[], + char * const attrs[], unsigned int *count, struct ldb_message ***res) { @@ -368,7 +368,7 @@ struct ltdb_search_info { struct ldb_parse_tree *tree; const char *base; enum ldb_scope scope; - const char * const *attrs; + char * const *attrs; struct ldb_message **msgs; int failures; int count; @@ -445,7 +445,7 @@ static int ltdb_search_full(struct ldb_context *ldb, const char *base, enum ldb_scope scope, struct ldb_parse_tree *tree, - const char * const attrs[], struct ldb_message ***res) + char * const attrs[], struct ldb_message ***res) { struct ltdb_private *ltdb = ldb->private_data; int ret; @@ -478,7 +478,7 @@ static int ltdb_search_full(struct ldb_context *ldb, */ int ltdb_search(struct ldb_context *ldb, const char *base, enum ldb_scope scope, const char *expression, - const char * const attrs[], struct ldb_message ***res) + char * const attrs[], struct ldb_message ***res) { struct ldb_parse_tree *tree; int ret; -- cgit From d8ce7c6a2acbf371509a23775470e7614bcb6027 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 6 May 2004 04:40:15 +0000 Subject: r502: modified ldb to allow the use of an external pool memory allocator. The way to use this is to call ldb_set_alloc() with a function pointer to whatever memory allocator you like. It includes a context pointer to allow for pool based allocators. (This used to be commit 3955c482e6c2c9e975a4bb809ec8cb6068e48e34) --- source4/lib/ldb/ldb_tdb/ldb_search.c | 109 ++++++++++++++++++++--------------- 1 file changed, 63 insertions(+), 46 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index 1dce8f83a2..5ee4449dee 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -38,27 +38,27 @@ /* free a message that has all parts separately allocated */ -static void msg_free_all_parts(struct ldb_message *msg) +static void msg_free_all_parts(struct ldb_context *ldb, struct ldb_message *msg) { int i, j; - if (msg->dn) free(msg->dn); + ldb_free(ldb, msg->dn); for (i=0;inum_elements;i++) { - if (msg->elements[i].name) free(msg->elements[i].name); + ldb_free(ldb, msg->elements[i].name); for (j=0;jelements[i].num_values;j++) { - if (msg->elements[i].values[j].data) - free(msg->elements[i].values[j].data); + ldb_free(ldb, msg->elements[i].values[j].data); } - if (msg->elements[i].values) free(msg->elements[i].values); + ldb_free(ldb, msg->elements[i].values); } - free(msg->elements); - free(msg); + ldb_free(ldb, msg->elements); + ldb_free(ldb, msg); } /* duplicate a ldb_val structure */ -struct ldb_val ldb_val_dup(const struct ldb_val *v) +struct ldb_val ldb_val_dup(struct ldb_context *ldb, + const struct ldb_val *v) { struct ldb_val v2; v2.length = v->length; @@ -69,7 +69,7 @@ struct ldb_val ldb_val_dup(const struct ldb_val *v) /* the +1 is to cope with buggy C library routines like strndup that look one byte beyond */ - v2.data = malloc(v->length+1); + v2.data = ldb_malloc(ldb, v->length+1); if (!v2.data) { v2.length = 0; return v2; @@ -85,12 +85,13 @@ struct ldb_val ldb_val_dup(const struct ldb_val *v) /* add one element to a message */ -static int msg_add_element(struct ldb_message *ret, const struct ldb_message_element *el) +static int msg_add_element(struct ldb_context *ldb, + struct ldb_message *ret, const struct ldb_message_element *el) { int i; struct ldb_message_element *e2, *elnew; - e2 = realloc_p(ret->elements, struct ldb_message_element, ret->num_elements+1); + e2 = ldb_realloc_p(ldb, ret->elements, struct ldb_message_element, ret->num_elements+1); if (!e2) { return -1; } @@ -98,13 +99,13 @@ static int msg_add_element(struct ldb_message *ret, const struct ldb_message_ele elnew = &e2[ret->num_elements]; - elnew->name = strdup(el->name); + elnew->name = ldb_strdup(ldb, el->name); if (!elnew->name) { return -1; } if (el->num_values) { - elnew->values = malloc_array_p(struct ldb_val, el->num_values); + elnew->values = ldb_malloc_array_p(ldb, struct ldb_val, el->num_values); if (!elnew->values) { return -1; } @@ -113,7 +114,7 @@ static int msg_add_element(struct ldb_message *ret, const struct ldb_message_ele } for (i=0;inum_values;i++) { - elnew->values[i] = ldb_val_dup(&el->values[i]); + elnew->values[i] = ldb_val_dup(ldb, &el->values[i]); if (elnew->values[i].length != el->values[i].length) { return -1; } @@ -129,12 +130,12 @@ static int msg_add_element(struct ldb_message *ret, const struct ldb_message_ele /* add all elements from one message into another */ -static int msg_add_all_elements(struct ldb_message *ret, +static int msg_add_all_elements(struct ldb_context *ldb, struct ldb_message *ret, const struct ldb_message *msg) { int i; for (i=0;inum_elements;i++) { - if (msg_add_element(ret, &msg->elements[i]) != 0) { + if (msg_add_element(ldb, ret, &msg->elements[i]) != 0) { return -1; } } @@ -153,14 +154,14 @@ static struct ldb_message *ltdb_pull_attrs(struct ldb_context *ldb, struct ldb_message *ret; int i; - ret = malloc_p(struct ldb_message); + ret = ldb_malloc_p(ldb, struct ldb_message); if (!ret) { return NULL; } - ret->dn = strdup(msg->dn); + ret->dn = ldb_strdup(ldb, msg->dn); if (!ret->dn) { - free(ret); + ldb_free(ldb, ret); return NULL; } @@ -169,8 +170,8 @@ static struct ldb_message *ltdb_pull_attrs(struct ldb_context *ldb, ret->private_data = NULL; if (!attrs) { - if (msg_add_all_elements(ret, msg) != 0) { - msg_free_all_parts(ret); + if (msg_add_all_elements(ldb, ret, msg) != 0) { + msg_free_all_parts(ldb, ret); return NULL; } return ret; @@ -180,8 +181,8 @@ static struct ldb_message *ltdb_pull_attrs(struct ldb_context *ldb, struct ldb_message_element *el; if (strcmp(attrs[i], "*") == 0) { - if (msg_add_all_elements(ret, msg) != 0) { - msg_free_all_parts(ret); + if (msg_add_all_elements(ldb, ret, msg) != 0) { + msg_free_all_parts(ldb, ret); return NULL; } continue; @@ -191,8 +192,8 @@ static struct ldb_message *ltdb_pull_attrs(struct ldb_context *ldb, if (!el) { continue; } - if (msg_add_element(ret, el) != 0) { - msg_free_all_parts(ret); + if (msg_add_element(ldb, ret, el) != 0) { + msg_free_all_parts(ldb, ret); return NULL; } } @@ -235,11 +236,11 @@ int ltdb_has_wildcard(struct ldb_context *ldb, const char *attr_name, void ltdb_search_dn1_free(struct ldb_context *ldb, struct ldb_message *msg) { int i; - if (msg->private_data) free(msg->private_data); + ldb_free(ldb, msg->private_data); for (i=0;inum_elements;i++) { - if (msg->elements[i].values) free(msg->elements[i].values); + ldb_free(ldb, msg->elements[i].values); } - if (msg->elements) free(msg->elements); + ldb_free(ldb, msg->elements); memset(msg, 0, sizeof(*msg)); } @@ -254,7 +255,7 @@ int ltdb_search_dn1(struct ldb_context *ldb, const char *dn, struct ldb_message { struct ltdb_private *ltdb = ldb->private_data; int ret; - TDB_DATA tdb_key, tdb_data; + TDB_DATA tdb_key, tdb_data, tdb_data2; /* form the key */ tdb_key = ltdb_key(ldb, dn); @@ -263,26 +264,35 @@ int ltdb_search_dn1(struct ldb_context *ldb, const char *dn, struct ldb_message } tdb_data = tdb_fetch(ltdb->tdb, tdb_key); - free(tdb_key.dptr); + ldb_free(ldb, tdb_key.dptr); if (!tdb_data.dptr) { return 0; } - msg->private_data = tdb_data.dptr; + tdb_data2.dptr = ldb_malloc(ldb, tdb_data.dsize); + if (!tdb_data2.dptr) { + free(tdb_data.dptr); + return -1; + } + memcpy(tdb_data2.dptr, tdb_data.dptr, tdb_data.dsize); + free(tdb_data.dptr); + tdb_data2.dsize = tdb_data.dsize; + + msg->private_data = tdb_data2.dptr; msg->num_elements = 0; msg->elements = NULL; - ret = ltdb_unpack_data(ldb, &tdb_data, msg); + ret = ltdb_unpack_data(ldb, &tdb_data2, msg); if (ret == -1) { - free(tdb_data.dptr); + free(tdb_data2.dptr); return -1; } if (!msg->dn) { - msg->dn = strdup(dn); + msg->dn = ldb_strdup(ldb, dn); } if (!msg->dn) { - free(tdb_data.dptr); + ldb_free(ldb, tdb_data2.dptr); return -1; } @@ -312,9 +322,9 @@ int ltdb_search_dn(struct ldb_context *ldb, char *dn, return -1; } - *res = malloc_array_p(struct ldb_message *, 2); + *res = ldb_malloc_array_p(ldb, struct ldb_message *, 2); if (! *res) { - msg_free_all_parts(msg2); + msg_free_all_parts(ldb, msg2); return -1; } @@ -344,9 +354,9 @@ int ltdb_add_attr_results(struct ldb_context *ldb, struct ldb_message *msg, } /* add to the results list */ - res2 = realloc_p(*res, struct ldb_message *, (*count)+2); + res2 = ldb_realloc_p(ldb, *res, struct ldb_message *, (*count)+2); if (!res2) { - msg_free_all_parts(msg2); + msg_free_all_parts(ldb, msg2); return -1; } @@ -403,7 +413,7 @@ static int search_func(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, voi /* see if it matches the given expression */ if (!ldb_message_match(sinfo->ldb, &msg, sinfo->tree, sinfo->base, sinfo->scope)) { - ltdb_unpack_data_free(&msg); + ltdb_unpack_data_free(sinfo->ldb, &msg); return 0; } @@ -413,7 +423,7 @@ static int search_func(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, voi sinfo->failures++; } - ltdb_unpack_data_free(&msg); + ltdb_unpack_data_free(sinfo->ldb, &msg); return ret; } @@ -424,15 +434,18 @@ static int search_func(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, voi */ int ltdb_search_free(struct ldb_context *ldb, struct ldb_message **msgs) { + struct ltdb_private *ltdb = ldb->private_data; int i; + ltdb->last_err_string = NULL; + if (!msgs) return 0; for (i=0;msgs[i];i++) { - msg_free_all_parts(msgs[i]); + msg_free_all_parts(ldb, msgs[i]); } - free(msgs); + ldb_free(ldb, msgs); return 0; } @@ -480,9 +493,12 @@ int ltdb_search(struct ldb_context *ldb, const char *base, enum ldb_scope scope, const char *expression, char * const attrs[], struct ldb_message ***res) { + struct ltdb_private *ltdb = ldb->private_data; struct ldb_parse_tree *tree; int ret; + ltdb->last_err_string = NULL; + if (ltdb_cache_load(ldb) != 0) { return -1; } @@ -490,8 +506,9 @@ int ltdb_search(struct ldb_context *ldb, const char *base, *res = NULL; /* form a parse tree for the expression */ - tree = ldb_parse_tree(expression); + tree = ldb_parse_tree(ldb, expression); if (!tree) { + ltdb->last_err_string = "expression parse failed"; return -1; } @@ -507,7 +524,7 @@ int ltdb_search(struct ldb_context *ldb, const char *base, } } - ldb_parse_tree_free(tree); + ldb_parse_tree_free(ldb, tree); return ret; } -- cgit From 265023fafa463c742f89510879acb2a830de8ab9 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 7 May 2004 23:54:41 +0000 Subject: r574: - another attempt at const cleanliness in ldb - fixed a problem with searching for values containing an '=' sign - fixed the semantics of attempting an attribute deletion on an attribute that doesn't exist. - added some more ldb_msg_*() utilities (This used to be commit 62b4ec367d170330d837b0f1fe5cd13205a53b59) --- source4/lib/ldb/ldb_tdb/ldb_search.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index 5ee4449dee..60eaf3117c 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -149,7 +149,7 @@ static int msg_add_all_elements(struct ldb_context *ldb, struct ldb_message *ret */ static struct ldb_message *ltdb_pull_attrs(struct ldb_context *ldb, const struct ldb_message *msg, - char * const *attrs) + const char * const *attrs) { struct ldb_message *ret; int i; @@ -304,7 +304,7 @@ int ltdb_search_dn1(struct ldb_context *ldb, const char *dn, struct ldb_message search the database for a single simple dn */ int ltdb_search_dn(struct ldb_context *ldb, char *dn, - char * const attrs[], struct ldb_message ***res) + const char * const attrs[], struct ldb_message ***res) { int ret; struct ldb_message msg, *msg2; @@ -340,7 +340,7 @@ int ltdb_search_dn(struct ldb_context *ldb, char *dn, return 0 on success, -1 on failure */ int ltdb_add_attr_results(struct ldb_context *ldb, struct ldb_message *msg, - char * const attrs[], + const char * const attrs[], unsigned int *count, struct ldb_message ***res) { @@ -378,7 +378,7 @@ struct ltdb_search_info { struct ldb_parse_tree *tree; const char *base; enum ldb_scope scope; - char * const *attrs; + const char * const *attrs; struct ldb_message **msgs; int failures; int count; @@ -458,7 +458,7 @@ static int ltdb_search_full(struct ldb_context *ldb, const char *base, enum ldb_scope scope, struct ldb_parse_tree *tree, - char * const attrs[], struct ldb_message ***res) + const char * const attrs[], struct ldb_message ***res) { struct ltdb_private *ltdb = ldb->private_data; int ret; @@ -491,7 +491,7 @@ static int ltdb_search_full(struct ldb_context *ldb, */ int ltdb_search(struct ldb_context *ldb, const char *base, enum ldb_scope scope, const char *expression, - char * const attrs[], struct ldb_message ***res) + const char * const attrs[], struct ldb_message ***res) { struct ltdb_private *ltdb = ldb->private_data; struct ldb_parse_tree *tree; -- cgit From d2c7b5cd338d41f9b47113ec21b36a12fe10c3fc Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 8 May 2004 03:44:47 +0000 Subject: r583: fixed two bugs in the handling of index entry deletion (This used to be commit 7b5f3370e6c078bf506ac3eb24fb330d4aee7688) --- source4/lib/ldb/ldb_tdb/ldb_search.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index 60eaf3117c..e2c83202e9 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -257,6 +257,8 @@ int ltdb_search_dn1(struct ldb_context *ldb, const char *dn, struct ldb_message int ret; TDB_DATA tdb_key, tdb_data, tdb_data2; + memset(msg, 0, sizeof(*msg)); + /* form the key */ tdb_key = ltdb_key(ldb, dn); if (!tdb_key.dptr) { -- cgit From 51d5ddecc60b6e33e1d542cb92b2fe6736849398 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 9 May 2004 12:30:30 +0000 Subject: r606: added a HIDDEN attribute on fields in ldb (in @ATTRIBUTES). This allows you to mark an attribute as only appearing in searches that explicitly name it. It will be used for attributes like nTSecurityDescriptor (This used to be commit f5cd3d733b71368ea652f8a4d653d87f45ff983f) --- source4/lib/ldb/ldb_tdb/ldb_search.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index e2c83202e9..25e22b3dd4 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -135,6 +135,10 @@ static int msg_add_all_elements(struct ldb_context *ldb, struct ldb_message *ret { int i; for (i=0;inum_elements;i++) { + int flags = ltdb_attribute_flags(ldb, msg->elements[i].name); + if (flags & LTDB_FLAG_HIDDEN) { + continue; + } if (msg_add_element(ldb, ret, &msg->elements[i]) != 0) { return -1; } -- cgit From f2548cd87339eca45b19b9f8173844ca932c96c3 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 14 May 2004 00:22:26 +0000 Subject: r711: don't hide attributes inside the special ldb_tdb records (so the fact that a attribute is hidden is not itself hidden!) (This used to be commit b42d1f39842ac25fee2238040ac01321f71a79c5) --- source4/lib/ldb/ldb_tdb/ldb_search.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index 25e22b3dd4..6b38a28296 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -136,7 +136,7 @@ static int msg_add_all_elements(struct ldb_context *ldb, struct ldb_message *ret int i; for (i=0;inum_elements;i++) { int flags = ltdb_attribute_flags(ldb, msg->elements[i].name); - if (flags & LTDB_FLAG_HIDDEN) { + if ((msg->dn[0] != '@') && (flags & LTDB_FLAG_HIDDEN)) { continue; } if (msg_add_element(ldb, ret, &msg->elements[i]) != 0) { -- cgit From f0a8f718ff474009300af6746fa0fbb61c649ea9 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 20 May 2004 13:25:06 +0000 Subject: r792: - changed the ldb ldif_* functions to be in the ldb_ namespace - added better error reporting in ldbdel - fixed a bug in handling packing of records which contain elements with no values (it caused db corruption) - allow search with "dn" as target attribute (This used to be commit 36575396234e3d35dbd442c8f1ff54a17ae64e64) --- source4/lib/ldb/ldb_tdb/ldb_search.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index 6b38a28296..d97444a6e8 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -34,6 +34,7 @@ #include "includes.h" #include "ldb/ldb_tdb/ldb_tdb.h" +#include "ldb/include/ldb_parse.h" /* free a message that has all parts separately allocated @@ -192,6 +193,31 @@ static struct ldb_message *ltdb_pull_attrs(struct ldb_context *ldb, continue; } + if (ldb_attr_cmp(attrs[i], "dn") == 0) { + struct ldb_message_element el2; + struct ldb_val val; + + el2.flags = 0; + el2.name = ldb_strdup(ldb, "dn"); + if (!el2.name) { + msg_free_all_parts(ldb, ret); + ldb_free(ldb, el2.name); + return NULL; + } + el2.num_values = 1; + el2.values = &val; + val.data = ret->dn; + val.length = strlen(ret->dn); + + if (msg_add_element(ldb, ret, &el2) != 0) { + msg_free_all_parts(ldb, ret); + ldb_free(ldb, el2.name); + return NULL; + } + ldb_free(ldb, el2.name); + continue; + } + el = ldb_msg_find_element(msg, attrs[i]); if (!el) { continue; @@ -290,7 +316,7 @@ int ltdb_search_dn1(struct ldb_context *ldb, const char *dn, struct ldb_message ret = ltdb_unpack_data(ldb, &tdb_data2, msg); if (ret == -1) { - free(tdb_data2.dptr); + ldb_free(ldb, tdb_data2.dptr); return -1; } -- cgit From 37fcf2236433bc5e74f19d2afac3d1d0055dcd01 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Sun, 27 Jun 2004 11:06:10 +0000 Subject: r1268: varient -> variant (This used to be commit de5984c95602ca67e8ac3139c3aa4330b74266e0) --- source4/lib/ldb/ldb_tdb/ldb_search.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index d97444a6e8..7e8cd8b289 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -484,7 +484,7 @@ int ltdb_search_free(struct ldb_context *ldb, struct ldb_message **msgs) /* search the database with a LDAP-like expression. - this is the "full search" non-indexed varient + this is the "full search" non-indexed variant */ static int ltdb_search_full(struct ldb_context *ldb, const char *base, -- cgit From 34ca729f733d9d22fc789a5fce6c448b03c96545 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 7 Jul 2004 01:02:54 +0000 Subject: r1374: Fix signed/unsigned warnings (actually found by g++) after unsigned int changes in r1018. (This used to be commit 45b4016530fc0bfa13146f73a503866b5dbed517) --- source4/lib/ldb/ldb_tdb/ldb_search.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index 7e8cd8b289..18d51d1aa4 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -41,7 +41,7 @@ */ static void msg_free_all_parts(struct ldb_context *ldb, struct ldb_message *msg) { - int i, j; + unsigned int i, j; ldb_free(ldb, msg->dn); for (i=0;inum_elements;i++) { ldb_free(ldb, msg->elements[i].name); @@ -89,7 +89,7 @@ struct ldb_val ldb_val_dup(struct ldb_context *ldb, static int msg_add_element(struct ldb_context *ldb, struct ldb_message *ret, const struct ldb_message_element *el) { - int i; + unsigned int i; struct ldb_message_element *e2, *elnew; e2 = ldb_realloc_p(ldb, ret->elements, struct ldb_message_element, ret->num_elements+1); @@ -134,7 +134,7 @@ static int msg_add_element(struct ldb_context *ldb, static int msg_add_all_elements(struct ldb_context *ldb, struct ldb_message *ret, const struct ldb_message *msg) { - int i; + unsigned int i; for (i=0;inum_elements;i++) { int flags = ltdb_attribute_flags(ldb, msg->elements[i].name); if ((msg->dn[0] != '@') && (flags & LTDB_FLAG_HIDDEN)) { @@ -265,7 +265,7 @@ int ltdb_has_wildcard(struct ldb_context *ldb, const char *attr_name, */ void ltdb_search_dn1_free(struct ldb_context *ldb, struct ldb_message *msg) { - int i; + unsigned int i; ldb_free(ldb, msg->private_data); for (i=0;inum_elements;i++) { ldb_free(ldb, msg->elements[i].values); -- cgit From 900e2cdf6d371ff67adaf83936cf9e2e455bf234 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 20 Oct 2004 17:42:17 +0000 Subject: r3089: fix memleak metze (This used to be commit 52eab8dc17a1cd1a8c0382ab8d6e7f6c7ddeea19) --- source4/lib/ldb/ldb_tdb/ldb_search.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index 18d51d1aa4..a11f137cc9 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -266,6 +266,7 @@ int ltdb_has_wildcard(struct ldb_context *ldb, const char *attr_name, void ltdb_search_dn1_free(struct ldb_context *ldb, struct ldb_message *msg) { unsigned int i; + ldb_free(ldb, msg->dn); ldb_free(ldb, msg->private_data); for (i=0;inum_elements;i++) { ldb_free(ldb, msg->elements[i].values); -- cgit From 6d18904b037a39aeff2cad29fb2db84e0d1b2fe4 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 20 Oct 2004 20:48:31 +0000 Subject: r3095: - fix a free'ing of msg.dn - reenable index tests metze (This used to be commit 1e7e94fdb10db831090f9bd37e39053dfcde04ce) --- source4/lib/ldb/ldb_tdb/ldb_search.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index a11f137cc9..18d51d1aa4 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -266,7 +266,6 @@ int ltdb_has_wildcard(struct ldb_context *ldb, const char *attr_name, void ltdb_search_dn1_free(struct ldb_context *ldb, struct ldb_message *msg) { unsigned int i; - ldb_free(ldb, msg->dn); ldb_free(ldb, msg->private_data); for (i=0;inum_elements;i++) { ldb_free(ldb, msg->elements[i].values); -- cgit From 679e95db033fd11d17c1f1ac5e44f6cc4df2220e Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 15 Nov 2004 11:40:27 +0000 Subject: r3754: merge in ldb modules support from the tmp branch ldbPlugins (This used to be commit 71323f424b4561af1fdddd2358629049be3dad8c) --- source4/lib/ldb/ldb_tdb/ldb_search.c | 81 ++++++++++++++++++++---------------- 1 file changed, 45 insertions(+), 36 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index 18d51d1aa4..cb93483881 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -131,12 +131,14 @@ static int msg_add_element(struct ldb_context *ldb, /* add all elements from one message into another */ -static int msg_add_all_elements(struct ldb_context *ldb, struct ldb_message *ret, +static int msg_add_all_elements(struct ldb_module *module, struct ldb_message *ret, const struct ldb_message *msg) { + struct ldb_context *ldb = module->ldb; unsigned int i; + for (i=0;inum_elements;i++) { - int flags = ltdb_attribute_flags(ldb, msg->elements[i].name); + int flags = ltdb_attribute_flags(module, msg->elements[i].name); if ((msg->dn[0] != '@') && (flags & LTDB_FLAG_HIDDEN)) { continue; } @@ -152,10 +154,11 @@ static int msg_add_all_elements(struct ldb_context *ldb, struct ldb_message *ret /* pull the specified list of attributes from a message */ -static struct ldb_message *ltdb_pull_attrs(struct ldb_context *ldb, +static struct ldb_message *ltdb_pull_attrs(struct ldb_module *module, const struct ldb_message *msg, const char * const *attrs) { + struct ldb_context *ldb = module->ldb; struct ldb_message *ret; int i; @@ -175,7 +178,7 @@ static struct ldb_message *ltdb_pull_attrs(struct ldb_context *ldb, ret->private_data = NULL; if (!attrs) { - if (msg_add_all_elements(ldb, ret, msg) != 0) { + if (msg_add_all_elements(module, ret, msg) != 0) { msg_free_all_parts(ldb, ret); return NULL; } @@ -186,7 +189,7 @@ static struct ldb_message *ltdb_pull_attrs(struct ldb_context *ldb, struct ldb_message_element *el; if (strcmp(attrs[i], "*") == 0) { - if (msg_add_all_elements(ldb, ret, msg) != 0) { + if (msg_add_all_elements(module, ret, msg) != 0) { msg_free_all_parts(ldb, ret); return NULL; } @@ -237,7 +240,7 @@ static struct ldb_message *ltdb_pull_attrs(struct ldb_context *ldb, see if a ldb_val is a wildcard return 1 if yes, 0 if no */ -int ltdb_has_wildcard(struct ldb_context *ldb, const char *attr_name, +int ltdb_has_wildcard(struct ldb_module *module, const char *attr_name, const struct ldb_val *val) { int flags; @@ -251,7 +254,7 @@ int ltdb_has_wildcard(struct ldb_context *ldb, const char *attr_name, return 0; } - flags = ltdb_attribute_flags(ldb, attr_name); + flags = ltdb_attribute_flags(module, attr_name); if (flags & LTDB_FLAG_WILDCARD) { return 1; } @@ -263,8 +266,9 @@ int ltdb_has_wildcard(struct ldb_context *ldb, const char *attr_name, /* free the results of a ltdb_search_dn1 search */ -void ltdb_search_dn1_free(struct ldb_context *ldb, struct ldb_message *msg) +void ltdb_search_dn1_free(struct ldb_module *module, struct ldb_message *msg) { + struct ldb_context *ldb = module->ldb; unsigned int i; ldb_free(ldb, msg->private_data); for (i=0;inum_elements;i++) { @@ -281,16 +285,17 @@ void ltdb_search_dn1_free(struct ldb_context *ldb, struct ldb_message *msg) return 1 on success, 0 on record-not-found and -1 on error */ -int ltdb_search_dn1(struct ldb_context *ldb, const char *dn, struct ldb_message *msg) +int ltdb_search_dn1(struct ldb_module *module, const char *dn, struct ldb_message *msg) { - struct ltdb_private *ltdb = ldb->private_data; + struct ldb_context *ldb = module->ldb; + struct ltdb_private *ltdb = module->private_data; int ret; TDB_DATA tdb_key, tdb_data, tdb_data2; memset(msg, 0, sizeof(*msg)); /* form the key */ - tdb_key = ltdb_key(ldb, dn); + tdb_key = ltdb_key(module, dn); if (!tdb_key.dptr) { return -1; } @@ -335,20 +340,21 @@ int ltdb_search_dn1(struct ldb_context *ldb, const char *dn, struct ldb_message /* search the database for a single simple dn */ -int ltdb_search_dn(struct ldb_context *ldb, char *dn, +int ltdb_search_dn(struct ldb_module *module, char *dn, const char * const attrs[], struct ldb_message ***res) { + struct ldb_context *ldb = module->ldb; int ret; struct ldb_message msg, *msg2; - ret = ltdb_search_dn1(ldb, dn, &msg); + ret = ltdb_search_dn1(module, dn, &msg); if (ret != 1) { return ret; } - msg2 = ltdb_pull_attrs(ldb, &msg, attrs); + msg2 = ltdb_pull_attrs(module, &msg, attrs); - ltdb_search_dn1_free(ldb, &msg); + ltdb_search_dn1_free(module, &msg); if (!msg2) { return -1; @@ -371,16 +377,17 @@ int ltdb_search_dn(struct ldb_context *ldb, char *dn, add a set of attributes from a record to a set of results return 0 on success, -1 on failure */ -int ltdb_add_attr_results(struct ldb_context *ldb, struct ldb_message *msg, +int ltdb_add_attr_results(struct ldb_module *module, struct ldb_message *msg, const char * const attrs[], unsigned int *count, struct ldb_message ***res) { + struct ldb_context *ldb = module->ldb; struct ldb_message *msg2; struct ldb_message **res2; /* pull the attributes that the user wants */ - msg2 = ltdb_pull_attrs(ldb, msg, attrs); + msg2 = ltdb_pull_attrs(module, msg, attrs); if (!msg2) { return -1; } @@ -406,7 +413,7 @@ int ltdb_add_attr_results(struct ldb_context *ldb, struct ldb_message *msg, internal search state during a full db search */ struct ltdb_search_info { - struct ldb_context *ldb; + struct ldb_module *module; struct ldb_parse_tree *tree; const char *base; enum ldb_scope scope; @@ -432,7 +439,7 @@ static int search_func(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, voi } /* unpack the record */ - ret = ltdb_unpack_data(sinfo->ldb, &data, &msg); + ret = ltdb_unpack_data(sinfo->module->ldb, &data, &msg); if (ret == -1) { sinfo->failures++; return 0; @@ -443,19 +450,19 @@ static int search_func(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, voi } /* see if it matches the given expression */ - if (!ldb_message_match(sinfo->ldb, &msg, sinfo->tree, + if (!ldb_message_match(sinfo->module, &msg, sinfo->tree, sinfo->base, sinfo->scope)) { - ltdb_unpack_data_free(sinfo->ldb, &msg); + ltdb_unpack_data_free(sinfo->module->ldb, &msg); return 0; } - ret = ltdb_add_attr_results(sinfo->ldb, &msg, sinfo->attrs, &sinfo->count, &sinfo->msgs); + ret = ltdb_add_attr_results(sinfo->module, &msg, sinfo->attrs, &sinfo->count, &sinfo->msgs); if (ret == -1) { sinfo->failures++; } - ltdb_unpack_data_free(sinfo->ldb, &msg); + ltdb_unpack_data_free(sinfo->module->ldb, &msg); return ret; } @@ -464,9 +471,10 @@ static int search_func(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, voi /* free a set of search results */ -int ltdb_search_free(struct ldb_context *ldb, struct ldb_message **msgs) +int ltdb_search_free(struct ldb_module *module, struct ldb_message **msgs) { - struct ltdb_private *ltdb = ldb->private_data; + struct ldb_context *ldb = module->ldb; + struct ltdb_private *ltdb = module->private_data; int i; ltdb->last_err_string = NULL; @@ -486,18 +494,18 @@ int ltdb_search_free(struct ldb_context *ldb, struct ldb_message **msgs) search the database with a LDAP-like expression. this is the "full search" non-indexed variant */ -static int ltdb_search_full(struct ldb_context *ldb, +static int ltdb_search_full(struct ldb_module *module, const char *base, enum ldb_scope scope, struct ldb_parse_tree *tree, const char * const attrs[], struct ldb_message ***res) { - struct ltdb_private *ltdb = ldb->private_data; + struct ltdb_private *ltdb = module->private_data; int ret; struct ltdb_search_info sinfo; sinfo.tree = tree; - sinfo.ldb = ldb; + sinfo.module = module; sinfo.scope = scope; sinfo.base = base; sinfo.attrs = attrs; @@ -508,7 +516,7 @@ static int ltdb_search_full(struct ldb_context *ldb, ret = tdb_traverse(ltdb->tdb, search_func, &sinfo); if (ret == -1) { - ltdb_search_free(ldb, sinfo.msgs); + ltdb_search_free(module, sinfo.msgs); return -1; } @@ -521,17 +529,18 @@ static int ltdb_search_full(struct ldb_context *ldb, search the database with a LDAP-like expression. choses a search method */ -int ltdb_search(struct ldb_context *ldb, const char *base, +int ltdb_search(struct ldb_module *module, const char *base, enum ldb_scope scope, const char *expression, const char * const attrs[], struct ldb_message ***res) { - struct ltdb_private *ltdb = ldb->private_data; + struct ldb_context *ldb = module->ldb; + struct ltdb_private *ltdb = module->private_data; struct ldb_parse_tree *tree; int ret; ltdb->last_err_string = NULL; - if (ltdb_cache_load(ldb) != 0) { + if (ltdb_cache_load(module) != 0) { return -1; } @@ -546,13 +555,13 @@ int ltdb_search(struct ldb_context *ldb, const char *base, if (tree->operation == LDB_OP_SIMPLE && ldb_attr_cmp(tree->u.simple.attr, "dn") == 0 && - !ltdb_has_wildcard(ldb, tree->u.simple.attr, &tree->u.simple.value)) { + !ltdb_has_wildcard(module, tree->u.simple.attr, &tree->u.simple.value)) { /* yay! its a nice simple one */ - ret = ltdb_search_dn(ldb, tree->u.simple.value.data, attrs, res); + ret = ltdb_search_dn(module, tree->u.simple.value.data, attrs, res); } else { - ret = ltdb_search_indexed(ldb, base, scope, tree, attrs, res); + ret = ltdb_search_indexed(module, base, scope, tree, attrs, res); if (ret == -1) { - ret = ltdb_search_full(ldb, base, scope, tree, attrs, res); + ret = ltdb_search_full(module, base, scope, tree, attrs, res); } } -- cgit From 8a18778286a16423d7d6e483fdb308a91e294efe Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 16 Nov 2004 09:00:52 +0000 Subject: r3783: - don't use make proto for ldb anymore - split ldh.h out of samba's includes.h - make ldb_context and ldb_module private to the subsystem - use ltdb_ prefix for all ldb_tdb functions metze (This used to be commit f5ee40d6ce8224e280070975efc9911558fe675c) --- source4/lib/ldb/ldb_tdb/ldb_search.c | 40 +++++++----------------------------- 1 file changed, 7 insertions(+), 33 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index cb93483881..903c4cb802 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -33,6 +33,8 @@ */ #include "includes.h" +#include "ldb/include/ldb.h" +#include "ldb/include/ldb_private.h" #include "ldb/ldb_tdb/ldb_tdb.h" #include "ldb/include/ldb_parse.h" @@ -55,34 +57,6 @@ static void msg_free_all_parts(struct ldb_context *ldb, struct ldb_message *msg) } -/* - duplicate a ldb_val structure -*/ -struct ldb_val ldb_val_dup(struct ldb_context *ldb, - const struct ldb_val *v) -{ - struct ldb_val v2; - v2.length = v->length; - if (v->length == 0) { - v2.data = NULL; - return v2; - } - - /* the +1 is to cope with buggy C library routines like strndup - that look one byte beyond */ - v2.data = ldb_malloc(ldb, v->length+1); - if (!v2.data) { - v2.length = 0; - return v2; - } - - memcpy(v2.data, v->data, v->length); - ((char *)v2.data)[v->length] = 0; - return v2; -} - - - /* add one element to a message */ @@ -319,7 +293,7 @@ int ltdb_search_dn1(struct ldb_module *module, const char *dn, struct ldb_messag msg->num_elements = 0; msg->elements = NULL; - ret = ltdb_unpack_data(ldb, &tdb_data2, msg); + ret = ltdb_unpack_data(module, &tdb_data2, msg); if (ret == -1) { ldb_free(ldb, tdb_data2.dptr); return -1; @@ -439,7 +413,7 @@ static int search_func(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, voi } /* unpack the record */ - ret = ltdb_unpack_data(sinfo->module->ldb, &data, &msg); + ret = ltdb_unpack_data(sinfo->module, &data, &msg); if (ret == -1) { sinfo->failures++; return 0; @@ -450,9 +424,9 @@ static int search_func(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, voi } /* see if it matches the given expression */ - if (!ldb_message_match(sinfo->module, &msg, sinfo->tree, + if (!ltdb_message_match(sinfo->module, &msg, sinfo->tree, sinfo->base, sinfo->scope)) { - ltdb_unpack_data_free(sinfo->module->ldb, &msg); + ltdb_unpack_data_free(sinfo->module, &msg); return 0; } @@ -462,7 +436,7 @@ static int search_func(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, voi sinfo->failures++; } - ltdb_unpack_data_free(sinfo->module->ldb, &msg); + ltdb_unpack_data_free(sinfo->module, &msg); return ret; } -- cgit From b6c4b63dc59d10e7f93e726282b6f93f64dd7bb8 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 30 Nov 2004 22:55:36 +0000 Subject: r4022: fix compiler warnings metze (This used to be commit 79d0eb2f677f9e985ba476a9680f68537d41be6f) --- source4/lib/ldb/ldb_tdb/ldb_search.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index 903c4cb802..27718a4c86 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -353,7 +353,7 @@ int ltdb_search_dn(struct ldb_module *module, char *dn, */ int ltdb_add_attr_results(struct ldb_module *module, struct ldb_message *msg, const char * const attrs[], - unsigned int *count, + int *count, struct ldb_message ***res) { struct ldb_context *ldb = module->ldb; -- cgit From 1a988ec9af7960616fb4661b20d86ff05146d836 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 2 Jan 2005 07:49:29 +0000 Subject: r4474: - converted ldb to use talloc internally - added gcov flags to Makefile.ldb - expanded ldb test suite to get more coverage (This used to be commit 0ab98f50a7e0fe15347a99e5c29a6590a87729a0) --- source4/lib/ldb/ldb_tdb/ldb_search.c | 185 +++++++++++++++-------------------- 1 file changed, 79 insertions(+), 106 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index 27718a4c86..720188b74c 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -38,25 +38,6 @@ #include "ldb/ldb_tdb/ldb_tdb.h" #include "ldb/include/ldb_parse.h" -/* - free a message that has all parts separately allocated -*/ -static void msg_free_all_parts(struct ldb_context *ldb, struct ldb_message *msg) -{ - unsigned int i, j; - ldb_free(ldb, msg->dn); - for (i=0;inum_elements;i++) { - ldb_free(ldb, msg->elements[i].name); - for (j=0;jelements[i].num_values;j++) { - ldb_free(ldb, msg->elements[i].values[j].data); - } - ldb_free(ldb, msg->elements[i].values); - } - ldb_free(ldb, msg->elements); - ldb_free(ldb, msg); -} - - /* add one element to a message */ @@ -66,7 +47,7 @@ static int msg_add_element(struct ldb_context *ldb, unsigned int i; struct ldb_message_element *e2, *elnew; - e2 = ldb_realloc_p(ldb, ret->elements, struct ldb_message_element, ret->num_elements+1); + e2 = talloc_realloc_p(ret, ret->elements, struct ldb_message_element, ret->num_elements+1); if (!e2) { return -1; } @@ -74,13 +55,13 @@ static int msg_add_element(struct ldb_context *ldb, elnew = &e2[ret->num_elements]; - elnew->name = ldb_strdup(ldb, el->name); + elnew->name = talloc_strdup(ret->elements, el->name); if (!elnew->name) { return -1; } if (el->num_values) { - elnew->values = ldb_malloc_array_p(ldb, struct ldb_val, el->num_values); + elnew->values = talloc_array_p(ret->elements, struct ldb_val, el->num_values); if (!elnew->values) { return -1; } @@ -89,7 +70,7 @@ static int msg_add_element(struct ldb_context *ldb, } for (i=0;inum_values;i++) { - elnew->values[i] = ldb_val_dup(ldb, &el->values[i]); + elnew->values[i] = ldb_val_dup(elnew->values, &el->values[i]); if (elnew->values[i].length != el->values[i].length) { return -1; } @@ -136,24 +117,23 @@ static struct ldb_message *ltdb_pull_attrs(struct ldb_module *module, struct ldb_message *ret; int i; - ret = ldb_malloc_p(ldb, struct ldb_message); + ret = talloc_p(ldb, struct ldb_message); if (!ret) { return NULL; } - ret->dn = ldb_strdup(ldb, msg->dn); + ret->dn = talloc_strdup(ret, msg->dn); if (!ret->dn) { - ldb_free(ldb, ret); + talloc_free(ret); return NULL; } ret->num_elements = 0; ret->elements = NULL; - ret->private_data = NULL; if (!attrs) { if (msg_add_all_elements(module, ret, msg) != 0) { - msg_free_all_parts(ldb, ret); + talloc_free(ret); return NULL; } return ret; @@ -164,7 +144,7 @@ static struct ldb_message *ltdb_pull_attrs(struct ldb_module *module, if (strcmp(attrs[i], "*") == 0) { if (msg_add_all_elements(module, ret, msg) != 0) { - msg_free_all_parts(ldb, ret); + talloc_free(ret); return NULL; } continue; @@ -175,10 +155,9 @@ static struct ldb_message *ltdb_pull_attrs(struct ldb_module *module, struct ldb_val val; el2.flags = 0; - el2.name = ldb_strdup(ldb, "dn"); + el2.name = talloc_strdup(ret, "dn"); if (!el2.name) { - msg_free_all_parts(ldb, ret); - ldb_free(ldb, el2.name); + talloc_free(ret); return NULL; } el2.num_values = 1; @@ -187,11 +166,10 @@ static struct ldb_message *ltdb_pull_attrs(struct ldb_module *module, val.length = strlen(ret->dn); if (msg_add_element(ldb, ret, &el2) != 0) { - msg_free_all_parts(ldb, ret); - ldb_free(ldb, el2.name); + talloc_free(ret); return NULL; } - ldb_free(ldb, el2.name); + talloc_free(el2.name); continue; } @@ -200,7 +178,7 @@ static struct ldb_message *ltdb_pull_attrs(struct ldb_module *module, continue; } if (msg_add_element(ldb, ret, el) != 0) { - msg_free_all_parts(ldb, ret); + talloc_free(ret); return NULL; } } @@ -237,22 +215,6 @@ int ltdb_has_wildcard(struct ldb_module *module, const char *attr_name, } -/* - free the results of a ltdb_search_dn1 search -*/ -void ltdb_search_dn1_free(struct ldb_module *module, struct ldb_message *msg) -{ - struct ldb_context *ldb = module->ldb; - unsigned int i; - ldb_free(ldb, msg->private_data); - for (i=0;inum_elements;i++) { - ldb_free(ldb, msg->elements[i].values); - } - ldb_free(ldb, msg->elements); - memset(msg, 0, sizeof(*msg)); -} - - /* search the database for a single simple dn, returning all attributes in a single message @@ -261,7 +223,6 @@ void ltdb_search_dn1_free(struct ldb_module *module, struct ldb_message *msg) */ int ltdb_search_dn1(struct ldb_module *module, const char *dn, struct ldb_message *msg) { - struct ldb_context *ldb = module->ldb; struct ltdb_private *ltdb = module->private_data; int ret; TDB_DATA tdb_key, tdb_data, tdb_data2; @@ -275,35 +236,32 @@ int ltdb_search_dn1(struct ldb_module *module, const char *dn, struct ldb_messag } tdb_data = tdb_fetch(ltdb->tdb, tdb_key); - ldb_free(ldb, tdb_key.dptr); + talloc_free(tdb_key.dptr); if (!tdb_data.dptr) { return 0; } - tdb_data2.dptr = ldb_malloc(ldb, tdb_data.dsize); + tdb_data2.dptr = talloc_memdup(msg, tdb_data.dptr, tdb_data.dsize); + free(tdb_data.dptr); if (!tdb_data2.dptr) { - free(tdb_data.dptr); return -1; } - memcpy(tdb_data2.dptr, tdb_data.dptr, tdb_data.dsize); - free(tdb_data.dptr); tdb_data2.dsize = tdb_data.dsize; - msg->private_data = tdb_data2.dptr; msg->num_elements = 0; msg->elements = NULL; ret = ltdb_unpack_data(module, &tdb_data2, msg); if (ret == -1) { - ldb_free(ldb, tdb_data2.dptr); + talloc_free(tdb_data2.dptr); return -1; } if (!msg->dn) { - msg->dn = ldb_strdup(ldb, dn); + msg->dn = talloc_strdup(tdb_data2.dptr, dn); } if (!msg->dn) { - ldb_free(ldb, tdb_data2.dptr); + talloc_free(tdb_data2.dptr); return -1; } @@ -319,27 +277,35 @@ int ltdb_search_dn(struct ldb_module *module, char *dn, { struct ldb_context *ldb = module->ldb; int ret; - struct ldb_message msg, *msg2; + struct ldb_message *msg, *msg2; + + *res = talloc_array_p(ldb, struct ldb_message *, 2); + if (! *res) { + return -1; + } - ret = ltdb_search_dn1(module, dn, &msg); + msg = talloc_p(*res, struct ldb_message); + if (msg == NULL) { + talloc_free(*res); + *res = NULL; + return -1; + } + + ret = ltdb_search_dn1(module, dn, msg); if (ret != 1) { + talloc_free(*res); + *res = NULL; return ret; } - msg2 = ltdb_pull_attrs(module, &msg, attrs); + msg2 = ltdb_pull_attrs(module, msg, attrs); - ltdb_search_dn1_free(module, &msg); + talloc_free(msg); if (!msg2) { return -1; } - *res = ldb_malloc_array_p(ldb, struct ldb_message *, 2); - if (! *res) { - msg_free_all_parts(ldb, msg2); - return -1; - } - (*res)[0] = msg2; (*res)[1] = NULL; @@ -367,9 +333,9 @@ int ltdb_add_attr_results(struct ldb_module *module, struct ldb_message *msg, } /* add to the results list */ - res2 = ldb_realloc_p(ldb, *res, struct ldb_message *, (*count)+2); + res2 = talloc_realloc_p(ldb, *res, struct ldb_message *, (*count)+2); if (!res2) { - msg_free_all_parts(ldb, msg2); + talloc_free(msg2); return -1; } @@ -404,7 +370,7 @@ struct ltdb_search_info { static int search_func(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, void *state) { struct ltdb_search_info *sinfo = state; - struct ldb_message msg; + struct ldb_message *msg; int ret; if (key.dsize < 4 || @@ -412,31 +378,37 @@ static int search_func(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, voi return 0; } + msg = talloc_p(sinfo, struct ldb_message); + if (msg == NULL) { + return -1; + } + /* unpack the record */ - ret = ltdb_unpack_data(sinfo->module, &data, &msg); + ret = ltdb_unpack_data(sinfo->module, &data, msg); if (ret == -1) { sinfo->failures++; + talloc_free(msg); return 0; } - if (!msg.dn) { - msg.dn = key.dptr + 3; + if (!msg->dn) { + msg->dn = key.dptr + 3; } /* see if it matches the given expression */ - if (!ltdb_message_match(sinfo->module, &msg, sinfo->tree, - sinfo->base, sinfo->scope)) { - ltdb_unpack_data_free(sinfo->module, &msg); + if (!ltdb_message_match(sinfo->module, msg, sinfo->tree, + sinfo->base, sinfo->scope)) { + talloc_free(msg); return 0; } - ret = ltdb_add_attr_results(sinfo->module, &msg, sinfo->attrs, &sinfo->count, &sinfo->msgs); + ret = ltdb_add_attr_results(sinfo->module, msg, sinfo->attrs, &sinfo->count, &sinfo->msgs); if (ret == -1) { sinfo->failures++; } - ltdb_unpack_data_free(sinfo->module, &msg); + talloc_free(msg); return ret; } @@ -447,19 +419,11 @@ static int search_func(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, voi */ int ltdb_search_free(struct ldb_module *module, struct ldb_message **msgs) { - struct ldb_context *ldb = module->ldb; struct ltdb_private *ltdb = module->private_data; - int i; ltdb->last_err_string = NULL; - if (!msgs) return 0; - - for (i=0;msgs[i];i++) { - msg_free_all_parts(ldb, msgs[i]); - } - - ldb_free(ldb, msgs); + talloc_free(msgs); return 0; } @@ -475,27 +439,36 @@ static int ltdb_search_full(struct ldb_module *module, const char * const attrs[], struct ldb_message ***res) { struct ltdb_private *ltdb = module->private_data; - int ret; - struct ltdb_search_info sinfo; + int ret, count; + struct ltdb_search_info *sinfo; + + sinfo = talloc_p(ltdb, struct ltdb_search_info); + if (sinfo == NULL) { + return -1; + } - sinfo.tree = tree; - sinfo.module = module; - sinfo.scope = scope; - sinfo.base = base; - sinfo.attrs = attrs; - sinfo.msgs = NULL; - sinfo.count = 0; - sinfo.failures = 0; + sinfo->tree = tree; + sinfo->module = module; + sinfo->scope = scope; + sinfo->base = base; + sinfo->attrs = attrs; + sinfo->msgs = NULL; + sinfo->count = 0; + sinfo->failures = 0; - ret = tdb_traverse(ltdb->tdb, search_func, &sinfo); + ret = tdb_traverse(ltdb->tdb, search_func, sinfo); if (ret == -1) { - ltdb_search_free(module, sinfo.msgs); + talloc_free(sinfo); return -1; } - *res = sinfo.msgs; - return sinfo.count; + *res = talloc_steal(ltdb, sinfo->msgs); + count = sinfo->count; + + talloc_free(sinfo); + + return count; } -- cgit From 3e5235a568777b5103612069e413cabe37b83c2b Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 2 Jan 2005 23:03:50 +0000 Subject: r4486: fixed some memory leaks in the new ldb code, by ensuring that memory is always allocated as a child of the right context (This used to be commit 1071712cf5951fa2e94f314bd7678cfa51b2dbcd) --- source4/lib/ldb/ldb_tdb/ldb_search.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index 720188b74c..295c9578cc 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -306,7 +306,7 @@ int ltdb_search_dn(struct ldb_module *module, char *dn, return -1; } - (*res)[0] = msg2; + (*res)[0] = talloc_steal(*res, msg2); (*res)[1] = NULL; return 1; @@ -341,7 +341,7 @@ int ltdb_add_attr_results(struct ldb_module *module, struct ldb_message *msg, (*res) = res2; - (*res)[*count] = msg2; + (*res)[*count] = talloc_steal(*res, msg2); (*res)[(*count)+1] = NULL; (*count)++; -- cgit From a2f77f979d7271a9708ed06f43b00ffb10ec7f4c Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Wed, 12 Jan 2005 16:00:01 +0000 Subject: r4714: move the ldb code to the new talloc interface (eg remove _p suffix) this helps standalone building of ldb renew the schema module split code into functions to improve readability and code reuse add and modify works correctly but we need a proper testsuite Simo (This used to be commit a681ae365ff1b5a2771b42ebd90336651ce1e513) --- source4/lib/ldb/ldb_tdb/ldb_search.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index 295c9578cc..536d1ac005 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -47,7 +47,7 @@ static int msg_add_element(struct ldb_context *ldb, unsigned int i; struct ldb_message_element *e2, *elnew; - e2 = talloc_realloc_p(ret, ret->elements, struct ldb_message_element, ret->num_elements+1); + e2 = talloc_realloc(ret, ret->elements, struct ldb_message_element, ret->num_elements+1); if (!e2) { return -1; } @@ -61,7 +61,7 @@ static int msg_add_element(struct ldb_context *ldb, } if (el->num_values) { - elnew->values = talloc_array_p(ret->elements, struct ldb_val, el->num_values); + elnew->values = talloc_array(ret->elements, struct ldb_val, el->num_values); if (!elnew->values) { return -1; } @@ -117,7 +117,7 @@ static struct ldb_message *ltdb_pull_attrs(struct ldb_module *module, struct ldb_message *ret; int i; - ret = talloc_p(ldb, struct ldb_message); + ret = talloc(ldb, struct ldb_message); if (!ret) { return NULL; } @@ -279,12 +279,12 @@ int ltdb_search_dn(struct ldb_module *module, char *dn, int ret; struct ldb_message *msg, *msg2; - *res = talloc_array_p(ldb, struct ldb_message *, 2); + *res = talloc_array(ldb, struct ldb_message *, 2); if (! *res) { return -1; } - msg = talloc_p(*res, struct ldb_message); + msg = talloc(*res, struct ldb_message); if (msg == NULL) { talloc_free(*res); *res = NULL; @@ -333,7 +333,7 @@ int ltdb_add_attr_results(struct ldb_module *module, struct ldb_message *msg, } /* add to the results list */ - res2 = talloc_realloc_p(ldb, *res, struct ldb_message *, (*count)+2); + res2 = talloc_realloc(ldb, *res, struct ldb_message *, (*count)+2); if (!res2) { talloc_free(msg2); return -1; @@ -378,7 +378,7 @@ static int search_func(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, voi return 0; } - msg = talloc_p(sinfo, struct ldb_message); + msg = talloc(sinfo, struct ldb_message); if (msg == NULL) { return -1; } @@ -442,7 +442,7 @@ static int ltdb_search_full(struct ldb_module *module, int ret, count; struct ltdb_search_info *sinfo; - sinfo = talloc_p(ltdb, struct ltdb_search_info); + sinfo = talloc(ltdb, struct ltdb_search_info); if (sinfo == NULL) { return -1; } -- cgit From 9f676afe3ab19bb0502e6dca45fe0039a2ec285b Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 15 Jan 2005 02:54:53 +0000 Subject: r4744: until we decide what to do about attribute aliasing (see my recent samba-technical posting), this is an interim solution that makes us work pretty much like w2k3 does. (This used to be commit 789325145651f2f6fc8716aa4bced83a2eb31994) --- source4/lib/ldb/ldb_tdb/ldb_search.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index 536d1ac005..f813841edb 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -150,12 +150,13 @@ static struct ldb_message *ltdb_pull_attrs(struct ldb_module *module, continue; } - if (ldb_attr_cmp(attrs[i], "dn") == 0) { + if (ldb_attr_cmp(attrs[i], "dn") == 0 || + ldb_attr_cmp(attrs[i], "distinguishedName") == 0) { struct ldb_message_element el2; struct ldb_val val; el2.flags = 0; - el2.name = talloc_strdup(ret, "dn"); + el2.name = talloc_strdup(ret, attrs[i]); if (!el2.name) { talloc_free(ret); return NULL; @@ -501,7 +502,8 @@ int ltdb_search(struct ldb_module *module, const char *base, } if (tree->operation == LDB_OP_SIMPLE && - ldb_attr_cmp(tree->u.simple.attr, "dn") == 0 && + (ldb_attr_cmp(tree->u.simple.attr, "dn") == 0 || + ldb_attr_cmp(tree->u.simple.attr, "distinguishedName") == 0) && !ltdb_has_wildcard(module, tree->u.simple.attr, &tree->u.simple.value)) { /* yay! its a nice simple one */ ret = ltdb_search_dn(module, tree->u.simple.value.data, attrs, res); -- cgit From fe4d985b6f3d318d9b58a16677be3b4ae34fba15 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 25 Apr 2005 12:46:18 +0000 Subject: r6470: Remove ldb_search_free() it is not needed anymore. Just use talloc_free() to release the memory after an ldb_search(). (This used to be commit 4f0948dab0aa5e8b6a4ce486f3668ca8dfae23db) --- source4/lib/ldb/ldb_tdb/ldb_search.c | 14 -------------- 1 file changed, 14 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index f813841edb..4f45fdf376 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -415,20 +415,6 @@ static int search_func(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, voi } -/* - free a set of search results -*/ -int ltdb_search_free(struct ldb_module *module, struct ldb_message **msgs) -{ - struct ltdb_private *ltdb = module->private_data; - - ltdb->last_err_string = NULL; - - talloc_free(msgs); - - return 0; -} - /* search the database with a LDAP-like expression. this is the "full search" non-indexed variant -- cgit From 425350bb618b7168de1d5d808c9ac5a76d84fcf0 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 1 May 2005 12:34:12 +0000 Subject: r6560: added a tdb_chainlock_read() call in ldb_search(). This guarantees that ldb_search() sees a single consistent view of the database (by blocking writes during a ldb_search) (This used to be commit 917f2a8a073fd501f0626bea4f9deb91b95fdc90) --- source4/lib/ldb/ldb_tdb/ldb_search.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index 4f45fdf376..7883ee6e7b 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -472,9 +472,14 @@ int ltdb_search(struct ldb_module *module, const char *base, struct ldb_parse_tree *tree; int ret; + if (ltdb_lock_read(module) != 0) { + return -1; + } + ltdb->last_err_string = NULL; if (ltdb_cache_load(module) != 0) { + ltdb_unlock_read(module); return -1; } @@ -484,6 +489,7 @@ int ltdb_search(struct ldb_module *module, const char *base, tree = ldb_parse_tree(ldb, expression); if (!tree) { ltdb->last_err_string = "expression parse failed"; + ltdb_unlock_read(module); return -1; } @@ -501,6 +507,7 @@ int ltdb_search(struct ldb_module *module, const char *base, } ldb_parse_tree_free(ldb, tree); + ltdb_unlock_read(module); return ret; } -- cgit From 87acba39f9e45eb6849cfd945ce6255bac5564c9 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 13 Jun 2005 05:18:17 +0000 Subject: r7514: make the ldb_parse code not depend on a ldb_context, so we can now potentially use it in our ldap client code, instead of replicating all the code (This used to be commit 5b3575d9303d54a771e080a670dcd2f444b10c20) --- source4/lib/ldb/ldb_tdb/ldb_search.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index 7883ee6e7b..e036ae0966 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -506,7 +506,7 @@ int ltdb_search(struct ldb_module *module, const char *base, } } - ldb_parse_tree_free(ldb, tree); + talloc_free(tree); ltdb_unlock_read(module); return ret; -- cgit From 4b0e5bd75373ffa2d847706a71fd0349dfa15e71 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 13 Jun 2005 09:10:17 +0000 Subject: r7527: - added a ldb_search_bytree() interface, which takes a ldb_parse_tree instead of a search expression. This allows our ldap server to pass its ASN.1 parsed search expressions straight to ldb, instead of going via strings. - updated all the ldb modules code to handle the new interface - got rid of the separate ldb_parse.h now that the ldb_parse structures are exposed externally - moved to C99 structure initialisation in ldb - switched ldap server to using ldb_search_bytree() (This used to be commit 96620ab2ee5d440bbbc51c1bc0cad9977770f897) --- source4/lib/ldb/ldb_tdb/ldb_search.c | 42 +++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 15 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index e036ae0966..17eff6f0a6 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -36,7 +36,6 @@ #include "ldb/include/ldb.h" #include "ldb/include/ldb_private.h" #include "ldb/ldb_tdb/ldb_tdb.h" -#include "ldb/include/ldb_parse.h" /* add one element to a message @@ -463,13 +462,11 @@ static int ltdb_search_full(struct ldb_module *module, search the database with a LDAP-like expression. choses a search method */ -int ltdb_search(struct ldb_module *module, const char *base, - enum ldb_scope scope, const char *expression, - const char * const attrs[], struct ldb_message ***res) +int ltdb_search_bytree(struct ldb_module *module, const char *base, + enum ldb_scope scope, struct ldb_parse_tree *tree, + const char * const attrs[], struct ldb_message ***res) { - struct ldb_context *ldb = module->ldb; struct ltdb_private *ltdb = module->private_data; - struct ldb_parse_tree *tree; int ret; if (ltdb_lock_read(module) != 0) { @@ -485,14 +482,6 @@ int ltdb_search(struct ldb_module *module, const char *base, *res = NULL; - /* form a parse tree for the expression */ - tree = ldb_parse_tree(ldb, expression); - if (!tree) { - ltdb->last_err_string = "expression parse failed"; - ltdb_unlock_read(module); - return -1; - } - if (tree->operation == LDB_OP_SIMPLE && (ldb_attr_cmp(tree->u.simple.attr, "dn") == 0 || ldb_attr_cmp(tree->u.simple.attr, "distinguishedName") == 0) && @@ -506,9 +495,32 @@ int ltdb_search(struct ldb_module *module, const char *base, } } - talloc_free(tree); ltdb_unlock_read(module); return ret; } + +/* + search the database with a LDAP-like expression. + choses a search method +*/ +int ltdb_search(struct ldb_module *module, const char *base, + enum ldb_scope scope, const char *expression, + const char * const attrs[], struct ldb_message ***res) +{ + struct ltdb_private *ltdb = module->private_data; + struct ldb_parse_tree *tree; + int ret; + + tree = ldb_parse_tree(ltdb, expression); + if (tree == NULL) { + ltdb->last_err_string = "expression parse failed"; + return -1; + } + + ret = ltdb_search_bytree(module, base, scope, tree, attrs, res); + talloc_free(tree); + return ret; +} + -- cgit From 9189833a8753a723a8b8d0af9c8b096571b06a84 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Tue, 14 Jun 2005 19:15:17 +0000 Subject: r7582: Better way to have a fast path searching for a specific DN. Old way was ugly and had a bug, you couldn't add an attribute named dn or distinguishedName and search for it, tdb would change that search in a dn search. This makes it also possible to search by dn against an ldap server as the old method was not supported by ldap syntaxes. sss (This used to be commit a614466dec2484a0d39bdfae53da822cfcf80926) --- source4/lib/ldb/ldb_tdb/ldb_search.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index 17eff6f0a6..d210510ff2 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -272,7 +272,7 @@ int ltdb_search_dn1(struct ldb_module *module, const char *dn, struct ldb_messag /* search the database for a single simple dn */ -int ltdb_search_dn(struct ldb_module *module, char *dn, +int ltdb_search_dn(struct ldb_module *module, const char *dn, const char * const attrs[], struct ldb_message ***res) { struct ldb_context *ldb = module->ldb; @@ -482,17 +482,9 @@ int ltdb_search_bytree(struct ldb_module *module, const char *base, *res = NULL; - if (tree->operation == LDB_OP_SIMPLE && - (ldb_attr_cmp(tree->u.simple.attr, "dn") == 0 || - ldb_attr_cmp(tree->u.simple.attr, "distinguishedName") == 0) && - !ltdb_has_wildcard(module, tree->u.simple.attr, &tree->u.simple.value)) { - /* yay! its a nice simple one */ - ret = ltdb_search_dn(module, tree->u.simple.value.data, attrs, res); - } else { - ret = ltdb_search_indexed(module, base, scope, tree, attrs, res); - if (ret == -1) { - ret = ltdb_search_full(module, base, scope, tree, attrs, res); - } + ret = ltdb_search_indexed(module, base, scope, tree, attrs, res); + if (ret == -1) { + ret = ltdb_search_full(module, base, scope, tree, attrs, res); } ltdb_unlock_read(module); @@ -513,6 +505,13 @@ int ltdb_search(struct ldb_module *module, const char *base, struct ldb_parse_tree *tree; int ret; + /* check if we are looking for a simple dn */ + if (scope == LDB_SCOPE_BASE && (expression == NULL || expression[0] == '\0')) { + ret = ltdb_search_dn(module, base, attrs, res); + ltdb_unlock_read(module); + return ret; + } + tree = ldb_parse_tree(ltdb, expression); if (tree == NULL) { ltdb->last_err_string = "expression parse failed"; -- cgit From 93e03bd27215a54d79ca996941468d1c33099ff3 Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Wed, 15 Jun 2005 02:45:11 +0000 Subject: r7602: fix some compiler warnings (This used to be commit ce9966e091d36f66d409ac6f7b5e462c9dc37325) --- source4/lib/ldb/ldb_tdb/ldb_search.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index d210510ff2..3644d046e0 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -169,7 +169,7 @@ static struct ldb_message *ltdb_pull_attrs(struct ldb_module *module, talloc_free(ret); return NULL; } - talloc_free(el2.name); + talloc_free(discard_const_p(char, el2.name)); continue; } -- cgit From ed3d8091ce2b2014350a2f7f22202dde6846a130 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 18 Jun 2005 07:42:21 +0000 Subject: r7709: - convert ldb to use popt, so that it can interact with the samba cmdline credentials code (which will be done soon) - added a ldb_init() call, and changed ldb_connect() to take a ldb context. This allows for much better error handling in ldb_connect(), and also made the popt conversion easier - fixed up all the existing backends with the new syntax - improved error handling in *_connect() - fixed a crash bug in the new case_fold_required() code - ensured that ltdb_rename() and all ltdb_search() paths get the read lock - added a ldb_oom() macro to make it easier to report out of memory situations in ldb code (This used to be commit f648fdf187669d6d87d01dd4e786b03cd420f220) --- source4/lib/ldb/ldb_tdb/ldb_search.c | 38 ++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index 3644d046e0..d6e7d66f68 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -272,44 +272,63 @@ int ltdb_search_dn1(struct ldb_module *module, const char *dn, struct ldb_messag /* search the database for a single simple dn */ -int ltdb_search_dn(struct ldb_module *module, const char *dn, - const char * const attrs[], struct ldb_message ***res) +static int ltdb_search_dn(struct ldb_module *module, const char *dn, + const char * const attrs[], struct ldb_message ***res) { struct ldb_context *ldb = module->ldb; + struct ltdb_private *ltdb = module->private_data; int ret; struct ldb_message *msg, *msg2; + *res = NULL; + + if (ltdb_lock_read(module) != 0) { + return -1; + } + + ltdb->last_err_string = NULL; + + if (ltdb_cache_load(module) != 0) { + ltdb_unlock_read(module); + return -1; + } + *res = talloc_array(ldb, struct ldb_message *, 2); if (! *res) { - return -1; + goto failed; } msg = talloc(*res, struct ldb_message); if (msg == NULL) { - talloc_free(*res); - *res = NULL; - return -1; + goto failed; } ret = ltdb_search_dn1(module, dn, msg); if (ret != 1) { talloc_free(*res); *res = NULL; - return ret; + ltdb_unlock_read(module); + return 0; } msg2 = ltdb_pull_attrs(module, msg, attrs); talloc_free(msg); - if (!msg2) { - return -1; + goto failed; } (*res)[0] = talloc_steal(*res, msg2); (*res)[1] = NULL; + ltdb_unlock_read(module); + return 1; + +failed: + talloc_free(*res); + ltdb_unlock_read(module); + return -1; } @@ -508,7 +527,6 @@ int ltdb_search(struct ldb_module *module, const char *base, /* check if we are looking for a simple dn */ if (scope == LDB_SCOPE_BASE && (expression == NULL || expression[0] == '\0')) { ret = ltdb_search_dn(module, base, attrs, res); - ltdb_unlock_read(module); return ret; } -- cgit From a06d66a3a669c3a0a0f816438e2b3e91e208f398 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 1 Jul 2005 06:21:26 +0000 Subject: r8037: a fairly major update to the internals of ldb. Changes are: - moved the knowledge of attribute types out of ldb_tdb and into the generic ldb code. This allows the ldb_match() message match logic to be generic, so it can be used by other backend - added the generic ability to load attribute handlers, for canonicalisation, compare, ldif read and ldif write. In the future this will be used by the schema module to allow us to correctly obey the attributetype schema elements - added attribute handlers for some of the core ldap attribute types, Integer, DirectoryString, DN, ObjectClass etc - added automatic registration of attribute handlers for well-known attribute names 'cn', 'dc', 'dn', 'ou' and 'objectClass' - converted the objectSid special handlers for Samba to the new system - added more correct handling of indexing in tdb backend based on the attribute canonicalisation function - added generic support for subclasses, moving it out of the tdb backend. This will be used in future by the schema module - fixed several bugs in the dn_explode code. It still needs more work, but doesn't corrupt ldb dbs any more. (This used to be commit 944c5844ab441b96d8e5d7b2d151982139d1fab9) --- source4/lib/ldb/ldb_tdb/ldb_search.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index d6e7d66f68..e48043da88 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -92,8 +92,9 @@ static int msg_add_all_elements(struct ldb_module *module, struct ldb_message *r unsigned int i; for (i=0;inum_elements;i++) { - int flags = ltdb_attribute_flags(module, msg->elements[i].name); - if ((msg->dn[0] != '@') && (flags & LTDB_FLAG_HIDDEN)) { + const struct ldb_attrib_handler *h; + h = ldb_attrib_handler(ldb, msg->elements[i].name); + if ((msg->dn[0] != '@') && (h->flags & LDB_ATTR_FLAG_HIDDEN)) { continue; } if (msg_add_element(ldb, ret, &msg->elements[i]) != 0) { @@ -195,7 +196,7 @@ static struct ldb_message *ltdb_pull_attrs(struct ldb_module *module, int ltdb_has_wildcard(struct ldb_module *module, const char *attr_name, const struct ldb_val *val) { - int flags; + const struct ldb_attrib_handler *h; /* all attribute types recognise the "*" wildcard */ if (val->length == 1 && strncmp((char *)val->data, "*", 1) == 0) { @@ -206,8 +207,8 @@ int ltdb_has_wildcard(struct ldb_module *module, const char *attr_name, return 0; } - flags = ltdb_attribute_flags(module, attr_name); - if (flags & LTDB_FLAG_WILDCARD) { + h = ldb_attrib_handler(module->ldb, attr_name); + if (h->flags & LDB_ATTR_FLAG_WILDCARD) { return 1; } @@ -415,8 +416,8 @@ static int search_func(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, voi } /* see if it matches the given expression */ - if (!ltdb_message_match(sinfo->module, msg, sinfo->tree, - sinfo->base, sinfo->scope)) { + if (!ldb_match_message(sinfo->module->ldb, msg, sinfo->tree, + sinfo->base, sinfo->scope)) { talloc_free(msg); return 0; } -- cgit From c9b0e86a436b5b169a4c33bd25eac379cb622b17 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Tue, 12 Jul 2005 12:04:54 +0000 Subject: r8373: New wildcard matching code. This code applies correct ldap standard wildcard matching code removes WILDCARD matching from tdb @ATTRIBUTES, that's now handled independently adds some more tests for wildcard matching fixes dn comparison code in ldb_match (This used to be commit 4eb5863042011988d85092d7dde3d809aa15bd59) --- source4/lib/ldb/ldb_tdb/ldb_search.c | 30 +----------------------------- 1 file changed, 1 insertion(+), 29 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index e48043da88..3ecb2d9b39 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -188,34 +188,6 @@ static struct ldb_message *ltdb_pull_attrs(struct ldb_module *module, } - -/* - see if a ldb_val is a wildcard - return 1 if yes, 0 if no -*/ -int ltdb_has_wildcard(struct ldb_module *module, const char *attr_name, - const struct ldb_val *val) -{ - const struct ldb_attrib_handler *h; - - /* all attribute types recognise the "*" wildcard */ - if (val->length == 1 && strncmp((char *)val->data, "*", 1) == 0) { - return 1; - } - - if (strpbrk(val->data, "*?") == NULL) { - return 0; - } - - h = ldb_attrib_handler(module->ldb, attr_name); - if (h->flags & LDB_ATTR_FLAG_WILDCARD) { - return 1; - } - - return 0; -} - - /* search the database for a single simple dn, returning all attributes in a single message @@ -416,7 +388,7 @@ static int search_func(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, voi } /* see if it matches the given expression */ - if (!ldb_match_message(sinfo->module->ldb, msg, sinfo->tree, + if (!ldb_match_msg(sinfo->module->ldb, msg, sinfo->tree, sinfo->base, sinfo->scope)) { talloc_free(msg); return 0; -- cgit From 79cac4b6e2f1b4e808930cb584c20c11b5df903f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 24 Jul 2005 12:38:42 +0000 Subject: r8736: this fixes the ldb speed (raises BENCH-WINS from 15 ops/sec to over 4000) simo, we need to be careful to cope with this sort of direct dn query efficiently (This used to be commit 7b37923b726752101062fa8a92d3f96e41d55602) --- source4/lib/ldb/ldb_tdb/ldb_search.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index 3ecb2d9b39..8e84cfa681 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -461,6 +461,13 @@ int ltdb_search_bytree(struct ldb_module *module, const char *base, struct ltdb_private *ltdb = module->private_data; int ret; + /* it is important that we handle dn queries this way, and not + via a full db search, otherwise ldb is horribly slow */ + if (tree->operation == LDB_OP_EQUALITY && + ldb_attr_cmp(tree->u.equality.attr, "dn") == 0) { + return ltdb_search_dn(module, tree->u.equality.value.data, attrs, res); + } + if (ltdb_lock_read(module) != 0) { return -1; } -- cgit From 768585b1dd3fcc2f2180528bd94e1fef4a6ead7b Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Tue, 26 Jul 2005 09:17:46 +0000 Subject: r8779: Add rdn module to makefile and headers Search by distinguishedName as if searching by dn (This used to be commit 1d4046136255aead319ab08da229146dbd285b38) --- source4/lib/ldb/ldb_tdb/ldb_search.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index 8e84cfa681..922d24b6eb 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -464,7 +464,8 @@ int ltdb_search_bytree(struct ldb_module *module, const char *base, /* it is important that we handle dn queries this way, and not via a full db search, otherwise ldb is horribly slow */ if (tree->operation == LDB_OP_EQUALITY && - ldb_attr_cmp(tree->u.equality.attr, "dn") == 0) { + (ldb_attr_cmp(tree->u.equality.attr, "dn") == 0 || + ldb_attr_cmp(tree->u.equality.attr, "distinguishedName") == 0)) { return ltdb_search_dn(module, tree->u.equality.value.data, attrs, res); } -- cgit From 3e4c4cff2177af33efdb15f03a1bbcb639505cee Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Thu, 18 Aug 2005 15:02:01 +0000 Subject: r9391: Convert all the code to use struct ldb_dn to ohandle ldap like distinguished names Provide more functions to handle DNs in this form (This used to be commit 692e35b7797e39533dd2a1c4b63d9da30f1eb5ba) --- source4/lib/ldb/ldb_tdb/ldb_search.c | 37 +++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index 922d24b6eb..160affd4e7 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -94,7 +94,7 @@ static int msg_add_all_elements(struct ldb_module *module, struct ldb_message *r for (i=0;inum_elements;i++) { const struct ldb_attrib_handler *h; h = ldb_attrib_handler(ldb, msg->elements[i].name); - if ((msg->dn[0] != '@') && (h->flags & LDB_ATTR_FLAG_HIDDEN)) { + if (ldb_dn_is_special(msg->dn) && (h->flags & LDB_ATTR_FLAG_HIDDEN)) { continue; } if (msg_add_element(ldb, ret, &msg->elements[i]) != 0) { @@ -122,7 +122,7 @@ static struct ldb_message *ltdb_pull_attrs(struct ldb_module *module, return NULL; } - ret->dn = talloc_strdup(ret, msg->dn); + ret->dn = ldb_dn_copy(ret, msg->dn); if (!ret->dn) { talloc_free(ret); return NULL; @@ -163,8 +163,8 @@ static struct ldb_message *ltdb_pull_attrs(struct ldb_module *module, } el2.num_values = 1; el2.values = &val; - val.data = ret->dn; - val.length = strlen(ret->dn); + val.data = ldb_dn_linearize(ret, ret->dn); + val.length = strlen(val.data); if (msg_add_element(ldb, ret, &el2) != 0) { talloc_free(ret); @@ -194,7 +194,7 @@ static struct ldb_message *ltdb_pull_attrs(struct ldb_module *module, return 1 on success, 0 on record-not-found and -1 on error */ -int ltdb_search_dn1(struct ldb_module *module, const char *dn, struct ldb_message *msg) +int ltdb_search_dn1(struct ldb_module *module, const struct ldb_dn *dn, struct ldb_message *msg) { struct ltdb_private *ltdb = module->private_data; int ret; @@ -231,7 +231,7 @@ int ltdb_search_dn1(struct ldb_module *module, const char *dn, struct ldb_messag } if (!msg->dn) { - msg->dn = talloc_strdup(tdb_data2.dptr, dn); + msg->dn = ldb_dn_copy(tdb_data2.dptr, dn); } if (!msg->dn) { talloc_free(tdb_data2.dptr); @@ -245,7 +245,7 @@ int ltdb_search_dn1(struct ldb_module *module, const char *dn, struct ldb_messag /* search the database for a single simple dn */ -static int ltdb_search_dn(struct ldb_module *module, const char *dn, +static int ltdb_search_dn(struct ldb_module *module, const struct ldb_dn *dn, const char * const attrs[], struct ldb_message ***res) { struct ldb_context *ldb = module->ldb; @@ -347,7 +347,7 @@ int ltdb_add_attr_results(struct ldb_module *module, struct ldb_message *msg, struct ltdb_search_info { struct ldb_module *module; struct ldb_parse_tree *tree; - const char *base; + const struct ldb_dn *base; enum ldb_scope scope; const char * const *attrs; struct ldb_message **msgs; @@ -384,7 +384,11 @@ static int search_func(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, voi } if (!msg->dn) { - msg->dn = key.dptr + 3; + msg->dn = ldb_dn_explode(msg, key.dptr + 3); + if (msg->dn == NULL) { + talloc_free(msg); + return -1; + } } /* see if it matches the given expression */ @@ -411,7 +415,7 @@ static int search_func(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, voi this is the "full search" non-indexed variant */ static int ltdb_search_full(struct ldb_module *module, - const char *base, + const struct ldb_dn *base, enum ldb_scope scope, struct ldb_parse_tree *tree, const char * const attrs[], struct ldb_message ***res) @@ -454,7 +458,7 @@ static int ltdb_search_full(struct ldb_module *module, search the database with a LDAP-like expression. choses a search method */ -int ltdb_search_bytree(struct ldb_module *module, const char *base, +int ltdb_search_bytree(struct ldb_module *module, const struct ldb_dn *base, enum ldb_scope scope, struct ldb_parse_tree *tree, const char * const attrs[], struct ldb_message ***res) { @@ -466,7 +470,14 @@ int ltdb_search_bytree(struct ldb_module *module, const char *base, if (tree->operation == LDB_OP_EQUALITY && (ldb_attr_cmp(tree->u.equality.attr, "dn") == 0 || ldb_attr_cmp(tree->u.equality.attr, "distinguishedName") == 0)) { - return ltdb_search_dn(module, tree->u.equality.value.data, attrs, res); + struct ldb_dn *dn; + dn = ldb_dn_explode(module->ldb, tree->u.equality.value.data); + if (dn == NULL) { + return -1; + } + ret = ltdb_search_dn(module, dn, attrs, res); + talloc_free(dn); + return ret; } if (ltdb_lock_read(module) != 0) { @@ -497,7 +508,7 @@ int ltdb_search_bytree(struct ldb_module *module, const char *base, search the database with a LDAP-like expression. choses a search method */ -int ltdb_search(struct ldb_module *module, const char *base, +int ltdb_search(struct ldb_module *module, const struct ldb_dn *base, enum ldb_scope scope, const char *expression, const char * const attrs[], struct ldb_message ***res) { -- cgit From d8da5e4fb7534d2931a01bfc4b6f59bdca206c65 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Thu, 15 Sep 2005 23:10:07 +0000 Subject: r10251: some more work on ldb_sqlite3 I must say that writing a new module is a very good way to find lot of subtle bugs laying in the code We need more tests! commit oLschema2ldif.c to keep it safe from data losses (rm -fr :-) update test generic to reflect the fix made on comparsion functions (This used to be commit 4357a2db5eadb15519ed93b957b2bad25ebf2a7d) --- source4/lib/ldb/ldb_tdb/ldb_search.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index 160affd4e7..ca0ae06354 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -465,6 +465,9 @@ int ltdb_search_bytree(struct ldb_module *module, const struct ldb_dn *base, struct ltdb_private *ltdb = module->private_data; int ret; + if ((base == NULL || base->comp_num == 0) && + (scope == LDB_SCOPE_BASE || scope == LDB_SCOPE_ONELEVEL)) return -1; + /* it is important that we handle dn queries this way, and not via a full db search, otherwise ldb is horribly slow */ if (tree->operation == LDB_OP_EQUALITY && @@ -516,6 +519,9 @@ int ltdb_search(struct ldb_module *module, const struct ldb_dn *base, struct ldb_parse_tree *tree; int ret; + if ((base == NULL || base->comp_num == 0) && + (scope == LDB_SCOPE_BASE || scope == LDB_SCOPE_ONELEVEL)) return -1; + /* check if we are looking for a simple dn */ if (scope == LDB_SCOPE_BASE && (expression == NULL || expression[0] == '\0')) { ret = ltdb_search_dn(module, base, attrs, res); -- cgit From 16aff2a184f7fab64d718b356056070e305e99e9 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sun, 18 Sep 2005 18:49:06 +0000 Subject: r10305: start implementing better error handling changed the prioivate modules API error string are now not spread over all modules but are kept in a single place. This allows a better control of memory and error reporting. (This used to be commit 3fc676ac1d6f59d08bedbbd9377986154cf84ce4) --- source4/lib/ldb/ldb_tdb/ldb_search.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index ca0ae06354..fc864ac2ea 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -34,6 +34,7 @@ #include "includes.h" #include "ldb/include/ldb.h" +#include "ldb/include/ldb_errors.h" #include "ldb/include/ldb_private.h" #include "ldb/ldb_tdb/ldb_tdb.h" @@ -249,7 +250,6 @@ static int ltdb_search_dn(struct ldb_module *module, const struct ldb_dn *dn, const char * const attrs[], struct ldb_message ***res) { struct ldb_context *ldb = module->ldb; - struct ltdb_private *ltdb = module->private_data; int ret; struct ldb_message *msg, *msg2; @@ -259,8 +259,6 @@ static int ltdb_search_dn(struct ldb_module *module, const struct ldb_dn *dn, return -1; } - ltdb->last_err_string = NULL; - if (ltdb_cache_load(module) != 0) { ltdb_unlock_read(module); return -1; @@ -462,7 +460,6 @@ int ltdb_search_bytree(struct ldb_module *module, const struct ldb_dn *base, enum ldb_scope scope, struct ldb_parse_tree *tree, const char * const attrs[], struct ldb_message ***res) { - struct ltdb_private *ltdb = module->private_data; int ret; if ((base == NULL || base->comp_num == 0) && @@ -476,7 +473,7 @@ int ltdb_search_bytree(struct ldb_module *module, const struct ldb_dn *base, struct ldb_dn *dn; dn = ldb_dn_explode(module->ldb, tree->u.equality.value.data); if (dn == NULL) { - return -1; + return LDB_ERR_INVALID_DN_SYNTAX; } ret = ltdb_search_dn(module, dn, attrs, res); talloc_free(dn); @@ -487,8 +484,6 @@ int ltdb_search_bytree(struct ldb_module *module, const struct ldb_dn *base, return -1; } - ltdb->last_err_string = NULL; - if (ltdb_cache_load(module) != 0) { ltdb_unlock_read(module); return -1; @@ -530,7 +525,8 @@ int ltdb_search(struct ldb_module *module, const struct ldb_dn *base, tree = ldb_parse_tree(ltdb, expression); if (tree == NULL) { - ltdb->last_err_string = "expression parse failed"; + char *err_string = talloc_strdup(module, "expression parse failed"); + if (err_string) ldb_set_errstring(module, err_string); return -1; } -- cgit From af352b4664332416a49569618fb6a2ef4099be04 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 22 Sep 2005 04:40:23 +0000 Subject: r10408: now that we are using tdb transactions we don't need any additional locking code in the ldb_tdb backend, except for a single read lock during searches to ensure searches don't cross transaction boundaries The tdb transactions code would map these extra locks to noops anyway (as locking makes no sense inside a transaction), but the work in setting up the locking keys still costs something, and it makes the code needlessly complex (This used to be commit 1b8d368a6771360fb0626127c02b3eb95f3eae59) --- source4/lib/ldb/ldb_tdb/ldb_search.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index fc864ac2ea..83079eab81 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -242,6 +242,42 @@ int ltdb_search_dn1(struct ldb_module *module, const struct ldb_dn *dn, struct l return 1; } +/* the lock key for search locking. Note that this is not a DN, its + just an arbitrary key to give to tdb. Also note that as we and + using transactions for all write operations and transactions take + care of their own locks, we don't need to do any locking anywhere + other than in ldb_search() */ +#define LDBLOCK "INT_LDBLOCK" + +/* + lock the database for read - use by ltdb_search +*/ +static int ltdb_lock_read(struct ldb_module *module) +{ + struct ltdb_private *ltdb = module->private_data; + TDB_DATA key; + + key.dptr = discard_const(LDBLOCK); + key.dsize = strlen(LDBLOCK); + + return tdb_chainlock_read(ltdb->tdb, key); +} + +/* + unlock the database after a ltdb_lock_read() +*/ +static int ltdb_unlock_read(struct ldb_module *module) +{ + struct ltdb_private *ltdb = module->private_data; + TDB_DATA key; + + key.dptr = discard_const(LDBLOCK); + key.dsize = strlen(LDBLOCK); + + return tdb_chainunlock_read(ltdb->tdb, key); +} + + /* search the database for a single simple dn -- cgit From 1828b783cf2e975c8cfc1be3eb857d9c6fbda94b Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 22 Sep 2005 13:14:12 +0000 Subject: r10422: ldb_search() can now use tdb_traverse_read() to ensure it can run in parallel with any transaction (This used to be commit ddff66298f1a668c5220e24fc47f98d7dfc3068a) --- source4/lib/ldb/ldb_tdb/ldb_search.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index 83079eab81..9af62c7754 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -472,7 +472,7 @@ static int ltdb_search_full(struct ldb_module *module, sinfo->count = 0; sinfo->failures = 0; - ret = tdb_traverse(ltdb->tdb, search_func, sinfo); + ret = tdb_traverse_read(ltdb->tdb, search_func, sinfo); if (ret == -1) { talloc_free(sinfo); -- cgit From 5ed07022b04bdbb42b7404146c7978b5de0745c0 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 30 Sep 2005 23:47:40 +0000 Subject: r10667: cope with a NULL tree for base searches in ldb_search() (This used to be commit 26ff53857802ae4a63f2b6e46c9caa7ca2fbbe89) --- source4/lib/ldb/ldb_tdb/ldb_search.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index 9af62c7754..574d9485f8 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -501,6 +501,17 @@ int ltdb_search_bytree(struct ldb_module *module, const struct ldb_dn *base, if ((base == NULL || base->comp_num == 0) && (scope == LDB_SCOPE_BASE || scope == LDB_SCOPE_ONELEVEL)) return -1; + /* check if we are looking for a simple dn */ + if (scope == LDB_SCOPE_BASE && tree == NULL) { + return ltdb_search_dn(module, base, attrs, res); + } + + if (tree == NULL) { + char *err_string = talloc_strdup(module, "expression parse failed"); + if (err_string) ldb_set_errstring(module, err_string); + return -1; + } + /* it is important that we handle dn queries this way, and not via a full db search, otherwise ldb is horribly slow */ if (tree->operation == LDB_OP_EQUALITY && @@ -553,18 +564,7 @@ int ltdb_search(struct ldb_module *module, const struct ldb_dn *base, if ((base == NULL || base->comp_num == 0) && (scope == LDB_SCOPE_BASE || scope == LDB_SCOPE_ONELEVEL)) return -1; - /* check if we are looking for a simple dn */ - if (scope == LDB_SCOPE_BASE && (expression == NULL || expression[0] == '\0')) { - ret = ltdb_search_dn(module, base, attrs, res); - return ret; - } - tree = ldb_parse_tree(ltdb, expression); - if (tree == NULL) { - char *err_string = talloc_strdup(module, "expression parse failed"); - if (err_string) ldb_set_errstring(module, err_string); - return -1; - } ret = ltdb_search_bytree(module, base, scope, tree, attrs, res); talloc_free(tree); -- cgit From 5fd031c97daaa1bf09a7ad80550753acd434075f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 6 Oct 2005 05:24:46 +0000 Subject: r10753: don't require every ldb module to implement both a search_bytree() and a search() function, instead each module now only implements the bytree method, and the expression based search is handled generically by the modules code. This makes for more consistency and less code duplication. fixed the tdb backend to handle BASE searches much more efficiently. They now always only lookup one record, regardless of the search expression (This used to be commit 7e44f9153c5578624e2fca04cdc0a00af0fd9eb4) --- source4/lib/ldb/ldb_tdb/ldb_search.c | 35 +---------------------------------- 1 file changed, 1 insertion(+), 34 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index 574d9485f8..eb89753007 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -95,7 +95,7 @@ static int msg_add_all_elements(struct ldb_module *module, struct ldb_message *r for (i=0;inum_elements;i++) { const struct ldb_attrib_handler *h; h = ldb_attrib_handler(ldb, msg->elements[i].name); - if (ldb_dn_is_special(msg->dn) && (h->flags & LDB_ATTR_FLAG_HIDDEN)) { + if (h->flags & LDB_ATTR_FLAG_HIDDEN) { continue; } if (msg_add_element(ldb, ret, &msg->elements[i]) != 0) { @@ -501,17 +501,6 @@ int ltdb_search_bytree(struct ldb_module *module, const struct ldb_dn *base, if ((base == NULL || base->comp_num == 0) && (scope == LDB_SCOPE_BASE || scope == LDB_SCOPE_ONELEVEL)) return -1; - /* check if we are looking for a simple dn */ - if (scope == LDB_SCOPE_BASE && tree == NULL) { - return ltdb_search_dn(module, base, attrs, res); - } - - if (tree == NULL) { - char *err_string = talloc_strdup(module, "expression parse failed"); - if (err_string) ldb_set_errstring(module, err_string); - return -1; - } - /* it is important that we handle dn queries this way, and not via a full db search, otherwise ldb is horribly slow */ if (tree->operation == LDB_OP_EQUALITY && @@ -549,25 +538,3 @@ int ltdb_search_bytree(struct ldb_module *module, const struct ldb_dn *base, } -/* - search the database with a LDAP-like expression. - choses a search method -*/ -int ltdb_search(struct ldb_module *module, const struct ldb_dn *base, - enum ldb_scope scope, const char *expression, - const char * const attrs[], struct ldb_message ***res) -{ - struct ltdb_private *ltdb = module->private_data; - struct ldb_parse_tree *tree; - int ret; - - if ((base == NULL || base->comp_num == 0) && - (scope == LDB_SCOPE_BASE || scope == LDB_SCOPE_ONELEVEL)) return -1; - - tree = ldb_parse_tree(ltdb, expression); - - ret = ltdb_search_bytree(module, base, scope, tree, attrs, res); - talloc_free(tree); - return ret; -} - -- cgit From a3b33d6fa811dd1277e51e17ba4a4c3954457397 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 11 Oct 2005 04:34:15 +0000 Subject: r10889: make searches for dn's less of a special case, and much faster when part of more complex expressions (This used to be commit 40d304140b4cf22559d6b55c8cbaf1b984baf62f) --- source4/lib/ldb/ldb_tdb/ldb_search.c | 15 --------------- 1 file changed, 15 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index eb89753007..74046475e0 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -501,21 +501,6 @@ int ltdb_search_bytree(struct ldb_module *module, const struct ldb_dn *base, if ((base == NULL || base->comp_num == 0) && (scope == LDB_SCOPE_BASE || scope == LDB_SCOPE_ONELEVEL)) return -1; - /* it is important that we handle dn queries this way, and not - via a full db search, otherwise ldb is horribly slow */ - if (tree->operation == LDB_OP_EQUALITY && - (ldb_attr_cmp(tree->u.equality.attr, "dn") == 0 || - ldb_attr_cmp(tree->u.equality.attr, "distinguishedName") == 0)) { - struct ldb_dn *dn; - dn = ldb_dn_explode(module->ldb, tree->u.equality.value.data); - if (dn == NULL) { - return LDB_ERR_INVALID_DN_SYNTAX; - } - ret = ltdb_search_dn(module, dn, attrs, res); - talloc_free(dn); - return ret; - } - if (ltdb_lock_read(module) != 0) { return -1; } -- cgit From 39a504699bc1e9514fbfc0b8cea8da8933e3a2af Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 11 Oct 2005 06:21:07 +0000 Subject: r10892: - improved the handling of the special distinguishedName attribute - ensure we don't add attributes twice, should a user ask for the attribute twice. Do this in such a way that we don't become O(n^2) - removed some unused code (This used to be commit 7684cdb47b4ae516f066afb249d5f88032152ec9) --- source4/lib/ldb/ldb_tdb/ldb_search.c | 128 ++++++++++++----------------------- 1 file changed, 43 insertions(+), 85 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index 74046475e0..e0a62962c7 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -42,11 +42,18 @@ add one element to a message */ static int msg_add_element(struct ldb_context *ldb, - struct ldb_message *ret, const struct ldb_message_element *el) + struct ldb_message *ret, + const struct ldb_message_element *el, + int check_duplicates) { unsigned int i; struct ldb_message_element *e2, *elnew; + if (check_duplicates && ldb_msg_find_element(ret, el->name)) { + /* its already there */ + return 0; + } + e2 = talloc_realloc(ret, ret->elements, struct ldb_message_element, ret->num_elements+1); if (!e2) { return -1; @@ -83,6 +90,30 @@ static int msg_add_element(struct ldb_context *ldb, return 0; } +/* + add the special distinguishedName element +*/ +static int msg_add_distinguished_name(struct ldb_module *module, struct ldb_message *msg) +{ + struct ldb_message_element el; + struct ldb_val val; + int ret; + + el.flags = 0; + el.name = talloc_strdup(msg, "distinguishedName"); + if (!el.name) { + return -1; + } + el.num_values = 1; + el.values = &val; + val.data = ldb_dn_linearize(msg, msg->dn); + val.length = strlen(val.data); + + ret = msg_add_element(module->ldb, msg, &el, 1); + talloc_free(el.name); + return ret; +} + /* add all elements from one message into another */ @@ -91,6 +122,11 @@ static int msg_add_all_elements(struct ldb_module *module, struct ldb_message *r { struct ldb_context *ldb = module->ldb; unsigned int i; + int check_duplicates = (ret->num_elements != 0); + + if (msg_add_distinguished_name(module, ret) != 0) { + return -1; + } for (i=0;inum_elements;i++) { const struct ldb_attrib_handler *h; @@ -98,7 +134,8 @@ static int msg_add_all_elements(struct ldb_module *module, struct ldb_message *r if (h->flags & LDB_ATTR_FLAG_HIDDEN) { continue; } - if (msg_add_element(ldb, ret, &msg->elements[i]) != 0) { + if (msg_add_element(ldb, ret, &msg->elements[i], + check_duplicates) != 0) { return -1; } } @@ -151,27 +188,10 @@ static struct ldb_message *ltdb_pull_attrs(struct ldb_module *module, continue; } - if (ldb_attr_cmp(attrs[i], "dn") == 0 || - ldb_attr_cmp(attrs[i], "distinguishedName") == 0) { - struct ldb_message_element el2; - struct ldb_val val; - - el2.flags = 0; - el2.name = talloc_strdup(ret, attrs[i]); - if (!el2.name) { - talloc_free(ret); - return NULL; - } - el2.num_values = 1; - el2.values = &val; - val.data = ldb_dn_linearize(ret, ret->dn); - val.length = strlen(val.data); - - if (msg_add_element(ldb, ret, &el2) != 0) { - talloc_free(ret); - return NULL; + if (ldb_attr_cmp(attrs[i], "distinguishedName") == 0) { + if (msg_add_distinguished_name(module, ret) != 0) { + return -1; } - talloc_free(discard_const_p(char, el2.name)); continue; } @@ -179,7 +199,7 @@ static struct ldb_message *ltdb_pull_attrs(struct ldb_module *module, if (!el) { continue; } - if (msg_add_element(ldb, ret, el) != 0) { + if (msg_add_element(ldb, ret, el, 1) != 0) { talloc_free(ret); return NULL; } @@ -277,68 +297,6 @@ static int ltdb_unlock_read(struct ldb_module *module) return tdb_chainunlock_read(ltdb->tdb, key); } - - -/* - search the database for a single simple dn -*/ -static int ltdb_search_dn(struct ldb_module *module, const struct ldb_dn *dn, - const char * const attrs[], struct ldb_message ***res) -{ - struct ldb_context *ldb = module->ldb; - int ret; - struct ldb_message *msg, *msg2; - - *res = NULL; - - if (ltdb_lock_read(module) != 0) { - return -1; - } - - if (ltdb_cache_load(module) != 0) { - ltdb_unlock_read(module); - return -1; - } - - *res = talloc_array(ldb, struct ldb_message *, 2); - if (! *res) { - goto failed; - } - - msg = talloc(*res, struct ldb_message); - if (msg == NULL) { - goto failed; - } - - ret = ltdb_search_dn1(module, dn, msg); - if (ret != 1) { - talloc_free(*res); - *res = NULL; - ltdb_unlock_read(module); - return 0; - } - - msg2 = ltdb_pull_attrs(module, msg, attrs); - - talloc_free(msg); - if (!msg2) { - goto failed; - } - - (*res)[0] = talloc_steal(*res, msg2); - (*res)[1] = NULL; - - ltdb_unlock_read(module); - - return 1; - -failed: - talloc_free(*res); - ltdb_unlock_read(module); - return -1; -} - - /* add a set of attributes from a record to a set of results return 0 on success, -1 on failure -- cgit From a599edf04cbdeef9014923ba0d3713b8ff84f266 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 12 Oct 2005 06:10:23 +0000 Subject: r10913: This patch isn't as big as it looks ... most of the changes are fixes to make all the ldb code compile without warnings on gcc4. Unfortunately That required a lot of casts :-( I have also added the start of an 'operational' module, which will replace the timestamp module, plus add support for some other operational attributes In ldb_msg_*() I added some new utility functions to make the operational module sane, and remove the 'ldb' argument from the ldb_msg_add_*() functions. That argument was only needed back in the early days of ldb when we didn't use the hierarchical talloc and thus needed a place to get the allocation function from. Now its just a pain to pass around everywhere. Also added a ldb_debug_set() function that calls ldb_debug() plus sets the result using ldb_set_errstring(). That saves on some awkward coding in a few places. (This used to be commit f6818daecca95760c12f79fd307770cbe3346f57) --- source4/lib/ldb/ldb_tdb/ldb_search.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index e0a62962c7..97f8a7d0be 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -100,17 +100,13 @@ static int msg_add_distinguished_name(struct ldb_module *module, struct ldb_mess int ret; el.flags = 0; - el.name = talloc_strdup(msg, "distinguishedName"); - if (!el.name) { - return -1; - } + el.name = "distinguishedName"; el.num_values = 1; el.values = &val; - val.data = ldb_dn_linearize(msg, msg->dn); - val.length = strlen(val.data); + val.data = (uint8_t *)ldb_dn_linearize(msg, msg->dn); + val.length = strlen((char *)val.data); ret = msg_add_element(module->ldb, msg, &el, 1); - talloc_free(el.name); return ret; } @@ -190,7 +186,7 @@ static struct ldb_message *ltdb_pull_attrs(struct ldb_module *module, if (ldb_attr_cmp(attrs[i], "distinguishedName") == 0) { if (msg_add_distinguished_name(module, ret) != 0) { - return -1; + return NULL; } continue; } @@ -358,7 +354,7 @@ static int search_func(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, voi int ret; if (key.dsize < 4 || - strncmp(key.dptr, "DN=", 3) != 0) { + strncmp((char *)key.dptr, "DN=", 3) != 0) { return 0; } @@ -376,7 +372,7 @@ static int search_func(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, voi } if (!msg->dn) { - msg->dn = ldb_dn_explode(msg, key.dptr + 3); + msg->dn = ldb_dn_explode(msg, (char *)key.dptr + 3); if (msg->dn == NULL) { talloc_free(msg); return -1; -- cgit From 5c9590587197dcb95007fdc54318187d5716c7c6 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Tue, 8 Nov 2005 00:11:45 +0000 Subject: r11567: Ldb API change patch. This patch changes the way lsb_search is called and the meaning of the returned integer. The last argument of ldb_search is changed from struct ldb_message to struct ldb_result which contains a pointer to a struct ldb_message list and a count of the number of messages. The return is not the count of messages anymore but instead it is an ldb error value. I tryed to keep the patch as tiny as possible bu as you can guess I had to change a good amount of places. I also tried to double check all my changes being sure that the calling functions would still behave as before. But this patch is big enough that I fear some bug may have been introduced anyway even if it passes the test suite. So if you are currently working on any file being touched please give it a deep look and blame me for any error. Simo. (This used to be commit 22c8c97e6fb466b41859e090e959d7f1134be780) --- source4/lib/ldb/ldb_tdb/ldb_search.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index 97f8a7d0be..01a87e00b1 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -299,7 +299,7 @@ static int ltdb_unlock_read(struct ldb_module *module) */ int ltdb_add_attr_results(struct ldb_module *module, struct ldb_message *msg, const char * const attrs[], - int *count, + unsigned int *count, struct ldb_message ***res) { struct ldb_context *ldb = module->ldb; @@ -339,8 +339,8 @@ struct ltdb_search_info { enum ldb_scope scope; const char * const *attrs; struct ldb_message **msgs; - int failures; - int count; + unsigned int failures; + unsigned int count; }; @@ -406,15 +406,22 @@ static int ltdb_search_full(struct ldb_module *module, const struct ldb_dn *base, enum ldb_scope scope, struct ldb_parse_tree *tree, - const char * const attrs[], struct ldb_message ***res) + const char * const attrs[], struct ldb_result **res) { struct ltdb_private *ltdb = module->private_data; - int ret, count; + struct ldb_result *result; + int ret; struct ltdb_search_info *sinfo; + result = talloc(ltdb, struct ldb_result); + if (result == NULL) { + return LDB_ERR_OTHER; + } + sinfo = talloc(ltdb, struct ltdb_search_info); if (sinfo == NULL) { - return -1; + talloc_free(result); + return LDB_ERR_OTHER; } sinfo->tree = tree; @@ -429,16 +436,18 @@ static int ltdb_search_full(struct ldb_module *module, ret = tdb_traverse_read(ltdb->tdb, search_func, sinfo); if (ret == -1) { + talloc_free(result); talloc_free(sinfo); return -1; } - *res = talloc_steal(ltdb, sinfo->msgs); - count = sinfo->count; + result->msgs = talloc_steal(result, sinfo->msgs); + result->count = sinfo->count; + *res = result; talloc_free(sinfo); - return count; + return LDB_SUCCESS; } @@ -448,7 +457,7 @@ static int ltdb_search_full(struct ldb_module *module, */ int ltdb_search_bytree(struct ldb_module *module, const struct ldb_dn *base, enum ldb_scope scope, struct ldb_parse_tree *tree, - const char * const attrs[], struct ldb_message ***res) + const char * const attrs[], struct ldb_result **res) { int ret; -- cgit 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/ldb_tdb/ldb_search.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index 01a87e00b1..aa5cb40712 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -441,6 +441,7 @@ static int ltdb_search_full(struct ldb_module *module, return -1; } + result->controls = NULL; result->msgs = talloc_steal(result, sinfo->msgs); result->count = sinfo->count; *res = result; -- 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/ldb_tdb/ldb_search.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index aa5cb40712..6701d1bd11 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -33,9 +33,8 @@ */ #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" + #include "ldb/ldb_tdb/ldb_tdb.h" /* -- cgit From b60415745a0038dbfdca752861201fba0d942ff6 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Tue, 31 Jan 2006 11:16:43 +0000 Subject: r13258: Fix the talloc heirachy for ldb_tdb. In the return value res->msgs, msgs was not a child of res, in the indexed path. Instead, it hung directly off the ldb, which was sometimes a long-term context. Also remove unused parameters. Found by --leak-report-full Andrew Bartlett (This used to be commit 29cb5af827c459758997c80dca034d471bb92449) --- source4/lib/ldb/ldb_tdb/ldb_search.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index 6701d1bd11..ebbc1a3974 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -40,8 +40,7 @@ /* add one element to a message */ -static int msg_add_element(struct ldb_context *ldb, - struct ldb_message *ret, +static int msg_add_element(struct ldb_message *ret, const struct ldb_message_element *el, int check_duplicates) { @@ -92,7 +91,7 @@ static int msg_add_element(struct ldb_context *ldb, /* add the special distinguishedName element */ -static int msg_add_distinguished_name(struct ldb_module *module, struct ldb_message *msg) +static int msg_add_distinguished_name(struct ldb_message *msg) { struct ldb_message_element el; struct ldb_val val; @@ -105,7 +104,7 @@ static int msg_add_distinguished_name(struct ldb_module *module, struct ldb_mess val.data = (uint8_t *)ldb_dn_linearize(msg, msg->dn); val.length = strlen((char *)val.data); - ret = msg_add_element(module->ldb, msg, &el, 1); + ret = msg_add_element(msg, &el, 1); return ret; } @@ -119,7 +118,7 @@ static int msg_add_all_elements(struct ldb_module *module, struct ldb_message *r unsigned int i; int check_duplicates = (ret->num_elements != 0); - if (msg_add_distinguished_name(module, ret) != 0) { + if (msg_add_distinguished_name(ret) != 0) { return -1; } @@ -129,7 +128,7 @@ static int msg_add_all_elements(struct ldb_module *module, struct ldb_message *r if (h->flags & LDB_ATTR_FLAG_HIDDEN) { continue; } - if (msg_add_element(ldb, ret, &msg->elements[i], + if (msg_add_element(ret, &msg->elements[i], check_duplicates) != 0) { return -1; } @@ -143,14 +142,14 @@ static int msg_add_all_elements(struct ldb_module *module, struct ldb_message *r pull the specified list of attributes from a message */ static struct ldb_message *ltdb_pull_attrs(struct ldb_module *module, + TALLOC_CTX *mem_ctx, const struct ldb_message *msg, const char * const *attrs) { - struct ldb_context *ldb = module->ldb; struct ldb_message *ret; int i; - ret = talloc(ldb, struct ldb_message); + ret = talloc(mem_ctx, struct ldb_message); if (!ret) { return NULL; } @@ -184,7 +183,7 @@ static struct ldb_message *ltdb_pull_attrs(struct ldb_module *module, } if (ldb_attr_cmp(attrs[i], "distinguishedName") == 0) { - if (msg_add_distinguished_name(module, ret) != 0) { + if (msg_add_distinguished_name(ret) != 0) { return NULL; } continue; @@ -194,7 +193,7 @@ static struct ldb_message *ltdb_pull_attrs(struct ldb_module *module, if (!el) { continue; } - if (msg_add_element(ldb, ret, el, 1) != 0) { + if (msg_add_element(ret, el, 1) != 0) { talloc_free(ret); return NULL; } @@ -296,23 +295,24 @@ static int ltdb_unlock_read(struct ldb_module *module) add a set of attributes from a record to a set of results return 0 on success, -1 on failure */ -int ltdb_add_attr_results(struct ldb_module *module, struct ldb_message *msg, +int ltdb_add_attr_results(struct ldb_module *module, + TALLOC_CTX *mem_ctx, + struct ldb_message *msg, const char * const attrs[], unsigned int *count, struct ldb_message ***res) { - struct ldb_context *ldb = module->ldb; struct ldb_message *msg2; struct ldb_message **res2; /* pull the attributes that the user wants */ - msg2 = ltdb_pull_attrs(module, msg, attrs); + msg2 = ltdb_pull_attrs(module, mem_ctx, msg, attrs); if (!msg2) { return -1; } /* add to the results list */ - res2 = talloc_realloc(ldb, *res, struct ldb_message *, (*count)+2); + res2 = talloc_realloc(mem_ctx, *res, struct ldb_message *, (*count)+2); if (!res2) { talloc_free(msg2); return -1; @@ -385,7 +385,7 @@ static int search_func(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, voi return 0; } - ret = ltdb_add_attr_results(sinfo->module, msg, sinfo->attrs, &sinfo->count, &sinfo->msgs); + ret = ltdb_add_attr_results(sinfo->module, sinfo, msg, sinfo->attrs, &sinfo->count, &sinfo->msgs); if (ret == -1) { sinfo->failures++; -- cgit From ab6a39fa4f6442412f3629c4b9b64feeb1e32b19 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Wed, 1 Feb 2006 20:48:05 +0000 Subject: r13289: Check the tree is not NULL Thanks to Aaron J. Seigo for spotting this (This used to be commit 4b5c0493e2276a9eba1bada7c4bac99999a465e2) --- source4/lib/ldb/ldb_tdb/ldb_search.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index ebbc1a3974..e43125d588 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -473,6 +473,10 @@ int ltdb_search_bytree(struct ldb_module *module, const struct ldb_dn *base, return -1; } + if (tree == NULL) { + return -1; + } + *res = NULL; ret = ltdb_search_indexed(module, base, scope, tree, attrs, res); -- cgit From 00fe70e5b917769418f68eaa255d3a06a9a08ce7 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Wed, 22 Feb 2006 01:31:35 +0000 Subject: r13609: Get in the initial work on making ldb async Currently only ldb_ildap is async, the plan is to first make all backend support the async calls, and then remove the sync functions from backends and keep the only in the API. Modules will need to be transformed along the way. Simo (This used to be commit 1e2c13b2d52de7c534493dd79a2c0596a3e8c1f5) --- source4/lib/ldb/ldb_tdb/ldb_search.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index e43125d588..d468f02e77 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -441,6 +441,7 @@ static int ltdb_search_full(struct ldb_module *module, } result->controls = NULL; + result->refs = NULL; result->msgs = talloc_steal(result, sinfo->msgs); result->count = sinfo->count; *res = result; -- cgit From 6ef61825541131e16a03975cdbd344e2bbebf810 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Fri, 3 Mar 2006 17:44:03 +0000 Subject: r13818: Make ldb_tdb 'fake' async. Simo. (This used to be commit 0db616ef59ed51cac7e0bfaea8a799d5aa42ef16) --- source4/lib/ldb/ldb_tdb/ldb_search.c | 301 ++++++++++++++++++++++++----------- 1 file changed, 208 insertions(+), 93 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index d468f02e77..46f560f817 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -213,7 +213,7 @@ int ltdb_search_dn1(struct ldb_module *module, const struct ldb_dn *dn, struct l { struct ltdb_private *ltdb = module->private_data; int ret; - TDB_DATA tdb_key, tdb_data, tdb_data2; + TDB_DATA tdb_key, tdb_data; memset(msg, 0, sizeof(*msg)); @@ -229,27 +229,19 @@ int ltdb_search_dn1(struct ldb_module *module, const struct ldb_dn *dn, struct l return 0; } - tdb_data2.dptr = talloc_memdup(msg, tdb_data.dptr, tdb_data.dsize); - free(tdb_data.dptr); - if (!tdb_data2.dptr) { - return -1; - } - tdb_data2.dsize = tdb_data.dsize; - msg->num_elements = 0; msg->elements = NULL; - ret = ltdb_unpack_data(module, &tdb_data2, msg); + ret = ltdb_unpack_data(module, &tdb_data, msg); + free(tdb_data.dptr); if (ret == -1) { - talloc_free(tdb_data2.dptr); return -1; } if (!msg->dn) { - msg->dn = ldb_dn_copy(tdb_data2.dptr, dn); + msg->dn = ldb_dn_copy(msg, dn); } if (!msg->dn) { - talloc_free(tdb_data2.dptr); return -1; } @@ -328,28 +320,67 @@ int ltdb_add_attr_results(struct ldb_module *module, } + /* - internal search state during a full db search -*/ -struct ltdb_search_info { - struct ldb_module *module; - struct ldb_parse_tree *tree; - const struct ldb_dn *base; - enum ldb_scope scope; - const char * const *attrs; - struct ldb_message **msgs; - unsigned int failures; - unsigned int count; -}; + filter the specified list of attributes from a message + removing not requested attrs. + */ +int ltdb_filter_attrs(struct ldb_message *msg, const char * const *attrs) +{ + int i, keep_all = 0; + + if (attrs) { + /* check for special attrs */ + for (i = 0; attrs[i]; i++) { + if (strcmp(attrs[i], "*") == 0) { + keep_all = 1; + break; + } + + if (ldb_attr_cmp(attrs[i], "distinguishedName") == 0) { + if (msg_add_distinguished_name(msg) != 0) { + return -1; + } + } + } + } else { + keep_all = 1; + } + + if (keep_all) { + if (msg_add_distinguished_name(msg) != 0) { + return -1; + } + return 0; + } + + for (i = 0; i < msg->num_elements; i++) { + int j, found; + + for (j = 0, found = 0; attrs[j]; j++) { + if (ldb_attr_cmp(msg->elements[i].name, attrs[j]) == 0) { + found = 1; + break; + } + } + if (!found) { + ldb_msg_remove_attr(msg, msg->elements[i].name); + i--; + } + } + + return 0; +} /* search function for a non-indexed search */ static int search_func(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, void *state) { - struct ltdb_search_info *sinfo = state; - struct ldb_message *msg; + struct ldb_async_handle *handle = talloc_get_type(state, struct ldb_async_handle); + struct ltdb_async_context *ac = talloc_get_type(handle->private_data, struct ltdb_async_context); + struct ldb_async_result *ares = NULL; int ret; if (key.dsize < 4 || @@ -357,43 +388,65 @@ static int search_func(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, voi return 0; } - msg = talloc(sinfo, struct ldb_message); - if (msg == NULL) { + ares = talloc_zero(ac, struct ldb_async_result); + if (!ares) { + handle->status = LDB_ERR_OPERATIONS_ERROR; + handle->state = LDB_ASYNC_DONE; + return -1; + } + + ares->message = ldb_msg_new(ares); + if (!ares->message) { + handle->status = LDB_ERR_OPERATIONS_ERROR; + handle->state = LDB_ASYNC_DONE; + talloc_free(ares); return -1; } /* unpack the record */ - ret = ltdb_unpack_data(sinfo->module, &data, msg); + ret = ltdb_unpack_data(ac->module, &data, ares->message); if (ret == -1) { - sinfo->failures++; - talloc_free(msg); - return 0; + talloc_free(ares); + return -1; } - if (!msg->dn) { - msg->dn = ldb_dn_explode(msg, (char *)key.dptr + 3); - if (msg->dn == NULL) { - talloc_free(msg); + if (!ares->message->dn) { + ares->message->dn = ldb_dn_explode(ares->message, (char *)key.dptr + 3); + if (ares->message->dn == NULL) { + handle->status = LDB_ERR_OPERATIONS_ERROR; + handle->state = LDB_ASYNC_DONE; + talloc_free(ares); return -1; } } /* see if it matches the given expression */ - if (!ldb_match_msg(sinfo->module->ldb, msg, sinfo->tree, - sinfo->base, sinfo->scope)) { - talloc_free(msg); + if (!ldb_match_msg(ac->module->ldb, ares->message, ac->tree, + ac->base, ac->scope)) { + talloc_free(ares); return 0; } - ret = ltdb_add_attr_results(sinfo->module, sinfo, msg, sinfo->attrs, &sinfo->count, &sinfo->msgs); + /* filter the attributes that the user wants */ + ret = ltdb_filter_attrs(ares->message, ac->attrs); if (ret == -1) { - sinfo->failures++; + handle->status = LDB_ERR_OPERATIONS_ERROR; + handle->state = LDB_ASYNC_DONE; + talloc_free(ares); + return -1; } - talloc_free(msg); + ares->type = LDB_REPLY_ENTRY; + handle->state = LDB_ASYNC_PENDING; + handle->status = ac->callback(ac->module->ldb, ac->context, ares); - return ret; + if (handle->status != LDB_SUCCESS) { + /* don't try to free ares here, the callback is in charge of that */ + return -1; + } + + return 0; } @@ -401,88 +454,121 @@ static int search_func(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, voi search the database with a LDAP-like expression. this is the "full search" non-indexed variant */ -static int ltdb_search_full(struct ldb_module *module, - const struct ldb_dn *base, - enum ldb_scope scope, - struct ldb_parse_tree *tree, - const char * const attrs[], struct ldb_result **res) +static int ltdb_search_full(struct ldb_async_handle *handle) { - struct ltdb_private *ltdb = module->private_data; - struct ldb_result *result; + struct ltdb_async_context *ac = talloc_get_type(handle->private_data, struct ltdb_async_context); + struct ltdb_private *ltdb = talloc_get_type(ac->module->private_data, struct ltdb_private); int ret; - struct ltdb_search_info *sinfo; - result = talloc(ltdb, struct ldb_result); - if (result == NULL) { - return LDB_ERR_OTHER; - } + ret = tdb_traverse_read(ltdb->tdb, search_func, handle); - sinfo = talloc(ltdb, struct ltdb_search_info); - if (sinfo == NULL) { - talloc_free(result); - return LDB_ERR_OTHER; + handle->state = LDB_ASYNC_DONE; + + if (ret == -1) { + handle->status = LDB_ERR_OPERATIONS_ERROR; + return handle->status; } - sinfo->tree = tree; - sinfo->module = module; - sinfo->scope = scope; - sinfo->base = base; - sinfo->attrs = attrs; - sinfo->msgs = NULL; - sinfo->count = 0; - sinfo->failures = 0; + handle->status = LDB_SUCCESS; + return handle->status; +} + +static int ltdb_search_sync_callback(struct ldb_context *ldb, void *context, struct ldb_async_result *ares) +{ + struct ldb_result *res; + + if (!context) { + ldb_set_errstring(ldb, talloc_strdup(ldb, "NULL Context in callback")); + goto error; + } - ret = tdb_traverse_read(ltdb->tdb, search_func, sinfo); + res = *((struct ldb_result **)context); - if (ret == -1) { - talloc_free(result); - talloc_free(sinfo); - return -1; + if (!res || !ares) { + goto error; } - result->controls = NULL; - result->refs = NULL; - result->msgs = talloc_steal(result, sinfo->msgs); - result->count = sinfo->count; - *res = result; + if (ares->type == LDB_REPLY_ENTRY) { + res->msgs = talloc_realloc(res, res->msgs, struct ldb_message *, res->count + 2); + if (! res->msgs) { + goto error; + } + + res->msgs[res->count + 1] = NULL; + + res->msgs[res->count] = talloc_steal(res->msgs, ares->message); + if (! res->msgs[res->count]) { + goto error; + } - talloc_free(sinfo); + res->count++; + } else { + ldb_debug(ldb, LDB_DEBUG_ERROR, "unrecognized async reply in ltdb_search_sync_callback!\n"); + goto error; + } + talloc_free(ares); return LDB_SUCCESS; -} +error: + if (ares) talloc_free(ares); + if (res) talloc_free(res); + if (context) *((struct ldb_result **)context) = NULL; + return LDB_ERR_OPERATIONS_ERROR; +} -/* - search the database with a LDAP-like expression. - choses a search method -*/ -int ltdb_search_bytree(struct ldb_module *module, const struct ldb_dn *base, - enum ldb_scope scope, struct ldb_parse_tree *tree, - const char * const attrs[], struct ldb_result **res) +int ltdb_search_async(struct ldb_module *module, const struct ldb_dn *base, + enum ldb_scope scope, struct ldb_parse_tree *tree, + const char * const *attrs, + void *context, + int (*callback)(struct ldb_context *, void *, struct ldb_async_result *), + int timeout, + struct ldb_async_handle **handle) { + struct ltdb_private *ltdb = talloc_get_type(module->private_data, struct ltdb_private); + struct ltdb_async_context *ltdb_ac; int ret; if ((base == NULL || base->comp_num == 0) && - (scope == LDB_SCOPE_BASE || scope == LDB_SCOPE_ONELEVEL)) return -1; + (scope == LDB_SCOPE_BASE || scope == LDB_SCOPE_ONELEVEL)) + return LDB_ERR_OPERATIONS_ERROR; if (ltdb_lock_read(module) != 0) { - return -1; + return LDB_ERR_OPERATIONS_ERROR; } if (ltdb_cache_load(module) != 0) { ltdb_unlock_read(module); - return -1; + return LDB_ERR_OPERATIONS_ERROR; } if (tree == NULL) { - return -1; + ltdb_unlock_read(module); + return LDB_ERR_OPERATIONS_ERROR; + } + + *handle = init_ltdb_handle(ltdb, module, context, callback, timeout); + if (*handle == NULL) { + talloc_free(*handle); + ltdb_unlock_read(module); + return LDB_ERR_OPERATIONS_ERROR; } - *res = NULL; + ltdb_ac = talloc_get_type((*handle)->private_data, struct ltdb_async_context); + + ltdb_ac->tree = tree; + ltdb_ac->scope = scope; + ltdb_ac->base = base; + ltdb_ac->attrs = attrs; - ret = ltdb_search_indexed(module, base, scope, tree, attrs, res); + ret = ltdb_search_indexed(*handle); if (ret == -1) { - ret = ltdb_search_full(module, base, scope, tree, attrs, res); + ret = ltdb_search_full(*handle); + } + if (ret != LDB_SUCCESS) { + ldb_set_errstring(module->ldb, talloc_strdup(module->ldb, "Indexed and full searches both failed!\n")); + talloc_free(*handle); + *handle = NULL; } ltdb_unlock_read(module); @@ -490,4 +576,33 @@ int ltdb_search_bytree(struct ldb_module *module, const struct ldb_dn *base, return ret; } +/* + search the database with a LDAP-like expression. + choses a search method +*/ +int ltdb_search_bytree(struct ldb_module *module, const struct ldb_dn *base, + enum ldb_scope scope, struct ldb_parse_tree *tree, + const char * const attrs[], struct ldb_result **res) +{ + struct ldb_async_handle *handle; + int ret; + + *res = talloc_zero(module, struct ldb_result); + if (! *res) { + return LDB_ERR_OPERATIONS_ERROR; + } + + ret = ltdb_search_async(module, base, scope, tree, attrs, + res, <db_search_sync_callback, + 0, &handle); + + if (ret != LDB_SUCCESS) + return ret; + + ret = ldb_async_wait(module->ldb, handle, LDB_WAIT_ALL); + + talloc_free(handle); + return ret; +} + -- cgit From 509814bd037a3c73fea4ab92b531c25964f34dfa Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Fri, 3 Mar 2006 20:01:19 +0000 Subject: r13823: make async_wait part of the modules ops (This used to be commit b4202cf030d5f154f0f94f5f501ecd648ba5c48f) --- source4/lib/ldb/ldb_tdb/ldb_search.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index 46f560f817..5ffd45aa3b 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -475,7 +475,7 @@ static int ltdb_search_full(struct ldb_async_handle *handle) static int ltdb_search_sync_callback(struct ldb_context *ldb, void *context, struct ldb_async_result *ares) { - struct ldb_result *res; + struct ldb_result *res = NULL; if (!context) { ldb_set_errstring(ldb, talloc_strdup(ldb, "NULL Context in callback")); -- cgit From 8edf29e8ef4d886321a6e8ec3902065641d34f40 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Fri, 3 Mar 2006 22:52:57 +0000 Subject: r13827: Minor enhancements or cosmetic changes (This used to be commit 7ef63abae12f65835a82f9931ad1f5ea75e5f3f6) --- source4/lib/ldb/ldb_tdb/ldb_search.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index 5ffd45aa3b..5155031055 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -522,7 +522,6 @@ int ltdb_search_async(struct ldb_module *module, const struct ldb_dn *base, const char * const *attrs, void *context, int (*callback)(struct ldb_context *, void *, struct ldb_async_result *), - int timeout, struct ldb_async_handle **handle) { struct ltdb_private *ltdb = talloc_get_type(module->private_data, struct ltdb_private); @@ -547,7 +546,7 @@ int ltdb_search_async(struct ldb_module *module, const struct ldb_dn *base, return LDB_ERR_OPERATIONS_ERROR; } - *handle = init_ltdb_handle(ltdb, module, context, callback, timeout); + *handle = init_ltdb_handle(ltdb, module, context, callback); if (*handle == NULL) { talloc_free(*handle); ltdb_unlock_read(module); @@ -594,14 +593,17 @@ int ltdb_search_bytree(struct ldb_module *module, const struct ldb_dn *base, ret = ltdb_search_async(module, base, scope, tree, attrs, res, <db_search_sync_callback, - 0, &handle); + &handle); - if (ret != LDB_SUCCESS) - return ret; + if (ret == LDB_SUCCESS) { + ret = ldb_async_wait(module->ldb, handle, LDB_WAIT_ALL); + talloc_free(handle); + } - ret = ldb_async_wait(module->ldb, handle, LDB_WAIT_ALL); + if (ret != LDB_SUCCESS) { + talloc_free(*res); + } - talloc_free(handle); return ret; } -- 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/ldb_tdb/ldb_search.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index 5155031055..7e14a3000a 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -596,7 +596,7 @@ int ltdb_search_bytree(struct ldb_module *module, const struct ldb_dn *base, &handle); if (ret == LDB_SUCCESS) { - ret = ldb_async_wait(module->ldb, handle, LDB_WAIT_ALL); + ret = ldb_async_wait(handle, LDB_WAIT_ALL); talloc_free(handle); } -- cgit From 90a5e19e03842b77fd7811965fb2603e552261bc Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sun, 28 May 2006 02:10:44 +0000 Subject: r15913: Error passing in the async code is not in agood shape Start enhancing it and fix some problems with incorrect evalutaion of the codes Implement rdn rename (async only) (This used to be commit 6af1d738b9668d4f0eb6194ac0f84af9e73f8c2e) --- source4/lib/ldb/ldb_tdb/ldb_search.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index 7e14a3000a..0ab1442c2f 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -462,15 +462,12 @@ static int ltdb_search_full(struct ldb_async_handle *handle) ret = tdb_traverse_read(ltdb->tdb, search_func, handle); - handle->state = LDB_ASYNC_DONE; - if (ret == -1) { handle->status = LDB_ERR_OPERATIONS_ERROR; - return handle->status; } - handle->status = LDB_SUCCESS; - return handle->status; + handle->state = LDB_ASYNC_DONE; + return LDB_SUCCESS; } static int ltdb_search_sync_callback(struct ldb_context *ldb, void *context, struct ldb_async_result *ares) @@ -548,7 +545,6 @@ int ltdb_search_async(struct ldb_module *module, const struct ldb_dn *base, *handle = init_ltdb_handle(ltdb, module, context, callback); if (*handle == NULL) { - talloc_free(*handle); ltdb_unlock_read(module); return LDB_ERR_OPERATIONS_ERROR; } @@ -566,13 +562,13 @@ int ltdb_search_async(struct ldb_module *module, const struct ldb_dn *base, } if (ret != LDB_SUCCESS) { ldb_set_errstring(module->ldb, talloc_strdup(module->ldb, "Indexed and full searches both failed!\n")); - talloc_free(*handle); - *handle = NULL; + (*handle)->state = LDB_ASYNC_DONE; + (*handle)->status = ret; } ltdb_unlock_read(module); - return ret; + return LDB_SUCCESS; } /* -- 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/ldb_tdb/ldb_search.c | 59 ++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 26 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index 0ab1442c2f..9b45697098 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -514,19 +514,14 @@ error: return LDB_ERR_OPERATIONS_ERROR; } -int ltdb_search_async(struct ldb_module *module, const struct ldb_dn *base, - enum ldb_scope scope, struct ldb_parse_tree *tree, - const char * const *attrs, - void *context, - int (*callback)(struct ldb_context *, void *, struct ldb_async_result *), - struct ldb_async_handle **handle) +int ltdb_search_async(struct ldb_module *module, struct ldb_request *req) { struct ltdb_private *ltdb = talloc_get_type(module->private_data, struct ltdb_private); struct ltdb_async_context *ltdb_ac; int ret; - if ((base == NULL || base->comp_num == 0) && - (scope == LDB_SCOPE_BASE || scope == LDB_SCOPE_ONELEVEL)) + if ((req->op.search.base == NULL || req->op.search.base->comp_num == 0) && + (req->op.search.scope == LDB_SCOPE_BASE || req->op.search.scope == LDB_SCOPE_ONELEVEL)) return LDB_ERR_OPERATIONS_ERROR; if (ltdb_lock_read(module) != 0) { @@ -538,32 +533,32 @@ int ltdb_search_async(struct ldb_module *module, const struct ldb_dn *base, return LDB_ERR_OPERATIONS_ERROR; } - if (tree == NULL) { + if (req->op.search.tree == NULL) { ltdb_unlock_read(module); return LDB_ERR_OPERATIONS_ERROR; } - *handle = init_ltdb_handle(ltdb, module, context, callback); - if (*handle == NULL) { + req->async.handle = init_ltdb_handle(ltdb, module, req->async.context, req->async.callback); + if (req->async.handle == NULL) { ltdb_unlock_read(module); return LDB_ERR_OPERATIONS_ERROR; } - ltdb_ac = talloc_get_type((*handle)->private_data, struct ltdb_async_context); + ltdb_ac = talloc_get_type(req->async.handle->private_data, struct ltdb_async_context); - ltdb_ac->tree = tree; - ltdb_ac->scope = scope; - ltdb_ac->base = base; - ltdb_ac->attrs = attrs; + ltdb_ac->tree = req->op.search.tree; + ltdb_ac->scope = req->op.search.scope; + ltdb_ac->base = req->op.search.base; + ltdb_ac->attrs = req->op.search.attrs; - ret = ltdb_search_indexed(*handle); + ret = ltdb_search_indexed(req->async.handle); if (ret == -1) { - ret = ltdb_search_full(*handle); + ret = ltdb_search_full(req->async.handle); } if (ret != LDB_SUCCESS) { ldb_set_errstring(module->ldb, talloc_strdup(module->ldb, "Indexed and full searches both failed!\n")); - (*handle)->state = LDB_ASYNC_DONE; - (*handle)->status = ret; + req->async.handle->state = LDB_ASYNC_DONE; + req->async.handle->status = ret; } ltdb_unlock_read(module); @@ -579,7 +574,7 @@ int ltdb_search_bytree(struct ldb_module *module, const struct ldb_dn *base, enum ldb_scope scope, struct ldb_parse_tree *tree, const char * const attrs[], struct ldb_result **res) { - struct ldb_async_handle *handle; + struct ldb_request *req; int ret; *res = talloc_zero(module, struct ldb_result); @@ -587,13 +582,25 @@ int ltdb_search_bytree(struct ldb_module *module, const struct ldb_dn *base, return LDB_ERR_OPERATIONS_ERROR; } - ret = ltdb_search_async(module, base, scope, tree, attrs, - res, <db_search_sync_callback, - &handle); + req = talloc_zero(module, struct ldb_request); + if (! req) { + return LDB_ERR_OPERATIONS_ERROR; + } + + req->operation = LDB_ASYNC_SEARCH; + req->op.search.base = base; + req->op.search.scope = scope; + req->op.search.tree = tree; + req->op.search.attrs = attrs; + req->controls = NULL; + req->async.context = (void *)res; + req->async.callback = ltdb_search_sync_callback; + + ret = ltdb_search_async(module, req); if (ret == LDB_SUCCESS) { - ret = ldb_async_wait(handle, LDB_WAIT_ALL); - talloc_free(handle); + ret = ldb_async_wait(req->async.handle, LDB_WAIT_ALL); + talloc_free(req); } if (ret != LDB_SUCCESS) { -- 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/ldb_tdb/ldb_search.c | 95 ++---------------------------------- 1 file changed, 5 insertions(+), 90 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index 9b45697098..529049e36b 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -470,51 +470,11 @@ static int ltdb_search_full(struct ldb_async_handle *handle) return LDB_SUCCESS; } -static int ltdb_search_sync_callback(struct ldb_context *ldb, void *context, struct ldb_async_result *ares) -{ - struct ldb_result *res = NULL; - - if (!context) { - ldb_set_errstring(ldb, talloc_strdup(ldb, "NULL Context in callback")); - goto error; - } - - res = *((struct ldb_result **)context); - - if (!res || !ares) { - goto error; - } - - if (ares->type == LDB_REPLY_ENTRY) { - res->msgs = talloc_realloc(res, res->msgs, struct ldb_message *, res->count + 2); - if (! res->msgs) { - goto error; - } - - res->msgs[res->count + 1] = NULL; - - res->msgs[res->count] = talloc_steal(res->msgs, ares->message); - if (! res->msgs[res->count]) { - goto error; - } - - res->count++; - } else { - ldb_debug(ldb, LDB_DEBUG_ERROR, "unrecognized async reply in ltdb_search_sync_callback!\n"); - goto error; - } - - talloc_free(ares); - return LDB_SUCCESS; - -error: - if (ares) talloc_free(ares); - if (res) talloc_free(res); - if (context) *((struct ldb_result **)context) = NULL; - return LDB_ERR_OPERATIONS_ERROR; -} - -int ltdb_search_async(struct ldb_module *module, struct ldb_request *req) +/* + search the database with a LDAP-like expression. + choses a search method +*/ +int ltdb_search(struct ldb_module *module, struct ldb_request *req) { struct ltdb_private *ltdb = talloc_get_type(module->private_data, struct ltdb_private); struct ltdb_async_context *ltdb_ac; @@ -566,48 +526,3 @@ int ltdb_search_async(struct ldb_module *module, struct ldb_request *req) return LDB_SUCCESS; } -/* - search the database with a LDAP-like expression. - choses a search method -*/ -int ltdb_search_bytree(struct ldb_module *module, const struct ldb_dn *base, - enum ldb_scope scope, struct ldb_parse_tree *tree, - const char * const attrs[], struct ldb_result **res) -{ - struct ldb_request *req; - int ret; - - *res = talloc_zero(module, struct ldb_result); - if (! *res) { - return LDB_ERR_OPERATIONS_ERROR; - } - - req = talloc_zero(module, struct ldb_request); - if (! req) { - return LDB_ERR_OPERATIONS_ERROR; - } - - req->operation = LDB_ASYNC_SEARCH; - req->op.search.base = base; - req->op.search.scope = scope; - req->op.search.tree = tree; - req->op.search.attrs = attrs; - req->controls = NULL; - req->async.context = (void *)res; - req->async.callback = ltdb_search_sync_callback; - - ret = ltdb_search_async(module, req); - - if (ret == LDB_SUCCESS) { - ret = ldb_async_wait(req->async.handle, LDB_WAIT_ALL); - talloc_free(req); - } - - if (ret != LDB_SUCCESS) { - talloc_free(*res); - } - - return ret; -} - - -- 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/ldb_tdb/ldb_search.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index 529049e36b..62e310ede6 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -378,9 +378,9 @@ int ltdb_filter_attrs(struct ldb_message *msg, const char * const *attrs) */ static int search_func(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, void *state) { - struct ldb_async_handle *handle = talloc_get_type(state, struct ldb_async_handle); - struct ltdb_async_context *ac = talloc_get_type(handle->private_data, struct ltdb_async_context); - struct ldb_async_result *ares = NULL; + struct ldb_handle *handle = talloc_get_type(state, struct ldb_handle); + struct ltdb_context *ac = talloc_get_type(handle->private_data, struct ltdb_context); + struct ldb_reply *ares = NULL; int ret; if (key.dsize < 4 || @@ -388,7 +388,7 @@ static int search_func(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, voi return 0; } - ares = talloc_zero(ac, struct ldb_async_result); + ares = talloc_zero(ac, struct ldb_reply); if (!ares) { handle->status = LDB_ERR_OPERATIONS_ERROR; handle->state = LDB_ASYNC_DONE; @@ -454,9 +454,9 @@ static int search_func(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, voi search the database with a LDAP-like expression. this is the "full search" non-indexed variant */ -static int ltdb_search_full(struct ldb_async_handle *handle) +static int ltdb_search_full(struct ldb_handle *handle) { - struct ltdb_async_context *ac = talloc_get_type(handle->private_data, struct ltdb_async_context); + struct ltdb_context *ac = talloc_get_type(handle->private_data, struct ltdb_context); struct ltdb_private *ltdb = talloc_get_type(ac->module->private_data, struct ltdb_private); int ret; @@ -477,7 +477,7 @@ static int ltdb_search_full(struct ldb_async_handle *handle) int ltdb_search(struct ldb_module *module, struct ldb_request *req) { struct ltdb_private *ltdb = talloc_get_type(module->private_data, struct ltdb_private); - struct ltdb_async_context *ltdb_ac; + struct ltdb_context *ltdb_ac; int ret; if ((req->op.search.base == NULL || req->op.search.base->comp_num == 0) && @@ -504,7 +504,7 @@ int ltdb_search(struct ldb_module *module, struct ldb_request *req) return LDB_ERR_OPERATIONS_ERROR; } - ltdb_ac = talloc_get_type(req->async.handle->private_data, struct ltdb_async_context); + ltdb_ac = talloc_get_type(req->async.handle->private_data, struct ltdb_context); ltdb_ac->tree = req->op.search.tree; ltdb_ac->scope = req->op.search.scope; -- 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/ldb_tdb/ldb_search.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index 62e310ede6..ad6f98ea97 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -498,27 +498,27 @@ int ltdb_search(struct ldb_module *module, struct ldb_request *req) return LDB_ERR_OPERATIONS_ERROR; } - req->async.handle = init_ltdb_handle(ltdb, module, req->async.context, req->async.callback); - if (req->async.handle == NULL) { + req->handle = init_ltdb_handle(ltdb, module, req->context, req->callback); + if (req->handle == NULL) { ltdb_unlock_read(module); return LDB_ERR_OPERATIONS_ERROR; } - ltdb_ac = talloc_get_type(req->async.handle->private_data, struct ltdb_context); + ltdb_ac = talloc_get_type(req->handle->private_data, struct ltdb_context); ltdb_ac->tree = req->op.search.tree; ltdb_ac->scope = req->op.search.scope; ltdb_ac->base = req->op.search.base; ltdb_ac->attrs = req->op.search.attrs; - ret = ltdb_search_indexed(req->async.handle); + ret = ltdb_search_indexed(req->handle); if (ret == -1) { - ret = ltdb_search_full(req->async.handle); + ret = ltdb_search_full(req->handle); } if (ret != LDB_SUCCESS) { ldb_set_errstring(module->ldb, talloc_strdup(module->ldb, "Indexed and full searches both failed!\n")); - req->async.handle->state = LDB_ASYNC_DONE; - req->async.handle->status = ret; + req->handle->state = LDB_ASYNC_DONE; + req->handle->status = ret; } ltdb_unlock_read(module); -- cgit From eb16bc612a5edef2c3eae1a4dd516a71e43b4979 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Wed, 2 Aug 2006 00:01:09 +0000 Subject: r17370: Fix tdb searches, we need to return an LDAP_REPLY_DONE packet when done. Awesome how this didn't break everything around... (This used to be commit 1b3b6176592314e91af9ed911e8a244519dea9aa) --- source4/lib/ldb/ldb_tdb/ldb_search.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index ad6f98ea97..2a3781b2f0 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -478,6 +478,7 @@ int ltdb_search(struct ldb_module *module, struct ldb_request *req) { struct ltdb_private *ltdb = talloc_get_type(module->private_data, struct ltdb_private); struct ltdb_context *ltdb_ac; + struct ldb_reply *ares; int ret; if ((req->op.search.base == NULL || req->op.search.base->comp_num == 0) && @@ -521,6 +522,20 @@ int ltdb_search(struct ldb_module *module, struct ldb_request *req) req->handle->status = ret; } + /* Finally send an LDB_REPLY_DONE packet when searching is finished */ + + ares = talloc_zero(req, struct ldb_reply); + if (!ares) { + ltdb_unlock_read(module); + return LDB_ERR_OPERATIONS_ERROR; + } + + req->handle->state = LDB_ASYNC_DONE; + ares->type = LDB_REPLY_DONE; + + ret = req->callback(module->ldb, req->context, ares); + req->handle->status = ret; + ltdb_unlock_read(module); return LDB_SUCCESS; -- 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/ldb_tdb/ldb_search.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index 2a3781b2f0..6a35595d52 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -517,7 +517,7 @@ int ltdb_search(struct ldb_module *module, struct ldb_request *req) ret = ltdb_search_full(req->handle); } if (ret != LDB_SUCCESS) { - ldb_set_errstring(module->ldb, talloc_strdup(module->ldb, "Indexed and full searches both failed!\n")); + ldb_set_errstring(module->ldb, "Indexed and full searches both failed!\n"); req->handle->state = LDB_ASYNC_DONE; req->handle->status = ret; } -- 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/ldb_tdb/ldb_search.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index 6a35595d52..612ca5c0fe 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -312,7 +312,7 @@ int ltdb_add_attr_results(struct ldb_module *module, (*res) = res2; - (*res)[*count] = talloc_steal(*res, msg2); + (*res)[*count] = talloc_move(*res, msg2); (*res)[(*count)+1] = NULL; (*count)++; -- 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/ldb_tdb/ldb_search.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index 612ca5c0fe..7cdb2b672f 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -312,7 +312,7 @@ int ltdb_add_attr_results(struct ldb_module *module, (*res) = res2; - (*res)[*count] = talloc_move(*res, msg2); + (*res)[*count] = talloc_move(*res, &msg2); (*res)[(*count)+1] = NULL; (*count)++; -- cgit From 1b8e6fa6e9b45eb99ee34fa1a7628598d287c0f9 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 16 Oct 2006 03:15:41 +0000 Subject: r19314: Commit tridge's fixes for a big mem leak in ltdb I introduced when the code has been changed to be async. With the other committed fixes now this works. (This used to be commit 49fc640b5c0398516ac3a9e3f7c55205cd60b1de) --- source4/lib/ldb/ldb_tdb/ldb_search.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index 7cdb2b672f..85b6a123ca 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -499,12 +499,11 @@ int ltdb_search(struct ldb_module *module, struct ldb_request *req) return LDB_ERR_OPERATIONS_ERROR; } - req->handle = init_ltdb_handle(ltdb, module, req->context, req->callback); + req->handle = init_ltdb_handle(ltdb, module, req); if (req->handle == NULL) { ltdb_unlock_read(module); return LDB_ERR_OPERATIONS_ERROR; } - ltdb_ac = talloc_get_type(req->handle->private_data, struct ltdb_context); ltdb_ac->tree = req->op.search.tree; -- cgit From 4b9eee02c4a0c856f16d9f17929e726fb75e051f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 18 Oct 2006 21:45:46 +0000 Subject: r19402: - use the new tdb_lockall_read() to make ldb_search() more efficient, by avoiding chain locks on each tdb_fetch() within the search - use the tdb_get_seqnum() call to avoid re-reading the @BASEINFO record when it hasn't changed. These speed up the LOCAL-DBSPEED test for ldb from 7k ops/sec to a bit over 11k ops/sec (This used to be commit 1347ad254eb8cd12ce22a5a2a37bec0a0ac8dbf1) --- source4/lib/ldb/ldb_tdb/ldb_search.c | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index 85b6a123ca..4b76c437b6 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -248,25 +248,13 @@ int ltdb_search_dn1(struct ldb_module *module, const struct ldb_dn *dn, struct l return 1; } -/* the lock key for search locking. Note that this is not a DN, its - just an arbitrary key to give to tdb. Also note that as we and - using transactions for all write operations and transactions take - care of their own locks, we don't need to do any locking anywhere - other than in ldb_search() */ -#define LDBLOCK "INT_LDBLOCK" - /* lock the database for read - use by ltdb_search */ static int ltdb_lock_read(struct ldb_module *module) { struct ltdb_private *ltdb = module->private_data; - TDB_DATA key; - - key.dptr = discard_const(LDBLOCK); - key.dsize = strlen(LDBLOCK); - - return tdb_chainlock_read(ltdb->tdb, key); + return tdb_lockall_read(ltdb->tdb); } /* @@ -275,12 +263,7 @@ static int ltdb_lock_read(struct ldb_module *module) static int ltdb_unlock_read(struct ldb_module *module) { struct ltdb_private *ltdb = module->private_data; - TDB_DATA key; - - key.dptr = discard_const(LDBLOCK); - key.dsize = strlen(LDBLOCK); - - return tdb_chainunlock_read(ltdb->tdb, key); + return tdb_unlockall_read(ltdb->tdb); } /* -- cgit From b7774527faf095f612eb1de48efacec6bd710a87 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Wed, 1 Nov 2006 23:31:26 +0000 Subject: r19531: Make struct ldb_dn opaque and local to ldb_dn.c (This used to be commit 889fb983ba1cf8a11424a8b3dc3a5ef76e780082) --- source4/lib/ldb/ldb_tdb/ldb_search.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index 4b76c437b6..884eccd362 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -464,7 +464,7 @@ int ltdb_search(struct ldb_module *module, struct ldb_request *req) struct ldb_reply *ares; int ret; - if ((req->op.search.base == NULL || req->op.search.base->comp_num == 0) && + if ((req->op.search.base == NULL || ldb_dn_get_comp_num(req->op.search.base) == 0) && (req->op.search.scope == LDB_SCOPE_BASE || req->op.search.scope == LDB_SCOPE_ONELEVEL)) return LDB_ERR_OPERATIONS_ERROR; -- cgit From 4889eb9f7aae9349e426d0f6d2217adff67eaebd Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Wed, 22 Nov 2006 00:59:34 +0000 Subject: r19831: Big ldb_dn optimization and interfaces enhancement patch This patch changes a lot of the code in ldb_dn.c, and also removes and add a number of manipulation functions around. The aim is to avoid validating a dn if not necessary as the validation code is necessarily slow. This is mainly to speed up internal operations where input is not user generated and so we can assume the DNs need no validation. The code is designed to keep the data as a string if possible. The code is not yet 100% perfect, but pass all the tests so far. A memleak is certainly present, I'll work on that next. Simo. (This used to be commit a580c871d3784602a9cce32d33419e63c8236e63) --- source4/lib/ldb/ldb_tdb/ldb_search.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index 884eccd362..3f04994ce4 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -209,7 +209,7 @@ static struct ldb_message *ltdb_pull_attrs(struct ldb_module *module, return 1 on success, 0 on record-not-found and -1 on error */ -int ltdb_search_dn1(struct ldb_module *module, const struct ldb_dn *dn, struct ldb_message *msg) +int ltdb_search_dn1(struct ldb_module *module, struct ldb_dn *dn, struct ldb_message *msg) { struct ltdb_private *ltdb = module->private_data; int ret; @@ -394,7 +394,7 @@ static int search_func(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, voi } if (!ares->message->dn) { - ares->message->dn = ldb_dn_explode(ares->message, (char *)key.dptr + 3); + ares->message->dn = ldb_dn_new(ares->message, ac->module->ldb, (char *)key.dptr + 3); if (ares->message->dn == NULL) { handle->status = LDB_ERR_OPERATIONS_ERROR; handle->state = LDB_ASYNC_DONE; @@ -464,7 +464,7 @@ int ltdb_search(struct ldb_module *module, struct ldb_request *req) struct ldb_reply *ares; int ret; - if ((req->op.search.base == NULL || ldb_dn_get_comp_num(req->op.search.base) == 0) && + if ((( ! ldb_dn_is_valid(req->op.search.base)) || ldb_dn_is_null(req->op.search.base)) && (req->op.search.scope == LDB_SCOPE_BASE || req->op.search.scope == LDB_SCOPE_ONELEVEL)) return LDB_ERR_OPERATIONS_ERROR; -- cgit From a9e31b33b55a873c2f01db5e348560176adf863d Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Wed, 22 Nov 2006 02:05:19 +0000 Subject: r19832: better prototypes for the linearization functions: - ldb_dn_get_linearized returns a const string - ldb_dn_alloc_linearized allocs astring with the linearized dn (This used to be commit 3929c086d5d0b3f08b1c4f2f3f9602c3f4a9a4bd) --- source4/lib/ldb/ldb_tdb/ldb_search.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index 3f04994ce4..5736b7684b 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -101,7 +101,7 @@ static int msg_add_distinguished_name(struct ldb_message *msg) el.name = "distinguishedName"; el.num_values = 1; el.values = &val; - val.data = (uint8_t *)ldb_dn_linearize(msg, msg->dn); + val.data = (uint8_t *)ldb_dn_alloc_linearized(msg, msg->dn); val.length = strlen((char *)val.data); ret = msg_add_element(msg, &el, 1); -- 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/ldb_tdb/ldb_search.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index 5736b7684b..6890378185 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -123,9 +123,9 @@ static int msg_add_all_elements(struct ldb_module *module, struct ldb_message *r } for (i=0;inum_elements;i++) { - const struct ldb_attrib_handler *h; - h = ldb_attrib_handler(ldb, msg->elements[i].name); - if (h->flags & LDB_ATTR_FLAG_HIDDEN) { + const struct ldb_schema_attribute *a; + a = ldb_schema_attribute_by_name(ldb, msg->elements[i].name); + if (a->flags & LDB_ATTR_FLAG_HIDDEN) { continue; } if (msg_add_element(ret, &msg->elements[i], -- cgit From 9ec83ae25df8e8e55ab1e25de4972ec4d082783b Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 23 Apr 2007 00:36:49 +0000 Subject: r22471: Convert more code to use proper LDB error codes. This is a 1 to 1 convertion, next step is to make this code report an error if the basedn is not used, hopefully avoiding an explicit search on the base object in the most common cases. (This used to be commit 50534c84b4577b2d32565a74a4716088f706bfea) --- source4/lib/ldb/ldb_tdb/ldb_search.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index 6890378185..838f599642 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -207,7 +207,8 @@ static struct ldb_message *ltdb_pull_attrs(struct ldb_module *module, search the database for a single simple dn, returning all attributes in a single message - return 1 on success, 0 on record-not-found and -1 on error + return LDB_ERR_NO_SUCH_OBJECT on record-not-found + and LDB_SUCCESS on success */ int ltdb_search_dn1(struct ldb_module *module, struct ldb_dn *dn, struct ldb_message *msg) { @@ -220,13 +221,13 @@ int ltdb_search_dn1(struct ldb_module *module, struct ldb_dn *dn, struct ldb_mes /* form the key */ tdb_key = ltdb_key(module, dn); if (!tdb_key.dptr) { - return -1; + return LDB_ERR_OPERATIONS_ERROR; } tdb_data = tdb_fetch(ltdb->tdb, tdb_key); talloc_free(tdb_key.dptr); if (!tdb_data.dptr) { - return 0; + return LDB_ERR_NO_SUCH_OBJECT; } msg->num_elements = 0; @@ -235,17 +236,17 @@ int ltdb_search_dn1(struct ldb_module *module, struct ldb_dn *dn, struct ldb_mes ret = ltdb_unpack_data(module, &tdb_data, msg); free(tdb_data.dptr); if (ret == -1) { - return -1; + return LDB_ERR_OPERATIONS_ERROR; } if (!msg->dn) { msg->dn = ldb_dn_copy(msg, dn); } if (!msg->dn) { - return -1; + return LDB_ERR_OPERATIONS_ERROR; } - return 1; + return LDB_SUCCESS; } /* @@ -495,7 +496,7 @@ int ltdb_search(struct ldb_module *module, struct ldb_request *req) ltdb_ac->attrs = req->op.search.attrs; ret = ltdb_search_indexed(req->handle); - if (ret == -1) { + if (ret == LDB_ERR_OPERATIONS_ERROR) { ret = ltdb_search_full(req->handle); } if (ret != LDB_SUCCESS) { -- 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/ldb_tdb/ldb_search.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index 838f599642..419fa9d69b 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -32,10 +32,9 @@ * Author: Andrew Tridgell */ -#include "includes.h" -#include "ldb/include/includes.h" +#include "ldb_includes.h" -#include "ldb/ldb_tdb/ldb_tdb.h" +#include "ldb_tdb.h" /* add one element to a message -- 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/ldb_tdb/ldb_search.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index 419fa9d69b..7e73446b3d 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.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/ldb_tdb/ldb_search.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index 7e73446b3d..013b341d42 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.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 cd962355abad90a2161765a7be7d26e63572cab7 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 7 Sep 2007 15:08:14 +0000 Subject: r25000: Fix some more C++ compatibility warnings. (This used to be commit 08bb1ef643ab906f1645cf6f32763dc73b1884e4) --- source4/lib/ldb/ldb_tdb/ldb_search.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index 013b341d42..a195a39391 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -210,7 +210,7 @@ static struct ldb_message *ltdb_pull_attrs(struct ldb_module *module, */ int ltdb_search_dn1(struct ldb_module *module, struct ldb_dn *dn, struct ldb_message *msg) { - struct ltdb_private *ltdb = module->private_data; + struct ltdb_private *ltdb = (struct ltdb_private *)module->private_data; int ret; TDB_DATA tdb_key, tdb_data; @@ -252,7 +252,7 @@ int ltdb_search_dn1(struct ldb_module *module, struct ldb_dn *dn, struct ldb_mes */ static int ltdb_lock_read(struct ldb_module *module) { - struct ltdb_private *ltdb = module->private_data; + struct ltdb_private *ltdb = (struct ltdb_private *)module->private_data; return tdb_lockall_read(ltdb->tdb); } @@ -261,7 +261,7 @@ static int ltdb_lock_read(struct ldb_module *module) */ static int ltdb_unlock_read(struct ldb_module *module) { - struct ltdb_private *ltdb = module->private_data; + struct ltdb_private *ltdb = (struct ltdb_private *)module->private_data; return tdb_unlockall_read(ltdb->tdb); } -- cgit From 0906096ee4fbca6338863319edb68cfe338fd6a3 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 18 Oct 2007 02:03:21 +0200 Subject: r25690: - only use a readonly traverse in ldb_search when not in a transaction. When we are in a transaction then we could be in a top level modify operation (such as rename), so we must use a writeable traverse so that the async callbacks can do the modifies while the search is progressing. - don't do the lockall operation on the tdb during a ldb search if in a transaction, as this would prevent modifies by callbacks as well (This used to be commit aa9ab431e071882f42ebc882e809ae1d4b8778d4) --- source4/lib/ldb/ldb_tdb/ldb_search.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index a195a39391..8151b458d4 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -253,7 +253,10 @@ int ltdb_search_dn1(struct ldb_module *module, struct ldb_dn *dn, struct ldb_mes static int ltdb_lock_read(struct ldb_module *module) { struct ltdb_private *ltdb = (struct ltdb_private *)module->private_data; - return tdb_lockall_read(ltdb->tdb); + if (ltdb->in_transaction == 0) { + return tdb_lockall_read(ltdb->tdb); + } + return 0; } /* @@ -262,7 +265,10 @@ static int ltdb_lock_read(struct ldb_module *module) static int ltdb_unlock_read(struct ldb_module *module) { struct ltdb_private *ltdb = (struct ltdb_private *)module->private_data; - return tdb_unlockall_read(ltdb->tdb); + if (ltdb->in_transaction == 0) { + return tdb_unlockall_read(ltdb->tdb); + } + return 0; } /* @@ -442,7 +448,11 @@ static int ltdb_search_full(struct ldb_handle *handle) struct ltdb_private *ltdb = talloc_get_type(ac->module->private_data, struct ltdb_private); int ret; - ret = tdb_traverse_read(ltdb->tdb, search_func, handle); + if (ltdb->in_transaction != 0) { + ret = tdb_traverse(ltdb->tdb, search_func, handle); + } else { + ret = tdb_traverse_read(ltdb->tdb, search_func, handle); + } if (ret == -1) { handle->status = LDB_ERR_OPERATIONS_ERROR; -- cgit From d544879e434c36f02bfc7d1322f1179d00294669 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Thu, 15 Nov 2007 01:53:44 +0100 Subject: r25959: Add a new special DN to LDB: @OPTIONS Use the checkBaseOnSearch attribute to control if we should check the base DN on search requests. Also ensure we honour any errors in searching, not just errors in the supplied 'done' callback. Andrew Bartlett (This used to be commit deaac92f439ef001bfe052df170d6e34e8ba5845) --- source4/lib/ldb/ldb_tdb/ldb_search.c | 122 +++++++++++++++++++++++++++++++---- 1 file changed, 110 insertions(+), 12 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index 8151b458d4..1fa20740a5 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -200,6 +200,35 @@ static struct ldb_message *ltdb_pull_attrs(struct ldb_module *module, return ret; } +/* + search the database for a single simple dn. + return LDB_ERR_NO_SUCH_OBJECT on record-not-found + and LDB_SUCCESS on success +*/ +int ltdb_search_base(struct ldb_module *module, struct ldb_dn *dn) +{ + struct ltdb_private *ltdb = (struct ltdb_private *)module->private_data; + TDB_DATA tdb_key, tdb_data; + + if (ldb_dn_is_null(dn)) { + return LDB_ERR_NO_SUCH_OBJECT; + } + + /* form the key */ + tdb_key = ltdb_key(module, dn); + if (!tdb_key.dptr) { + return LDB_ERR_OPERATIONS_ERROR; + } + + tdb_data = tdb_fetch(ltdb->tdb, tdb_key); + talloc_free(tdb_key.dptr); + if (!tdb_data.dptr) { + return LDB_ERR_NO_SUCH_OBJECT; + } + + free(tdb_data.dptr); + return LDB_SUCCESS; +} /* search the database for a single simple dn, returning all attributes @@ -227,7 +256,7 @@ int ltdb_search_dn1(struct ldb_module *module, struct ldb_dn *dn, struct ldb_mes if (!tdb_data.dptr) { return LDB_ERR_NO_SUCH_OBJECT; } - + msg->num_elements = 0; msg->elements = NULL; @@ -473,10 +502,6 @@ int ltdb_search(struct ldb_module *module, struct ldb_request *req) struct ldb_reply *ares; int ret; - if ((( ! ldb_dn_is_valid(req->op.search.base)) || ldb_dn_is_null(req->op.search.base)) && - (req->op.search.scope == LDB_SCOPE_BASE || req->op.search.scope == LDB_SCOPE_ONELEVEL)) - return LDB_ERR_OPERATIONS_ERROR; - if (ltdb_lock_read(module) != 0) { return LDB_ERR_OPERATIONS_ERROR; } @@ -496,6 +521,65 @@ int ltdb_search(struct ldb_module *module, struct ldb_request *req) ltdb_unlock_read(module); return LDB_ERR_OPERATIONS_ERROR; } + + if ((req->op.search.base == NULL) || (ldb_dn_is_null(req->op.search.base) == true)) { + + /* Check what we should do with a NULL dn */ + switch (req->op.search.scope) { + case LDB_SCOPE_BASE: + ldb_asprintf_errstring(module->ldb, + "NULL Base DN invalid for a base search"); + ret = LDB_ERR_INVALID_DN_SYNTAX; + case LDB_SCOPE_ONELEVEL: + ldb_asprintf_errstring(module->ldb, + "NULL Base DN invalid for a one-level search"); + ret = LDB_ERR_INVALID_DN_SYNTAX; + case LDB_SCOPE_SUBTREE: + default: + /* We accept subtree searches from a NULL base DN, ie over the whole DB */ + ret = LDB_SUCCESS; + } + } else if (ldb_dn_is_valid(req->op.search.base) == false) { + + /* We don't want invalid base DNs here */ + ldb_asprintf_errstring(module->ldb, + "Invalid Base DN: %s", + ldb_dn_get_linearized(req->op.search.base)); + ret = LDB_ERR_INVALID_DN_SYNTAX; + + } else if (ldb_dn_is_null(req->op.search.base) == true) { + + /* Check what we should do with a NULL dn */ + switch (req->op.search.scope) { + case LDB_SCOPE_BASE: + ldb_asprintf_errstring(module->ldb, + "NULL Base DN invalid for a base search"); + ret = LDB_ERR_INVALID_DN_SYNTAX; + case LDB_SCOPE_ONELEVEL: + ldb_asprintf_errstring(module->ldb, + "NULL Base DN invalid for a one-level search"); + ret = LDB_ERR_INVALID_DN_SYNTAX; + case LDB_SCOPE_SUBTREE: + default: + /* We accept subtree searches from a NULL base DN, ie over the whole DB */ + ret = LDB_SUCCESS; + } + + } else if (ltdb->check_base) { + /* This database has been marked as 'checkBaseOnSearch', so do a spot check of the base dn */ + ret = ltdb_search_base(module, req->op.search.base); + + if (ret == LDB_ERR_NO_SUCH_OBJECT) { + ldb_asprintf_errstring(module->ldb, + "No such Base DN: %s", + ldb_dn_get_linearized(req->op.search.base)); + } + + } else { + /* If we are not checking the base DN life is easy */ + ret = LDB_SUCCESS; + } + ltdb_ac = talloc_get_type(req->handle->private_data, struct ltdb_context); ltdb_ac->tree = req->op.search.tree; @@ -503,12 +587,23 @@ int ltdb_search(struct ldb_module *module, struct ldb_request *req) ltdb_ac->base = req->op.search.base; ltdb_ac->attrs = req->op.search.attrs; - ret = ltdb_search_indexed(req->handle); - if (ret == LDB_ERR_OPERATIONS_ERROR) { - ret = ltdb_search_full(req->handle); + + if (ret == LDB_SUCCESS) { + ret = ltdb_search_indexed(req->handle); + if (ret == LDB_ERR_NO_SUCH_OBJECT) { + /* Not in the index, therefore OK! */ + ret = LDB_SUCCESS; + + } else if (ret == LDB_ERR_OPERATIONS_ERROR) { + /* Not indexed, so we need to do a full scan */ + ret = ltdb_search_full(req->handle); + if (ret != LDB_SUCCESS) { + ldb_set_errstring(module->ldb, "Indexed and full searches both failed!\n"); + } + } } + if (ret != LDB_SUCCESS) { - ldb_set_errstring(module->ldb, "Indexed and full searches both failed!\n"); req->handle->state = LDB_ASYNC_DONE; req->handle->status = ret; } @@ -522,10 +617,13 @@ int ltdb_search(struct ldb_module *module, struct ldb_request *req) } req->handle->state = LDB_ASYNC_DONE; - ares->type = LDB_REPLY_DONE; - ret = req->callback(module->ldb, req->context, ares); - req->handle->status = ret; + if (ret == LDB_SUCCESS) { + ares->type = LDB_REPLY_DONE; + + ret = req->callback(module->ldb, req->context, ares); + req->handle->status = ret; + } ltdb_unlock_read(module); -- cgit From fab68fd4d954f97cf6b4eae4c5e975e1660b6a28 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Thu, 15 Nov 2007 11:05:22 +0100 Subject: r25965: Remove duplicate block - thanks metze! Andrew Bartlett (This used to be commit d7e65da56454bc7721083e0aa7fa2e9c47f2b79d) --- source4/lib/ldb/ldb_tdb/ldb_search.c | 18 ------------------ 1 file changed, 18 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index 1fa20740a5..bf6bd91fc2 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -547,24 +547,6 @@ int ltdb_search(struct ldb_module *module, struct ldb_request *req) ldb_dn_get_linearized(req->op.search.base)); ret = LDB_ERR_INVALID_DN_SYNTAX; - } else if (ldb_dn_is_null(req->op.search.base) == true) { - - /* Check what we should do with a NULL dn */ - switch (req->op.search.scope) { - case LDB_SCOPE_BASE: - ldb_asprintf_errstring(module->ldb, - "NULL Base DN invalid for a base search"); - ret = LDB_ERR_INVALID_DN_SYNTAX; - case LDB_SCOPE_ONELEVEL: - ldb_asprintf_errstring(module->ldb, - "NULL Base DN invalid for a one-level search"); - ret = LDB_ERR_INVALID_DN_SYNTAX; - case LDB_SCOPE_SUBTREE: - default: - /* We accept subtree searches from a NULL base DN, ie over the whole DB */ - ret = LDB_SUCCESS; - } - } else if (ltdb->check_base) { /* This database has been marked as 'checkBaseOnSearch', so do a spot check of the base dn */ ret = ltdb_search_base(module, req->op.search.base); -- cgit From 37039ea5b0b460b0ac088e1e902a28d2b4135625 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 26 Nov 2007 06:12:01 +0100 Subject: r26131: Ensure we show the right errors in the NULL base DN case. Based on MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit bug 5090 by Matthias Dieter Wallnöfer Andrew Bartlett (This used to be commit cc2d0c9f15a9c687d212df14d8ffb6c60ad15242) --- source4/lib/ldb/ldb_tdb/ldb_search.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source4/lib/ldb/ldb_tdb/ldb_search.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index bf6bd91fc2..da899c361e 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -530,10 +530,12 @@ int ltdb_search(struct ldb_module *module, struct ldb_request *req) ldb_asprintf_errstring(module->ldb, "NULL Base DN invalid for a base search"); ret = LDB_ERR_INVALID_DN_SYNTAX; + break; case LDB_SCOPE_ONELEVEL: ldb_asprintf_errstring(module->ldb, "NULL Base DN invalid for a one-level search"); ret = LDB_ERR_INVALID_DN_SYNTAX; + break; case LDB_SCOPE_SUBTREE: default: /* We accept subtree searches from a NULL base DN, ie over the whole DB */ -- cgit