summaryrefslogtreecommitdiff
path: root/source4/lib/ldb/ldb_tdb
diff options
context:
space:
mode:
authorSimo Sorce <idra@samba.org>2004-11-15 11:40:27 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:05:51 -0500
commit679e95db033fd11d17c1f1ac5e44f6cc4df2220e (patch)
tree2a6138f9c6c66025ac0e68965dc73f32846f0d1b /source4/lib/ldb/ldb_tdb
parent5b397619ccd3a2189c053209387093b60ff53094 (diff)
downloadsamba-679e95db033fd11d17c1f1ac5e44f6cc4df2220e.tar.gz
samba-679e95db033fd11d17c1f1ac5e44f6cc4df2220e.tar.bz2
samba-679e95db033fd11d17c1f1ac5e44f6cc4df2220e.zip
r3754: merge in ldb modules support from the tmp branch ldbPlugins
(This used to be commit 71323f424b4561af1fdddd2358629049be3dad8c)
Diffstat (limited to 'source4/lib/ldb/ldb_tdb')
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_cache.c57
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_index.c121
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_match.c27
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_search.c81
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_tdb.c167
5 files changed, 247 insertions, 206 deletions
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, &ltdb->cache.baseinfo);
- ltdb_search_dn1_free(ldb, &ltdb->cache.indexlist);
- ltdb_search_dn1_free(ldb, &ltdb->cache.subclasses);
- ltdb_search_dn1_free(ldb, &ltdb->cache.attributes);
+ ltdb_search_dn1_free(module, &ltdb->cache.baseinfo);
+ ltdb_search_dn1_free(module, &ltdb->cache.indexlist);
+ ltdb_search_dn1_free(module, &ltdb->cache.subclasses);
+ ltdb_search_dn1_free(module, &ltdb->cache.attributes);
ldb_free(ldb, ltdb->cache.last_attribute.name);
memset(&ltdb->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, &ltdb->cache.baseinfo);
+ ltdb_search_dn1_free(module, &ltdb->cache.baseinfo);
- if (ltdb_search_dn1(ldb, LTDB_BASEINFO, &ltdb->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_baseinfo_init(ldb) != 0) {
+ if (ltdb_baseinfo_init(module) != 0) {
goto failed;
}
- if (ltdb_search_dn1(ldb, LTDB_BASEINFO, &ltdb->cache.baseinfo) != 1) {
+ if (ltdb_search_dn1(module, LTDB_BASEINFO, &ltdb->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(&ltdb->cache.last_attribute, 0, sizeof(ltdb->cache.last_attribute));
- ltdb_search_dn1_free(ldb, &ltdb->cache.indexlist);
- ltdb_search_dn1_free(ldb, &ltdb->cache.subclasses);
- ltdb_search_dn1_free(ldb, &ltdb->cache.attributes);
+ ltdb_search_dn1_free(module, &ltdb->cache.indexlist);
+ ltdb_search_dn1_free(module, &ltdb->cache.subclasses);
+ ltdb_search_dn1_free(module, &ltdb->cache.attributes);
- if (ltdb_search_dn1(ldb, LTDB_INDEXLIST, &ltdb->cache.indexlist) == -1) {
+ if (ltdb_search_dn1(module, LTDB_INDEXLIST, &ltdb->cache.indexlist) == -1) {
goto failed;
}
- if (ltdb_search_dn1(ldb, LTDB_SUBCLASSES, &ltdb->cache.subclasses) == -1) {
+ if (ltdb_search_dn1(module, LTDB_SUBCLASSES, &ltdb->cache.subclasses) == -1) {
goto failed;
}
- if (ltdb_search_dn1(ldb, LTDB_ATTRIBUTES, &ltdb->cache.attributes) == -1) {
+ if (ltdb_search_dn1(module, LTDB_ATTRIBUTES, &ltdb->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;
diff --git a/source4/lib/ldb/ldb_tdb/ldb_index.c b/source4/lib/ldb/ldb_tdb/ldb_index.c
index cfd097e361..d54208777d 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_index.c
+++ b/source4/lib/ldb/ldb_tdb/ldb_index.c
@@ -107,11 +107,12 @@ static int list_cmp(const char **s1, const char **s2)
/*
return a list of dn's that might match a simple indexed search or
*/
-static int ltdb_index_dn_simple(struct ldb_context *ldb,
+static int ltdb_index_dn_simple(struct ldb_module *module,
struct ldb_parse_tree *tree,
const struct ldb_message *index_list,
struct dn_list *list)
{
+ struct ldb_context *ldb = module->ldb;
char *dn = NULL;
int ret;
unsigned int i, j;
@@ -123,7 +124,7 @@ static int ltdb_index_dn_simple(struct ldb_context *ldb,
/*
if the value is a wildcard then we can't do a match via indexing
*/
- if (ltdb_has_wildcard(ldb, tree->u.simple.attr, &tree->u.simple.value)) {
+ if (ltdb_has_wildcard(module, tree->u.simple.attr, &tree->u.simple.value)) {
return -1;
}
@@ -138,7 +139,7 @@ static int ltdb_index_dn_simple(struct ldb_context *ldb,
dn = ldb_dn_key(ldb, tree->u.simple.attr, &tree->u.simple.value);
if (!dn) return -1;
- ret = ltdb_search_dn1(ldb, dn, &msg);
+ ret = ltdb_search_dn1(module, dn, &msg);
ldb_free(ldb, dn);
if (ret == 0 || ret == -1) {
return ret;
@@ -163,14 +164,14 @@ static int ltdb_index_dn_simple(struct ldb_context *ldb,
ldb_strdup(ldb, (char *)el->values[j].data);
if (!list->dn[list->count]) {
dn_list_free(ldb, list);
- ltdb_search_dn1_free(ldb, &msg);
+ ltdb_search_dn1_free(module, &msg);
return -1;
}
list->count++;
}
}
- ltdb_search_dn1_free(ldb, &msg);
+ ltdb_search_dn1_free(module, &msg);
qsort(list->dn, list->count, sizeof(char *), (comparison_fn_t) list_cmp);
@@ -184,12 +185,13 @@ static int list_union(struct ldb_context *, struct dn_list *, const struct dn_li
return a list of dn's that might match a simple indexed search on
the special objectclass attribute
*/
-static int ltdb_index_dn_objectclass(struct ldb_context *ldb,
+static int ltdb_index_dn_objectclass(struct ldb_module *module,
struct ldb_parse_tree *tree,
const struct ldb_message *index_list,
struct dn_list *list)
{
- struct ltdb_private *ltdb = ldb->private_data;
+ struct ldb_context *ldb = module->ldb;
+ struct ltdb_private *ltdb = module->private_data;
unsigned int i;
int ret;
const char *target = tree->u.simple.value.data;
@@ -197,7 +199,7 @@ static int ltdb_index_dn_objectclass(struct ldb_context *ldb,
list->count = 0;
list->dn = NULL;
- ret = ltdb_index_dn_simple(ldb, tree, index_list, list);
+ ret = ltdb_index_dn_simple(module, tree, index_list, list);
for (i=0;i<ltdb->cache.subclasses.num_elements;i++) {
struct ldb_message_element *el = &ltdb->cache.subclasses.elements[i];
@@ -212,7 +214,7 @@ static int ltdb_index_dn_objectclass(struct ldb_context *ldb,
return -1;
}
tree2.u.simple.value = el->values[j];
- if (ltdb_index_dn_objectclass(ldb, &tree2,
+ if (ltdb_index_dn_objectclass(module, &tree2,
index_list, &list2) == 1) {
if (list->count == 0) {
*list = list2;
@@ -233,15 +235,15 @@ static int ltdb_index_dn_objectclass(struct ldb_context *ldb,
/*
return a list of dn's that might match a leaf indexed search
*/
-static int ltdb_index_dn_leaf(struct ldb_context *ldb,
+static int ltdb_index_dn_leaf(struct ldb_module *module,
struct ldb_parse_tree *tree,
const struct ldb_message *index_list,
struct dn_list *list)
{
if (ldb_attr_cmp(tree->u.simple.attr, LTDB_OBJECTCLASS) == 0) {
- return ltdb_index_dn_objectclass(ldb, tree, index_list, list);
+ return ltdb_index_dn_objectclass(module, tree, index_list, list);
}
- return ltdb_index_dn_simple(ldb, tree, index_list, list);
+ return ltdb_index_dn_simple(module, tree, index_list, list);
}
@@ -331,7 +333,7 @@ static int list_union(struct ldb_context *ldb,
return 0;
}
-static int ltdb_index_dn(struct ldb_context *ldb,
+static int ltdb_index_dn(struct ldb_module *module,
struct ldb_parse_tree *tree,
const struct ldb_message *index_list,
struct dn_list *list);
@@ -340,11 +342,12 @@ static int ltdb_index_dn(struct ldb_context *ldb,
/*
OR two index results
*/
-static int ltdb_index_dn_or(struct ldb_context *ldb,
+static int ltdb_index_dn_or(struct ldb_module *module,
struct ldb_parse_tree *tree,
const struct ldb_message *index_list,
struct dn_list *list)
{
+ struct ldb_context *ldb = module->ldb;
unsigned int i;
int ret;
@@ -355,7 +358,7 @@ static int ltdb_index_dn_or(struct ldb_context *ldb,
for (i=0;i<tree->u.list.num_elements;i++) {
struct dn_list list2;
int v;
- v = ltdb_index_dn(ldb, tree->u.list.elements[i], index_list, &list2);
+ v = ltdb_index_dn(module, tree->u.list.elements[i], index_list, &list2);
if (v == 0) {
/* 0 || X == X */
@@ -395,7 +398,7 @@ static int ltdb_index_dn_or(struct ldb_context *ldb,
/*
NOT an index results
*/
-static int ltdb_index_dn_not(struct ldb_context *ldb,
+static int ltdb_index_dn_not(struct ldb_module *module,
struct ldb_parse_tree *tree,
const struct ldb_message *index_list,
struct dn_list *list)
@@ -414,11 +417,12 @@ static int ltdb_index_dn_not(struct ldb_context *ldb,
/*
AND two index results
*/
-static int ltdb_index_dn_and(struct ldb_context *ldb,
+static int ltdb_index_dn_and(struct ldb_module *module,
struct ldb_parse_tree *tree,
const struct ldb_message *index_list,
struct dn_list *list)
{
+ struct ldb_context *ldb = module->ldb;
unsigned int i;
int ret;
@@ -429,7 +433,7 @@ static int ltdb_index_dn_and(struct ldb_context *ldb,
for (i=0;i<tree->u.list.num_elements;i++) {
struct dn_list list2;
int v;
- v = ltdb_index_dn(ldb, tree->u.list.elements[i], index_list, &list2);
+ v = ltdb_index_dn(module, tree->u.list.elements[i], index_list, &list2);
if (v == 0) {
/* 0 && X == 0 */
@@ -465,7 +469,7 @@ static int ltdb_index_dn_and(struct ldb_context *ldb,
return a list of dn's that might match a indexed search or
-1 if an error. return 0 for no matches, or 1 for matches
*/
-static int ltdb_index_dn(struct ldb_context *ldb,
+static int ltdb_index_dn(struct ldb_module *module,
struct ldb_parse_tree *tree,
const struct ldb_message *index_list,
struct dn_list *list)
@@ -474,19 +478,19 @@ static int ltdb_index_dn(struct ldb_context *ldb,
switch (tree->operation) {
case LDB_OP_SIMPLE:
- ret = ltdb_index_dn_leaf(ldb, tree, index_list, list);
+ ret = ltdb_index_dn_leaf(module, tree, index_list, list);
break;
case LDB_OP_AND:
- ret = ltdb_index_dn_and(ldb, tree, index_list, list);
+ ret = ltdb_index_dn_and(module, tree, index_list, list);
break;
case LDB_OP_OR:
- ret = ltdb_index_dn_or(ldb, tree, index_list, list);
+ ret = ltdb_index_dn_or(module, tree, index_list, list);
break;
case LDB_OP_NOT:
- ret = ltdb_index_dn_not(ldb, tree, index_list, list);
+ ret = ltdb_index_dn_not(module, tree, index_list, list);
break;
}
@@ -497,7 +501,7 @@ static int ltdb_index_dn(struct ldb_context *ldb,
filter a candidate dn_list from an indexed search into a set of results
extracting just the given attributes
*/
-static int ldb_index_filter(struct ldb_context *ldb, struct ldb_parse_tree *tree,
+static int ldb_index_filter(struct ldb_module *module, struct ldb_parse_tree *tree,
const char *base,
enum ldb_scope scope,
const struct dn_list *dn_list,
@@ -508,7 +512,7 @@ static int ldb_index_filter(struct ldb_context *ldb, struct ldb_parse_tree *tree
for (i=0;i<dn_list->count;i++) {
struct ldb_message msg;
int ret;
- ret = ltdb_search_dn1(ldb, dn_list->dn[i], &msg);
+ ret = ltdb_search_dn1(module, dn_list->dn[i], &msg);
if (ret == 0) {
/* the record has disappeared? yes, this can happen */
continue;
@@ -519,10 +523,10 @@ static int ldb_index_filter(struct ldb_context *ldb, struct ldb_parse_tree *tree
return -1;
}
- if (ldb_message_match(ldb, &msg, tree, base, scope) == 1) {
- ret = ltdb_add_attr_results(ldb, &msg, attrs, &count, res);
+ if (ldb_message_match(module, &msg, tree, base, scope) == 1) {
+ ret = ltdb_add_attr_results(module, &msg, attrs, &count, res);
}
- ltdb_search_dn1_free(ldb, &msg);
+ ltdb_search_dn1_free(module, &msg);
if (ret != 0) {
return -1;
}
@@ -536,13 +540,14 @@ static int ldb_index_filter(struct ldb_context *ldb, struct ldb_parse_tree *tree
returns -1 if an indexed search is not possible, in which
case the caller should call ltdb_search_full()
*/
-int ltdb_search_indexed(struct ldb_context *ldb,
+int ltdb_search_indexed(struct ldb_module *module,
const char *base,
enum ldb_scope scope,
struct ldb_parse_tree *tree,
const char * const attrs[], struct ldb_message ***res)
{
- struct ltdb_private *ltdb = ldb->private_data;
+ struct ldb_context *ldb = module->ldb;
+ struct ltdb_private *ltdb = module->private_data;
struct dn_list dn_list;
int ret;
@@ -551,12 +556,12 @@ int ltdb_search_indexed(struct ldb_context *ldb,
return -1;
}
- ret = ltdb_index_dn(ldb, tree, &ltdb->cache.indexlist, &dn_list);
+ ret = ltdb_index_dn(module, tree, &ltdb->cache.indexlist, &dn_list);
if (ret == 1) {
/* we've got a candidate list - now filter by the full tree
and extract the needed attributes */
- ret = ldb_index_filter(ldb, tree, base, scope, &dn_list,
+ ret = ldb_index_filter(module, tree, base, scope, &dn_list,
attrs, res);
dn_list_free(ldb, &dn_list);
}
@@ -638,9 +643,10 @@ static int ltdb_index_add1_add(struct ldb_context *ldb,
/*
add an index entry for one message element
*/
-static int ltdb_index_add1(struct ldb_context *ldb, char *dn,
+static int ltdb_index_add1(struct ldb_module *module, char *dn,
struct ldb_message_element *el, int v_idx)
{
+ struct ldb_context *ldb = module->ldb;
struct ldb_message msg;
char *dn_key;
int ret, added=0, added_dn=0;
@@ -651,7 +657,7 @@ static int ltdb_index_add1(struct ldb_context *ldb, char *dn,
return -1;
}
- ret = ltdb_search_dn1(ldb, dn_key, &msg);
+ ret = ltdb_search_dn1(module, dn_key, &msg);
if (ret == -1) {
ldb_free(ldb, dn_key);
return -1;
@@ -686,7 +692,7 @@ static int ltdb_index_add1(struct ldb_context *ldb, char *dn,
}
if (ret == 0) {
- ret = ltdb_store(ldb, &msg, TDB_REPLACE);
+ ret = ltdb_store(module, &msg, TDB_REPLACE);
}
if (added) {
@@ -696,7 +702,7 @@ static int ltdb_index_add1(struct ldb_context *ldb, char *dn,
ldb_free(ldb, msg.dn);
}
- ltdb_search_dn1_free(ldb, &msg);
+ ltdb_search_dn1_free(module, &msg);
return ret;
}
@@ -705,9 +711,9 @@ static int ltdb_index_add1(struct ldb_context *ldb, char *dn,
add the index entries for a new record
return -1 on failure
*/
-int ltdb_index_add(struct ldb_context *ldb, const struct ldb_message *msg)
+int ltdb_index_add(struct ldb_module *module, const struct ldb_message *msg)
{
- struct ltdb_private *ltdb = ldb->private_data;
+ struct ltdb_private *ltdb = module->private_data;
int ret;
unsigned int i, j;
@@ -723,7 +729,7 @@ int ltdb_index_add(struct ldb_context *ldb, const struct ldb_message *msg)
continue;
}
for (j=0;j<msg->elements[i].num_values;j++) {
- ret = ltdb_index_add1(ldb, msg->dn, &msg->elements[i], j);
+ ret = ltdb_index_add1(module, msg->dn, &msg->elements[i], j);
if (ret == -1) {
return -1;
}
@@ -737,9 +743,10 @@ int ltdb_index_add(struct ldb_context *ldb, const struct ldb_message *msg)
/*
delete an index entry for one message element
*/
-static int ltdb_index_del1(struct ldb_context *ldb, const char *dn,
+static int ltdb_index_del1(struct ldb_module *module, const char *dn,
struct ldb_message_element *el, int v_idx)
{
+ struct ldb_context *ldb = module->ldb;
struct ldb_message msg;
char *dn_key;
int ret, i;
@@ -750,7 +757,7 @@ static int ltdb_index_del1(struct ldb_context *ldb, const char *dn,
return -1;
}
- ret = ltdb_search_dn1(ldb, dn_key, &msg);
+ ret = ltdb_search_dn1(module, dn_key, &msg);
if (ret == -1) {
ldb_free(ldb, dn_key);
return -1;
@@ -768,7 +775,7 @@ static int ltdb_index_del1(struct ldb_context *ldb, const char *dn,
if (i == -1) {
ldb_debug(ldb, LDB_DEBUG_ERROR, "ERROR: dn %s not found in %s\n", dn, dn_key);
/* it ain't there. hmmm */
- ltdb_search_dn1_free(ldb, &msg);
+ ltdb_search_dn1_free(module, &msg);
ldb_free(ldb, dn_key);
return 0;
}
@@ -782,12 +789,12 @@ static int ltdb_index_del1(struct ldb_context *ldb, const char *dn,
msg.elements[i].num_values--;
if (msg.elements[i].num_values == 0) {
- ret = ltdb_delete_noindex(ldb, dn_key);
+ ret = ltdb_delete_noindex(module, dn_key);
} else {
- ret = ltdb_store(ldb, &msg, TDB_REPLACE);
+ ret = ltdb_store(module, &msg, TDB_REPLACE);
}
- ltdb_search_dn1_free(ldb, &msg);
+ ltdb_search_dn1_free(module, &msg);
ldb_free(ldb, dn_key);
return ret;
@@ -797,9 +804,9 @@ static int ltdb_index_del1(struct ldb_context *ldb, const char *dn,
delete the index entries for a record
return -1 on failure
*/
-int ltdb_index_del(struct ldb_context *ldb, const struct ldb_message *msg)
+int ltdb_index_del(struct ldb_module *module, const struct ldb_message *msg)
{
- struct ltdb_private *ltdb = ldb->private_data;
+ struct ltdb_private *ltdb = module->private_data;
int ret;
unsigned int i, j;
@@ -816,7 +823,7 @@ int ltdb_index_del(struct ldb_context *ldb, const struct ldb_message *msg)
continue;
}
for (j=0;j<msg->elements[i].num_values;j++) {
- ret = ltdb_index_del1(ldb, msg->dn, &msg->elements[i], j);
+ ret = ltdb_index_del1(module, msg->dn, &msg->elements[i], j);
if (ret == -1) {
return -1;
}
@@ -844,7 +851,7 @@ static int delete_index(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, vo
*/
static int re_index(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, void *state)
{
- struct ldb_context *ldb = state;
+ struct ldb_module *module = state;
struct ldb_message msg;
int ret;
@@ -853,7 +860,7 @@ static int re_index(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, void *
return 0;
}
- ret = ltdb_unpack_data(ldb, &data, &msg);
+ ret = ltdb_unpack_data(module->ldb, &data, &msg);
if (ret != 0) {
return -1;
}
@@ -862,9 +869,9 @@ static int re_index(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, void *
msg.dn = key.dptr+3;
}
- ret = ltdb_index_add(ldb, &msg);
+ ret = ltdb_index_add(module, &msg);
- ltdb_unpack_data_free(ldb, &msg);
+ ltdb_unpack_data_free(module->ldb, &msg);
return ret;
}
@@ -872,14 +879,14 @@ static int re_index(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, void *
/*
force a complete reindex of the database
*/
-int ltdb_reindex(struct ldb_context *ldb)
+int ltdb_reindex(struct ldb_module *module)
{
- struct ltdb_private *ltdb = ldb->private_data;
+ struct ltdb_private *ltdb = module->private_data;
int ret;
- ltdb_cache_free(ldb);
+ ltdb_cache_free(module);
- if (ltdb_cache_load(ldb) != 0) {
+ if (ltdb_cache_load(module) != 0) {
return -1;
}
@@ -891,7 +898,7 @@ int ltdb_reindex(struct ldb_context *ldb)
}
/* now traverse adding any indexes for normal LDB records */
- ret = tdb_traverse(ltdb->tdb, re_index, ldb);
+ ret = tdb_traverse(ltdb->tdb, re_index, module);
if (ret == -1) {
errno = EIO;
return -1;
diff --git a/source4/lib/ldb/ldb_tdb/ldb_match.c b/source4/lib/ldb/ldb_tdb/ldb_match.c
index 6f55496042..52e9f5afc7 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_match.c
+++ b/source4/lib/ldb/ldb_tdb/ldb_match.c
@@ -137,10 +137,10 @@ static int ldb_val_equal_wildcard(struct ldb_context *ldb,
return 1 for a match, 0 for a mis-match
*/
-static int ldb_val_equal_objectclass(struct ldb_context *ldb,
+static int ldb_val_equal_objectclass(struct ldb_module *module,
const struct ldb_val *v1, const struct ldb_val *v2)
{
- struct ltdb_private *ltdb = ldb->private_data;
+ struct ltdb_private *ltdb = module->private_data;
unsigned int i;
if (ldb_val_equal_case_insensitive(v1, v2) == 1) {
@@ -152,7 +152,7 @@ static int ldb_val_equal_objectclass(struct ldb_context *ldb,
if (ldb_attr_cmp(el->name, v2->data) == 0) {
unsigned int j;
for (j=0;j<el->num_values;j++) {
- if (ldb_val_equal_objectclass(ldb, v1, &el->values[j])) {
+ if (ldb_val_equal_objectclass(module, v1, &el->values[j])) {
return 1;
}
}
@@ -171,14 +171,15 @@ static int ldb_val_equal_objectclass(struct ldb_context *ldb,
return 1 for a match, 0 for a mis-match
*/
-int ldb_val_equal(struct ldb_context *ldb,
+int ldb_val_equal(struct ldb_module *module,
const char *attr_name,
const struct ldb_val *v1, const struct ldb_val *v2)
{
- int flags = ltdb_attribute_flags(ldb, attr_name);
+ struct ldb_context *ldb = module->ldb;
+ int flags = ltdb_attribute_flags(module, attr_name);
if (flags & LTDB_FLAG_OBJECTCLASS) {
- return ldb_val_equal_objectclass(ldb, v1, v2);
+ return ldb_val_equal_objectclass(module, v1, v2);
}
if (flags & LTDB_FLAG_INTEGER) {
@@ -254,7 +255,7 @@ static int scope_match(const char *dn, const char *base, enum ldb_scope scope)
/*
match a leaf node
*/
-static int match_leaf(struct ldb_context *ldb,
+static int match_leaf(struct ldb_module *module,
struct ldb_message *msg,
struct ldb_parse_tree *tree,
const char *base,
@@ -279,7 +280,7 @@ static int match_leaf(struct ldb_context *ldb,
return 1;
}
for (j=0;j<msg->elements[i].num_values;j++) {
- if (ldb_val_equal(ldb, msg->elements[i].name,
+ if (ldb_val_equal(module, msg->elements[i].name,
&msg->elements[i].values[j],
&tree->u.simple.value)) {
return 1;
@@ -299,7 +300,7 @@ static int match_leaf(struct ldb_context *ldb,
this is a recursive function, and does short-circuit evaluation
*/
-int ldb_message_match(struct ldb_context *ldb,
+int ldb_message_match(struct ldb_module *module,
struct ldb_message *msg,
struct ldb_parse_tree *tree,
const char *base,
@@ -313,11 +314,11 @@ int ldb_message_match(struct ldb_context *ldb,
break;
case LDB_OP_NOT:
- return ! ldb_message_match(ldb, msg, tree->u.not.child, base, scope);
+ return ! ldb_message_match(module, msg, tree->u.not.child, base, scope);
case LDB_OP_AND:
for (i=0;i<tree->u.list.num_elements;i++) {
- v = ldb_message_match(ldb, msg, tree->u.list.elements[i],
+ v = ldb_message_match(module, msg, tree->u.list.elements[i],
base, scope);
if (!v) return 0;
}
@@ -325,12 +326,12 @@ int ldb_message_match(struct ldb_context *ldb,
case LDB_OP_OR:
for (i=0;i<tree->u.list.num_elements;i++) {
- v = ldb_message_match(ldb, msg, tree->u.list.elements[i],
+ v = ldb_message_match(module, msg, tree->u.list.elements[i],
base, scope);
if (v) return 1;
}
return 0;
}
- return match_leaf(ldb, msg, tree, base, scope);
+ return match_leaf(module, msg, tree, base, scope);
}
diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c
index 18d51d1aa4..cb93483881 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_search.c
+++ b/source4/lib/ldb/ldb_tdb/ldb_search.c
@@ -131,12 +131,14 @@ static int msg_add_element(struct ldb_context *ldb,
/*
add all elements from one message into another
*/
-static int msg_add_all_elements(struct ldb_context *ldb, struct ldb_message *ret,
+static int msg_add_all_elements(struct ldb_module *module, struct ldb_message *ret,
const struct ldb_message *msg)
{
+ struct ldb_context *ldb = module->ldb;
unsigned int i;
+
for (i=0;i<msg->num_elements;i++) {
- int flags = ltdb_attribute_flags(ldb, msg->elements[i].name);
+ int flags = ltdb_attribute_flags(module, msg->elements[i].name);
if ((msg->dn[0] != '@') && (flags & LTDB_FLAG_HIDDEN)) {
continue;
}
@@ -152,10 +154,11 @@ static int msg_add_all_elements(struct ldb_context *ldb, struct ldb_message *ret
/*
pull the specified list of attributes from a message
*/
-static struct ldb_message *ltdb_pull_attrs(struct ldb_context *ldb,
+static struct ldb_message *ltdb_pull_attrs(struct ldb_module *module,
const struct ldb_message *msg,
const char * const *attrs)
{
+ struct ldb_context *ldb = module->ldb;
struct ldb_message *ret;
int i;
@@ -175,7 +178,7 @@ static struct ldb_message *ltdb_pull_attrs(struct ldb_context *ldb,
ret->private_data = NULL;
if (!attrs) {
- if (msg_add_all_elements(ldb, ret, msg) != 0) {
+ if (msg_add_all_elements(module, ret, msg) != 0) {
msg_free_all_parts(ldb, ret);
return NULL;
}
@@ -186,7 +189,7 @@ static struct ldb_message *ltdb_pull_attrs(struct ldb_context *ldb,
struct ldb_message_element *el;
if (strcmp(attrs[i], "*") == 0) {
- if (msg_add_all_elements(ldb, ret, msg) != 0) {
+ if (msg_add_all_elements(module, ret, msg) != 0) {
msg_free_all_parts(ldb, ret);
return NULL;
}
@@ -237,7 +240,7 @@ static struct ldb_message *ltdb_pull_attrs(struct ldb_context *ldb,
see if a ldb_val is a wildcard
return 1 if yes, 0 if no
*/
-int ltdb_has_wildcard(struct ldb_context *ldb, const char *attr_name,
+int ltdb_has_wildcard(struct ldb_module *module, const char *attr_name,
const struct ldb_val *val)
{
int flags;
@@ -251,7 +254,7 @@ int ltdb_has_wildcard(struct ldb_context *ldb, const char *attr_name,
return 0;
}
- flags = ltdb_attribute_flags(ldb, attr_name);
+ flags = ltdb_attribute_flags(module, attr_name);
if (flags & LTDB_FLAG_WILDCARD) {
return 1;
}
@@ -263,8 +266,9 @@ int ltdb_has_wildcard(struct ldb_context *ldb, const char *attr_name,
/*
free the results of a ltdb_search_dn1 search
*/
-void ltdb_search_dn1_free(struct ldb_context *ldb, struct ldb_message *msg)
+void ltdb_search_dn1_free(struct ldb_module *module, struct ldb_message *msg)
{
+ struct ldb_context *ldb = module->ldb;
unsigned int i;
ldb_free(ldb, msg->private_data);
for (i=0;i<msg->num_elements;i++) {
@@ -281,16 +285,17 @@ void ltdb_search_dn1_free(struct ldb_context *ldb, struct ldb_message *msg)
return 1 on success, 0 on record-not-found and -1 on error
*/
-int ltdb_search_dn1(struct ldb_context *ldb, const char *dn, struct ldb_message *msg)
+int ltdb_search_dn1(struct ldb_module *module, const char *dn, struct ldb_message *msg)
{
- struct ltdb_private *ltdb = ldb->private_data;
+ struct ldb_context *ldb = module->ldb;
+ struct ltdb_private *ltdb = module->private_data;
int ret;
TDB_DATA tdb_key, tdb_data, tdb_data2;
memset(msg, 0, sizeof(*msg));
/* form the key */
- tdb_key = ltdb_key(ldb, dn);
+ tdb_key = ltdb_key(module, dn);
if (!tdb_key.dptr) {
return -1;
}
@@ -335,20 +340,21 @@ int ltdb_search_dn1(struct ldb_context *ldb, const char *dn, struct ldb_message
/*
search the database for a single simple dn
*/
-int ltdb_search_dn(struct ldb_context *ldb, char *dn,
+int ltdb_search_dn(struct ldb_module *module, char *dn,
const char * const attrs[], struct ldb_message ***res)
{
+ struct ldb_context *ldb = module->ldb;
int ret;
struct ldb_message msg, *msg2;
- ret = ltdb_search_dn1(ldb, dn, &msg);
+ ret = ltdb_search_dn1(module, dn, &msg);
if (ret != 1) {
return ret;
}
- msg2 = ltdb_pull_attrs(ldb, &msg, attrs);
+ msg2 = ltdb_pull_attrs(module, &msg, attrs);
- ltdb_search_dn1_free(ldb, &msg);
+ ltdb_search_dn1_free(module, &msg);
if (!msg2) {
return -1;
@@ -371,16 +377,17 @@ int ltdb_search_dn(struct ldb_context *ldb, char *dn,
add a set of attributes from a record to a set of results
return 0 on success, -1 on failure
*/
-int ltdb_add_attr_results(struct ldb_context *ldb, struct ldb_message *msg,
+int ltdb_add_attr_results(struct ldb_module *module, struct ldb_message *msg,
const char * const attrs[],
unsigned int *count,
struct ldb_message ***res)
{
+ struct ldb_context *ldb = module->ldb;
struct ldb_message *msg2;
struct ldb_message **res2;
/* pull the attributes that the user wants */
- msg2 = ltdb_pull_attrs(ldb, msg, attrs);
+ msg2 = ltdb_pull_attrs(module, msg, attrs);
if (!msg2) {
return -1;
}
@@ -406,7 +413,7 @@ int ltdb_add_attr_results(struct ldb_context *ldb, struct ldb_message *msg,
internal search state during a full db search
*/
struct ltdb_search_info {
- struct ldb_context *ldb;
+ struct ldb_module *module;
struct ldb_parse_tree *tree;
const char *base;
enum ldb_scope scope;
@@ -432,7 +439,7 @@ static int search_func(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, voi
}
/* unpack the record */
- ret = ltdb_unpack_data(sinfo->ldb, &data, &msg);
+ ret = ltdb_unpack_data(sinfo->module->ldb, &data, &msg);
if (ret == -1) {
sinfo->failures++;
return 0;
@@ -443,19 +450,19 @@ static int search_func(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, voi
}
/* see if it matches the given expression */
- if (!ldb_message_match(sinfo->ldb, &msg, sinfo->tree,
+ if (!ldb_message_match(sinfo->module, &msg, sinfo->tree,
sinfo->base, sinfo->scope)) {
- ltdb_unpack_data_free(sinfo->ldb, &msg);
+ ltdb_unpack_data_free(sinfo->module->ldb, &msg);
return 0;
}
- ret = ltdb_add_attr_results(sinfo->ldb, &msg, sinfo->attrs, &sinfo->count, &sinfo->msgs);
+ ret = ltdb_add_attr_results(sinfo->module, &msg, sinfo->attrs, &sinfo->count, &sinfo->msgs);
if (ret == -1) {
sinfo->failures++;
}
- ltdb_unpack_data_free(sinfo->ldb, &msg);
+ ltdb_unpack_data_free(sinfo->module->ldb, &msg);
return ret;
}
@@ -464,9 +471,10 @@ static int search_func(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, voi
/*
free a set of search results
*/
-int ltdb_search_free(struct ldb_context *ldb, struct ldb_message **msgs)
+int ltdb_search_free(struct ldb_module *module, struct ldb_message **msgs)
{
- struct ltdb_private *ltdb = ldb->private_data;
+ struct ldb_context *ldb = module->ldb;
+ struct ltdb_private *ltdb = module->private_data;
int i;
ltdb->last_err_string = NULL;
@@ -486,18 +494,18 @@ int ltdb_search_free(struct ldb_context *ldb, struct ldb_message **msgs)
search the database with a LDAP-like expression.
this is the "full search" non-indexed variant
*/
-static int ltdb_search_full(struct ldb_context *ldb,
+static int ltdb_search_full(struct ldb_module *module,
const char *base,
enum ldb_scope scope,
struct ldb_parse_tree *tree,
const char * const attrs[], struct ldb_message ***res)
{
- struct ltdb_private *ltdb = ldb->private_data;
+ struct ltdb_private *ltdb = module->private_data;
int ret;
struct ltdb_search_info sinfo;
sinfo.tree = tree;
- sinfo.ldb = ldb;
+ sinfo.module = module;
sinfo.scope = scope;
sinfo.base = base;
sinfo.attrs = attrs;
@@ -508,7 +516,7 @@ static int ltdb_search_full(struct ldb_context *ldb,
ret = tdb_traverse(ltdb->tdb, search_func, &sinfo);
if (ret == -1) {
- ltdb_search_free(ldb, sinfo.msgs);
+ ltdb_search_free(module, sinfo.msgs);
return -1;
}
@@ -521,17 +529,18 @@ static int ltdb_search_full(struct ldb_context *ldb,
search the database with a LDAP-like expression.
choses a search method
*/
-int ltdb_search(struct ldb_context *ldb, const char *base,
+int ltdb_search(struct ldb_module *module, const char *base,
enum ldb_scope scope, const char *expression,
const char * const attrs[], struct ldb_message ***res)
{
- struct ltdb_private *ltdb = ldb->private_data;
+ struct ldb_context *ldb = module->ldb;
+ struct ltdb_private *ltdb = module->private_data;
struct ldb_parse_tree *tree;
int ret;
ltdb->last_err_string = NULL;
- if (ltdb_cache_load(ldb) != 0) {
+ if (ltdb_cache_load(module) != 0) {
return -1;
}
@@ -546,13 +555,13 @@ int ltdb_search(struct ldb_context *ldb, const char *base,
if (tree->operation == LDB_OP_SIMPLE &&
ldb_attr_cmp(tree->u.simple.attr, "dn") == 0 &&
- !ltdb_has_wildcard(ldb, tree->u.simple.attr, &tree->u.simple.value)) {
+ !ltdb_has_wildcard(module, tree->u.simple.attr, &tree->u.simple.value)) {
/* yay! its a nice simple one */
- ret = ltdb_search_dn(ldb, tree->u.simple.value.data, attrs, res);
+ ret = ltdb_search_dn(module, tree->u.simple.value.data, attrs, res);
} else {
- ret = ltdb_search_indexed(ldb, base, scope, tree, attrs, res);
+ ret = ltdb_search_indexed(module, base, scope, tree, attrs, res);
if (ret == -1) {
- ret = ltdb_search_full(ldb, base, scope, tree, attrs, res);
+ ret = ltdb_search_full(module, base, scope, tree, attrs, res);
}
}
diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c
index 3d136ea014..a2aa5a7aca 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c
+++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c
@@ -45,8 +45,9 @@
note that the key for a record can depend on whether the
dn refers to a case sensitive index record or not
*/
-struct TDB_DATA ltdb_key(struct ldb_context *ldb, const char *dn)
+struct TDB_DATA ltdb_key(struct ldb_module *module, const char *dn)
{
+ struct ldb_context *ldb = module->ldb;
TDB_DATA key;
char *key_str = NULL;
char *dn_folded = NULL;
@@ -74,7 +75,7 @@ struct TDB_DATA ltdb_key(struct ldb_context *ldb, const char *dn)
if (!attr_name) {
goto failed;
}
- flags = ltdb_attribute_flags(ldb, attr_name);
+ flags = ltdb_attribute_flags(module, attr_name);
if (flags & LTDB_FLAG_CASE_INSENSITIVE) {
dn_folded = ldb_casefold(ldb, dn);
@@ -119,13 +120,14 @@ failed:
/*
lock the database for write - currently a single lock is used
*/
-static int ltdb_lock(struct ldb_context *ldb)
+static int ltdb_lock(struct ldb_module *module)
{
- struct ltdb_private *ltdb = ldb->private_data;
+ struct ldb_context *ldb = module->ldb;
+ struct ltdb_private *ltdb = module->private_data;
TDB_DATA key;
int ret;
- key = ltdb_key(ldb, "LDBLOCK");
+ key = ltdb_key(module, "LDBLOCK");
if (!key.dptr) {
return -1;
}
@@ -140,12 +142,13 @@ static int ltdb_lock(struct ldb_context *ldb)
/*
unlock the database after a ltdb_lock()
*/
-static void ltdb_unlock(struct ldb_context *ldb)
+static void ltdb_unlock(struct ldb_module *module)
{
- struct ltdb_private *ltdb = ldb->private_data;
+ struct ldb_context *ldb = module->ldb;
+ struct ltdb_private *ltdb = module->private_data;
TDB_DATA key;
- key = ltdb_key(ldb, "LDBLOCK");
+ key = ltdb_key(module, "LDBLOCK");
if (!key.dptr) {
return;
}
@@ -160,18 +163,18 @@ static void ltdb_unlock(struct ldb_context *ldb)
we've made a modification to a dn - possibly reindex and
update sequence number
*/
-static int ltdb_modified(struct ldb_context *ldb, const char *dn)
+static int ltdb_modified(struct ldb_module *module, const char *dn)
{
int ret = 0;
if (strcmp(dn, LTDB_INDEXLIST) == 0 ||
strcmp(dn, LTDB_ATTRIBUTES) == 0) {
- ret = ltdb_reindex(ldb);
+ ret = ltdb_reindex(module);
}
if (ret == 0 &&
strcmp(dn, LTDB_BASEINFO) != 0) {
- ret = ltdb_increase_sequence_number(ldb);
+ ret = ltdb_increase_sequence_number(module);
}
return ret;
@@ -180,13 +183,14 @@ static int ltdb_modified(struct ldb_context *ldb, const char *dn)
/*
store a record into the db
*/
-int ltdb_store(struct ldb_context *ldb, const struct ldb_message *msg, int flgs)
+int ltdb_store(struct ldb_module *module, const struct ldb_message *msg, int flgs)
{
- struct ltdb_private *ltdb = ldb->private_data;
+ struct ldb_context *ldb = module->ldb;
+ struct ltdb_private *ltdb = module->private_data;
TDB_DATA tdb_key, tdb_data;
int ret;
- tdb_key = ltdb_key(ldb, msg->dn);
+ tdb_key = ltdb_key(module, msg->dn);
if (!tdb_key.dptr) {
return -1;
}
@@ -202,7 +206,7 @@ int ltdb_store(struct ldb_context *ldb, const struct ldb_message *msg, int flgs)
goto done;
}
- ret = ltdb_index_add(ldb, msg);
+ ret = ltdb_index_add(module, msg);
if (ret == -1) {
tdb_delete(ltdb->tdb, tdb_key);
}
@@ -218,29 +222,29 @@ done:
/*
add a record to the database
*/
-static int ltdb_add(struct ldb_context *ldb, const struct ldb_message *msg)
+static int ltdb_add(struct ldb_module *module, const struct ldb_message *msg)
{
- struct ltdb_private *ltdb = ldb->private_data;
+ struct ltdb_private *ltdb = module->private_data;
int ret;
ltdb->last_err_string = NULL;
- if (ltdb_lock(ldb) != 0) {
+ if (ltdb_lock(module) != 0) {
return -1;
}
- if (ltdb_cache_load(ldb) != 0) {
- ltdb_unlock(ldb);
+ if (ltdb_cache_load(module) != 0) {
+ ltdb_unlock(module);
return -1;
}
- ret = ltdb_store(ldb, msg, TDB_INSERT);
+ ret = ltdb_store(module, msg, TDB_INSERT);
if (ret == 0) {
- ltdb_modified(ldb, msg->dn);
+ ltdb_modified(module, msg->dn);
}
- ltdb_unlock(ldb);
+ ltdb_unlock(module);
return ret;
}
@@ -249,13 +253,14 @@ static int ltdb_add(struct ldb_context *ldb, const struct ldb_message *msg)
delete a record from the database, not updating indexes (used for deleting
index records)
*/
-int ltdb_delete_noindex(struct ldb_context *ldb, const char *dn)
+int ltdb_delete_noindex(struct ldb_module *module, const char *dn)
{
- struct ltdb_private *ltdb = ldb->private_data;
+ struct ldb_context *ldb = module->ldb;
+ struct ltdb_private *ltdb = module->private_data;
TDB_DATA tdb_key;
int ret;
- tdb_key = ltdb_key(ldb, dn);
+ tdb_key = ltdb_key(module, dn);
if (!tdb_key.dptr) {
return -1;
}
@@ -269,51 +274,51 @@ int ltdb_delete_noindex(struct ldb_context *ldb, const char *dn)
/*
delete a record from the database
*/
-static int ltdb_delete(struct ldb_context *ldb, const char *dn)
+static int ltdb_delete(struct ldb_module *module, const char *dn)
{
- struct ltdb_private *ltdb = ldb->private_data;
+ struct ltdb_private *ltdb = module->private_data;
int ret;
struct ldb_message msg;
ltdb->last_err_string = NULL;
- if (ltdb_lock(ldb) != 0) {
+ if (ltdb_lock(module) != 0) {
return -1;
}
- if (ltdb_cache_load(ldb) != 0) {
- ltdb_unlock(ldb);
+ if (ltdb_cache_load(module) != 0) {
+ ltdb_unlock(module);
return -1;
}
/* in case any attribute of the message was indexed, we need
to fetch the old record */
- ret = ltdb_search_dn1(ldb, dn, &msg);
+ ret = ltdb_search_dn1(module, dn, &msg);
if (ret != 1) {
/* not finding the old record is an error */
goto failed;
}
- ret = ltdb_delete_noindex(ldb, dn);
+ ret = ltdb_delete_noindex(module, dn);
if (ret == -1) {
- ltdb_search_dn1_free(ldb, &msg);
+ ltdb_search_dn1_free(module, &msg);
goto failed;
}
/* remove any indexed attributes */
- ret = ltdb_index_del(ldb, &msg);
+ ret = ltdb_index_del(module, &msg);
- ltdb_search_dn1_free(ldb, &msg);
+ ltdb_search_dn1_free(module, &msg);
if (ret == 0) {
- ltdb_modified(ldb, dn);
+ ltdb_modified(module, dn);
}
- ltdb_unlock(ldb);
+ ltdb_unlock(module);
return ret;
failed:
- ltdb_unlock(ldb);
+ ltdb_unlock(module);
return -1;
}
@@ -416,11 +421,12 @@ static int msg_delete_attribute(struct ldb_context *ldb,
return 0 on success, -1 on failure
*/
-static int msg_delete_element(struct ldb_context *ldb,
+static int msg_delete_element(struct ldb_module *module,
struct ldb_message *msg,
const char *name,
const struct ldb_val *val)
{
+ struct ldb_context *ldb = module->ldb;
unsigned int i;
int found;
struct ldb_message_element *el;
@@ -433,7 +439,7 @@ static int msg_delete_element(struct ldb_context *ldb,
el = &msg->elements[found];
for (i=0;i<el->num_values;i++) {
- if (ldb_val_equal(ldb, msg->elements[i].name, &el->values[i], val)) {
+ if (ldb_val_equal(module, msg->elements[i].name, &el->values[i], val)) {
if (i<el->num_values-1) {
memmove(&el->values[i], &el->values[i+1],
sizeof(el->values[i])*(el->num_values-(i+1)));
@@ -457,15 +463,16 @@ static int msg_delete_element(struct ldb_context *ldb,
get away with it, but if we ever have really large attribute lists
then we'll need to look at this again
*/
-int ltdb_modify_internal(struct ldb_context *ldb, const struct ldb_message *msg)
+int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *msg)
{
- struct ltdb_private *ltdb = ldb->private_data;
+ struct ldb_context *ldb = module->ldb;
+ struct ltdb_private *ltdb = module->private_data;
TDB_DATA tdb_key, tdb_data;
struct ldb_message msg2;
unsigned i, j;
int ret;
- tdb_key = ltdb_key(ldb, msg->dn);
+ tdb_key = ltdb_key(module, msg->dn);
if (!tdb_key.dptr) {
return -1;
}
@@ -527,7 +534,7 @@ int ltdb_modify_internal(struct ldb_context *ldb, const struct ldb_message *msg)
break;
}
for (j=0;j<msg->elements[i].num_values;j++) {
- if (msg_delete_element(ldb,
+ if (msg_delete_element(module,
&msg2,
msg->elements[i].name,
&msg->elements[i].values[j]) != 0) {
@@ -540,7 +547,7 @@ int ltdb_modify_internal(struct ldb_context *ldb, const struct ldb_message *msg)
}
/* we've made all the mods - save the modified record back into the database */
- ret = ltdb_store(ldb, &msg2, TDB_MODIFY);
+ ret = ltdb_store(module, &msg2, TDB_MODIFY);
ldb_free(ldb, tdb_key.dptr);
free(tdb_data.dptr);
@@ -557,29 +564,29 @@ failed:
/*
modify a record
*/
-static int ltdb_modify(struct ldb_context *ldb, const struct ldb_message *msg)
+static int ltdb_modify(struct ldb_module *module, const struct ldb_message *msg)
{
- struct ltdb_private *ltdb = ldb->private_data;
+ struct ltdb_private *ltdb = module->private_data;
int ret;
ltdb->last_err_string = NULL;
- if (ltdb_lock(ldb) != 0) {
+ if (ltdb_lock(module) != 0) {
return -1;
}
- if (ltdb_cache_load(ldb) != 0) {
- ltdb_unlock(ldb);
+ if (ltdb_cache_load(module) != 0) {
+ ltdb_unlock(module);
return -1;
}
- ret = ltdb_modify_internal(ldb, msg);
+ ret = ltdb_modify_internal(module, msg);
if (ret == 0) {
- ltdb_modified(ldb, msg->dn);
+ ltdb_modified(module, msg->dn);
}
- ltdb_unlock(ldb);
+ ltdb_unlock(module);
return ret;
}
@@ -587,22 +594,23 @@ static int ltdb_modify(struct ldb_context *ldb, const struct ldb_message *msg)
/*
rename a record
*/
-static int ltdb_rename(struct ldb_context *ldb, const char *olddn, const char *newdn)
+static int ltdb_rename(struct ldb_module *module, const char *olddn, const char *newdn)
{
- struct ltdb_private *ltdb = ldb->private_data;
+ struct ldb_context *ldb = module->ldb;
+ struct ltdb_private *ltdb = module->private_data;
int ret;
struct ldb_message msg;
const char *error_str;
ltdb->last_err_string = NULL;
- if (ltdb_lock(ldb) != 0) {
+ if (ltdb_lock(module) != 0) {
return -1;
}
/* in case any attribute of the message was indexed, we need
to fetch the old record */
- ret = ltdb_search_dn1(ldb, olddn, &msg);
+ ret = ltdb_search_dn1(module, olddn, &msg);
if (ret != 1) {
/* not finding the old record is an error */
goto failed;
@@ -610,46 +618,47 @@ static int ltdb_rename(struct ldb_context *ldb, const char *olddn, const char *n
msg.dn = ldb_strdup(ldb,newdn);
if (!msg.dn) {
- ltdb_search_dn1_free(ldb, &msg);
+ ltdb_search_dn1_free(module, &msg);
goto failed;
}
- ret = ltdb_add(ldb, &msg);
+ ret = ltdb_add(module, &msg);
if (ret == -1) {
ldb_free(ldb, msg.dn);
- ltdb_search_dn1_free(ldb, &msg);
+ ltdb_search_dn1_free(module, &msg);
goto failed;
}
ldb_free(ldb, msg.dn);
- ltdb_search_dn1_free(ldb, &msg);
+ ltdb_search_dn1_free(module, &msg);
- ret = ltdb_delete(ldb, olddn);
+ ret = ltdb_delete(module, olddn);
error_str = ltdb->last_err_string;
if (ret == -1) {
- ltdb_delete(ldb, newdn);
+ ltdb_delete(module, newdn);
}
ltdb->last_err_string = error_str;
- ltdb_unlock(ldb);
+ ltdb_unlock(module);
return ret;
failed:
- ltdb_unlock(ldb);
+ ltdb_unlock(module);
return -1;
}
/*
close database
*/
-static int ltdb_close(struct ldb_context *ldb)
+static int ltdb_close(struct ldb_module *module)
{
- struct ltdb_private *ltdb = ldb->private_data;
+ struct ldb_context *ldb = module->ldb;
+ struct ltdb_private *ltdb = module->private_data;
int ret;
ltdb->last_err_string = NULL;
- ltdb_cache_free(ldb);
+ ltdb_cache_free(module);
ldb_set_alloc(ldb, NULL, NULL);
ret = tdb_close(ltdb->tdb);
@@ -662,9 +671,9 @@ static int ltdb_close(struct ldb_context *ldb)
/*
return extended error information
*/
-static const char *ltdb_errstring(struct ldb_context *ldb)
+static const char *ltdb_errstring(struct ldb_module *module)
{
- struct ltdb_private *ltdb = ldb->private_data;
+ struct ltdb_private *ltdb = module->private_data;
if (ltdb->last_err_string) {
return ltdb->last_err_string;
}
@@ -672,7 +681,8 @@ static const char *ltdb_errstring(struct ldb_context *ldb)
}
-static const struct ldb_backend_ops ltdb_ops = {
+static const struct ldb_module_ops ltdb_ops = {
+ "tdb",
ltdb_close,
ltdb_search,
ltdb_search_free,
@@ -743,8 +753,17 @@ struct ldb_context *ltdb_connect(const char *url,
memset(&ltdb->cache, 0, sizeof(ltdb->cache));
- ldb->private_data = ltdb;
- ldb->ops = &ltdb_ops;
+ ldb->modules = ldb_malloc_p(ldb, struct ldb_module);
+ if (!ldb->modules) {
+ tdb_close(tdb);
+ free(ldb);
+ errno = ENOMEM;
+ return NULL;
+ }
+ ldb->modules->ldb = ldb;
+ ldb->modules->prev = ldb->modules->next = NULL;
+ ldb->modules->private_data = ltdb;
+ ldb->modules->ops = &ltdb_ops;
return ldb;
}