4 Copyright (C) Andrew Bartlett <abartlet@samba.org> 2006
5 Copyright (C) Stefan Metzmacher <metze@samba.org> 2007
7 * NOTICE: this module is NOT released under the GNU LGPL license as
8 * other ldb code. This module is release under the GNU GPL v2 or
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 * Component: ldb partitions module
31 * Description: Implement LDAP partitions
33 * Author: Andrew Bartlett
34 * Author: Stefan Metzmacher
38 #include "ldb/include/includes.h"
39 #include "dsdb/samdb/samdb.h"
42 struct ldb_module *module;
46 struct partition_private_data {
47 struct partition **partitions;
48 struct ldb_dn **replicate;
51 struct partition_context {
52 struct ldb_module *module;
53 struct ldb_handle *handle;
54 struct ldb_request *orig_req;
56 struct ldb_request **down_req;
58 int finished_requests;
61 static struct partition_context *partition_init_handle(struct ldb_request *req, struct ldb_module *module)
63 struct partition_context *ac;
66 h = talloc_zero(req, struct ldb_handle);
68 ldb_set_errstring(module->ldb, "Out of Memory");
74 ac = talloc_zero(h, struct partition_context);
76 ldb_set_errstring(module->ldb, "Out of Memory");
92 struct ldb_module *make_module_for_next_request(TALLOC_CTX *mem_ctx,
93 struct ldb_context *ldb,
94 struct ldb_module *module)
96 struct ldb_module *current;
97 static const struct ldb_module_ops ops; /* zero */
98 current = talloc_zero(mem_ctx, struct ldb_module);
99 if (current == NULL) {
105 current->prev = NULL;
106 current->next = module;
110 struct ldb_module *find_backend(struct ldb_module *module, struct ldb_request *req, struct ldb_dn *dn)
113 struct partition_private_data *data = talloc_get_type(module->private_data,
114 struct partition_private_data);
115 /* Look at base DN */
116 /* Figure out which partition it is under */
117 /* Skip the lot if 'data' isn't here yet (initialistion) */
118 for (i=0; data && data->partitions && data->partitions[i]; i++) {
119 if (ldb_dn_compare_base(data->partitions[i]->dn, dn) == 0) {
120 return make_module_for_next_request(req, module->ldb, data->partitions[i]->module);
129 fire the caller's callback for every entry, but only send 'done' once.
131 static int partition_search_callback(struct ldb_context *ldb, void *context, struct ldb_reply *ares)
133 struct partition_context *ac;
135 if (!context || !ares) {
136 ldb_set_errstring(ldb, "partition_search_callback: NULL Context or Result in 'search' callback");
140 ac = talloc_get_type(context, struct partition_context);
142 if (ares->type == LDB_REPLY_ENTRY) {
143 return ac->orig_req->callback(ldb, ac->orig_req->context, ares);
145 ac->finished_requests++;
146 if (ac->finished_requests == ac->num_requests) {
147 return ac->orig_req->callback(ldb, ac->orig_req->context, ares);
155 return LDB_ERR_OPERATIONS_ERROR;
159 only fire the 'last' callback, and only for START-TLS for now
161 static int partition_other_callback(struct ldb_context *ldb, void *context, struct ldb_reply *ares)
163 struct partition_context *ac;
166 ldb_set_errstring(ldb, "partition_other_callback: NULL Context in 'other' callback");
170 ac = talloc_get_type(context, struct partition_context);
172 if (!ac->orig_req->callback) {
178 || (ares->type == LDB_REPLY_EXTENDED
179 && strcmp(ares->response->oid, LDB_EXTENDED_START_TLS_OID))) {
180 ac->finished_requests++;
181 if (ac->finished_requests == ac->num_requests) {
182 return ac->orig_req->callback(ldb, ac->orig_req->context, ares);
187 ldb_set_errstring(ldb, "partition_other_callback: Unknown reply type, only supports START_TLS");
190 return LDB_ERR_OPERATIONS_ERROR;
194 static int partition_send_request(struct partition_context *ac, struct ldb_module *partition,
195 struct ldb_dn *partition_base_dn)
198 struct ldb_module *next = make_module_for_next_request(ac->module, ac->module->ldb, partition);
199 struct ldb_request *req;
200 ac->down_req = talloc_realloc(ac, ac->down_req,
201 struct ldb_request *, ac->num_requests + 1);
203 ldb_set_errstring(ac->module->ldb, "Out of Memory");
204 return LDB_ERR_OPERATIONS_ERROR;
206 req = ac->down_req[ac->num_requests] = talloc(ac, struct ldb_request);
208 ldb_set_errstring(ac->module->ldb, "Out of Memory");
209 return LDB_ERR_OPERATIONS_ERROR;
212 *ac->down_req[ac->num_requests] = *ac->orig_req; /* copy the request */
214 if (req->operation == LDB_SEARCH) {
215 /* If the search is for 'more' than this partition,
216 * then change the basedn, so a remote LDAP server
218 if (ldb_dn_compare_base(partition_base_dn, req->op.search.base) != 0) {
219 req->op.search.base = partition_base_dn;
221 req->callback = partition_search_callback;
224 req->callback = partition_other_callback;
228 /* Spray off search requests to all backends */
229 ret = ldb_next_request(next, req);
230 if (ret != LDB_SUCCESS) {
238 /* Send a request down to all the partitions */
239 static int partition_send_all(struct ldb_module *module,
240 struct partition_context *ac, struct ldb_request *req)
243 struct partition_private_data *data = talloc_get_type(module->private_data,
244 struct partition_private_data);
245 int ret = partition_send_request(ac, module->next, NULL);
246 if (ret != LDB_SUCCESS) {
249 for (i=0; data && data->partitions && data->partitions[i]; i++) {
250 ret = partition_send_request(ac, data->partitions[i]->module, data->partitions[i]->dn);
251 if (ret != LDB_SUCCESS) {
258 /* Figure out which backend a request needs to be aimed at. Some
259 * requests must be replicated to all backends */
260 static int partition_replicate(struct ldb_module *module, struct ldb_request *req, struct ldb_dn *dn)
263 struct ldb_module *backend;
264 struct partition_private_data *data = talloc_get_type(module->private_data,
265 struct partition_private_data);
267 /* Is this a special DN, we need to replicate to every backend? */
268 for (i=0; data->replicate && data->replicate[i]; i++) {
269 if (ldb_dn_compare(data->replicate[i],
271 struct partition_context *ac;
273 ac = partition_init_handle(req, module);
275 return LDB_ERR_OPERATIONS_ERROR;
278 return partition_send_all(module, ac, req);
282 /* Otherwise, we need to find the backend to fire it to */
285 backend = find_backend(module, req, dn);
288 return ldb_next_request(backend, req);
293 static int partition_search(struct ldb_module *module, struct ldb_request *req)
296 struct partition_private_data *data = talloc_get_type(module->private_data,
297 struct partition_private_data);
300 /* (later) consider if we should be searching multiple
301 * partitions (for 'invisible' partition behaviour */
302 if (ldb_get_opaque(module->ldb, "global_catalog")) {
304 struct partition_context *ac;
306 ac = partition_init_handle(req, module);
308 return LDB_ERR_OPERATIONS_ERROR;
311 /* Search from the base DN */
312 if (!req->op.search.base || ldb_dn_is_null(req->op.search.base)) {
313 return partition_send_all(module, ac, req);
315 for (i=0; data && data->partitions && data->partitions[i]; i++) {
316 /* Find all partitions under the search base */
317 if (ldb_dn_compare_base(req->op.search.base, data->partitions[i]->dn) == 0) {
318 ret = partition_send_request(ac, data->partitions[i]->module, data->partitions[i]->dn);
319 if (ret != LDB_SUCCESS) {
325 /* Perhaps we didn't match any partitions. Try the main partition, only */
326 if (ac->num_requests == 0) {
328 return ldb_next_request(module, req);
333 struct ldb_module *backend = find_backend(module, req, req->op.search.base);
335 return ldb_next_request(backend, req);
340 static int partition_add(struct ldb_module *module, struct ldb_request *req)
342 return partition_replicate(module, req, req->op.add.message->dn);
346 static int partition_modify(struct ldb_module *module, struct ldb_request *req)
348 return partition_replicate(module, req, req->op.mod.message->dn);
352 static int partition_delete(struct ldb_module *module, struct ldb_request *req)
354 return partition_replicate(module, req, req->op.del.dn);
358 static int partition_rename(struct ldb_module *module, struct ldb_request *req)
361 struct ldb_module *backend = find_backend(module, req, req->op.rename.olddn);
362 struct ldb_module *backend2 = find_backend(module, req, req->op.rename.newdn);
364 if (backend->next != backend2->next) {
365 return LDB_ERR_AFFECTS_MULTIPLE_DSAS;
368 return partition_replicate(module, req, req->op.rename.olddn);
371 /* start a transaction */
372 static int partition_start_trans(struct ldb_module *module)
375 struct partition_private_data *data = talloc_get_type(module->private_data,
376 struct partition_private_data);
377 /* Look at base DN */
378 /* Figure out which partition it is under */
379 /* Skip the lot if 'data' isn't here yet (initialistion) */
380 ret = ldb_next_start_trans(module);
381 if (ret != LDB_SUCCESS) {
385 for (i=0; data && data->partitions && data->partitions[i]; i++) {
386 struct ldb_module *next = make_module_for_next_request(module, module->ldb, data->partitions[i]->module);
388 ret = ldb_next_start_trans(next);
390 if (ret != LDB_SUCCESS) {
391 /* Back it out, if it fails on one */
392 for (i--; i >= 0; i--) {
393 next = make_module_for_next_request(module, module->ldb, data->partitions[i]->module);
394 ldb_next_del_trans(next);
403 /* end a transaction */
404 static int partition_end_trans(struct ldb_module *module)
406 int i, ret, ret2 = LDB_SUCCESS;
407 struct partition_private_data *data = talloc_get_type(module->private_data,
408 struct partition_private_data);
409 ret = ldb_next_end_trans(module);
410 if (ret != LDB_SUCCESS) {
414 /* Look at base DN */
415 /* Figure out which partition it is under */
416 /* Skip the lot if 'data' isn't here yet (initialistion) */
417 for (i=0; data && data->partitions && data->partitions[i]; i++) {
418 struct ldb_module *next = make_module_for_next_request(module, module->ldb, data->partitions[i]->module);
420 ret = ldb_next_end_trans(next);
422 if (ret != LDB_SUCCESS) {
427 if (ret != LDB_SUCCESS) {
428 /* Back it out, if it fails on one */
429 for (i=0; data && data->partitions && data->partitions[i]; i++) {
430 struct ldb_module *next = make_module_for_next_request(module, module->ldb, data->partitions[i]->module);
431 ldb_next_del_trans(next);
438 /* delete a transaction */
439 static int partition_del_trans(struct ldb_module *module)
441 int i, ret, ret2 = LDB_SUCCESS;
442 struct partition_private_data *data = talloc_get_type(module->private_data,
443 struct partition_private_data);
444 ret = ldb_next_del_trans(module);
445 if (ret != LDB_SUCCESS) {
449 /* Look at base DN */
450 /* Figure out which partition it is under */
451 /* Skip the lot if 'data' isn't here yet (initialistion) */
452 for (i=0; data && data->partitions && data->partitions[i]; i++) {
453 struct ldb_module *next = make_module_for_next_request(module, module->ldb, data->partitions[i]->module);
455 ret = ldb_next_del_trans(next);
457 if (ret != LDB_SUCCESS) {
464 static int partition_sequence_number(struct ldb_module *module, struct ldb_request *req)
467 uint64_t seq_number = 0;
468 uint64_t timestamp_sequence = 0;
469 uint64_t timestamp = 0;
470 struct partition_private_data *data = talloc_get_type(module->private_data,
471 struct partition_private_data);
473 switch (req->op.seq_num.type) {
475 case LDB_SEQ_HIGHEST_SEQ:
476 ret = ldb_next_request(module, req);
477 if (ret != LDB_SUCCESS) {
480 if (req->op.seq_num.flags & LDB_SEQ_TIMESTAMP_SEQUENCE) {
481 timestamp_sequence = req->op.seq_num.seq_num;
483 seq_number = seq_number + req->op.seq_num.seq_num;
486 /* Look at base DN */
487 /* Figure out which partition it is under */
488 /* Skip the lot if 'data' isn't here yet (initialistion) */
489 for (i=0; data && data->partitions && data->partitions[i]; i++) {
490 struct ldb_module *next = make_module_for_next_request(req, module->ldb, data->partitions[i]->module);
492 ret = ldb_next_request(next, req);
494 if (ret != LDB_SUCCESS) {
497 if (req->op.seq_num.flags & LDB_SEQ_TIMESTAMP_SEQUENCE) {
498 timestamp_sequence = MAX(timestamp_sequence, req->op.seq_num.seq_num);
500 seq_number = seq_number + req->op.seq_num.seq_num;
504 case LDB_SEQ_HIGHEST_TIMESTAMP:
506 struct ldb_request *date_req = talloc(req, struct ldb_request);
508 return LDB_ERR_OPERATIONS_ERROR;
511 date_req->op.seq_num.flags = LDB_SEQ_HIGHEST_TIMESTAMP;
513 ret = ldb_next_request(module, date_req);
514 if (ret != LDB_SUCCESS) {
517 timestamp = date_req->op.seq_num.seq_num;
519 /* Look at base DN */
520 /* Figure out which partition it is under */
521 /* Skip the lot if 'data' isn't here yet (initialistion) */
522 for (i=0; data && data->partitions && data->partitions[i]; i++) {
523 struct ldb_module *next = make_module_for_next_request(req, module->ldb, data->partitions[i]->module);
525 ret = ldb_next_request(next, date_req);
527 if (ret != LDB_SUCCESS) {
530 timestamp = MAX(timestamp, date_req->op.seq_num.seq_num);
536 switch (req->op.seq_num.flags) {
538 case LDB_SEQ_HIGHEST_SEQ:
540 req->op.seq_num.flags = 0;
542 /* Has someone above set a timebase sequence? */
543 if (timestamp_sequence) {
544 req->op.seq_num.seq_num = (((unsigned long long)timestamp << 24) | (seq_number & 0xFFFFFF));
546 req->op.seq_num.seq_num = seq_number;
549 if (timestamp_sequence > req->op.seq_num.seq_num) {
550 req->op.seq_num.seq_num = timestamp_sequence;
551 req->op.seq_num.flags |= LDB_SEQ_TIMESTAMP_SEQUENCE;
554 req->op.seq_num.flags |= LDB_SEQ_GLOBAL_SEQUENCE;
556 case LDB_SEQ_HIGHEST_TIMESTAMP:
557 req->op.seq_num.seq_num = timestamp;
561 switch (req->op.seq_num.flags) {
563 req->op.seq_num.seq_num++;
568 static int partition_extended_replicated_objects(struct ldb_module *module, struct ldb_request *req)
570 struct dsdb_extended_replicated_objects *ext;
572 ext = talloc_get_type(req->op.extended.data, struct dsdb_extended_replicated_objects);
574 ldb_debug(module->ldb, LDB_DEBUG_FATAL, "partition_extended_replicated_objects: invalid extended data\n");
575 return LDB_ERR_PROTOCOL_ERROR;
578 if (ext->version != DSDB_EXTENDED_REPLICATED_OBJECTS_VERSION) {
579 ldb_debug(module->ldb, LDB_DEBUG_FATAL, "partition_extended_replicated_objects: extended data invalid version [%u != %u]\n",
580 ext->version, DSDB_EXTENDED_REPLICATED_OBJECTS_VERSION);
581 return LDB_ERR_PROTOCOL_ERROR;
584 return partition_replicate(module, req, ext->partition_dn);
588 static int partition_extended(struct ldb_module *module, struct ldb_request *req)
590 struct partition_context *ac;
592 if (strcmp(req->op.extended.oid, DSDB_EXTENDED_REPLICATED_OBJECTS_OID) == 0) {
593 return partition_extended_replicated_objects(module, req);
597 * as the extended operation has no dn
598 * we need to send it to all partitions
601 ac = partition_init_handle(req, module);
603 return LDB_ERR_OPERATIONS_ERROR;
606 return partition_send_all(module, ac, req);
609 static int sort_compare(void *void1,
610 void *void2, void *opaque)
612 struct partition **pp1 = void1;
613 struct partition **pp2 = void2;
614 struct partition *partition1 = talloc_get_type(*pp1, struct partition);
615 struct partition *partition2 = talloc_get_type(*pp2, struct partition);
617 return ldb_dn_compare(partition1->dn, partition2->dn);
620 static int partition_init(struct ldb_module *module)
623 TALLOC_CTX *mem_ctx = talloc_new(module);
624 static const char *attrs[] = { "partition", "replicateEntries", "modules", NULL };
625 struct ldb_result *res;
626 struct ldb_message *msg;
627 struct ldb_message_element *partition_attributes;
628 struct ldb_message_element *replicate_attributes;
629 struct ldb_message_element *modules_attributes;
631 struct partition_private_data *data;
634 return LDB_ERR_OPERATIONS_ERROR;
637 data = talloc(mem_ctx, struct partition_private_data);
639 return LDB_ERR_OPERATIONS_ERROR;
642 ret = ldb_search(module->ldb, ldb_dn_new(mem_ctx, module->ldb, "@PARTITION"),
646 if (ret != LDB_SUCCESS) {
647 talloc_free(mem_ctx);
650 talloc_steal(mem_ctx, res);
651 if (res->count == 0) {
652 talloc_free(mem_ctx);
653 return ldb_next_init(module);
656 if (res->count > 1) {
657 talloc_free(mem_ctx);
658 return LDB_ERR_CONSTRAINT_VIOLATION;
663 partition_attributes = ldb_msg_find_element(msg, "partition");
664 if (!partition_attributes) {
665 ldb_set_errstring(module->ldb, "partition_init: no partitions specified");
666 talloc_free(mem_ctx);
667 return LDB_ERR_CONSTRAINT_VIOLATION;
669 data->partitions = talloc_array(data, struct partition *, partition_attributes->num_values + 1);
670 if (!data->partitions) {
671 talloc_free(mem_ctx);
672 return LDB_ERR_OPERATIONS_ERROR;
674 for (i=0; i < partition_attributes->num_values; i++) {
675 char *base = talloc_strdup(data->partitions, (char *)partition_attributes->values[i].data);
676 char *p = strchr(base, ':');
678 ldb_asprintf_errstring(module->ldb,
680 "invalid form for partition record (missing ':'): %s", base);
681 talloc_free(mem_ctx);
682 return LDB_ERR_CONSTRAINT_VIOLATION;
687 ldb_asprintf_errstring(module->ldb,
689 "invalid form for partition record (missing backend database): %s", base);
690 talloc_free(mem_ctx);
691 return LDB_ERR_CONSTRAINT_VIOLATION;
693 data->partitions[i] = talloc(data->partitions, struct partition);
694 if (!data->partitions[i]) {
695 talloc_free(mem_ctx);
696 return LDB_ERR_OPERATIONS_ERROR;
699 data->partitions[i]->dn = ldb_dn_new(data->partitions[i], module->ldb, base);
700 if (!data->partitions[i]->dn) {
701 ldb_asprintf_errstring(module->ldb,
702 "partition_init: invalid DN in partition record: %s", base);
703 talloc_free(mem_ctx);
704 return LDB_ERR_CONSTRAINT_VIOLATION;
707 data->partitions[i]->backend = private_path(data->partitions[i], p);
708 ret = ldb_connect_backend(module->ldb, data->partitions[i]->backend, NULL, &data->partitions[i]->module);
709 if (ret != LDB_SUCCESS) {
710 talloc_free(mem_ctx);
714 data->partitions[i] = NULL;
716 /* sort these into order, most to least specific */
717 ldb_qsort(data->partitions, partition_attributes->num_values, sizeof(*data->partitions),
718 module->ldb, sort_compare);
720 for (i=0; data->partitions[i]; i++) {
721 struct ldb_request *req;
722 req = talloc_zero(mem_ctx, struct ldb_request);
724 ldb_debug(module->ldb, LDB_DEBUG_ERROR, "partition: Out of memory!\n");
725 talloc_free(mem_ctx);
726 return LDB_ERR_OPERATIONS_ERROR;
729 req->operation = LDB_REQ_REGISTER_PARTITION;
730 req->op.reg_partition.dn = data->partitions[i]->dn;
732 ret = ldb_request(module->ldb, req);
733 if (ret != LDB_SUCCESS) {
734 ldb_debug(module->ldb, LDB_DEBUG_ERROR, "partition: Unable to register partition with rootdse!\n");
735 talloc_free(mem_ctx);
736 return LDB_ERR_OTHER;
741 replicate_attributes = ldb_msg_find_element(msg, "replicateEntries");
742 if (!replicate_attributes) {
743 data->replicate = NULL;
745 data->replicate = talloc_array(data, struct ldb_dn *, replicate_attributes->num_values + 1);
746 if (!data->replicate) {
747 talloc_free(mem_ctx);
748 return LDB_ERR_OPERATIONS_ERROR;
751 for (i=0; i < replicate_attributes->num_values; i++) {
752 data->replicate[i] = ldb_dn_new(data->replicate, module->ldb, (const char *)replicate_attributes->values[i].data);
753 if (!ldb_dn_validate(data->replicate[i])) {
754 ldb_asprintf_errstring(module->ldb,
756 "invalid DN in partition replicate record: %s",
757 replicate_attributes->values[i].data);
758 talloc_free(mem_ctx);
759 return LDB_ERR_CONSTRAINT_VIOLATION;
762 data->replicate[i] = NULL;
765 /* Make the private data available to any searches the modules may trigger in initialisation */
766 module->private_data = data;
767 talloc_steal(module, data);
769 modules_attributes = ldb_msg_find_element(msg, "modules");
770 if (modules_attributes) {
771 for (i=0; i < modules_attributes->num_values; i++) {
772 struct ldb_dn *base_dn;
774 struct partition *partition = NULL;
775 const char **modules = NULL;
777 char *base = talloc_strdup(data->partitions, (char *)modules_attributes->values[i].data);
778 char *p = strchr(base, ':');
780 ldb_asprintf_errstring(module->ldb,
782 "invalid form for partition module record (missing ':'): %s", base);
783 talloc_free(mem_ctx);
784 return LDB_ERR_CONSTRAINT_VIOLATION;
789 ldb_asprintf_errstring(module->ldb,
791 "invalid form for partition module record (missing backend database): %s", base);
792 talloc_free(mem_ctx);
793 return LDB_ERR_CONSTRAINT_VIOLATION;
796 modules = ldb_modules_list_from_string(module->ldb, mem_ctx,
799 base_dn = ldb_dn_new(mem_ctx, module->ldb, base);
800 if (!ldb_dn_validate(base_dn)) {
801 talloc_free(mem_ctx);
802 return LDB_ERR_OPERATIONS_ERROR;
805 for (partition_idx = 0; data->partitions[partition_idx]; partition_idx++) {
806 if (ldb_dn_compare(data->partitions[partition_idx]->dn, base_dn) == 0) {
807 partition = data->partitions[partition_idx];
813 ldb_asprintf_errstring(module->ldb,
815 "invalid form for partition module record (no such partition): %s", base);
816 talloc_free(mem_ctx);
817 return LDB_ERR_CONSTRAINT_VIOLATION;
820 ret = ldb_load_modules_list(module->ldb, modules, partition->module, &partition->module);
821 if (ret != LDB_SUCCESS) {
822 ldb_asprintf_errstring(module->ldb,
824 "loading backend for %s failed: %s",
825 base, ldb_errstring(module->ldb));
826 talloc_free(mem_ctx);
829 ret = ldb_init_module_chain(module->ldb, partition->module);
830 if (ret != LDB_SUCCESS) {
831 ldb_asprintf_errstring(module->ldb,
833 "initialising backend for %s failed: %s",
834 base, ldb_errstring(module->ldb));
835 talloc_free(mem_ctx);
841 talloc_free(mem_ctx);
842 return ldb_next_init(module);
845 static int partition_wait_none(struct ldb_handle *handle) {
846 struct partition_context *ac;
850 if (!handle || !handle->private_data) {
851 return LDB_ERR_OPERATIONS_ERROR;
854 if (handle->state == LDB_ASYNC_DONE) {
855 return handle->status;
858 handle->state = LDB_ASYNC_PENDING;
859 handle->status = LDB_SUCCESS;
861 ac = talloc_get_type(handle->private_data, struct partition_context);
863 for (i=0; i < ac->num_requests; i++) {
864 ret = ldb_wait(ac->down_req[i]->handle, LDB_WAIT_NONE);
866 if (ret != LDB_SUCCESS) {
867 handle->status = ret;
870 if (ac->down_req[i]->handle->status != LDB_SUCCESS) {
871 handle->status = ac->down_req[i]->handle->status;
875 if (ac->down_req[i]->handle->state != LDB_ASYNC_DONE) {
883 handle->state = LDB_ASYNC_DONE;
888 static int partition_wait_all(struct ldb_handle *handle) {
892 while (handle->state != LDB_ASYNC_DONE) {
893 ret = partition_wait_none(handle);
894 if (ret != LDB_SUCCESS) {
899 return handle->status;
902 static int partition_wait(struct ldb_handle *handle, enum ldb_wait_type type)
904 if (type == LDB_WAIT_ALL) {
905 return partition_wait_all(handle);
907 return partition_wait_none(handle);
911 static const struct ldb_module_ops partition_ops = {
913 .init_context = partition_init,
914 .search = partition_search,
915 .add = partition_add,
916 .modify = partition_modify,
917 .del = partition_delete,
918 .rename = partition_rename,
919 .extended = partition_extended,
920 .sequence_number = partition_sequence_number,
921 .start_transaction = partition_start_trans,
922 .end_transaction = partition_end_trans,
923 .del_transaction = partition_del_trans,
924 .wait = partition_wait
927 int ldb_partition_init(void)
929 return ldb_register_module(&partition_ops);