summaryrefslogtreecommitdiff
path: root/source4/dsdb
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2009-12-04 17:46:14 +1100
committerAndrew Tridgell <tridge@samba.org>2009-12-04 17:49:19 +1100
commitbe78d4a70de2aede3b9c4a644ce64c85141790cb (patch)
treef83810d8b5e495b8ad88fe22e0bd5988487a468d /source4/dsdb
parentced3eef776dd44d0f3e9219f77e2660f9e49fa92 (diff)
downloadsamba-be78d4a70de2aede3b9c4a644ce64c85141790cb.tar.gz
samba-be78d4a70de2aede3b9c4a644ce64c85141790cb.tar.bz2
samba-be78d4a70de2aede3b9c4a644ce64c85141790cb.zip
s4-ldb: fixed show_deleted module not to corrupt parse trees
The show_deleted module was using a static private ptr in the module to hold a parse tree to save on parsing. The code caused this static ptr to change with each search, which caused incorrect searches and numerous valgrind errors. This patch replaces it with a hand-built parse tree.
Diffstat (limited to 'source4/dsdb')
-rw-r--r--source4/dsdb/samdb/ldb_modules/show_deleted.c49
1 files changed, 26 insertions, 23 deletions
diff --git a/source4/dsdb/samdb/ldb_modules/show_deleted.c b/source4/dsdb/samdb/ldb_modules/show_deleted.c
index 557e36f0bd..11503e6d3b 100644
--- a/source4/dsdb/samdb/ldb_modules/show_deleted.c
+++ b/source4/dsdb/samdb/ldb_modules/show_deleted.c
@@ -40,7 +40,6 @@ static int show_deleted_search(struct ldb_module *module, struct ldb_request *re
struct ldb_control *control;
struct ldb_control **saved_controls;
struct ldb_request *down_req;
- struct ldb_parse_tree *nodeleted_tree;
struct ldb_parse_tree *new_tree = req->op.search.tree;
int ret;
@@ -50,19 +49,33 @@ static int show_deleted_search(struct ldb_module *module, struct ldb_request *re
control = ldb_request_get_control(req, LDB_CONTROL_SHOW_DELETED_OID);
if (! control) {
- nodeleted_tree = talloc_get_type(ldb_module_get_private(module),
- struct ldb_parse_tree);
- if (nodeleted_tree) {
- new_tree = talloc(req, struct ldb_parse_tree);
- if (!new_tree) {
- ldb_oom(ldb);
- return LDB_ERR_OPERATIONS_ERROR;
- }
- *new_tree = *nodeleted_tree;
- /* Replace dummy part of 'and' with the old, tree,
- without a parse step */
- new_tree->u.list.elements[0] = req->op.search.tree;
+ /* FIXME: we could use a constant tree here once we
+ are sure that no ldb modules modify trees
+ in-situ */
+ new_tree = talloc(req, struct ldb_parse_tree);
+ if (!new_tree) {
+ ldb_oom(ldb);
+ return LDB_ERR_OPERATIONS_ERROR;
}
+ new_tree->operation = LDB_OP_AND;
+ new_tree->u.list.num_elements = 2;
+ new_tree->u.list.elements = talloc_array(new_tree, struct ldb_parse_tree *, 2);
+ if (!new_tree->u.list.elements) {
+ ldb_oom(ldb);
+ return LDB_ERR_OPERATIONS_ERROR;
+ }
+ new_tree->u.list.elements[0] = talloc(new_tree->u.list.elements, struct ldb_parse_tree);
+ new_tree->u.list.elements[0]->operation = LDB_OP_NOT;
+ new_tree->u.list.elements[0]->u.isnot.child =
+ talloc(new_tree->u.list.elements, struct ldb_parse_tree);
+ if (!new_tree->u.list.elements[0]->u.isnot.child) {
+ ldb_oom(ldb);
+ return LDB_ERR_OPERATIONS_ERROR;
+ }
+ new_tree->u.list.elements[0]->u.isnot.child->operation = LDB_OP_EQUALITY;
+ new_tree->u.list.elements[0]->u.isnot.child->u.equality.attr = "isDeleted";
+ new_tree->u.list.elements[0]->u.isnot.child->u.equality.value = data_blob_string_const("TRUE");
+ new_tree->u.list.elements[1] = req->op.search.tree;
}
ret = ldb_build_search_req_ex(&down_req, ldb, req,
@@ -89,20 +102,10 @@ static int show_deleted_search(struct ldb_module *module, struct ldb_request *re
static int show_deleted_init(struct ldb_module *module)
{
struct ldb_context *ldb;
- struct ldb_parse_tree *nodeleted_tree;
int ret;
ldb = ldb_module_get_ctx(module);
- nodeleted_tree = ldb_parse_tree(module, "(&(replace=me)(!(isDeleted=TRUE)))");
- if (!nodeleted_tree) {
- ldb_debug(ldb, LDB_DEBUG_ERROR,
- "show_deleted: Unable to parse isDeleted master expression!\n");
- return LDB_ERR_OPERATIONS_ERROR;
- }
-
- ldb_module_set_private(module, nodeleted_tree);
-
ret = ldb_mod_register_control(module, LDB_CONTROL_SHOW_DELETED_OID);
if (ret != LDB_SUCCESS) {
ldb_debug(ldb, LDB_DEBUG_ERROR,