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"
41 struct dsdb_control_current_partition {
42 struct ldb_module *module;
46 struct partition_private_data {
47 struct dsdb_control_current_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 dsdb_control_current_partition **pp1 = void1;
613 struct dsdb_control_current_partition **pp2 = void2;
614 struct dsdb_control_current_partition *partition1 = talloc_get_type(*pp1,
615 struct dsdb_control_current_partition);
616 struct dsdb_control_current_partition *partition2 = talloc_get_type(*pp2,
617 struct dsdb_control_current_partition);
619 return ldb_dn_compare(partition1->dn, partition2->dn);
622 static int partition_init(struct ldb_module *module)
625 TALLOC_CTX *mem_ctx = talloc_new(module);
626 static const char *attrs[] = { "partition", "replicateEntries", "modules", NULL };
627 struct ldb_result *res;
628 struct ldb_message *msg;
629 struct ldb_message_element *partition_attributes;
630 struct ldb_message_element *replicate_attributes;
631 struct ldb_message_element *modules_attributes;
633 struct partition_private_data *data;
636 return LDB_ERR_OPERATIONS_ERROR;
639 data = talloc(mem_ctx, struct partition_private_data);
641 return LDB_ERR_OPERATIONS_ERROR;
644 ret = ldb_search(module->ldb, ldb_dn_new(mem_ctx, module->ldb, "@PARTITION"),
648 if (ret != LDB_SUCCESS) {
649 talloc_free(mem_ctx);
652 talloc_steal(mem_ctx, res);
653 if (res->count == 0) {
654 talloc_free(mem_ctx);
655 return ldb_next_init(module);
658 if (res->count > 1) {
659 talloc_free(mem_ctx);
660 return LDB_ERR_CONSTRAINT_VIOLATION;
665 partition_attributes = ldb_msg_find_element(msg, "partition");
666 if (!partition_attributes) {
667 ldb_set_errstring(module->ldb, "partition_init: no partitions specified");
668 talloc_free(mem_ctx);
669 return LDB_ERR_CONSTRAINT_VIOLATION;
671 data->partitions = talloc_array(data, struct dsdb_control_current_partition *, partition_attributes->num_values + 1);
672 if (!data->partitions) {
673 talloc_free(mem_ctx);
674 return LDB_ERR_OPERATIONS_ERROR;
676 for (i=0; i < partition_attributes->num_values; i++) {
677 char *base = talloc_strdup(data->partitions, (char *)partition_attributes->values[i].data);
678 char *p = strchr(base, ':');
680 ldb_asprintf_errstring(module->ldb,
682 "invalid form for partition record (missing ':'): %s", base);
683 talloc_free(mem_ctx);
684 return LDB_ERR_CONSTRAINT_VIOLATION;
689 ldb_asprintf_errstring(module->ldb,
691 "invalid form for partition record (missing backend database): %s", base);
692 talloc_free(mem_ctx);
693 return LDB_ERR_CONSTRAINT_VIOLATION;
695 data->partitions[i] = talloc(data->partitions, struct dsdb_control_current_partition);
696 if (!data->partitions[i]) {
697 talloc_free(mem_ctx);
698 return LDB_ERR_OPERATIONS_ERROR;
701 data->partitions[i]->dn = ldb_dn_new(data->partitions[i], module->ldb, base);
702 if (!data->partitions[i]->dn) {
703 ldb_asprintf_errstring(module->ldb,
704 "partition_init: invalid DN in partition record: %s", base);
705 talloc_free(mem_ctx);
706 return LDB_ERR_CONSTRAINT_VIOLATION;
709 data->partitions[i]->backend = private_path(data->partitions[i], p);
710 ret = ldb_connect_backend(module->ldb, data->partitions[i]->backend, NULL, &data->partitions[i]->module);
711 if (ret != LDB_SUCCESS) {
712 talloc_free(mem_ctx);
716 data->partitions[i] = NULL;
718 /* sort these into order, most to least specific */
719 ldb_qsort(data->partitions, partition_attributes->num_values, sizeof(*data->partitions),
720 module->ldb, sort_compare);
722 for (i=0; data->partitions[i]; i++) {
723 struct ldb_request *req;
724 req = talloc_zero(mem_ctx, struct ldb_request);
726 ldb_debug(module->ldb, LDB_DEBUG_ERROR, "partition: Out of memory!\n");
727 talloc_free(mem_ctx);
728 return LDB_ERR_OPERATIONS_ERROR;
731 req->operation = LDB_REQ_REGISTER_PARTITION;
732 req->op.reg_partition.dn = data->partitions[i]->dn;
734 ret = ldb_request(module->ldb, req);
735 if (ret != LDB_SUCCESS) {
736 ldb_debug(module->ldb, LDB_DEBUG_ERROR, "partition: Unable to register partition with rootdse!\n");
737 talloc_free(mem_ctx);
738 return LDB_ERR_OTHER;
743 replicate_attributes = ldb_msg_find_element(msg, "replicateEntries");
744 if (!replicate_attributes) {
745 data->replicate = NULL;
747 data->replicate = talloc_array(data, struct ldb_dn *, replicate_attributes->num_values + 1);
748 if (!data->replicate) {
749 talloc_free(mem_ctx);
750 return LDB_ERR_OPERATIONS_ERROR;
753 for (i=0; i < replicate_attributes->num_values; i++) {
754 data->replicate[i] = ldb_dn_new(data->replicate, module->ldb, (const char *)replicate_attributes->values[i].data);
755 if (!ldb_dn_validate(data->replicate[i])) {
756 ldb_asprintf_errstring(module->ldb,
758 "invalid DN in partition replicate record: %s",
759 replicate_attributes->values[i].data);
760 talloc_free(mem_ctx);
761 return LDB_ERR_CONSTRAINT_VIOLATION;
764 data->replicate[i] = NULL;
767 /* Make the private data available to any searches the modules may trigger in initialisation */
768 module->private_data = data;
769 talloc_steal(module, data);
771 modules_attributes = ldb_msg_find_element(msg, "modules");
772 if (modules_attributes) {
773 for (i=0; i < modules_attributes->num_values; i++) {
774 struct ldb_dn *base_dn;
776 struct dsdb_control_current_partition *partition = NULL;
777 const char **modules = NULL;
779 char *base = talloc_strdup(data->partitions, (char *)modules_attributes->values[i].data);
780 char *p = strchr(base, ':');
782 ldb_asprintf_errstring(module->ldb,
784 "invalid form for partition module record (missing ':'): %s", base);
785 talloc_free(mem_ctx);
786 return LDB_ERR_CONSTRAINT_VIOLATION;
791 ldb_asprintf_errstring(module->ldb,
793 "invalid form for partition module record (missing backend database): %s", base);
794 talloc_free(mem_ctx);
795 return LDB_ERR_CONSTRAINT_VIOLATION;
798 modules = ldb_modules_list_from_string(module->ldb, mem_ctx,
801 base_dn = ldb_dn_new(mem_ctx, module->ldb, base);
802 if (!ldb_dn_validate(base_dn)) {
803 talloc_free(mem_ctx);
804 return LDB_ERR_OPERATIONS_ERROR;
807 for (partition_idx = 0; data->partitions[partition_idx]; partition_idx++) {
808 if (ldb_dn_compare(data->partitions[partition_idx]->dn, base_dn) == 0) {
809 partition = data->partitions[partition_idx];
815 ldb_asprintf_errstring(module->ldb,
817 "invalid form for partition module record (no such partition): %s", base);
818 talloc_free(mem_ctx);
819 return LDB_ERR_CONSTRAINT_VIOLATION;
822 ret = ldb_load_modules_list(module->ldb, modules, partition->module, &partition->module);
823 if (ret != LDB_SUCCESS) {
824 ldb_asprintf_errstring(module->ldb,
826 "loading backend for %s failed: %s",
827 base, ldb_errstring(module->ldb));
828 talloc_free(mem_ctx);
831 ret = ldb_init_module_chain(module->ldb, partition->module);
832 if (ret != LDB_SUCCESS) {
833 ldb_asprintf_errstring(module->ldb,
835 "initialising backend for %s failed: %s",
836 base, ldb_errstring(module->ldb));
837 talloc_free(mem_ctx);
843 talloc_free(mem_ctx);
844 return ldb_next_init(module);
847 static int partition_wait_none(struct ldb_handle *handle) {
848 struct partition_context *ac;
852 if (!handle || !handle->private_data) {
853 return LDB_ERR_OPERATIONS_ERROR;
856 if (handle->state == LDB_ASYNC_DONE) {
857 return handle->status;
860 handle->state = LDB_ASYNC_PENDING;
861 handle->status = LDB_SUCCESS;
863 ac = talloc_get_type(handle->private_data, struct partition_context);
865 for (i=0; i < ac->num_requests; i++) {
866 ret = ldb_wait(ac->down_req[i]->handle, LDB_WAIT_NONE);
868 if (ret != LDB_SUCCESS) {
869 handle->status = ret;
872 if (ac->down_req[i]->handle->status != LDB_SUCCESS) {
873 handle->status = ac->down_req[i]->handle->status;
877 if (ac->down_req[i]->handle->state != LDB_ASYNC_DONE) {
885 handle->state = LDB_ASYNC_DONE;
890 static int partition_wait_all(struct ldb_handle *handle) {
894 while (handle->state != LDB_ASYNC_DONE) {
895 ret = partition_wait_none(handle);
896 if (ret != LDB_SUCCESS) {
901 return handle->status;
904 static int partition_wait(struct ldb_handle *handle, enum ldb_wait_type type)
906 if (type == LDB_WAIT_ALL) {
907 return partition_wait_all(handle);
909 return partition_wait_none(handle);
913 static const struct ldb_module_ops partition_ops = {
915 .init_context = partition_init,
916 .search = partition_search,
917 .add = partition_add,
918 .modify = partition_modify,
919 .del = partition_delete,
920 .rename = partition_rename,
921 .extended = partition_extended,
922 .sequence_number = partition_sequence_number,
923 .start_transaction = partition_start_trans,
924 .end_transaction = partition_end_trans,
925 .del_transaction = partition_del_trans,
926 .wait = partition_wait
929 int ldb_partition_init(void)
931 return ldb_register_module(&partition_ops);