s4:dsdb/subtree_delete: do an early return and avoid some nesting
authorStefan Metzmacher <metze@samba.org>
Sat, 24 Nov 2012 09:04:39 +0000 (10:04 +0100)
committerStefan Metzmacher <metze@samba.org>
Sun, 25 Nov 2012 22:30:07 +0000 (23:30 +0100)
Signed-off-by: Stefan Metzmacher <metze@samba.org>
source4/dsdb/samdb/ldb_modules/subtree_delete.c

index d82c3ab828bcac0e0e3faa0ea4952242171a90ea..ce1b8922f35b9b380e8eb24dc33ccd5bcce90422 100644 (file)
@@ -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);