From 60192fd1004015b50e208b3da6a07bd67f9d7990 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Sat, 24 Nov 2012 10:04:39 +0100 Subject: [PATCH] s4:dsdb/subtree_delete: do an early return and avoid some nesting Signed-off-by: Stefan Metzmacher Reviewed-by: Michael Adam --- source4/dsdb/samdb/ldb_modules/subtree_delete.c | 52 +++++++++++++------------ 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/source4/dsdb/samdb/ldb_modules/subtree_delete.c b/source4/dsdb/samdb/ldb_modules/subtree_delete.c index d82c3ab828b..ce1b8922f35 100644 --- a/source4/dsdb/samdb/ldb_modules/subtree_delete.c +++ b/source4/dsdb/samdb/ldb_modules/subtree_delete.c @@ -61,34 +61,38 @@ static int subtree_delete(struct ldb_module *module, struct ldb_request *req) talloc_free(res); return ret; } - if (res->count > 0) { - if (ldb_request_get_control(req, LDB_CONTROL_TREE_DELETE_OID) == NULL) { - /* Do not add any DN outputs to this error string! - * Some MMC consoles (eg release 2000) have a strange - * bug and prevent subtree deletes afterwards. */ - ldb_asprintf_errstring(ldb_module_get_ctx(module), - "subtree_delete: Unable to " - "delete a non-leaf node " - "(it has %u children)!", - res->count); - talloc_free(res); - return LDB_ERR_NOT_ALLOWED_ON_NON_LEAF; - } + if (res->count == 0) { + talloc_free(res); + return ldb_next_request(module, req); + } - /* we need to start from the top since other LDB modules could - * enforce constraints (eg "objectclass" and "samldb" do so). */ - flags = DSDB_FLAG_TOP_MODULE | DSDB_TREE_DELETE; - if (ldb_request_get_control(req, LDB_CONTROL_RELAX_OID) != NULL) { - flags |= DSDB_MODIFY_RELAX; - } + if (ldb_request_get_control(req, LDB_CONTROL_TREE_DELETE_OID) == NULL) { + /* Do not add any DN outputs to this error string! + * Some MMC consoles (eg release 2000) have a strange + * bug and prevent subtree deletes afterwards. */ + ldb_asprintf_errstring(ldb_module_get_ctx(module), + "subtree_delete: Unable to " + "delete a non-leaf node " + "(it has %u children)!", + res->count); + talloc_free(res); + return LDB_ERR_NOT_ALLOWED_ON_NON_LEAF; + } - for (i = 0; i < res->count; i++) { - ret = dsdb_module_del(module, res->msgs[i]->dn, flags, req); - if (ret != LDB_SUCCESS) { - return ret; - } + /* we need to start from the top since other LDB modules could + * enforce constraints (eg "objectclass" and "samldb" do so). */ + flags = DSDB_FLAG_TOP_MODULE | DSDB_TREE_DELETE; + if (ldb_request_get_control(req, LDB_CONTROL_RELAX_OID) != NULL) { + flags |= DSDB_MODIFY_RELAX; + } + + for (i = 0; i < res->count; i++) { + ret = dsdb_module_del(module, res->msgs[i]->dn, flags, req); + if (ret != LDB_SUCCESS) { + return ret; } } + talloc_free(res); return ldb_next_request(module, req); -- 2.11.4.GIT