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_cache.c | 229 ++++++++++++++++++++++++++++++++++++ 1 file changed, 229 insertions(+) create mode 100644 source4/lib/ldb/ldb_tdb/ldb_cache.c (limited to 'source4/lib/ldb/ldb_tdb/ldb_cache.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_cache.c b/source4/lib/ldb/ldb_tdb/ldb_cache.c new file mode 100644 index 0000000000..5d61fd35b3 --- /dev/null +++ b/source4/lib/ldb/ldb_tdb/ldb_cache.c @@ -0,0 +1,229 @@ +/* + 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 cache functions + * + * Description: cache special records in a ldb/tdb + * + * Author: Andrew Tridgell + */ + +#include "includes.h" +#include "ldb/ldb_tdb/ldb_tdb.h" + +/* + initialise the baseinfo record +*/ +static int ltdb_baseinfo_init(struct ldb_context *ldb) +{ + struct ltdb_private *ltdb = ldb->private_data; + struct ldb_message msg; + struct ldb_message_element el; + struct ldb_val val; + + ltdb->sequence_number = 0; + + msg.num_elements = 1; + msg.elements = ⪙ + msg.dn = LTDB_BASEINFO; + el.name = LTDB_SEQUENCE_NUMBER; + el.values = &val; + el.num_values = 1; + el.flags = 0; + val.data = "0"; + val.length = 1; + + return ltdb_store(ldb, &msg, TDB_INSERT); +} + +/* + free any cache records + */ +void ltdb_cache_free(struct ldb_context *ldb) +{ + struct ltdb_private *ltdb = ldb->private_data; + + ltdb->sequence_number = 0; + ltdb_search_dn1_free(ldb, <db->cache.baseinfo); + ltdb_search_dn1_free(ldb, <db->cache.indexlist); + ltdb_search_dn1_free(ldb, <db->cache.subclasses); + ltdb_search_dn1_free(ldb, <db->cache.attributes); + + if (ltdb->cache.last_attribute.name) free(ltdb->cache.last_attribute.name); + memset(<db->cache, 0, sizeof(ltdb->cache)); +} + +/* + load the cache records +*/ +int ltdb_cache_load(struct ldb_context *ldb) +{ + struct ltdb_private *ltdb = ldb->private_data; + double seq; + + ltdb_search_dn1_free(ldb, <db->cache.baseinfo); + + if (ltdb_search_dn1(ldb, LTDB_BASEINFO, <db->cache.baseinfo) == -1) { + return -1; + } + + /* possibly initialise the baseinfo */ + if (!ltdb->cache.baseinfo.dn) { + if (ltdb_baseinfo_init(ldb) != 0) { + return -1; + } + if (ltdb_search_dn1(ldb, LTDB_BASEINFO, <db->cache.baseinfo) != 1) { + return -1; + } + } + + /* if the current internal sequence number is the same as the one + in the database then assume the rest of the cache is OK */ + seq = ldb_msg_find_double(<db->cache.baseinfo, LTDB_SEQUENCE_NUMBER, 0); + if (seq == ltdb->sequence_number) { + return 0; + } + ltdb->sequence_number = seq; + + if (ltdb->cache.last_attribute.name) free(ltdb->cache.last_attribute.name); + memset(<db->cache.last_attribute, 0, sizeof(ltdb->cache.last_attribute)); + + ltdb_search_dn1_free(ldb, <db->cache.indexlist); + ltdb_search_dn1_free(ldb, <db->cache.subclasses); + ltdb_search_dn1_free(ldb, <db->cache.attributes); + + if (ltdb_search_dn1(ldb, LTDB_INDEXLIST, <db->cache.indexlist) == -1) { + return -1; + } + if (ltdb_search_dn1(ldb, LTDB_SUBCLASSES, <db->cache.subclasses) == -1) { + return -1; + } + if (ltdb_search_dn1(ldb, LTDB_ATTRIBUTES, <db->cache.attributes) == -1) { + return -1; + } + + return 0; +} + + +/* + increase the sequence number to indicate a database change +*/ +int ltdb_increase_sequence_number(struct ldb_context *ldb) +{ + struct ltdb_private *ltdb = ldb->private_data; + struct ldb_message msg; + struct ldb_message_element el; + struct ldb_val val; + char *s = NULL; + int ret; + + asprintf(&s, "%.0f", ltdb->sequence_number+1); + if (!s) { + errno = ENOMEM; + return -1; + } + + msg.num_elements = 1; + msg.elements = ⪙ + msg.dn = LTDB_BASEINFO; + el.name = LTDB_SEQUENCE_NUMBER; + el.values = &val; + el.num_values = 1; + el.flags = LDB_FLAG_MOD_REPLACE; + val.data = s; + val.length = strlen(s); + + ret = ltdb_modify_internal(ldb, &msg); + + free(s); + + if (ret == 0) { + ltdb->sequence_number += 1; + } + + return ret; +} + + +/* + return the attribute flags from the @ATTRIBUTES record + for the given attribute +*/ +int ltdb_attribute_flags(struct ldb_context *ldb, const char *attr_name) +{ + struct ltdb_private *ltdb = ldb->private_data; + const char *attrs; + const struct { + const char *name; + int value; + } names[] = { + { "CASE_INSENSITIVE", LTDB_FLAG_CASE_INSENSITIVE }, + { "INTEGER", LTDB_FLAG_INTEGER }, + { "WILDCARD", LTDB_FLAG_WILDCARD }, + { NULL, 0} + }; + size_t len; + int i, ret=0; + + if (ltdb->cache.last_attribute.name && + ldb_attr_cmp(ltdb->cache.last_attribute.name, attr_name) == 0) { + return ltdb->cache.last_attribute.flags; + } + + /* objectclass is a special default case */ + if (ldb_attr_cmp(attr_name, LTDB_OBJECTCLASS) == 0) { + ret = LTDB_FLAG_OBJECTCLASS | LTDB_FLAG_CASE_INSENSITIVE; + } + + attrs = ldb_msg_find_string(<db->cache.attributes, attr_name, NULL); + + if (!attrs) { + return ret; + } + + /* we avoid using strtok and friends due to their nasty + interface. This is a little trickier, but much nicer + from a C interface point of view */ + while ((len = strcspn(attrs, " ,")) > 0) { + for (i=0;names[i].name;i++) { + if (strncmp(names[i].name, attrs, len) == 0 && + names[i].name[len] == 0) { + ret |= names[i].value; + } + } + attrs += len; + attrs += strspn(attrs, " ,"); + } + + if (ltdb->cache.last_attribute.name) free(ltdb->cache.last_attribute.name); + + ltdb->cache.last_attribute.name = strdup(attr_name); + ltdb->cache.last_attribute.flags = ret; + + return ret; +} -- cgit From 232bc1503fc0e3f85b4711f077d2566dc0f0c823 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 5 May 2004 04:27:29 +0000 Subject: r490: - expanded the test suite to test modify and delete operations - made yet another attempt to make ldb const clean. - "make test" now runs both the tdb and ldap backend tests, and run the ldbtest utility with and without indexing - added prototypes in ldb.h for ldb_msg_*() public functions (This used to be commit 01e87406768cb5a98ac8530a2f361a4987a36cd3) --- source4/lib/ldb/ldb_tdb/ldb_cache.c | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_cache.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_cache.c b/source4/lib/ldb/ldb_tdb/ldb_cache.c index 5d61fd35b3..3c6ce63c2b 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_cache.c +++ b/source4/lib/ldb/ldb_tdb/ldb_cache.c @@ -44,20 +44,42 @@ static int ltdb_baseinfo_init(struct ldb_context *ldb) struct ldb_message msg; struct ldb_message_element el; struct ldb_val val; + int ret; ltdb->sequence_number = 0; msg.num_elements = 1; msg.elements = ⪙ - msg.dn = LTDB_BASEINFO; - el.name = LTDB_SEQUENCE_NUMBER; + msg.dn = strdup(LTDB_BASEINFO); + if (!msg.dn) { + errno = ENOMEM; + return -1; + } + el.name = strdup(LTDB_SEQUENCE_NUMBER); + if (!el.name) { + free(msg.dn); + errno = ENOMEM; + return -1; + } el.values = &val; el.num_values = 1; el.flags = 0; - val.data = "0"; + val.data = strdup("0"); + if (!val.data) { + free(el.name); + free(msg.dn); + errno = ENOMEM; + return -1; + } val.length = 1; - return ltdb_store(ldb, &msg, TDB_INSERT); + ret = ltdb_store(ldb, &msg, TDB_INSERT); + + free(msg.dn); + free(el.name); + free(val.data); + + return ret; } /* @@ -150,8 +172,8 @@ int ltdb_increase_sequence_number(struct ldb_context *ldb) msg.num_elements = 1; msg.elements = ⪙ - msg.dn = LTDB_BASEINFO; - el.name = LTDB_SEQUENCE_NUMBER; + msg.dn = strdup(LTDB_BASEINFO); + el.name = strdup(LTDB_SEQUENCE_NUMBER); el.values = &val; el.num_values = 1; el.flags = LDB_FLAG_MOD_REPLACE; @@ -161,6 +183,8 @@ int ltdb_increase_sequence_number(struct ldb_context *ldb) ret = ltdb_modify_internal(ldb, &msg); free(s); + free(msg.dn); + free(el.name); if (ret == 0) { ltdb->sequence_number += 1; -- 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_cache.c | 65 ++++++++++++++++++++++--------------- 1 file changed, 39 insertions(+), 26 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_cache.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_cache.c b/source4/lib/ldb/ldb_tdb/ldb_cache.c index 3c6ce63c2b..6734de9fd8 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_cache.c +++ b/source4/lib/ldb/ldb_tdb/ldb_cache.c @@ -50,24 +50,24 @@ static int ltdb_baseinfo_init(struct ldb_context *ldb) msg.num_elements = 1; msg.elements = ⪙ - msg.dn = strdup(LTDB_BASEINFO); + msg.dn = ldb_strdup(ldb, LTDB_BASEINFO); if (!msg.dn) { errno = ENOMEM; return -1; } - el.name = strdup(LTDB_SEQUENCE_NUMBER); + el.name = ldb_strdup(ldb, LTDB_SEQUENCE_NUMBER); if (!el.name) { - free(msg.dn); + ldb_free(ldb, msg.dn); errno = ENOMEM; return -1; } el.values = &val; el.num_values = 1; el.flags = 0; - val.data = strdup("0"); + val.data = ldb_strdup(ldb, "0"); if (!val.data) { - free(el.name); - free(msg.dn); + ldb_free(ldb, el.name); + ldb_free(ldb, msg.dn); errno = ENOMEM; return -1; } @@ -75,9 +75,9 @@ static int ltdb_baseinfo_init(struct ldb_context *ldb) ret = ltdb_store(ldb, &msg, TDB_INSERT); - free(msg.dn); - free(el.name); - free(val.data); + ldb_free(ldb, msg.dn); + ldb_free(ldb, el.name); + ldb_free(ldb, val.data); return ret; } @@ -88,6 +88,8 @@ static int ltdb_baseinfo_init(struct ldb_context *ldb) void ltdb_cache_free(struct ldb_context *ldb) { struct ltdb_private *ltdb = ldb->private_data; + struct ldb_alloc_ops alloc = ldb->alloc_ops; + ldb->alloc_ops.alloc = NULL; ltdb->sequence_number = 0; ltdb_search_dn1_free(ldb, <db->cache.baseinfo); @@ -95,8 +97,10 @@ void ltdb_cache_free(struct ldb_context *ldb) ltdb_search_dn1_free(ldb, <db->cache.subclasses); ltdb_search_dn1_free(ldb, <db->cache.attributes); - if (ltdb->cache.last_attribute.name) free(ltdb->cache.last_attribute.name); + ldb_free(ldb, ltdb->cache.last_attribute.name); memset(<db->cache, 0, sizeof(ltdb->cache)); + + ldb->alloc_ops = alloc; } /* @@ -106,20 +110,23 @@ int ltdb_cache_load(struct ldb_context *ldb) { struct ltdb_private *ltdb = ldb->private_data; double seq; + struct ldb_alloc_ops alloc = ldb->alloc_ops; + + ldb->alloc_ops.alloc = NULL; ltdb_search_dn1_free(ldb, <db->cache.baseinfo); if (ltdb_search_dn1(ldb, LTDB_BASEINFO, <db->cache.baseinfo) == -1) { - return -1; + goto failed; } /* possibly initialise the baseinfo */ if (!ltdb->cache.baseinfo.dn) { if (ltdb_baseinfo_init(ldb) != 0) { - return -1; + goto failed; } if (ltdb_search_dn1(ldb, LTDB_BASEINFO, <db->cache.baseinfo) != 1) { - return -1; + goto failed; } } @@ -127,11 +134,11 @@ int ltdb_cache_load(struct ldb_context *ldb) in the database then assume the rest of the cache is OK */ seq = ldb_msg_find_double(<db->cache.baseinfo, LTDB_SEQUENCE_NUMBER, 0); if (seq == ltdb->sequence_number) { - return 0; + goto done; } ltdb->sequence_number = seq; - if (ltdb->cache.last_attribute.name) free(ltdb->cache.last_attribute.name); + ldb_free(ldb, ltdb->cache.last_attribute.name); memset(<db->cache.last_attribute, 0, sizeof(ltdb->cache.last_attribute)); ltdb_search_dn1_free(ldb, <db->cache.indexlist); @@ -139,16 +146,22 @@ int ltdb_cache_load(struct ldb_context *ldb) ltdb_search_dn1_free(ldb, <db->cache.attributes); if (ltdb_search_dn1(ldb, LTDB_INDEXLIST, <db->cache.indexlist) == -1) { - return -1; + goto failed; } if (ltdb_search_dn1(ldb, LTDB_SUBCLASSES, <db->cache.subclasses) == -1) { - return -1; + goto failed; } if (ltdb_search_dn1(ldb, LTDB_ATTRIBUTES, <db->cache.attributes) == -1) { - return -1; + goto failed; } +done: + ldb->alloc_ops = alloc; return 0; + +failed: + ldb->alloc_ops = alloc; + return -1; } @@ -164,7 +177,7 @@ int ltdb_increase_sequence_number(struct ldb_context *ldb) char *s = NULL; int ret; - asprintf(&s, "%.0f", ltdb->sequence_number+1); + ldb_asprintf(ldb, &s, "%.0f", ltdb->sequence_number+1); if (!s) { errno = ENOMEM; return -1; @@ -172,8 +185,8 @@ int ltdb_increase_sequence_number(struct ldb_context *ldb) msg.num_elements = 1; msg.elements = ⪙ - msg.dn = strdup(LTDB_BASEINFO); - el.name = strdup(LTDB_SEQUENCE_NUMBER); + msg.dn = ldb_strdup(ldb, LTDB_BASEINFO); + el.name = ldb_strdup(ldb, LTDB_SEQUENCE_NUMBER); el.values = &val; el.num_values = 1; el.flags = LDB_FLAG_MOD_REPLACE; @@ -182,9 +195,9 @@ int ltdb_increase_sequence_number(struct ldb_context *ldb) ret = ltdb_modify_internal(ldb, &msg); - free(s); - free(msg.dn); - free(el.name); + ldb_free(ldb, s); + ldb_free(ldb, msg.dn); + ldb_free(ldb, el.name); if (ret == 0) { ltdb->sequence_number += 1; @@ -244,9 +257,9 @@ int ltdb_attribute_flags(struct ldb_context *ldb, const char *attr_name) attrs += strspn(attrs, " ,"); } - if (ltdb->cache.last_attribute.name) free(ltdb->cache.last_attribute.name); + if (ltdb->cache.last_attribute.name) ldb_free(ldb, ltdb->cache.last_attribute.name); - ltdb->cache.last_attribute.name = strdup(attr_name); + ltdb->cache.last_attribute.name = ldb_strdup(ldb, attr_name); ltdb->cache.last_attribute.flags = ret; return ret; -- cgit From 7216d23ba5eef36872196eaeb0b629fe0cf272c5 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 6 May 2004 07:30:51 +0000 Subject: r509: fixed a memory handling bug that affects ldb with memory pools that change with each request (This used to be commit 18695cefa16b867427e3ca2fb0d787d850ea25c3) --- source4/lib/ldb/ldb_tdb/ldb_cache.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_cache.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_cache.c b/source4/lib/ldb/ldb_tdb/ldb_cache.c index 6734de9fd8..87e9538d01 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_cache.c +++ b/source4/lib/ldb/ldb_tdb/ldb_cache.c @@ -226,6 +226,7 @@ int ltdb_attribute_flags(struct ldb_context *ldb, const char *attr_name) }; size_t len; int i, ret=0; + struct ldb_alloc_ops alloc = ldb->alloc_ops; if (ltdb->cache.last_attribute.name && ldb_attr_cmp(ltdb->cache.last_attribute.name, attr_name) == 0) { @@ -257,10 +258,14 @@ int ltdb_attribute_flags(struct ldb_context *ldb, const char *attr_name) attrs += strspn(attrs, " ,"); } - if (ltdb->cache.last_attribute.name) ldb_free(ldb, ltdb->cache.last_attribute.name); + ldb->alloc_ops.alloc = NULL; + + ldb_free(ldb, ltdb->cache.last_attribute.name); ltdb->cache.last_attribute.name = ldb_strdup(ldb, attr_name); ltdb->cache.last_attribute.flags = ret; + + ldb->alloc_ops = alloc; return ret; } -- cgit From 51d5ddecc60b6e33e1d542cb92b2fe6736849398 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 9 May 2004 12:30:30 +0000 Subject: r606: added a HIDDEN attribute on fields in ldb (in @ATTRIBUTES). This allows you to mark an attribute as only appearing in searches that explicitly name it. It will be used for attributes like nTSecurityDescriptor (This used to be commit f5cd3d733b71368ea652f8a4d653d87f45ff983f) --- source4/lib/ldb/ldb_tdb/ldb_cache.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/lib/ldb/ldb_tdb/ldb_cache.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_cache.c b/source4/lib/ldb/ldb_tdb/ldb_cache.c index 87e9538d01..2a879f384c 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_cache.c +++ b/source4/lib/ldb/ldb_tdb/ldb_cache.c @@ -222,6 +222,7 @@ int ltdb_attribute_flags(struct ldb_context *ldb, const char *attr_name) { "CASE_INSENSITIVE", LTDB_FLAG_CASE_INSENSITIVE }, { "INTEGER", LTDB_FLAG_INTEGER }, { "WILDCARD", LTDB_FLAG_WILDCARD }, + { "HIDDEN", LTDB_FLAG_HIDDEN }, { NULL, 0} }; size_t len; -- cgit From 4b09c0e5d9619fea420da80022829682e028ea57 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 22 Sep 2004 02:05:02 +0000 Subject: r2485: - add a test case in ldbtest for a bug pointed out by Jon Haswell. - fixed the bug shown with the above test, by initialising the sequence number to something different from the value used in ltdb_cache_free() (This used to be commit 856cdf82f24aada074ee5c605cccb2e8ceeea487) --- source4/lib/ldb/ldb_tdb/ldb_cache.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_cache.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_cache.c b/source4/lib/ldb/ldb_tdb/ldb_cache.c index 2a879f384c..55dea406b5 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_cache.c +++ b/source4/lib/ldb/ldb_tdb/ldb_cache.c @@ -45,8 +45,12 @@ static int ltdb_baseinfo_init(struct ldb_context *ldb) struct ldb_message_element el; struct ldb_val val; int ret; + /* the initial sequence number must be different from the one + set in ltdb_cache_free(). Thanks to Jon for pointing this + out. */ + const char *initial_sequence_number = "1"; - ltdb->sequence_number = 0; + ltdb->sequence_number = atof(initial_sequence_number); msg.num_elements = 1; msg.elements = ⪙ @@ -64,7 +68,7 @@ static int ltdb_baseinfo_init(struct ldb_context *ldb) el.values = &val; el.num_values = 1; el.flags = 0; - val.data = ldb_strdup(ldb, "0"); + val.data = ldb_strdup(ldb, initial_sequence_number); if (!val.data) { ldb_free(ldb, el.name); ldb_free(ldb, msg.dn); -- 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_cache.c | 57 ++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 26 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_cache.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_cache.c b/source4/lib/ldb/ldb_tdb/ldb_cache.c index 55dea406b5..cf175090e6 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_cache.c +++ b/source4/lib/ldb/ldb_tdb/ldb_cache.c @@ -38,9 +38,10 @@ /* initialise the baseinfo record */ -static int ltdb_baseinfo_init(struct ldb_context *ldb) +static int ltdb_baseinfo_init(struct ldb_module *module) { - struct ltdb_private *ltdb = ldb->private_data; + struct ldb_context *ldb = module->ldb; + struct ltdb_private *ltdb = module->private_data; struct ldb_message msg; struct ldb_message_element el; struct ldb_val val; @@ -77,7 +78,7 @@ static int ltdb_baseinfo_init(struct ldb_context *ldb) } val.length = 1; - ret = ltdb_store(ldb, &msg, TDB_INSERT); + ret = ltdb_store(module, &msg, TDB_INSERT); ldb_free(ldb, msg.dn); ldb_free(ldb, el.name); @@ -89,17 +90,18 @@ static int ltdb_baseinfo_init(struct ldb_context *ldb) /* free any cache records */ -void ltdb_cache_free(struct ldb_context *ldb) +void ltdb_cache_free(struct ldb_module *module) { - struct ltdb_private *ltdb = ldb->private_data; + struct ldb_context *ldb = module->ldb; + struct ltdb_private *ltdb = module->private_data; struct ldb_alloc_ops alloc = ldb->alloc_ops; ldb->alloc_ops.alloc = NULL; ltdb->sequence_number = 0; - ltdb_search_dn1_free(ldb, <db->cache.baseinfo); - ltdb_search_dn1_free(ldb, <db->cache.indexlist); - ltdb_search_dn1_free(ldb, <db->cache.subclasses); - ltdb_search_dn1_free(ldb, <db->cache.attributes); + ltdb_search_dn1_free(module, <db->cache.baseinfo); + ltdb_search_dn1_free(module, <db->cache.indexlist); + ltdb_search_dn1_free(module, <db->cache.subclasses); + ltdb_search_dn1_free(module, <db->cache.attributes); ldb_free(ldb, ltdb->cache.last_attribute.name); memset(<db->cache, 0, sizeof(ltdb->cache)); @@ -110,26 +112,27 @@ void ltdb_cache_free(struct ldb_context *ldb) /* load the cache records */ -int ltdb_cache_load(struct ldb_context *ldb) +int ltdb_cache_load(struct ldb_module *module) { - struct ltdb_private *ltdb = ldb->private_data; + struct ldb_context *ldb = module->ldb; + struct ltdb_private *ltdb = module->private_data; double seq; struct ldb_alloc_ops alloc = ldb->alloc_ops; ldb->alloc_ops.alloc = NULL; - ltdb_search_dn1_free(ldb, <db->cache.baseinfo); + ltdb_search_dn1_free(module, <db->cache.baseinfo); - if (ltdb_search_dn1(ldb, LTDB_BASEINFO, <db->cache.baseinfo) == -1) { + if (ltdb_search_dn1(module, LTDB_BASEINFO, <db->cache.baseinfo) == -1) { goto failed; } /* possibly initialise the baseinfo */ if (!ltdb->cache.baseinfo.dn) { - if (ltdb_baseinfo_init(ldb) != 0) { + if (ltdb_baseinfo_init(module) != 0) { goto failed; } - if (ltdb_search_dn1(ldb, LTDB_BASEINFO, <db->cache.baseinfo) != 1) { + if (ltdb_search_dn1(module, LTDB_BASEINFO, <db->cache.baseinfo) != 1) { goto failed; } } @@ -145,17 +148,17 @@ int ltdb_cache_load(struct ldb_context *ldb) ldb_free(ldb, ltdb->cache.last_attribute.name); memset(<db->cache.last_attribute, 0, sizeof(ltdb->cache.last_attribute)); - ltdb_search_dn1_free(ldb, <db->cache.indexlist); - ltdb_search_dn1_free(ldb, <db->cache.subclasses); - ltdb_search_dn1_free(ldb, <db->cache.attributes); + ltdb_search_dn1_free(module, <db->cache.indexlist); + ltdb_search_dn1_free(module, <db->cache.subclasses); + ltdb_search_dn1_free(module, <db->cache.attributes); - if (ltdb_search_dn1(ldb, LTDB_INDEXLIST, <db->cache.indexlist) == -1) { + if (ltdb_search_dn1(module, LTDB_INDEXLIST, <db->cache.indexlist) == -1) { goto failed; } - if (ltdb_search_dn1(ldb, LTDB_SUBCLASSES, <db->cache.subclasses) == -1) { + if (ltdb_search_dn1(module, LTDB_SUBCLASSES, <db->cache.subclasses) == -1) { goto failed; } - if (ltdb_search_dn1(ldb, LTDB_ATTRIBUTES, <db->cache.attributes) == -1) { + if (ltdb_search_dn1(module, LTDB_ATTRIBUTES, <db->cache.attributes) == -1) { goto failed; } @@ -172,9 +175,10 @@ failed: /* increase the sequence number to indicate a database change */ -int ltdb_increase_sequence_number(struct ldb_context *ldb) +int ltdb_increase_sequence_number(struct ldb_module *module) { - struct ltdb_private *ltdb = ldb->private_data; + struct ldb_context *ldb = module->ldb; + struct ltdb_private *ltdb = module->private_data; struct ldb_message msg; struct ldb_message_element el; struct ldb_val val; @@ -197,7 +201,7 @@ int ltdb_increase_sequence_number(struct ldb_context *ldb) val.data = s; val.length = strlen(s); - ret = ltdb_modify_internal(ldb, &msg); + ret = ltdb_modify_internal(module, &msg); ldb_free(ldb, s); ldb_free(ldb, msg.dn); @@ -215,9 +219,10 @@ int ltdb_increase_sequence_number(struct ldb_context *ldb) return the attribute flags from the @ATTRIBUTES record for the given attribute */ -int ltdb_attribute_flags(struct ldb_context *ldb, const char *attr_name) +int ltdb_attribute_flags(struct ldb_module *module, const char *attr_name) { - struct ltdb_private *ltdb = ldb->private_data; + struct ldb_context *ldb = module->ldb; + struct ltdb_private *ltdb = module->private_data; const char *attrs; const struct { const char *name; -- 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_cache.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source4/lib/ldb/ldb_tdb/ldb_cache.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_cache.c b/source4/lib/ldb/ldb_tdb/ldb_cache.c index cf175090e6..a8eb9ae916 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_cache.c +++ b/source4/lib/ldb/ldb_tdb/ldb_cache.c @@ -33,6 +33,8 @@ */ #include "includes.h" +#include "ldb/include/ldb.h" +#include "ldb/include/ldb_private.h" #include "ldb/ldb_tdb/ldb_tdb.h" /* -- 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_cache.c | 164 ++++++++++++++++++++---------------- 1 file changed, 90 insertions(+), 74 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_cache.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_cache.c b/source4/lib/ldb/ldb_tdb/ldb_cache.c index a8eb9ae916..e7420c5f7a 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_cache.c +++ b/source4/lib/ldb/ldb_tdb/ldb_cache.c @@ -42,9 +42,8 @@ */ static int ltdb_baseinfo_init(struct ldb_module *module) { - struct ldb_context *ldb = module->ldb; struct ltdb_private *ltdb = module->private_data; - struct ldb_message msg; + struct ldb_message *msg; struct ldb_message_element el; struct ldb_val val; int ret; @@ -55,60 +54,61 @@ static int ltdb_baseinfo_init(struct ldb_module *module) ltdb->sequence_number = atof(initial_sequence_number); - msg.num_elements = 1; - msg.elements = ⪙ - msg.dn = ldb_strdup(ldb, LTDB_BASEINFO); - if (!msg.dn) { - errno = ENOMEM; - return -1; + msg = talloc_p(ltdb, struct ldb_message); + if (msg == NULL) { + goto failed; } - el.name = ldb_strdup(ldb, LTDB_SEQUENCE_NUMBER); + + msg->num_elements = 1; + msg->elements = ⪙ + msg->dn = talloc_strdup(msg, LTDB_BASEINFO); + if (!msg->dn) { + goto failed; + } + el.name = talloc_strdup(msg, LTDB_SEQUENCE_NUMBER); if (!el.name) { - ldb_free(ldb, msg.dn); - errno = ENOMEM; - return -1; + goto failed; } el.values = &val; el.num_values = 1; el.flags = 0; - val.data = ldb_strdup(ldb, initial_sequence_number); + val.data = talloc_strdup(msg, initial_sequence_number); if (!val.data) { - ldb_free(ldb, el.name); - ldb_free(ldb, msg.dn); - errno = ENOMEM; - return -1; + goto failed; } val.length = 1; - ret = ltdb_store(module, &msg, TDB_INSERT); + ret = ltdb_store(module, msg, TDB_INSERT); - ldb_free(ldb, msg.dn); - ldb_free(ldb, el.name); - ldb_free(ldb, val.data); + talloc_free(msg); return ret; + +failed: + talloc_free(msg); + errno = ENOMEM; + return -1; } /* free any cache records */ -void ltdb_cache_free(struct ldb_module *module) +static void ltdb_cache_free(struct ldb_module *module) { - struct ldb_context *ldb = module->ldb; struct ltdb_private *ltdb = module->private_data; - struct ldb_alloc_ops alloc = ldb->alloc_ops; - ldb->alloc_ops.alloc = NULL; ltdb->sequence_number = 0; - ltdb_search_dn1_free(module, <db->cache.baseinfo); - ltdb_search_dn1_free(module, <db->cache.indexlist); - ltdb_search_dn1_free(module, <db->cache.subclasses); - ltdb_search_dn1_free(module, <db->cache.attributes); - - ldb_free(ldb, ltdb->cache.last_attribute.name); - memset(<db->cache, 0, sizeof(ltdb->cache)); + talloc_free(ltdb->cache); + ltdb->cache = NULL; +} - ldb->alloc_ops = alloc; +/* + force a cache reload +*/ +int ltdb_cache_reload(struct ldb_module *module) +{ + ltdb_cache_free(module); + return ltdb_cache_load(module); } /* @@ -116,60 +116,78 @@ void ltdb_cache_free(struct ldb_module *module) */ int ltdb_cache_load(struct ldb_module *module) { - struct ldb_context *ldb = module->ldb; struct ltdb_private *ltdb = module->private_data; double seq; - struct ldb_alloc_ops alloc = ldb->alloc_ops; - ldb->alloc_ops.alloc = NULL; + if (ltdb->cache == NULL) { + ltdb->cache = talloc_zero_p(ltdb, struct ltdb_cache); + if (ltdb->cache == NULL) goto failed; + ltdb->cache->indexlist = talloc_zero_p(ltdb->cache, struct ldb_message); + ltdb->cache->subclasses = talloc_zero_p(ltdb->cache, struct ldb_message); + ltdb->cache->attributes = talloc_zero_p(ltdb->cache, struct ldb_message); + if (ltdb->cache->indexlist == NULL || + ltdb->cache->subclasses == NULL || + ltdb->cache->attributes == NULL) { + goto failed; + } + } - ltdb_search_dn1_free(module, <db->cache.baseinfo); + talloc_free(ltdb->cache->baseinfo); + ltdb->cache->baseinfo = talloc_p(ltdb->cache, struct ldb_message); + if (ltdb->cache->baseinfo == NULL) goto failed; - if (ltdb_search_dn1(module, LTDB_BASEINFO, <db->cache.baseinfo) == -1) { + if (ltdb_search_dn1(module, LTDB_BASEINFO, ltdb->cache->baseinfo) == -1) { goto failed; } /* possibly initialise the baseinfo */ - if (!ltdb->cache.baseinfo.dn) { + if (!ltdb->cache->baseinfo->dn) { if (ltdb_baseinfo_init(module) != 0) { goto failed; } - if (ltdb_search_dn1(module, LTDB_BASEINFO, <db->cache.baseinfo) != 1) { + if (ltdb_search_dn1(module, LTDB_BASEINFO, ltdb->cache->baseinfo) != 1) { goto failed; } } /* if the current internal sequence number is the same as the one in the database then assume the rest of the cache is OK */ - seq = ldb_msg_find_double(<db->cache.baseinfo, LTDB_SEQUENCE_NUMBER, 0); + seq = ldb_msg_find_double(ltdb->cache->baseinfo, LTDB_SEQUENCE_NUMBER, 0); if (seq == ltdb->sequence_number) { goto done; } ltdb->sequence_number = seq; - ldb_free(ldb, ltdb->cache.last_attribute.name); - memset(<db->cache.last_attribute, 0, sizeof(ltdb->cache.last_attribute)); + talloc_free(ltdb->cache->last_attribute.name); + memset(<db->cache->last_attribute, 0, sizeof(ltdb->cache->last_attribute)); - ltdb_search_dn1_free(module, <db->cache.indexlist); - ltdb_search_dn1_free(module, <db->cache.subclasses); - ltdb_search_dn1_free(module, <db->cache.attributes); + talloc_free(ltdb->cache->indexlist); + talloc_free(ltdb->cache->subclasses); + talloc_free(ltdb->cache->attributes); - if (ltdb_search_dn1(module, LTDB_INDEXLIST, <db->cache.indexlist) == -1) { + ltdb->cache->indexlist = talloc_zero_p(ltdb->cache, struct ldb_message); + ltdb->cache->subclasses = talloc_zero_p(ltdb->cache, struct ldb_message); + ltdb->cache->attributes = talloc_zero_p(ltdb->cache, struct ldb_message); + if (ltdb->cache->indexlist == NULL || + ltdb->cache->subclasses == NULL || + ltdb->cache->attributes == NULL) { goto failed; } - if (ltdb_search_dn1(module, LTDB_SUBCLASSES, <db->cache.subclasses) == -1) { + + if (ltdb_search_dn1(module, LTDB_INDEXLIST, ltdb->cache->indexlist) == -1) { goto failed; } - if (ltdb_search_dn1(module, LTDB_ATTRIBUTES, <db->cache.attributes) == -1) { + if (ltdb_search_dn1(module, LTDB_SUBCLASSES, ltdb->cache->subclasses) == -1) { + goto failed; + } + if (ltdb_search_dn1(module, LTDB_ATTRIBUTES, ltdb->cache->attributes) == -1) { goto failed; } done: - ldb->alloc_ops = alloc; return 0; failed: - ldb->alloc_ops = alloc; return -1; } @@ -181,33 +199,37 @@ int ltdb_increase_sequence_number(struct ldb_module *module) { struct ldb_context *ldb = module->ldb; struct ltdb_private *ltdb = module->private_data; - struct ldb_message msg; + struct ldb_message *msg; struct ldb_message_element el; struct ldb_val val; char *s = NULL; int ret; - ldb_asprintf(ldb, &s, "%.0f", ltdb->sequence_number+1); + s = talloc_asprintf(ldb, "%.0f", ltdb->sequence_number+1); if (!s) { errno = ENOMEM; return -1; } - msg.num_elements = 1; - msg.elements = ⪙ - msg.dn = ldb_strdup(ldb, LTDB_BASEINFO); - el.name = ldb_strdup(ldb, LTDB_SEQUENCE_NUMBER); + msg = talloc_p(ltdb, struct ldb_message); + if (msg == NULL) { + errno = ENOMEM; + return -1; + } + + msg->num_elements = 1; + msg->elements = ⪙ + msg->dn = talloc_strdup(msg, LTDB_BASEINFO); + el.name = talloc_strdup(msg, LTDB_SEQUENCE_NUMBER); el.values = &val; el.num_values = 1; el.flags = LDB_FLAG_MOD_REPLACE; val.data = s; val.length = strlen(s); - ret = ltdb_modify_internal(module, &msg); + ret = ltdb_modify_internal(module, msg); - ldb_free(ldb, s); - ldb_free(ldb, msg.dn); - ldb_free(ldb, el.name); + talloc_free(msg); if (ret == 0) { ltdb->sequence_number += 1; @@ -223,7 +245,6 @@ int ltdb_increase_sequence_number(struct ldb_module *module) */ int ltdb_attribute_flags(struct ldb_module *module, const char *attr_name) { - struct ldb_context *ldb = module->ldb; struct ltdb_private *ltdb = module->private_data; const char *attrs; const struct { @@ -238,11 +259,10 @@ int ltdb_attribute_flags(struct ldb_module *module, const char *attr_name) }; size_t len; int i, ret=0; - struct ldb_alloc_ops alloc = ldb->alloc_ops; - if (ltdb->cache.last_attribute.name && - ldb_attr_cmp(ltdb->cache.last_attribute.name, attr_name) == 0) { - return ltdb->cache.last_attribute.flags; + if (ltdb->cache->last_attribute.name && + ldb_attr_cmp(ltdb->cache->last_attribute.name, attr_name) == 0) { + return ltdb->cache->last_attribute.flags; } /* objectclass is a special default case */ @@ -250,7 +270,7 @@ int ltdb_attribute_flags(struct ldb_module *module, const char *attr_name) ret = LTDB_FLAG_OBJECTCLASS | LTDB_FLAG_CASE_INSENSITIVE; } - attrs = ldb_msg_find_string(<db->cache.attributes, attr_name, NULL); + attrs = ldb_msg_find_string(ltdb->cache->attributes, attr_name, NULL); if (!attrs) { return ret; @@ -270,14 +290,10 @@ int ltdb_attribute_flags(struct ldb_module *module, const char *attr_name) attrs += strspn(attrs, " ,"); } - ldb->alloc_ops.alloc = NULL; + talloc_free(ltdb->cache->last_attribute.name); - ldb_free(ldb, ltdb->cache.last_attribute.name); + ltdb->cache->last_attribute.name = talloc_strdup(ltdb->cache, attr_name); + ltdb->cache->last_attribute.flags = ret; - ltdb->cache.last_attribute.name = ldb_strdup(ldb, attr_name); - ltdb->cache.last_attribute.flags = ret; - - ldb->alloc_ops = alloc; - return ret; } -- cgit From 3e5235a568777b5103612069e413cabe37b83c2b Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 2 Jan 2005 23:03:50 +0000 Subject: r4486: fixed some memory leaks in the new ldb code, by ensuring that memory is always allocated as a child of the right context (This used to be commit 1071712cf5951fa2e94f314bd7678cfa51b2dbcd) --- source4/lib/ldb/ldb_tdb/ldb_cache.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_cache.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_cache.c b/source4/lib/ldb/ldb_tdb/ldb_cache.c index e7420c5f7a..037403d81e 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_cache.c +++ b/source4/lib/ldb/ldb_tdb/ldb_cache.c @@ -205,14 +205,14 @@ int ltdb_increase_sequence_number(struct ldb_module *module) char *s = NULL; int ret; - s = talloc_asprintf(ldb, "%.0f", ltdb->sequence_number+1); - if (!s) { + msg = talloc_p(ltdb, struct ldb_message); + if (msg == NULL) { errno = ENOMEM; return -1; } - msg = talloc_p(ltdb, struct ldb_message); - if (msg == NULL) { + s = talloc_asprintf(msg, "%.0f", ltdb->sequence_number+1); + if (!s) { errno = ENOMEM; return -1; } -- cgit From 7eeeb4a727f5cf96258674fb4048ad328927d513 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 2 Jan 2005 23:09:11 +0000 Subject: r4488: removed an unused variable (This used to be commit 1dfc41c9a3b6418236a1f04b5cf3f9ef9e8b608e) --- source4/lib/ldb/ldb_tdb/ldb_cache.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_cache.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_cache.c b/source4/lib/ldb/ldb_tdb/ldb_cache.c index 037403d81e..ebdfdb7bed 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_cache.c +++ b/source4/lib/ldb/ldb_tdb/ldb_cache.c @@ -197,7 +197,6 @@ failed: */ int ltdb_increase_sequence_number(struct ldb_module *module) { - struct ldb_context *ldb = module->ldb; struct ltdb_private *ltdb = module->private_data; struct ldb_message *msg; struct ldb_message_element el; -- 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_cache.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_cache.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_cache.c b/source4/lib/ldb/ldb_tdb/ldb_cache.c index ebdfdb7bed..8cc6616d52 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_cache.c +++ b/source4/lib/ldb/ldb_tdb/ldb_cache.c @@ -54,7 +54,7 @@ static int ltdb_baseinfo_init(struct ldb_module *module) ltdb->sequence_number = atof(initial_sequence_number); - msg = talloc_p(ltdb, struct ldb_message); + msg = talloc(ltdb, struct ldb_message); if (msg == NULL) { goto failed; } @@ -120,11 +120,11 @@ int ltdb_cache_load(struct ldb_module *module) double seq; if (ltdb->cache == NULL) { - ltdb->cache = talloc_zero_p(ltdb, struct ltdb_cache); + ltdb->cache = talloc_zero(ltdb, struct ltdb_cache); if (ltdb->cache == NULL) goto failed; - ltdb->cache->indexlist = talloc_zero_p(ltdb->cache, struct ldb_message); - ltdb->cache->subclasses = talloc_zero_p(ltdb->cache, struct ldb_message); - ltdb->cache->attributes = talloc_zero_p(ltdb->cache, struct ldb_message); + ltdb->cache->indexlist = talloc_zero(ltdb->cache, struct ldb_message); + ltdb->cache->subclasses = talloc_zero(ltdb->cache, struct ldb_message); + ltdb->cache->attributes = talloc_zero(ltdb->cache, struct ldb_message); if (ltdb->cache->indexlist == NULL || ltdb->cache->subclasses == NULL || ltdb->cache->attributes == NULL) { @@ -133,7 +133,7 @@ int ltdb_cache_load(struct ldb_module *module) } talloc_free(ltdb->cache->baseinfo); - ltdb->cache->baseinfo = talloc_p(ltdb->cache, struct ldb_message); + ltdb->cache->baseinfo = talloc(ltdb->cache, struct ldb_message); if (ltdb->cache->baseinfo == NULL) goto failed; if (ltdb_search_dn1(module, LTDB_BASEINFO, ltdb->cache->baseinfo) == -1) { @@ -165,9 +165,9 @@ int ltdb_cache_load(struct ldb_module *module) talloc_free(ltdb->cache->subclasses); talloc_free(ltdb->cache->attributes); - ltdb->cache->indexlist = talloc_zero_p(ltdb->cache, struct ldb_message); - ltdb->cache->subclasses = talloc_zero_p(ltdb->cache, struct ldb_message); - ltdb->cache->attributes = talloc_zero_p(ltdb->cache, struct ldb_message); + ltdb->cache->indexlist = talloc_zero(ltdb->cache, struct ldb_message); + ltdb->cache->subclasses = talloc_zero(ltdb->cache, struct ldb_message); + ltdb->cache->attributes = talloc_zero(ltdb->cache, struct ldb_message); if (ltdb->cache->indexlist == NULL || ltdb->cache->subclasses == NULL || ltdb->cache->attributes == NULL) { @@ -204,7 +204,7 @@ int ltdb_increase_sequence_number(struct ldb_module *module) char *s = NULL; int ret; - msg = talloc_p(ltdb, struct ldb_message); + msg = talloc(ltdb, struct ldb_message); if (msg == NULL) { errno = ENOMEM; return -1; -- cgit From 62ccaf2d86c269acd7fb39bc83793577ab1c05f4 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Thu, 12 May 2005 14:39:03 +0000 Subject: r6759: let us have a wildcard attribute so that we can set a default for all attributes example: *: CASE_INSENSITIVE by placing it in the @ATTRIBUTES object you make all the matching be case insensitive to make an excepion to the general rule now you just need to create an entry like: name: CASE_SENSITIVE the key CASE_SENSITIVE currently does not exist but has the effect of making the code ignore the wildcard default flag and being ldb case sensitive by default it let the "name" attribute be case sensitive again Tridge, can you look at this commit? Should we introduce a CASE_SENSITVE/BINARY flag and handle it in the code ? Simo. (This used to be commit 5f10707e8ac36db03f3aa3e1ee1c40a9d9da2016) --- source4/lib/ldb/ldb_tdb/ldb_cache.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_cache.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_cache.c b/source4/lib/ldb/ldb_tdb/ldb_cache.c index 8cc6616d52..ec22aca3ec 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_cache.c +++ b/source4/lib/ldb/ldb_tdb/ldb_cache.c @@ -272,7 +272,13 @@ int ltdb_attribute_flags(struct ldb_module *module, const char *attr_name) attrs = ldb_msg_find_string(ltdb->cache->attributes, attr_name, NULL); if (!attrs) { - return ret; + + /* check if theres a wildcard attribute */ + attrs = ldb_msg_find_string(ltdb->cache->attributes, "*", NULL); + + if (!attrs) { + return ret; + } } /* we avoid using strtok and friends due to their nasty -- 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_cache.c | 64 +++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 27 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_cache.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_cache.c b/source4/lib/ldb/ldb_tdb/ldb_cache.c index ec22aca3ec..0fe573a829 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_cache.c +++ b/source4/lib/ldb/ldb_tdb/ldb_cache.c @@ -37,6 +37,21 @@ #include "ldb/include/ldb_private.h" #include "ldb/ldb_tdb/ldb_tdb.h" + +/* valid attribute flags */ +static const struct { + const char *name; + int value; +} ltdb_valid_attr_flags[] = { + { "CASE_INSENSITIVE", LTDB_FLAG_CASE_INSENSITIVE }, + { "INTEGER", LTDB_FLAG_INTEGER }, + { "WILDCARD", LTDB_FLAG_WILDCARD }, + { "HIDDEN", LTDB_FLAG_HIDDEN }, + { "NONE", LTDB_FLAG_NONE }, + { NULL, 0 } +}; + + /* initialise the baseinfo record */ @@ -245,18 +260,7 @@ int ltdb_increase_sequence_number(struct ldb_module *module) int ltdb_attribute_flags(struct ldb_module *module, const char *attr_name) { struct ltdb_private *ltdb = module->private_data; - const char *attrs; - const struct { - const char *name; - int value; - } names[] = { - { "CASE_INSENSITIVE", LTDB_FLAG_CASE_INSENSITIVE }, - { "INTEGER", LTDB_FLAG_INTEGER }, - { "WILDCARD", LTDB_FLAG_WILDCARD }, - { "HIDDEN", LTDB_FLAG_HIDDEN }, - { NULL, 0} - }; - size_t len; + const struct ldb_message_element *attr_el; int i, ret=0; if (ltdb->cache->last_attribute.name && @@ -269,30 +273,22 @@ int ltdb_attribute_flags(struct ldb_module *module, const char *attr_name) ret = LTDB_FLAG_OBJECTCLASS | LTDB_FLAG_CASE_INSENSITIVE; } - attrs = ldb_msg_find_string(ltdb->cache->attributes, attr_name, NULL); + attr_el = ldb_msg_find_element(ltdb->cache->attributes, attr_name); - if (!attrs) { + if (!attr_el) { /* check if theres a wildcard attribute */ - attrs = ldb_msg_find_string(ltdb->cache->attributes, "*", NULL); + attr_el = ldb_msg_find_element(ltdb->cache->attributes, "*"); - if (!attrs) { + if (!attr_el) { return ret; } } - /* we avoid using strtok and friends due to their nasty - interface. This is a little trickier, but much nicer - from a C interface point of view */ - while ((len = strcspn(attrs, " ,")) > 0) { - for (i=0;names[i].name;i++) { - if (strncmp(names[i].name, attrs, len) == 0 && - names[i].name[len] == 0) { - ret |= names[i].value; - } + for (i = 0; i < attr_el->num_values; i++) { + if (strcmp(ltdb_valid_attr_flags[i].name, attr_el->values[i].data) == 0) { + ret |= ltdb_valid_attr_flags[i].value; } - attrs += len; - attrs += strspn(attrs, " ,"); } talloc_free(ltdb->cache->last_attribute.name); @@ -302,3 +298,17 @@ int ltdb_attribute_flags(struct ldb_module *module, const char *attr_name) return ret; } + +int ltdb_check_at_attributes_values(const struct ldb_val *value) +{ + int i; + + for (i = 0; ltdb_valid_attr_flags[i].name != NULL; i++) { + if ((strcmp(ltdb_valid_attr_flags[i].name, value->data) == 0)) { + return 0; + } + } + + return -1; +} + -- cgit From 942eb58e61621dc710a2c96418dda6aaba7e06c3 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 25 May 2005 09:05:23 +0000 Subject: r6967: fixed the new multi-value dn=@ATTRIBUTES so it actually works :-) this demonstrates that we need a improved test suite as well (This used to be commit 959c73e93faa243154288c91a716e5a293d7a51c) --- source4/lib/ldb/ldb_tdb/ldb_cache.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_cache.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_cache.c b/source4/lib/ldb/ldb_tdb/ldb_cache.c index 0fe573a829..0bc2d7b123 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_cache.c +++ b/source4/lib/ldb/ldb_tdb/ldb_cache.c @@ -261,7 +261,7 @@ int ltdb_attribute_flags(struct ldb_module *module, const char *attr_name) { struct ltdb_private *ltdb = module->private_data; const struct ldb_message_element *attr_el; - int i, ret=0; + int i, j, ret=0; if (ltdb->cache->last_attribute.name && ldb_attr_cmp(ltdb->cache->last_attribute.name, attr_name) == 0) { @@ -276,7 +276,6 @@ int ltdb_attribute_flags(struct ldb_module *module, const char *attr_name) attr_el = ldb_msg_find_element(ltdb->cache->attributes, attr_name); if (!attr_el) { - /* check if theres a wildcard attribute */ attr_el = ldb_msg_find_element(ltdb->cache->attributes, "*"); @@ -286,8 +285,11 @@ int ltdb_attribute_flags(struct ldb_module *module, const char *attr_name) } for (i = 0; i < attr_el->num_values; i++) { - if (strcmp(ltdb_valid_attr_flags[i].name, attr_el->values[i].data) == 0) { - ret |= ltdb_valid_attr_flags[i].value; + for (j=0; ltdb_valid_attr_flags[j].name; j++) { + if (strcmp(ltdb_valid_attr_flags[j].name, + attr_el->values[i].data) == 0) { + ret |= ltdb_valid_attr_flags[j].value; + } } } -- 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_cache.c | 188 +++++++++++++++++++++++++++++++++++- 1 file changed, 184 insertions(+), 4 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_cache.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_cache.c b/source4/lib/ldb/ldb_tdb/ldb_cache.c index 0bc2d7b123..0b7ddad5db 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_cache.c +++ b/source4/lib/ldb/ldb_tdb/ldb_cache.c @@ -37,6 +37,11 @@ #include "ldb/include/ldb_private.h" #include "ldb/ldb_tdb/ldb_tdb.h" +#define LTDB_FLAG_CASE_INSENSITIVE (1<<0) +#define LTDB_FLAG_INTEGER (1<<1) +#define LTDB_FLAG_WILDCARD (1<<2) +#define LTDB_FLAG_HIDDEN (1<<3) +#define LTDB_FLAG_OBJECTCLASS (1<<4) /* valid attribute flags */ static const struct { @@ -47,11 +52,181 @@ static const struct { { "INTEGER", LTDB_FLAG_INTEGER }, { "WILDCARD", LTDB_FLAG_WILDCARD }, { "HIDDEN", LTDB_FLAG_HIDDEN }, - { "NONE", LTDB_FLAG_NONE }, + { "NONE", 0 }, { NULL, 0 } }; +/* + de-register any special handlers for @ATTRIBUTES +*/ +static void ltdb_attributes_unload(struct ldb_module *module) +{ + struct ltdb_private *ltdb = module->private_data; + struct ldb_message *msg; + int i; + + if (ltdb->cache->attributes == NULL) { + /* no previously loaded attributes */ + return; + } + + msg = ltdb->cache->attributes; + for (i=0;inum_elements;i++) { + const struct ldb_attrib_handler *h; + /* this is rather ugly - a consequence of const handling */ + h = ldb_attrib_handler(module->ldb, msg->elements[i].name); + ldb_remove_attrib_handler(module->ldb, msg->elements[i].name); + if (strcmp(h->attr, msg->elements[i].name) == 0) { + talloc_steal(msg, h->attr); + } + } + + talloc_free(ltdb->cache->attributes); + ltdb->cache->attributes = NULL; +} + +/* + add up the attrib flags for a @ATTRIBUTES element +*/ +static int ltdb_attributes_flags(struct ldb_message_element *el, unsigned *v) +{ + int i; + unsigned value = 0; + for (i=0;inum_values;i++) { + int j; + for (j=0;ltdb_valid_attr_flags[j].name;j++) { + if (strcmp(ltdb_valid_attr_flags[j].name, + el->values[i].data) == 0) { + value |= ltdb_valid_attr_flags[j].value; + break; + } + } + if (ltdb_valid_attr_flags[j].name == NULL) { + return -1; + } + } + *v = value; + return 0; +} + +/* + register any special handlers from @ATTRIBUTES +*/ +static int ltdb_attributes_load(struct ldb_module *module) +{ + struct ltdb_private *ltdb = module->private_data; + struct ldb_message *msg = ltdb->cache->attributes; + int i; + + if (ltdb_search_dn1(module, LTDB_ATTRIBUTES, msg) == -1) { + goto failed; + } + /* mapping these flags onto ldap 'syntaxes' isn't strictly correct, + but its close enough for now */ + for (i=0;inum_elements;i++) { + unsigned flags; + const char *syntax; + const struct ldb_attrib_handler *h; + struct ldb_attrib_handler h2; + + if (ltdb_attributes_flags(&msg->elements[i], &flags) != 0) { + ldb_debug(module->ldb, LDB_DEBUG_ERROR, "Invalid @ATTRIBUTES element for '%s'\n", msg->elements[i].name); + goto failed; + } + switch (flags & ~LTDB_FLAG_HIDDEN) { + case 0: + syntax = LDB_SYNTAX_OCTET_STRING; + break; + case LTDB_FLAG_WILDCARD: + case LTDB_FLAG_WILDCARD | LTDB_FLAG_CASE_INSENSITIVE: + syntax = LDB_SYNTAX_WILDCARD; + break; + case LTDB_FLAG_CASE_INSENSITIVE: + syntax = LDB_SYNTAX_DIRECTORY_STRING; + break; + case LTDB_FLAG_INTEGER: + syntax = LDB_SYNTAX_INTEGER; + break; + default: + ldb_debug(module->ldb, LDB_DEBUG_ERROR, + "Invalid flag combination 0x%x for '%s' in @ATTRIBUTES\n", + flags, msg->elements[i].name); + goto failed; + } + + h = ldb_attrib_handler_syntax(module->ldb, syntax); + if (h == NULL) { + ldb_debug(module->ldb, LDB_DEBUG_ERROR, + "Invalid attribute syntax '%s' for '%s' in @ATTRIBUTES\n", + syntax, msg->elements[i].name); + goto failed; + } + h2 = *h; + h2.attr = talloc_strdup(module, msg->elements[i].name); + if (ldb_set_attrib_handlers(module->ldb, &h2, 1) != 0) { + goto failed; + } + } + + return 0; +failed: + return -1; +} + + +/* + register any subclasses from @SUBCLASSES +*/ +static int ltdb_subclasses_load(struct ldb_module *module) +{ + struct ltdb_private *ltdb = module->private_data; + struct ldb_message *msg = ltdb->cache->subclasses; + int i, j; + + if (ltdb_search_dn1(module, LTDB_SUBCLASSES, msg) == -1) { + goto failed; + } + + for (i=0;inum_elements;i++) { + struct ldb_message_element *el = &msg->elements[i]; + for (j=0;jnum_values;j++) { + if (ldb_subclass_add(module->ldb, el->name, el->values[j].data) != 0) { + goto failed; + } + } + } + + return 0; +failed: + return -1; +} + + +/* + de-register any @SUBCLASSES +*/ +static void ltdb_subclasses_unload(struct ldb_module *module) +{ + struct ltdb_private *ltdb = module->private_data; + struct ldb_message *msg; + int i; + + if (ltdb->cache->subclasses == NULL) { + /* no previously loaded subclasses */ + return; + } + + msg = ltdb->cache->subclasses; + for (i=0;inum_elements;i++) { + ldb_subclass_remove(module->ldb, msg->elements[i].name); + } + + talloc_free(ltdb->cache->subclasses); + ltdb->cache->subclasses = NULL; +} + + /* initialise the baseinfo record */ @@ -122,6 +297,8 @@ static void ltdb_cache_free(struct ldb_module *module) */ int ltdb_cache_reload(struct ldb_module *module) { + ltdb_attributes_unload(module); + ltdb_subclasses_unload(module); ltdb_cache_free(module); return ltdb_cache_load(module); } @@ -176,9 +353,11 @@ int ltdb_cache_load(struct ldb_module *module) talloc_free(ltdb->cache->last_attribute.name); memset(<db->cache->last_attribute, 0, sizeof(ltdb->cache->last_attribute)); + ltdb_attributes_unload(module); + ltdb_subclasses_unload(module); + talloc_free(ltdb->cache->indexlist); talloc_free(ltdb->cache->subclasses); - talloc_free(ltdb->cache->attributes); ltdb->cache->indexlist = talloc_zero(ltdb->cache, struct ldb_message); ltdb->cache->subclasses = talloc_zero(ltdb->cache, struct ldb_message); @@ -192,10 +371,11 @@ int ltdb_cache_load(struct ldb_module *module) if (ltdb_search_dn1(module, LTDB_INDEXLIST, ltdb->cache->indexlist) == -1) { goto failed; } - if (ltdb_search_dn1(module, LTDB_SUBCLASSES, ltdb->cache->subclasses) == -1) { + + if (ltdb_attributes_load(module) == -1) { goto failed; } - if (ltdb_search_dn1(module, LTDB_ATTRIBUTES, ltdb->cache->attributes) == -1) { + if (ltdb_subclasses_load(module) == -1) { goto failed; } -- cgit From c9b0e86a436b5b169a4c33bd25eac379cb622b17 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Tue, 12 Jul 2005 12:04:54 +0000 Subject: r8373: New wildcard matching code. This code applies correct ldap standard wildcard matching code removes WILDCARD matching from tdb @ATTRIBUTES, that's now handled independently adds some more tests for wildcard matching fixes dn comparison code in ldb_match (This used to be commit 4eb5863042011988d85092d7dde3d809aa15bd59) --- source4/lib/ldb/ldb_tdb/ldb_cache.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_cache.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_cache.c b/source4/lib/ldb/ldb_tdb/ldb_cache.c index 0b7ddad5db..be76f7085b 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_cache.c +++ b/source4/lib/ldb/ldb_tdb/ldb_cache.c @@ -39,9 +39,8 @@ #define LTDB_FLAG_CASE_INSENSITIVE (1<<0) #define LTDB_FLAG_INTEGER (1<<1) -#define LTDB_FLAG_WILDCARD (1<<2) -#define LTDB_FLAG_HIDDEN (1<<3) -#define LTDB_FLAG_OBJECTCLASS (1<<4) +#define LTDB_FLAG_HIDDEN (1<<2) +#define LTDB_FLAG_OBJECTCLASS (1<<3) /* valid attribute flags */ static const struct { @@ -50,7 +49,6 @@ static const struct { } ltdb_valid_attr_flags[] = { { "CASE_INSENSITIVE", LTDB_FLAG_CASE_INSENSITIVE }, { "INTEGER", LTDB_FLAG_INTEGER }, - { "WILDCARD", LTDB_FLAG_WILDCARD }, { "HIDDEN", LTDB_FLAG_HIDDEN }, { "NONE", 0 }, { NULL, 0 } @@ -138,10 +136,6 @@ static int ltdb_attributes_load(struct ldb_module *module) case 0: syntax = LDB_SYNTAX_OCTET_STRING; break; - case LTDB_FLAG_WILDCARD: - case LTDB_FLAG_WILDCARD | LTDB_FLAG_CASE_INSENSITIVE: - syntax = LDB_SYNTAX_WILDCARD; - break; case LTDB_FLAG_CASE_INSENSITIVE: syntax = LDB_SYNTAX_DIRECTORY_STRING; break; -- 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_cache.c | 50 +++++++++++++++++++++++++++++++------ 1 file changed, 42 insertions(+), 8 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_cache.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_cache.c b/source4/lib/ldb/ldb_tdb/ldb_cache.c index be76f7085b..5e40b8fd3f 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_cache.c +++ b/source4/lib/ldb/ldb_tdb/ldb_cache.c @@ -115,11 +115,17 @@ static int ltdb_attributes_load(struct ldb_module *module) { struct ltdb_private *ltdb = module->private_data; struct ldb_message *msg = ltdb->cache->attributes; + struct ldb_dn *dn; int i; - if (ltdb_search_dn1(module, LTDB_ATTRIBUTES, msg) == -1) { + dn = ldb_dn_explode(module->ldb, LTDB_ATTRIBUTES); + if (dn == NULL) goto failed; + + if (ltdb_search_dn1(module, dn, msg) == -1) { + talloc_free(dn); goto failed; } + talloc_free(dn); /* mapping these flags onto ldap 'syntaxes' isn't strictly correct, but its close enough for now */ for (i=0;inum_elements;i++) { @@ -176,11 +182,17 @@ static int ltdb_subclasses_load(struct ldb_module *module) { struct ltdb_private *ltdb = module->private_data; struct ldb_message *msg = ltdb->cache->subclasses; + struct ldb_dn *dn; int i, j; - if (ltdb_search_dn1(module, LTDB_SUBCLASSES, msg) == -1) { + dn = ldb_dn_explode(module->ldb, LTDB_SUBCLASSES); + if (dn == NULL) goto failed; + + if (ltdb_search_dn1(module, dn, msg) == -1) { + talloc_free(dn); goto failed; } + talloc_free(dn); for (i=0;inum_elements;i++) { struct ldb_message_element *el = &msg->elements[i]; @@ -245,7 +257,7 @@ static int ltdb_baseinfo_init(struct ldb_module *module) msg->num_elements = 1; msg->elements = ⪙ - msg->dn = talloc_strdup(msg, LTDB_BASEINFO); + msg->dn = ldb_dn_explode(msg, LTDB_BASEINFO); if (!msg->dn) { goto failed; } @@ -303,6 +315,8 @@ int ltdb_cache_reload(struct ldb_module *module) int ltdb_cache_load(struct ldb_module *module) { struct ltdb_private *ltdb = module->private_data; + struct ldb_dn *baseinfo_dn = NULL; + struct ldb_dn *indexlist_dn = NULL; double seq; if (ltdb->cache == NULL) { @@ -321,8 +335,11 @@ int ltdb_cache_load(struct ldb_module *module) talloc_free(ltdb->cache->baseinfo); ltdb->cache->baseinfo = talloc(ltdb->cache, struct ldb_message); if (ltdb->cache->baseinfo == NULL) goto failed; - - if (ltdb_search_dn1(module, LTDB_BASEINFO, ltdb->cache->baseinfo) == -1) { + + baseinfo_dn = ldb_dn_explode(module->ldb, LTDB_BASEINFO); + if (baseinfo_dn == NULL) goto failed; + + if (ltdb_search_dn1(module, baseinfo_dn, ltdb->cache->baseinfo) == -1) { goto failed; } @@ -331,7 +348,7 @@ int ltdb_cache_load(struct ldb_module *module) if (ltdb_baseinfo_init(module) != 0) { goto failed; } - if (ltdb_search_dn1(module, LTDB_BASEINFO, ltdb->cache->baseinfo) != 1) { + if (ltdb_search_dn1(module, baseinfo_dn, ltdb->cache->baseinfo) != 1) { goto failed; } } @@ -362,7 +379,10 @@ int ltdb_cache_load(struct ldb_module *module) goto failed; } - if (ltdb_search_dn1(module, LTDB_INDEXLIST, ltdb->cache->indexlist) == -1) { + indexlist_dn = ldb_dn_explode(module->ldb, LTDB_INDEXLIST); + if (indexlist_dn == NULL) goto failed; + + if (ltdb_search_dn1(module, indexlist_dn, ltdb->cache->indexlist) == -1) { goto failed; } @@ -374,9 +394,13 @@ int ltdb_cache_load(struct ldb_module *module) } done: + talloc_free(baseinfo_dn); + talloc_free(indexlist_dn); return 0; failed: + talloc_free(baseinfo_dn); + talloc_free(indexlist_dn); return -1; } @@ -407,8 +431,18 @@ int ltdb_increase_sequence_number(struct ldb_module *module) msg->num_elements = 1; msg->elements = ⪙ - msg->dn = talloc_strdup(msg, LTDB_BASEINFO); + msg->dn = ldb_dn_explode(msg, LTDB_BASEINFO); + if (msg->dn == NULL) { + talloc_free(msg); + errno = ENOMEM; + return -1; + } el.name = talloc_strdup(msg, LTDB_SEQUENCE_NUMBER); + if (el.name == NULL) { + talloc_free(msg); + errno = ENOMEM; + return -1; + } el.values = &val; el.num_values = 1; el.flags = LDB_FLAG_MOD_REPLACE; -- 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_cache.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_cache.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_cache.c b/source4/lib/ldb/ldb_tdb/ldb_cache.c index 5e40b8fd3f..01f9338009 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_cache.c +++ b/source4/lib/ldb/ldb_tdb/ldb_cache.c @@ -95,7 +95,7 @@ static int ltdb_attributes_flags(struct ldb_message_element *el, unsigned *v) int j; for (j=0;ltdb_valid_attr_flags[j].name;j++) { if (strcmp(ltdb_valid_attr_flags[j].name, - el->values[i].data) == 0) { + (char *)el->values[i].data) == 0) { value |= ltdb_valid_attr_flags[j].value; break; } @@ -197,7 +197,8 @@ static int ltdb_subclasses_load(struct ldb_module *module) for (i=0;inum_elements;i++) { struct ldb_message_element *el = &msg->elements[i]; for (j=0;jnum_values;j++) { - if (ldb_subclass_add(module->ldb, el->name, el->values[j].data) != 0) { + if (ldb_subclass_add(module->ldb, el->name, + (char *)el->values[j].data) != 0) { goto failed; } } @@ -268,7 +269,7 @@ static int ltdb_baseinfo_init(struct ldb_module *module) el.values = &val; el.num_values = 1; el.flags = 0; - val.data = talloc_strdup(msg, initial_sequence_number); + val.data = (uint8_t *)talloc_strdup(msg, initial_sequence_number); if (!val.data) { goto failed; } @@ -446,7 +447,7 @@ int ltdb_increase_sequence_number(struct ldb_module *module) el.values = &val; el.num_values = 1; el.flags = LDB_FLAG_MOD_REPLACE; - val.data = s; + val.data = (uint8_t *)s; val.length = strlen(s); ret = ltdb_modify_internal(module, msg); @@ -495,7 +496,7 @@ int ltdb_attribute_flags(struct ldb_module *module, const char *attr_name) for (i = 0; i < attr_el->num_values; i++) { for (j=0; ltdb_valid_attr_flags[j].name; j++) { if (strcmp(ltdb_valid_attr_flags[j].name, - attr_el->values[i].data) == 0) { + (char *)attr_el->values[i].data) == 0) { ret |= ltdb_valid_attr_flags[j].value; } } @@ -514,7 +515,7 @@ int ltdb_check_at_attributes_values(const struct ldb_val *value) int i; for (i = 0; ltdb_valid_attr_flags[i].name != NULL; i++) { - if ((strcmp(ltdb_valid_attr_flags[i].name, value->data) == 0)) { + if ((strcmp(ltdb_valid_attr_flags[i].name, (char *)value->data) == 0)) { return 0; } } -- 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_cache.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_cache.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_cache.c b/source4/lib/ldb/ldb_tdb/ldb_cache.c index 01f9338009..cfbe7b2ab3 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_cache.c +++ b/source4/lib/ldb/ldb_tdb/ldb_cache.c @@ -33,8 +33,8 @@ */ #include "includes.h" -#include "ldb/include/ldb.h" -#include "ldb/include/ldb_private.h" +#include "ldb/include/includes.h" + #include "ldb/ldb_tdb/ldb_tdb.h" #define LTDB_FLAG_CASE_INSENSITIVE (1<<0) -- 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_cache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_cache.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_cache.c b/source4/lib/ldb/ldb_tdb/ldb_cache.c index cfbe7b2ab3..5634e9ad16 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_cache.c +++ b/source4/lib/ldb/ldb_tdb/ldb_cache.c @@ -356,7 +356,7 @@ int ltdb_cache_load(struct ldb_module *module) /* if the current internal sequence number is the same as the one in the database then assume the rest of the cache is OK */ - seq = ldb_msg_find_double(ltdb->cache->baseinfo, LTDB_SEQUENCE_NUMBER, 0); + seq = ldb_msg_find_attr_as_double(ltdb->cache->baseinfo, LTDB_SEQUENCE_NUMBER, 0); if (seq == ltdb->sequence_number) { goto done; } -- 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_cache.c | 38 ++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_cache.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_cache.c b/source4/lib/ldb/ldb_tdb/ldb_cache.c index 5634e9ad16..d6d66dd37f 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_cache.c +++ b/source4/lib/ldb/ldb_tdb/ldb_cache.c @@ -413,8 +413,10 @@ int ltdb_increase_sequence_number(struct ldb_module *module) { struct ltdb_private *ltdb = module->private_data; struct ldb_message *msg; - struct ldb_message_element el; + struct ldb_message_element el[2]; struct ldb_val val; + struct ldb_val val_time; + time_t t = time(NULL); char *s = NULL; int ret; @@ -424,32 +426,50 @@ int ltdb_increase_sequence_number(struct ldb_module *module) return -1; } - s = talloc_asprintf(msg, "%.0f", ltdb->sequence_number+1); + s = talloc_asprintf(msg, "%llu", ltdb->sequence_number+1); if (!s) { errno = ENOMEM; return -1; } - msg->num_elements = 1; - msg->elements = ⪙ + msg->num_elements = ARRAY_SIZE(el); + msg->elements = el; msg->dn = ldb_dn_explode(msg, LTDB_BASEINFO); if (msg->dn == NULL) { talloc_free(msg); errno = ENOMEM; return -1; } - el.name = talloc_strdup(msg, LTDB_SEQUENCE_NUMBER); - if (el.name == NULL) { + el[0].name = talloc_strdup(msg, LTDB_SEQUENCE_NUMBER); + if (el[0].name == NULL) { talloc_free(msg); errno = ENOMEM; return -1; } - el.values = &val; - el.num_values = 1; - el.flags = LDB_FLAG_MOD_REPLACE; + el[0].values = &val; + el[0].num_values = 1; + el[0].flags = LDB_FLAG_MOD_REPLACE; val.data = (uint8_t *)s; val.length = strlen(s); + el[1].name = talloc_strdup(msg, LTDB_MOD_TIMESTAMP); + if (el[1].name == NULL) { + talloc_free(msg); + errno = ENOMEM; + return -1; + } + el[1].values = &val_time; + el[1].num_values = 1; + el[1].flags = LDB_FLAG_MOD_REPLACE; + + s = ldb_timestring(msg, t); + if (s == NULL) { + return -1; + } + + val_time.data = (uint8_t *)s; + val_time.length = strlen(s); + ret = ltdb_modify_internal(module, msg); talloc_free(msg); -- cgit From 118dae99def28d8dcda0dca1b3b4c987f0b38cde Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Wed, 4 Oct 2006 19:08:36 +0000 Subject: r19069: The sequence number is a 64 bit unsigned integer Well spotted Volker (This used to be commit f4239ef5983cfc06fd5cab42448564faed676944) --- source4/lib/ldb/ldb_tdb/ldb_cache.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_cache.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_cache.c b/source4/lib/ldb/ldb_tdb/ldb_cache.c index d6d66dd37f..a6092c45f9 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_cache.c +++ b/source4/lib/ldb/ldb_tdb/ldb_cache.c @@ -318,7 +318,7 @@ int ltdb_cache_load(struct ldb_module *module) struct ltdb_private *ltdb = module->private_data; struct ldb_dn *baseinfo_dn = NULL; struct ldb_dn *indexlist_dn = NULL; - double seq; + uint64_t seq; if (ltdb->cache == NULL) { ltdb->cache = talloc_zero(ltdb, struct ltdb_cache); @@ -356,7 +356,7 @@ int ltdb_cache_load(struct ldb_module *module) /* if the current internal sequence number is the same as the one in the database then assume the rest of the cache is OK */ - seq = ldb_msg_find_attr_as_double(ltdb->cache->baseinfo, LTDB_SEQUENCE_NUMBER, 0); + seq = ldb_msg_find_attr_as_uint64(ltdb->cache->baseinfo, LTDB_SEQUENCE_NUMBER, 0); if (seq == ltdb->sequence_number) { goto done; } -- cgit From 7f00bee3dcc8eeb5505dc70f6b4e1baaad8ca683 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 16 Oct 2006 09:08:43 +0000 Subject: r19322: fix a minor memory leak in the ltdb cache code (This used to be commit e03ed5822a690e2d151107f2edb9b4f1d3a1e1b9) --- source4/lib/ldb/ldb_tdb/ldb_cache.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/lib/ldb/ldb_tdb/ldb_cache.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_cache.c b/source4/lib/ldb/ldb_tdb/ldb_cache.c index a6092c45f9..a98b5d8257 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_cache.c +++ b/source4/lib/ldb/ldb_tdb/ldb_cache.c @@ -167,6 +167,7 @@ static int ltdb_attributes_load(struct ldb_module *module) if (ldb_set_attrib_handlers(module->ldb, &h2, 1) != 0) { goto failed; } + talloc_steal(module->ldb->schema.attrib_handlers, h2.attr); } return 0; -- cgit From 1865044d5c6379589c8f06b2f9bf0ccbdfe0cff9 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 17 Oct 2006 01:21:25 +0000 Subject: r19363: - don't need to store the baseinfo message after cache load (This used to be commit 8c091bcdece5c17073838ad2367f3f4e22e97c31) --- source4/lib/ldb/ldb_tdb/ldb_cache.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_cache.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_cache.c b/source4/lib/ldb/ldb_tdb/ldb_cache.c index a98b5d8257..a903ceb4cd 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_cache.c +++ b/source4/lib/ldb/ldb_tdb/ldb_cache.c @@ -320,6 +320,7 @@ int ltdb_cache_load(struct ldb_module *module) struct ldb_dn *baseinfo_dn = NULL; struct ldb_dn *indexlist_dn = NULL; uint64_t seq; + struct ldb_message *baseinfo; if (ltdb->cache == NULL) { ltdb->cache = talloc_zero(ltdb, struct ltdb_cache); @@ -334,30 +335,29 @@ int ltdb_cache_load(struct ldb_module *module) } } - talloc_free(ltdb->cache->baseinfo); - ltdb->cache->baseinfo = talloc(ltdb->cache, struct ldb_message); - if (ltdb->cache->baseinfo == NULL) goto failed; + baseinfo = talloc(ltdb->cache, struct ldb_message); + if (baseinfo == NULL) goto failed; baseinfo_dn = ldb_dn_explode(module->ldb, LTDB_BASEINFO); if (baseinfo_dn == NULL) goto failed; - if (ltdb_search_dn1(module, baseinfo_dn, ltdb->cache->baseinfo) == -1) { + if (ltdb_search_dn1(module, baseinfo_dn, baseinfo) == -1) { goto failed; } /* possibly initialise the baseinfo */ - if (!ltdb->cache->baseinfo->dn) { + if (!baseinfo->dn) { if (ltdb_baseinfo_init(module) != 0) { goto failed; } - if (ltdb_search_dn1(module, baseinfo_dn, ltdb->cache->baseinfo) != 1) { + if (ltdb_search_dn1(module, baseinfo_dn, baseinfo) != 1) { goto failed; } } /* if the current internal sequence number is the same as the one in the database then assume the rest of the cache is OK */ - seq = ldb_msg_find_attr_as_uint64(ltdb->cache->baseinfo, LTDB_SEQUENCE_NUMBER, 0); + seq = ldb_msg_find_attr_as_uint64(baseinfo, LTDB_SEQUENCE_NUMBER, 0); if (seq == ltdb->sequence_number) { goto done; } @@ -396,11 +396,13 @@ int ltdb_cache_load(struct ldb_module *module) } done: + talloc_free(baseinfo); talloc_free(baseinfo_dn); talloc_free(indexlist_dn); return 0; failed: + talloc_free(baseinfo); talloc_free(baseinfo_dn); talloc_free(indexlist_dn); return -1; -- cgit From 0cf42c464ea240c4e57cc5b0c31227a0c5f684d4 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 17 Oct 2006 05:50:01 +0000 Subject: r19365: fixed a memory leak in the ldb attribute handling (This used to be commit d7e07685164141f8fb2c2a6258e1fcb46ff9d06c) --- source4/lib/ldb/ldb_tdb/ldb_cache.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_cache.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_cache.c b/source4/lib/ldb/ldb_tdb/ldb_cache.c index a903ceb4cd..84932ac47f 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_cache.c +++ b/source4/lib/ldb/ldb_tdb/ldb_cache.c @@ -71,13 +71,7 @@ static void ltdb_attributes_unload(struct ldb_module *module) msg = ltdb->cache->attributes; for (i=0;inum_elements;i++) { - const struct ldb_attrib_handler *h; - /* this is rather ugly - a consequence of const handling */ - h = ldb_attrib_handler(module->ldb, msg->elements[i].name); ldb_remove_attrib_handler(module->ldb, msg->elements[i].name); - if (strcmp(h->attr, msg->elements[i].name) == 0) { - talloc_steal(msg, h->attr); - } } talloc_free(ltdb->cache->attributes); @@ -163,11 +157,11 @@ static int ltdb_attributes_load(struct ldb_module *module) goto failed; } h2 = *h; - h2.attr = talloc_strdup(module, msg->elements[i].name); + h2.attr = msg->elements[i].name; + h2.flags |= LDB_ATTR_FLAG_ALLOCATED; if (ldb_set_attrib_handlers(module->ldb, &h2, 1) != 0) { goto failed; } - talloc_steal(module->ldb->schema.attrib_handlers, h2.attr); } 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_cache.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'source4/lib/ldb/ldb_tdb/ldb_cache.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_cache.c b/source4/lib/ldb/ldb_tdb/ldb_cache.c index 84932ac47f..467f1ac34d 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_cache.c +++ b/source4/lib/ldb/ldb_tdb/ldb_cache.c @@ -316,6 +316,12 @@ int ltdb_cache_load(struct ldb_module *module) uint64_t seq; struct ldb_message *baseinfo; + /* a very fast check to avoid extra database reads */ + if (ltdb->cache != NULL && + tdb_get_seqnum(ltdb->tdb) == ltdb->tdb_seqnum) { + return 0; + } + if (ltdb->cache == NULL) { ltdb->cache = talloc_zero(ltdb, struct ltdb_cache); if (ltdb->cache == NULL) goto failed; @@ -349,6 +355,8 @@ int ltdb_cache_load(struct ldb_module *module) } } + ltdb->tdb_seqnum = tdb_get_seqnum(ltdb->tdb); + /* if the current internal sequence number is the same as the one in the database then assume the rest of the cache is OK */ seq = ldb_msg_find_attr_as_uint64(baseinfo, LTDB_SEQUENCE_NUMBER, 0); -- 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_cache.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_cache.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_cache.c b/source4/lib/ldb/ldb_tdb/ldb_cache.c index 467f1ac34d..756c198106 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_cache.c +++ b/source4/lib/ldb/ldb_tdb/ldb_cache.c @@ -112,7 +112,7 @@ static int ltdb_attributes_load(struct ldb_module *module) struct ldb_dn *dn; int i; - dn = ldb_dn_explode(module->ldb, LTDB_ATTRIBUTES); + dn = ldb_dn_new(module, module->ldb, LTDB_ATTRIBUTES); if (dn == NULL) goto failed; if (ltdb_search_dn1(module, dn, msg) == -1) { @@ -180,7 +180,7 @@ static int ltdb_subclasses_load(struct ldb_module *module) struct ldb_dn *dn; int i, j; - dn = ldb_dn_explode(module->ldb, LTDB_SUBCLASSES); + dn = ldb_dn_new(module, module->ldb, LTDB_SUBCLASSES); if (dn == NULL) goto failed; if (ltdb_search_dn1(module, dn, msg) == -1) { @@ -253,7 +253,7 @@ static int ltdb_baseinfo_init(struct ldb_module *module) msg->num_elements = 1; msg->elements = ⪙ - msg->dn = ldb_dn_explode(msg, LTDB_BASEINFO); + msg->dn = ldb_dn_new(msg, module->ldb, LTDB_BASEINFO); if (!msg->dn) { goto failed; } @@ -338,7 +338,7 @@ int ltdb_cache_load(struct ldb_module *module) baseinfo = talloc(ltdb->cache, struct ldb_message); if (baseinfo == NULL) goto failed; - baseinfo_dn = ldb_dn_explode(module->ldb, LTDB_BASEINFO); + baseinfo_dn = ldb_dn_new(module, module->ldb, LTDB_BASEINFO); if (baseinfo_dn == NULL) goto failed; if (ltdb_search_dn1(module, baseinfo_dn, baseinfo) == -1) { @@ -383,7 +383,7 @@ int ltdb_cache_load(struct ldb_module *module) goto failed; } - indexlist_dn = ldb_dn_explode(module->ldb, LTDB_INDEXLIST); + indexlist_dn = ldb_dn_new(module, module->ldb, LTDB_INDEXLIST); if (indexlist_dn == NULL) goto failed; if (ltdb_search_dn1(module, indexlist_dn, ltdb->cache->indexlist) == -1) { @@ -439,7 +439,7 @@ int ltdb_increase_sequence_number(struct ldb_module *module) msg->num_elements = ARRAY_SIZE(el); msg->elements = el; - msg->dn = ldb_dn_explode(msg, LTDB_BASEINFO); + msg->dn = ldb_dn_new(msg, module->ldb, LTDB_BASEINFO); if (msg->dn == NULL) { talloc_free(msg); errno = ENOMEM; -- cgit From e55ff42229d67c1447f2c811191b79137b1ce8cc Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 14 Dec 2006 10:03:21 +0000 Subject: r20168: start separating attributes and syntaxes metze (This used to be commit 8dda4342f648aa71878ac9eeb7941710e2813aee) --- source4/lib/ldb/ldb_tdb/ldb_cache.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_cache.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_cache.c b/source4/lib/ldb/ldb_tdb/ldb_cache.c index 756c198106..d64340b5d0 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_cache.c +++ b/source4/lib/ldb/ldb_tdb/ldb_cache.c @@ -125,8 +125,8 @@ static int ltdb_attributes_load(struct ldb_module *module) for (i=0;inum_elements;i++) { unsigned flags; const char *syntax; - const struct ldb_attrib_handler *h; - struct ldb_attrib_handler h2; + const struct ldb_schema_syntax *s; + struct ldb_attrib_handler h; if (ltdb_attributes_flags(&msg->elements[i], &flags) != 0) { ldb_debug(module->ldb, LDB_DEBUG_ERROR, "Invalid @ATTRIBUTES element for '%s'\n", msg->elements[i].name); @@ -149,17 +149,21 @@ static int ltdb_attributes_load(struct ldb_module *module) goto failed; } - h = ldb_attrib_handler_syntax(module->ldb, syntax); - if (h == NULL) { + s = ldb_standard_syntax_by_name(module->ldb, syntax); + if (s == NULL) { ldb_debug(module->ldb, LDB_DEBUG_ERROR, "Invalid attribute syntax '%s' for '%s' in @ATTRIBUTES\n", syntax, msg->elements[i].name); goto failed; } - h2 = *h; - h2.attr = msg->elements[i].name; - h2.flags |= LDB_ATTR_FLAG_ALLOCATED; - if (ldb_set_attrib_handlers(module->ldb, &h2, 1) != 0) { + h.attr = msg->elements[i].name; + h.flags |= LDB_ATTR_FLAG_ALLOCATED; + h.ldif_read_fn = s->ldif_read_fn; + h.ldif_write_fn = s->ldif_write_fn; + h.canonicalise_fn = s->canonicalise_fn; + h.comparison_fn = s->comparison_fn; + + if (ldb_set_attrib_handlers(module->ldb, &h, 1) != 0) { goto failed; } } -- 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_cache.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_cache.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_cache.c b/source4/lib/ldb/ldb_tdb/ldb_cache.c index d64340b5d0..dbd5222ce5 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_cache.c +++ b/source4/lib/ldb/ldb_tdb/ldb_cache.c @@ -71,7 +71,7 @@ static void ltdb_attributes_unload(struct ldb_module *module) msg = ltdb->cache->attributes; for (i=0;inum_elements;i++) { - ldb_remove_attrib_handler(module->ldb, msg->elements[i].name); + ldb_schema_attribute_remove(module->ldb, msg->elements[i].name); } talloc_free(ltdb->cache->attributes); @@ -126,7 +126,6 @@ static int ltdb_attributes_load(struct ldb_module *module) unsigned flags; const char *syntax; const struct ldb_schema_syntax *s; - struct ldb_attrib_handler h; if (ltdb_attributes_flags(&msg->elements[i], &flags) != 0) { ldb_debug(module->ldb, LDB_DEBUG_ERROR, "Invalid @ATTRIBUTES element for '%s'\n", msg->elements[i].name); @@ -156,14 +155,9 @@ static int ltdb_attributes_load(struct ldb_module *module) syntax, msg->elements[i].name); goto failed; } - h.attr = msg->elements[i].name; - h.flags |= LDB_ATTR_FLAG_ALLOCATED; - h.ldif_read_fn = s->ldif_read_fn; - h.ldif_write_fn = s->ldif_write_fn; - h.canonicalise_fn = s->canonicalise_fn; - h.comparison_fn = s->comparison_fn; - - if (ldb_set_attrib_handlers(module->ldb, &h, 1) != 0) { + + flags |= LDB_ATTR_FLAG_ALLOCATED; + if (ldb_schema_attribute_add_with_syntax(module->ldb, msg->elements[i].name, flags, s) != 0) { goto failed; } } -- cgit From c8c023ea621bd926a515277f909a83206772670e Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 15 Dec 2006 22:00:56 +0000 Subject: r20191: fix bug found by the IBM checker metze (This used to be commit 4c1e4bfeef8d93583b6d4345dbb1b8fa90368308) --- source4/lib/ldb/ldb_tdb/ldb_cache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_cache.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_cache.c b/source4/lib/ldb/ldb_tdb/ldb_cache.c index dbd5222ce5..55eeca56a4 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_cache.c +++ b/source4/lib/ldb/ldb_tdb/ldb_cache.c @@ -312,7 +312,7 @@ int ltdb_cache_load(struct ldb_module *module) struct ldb_dn *baseinfo_dn = NULL; struct ldb_dn *indexlist_dn = NULL; uint64_t seq; - struct ldb_message *baseinfo; + struct ldb_message *baseinfo = NULL; /* a very fast check to avoid extra database reads */ if (ltdb->cache != NULL && -- cgit From 13b7d545350f27db883b27b58b75dbdfc1d5d88f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 17 Dec 2006 23:11:46 +0000 Subject: r20234: metze pointed out that we are re-loading the cache records on each write. We should only be doing this if another process writes and changes the seqnum. This avoids the extra cache loads (This used to be commit 65858ebb68c25a672e9284e8cba9a6675902f1df) --- source4/lib/ldb/ldb_tdb/ldb_cache.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source4/lib/ldb/ldb_tdb/ldb_cache.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_cache.c b/source4/lib/ldb/ldb_tdb/ldb_cache.c index 55eeca56a4..571e952e76 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_cache.c +++ b/source4/lib/ldb/ldb_tdb/ldb_cache.c @@ -481,6 +481,10 @@ int ltdb_increase_sequence_number(struct ldb_module *module) ltdb->sequence_number += 1; } + /* updating the tdb_seqnum here avoids us reloading the cache + records due to our own modification */ + ltdb->tdb_seqnum = tdb_get_seqnum(ltdb->tdb); + return ret; } -- cgit From 97666f12a42dfe04916a9f6397a1c1efd0be75a0 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 23 Jan 2007 10:37:36 +0000 Subject: r20969: remove unused function, found my lcov metze (This used to be commit 0c5eb19ebc12bc954c23e9f561d5f96644a19aca) --- source4/lib/ldb/ldb_tdb/ldb_cache.c | 49 ------------------------------------- 1 file changed, 49 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_cache.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_cache.c b/source4/lib/ldb/ldb_tdb/ldb_cache.c index 571e952e76..7032852d1c 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_cache.c +++ b/source4/lib/ldb/ldb_tdb/ldb_cache.c @@ -488,55 +488,6 @@ int ltdb_increase_sequence_number(struct ldb_module *module) return ret; } - -/* - return the attribute flags from the @ATTRIBUTES record - for the given attribute -*/ -int ltdb_attribute_flags(struct ldb_module *module, const char *attr_name) -{ - struct ltdb_private *ltdb = module->private_data; - const struct ldb_message_element *attr_el; - int i, j, ret=0; - - if (ltdb->cache->last_attribute.name && - ldb_attr_cmp(ltdb->cache->last_attribute.name, attr_name) == 0) { - return ltdb->cache->last_attribute.flags; - } - - /* objectclass is a special default case */ - if (ldb_attr_cmp(attr_name, LTDB_OBJECTCLASS) == 0) { - ret = LTDB_FLAG_OBJECTCLASS | LTDB_FLAG_CASE_INSENSITIVE; - } - - attr_el = ldb_msg_find_element(ltdb->cache->attributes, attr_name); - - if (!attr_el) { - /* check if theres a wildcard attribute */ - attr_el = ldb_msg_find_element(ltdb->cache->attributes, "*"); - - if (!attr_el) { - return ret; - } - } - - for (i = 0; i < attr_el->num_values; i++) { - for (j=0; ltdb_valid_attr_flags[j].name; j++) { - if (strcmp(ltdb_valid_attr_flags[j].name, - (char *)attr_el->values[i].data) == 0) { - ret |= ltdb_valid_attr_flags[j].value; - } - } - } - - talloc_free(ltdb->cache->last_attribute.name); - - ltdb->cache->last_attribute.name = talloc_strdup(ltdb->cache, attr_name); - ltdb->cache->last_attribute.flags = ret; - - return ret; -} - int ltdb_check_at_attributes_values(const struct ldb_val *value) { int i; -- cgit From 9ec83ae25df8e8e55ab1e25de4972ec4d082783b Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 23 Apr 2007 00:36:49 +0000 Subject: r22471: Convert more code to use proper LDB error codes. This is a 1 to 1 convertion, next step is to make this code report an error if the basedn is not used, hopefully avoiding an explicit search on the base object in the most common cases. (This used to be commit 50534c84b4577b2d32565a74a4716088f706bfea) --- source4/lib/ldb/ldb_tdb/ldb_cache.c | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_cache.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_cache.c b/source4/lib/ldb/ldb_tdb/ldb_cache.c index 7032852d1c..52e3d2f4e9 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_cache.c +++ b/source4/lib/ldb/ldb_tdb/ldb_cache.c @@ -110,12 +110,13 @@ static int ltdb_attributes_load(struct ldb_module *module) struct ltdb_private *ltdb = module->private_data; struct ldb_message *msg = ltdb->cache->attributes; struct ldb_dn *dn; - int i; + int i, r; dn = ldb_dn_new(module, module->ldb, LTDB_ATTRIBUTES); if (dn == NULL) goto failed; - if (ltdb_search_dn1(module, dn, msg) == -1) { + r = ltdb_search_dn1(module, dn, msg); + if (r != LDB_SUCCESS && r != LDB_ERR_NO_SUCH_OBJECT) { talloc_free(dn); goto failed; } @@ -176,12 +177,13 @@ static int ltdb_subclasses_load(struct ldb_module *module) struct ltdb_private *ltdb = module->private_data; struct ldb_message *msg = ltdb->cache->subclasses; struct ldb_dn *dn; - int i, j; + int i, j, r; dn = ldb_dn_new(module, module->ldb, LTDB_SUBCLASSES); if (dn == NULL) goto failed; - if (ltdb_search_dn1(module, dn, msg) == -1) { + r = ltdb_search_dn1(module, dn, msg); + if (r != LDB_SUCCESS && r != LDB_ERR_NO_SUCH_OBJECT) { talloc_free(dn); goto failed; } @@ -277,7 +279,7 @@ static int ltdb_baseinfo_init(struct ldb_module *module) failed: talloc_free(msg); errno = ENOMEM; - return -1; + return LDB_ERR_OPERATIONS_ERROR; } /* @@ -313,6 +315,7 @@ int ltdb_cache_load(struct ldb_module *module) struct ldb_dn *indexlist_dn = NULL; uint64_t seq; struct ldb_message *baseinfo = NULL; + int r; /* a very fast check to avoid extra database reads */ if (ltdb->cache != NULL && @@ -339,16 +342,17 @@ int ltdb_cache_load(struct ldb_module *module) baseinfo_dn = ldb_dn_new(module, module->ldb, LTDB_BASEINFO); if (baseinfo_dn == NULL) goto failed; - if (ltdb_search_dn1(module, baseinfo_dn, baseinfo) == -1) { + r= ltdb_search_dn1(module, baseinfo_dn, baseinfo); + if (r != LDB_SUCCESS && r != LDB_ERR_NO_SUCH_OBJECT) { goto failed; } /* possibly initialise the baseinfo */ if (!baseinfo->dn) { - if (ltdb_baseinfo_init(module) != 0) { + if (ltdb_baseinfo_init(module) != LDB_SUCCESS) { goto failed; } - if (ltdb_search_dn1(module, baseinfo_dn, baseinfo) != 1) { + if (ltdb_search_dn1(module, baseinfo_dn, baseinfo) != LDB_SUCCESS) { goto failed; } } @@ -384,7 +388,8 @@ int ltdb_cache_load(struct ldb_module *module) indexlist_dn = ldb_dn_new(module, module->ldb, LTDB_INDEXLIST); if (indexlist_dn == NULL) goto failed; - if (ltdb_search_dn1(module, indexlist_dn, ltdb->cache->indexlist) == -1) { + r = ltdb_search_dn1(module, indexlist_dn, ltdb->cache->indexlist); + if (r != LDB_SUCCESS && r != LDB_ERR_NO_SUCH_OBJECT) { goto failed; } @@ -426,13 +431,13 @@ int ltdb_increase_sequence_number(struct ldb_module *module) msg = talloc(ltdb, struct ldb_message); if (msg == NULL) { errno = ENOMEM; - return -1; + return LDB_ERR_OPERATIONS_ERROR; } s = talloc_asprintf(msg, "%llu", ltdb->sequence_number+1); if (!s) { errno = ENOMEM; - return -1; + return LDB_ERR_OPERATIONS_ERROR; } msg->num_elements = ARRAY_SIZE(el); @@ -441,13 +446,13 @@ int ltdb_increase_sequence_number(struct ldb_module *module) if (msg->dn == NULL) { talloc_free(msg); errno = ENOMEM; - return -1; + return LDB_ERR_OPERATIONS_ERROR; } el[0].name = talloc_strdup(msg, LTDB_SEQUENCE_NUMBER); if (el[0].name == NULL) { talloc_free(msg); errno = ENOMEM; - return -1; + return LDB_ERR_OPERATIONS_ERROR; } el[0].values = &val; el[0].num_values = 1; @@ -459,7 +464,7 @@ int ltdb_increase_sequence_number(struct ldb_module *module) if (el[1].name == NULL) { talloc_free(msg); errno = ENOMEM; - return -1; + return LDB_ERR_OPERATIONS_ERROR; } el[1].values = &val_time; el[1].num_values = 1; @@ -467,7 +472,7 @@ int ltdb_increase_sequence_number(struct ldb_module *module) s = ldb_timestring(msg, t); if (s == NULL) { - return -1; + return LDB_ERR_OPERATIONS_ERROR; } val_time.data = (uint8_t *)s; @@ -477,7 +482,7 @@ int ltdb_increase_sequence_number(struct ldb_module *module) talloc_free(msg); - if (ret == 0) { + if (ret == LDB_SUCCESS) { ltdb->sequence_number += 1; } -- 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_cache.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_cache.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_cache.c b/source4/lib/ldb/ldb_tdb/ldb_cache.c index 52e3d2f4e9..3600bae4ef 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_cache.c +++ b/source4/lib/ldb/ldb_tdb/ldb_cache.c @@ -32,10 +32,9 @@ * Author: Andrew Tridgell */ -#include "includes.h" -#include "ldb/include/includes.h" +#include "ldb_includes.h" -#include "ldb/ldb_tdb/ldb_tdb.h" +#include "ldb_tdb.h" #define LTDB_FLAG_CASE_INSENSITIVE (1<<0) #define LTDB_FLAG_INTEGER (1<<1) -- 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_cache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_cache.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_cache.c b/source4/lib/ldb/ldb_tdb/ldb_cache.c index 3600bae4ef..adb1943dc9 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_cache.c +++ b/source4/lib/ldb/ldb_tdb/ldb_cache.c @@ -10,7 +10,7 @@ This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. + version 3 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of -- cgit From 6c973f4e8ccbcb6c9275f8a54e26abb19df7e15a Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 03:42:26 +0000 Subject: r23798: updated old Temple Place FSF addresses to new URL (This used to be commit 40c0919aaa9c1b14bbaebb95ecce53eb0380fdbb) --- source4/lib/ldb/ldb_tdb/ldb_cache.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_cache.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_cache.c b/source4/lib/ldb/ldb_tdb/ldb_cache.c index adb1943dc9..6bbf31dee7 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_cache.c +++ b/source4/lib/ldb/ldb_tdb/ldb_cache.c @@ -18,8 +18,7 @@ Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + License along with this library; if not, see . */ /* -- cgit From cd962355abad90a2161765a7be7d26e63572cab7 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 7 Sep 2007 15:08:14 +0000 Subject: r25000: Fix some more C++ compatibility warnings. (This used to be commit 08bb1ef643ab906f1645cf6f32763dc73b1884e4) --- source4/lib/ldb/ldb_tdb/ldb_cache.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_cache.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_cache.c b/source4/lib/ldb/ldb_tdb/ldb_cache.c index 6bbf31dee7..a7f72dd6d0 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_cache.c +++ b/source4/lib/ldb/ldb_tdb/ldb_cache.c @@ -58,7 +58,7 @@ static const struct { */ static void ltdb_attributes_unload(struct ldb_module *module) { - struct ltdb_private *ltdb = module->private_data; + struct ltdb_private *ltdb = (struct ltdb_private *)module->private_data; struct ldb_message *msg; int i; @@ -105,7 +105,7 @@ static int ltdb_attributes_flags(struct ldb_message_element *el, unsigned *v) */ static int ltdb_attributes_load(struct ldb_module *module) { - struct ltdb_private *ltdb = module->private_data; + struct ltdb_private *ltdb = (struct ltdb_private *)module->private_data; struct ldb_message *msg = ltdb->cache->attributes; struct ldb_dn *dn; int i, r; @@ -172,7 +172,7 @@ failed: */ static int ltdb_subclasses_load(struct ldb_module *module) { - struct ltdb_private *ltdb = module->private_data; + struct ltdb_private *ltdb = (struct ltdb_private *)module->private_data; struct ldb_message *msg = ltdb->cache->subclasses; struct ldb_dn *dn; int i, j, r; @@ -208,7 +208,7 @@ failed: */ static void ltdb_subclasses_unload(struct ldb_module *module) { - struct ltdb_private *ltdb = module->private_data; + struct ltdb_private *ltdb = (struct ltdb_private *)module->private_data; struct ldb_message *msg; int i; @@ -232,7 +232,7 @@ static void ltdb_subclasses_unload(struct ldb_module *module) */ static int ltdb_baseinfo_init(struct ldb_module *module) { - struct ltdb_private *ltdb = module->private_data; + struct ltdb_private *ltdb = (struct ltdb_private *)module->private_data; struct ldb_message *msg; struct ldb_message_element el; struct ldb_val val; @@ -285,7 +285,7 @@ failed: */ static void ltdb_cache_free(struct ldb_module *module) { - struct ltdb_private *ltdb = module->private_data; + struct ltdb_private *ltdb = (struct ltdb_private *)module->private_data; ltdb->sequence_number = 0; talloc_free(ltdb->cache); @@ -308,7 +308,7 @@ int ltdb_cache_reload(struct ldb_module *module) */ int ltdb_cache_load(struct ldb_module *module) { - struct ltdb_private *ltdb = module->private_data; + struct ltdb_private *ltdb = (struct ltdb_private *)module->private_data; struct ldb_dn *baseinfo_dn = NULL; struct ldb_dn *indexlist_dn = NULL; uint64_t seq; @@ -417,7 +417,7 @@ failed: */ int ltdb_increase_sequence_number(struct ldb_module *module) { - struct ltdb_private *ltdb = module->private_data; + struct ltdb_private *ltdb = (struct ltdb_private *)module->private_data; struct ldb_message *msg; struct ldb_message_element el[2]; struct ldb_val val; -- cgit From c64116e158080c7cd7304cdd3b80c8666f78c7c6 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Tue, 18 Sep 2007 22:43:06 +0000 Subject: r25218: After discussion with Simo, remove the subclass support from LDB. Subclass support was designed to avoid needing to spell out the full list of objectClasses that an entry was in. However, Samba4 now enforces this restriction in the objectClass module, and the way subclass matching was handled was complex and counter-intuitive in my opinion (and did not match LDAP). Andrew Bartlett (This used to be commit f5ce04b904e14445a2a7e7f92e7e1f64b645c6f2) --- source4/lib/ldb/ldb_tdb/ldb_cache.c | 71 ------------------------------------- 1 file changed, 71 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_cache.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_cache.c b/source4/lib/ldb/ldb_tdb/ldb_cache.c index a7f72dd6d0..de489e3d8b 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_cache.c +++ b/source4/lib/ldb/ldb_tdb/ldb_cache.c @@ -38,7 +38,6 @@ #define LTDB_FLAG_CASE_INSENSITIVE (1<<0) #define LTDB_FLAG_INTEGER (1<<1) #define LTDB_FLAG_HIDDEN (1<<2) -#define LTDB_FLAG_OBJECTCLASS (1<<3) /* valid attribute flags */ static const struct { @@ -167,66 +166,6 @@ failed: } -/* - register any subclasses from @SUBCLASSES -*/ -static int ltdb_subclasses_load(struct ldb_module *module) -{ - struct ltdb_private *ltdb = (struct ltdb_private *)module->private_data; - struct ldb_message *msg = ltdb->cache->subclasses; - struct ldb_dn *dn; - int i, j, r; - - dn = ldb_dn_new(module, module->ldb, LTDB_SUBCLASSES); - if (dn == NULL) goto failed; - - r = ltdb_search_dn1(module, dn, msg); - if (r != LDB_SUCCESS && r != LDB_ERR_NO_SUCH_OBJECT) { - talloc_free(dn); - goto failed; - } - talloc_free(dn); - - for (i=0;inum_elements;i++) { - struct ldb_message_element *el = &msg->elements[i]; - for (j=0;jnum_values;j++) { - if (ldb_subclass_add(module->ldb, el->name, - (char *)el->values[j].data) != 0) { - goto failed; - } - } - } - - return 0; -failed: - return -1; -} - - -/* - de-register any @SUBCLASSES -*/ -static void ltdb_subclasses_unload(struct ldb_module *module) -{ - struct ltdb_private *ltdb = (struct ltdb_private *)module->private_data; - struct ldb_message *msg; - int i; - - if (ltdb->cache->subclasses == NULL) { - /* no previously loaded subclasses */ - return; - } - - msg = ltdb->cache->subclasses; - for (i=0;inum_elements;i++) { - ldb_subclass_remove(module->ldb, msg->elements[i].name); - } - - talloc_free(ltdb->cache->subclasses); - ltdb->cache->subclasses = NULL; -} - - /* initialise the baseinfo record */ @@ -298,7 +237,6 @@ static void ltdb_cache_free(struct ldb_module *module) int ltdb_cache_reload(struct ldb_module *module) { ltdb_attributes_unload(module); - ltdb_subclasses_unload(module); ltdb_cache_free(module); return ltdb_cache_load(module); } @@ -325,10 +263,8 @@ int ltdb_cache_load(struct ldb_module *module) ltdb->cache = talloc_zero(ltdb, struct ltdb_cache); if (ltdb->cache == NULL) goto failed; ltdb->cache->indexlist = talloc_zero(ltdb->cache, struct ldb_message); - ltdb->cache->subclasses = talloc_zero(ltdb->cache, struct ldb_message); ltdb->cache->attributes = talloc_zero(ltdb->cache, struct ldb_message); if (ltdb->cache->indexlist == NULL || - ltdb->cache->subclasses == NULL || ltdb->cache->attributes == NULL) { goto failed; } @@ -369,16 +305,12 @@ int ltdb_cache_load(struct ldb_module *module) memset(<db->cache->last_attribute, 0, sizeof(ltdb->cache->last_attribute)); ltdb_attributes_unload(module); - ltdb_subclasses_unload(module); talloc_free(ltdb->cache->indexlist); - talloc_free(ltdb->cache->subclasses); ltdb->cache->indexlist = talloc_zero(ltdb->cache, struct ldb_message); - ltdb->cache->subclasses = talloc_zero(ltdb->cache, struct ldb_message); ltdb->cache->attributes = talloc_zero(ltdb->cache, struct ldb_message); if (ltdb->cache->indexlist == NULL || - ltdb->cache->subclasses == NULL || ltdb->cache->attributes == NULL) { goto failed; } @@ -394,9 +326,6 @@ int ltdb_cache_load(struct ldb_module *module) if (ltdb_attributes_load(module) == -1) { goto failed; } - if (ltdb_subclasses_load(module) == -1) { - goto failed; - } done: talloc_free(baseinfo); -- cgit From d544879e434c36f02bfc7d1322f1179d00294669 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Thu, 15 Nov 2007 01:53:44 +0100 Subject: r25959: Add a new special DN to LDB: @OPTIONS Use the checkBaseOnSearch attribute to control if we should check the base DN on search requests. Also ensure we honour any errors in searching, not just errors in the supplied 'done' callback. Andrew Bartlett (This used to be commit deaac92f439ef001bfe052df170d6e34e8ba5845) --- source4/lib/ldb/ldb_tdb/ldb_cache.c | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_cache.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_cache.c b/source4/lib/ldb/ldb_tdb/ldb_cache.c index de489e3d8b..77922a97c7 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_cache.c +++ b/source4/lib/ldb/ldb_tdb/ldb_cache.c @@ -113,11 +113,13 @@ static int ltdb_attributes_load(struct ldb_module *module) if (dn == NULL) goto failed; r = ltdb_search_dn1(module, dn, msg); + talloc_free(dn); if (r != LDB_SUCCESS && r != LDB_ERR_NO_SUCH_OBJECT) { - talloc_free(dn); goto failed; } - talloc_free(dn); + if (r == LDB_ERR_NO_SUCH_OBJECT) { + return 0; + } /* mapping these flags onto ldap 'syntaxes' isn't strictly correct, but its close enough for now */ for (i=0;inum_elements;i++) { @@ -247,10 +249,10 @@ int ltdb_cache_reload(struct ldb_module *module) int ltdb_cache_load(struct ldb_module *module) { struct ltdb_private *ltdb = (struct ltdb_private *)module->private_data; - struct ldb_dn *baseinfo_dn = NULL; + struct ldb_dn *baseinfo_dn = NULL, *options_dn = NULL; struct ldb_dn *indexlist_dn = NULL; uint64_t seq; - struct ldb_message *baseinfo = NULL; + struct ldb_message *baseinfo = NULL, *options = NULL; int r; /* a very fast check to avoid extra database reads */ @@ -282,7 +284,7 @@ int ltdb_cache_load(struct ldb_module *module) } /* possibly initialise the baseinfo */ - if (!baseinfo->dn) { + if (r == LDB_ERR_NO_SUCH_OBJECT) { if (ltdb_baseinfo_init(module) != LDB_SUCCESS) { goto failed; } @@ -301,6 +303,25 @@ int ltdb_cache_load(struct ldb_module *module) } ltdb->sequence_number = seq; + /* Read an interpret database options */ + options = talloc(ltdb->cache, struct ldb_message); + if (options == NULL) goto failed; + + options_dn = ldb_dn_new(module, module->ldb, LTDB_OPTIONS); + if (options_dn == NULL) goto failed; + + r= ltdb_search_dn1(module, options_dn, options); + if (r != LDB_SUCCESS && r != LDB_ERR_NO_SUCH_OBJECT) { + goto failed; + } + + /* possibly initialise the baseinfo */ + if (r == LDB_SUCCESS) { + ltdb->check_base = ldb_msg_find_attr_as_bool(options, LTDB_CHECK_BASE, false); + } else { + ltdb->check_base = false; + } + talloc_free(ltdb->cache->last_attribute.name); memset(<db->cache->last_attribute, 0, sizeof(ltdb->cache->last_attribute)); @@ -328,12 +349,16 @@ int ltdb_cache_load(struct ldb_module *module) } done: + talloc_free(options); + talloc_free(options_dn); talloc_free(baseinfo); talloc_free(baseinfo_dn); talloc_free(indexlist_dn); return 0; failed: + talloc_free(options); + talloc_free(options_dn); talloc_free(baseinfo); talloc_free(baseinfo_dn); talloc_free(indexlist_dn); -- cgit From fe61b63393e1deaf98982841ce3693ee63af52f0 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Thu, 15 Nov 2007 11:01:14 +0100 Subject: r25964: Fix comment and use talloc hirachy in ldb_tdb initialisation. Andrew Bartlett (This used to be commit 05cc2a7d966a10f1f111d7bae3261e1087fdffe6) --- source4/lib/ldb/ldb_tdb/ldb_cache.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb/ldb_cache.c') diff --git a/source4/lib/ldb/ldb_tdb/ldb_cache.c b/source4/lib/ldb/ldb_tdb/ldb_cache.c index 77922a97c7..2576e2c7bd 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_cache.c +++ b/source4/lib/ldb/ldb_tdb/ldb_cache.c @@ -307,7 +307,7 @@ int ltdb_cache_load(struct ldb_module *module) options = talloc(ltdb->cache, struct ldb_message); if (options == NULL) goto failed; - options_dn = ldb_dn_new(module, module->ldb, LTDB_OPTIONS); + options_dn = ldb_dn_new(options, module->ldb, LTDB_OPTIONS); if (options_dn == NULL) goto failed; r= ltdb_search_dn1(module, options_dn, options); @@ -315,7 +315,7 @@ int ltdb_cache_load(struct ldb_module *module) goto failed; } - /* possibly initialise the baseinfo */ + /* set flag for checking base DN on searches */ if (r == LDB_SUCCESS) { ltdb->check_base = ldb_msg_find_attr_as_bool(options, LTDB_CHECK_BASE, false); } else { @@ -350,7 +350,6 @@ int ltdb_cache_load(struct ldb_module *module) done: talloc_free(options); - talloc_free(options_dn); talloc_free(baseinfo); talloc_free(baseinfo_dn); talloc_free(indexlist_dn); @@ -358,7 +357,6 @@ done: failed: talloc_free(options); - talloc_free(options_dn); talloc_free(baseinfo); talloc_free(baseinfo_dn); talloc_free(indexlist_dn); -- cgit