summaryrefslogtreecommitdiff
path: root/source4/dsdb/samdb/ldb_modules/linked_attributes.c
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2007-11-13 22:54:52 +0100
committerStefan Metzmacher <metze@samba.org>2007-12-21 05:45:11 +0100
commit5d4f507a65144d8fe30b3fcd0b9cbcdc088146c6 (patch)
tree6a134f6519fd958bc3dde6cf4021ca1147521202 /source4/dsdb/samdb/ldb_modules/linked_attributes.c
parent7f18e15e3f48d92a4f8f2b929a6337761b26fc67 (diff)
downloadsamba-5d4f507a65144d8fe30b3fcd0b9cbcdc088146c6.tar.gz
samba-5d4f507a65144d8fe30b3fcd0b9cbcdc088146c6.tar.bz2
samba-5d4f507a65144d8fe30b3fcd0b9cbcdc088146c6.zip
r25942: Make various ldb modules handle an LDB backend that enforces validity
of Base DNs in searches (returning an error of LDB_ERR_NO_SUCH_ENTRY). We need to handle this if ldb_tdb is to behave correctly compared with LDAP, as well as if we are using an LDAP backend. In doing so, I realised that subtree_rename and subtree_delete (prevention) need rather different wait loops, so it seemed easier to split it out into it's own module. I've fixed the licence on both of these modules to be GPLv3. Andrew Bartlett (This used to be commit d3894c90f31fb45e038ab478cd9d7d34962d069b)
Diffstat (limited to 'source4/dsdb/samdb/ldb_modules/linked_attributes.c')
-rw-r--r--source4/dsdb/samdb/ldb_modules/linked_attributes.c68
1 files changed, 38 insertions, 30 deletions
diff --git a/source4/dsdb/samdb/ldb_modules/linked_attributes.c b/source4/dsdb/samdb/ldb_modules/linked_attributes.c
index be5dd12d3b..f3e66c5065 100644
--- a/source4/dsdb/samdb/ldb_modules/linked_attributes.c
+++ b/source4/dsdb/samdb/ldb_modules/linked_attributes.c
@@ -34,10 +34,12 @@
#include "dsdb/samdb/samdb.h"
struct linked_attributes_context {
+ enum la_step {LA_SEARCH, LA_DO_OPS} step;
struct ldb_module *module;
struct ldb_handle *handle;
struct ldb_request *orig_req;
+ struct ldb_request *search_req;
struct ldb_request **down_req;
int num_requests;
int finished_requests;
@@ -82,7 +84,7 @@ static struct linked_attributes_context *linked_attributes_init_handle(struct ld
static int setup_modifies(struct ldb_context *ldb, TALLOC_CTX *mem_ctx,
struct linked_attributes_context *ac,
- struct ldb_message *msg,
+ const struct ldb_message *msg,
struct ldb_dn *olddn, struct ldb_dn *newdn)
{
int i, j, ret = LDB_SUCCESS;
@@ -192,6 +194,7 @@ static int setup_modifies(struct ldb_context *ldb, TALLOC_CTX *mem_ctx,
ac->down_req[ac->num_requests] = new_req;
ac->num_requests++;
+
/* Run the new request */
ret = ldb_next_request(ac->module, new_req);
if (ret != LDB_SUCCESS) {
@@ -272,6 +275,8 @@ static int linked_attributes_add(struct ldb_module *module, struct ldb_request *
/* Even link IDs are for the originating attribute */
}
+
+ ac->step = LA_DO_OPS;
/* Now call the common routine to setup the modifies across all the attributes */
return setup_modifies(module->ldb, ac, ac, req->op.add.message, NULL, req->op.add.message->dn);
@@ -322,6 +327,8 @@ static int linked_attributes_modify(struct ldb_module *module, struct ldb_reques
ac->num_requests++;
+ ac->step = LA_DO_OPS;
+
/* Run the original request */
ret = ldb_next_request(module, ac->down_req[0]);
if (ret != LDB_SUCCESS) {
@@ -539,18 +546,8 @@ static int linked_attributes_rename(struct ldb_module *module, struct ldb_reques
talloc_steal(new_req, attrs);
- ac->down_req = talloc_realloc(ac, ac->down_req,
- struct ldb_request *, ac->num_requests + 1);
- if (!ac->down_req) {
- ldb_oom(ac->module->ldb);
- return LDB_ERR_OPERATIONS_ERROR;
- }
- ac->down_req[ac->num_requests] = new_req;
- if (req == NULL) {
- ldb_oom(ac->module->ldb);
- return LDB_ERR_OPERATIONS_ERROR;
- }
- ac->num_requests++;
+ ac->search_req = new_req;
+ ac->step = LA_SEARCH;
return ldb_next_request(module, new_req);
}
@@ -602,18 +599,8 @@ static int linked_attributes_delete(struct ldb_module *module, struct ldb_reques
talloc_steal(new_req, attrs);
- ac->down_req = talloc_realloc(ac, ac->down_req,
- struct ldb_request *, ac->num_requests + 1);
- if (!ac->down_req) {
- ldb_oom(ac->module->ldb);
- return LDB_ERR_OPERATIONS_ERROR;
- }
- ac->down_req[ac->num_requests] = new_req;
- if (req == NULL) {
- ldb_oom(ac->module->ldb);
- return LDB_ERR_OPERATIONS_ERROR;
- }
- ac->num_requests++;
+ ac->search_req = new_req;
+ ac->step = LA_SEARCH;
return ldb_next_request(module, new_req);
}
@@ -634,21 +621,42 @@ static int linked_attributes_wait_none(struct ldb_handle *handle) {
ac = talloc_get_type(handle->private_data, struct linked_attributes_context);
- for (i=0; i < ac->num_requests; i++) {
- ret = ldb_wait(ac->down_req[i]->handle, LDB_WAIT_NONE);
+ switch (ac->step) {
+ case LA_SEARCH:
+ ret = ldb_wait(ac->search_req->handle, LDB_WAIT_NONE);
if (ret != LDB_SUCCESS) {
handle->status = ret;
goto done;
}
- if (ac->down_req[i]->handle->status != LDB_SUCCESS) {
- handle->status = ac->down_req[i]->handle->status;
+ if (ac->search_req->handle->status != LDB_SUCCESS) {
+ handle->status = ac->search_req->handle->status;
goto done;
}
- if (ac->down_req[i]->handle->state != LDB_ASYNC_DONE) {
+ if (ac->search_req->handle->state != LDB_ASYNC_DONE) {
return LDB_SUCCESS;
}
+ ac->step = LA_DO_OPS;
+ return LDB_SUCCESS;
+
+ case LA_DO_OPS:
+ for (i=0; i < ac->num_requests; i++) {
+ ret = ldb_wait(ac->down_req[i]->handle, LDB_WAIT_NONE);
+
+ if (ret != LDB_SUCCESS) {
+ handle->status = ret;
+ goto done;
+ }
+ if (ac->down_req[i]->handle->status != LDB_SUCCESS) {
+ handle->status = ac->down_req[i]->handle->status;
+ goto done;
+ }
+
+ if (ac->down_req[i]->handle->state != LDB_ASYNC_DONE) {
+ return LDB_SUCCESS;
+ }
+ }
}
done: