s4:dsdb - add a new dsdb delete function which understands the tree delete control
authorMatthias Dieter Wallnöfer <mdw@samba.org>
Sun, 20 Jun 2010 10:43:49 +0000 (12:43 +0200)
committerMatthias Dieter Wallnöfer <mdw@samba.org>
Sun, 20 Jun 2010 16:52:29 +0000 (18:52 +0200)
source4/dsdb/common/util.c
source4/dsdb/common/util.h
source4/dsdb/samdb/ldb_modules/util.c

index d644d2d0ddff52822ef4d79d90d389951523f0ac..28061f323119a445799424e46c08581b4adcea09 100644 (file)
@@ -3479,6 +3479,13 @@ int dsdb_request_add_controls(struct ldb_request *req, uint32_t dsdb_flags)
                }
        }
 
+       if (dsdb_flags & DSDB_TREE_DELETE) {
+               ret = ldb_request_add_control(req, LDB_CONTROL_TREE_DELETE_OID, false, NULL);
+               if (ret != LDB_SUCCESS) {
+                       return ret;
+               }
+       }
+
        return LDB_SUCCESS;
 }
 
index 0b6ef3d0a12d9c900d11725ce4a8875a235b05f8..edada70d81a62ba6c97e6e42dcbd56d227637791 100644 (file)
@@ -31,5 +31,5 @@
 #define DSDB_MODIFY_RELAX                    0x0020
 #define DSDB_MODIFY_PERMISSIVE               0x0040
 #define DSDB_FLAG_AS_SYSTEM                  0x0080
-
-#define DSDB_SEARCH_ONE_ONLY                 0x0020 /* give an error unless 1 record */
+#define DSDB_TREE_DELETE                     0x0100
+#define DSDB_SEARCH_ONE_ONLY                 0x0200 /* give an error unless 1 record */
index bf9277485d27445c6ffa9d330733fa42becab0fa..ec07350a0a3049e5975d7579bd193e9ce5308f29 100644 (file)
@@ -407,6 +407,59 @@ int dsdb_module_add(struct ldb_module *module,
        return ret;
 }
 
+/*
+  a ldb_delete request operating on modules below the
+  current module
+ */
+int dsdb_module_del(struct ldb_module *module,
+                   struct ldb_dn *dn,
+                   uint32_t dsdb_flags)
+{
+       struct ldb_request *req;
+       int ret;
+       struct ldb_context *ldb = ldb_module_get_ctx(module);
+       TALLOC_CTX *tmp_ctx = talloc_new(module);
+       struct ldb_result *res;
+
+       res = talloc_zero(tmp_ctx, struct ldb_result);
+       if (!res) {
+               talloc_free(tmp_ctx);
+               return LDB_ERR_OPERATIONS_ERROR;
+       }
+
+       ret = ldb_build_del_req(&req, ldb, tmp_ctx,
+                               dn,
+                               NULL,
+                               res,
+                               ldb_modify_default_callback,
+                               NULL);
+       if (ret != LDB_SUCCESS) {
+               talloc_free(tmp_ctx);
+               return ret;
+       }
+
+       ret = dsdb_request_add_controls(req, dsdb_flags);
+       if (ret != LDB_SUCCESS) {
+               talloc_free(tmp_ctx);
+               return ret;
+       }
+
+       /* Run the new request */
+       if (dsdb_flags & DSDB_FLAG_OWN_MODULE) {
+               const struct ldb_module_ops *ops = ldb_module_get_ops(module);
+               ret = ops->del(module, req);
+       } else if (dsdb_flags & DSDB_FLAG_TOP_MODULE) {
+               ret = ldb_request(ldb_module_get_ctx(module), req);
+       } else {
+               ret = ldb_next_request(module, req);
+       }
+       if (ret == LDB_SUCCESS) {
+               ret = ldb_wait(req->handle, LDB_WAIT_ALL);
+       }
+
+       talloc_free(tmp_ctx);
+       return ret;
+}
 
 const struct dsdb_class * get_last_structural_class(const struct dsdb_schema *schema,const struct ldb_message_element *element)
 {