s4:subtree delete module - Cosmetic adaptions
authorMatthias Dieter Wallnöfer <mwallnoefer@yahoo.de>
Sun, 6 Sep 2009 15:27:51 +0000 (17:27 +0200)
committerMatthias Dieter Wallnöfer <mwallnoefer@yahoo.de>
Mon, 7 Sep 2009 06:37:25 +0000 (08:37 +0200)
source4/dsdb/samdb/ldb_modules/subtree_delete.c

index 55a24549dd8af403b6abb1134b8a6e1f7678aa1d..241cc5f7d6fe85f7f450c09a95d45ae49035ae8d 100644 (file)
@@ -69,8 +69,8 @@ static int subtree_delete_search_callback(struct ldb_request *req,
        ldb = ldb_module_get_ctx(ac->module);
 
        if (!ares) {
-               return ldb_module_done(ac->req, NULL, NULL,
-                                       LDB_ERR_OPERATIONS_ERROR);
+               ret = LDB_ERR_OPERATIONS_ERROR;
+               goto done;
        }
        if (ares->error != LDB_SUCCESS) {
                return ldb_module_done(ac->req, ares->controls,
@@ -79,21 +79,23 @@ static int subtree_delete_search_callback(struct ldb_request *req,
 
        switch (ares->type) {
        case LDB_REPLY_ENTRY:
+               /* count entry */
+               ++(ac->num_children);
 
                talloc_free(ares);
-               ac->num_children++;
+               ret = LDB_SUCCESS;
                break;
 
        case LDB_REPLY_REFERRAL:
-
                /* ignore */
                talloc_free(ares);
+               ret = LDB_SUCCESS;
                break;
 
        case LDB_REPLY_DONE:
+               talloc_free(ares);
 
                if (ac->num_children > 0) {
-                       talloc_free(ares);
                        ldb_asprintf_errstring(ldb,
                                "Cannot delete %s, not a leaf node "
                                "(has %d children)\n",
@@ -105,13 +107,14 @@ static int subtree_delete_search_callback(struct ldb_request *req,
 
                /* ok no children, let the original request through */
                ret = ldb_next_request(ac->module, ac->req);
-               if (ret != LDB_SUCCESS) {
-                       return ldb_module_done(ac->req, NULL, NULL, ret);
-               }
+               break;
+       }
 
-               /* free our own context we are not going to be called back */
-               talloc_free(ac);
+done:
+       if (ret != LDB_SUCCESS) {
+               return ldb_module_done(ac->req, NULL, NULL, ret);
        }
+
        return LDB_SUCCESS;
 }
 
@@ -122,7 +125,9 @@ static int subtree_delete(struct ldb_module *module, struct ldb_request *req)
        struct ldb_request *search_req;
        struct subtree_delete_context *ac;
        int ret;
-       if (ldb_dn_is_special(req->op.rename.olddn)) { /* do not manipulate our control entries */
+
+       if (ldb_dn_is_special(req->op.rename.olddn)) {
+               /* do not manipulate our control entries */
                return ldb_next_request(module, req);
        }