s4-dsdb: added dsdb_module_add()
authorAndrew Tridgell <tridge@samba.org>
Tue, 5 Jan 2010 22:17:19 +0000 (09:17 +1100)
committerAndrew Tridgell <tridge@samba.org>
Fri, 8 Jan 2010 02:02:59 +0000 (13:02 +1100)
added a ldb add function for modules

Pair-Programmed-With: Andrew Bartlett <abartlet@samba.org>

source4/dsdb/samdb/ldb_modules/util.c

index 32b79a6701064678d0118837c0b2fa67b966879e..5d66177d8b037505aa6efb4a87bc62dd9a107b62 100644 (file)
@@ -391,6 +391,52 @@ int dsdb_module_rename(struct ldb_module *module,
        return ret;
 }
 
+/*
+  a ldb_add request operating on modules below the
+  current module
+ */
+int dsdb_module_add(struct ldb_module *module,
+                   const struct ldb_message *message,
+                   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);
+
+       ret = ldb_build_add_req(&req, ldb, tmp_ctx,
+                               message,
+                               NULL,
+                               NULL,
+                               ldb_op_default_callback,
+                               NULL);
+       if (ret != LDB_SUCCESS) {
+               talloc_free(tmp_ctx);
+               return ret;
+       }
+
+       ret = dsdb_request_add_controls(module, 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->add(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)
 {
        const struct dsdb_class *last_class = NULL;