summaryrefslogtreecommitdiff
path: root/source4/dsdb/samdb/ldb_modules/instancetype.c
diff options
context:
space:
mode:
authorSimo Sorce <idra@samba.org>2008-09-11 18:36:28 -0400
committerStefan Metzmacher <metze@samba.org>2008-09-29 04:22:20 +0200
commit51baa8deec00244cc0a6e3d29c53932427800610 (patch)
treee4a63113b3e39120259c5ac3dc80ed2199d749fe /source4/dsdb/samdb/ldb_modules/instancetype.c
parent4f40ee2b86007f7dc631e93e59f24f970bc25ea2 (diff)
downloadsamba-51baa8deec00244cc0a6e3d29c53932427800610.tar.gz
samba-51baa8deec00244cc0a6e3d29c53932427800610.tar.bz2
samba-51baa8deec00244cc0a6e3d29c53932427800610.zip
LDB ASYNC: samba4 modules
Diffstat (limited to 'source4/dsdb/samdb/ldb_modules/instancetype.c')
-rw-r--r--source4/dsdb/samdb/ldb_modules/instancetype.c66
1 files changed, 47 insertions, 19 deletions
diff --git a/source4/dsdb/samdb/ldb_modules/instancetype.c b/source4/dsdb/samdb/ldb_modules/instancetype.c
index fd5aa5e18a..492ef1c92b 100644
--- a/source4/dsdb/samdb/ldb_modules/instancetype.c
+++ b/source4/dsdb/samdb/ldb_modules/instancetype.c
@@ -1,7 +1,7 @@
/*
ldb database library
- Copyright (C) Simo Sorce 2004-2006
+ Copyright (C) Simo Sorce 2004-2008
Copyright (C) Andrew Bartlett <abartlet@samba.org> 2005
Copyright (C) Andrew Tridgell 2005
Copyright (C) Stefan Metzmacher <metze@samba.org> 2007
@@ -41,11 +41,43 @@
#include "dsdb/samdb/samdb.h"
#include "dsdb/common/flags.h"
+struct it_context {
+ struct ldb_module *module;
+ struct ldb_request *req;
+};
+
+static int it_callback(struct ldb_request *req, struct ldb_reply *ares)
+{
+ struct it_context *ac;
+
+ ac = talloc_get_type(req->context, struct it_context);
+
+
+ if (!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);
+ }
+
+ if (ares->type != LDB_REPLY_DONE) {
+ ldb_set_errstring(req->handle->ldb, "Invalid reply type!");
+ return ldb_module_done(ac->req, NULL, NULL,
+ LDB_ERR_OPERATIONS_ERROR);
+ }
+
+ return ldb_module_done(ac->req, ares->controls,
+ ares->response, ares->error);
+}
+
/* add_record: add instancetype attribute */
static int instancetype_add(struct ldb_module *module, struct ldb_request *req)
{
struct ldb_request *down_req;
struct ldb_message *msg;
+ struct it_context *ac;
uint32_t instance_type;
int ret;
const struct ldb_control *partition_ctrl;
@@ -70,18 +102,16 @@ static int instancetype_add(struct ldb_module *module, struct ldb_request *req)
struct dsdb_control_current_partition);
SMB_ASSERT(partition && partition->version == DSDB_CONTROL_CURRENT_PARTITION_VERSION);
- down_req = talloc(req, struct ldb_request);
- if (down_req == NULL) {
- ldb_oom(module->ldb);
+ ac = talloc(req, struct it_context);
+ if (ac == NULL) {
return LDB_ERR_OPERATIONS_ERROR;
}
-
- *down_req = *req;
+ ac->module = module;
+ ac->req = req;
/* we have to copy the message as the caller might have it as a const */
- down_req->op.add.message = msg = ldb_msg_copy_shallow(down_req, req->op.add.message);
+ msg = ldb_msg_copy_shallow(ac, req->op.add.message);
if (msg == NULL) {
- talloc_free(down_req);
ldb_oom(module->ldb);
return LDB_ERR_OPERATIONS_ERROR;
}
@@ -99,23 +129,21 @@ static int instancetype_add(struct ldb_module *module, struct ldb_request *req)
ret = ldb_msg_add_fmt(msg, "instanceType", "%u", instance_type);
if (ret != LDB_SUCCESS) {
- talloc_free(down_req);
ldb_oom(module->ldb);
return LDB_ERR_OPERATIONS_ERROR;
}
- ldb_set_timeout_from_prev_req(module->ldb, req, down_req);
-
- /* go on with the call chain */
- ret = ldb_next_request(module, down_req);
-
- /* do not free down_req as the call results may be linked to it,
- * it will be freed when the upper level request get freed */
- if (ret == LDB_SUCCESS) {
- req->handle = down_req->handle;
+ ret = ldb_build_add_req(&down_req, module->ldb, ac,
+ msg,
+ req->controls,
+ ac, it_callback,
+ req);
+ if (ret != LDB_SUCCESS) {
+ return ret;
}
- return ret;
+ /* go on with the call chain */
+ return ldb_next_request(module, down_req);
}
_PUBLIC_ const struct ldb_module_ops ldb_instancetype_module_ops = {