From aa7a02d45fefad3640f273b1d3bfe535a1e6b88c Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sat, 13 May 2006 21:08:37 +0000 Subject: r15582: Commit some forgotten stuff that have been setting on my private tree fro long (This used to be commit 7c050b541e98cd442a0c9ed0ddadb3e573cd1304) --- source4/dsdb/samdb/ldb_modules/objectguid.c | 75 +++++++++++++++++++++++++++-- source4/dsdb/samdb/ldb_modules/samldb.c | 10 +--- 2 files changed, 73 insertions(+), 12 deletions(-) (limited to 'source4/dsdb/samdb') diff --git a/source4/dsdb/samdb/ldb_modules/objectguid.c b/source4/dsdb/samdb/ldb_modules/objectguid.c index 7169aa6842..699f04775c 100644 --- a/source4/dsdb/samdb/ldb_modules/objectguid.c +++ b/source4/dsdb/samdb/ldb_modules/objectguid.c @@ -1,7 +1,7 @@ /* ldb database library - Copyright (C) Simo Sorce 2004 + Copyright (C) Simo Sorce 2004-2006 Copyright (C) Andrew Bartlett 2005 ** NOTE! The following LGPL license applies to the ldb @@ -34,8 +34,7 @@ */ #include "includes.h" -#include "ldb/include/ldb.h" -#include "ldb/include/ldb_private.h" +#include "ldb/include/includes.h" #include "librpc/gen_ndr/ndr_misc.h" static struct ldb_message_element *objectguid_find_attribute(const struct ldb_message *msg, const char *name) @@ -108,6 +107,73 @@ static int objectguid_add(struct ldb_module *module, struct ldb_request *req) return ret; } +static int objectguid_add_async(struct ldb_module *module, struct ldb_request *req) +{ + struct ldb_request *down_req; + struct ldb_message_element *attribute; + struct ldb_message *msg; + struct ldb_val v; + struct GUID guid; + NTSTATUS nt_status; + int ret; + + ldb_debug(module->ldb, LDB_DEBUG_TRACE, "objectguid_add_record\n"); + + /* do not manipulate our control entries */ + if (ldb_dn_is_special(req->op.add.message->dn)) { + return ldb_next_request(module, req); + } + + if ((attribute = objectguid_find_attribute(req->op.add.message, "objectGUID")) != NULL ) { + return ldb_next_request(module, req); + } + + down_req = talloc(req, struct ldb_request); + if (down_req == NULL) { + return LDB_ERR_OPERATIONS_ERROR; + } + + /* we have to copy the message as the caller might have it as a const */ + msg = ldb_msg_copy_shallow(down_req, req->op.add.message); + if (msg == NULL) { + return LDB_ERR_OPERATIONS_ERROR; + } + + /* a new GUID */ + guid = GUID_random(); + + nt_status = ndr_push_struct_blob(&v, msg, &guid, + (ndr_push_flags_fn_t)ndr_push_GUID); + if (!NT_STATUS_IS_OK(nt_status)) { + return -1; + } + + ret = ldb_msg_add_value(msg, "objectGUID", &v); + if (ret) { + return ret; + } + + down_req->op.add.message = msg; + + down_req->controls = req->controls; + down_req->creds = req->creds; + + down_req->async.context = req->async.context; + down_req->async.callback = req->async.callback; + down_req->async.timeout = req->async.timeout; + + /* 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->async.handle = down_req->async.handle; + } + + return ret; +} + static int objectguid_request(struct ldb_module *module, struct ldb_request *req) { switch (req->operation) { @@ -115,6 +181,9 @@ static int objectguid_request(struct ldb_module *module, struct ldb_request *req case LDB_REQ_ADD: return objectguid_add(module, req); + case LDB_ASYNC_ADD: + return objectguid_add_async(module, req); + default: return ldb_next_request(module, req); diff --git a/source4/dsdb/samdb/ldb_modules/samldb.c b/source4/dsdb/samdb/ldb_modules/samldb.c index cfc7192543..f8a151ddda 100644 --- a/source4/dsdb/samdb/ldb_modules/samldb.c +++ b/source4/dsdb/samdb/ldb_modules/samldb.c @@ -859,20 +859,12 @@ static int samldb_add_async(struct ldb_module *module, struct ldb_request *req) } } + *down_req = *req; if (msg2 != NULL) { down_req->op.add.message = talloc_steal(down_req, msg2); - } else { - down_req->op.add.message = msg; } - down_req->controls = req->controls; - down_req->creds = req->creds; - - down_req->async.context = req->async.context; - down_req->async.callback = req->async.callback; - down_req->async.timeout = req->async.timeout; - /* go on with the call chain */ ret = ldb_next_request(module, down_req); -- cgit