mirror of
https://github.com/samba-team/samba.git
synced 2024-12-23 17:34:34 +03:00
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.
This commit is contained in:
parent
ced3eef776
commit
be78d4a70d
@ -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) {
|
||||
/* 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 = *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;
|
||||
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,
|
||||
|
Loading…
Reference in New Issue
Block a user