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_tdb.c | 303 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 303 insertions(+) create mode 100644 source4/lib/ldb/ldb_tdb/ldb_tdb.c (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c new file mode 100644 index 0000000000..17931352f7 --- /dev/null +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -0,0 +1,303 @@ +/* + 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 tdb backend + * + * Description: core functions for tdb backend + * + * Author: Andrew Tridgell + */ + +#include "includes.h" +#include "ldb_tdb/ldb_tdb.h" + +/* + form a TDB_DATA for a record key + caller frees +*/ +struct TDB_DATA ltdb_key(const char *dn) +{ + TDB_DATA key; + char *key_str = NULL; + + asprintf(&key_str, "DN=%s", dn); + if (!key_str) { + errno = ENOMEM; + key.dptr = NULL; + key.dsize = 0; + return key; + } + + key.dptr = key_str; + key.dsize = strlen(key_str)+1; + + return key; +} + + +/* + store a record into the db +*/ +int ltdb_store(struct ldb_context *ldb, const struct ldb_message *msg, int flgs) +{ + struct ltdb_private *ltdb = ldb->private; + TDB_DATA tdb_key, tdb_data; + int ret; + + tdb_key = ltdb_key(msg->dn); + if (!tdb_key.dptr) { + return -1; + } + + ret = ltdb_pack_data(ldb, msg, &tdb_data); + if (ret == -1) { + free(tdb_key.dptr); + return -1; + } + + ret = tdb_store(ltdb->tdb, tdb_key, tdb_data, flgs); + if (ret == -1) { + goto done; + } + + ret = ltdb_index_add(ldb, msg); + if (ret == -1) { + tdb_delete(ltdb->tdb, tdb_key); + } + +done: + free(tdb_key.dptr); + free(tdb_data.dptr); + + return ret; +} + + +/* + add a record to the database +*/ +static int ltdb_add(struct ldb_context *ldb, const struct ldb_message *msg) +{ + return ltdb_store(ldb, msg, TDB_INSERT); +} + + +/* + delete a record from the database, not updating indexes (used for deleting + index records) +*/ +int ltdb_delete_noindex(struct ldb_context *ldb, const char *dn) +{ + struct ltdb_private *ltdb = ldb->private; + TDB_DATA tdb_key; + int ret; + + tdb_key = ltdb_key(dn); + if (!tdb_key.dptr) { + return -1; + } + + ret = tdb_delete(ltdb->tdb, tdb_key); + free(tdb_key.dptr); + + return ret; +} + +/* + delete a record from the database +*/ +static int ltdb_delete(struct ldb_context *ldb, const char *dn) +{ + int ret; + struct ldb_message msg; + + /* in case any attribute of the message was indexed, we need + to fetch the old record */ + ret = ltdb_search_dn1(ldb, dn, &msg); + if (ret != 1) { + /* not finding the old record is an error */ + return -1; + } + + ret = ltdb_delete_noindex(ldb, dn); + if (ret == -1) { + ltdb_search_dn1_free(ldb, &msg); + return -1; + } + + /* remove any indexed attributes */ + ret = ltdb_index_del(ldb, &msg); + + ltdb_search_dn1_free(ldb, &msg); + + return ret; +} + + +/* + modify a record +*/ +static int ltdb_modify(struct ldb_context *ldb, const struct ldb_message *msg) +{ + struct ltdb_private *ltdb = ldb->private; + TDB_DATA tdb_key, tdb_data; + struct ldb_message msg2; + int ret; + + tdb_key = ltdb_key(msg->dn); + if (!tdb_key.dptr) { + return -1; + } + + tdb_data = tdb_fetch(ltdb->tdb, tdb_key); + if (!tdb_data.dptr) { + free(tdb_key.dptr); + return -1; + } + + ret = ltdb_unpack_data(ldb, &tdb_data, &msg2); + if (ret == -1) { + free(tdb_key.dptr); + free(tdb_data.dptr); + return -1; + } + +#if 0 + for (i=0;inum_elements;i++) { + switch (msg->elements[i].flags & LDB_FLAG_MOD_MASK) { + case LDB_FLAG_MOD_ADD: + ret = find_element(&msg2, msg->elements[i].name); + if (ret != -1) { + errno = EEXIST; + goto failed; + } + + } + } + +failed: +#endif + + free(tdb_key.dptr); + free(tdb_data.dptr); + if (msg2.elements) free(msg2.elements); + + return -1; +} + +/* + close database +*/ +static int ltdb_close(struct ldb_context *ldb) +{ + struct ltdb_private *ltdb = ldb->private; + int ret; + ret = tdb_close(ltdb->tdb); + free(ltdb); + free(ldb); + return ret; +} + + +/* + return extended error information +*/ +static const char *ltdb_errstring(struct ldb_context *ldb) +{ + struct ltdb_private *ltdb = ldb->private; + return tdb_errorstr(ltdb->tdb); +} + + +static const struct ldb_backend_ops ltdb_ops = { + ltdb_close, + ltdb_search, + ltdb_search_free, + ltdb_add, + ltdb_modify, + ltdb_delete, + ltdb_errstring +}; + + +/* + connect to the database +*/ +struct ldb_context *ltdb_connect(const char *url, + unsigned int flags, + const char *options[]) +{ + const char *path; + int tdb_flags, open_flags; + struct ltdb_private *ltdb; + TDB_CONTEXT *tdb; + struct ldb_context *ldb; + + /* parse the url */ + if (strncmp(url, "tdb://", 6) != 0) { + errno = EINVAL; + return NULL; + } + + path = url+6; + + tdb_flags = TDB_DEFAULT; + + if (flags & LDB_FLG_RDONLY) { + open_flags = O_RDONLY; + } else { + open_flags = O_CREAT | O_RDWR; + } + + tdb = tdb_open(path, 0, tdb_flags, open_flags, 0666); + if (!tdb) { + return NULL; + } + + ltdb = malloc_p(struct ltdb_private); + if (!ltdb) { + tdb_close(tdb); + errno = ENOMEM; + return NULL; + } + + ltdb->tdb = tdb; + + + ldb = malloc_p(struct ldb_context); + if (!ldb) { + tdb_close(tdb); + free(ltdb); + errno = ENOMEM; + return NULL; + } + + ldb->private = ltdb; + ldb->ops = <db_ops; + + return ldb; +} -- 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_tdb.c | 263 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 251 insertions(+), 12 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 17931352f7..95dce498f1 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -58,6 +58,44 @@ struct TDB_DATA ltdb_key(const char *dn) return key; } +/* + lock the database for write - currently a single lock is used +*/ +static int ltdb_lock(struct ldb_context *ldb) +{ + struct ltdb_private *ltdb = ldb->private; + TDB_DATA key; + int ret; + + key = ltdb_key("LDBLOCK"); + if (!key.dptr) { + return -1; + } + + ret = tdb_chainlock(ltdb->tdb, key); + + free(key.dptr); + + return ret; +} + +/* + unlock the database after a ltdb_lock() +*/ +static void ltdb_unlock(struct ldb_context *ldb) +{ + struct ltdb_private *ltdb = ldb->private; + TDB_DATA key; + + key = ltdb_key("LDBLOCK"); + if (!key.dptr) { + return; + } + + tdb_chainunlock(ltdb->tdb, key); + + free(key.dptr); +} /* store a record into the db @@ -102,7 +140,17 @@ done: */ static int ltdb_add(struct ldb_context *ldb, const struct ldb_message *msg) { - return ltdb_store(ldb, msg, TDB_INSERT); + int ret; + + if (ltdb_lock(ldb) != 0) { + return -1; + } + + ret = ltdb_store(ldb, msg, TDB_INSERT); + + ltdb_unlock(ldb); + + return ret; } @@ -135,18 +183,22 @@ static int ltdb_delete(struct ldb_context *ldb, const char *dn) int ret; struct ldb_message msg; + if (ltdb_lock(ldb) != 0) { + return -1; + } + /* in case any attribute of the message was indexed, we need to fetch the old record */ ret = ltdb_search_dn1(ldb, dn, &msg); if (ret != 1) { /* not finding the old record is an error */ - return -1; + goto failed; } ret = ltdb_delete_noindex(ldb, dn); if (ret == -1) { ltdb_search_dn1_free(ldb, &msg); - return -1; + goto failed; } /* remove any indexed attributes */ @@ -154,57 +206,244 @@ static int ltdb_delete(struct ldb_context *ldb, const char *dn) ltdb_search_dn1_free(ldb, &msg); + ltdb_unlock(ldb); return ret; + +failed: + ltdb_unlock(ldb); + return -1; +} + + +/* + find an element by attribute name. At the moment this does a linear search, it should + be re-coded to use a binary search once all places that modify records guarantee + sorted order + + return the index of the first matching element if found, otherwise -1 +*/ +static int find_element(const struct ldb_message *msg, const char *name) +{ + int i; + for (i=0;inum_elements;i++) { + if (strcmp(msg->elements[i].name, name) == 0) { + return i; + } + } + return -1; +} + + +/* + add an element to an existing record. Assumes a elements array that we + can call re-alloc on, and assumed that we can re-use the data pointers from the + passed in additional values. Use with care! + + returns 0 on success, -1 on failure (and sets errno) +*/ +static int msg_add_element(struct ldb_message *msg, struct ldb_message_element *el) +{ + struct ldb_message_element *e2; + int i; + + e2 = realloc_p(msg->elements, struct ldb_message_element, + msg->num_elements+1); + if (!e2) { + errno = ENOMEM; + return -1; + } + + msg->elements = e2; + + e2 = &msg->elements[msg->num_elements]; + + e2->name = el->name; + e2->flags = el->flags; + e2->values = NULL; + if (el->num_values != 0) { + e2->values = malloc_array_p(struct ldb_val, el->num_values); + if (!e2->values) { + free(e2->name); + errno = ENOMEM; + return -1; + } + } + for (i=0;inum_values;i++) { + e2->values[i] = el->values[i]; + } + e2->num_values = el->num_values; + + msg->num_elements++; + + return 0; +} + +/* + delete all elements having a specified attribute name +*/ +static int msg_delete_attribute(struct ldb_message *msg, const char *name) +{ + int i, count=0; + struct ldb_message_element *el2; + + el2 = malloc_array_p(struct ldb_message_element, msg->num_elements); + if (!el2) { + errno = ENOMEM; + return -1; + } + + for (i=0;inum_elements;i++) { + if (strcmp(msg->elements[i].name, name) != 0) { + el2[count++] = msg->elements[i]; + } else { + if (msg->elements[i].values) free(msg->elements[i].values); + } + } + + msg->num_elements = count; + if (msg->elements) free(msg->elements); + msg->elements = el2; + + return 0; } +/* + delete all elements matching an attribute name/value + + return 0 on success, -1 on failure +*/ +static int msg_delete_element(struct ldb_message *msg, + const char *name, + const struct ldb_val *val) +{ + int i; + struct ldb_message_element *el; + + i = find_element(msg, name); + if (i == -1) { + return -1; + } + + el = &msg->elements[i]; + + for (i=0;inum_values;i++) { + if (ldb_val_equal(&el->values[i], val)) { + if (inum_values-1) { + memmove(&el->values[i], &el->values[i+1], + sizeof(el->values[i])*el->num_values-(i+1)); + } + el->num_values--; + return 0; + } + } + + return -1; +} /* modify a record + + yuck - this is O(n^2). Luckily n is usually small so we probably + get away with it, but if we ever have really large attribute lists + then we'll need to look at this again */ static int ltdb_modify(struct ldb_context *ldb, const struct ldb_message *msg) { struct ltdb_private *ltdb = ldb->private; TDB_DATA tdb_key, tdb_data; struct ldb_message msg2; - int ret; + int ret, i, j; + + if (ltdb_lock(ldb) != 0) { + return -1; + } tdb_key = ltdb_key(msg->dn); if (!tdb_key.dptr) { - return -1; + goto unlock_fail; } tdb_data = tdb_fetch(ltdb->tdb, tdb_key); if (!tdb_data.dptr) { free(tdb_key.dptr); - return -1; + goto unlock_fail; } ret = ltdb_unpack_data(ldb, &tdb_data, &msg2); if (ret == -1) { free(tdb_key.dptr); free(tdb_data.dptr); - return -1; + goto unlock_fail; } -#if 0 + msg2.dn = msg->dn; + for (i=0;inum_elements;i++) { switch (msg->elements[i].flags & LDB_FLAG_MOD_MASK) { + case LDB_FLAG_MOD_ADD: + /* add this element to the message. fail if it + already exists */ ret = find_element(&msg2, msg->elements[i].name); if (ret != -1) { errno = EEXIST; goto failed; } - + if (msg_add_element(&msg2, &msg->elements[i]) != 0) { + goto failed; + } + break; + + case LDB_FLAG_MOD_REPLACE: + /* replace all elements of this attribute name with the elements + listed */ + if (msg_delete_attribute(&msg2, msg->elements[i].name) != 0) { + goto failed; + } + /* add the replacement element */ + if (msg_add_element(&msg2, &msg->elements[i]) != 0) { + goto failed; + } + break; + + case LDB_FLAG_MOD_DELETE: + /* we could be being asked to delete all + values or just some values */ + if (msg->elements[i].num_values == 0) { + if (msg_delete_attribute(&msg2, + msg->elements[i].name) != 0) { + goto failed; + } + break; + } + for (j=0;jelements[i].num_values;j++) { + if (msg_delete_element(&msg2, + msg->elements[i].name, + &msg->elements[i].values[j]) != 0) { + goto failed; + } + } + break; } } -failed: -#endif + /* we've made all the mods - save the modified record back into the database */ + ret = ltdb_store(ldb, &msg2, TDB_MODIFY); + + free(tdb_key.dptr); + free(tdb_data.dptr); + ltdb_unpack_data_free(&msg2); + ltdb_unlock(ldb); + return ret; + +failed: free(tdb_key.dptr); free(tdb_data.dptr); - if (msg2.elements) free(msg2.elements); + ltdb_unpack_data_free(&msg2); + +unlock_fail: + ltdb_unlock(ldb); return -1; } -- 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_tdb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 95dce498f1..ec90eec03f 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -33,7 +33,7 @@ */ #include "includes.h" -#include "ldb_tdb/ldb_tdb.h" +#include "ldb_tdb.h" /* form a TDB_DATA for a record key -- 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_tdb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index ec90eec03f..b28d73cbea 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -33,7 +33,7 @@ */ #include "includes.h" -#include "ldb_tdb.h" +#include "ldb/ldb_tdb/ldb_tdb.h" /* form a TDB_DATA for a record key -- cgit From 07882b5460121c4ed100f9655935501f7cf23856 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 23 Apr 2004 13:05:27 +0000 Subject: r343: added automatic reindexing of the database when the index list changes (This used to be commit a811640ce408373a5c2c0ee2c125bd735d96d5e1) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index b28d73cbea..34cff41794 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -148,6 +148,10 @@ static int ltdb_add(struct ldb_context *ldb, const struct ldb_message *msg) ret = ltdb_store(ldb, msg, TDB_INSERT); + if (strcmp(msg->dn, "@INDEXLIST") == 0) { + ltdb_reindex(ldb); + } + ltdb_unlock(ldb); return ret; @@ -206,6 +210,10 @@ static int ltdb_delete(struct ldb_context *ldb, const char *dn) ltdb_search_dn1_free(ldb, &msg); + if (strcmp(dn, "@INDEXLIST") == 0) { + ltdb_reindex(ldb); + } + ltdb_unlock(ldb); return ret; @@ -430,6 +438,10 @@ static int ltdb_modify(struct ldb_context *ldb, const struct ldb_message *msg) /* we've made all the mods - save the modified record back into the database */ ret = ltdb_store(ldb, &msg2, TDB_MODIFY); + if (strcmp(msg2.dn, "@INDEXLIST") == 0) { + ltdb_reindex(ldb); + } + free(tdb_key.dptr); free(tdb_data.dptr); ltdb_unpack_data_free(&msg2); -- cgit From 888240138203123222c5a983616b524f9325f606 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 27 Apr 2004 07:10:16 +0000 Subject: r373: use a much larger default tdb hash size in ldb (This used to be commit 54f47c45b8f828ad5ddaa630d0c1e673f2c74b7a) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 34cff41794..a4eb83a20e 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -524,7 +524,8 @@ struct ldb_context *ltdb_connect(const char *url, open_flags = O_CREAT | O_RDWR; } - tdb = tdb_open(path, 0, tdb_flags, open_flags, 0666); + /* note that we use quite a large default hash size */ + tdb = tdb_open(path, 10000, tdb_flags, open_flags, 0666); if (!tdb) { return NULL; } -- 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_tdb.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index a4eb83a20e..ff0c0a53b7 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -63,7 +63,7 @@ struct TDB_DATA ltdb_key(const char *dn) */ static int ltdb_lock(struct ldb_context *ldb) { - struct ltdb_private *ltdb = ldb->private; + struct ltdb_private *ltdb = ldb->private_data; TDB_DATA key; int ret; @@ -84,7 +84,7 @@ static int ltdb_lock(struct ldb_context *ldb) */ static void ltdb_unlock(struct ldb_context *ldb) { - struct ltdb_private *ltdb = ldb->private; + struct ltdb_private *ltdb = ldb->private_data; TDB_DATA key; key = ltdb_key("LDBLOCK"); @@ -102,7 +102,7 @@ static void ltdb_unlock(struct ldb_context *ldb) */ int ltdb_store(struct ldb_context *ldb, const struct ldb_message *msg, int flgs) { - struct ltdb_private *ltdb = ldb->private; + struct ltdb_private *ltdb = ldb->private_data; TDB_DATA tdb_key, tdb_data; int ret; @@ -164,7 +164,7 @@ static int ltdb_add(struct ldb_context *ldb, const struct ldb_message *msg) */ int ltdb_delete_noindex(struct ldb_context *ldb, const char *dn) { - struct ltdb_private *ltdb = ldb->private; + struct ltdb_private *ltdb = ldb->private_data; TDB_DATA tdb_key; int ret; @@ -357,7 +357,7 @@ static int msg_delete_element(struct ldb_message *msg, */ static int ltdb_modify(struct ldb_context *ldb, const struct ldb_message *msg) { - struct ltdb_private *ltdb = ldb->private; + struct ltdb_private *ltdb = ldb->private_data; TDB_DATA tdb_key, tdb_data; struct ldb_message msg2; int ret, i, j; @@ -465,7 +465,7 @@ unlock_fail: */ static int ltdb_close(struct ldb_context *ldb) { - struct ltdb_private *ltdb = ldb->private; + struct ltdb_private *ltdb = ldb->private_data; int ret; ret = tdb_close(ltdb->tdb); free(ltdb); @@ -479,7 +479,7 @@ static int ltdb_close(struct ldb_context *ldb) */ static const char *ltdb_errstring(struct ldb_context *ldb) { - struct ltdb_private *ltdb = ldb->private; + struct ltdb_private *ltdb = ldb->private_data; return tdb_errorstr(ltdb->tdb); } @@ -548,7 +548,7 @@ struct ldb_context *ltdb_connect(const char *url, return NULL; } - ldb->private = ltdb; + ldb->private_data = ltdb; ldb->ops = <db_ops; return ldb; -- 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_tdb.c | 186 +++++++++++++++++++++++++++++--------- 1 file changed, 143 insertions(+), 43 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index ff0c0a53b7..eb2decfe31 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -38,24 +38,70 @@ /* form a TDB_DATA for a record key caller frees + + note that the key for a record can depend on whether the + dn refers to a case sensitive index record or not */ -struct TDB_DATA ltdb_key(const char *dn) +struct TDB_DATA ltdb_key(struct ldb_context *ldb, const char *dn) { TDB_DATA key; char *key_str = NULL; + char *dn_folded = NULL; + const char *prefix = LTDB_INDEX ":"; + const char *s; + int flags; + + /* + most DNs are case insensitive. The exception is index DNs for + case sensitive attributes + */ + if (strncmp(dn, prefix, strlen(prefix)) == 0 && + (s = strchr(dn+strlen(prefix), ':'))) { + char *attr_name, *attr_name_folded; + attr_name = strndup(dn+strlen(prefix), (s-(dn+strlen(prefix)))); + if (!attr_name) { + goto failed; + } + flags = ltdb_attribute_flags(ldb, attr_name); + + if (flags & LTDB_FLAG_CASE_INSENSITIVE) { + dn_folded = ldb_casefold(dn); + } else { + attr_name_folded = ldb_casefold(attr_name); + if (!attr_name_folded) { + goto failed; + } + asprintf(&dn_folded, "%s:%s:%s", + prefix, attr_name_folded, + s+1); + free(attr_name_folded); + } + free(attr_name); + } else { + dn_folded = ldb_casefold(dn); + } + + if (!dn_folded) { + goto failed; + } + + asprintf(&key_str, "DN=%s", dn_folded); + free(dn_folded); - asprintf(&key_str, "DN=%s", dn); if (!key_str) { - errno = ENOMEM; - key.dptr = NULL; - key.dsize = 0; - return key; + goto failed; } key.dptr = key_str; key.dsize = strlen(key_str)+1; return key; + +failed: + errno = ENOMEM; + key.dptr = NULL; + key.dsize = 0; + return key; } /* @@ -67,7 +113,7 @@ static int ltdb_lock(struct ldb_context *ldb) TDB_DATA key; int ret; - key = ltdb_key("LDBLOCK"); + key = ltdb_key(ldb, "LDBLOCK"); if (!key.dptr) { return -1; } @@ -87,7 +133,7 @@ static void ltdb_unlock(struct ldb_context *ldb) struct ltdb_private *ltdb = ldb->private_data; TDB_DATA key; - key = ltdb_key("LDBLOCK"); + key = ltdb_key(ldb, "LDBLOCK"); if (!key.dptr) { return; } @@ -97,6 +143,28 @@ static void ltdb_unlock(struct ldb_context *ldb) free(key.dptr); } + +/* + we've made a modification to a dn - possibly reindex and + update sequence number +*/ +static int ltdb_modified(struct ldb_context *ldb, const char *dn) +{ + int ret = 0; + + if (strcmp(dn, LTDB_INDEXLIST) == 0 || + strcmp(dn, LTDB_ATTRIBUTES) == 0) { + ret = ltdb_reindex(ldb); + } + + if (ret == 0 && + strcmp(dn, LTDB_BASEINFO) != 0) { + ret = ltdb_increase_sequence_number(ldb); + } + + return ret; +} + /* store a record into the db */ @@ -106,7 +174,7 @@ int ltdb_store(struct ldb_context *ldb, const struct ldb_message *msg, int flgs) TDB_DATA tdb_key, tdb_data; int ret; - tdb_key = ltdb_key(msg->dn); + tdb_key = ltdb_key(ldb, msg->dn); if (!tdb_key.dptr) { return -1; } @@ -145,15 +213,19 @@ static int ltdb_add(struct ldb_context *ldb, const struct ldb_message *msg) if (ltdb_lock(ldb) != 0) { return -1; } + + if (ltdb_cache_load(ldb) != 0) { + ltdb_unlock(ldb); + return -1; + } ret = ltdb_store(ldb, msg, TDB_INSERT); - if (strcmp(msg->dn, "@INDEXLIST") == 0) { - ltdb_reindex(ldb); + if (ret == 0) { + ltdb_modified(ldb, msg->dn); } ltdb_unlock(ldb); - return ret; } @@ -168,7 +240,7 @@ int ltdb_delete_noindex(struct ldb_context *ldb, const char *dn) TDB_DATA tdb_key; int ret; - tdb_key = ltdb_key(dn); + tdb_key = ltdb_key(ldb, dn); if (!tdb_key.dptr) { return -1; } @@ -191,6 +263,11 @@ static int ltdb_delete(struct ldb_context *ldb, const char *dn) return -1; } + if (ltdb_cache_load(ldb) != 0) { + ltdb_unlock(ldb); + return -1; + } + /* in case any attribute of the message was indexed, we need to fetch the old record */ ret = ltdb_search_dn1(ldb, dn, &msg); @@ -210,8 +287,8 @@ static int ltdb_delete(struct ldb_context *ldb, const char *dn) ltdb_search_dn1_free(ldb, &msg); - if (strcmp(dn, "@INDEXLIST") == 0) { - ltdb_reindex(ldb); + if (ret == 0) { + ltdb_modified(ldb, dn); } ltdb_unlock(ldb); @@ -234,7 +311,7 @@ static int find_element(const struct ldb_message *msg, const char *name) { int i; for (i=0;inum_elements;i++) { - if (strcmp(msg->elements[i].name, name) == 0) { + if (ldb_attr_cmp(msg->elements[i].name, name) == 0) { return i; } } @@ -301,7 +378,7 @@ static int msg_delete_attribute(struct ldb_message *msg, const char *name) } for (i=0;inum_elements;i++) { - if (strcmp(msg->elements[i].name, name) != 0) { + if (ldb_attr_cmp(msg->elements[i].name, name) != 0) { el2[count++] = msg->elements[i]; } else { if (msg->elements[i].values) free(msg->elements[i].values); @@ -320,7 +397,8 @@ static int msg_delete_attribute(struct ldb_message *msg, const char *name) return 0 on success, -1 on failure */ -static int msg_delete_element(struct ldb_message *msg, +static int msg_delete_element(struct ldb_context *ldb, + struct ldb_message *msg, const char *name, const struct ldb_val *val) { @@ -335,7 +413,7 @@ static int msg_delete_element(struct ldb_message *msg, el = &msg->elements[i]; for (i=0;inum_values;i++) { - if (ldb_val_equal(&el->values[i], val)) { + if (ldb_val_equal(ldb, msg->elements[i].name, &el->values[i], val)) { if (inum_values-1) { memmove(&el->values[i], &el->values[i+1], sizeof(el->values[i])*el->num_values-(i+1)); @@ -348,43 +426,42 @@ static int msg_delete_element(struct ldb_message *msg, return -1; } + /* - modify a record + modify a record - internal interface yuck - this is O(n^2). Luckily n is usually small so we probably get away with it, but if we ever have really large attribute lists then we'll need to look at this again */ -static int ltdb_modify(struct ldb_context *ldb, const struct ldb_message *msg) +int ltdb_modify_internal(struct ldb_context *ldb, const struct ldb_message *msg) { struct ltdb_private *ltdb = ldb->private_data; TDB_DATA tdb_key, tdb_data; struct ldb_message msg2; int ret, i, j; - if (ltdb_lock(ldb) != 0) { - return -1; - } - - tdb_key = ltdb_key(msg->dn); + tdb_key = ltdb_key(ldb, msg->dn); if (!tdb_key.dptr) { - goto unlock_fail; + return -1; } tdb_data = tdb_fetch(ltdb->tdb, tdb_key); if (!tdb_data.dptr) { free(tdb_key.dptr); - goto unlock_fail; + return -1; } ret = ltdb_unpack_data(ldb, &tdb_data, &msg2); if (ret == -1) { free(tdb_key.dptr); free(tdb_data.dptr); - goto unlock_fail; + return -1; } - msg2.dn = msg->dn; + if (!msg2.dn) { + msg2.dn = msg->dn; + } for (i=0;inum_elements;i++) { switch (msg->elements[i].flags & LDB_FLAG_MOD_MASK) { @@ -425,9 +502,10 @@ static int ltdb_modify(struct ldb_context *ldb, const struct ldb_message *msg) break; } for (j=0;jelements[i].num_values;j++) { - if (msg_delete_element(&msg2, - msg->elements[i].name, - &msg->elements[i].values[j]) != 0) { + if (msg_delete_element(ldb, + &msg2, + msg->elements[i].name, + &msg->elements[i].values[j]) != 0) { goto failed; } } @@ -438,26 +516,43 @@ static int ltdb_modify(struct ldb_context *ldb, const struct ldb_message *msg) /* we've made all the mods - save the modified record back into the database */ ret = ltdb_store(ldb, &msg2, TDB_MODIFY); - if (strcmp(msg2.dn, "@INDEXLIST") == 0) { - ltdb_reindex(ldb); - } - free(tdb_key.dptr); free(tdb_data.dptr); ltdb_unpack_data_free(&msg2); - ltdb_unlock(ldb); - return ret; failed: free(tdb_key.dptr); free(tdb_data.dptr); ltdb_unpack_data_free(&msg2); + return -1; +} + +/* + modify a record +*/ +static int ltdb_modify(struct ldb_context *ldb, const struct ldb_message *msg) +{ + int ret; + + if (ltdb_lock(ldb) != 0) { + return -1; + } + + if (ltdb_cache_load(ldb) != 0) { + ltdb_unlock(ldb); + return -1; + } + + ret = ltdb_modify_internal(ldb, msg); + + if (ret == 0) { + ltdb_modified(ldb, msg->dn); + } -unlock_fail: ltdb_unlock(ldb); - - return -1; + + return ret; } /* @@ -467,6 +562,9 @@ static int ltdb_close(struct ldb_context *ldb) { struct ltdb_private *ltdb = ldb->private_data; int ret; + + ltdb_cache_free(ldb); + ret = tdb_close(ltdb->tdb); free(ltdb); free(ldb); @@ -538,7 +636,9 @@ struct ldb_context *ltdb_connect(const char *url, } ltdb->tdb = tdb; - + ltdb->sequence_number = 0; + + memset(<db->cache, 0, sizeof(ltdb->cache)); ldb = malloc_p(struct ldb_context); if (!ldb) { -- cgit From b96695ca23f8d1d95ed2e038ea66e6a0580356c3 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 3 May 2004 09:34:18 +0000 Subject: r454: allow a non-URL form of a filename to be used in ldb_connect(). This makes it a little easier to work with the ldb tools (This used to be commit 03df31cef025b2087531579437d6bae1ec36e82f) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index eb2decfe31..92b88e4fb5 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -607,13 +607,16 @@ struct ldb_context *ltdb_connect(const char *url, struct ldb_context *ldb; /* parse the url */ - if (strncmp(url, "tdb://", 6) != 0) { - errno = EINVAL; - return NULL; + if (strchr(url, ':')) { + if (strncmp(url, "tdb://", 6) != 0) { + errno = EINVAL; + return NULL; + } + path = url+6; + } else { + path = url; } - path = url+6; - tdb_flags = TDB_DEFAULT; if (flags & LDB_FLG_RDONLY) { -- cgit From d6f20f8e92bbbf7b8ac5ace83aae15bad8ef8bba Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 4 May 2004 05:58:22 +0000 Subject: r462: added an explanation about the rather complex ltdb_key() function (This used to be commit 894e44022d16d9ff43f421fb15495845710000ab) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 92b88e4fb5..c674f0c27e 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -54,6 +54,15 @@ struct TDB_DATA ltdb_key(struct ldb_context *ldb, const char *dn) /* most DNs are case insensitive. The exception is index DNs for case sensitive attributes + + there are 3 cases dealt with in this code: + + 1) if the dn doesn't start with @INDEX: then uppercase whole dn + 2) if the dn starts with @INDEX:attr and 'attr' is a case insensitive + attribute then uppercase whole dn + 3) if the dn starts with @INDEX:attr and 'attr' is a case sensitive + attribute then uppercase up to the value of the attribute, but + not the value itself */ if (strncmp(dn, prefix, strlen(prefix)) == 0 && (s = strchr(dn+strlen(prefix), ':'))) { -- 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_tdb.c | 106 ++++++++++++++++++++++---------------- 1 file changed, 62 insertions(+), 44 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index c674f0c27e..eb28bc4938 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -67,35 +67,35 @@ struct TDB_DATA ltdb_key(struct ldb_context *ldb, const char *dn) if (strncmp(dn, prefix, strlen(prefix)) == 0 && (s = strchr(dn+strlen(prefix), ':'))) { char *attr_name, *attr_name_folded; - attr_name = strndup(dn+strlen(prefix), (s-(dn+strlen(prefix)))); + attr_name = ldb_strndup(ldb, dn+strlen(prefix), (s-(dn+strlen(prefix)))); if (!attr_name) { goto failed; } flags = ltdb_attribute_flags(ldb, attr_name); if (flags & LTDB_FLAG_CASE_INSENSITIVE) { - dn_folded = ldb_casefold(dn); + dn_folded = ldb_casefold(ldb, dn); } else { - attr_name_folded = ldb_casefold(attr_name); + attr_name_folded = ldb_casefold(ldb, attr_name); if (!attr_name_folded) { goto failed; } - asprintf(&dn_folded, "%s:%s:%s", + ldb_asprintf(ldb, &dn_folded, "%s:%s:%s", prefix, attr_name_folded, s+1); - free(attr_name_folded); + ldb_free(ldb, attr_name_folded); } - free(attr_name); + ldb_free(ldb, attr_name); } else { - dn_folded = ldb_casefold(dn); + dn_folded = ldb_casefold(ldb, dn); } if (!dn_folded) { goto failed; } - asprintf(&key_str, "DN=%s", dn_folded); - free(dn_folded); + ldb_asprintf(ldb, &key_str, "DN=%s", dn_folded); + ldb_free(ldb, dn_folded); if (!key_str) { goto failed; @@ -129,7 +129,7 @@ static int ltdb_lock(struct ldb_context *ldb) ret = tdb_chainlock(ltdb->tdb, key); - free(key.dptr); + ldb_free(ldb, key.dptr); return ret; } @@ -149,7 +149,7 @@ static void ltdb_unlock(struct ldb_context *ldb) tdb_chainunlock(ltdb->tdb, key); - free(key.dptr); + ldb_free(ldb, key.dptr); } @@ -190,7 +190,7 @@ int ltdb_store(struct ldb_context *ldb, const struct ldb_message *msg, int flgs) ret = ltdb_pack_data(ldb, msg, &tdb_data); if (ret == -1) { - free(tdb_key.dptr); + ldb_free(ldb, tdb_key.dptr); return -1; } @@ -205,8 +205,8 @@ int ltdb_store(struct ldb_context *ldb, const struct ldb_message *msg, int flgs) } done: - free(tdb_key.dptr); - free(tdb_data.dptr); + ldb_free(ldb, tdb_key.dptr); + ldb_free(ldb, tdb_data.dptr); return ret; } @@ -217,8 +217,11 @@ done: */ static int ltdb_add(struct ldb_context *ldb, const struct ldb_message *msg) { + struct ltdb_private *ltdb = ldb->private_data; int ret; + ltdb->last_err_string = NULL; + if (ltdb_lock(ldb) != 0) { return -1; } @@ -255,7 +258,7 @@ int ltdb_delete_noindex(struct ldb_context *ldb, const char *dn) } ret = tdb_delete(ltdb->tdb, tdb_key); - free(tdb_key.dptr); + ldb_free(ldb, tdb_key.dptr); return ret; } @@ -265,9 +268,12 @@ int ltdb_delete_noindex(struct ldb_context *ldb, const char *dn) */ static int ltdb_delete(struct ldb_context *ldb, const char *dn) { + struct ltdb_private *ltdb = ldb->private_data; int ret; struct ldb_message msg; + ltdb->last_err_string = NULL; + if (ltdb_lock(ldb) != 0) { return -1; } @@ -335,12 +341,13 @@ static int find_element(const struct ldb_message *msg, const char *name) returns 0 on success, -1 on failure (and sets errno) */ -static int msg_add_element(struct ldb_message *msg, struct ldb_message_element *el) +static int msg_add_element(struct ldb_context *ldb, + struct ldb_message *msg, struct ldb_message_element *el) { struct ldb_message_element *e2; int i; - e2 = realloc_p(msg->elements, struct ldb_message_element, + e2 = ldb_realloc_p(ldb, msg->elements, struct ldb_message_element, msg->num_elements+1); if (!e2) { errno = ENOMEM; @@ -355,7 +362,7 @@ static int msg_add_element(struct ldb_message *msg, struct ldb_message_element * e2->flags = el->flags; e2->values = NULL; if (el->num_values != 0) { - e2->values = malloc_array_p(struct ldb_val, el->num_values); + e2->values = ldb_malloc_array_p(ldb, struct ldb_val, el->num_values); if (!e2->values) { free(e2->name); errno = ENOMEM; @@ -375,12 +382,13 @@ static int msg_add_element(struct ldb_message *msg, struct ldb_message_element * /* delete all elements having a specified attribute name */ -static int msg_delete_attribute(struct ldb_message *msg, const char *name) +static int msg_delete_attribute(struct ldb_context *ldb, + struct ldb_message *msg, const char *name) { int i, count=0; struct ldb_message_element *el2; - el2 = malloc_array_p(struct ldb_message_element, msg->num_elements); + el2 = ldb_malloc_array_p(ldb, struct ldb_message_element, msg->num_elements); if (!el2) { errno = ENOMEM; return -1; @@ -390,12 +398,12 @@ static int msg_delete_attribute(struct ldb_message *msg, const char *name) if (ldb_attr_cmp(msg->elements[i].name, name) != 0) { el2[count++] = msg->elements[i]; } else { - if (msg->elements[i].values) free(msg->elements[i].values); + ldb_free(ldb, msg->elements[i].values); } } msg->num_elements = count; - if (msg->elements) free(msg->elements); + ldb_free(ldb, msg->elements); msg->elements = el2; return 0; @@ -425,7 +433,7 @@ static int msg_delete_element(struct ldb_context *ldb, if (ldb_val_equal(ldb, msg->elements[i].name, &el->values[i], val)) { if (inum_values-1) { memmove(&el->values[i], &el->values[i+1], - sizeof(el->values[i])*el->num_values-(i+1)); + sizeof(el->values[i])*(el->num_values-(i+1))); } el->num_values--; return 0; @@ -463,7 +471,7 @@ int ltdb_modify_internal(struct ldb_context *ldb, const struct ldb_message *msg) ret = ltdb_unpack_data(ldb, &tdb_data, &msg2); if (ret == -1) { - free(tdb_key.dptr); + ldb_free(ldb, tdb_key.dptr); free(tdb_data.dptr); return -1; } @@ -483,7 +491,7 @@ int ltdb_modify_internal(struct ldb_context *ldb, const struct ldb_message *msg) errno = EEXIST; goto failed; } - if (msg_add_element(&msg2, &msg->elements[i]) != 0) { + if (msg_add_element(ldb, &msg2, &msg->elements[i]) != 0) { goto failed; } break; @@ -491,11 +499,11 @@ int ltdb_modify_internal(struct ldb_context *ldb, const struct ldb_message *msg) case LDB_FLAG_MOD_REPLACE: /* replace all elements of this attribute name with the elements listed */ - if (msg_delete_attribute(&msg2, msg->elements[i].name) != 0) { + if (msg_delete_attribute(ldb, &msg2, msg->elements[i].name) != 0) { goto failed; } /* add the replacement element */ - if (msg_add_element(&msg2, &msg->elements[i]) != 0) { + if (msg_add_element(ldb, &msg2, &msg->elements[i]) != 0) { goto failed; } break; @@ -504,8 +512,8 @@ int ltdb_modify_internal(struct ldb_context *ldb, const struct ldb_message *msg) /* we could be being asked to delete all values or just some values */ if (msg->elements[i].num_values == 0) { - if (msg_delete_attribute(&msg2, - msg->elements[i].name) != 0) { + if (msg_delete_attribute(ldb, &msg2, + msg->elements[i].name) != 0) { goto failed; } break; @@ -525,15 +533,15 @@ int ltdb_modify_internal(struct ldb_context *ldb, const struct ldb_message *msg) /* we've made all the mods - save the modified record back into the database */ ret = ltdb_store(ldb, &msg2, TDB_MODIFY); - free(tdb_key.dptr); + ldb_free(ldb, tdb_key.dptr); free(tdb_data.dptr); - ltdb_unpack_data_free(&msg2); + ltdb_unpack_data_free(ldb, &msg2); return ret; failed: - free(tdb_key.dptr); + ldb_free(ldb, tdb_key.dptr); free(tdb_data.dptr); - ltdb_unpack_data_free(&msg2); + ltdb_unpack_data_free(ldb, &msg2); return -1; } @@ -542,8 +550,11 @@ failed: */ static int ltdb_modify(struct ldb_context *ldb, const struct ldb_message *msg) { + struct ltdb_private *ltdb = ldb->private_data; int ret; + ltdb->last_err_string = NULL; + if (ltdb_lock(ldb) != 0) { return -1; } @@ -572,10 +583,13 @@ static int ltdb_close(struct ldb_context *ldb) struct ltdb_private *ltdb = ldb->private_data; int ret; + ltdb->last_err_string = NULL; + ltdb_cache_free(ldb); + ldb_set_alloc(ldb, NULL, NULL); ret = tdb_close(ltdb->tdb); - free(ltdb); + ldb_free(ldb, ltdb); free(ldb); return ret; } @@ -587,6 +601,9 @@ static int ltdb_close(struct ldb_context *ldb) static const char *ltdb_errstring(struct ldb_context *ldb) { struct ltdb_private *ltdb = ldb->private_data; + if (ltdb->last_err_string) { + return ltdb->last_err_string; + } return tdb_errorstr(ltdb->tdb); } @@ -598,7 +615,8 @@ static const struct ldb_backend_ops ltdb_ops = { ltdb_add, ltdb_modify, ltdb_delete, - ltdb_errstring + ltdb_errstring, + ltdb_cache_free }; @@ -615,6 +633,12 @@ struct ldb_context *ltdb_connect(const char *url, TDB_CONTEXT *tdb; struct ldb_context *ldb; + ldb = calloc(1, sizeof(struct ldb_context)); + if (!ldb) { + errno = ENOMEM; + return NULL; + } + /* parse the url */ if (strchr(url, ':')) { if (strncmp(url, "tdb://", 6) != 0) { @@ -637,12 +661,14 @@ struct ldb_context *ltdb_connect(const char *url, /* note that we use quite a large default hash size */ tdb = tdb_open(path, 10000, tdb_flags, open_flags, 0666); if (!tdb) { + free(ldb); return NULL; } - ltdb = malloc_p(struct ltdb_private); + ltdb = ldb_malloc_p(ldb, struct ltdb_private); if (!ltdb) { tdb_close(tdb); + free(ldb); errno = ENOMEM; return NULL; } @@ -652,14 +678,6 @@ struct ldb_context *ltdb_connect(const char *url, memset(<db->cache, 0, sizeof(ltdb->cache)); - ldb = malloc_p(struct ldb_context); - if (!ldb) { - tdb_close(tdb); - free(ltdb); - errno = ENOMEM; - return NULL; - } - ldb->private_data = ltdb; ldb->ops = <db_ops; -- 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_tdb.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index eb28bc4938..09d1618ffc 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -436,10 +436,13 @@ static int msg_delete_element(struct ldb_context *ldb, sizeof(el->values[i])*(el->num_values-(i+1))); } el->num_values--; + if (el->num_values == 0) { + return msg_delete_attribute(ldb, msg, name); + } return 0; } } - + return -1; } @@ -488,7 +491,7 @@ int ltdb_modify_internal(struct ldb_context *ldb, const struct ldb_message *msg) already exists */ ret = find_element(&msg2, msg->elements[i].name); if (ret != -1) { - errno = EEXIST; + ltdb->last_err_string = "Attribute exists"; goto failed; } if (msg_add_element(ldb, &msg2, &msg->elements[i]) != 0) { @@ -500,6 +503,7 @@ int ltdb_modify_internal(struct ldb_context *ldb, const struct ldb_message *msg) /* replace all elements of this attribute name with the elements listed */ if (msg_delete_attribute(ldb, &msg2, msg->elements[i].name) != 0) { + ltdb->last_err_string = "No such attribute"; goto failed; } /* add the replacement element */ @@ -514,6 +518,7 @@ int ltdb_modify_internal(struct ldb_context *ldb, const struct ldb_message *msg) if (msg->elements[i].num_values == 0) { if (msg_delete_attribute(ldb, &msg2, msg->elements[i].name) != 0) { + ltdb->last_err_string = "No such attribute"; goto failed; } break; @@ -523,6 +528,7 @@ int ltdb_modify_internal(struct ldb_context *ldb, const struct ldb_message *msg) &msg2, msg->elements[i].name, &msg->elements[i].values[j]) != 0) { + ltdb->last_err_string = "No such attribute"; goto failed; } } -- cgit From 054453b5849d97bb244e3e45b5d5f92155311f8b Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 22 May 2004 00:52:04 +0000 Subject: r811: make the ldb_modify REPLACE semantics better match LDAP (ie. no error on the attribute not existing and allow an empty replace) (This used to be commit 1418b667d9041430786089713eafee63dd7b4a28) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 09d1618ffc..d60504ff17 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -501,13 +501,12 @@ int ltdb_modify_internal(struct ldb_context *ldb, const struct ldb_message *msg) case LDB_FLAG_MOD_REPLACE: /* replace all elements of this attribute name with the elements - listed */ - if (msg_delete_attribute(ldb, &msg2, msg->elements[i].name) != 0) { - ltdb->last_err_string = "No such attribute"; - goto failed; - } - /* add the replacement element */ - if (msg_add_element(ldb, &msg2, &msg->elements[i]) != 0) { + listed. The attribute not existing is not an error */ + msg_delete_attribute(ldb, &msg2, msg->elements[i].name); + + /* add the replacement element, if not empty */ + if (msg->elements[i].num_values != 0 && + msg_add_element(ldb, &msg2, &msg->elements[i]) != 0) { goto failed; } break; -- 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_tdb.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index d60504ff17..b36c53e100 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -324,7 +324,7 @@ failed: */ static int find_element(const struct ldb_message *msg, const char *name) { - int i; + unsigned int i; for (i=0;inum_elements;i++) { if (ldb_attr_cmp(msg->elements[i].name, name) == 0) { return i; @@ -345,7 +345,7 @@ static int msg_add_element(struct ldb_context *ldb, struct ldb_message *msg, struct ldb_message_element *el) { struct ldb_message_element *e2; - int i; + unsigned int i; e2 = ldb_realloc_p(ldb, msg->elements, struct ldb_message_element, msg->num_elements+1); @@ -385,7 +385,7 @@ static int msg_add_element(struct ldb_context *ldb, static int msg_delete_attribute(struct ldb_context *ldb, struct ldb_message *msg, const char *name) { - int i, count=0; + unsigned int i, count=0; struct ldb_message_element *el2; el2 = ldb_malloc_array_p(ldb, struct ldb_message_element, msg->num_elements); @@ -419,15 +419,16 @@ static int msg_delete_element(struct ldb_context *ldb, const char *name, const struct ldb_val *val) { - int i; + unsigned int i; + int found; struct ldb_message_element *el; - i = find_element(msg, name); - if (i == -1) { + found = find_element(msg, name); + if (found == -1) { return -1; } - el = &msg->elements[i]; + el = &msg->elements[found]; for (i=0;inum_values;i++) { if (ldb_val_equal(ldb, msg->elements[i].name, &el->values[i], val)) { @@ -459,7 +460,8 @@ int ltdb_modify_internal(struct ldb_context *ldb, const struct ldb_message *msg) struct ltdb_private *ltdb = ldb->private_data; TDB_DATA tdb_key, tdb_data; struct ldb_message msg2; - int ret, i, j; + unsigned i, j; + int ret; tdb_key = ltdb_key(ldb, msg->dn); if (!tdb_key.dptr) { -- cgit From 6f47dec36459dda22130ff36f7cdf8b675a28742 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 15 Jul 2004 07:16:15 +0000 Subject: r1511: fixed a free() that should be ldb_free() this might explain the tdb corruption that metze found - it caused heap corruption that affected tdb (This used to be commit 31d55dfb443612a341ff6ade77c6e4477c4fefca) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index b36c53e100..355de21250 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -470,7 +470,7 @@ int ltdb_modify_internal(struct ldb_context *ldb, const struct ldb_message *msg) tdb_data = tdb_fetch(ltdb->tdb, tdb_key); if (!tdb_data.dptr) { - free(tdb_key.dptr); + ldb_free(ldb, tdb_key.dptr); return -1; } -- cgit From 37dc4e9bf757710c30d05ff9cba3c960ce76989a Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 2 Sep 2004 21:55:24 +0000 Subject: r2192: removed an erroneous free() call on an error path (This used to be commit c80d686f59a8b6c53305af1233137c22a26f6750) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 355de21250..e36770f88b 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -364,7 +364,6 @@ static int msg_add_element(struct ldb_context *ldb, if (el->num_values != 0) { e2->values = ldb_malloc_array_p(ldb, struct ldb_val, el->num_values); if (!e2->values) { - free(e2->name); errno = ENOMEM; return -1; } -- cgit From a9bd40549767c19207f3ec520a3e4346beeabef4 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 20 Oct 2004 19:28:02 +0000 Subject: r3093: - implment ldb_rename() and ldbrename - add tests for ldbrename - disable all tests which regenerate the index (this is broken for me...the process hangs, tridge we need to discuss that) - link only the needed stuff to the ldb tools - build ldbtest inside samba metze (This used to be commit 18552f4786c24e0019cc87726ef4c05365fe586e) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 58 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index e36770f88b..934ec68958 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -2,6 +2,8 @@ ldb database library Copyright (C) Andrew Tridgell 2004 + Copyright (C) Stefan Metzmacher 2004 + ** NOTE! The following LGPL license applies to the ldb ** library. This does NOT imply that all of Samba is released @@ -30,6 +32,7 @@ * Description: core functions for tdb backend * * Author: Andrew Tridgell + * Author: Stefan Metzmacher */ #include "includes.h" @@ -581,6 +584,60 @@ static int ltdb_modify(struct ldb_context *ldb, const struct ldb_message *msg) return ret; } +/* + rename a record +*/ +static int ltdb_rename(struct ldb_context *ldb, const char *olddn, const char *newdn) +{ + struct ltdb_private *ltdb = ldb->private_data; + int ret; + struct ldb_message msg; + const char *error_str; + + ltdb->last_err_string = NULL; + + if (ltdb_lock(ldb) != 0) { + return -1; + } + + /* in case any attribute of the message was indexed, we need + to fetch the old record */ + ret = ltdb_search_dn1(ldb, olddn, &msg); + if (ret != 1) { + /* not finding the old record is an error */ + goto failed; + } + + ldb_free(ldb, msg.dn); + msg.dn = ldb_strdup(ldb,newdn); + if (!msg.dn) { + ltdb_search_dn1_free(ldb, &msg); + goto failed; + } + + ret = ltdb_add(ldb, &msg); + if (ret == -1) { + ltdb_search_dn1_free(ldb, &msg); + goto failed; + } + ltdb_search_dn1_free(ldb, &msg); + + ret = ltdb_delete(ldb, olddn); + error_str = ltdb->last_err_string; + if (ret == -1) { + ltdb_delete(ldb, newdn); + } + + ltdb->last_err_string = error_str; + + ltdb_unlock(ldb); + + return ret; +failed: + ltdb_unlock(ldb); + return -1; +} + /* close database */ @@ -621,6 +678,7 @@ static const struct ldb_backend_ops ltdb_ops = { ltdb_add, ltdb_modify, ltdb_delete, + ltdb_rename, ltdb_errstring, ltdb_cache_free }; -- 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_tdb.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 934ec68958..3d136ea014 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -608,7 +608,6 @@ static int ltdb_rename(struct ldb_context *ldb, const char *olddn, const char *n goto failed; } - ldb_free(ldb, msg.dn); msg.dn = ldb_strdup(ldb,newdn); if (!msg.dn) { ltdb_search_dn1_free(ldb, &msg); @@ -617,9 +616,11 @@ static int ltdb_rename(struct ldb_context *ldb, const char *olddn, const char *n ret = ltdb_add(ldb, &msg); if (ret == -1) { + ldb_free(ldb, msg.dn); ltdb_search_dn1_free(ldb, &msg); goto failed; } + ldb_free(ldb, msg.dn); ltdb_search_dn1_free(ldb, &msg); ret = ltdb_delete(ldb, olddn); -- 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_tdb.c | 167 +++++++++++++++++++++----------------- 1 file changed, 93 insertions(+), 74 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 3d136ea014..a2aa5a7aca 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -45,8 +45,9 @@ note that the key for a record can depend on whether the dn refers to a case sensitive index record or not */ -struct TDB_DATA ltdb_key(struct ldb_context *ldb, const char *dn) +struct TDB_DATA ltdb_key(struct ldb_module *module, const char *dn) { + struct ldb_context *ldb = module->ldb; TDB_DATA key; char *key_str = NULL; char *dn_folded = NULL; @@ -74,7 +75,7 @@ struct TDB_DATA ltdb_key(struct ldb_context *ldb, const char *dn) if (!attr_name) { goto failed; } - flags = ltdb_attribute_flags(ldb, attr_name); + flags = ltdb_attribute_flags(module, attr_name); if (flags & LTDB_FLAG_CASE_INSENSITIVE) { dn_folded = ldb_casefold(ldb, dn); @@ -119,13 +120,14 @@ failed: /* lock the database for write - currently a single lock is used */ -static int ltdb_lock(struct ldb_context *ldb) +static int ltdb_lock(struct ldb_module *module) { - struct ltdb_private *ltdb = ldb->private_data; + struct ldb_context *ldb = module->ldb; + struct ltdb_private *ltdb = module->private_data; TDB_DATA key; int ret; - key = ltdb_key(ldb, "LDBLOCK"); + key = ltdb_key(module, "LDBLOCK"); if (!key.dptr) { return -1; } @@ -140,12 +142,13 @@ static int ltdb_lock(struct ldb_context *ldb) /* unlock the database after a ltdb_lock() */ -static void ltdb_unlock(struct ldb_context *ldb) +static void ltdb_unlock(struct ldb_module *module) { - struct ltdb_private *ltdb = ldb->private_data; + struct ldb_context *ldb = module->ldb; + struct ltdb_private *ltdb = module->private_data; TDB_DATA key; - key = ltdb_key(ldb, "LDBLOCK"); + key = ltdb_key(module, "LDBLOCK"); if (!key.dptr) { return; } @@ -160,18 +163,18 @@ static void ltdb_unlock(struct ldb_context *ldb) we've made a modification to a dn - possibly reindex and update sequence number */ -static int ltdb_modified(struct ldb_context *ldb, const char *dn) +static int ltdb_modified(struct ldb_module *module, const char *dn) { int ret = 0; if (strcmp(dn, LTDB_INDEXLIST) == 0 || strcmp(dn, LTDB_ATTRIBUTES) == 0) { - ret = ltdb_reindex(ldb); + ret = ltdb_reindex(module); } if (ret == 0 && strcmp(dn, LTDB_BASEINFO) != 0) { - ret = ltdb_increase_sequence_number(ldb); + ret = ltdb_increase_sequence_number(module); } return ret; @@ -180,13 +183,14 @@ static int ltdb_modified(struct ldb_context *ldb, const char *dn) /* store a record into the db */ -int ltdb_store(struct ldb_context *ldb, const struct ldb_message *msg, int flgs) +int ltdb_store(struct ldb_module *module, const struct ldb_message *msg, int flgs) { - struct ltdb_private *ltdb = ldb->private_data; + struct ldb_context *ldb = module->ldb; + struct ltdb_private *ltdb = module->private_data; TDB_DATA tdb_key, tdb_data; int ret; - tdb_key = ltdb_key(ldb, msg->dn); + tdb_key = ltdb_key(module, msg->dn); if (!tdb_key.dptr) { return -1; } @@ -202,7 +206,7 @@ int ltdb_store(struct ldb_context *ldb, const struct ldb_message *msg, int flgs) goto done; } - ret = ltdb_index_add(ldb, msg); + ret = ltdb_index_add(module, msg); if (ret == -1) { tdb_delete(ltdb->tdb, tdb_key); } @@ -218,29 +222,29 @@ done: /* add a record to the database */ -static int ltdb_add(struct ldb_context *ldb, const struct ldb_message *msg) +static int ltdb_add(struct ldb_module *module, const struct ldb_message *msg) { - struct ltdb_private *ltdb = ldb->private_data; + struct ltdb_private *ltdb = module->private_data; int ret; ltdb->last_err_string = NULL; - if (ltdb_lock(ldb) != 0) { + if (ltdb_lock(module) != 0) { return -1; } - if (ltdb_cache_load(ldb) != 0) { - ltdb_unlock(ldb); + if (ltdb_cache_load(module) != 0) { + ltdb_unlock(module); return -1; } - ret = ltdb_store(ldb, msg, TDB_INSERT); + ret = ltdb_store(module, msg, TDB_INSERT); if (ret == 0) { - ltdb_modified(ldb, msg->dn); + ltdb_modified(module, msg->dn); } - ltdb_unlock(ldb); + ltdb_unlock(module); return ret; } @@ -249,13 +253,14 @@ static int ltdb_add(struct ldb_context *ldb, const struct ldb_message *msg) delete a record from the database, not updating indexes (used for deleting index records) */ -int ltdb_delete_noindex(struct ldb_context *ldb, const char *dn) +int ltdb_delete_noindex(struct ldb_module *module, const char *dn) { - struct ltdb_private *ltdb = ldb->private_data; + struct ldb_context *ldb = module->ldb; + struct ltdb_private *ltdb = module->private_data; TDB_DATA tdb_key; int ret; - tdb_key = ltdb_key(ldb, dn); + tdb_key = ltdb_key(module, dn); if (!tdb_key.dptr) { return -1; } @@ -269,51 +274,51 @@ int ltdb_delete_noindex(struct ldb_context *ldb, const char *dn) /* delete a record from the database */ -static int ltdb_delete(struct ldb_context *ldb, const char *dn) +static int ltdb_delete(struct ldb_module *module, const char *dn) { - struct ltdb_private *ltdb = ldb->private_data; + struct ltdb_private *ltdb = module->private_data; int ret; struct ldb_message msg; ltdb->last_err_string = NULL; - if (ltdb_lock(ldb) != 0) { + if (ltdb_lock(module) != 0) { return -1; } - if (ltdb_cache_load(ldb) != 0) { - ltdb_unlock(ldb); + if (ltdb_cache_load(module) != 0) { + ltdb_unlock(module); return -1; } /* in case any attribute of the message was indexed, we need to fetch the old record */ - ret = ltdb_search_dn1(ldb, dn, &msg); + ret = ltdb_search_dn1(module, dn, &msg); if (ret != 1) { /* not finding the old record is an error */ goto failed; } - ret = ltdb_delete_noindex(ldb, dn); + ret = ltdb_delete_noindex(module, dn); if (ret == -1) { - ltdb_search_dn1_free(ldb, &msg); + ltdb_search_dn1_free(module, &msg); goto failed; } /* remove any indexed attributes */ - ret = ltdb_index_del(ldb, &msg); + ret = ltdb_index_del(module, &msg); - ltdb_search_dn1_free(ldb, &msg); + ltdb_search_dn1_free(module, &msg); if (ret == 0) { - ltdb_modified(ldb, dn); + ltdb_modified(module, dn); } - ltdb_unlock(ldb); + ltdb_unlock(module); return ret; failed: - ltdb_unlock(ldb); + ltdb_unlock(module); return -1; } @@ -416,11 +421,12 @@ static int msg_delete_attribute(struct ldb_context *ldb, return 0 on success, -1 on failure */ -static int msg_delete_element(struct ldb_context *ldb, +static int msg_delete_element(struct ldb_module *module, struct ldb_message *msg, const char *name, const struct ldb_val *val) { + struct ldb_context *ldb = module->ldb; unsigned int i; int found; struct ldb_message_element *el; @@ -433,7 +439,7 @@ static int msg_delete_element(struct ldb_context *ldb, el = &msg->elements[found]; for (i=0;inum_values;i++) { - if (ldb_val_equal(ldb, msg->elements[i].name, &el->values[i], val)) { + if (ldb_val_equal(module, msg->elements[i].name, &el->values[i], val)) { if (inum_values-1) { memmove(&el->values[i], &el->values[i+1], sizeof(el->values[i])*(el->num_values-(i+1))); @@ -457,15 +463,16 @@ static int msg_delete_element(struct ldb_context *ldb, get away with it, but if we ever have really large attribute lists then we'll need to look at this again */ -int ltdb_modify_internal(struct ldb_context *ldb, const struct ldb_message *msg) +int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *msg) { - struct ltdb_private *ltdb = ldb->private_data; + struct ldb_context *ldb = module->ldb; + struct ltdb_private *ltdb = module->private_data; TDB_DATA tdb_key, tdb_data; struct ldb_message msg2; unsigned i, j; int ret; - tdb_key = ltdb_key(ldb, msg->dn); + tdb_key = ltdb_key(module, msg->dn); if (!tdb_key.dptr) { return -1; } @@ -527,7 +534,7 @@ int ltdb_modify_internal(struct ldb_context *ldb, const struct ldb_message *msg) break; } for (j=0;jelements[i].num_values;j++) { - if (msg_delete_element(ldb, + if (msg_delete_element(module, &msg2, msg->elements[i].name, &msg->elements[i].values[j]) != 0) { @@ -540,7 +547,7 @@ int ltdb_modify_internal(struct ldb_context *ldb, const struct ldb_message *msg) } /* we've made all the mods - save the modified record back into the database */ - ret = ltdb_store(ldb, &msg2, TDB_MODIFY); + ret = ltdb_store(module, &msg2, TDB_MODIFY); ldb_free(ldb, tdb_key.dptr); free(tdb_data.dptr); @@ -557,29 +564,29 @@ failed: /* modify a record */ -static int ltdb_modify(struct ldb_context *ldb, const struct ldb_message *msg) +static int ltdb_modify(struct ldb_module *module, const struct ldb_message *msg) { - struct ltdb_private *ltdb = ldb->private_data; + struct ltdb_private *ltdb = module->private_data; int ret; ltdb->last_err_string = NULL; - if (ltdb_lock(ldb) != 0) { + if (ltdb_lock(module) != 0) { return -1; } - if (ltdb_cache_load(ldb) != 0) { - ltdb_unlock(ldb); + if (ltdb_cache_load(module) != 0) { + ltdb_unlock(module); return -1; } - ret = ltdb_modify_internal(ldb, msg); + ret = ltdb_modify_internal(module, msg); if (ret == 0) { - ltdb_modified(ldb, msg->dn); + ltdb_modified(module, msg->dn); } - ltdb_unlock(ldb); + ltdb_unlock(module); return ret; } @@ -587,22 +594,23 @@ static int ltdb_modify(struct ldb_context *ldb, const struct ldb_message *msg) /* rename a record */ -static int ltdb_rename(struct ldb_context *ldb, const char *olddn, const char *newdn) +static int ltdb_rename(struct ldb_module *module, const char *olddn, const char *newdn) { - struct ltdb_private *ltdb = ldb->private_data; + struct ldb_context *ldb = module->ldb; + struct ltdb_private *ltdb = module->private_data; int ret; struct ldb_message msg; const char *error_str; ltdb->last_err_string = NULL; - if (ltdb_lock(ldb) != 0) { + if (ltdb_lock(module) != 0) { return -1; } /* in case any attribute of the message was indexed, we need to fetch the old record */ - ret = ltdb_search_dn1(ldb, olddn, &msg); + ret = ltdb_search_dn1(module, olddn, &msg); if (ret != 1) { /* not finding the old record is an error */ goto failed; @@ -610,46 +618,47 @@ static int ltdb_rename(struct ldb_context *ldb, const char *olddn, const char *n msg.dn = ldb_strdup(ldb,newdn); if (!msg.dn) { - ltdb_search_dn1_free(ldb, &msg); + ltdb_search_dn1_free(module, &msg); goto failed; } - ret = ltdb_add(ldb, &msg); + ret = ltdb_add(module, &msg); if (ret == -1) { ldb_free(ldb, msg.dn); - ltdb_search_dn1_free(ldb, &msg); + ltdb_search_dn1_free(module, &msg); goto failed; } ldb_free(ldb, msg.dn); - ltdb_search_dn1_free(ldb, &msg); + ltdb_search_dn1_free(module, &msg); - ret = ltdb_delete(ldb, olddn); + ret = ltdb_delete(module, olddn); error_str = ltdb->last_err_string; if (ret == -1) { - ltdb_delete(ldb, newdn); + ltdb_delete(module, newdn); } ltdb->last_err_string = error_str; - ltdb_unlock(ldb); + ltdb_unlock(module); return ret; failed: - ltdb_unlock(ldb); + ltdb_unlock(module); return -1; } /* close database */ -static int ltdb_close(struct ldb_context *ldb) +static int ltdb_close(struct ldb_module *module) { - struct ltdb_private *ltdb = ldb->private_data; + struct ldb_context *ldb = module->ldb; + struct ltdb_private *ltdb = module->private_data; int ret; ltdb->last_err_string = NULL; - ltdb_cache_free(ldb); + ltdb_cache_free(module); ldb_set_alloc(ldb, NULL, NULL); ret = tdb_close(ltdb->tdb); @@ -662,9 +671,9 @@ static int ltdb_close(struct ldb_context *ldb) /* return extended error information */ -static const char *ltdb_errstring(struct ldb_context *ldb) +static const char *ltdb_errstring(struct ldb_module *module) { - struct ltdb_private *ltdb = ldb->private_data; + struct ltdb_private *ltdb = module->private_data; if (ltdb->last_err_string) { return ltdb->last_err_string; } @@ -672,7 +681,8 @@ static const char *ltdb_errstring(struct ldb_context *ldb) } -static const struct ldb_backend_ops ltdb_ops = { +static const struct ldb_module_ops ltdb_ops = { + "tdb", ltdb_close, ltdb_search, ltdb_search_free, @@ -743,8 +753,17 @@ struct ldb_context *ltdb_connect(const char *url, memset(<db->cache, 0, sizeof(ltdb->cache)); - ldb->private_data = ltdb; - ldb->ops = <db_ops; + ldb->modules = ldb_malloc_p(ldb, struct ldb_module); + if (!ldb->modules) { + tdb_close(tdb); + free(ldb); + errno = ENOMEM; + return NULL; + } + ldb->modules->ldb = ldb; + ldb->modules->prev = ldb->modules->next = NULL; + ldb->modules->private_data = ltdb; + ldb->modules->ops = <db_ops; return ldb; } -- 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_tdb.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index a2aa5a7aca..5f6af43f94 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -36,6 +36,8 @@ */ #include "includes.h" +#include "ldb/include/ldb.h" +#include "ldb/include/ldb_private.h" #include "ldb/ldb_tdb/ldb_tdb.h" /* @@ -195,7 +197,7 @@ int ltdb_store(struct ldb_module *module, const struct ldb_message *msg, int flg return -1; } - ret = ltdb_pack_data(ldb, msg, &tdb_data); + ret = ltdb_pack_data(module, msg, &tdb_data); if (ret == -1) { ldb_free(ldb, tdb_key.dptr); return -1; @@ -439,7 +441,7 @@ static int msg_delete_element(struct ldb_module *module, el = &msg->elements[found]; for (i=0;inum_values;i++) { - if (ldb_val_equal(module, msg->elements[i].name, &el->values[i], val)) { + if (ltdb_val_equal(module, msg->elements[i].name, &el->values[i], val)) { if (inum_values-1) { memmove(&el->values[i], &el->values[i+1], sizeof(el->values[i])*(el->num_values-(i+1))); @@ -483,7 +485,7 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms return -1; } - ret = ltdb_unpack_data(ldb, &tdb_data, &msg2); + ret = ltdb_unpack_data(module, &tdb_data, &msg2); if (ret == -1) { ldb_free(ldb, tdb_key.dptr); free(tdb_data.dptr); @@ -551,13 +553,13 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms ldb_free(ldb, tdb_key.dptr); free(tdb_data.dptr); - ltdb_unpack_data_free(ldb, &msg2); + ltdb_unpack_data_free(module, &msg2); return ret; failed: ldb_free(ldb, tdb_key.dptr); free(tdb_data.dptr); - ltdb_unpack_data_free(ldb, &msg2); + ltdb_unpack_data_free(module, &msg2); return -1; } -- cgit From a4de8cd6a5a882a8d49fdb4b0e625ffdc6b401bb Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sun, 21 Nov 2004 15:51:54 +0000 Subject: r3897: add a locking infrastructure (This used to be commit a99c0adb09e2bc77b876d23cb2d0711ccffd83ca) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 50 +++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 18 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 5f6af43f94..4049900a23 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -40,6 +40,8 @@ #include "ldb/include/ldb_private.h" #include "ldb/ldb_tdb/ldb_tdb.h" +#define LDBLOCK "INT_LDBLOCK" + /* form a TDB_DATA for a record key caller frees @@ -122,14 +124,18 @@ failed: /* lock the database for write - currently a single lock is used */ -static int ltdb_lock(struct ldb_module *module) +static int ltdb_lock(struct ldb_module *module, const char *lockname) { struct ldb_context *ldb = module->ldb; struct ltdb_private *ltdb = module->private_data; TDB_DATA key; int ret; - key = ltdb_key(module, "LDBLOCK"); + if (lockname == NULL) { + return -1; + } + + key = ltdb_key(module, lockname); if (!key.dptr) { return -1; } @@ -144,20 +150,26 @@ static int ltdb_lock(struct ldb_module *module) /* unlock the database after a ltdb_lock() */ -static void ltdb_unlock(struct ldb_module *module) +static int ltdb_unlock(struct ldb_module *module, const char *lockname) { struct ldb_context *ldb = module->ldb; struct ltdb_private *ltdb = module->private_data; TDB_DATA key; - key = ltdb_key(module, "LDBLOCK"); + if (lockname == NULL) { + return -1; + } + + key = ltdb_key(module, lockname); if (!key.dptr) { - return; + return -1; } tdb_chainunlock(ltdb->tdb, key); ldb_free(ldb, key.dptr); + + return 0; } @@ -231,12 +243,12 @@ static int ltdb_add(struct ldb_module *module, const struct ldb_message *msg) ltdb->last_err_string = NULL; - if (ltdb_lock(module) != 0) { + if (ltdb_lock(module, LDBLOCK) != 0) { return -1; } if (ltdb_cache_load(module) != 0) { - ltdb_unlock(module); + ltdb_unlock(module, LDBLOCK); return -1; } @@ -246,7 +258,7 @@ static int ltdb_add(struct ldb_module *module, const struct ldb_message *msg) ltdb_modified(module, msg->dn); } - ltdb_unlock(module); + ltdb_unlock(module, LDBLOCK); return ret; } @@ -284,12 +296,12 @@ static int ltdb_delete(struct ldb_module *module, const char *dn) ltdb->last_err_string = NULL; - if (ltdb_lock(module) != 0) { + if (ltdb_lock(module, LDBLOCK) != 0) { return -1; } if (ltdb_cache_load(module) != 0) { - ltdb_unlock(module); + ltdb_unlock(module, LDBLOCK); return -1; } @@ -316,11 +328,11 @@ static int ltdb_delete(struct ldb_module *module, const char *dn) ltdb_modified(module, dn); } - ltdb_unlock(module); + ltdb_unlock(module, LDBLOCK); return ret; failed: - ltdb_unlock(module); + ltdb_unlock(module, LDBLOCK); return -1; } @@ -573,12 +585,12 @@ static int ltdb_modify(struct ldb_module *module, const struct ldb_message *msg) ltdb->last_err_string = NULL; - if (ltdb_lock(module) != 0) { + if (ltdb_lock(module, LDBLOCK) != 0) { return -1; } if (ltdb_cache_load(module) != 0) { - ltdb_unlock(module); + ltdb_unlock(module, LDBLOCK); return -1; } @@ -588,7 +600,7 @@ static int ltdb_modify(struct ldb_module *module, const struct ldb_message *msg) ltdb_modified(module, msg->dn); } - ltdb_unlock(module); + ltdb_unlock(module, LDBLOCK); return ret; } @@ -606,7 +618,7 @@ static int ltdb_rename(struct ldb_module *module, const char *olddn, const char ltdb->last_err_string = NULL; - if (ltdb_lock(module) != 0) { + if (ltdb_lock(module, LDBLOCK) != 0) { return -1; } @@ -641,11 +653,11 @@ static int ltdb_rename(struct ldb_module *module, const char *olddn, const char ltdb->last_err_string = error_str; - ltdb_unlock(module); + ltdb_unlock(module, LDBLOCK); return ret; failed: - ltdb_unlock(module); + ltdb_unlock(module, LDBLOCK); return -1; } @@ -692,6 +704,8 @@ static const struct ldb_module_ops ltdb_ops = { ltdb_modify, ltdb_delete, ltdb_rename, + ltdb_lock, + ltdb_unlock, ltdb_errstring, ltdb_cache_free }; -- cgit From a42dba94d0d6d8203d845f771817d4e48b8c5205 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 6 Dec 2004 06:45:51 +0000 Subject: r4071: - ldap does allow adding additional attribute values with a modify operation, but not if the value already exists - fixed syntax of test.ldif for ldap backend (This used to be commit 29225d0bec39038e42e68849bd9378898f062081) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 4049900a23..6623fd0052 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -516,8 +516,13 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms already exists */ ret = find_element(&msg2, msg->elements[i].name); if (ret != -1) { - ltdb->last_err_string = "Attribute exists"; - goto failed; + for (j=0;jelements[i].num_values;j++) { + if (ldb_msg_find_val(&msg2.elements[ret], + &msg->elements[i].values[j])) { + ltdb->last_err_string = "Type or value exists"; + goto failed; + } + } } if (msg_add_element(ldb, &msg2, &msg->elements[i]) != 0) { goto failed; -- cgit From cf4298874c01644eaedb8f80eec131ec5a220e08 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 19 Dec 2004 10:56:29 +0000 Subject: r4281: fixed an ldb indexing bug in ldb found by volker. index entries were not always being removed on modify (This used to be commit 9c668e7b43dc2d82d3d639b64c53e887723ccba7) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 6623fd0052..5bceab0f13 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -403,10 +403,11 @@ static int msg_add_element(struct ldb_context *ldb, /* delete all elements having a specified attribute name */ -static int msg_delete_attribute(struct ldb_context *ldb, +static int msg_delete_attribute(struct ldb_module *module, + struct ldb_context *ldb, struct ldb_message *msg, const char *name) { - unsigned int i, count=0; + unsigned int i, j, count=0; struct ldb_message_element *el2; el2 = ldb_malloc_array_p(ldb, struct ldb_message_element, msg->num_elements); @@ -419,6 +420,9 @@ static int msg_delete_attribute(struct ldb_context *ldb, if (ldb_attr_cmp(msg->elements[i].name, name) != 0) { el2[count++] = msg->elements[i]; } else { + for (j=0;jelements[i].num_values;j++) { + ltdb_index_del_value(module, msg->dn, &msg->elements[i], j); + } ldb_free(ldb, msg->elements[i].values); } } @@ -460,7 +464,7 @@ static int msg_delete_element(struct ldb_module *module, } el->num_values--; if (el->num_values == 0) { - return msg_delete_attribute(ldb, msg, name); + return msg_delete_attribute(module, ldb, msg, name); } return 0; } @@ -532,7 +536,7 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms case LDB_FLAG_MOD_REPLACE: /* replace all elements of this attribute name with the elements listed. The attribute not existing is not an error */ - msg_delete_attribute(ldb, &msg2, msg->elements[i].name); + msg_delete_attribute(module, ldb, &msg2, msg->elements[i].name); /* add the replacement element, if not empty */ if (msg->elements[i].num_values != 0 && @@ -545,7 +549,7 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms /* we could be being asked to delete all values or just some values */ if (msg->elements[i].num_values == 0) { - if (msg_delete_attribute(ldb, &msg2, + if (msg_delete_attribute(module, ldb, &msg2, msg->elements[i].name) != 0) { ltdb->last_err_string = "No such attribute"; goto failed; @@ -560,6 +564,9 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms ltdb->last_err_string = "No such attribute"; goto failed; } + if (ltdb_index_del_value(module, msg->dn, &msg->elements[i], j) != 0) { + goto failed; + } } break; } -- cgit From b29b10e48ee351c19cb7a0e9766718fa1715f747 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 26 Dec 2004 17:30:27 +0000 Subject: r4366: Fix ldb_modify_internal: Adding values to an existing attribute you could end up with a corrupt data structure on disk, namely with two attribute structures for the same attribute name. Volker (This used to be commit 284044b5b20102894a8128f84ab41d59cfcc9285) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 45 +++++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 9 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 5bceab0f13..179b205097 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -513,24 +513,51 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms } for (i=0;inum_elements;i++) { + struct ldb_message_element *el = &msg->elements[i]; + struct ldb_message_element *el2; + struct ldb_val *vals; + switch (msg->elements[i].flags & LDB_FLAG_MOD_MASK) { case LDB_FLAG_MOD_ADD: /* add this element to the message. fail if it already exists */ - ret = find_element(&msg2, msg->elements[i].name); - if (ret != -1) { - for (j=0;jelements[i].num_values;j++) { - if (ldb_msg_find_val(&msg2.elements[ret], - &msg->elements[i].values[j])) { - ltdb->last_err_string = "Type or value exists"; - goto failed; - } + ret = find_element(&msg2, el->name); + + if (ret == -1) { + if (msg_add_element(ldb, &msg2, el) != 0) { + goto failed; + } + continue; + } + + el2 = &msg2.elements[ret]; + + /* An attribute with this name already exists, add all + * values if they don't already exist. */ + + for (j=0;jnum_values;j++) { + if (ldb_msg_find_val(el2, &el->values[j])) { + ltdb->last_err_string = + "Type or value exists"; + goto failed; } } - if (msg_add_element(ldb, &msg2, &msg->elements[i]) != 0) { + + vals = ldb_realloc_p(ldb, el2->values, struct ldb_val, + el2->num_values + el->num_values); + + if (vals == NULL) goto failed; + + for (j=0;jnum_values;j++) { + vals[el2->num_values + j] = + ldb_val_dup(ldb, &el->values[j]); } + + el2->values = vals; + el2->num_values += el->num_values; + break; case LDB_FLAG_MOD_REPLACE: -- 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_tdb.c | 200 +++++++++++++++++++------------------- 1 file changed, 101 insertions(+), 99 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 179b205097..288633cb01 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -75,7 +75,7 @@ struct TDB_DATA ltdb_key(struct ldb_module *module, const char *dn) if (strncmp(dn, prefix, strlen(prefix)) == 0 && (s = strchr(dn+strlen(prefix), ':'))) { char *attr_name, *attr_name_folded; - attr_name = ldb_strndup(ldb, dn+strlen(prefix), (s-(dn+strlen(prefix)))); + attr_name = talloc_strndup(ldb, dn+strlen(prefix), (s-(dn+strlen(prefix)))); if (!attr_name) { goto failed; } @@ -88,12 +88,12 @@ struct TDB_DATA ltdb_key(struct ldb_module *module, const char *dn) if (!attr_name_folded) { goto failed; } - ldb_asprintf(ldb, &dn_folded, "%s:%s:%s", - prefix, attr_name_folded, - s+1); - ldb_free(ldb, attr_name_folded); + dn_folded = talloc_asprintf(ldb, "%s:%s:%s", + prefix, attr_name_folded, + s+1); + talloc_free(attr_name_folded); } - ldb_free(ldb, attr_name); + talloc_free(attr_name); } else { dn_folded = ldb_casefold(ldb, dn); } @@ -102,8 +102,8 @@ struct TDB_DATA ltdb_key(struct ldb_module *module, const char *dn) goto failed; } - ldb_asprintf(ldb, &key_str, "DN=%s", dn_folded); - ldb_free(ldb, dn_folded); + key_str = talloc_asprintf(ldb, "DN=%s", dn_folded); + talloc_free(dn_folded); if (!key_str) { goto failed; @@ -126,7 +126,6 @@ failed: */ static int ltdb_lock(struct ldb_module *module, const char *lockname) { - struct ldb_context *ldb = module->ldb; struct ltdb_private *ltdb = module->private_data; TDB_DATA key; int ret; @@ -142,7 +141,7 @@ static int ltdb_lock(struct ldb_module *module, const char *lockname) ret = tdb_chainlock(ltdb->tdb, key); - ldb_free(ldb, key.dptr); + talloc_free(key.dptr); return ret; } @@ -152,7 +151,6 @@ static int ltdb_lock(struct ldb_module *module, const char *lockname) */ static int ltdb_unlock(struct ldb_module *module, const char *lockname) { - struct ldb_context *ldb = module->ldb; struct ltdb_private *ltdb = module->private_data; TDB_DATA key; @@ -167,7 +165,7 @@ static int ltdb_unlock(struct ldb_module *module, const char *lockname) tdb_chainunlock(ltdb->tdb, key); - ldb_free(ldb, key.dptr); + talloc_free(key.dptr); return 0; } @@ -199,7 +197,6 @@ static int ltdb_modified(struct ldb_module *module, const char *dn) */ int ltdb_store(struct ldb_module *module, const struct ldb_message *msg, int flgs) { - struct ldb_context *ldb = module->ldb; struct ltdb_private *ltdb = module->private_data; TDB_DATA tdb_key, tdb_data; int ret; @@ -211,7 +208,7 @@ int ltdb_store(struct ldb_module *module, const struct ldb_message *msg, int flg ret = ltdb_pack_data(module, msg, &tdb_data); if (ret == -1) { - ldb_free(ldb, tdb_key.dptr); + talloc_free(tdb_key.dptr); return -1; } @@ -226,8 +223,8 @@ int ltdb_store(struct ldb_module *module, const struct ldb_message *msg, int flg } done: - ldb_free(ldb, tdb_key.dptr); - ldb_free(ldb, tdb_data.dptr); + talloc_free(tdb_key.dptr); + talloc_free(tdb_data.dptr); return ret; } @@ -269,7 +266,6 @@ static int ltdb_add(struct ldb_module *module, const struct ldb_message *msg) */ int ltdb_delete_noindex(struct ldb_module *module, const char *dn) { - struct ldb_context *ldb = module->ldb; struct ltdb_private *ltdb = module->private_data; TDB_DATA tdb_key; int ret; @@ -280,7 +276,7 @@ int ltdb_delete_noindex(struct ldb_module *module, const char *dn) } ret = tdb_delete(ltdb->tdb, tdb_key); - ldb_free(ldb, tdb_key.dptr); + talloc_free(tdb_key.dptr); return ret; } @@ -292,7 +288,7 @@ static int ltdb_delete(struct ldb_module *module, const char *dn) { struct ltdb_private *ltdb = module->private_data; int ret; - struct ldb_message msg; + struct ldb_message *msg = NULL; ltdb->last_err_string = NULL; @@ -301,13 +297,17 @@ static int ltdb_delete(struct ldb_module *module, const char *dn) } if (ltdb_cache_load(module) != 0) { - ltdb_unlock(module, LDBLOCK); - return -1; + goto failed; + } + + msg = talloc_p(module, struct ldb_message); + if (msg == NULL) { + goto failed; } /* in case any attribute of the message was indexed, we need to fetch the old record */ - ret = ltdb_search_dn1(module, dn, &msg); + ret = ltdb_search_dn1(module, dn, msg); if (ret != 1) { /* not finding the old record is an error */ goto failed; @@ -315,23 +315,22 @@ static int ltdb_delete(struct ldb_module *module, const char *dn) ret = ltdb_delete_noindex(module, dn); if (ret == -1) { - ltdb_search_dn1_free(module, &msg); goto failed; } /* remove any indexed attributes */ - ret = ltdb_index_del(module, &msg); - - ltdb_search_dn1_free(module, &msg); + ret = ltdb_index_del(module, msg); if (ret == 0) { ltdb_modified(module, dn); } + talloc_free(msg); ltdb_unlock(module, LDBLOCK); return ret; failed: + talloc_free(msg); ltdb_unlock(module, LDBLOCK); return -1; } @@ -369,8 +368,8 @@ static int msg_add_element(struct ldb_context *ldb, struct ldb_message_element *e2; unsigned int i; - e2 = ldb_realloc_p(ldb, msg->elements, struct ldb_message_element, - msg->num_elements+1); + e2 = talloc_realloc_p(msg, msg->elements, struct ldb_message_element, + msg->num_elements+1); if (!e2) { errno = ENOMEM; return -1; @@ -384,7 +383,7 @@ static int msg_add_element(struct ldb_context *ldb, e2->flags = el->flags; e2->values = NULL; if (el->num_values != 0) { - e2->values = ldb_malloc_array_p(ldb, struct ldb_val, el->num_values); + e2->values = talloc_array_p(msg->elements, struct ldb_val, el->num_values); if (!e2->values) { errno = ENOMEM; return -1; @@ -407,30 +406,28 @@ static int msg_delete_attribute(struct ldb_module *module, struct ldb_context *ldb, struct ldb_message *msg, const char *name) { - unsigned int i, j, count=0; - struct ldb_message_element *el2; - - el2 = ldb_malloc_array_p(ldb, struct ldb_message_element, msg->num_elements); - if (!el2) { - errno = ENOMEM; - return -1; - } + unsigned int i, j; for (i=0;inum_elements;i++) { - if (ldb_attr_cmp(msg->elements[i].name, name) != 0) { - el2[count++] = msg->elements[i]; - } else { + if (ldb_attr_cmp(msg->elements[i].name, name) == 0) { for (j=0;jelements[i].num_values;j++) { ltdb_index_del_value(module, msg->dn, &msg->elements[i], j); } - ldb_free(ldb, msg->elements[i].values); + talloc_free(msg->elements[i].values); + if (msg->num_elements > (i+1)) { + memmove(&msg->elements[i], + &msg->elements[i+1], + sizeof(struct ldb_message_element)* + (msg->num_elements - (i+1))); + } + msg->num_elements--; + i--; + msg->elements = talloc_realloc_p(msg, msg->elements, + struct ldb_message_element, + msg->num_elements); } } - msg->num_elements = count; - ldb_free(ldb, msg->elements); - msg->elements = el2; - return 0; } @@ -486,7 +483,7 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms struct ldb_context *ldb = module->ldb; struct ltdb_private *ltdb = module->private_data; TDB_DATA tdb_key, tdb_data; - struct ldb_message msg2; + struct ldb_message *msg2; unsigned i, j; int ret; @@ -497,19 +494,25 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms tdb_data = tdb_fetch(ltdb->tdb, tdb_key); if (!tdb_data.dptr) { - ldb_free(ldb, tdb_key.dptr); + talloc_free(tdb_key.dptr); + return -1; + } + + msg2 = talloc_p(tdb_key.dptr, struct ldb_message); + if (msg2 == NULL) { + talloc_free(tdb_key.dptr); return -1; } - ret = ltdb_unpack_data(module, &tdb_data, &msg2); + ret = ltdb_unpack_data(module, &tdb_data, msg2); if (ret == -1) { - ldb_free(ldb, tdb_key.dptr); + talloc_free(tdb_key.dptr); free(tdb_data.dptr); return -1; } - if (!msg2.dn) { - msg2.dn = msg->dn; + if (!msg2->dn) { + msg2->dn = msg->dn; } for (i=0;inum_elements;i++) { @@ -522,16 +525,16 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms case LDB_FLAG_MOD_ADD: /* add this element to the message. fail if it already exists */ - ret = find_element(&msg2, el->name); + ret = find_element(msg2, el->name); if (ret == -1) { - if (msg_add_element(ldb, &msg2, el) != 0) { + if (msg_add_element(ldb, msg2, el) != 0) { goto failed; } continue; } - el2 = &msg2.elements[ret]; + el2 = &msg2->elements[ret]; /* An attribute with this name already exists, add all * values if they don't already exist. */ @@ -544,15 +547,15 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms } } - vals = ldb_realloc_p(ldb, el2->values, struct ldb_val, - el2->num_values + el->num_values); + vals = talloc_realloc_p(msg2->elements, el2->values, struct ldb_val, + el2->num_values + el->num_values); if (vals == NULL) goto failed; for (j=0;jnum_values;j++) { vals[el2->num_values + j] = - ldb_val_dup(ldb, &el->values[j]); + ldb_val_dup(vals, &el->values[j]); } el2->values = vals; @@ -563,11 +566,11 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms case LDB_FLAG_MOD_REPLACE: /* replace all elements of this attribute name with the elements listed. The attribute not existing is not an error */ - msg_delete_attribute(module, ldb, &msg2, msg->elements[i].name); + msg_delete_attribute(module, ldb, msg2, msg->elements[i].name); /* add the replacement element, if not empty */ if (msg->elements[i].num_values != 0 && - msg_add_element(ldb, &msg2, &msg->elements[i]) != 0) { + msg_add_element(ldb, msg2, &msg->elements[i]) != 0) { goto failed; } break; @@ -576,7 +579,7 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms /* we could be being asked to delete all values or just some values */ if (msg->elements[i].num_values == 0) { - if (msg_delete_attribute(module, ldb, &msg2, + if (msg_delete_attribute(module, ldb, msg2, msg->elements[i].name) != 0) { ltdb->last_err_string = "No such attribute"; goto failed; @@ -585,7 +588,7 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms } for (j=0;jelements[i].num_values;j++) { if (msg_delete_element(module, - &msg2, + msg2, msg->elements[i].name, &msg->elements[i].values[j]) != 0) { ltdb->last_err_string = "No such attribute"; @@ -600,17 +603,15 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms } /* we've made all the mods - save the modified record back into the database */ - ret = ltdb_store(module, &msg2, TDB_MODIFY); + ret = ltdb_store(module, msg2, TDB_MODIFY); - ldb_free(ldb, tdb_key.dptr); + talloc_free(tdb_key.dptr); free(tdb_data.dptr); - ltdb_unpack_data_free(module, &msg2); return ret; failed: - ldb_free(ldb, tdb_key.dptr); + talloc_free(tdb_key.dptr); free(tdb_data.dptr); - ltdb_unpack_data_free(module, &msg2); return -1; } @@ -649,10 +650,9 @@ static int ltdb_modify(struct ldb_module *module, const struct ldb_message *msg) */ static int ltdb_rename(struct ldb_module *module, const char *olddn, const char *newdn) { - struct ldb_context *ldb = module->ldb; struct ltdb_private *ltdb = module->private_data; int ret; - struct ldb_message msg; + struct ldb_message *msg; const char *error_str; ltdb->last_err_string = NULL; @@ -661,28 +661,28 @@ static int ltdb_rename(struct ldb_module *module, const char *olddn, const char return -1; } + msg = talloc_p(module, struct ldb_message); + if (msg == NULL) { + goto failed; + } + /* in case any attribute of the message was indexed, we need to fetch the old record */ - ret = ltdb_search_dn1(module, olddn, &msg); + ret = ltdb_search_dn1(module, olddn, msg); if (ret != 1) { /* not finding the old record is an error */ goto failed; } - msg.dn = ldb_strdup(ldb,newdn); - if (!msg.dn) { - ltdb_search_dn1_free(module, &msg); + msg->dn = talloc_strdup(msg, newdn); + if (!msg->dn) { goto failed; } - ret = ltdb_add(module, &msg); + ret = ltdb_add(module, msg); if (ret == -1) { - ldb_free(ldb, msg.dn); - ltdb_search_dn1_free(module, &msg); goto failed; } - ldb_free(ldb, msg.dn); - ltdb_search_dn1_free(module, &msg); ret = ltdb_delete(module, olddn); error_str = ltdb->last_err_string; @@ -692,10 +692,13 @@ static int ltdb_rename(struct ldb_module *module, const char *olddn, const char ltdb->last_err_string = error_str; + talloc_free(msg); ltdb_unlock(module, LDBLOCK); return ret; + failed: + talloc_free(msg); ltdb_unlock(module, LDBLOCK); return -1; } @@ -706,18 +709,8 @@ failed: static int ltdb_close(struct ldb_module *module) { struct ldb_context *ldb = module->ldb; - struct ltdb_private *ltdb = module->private_data; - int ret; - - ltdb->last_err_string = NULL; - - ltdb_cache_free(module); - ldb_set_alloc(ldb, NULL, NULL); - - ret = tdb_close(ltdb->tdb); - ldb_free(ldb, ltdb); - free(ldb); - return ret; + talloc_free(ldb); + return 0; } @@ -745,11 +738,20 @@ static const struct ldb_module_ops ltdb_ops = { ltdb_rename, ltdb_lock, ltdb_unlock, - ltdb_errstring, - ltdb_cache_free + ltdb_errstring }; +/* + destroy the ltdb context +*/ +static int ltdb_destructor(void *p) +{ + struct ltdb_private *ltdb = p; + tdb_close(ltdb->tdb); + return 0; +} + /* connect to the database */ @@ -763,7 +765,7 @@ struct ldb_context *ltdb_connect(const char *url, TDB_CONTEXT *tdb; struct ldb_context *ldb; - ldb = calloc(1, sizeof(struct ldb_context)); + ldb = talloc_zero_p(NULL, struct ldb_context); if (!ldb) { errno = ENOMEM; return NULL; @@ -773,6 +775,7 @@ struct ldb_context *ltdb_connect(const char *url, if (strchr(url, ':')) { if (strncmp(url, "tdb://", 6) != 0) { errno = EINVAL; + talloc_free(ldb); return NULL; } path = url+6; @@ -791,14 +794,14 @@ struct ldb_context *ltdb_connect(const char *url, /* note that we use quite a large default hash size */ tdb = tdb_open(path, 10000, tdb_flags, open_flags, 0666); if (!tdb) { - free(ldb); + talloc_free(ldb); return NULL; } - ltdb = ldb_malloc_p(ldb, struct ltdb_private); + ltdb = talloc_zero_p(ldb, struct ltdb_private); if (!ltdb) { tdb_close(tdb); - free(ldb); + talloc_free(ldb); errno = ENOMEM; return NULL; } @@ -806,12 +809,11 @@ struct ldb_context *ltdb_connect(const char *url, ltdb->tdb = tdb; ltdb->sequence_number = 0; - memset(<db->cache, 0, sizeof(ltdb->cache)); + talloc_set_destructor(ltdb, ltdb_destructor); - ldb->modules = ldb_malloc_p(ldb, struct ldb_module); + ldb->modules = talloc_p(ldb, struct ldb_module); if (!ldb->modules) { - tdb_close(tdb); - free(ldb); + talloc_free(ldb); errno = ENOMEM; return NULL; } -- 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_tdb.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 288633cb01..b1de96986d 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -300,7 +300,7 @@ static int ltdb_delete(struct ldb_module *module, const char *dn) goto failed; } - msg = talloc_p(module, struct ldb_message); + msg = talloc(module, struct ldb_message); if (msg == NULL) { goto failed; } @@ -368,7 +368,7 @@ static int msg_add_element(struct ldb_context *ldb, struct ldb_message_element *e2; unsigned int i; - e2 = talloc_realloc_p(msg, msg->elements, struct ldb_message_element, + e2 = talloc_realloc(msg, msg->elements, struct ldb_message_element, msg->num_elements+1); if (!e2) { errno = ENOMEM; @@ -383,7 +383,7 @@ static int msg_add_element(struct ldb_context *ldb, e2->flags = el->flags; e2->values = NULL; if (el->num_values != 0) { - e2->values = talloc_array_p(msg->elements, struct ldb_val, el->num_values); + e2->values = talloc_array(msg->elements, struct ldb_val, el->num_values); if (!e2->values) { errno = ENOMEM; return -1; @@ -422,7 +422,7 @@ static int msg_delete_attribute(struct ldb_module *module, } msg->num_elements--; i--; - msg->elements = talloc_realloc_p(msg, msg->elements, + msg->elements = talloc_realloc(msg, msg->elements, struct ldb_message_element, msg->num_elements); } @@ -498,7 +498,7 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms return -1; } - msg2 = talloc_p(tdb_key.dptr, struct ldb_message); + msg2 = talloc(tdb_key.dptr, struct ldb_message); if (msg2 == NULL) { talloc_free(tdb_key.dptr); return -1; @@ -547,7 +547,7 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms } } - vals = talloc_realloc_p(msg2->elements, el2->values, struct ldb_val, + vals = talloc_realloc(msg2->elements, el2->values, struct ldb_val, el2->num_values + el->num_values); if (vals == NULL) @@ -661,7 +661,7 @@ static int ltdb_rename(struct ldb_module *module, const char *olddn, const char return -1; } - msg = talloc_p(module, struct ldb_message); + msg = talloc(module, struct ldb_message); if (msg == NULL) { goto failed; } @@ -765,7 +765,7 @@ struct ldb_context *ltdb_connect(const char *url, TDB_CONTEXT *tdb; struct ldb_context *ldb; - ldb = talloc_zero_p(NULL, struct ldb_context); + ldb = talloc_zero(NULL, struct ldb_context); if (!ldb) { errno = ENOMEM; return NULL; @@ -798,7 +798,7 @@ struct ldb_context *ltdb_connect(const char *url, return NULL; } - ltdb = talloc_zero_p(ldb, struct ltdb_private); + ltdb = talloc_zero(ldb, struct ltdb_private); if (!ltdb) { tdb_close(tdb); talloc_free(ldb); @@ -811,7 +811,7 @@ struct ldb_context *ltdb_connect(const char *url, talloc_set_destructor(ltdb, ltdb_destructor); - ldb->modules = talloc_p(ldb, struct ldb_module); + ldb->modules = talloc(ldb, struct ldb_module); if (!ldb->modules) { talloc_free(ldb); errno = ENOMEM; -- cgit From 5a88d5211ba0f6b1d09cdd92489b34d0e603716b Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 13 Feb 2005 12:27:57 +0000 Subject: r5374: - changed the dn key code in the ldb tdb backend to correctly honor the case sensitive/insensitive flags on sections of a dn. So if a dn is made up of 4 attributes, and 2 of those are case insensitive and 2 are case sensitive, then all the attribute names are uppercases, but only the values of the case insensitive attributes are uppercased when forming the tdb key. - added code to canonicalise the dn, removing leading and trailing spaces from attribute names and values - when the @ATTRIBUTES record changes, fix the dn keys of any records that should now have new dn keys due to changes in the case sensitivity of the record I really did this to allow me to make the WINS database properly case insensitive, but it is also the correct general fix for ldb, as it matches the LDAP specification (and w2k LDAP server behaviour) (This used to be commit 0f034dc5636d182a1d9207ad662b3fc8df7ca3e4) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 81 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 79 insertions(+), 2 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index b1de96986d..07a9fa8866 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -42,6 +42,82 @@ #define LDBLOCK "INT_LDBLOCK" + +/* + casefold a dn. We need to uppercase the attribute names, and the + attribute values of case insensitive attributes. We also need to remove + extraneous spaces between elements +*/ +static char *ltdb_dn_fold(struct ldb_module *module, const char *dn) +{ + const char *dn_orig = dn; + struct ldb_context *ldb = module->ldb; + TALLOC_CTX *tmp_ctx = talloc_new(ldb); + char *ret; + size_t len; + + ret = talloc_strdup(tmp_ctx, ""); + if (ret == NULL) goto failed; + + while ((len = strcspn(dn, ",")) > 0) { + char *p = strchr(dn, '='); + char *attr, *value; + int flags; + + if (p == NULL || (p-dn) > len) goto failed; + + attr = talloc_strndup(tmp_ctx, dn, p-dn); + if (attr == NULL) goto failed; + + /* trim spaces from the attribute name */ + while (' ' == *attr) attr++; + while (' ' == attr[strlen(attr)-1]) { + attr[strlen(attr)-1] = 0; + } + if (*attr == 0) goto failed; + + value = talloc_strndup(tmp_ctx, p+1, len-(p+1-dn)); + if (value == NULL) goto failed; + + /* trim spaces from the value */ + while (' ' == *value) value++; + while (' ' == value[strlen(value)-1]) { + value[strlen(value)-1] = 0; + } + if (*value == 0) goto failed; + + flags = ltdb_attribute_flags(module, attr); + + attr = ldb_casefold(ldb, attr); + if (attr == NULL) goto failed; + talloc_steal(tmp_ctx, attr); + + if (flags & LTDB_FLAG_CASE_INSENSITIVE) { + value = ldb_casefold(ldb, value); + if (value == NULL) goto failed; + talloc_steal(tmp_ctx, value); + } + + if (dn[len] == ',') { + ret = talloc_asprintf_append(ret, "%s=%s,", attr, value); + } else { + ret = talloc_asprintf_append(ret, "%s=%s", attr, value); + } + if (ret == NULL) goto failed; + + dn += len; + if (*dn == ',') dn++; + } + + talloc_steal(ldb, ret); + talloc_free(tmp_ctx); + return ret; + +failed: + talloc_free(tmp_ctx); + return ldb_casefold(ldb, dn_orig); +} + /* form a TDB_DATA for a record key caller frees @@ -65,7 +141,8 @@ struct TDB_DATA ltdb_key(struct ldb_module *module, const char *dn) there are 3 cases dealt with in this code: - 1) if the dn doesn't start with @INDEX: then uppercase whole dn + 1) if the dn doesn't start with @INDEX: then uppercase the attribute + names and the attributes values of case insensitive attributes 2) if the dn starts with @INDEX:attr and 'attr' is a case insensitive attribute then uppercase whole dn 3) if the dn starts with @INDEX:attr and 'attr' is a case sensitive @@ -95,7 +172,7 @@ struct TDB_DATA ltdb_key(struct ldb_module *module, const char *dn) } talloc_free(attr_name); } else { - dn_folded = ldb_casefold(ldb, dn); + dn_folded = ltdb_dn_fold(module, dn); } if (!dn_folded) { -- cgit From b1b14817eaa6e6579596d54166e17bc8d5605c01 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sun, 27 Feb 2005 11:35:47 +0000 Subject: r5585: LDB interfaces change: changes: - ldb_wrap disappears from code and become a private structure of db_wrap.c thanks to our move to talloc in ldb code, we do not need to expose it anymore - removal of ldb_close() function form the code thanks to our move to talloc in ldb code, we do not need it anymore use talloc_free() to close and free an ldb database - some minor updates to ldb modules code to cope with the change and fix some bugs I found out during the process (This used to be commit d58be9e74b786a11a57e89df36081d55730dfe0a) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 11 ----------- 1 file changed, 11 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 07a9fa8866..204eaf9d3c 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -780,16 +780,6 @@ failed: return -1; } -/* - close database -*/ -static int ltdb_close(struct ldb_module *module) -{ - struct ldb_context *ldb = module->ldb; - talloc_free(ldb); - return 0; -} - /* return extended error information @@ -806,7 +796,6 @@ static const char *ltdb_errstring(struct ldb_module *module) static const struct ldb_module_ops ltdb_ops = { "tdb", - ltdb_close, ltdb_search, ltdb_search_free, ltdb_add, -- 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_tdb.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 204eaf9d3c..87582cf4eb 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -797,7 +797,6 @@ static const char *ltdb_errstring(struct ldb_module *module) static const struct ldb_module_ops ltdb_ops = { "tdb", ltdb_search, - ltdb_search_free, ltdb_add, ltdb_modify, ltdb_delete, -- 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_tdb.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 87582cf4eb..b47d79de52 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -248,6 +248,40 @@ static int ltdb_unlock(struct ldb_module *module, const char *lockname) } +/* + lock the database for read - use by ltdb_search +*/ +int ltdb_lock_read(struct ldb_module *module) +{ + struct ltdb_private *ltdb = module->private_data; + TDB_DATA key; + int ret; + key = ltdb_key(module, LDBLOCK); + if (!key.dptr) { + return -1; + } + ret = tdb_chainlock_read(ltdb->tdb, key); + talloc_free(key.dptr); + return ret; +} + +/* + unlock the database after a ltdb_lock_read() +*/ +int ltdb_unlock_read(struct ldb_module *module) +{ + struct ltdb_private *ltdb = module->private_data; + TDB_DATA key; + key = ltdb_key(module, LDBLOCK); + if (!key.dptr) { + return -1; + } + tdb_chainunlock_read(ltdb->tdb, key); + talloc_free(key.dptr); + return 0; +} + + /* we've made a modification to a dn - possibly reindex and update sequence number -- cgit From ca4e0c8539e5b0e01ca9d68eba8692c544d7a4d6 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Tue, 17 May 2005 21:43:47 +0000 Subject: r6867: this code will change the way the @ATTRIBUTES object is handled this object properties are now used as multivalue attributes now all values inserted are checked against a "valid values table" eg: this form is now accepted: dn: @ATTRIBUTES uid: CASE_INSENSITIVE uid: WILDCARD this form is now rejected: dn: @ATTRIBUTES uid: CASE_INSENSITIVE WILDCARD please update your .ldb files if you make use of @ATTRIBUTES (sam.ldb heavily uses it) the code passes all make test tests for both tdb and ldap, it also passes the new test to check for wrong @ATTRIBUTES attribute values Simo. (This used to be commit 1295b891a26c2cb2c34540f90ded83390cf87da2) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index b47d79de52..f6a23d7433 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -281,6 +281,33 @@ int ltdb_unlock_read(struct ldb_module *module) return 0; } +/* + check special dn's have valid attributes + currently only @ATTRIBUTES is checked +*/ +int ltdb_check_special_dn(struct ldb_module *module, const struct ldb_message *msg) +{ + struct ltdb_private *ltdb = module->private_data; + int i, j; + + if (strcmp(msg->dn, LTDB_ATTRIBUTES) != 0) { + return 0; + } + + /* we have @ATTRIBUTES, let's check attributes are fine */ + /* should we check that we deny multivalued attributes ? */ + for (i = 0; i < msg->num_elements; i++) { + for (j = 0; j < msg->elements[i].num_values; j++) { + if (ltdb_check_at_attributes_values(&msg->elements[i].values[j]) != 0) { + ltdb->last_err_string = "Invalid attribute value in an @ATTRIBUTES entry"; + return -1; + } + } + } + + return 0; +} + /* we've made a modification to a dn - possibly reindex and @@ -351,6 +378,11 @@ static int ltdb_add(struct ldb_module *module, const struct ldb_message *msg) ltdb->last_err_string = NULL; + ret = ltdb_check_special_dn(module, msg); + if (ret != 0) { + return ret; + } + if (ltdb_lock(module, LDBLOCK) != 0) { return -1; } @@ -359,7 +391,7 @@ static int ltdb_add(struct ldb_module *module, const struct ldb_message *msg) ltdb_unlock(module, LDBLOCK); return -1; } - + ret = ltdb_store(module, msg, TDB_INSERT); if (ret == 0) { @@ -736,6 +768,11 @@ static int ltdb_modify(struct ldb_module *module, const struct ldb_message *msg) ltdb->last_err_string = NULL; + ret = ltdb_check_special_dn(module, msg); + if (ret != 0) { + return ret; + } + if (ltdb_lock(module, LDBLOCK) != 0) { return -1; } -- cgit From a1ba224107fbcf6f8a9a3091f42cde2a0c47f85e Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Sat, 4 Jun 2005 17:13:43 +0000 Subject: r7276: - moved static tdb function ltdb_dn_fold() into common/ so that it can be called from multiple backends. (ldb_sqlite3 needs it too.) Added parameter for a callback function that determines whether an attribute needs case folding. - begin to prepare for sqlite3 in build process - work-in-progress updates, on ldb_sqlite3 (This used to be commit a80bced0b96ffb655559a43cf7f4d7a34deb5a7d) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 76 +++------------------------------------ 1 file changed, 5 insertions(+), 71 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index f6a23d7433..9c126c1dfd 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -44,78 +44,12 @@ /* - casefold a dn. We need to uppercase the attribute names, and the - attribute values of case insensitive attributes. We also need to remove - extraneous spaces between elements + callback function used in call to ldb_dn_fold() for determining whether an + attribute type requires case folding. */ -static char *ltdb_dn_fold(struct ldb_module *module, const char *dn) +static int ltdb_case_fold_attr_required(struct ldb_module *module, char *attr) { - const char *dn_orig = dn; - struct ldb_context *ldb = module->ldb; - TALLOC_CTX *tmp_ctx = talloc_new(ldb); - char *ret; - size_t len; - - ret = talloc_strdup(tmp_ctx, ""); - if (ret == NULL) goto failed; - - while ((len = strcspn(dn, ",")) > 0) { - char *p = strchr(dn, '='); - char *attr, *value; - int flags; - - if (p == NULL || (p-dn) > len) goto failed; - - attr = talloc_strndup(tmp_ctx, dn, p-dn); - if (attr == NULL) goto failed; - - /* trim spaces from the attribute name */ - while (' ' == *attr) attr++; - while (' ' == attr[strlen(attr)-1]) { - attr[strlen(attr)-1] = 0; - } - if (*attr == 0) goto failed; - - value = talloc_strndup(tmp_ctx, p+1, len-(p+1-dn)); - if (value == NULL) goto failed; - - /* trim spaces from the value */ - while (' ' == *value) value++; - while (' ' == value[strlen(value)-1]) { - value[strlen(value)-1] = 0; - } - if (*value == 0) goto failed; - - flags = ltdb_attribute_flags(module, attr); - - attr = ldb_casefold(ldb, attr); - if (attr == NULL) goto failed; - talloc_steal(tmp_ctx, attr); - - if (flags & LTDB_FLAG_CASE_INSENSITIVE) { - value = ldb_casefold(ldb, value); - if (value == NULL) goto failed; - talloc_steal(tmp_ctx, value); - } - - if (dn[len] == ',') { - ret = talloc_asprintf_append(ret, "%s=%s,", attr, value); - } else { - ret = talloc_asprintf_append(ret, "%s=%s", attr, value); - } - if (ret == NULL) goto failed; - - dn += len; - if (*dn == ',') dn++; - } - - talloc_steal(ldb, ret); - talloc_free(tmp_ctx); - return ret; - -failed: - talloc_free(tmp_ctx); - return ldb_casefold(ldb, dn_orig); + return ltdb_attribute_flags(module, attr) & LTDB_FLAG_CASE_INSENSITIVE; } /* @@ -172,7 +106,7 @@ struct TDB_DATA ltdb_key(struct ldb_module *module, const char *dn) } talloc_free(attr_name); } else { - dn_folded = ltdb_dn_fold(module, dn); + dn_folded = ldb_dn_fold(module, dn, ltdb_case_fold_attr_required); } if (!dn_folded) { -- 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_tdb.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 9c126c1dfd..0366809c33 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -800,15 +800,16 @@ static const char *ltdb_errstring(struct ldb_module *module) static const struct ldb_module_ops ltdb_ops = { - "tdb", - ltdb_search, - ltdb_add, - ltdb_modify, - ltdb_delete, - ltdb_rename, - ltdb_lock, - ltdb_unlock, - ltdb_errstring + .name = "tdb", + .search = ltdb_search, + .search_bytree = ltdb_search_bytree, + .add_record = ltdb_add, + .modify_record = ltdb_modify, + .delete_record = ltdb_delete, + .rename_record = ltdb_rename, + .named_lock = ltdb_lock, + .named_unlock = ltdb_unlock, + .errstring = ltdb_errstring }; -- cgit From f021dffb6991138213967521c743f03f474f9af9 Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Wed, 15 Jun 2005 02:43:42 +0000 Subject: r7601: ldb_sqlite3 work in progress (This used to be commit 0a64948152a446b5e127578d49b1ed8a90a1a222) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 0366809c33..6516787a5a 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -47,8 +47,10 @@ callback function used in call to ldb_dn_fold() for determining whether an attribute type requires case folding. */ -static int ltdb_case_fold_attr_required(struct ldb_module *module, char *attr) +static int ltdb_case_fold_attr_required(void * user_data, char *attr) { + struct ldb_module *module = user_data; + return ltdb_attribute_flags(module, attr) & LTDB_FLAG_CASE_INSENSITIVE; } @@ -106,7 +108,8 @@ struct TDB_DATA ltdb_key(struct ldb_module *module, const char *dn) } talloc_free(attr_name); } else { - dn_folded = ldb_dn_fold(module, dn, ltdb_case_fold_attr_required); + dn_folded = ldb_dn_fold(module->ldb, dn, + module, ltdb_case_fold_attr_required); } if (!dn_folded) { -- 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_tdb.c | 43 +++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 24 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 6516787a5a..596ede8a4e 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -49,9 +49,9 @@ */ static int ltdb_case_fold_attr_required(void * user_data, char *attr) { - struct ldb_module *module = user_data; + struct ldb_module *module = talloc_get_type(user_data, struct ldb_module); - return ltdb_attribute_flags(module, attr) & LTDB_FLAG_CASE_INSENSITIVE; + return ltdb_attribute_flags(module, attr) & LTDB_FLAG_CASE_INSENSITIVE; } /* @@ -746,6 +746,11 @@ static int ltdb_rename(struct ldb_module *module, const char *olddn, const char return -1; } + if (ltdb_cache_load(module) != 0) { + ltdb_unlock(module, LDBLOCK); + return -1; + } + msg = talloc(module, struct ldb_message); if (msg == NULL) { goto failed; @@ -829,28 +834,19 @@ static int ltdb_destructor(void *p) /* connect to the database */ -struct ldb_context *ltdb_connect(const char *url, - unsigned int flags, - const char *options[]) +int ltdb_connect(struct ldb_context *ldb, const char *url, + unsigned int flags, const char *options[]) { const char *path; int tdb_flags, open_flags; struct ltdb_private *ltdb; TDB_CONTEXT *tdb; - struct ldb_context *ldb; - - ldb = talloc_zero(NULL, struct ldb_context); - if (!ldb) { - errno = ENOMEM; - return NULL; - } /* parse the url */ if (strchr(url, ':')) { if (strncmp(url, "tdb://", 6) != 0) { - errno = EINVAL; - talloc_free(ldb); - return NULL; + ldb_debug(ldb, LDB_DEBUG_ERROR, "Invalid tdb URL '%s'", url); + return -1; } path = url+6; } else { @@ -868,16 +864,15 @@ struct ldb_context *ltdb_connect(const char *url, /* note that we use quite a large default hash size */ tdb = tdb_open(path, 10000, tdb_flags, open_flags, 0666); if (!tdb) { - talloc_free(ldb); - return NULL; + ldb_debug(ldb, LDB_DEBUG_ERROR, "Unable to open tdb '%s'", path); + return -1; } ltdb = talloc_zero(ldb, struct ltdb_private); if (!ltdb) { tdb_close(tdb); - talloc_free(ldb); - errno = ENOMEM; - return NULL; + ldb_oom(ldb); + return -1; } ltdb->tdb = tdb; @@ -887,14 +882,14 @@ struct ldb_context *ltdb_connect(const char *url, ldb->modules = talloc(ldb, struct ldb_module); if (!ldb->modules) { - talloc_free(ldb); - errno = ENOMEM; - return NULL; + ldb_oom(ldb); + talloc_free(ltdb); + return -1; } ldb->modules->ldb = ldb; ldb->modules->prev = ldb->modules->next = NULL; ldb->modules->private_data = ltdb; ldb->modules->ops = <db_ops; - return ldb; + return 0; } -- cgit From b7be627e35b81fb2df8cdd83d129713aa8f0127a Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 20 Jun 2005 08:50:53 +0000 Subject: r7784: give an error in ldb_tdb for invalid modify flags. The "whenChanged" bug was being silently ignored with the tdb backend because of this bug. A case where the ldap backend was right, and the tdb backend was wrong! (This used to be commit ddb26db763c314049043d80d27113226c0f2e656) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 596ede8a4e..f8c98d6712 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -679,6 +679,9 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms } } break; + default: + ltdb->last_err_string = "Invalid ldb_modify flags"; + goto failed; } } -- cgit From 1702f52498168c0437416dec1014cedead634774 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sun, 26 Jun 2005 23:59:22 +0000 Subject: r7936: new ldb_dn_explode and ldb_dn_casefold functions and co (This used to be commit 7ccf21ab4eeb9821e457308a239f2103a106fb12) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 48 +++++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 5 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index f8c98d6712..bc61378f18 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -38,6 +38,7 @@ #include "includes.h" #include "ldb/include/ldb.h" #include "ldb/include/ldb_private.h" +#include "ldb/include/ldb_dn.h" #include "ldb/ldb_tdb/ldb_tdb.h" #define LDBLOCK "INT_LDBLOCK" @@ -107,9 +108,30 @@ struct TDB_DATA ltdb_key(struct ldb_module *module, const char *dn) talloc_free(attr_name_folded); } talloc_free(attr_name); - } else { - dn_folded = ldb_dn_fold(module->ldb, dn, - module, ltdb_case_fold_attr_required); + } + /* special cases for tdb */ + else if (*dn == '@' || strncmp(LDBLOCK, dn, strlen(LDBLOCK)) == 0) { + + dn_folded = talloc_strdup(ldb, dn); + } + else { + struct ldb_dn *edn, *cedn; + + edn = ldb_dn_explode(ldb, dn); + if (!edn) + goto failed; + + cedn = ldb_dn_casefold(ldb, edn, module, + ltdb_case_fold_attr_required); + if (!edn) + goto failed; + + dn_folded = ldb_dn_linearize(ldb, cedn); + if (!dn_folded) + goto failed; + + talloc_free(edn); + talloc_free(cedn); } if (!dn_folded) { @@ -141,6 +163,7 @@ failed: static int ltdb_lock(struct ldb_module *module, const char *lockname) { struct ltdb_private *ltdb = module->private_data; + char *lock_dn; TDB_DATA key; int ret; @@ -148,14 +171,21 @@ static int ltdb_lock(struct ldb_module *module, const char *lockname) return -1; } - key = ltdb_key(module, lockname); + lock_dn = talloc_asprintf(module->ldb, "%s_%s", LDBLOCK, lockname); + if (lock_dn == NULL) { + return -1; + } + + key = ltdb_key(module, lock_dn); if (!key.dptr) { + talloc_free(lock_dn); return -1; } ret = tdb_chainlock(ltdb->tdb, key); talloc_free(key.dptr); + talloc_free(lock_dn); return ret; } @@ -166,20 +196,28 @@ static int ltdb_lock(struct ldb_module *module, const char *lockname) static int ltdb_unlock(struct ldb_module *module, const char *lockname) { struct ltdb_private *ltdb = module->private_data; + char *lock_dn; TDB_DATA key; if (lockname == NULL) { return -1; } - key = ltdb_key(module, lockname); + lock_dn = talloc_asprintf(module->ldb, "%s_%s", LDBLOCK, lockname); + if (lock_dn == NULL) { + return -1; + } + + key = ltdb_key(module, lock_dn); if (!key.dptr) { + talloc_free(lock_dn); return -1; } tdb_chainunlock(ltdb->tdb, key); talloc_free(key.dptr); + talloc_free(lock_dn); return 0; } -- 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_tdb.c | 65 ++++++++------------------------------- 1 file changed, 12 insertions(+), 53 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index bc61378f18..22797b96d1 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -41,20 +41,9 @@ #include "ldb/include/ldb_dn.h" #include "ldb/ldb_tdb/ldb_tdb.h" -#define LDBLOCK "INT_LDBLOCK" +#define LDBLOCK "@INT_LDBLOCK" -/* - callback function used in call to ldb_dn_fold() for determining whether an - attribute type requires case folding. -*/ -static int ltdb_case_fold_attr_required(void * user_data, char *attr) -{ - struct ldb_module *module = talloc_get_type(user_data, struct ldb_module); - - return ltdb_attribute_flags(module, attr) & LTDB_FLAG_CASE_INSENSITIVE; -} - /* form a TDB_DATA for a record key caller frees @@ -68,9 +57,6 @@ struct TDB_DATA ltdb_key(struct ldb_module *module, const char *dn) TDB_DATA key; char *key_str = NULL; char *dn_folded = NULL; - const char *prefix = LTDB_INDEX ":"; - const char *s; - int flags; /* most DNs are case insensitive. The exception is index DNs for @@ -78,52 +64,22 @@ struct TDB_DATA ltdb_key(struct ldb_module *module, const char *dn) there are 3 cases dealt with in this code: - 1) if the dn doesn't start with @INDEX: then uppercase the attribute + 1) if the dn doesn't start with @ then uppercase the attribute names and the attributes values of case insensitive attributes - 2) if the dn starts with @INDEX:attr and 'attr' is a case insensitive - attribute then uppercase whole dn - 3) if the dn starts with @INDEX:attr and 'attr' is a case sensitive - attribute then uppercase up to the value of the attribute, but - not the value itself + 2) if the dn starts with @ then leave it alone - the indexing code handles + the rest */ - if (strncmp(dn, prefix, strlen(prefix)) == 0 && - (s = strchr(dn+strlen(prefix), ':'))) { - char *attr_name, *attr_name_folded; - attr_name = talloc_strndup(ldb, dn+strlen(prefix), (s-(dn+strlen(prefix)))); - if (!attr_name) { - goto failed; - } - flags = ltdb_attribute_flags(module, attr_name); - - if (flags & LTDB_FLAG_CASE_INSENSITIVE) { - dn_folded = ldb_casefold(ldb, dn); - } else { - attr_name_folded = ldb_casefold(ldb, attr_name); - if (!attr_name_folded) { - goto failed; - } - dn_folded = talloc_asprintf(ldb, "%s:%s:%s", - prefix, attr_name_folded, - s+1); - talloc_free(attr_name_folded); - } - talloc_free(attr_name); - } - /* special cases for tdb */ - else if (*dn == '@' || strncmp(LDBLOCK, dn, strlen(LDBLOCK)) == 0) { - + if (*dn == '@') { dn_folded = talloc_strdup(ldb, dn); - } - else { + } else { struct ldb_dn *edn, *cedn; edn = ldb_dn_explode(ldb, dn); if (!edn) goto failed; - cedn = ldb_dn_casefold(ldb, edn, module, - ltdb_case_fold_attr_required); - if (!edn) + cedn = ldb_dn_casefold(ldb, edn); + if (!cedn) goto failed; dn_folded = ldb_dn_linearize(ldb, cedn); @@ -563,6 +519,7 @@ static int msg_delete_element(struct ldb_module *module, unsigned int i; int found; struct ldb_message_element *el; + const struct ldb_attrib_handler *h; found = find_element(msg, name); if (found == -1) { @@ -571,8 +528,10 @@ static int msg_delete_element(struct ldb_module *module, el = &msg->elements[found]; + h = ldb_attrib_handler(ldb, el->name); + for (i=0;inum_values;i++) { - if (ltdb_val_equal(module, msg->elements[i].name, &el->values[i], val)) { + if (h->comparison_fn(ldb, &el->values[i], val) == 0) { if (inum_values-1) { memmove(&el->values[i], &el->values[i+1], sizeof(el->values[i])*(el->num_values-(i+1))); -- cgit From 1c5105065a44173667de2a022dd2417e56b527d6 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sat, 2 Jul 2005 17:30:03 +0000 Subject: r8082: large rewite of ldb_dn.c - we do not support multpiple attribute components anymore, makes code a lot easier they will be readded later if we found out they are really used, so far my tests show w2k3 do not handle them as well - fix escaping issues, move component value to be in an ldb_val structure still need to handle binary values case - make cononicalize functions leak less memory by giving a specific memory context - fix tests scripts so that test-ldap can start - make test not delete databases on completion so that I can inspect them (This used to be commit 624a73148d125690ce18515f19231d26df207738) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 22797b96d1..eb72e665f5 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -38,7 +38,6 @@ #include "includes.h" #include "ldb/include/ldb.h" #include "ldb/include/ldb_private.h" -#include "ldb/include/ldb_dn.h" #include "ldb/ldb_tdb/ldb_tdb.h" #define LDBLOCK "@INT_LDBLOCK" @@ -531,7 +530,7 @@ static int msg_delete_element(struct ldb_module *module, h = ldb_attrib_handler(ldb, el->name); for (i=0;inum_values;i++) { - if (h->comparison_fn(ldb, &el->values[i], val) == 0) { + if (h->comparison_fn(ldb, ldb, &el->values[i], val) == 0) { if (inum_values-1) { memmove(&el->values[i], &el->values[i+1], sizeof(el->values[i])*(el->num_values-(i+1))); -- cgit From 3fe6ca1c189f43e8e9f7059943ab7e2939c7582e Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sat, 2 Jul 2005 18:43:22 +0000 Subject: r8084: do not leak memory on errors (This used to be commit 2e328e6c2fc2c66b0d0de910cd43ab232049bc90) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index eb72e665f5..df94b0691d 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -56,6 +56,8 @@ struct TDB_DATA ltdb_key(struct ldb_module *module, const char *dn) TDB_DATA key; char *key_str = NULL; char *dn_folded = NULL; + struct ldb_dn *edn = NULL; + struct ldb_dn *cedn = NULL; /* most DNs are case insensitive. The exception is index DNs for @@ -71,8 +73,6 @@ struct TDB_DATA ltdb_key(struct ldb_module *module, const char *dn) if (*dn == '@') { dn_folded = talloc_strdup(ldb, dn); } else { - struct ldb_dn *edn, *cedn; - edn = ldb_dn_explode(ldb, dn); if (!edn) goto failed; @@ -89,10 +89,6 @@ struct TDB_DATA ltdb_key(struct ldb_module *module, const char *dn) talloc_free(cedn); } - if (!dn_folded) { - goto failed; - } - key_str = talloc_asprintf(ldb, "DN=%s", dn_folded); talloc_free(dn_folded); @@ -101,11 +97,13 @@ struct TDB_DATA ltdb_key(struct ldb_module *module, const char *dn) } key.dptr = key_str; - key.dsize = strlen(key_str)+1; + key.dsize = strlen(key_str) + 1; return key; failed: + talloc_free(edn); + talloc_free(cedn); errno = ENOMEM; key.dptr = NULL; key.dsize = 0; -- cgit From c1a4f0c769479f0a5a262db6f9d82814bf81d1d3 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 19 Jul 2005 11:54:00 +0000 Subject: r8601: fixed null termination in ltdb connect error (This used to be commit 64b6586b57de0bf22f8779447d217a918b7024a0) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index df94b0691d..0c8d2cea3e 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -861,7 +861,7 @@ int ltdb_connect(struct ldb_context *ldb, const char *url, /* note that we use quite a large default hash size */ tdb = tdb_open(path, 10000, tdb_flags, open_flags, 0666); if (!tdb) { - ldb_debug(ldb, LDB_DEBUG_ERROR, "Unable to open tdb '%s'", path); + ldb_debug(ldb, LDB_DEBUG_ERROR, "Unable to open tdb '%s'\n", path); return -1; } -- cgit From 338c3f8523d5db2cba1b79f94ff0cecabcd9e9cd Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 20 Jul 2005 00:59:38 +0000 Subject: r8625: move the ldb_wrap logic into the ldb code. This logic is meant to avoid the horrors of posix locking, but it was preventing us having an ldb open twice with different options. Now each ldb open of the same file shares the same underlying tdb, but uses a different ldb structure (This used to be commit 4e090c66dfa1d2764e4693578d3845be3b8893f6) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 0c8d2cea3e..40cfe97c29 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -818,16 +818,6 @@ static const struct ldb_module_ops ltdb_ops = { }; -/* - destroy the ltdb context -*/ -static int ltdb_destructor(void *p) -{ - struct ltdb_private *ltdb = p; - tdb_close(ltdb->tdb); - return 0; -} - /* connect to the database */ @@ -837,7 +827,6 @@ int ltdb_connect(struct ldb_context *ldb, const char *url, const char *path; int tdb_flags, open_flags; struct ltdb_private *ltdb; - TDB_CONTEXT *tdb; /* parse the url */ if (strchr(url, ':')) { @@ -858,24 +847,21 @@ int ltdb_connect(struct ldb_context *ldb, const char *url, open_flags = O_CREAT | O_RDWR; } - /* note that we use quite a large default hash size */ - tdb = tdb_open(path, 10000, tdb_flags, open_flags, 0666); - if (!tdb) { - ldb_debug(ldb, LDB_DEBUG_ERROR, "Unable to open tdb '%s'\n", path); - return -1; - } - ltdb = talloc_zero(ldb, struct ltdb_private); if (!ltdb) { - tdb_close(tdb); ldb_oom(ldb); return -1; } - ltdb->tdb = tdb; - ltdb->sequence_number = 0; + /* note that we use quite a large default hash size */ + ltdb->tdb = ltdb_wrap_open(ltdb, path, 10000, tdb_flags, open_flags, 0666); + if (!ltdb->tdb) { + ldb_debug(ldb, LDB_DEBUG_ERROR, "Unable to open tdb '%s'\n", path); + talloc_free(ltdb); + return -1; + } - talloc_set_destructor(ltdb, ltdb_destructor); + ltdb->sequence_number = 0; ldb->modules = talloc(ldb, struct ldb_module); if (!ldb->modules) { -- 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_tdb.c | 113 +++++++++++++++++++++++++------------- 1 file changed, 74 insertions(+), 39 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 40cfe97c29..61d0f9b64a 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -50,14 +50,12 @@ note that the key for a record can depend on whether the dn refers to a case sensitive index record or not */ -struct TDB_DATA ltdb_key(struct ldb_module *module, const char *dn) +struct TDB_DATA ltdb_key(struct ldb_module *module, const struct ldb_dn *dn) { struct ldb_context *ldb = module->ldb; TDB_DATA key; char *key_str = NULL; char *dn_folded = NULL; - struct ldb_dn *edn = NULL; - struct ldb_dn *cedn = NULL; /* most DNs are case insensitive. The exception is index DNs for @@ -70,26 +68,14 @@ struct TDB_DATA ltdb_key(struct ldb_module *module, const char *dn) 2) if the dn starts with @ then leave it alone - the indexing code handles the rest */ - if (*dn == '@') { - dn_folded = talloc_strdup(ldb, dn); - } else { - edn = ldb_dn_explode(ldb, dn); - if (!edn) - goto failed; - - cedn = ldb_dn_casefold(ldb, edn); - if (!cedn) - goto failed; - - dn_folded = ldb_dn_linearize(ldb, cedn); - if (!dn_folded) - goto failed; - talloc_free(edn); - talloc_free(cedn); + dn_folded = ldb_dn_linearize_casefold(ldb, dn); + if (!dn_folded) { + goto failed; } key_str = talloc_asprintf(ldb, "DN=%s", dn_folded); + talloc_free(dn_folded); if (!key_str) { @@ -102,8 +88,6 @@ struct TDB_DATA ltdb_key(struct ldb_module *module, const char *dn) return key; failed: - talloc_free(edn); - talloc_free(cedn); errno = ENOMEM; key.dptr = NULL; key.dsize = 0; @@ -116,7 +100,8 @@ failed: static int ltdb_lock(struct ldb_module *module, const char *lockname) { struct ltdb_private *ltdb = module->private_data; - char *lock_dn; + struct ldb_dn *lock_dn; + char *ldn; TDB_DATA key; int ret; @@ -124,10 +109,17 @@ static int ltdb_lock(struct ldb_module *module, const char *lockname) return -1; } - lock_dn = talloc_asprintf(module->ldb, "%s_%s", LDBLOCK, lockname); + ldn = talloc_asprintf(module->ldb, "%s_%s", LDBLOCK, lockname); + if (ldn == NULL) { + return -1; + } + + lock_dn = ldb_dn_explode(module->ldb, ldn); if (lock_dn == NULL) { + talloc_free(ldn); return -1; } + talloc_free(ldn); key = ltdb_key(module, lock_dn); if (!key.dptr) { @@ -149,17 +141,25 @@ static int ltdb_lock(struct ldb_module *module, const char *lockname) static int ltdb_unlock(struct ldb_module *module, const char *lockname) { struct ltdb_private *ltdb = module->private_data; - char *lock_dn; + struct ldb_dn *lock_dn; + char *ldn; TDB_DATA key; if (lockname == NULL) { return -1; } - lock_dn = talloc_asprintf(module->ldb, "%s_%s", LDBLOCK, lockname); + ldn = talloc_asprintf(module->ldb, "%s_%s", LDBLOCK, lockname); + if (ldn == NULL) { + return -1; + } + + lock_dn = ldb_dn_explode(module->ldb, ldn); if (lock_dn == NULL) { + talloc_free(ldn); return -1; } + talloc_free(ldn); key = ltdb_key(module, lock_dn); if (!key.dptr) { @@ -183,11 +183,21 @@ int ltdb_lock_read(struct ldb_module *module) { struct ltdb_private *ltdb = module->private_data; TDB_DATA key; + struct ldb_dn *lock_dn; int ret; - key = ltdb_key(module, LDBLOCK); + + lock_dn = ldb_dn_explode(module, LDBLOCK); + if (lock_dn == NULL) { + return -1; + } + + key = ltdb_key(module, lock_dn); if (!key.dptr) { + talloc_free(lock_dn); return -1; } + talloc_free(lock_dn); + ret = tdb_chainlock_read(ltdb->tdb, key); talloc_free(key.dptr); return ret; @@ -199,11 +209,21 @@ int ltdb_lock_read(struct ldb_module *module) int ltdb_unlock_read(struct ldb_module *module) { struct ltdb_private *ltdb = module->private_data; + struct ldb_dn *lock_dn; TDB_DATA key; - key = ltdb_key(module, LDBLOCK); + + lock_dn = ldb_dn_explode(module, LDBLOCK); + if (lock_dn == NULL) { + return -1; + } + + key = ltdb_key(module, lock_dn); if (!key.dptr) { + talloc_free(lock_dn); return -1; } + talloc_free(lock_dn); + tdb_chainunlock_read(ltdb->tdb, key); talloc_free(key.dptr); return 0; @@ -217,8 +237,9 @@ int ltdb_check_special_dn(struct ldb_module *module, const struct ldb_message *m { struct ltdb_private *ltdb = module->private_data; int i, j; - - if (strcmp(msg->dn, LTDB_ATTRIBUTES) != 0) { + + if (! ldb_dn_is_special(msg->dn) || + ! ldb_dn_check_special(msg->dn, LTDB_ATTRIBUTES)) { return 0; } @@ -241,17 +262,19 @@ int ltdb_check_special_dn(struct ldb_module *module, const struct ldb_message *m we've made a modification to a dn - possibly reindex and update sequence number */ -static int ltdb_modified(struct ldb_module *module, const char *dn) +static int ltdb_modified(struct ldb_module *module, const struct ldb_dn *dn) { int ret = 0; - if (strcmp(dn, LTDB_INDEXLIST) == 0 || - strcmp(dn, LTDB_ATTRIBUTES) == 0) { + if (ldb_dn_is_special(dn) && + (ldb_dn_check_special(dn, LTDB_INDEXLIST) || + ldb_dn_check_special(dn, LTDB_ATTRIBUTES)) ) { ret = ltdb_reindex(module); } if (ret == 0 && - strcmp(dn, LTDB_BASEINFO) != 0) { + !(ldb_dn_is_special(dn) && + ldb_dn_check_special(dn, LTDB_BASEINFO)) ) { ret = ltdb_increase_sequence_number(module); } @@ -335,7 +358,7 @@ static int ltdb_add(struct ldb_module *module, const struct ldb_message *msg) delete a record from the database, not updating indexes (used for deleting index records) */ -int ltdb_delete_noindex(struct ldb_module *module, const char *dn) +int ltdb_delete_noindex(struct ldb_module *module, const struct ldb_dn *dn) { struct ltdb_private *ltdb = module->private_data; TDB_DATA tdb_key; @@ -355,7 +378,7 @@ int ltdb_delete_noindex(struct ldb_module *module, const char *dn) /* delete a record from the database */ -static int ltdb_delete(struct ldb_module *module, const char *dn) +static int ltdb_delete(struct ldb_module *module, const struct ldb_dn *dn) { struct ltdb_private *ltdb = module->private_data; int ret; @@ -477,12 +500,18 @@ static int msg_delete_attribute(struct ldb_module *module, struct ldb_context *ldb, struct ldb_message *msg, const char *name) { + char *dn; unsigned int i, j; + dn = ldb_dn_linearize(ldb, msg->dn); + if (dn == NULL) { + return -1; + } + for (i=0;inum_elements;i++) { if (ldb_attr_cmp(msg->elements[i].name, name) == 0) { for (j=0;jelements[i].num_values;j++) { - ltdb_index_del_value(module, msg->dn, &msg->elements[i], j); + ltdb_index_del_value(module, dn, &msg->elements[i], j); } talloc_free(msg->elements[i].values); if (msg->num_elements > (i+1)) { @@ -499,6 +528,7 @@ static int msg_delete_attribute(struct ldb_module *module, } } + talloc_free(dn); return 0; } @@ -593,6 +623,7 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms struct ldb_message_element *el = &msg->elements[i]; struct ldb_message_element *el2; struct ldb_val *vals; + char *dn; switch (msg->elements[i].flags & LDB_FLAG_MOD_MASK) { @@ -650,6 +681,10 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms break; case LDB_FLAG_MOD_DELETE: + + dn = ldb_dn_linearize(msg2, msg->dn); + if (dn == NULL) goto failed; + /* we could be being asked to delete all values or just some values */ if (msg->elements[i].num_values == 0) { @@ -668,7 +703,7 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms ltdb->last_err_string = "No such attribute"; goto failed; } - if (ltdb_index_del_value(module, msg->dn, &msg->elements[i], j) != 0) { + if (ltdb_index_del_value(module, dn, &msg->elements[i], j) != 0) { goto failed; } } @@ -730,7 +765,7 @@ static int ltdb_modify(struct ldb_module *module, const struct ldb_message *msg) /* rename a record */ -static int ltdb_rename(struct ldb_module *module, const char *olddn, const char *newdn) +static int ltdb_rename(struct ldb_module *module, const struct ldb_dn *olddn, const struct ldb_dn *newdn) { struct ltdb_private *ltdb = module->private_data; int ret; @@ -761,7 +796,7 @@ static int ltdb_rename(struct ldb_module *module, const char *olddn, const char goto failed; } - msg->dn = talloc_strdup(msg, newdn); + msg->dn = ldb_dn_copy(msg, newdn); if (!msg->dn) { goto failed; } -- cgit From 8919d6bf9a88ce9ac43dae61989c33082c984b66 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sat, 17 Sep 2005 19:25:50 +0000 Subject: r10299: remove the public (un)lock functions and introduce a transaction based private ldb API ldb_sqlite3 is already working with this model and ldb_tdb will do as soon as tridge finishes the tdb transaction code. currently the transactions are always implicit and wrap any single ldb API call except searching, the transaction functions are currently not made public on purpose. Simo. (This used to be commit 1da4ac2cdcb7e54076f85242a93784260dced918) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 61d0f9b64a..c3f59a2dbe 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -825,6 +825,19 @@ failed: return -1; } +static int ltdb_start_trans(struct ldb_module *module) +{ + /* TODO: implement transactions */ + + return 0; +} + +static int ltdb_end_trans(struct ldb_module *module, int status) +{ + /* TODO: implement transactions */ + + return status; +} /* return extended error information @@ -840,16 +853,16 @@ static const char *ltdb_errstring(struct ldb_module *module) static const struct ldb_module_ops ltdb_ops = { - .name = "tdb", - .search = ltdb_search, - .search_bytree = ltdb_search_bytree, - .add_record = ltdb_add, - .modify_record = ltdb_modify, - .delete_record = ltdb_delete, - .rename_record = ltdb_rename, - .named_lock = ltdb_lock, - .named_unlock = ltdb_unlock, - .errstring = ltdb_errstring + .name = "tdb", + .search = ltdb_search, + .search_bytree = ltdb_search_bytree, + .add_record = ltdb_add, + .modify_record = ltdb_modify, + .delete_record = ltdb_delete, + .rename_record = ltdb_rename, + .start_transaction = ltdb_start_trans, + .end_transaction = ltdb_end_trans, + .errstring = ltdb_errstring }; -- 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_tdb.c | 122 ++++++++++++++++++-------------------- 1 file changed, 57 insertions(+), 65 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index c3f59a2dbe..265e04a057 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -37,6 +37,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" @@ -235,7 +236,6 @@ int ltdb_unlock_read(struct ldb_module *module) */ int ltdb_check_special_dn(struct ldb_module *module, const struct ldb_message *msg) { - struct ltdb_private *ltdb = module->private_data; int i, j; if (! ldb_dn_is_special(msg->dn) || @@ -248,8 +248,11 @@ int ltdb_check_special_dn(struct ldb_module *module, const struct ldb_message *m for (i = 0; i < msg->num_elements; i++) { for (j = 0; j < msg->elements[i].num_values; j++) { if (ltdb_check_at_attributes_values(&msg->elements[i].values[j]) != 0) { - ltdb->last_err_string = "Invalid attribute value in an @ATTRIBUTES entry"; - return -1; + char *err_string = talloc_strdup(module, "Invalid attribute value in an @ATTRIBUTES entry"); + if (err_string) { + ldb_set_errstring(module, err_string); + } + return LDB_ERR_INVALID_ATTRIBUTE_SYNTAX; } } } @@ -292,17 +295,18 @@ int ltdb_store(struct ldb_module *module, const struct ldb_message *msg, int flg tdb_key = ltdb_key(module, msg->dn); if (!tdb_key.dptr) { - return -1; + return LDB_ERR_OTHER; } ret = ltdb_pack_data(module, msg, &tdb_data); if (ret == -1) { talloc_free(tdb_key.dptr); - return -1; + return LDB_ERR_OTHER; } ret = tdb_store(ltdb->tdb, tdb_key, tdb_data, flgs); if (ret == -1) { + ret = LDB_ERR_OTHER; goto done; } @@ -324,28 +328,25 @@ done: */ static int ltdb_add(struct ldb_module *module, const struct ldb_message *msg) { - struct ltdb_private *ltdb = module->private_data; int ret; - ltdb->last_err_string = NULL; - ret = ltdb_check_special_dn(module, msg); - if (ret != 0) { + if (ret != LDB_ERR_SUCCESS) { return ret; } if (ltdb_lock(module, LDBLOCK) != 0) { - return -1; + return LDB_ERR_OTHER; } if (ltdb_cache_load(module) != 0) { ltdb_unlock(module, LDBLOCK); - return -1; + return LDB_ERR_OTHER; } ret = ltdb_store(module, msg, TDB_INSERT); - if (ret == 0) { + if (ret == LDB_ERR_SUCCESS) { ltdb_modified(module, msg->dn); } @@ -366,12 +367,14 @@ int ltdb_delete_noindex(struct ldb_module *module, const struct ldb_dn *dn) tdb_key = ltdb_key(module, dn); if (!tdb_key.dptr) { - return -1; + return LDB_ERR_OTHER; } ret = tdb_delete(ltdb->tdb, tdb_key); talloc_free(tdb_key.dptr); + if (ret != 0) ret = LDB_ERR_OTHER; + return ret; } @@ -380,14 +383,11 @@ int ltdb_delete_noindex(struct ldb_module *module, const struct ldb_dn *dn) */ static int ltdb_delete(struct ldb_module *module, const struct ldb_dn *dn) { - struct ltdb_private *ltdb = module->private_data; - int ret; struct ldb_message *msg = NULL; - - ltdb->last_err_string = NULL; + int ret = LDB_ERR_OTHER; if (ltdb_lock(module, LDBLOCK) != 0) { - return -1; + return ret; } if (ltdb_cache_load(module) != 0) { @@ -404,20 +404,21 @@ static int ltdb_delete(struct ldb_module *module, const struct ldb_dn *dn) ret = ltdb_search_dn1(module, dn, msg); if (ret != 1) { /* not finding the old record is an error */ + ret = LDB_ERR_NO_SUCH_OBJECT; goto failed; } ret = ltdb_delete_noindex(module, dn); - if (ret == -1) { + if (ret != LDB_ERR_SUCCESS) { goto failed; } /* remove any indexed attributes */ ret = ltdb_index_del(module, msg); - - if (ret == 0) { + if (ret == LDB_ERR_SUCCESS) { ltdb_modified(module, dn); - } + } else + ret = LDB_ERR_OTHER; talloc_free(msg); ltdb_unlock(module, LDBLOCK); @@ -426,7 +427,7 @@ static int ltdb_delete(struct ldb_module *module, const struct ldb_dn *dn) failed: talloc_free(msg); ltdb_unlock(module, LDBLOCK); - return -1; + return ret; } @@ -593,26 +594,26 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms tdb_key = ltdb_key(module, msg->dn); if (!tdb_key.dptr) { - return -1; + return LDB_ERR_OTHER; } tdb_data = tdb_fetch(ltdb->tdb, tdb_key); if (!tdb_data.dptr) { talloc_free(tdb_key.dptr); - return -1; + return LDB_ERR_OTHER; } msg2 = talloc(tdb_key.dptr, struct ldb_message); if (msg2 == NULL) { talloc_free(tdb_key.dptr); - return -1; + return LDB_ERR_OTHER; } ret = ltdb_unpack_data(module, &tdb_data, msg2); if (ret == -1) { talloc_free(tdb_key.dptr); free(tdb_data.dptr); - return -1; + return LDB_ERR_OTHER; } if (!msg2->dn) { @@ -623,6 +624,7 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms struct ldb_message_element *el = &msg->elements[i]; struct ldb_message_element *el2; struct ldb_val *vals; + char *err_string; char *dn; switch (msg->elements[i].flags & LDB_FLAG_MOD_MASK) { @@ -634,6 +636,7 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms if (ret == -1) { if (msg_add_element(ldb, msg2, el) != 0) { + ret = LDB_ERR_OTHER; goto failed; } continue; @@ -646,8 +649,9 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms for (j=0;jnum_values;j++) { if (ldb_msg_find_val(el2, &el->values[j])) { - ltdb->last_err_string = - "Type or value exists"; + err_string = talloc_strdup(module, "Type or value exists"); + if (err_string) ldb_set_errstring(module, err_string); + ret = LDB_ERR_ATTRIBUTE_OR_VALUE_EXISTS; goto failed; } } @@ -690,7 +694,9 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms if (msg->elements[i].num_values == 0) { if (msg_delete_attribute(module, ldb, msg2, msg->elements[i].name) != 0) { - ltdb->last_err_string = "No such attribute"; + err_string = talloc_strdup(module, "No such attribute"); + if (err_string) ldb_set_errstring(module, err_string); + ret = LDB_ERR_NO_SUCH_ATTRIBUTE; goto failed; } break; @@ -700,7 +706,9 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms msg2, msg->elements[i].name, &msg->elements[i].values[j]) != 0) { - ltdb->last_err_string = "No such attribute"; + err_string = talloc_strdup(module, "No such attribute"); + if (err_string) ldb_set_errstring(module, err_string); + ret = LDB_ERR_NO_SUCH_ATTRIBUTE; goto failed; } if (ltdb_index_del_value(module, dn, &msg->elements[i], j) != 0) { @@ -709,7 +717,9 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms } break; default: - ltdb->last_err_string = "Invalid ldb_modify flags"; + err_string = talloc_strdup(module, "Invalid ldb_modify flags"); + if (err_string) ldb_set_errstring(module, err_string); + ret = LDB_ERR_PROTOCOL_ERROR; goto failed; } } @@ -724,7 +734,7 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms failed: talloc_free(tdb_key.dptr); free(tdb_data.dptr); - return -1; + return ret; } /* @@ -732,11 +742,8 @@ failed: */ static int ltdb_modify(struct ldb_module *module, const struct ldb_message *msg) { - struct ltdb_private *ltdb = module->private_data; int ret; - ltdb->last_err_string = NULL; - ret = ltdb_check_special_dn(module, msg); if (ret != 0) { return ret; @@ -753,7 +760,7 @@ static int ltdb_modify(struct ldb_module *module, const struct ldb_message *msg) ret = ltdb_modify_internal(module, msg); - if (ret == 0) { + if (ret == LDB_ERR_SUCCESS) { ltdb_modified(module, msg->dn); } @@ -767,20 +774,17 @@ static int ltdb_modify(struct ldb_module *module, const struct ldb_message *msg) */ static int ltdb_rename(struct ldb_module *module, const struct ldb_dn *olddn, const struct ldb_dn *newdn) { - struct ltdb_private *ltdb = module->private_data; - int ret; struct ldb_message *msg; - const char *error_str; - - ltdb->last_err_string = NULL; + char *error_str; + int ret = LDB_ERR_OTHER; if (ltdb_lock(module, LDBLOCK) != 0) { - return -1; + return ret; } if (ltdb_cache_load(module) != 0) { ltdb_unlock(module, LDBLOCK); - return -1; + return ret; } msg = talloc(module, struct ldb_message); @@ -793,26 +797,28 @@ static int ltdb_rename(struct ldb_module *module, const struct ldb_dn *olddn, co ret = ltdb_search_dn1(module, olddn, msg); if (ret != 1) { /* not finding the old record is an error */ + ret = LDB_ERR_NO_SUCH_OBJECT; goto failed; } msg->dn = ldb_dn_copy(msg, newdn); if (!msg->dn) { + ret = LDB_ERR_OTHER; goto failed; } ret = ltdb_add(module, msg); - if (ret == -1) { + if (ret != LDB_ERR_SUCCESS) { goto failed; } ret = ltdb_delete(module, olddn); - error_str = ltdb->last_err_string; - if (ret == -1) { + error_str = talloc_strdup(module, ldb_errstring(module->ldb)); + if (ret != LDB_ERR_SUCCESS) { ltdb_delete(module, newdn); } - ltdb->last_err_string = error_str; + ldb_set_errstring(module, error_str); talloc_free(msg); ltdb_unlock(module, LDBLOCK); @@ -822,14 +828,14 @@ static int ltdb_rename(struct ldb_module *module, const struct ldb_dn *olddn, co failed: talloc_free(msg); ltdb_unlock(module, LDBLOCK); - return -1; + return ret; } static int ltdb_start_trans(struct ldb_module *module) { /* TODO: implement transactions */ - return 0; + return LDB_ERR_SUCCESS; } static int ltdb_end_trans(struct ldb_module *module, int status) @@ -839,19 +845,6 @@ static int ltdb_end_trans(struct ldb_module *module, int status) return status; } -/* - return extended error information -*/ -static const char *ltdb_errstring(struct ldb_module *module) -{ - struct ltdb_private *ltdb = module->private_data; - if (ltdb->last_err_string) { - return ltdb->last_err_string; - } - return tdb_errorstr(ltdb->tdb); -} - - static const struct ldb_module_ops ltdb_ops = { .name = "tdb", .search = ltdb_search, @@ -861,8 +854,7 @@ static const struct ldb_module_ops ltdb_ops = { .delete_record = ltdb_delete, .rename_record = ltdb_rename, .start_transaction = ltdb_start_trans, - .end_transaction = ltdb_end_trans, - .errstring = ltdb_errstring + .end_transaction = ltdb_end_trans }; -- cgit From ede8415d61b6791114c65de1c283a4e8c11f1585 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 22 Sep 2005 03:56:41 +0000 Subject: r10405: added transactions into tdb, and hook them into ldb. See my samba-technical posting for more details on the transactions design. This also adds a number of command line arguments to tdbtorture, making it more flexible, and fixes some lock deadlock conditions in the tdbtorture code. (This used to be commit 06bd8abba942ec9f1e23f5c5d546cbb71ca3a701) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 265e04a057..c056bd2e2d 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -833,14 +833,28 @@ failed: static int ltdb_start_trans(struct ldb_module *module) { - /* TODO: implement transactions */ + struct ltdb_private *ltdb = module->private_data; + + if (tdb_transaction_start(ltdb->tdb) != 0) { + return LDB_ERR_OPERATIONS_ERROR; + } return LDB_ERR_SUCCESS; } static int ltdb_end_trans(struct ldb_module *module, int status) { - /* TODO: implement transactions */ + struct ltdb_private *ltdb = module->private_data; + + if (status != LDB_ERR_SUCCESS) { + if (tdb_transaction_cancel(ltdb->tdb) != 0) { + return LDB_ERR_OPERATIONS_ERROR; + } + } else { + if (tdb_transaction_commit(ltdb->tdb) != 0) { + return LDB_ERR_OPERATIONS_ERROR; + } + } return status; } @@ -881,6 +895,12 @@ int ltdb_connect(struct ldb_context *ldb, const char *url, tdb_flags = TDB_DEFAULT; +#if 0 + /* set this to run tdb without disk sync, but still with + transactions */ + tdb_flags |= TDB_NOSYNC; +#endif + if (flags & LDB_FLG_RDONLY) { open_flags = O_RDONLY; } else { -- cgit From d78ea3e34abd30fb388c4cc39e12611e211416a6 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 22 Sep 2005 04:16:46 +0000 Subject: r10406: added --nosync option to all ldb tools, so that you can control if transactions are synchronous or not on the command line. add LDB_FLG_NOSYNC flag to ldb_connect() so we can make our temporary ldb databases non-synchronous (This used to be commit dba41164e0c52f1e4351bd9057b16661cee3a822) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index c056bd2e2d..a2faaa805f 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -895,11 +895,10 @@ int ltdb_connect(struct ldb_context *ldb, const char *url, tdb_flags = TDB_DEFAULT; -#if 0 - /* set this to run tdb without disk sync, but still with - transactions */ - tdb_flags |= TDB_NOSYNC; -#endif + /* check for the 'nosync' option */ + if (flags & LDB_FLG_NOSYNC) { + tdb_flags |= TDB_NOSYNC; + } if (flags & LDB_FLG_RDONLY) { open_flags = O_RDONLY; -- 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_tdb.c | 164 -------------------------------------- 1 file changed, 164 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index a2faaa805f..d8a03c3f55 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -41,9 +41,6 @@ #include "ldb/include/ldb_private.h" #include "ldb/ldb_tdb/ldb_tdb.h" -#define LDBLOCK "@INT_LDBLOCK" - - /* form a TDB_DATA for a record key caller frees @@ -95,141 +92,6 @@ failed: return key; } -/* - lock the database for write - currently a single lock is used -*/ -static int ltdb_lock(struct ldb_module *module, const char *lockname) -{ - struct ltdb_private *ltdb = module->private_data; - struct ldb_dn *lock_dn; - char *ldn; - TDB_DATA key; - int ret; - - if (lockname == NULL) { - return -1; - } - - ldn = talloc_asprintf(module->ldb, "%s_%s", LDBLOCK, lockname); - if (ldn == NULL) { - return -1; - } - - lock_dn = ldb_dn_explode(module->ldb, ldn); - if (lock_dn == NULL) { - talloc_free(ldn); - return -1; - } - talloc_free(ldn); - - key = ltdb_key(module, lock_dn); - if (!key.dptr) { - talloc_free(lock_dn); - return -1; - } - - ret = tdb_chainlock(ltdb->tdb, key); - - talloc_free(key.dptr); - talloc_free(lock_dn); - - return ret; -} - -/* - unlock the database after a ltdb_lock() -*/ -static int ltdb_unlock(struct ldb_module *module, const char *lockname) -{ - struct ltdb_private *ltdb = module->private_data; - struct ldb_dn *lock_dn; - char *ldn; - TDB_DATA key; - - if (lockname == NULL) { - return -1; - } - - ldn = talloc_asprintf(module->ldb, "%s_%s", LDBLOCK, lockname); - if (ldn == NULL) { - return -1; - } - - lock_dn = ldb_dn_explode(module->ldb, ldn); - if (lock_dn == NULL) { - talloc_free(ldn); - return -1; - } - talloc_free(ldn); - - key = ltdb_key(module, lock_dn); - if (!key.dptr) { - talloc_free(lock_dn); - return -1; - } - - tdb_chainunlock(ltdb->tdb, key); - - talloc_free(key.dptr); - talloc_free(lock_dn); - - return 0; -} - - -/* - lock the database for read - use by ltdb_search -*/ -int ltdb_lock_read(struct ldb_module *module) -{ - struct ltdb_private *ltdb = module->private_data; - TDB_DATA key; - struct ldb_dn *lock_dn; - int ret; - - lock_dn = ldb_dn_explode(module, LDBLOCK); - if (lock_dn == NULL) { - return -1; - } - - key = ltdb_key(module, lock_dn); - if (!key.dptr) { - talloc_free(lock_dn); - return -1; - } - talloc_free(lock_dn); - - ret = tdb_chainlock_read(ltdb->tdb, key); - talloc_free(key.dptr); - return ret; -} - -/* - unlock the database after a ltdb_lock_read() -*/ -int ltdb_unlock_read(struct ldb_module *module) -{ - struct ltdb_private *ltdb = module->private_data; - struct ldb_dn *lock_dn; - TDB_DATA key; - - lock_dn = ldb_dn_explode(module, LDBLOCK); - if (lock_dn == NULL) { - return -1; - } - - key = ltdb_key(module, lock_dn); - if (!key.dptr) { - talloc_free(lock_dn); - return -1; - } - talloc_free(lock_dn); - - tdb_chainunlock_read(ltdb->tdb, key); - talloc_free(key.dptr); - return 0; -} - /* check special dn's have valid attributes currently only @ATTRIBUTES is checked @@ -335,12 +197,7 @@ static int ltdb_add(struct ldb_module *module, const struct ldb_message *msg) return ret; } - if (ltdb_lock(module, LDBLOCK) != 0) { - return LDB_ERR_OTHER; - } - if (ltdb_cache_load(module) != 0) { - ltdb_unlock(module, LDBLOCK); return LDB_ERR_OTHER; } @@ -350,7 +207,6 @@ static int ltdb_add(struct ldb_module *module, const struct ldb_message *msg) ltdb_modified(module, msg->dn); } - ltdb_unlock(module, LDBLOCK); return ret; } @@ -386,10 +242,6 @@ static int ltdb_delete(struct ldb_module *module, const struct ldb_dn *dn) struct ldb_message *msg = NULL; int ret = LDB_ERR_OTHER; - if (ltdb_lock(module, LDBLOCK) != 0) { - return ret; - } - if (ltdb_cache_load(module) != 0) { goto failed; } @@ -421,12 +273,10 @@ static int ltdb_delete(struct ldb_module *module, const struct ldb_dn *dn) ret = LDB_ERR_OTHER; talloc_free(msg); - ltdb_unlock(module, LDBLOCK); return ret; failed: talloc_free(msg); - ltdb_unlock(module, LDBLOCK); return ret; } @@ -749,12 +599,7 @@ static int ltdb_modify(struct ldb_module *module, const struct ldb_message *msg) return ret; } - if (ltdb_lock(module, LDBLOCK) != 0) { - return -1; - } - if (ltdb_cache_load(module) != 0) { - ltdb_unlock(module, LDBLOCK); return -1; } @@ -764,8 +609,6 @@ static int ltdb_modify(struct ldb_module *module, const struct ldb_message *msg) ltdb_modified(module, msg->dn); } - ltdb_unlock(module, LDBLOCK); - return ret; } @@ -778,12 +621,7 @@ static int ltdb_rename(struct ldb_module *module, const struct ldb_dn *olddn, co char *error_str; int ret = LDB_ERR_OTHER; - if (ltdb_lock(module, LDBLOCK) != 0) { - return ret; - } - if (ltdb_cache_load(module) != 0) { - ltdb_unlock(module, LDBLOCK); return ret; } @@ -821,13 +659,11 @@ static int ltdb_rename(struct ldb_module *module, const struct ldb_dn *olddn, co ldb_set_errstring(module, error_str); talloc_free(msg); - ltdb_unlock(module, LDBLOCK); return ret; failed: talloc_free(msg); - ltdb_unlock(module, LDBLOCK); return ret; } -- cgit From 63b43dd12fb579aaaccedd07aaa630cb1cd7aa88 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sat, 24 Sep 2005 15:42:15 +0000 Subject: r10477: expose transactions outside ldb and change the API once more do not autostart transactions on ldb operations if a transaction is already in place test transactions on winsdb all my tests passes so far tridge please confirm this is ok for you (This used to be commit c2bb2a36bdbe0ec7519697a9a9ba7526a0defac2) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 44 ++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 19 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index d8a03c3f55..701ed602ce 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -193,7 +193,7 @@ static int ltdb_add(struct ldb_module *module, const struct ldb_message *msg) int ret; ret = ltdb_check_special_dn(module, msg); - if (ret != LDB_ERR_SUCCESS) { + if (ret != LDB_SUCCESS) { return ret; } @@ -203,7 +203,7 @@ static int ltdb_add(struct ldb_module *module, const struct ldb_message *msg) ret = ltdb_store(module, msg, TDB_INSERT); - if (ret == LDB_ERR_SUCCESS) { + if (ret == LDB_SUCCESS) { ltdb_modified(module, msg->dn); } @@ -261,13 +261,13 @@ static int ltdb_delete(struct ldb_module *module, const struct ldb_dn *dn) } ret = ltdb_delete_noindex(module, dn); - if (ret != LDB_ERR_SUCCESS) { + if (ret != LDB_SUCCESS) { goto failed; } /* remove any indexed attributes */ ret = ltdb_index_del(module, msg); - if (ret == LDB_ERR_SUCCESS) { + if (ret == LDB_SUCCESS) { ltdb_modified(module, dn); } else ret = LDB_ERR_OTHER; @@ -605,7 +605,7 @@ static int ltdb_modify(struct ldb_module *module, const struct ldb_message *msg) ret = ltdb_modify_internal(module, msg); - if (ret == LDB_ERR_SUCCESS) { + if (ret == LDB_SUCCESS) { ltdb_modified(module, msg->dn); } @@ -646,13 +646,13 @@ static int ltdb_rename(struct ldb_module *module, const struct ldb_dn *olddn, co } ret = ltdb_add(module, msg); - if (ret != LDB_ERR_SUCCESS) { + if (ret != LDB_SUCCESS) { goto failed; } ret = ltdb_delete(module, olddn); error_str = talloc_strdup(module, ldb_errstring(module->ldb)); - if (ret != LDB_ERR_SUCCESS) { + if (ret != LDB_SUCCESS) { ltdb_delete(module, newdn); } @@ -675,24 +675,29 @@ static int ltdb_start_trans(struct ldb_module *module) return LDB_ERR_OPERATIONS_ERROR; } - return LDB_ERR_SUCCESS; + return LDB_SUCCESS; } -static int ltdb_end_trans(struct ldb_module *module, int status) +static int ltdb_end_trans(struct ldb_module *module) { struct ltdb_private *ltdb = module->private_data; - if (status != LDB_ERR_SUCCESS) { - if (tdb_transaction_cancel(ltdb->tdb) != 0) { - return LDB_ERR_OPERATIONS_ERROR; - } - } else { - if (tdb_transaction_commit(ltdb->tdb) != 0) { - return LDB_ERR_OPERATIONS_ERROR; - } + if (tdb_transaction_commit(ltdb->tdb) != 0) { + return LDB_ERR_OPERATIONS_ERROR; + } + + return LDB_SUCCESS; +} + +static int ltdb_del_trans(struct ldb_module *module) +{ + struct ltdb_private *ltdb = module->private_data; + + if (tdb_transaction_cancel(ltdb->tdb) != 0) { + return LDB_ERR_OPERATIONS_ERROR; } - return status; + return LDB_SUCCESS; } static const struct ldb_module_ops ltdb_ops = { @@ -704,7 +709,8 @@ static const struct ldb_module_ops ltdb_ops = { .delete_record = ltdb_delete, .rename_record = ltdb_rename, .start_transaction = ltdb_start_trans, - .end_transaction = ltdb_end_trans + .end_transaction = ltdb_end_trans, + .del_transaction = ltdb_del_trans }; -- 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_tdb.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 701ed602ce..22360ffb1c 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -702,7 +702,6 @@ static int ltdb_del_trans(struct ldb_module *module) static const struct ldb_module_ops ltdb_ops = { .name = "tdb", - .search = ltdb_search, .search_bytree = ltdb_search_bytree, .add_record = ltdb_add, .modify_record = ltdb_modify, -- 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_tdb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 22360ffb1c..b9404a557b 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -80,7 +80,7 @@ struct TDB_DATA ltdb_key(struct ldb_module *module, const struct ldb_dn *dn) goto failed; } - key.dptr = key_str; + key.dptr = (uint8_t *)key_str; key.dsize = strlen(key_str) + 1; return key; -- cgit From d812957a3162d37ec355b2e2673f3e7297626da7 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 28 Oct 2005 03:43:39 +0000 Subject: r11353: a bit of an improvement to the ldb_tdb error handling (This used to be commit 896704f5c139c8bce30dfc898bb3a12be10035ed) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 45 +++++++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 6 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index b9404a557b..5b2feb741b 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -41,6 +41,37 @@ #include "ldb/include/ldb_private.h" #include "ldb/ldb_tdb/ldb_tdb.h" + +/* + map a tdb error code to a ldb error code +*/ +static int ltdb_err_map(enum TDB_ERROR tdb_code) +{ + switch (tdb_code) { + case TDB_SUCCESS: + return LDB_SUCCESS; + case TDB_ERR_CORRUPT: + case TDB_ERR_OOM: + case TDB_ERR_EINVAL: + return LDB_ERR_OPERATIONS_ERROR; + case TDB_ERR_IO: + return LDB_ERR_PROTOCOL_ERROR; + case TDB_ERR_LOCK: + case TDB_ERR_NOLOCK: + return LDB_ERR_BUSY; + case TDB_ERR_LOCK_TIMEOUT: + return LDB_ERR_TIME_LIMIT_EXCEEDED; + case TDB_ERR_EXISTS: + return LDB_ERR_ENTRY_ALREADY_EXISTS; + case TDB_ERR_NOEXIST: + return LDB_ERR_NO_SUCH_OBJECT; + case TDB_ERR_RDONLY: + return LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS; + } + return LDB_ERR_OTHER; +} + + /* form a TDB_DATA for a record key caller frees @@ -168,7 +199,7 @@ int ltdb_store(struct ldb_module *module, const struct ldb_message *msg, int flg ret = tdb_store(ltdb->tdb, tdb_key, tdb_data, flgs); if (ret == -1) { - ret = LDB_ERR_OTHER; + ret = ltdb_err_map(tdb_error(ltdb->tdb)); goto done; } @@ -229,7 +260,9 @@ int ltdb_delete_noindex(struct ldb_module *module, const struct ldb_dn *dn) ret = tdb_delete(ltdb->tdb, tdb_key); talloc_free(tdb_key.dptr); - if (ret != 0) ret = LDB_ERR_OTHER; + if (ret != 0) { + ret = ltdb_err_map(tdb_error(ltdb->tdb)); + } return ret; } @@ -450,7 +483,7 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms tdb_data = tdb_fetch(ltdb->tdb, tdb_key); if (!tdb_data.dptr) { talloc_free(tdb_key.dptr); - return LDB_ERR_OTHER; + return ltdb_err_map(tdb_error(ltdb->tdb)); } msg2 = talloc(tdb_key.dptr, struct ldb_message); @@ -672,7 +705,7 @@ static int ltdb_start_trans(struct ldb_module *module) struct ltdb_private *ltdb = module->private_data; if (tdb_transaction_start(ltdb->tdb) != 0) { - return LDB_ERR_OPERATIONS_ERROR; + return ltdb_err_map(tdb_error(ltdb->tdb)); } return LDB_SUCCESS; @@ -683,7 +716,7 @@ static int ltdb_end_trans(struct ldb_module *module) struct ltdb_private *ltdb = module->private_data; if (tdb_transaction_commit(ltdb->tdb) != 0) { - return LDB_ERR_OPERATIONS_ERROR; + return ltdb_err_map(tdb_error(ltdb->tdb)); } return LDB_SUCCESS; @@ -694,7 +727,7 @@ static int ltdb_del_trans(struct ldb_module *module) struct ltdb_private *ltdb = module->private_data; if (tdb_transaction_cancel(ltdb->tdb) != 0) { - return LDB_ERR_OPERATIONS_ERROR; + return ltdb_err_map(tdb_error(ltdb->tdb)); } return LDB_SUCCESS; -- 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_tdb.c | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 5b2feb741b..d1e60e0f5d 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -733,13 +733,41 @@ static int ltdb_del_trans(struct ldb_module *module) return LDB_SUCCESS; } +static int ltdb_request(struct ldb_module *module, struct ldb_request *req) +{ + switch (req->operation) { + + case LDB_REQ_SEARCH: + return ltdb_search_bytree(module, + req->op.search.base, + req->op.search.scope, + req->op.search.tree, + req->op.search.attrs, + req->op.search.res); + + case LDB_REQ_ADD: + return ltdb_add(module, req->op.add.message); + + case LDB_REQ_MODIFY: + return ltdb_modify(module, req->op.mod.message); + + case LDB_REQ_DELETE: + return ltdb_delete(module, req->op.del.dn); + + case LDB_REQ_RENAME: + return ltdb_rename(module, + req->op.rename.olddn, + req->op.rename.newdn); + + default: + return LDB_ERR_OPERATIONS_ERROR; + + } +} + static const struct ldb_module_ops ltdb_ops = { .name = "tdb", - .search_bytree = ltdb_search_bytree, - .add_record = ltdb_add, - .modify_record = ltdb_modify, - .delete_record = ltdb_delete, - .rename_record = ltdb_rename, + .request = ltdb_request, .start_transaction = ltdb_start_trans, .end_transaction = ltdb_end_trans, .del_transaction = ltdb_del_trans -- cgit From 6eabad9c9d977c1c5c6ecf7494a0be42ad113d23 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 29 Nov 2005 12:34:03 +0000 Subject: r11958: - fixed memory leaks in the ldb_result handling in ldb operations - removed an unnecessary level of pointer in ldb_search structure (This used to be commit b8d4afb14a18dfd8bac79882a035e74d3ed312bd) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index d1e60e0f5d..0de7a3e558 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -743,7 +743,7 @@ static int ltdb_request(struct ldb_module *module, struct ldb_request *req) req->op.search.scope, req->op.search.tree, req->op.search.attrs, - req->op.search.res); + &req->op.search.res); case LDB_REQ_ADD: return ltdb_add(module, req->op.add.message); -- cgit From 451797744d8c2bd2c9521a2cdada3f6b8621e2dc Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Wed, 28 Dec 2005 11:34:19 +0000 Subject: r12540: Provide more information in the ldb error string. Andrew Bartlett (This used to be commit 31f65e510cdd46b1962cf06b3d51f152b1cecf37) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 0de7a3e558..ebee029d9c 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -577,7 +577,7 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms if (msg->elements[i].num_values == 0) { if (msg_delete_attribute(module, ldb, msg2, msg->elements[i].name) != 0) { - err_string = talloc_strdup(module, "No such attribute"); + err_string = talloc_asprintf(module, "No such attribute: %s", msg->elements[i].name); if (err_string) ldb_set_errstring(module, err_string); ret = LDB_ERR_NO_SUCH_ATTRIBUTE; goto failed; @@ -589,7 +589,7 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms msg2, msg->elements[i].name, &msg->elements[i].values[j]) != 0) { - err_string = talloc_strdup(module, "No such attribute"); + err_string = talloc_asprintf(module, "No such attribute: %s", msg->elements[i].name); if (err_string) ldb_set_errstring(module, err_string); ret = LDB_ERR_NO_SUCH_ATTRIBUTE; goto failed; @@ -600,7 +600,9 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms } break; default: - err_string = talloc_strdup(module, "Invalid ldb_modify flags"); + err_string = talloc_asprintf(module, "Invalid ldb_modify flags on %s: 0x%x", + msg->elements[i].name, + msg->elements[i].flags & LDB_FLAG_MOD_MASK); if (err_string) ldb_set_errstring(module, err_string); ret = LDB_ERR_PROTOCOL_ERROR; goto failed; -- 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_tdb.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index ebee029d9c..432c713336 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -737,6 +737,12 @@ static int ltdb_del_trans(struct ldb_module *module) static int ltdb_request(struct ldb_module *module, struct ldb_request *req) { + /* check for oustanding critical controls and return an error if found */ + + if (check_critical_controls(req->controls)) { + return LDB_ERR_UNSUPPORTED_CRITICAL_EXTENSION; + } + switch (req->operation) { case LDB_REQ_SEARCH: -- cgit From dbef4d76de92c3388f4e1819a76d6febf90be290 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Fri, 6 Jan 2006 16:12:45 +0000 Subject: r12743: Remove the ugly way we had to make a second stage init and introduce a second_stage_init private function for modules that need a second stage init. Simo. (This used to be commit 5e8b365fa2d93801a5de1d9ea76ce9d5546bd248) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 432c713336..0a9a99ccea 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -773,12 +773,18 @@ static int ltdb_request(struct ldb_module *module, struct ldb_request *req) } } +static int ltdb_init_2(struct ldb_module *module) +{ + return LDB_SUCCESS; +} + static const struct ldb_module_ops ltdb_ops = { .name = "tdb", .request = ltdb_request, .start_transaction = ltdb_start_trans, .end_transaction = ltdb_end_trans, - .del_transaction = ltdb_del_trans + .del_transaction = ltdb_del_trans, + .second_stage_init = ltdb_init_2 }; -- 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_tdb.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 0a9a99ccea..1be11bc64c 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -36,9 +36,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 d590dea10b3abf93fcc8138189291e8b66bae7d7 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Wed, 22 Feb 2006 05:21:43 +0000 Subject: r13615: Make ldb_set_errstring get ldb instead of module as parameter. The module was just used to get to the ldb so it was meningless. Also add LDB_WAIT_ONCE e relative code in ldb_ildap.c (This used to be commit d5b467b7c132b0bd4d23918ba7bf3370b1afcce8) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 1be11bc64c..8d8c01278d 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -142,7 +142,7 @@ int ltdb_check_special_dn(struct ldb_module *module, const struct ldb_message *m if (ltdb_check_at_attributes_values(&msg->elements[i].values[j]) != 0) { char *err_string = talloc_strdup(module, "Invalid attribute value in an @ATTRIBUTES entry"); if (err_string) { - ldb_set_errstring(module, err_string); + ldb_set_errstring(module->ldb, err_string); } return LDB_ERR_INVALID_ATTRIBUTE_SYNTAX; } @@ -532,7 +532,7 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms for (j=0;jnum_values;j++) { if (ldb_msg_find_val(el2, &el->values[j])) { err_string = talloc_strdup(module, "Type or value exists"); - if (err_string) ldb_set_errstring(module, err_string); + if (err_string) ldb_set_errstring(module->ldb, err_string); ret = LDB_ERR_ATTRIBUTE_OR_VALUE_EXISTS; goto failed; } @@ -577,7 +577,7 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms if (msg_delete_attribute(module, ldb, msg2, msg->elements[i].name) != 0) { err_string = talloc_asprintf(module, "No such attribute: %s", msg->elements[i].name); - if (err_string) ldb_set_errstring(module, err_string); + if (err_string) ldb_set_errstring(module->ldb, err_string); ret = LDB_ERR_NO_SUCH_ATTRIBUTE; goto failed; } @@ -589,7 +589,7 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms msg->elements[i].name, &msg->elements[i].values[j]) != 0) { err_string = talloc_asprintf(module, "No such attribute: %s", msg->elements[i].name); - if (err_string) ldb_set_errstring(module, err_string); + if (err_string) ldb_set_errstring(module->ldb, err_string); ret = LDB_ERR_NO_SUCH_ATTRIBUTE; goto failed; } @@ -602,7 +602,7 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms err_string = talloc_asprintf(module, "Invalid ldb_modify flags on %s: 0x%x", msg->elements[i].name, msg->elements[i].flags & LDB_FLAG_MOD_MASK); - if (err_string) ldb_set_errstring(module, err_string); + if (err_string) ldb_set_errstring(module->ldb, err_string); ret = LDB_ERR_PROTOCOL_ERROR; goto failed; } @@ -690,7 +690,7 @@ static int ltdb_rename(struct ldb_module *module, const struct ldb_dn *olddn, co ltdb_delete(module, newdn); } - ldb_set_errstring(module, error_str); + ldb_set_errstring(module->ldb, error_str); talloc_free(msg); -- cgit From 57d5f19b3f032dfcecde9883651c6df8b18a8b58 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 27 Feb 2006 00:39:26 +0000 Subject: r13700: added highestCommittedUSN, uSNChanged and uSNCreated support, using the @BASEINFO sequenceNumber (simo, I changed the function pointer to a structure element as you preferred) (This used to be commit 68c9ac38c7eed221b44499ee3d74597063dfe7a1) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 8d8c01278d..b58b03f221 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -772,6 +772,31 @@ static int ltdb_request(struct ldb_module *module, struct ldb_request *req) } } +/* + return sequenceNumber from @BASEINFO +*/ +static uint64_t ltdb_sequence_number(struct ldb_context *ldb) +{ + TALLOC_CTX *tmp_ctx = talloc_new(ldb); + const char *attrs[] = { "sequenceNumber", NULL }; + struct ldb_result *res = NULL; + struct ldb_dn *dn = ldb_dn_explode(tmp_ctx, "@BASEINFO"); + int ret; + uint64_t seq_num; + + ret = ldb_search(ldb, dn, LDB_SCOPE_BASE, NULL, attrs, &res); + talloc_steal(tmp_ctx, res); + if (ret != LDB_SUCCESS || res->count != 1) { + talloc_free(tmp_ctx); + /* zero is as good as anything when we don't know */ + return 0; + } + + seq_num = ldb_msg_find_uint64(res->msgs[0], "sequenceNumber", 0); + talloc_free(tmp_ctx); + return seq_num; +} + static int ltdb_init_2(struct ldb_module *module) { return LDB_SUCCESS; @@ -847,6 +872,7 @@ int ltdb_connect(struct ldb_context *ldb, const char *url, ldb->modules->prev = ldb->modules->next = NULL; ldb->modules->private_data = ltdb; ldb->modules->ops = <db_ops; + ldb->sequence_number = ltdb_sequence_number; return 0; } -- cgit From 26af14c39b88b0e7eb53657b89be65d865804688 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 2 Mar 2006 16:32:53 +0000 Subject: r13786: [merge] Add registration functions for LDB modules Applications that use LDB modules will now have to run ldb_global_init() before they can use LDB. The next step will be adding support for loading LDB modules from .so files. This will also allow us to use one LDB without difference between the standalone and the Samba-specific build (This used to be commit 52a235650514039bf8ffee99a784bbc1b6ae6b92) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index b58b03f221..7cf6138b12 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -797,18 +797,12 @@ static uint64_t ltdb_sequence_number(struct ldb_context *ldb) return seq_num; } -static int ltdb_init_2(struct ldb_module *module) -{ - return LDB_SUCCESS; -} - static const struct ldb_module_ops ltdb_ops = { .name = "tdb", .request = ltdb_request, .start_transaction = ltdb_start_trans, .end_transaction = ltdb_end_trans, - .del_transaction = ltdb_del_trans, - .second_stage_init = ltdb_init_2 + .del_transaction = ltdb_del_trans }; -- 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_tdb.c | 316 +++++++++++++++++++++++++++++++++----- 1 file changed, 277 insertions(+), 39 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 7cf6138b12..04766c53a1 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -3,6 +3,7 @@ Copyright (C) Andrew Tridgell 2004 Copyright (C) Stefan Metzmacher 2004 + Copyright (C) Simo Sorce 2006 ** NOTE! The following LGPL license applies to the ldb @@ -25,7 +26,7 @@ */ /* - * Name: ldb + * Name: ldb_tdb * * Component: ldb tdb backend * @@ -33,6 +34,12 @@ * * Author: Andrew Tridgell * Author: Stefan Metzmacher + * + * Modifications: + * + * - description: make the module use asyncronous calls + * date: Feb 2006 + * Author: Simo Sorce */ #include "includes.h" @@ -71,6 +78,37 @@ static int ltdb_err_map(enum TDB_ERROR tdb_code) } +struct ldb_async_handle *init_ltdb_handle(struct ltdb_private *ltdb, struct ldb_module *module, + void *context, + int (*callback)(struct ldb_context *, void *, struct ldb_async_result *), + int timeout) +{ + struct ltdb_async_context *ac; + struct ldb_async_handle *h; + + h = talloc_zero(ltdb, struct ldb_async_handle); + if (h == NULL) { + ldb_set_errstring(module->ldb, talloc_asprintf(module, "Out of Memory")); + return NULL; + } + + ac = talloc_zero(h, struct ltdb_async_context); + if (ac == NULL) { + ldb_set_errstring(module->ldb, talloc_asprintf(module, "Out of Memory")); + talloc_free(h); + return NULL; + } + + h->private_data = (void *)ac; + + ac->module = module; + ac->context = context; + ac->callback = callback; + ac->timeout = timeout; + + return h; +} + /* form a TDB_DATA for a record key caller frees @@ -218,28 +256,65 @@ done: /* add a record to the database */ -static int ltdb_add(struct ldb_module *module, const struct ldb_message *msg) +static int ltdb_add_async(struct ldb_module *module, const struct ldb_message *msg, + void *context, + int (*callback)(struct ldb_context *, void *, struct ldb_async_result *), + int timeout, + struct ldb_async_handle **handle) { - int ret; + struct ltdb_private *ltdb = talloc_get_type(module->private_data, struct ltdb_private); + struct ltdb_async_context *ltdb_ac; + int ret = LDB_ERR_OPERATIONS_ERROR; + + *handle = init_ltdb_handle(ltdb, module, context, callback, timeout); + if (*handle == NULL) { + return ret; + } + ltdb_ac = talloc_get_type((*handle)->private_data, struct ltdb_async_context); + (*handle)->state = LDB_ASYNC_DONE; + (*handle)->status = LDB_SUCCESS; ret = ltdb_check_special_dn(module, msg); if (ret != LDB_SUCCESS) { + talloc_free(*handle); return ret; } if (ltdb_cache_load(module) != 0) { + talloc_free(*handle); return LDB_ERR_OTHER; } ret = ltdb_store(module, msg, TDB_INSERT); - if (ret == LDB_SUCCESS) { - ltdb_modified(module, msg->dn); + if (ret != LDB_SUCCESS) { + (*handle)->status = ret; + return LDB_SUCCESS; } - return ret; + ltdb_modified(module, msg->dn); + + if (ltdb_ac->callback) + (*handle)->status = ltdb_ac->callback(module->ldb, ltdb_ac->context, NULL); + + return LDB_SUCCESS; } +static int ltdb_add(struct ldb_module *module, const struct ldb_message *msg) +{ + struct ldb_async_handle *handle; + int ret; + + ret = ltdb_add_async(module, msg, NULL, NULL, 0, &handle); + + if (ret != LDB_SUCCESS) + return ret; + + ret = ldb_async_wait(module->ldb, handle, LDB_WAIT_ALL); + + talloc_free(handle); + return ret; +} /* delete a record from the database, not updating indexes (used for deleting @@ -269,16 +344,32 @@ int ltdb_delete_noindex(struct ldb_module *module, const struct ldb_dn *dn) /* delete a record from the database */ -static int ltdb_delete(struct ldb_module *module, const struct ldb_dn *dn) +static int ltdb_delete_async(struct ldb_module *module, const struct ldb_dn *dn, + void *context, + int (*callback)(struct ldb_context *, void *, struct ldb_async_result *), + int timeout, + struct ldb_async_handle **handle) { - struct ldb_message *msg = NULL; - int ret = LDB_ERR_OTHER; + struct ltdb_private *ltdb = talloc_get_type(module->private_data, struct ltdb_private); + struct ltdb_async_context *ltdb_ac; + struct ldb_message *msg; + int ret = LDB_ERR_OPERATIONS_ERROR; + + *handle = NULL; if (ltdb_cache_load(module) != 0) { goto failed; } - msg = talloc(module, struct ldb_message); + *handle = init_ltdb_handle(ltdb, module, context, callback, timeout); + if (*handle == NULL) { + goto failed; + } + ltdb_ac = talloc_get_type((*handle)->private_data, struct ltdb_async_context); + (*handle)->state = LDB_ASYNC_DONE; + (*handle)->status = LDB_SUCCESS; + + msg = talloc(ltdb_ac, struct ldb_message); if (msg == NULL) { goto failed; } @@ -288,8 +379,8 @@ static int ltdb_delete(struct ldb_module *module, const struct ldb_dn *dn) ret = ltdb_search_dn1(module, dn, msg); if (ret != 1) { /* not finding the old record is an error */ - ret = LDB_ERR_NO_SUCH_OBJECT; - goto failed; + (*handle)->status = LDB_ERR_NO_SUCH_OBJECT; + return LDB_SUCCESS; } ret = ltdb_delete_noindex(module, dn); @@ -299,16 +390,35 @@ static int ltdb_delete(struct ldb_module *module, const struct ldb_dn *dn) /* remove any indexed attributes */ ret = ltdb_index_del(module, msg); - if (ret == LDB_SUCCESS) { - ltdb_modified(module, dn); - } else - ret = LDB_ERR_OTHER; + if (ret) { + goto failed; + } + ltdb_modified(module, dn); - talloc_free(msg); - return ret; + if (ltdb_ac->callback) + (*handle)->status = ltdb_ac->callback(module->ldb, ltdb_ac->context, NULL); + + return LDB_SUCCESS; failed: - talloc_free(msg); + talloc_free(*handle); + return ret; +} + +static int ltdb_delete(struct ldb_module *module, const struct ldb_dn *dn) +{ + struct ldb_async_handle *handle; + int ret; + + ret = ltdb_delete_async(module, dn, + NULL, NULL, 0, &handle); + + if (ret != LDB_SUCCESS) + return ret; + + ret = ldb_async_wait(module->ldb, handle, LDB_WAIT_ALL); + + talloc_free(handle); return ret; } @@ -624,42 +734,97 @@ failed: /* modify a record */ -static int ltdb_modify(struct ldb_module *module, const struct ldb_message *msg) +static int ltdb_modify_async(struct ldb_module *module, const struct ldb_message *msg, + void *context, + int (*callback)(struct ldb_context *, void *, struct ldb_async_result *), + int timeout, + struct ldb_async_handle **handle) { - int ret; + struct ltdb_private *ltdb = talloc_get_type(module->private_data, struct ltdb_private); + struct ltdb_async_context *ltdb_ac; + int ret = LDB_ERR_OPERATIONS_ERROR; + + *handle = NULL; + + *handle = init_ltdb_handle(ltdb, module, context, callback, timeout); + if (*handle == NULL) { + return ret; + } + ltdb_ac = talloc_get_type((*handle)->private_data, struct ltdb_async_context); + (*handle)->state = LDB_ASYNC_DONE; + (*handle)->status = LDB_SUCCESS; ret = ltdb_check_special_dn(module, msg); - if (ret != 0) { + if (ret != LDB_SUCCESS) { + talloc_free(*handle); return ret; } if (ltdb_cache_load(module) != 0) { - return -1; + talloc_free(*handle); + return LDB_ERR_OTHER; } ret = ltdb_modify_internal(module, msg); - if (ret == LDB_SUCCESS) { - ltdb_modified(module, msg->dn); + if (ret != LDB_SUCCESS) { + (*handle)->status = ret; + return LDB_SUCCESS; } + ltdb_modified(module, msg->dn); + + if (ltdb_ac->callback) + (*handle)->status = ltdb_ac->callback(module->ldb, ltdb_ac->context, NULL); + + return LDB_SUCCESS; +} + +static int ltdb_modify(struct ldb_module *module, const struct ldb_message *msg) +{ + struct ldb_async_handle *handle; + int ret; + + ret = ltdb_modify_async(module, msg, NULL, NULL, 0, &handle); + + if (ret != LDB_SUCCESS) + return ret; + + ret = ldb_async_wait(module->ldb, handle, LDB_WAIT_ALL); + + talloc_free(handle); return ret; } /* rename a record */ -static int ltdb_rename(struct ldb_module *module, const struct ldb_dn *olddn, const struct ldb_dn *newdn) +static int ltdb_rename_async(struct ldb_module *module, const struct ldb_dn *olddn, const struct ldb_dn *newdn, + void *context, + int (*callback)(struct ldb_context *, void *, struct ldb_async_result *), + 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; struct ldb_message *msg; - char *error_str; - int ret = LDB_ERR_OTHER; + int ret = LDB_ERR_OPERATIONS_ERROR; + + *handle = NULL; if (ltdb_cache_load(module) != 0) { return ret; } - msg = talloc(module, struct ldb_message); + *handle = init_ltdb_handle(ltdb, module, context, callback, timeout); + if (*handle == NULL) { + goto failed; + } + ltdb_ac = talloc_get_type((*handle)->private_data, struct ltdb_async_context); + (*handle)->state = LDB_ASYNC_DONE; + (*handle)->status = LDB_SUCCESS; + + msg = talloc(ltdb_ac, struct ldb_message); if (msg == NULL) { goto failed; } @@ -669,35 +834,53 @@ static int ltdb_rename(struct ldb_module *module, const struct ldb_dn *olddn, co ret = ltdb_search_dn1(module, olddn, msg); if (ret != 1) { /* not finding the old record is an error */ - ret = LDB_ERR_NO_SUCH_OBJECT; - goto failed; + (*handle)->status = LDB_ERR_NO_SUCH_OBJECT; + return LDB_SUCCESS; } msg->dn = ldb_dn_copy(msg, newdn); if (!msg->dn) { - ret = LDB_ERR_OTHER; + ret = LDB_ERR_OPERATIONS_ERROR; goto failed; } ret = ltdb_add(module, msg); if (ret != LDB_SUCCESS) { - goto failed; + (*handle)->status = LDB_ERR_OPERATIONS_ERROR; + return LDB_SUCCESS; } ret = ltdb_delete(module, olddn); - error_str = talloc_strdup(module, ldb_errstring(module->ldb)); if (ret != LDB_SUCCESS) { ltdb_delete(module, newdn); + (*handle)->status = ret; + return LDB_SUCCESS; } - ldb_set_errstring(module->ldb, error_str); + if (ltdb_ac->callback) + (*handle)->status = ltdb_ac->callback(module->ldb, ltdb_ac->context, NULL); - talloc_free(msg); + return LDB_SUCCESS; +failed: + talloc_free(*handle); return ret; +} -failed: - talloc_free(msg); +static int ltdb_rename(struct ldb_module *module, const struct ldb_dn *olddn, const struct ldb_dn *newdn) +{ + struct ldb_async_handle *handle; + int ret; + + ret = ltdb_rename_async(module, olddn, newdn, + NULL, NULL, 0, &handle); + + if (ret != LDB_SUCCESS) + return ret; + + ret = ldb_async_wait(module->ldb, handle, LDB_WAIT_ALL); + + talloc_free(handle); return ret; } @@ -734,10 +917,19 @@ static int ltdb_del_trans(struct ldb_module *module) return LDB_SUCCESS; } +static int ltdb_async_wait(struct ldb_async_handle *handle, enum ldb_async_wait_type type) +{ + return handle->status; +} + static int ltdb_request(struct ldb_module *module, struct ldb_request *req) { /* check for oustanding critical controls and return an error if found */ + if (req->controls != NULL) { + ldb_debug(module->ldb, LDB_DEBUG_WARNING, "Controls should not reach the ldb_tdb backend!\n"); + } + if (check_critical_controls(req->controls)) { return LDB_ERR_UNSUPPORTED_CRITICAL_EXTENSION; } @@ -749,7 +941,7 @@ static int ltdb_request(struct ldb_module *module, struct ldb_request *req) req->op.search.base, req->op.search.scope, req->op.search.tree, - req->op.search.attrs, + req->op.search.attrs, &req->op.search.res); case LDB_REQ_ADD: @@ -766,6 +958,50 @@ static int ltdb_request(struct ldb_module *module, struct ldb_request *req) req->op.rename.olddn, req->op.rename.newdn); + case LDB_ASYNC_SEARCH: + return ltdb_search_async(module, + req->op.search.base, + req->op.search.scope, + req->op.search.tree, + req->op.search.attrs, + req->async.context, + req->async.callback, + req->async.timeout, + &req->async.handle); + + case LDB_ASYNC_ADD: + return ltdb_add_async(module, + req->op.add.message, + req->async.context, + req->async.callback, + req->async.timeout, + &req->async.handle); + + case LDB_ASYNC_MODIFY: + return ltdb_modify_async(module, + req->op.mod.message, + req->async.context, + req->async.callback, + req->async.timeout, + &req->async.handle); + + case LDB_ASYNC_DELETE: + return ltdb_delete_async(module, + req->op.del.dn, + req->async.context, + req->async.callback, + req->async.timeout, + &req->async.handle); + + case LDB_ASYNC_RENAME: + return ltdb_rename_async(module, + req->op.rename.olddn, + req->op.rename.newdn, + req->async.context, + req->async.callback, + req->async.timeout, + &req->async.handle); + default: return LDB_ERR_OPERATIONS_ERROR; @@ -868,5 +1104,7 @@ int ltdb_connect(struct ldb_context *ldb, const char *url, ldb->modules->ops = <db_ops; ldb->sequence_number = ltdb_sequence_number; + ldb->async_wait = <db_async_wait; + return 0; } -- 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_tdb.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 04766c53a1..da9596199a 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -917,7 +917,7 @@ static int ltdb_del_trans(struct ldb_module *module) return LDB_SUCCESS; } -static int ltdb_async_wait(struct ldb_async_handle *handle, enum ldb_async_wait_type type) +static int ltdb_async_wait(struct ldb_module *module, struct ldb_async_handle *handle, enum ldb_async_wait_type type) { return handle->status; } @@ -1038,7 +1038,8 @@ static const struct ldb_module_ops ltdb_ops = { .request = ltdb_request, .start_transaction = ltdb_start_trans, .end_transaction = ltdb_end_trans, - .del_transaction = ltdb_del_trans + .del_transaction = ltdb_del_trans, + .async_wait = ltdb_async_wait }; @@ -1104,7 +1105,5 @@ int ltdb_connect(struct ldb_context *ldb, const char *url, ldb->modules->ops = <db_ops; ldb->sequence_number = ltdb_sequence_number; - ldb->async_wait = <db_async_wait; - return 0; } -- 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_tdb.c | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index da9596199a..0825348658 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -80,8 +80,7 @@ static int ltdb_err_map(enum TDB_ERROR tdb_code) struct ldb_async_handle *init_ltdb_handle(struct ltdb_private *ltdb, struct ldb_module *module, void *context, - int (*callback)(struct ldb_context *, void *, struct ldb_async_result *), - int timeout) + int (*callback)(struct ldb_context *, void *, struct ldb_async_result *)) { struct ltdb_async_context *ac; struct ldb_async_handle *h; @@ -104,7 +103,6 @@ struct ldb_async_handle *init_ltdb_handle(struct ltdb_private *ltdb, struct ldb_ ac->module = module; ac->context = context; ac->callback = callback; - ac->timeout = timeout; return h; } @@ -259,14 +257,13 @@ done: static int ltdb_add_async(struct ldb_module *module, const struct ldb_message *msg, void *context, int (*callback)(struct ldb_context *, void *, struct ldb_async_result *), - 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 = LDB_ERR_OPERATIONS_ERROR; - *handle = init_ltdb_handle(ltdb, module, context, callback, timeout); + *handle = init_ltdb_handle(ltdb, module, context, callback); if (*handle == NULL) { return ret; } @@ -305,7 +302,7 @@ static int ltdb_add(struct ldb_module *module, const struct ldb_message *msg) struct ldb_async_handle *handle; int ret; - ret = ltdb_add_async(module, msg, NULL, NULL, 0, &handle); + ret = ltdb_add_async(module, msg, NULL, NULL, &handle); if (ret != LDB_SUCCESS) return ret; @@ -347,7 +344,6 @@ int ltdb_delete_noindex(struct ldb_module *module, const struct ldb_dn *dn) static int ltdb_delete_async(struct ldb_module *module, const struct ldb_dn *dn, void *context, int (*callback)(struct ldb_context *, void *, struct ldb_async_result *), - int timeout, struct ldb_async_handle **handle) { struct ltdb_private *ltdb = talloc_get_type(module->private_data, struct ltdb_private); @@ -361,7 +357,7 @@ static int ltdb_delete_async(struct ldb_module *module, const struct ldb_dn *dn, goto failed; } - *handle = init_ltdb_handle(ltdb, module, context, callback, timeout); + *handle = init_ltdb_handle(ltdb, module, context, callback); if (*handle == NULL) { goto failed; } @@ -410,8 +406,7 @@ static int ltdb_delete(struct ldb_module *module, const struct ldb_dn *dn) struct ldb_async_handle *handle; int ret; - ret = ltdb_delete_async(module, dn, - NULL, NULL, 0, &handle); + ret = ltdb_delete_async(module, dn, NULL, NULL, &handle); if (ret != LDB_SUCCESS) return ret; @@ -737,7 +732,6 @@ failed: static int ltdb_modify_async(struct ldb_module *module, const struct ldb_message *msg, void *context, int (*callback)(struct ldb_context *, void *, struct ldb_async_result *), - int timeout, struct ldb_async_handle **handle) { struct ltdb_private *ltdb = talloc_get_type(module->private_data, struct ltdb_private); @@ -746,7 +740,7 @@ static int ltdb_modify_async(struct ldb_module *module, const struct ldb_message *handle = NULL; - *handle = init_ltdb_handle(ltdb, module, context, callback, timeout); + *handle = init_ltdb_handle(ltdb, module, context, callback); if (*handle == NULL) { return ret; } @@ -785,7 +779,7 @@ static int ltdb_modify(struct ldb_module *module, const struct ldb_message *msg) struct ldb_async_handle *handle; int ret; - ret = ltdb_modify_async(module, msg, NULL, NULL, 0, &handle); + ret = ltdb_modify_async(module, msg, NULL, NULL, &handle); if (ret != LDB_SUCCESS) return ret; @@ -802,7 +796,6 @@ static int ltdb_modify(struct ldb_module *module, const struct ldb_message *msg) static int ltdb_rename_async(struct ldb_module *module, const struct ldb_dn *olddn, const struct ldb_dn *newdn, void *context, int (*callback)(struct ldb_context *, void *, struct ldb_async_result *), - int timeout, struct ldb_async_handle **handle) { struct ltdb_private *ltdb = talloc_get_type(module->private_data, struct ltdb_private); @@ -816,7 +809,7 @@ static int ltdb_rename_async(struct ldb_module *module, const struct ldb_dn *old return ret; } - *handle = init_ltdb_handle(ltdb, module, context, callback, timeout); + *handle = init_ltdb_handle(ltdb, module, context, callback); if (*handle == NULL) { goto failed; } @@ -872,8 +865,7 @@ static int ltdb_rename(struct ldb_module *module, const struct ldb_dn *olddn, co struct ldb_async_handle *handle; int ret; - ret = ltdb_rename_async(module, olddn, newdn, - NULL, NULL, 0, &handle); + ret = ltdb_rename_async(module, olddn, newdn, NULL, NULL, &handle); if (ret != LDB_SUCCESS) return ret; @@ -966,7 +958,6 @@ static int ltdb_request(struct ldb_module *module, struct ldb_request *req) req->op.search.attrs, req->async.context, req->async.callback, - req->async.timeout, &req->async.handle); case LDB_ASYNC_ADD: @@ -974,7 +965,6 @@ static int ltdb_request(struct ldb_module *module, struct ldb_request *req) req->op.add.message, req->async.context, req->async.callback, - req->async.timeout, &req->async.handle); case LDB_ASYNC_MODIFY: @@ -982,7 +972,6 @@ static int ltdb_request(struct ldb_module *module, struct ldb_request *req) req->op.mod.message, req->async.context, req->async.callback, - req->async.timeout, &req->async.handle); case LDB_ASYNC_DELETE: @@ -990,7 +979,6 @@ static int ltdb_request(struct ldb_module *module, struct ldb_request *req) req->op.del.dn, req->async.context, req->async.callback, - req->async.timeout, &req->async.handle); case LDB_ASYNC_RENAME: @@ -999,7 +987,6 @@ static int ltdb_request(struct ldb_module *module, struct ldb_request *req) req->op.rename.newdn, req->async.context, req->async.callback, - req->async.timeout, &req->async.handle); default: -- cgit From 5d0aa16dfcf3047a52d3dd7e12ffb704a9725e83 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 5 Mar 2006 16:05:26 +0000 Subject: r13839: Use registration mechanism for backends as well (in the same sense my previous patch added it for modules). This is the next step towards LDB backends and modules as run-time loadable .so files. (This used to be commit fb2f70de4f6c4a9b13ad590cb4d3a9c858cede49) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 0825348658..5470fccb97 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -1033,7 +1033,7 @@ static const struct ldb_module_ops ltdb_ops = { /* connect to the database */ -int ltdb_connect(struct ldb_context *ldb, const char *url, +static int ltdb_connect(struct ldb_context *ldb, const char *url, unsigned int flags, const char *options[]) { const char *path; @@ -1094,3 +1094,8 @@ int ltdb_connect(struct ldb_context *ldb, const char *url, return 0; } + +int ldb_tdb_init(void) +{ + return ldb_register_backend("tdb:", ltdb_connect); +} -- cgit From 7b82c4beb93375f79b6c06fc86bb31873baa187b Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Tue, 7 Mar 2006 21:08:09 +0000 Subject: r13992: change the way ldb_async_wait() works. I think I should change the name of this function to ldb_async_process(), any opinions ? (This used to be commit 3347322d1327cfa975ee9dccd4f2774e6e14fbcb) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 5470fccb97..c0e070de69 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -91,6 +91,8 @@ struct ldb_async_handle *init_ltdb_handle(struct ltdb_private *ltdb, struct ldb_ return NULL; } + h->module = module; + ac = talloc_zero(h, struct ltdb_async_context); if (ac == NULL) { ldb_set_errstring(module->ldb, talloc_asprintf(module, "Out of Memory")); @@ -909,7 +911,7 @@ static int ltdb_del_trans(struct ldb_module *module) return LDB_SUCCESS; } -static int ltdb_async_wait(struct ldb_module *module, struct ldb_async_handle *handle, enum ldb_async_wait_type type) +static int ltdb_async_wait(struct ldb_async_handle *handle, enum ldb_async_wait_type type) { return handle->status; } -- 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_tdb.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index c0e070de69..a77553dcb8 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -309,7 +309,7 @@ static int ltdb_add(struct ldb_module *module, const struct ldb_message *msg) if (ret != LDB_SUCCESS) return ret; - ret = ldb_async_wait(module->ldb, handle, LDB_WAIT_ALL); + ret = ldb_async_wait(handle, LDB_WAIT_ALL); talloc_free(handle); return ret; @@ -413,7 +413,7 @@ static int ltdb_delete(struct ldb_module *module, const struct ldb_dn *dn) if (ret != LDB_SUCCESS) return ret; - ret = ldb_async_wait(module->ldb, handle, LDB_WAIT_ALL); + ret = ldb_async_wait(handle, LDB_WAIT_ALL); talloc_free(handle); return ret; @@ -786,7 +786,7 @@ static int ltdb_modify(struct ldb_module *module, const struct ldb_message *msg) if (ret != LDB_SUCCESS) return ret; - ret = ldb_async_wait(module->ldb, handle, LDB_WAIT_ALL); + ret = ldb_async_wait(handle, LDB_WAIT_ALL); talloc_free(handle); return ret; @@ -872,7 +872,7 @@ static int ltdb_rename(struct ldb_module *module, const struct ldb_dn *olddn, co if (ret != LDB_SUCCESS) return ret; - ret = ldb_async_wait(module->ldb, handle, LDB_WAIT_ALL); + ret = ldb_async_wait(handle, LDB_WAIT_ALL); talloc_free(handle); return ret; -- cgit From 3baf0606040419988f1a08c0da7f546c5904d8ca Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Fri, 10 Mar 2006 15:27:16 +0000 Subject: r14161: return early if we know the job is already finished (This used to be commit 09f6f552d73f782dc8d62cefad9c5f584b7b07d2) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index a77553dcb8..bc936eb71e 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -102,6 +102,9 @@ struct ldb_async_handle *init_ltdb_handle(struct ltdb_private *ltdb, struct ldb_ h->private_data = (void *)ac; + h->state = LDB_ASYNC_INIT; + h->status = LDB_SUCCESS; + ac->module = module; ac->context = context; ac->callback = callback; -- cgit From bb1909e15e7a9f3cd79da2ce8b8ef90f1a557376 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 20 Mar 2006 21:44:59 +0000 Subject: r14592: Add support for loading shared modules to LDB. (This used to be commit f10fae23f0685b2d9c6174596e1c66d799f02c52) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index bc936eb71e..3a1a08aafd 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -1102,5 +1102,5 @@ static int ltdb_connect(struct ldb_context *ldb, const char *url, int ldb_tdb_init(void) { - return ldb_register_backend("tdb:", ltdb_connect); + return ldb_register_backend("tdb", ltdb_connect); } -- 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_tdb.c | 153 +++++++++++++++++++------------------- 1 file changed, 75 insertions(+), 78 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 3a1a08aafd..e0465afb30 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -266,40 +266,41 @@ static int ltdb_add_async(struct ldb_module *module, const struct ldb_message *m { struct ltdb_private *ltdb = talloc_get_type(module->private_data, struct ltdb_private); struct ltdb_async_context *ltdb_ac; - int ret = LDB_ERR_OPERATIONS_ERROR; + int tret, ret = LDB_SUCCESS; *handle = init_ltdb_handle(ltdb, module, context, callback); if (*handle == NULL) { - return ret; + return LDB_ERR_OPERATIONS_ERROR; } ltdb_ac = talloc_get_type((*handle)->private_data, struct ltdb_async_context); - (*handle)->state = LDB_ASYNC_DONE; - (*handle)->status = LDB_SUCCESS; - ret = ltdb_check_special_dn(module, msg); - if (ret != LDB_SUCCESS) { - talloc_free(*handle); - return ret; + tret = ltdb_check_special_dn(module, msg); + if (tret != LDB_SUCCESS) { + (*handle)->status = tret; + goto done; } if (ltdb_cache_load(module) != 0) { - talloc_free(*handle); - return LDB_ERR_OTHER; + ret = LDB_ERR_OTHER; + goto done; } - ret = ltdb_store(module, msg, TDB_INSERT); + tret = ltdb_store(module, msg, TDB_INSERT); - if (ret != LDB_SUCCESS) { - (*handle)->status = ret; - return LDB_SUCCESS; + if (tret != LDB_SUCCESS) { + (*handle)->status = tret; + goto done; } ltdb_modified(module, msg->dn); - if (ltdb_ac->callback) - (*handle)->status = ltdb_ac->callback(module->ldb, ltdb_ac->context, NULL); - - return LDB_SUCCESS; + if (ltdb_ac->callback) { + ret = ltdb_ac->callback(module->ldb, ltdb_ac->context, NULL); + } + +done: + (*handle)->state = LDB_ASYNC_DONE; + return ret; } static int ltdb_add(struct ldb_module *module, const struct ldb_message *msg) @@ -354,55 +355,54 @@ static int ltdb_delete_async(struct ldb_module *module, const struct ldb_dn *dn, struct ltdb_private *ltdb = talloc_get_type(module->private_data, struct ltdb_private); struct ltdb_async_context *ltdb_ac; struct ldb_message *msg; - int ret = LDB_ERR_OPERATIONS_ERROR; + int tret, ret = LDB_SUCCESS; *handle = NULL; if (ltdb_cache_load(module) != 0) { - goto failed; + return LDB_ERR_OPERATIONS_ERROR; } *handle = init_ltdb_handle(ltdb, module, context, callback); if (*handle == NULL) { - goto failed; + return LDB_ERR_OPERATIONS_ERROR; } ltdb_ac = talloc_get_type((*handle)->private_data, struct ltdb_async_context); - (*handle)->state = LDB_ASYNC_DONE; - (*handle)->status = LDB_SUCCESS; msg = talloc(ltdb_ac, struct ldb_message); if (msg == NULL) { - goto failed; + ret = LDB_ERR_OPERATIONS_ERROR; + goto done; } /* in case any attribute of the message was indexed, we need to fetch the old record */ - ret = ltdb_search_dn1(module, dn, msg); - if (ret != 1) { + tret = ltdb_search_dn1(module, dn, msg); + if (tret != 1) { /* not finding the old record is an error */ (*handle)->status = LDB_ERR_NO_SUCH_OBJECT; - return LDB_SUCCESS; + goto done; } - ret = ltdb_delete_noindex(module, dn); - if (ret != LDB_SUCCESS) { - goto failed; + tret = ltdb_delete_noindex(module, dn); + if (tret != LDB_SUCCESS) { + (*handle)->status = LDB_ERR_NO_SUCH_OBJECT; + goto done; } /* remove any indexed attributes */ - ret = ltdb_index_del(module, msg); - if (ret) { - goto failed; + tret = ltdb_index_del(module, msg); + if (tret != LDB_SUCCESS) { + (*handle)->status = LDB_ERR_NO_SUCH_OBJECT; + goto done; } ltdb_modified(module, dn); if (ltdb_ac->callback) - (*handle)->status = ltdb_ac->callback(module->ldb, ltdb_ac->context, NULL); - - return LDB_SUCCESS; + ret = ltdb_ac->callback(module->ldb, ltdb_ac->context, NULL); -failed: - talloc_free(*handle); +done: + (*handle)->state = LDB_ASYNC_DONE; return ret; } @@ -741,42 +741,42 @@ static int ltdb_modify_async(struct ldb_module *module, const struct ldb_message { struct ltdb_private *ltdb = talloc_get_type(module->private_data, struct ltdb_private); struct ltdb_async_context *ltdb_ac; - int ret = LDB_ERR_OPERATIONS_ERROR; + int tret, ret = LDB_SUCCESS; *handle = NULL; *handle = init_ltdb_handle(ltdb, module, context, callback); if (*handle == NULL) { - return ret; + return LDB_ERR_OPERATIONS_ERROR; } ltdb_ac = talloc_get_type((*handle)->private_data, struct ltdb_async_context); - (*handle)->state = LDB_ASYNC_DONE; - (*handle)->status = LDB_SUCCESS; - ret = ltdb_check_special_dn(module, msg); - if (ret != LDB_SUCCESS) { - talloc_free(*handle); - return ret; + tret = ltdb_check_special_dn(module, msg); + if (tret != LDB_SUCCESS) { + (*handle)->status = tret; + goto done; } if (ltdb_cache_load(module) != 0) { - talloc_free(*handle); - return LDB_ERR_OTHER; + ret = LDB_ERR_OPERATIONS_ERROR; + goto done; } - ret = ltdb_modify_internal(module, msg); + tret = ltdb_modify_internal(module, msg); - if (ret != LDB_SUCCESS) { - (*handle)->status = ret; - return LDB_SUCCESS; + if (tret != LDB_SUCCESS) { + (*handle)->status = tret; + goto done; } ltdb_modified(module, msg->dn); if (ltdb_ac->callback) - (*handle)->status = ltdb_ac->callback(module->ldb, ltdb_ac->context, NULL); - - return LDB_SUCCESS; + ret = ltdb_ac->callback(module->ldb, ltdb_ac->context, NULL); + +done: + (*handle)->state = LDB_ASYNC_DONE; + return ret; } static int ltdb_modify(struct ldb_module *module, const struct ldb_message *msg) @@ -806,62 +806,59 @@ static int ltdb_rename_async(struct ldb_module *module, const struct ldb_dn *old struct ltdb_private *ltdb = talloc_get_type(module->private_data, struct ltdb_private); struct ltdb_async_context *ltdb_ac; struct ldb_message *msg; - int ret = LDB_ERR_OPERATIONS_ERROR; + int tret, ret = LDB_SUCCESS; *handle = NULL; if (ltdb_cache_load(module) != 0) { - return ret; + return LDB_ERR_OPERATIONS_ERROR; } *handle = init_ltdb_handle(ltdb, module, context, callback); if (*handle == NULL) { - goto failed; + return LDB_ERR_OPERATIONS_ERROR; } ltdb_ac = talloc_get_type((*handle)->private_data, struct ltdb_async_context); - (*handle)->state = LDB_ASYNC_DONE; - (*handle)->status = LDB_SUCCESS; msg = talloc(ltdb_ac, struct ldb_message); if (msg == NULL) { - goto failed; + ret = LDB_ERR_OPERATIONS_ERROR; + goto done; } /* in case any attribute of the message was indexed, we need to fetch the old record */ - ret = ltdb_search_dn1(module, olddn, msg); - if (ret != 1) { + tret = ltdb_search_dn1(module, olddn, msg); + if (tret != 1) { /* not finding the old record is an error */ (*handle)->status = LDB_ERR_NO_SUCH_OBJECT; - return LDB_SUCCESS; + goto done; } msg->dn = ldb_dn_copy(msg, newdn); if (!msg->dn) { ret = LDB_ERR_OPERATIONS_ERROR; - goto failed; + goto done; } - ret = ltdb_add(module, msg); - if (ret != LDB_SUCCESS) { - (*handle)->status = LDB_ERR_OPERATIONS_ERROR; - return LDB_SUCCESS; + tret = ltdb_add(module, msg); + if (tret != LDB_SUCCESS) { + ret = LDB_ERR_OPERATIONS_ERROR; + goto done; } - ret = ltdb_delete(module, olddn); - if (ret != LDB_SUCCESS) { + tret = ltdb_delete(module, olddn); + if (tret != LDB_SUCCESS) { ltdb_delete(module, newdn); - (*handle)->status = ret; - return LDB_SUCCESS; + ret = LDB_ERR_OPERATIONS_ERROR; + goto done; } if (ltdb_ac->callback) - (*handle)->status = ltdb_ac->callback(module->ldb, ltdb_ac->context, NULL); + ret = ltdb_ac->callback(module->ldb, ltdb_ac->context, NULL); - return LDB_SUCCESS; - -failed: - talloc_free(*handle); +done: + (*handle)->state = LDB_ASYNC_DONE; return ret; } -- 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_tdb.c | 237 ++++++++++++++++++++------------------ 1 file changed, 122 insertions(+), 115 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index e0465afb30..e5b0ca0668 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -259,24 +259,21 @@ done: /* add a record to the database */ -static int ltdb_add_async(struct ldb_module *module, const struct ldb_message *msg, - void *context, - int (*callback)(struct ldb_context *, void *, struct ldb_async_result *), - struct ldb_async_handle **handle) +static int ltdb_add_async(struct ldb_module *module, struct ldb_request *req) { struct ltdb_private *ltdb = talloc_get_type(module->private_data, struct ltdb_private); struct ltdb_async_context *ltdb_ac; int tret, ret = LDB_SUCCESS; - *handle = init_ltdb_handle(ltdb, module, context, callback); - if (*handle == NULL) { + req->async.handle = init_ltdb_handle(ltdb, module, req->async.context, req->async.callback); + if (req->async.handle == NULL) { return LDB_ERR_OPERATIONS_ERROR; } - ltdb_ac = talloc_get_type((*handle)->private_data, struct ltdb_async_context); + ltdb_ac = talloc_get_type(req->async.handle->private_data, struct ltdb_async_context); - tret = ltdb_check_special_dn(module, msg); + tret = ltdb_check_special_dn(module, req->op.add.message); if (tret != LDB_SUCCESS) { - (*handle)->status = tret; + req->async.handle->status = tret; goto done; } @@ -285,37 +282,50 @@ static int ltdb_add_async(struct ldb_module *module, const struct ldb_message *m goto done; } - tret = ltdb_store(module, msg, TDB_INSERT); + tret = ltdb_store(module, req->op.add.message, TDB_INSERT); if (tret != LDB_SUCCESS) { - (*handle)->status = tret; + req->async.handle->status = tret; goto done; } - ltdb_modified(module, msg->dn); + ltdb_modified(module, req->op.add.message->dn); if (ltdb_ac->callback) { ret = ltdb_ac->callback(module->ldb, ltdb_ac->context, NULL); } done: - (*handle)->state = LDB_ASYNC_DONE; + req->async.handle->state = LDB_ASYNC_DONE; return ret; } static int ltdb_add(struct ldb_module *module, const struct ldb_message *msg) { - struct ldb_async_handle *handle; + struct ldb_request *req; int ret; - ret = ltdb_add_async(module, msg, NULL, NULL, &handle); + req = talloc_zero(module, struct ldb_request); + if (! req) { + return LDB_ERR_OPERATIONS_ERROR; + } + + req->operation = LDB_ASYNC_ADD; + req->op.add.message = msg; + req->controls = NULL; + req->async.context = NULL; + req->async.callback = NULL; - if (ret != LDB_SUCCESS) + ret = ltdb_add_async(module, req); + + if (ret != LDB_SUCCESS) { + talloc_free(req); return ret; + } - ret = ldb_async_wait(handle, LDB_WAIT_ALL); + ret = ldb_async_wait(req->async.handle, LDB_WAIT_ALL); - talloc_free(handle); + talloc_free(req); return ret; } @@ -347,27 +357,24 @@ int ltdb_delete_noindex(struct ldb_module *module, const struct ldb_dn *dn) /* delete a record from the database */ -static int ltdb_delete_async(struct ldb_module *module, const struct ldb_dn *dn, - void *context, - int (*callback)(struct ldb_context *, void *, struct ldb_async_result *), - struct ldb_async_handle **handle) +static int ltdb_delete_async(struct ldb_module *module, struct ldb_request *req) { struct ltdb_private *ltdb = talloc_get_type(module->private_data, struct ltdb_private); struct ltdb_async_context *ltdb_ac; struct ldb_message *msg; int tret, ret = LDB_SUCCESS; - *handle = NULL; + req->async.handle = NULL; if (ltdb_cache_load(module) != 0) { return LDB_ERR_OPERATIONS_ERROR; } - *handle = init_ltdb_handle(ltdb, module, context, callback); - if (*handle == NULL) { + req->async.handle = init_ltdb_handle(ltdb, module, req->async.context, req->async.callback); + if (req->async.handle == NULL) { return LDB_ERR_OPERATIONS_ERROR; } - ltdb_ac = talloc_get_type((*handle)->private_data, struct ltdb_async_context); + ltdb_ac = talloc_get_type(req->async.handle->private_data, struct ltdb_async_context); msg = talloc(ltdb_ac, struct ldb_message); if (msg == NULL) { @@ -377,48 +384,61 @@ static int ltdb_delete_async(struct ldb_module *module, const struct ldb_dn *dn, /* in case any attribute of the message was indexed, we need to fetch the old record */ - tret = ltdb_search_dn1(module, dn, msg); + tret = ltdb_search_dn1(module, req->op.del.dn, msg); if (tret != 1) { /* not finding the old record is an error */ - (*handle)->status = LDB_ERR_NO_SUCH_OBJECT; + req->async.handle->status = LDB_ERR_NO_SUCH_OBJECT; goto done; } - tret = ltdb_delete_noindex(module, dn); + tret = ltdb_delete_noindex(module, req->op.del.dn); if (tret != LDB_SUCCESS) { - (*handle)->status = LDB_ERR_NO_SUCH_OBJECT; + req->async.handle->status = LDB_ERR_NO_SUCH_OBJECT; goto done; } /* remove any indexed attributes */ tret = ltdb_index_del(module, msg); if (tret != LDB_SUCCESS) { - (*handle)->status = LDB_ERR_NO_SUCH_OBJECT; + req->async.handle->status = LDB_ERR_NO_SUCH_OBJECT; goto done; } - ltdb_modified(module, dn); + ltdb_modified(module, req->op.del.dn); if (ltdb_ac->callback) ret = ltdb_ac->callback(module->ldb, ltdb_ac->context, NULL); done: - (*handle)->state = LDB_ASYNC_DONE; + req->async.handle->state = LDB_ASYNC_DONE; return ret; } static int ltdb_delete(struct ldb_module *module, const struct ldb_dn *dn) { - struct ldb_async_handle *handle; + struct ldb_request *req; int ret; - ret = ltdb_delete_async(module, dn, NULL, NULL, &handle); + req = talloc_zero(module, struct ldb_request); + if (! req) { + return LDB_ERR_OPERATIONS_ERROR; + } + + req->operation = LDB_ASYNC_DELETE; + req->op.del.dn = dn; + req->controls = NULL; + req->async.context = NULL; + req->async.callback = NULL; + + ret = ltdb_delete_async(module, req); - if (ret != LDB_SUCCESS) + if (ret != LDB_SUCCESS) { + talloc_free(req); return ret; + } - ret = ldb_async_wait(handle, LDB_WAIT_ALL); + ret = ldb_async_wait(req->async.handle, LDB_WAIT_ALL); - talloc_free(handle); + talloc_free(req); return ret; } @@ -734,26 +754,23 @@ failed: /* modify a record */ -static int ltdb_modify_async(struct ldb_module *module, const struct ldb_message *msg, - void *context, - int (*callback)(struct ldb_context *, void *, struct ldb_async_result *), - struct ldb_async_handle **handle) +static int ltdb_modify_async(struct ldb_module *module, struct ldb_request *req) { struct ltdb_private *ltdb = talloc_get_type(module->private_data, struct ltdb_private); struct ltdb_async_context *ltdb_ac; int tret, ret = LDB_SUCCESS; - *handle = NULL; + req->async.handle = NULL; - *handle = init_ltdb_handle(ltdb, module, context, callback); - if (*handle == NULL) { + req->async.handle = init_ltdb_handle(ltdb, module, req->async.context, req->async.callback); + if (req->async.handle == NULL) { return LDB_ERR_OPERATIONS_ERROR; } - ltdb_ac = talloc_get_type((*handle)->private_data, struct ltdb_async_context); + ltdb_ac = talloc_get_type(req->async.handle->private_data, struct ltdb_async_context); - tret = ltdb_check_special_dn(module, msg); + tret = ltdb_check_special_dn(module, req->op.mod.message); if (tret != LDB_SUCCESS) { - (*handle)->status = tret; + req->async.handle->status = tret; goto done; } @@ -762,63 +779,73 @@ static int ltdb_modify_async(struct ldb_module *module, const struct ldb_message goto done; } - tret = ltdb_modify_internal(module, msg); + tret = ltdb_modify_internal(module, req->op.mod.message); if (tret != LDB_SUCCESS) { - (*handle)->status = tret; + req->async.handle->status = tret; goto done; } - ltdb_modified(module, msg->dn); + ltdb_modified(module, req->op.mod.message->dn); if (ltdb_ac->callback) ret = ltdb_ac->callback(module->ldb, ltdb_ac->context, NULL); done: - (*handle)->state = LDB_ASYNC_DONE; + req->async.handle->state = LDB_ASYNC_DONE; return ret; } static int ltdb_modify(struct ldb_module *module, const struct ldb_message *msg) { - struct ldb_async_handle *handle; + struct ldb_request *req; int ret; - ret = ltdb_modify_async(module, msg, NULL, NULL, &handle); + req = talloc_zero(module, struct ldb_request); + if (! req) { + return LDB_ERR_OPERATIONS_ERROR; + } + + req->operation = LDB_ASYNC_MODIFY; + req->op.mod.message = msg; + req->controls = NULL; + req->async.context = NULL; + req->async.callback = NULL; + + ret = ltdb_modify_async(module, req); - if (ret != LDB_SUCCESS) + if (ret != LDB_SUCCESS) { + talloc_free(req); return ret; + } - ret = ldb_async_wait(handle, LDB_WAIT_ALL); + ret = ldb_async_wait(req->async.handle, LDB_WAIT_ALL); - talloc_free(handle); + talloc_free(req); return ret; } /* rename a record */ -static int ltdb_rename_async(struct ldb_module *module, const struct ldb_dn *olddn, const struct ldb_dn *newdn, - void *context, - int (*callback)(struct ldb_context *, void *, struct ldb_async_result *), - struct ldb_async_handle **handle) +static int ltdb_rename_async(struct ldb_module *module, struct ldb_request *req) { struct ltdb_private *ltdb = talloc_get_type(module->private_data, struct ltdb_private); struct ltdb_async_context *ltdb_ac; struct ldb_message *msg; int tret, ret = LDB_SUCCESS; - *handle = NULL; + req->async.handle = NULL; if (ltdb_cache_load(module) != 0) { return LDB_ERR_OPERATIONS_ERROR; } - *handle = init_ltdb_handle(ltdb, module, context, callback); - if (*handle == NULL) { + req->async.handle = init_ltdb_handle(ltdb, module, req->async.context, req->async.callback); + if (req->async.handle == NULL) { return LDB_ERR_OPERATIONS_ERROR; } - ltdb_ac = talloc_get_type((*handle)->private_data, struct ltdb_async_context); + ltdb_ac = talloc_get_type(req->async.handle->private_data, struct ltdb_async_context); msg = talloc(ltdb_ac, struct ldb_message); if (msg == NULL) { @@ -828,14 +855,14 @@ static int ltdb_rename_async(struct ldb_module *module, const struct ldb_dn *old /* in case any attribute of the message was indexed, we need to fetch the old record */ - tret = ltdb_search_dn1(module, olddn, msg); + tret = ltdb_search_dn1(module, req->op.rename.olddn, msg); if (tret != 1) { /* not finding the old record is an error */ - (*handle)->status = LDB_ERR_NO_SUCH_OBJECT; + req->async.handle->status = LDB_ERR_NO_SUCH_OBJECT; goto done; } - msg->dn = ldb_dn_copy(msg, newdn); + msg->dn = ldb_dn_copy(msg, req->op.rename.newdn); if (!msg->dn) { ret = LDB_ERR_OPERATIONS_ERROR; goto done; @@ -847,9 +874,9 @@ static int ltdb_rename_async(struct ldb_module *module, const struct ldb_dn *old goto done; } - tret = ltdb_delete(module, olddn); + tret = ltdb_delete(module, req->op.rename.olddn); if (tret != LDB_SUCCESS) { - ltdb_delete(module, newdn); + ltdb_delete(module, req->op.rename.newdn); ret = LDB_ERR_OPERATIONS_ERROR; goto done; } @@ -858,23 +885,37 @@ static int ltdb_rename_async(struct ldb_module *module, const struct ldb_dn *old ret = ltdb_ac->callback(module->ldb, ltdb_ac->context, NULL); done: - (*handle)->state = LDB_ASYNC_DONE; + req->async.handle->state = LDB_ASYNC_DONE; return ret; } static int ltdb_rename(struct ldb_module *module, const struct ldb_dn *olddn, const struct ldb_dn *newdn) { - struct ldb_async_handle *handle; + struct ldb_request *req; int ret; - ret = ltdb_rename_async(module, olddn, newdn, NULL, NULL, &handle); + req = talloc_zero(module, struct ldb_request); + if (! req) { + return LDB_ERR_OPERATIONS_ERROR; + } - if (ret != LDB_SUCCESS) + req->operation = LDB_ASYNC_RENAME; + req->op.rename.olddn = olddn; + req->op.rename.newdn = newdn; + req->controls = NULL; + req->async.context = NULL; + req->async.callback = NULL; + + ret = ltdb_rename_async(module, req); + + if (ret != LDB_SUCCESS) { + talloc_free(req); return ret; + } - ret = ldb_async_wait(handle, LDB_WAIT_ALL); + ret = ldb_async_wait(req->async.handle, LDB_WAIT_ALL); - talloc_free(handle); + talloc_free(req); return ret; } @@ -952,45 +993,6 @@ static int ltdb_request(struct ldb_module *module, struct ldb_request *req) req->op.rename.olddn, req->op.rename.newdn); - case LDB_ASYNC_SEARCH: - return ltdb_search_async(module, - req->op.search.base, - req->op.search.scope, - req->op.search.tree, - req->op.search.attrs, - req->async.context, - req->async.callback, - &req->async.handle); - - case LDB_ASYNC_ADD: - return ltdb_add_async(module, - req->op.add.message, - req->async.context, - req->async.callback, - &req->async.handle); - - case LDB_ASYNC_MODIFY: - return ltdb_modify_async(module, - req->op.mod.message, - req->async.context, - req->async.callback, - &req->async.handle); - - case LDB_ASYNC_DELETE: - return ltdb_delete_async(module, - req->op.del.dn, - req->async.context, - req->async.callback, - &req->async.handle); - - case LDB_ASYNC_RENAME: - return ltdb_rename_async(module, - req->op.rename.olddn, - req->op.rename.newdn, - req->async.context, - req->async.callback, - &req->async.handle); - default: return LDB_ERR_OPERATIONS_ERROR; @@ -1024,6 +1026,11 @@ static uint64_t ltdb_sequence_number(struct ldb_context *ldb) static const struct ldb_module_ops ltdb_ops = { .name = "tdb", + .search = ltdb_search_async, + .add = ltdb_add_async, + .modify = ltdb_modify_async, + .del = ltdb_delete_async, + .rename = ltdb_rename_async, .request = ltdb_request, .start_transaction = ltdb_start_trans, .end_transaction = ltdb_end_trans, -- 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_tdb.c | 313 +++++++++++++------------------------- 1 file changed, 109 insertions(+), 204 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index e5b0ca0668..5ea92aa1b1 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -256,41 +256,58 @@ done: } +static int ltdb_add_internal(struct ldb_module *module, struct ldb_message *msg) +{ + int ret; + + ret = ltdb_check_special_dn(module, msg); + if (ret != LDB_SUCCESS) { + return LDB_ERR_OPERATIONS_ERROR; + } + + if (ltdb_cache_load(module) != 0) { + return LDB_ERR_OPERATIONS_ERROR; + } + + ret = ltdb_store(module, msg, TDB_INSERT); + + if (ret != LDB_SUCCESS) { + return LDB_ERR_OPERATIONS_ERROR; + } + + ltdb_modified(module, msg->dn); + + return LDB_SUCCESS; +} + /* add a record to the database */ -static int ltdb_add_async(struct ldb_module *module, struct ldb_request *req) +static int ltdb_add(struct ldb_module *module, struct ldb_request *req) { struct ltdb_private *ltdb = talloc_get_type(module->private_data, struct ltdb_private); struct ltdb_async_context *ltdb_ac; int tret, ret = LDB_SUCCESS; + if (req->controls != NULL) { + ldb_debug(module->ldb, LDB_DEBUG_WARNING, "Controls should not reach the ldb_tdb backend!\n"); + if (check_critical_controls(req->controls)) { + return LDB_ERR_UNSUPPORTED_CRITICAL_EXTENSION; + } + } + req->async.handle = init_ltdb_handle(ltdb, module, req->async.context, req->async.callback); if (req->async.handle == NULL) { return LDB_ERR_OPERATIONS_ERROR; } ltdb_ac = talloc_get_type(req->async.handle->private_data, struct ltdb_async_context); - tret = ltdb_check_special_dn(module, req->op.add.message); + tret = ltdb_add_internal(module, req->op.add.message); if (tret != LDB_SUCCESS) { req->async.handle->status = tret; goto done; } - if (ltdb_cache_load(module) != 0) { - ret = LDB_ERR_OTHER; - goto done; - } - - tret = ltdb_store(module, req->op.add.message, TDB_INSERT); - - if (tret != LDB_SUCCESS) { - req->async.handle->status = tret; - goto done; - } - - ltdb_modified(module, req->op.add.message->dn); - if (ltdb_ac->callback) { ret = ltdb_ac->callback(module->ldb, ltdb_ac->context, NULL); } @@ -300,35 +317,6 @@ done: return ret; } -static int ltdb_add(struct ldb_module *module, const struct ldb_message *msg) -{ - struct ldb_request *req; - int ret; - - req = talloc_zero(module, struct ldb_request); - if (! req) { - return LDB_ERR_OPERATIONS_ERROR; - } - - req->operation = LDB_ASYNC_ADD; - req->op.add.message = msg; - req->controls = NULL; - req->async.context = NULL; - req->async.callback = NULL; - - ret = ltdb_add_async(module, req); - - if (ret != LDB_SUCCESS) { - talloc_free(req); - return ret; - } - - ret = ldb_async_wait(req->async.handle, LDB_WAIT_ALL); - - talloc_free(req); - return ret; -} - /* delete a record from the database, not updating indexes (used for deleting index records) @@ -354,16 +342,59 @@ int ltdb_delete_noindex(struct ldb_module *module, const struct ldb_dn *dn) return ret; } +static int ltdb_delete_internal(struct ldb_module *module, struct ldb_dn *dn) +{ + struct ldb_message *msg; + int ret; + + msg = talloc(module, struct ldb_message); + if (msg == NULL) { + return LDB_ERR_OPERATIONS_ERROR; + } + + /* in case any attribute of the message was indexed, we need + to fetch the old record */ + ret = ltdb_search_dn1(module, dn, msg); + if (ret != 1) { + /* not finding the old record is an error */ + talloc_free(msg); + return LDB_ERR_NO_SUCH_OBJECT; + } + + ret = ltdb_delete_noindex(module, dn); + if (ret != LDB_SUCCESS) { + talloc_free(msg); + return LDB_ERR_NO_SUCH_OBJECT; + } + + /* remove any indexed attributes */ + ret = ltdb_index_del(module, msg); + if (ret != LDB_SUCCESS) { + talloc_free(msg); + return LDB_ERR_OPERATIONS_ERROR; + } + ltdb_modified(module, dn); + + talloc_free(msg); + return LDB_SUCCESS; +} + /* delete a record from the database */ -static int ltdb_delete_async(struct ldb_module *module, struct ldb_request *req) +static int ltdb_delete(struct ldb_module *module, struct ldb_request *req) { struct ltdb_private *ltdb = talloc_get_type(module->private_data, struct ltdb_private); struct ltdb_async_context *ltdb_ac; - struct ldb_message *msg; int tret, ret = LDB_SUCCESS; + if (req->controls != NULL) { + ldb_debug(module->ldb, LDB_DEBUG_WARNING, "Controls should not reach the ldb_tdb backend!\n"); + if (check_critical_controls(req->controls)) { + return LDB_ERR_UNSUPPORTED_CRITICAL_EXTENSION; + } + } + req->async.handle = NULL; if (ltdb_cache_load(module) != 0) { @@ -376,34 +407,11 @@ static int ltdb_delete_async(struct ldb_module *module, struct ldb_request *req) } ltdb_ac = talloc_get_type(req->async.handle->private_data, struct ltdb_async_context); - msg = talloc(ltdb_ac, struct ldb_message); - if (msg == NULL) { - ret = LDB_ERR_OPERATIONS_ERROR; - goto done; - } - - /* in case any attribute of the message was indexed, we need - to fetch the old record */ - tret = ltdb_search_dn1(module, req->op.del.dn, msg); - if (tret != 1) { - /* not finding the old record is an error */ - req->async.handle->status = LDB_ERR_NO_SUCH_OBJECT; - goto done; - } - - tret = ltdb_delete_noindex(module, req->op.del.dn); - if (tret != LDB_SUCCESS) { - req->async.handle->status = LDB_ERR_NO_SUCH_OBJECT; - goto done; - } - - /* remove any indexed attributes */ - tret = ltdb_index_del(module, msg); + tret = ltdb_delete_internal(module, req->op.del.dn); if (tret != LDB_SUCCESS) { - req->async.handle->status = LDB_ERR_NO_SUCH_OBJECT; + req->async.handle->status = tret; goto done; } - ltdb_modified(module, req->op.del.dn); if (ltdb_ac->callback) ret = ltdb_ac->callback(module->ldb, ltdb_ac->context, NULL); @@ -413,36 +421,6 @@ done: return ret; } -static int ltdb_delete(struct ldb_module *module, const struct ldb_dn *dn) -{ - struct ldb_request *req; - int ret; - - req = talloc_zero(module, struct ldb_request); - if (! req) { - return LDB_ERR_OPERATIONS_ERROR; - } - - req->operation = LDB_ASYNC_DELETE; - req->op.del.dn = dn; - req->controls = NULL; - req->async.context = NULL; - req->async.callback = NULL; - - ret = ltdb_delete_async(module, req); - - if (ret != LDB_SUCCESS) { - talloc_free(req); - return ret; - } - - ret = ldb_async_wait(req->async.handle, LDB_WAIT_ALL); - - talloc_free(req); - return ret; -} - - /* find an element by attribute name. At the moment this does a linear search, it should be re-coded to use a binary search once all places that modify records guarantee @@ -754,12 +732,19 @@ failed: /* modify a record */ -static int ltdb_modify_async(struct ldb_module *module, struct ldb_request *req) +static int ltdb_modify(struct ldb_module *module, struct ldb_request *req) { struct ltdb_private *ltdb = talloc_get_type(module->private_data, struct ltdb_private); struct ltdb_async_context *ltdb_ac; int tret, ret = LDB_SUCCESS; + if (req->controls != NULL) { + ldb_debug(module->ldb, LDB_DEBUG_WARNING, "Controls should not reach the ldb_tdb backend!\n"); + if (check_critical_controls(req->controls)) { + return LDB_ERR_UNSUPPORTED_CRITICAL_EXTENSION; + } + } + req->async.handle = NULL; req->async.handle = init_ltdb_handle(ltdb, module, req->async.context, req->async.callback); @@ -796,45 +781,23 @@ done: return ret; } -static int ltdb_modify(struct ldb_module *module, const struct ldb_message *msg) -{ - struct ldb_request *req; - int ret; - - req = talloc_zero(module, struct ldb_request); - if (! req) { - return LDB_ERR_OPERATIONS_ERROR; - } - - req->operation = LDB_ASYNC_MODIFY; - req->op.mod.message = msg; - req->controls = NULL; - req->async.context = NULL; - req->async.callback = NULL; - - ret = ltdb_modify_async(module, req); - - if (ret != LDB_SUCCESS) { - talloc_free(req); - return ret; - } - - ret = ldb_async_wait(req->async.handle, LDB_WAIT_ALL); - - talloc_free(req); - return ret; -} - /* rename a record */ -static int ltdb_rename_async(struct ldb_module *module, struct ldb_request *req) +static int ltdb_rename(struct ldb_module *module, struct ldb_request *req) { struct ltdb_private *ltdb = talloc_get_type(module->private_data, struct ltdb_private); struct ltdb_async_context *ltdb_ac; struct ldb_message *msg; int tret, ret = LDB_SUCCESS; + if (req->controls != NULL) { + ldb_debug(module->ldb, LDB_DEBUG_WARNING, "Controls should not reach the ldb_tdb backend!\n"); + if (check_critical_controls(req->controls)) { + return LDB_ERR_UNSUPPORTED_CRITICAL_EXTENSION; + } + } + req->async.handle = NULL; if (ltdb_cache_load(module) != 0) { @@ -868,15 +831,15 @@ static int ltdb_rename_async(struct ldb_module *module, struct ldb_request *req) goto done; } - tret = ltdb_add(module, msg); + tret = ltdb_add_internal(module, msg); if (tret != LDB_SUCCESS) { ret = LDB_ERR_OPERATIONS_ERROR; goto done; } - tret = ltdb_delete(module, req->op.rename.olddn); + tret = ltdb_delete_internal(module, req->op.rename.olddn); if (tret != LDB_SUCCESS) { - ltdb_delete(module, req->op.rename.newdn); + ltdb_delete_internal(module, req->op.rename.newdn); ret = LDB_ERR_OPERATIONS_ERROR; goto done; } @@ -889,36 +852,6 @@ done: return ret; } -static int ltdb_rename(struct ldb_module *module, const struct ldb_dn *olddn, const struct ldb_dn *newdn) -{ - struct ldb_request *req; - int ret; - - req = talloc_zero(module, struct ldb_request); - if (! req) { - return LDB_ERR_OPERATIONS_ERROR; - } - - req->operation = LDB_ASYNC_RENAME; - req->op.rename.olddn = olddn; - req->op.rename.newdn = newdn; - req->controls = NULL; - req->async.context = NULL; - req->async.callback = NULL; - - ret = ltdb_rename_async(module, req); - - if (ret != LDB_SUCCESS) { - talloc_free(req); - return ret; - } - - ret = ldb_async_wait(req->async.handle, LDB_WAIT_ALL); - - talloc_free(req); - return ret; -} - static int ltdb_start_trans(struct ldb_module *module) { struct ltdb_private *ltdb = module->private_data; @@ -960,43 +893,15 @@ static int ltdb_async_wait(struct ldb_async_handle *handle, enum ldb_async_wait_ static int ltdb_request(struct ldb_module *module, struct ldb_request *req) { /* check for oustanding critical controls and return an error if found */ - if (req->controls != NULL) { ldb_debug(module->ldb, LDB_DEBUG_WARNING, "Controls should not reach the ldb_tdb backend!\n"); - } - - if (check_critical_controls(req->controls)) { - return LDB_ERR_UNSUPPORTED_CRITICAL_EXTENSION; + if (check_critical_controls(req->controls)) { + return LDB_ERR_UNSUPPORTED_CRITICAL_EXTENSION; + } } - switch (req->operation) { - - case LDB_REQ_SEARCH: - return ltdb_search_bytree(module, - req->op.search.base, - req->op.search.scope, - req->op.search.tree, - req->op.search.attrs, - &req->op.search.res); - - case LDB_REQ_ADD: - return ltdb_add(module, req->op.add.message); - - case LDB_REQ_MODIFY: - return ltdb_modify(module, req->op.mod.message); - - case LDB_REQ_DELETE: - return ltdb_delete(module, req->op.del.dn); - - case LDB_REQ_RENAME: - return ltdb_rename(module, - req->op.rename.olddn, - req->op.rename.newdn); - - default: - return LDB_ERR_OPERATIONS_ERROR; - - } + /* search, add, modify, delete, rename are handled by their own, no other op supported */ + return LDB_ERR_OPERATIONS_ERROR; } /* @@ -1026,11 +931,11 @@ static uint64_t ltdb_sequence_number(struct ldb_context *ldb) static const struct ldb_module_ops ltdb_ops = { .name = "tdb", - .search = ltdb_search_async, - .add = ltdb_add_async, - .modify = ltdb_modify_async, - .del = ltdb_delete_async, - .rename = ltdb_rename_async, + .search = ltdb_search, + .add = ltdb_add, + .modify = ltdb_modify, + .del = ltdb_delete, + .rename = ltdb_rename, .request = ltdb_request, .start_transaction = ltdb_start_trans, .end_transaction = ltdb_end_trans, -- cgit From 17936b09dba370928faf3794caadfe22c1862622 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Tue, 30 May 2006 01:46:14 +0000 Subject: r15945: Check ltdb_modified results (This used to be commit bbda863f0766e4f4100a644f9a1ddcd8e18d29cd) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 5ea92aa1b1..629a18b9c6 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -256,7 +256,7 @@ done: } -static int ltdb_add_internal(struct ldb_module *module, struct ldb_message *msg) +static int ltdb_add_internal(struct ldb_module *module, const struct ldb_message *msg) { int ret; @@ -270,12 +270,14 @@ static int ltdb_add_internal(struct ldb_module *module, struct ldb_message *msg) } ret = ltdb_store(module, msg, TDB_INSERT); - if (ret != LDB_SUCCESS) { return LDB_ERR_OPERATIONS_ERROR; } - ltdb_modified(module, msg->dn); + ret = ltdb_modified(module, msg->dn); + if (ret != LDB_SUCCESS) { + return LDB_ERR_OPERATIONS_ERROR; + } return LDB_SUCCESS; } @@ -342,7 +344,7 @@ int ltdb_delete_noindex(struct ldb_module *module, const struct ldb_dn *dn) return ret; } -static int ltdb_delete_internal(struct ldb_module *module, struct ldb_dn *dn) +static int ltdb_delete_internal(struct ldb_module *module, const struct ldb_dn *dn) { struct ldb_message *msg; int ret; @@ -373,7 +375,11 @@ static int ltdb_delete_internal(struct ldb_module *module, struct ldb_dn *dn) talloc_free(msg); return LDB_ERR_OPERATIONS_ERROR; } - ltdb_modified(module, dn); + + ret = ltdb_modified(module, dn); + if (ret != LDB_SUCCESS) { + return LDB_ERR_OPERATIONS_ERROR; + } talloc_free(msg); return LDB_SUCCESS; @@ -718,6 +724,14 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms /* we've made all the mods - save the modified record back into the database */ ret = ltdb_store(module, msg2, TDB_MODIFY); + if (ret != LDB_SUCCESS) { + goto failed; + } + + if (ltdb_modified(module, msg->dn) != LDB_SUCCESS) { + ret = LDB_ERR_OPERATIONS_ERROR; + goto failed; + } talloc_free(tdb_key.dptr); free(tdb_data.dptr); @@ -765,14 +779,11 @@ static int ltdb_modify(struct ldb_module *module, struct ldb_request *req) } tret = ltdb_modify_internal(module, req->op.mod.message); - if (tret != LDB_SUCCESS) { req->async.handle->status = tret; goto done; } - ltdb_modified(module, req->op.mod.message->dn); - if (ltdb_ac->callback) ret = ltdb_ac->callback(module->ldb, ltdb_ac->context, NULL); -- cgit From 3dcbe5702d795e0525029c73ef1aad58ece58309 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 31 May 2006 10:17:05 +0000 Subject: r15978: - pass the error code back to the caller... - we were giving OPERATIONS_ERROR in all cases:-( - we now pass ALREADY_EXIST fine to the caller, and the code in libnet_site.c is happy again. - this bug wasn't noticed for a long time because the ldb_ildap code always passed SUCCESS to it's caller metze (This used to be commit 7b9d7119205c442f338deab07122ce1548bad9b6) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 629a18b9c6..29c2703644 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -262,7 +262,7 @@ static int ltdb_add_internal(struct ldb_module *module, const struct ldb_message ret = ltdb_check_special_dn(module, msg); if (ret != LDB_SUCCESS) { - return LDB_ERR_OPERATIONS_ERROR; + return ret; } if (ltdb_cache_load(module) != 0) { @@ -271,7 +271,7 @@ static int ltdb_add_internal(struct ldb_module *module, const struct ldb_message ret = ltdb_store(module, msg, TDB_INSERT); if (ret != LDB_SUCCESS) { - return LDB_ERR_OPERATIONS_ERROR; + return ret; } ret = ltdb_modified(module, msg->dn); -- cgit From bd22992274bdd286cf635956b4897b50f6377d66 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 31 May 2006 10:22:38 +0000 Subject: r15979: some farmating... metze (This used to be commit 53ec76d8d2edaa37bbccb6de838248931a3a76d2) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 29c2703644..fe357072e6 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -313,7 +313,6 @@ static int ltdb_add(struct ldb_module *module, struct ldb_request *req) if (ltdb_ac->callback) { ret = ltdb_ac->callback(module->ldb, ltdb_ac->context, NULL); } - done: req->async.handle->state = LDB_ASYNC_DONE; return ret; @@ -419,9 +418,9 @@ static int ltdb_delete(struct ldb_module *module, struct ldb_request *req) goto done; } - if (ltdb_ac->callback) + if (ltdb_ac->callback) { ret = ltdb_ac->callback(module->ldb, ltdb_ac->context, NULL); - + } done: req->async.handle->state = LDB_ASYNC_DONE; return ret; @@ -784,9 +783,9 @@ static int ltdb_modify(struct ldb_module *module, struct ldb_request *req) goto done; } - if (ltdb_ac->callback) + if (ltdb_ac->callback) { ret = ltdb_ac->callback(module->ldb, ltdb_ac->context, NULL); - + } done: req->async.handle->state = LDB_ASYNC_DONE; return ret; @@ -855,9 +854,9 @@ static int ltdb_rename(struct ldb_module *module, struct ldb_request *req) goto done; } - if (ltdb_ac->callback) + if (ltdb_ac->callback) { ret = ltdb_ac->callback(module->ldb, ltdb_ac->context, NULL); - + } done: req->async.handle->state = LDB_ASYNC_DONE; return ret; -- cgit From c27a242130b850ef937bc564d061be62c3b0e701 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 31 May 2006 10:36:48 +0000 Subject: r15981: we need to initialize 'ret' before 'goto failed' metze (This used to be commit 941f93f93f3ce9dacaafe80520b8751f738e7032) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index fe357072e6..b8f4a024d2 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -606,9 +606,8 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms ret = ltdb_unpack_data(module, &tdb_data, msg2); if (ret == -1) { - talloc_free(tdb_key.dptr); - free(tdb_data.dptr); - return LDB_ERR_OTHER; + ret = LDB_ERR_OTHER; + goto failed; } if (!msg2->dn) { @@ -654,8 +653,10 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms vals = talloc_realloc(msg2->elements, el2->values, struct ldb_val, el2->num_values + el->num_values); - if (vals == NULL) + if (vals == NULL) { + ret = LDB_ERR_OTHER; goto failed; + } for (j=0;jnum_values;j++) { vals[el2->num_values + j] = @@ -675,6 +676,7 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms /* add the replacement element, if not empty */ if (msg->elements[i].num_values != 0 && msg_add_element(ldb, msg2, &msg->elements[i]) != 0) { + ret = LDB_ERR_OTHER; goto failed; } break; @@ -682,7 +684,10 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms case LDB_FLAG_MOD_DELETE: dn = ldb_dn_linearize(msg2, msg->dn); - if (dn == NULL) goto failed; + if (dn == NULL) { + ret = LDB_ERR_OTHER; + goto failed; + } /* we could be being asked to delete all values or just some values */ @@ -707,6 +712,7 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms goto failed; } if (ltdb_index_del_value(module, dn, &msg->elements[i], j) != 0) { + ret = LDB_ERR_OTHER; goto failed; } } -- cgit From 247af0d569594512a24e83156e257b8d4d356883 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Wed, 7 Jun 2006 21:03:38 +0000 Subject: r16083: Make it possible to initialise a backend module, without it setting up the whole ldb structure. Because the sequence number was a fn pointer on the main ldb context, turn it into a full request (currently sync). Andrew Bartlett (This used to be commit fbe7d0ca9031e292b2d2fae263233c973982980a) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 52 +++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 21 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index b8f4a024d2..224c25891c 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -923,26 +923,35 @@ static int ltdb_request(struct ldb_module *module, struct ldb_request *req) /* return sequenceNumber from @BASEINFO */ -static uint64_t ltdb_sequence_number(struct ldb_context *ldb) +static int ltdb_sequence_number(struct ldb_module *module, struct ldb_request *req) { - TALLOC_CTX *tmp_ctx = talloc_new(ldb); - const char *attrs[] = { "sequenceNumber", NULL }; - struct ldb_result *res = NULL; + TALLOC_CTX *tmp_ctx = talloc_new(req); + struct ldb_message *msg = NULL; struct ldb_dn *dn = ldb_dn_explode(tmp_ctx, "@BASEINFO"); - int ret; - uint64_t seq_num; + int tret; + + if (tmp_ctx == NULL) { + talloc_free(tmp_ctx); + return LDB_ERR_OPERATIONS_ERROR; + } + + msg = talloc(tmp_ctx, struct ldb_message); + if (msg == NULL) { + talloc_free(tmp_ctx); + return LDB_ERR_OPERATIONS_ERROR; + } - ret = ldb_search(ldb, dn, LDB_SCOPE_BASE, NULL, attrs, &res); - talloc_steal(tmp_ctx, res); - if (ret != LDB_SUCCESS || res->count != 1) { + tret = ltdb_search_dn1(module, dn, msg); + if (tret != 1) { talloc_free(tmp_ctx); + req->op.seq_num.seq_num = 0; /* zero is as good as anything when we don't know */ - return 0; + return LDB_SUCCESS; } - seq_num = ldb_msg_find_uint64(res->msgs[0], "sequenceNumber", 0); + req->op.seq_num.seq_num = ldb_msg_find_uint64(msg, "sequenceNumber", 0); talloc_free(tmp_ctx); - return seq_num; + return LDB_SUCCESS; } static const struct ldb_module_ops ltdb_ops = { @@ -956,7 +965,8 @@ static const struct ldb_module_ops ltdb_ops = { .start_transaction = ltdb_start_trans, .end_transaction = ltdb_end_trans, .del_transaction = ltdb_del_trans, - .async_wait = ltdb_async_wait + .async_wait = ltdb_async_wait, + .sequence_number = ltdb_sequence_number }; @@ -964,7 +974,8 @@ static const struct ldb_module_ops ltdb_ops = { connect to the database */ static int ltdb_connect(struct ldb_context *ldb, const char *url, - unsigned int flags, const char *options[]) + unsigned int flags, const char *options[], + struct ldb_module **module) { const char *path; int tdb_flags, open_flags; @@ -1010,17 +1021,16 @@ static int ltdb_connect(struct ldb_context *ldb, const char *url, ltdb->sequence_number = 0; - ldb->modules = talloc(ldb, struct ldb_module); - if (!ldb->modules) { + *module = talloc(ldb, struct ldb_module); + if (!module) { ldb_oom(ldb); talloc_free(ltdb); return -1; } - ldb->modules->ldb = ldb; - ldb->modules->prev = ldb->modules->next = NULL; - ldb->modules->private_data = ltdb; - ldb->modules->ops = <db_ops; - ldb->sequence_number = ltdb_sequence_number; + (*module)->ldb = ldb; + (*module)->prev = ldb->modules->next = NULL; + (*module)->private_data = ltdb; + (*module)->ops = <db_ops; return 0; } -- cgit From d912d6fcef28fad1c6e1c04a3a2eb4ed9e1a4ca3 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Thu, 8 Jun 2006 01:02:14 +0000 Subject: r16087: Fix silly cut-and-paste typo that cost me much of my afternoon... This only affects my new partitions module, which I will post soon, but should be fixed anyway. Andrew Bartlett (This used to be commit 8912c4e057eb3962321245cf49b92999afcc64fc) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 224c25891c..c6b0ab4c63 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -1028,7 +1028,7 @@ static int ltdb_connect(struct ldb_context *ldb, const char *url, return -1; } (*module)->ldb = ldb; - (*module)->prev = ldb->modules->next = NULL; + (*module)->prev = (*module)->next = NULL; (*module)->private_data = ltdb; (*module)->ops = <db_ops; -- cgit From d3fee429aee87e9c05a4a606fbf0b60b16dac782 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 3 Jul 2006 06:40:56 +0000 Subject: r16774: This patch modifies the tdb API to allow the logging function to be used as part of ldb. This allows tdb failures to be passed all the way up to Samba's DEBUG system, which allowed easier debugging. Unfortunately I had to extend the tdb API, as the logging function didn't have a context pointer. I've worked over the 'debug levels' in TDB. Most of them were 0, which didn't seem right, as some were trace-like messages. We didn't see any of these previously, except when accessing TDB directly. Andrew Bartlett (This used to be commit 58898092c1ce043f6d698db5065f372b79109e22) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index c6b0ab4c63..15f34db5e1 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -969,7 +969,6 @@ static const struct ldb_module_ops ltdb_ops = { .sequence_number = ltdb_sequence_number }; - /* connect to the database */ @@ -1012,7 +1011,8 @@ static int ltdb_connect(struct ldb_context *ldb, const char *url, } /* note that we use quite a large default hash size */ - ltdb->tdb = ltdb_wrap_open(ltdb, path, 10000, tdb_flags, open_flags, 0666); + ltdb->tdb = ltdb_wrap_open(ltdb, path, 10000, + tdb_flags, open_flags, 0666, ldb); if (!ltdb->tdb) { ldb_debug(ldb, LDB_DEBUG_ERROR, "Unable to open tdb '%s'\n", path); talloc_free(ltdb); -- cgit From 2caa112ae4988d4e14e0d34de94da307675777af Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Tue, 11 Jul 2006 02:03:44 +0000 Subject: r16932: Consistanly use the macro for these DNs and attributes. Andrew Bartlett (This used to be commit dd6ca3342218aa25619a98d48e0efbbe31012c30) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 15f34db5e1..090151cad9 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -927,7 +927,7 @@ static int ltdb_sequence_number(struct ldb_module *module, struct ldb_request *r { TALLOC_CTX *tmp_ctx = talloc_new(req); struct ldb_message *msg = NULL; - struct ldb_dn *dn = ldb_dn_explode(tmp_ctx, "@BASEINFO"); + struct ldb_dn *dn = ldb_dn_explode(tmp_ctx, LTDB_BASEINFO); int tret; if (tmp_ctx == NULL) { @@ -949,7 +949,7 @@ static int ltdb_sequence_number(struct ldb_module *module, struct ldb_request *r return LDB_SUCCESS; } - req->op.seq_num.seq_num = ldb_msg_find_uint64(msg, "sequenceNumber", 0); + req->op.seq_num.seq_num = ldb_msg_find_uint64(msg, LTDB_SEQUENCE_NUMBER, 0); talloc_free(tmp_ctx); return LDB_SUCCESS; } -- cgit From c93817b36d3ff7f44cb7b3e1d1a29e37ec12affe Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sat, 22 Jul 2006 16:56:33 +0000 Subject: r17185: Oh, I wanted to do this for sooo long time. Finally acknowledge that ldb is inherently async and does not have a dual personality anymore Rename all ldb_async_XXX functions to ldb_XXX except for ldb_async_result, it is now ldb_reply to reflect the real function of this structure. Simo. (This used to be commit 25fc7354049d62efeba17681ef1cdd326bc3f2ef) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 090151cad9..ababedad15 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -78,14 +78,14 @@ static int ltdb_err_map(enum TDB_ERROR tdb_code) } -struct ldb_async_handle *init_ltdb_handle(struct ltdb_private *ltdb, struct ldb_module *module, +struct ldb_handle *init_ltdb_handle(struct ltdb_private *ltdb, struct ldb_module *module, void *context, - int (*callback)(struct ldb_context *, void *, struct ldb_async_result *)) + int (*callback)(struct ldb_context *, void *, struct ldb_reply *)) { - struct ltdb_async_context *ac; - struct ldb_async_handle *h; + struct ltdb_context *ac; + struct ldb_handle *h; - h = talloc_zero(ltdb, struct ldb_async_handle); + h = talloc_zero(ltdb, struct ldb_handle); if (h == NULL) { ldb_set_errstring(module->ldb, talloc_asprintf(module, "Out of Memory")); return NULL; @@ -93,7 +93,7 @@ struct ldb_async_handle *init_ltdb_handle(struct ltdb_private *ltdb, struct ldb_ h->module = module; - ac = talloc_zero(h, struct ltdb_async_context); + ac = talloc_zero(h, struct ltdb_context); if (ac == NULL) { ldb_set_errstring(module->ldb, talloc_asprintf(module, "Out of Memory")); talloc_free(h); @@ -288,7 +288,7 @@ static int ltdb_add_internal(struct ldb_module *module, const struct ldb_message static int ltdb_add(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 tret, ret = LDB_SUCCESS; if (req->controls != NULL) { @@ -302,7 +302,7 @@ static int ltdb_add(struct ldb_module *module, struct ldb_request *req) if (req->async.handle == NULL) { 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); tret = ltdb_add_internal(module, req->op.add.message); if (tret != LDB_SUCCESS) { @@ -390,7 +390,7 @@ static int ltdb_delete_internal(struct ldb_module *module, const struct ldb_dn * static int ltdb_delete(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 tret, ret = LDB_SUCCESS; if (req->controls != NULL) { @@ -410,7 +410,7 @@ static int ltdb_delete(struct ldb_module *module, struct ldb_request *req) if (req->async.handle == NULL) { 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); tret = ltdb_delete_internal(module, req->op.del.dn); if (tret != LDB_SUCCESS) { @@ -754,7 +754,7 @@ failed: static int ltdb_modify(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 tret, ret = LDB_SUCCESS; if (req->controls != NULL) { @@ -770,7 +770,7 @@ static int ltdb_modify(struct ldb_module *module, struct ldb_request *req) if (req->async.handle == NULL) { 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); tret = ltdb_check_special_dn(module, req->op.mod.message); if (tret != LDB_SUCCESS) { @@ -803,7 +803,7 @@ done: static int ltdb_rename(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; struct ldb_message *msg; int tret, ret = LDB_SUCCESS; @@ -824,7 +824,7 @@ static int ltdb_rename(struct ldb_module *module, struct ldb_request *req) if (req->async.handle == NULL) { 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); msg = talloc(ltdb_ac, struct ldb_message); if (msg == NULL) { @@ -901,7 +901,7 @@ static int ltdb_del_trans(struct ldb_module *module) return LDB_SUCCESS; } -static int ltdb_async_wait(struct ldb_async_handle *handle, enum ldb_async_wait_type type) +static int ltdb_wait(struct ldb_handle *handle, enum ldb_wait_type type) { return handle->status; } @@ -965,7 +965,7 @@ static const struct ldb_module_ops ltdb_ops = { .start_transaction = ltdb_start_trans, .end_transaction = ltdb_end_trans, .del_transaction = ltdb_del_trans, - .async_wait = ltdb_async_wait, + .wait = ltdb_wait, .sequence_number = ltdb_sequence_number }; -- 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_tdb.c | 48 +++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 24 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index ababedad15..1401052955 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -298,15 +298,15 @@ static int ltdb_add(struct ldb_module *module, struct ldb_request *req) } } - 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) { 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); tret = ltdb_add_internal(module, req->op.add.message); if (tret != LDB_SUCCESS) { - req->async.handle->status = tret; + req->handle->status = tret; goto done; } @@ -314,7 +314,7 @@ static int ltdb_add(struct ldb_module *module, struct ldb_request *req) ret = ltdb_ac->callback(module->ldb, ltdb_ac->context, NULL); } done: - req->async.handle->state = LDB_ASYNC_DONE; + req->handle->state = LDB_ASYNC_DONE; return ret; } @@ -400,21 +400,21 @@ static int ltdb_delete(struct ldb_module *module, struct ldb_request *req) } } - req->async.handle = NULL; + req->handle = NULL; if (ltdb_cache_load(module) != 0) { 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) { 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); tret = ltdb_delete_internal(module, req->op.del.dn); if (tret != LDB_SUCCESS) { - req->async.handle->status = tret; + req->handle->status = tret; goto done; } @@ -422,7 +422,7 @@ static int ltdb_delete(struct ldb_module *module, struct ldb_request *req) ret = ltdb_ac->callback(module->ldb, ltdb_ac->context, NULL); } done: - req->async.handle->state = LDB_ASYNC_DONE; + req->handle->state = LDB_ASYNC_DONE; return ret; } @@ -764,17 +764,17 @@ static int ltdb_modify(struct ldb_module *module, struct ldb_request *req) } } - req->async.handle = NULL; + req->handle = NULL; - 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) { 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); tret = ltdb_check_special_dn(module, req->op.mod.message); if (tret != LDB_SUCCESS) { - req->async.handle->status = tret; + req->handle->status = tret; goto done; } @@ -785,7 +785,7 @@ static int ltdb_modify(struct ldb_module *module, struct ldb_request *req) tret = ltdb_modify_internal(module, req->op.mod.message); if (tret != LDB_SUCCESS) { - req->async.handle->status = tret; + req->handle->status = tret; goto done; } @@ -793,7 +793,7 @@ static int ltdb_modify(struct ldb_module *module, struct ldb_request *req) ret = ltdb_ac->callback(module->ldb, ltdb_ac->context, NULL); } done: - req->async.handle->state = LDB_ASYNC_DONE; + req->handle->state = LDB_ASYNC_DONE; return ret; } @@ -814,17 +814,17 @@ static int ltdb_rename(struct ldb_module *module, struct ldb_request *req) } } - req->async.handle = NULL; + req->handle = NULL; if (ltdb_cache_load(module) != 0) { 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) { 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); msg = talloc(ltdb_ac, struct ldb_message); if (msg == NULL) { @@ -837,7 +837,7 @@ static int ltdb_rename(struct ldb_module *module, struct ldb_request *req) tret = ltdb_search_dn1(module, req->op.rename.olddn, msg); if (tret != 1) { /* not finding the old record is an error */ - req->async.handle->status = LDB_ERR_NO_SUCH_OBJECT; + req->handle->status = LDB_ERR_NO_SUCH_OBJECT; goto done; } @@ -864,7 +864,7 @@ static int ltdb_rename(struct ldb_module *module, struct ldb_request *req) ret = ltdb_ac->callback(module->ldb, ltdb_ac->context, NULL); } done: - req->async.handle->state = LDB_ASYNC_DONE; + req->handle->state = LDB_ASYNC_DONE; return ret; } -- cgit From ce20796be2e7259943afa203a2f1a471eaa6776a Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sat, 29 Jul 2006 03:00:16 +0000 Subject: r17304: Improve ldb_tdb error strings a bit more. Andrew Bartlett (This used to be commit 38bd4f61794e5a664822240d77c1e1c61abc7c44) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 1401052955..cbc9d61613 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -271,6 +271,25 @@ static int ltdb_add_internal(struct ldb_module *module, const struct ldb_message ret = ltdb_store(module, msg, TDB_INSERT); if (ret != LDB_SUCCESS) { + switch (ret) { + case LDB_ERR_ENTRY_ALREADY_EXISTS: + { + TALLOC_CTX *mem_ctx = talloc_new(module); + char *errstring, *dn; + if (!mem_ctx) { + break; + } + dn = ldb_dn_linearize(mem_ctx, msg->dn); + if (!dn) { + break; + } + errstring = talloc_asprintf(mem_ctx, "Entry %s already exists", + dn); + ldb_set_errstring(module->ldb, errstring); + talloc_free(mem_ctx); + break; + } + } return ret; } @@ -694,7 +713,8 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms if (msg->elements[i].num_values == 0) { if (msg_delete_attribute(module, ldb, msg2, msg->elements[i].name) != 0) { - err_string = talloc_asprintf(module, "No such attribute: %s", msg->elements[i].name); + err_string = talloc_asprintf(module, "No such attribute: %s for delete on %s", + msg->elements[i].name, dn); if (err_string) ldb_set_errstring(module->ldb, err_string); ret = LDB_ERR_NO_SUCH_ATTRIBUTE; goto failed; @@ -706,7 +726,8 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms msg2, msg->elements[i].name, &msg->elements[i].values[j]) != 0) { - err_string = talloc_asprintf(module, "No such attribute: %s", msg->elements[i].name); + err_string = talloc_asprintf(module, "No matching attribute value when deleting attribute: %s on %s", + msg->elements[i].name, dn); if (err_string) ldb_set_errstring(module->ldb, err_string); ret = LDB_ERR_NO_SUCH_ATTRIBUTE; goto failed; -- cgit From b94b9d8c3d7b99294eb48437894d8c6901e9dc70 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Tue, 1 Aug 2006 02:25:05 +0000 Subject: r17349: We can't just return sucess here, modules below us expect the async reply rules to be followed. Add code to do a fake async callback on the skipped records. Andrew Bartlett (This used to be commit 26bc7dbed978f92e814d9803366eac7d7f4ded3e) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 55 ++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 24 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index cbc9d61613..588f73fe23 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -270,35 +270,42 @@ static int ltdb_add_internal(struct ldb_module *module, const struct ldb_message } ret = ltdb_store(module, msg, TDB_INSERT); - if (ret != LDB_SUCCESS) { - switch (ret) { - case LDB_ERR_ENTRY_ALREADY_EXISTS: - { - TALLOC_CTX *mem_ctx = talloc_new(module); - char *errstring, *dn; - if (!mem_ctx) { - break; - } - dn = ldb_dn_linearize(mem_ctx, msg->dn); - if (!dn) { - break; - } - errstring = talloc_asprintf(mem_ctx, "Entry %s already exists", - dn); - ldb_set_errstring(module->ldb, errstring); - talloc_free(mem_ctx); + switch (ret) { + case LDB_SUCCESS: + { + TALLOC_CTX *mem_ctx = talloc_new(module); + char *dn; + dn = ldb_dn_linearize(mem_ctx, msg->dn); + if (!dn) { break; } + ret = ltdb_modified(module, msg->dn); + if (ret != LDB_SUCCESS) { + return LDB_ERR_OPERATIONS_ERROR; } - return ret; + break; } - - ret = ltdb_modified(module, msg->dn); - if (ret != LDB_SUCCESS) { - return LDB_ERR_OPERATIONS_ERROR; + case LDB_ERR_ENTRY_ALREADY_EXISTS: + { + TALLOC_CTX *mem_ctx = talloc_new(module); + char *errstring, *dn; + if (!mem_ctx) { + break; + } + dn = ldb_dn_linearize(mem_ctx, msg->dn); + if (!dn) { + break; + } + errstring = talloc_asprintf(mem_ctx, "Entry %s already exists", + dn); + ldb_set_errstring(module->ldb, errstring); + talloc_free(mem_ctx); + break; } - - return LDB_SUCCESS; + default: + break; + } + return ret; } /* -- cgit From b1b9617d1c1833da2efa93b011733060c6670976 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Tue, 1 Aug 2006 03:22:02 +0000 Subject: r17350: Avoid a couple of memleaks, unnecessary code and use a more linear style (This used to be commit 97c4d41a30a5d85145abb781cb7001b502bc7dcb) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 39 ++++++++++++--------------------------- 1 file changed, 12 insertions(+), 27 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 588f73fe23..7ee715f561 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -270,41 +270,26 @@ static int ltdb_add_internal(struct ldb_module *module, const struct ldb_message } ret = ltdb_store(module, msg, TDB_INSERT); - switch (ret) { - case LDB_SUCCESS: - { - TALLOC_CTX *mem_ctx = talloc_new(module); + + if (ret == LDB_ERR_ENTRY_ALREADY_EXISTS) { char *dn; - dn = ldb_dn_linearize(mem_ctx, msg->dn); + + dn = ldb_dn_linearize(module, msg->dn); if (!dn) { - break; + return ret; } + ldb_set_errstring(module->ldb, talloc_asprintf(module, "Entry %s already exists", dn)); + talloc_free(dn); + return ret; + } + + if (ret == LDB_SUCCESS) { ret = ltdb_modified(module, msg->dn); if (ret != LDB_SUCCESS) { return LDB_ERR_OPERATIONS_ERROR; } - break; - } - case LDB_ERR_ENTRY_ALREADY_EXISTS: - { - TALLOC_CTX *mem_ctx = talloc_new(module); - char *errstring, *dn; - if (!mem_ctx) { - break; - } - dn = ldb_dn_linearize(mem_ctx, msg->dn); - if (!dn) { - break; - } - errstring = talloc_asprintf(mem_ctx, "Entry %s already exists", - dn); - ldb_set_errstring(module->ldb, errstring); - talloc_free(mem_ctx); - break; - } - default: - break; } + return ret; } -- 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_tdb.c | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 7ee715f561..8f8cb68d98 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -87,7 +87,7 @@ struct ldb_handle *init_ltdb_handle(struct ltdb_private *ltdb, struct ldb_module h = talloc_zero(ltdb, struct ldb_handle); if (h == NULL) { - ldb_set_errstring(module->ldb, talloc_asprintf(module, "Out of Memory")); + ldb_set_errstring(module->ldb, "Out of Memory"); return NULL; } @@ -95,7 +95,7 @@ struct ldb_handle *init_ltdb_handle(struct ltdb_private *ltdb, struct ldb_module ac = talloc_zero(h, struct ltdb_context); if (ac == NULL) { - ldb_set_errstring(module->ldb, talloc_asprintf(module, "Out of Memory")); + ldb_set_errstring(module->ldb, "Out of Memory"); talloc_free(h); return NULL; } @@ -181,10 +181,7 @@ int ltdb_check_special_dn(struct ldb_module *module, const struct ldb_message *m for (i = 0; i < msg->num_elements; i++) { for (j = 0; j < msg->elements[i].num_values; j++) { if (ltdb_check_at_attributes_values(&msg->elements[i].values[j]) != 0) { - char *err_string = talloc_strdup(module, "Invalid attribute value in an @ATTRIBUTES entry"); - if (err_string) { - ldb_set_errstring(module->ldb, err_string); - } + ldb_set_errstring(module->ldb, "Invalid attribute value in an @ATTRIBUTES entry"); return LDB_ERR_INVALID_ATTRIBUTE_SYNTAX; } } @@ -258,6 +255,7 @@ done: static int ltdb_add_internal(struct ldb_module *module, const struct ldb_message *msg) { + char *err; int ret; ret = ltdb_check_special_dn(module, msg); @@ -278,7 +276,7 @@ static int ltdb_add_internal(struct ldb_module *module, const struct ldb_message if (!dn) { return ret; } - ldb_set_errstring(module->ldb, talloc_asprintf(module, "Entry %s already exists", dn)); + ldb_asprintf_errstring(module->ldb, "Entry %s already exists", dn); talloc_free(dn); return ret; } @@ -629,7 +627,6 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms struct ldb_message_element *el = &msg->elements[i]; struct ldb_message_element *el2; struct ldb_val *vals; - char *err_string; char *dn; switch (msg->elements[i].flags & LDB_FLAG_MOD_MASK) { @@ -654,8 +651,7 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms for (j=0;jnum_values;j++) { if (ldb_msg_find_val(el2, &el->values[j])) { - err_string = talloc_strdup(module, "Type or value exists"); - if (err_string) ldb_set_errstring(module->ldb, err_string); + ldb_set_errstring(module->ldb, "Type or value exists"); ret = LDB_ERR_ATTRIBUTE_OR_VALUE_EXISTS; goto failed; } @@ -705,9 +701,7 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms if (msg->elements[i].num_values == 0) { if (msg_delete_attribute(module, ldb, msg2, msg->elements[i].name) != 0) { - err_string = talloc_asprintf(module, "No such attribute: %s for delete on %s", - msg->elements[i].name, dn); - if (err_string) ldb_set_errstring(module->ldb, err_string); + ldb_asprintf_errstring(module->ldb, "No such attribute: %s for delete on %s", msg->elements[i].name, dn); ret = LDB_ERR_NO_SUCH_ATTRIBUTE; goto failed; } @@ -718,9 +712,7 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms msg2, msg->elements[i].name, &msg->elements[i].values[j]) != 0) { - err_string = talloc_asprintf(module, "No matching attribute value when deleting attribute: %s on %s", - msg->elements[i].name, dn); - if (err_string) ldb_set_errstring(module->ldb, err_string); + ldb_asprintf_errstring(module->ldb, "No matching attribute value when deleting attribute: %s on %s", msg->elements[i].name, dn); ret = LDB_ERR_NO_SUCH_ATTRIBUTE; goto failed; } @@ -731,10 +723,9 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms } break; default: - err_string = talloc_asprintf(module, "Invalid ldb_modify flags on %s: 0x%x", - msg->elements[i].name, - msg->elements[i].flags & LDB_FLAG_MOD_MASK); - if (err_string) ldb_set_errstring(module->ldb, err_string); + ldb_asprintf_errstring(module->ldb, "Invalid ldb_modify flags on %s: 0x%x", + msg->elements[i].name, + msg->elements[i].flags & LDB_FLAG_MOD_MASK); ret = LDB_ERR_PROTOCOL_ERROR; goto failed; } -- cgit From a23b63a8e54db7d0ec98ad95cdca11dd4d039e17 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sun, 13 Aug 2006 08:00:36 +0000 Subject: r17516: Change helper function names to make more clear what they are meant to do (This used to be commit ad75cf869550af66119d0293503024d41d834e02) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 8f8cb68d98..97b03a9410 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -953,7 +953,7 @@ static int ltdb_sequence_number(struct ldb_module *module, struct ldb_request *r return LDB_SUCCESS; } - req->op.seq_num.seq_num = ldb_msg_find_uint64(msg, LTDB_SEQUENCE_NUMBER, 0); + req->op.seq_num.seq_num = ldb_msg_find_attr_as_uint64(msg, LTDB_SEQUENCE_NUMBER, 0); talloc_free(tmp_ctx); return LDB_SUCCESS; } -- cgit From cc973cbd7776ba03a08047ca7e6bef7700bbf37d Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 22 Aug 2006 18:09:49 +0000 Subject: r17711: fix compiler warnings metze (This used to be commit f3dc51fef53287cc2e2af7ed4a9f3f52a5cd06ed) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 97b03a9410..5a19dd96fc 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -255,7 +255,6 @@ done: static int ltdb_add_internal(struct ldb_module *module, const struct ldb_message *msg) { - char *err; int ret; ret = ltdb_check_special_dn(module, msg); -- cgit From 77db3973c417cc934485dbd6bf1a8a1c84c1b30b Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Thu, 21 Sep 2006 06:44:12 +0000 Subject: r18781: Move the usnCreated and usnChanged handling around again. This moves these attributes from objectguid into an optional backend (objectguid), used by ltdb. For OpenLDAP, the entryUUID module converts entryCSN into usnChanged. This also changes the sequence number API, and uses 'time based' sequence numbers, when an LDAP or similar backend is detected. To assist this, we also store the last modified time in the TDB, whenever we change a value. Andrew Bartlett (This used to be commit 72858f859483c0c532dddb2c146d6bd7b9be5072) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 5a19dd96fc..8f676654a6 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -944,6 +944,8 @@ static int ltdb_sequence_number(struct ldb_module *module, struct ldb_request *r return LDB_ERR_OPERATIONS_ERROR; } + req->op.seq_num.flags = 0; + tret = ltdb_search_dn1(module, dn, msg); if (tret != 1) { talloc_free(tmp_ctx); @@ -952,7 +954,26 @@ static int ltdb_sequence_number(struct ldb_module *module, struct ldb_request *r return LDB_SUCCESS; } - req->op.seq_num.seq_num = ldb_msg_find_attr_as_uint64(msg, LTDB_SEQUENCE_NUMBER, 0); + switch (req->op.seq_num.type) { + case LDB_SEQ_HIGHEST_SEQ: + req->op.seq_num.seq_num = ldb_msg_find_attr_as_uint64(msg, LTDB_SEQUENCE_NUMBER, 0); + break; + case LDB_SEQ_NEXT: + req->op.seq_num.seq_num = ldb_msg_find_attr_as_uint64(msg, LTDB_SEQUENCE_NUMBER, 0); + req->op.seq_num.seq_num++; + break; + case LDB_SEQ_HIGHEST_TIMESTAMP: + { + const char *date = ldb_msg_find_attr_as_string(msg, LTDB_MOD_TIMESTAMP, NULL); + if (date) { + req->op.seq_num.seq_num = ldb_string_to_time(date); + } else { + req->op.seq_num.seq_num = 0; + /* zero is as good as anything when we don't know */ + } + break; + } + } talloc_free(tmp_ctx); return LDB_SUCCESS; } -- cgit From 4e7c9367a7f885b685d7d1476c359e5848356f83 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 27 Sep 2006 03:34:50 +0000 Subject: r18939: don't rely on the umask being right in ldb creation. Both Samba3 and Samba4 smbd force the umask to 0, which meant we ended up with ldb being world writable. This isn't really an ideal fix, as it means ldb no longer honors umask (as it should do, like all good libraries). Unfortunately the 'proper' fix is too complex for now this also merges a tiny code style fix from s4 to s3 (This used to be commit 1a42f38dfdc55d7429a1f8d3e811f3d857195a58) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 8f676654a6..5d43783903 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -1036,7 +1036,7 @@ static int ltdb_connect(struct ldb_context *ldb, const char *url, /* note that we use quite a large default hash size */ ltdb->tdb = ltdb_wrap_open(ltdb, path, 10000, - tdb_flags, open_flags, 0666, ldb); + tdb_flags, open_flags, 0644, ldb); if (!ltdb->tdb) { ldb_debug(ldb, LDB_DEBUG_ERROR, "Unable to open tdb '%s'\n", path); talloc_free(ltdb); -- cgit From 4c3b07b654f4eb9041da0e9a84bc60d667901fe5 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 27 Sep 2006 05:57:41 +0000 Subject: r18942: add a ldb_set_create_perms() function in ldb. I didn't call it ldb_set_umask() (which is what we had discussed) as it doesn't actually set the umask (in effect it sets the inverse of the umask - the perms to be used for the file) (This used to be commit 7e2ec875908c112d5c3b0f6d18f9a8bbacf33539) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 5d43783903..579c48791b 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -1036,7 +1036,8 @@ static int ltdb_connect(struct ldb_context *ldb, const char *url, /* note that we use quite a large default hash size */ ltdb->tdb = ltdb_wrap_open(ltdb, path, 10000, - tdb_flags, open_flags, 0644, ldb); + tdb_flags, open_flags, + ldb->create_perms, ldb); if (!ltdb->tdb) { ldb_debug(ldb, LDB_DEBUG_ERROR, "Unable to open tdb '%s'\n", path); talloc_free(ltdb); -- cgit From 109bf77ea3e96d255e74aa7c5dfbaf131a625452 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 6 Oct 2006 15:03:41 +0000 Subject: r19134: Merge the second set of C++ warning fixes from Samba3. I'll leave r19132 to metze to merge until the questions have been answered. Volker (This used to be commit e946717bf600f4ff922dc55a9a5d259535d0d1c9) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 579c48791b..171752d106 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -219,7 +219,8 @@ static int ltdb_modified(struct ldb_module *module, const struct ldb_dn *dn) */ int ltdb_store(struct ldb_module *module, const struct ldb_message *msg, int flgs) { - struct ltdb_private *ltdb = module->private_data; + struct ltdb_private *ltdb = + talloc_get_type(module->private_data, struct ltdb_private); TDB_DATA tdb_key, tdb_data; int ret; @@ -332,7 +333,8 @@ done: */ int ltdb_delete_noindex(struct ldb_module *module, const struct ldb_dn *dn) { - struct ltdb_private *ltdb = module->private_data; + struct ltdb_private *ltdb = + talloc_get_type(module->private_data, struct ltdb_private); TDB_DATA tdb_key; int ret; @@ -589,7 +591,8 @@ static int msg_delete_element(struct ldb_module *module, int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *msg) { struct ldb_context *ldb = module->ldb; - struct ltdb_private *ltdb = module->private_data; + struct ltdb_private *ltdb = + talloc_get_type(module->private_data, struct ltdb_private); TDB_DATA tdb_key, tdb_data; struct ldb_message *msg2; unsigned i, j; @@ -873,7 +876,8 @@ done: static int ltdb_start_trans(struct ldb_module *module) { - struct ltdb_private *ltdb = module->private_data; + struct ltdb_private *ltdb = + talloc_get_type(module->private_data, struct ltdb_private); if (tdb_transaction_start(ltdb->tdb) != 0) { return ltdb_err_map(tdb_error(ltdb->tdb)); @@ -884,7 +888,8 @@ static int ltdb_start_trans(struct ldb_module *module) static int ltdb_end_trans(struct ldb_module *module) { - struct ltdb_private *ltdb = module->private_data; + struct ltdb_private *ltdb = + talloc_get_type(module->private_data, struct ltdb_private); if (tdb_transaction_commit(ltdb->tdb) != 0) { return ltdb_err_map(tdb_error(ltdb->tdb)); @@ -895,7 +900,8 @@ static int ltdb_end_trans(struct ldb_module *module) static int ltdb_del_trans(struct ldb_module *module) { - struct ltdb_private *ltdb = module->private_data; + struct ltdb_private *ltdb = + talloc_get_type(module->private_data, struct ltdb_private); if (tdb_transaction_cancel(ltdb->tdb) != 0) { return ltdb_err_map(tdb_error(ltdb->tdb)); -- cgit From bbc056e067e1b721dc2ef6958ab653c1eddec3a1 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 9 Oct 2006 09:56:13 +0000 Subject: r19196: merge from samba3: pass always a mem_ctx to functions and a ldb_context where needed metze (This used to be commit 67a6a41ba3af840cd8226de73576a90ecf602caa) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 171752d106..608120e3a7 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -138,7 +138,7 @@ struct TDB_DATA ltdb_key(struct ldb_module *module, const struct ldb_dn *dn) the rest */ - dn_folded = ldb_dn_linearize_casefold(ldb, dn); + dn_folded = ldb_dn_linearize_casefold(ldb, ldb, dn); if (!dn_folded) { goto failed; } -- 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_tdb.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 608120e3a7..bd3045d477 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -79,13 +79,12 @@ static int ltdb_err_map(enum TDB_ERROR tdb_code) struct ldb_handle *init_ltdb_handle(struct ltdb_private *ltdb, struct ldb_module *module, - void *context, - int (*callback)(struct ldb_context *, void *, struct ldb_reply *)) + struct ldb_request *req) { struct ltdb_context *ac; struct ldb_handle *h; - h = talloc_zero(ltdb, struct ldb_handle); + h = talloc_zero(req, struct ldb_handle); if (h == NULL) { ldb_set_errstring(module->ldb, "Out of Memory"); return NULL; @@ -106,8 +105,8 @@ struct ldb_handle *init_ltdb_handle(struct ltdb_private *ltdb, struct ldb_module h->status = LDB_SUCCESS; ac->module = module; - ac->context = context; - ac->callback = callback; + ac->context = req->context; + ac->callback = req->callback; return h; } @@ -307,7 +306,7 @@ static int ltdb_add(struct ldb_module *module, struct ldb_request *req) } } - req->handle = init_ltdb_handle(ltdb, module, req->context, req->callback); + req->handle = init_ltdb_handle(ltdb, module, req); if (req->handle == NULL) { return LDB_ERR_OPERATIONS_ERROR; } @@ -416,7 +415,7 @@ static int ltdb_delete(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) { return LDB_ERR_OPERATIONS_ERROR; } @@ -772,7 +771,7 @@ static int ltdb_modify(struct ldb_module *module, struct ldb_request *req) req->handle = NULL; - req->handle = init_ltdb_handle(ltdb, module, req->context, req->callback); + req->handle = init_ltdb_handle(ltdb, module, req); if (req->handle == NULL) { return LDB_ERR_OPERATIONS_ERROR; } @@ -826,7 +825,7 @@ static int ltdb_rename(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) { return LDB_ERR_OPERATIONS_ERROR; } -- cgit From 0f2347e417dec4a50f95d64353b260cd53a44a2b Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 16 Oct 2006 12:33:21 +0000 Subject: r19338: leak on error (This used to be commit 326389afed0521133ac07339bd5e2bfbf8d80d0a) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index bd3045d477..b7a202442d 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -386,6 +386,7 @@ static int ltdb_delete_internal(struct ldb_module *module, const struct ldb_dn * ret = ltdb_modified(module, dn); if (ret != LDB_SUCCESS) { + talloc_free(msg); return LDB_ERR_OPERATIONS_ERROR; } -- cgit From e36ea2e8ebe44079dd3989694f0235e77caf4fe2 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 17 Oct 2006 01:21:02 +0000 Subject: r19362: - don't need to store the baseinfo message after cache load - set better names on talloc structures in ldb modules, making leaks easier to track down (This used to be commit 3bf76db42dc6dde5d71083216dba819869b31c75) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index b7a202442d..fd1c8780ae 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -1058,11 +1058,18 @@ static int ltdb_connect(struct ldb_context *ldb, const char *url, talloc_free(ltdb); return -1; } + talloc_set_name_const(*module, "ldb_tdb backend"); (*module)->ldb = ldb; (*module)->prev = (*module)->next = NULL; (*module)->private_data = ltdb; (*module)->ops = <db_ops; + if (ltdb_cache_load(*module) != 0) { + talloc_free(*module); + talloc_free(ltdb); + return -1; + } + return 0; } -- 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_tdb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index fd1c8780ae..3f9db39097 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -1021,7 +1021,7 @@ static int ltdb_connect(struct ldb_context *ldb, const char *url, path = url; } - tdb_flags = TDB_DEFAULT; + tdb_flags = TDB_DEFAULT | TDB_SEQNUM; /* check for the 'nosync' option */ if (flags & LDB_FLG_NOSYNC) { -- 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_tdb.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 3f9db39097..d950ab9cf0 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -118,7 +118,7 @@ struct ldb_handle *init_ltdb_handle(struct ltdb_private *ltdb, struct ldb_module note that the key for a record can depend on whether the dn refers to a case sensitive index record or not */ -struct TDB_DATA ltdb_key(struct ldb_module *module, const struct ldb_dn *dn) +struct TDB_DATA ltdb_key(struct ldb_module *module, struct ldb_dn *dn) { struct ldb_context *ldb = module->ldb; TDB_DATA key; @@ -137,15 +137,13 @@ struct TDB_DATA ltdb_key(struct ldb_module *module, const struct ldb_dn *dn) the rest */ - dn_folded = ldb_dn_linearize_casefold(ldb, ldb, dn); + dn_folded = ldb_dn_get_casefold(dn); if (!dn_folded) { goto failed; } key_str = talloc_asprintf(ldb, "DN=%s", dn_folded); - talloc_free(dn_folded); - if (!key_str) { goto failed; } @@ -194,7 +192,7 @@ int ltdb_check_special_dn(struct ldb_module *module, const struct ldb_message *m we've made a modification to a dn - possibly reindex and update sequence number */ -static int ltdb_modified(struct ldb_module *module, const struct ldb_dn *dn) +static int ltdb_modified(struct ldb_module *module, struct ldb_dn *dn) { int ret = 0; @@ -330,7 +328,7 @@ done: delete a record from the database, not updating indexes (used for deleting index records) */ -int ltdb_delete_noindex(struct ldb_module *module, const struct ldb_dn *dn) +int ltdb_delete_noindex(struct ldb_module *module, struct ldb_dn *dn) { struct ltdb_private *ltdb = talloc_get_type(module->private_data, struct ltdb_private); @@ -352,7 +350,7 @@ int ltdb_delete_noindex(struct ldb_module *module, const struct ldb_dn *dn) return ret; } -static int ltdb_delete_internal(struct ldb_module *module, const struct ldb_dn *dn) +static int ltdb_delete_internal(struct ldb_module *module, struct ldb_dn *dn) { struct ldb_message *msg; int ret; @@ -936,7 +934,7 @@ static int ltdb_sequence_number(struct ldb_module *module, struct ldb_request *r { TALLOC_CTX *tmp_ctx = talloc_new(req); struct ldb_message *msg = NULL; - struct ldb_dn *dn = ldb_dn_explode(tmp_ctx, LTDB_BASEINFO); + struct ldb_dn *dn = ldb_dn_new(tmp_ctx, module->ldb, LTDB_BASEINFO); int tret; if (tmp_ctx == NULL) { -- 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_tdb.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index d950ab9cf0..9b05d98a66 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -123,7 +123,7 @@ struct TDB_DATA ltdb_key(struct ldb_module *module, struct ldb_dn *dn) struct ldb_context *ldb = module->ldb; TDB_DATA key; char *key_str = NULL; - char *dn_folded = NULL; + const char *dn_folded = NULL; /* most DNs are case insensitive. The exception is index DNs for @@ -267,14 +267,7 @@ static int ltdb_add_internal(struct ldb_module *module, const struct ldb_message ret = ltdb_store(module, msg, TDB_INSERT); if (ret == LDB_ERR_ENTRY_ALREADY_EXISTS) { - char *dn; - - dn = ldb_dn_linearize(module, msg->dn); - if (!dn) { - return ret; - } - ldb_asprintf_errstring(module->ldb, "Entry %s already exists", dn); - talloc_free(dn); + ldb_asprintf_errstring(module->ldb, "Entry %s already exists", ldb_dn_get_linearized(msg->dn)); return ret; } @@ -504,10 +497,10 @@ static int msg_delete_attribute(struct ldb_module *module, struct ldb_context *ldb, struct ldb_message *msg, const char *name) { - char *dn; + const char *dn; unsigned int i, j; - dn = ldb_dn_linearize(ldb, msg->dn); + dn = ldb_dn_get_linearized(msg->dn); if (dn == NULL) { return -1; } @@ -532,7 +525,6 @@ static int msg_delete_attribute(struct ldb_module *module, } } - talloc_free(dn); return 0; } @@ -627,7 +619,7 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms struct ldb_message_element *el = &msg->elements[i]; struct ldb_message_element *el2; struct ldb_val *vals; - char *dn; + const char *dn; switch (msg->elements[i].flags & LDB_FLAG_MOD_MASK) { @@ -690,7 +682,7 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms case LDB_FLAG_MOD_DELETE: - dn = ldb_dn_linearize(msg2, msg->dn); + dn = ldb_dn_get_linearized(msg->dn); if (dn == NULL) { ret = LDB_ERR_OTHER; goto failed; -- cgit From 2ee7e831f2e5dbd41a61b92eaccf20aa9e17145f Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 27 Nov 2006 05:32:35 +0000 Subject: r19911: talloc_apsrintf is not really required here its faster this way (another 2-4%s) (This used to be commit 8bbbfa3467c00543b0b330aec14e22b7e796fea7) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 9b05d98a66..bf90115f51 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -142,8 +142,12 @@ struct TDB_DATA ltdb_key(struct ldb_module *module, struct ldb_dn *dn) goto failed; } - key_str = talloc_asprintf(ldb, "DN=%s", dn_folded); + key_str = talloc_strdup(ldb, "DN="); + if (!key_str) { + goto failed; + } + key_str = talloc_append_string(ldb, key_str, dn_folded); if (!key_str) { goto failed; } -- cgit From 2cd08c14a014a9326c6f42b83b4f2187bd2165b2 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 11 Dec 2006 15:49:39 +0000 Subject: r20106: Optional ONE Level indexing for ldb_tdb To activate it you must modify the @INDEXLIST object adding the attribute @IDXONE: 1 Ldb test included Simo. (This used to be commit ea111795f4016916473ccc05d23c6655e6af1207) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index bf90115f51..09ddca5034 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -276,6 +276,11 @@ static int ltdb_add_internal(struct ldb_module *module, const struct ldb_message } if (ret == LDB_SUCCESS) { + ret = ltdb_index_one(module, msg, 1); + if (ret != LDB_SUCCESS) { + return LDB_ERR_OPERATIONS_ERROR; + } + ret = ltdb_modified(module, msg->dn); if (ret != LDB_SUCCESS) { return LDB_ERR_OPERATIONS_ERROR; @@ -372,6 +377,13 @@ static int ltdb_delete_internal(struct ldb_module *module, struct ldb_dn *dn) return LDB_ERR_NO_SUCH_OBJECT; } + /* remove one level attribute */ + ret = ltdb_index_one(module, msg, 0); + if (ret != LDB_SUCCESS) { + talloc_free(msg); + return LDB_ERR_OPERATIONS_ERROR; + } + /* remove any indexed attributes */ ret = ltdb_index_del(module, msg); if (ret != LDB_SUCCESS) { -- 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_tdb.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 09ddca5034..6adf6f48ca 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -558,7 +558,7 @@ static int msg_delete_element(struct ldb_module *module, unsigned int i; int found; struct ldb_message_element *el; - const struct ldb_attrib_handler *h; + const struct ldb_schema_attribute *a; found = find_element(msg, name); if (found == -1) { @@ -567,10 +567,10 @@ static int msg_delete_element(struct ldb_module *module, el = &msg->elements[found]; - h = ldb_attrib_handler(ldb, el->name); + a = ldb_schema_attribute_by_name(ldb, el->name); for (i=0;inum_values;i++) { - if (h->comparison_fn(ldb, ldb, &el->values[i], val) == 0) { + if (a->syntax->comparison_fn(ldb, ldb, &el->values[i], val) == 0) { if (inum_values-1) { memmove(&el->values[i], &el->values[i+1], sizeof(el->values[i])*(el->num_values-(i+1))); -- cgit From 545f97f94e443fa7b05fe9be95efcecec89346c5 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 17 Jan 2007 22:22:29 +0000 Subject: r20865: remove useless warning, we now always pass the current partition control as non critical control metze (This used to be commit 21fddb643bf05ca2b7c60a4695e1fff0f29ec6d1) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 35 ++++++++++------------------------- 1 file changed, 10 insertions(+), 25 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 6adf6f48ca..16ab5b905b 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -299,11 +299,8 @@ static int ltdb_add(struct ldb_module *module, struct ldb_request *req) struct ltdb_context *ltdb_ac; int tret, ret = LDB_SUCCESS; - if (req->controls != NULL) { - ldb_debug(module->ldb, LDB_DEBUG_WARNING, "Controls should not reach the ldb_tdb backend!\n"); - if (check_critical_controls(req->controls)) { - return LDB_ERR_UNSUPPORTED_CRITICAL_EXTENSION; - } + if (check_critical_controls(req->controls)) { + return LDB_ERR_UNSUPPORTED_CRITICAL_EXTENSION; } req->handle = init_ltdb_handle(ltdb, module, req); @@ -410,11 +407,8 @@ static int ltdb_delete(struct ldb_module *module, struct ldb_request *req) struct ltdb_context *ltdb_ac; int tret, ret = LDB_SUCCESS; - if (req->controls != NULL) { - ldb_debug(module->ldb, LDB_DEBUG_WARNING, "Controls should not reach the ldb_tdb backend!\n"); - if (check_critical_controls(req->controls)) { - return LDB_ERR_UNSUPPORTED_CRITICAL_EXTENSION; - } + if (check_critical_controls(req->controls)) { + return LDB_ERR_UNSUPPORTED_CRITICAL_EXTENSION; } req->handle = NULL; @@ -769,11 +763,8 @@ static int ltdb_modify(struct ldb_module *module, struct ldb_request *req) struct ltdb_context *ltdb_ac; int tret, ret = LDB_SUCCESS; - if (req->controls != NULL) { - ldb_debug(module->ldb, LDB_DEBUG_WARNING, "Controls should not reach the ldb_tdb backend!\n"); - if (check_critical_controls(req->controls)) { - return LDB_ERR_UNSUPPORTED_CRITICAL_EXTENSION; - } + if (check_critical_controls(req->controls)) { + return LDB_ERR_UNSUPPORTED_CRITICAL_EXTENSION; } req->handle = NULL; @@ -819,11 +810,8 @@ static int ltdb_rename(struct ldb_module *module, struct ldb_request *req) struct ldb_message *msg; int tret, ret = LDB_SUCCESS; - if (req->controls != NULL) { - ldb_debug(module->ldb, LDB_DEBUG_WARNING, "Controls should not reach the ldb_tdb backend!\n"); - if (check_critical_controls(req->controls)) { - return LDB_ERR_UNSUPPORTED_CRITICAL_EXTENSION; - } + if (check_critical_controls(req->controls)) { + return LDB_ERR_UNSUPPORTED_CRITICAL_EXTENSION; } req->handle = NULL; @@ -924,11 +912,8 @@ static int ltdb_wait(struct ldb_handle *handle, enum ldb_wait_type type) static int ltdb_request(struct ldb_module *module, struct ldb_request *req) { /* check for oustanding critical controls and return an error if found */ - if (req->controls != NULL) { - ldb_debug(module->ldb, LDB_DEBUG_WARNING, "Controls should not reach the ldb_tdb backend!\n"); - if (check_critical_controls(req->controls)) { - return LDB_ERR_UNSUPPORTED_CRITICAL_EXTENSION; - } + if (check_critical_controls(req->controls)) { + return LDB_ERR_UNSUPPORTED_CRITICAL_EXTENSION; } /* search, add, modify, delete, rename are handled by their own, no other op supported */ -- 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_tdb.c | 46 ++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 25 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 16ab5b905b..8a6d26ff98 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -198,7 +198,7 @@ int ltdb_check_special_dn(struct ldb_module *module, const struct ldb_message *m */ static int ltdb_modified(struct ldb_module *module, struct ldb_dn *dn) { - int ret = 0; + int ret = LDB_SUCCESS; if (ldb_dn_is_special(dn) && (ldb_dn_check_special(dn, LTDB_INDEXLIST) || @@ -206,7 +206,7 @@ static int ltdb_modified(struct ldb_module *module, struct ldb_dn *dn) ret = ltdb_reindex(module); } - if (ret == 0 && + if (ret == LDB_SUCCESS && !(ldb_dn_is_special(dn) && ldb_dn_check_special(dn, LTDB_BASEINFO)) ) { ret = ltdb_increase_sequence_number(module); @@ -243,7 +243,7 @@ int ltdb_store(struct ldb_module *module, const struct ldb_message *msg, int flg } ret = ltdb_index_add(module, msg); - if (ret == -1) { + if (ret != LDB_SUCCESS) { tdb_delete(ltdb->tdb, tdb_key); } @@ -278,12 +278,12 @@ static int ltdb_add_internal(struct ldb_module *module, const struct ldb_message if (ret == LDB_SUCCESS) { ret = ltdb_index_one(module, msg, 1); if (ret != LDB_SUCCESS) { - return LDB_ERR_OPERATIONS_ERROR; + return ret; } ret = ltdb_modified(module, msg->dn); if (ret != LDB_SUCCESS) { - return LDB_ERR_OPERATIONS_ERROR; + return ret; } } @@ -362,40 +362,36 @@ static int ltdb_delete_internal(struct ldb_module *module, struct ldb_dn *dn) /* in case any attribute of the message was indexed, we need to fetch the old record */ ret = ltdb_search_dn1(module, dn, msg); - if (ret != 1) { + if (ret != LDB_SUCCESS) { /* not finding the old record is an error */ - talloc_free(msg); - return LDB_ERR_NO_SUCH_OBJECT; + goto done; } ret = ltdb_delete_noindex(module, dn); if (ret != LDB_SUCCESS) { - talloc_free(msg); - return LDB_ERR_NO_SUCH_OBJECT; + goto done; } /* remove one level attribute */ ret = ltdb_index_one(module, msg, 0); if (ret != LDB_SUCCESS) { - talloc_free(msg); - return LDB_ERR_OPERATIONS_ERROR; + goto done; } /* remove any indexed attributes */ ret = ltdb_index_del(module, msg); if (ret != LDB_SUCCESS) { - talloc_free(msg); - return LDB_ERR_OPERATIONS_ERROR; + goto done; } ret = ltdb_modified(module, dn); if (ret != LDB_SUCCESS) { - talloc_free(msg); - return LDB_ERR_OPERATIONS_ERROR; + goto done; } +done: talloc_free(msg); - return LDB_SUCCESS; + return ret; } /* @@ -718,8 +714,8 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms ret = LDB_ERR_NO_SUCH_ATTRIBUTE; goto failed; } - if (ltdb_index_del_value(module, dn, &msg->elements[i], j) != 0) { - ret = LDB_ERR_OTHER; + ret = ltdb_index_del_value(module, dn, &msg->elements[i], j); + if (ret != LDB_SUCCESS) { goto failed; } } @@ -739,8 +735,8 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms goto failed; } - if (ltdb_modified(module, msg->dn) != LDB_SUCCESS) { - ret = LDB_ERR_OPERATIONS_ERROR; + ret = ltdb_modified(module, msg->dn); + if (ret != LDB_SUCCESS) { goto failed; } @@ -835,9 +831,9 @@ static int ltdb_rename(struct ldb_module *module, struct ldb_request *req) /* in case any attribute of the message was indexed, we need to fetch the old record */ tret = ltdb_search_dn1(module, req->op.rename.olddn, msg); - if (tret != 1) { + if (tret != LDB_SUCCESS) { /* not finding the old record is an error */ - req->handle->status = LDB_ERR_NO_SUCH_OBJECT; + req->handle->status = tret; goto done; } @@ -944,10 +940,10 @@ static int ltdb_sequence_number(struct ldb_module *module, struct ldb_request *r req->op.seq_num.flags = 0; tret = ltdb_search_dn1(module, dn, msg); - if (tret != 1) { + if (tret != LDB_SUCCESS) { talloc_free(tmp_ctx); - req->op.seq_num.seq_num = 0; /* zero is as good as anything when we don't know */ + req->op.seq_num.seq_num = 0; return 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_tdb.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 8a6d26ff98..dee61308d3 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -42,10 +42,9 @@ * Author: Simo Sorce */ -#include "includes.h" -#include "ldb/include/includes.h" +#include "ldb_includes.h" -#include "ldb/ldb_tdb/ldb_tdb.h" +#include "ldb_tdb.h" /* -- cgit From d89e6c774bbf6738183459c52acbd3220482d58a Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 6 Jun 2007 12:44:04 +0000 Subject: r23364: add LDB_FLG_NOMMAP flag (This used to be commit 0c3442c68b01b6804f3fd966fc1fe9097eb863aa) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index dee61308d3..b8e2ec6191 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -1014,6 +1014,11 @@ static int ltdb_connect(struct ldb_context *ldb, const char *url, tdb_flags |= TDB_NOSYNC; } + /* and nommap option */ + if (flags & LDB_FLG_NOMMAP) { + tdb_flags |= TDB_NOMMAP; + } + if (flags & LDB_FLG_RDONLY) { open_flags = O_RDONLY; } else { -- cgit From b0db52b63aaf2278d72c5e0bafbbdb6582b85112 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sat, 7 Jul 2007 04:34:36 +0000 Subject: r23737: Validate that we object to duplicate values in an add or replace. We can't ever allow duplicates, even if the client sends them Andrew Bartlett (This used to be commit 10277f27246b9e16ed36fb72eb4c318b43cb9395) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index b8e2ec6191..6dff3942a8 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -591,7 +591,7 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms TDB_DATA tdb_key, tdb_data; struct ldb_message *msg2; unsigned i, j; - int ret; + int ret, idx; tdb_key = ltdb_key(module, msg->dn); if (!tdb_key.dptr) { @@ -631,9 +631,9 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms case LDB_FLAG_MOD_ADD: /* add this element to the message. fail if it already exists */ - ret = find_element(msg2, el->name); + idx = find_element(msg2, el->name); - if (ret == -1) { + if (idx == -1) { if (msg_add_element(ldb, msg2, el) != 0) { ret = LDB_ERR_OTHER; goto failed; @@ -641,14 +641,21 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms continue; } - el2 = &msg2->elements[ret]; + el2 = &msg2->elements[idx]; - /* An attribute with this name already exists, add all - * values if they don't already exist. */ + /* An attribute with this name already exists, + * add all values if they don't already exist + * (check both the other elements to be added, + * and those already in the db). */ for (j=0;jnum_values;j++) { if (ldb_msg_find_val(el2, &el->values[j])) { - ldb_set_errstring(module->ldb, "Type or value exists"); + ldb_asprintf_errstring(module->ldb, "%s: value #%d already exists", el->name, j); + ret = LDB_ERR_ATTRIBUTE_OR_VALUE_EXISTS; + goto failed; + } + if (ldb_msg_find_val(el, &el->values[j]) != &el->values[j]) { + ldb_asprintf_errstring(module->ldb, "%s: value #%d provided more than once", el->name, j); ret = LDB_ERR_ATTRIBUTE_OR_VALUE_EXISTS; goto failed; } @@ -675,11 +682,19 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms case LDB_FLAG_MOD_REPLACE: /* replace all elements of this attribute name with the elements listed. The attribute not existing is not an error */ - msg_delete_attribute(module, ldb, msg2, msg->elements[i].name); + msg_delete_attribute(module, ldb, msg2, el->name); + + for (j=0;jnum_values;j++) { + if (ldb_msg_find_val(el, &el->values[j]) != &el->values[j]) { + ldb_asprintf_errstring(module->ldb, "%s: value #%d provided more than once", el->name, j); + ret = LDB_ERR_ATTRIBUTE_OR_VALUE_EXISTS; + goto failed; + } + } /* add the replacement element, if not empty */ - if (msg->elements[i].num_values != 0 && - msg_add_element(ldb, msg2, &msg->elements[i]) != 0) { + if (el->num_values != 0 && + msg_add_element(ldb, msg2, el) != 0) { ret = LDB_ERR_OTHER; goto failed; } -- cgit From 2d2cde7d95e0871ea66ce8186a54c3b28834051b Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 9 Jul 2007 12:31:35 +0000 Subject: r23762: Fix DN renames over LDAP, and instrument the partition module. Add a test to prove the behaviour of LDAP renames etc. Fix LDB to return correct error code when failing to rename one DN onto another. Andrew Bartlett (This used to be commit 3f3da9c4710b7752ed97f55c2fc3d32a63d352af) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 6dff3942a8..335e7d540e 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -857,9 +857,8 @@ static int ltdb_rename(struct ldb_module *module, struct ldb_request *req) goto done; } - tret = ltdb_add_internal(module, msg); - if (tret != LDB_SUCCESS) { - ret = LDB_ERR_OPERATIONS_ERROR; + ret = ltdb_add_internal(module, msg); + if (ret != LDB_SUCCESS) { goto done; } -- 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_tdb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 335e7d540e..3cbd2ea6a7 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -13,7 +13,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_tdb.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 3cbd2ea6a7..324a8e3881 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -21,8 +21,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 6a9a1bd913a7cdc865c88a290020e6bddb777f98 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Tue, 18 Sep 2007 06:36:07 +0000 Subject: r25204: Patch by Andrew Kroeger fixing bug #4958 - rename of ldb entries for a case change (only). I've modified the testsuite to verify this. Andrew Bartlett (This used to be commit 9cccd00dac44dd9152ec03cecf5ffac24f918445) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 40 ++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 324a8e3881..21661b1d46 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -856,16 +856,38 @@ static int ltdb_rename(struct ldb_module *module, struct ldb_request *req) goto done; } - ret = ltdb_add_internal(module, msg); - if (ret != LDB_SUCCESS) { - goto done; - } + if (ldb_dn_compare(req->op.rename.olddn, req->op.rename.newdn) == 0) { + /* The rename operation is apparently only changing case - + the DNs are the same. Delete the old DN before adding + the new one to avoid a TDB_ERR_EXISTS error. + + The only drawback to this is that if the delete + succeeds but the add fails, we rely on the + transaction to roll this all back. */ + ret = ltdb_delete_internal(module, req->op.rename.olddn); + if (ret != LDB_SUCCESS) { + goto done; + } - tret = ltdb_delete_internal(module, req->op.rename.olddn); - if (tret != LDB_SUCCESS) { - ltdb_delete_internal(module, req->op.rename.newdn); - ret = LDB_ERR_OPERATIONS_ERROR; - goto done; + ret = ltdb_add_internal(module, msg); + if (ret != LDB_SUCCESS) { + goto done; + } + } else { + /* The rename operation is changing DNs. Try to add the new + DN first to avoid clobbering another DN not related to + this rename operation. */ + ret = ltdb_add_internal(module, msg); + if (ret != LDB_SUCCESS) { + goto done; + } + + tret = ltdb_delete_internal(module, req->op.rename.olddn); + if (tret != LDB_SUCCESS) { + ltdb_delete_internal(module, req->op.rename.newdn); + ret = LDB_ERR_OPERATIONS_ERROR; + goto done; + } } if (ltdb_ac->callback) { -- cgit From c364bbbfa3441f40e3bcab76392d998163e7bf76 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 18 Sep 2007 13:41:50 +0000 Subject: r25215: replace talloc_append_string() with talloc_strdup_append_buffer() metze (This used to be commit 8f2db3c130ce85d38f805836a7df039822ede066) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 21661b1d46..3461f98d5f 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -145,7 +145,7 @@ struct TDB_DATA ltdb_key(struct ldb_module *module, struct ldb_dn *dn) goto failed; } - key_str = talloc_append_string(ldb, key_str, dn_folded); + key_str = talloc_strdup_append_buffer(key_str, dn_folded); if (!key_str) { goto failed; } -- 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_tdb.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 3461f98d5f..949164a505 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -907,6 +907,8 @@ static int ltdb_start_trans(struct ldb_module *module) return ltdb_err_map(tdb_error(ltdb->tdb)); } + ltdb->in_transaction++; + return LDB_SUCCESS; } @@ -915,6 +917,8 @@ static int ltdb_end_trans(struct ldb_module *module) struct ltdb_private *ltdb = talloc_get_type(module->private_data, struct ltdb_private); + ltdb->in_transaction--; + if (tdb_transaction_commit(ltdb->tdb) != 0) { return ltdb_err_map(tdb_error(ltdb->tdb)); } @@ -927,6 +931,8 @@ static int ltdb_del_trans(struct ldb_module *module) struct ltdb_private *ltdb = talloc_get_type(module->private_data, struct ltdb_private); + ltdb->in_transaction--; + if (tdb_transaction_cancel(ltdb->tdb) != 0) { return ltdb_err_map(tdb_error(ltdb->tdb)); } -- cgit From 2d400c1dd1ba1c5a49d2d79bdf7593d430da92e8 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sun, 23 Dec 2007 22:03:31 -0600 Subject: r26574: Do not call functions in the variable declaration, fix checking for tmp_ctx, and also makes code more readable and debuggable. Eliminate silly parenthesys. Simo. (This used to be commit 166195b487ffa51933f772a56f47f7f0d4c867eb) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 949164a505..45a8109584 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -961,16 +961,20 @@ static int ltdb_request(struct ldb_module *module, struct ldb_request *req) */ static int ltdb_sequence_number(struct ldb_module *module, struct ldb_request *req) { - TALLOC_CTX *tmp_ctx = talloc_new(req); + TALLOC_CTX *tmp_ctx; struct ldb_message *msg = NULL; - struct ldb_dn *dn = ldb_dn_new(tmp_ctx, module->ldb, LTDB_BASEINFO); + struct ldb_dn *dn; + const char *date; int tret; + tmp_ctx = talloc_new(req); if (tmp_ctx == NULL) { talloc_free(tmp_ctx); return LDB_ERR_OPERATIONS_ERROR; } + dn = ldb_dn_new(tmp_ctx, module->ldb, LTDB_BASEINFO); + msg = talloc(tmp_ctx, struct ldb_message); if (msg == NULL) { talloc_free(tmp_ctx); @@ -996,8 +1000,7 @@ static int ltdb_sequence_number(struct ldb_module *module, struct ldb_request *r req->op.seq_num.seq_num++; break; case LDB_SEQ_HIGHEST_TIMESTAMP: - { - const char *date = ldb_msg_find_attr_as_string(msg, LTDB_MOD_TIMESTAMP, NULL); + date = ldb_msg_find_attr_as_string(msg, LTDB_MOD_TIMESTAMP, NULL); if (date) { req->op.seq_num.seq_num = ldb_string_to_time(date); } else { @@ -1006,7 +1009,6 @@ static int ltdb_sequence_number(struct ldb_module *module, struct ldb_request *r } break; } - } talloc_free(tmp_ctx); return LDB_SUCCESS; } -- cgit From 995788536e5ba7b3a0e67e377a9769b279d0b8ae Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 20 Feb 2008 02:57:07 +0100 Subject: Remove more function-based inits. (This used to be commit b1a7810f3e70f9a831d9b8e85d531e448072adaf) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 45a8109584..11d6c30710 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -1107,7 +1107,7 @@ static int ltdb_connect(struct ldb_context *ldb, const char *url, return 0; } -int ldb_tdb_init(void) -{ - return ldb_register_backend("tdb", ltdb_connect); -} +const struct ldb_backend_ops ldb_tdb_backend_ops = { + .name = "tdb", + .connect_fn = ltdb_connect +}; -- cgit From 4d8804f26cc554fe3a7bec78d09738ff1bbda7f7 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sat, 14 Jun 2008 20:37:40 -0400 Subject: Cleanup, Remove trailing spaces and try to fit 80 columns where possible (This used to be commit edf6b77a1314d8f91839836855ae049393f73aca) --- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 149 ++++++++++++++++++++++---------------- 1 file changed, 88 insertions(+), 61 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_tdb.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 11d6c30710..01d570c89a 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -1,15 +1,15 @@ -/* +/* ldb database library Copyright (C) Andrew Tridgell 2004 Copyright (C) Stefan Metzmacher 2004 Copyright (C) Simo Sorce 2006 - + ** 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 @@ -76,7 +76,8 @@ static int ltdb_err_map(enum TDB_ERROR tdb_code) } -struct ldb_handle *init_ltdb_handle(struct ltdb_private *ltdb, struct ldb_module *module, +struct ldb_handle *init_ltdb_handle(struct ltdb_private *ltdb, + struct ldb_module *module, struct ldb_request *req) { struct ltdb_context *ac; @@ -113,7 +114,7 @@ struct ldb_handle *init_ltdb_handle(struct ltdb_private *ltdb, struct ldb_module form a TDB_DATA for a record key caller frees - note that the key for a record can depend on whether the + note that the key for a record can depend on whether the dn refers to a case sensitive index record or not */ struct TDB_DATA ltdb_key(struct ldb_module *module, struct ldb_dn *dn) @@ -131,8 +132,8 @@ struct TDB_DATA ltdb_key(struct ldb_module *module, struct ldb_dn *dn) 1) if the dn doesn't start with @ then uppercase the attribute names and the attributes values of case insensitive attributes - 2) if the dn starts with @ then leave it alone - the indexing code handles - the rest + 2) if the dn starts with @ then leave it alone - + the indexing code handles the rest */ dn_folded = ldb_dn_get_casefold(dn); @@ -166,10 +167,11 @@ failed: check special dn's have valid attributes currently only @ATTRIBUTES is checked */ -int ltdb_check_special_dn(struct ldb_module *module, const struct ldb_message *msg) +int ltdb_check_special_dn(struct ldb_module *module, + const struct ldb_message *msg) { int i, j; - + if (! ldb_dn_is_special(msg->dn) || ! ldb_dn_check_special(msg->dn, LTDB_ATTRIBUTES)) { return 0; @@ -191,7 +193,7 @@ int ltdb_check_special_dn(struct ldb_module *module, const struct ldb_message *m /* - we've made a modification to a dn - possibly reindex and + we've made a modification to a dn - possibly reindex and update sequence number */ static int ltdb_modified(struct ldb_module *module, struct ldb_dn *dn) @@ -239,7 +241,7 @@ int ltdb_store(struct ldb_module *module, const struct ldb_message *msg, int flg ret = ltdb_err_map(tdb_error(ltdb->tdb)); goto done; } - + ret = ltdb_index_add(module, msg); if (ret != LDB_SUCCESS) { tdb_delete(ltdb->tdb, tdb_key); @@ -253,15 +255,16 @@ done: } -static int ltdb_add_internal(struct ldb_module *module, const struct ldb_message *msg) +static int ltdb_add_internal(struct ldb_module *module, + const struct ldb_message *msg) { int ret; - + ret = ltdb_check_special_dn(module, msg); if (ret != LDB_SUCCESS) { return ret; } - + if (ltdb_cache_load(module) != 0) { return LDB_ERR_OPERATIONS_ERROR; } @@ -269,10 +272,12 @@ static int ltdb_add_internal(struct ldb_module *module, const struct ldb_message ret = ltdb_store(module, msg, TDB_INSERT); if (ret == LDB_ERR_ENTRY_ALREADY_EXISTS) { - ldb_asprintf_errstring(module->ldb, "Entry %s already exists", ldb_dn_get_linearized(msg->dn)); + ldb_asprintf_errstring(module->ldb, + "Entry %s already exists", + ldb_dn_get_linearized(msg->dn)); return ret; } - + if (ret == LDB_SUCCESS) { ret = ltdb_index_one(module, msg, 1); if (ret != LDB_SUCCESS) { @@ -293,14 +298,16 @@ static int ltdb_add_internal(struct ldb_module *module, const struct ldb_message */ static int ltdb_add(struct ldb_module *module, struct ldb_request *req) { - struct ltdb_private *ltdb = talloc_get_type(module->private_data, struct ltdb_private); + struct ltdb_private *ltdb; struct ltdb_context *ltdb_ac; int tret, ret = LDB_SUCCESS; + ltdb = talloc_get_type(module->private_data, struct ltdb_private); + if (check_critical_controls(req->controls)) { return LDB_ERR_UNSUPPORTED_CRITICAL_EXTENSION; } - + req->handle = init_ltdb_handle(ltdb, module, req); if (req->handle == NULL) { return LDB_ERR_OPERATIONS_ERROR; @@ -312,7 +319,7 @@ static int ltdb_add(struct ldb_module *module, struct ldb_request *req) req->handle->status = tret; goto done; } - + if (ltdb_ac->callback) { ret = ltdb_ac->callback(module->ldb, ltdb_ac->context, NULL); } @@ -397,14 +404,16 @@ done: */ static int ltdb_delete(struct ldb_module *module, struct ldb_request *req) { - struct ltdb_private *ltdb = talloc_get_type(module->private_data, struct ltdb_private); + struct ltdb_private *ltdb; struct ltdb_context *ltdb_ac; int tret, ret = LDB_SUCCESS; + ltdb = talloc_get_type(module->private_data, struct ltdb_private); + if (check_critical_controls(req->controls)) { return LDB_ERR_UNSUPPORTED_CRITICAL_EXTENSION; } - + req->handle = NULL; if (ltdb_cache_load(module) != 0) { @@ -419,7 +428,7 @@ static int ltdb_delete(struct ldb_module *module, struct ldb_request *req) tret = ltdb_delete_internal(module, req->op.del.dn); if (tret != LDB_SUCCESS) { - req->handle->status = tret; + req->handle->status = tret; goto done; } @@ -432,9 +441,9 @@ done: } /* - find an element by attribute name. At the moment this does a linear search, it should - be re-coded to use a binary search once all places that modify records guarantee - sorted order + find an element by attribute name. At the moment this does a linear search, + it should be re-coded to use a binary search once all places that modify + records guarantee sorted order return the index of the first matching element if found, otherwise -1 */ @@ -452,18 +461,19 @@ static int find_element(const struct ldb_message *msg, const char *name) /* add an element to an existing record. Assumes a elements array that we - can call re-alloc on, and assumed that we can re-use the data pointers from the - passed in additional values. Use with care! + can call re-alloc on, and assumed that we can re-use the data pointers from + the passed in additional values. Use with care! returns 0 on success, -1 on failure (and sets errno) */ static int msg_add_element(struct ldb_context *ldb, - struct ldb_message *msg, struct ldb_message_element *el) + struct ldb_message *msg, + struct ldb_message_element *el) { struct ldb_message_element *e2; unsigned int i; - e2 = talloc_realloc(msg, msg->elements, struct ldb_message_element, + e2 = talloc_realloc(msg, msg->elements, struct ldb_message_element, msg->num_elements+1); if (!e2) { errno = ENOMEM; @@ -478,7 +488,8 @@ static int msg_add_element(struct ldb_context *ldb, e2->flags = el->flags; e2->values = NULL; if (el->num_values != 0) { - e2->values = talloc_array(msg->elements, struct ldb_val, el->num_values); + e2->values = talloc_array(msg->elements, + struct ldb_val, el->num_values); if (!e2->values) { errno = ENOMEM; return -1; @@ -512,20 +523,21 @@ static int msg_delete_attribute(struct ldb_module *module, for (i=0;inum_elements;i++) { if (ldb_attr_cmp(msg->elements[i].name, name) == 0) { for (j=0;jelements[i].num_values;j++) { - ltdb_index_del_value(module, dn, &msg->elements[i], j); + ltdb_index_del_value(module, dn, + &msg->elements[i], j); } talloc_free(msg->elements[i].values); if (msg->num_elements > (i+1)) { - memmove(&msg->elements[i], - &msg->elements[i+1], + memmove(&msg->elements[i], + &msg->elements[i+1], sizeof(struct ldb_message_element)* (msg->num_elements - (i+1))); } msg->num_elements--; i--; - msg->elements = talloc_realloc(msg, msg->elements, - struct ldb_message_element, - msg->num_elements); + msg->elements = talloc_realloc(msg, msg->elements, + struct ldb_message_element, + msg->num_elements); } } @@ -533,12 +545,12 @@ static int msg_delete_attribute(struct ldb_module *module, } /* - delete all elements matching an attribute name/value + delete all elements matching an attribute name/value return 0 on success, -1 on failure */ static int msg_delete_element(struct ldb_module *module, - struct ldb_message *msg, + struct ldb_message *msg, const char *name, const struct ldb_val *val) { @@ -558,14 +570,17 @@ static int msg_delete_element(struct ldb_module *module, a = ldb_schema_attribute_by_name(ldb, el->name); for (i=0;inum_values;i++) { - if (a->syntax->comparison_fn(ldb, ldb, &el->values[i], val) == 0) { + if (a->syntax->comparison_fn(ldb, ldb, + &el->values[i], val) == 0) { if (inum_values-1) { memmove(&el->values[i], &el->values[i+1], - sizeof(el->values[i])*(el->num_values-(i+1))); + sizeof(el->values[i])* + (el->num_values-(i+1))); } el->num_values--; if (el->num_values == 0) { - return msg_delete_attribute(module, ldb, msg, name); + return msg_delete_attribute(module, ldb, + msg, name); } return 0; } @@ -579,10 +594,11 @@ static int msg_delete_element(struct ldb_module *module, modify a record - internal interface yuck - this is O(n^2). Luckily n is usually small so we probably - get away with it, but if we ever have really large attribute lists + get away with it, but if we ever have really large attribute lists then we'll need to look at this again */ -int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *msg) +int ltdb_modify_internal(struct ldb_module *module, + const struct ldb_message *msg) { struct ldb_context *ldb = module->ldb; struct ltdb_private *ltdb = @@ -734,15 +750,17 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms } break; default: - ldb_asprintf_errstring(module->ldb, "Invalid ldb_modify flags on %s: 0x%x", - msg->elements[i].name, - msg->elements[i].flags & LDB_FLAG_MOD_MASK); + ldb_asprintf_errstring(module->ldb, + "Invalid ldb_modify flags on %s: 0x%x", + msg->elements[i].name, + msg->elements[i].flags & LDB_FLAG_MOD_MASK); ret = LDB_ERR_PROTOCOL_ERROR; goto failed; } } - /* we've made all the mods - save the modified record back into the database */ + /* we've made all the mods + * save the modified record back into the database */ ret = ltdb_store(module, msg2, TDB_MODIFY); if (ret != LDB_SUCCESS) { goto failed; @@ -768,14 +786,16 @@ failed: */ static int ltdb_modify(struct ldb_module *module, struct ldb_request *req) { - struct ltdb_private *ltdb = talloc_get_type(module->private_data, struct ltdb_private); + struct ltdb_private *ltdb; struct ltdb_context *ltdb_ac; int tret, ret = LDB_SUCCESS; + ltdb = talloc_get_type(module->private_data, struct ltdb_private); + if (check_critical_controls(req->controls)) { return LDB_ERR_UNSUPPORTED_CRITICAL_EXTENSION; } - + req->handle = NULL; req->handle = init_ltdb_handle(ltdb, module, req); @@ -789,7 +809,7 @@ static int ltdb_modify(struct ldb_module *module, struct ldb_request *req) req->handle->status = tret; goto done; } - + if (ltdb_cache_load(module) != 0) { ret = LDB_ERR_OPERATIONS_ERROR; goto done; @@ -814,15 +834,17 @@ done: */ static int ltdb_rename(struct ldb_module *module, struct ldb_request *req) { - struct ltdb_private *ltdb = talloc_get_type(module->private_data, struct ltdb_private); + struct ltdb_private *ltdb; struct ltdb_context *ltdb_ac; struct ldb_message *msg; int tret, ret = LDB_SUCCESS; + ltdb = talloc_get_type(module->private_data, struct ltdb_private); + if (check_critical_controls(req->controls)) { return LDB_ERR_UNSUPPORTED_CRITICAL_EXTENSION; } - + req->handle = NULL; if (ltdb_cache_load(module) != 0) { @@ -947,19 +969,22 @@ static int ltdb_wait(struct ldb_handle *handle, enum ldb_wait_type type) static int ltdb_request(struct ldb_module *module, struct ldb_request *req) { - /* check for oustanding critical controls and return an error if found */ + /* check for oustanding critical controls + * and return an error if found */ if (check_critical_controls(req->controls)) { return LDB_ERR_UNSUPPORTED_CRITICAL_EXTENSION; } - - /* search, add, modify, delete, rename are handled by their own, no other op supported */ + + /* search, add, modify, delete, rename are handled by their own, + * no other op supported */ return LDB_ERR_OPERATIONS_ERROR; } /* return sequenceNumber from @BASEINFO */ -static int ltdb_sequence_number(struct ldb_module *module, struct ldb_request *req) +static int ltdb_sequence_number(struct ldb_module *module, + struct ldb_request *req) { TALLOC_CTX *tmp_ctx; struct ldb_message *msg = NULL; @@ -1031,7 +1056,7 @@ static const struct ldb_module_ops ltdb_ops = { /* connect to the database */ -static int ltdb_connect(struct ldb_context *ldb, const char *url, +static int ltdb_connect(struct ldb_context *ldb, const char *url, unsigned int flags, const char *options[], struct ldb_module **module) { @@ -1042,7 +1067,8 @@ static int ltdb_connect(struct ldb_context *ldb, const char *url, /* parse the url */ if (strchr(url, ':')) { if (strncmp(url, "tdb://", 6) != 0) { - ldb_debug(ldb, LDB_DEBUG_ERROR, "Invalid tdb URL '%s'", url); + ldb_debug(ldb, LDB_DEBUG_ERROR, + "Invalid tdb URL '%s'", url); return -1; } path = url+6; @@ -1075,11 +1101,12 @@ static int ltdb_connect(struct ldb_context *ldb, const char *url, } /* note that we use quite a large default hash size */ - ltdb->tdb = ltdb_wrap_open(ltdb, path, 10000, - tdb_flags, open_flags, + ltdb->tdb = ltdb_wrap_open(ltdb, path, 10000, + tdb_flags, open_flags, ldb->create_perms, ldb); if (!ltdb->tdb) { - ldb_debug(ldb, LDB_DEBUG_ERROR, "Unable to open tdb '%s'\n", path); + ldb_debug(ldb, LDB_DEBUG_ERROR, + "Unable to open tdb '%s'\n", path); talloc_free(ltdb); return -1; } -- cgit