diff options
author | Andrew Tridgell <tridge@samba.org> | 2004-12-19 10:56:29 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:07:31 -0500 |
commit | cf4298874c01644eaedb8f80eec131ec5a220e08 (patch) | |
tree | a724565830c9bae132ffa5edd5fd287326c951ff /source4/lib | |
parent | 134769f9ad58c3431ddb2924e1231be3b16acdbe (diff) | |
download | samba-cf4298874c01644eaedb8f80eec131ec5a220e08.tar.gz samba-cf4298874c01644eaedb8f80eec131ec5a220e08.tar.bz2 samba-cf4298874c01644eaedb8f80eec131ec5a220e08.zip |
r4281: fixed an ldb indexing bug in ldb found by volker.
index entries were not always being removed on modify
(This used to be commit 9c668e7b43dc2d82d3d639b64c53e887723ccba7)
Diffstat (limited to 'source4/lib')
-rw-r--r-- | source4/lib/ldb/ldb_tdb/ldb_index.c | 6 | ||||
-rw-r--r-- | source4/lib/ldb/ldb_tdb/ldb_tdb.c | 17 | ||||
-rw-r--r-- | source4/lib/ldb/ldb_tdb/ldb_tdb.h | 4 |
3 files changed, 19 insertions, 8 deletions
diff --git a/source4/lib/ldb/ldb_tdb/ldb_index.c b/source4/lib/ldb/ldb_tdb/ldb_index.c index df0a436172..b0a1b0f89f 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_index.c +++ b/source4/lib/ldb/ldb_tdb/ldb_index.c @@ -746,8 +746,8 @@ int ltdb_index_add(struct ldb_module *module, const struct ldb_message *msg) /* delete an index entry for one message element */ -static int ltdb_index_del1(struct ldb_module *module, const char *dn, - struct ldb_message_element *el, int v_idx) +int ltdb_index_del_value(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; @@ -826,7 +826,7 @@ int ltdb_index_del(struct ldb_module *module, const struct ldb_message *msg) continue; } for (j=0;j<msg->elements[i].num_values;j++) { - ret = ltdb_index_del1(module, msg->dn, &msg->elements[i], j); + ret = ltdb_index_del_value(module, msg->dn, &msg->elements[i], j); if (ret == -1) { return -1; } diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 6623fd0052..5bceab0f13 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -403,10 +403,11 @@ static int msg_add_element(struct ldb_context *ldb, /* delete all elements having a specified attribute name */ -static int msg_delete_attribute(struct ldb_context *ldb, +static int msg_delete_attribute(struct ldb_module *module, + struct ldb_context *ldb, struct ldb_message *msg, const char *name) { - unsigned int i, count=0; + unsigned int i, j, count=0; struct ldb_message_element *el2; el2 = ldb_malloc_array_p(ldb, struct ldb_message_element, msg->num_elements); @@ -419,6 +420,9 @@ static int msg_delete_attribute(struct ldb_context *ldb, if (ldb_attr_cmp(msg->elements[i].name, name) != 0) { el2[count++] = msg->elements[i]; } else { + for (j=0;j<msg->elements[i].num_values;j++) { + ltdb_index_del_value(module, msg->dn, &msg->elements[i], j); + } ldb_free(ldb, msg->elements[i].values); } } @@ -460,7 +464,7 @@ static int msg_delete_element(struct ldb_module *module, } el->num_values--; if (el->num_values == 0) { - return msg_delete_attribute(ldb, msg, name); + return msg_delete_attribute(module, ldb, msg, name); } return 0; } @@ -532,7 +536,7 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms case LDB_FLAG_MOD_REPLACE: /* replace all elements of this attribute name with the elements listed. The attribute not existing is not an error */ - msg_delete_attribute(ldb, &msg2, msg->elements[i].name); + msg_delete_attribute(module, ldb, &msg2, msg->elements[i].name); /* add the replacement element, if not empty */ if (msg->elements[i].num_values != 0 && @@ -545,7 +549,7 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms /* we could be being asked to delete all values or just some values */ if (msg->elements[i].num_values == 0) { - if (msg_delete_attribute(ldb, &msg2, + if (msg_delete_attribute(module, ldb, &msg2, msg->elements[i].name) != 0) { ltdb->last_err_string = "No such attribute"; goto failed; @@ -560,6 +564,9 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms ltdb->last_err_string = "No such attribute"; goto failed; } + if (ltdb_index_del_value(module, msg->dn, &msg->elements[i], j) != 0) { + goto failed; + } } break; } diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.h b/source4/lib/ldb/ldb_tdb/ldb_tdb.h index 2cc25b3152..05311346f4 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.h +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.h @@ -112,3 +112,7 @@ int ltdb_message_match(struct ldb_module *module, struct ldb_parse_tree *tree, const char *base, enum ldb_scope scope); + +int ltdb_index_del_value(struct ldb_module *module, const char *dn, + struct ldb_message_element *el, int v_idx); + |