summaryrefslogtreecommitdiff
path: root/source3/lib/ldb
diff options
context:
space:
mode:
authorVolker Lendecke <vlendec@samba.org>2006-12-06 14:40:47 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:16:22 -0500
commit4a1efb1abe1882173d25dbd6c4ebdbf53521b42c (patch)
treeb67da2f060fafdb27ab7bd8206c7b51ebe2f5969 /source3/lib/ldb
parentc0d74d11bc205b4fef80f8faa81df2dee5613368 (diff)
downloadsamba-4a1efb1abe1882173d25dbd6c4ebdbf53521b42c.tar.gz
samba-4a1efb1abe1882173d25dbd6c4ebdbf53521b42c.tar.bz2
samba-4a1efb1abe1882173d25dbd6c4ebdbf53521b42c.zip
r20054: Revert my changes, Simo promised to work on it :-)
(This used to be commit 4b5cf0c9cffe9903c86ac7e8b41c303fdbde5bac)
Diffstat (limited to 'source3/lib/ldb')
-rw-r--r--source3/lib/ldb/ldb_tdb/ldb_index.c109
1 files changed, 42 insertions, 67 deletions
diff --git a/source3/lib/ldb/ldb_tdb/ldb_index.c b/source3/lib/ldb/ldb_tdb/ldb_index.c
index e84dac3f90..2c88d7e19d 100644
--- a/source3/lib/ldb/ldb_tdb/ldb_index.c
+++ b/source3/lib/ldb/ldb_tdb/ldb_index.c
@@ -41,8 +41,7 @@
find an element in a list, using the given comparison function and
assuming that the list is already sorted using comp_fn
- return -1 if not found, or the index of the first occurance of needle if
- found
+ return -1 if not found, or the index of the first occurance of needle if found
*/
static int ldb_list_find(const void *needle,
const void *base, size_t nmemb, size_t size,
@@ -129,8 +128,7 @@ static struct ldb_dn *ldb_dn_key(struct ldb_context *ldb,
if (ldb_should_b64_encode(&v)) {
char *vstr = ldb_base64_encode(ldb, (char *)v.data, v.length);
if (!vstr) return NULL;
- dn = talloc_asprintf(ldb, "%s:%s::%s", LTDB_INDEX, attr_folded,
- vstr);
+ dn = talloc_asprintf(ldb, "%s:%s::%s", LTDB_INDEX, attr_folded, vstr);
talloc_free(vstr);
if (v.data != value->data) {
talloc_free(v.data);
@@ -140,8 +138,8 @@ static struct ldb_dn *ldb_dn_key(struct ldb_context *ldb,
goto done;
}
- dn = talloc_asprintf(ldb, "%s:%s:%.*s", LTDB_INDEX, attr_folded,
- (int)v.length, (char *)v.data);
+ dn = talloc_asprintf(ldb, "%s:%s:%.*s",
+ LTDB_INDEX, attr_folded, (int)v.length, (char *)v.data);
if (v.data != value->data) {
talloc_free(v.data);
@@ -166,8 +164,7 @@ static int ldb_msg_find_idx(const struct ldb_message *msg, const char *attr,
const struct ldb_message_element *el =
&msg->elements[i];
for (j=0;j<el->num_values;j++) {
- if (ldb_attr_cmp((char *)el->values[j].data,
- attr) == 0) {
+ if (ldb_attr_cmp((char *)el->values[j].data, attr) == 0) {
if (v_idx) {
*v_idx = j;
}
@@ -204,8 +201,7 @@ static int ltdb_index_dn_simple(struct ldb_module *module,
/* if the attribute isn't in the list of indexed attributes then
this node needs a full search */
- if (ldb_msg_find_idx(index_list, tree->u.equality.attr, NULL,
- LTDB_IDXATTR) == -1) {
+ if (ldb_msg_find_idx(index_list, tree->u.equality.attr, NULL, LTDB_IDXATTR) == -1) {
return -1;
}
@@ -241,8 +237,8 @@ static int ltdb_index_dn_simple(struct ldb_module *module,
}
for (j=0;j<el->num_values;j++) {
- list->dn[list->count] = talloc_strdup(
- list->dn, (char *)el->values[j].data);
+ list->dn[list->count] =
+ talloc_strdup(list->dn, (char *)el->values[j].data);
if (!list->dn[list->count]) {
talloc_free(msg);
return -1;
@@ -254,16 +250,14 @@ static int ltdb_index_dn_simple(struct ldb_module *module,
talloc_free(msg);
if (list->count > 1) {
- qsort(list->dn, list->count, sizeof(char *),
- (comparison_fn_t) list_cmp);
+ qsort(list->dn, list->count, sizeof(char *), (comparison_fn_t) list_cmp);
}
return 1;
}
-static int list_union(struct ldb_context *, struct dn_list *,
- const struct dn_list *);
+static int list_union(struct ldb_context *, struct dn_list *, const struct dn_list *);
/*
return a list of dn's that might match a simple indexed search on
@@ -296,6 +290,9 @@ static int ltdb_index_dn_objectclass(struct ldb_module *module,
struct dn_list *list2;
tree2.operation = LDB_OP_EQUALITY;
tree2.u.equality.attr = LTDB_OBJECTCLASS;
+ if (!tree2.u.equality.attr) {
+ return -1;
+ }
tree2.u.equality.value.data =
(uint8_t *)talloc_strdup(list, subclasses[i]);
if (tree2.u.equality.value.data == NULL) {
@@ -332,8 +329,7 @@ static int ltdb_index_dn_leaf(struct ldb_module *module,
struct dn_list *list)
{
if (ldb_attr_cmp(tree->u.equality.attr, LTDB_OBJECTCLASS) == 0) {
- return ltdb_index_dn_objectclass(module, tree, index_list,
- list);
+ return ltdb_index_dn_objectclass(module, tree, index_list, list);
}
if (ldb_attr_dn(tree->u.equality.attr) == 0) {
list->dn = talloc_array(list, char *, 1);
@@ -341,8 +337,7 @@ static int ltdb_index_dn_leaf(struct ldb_module *module,
ldb_oom(module->ldb);
return -1;
}
- list->dn[0] = talloc_strdup(
- list, (char *)tree->u.equality.value.data);
+ list->dn[0] = talloc_strdup(list, (char *)tree->u.equality.value.data);
if (list->dn[0] == NULL) {
ldb_oom(module->ldb);
return -1;
@@ -385,8 +380,7 @@ static int list_intersect(struct ldb_context *ldb,
for (i=0;i<list->count;i++) {
if (ldb_list_find(list->dn[i], list2->dn, list2->count,
sizeof(char *), (comparison_fn_t)strcmp) != -1) {
- list3->dn[list3->count] = talloc_move(
- list3->dn, &list->dn[i]);
+ list3->dn[list3->count] = talloc_move(list3->dn, &list->dn[i]);
list3->count++;
} else {
talloc_free(list->dn[i]);
@@ -428,8 +422,7 @@ static int list_union(struct ldb_context *ldb,
for (i=0;i<list2->count;i++) {
if (ldb_list_find(list2->dn[i], list->dn, count,
sizeof(char *), (comparison_fn_t)strcmp) == -1) {
- list->dn[list->count] = talloc_strdup(
- list->dn, list2->dn[i]);
+ list->dn[list->count] = talloc_strdup(list->dn, list2->dn[i]);
if (!list->dn[list->count]) {
return -1;
}
@@ -438,8 +431,7 @@ static int list_union(struct ldb_context *ldb,
}
if (list->count != count) {
- qsort(list->dn, list->count, sizeof(char *),
- (comparison_fn_t)list_cmp);
+ qsort(list->dn, list->count, sizeof(char *), (comparison_fn_t)list_cmp);
}
return 0;
@@ -476,8 +468,7 @@ static int ltdb_index_dn_or(struct ldb_module *module,
return -1;
}
- v = ltdb_index_dn(module, 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 */
@@ -561,8 +552,7 @@ static int ltdb_index_dn_and(struct ldb_module *module,
return -1;
}
- v = ltdb_index_dn(module, 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 */
@@ -648,8 +638,7 @@ static int ltdb_index_dn(struct ldb_module *module,
static int ltdb_index_filter(const struct dn_list *dn_list,
struct ldb_handle *handle)
{
- struct ltdb_context *ac = talloc_get_type(handle->private_data,
- struct ltdb_context);
+ struct ltdb_context *ac = talloc_get_type(handle->private_data, struct ltdb_context);
struct ldb_reply *ares = NULL;
unsigned int i;
@@ -697,8 +686,7 @@ static int ltdb_index_filter(const struct dn_list *dn_list,
return LDB_ERR_OPERATIONS_ERROR;
}
- if (!ldb_match_msg(ac->module->ldb, ares->message, ac->tree,
- ac->base, ac->scope)) {
+ if (!ldb_match_msg(ac->module->ldb, ares->message, ac->tree, ac->base, ac->scope)) {
talloc_free(ares);
continue;
}
@@ -715,8 +703,7 @@ static int ltdb_index_filter(const struct dn_list *dn_list,
ares->type = LDB_REPLY_ENTRY;
handle->state = LDB_ASYNC_PENDING;
- handle->status = ac->callback(ac->module->ldb, ac->context,
- ares);
+ handle->status = ac->callback(ac->module->ldb, ac->context, ares);
if (handle->status != LDB_SUCCESS) {
handle->state = LDB_ASYNC_DONE;
@@ -772,8 +759,7 @@ int ltdb_search_indexed(struct ldb_handle *handle)
dn_list->count = 1;
ret = 1;
} else {
- ret = ltdb_index_dn(ac->module, ac->tree,
- ltdb->cache->indexlist, dn_list);
+ ret = ltdb_index_dn(ac->module, ac->tree, ltdb->cache->indexlist, dn_list);
}
if (ret == 1) {
@@ -801,26 +787,23 @@ static int ltdb_index_add1_new(struct ldb_context *ldb,
/* add another entry */
el2 = talloc_realloc(msg, msg->elements,
- struct ldb_message_element, msg->num_elements+1);
+ struct ldb_message_element, msg->num_elements+1);
if (!el2) {
return -1;
}
msg->elements = el2;
- msg->elements[msg->num_elements].name = talloc_strdup(msg->elements,
- LTDB_IDX);
+ msg->elements[msg->num_elements].name = talloc_strdup(msg->elements, LTDB_IDX);
if (!msg->elements[msg->num_elements].name) {
return -1;
}
msg->elements[msg->num_elements].num_values = 0;
- msg->elements[msg->num_elements].values = talloc(msg->elements,
- struct ldb_val);
+ msg->elements[msg->num_elements].values = talloc(msg->elements, struct ldb_val);
if (!msg->elements[msg->num_elements].values) {
return -1;
}
msg->elements[msg->num_elements].values[0].length = strlen(dn);
- msg->elements[msg->num_elements].values[0].data =
- discard_const_p(uint8_t, dn);
+ msg->elements[msg->num_elements].values[0].data = discard_const_p(uint8_t, dn);
msg->elements[msg->num_elements].num_values = 1;
msg->num_elements++;
@@ -843,8 +826,7 @@ static int ltdb_index_add1_add(struct ldb_context *ldb,
/* for multi-valued attributes we can end up with repeats */
for (i=0;i<msg->elements[idx].num_values;i++) {
- if (strcmp(dn,
- (char *)msg->elements[idx].values[i].data) == 0) {
+ if (strcmp(dn, (char *)msg->elements[idx].values[i].data) == 0) {
return 0;
}
}
@@ -857,10 +839,8 @@ static int ltdb_index_add1_add(struct ldb_context *ldb,
}
msg->elements[idx].values = v2;
- msg->elements[idx].values[msg->elements[idx].num_values].length =
- strlen(dn);
- msg->elements[idx].values[msg->elements[idx].num_values].data =
- discard_const_p(uint8_t, dn);
+ msg->elements[idx].values[msg->elements[idx].num_values].length = strlen(dn);
+ msg->elements[idx].values[msg->elements[idx].num_values].data = discard_const_p(uint8_t, dn);
msg->elements[idx].num_values++;
return 0;
@@ -943,8 +923,8 @@ static int ltdb_index_add0(struct ldb_module *module, const char *dn,
}
for (i = 0; i < num_el; i++) {
- ret = ldb_msg_find_idx(ltdb->cache->indexlist,
- elements[i].name, NULL, LTDB_IDXATTR);
+ ret = ldb_msg_find_idx(ltdb->cache->indexlist, elements[i].name,
+ NULL, LTDB_IDXATTR);
if (ret == -1) {
continue;
}
@@ -1017,8 +997,8 @@ int ltdb_index_del_value(struct ldb_module *module, const char *dn,
}
if (ret == 0) {
- /* it wasn't indexed. Did we have an earlier error? If we did
- then its gone now */
+ /* it wasn't indexed. Did we have an earlier error? If we did then
+ its gone now */
talloc_free(dn_key);
return 0;
}
@@ -1080,15 +1060,13 @@ int ltdb_index_del(struct ldb_module *module, const struct ldb_message *msg)
}
for (i = 0; i < msg->num_elements; i++) {
- ret = ldb_msg_find_idx(ltdb->cache->indexlist,
- msg->elements[i].name, NULL,
- LTDB_IDXATTR);
+ ret = ldb_msg_find_idx(ltdb->cache->indexlist, msg->elements[i].name,
+ NULL, LTDB_IDXATTR);
if (ret == -1) {
continue;
}
for (j = 0; j < msg->elements[i].num_values; j++) {
- ret = ltdb_index_del_value(module, dn,
- &msg->elements[i], j);
+ ret = ltdb_index_del_value(module, dn, &msg->elements[i], j);
if (ret == -1) {
talloc_free(dn);
return -1;
@@ -1104,8 +1082,7 @@ int ltdb_index_del(struct ldb_module *module, const struct ldb_message *msg)
/*
traversal function that deletes all @INDEX records
*/
-static int delete_index(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data,
- void *state)
+static int delete_index(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, void *state)
{
const char *dn = "DN=" LTDB_INDEX ":";
if (strncmp((char *)key.dptr, dn, strlen(dn)) == 0) {
@@ -1117,8 +1094,7 @@ static int delete_index(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data,
/*
traversal function that adds @INDEX records during a re index
*/
-static int re_index(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data,
- void *state)
+static int re_index(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, void *state)
{
struct ldb_module *module = (struct ldb_module *)state;
struct ldb_message *msg;
@@ -1147,9 +1123,8 @@ static int re_index(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data,
key2 = ltdb_key(module, msg->dn);
if (key2.dptr == NULL) {
/* probably a corrupt record ... darn */
- ldb_debug(module->ldb, LDB_DEBUG_ERROR,
- "Invalid DN in re_index: %s\n",
- ldb_dn_linearize(msg, msg->dn));
+ ldb_debug(module->ldb, LDB_DEBUG_ERROR, "Invalid DN in re_index: %s\n",
+ ldb_dn_linearize(msg, msg->dn));
talloc_free(msg);
return 0;
}