From c59f00805cb06f3cb90d89690e142006658972d3 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Fri, 2 Oct 2009 10:28:29 +1000 Subject: s4:dsdb Rework modules create new partitions at runtime This is done by passing an extended operation to the partitions module to extend the @PARTITION record and to extend the in-memory list of partitions. This also splits things up into module parts that belong above and below repl_meta_data Also slit the partitions module into two files due to the complexity of the code Andrew Barltett --- source4/dsdb/samdb/ldb_modules/instancetype.c | 37 ++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 7 deletions(-) (limited to 'source4/dsdb/samdb/ldb_modules/instancetype.c') diff --git a/source4/dsdb/samdb/ldb_modules/instancetype.c b/source4/dsdb/samdb/ldb_modules/instancetype.c index 201ed04412..b17f40e82a 100644 --- a/source4/dsdb/samdb/ldb_modules/instancetype.c +++ b/source4/dsdb/samdb/ldb_modules/instancetype.c @@ -31,6 +31,7 @@ */ #include "includes.h" +#include "ldb.h" #include "ldb_module.h" #include "librpc/gen_ndr/ndr_misc.h" #include "dsdb/samdb/samdb.h" @@ -39,9 +40,10 @@ struct it_context { struct ldb_module *module; struct ldb_request *req; + struct ldb_request *add_req; }; -static int it_callback(struct ldb_request *req, struct ldb_reply *ares) +static int it_add_callback(struct ldb_request *req, struct ldb_reply *ares) { struct ldb_context *ldb; struct it_context *ac; @@ -53,6 +55,7 @@ static int it_callback(struct ldb_request *req, struct ldb_reply *ares) return ldb_module_done(ac->req, NULL, NULL, LDB_ERR_OPERATIONS_ERROR); } + if (ares->error != LDB_SUCCESS) { return ldb_module_done(ac->req, ares->controls, ares->response, ares->error); @@ -64,8 +67,10 @@ static int it_callback(struct ldb_request *req, struct ldb_reply *ares) LDB_ERR_OPERATIONS_ERROR); } + /* Add the boilerplate entries */ + return ldb_module_done(ac->req, ares->controls, - ares->response, ares->error); + ares->response, ares->error); } /* add_record: add instancetype attribute */ @@ -89,14 +94,32 @@ static int instancetype_add(struct ldb_module *module, struct ldb_request *req) if (ldb_msg_find_element(req->op.add.message, "instanceType")) { unsigned int instanceType = ldb_msg_find_attr_as_uint(req->op.add.message, "instanceType", 0); + if (!(instanceType & INSTANCE_TYPE_IS_NC_HEAD)) { + return ldb_next_request(module, req); + } - if (instanceType & INSTANCE_TYPE_IS_NC_HEAD) { - /* Do something in future */ + /* Forward the 'add' to the modules below, but if it + * succeeds, then we might need to add the boilerplate + * entries (lost+found, deleted objects) */ + ac = talloc(req, struct it_context); + if (ac == NULL) { + return LDB_ERR_OPERATIONS_ERROR; + } + ac->module = module; + ac->req = req; + + ret = ldb_build_add_req(&ac->add_req, ldb_module_get_ctx(ac->module), ac, + ac->req->op.add.message, + ac->req->controls, + ac, it_add_callback, + ac->req); + + if (ret != LDB_SUCCESS) { + return ret; } - /* TODO: we need to validate and possibly create a new - partition */ - return ldb_next_request(module, req); + /* Do the original add */ + return ldb_next_request(ac->module, ac->add_req); } /* we have to copy the message as the caller might have it as a const */ -- cgit