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 partition_private_data {
42 struct dsdb_control_current_partition **partitions;
43 struct ldb_dn **replicate;
46 struct partition_context {
47 struct ldb_module *module;
48 struct ldb_handle *handle;
49 struct ldb_request *orig_req;
51 struct ldb_request **down_req;
53 int finished_requests;
56 static struct partition_context *partition_init_handle(struct ldb_request *req, struct ldb_module *module)
58 struct partition_context *ac;
61 h = talloc_zero(req, struct ldb_handle);
63 ldb_set_errstring(module->ldb, "Out of Memory");
69 ac = talloc_zero(h, struct partition_context);
71 ldb_set_errstring(module->ldb, "Out of Memory");
87 static struct ldb_module *make_module_for_next_request(TALLOC_CTX *mem_ctx,
88 struct ldb_context *ldb,
89 struct ldb_module *module)
91 struct ldb_module *current;
92 static const struct ldb_module_ops ops; /* zero */
93 current = talloc_zero(mem_ctx, struct ldb_module);
94 if (current == NULL) {
100 current->prev = NULL;
101 current->next = module;
105 static struct dsdb_control_current_partition *find_partition(struct partition_private_data *data,
110 /* Look at base DN */
111 /* Figure out which partition it is under */
112 /* Skip the lot if 'data' isn't here yet (initialistion) */
113 for (i=0; data && data->partitions && data->partitions[i]; i++) {
114 if (ldb_dn_compare_base(data->partitions[i]->dn, dn) == 0) {
115 return data->partitions[i];
122 static struct ldb_module *find_backend(struct ldb_module *module, struct ldb_request *req, struct ldb_dn *dn)
124 struct dsdb_control_current_partition *partition;
125 struct partition_private_data *data = talloc_get_type(module->private_data,
126 struct partition_private_data);
128 /* Skip the lot if 'data' isn't here yet (initialistion) */
133 partition = find_partition(data, dn);
138 return make_module_for_next_request(req, module->ldb, partition->module);
143 fire the caller's callback for every entry, but only send 'done' once.
145 static int partition_search_callback(struct ldb_context *ldb, void *context, struct ldb_reply *ares)
147 struct partition_context *ac;
149 if (!context || !ares) {
150 ldb_set_errstring(ldb, "partition_search_callback: NULL Context or Result in 'search' callback");
154 ac = talloc_get_type(context, struct partition_context);
156 if (ares->type == LDB_REPLY_ENTRY) {
157 return ac->orig_req->callback(ldb, ac->orig_req->context, ares);
159 ac->finished_requests++;
160 if (ac->finished_requests == ac->num_requests) {
161 return ac->orig_req->callback(ldb, ac->orig_req->context, ares);
169 return LDB_ERR_OPERATIONS_ERROR;
173 only fire the 'last' callback, and only for START-TLS for now
175 static int partition_other_callback(struct ldb_context *ldb, void *context, struct ldb_reply *ares)
177 struct partition_context *ac;
180 ldb_set_errstring(ldb, "partition_other_callback: NULL Context in 'other' callback");
184 ac = talloc_get_type(context, struct partition_context);
186 if (!ac->orig_req->callback) {
192 || (ares->type == LDB_REPLY_EXTENDED
193 && strcmp(ares->response->oid, LDB_EXTENDED_START_TLS_OID))) {
194 ac->finished_requests++;
195 if (ac->finished_requests == ac->num_requests) {
196 return ac->orig_req->callback(ldb, ac->orig_req->context, ares);
201 ldb_set_errstring(ldb, "partition_other_callback: Unknown reply type, only supports START_TLS");
204 return LDB_ERR_OPERATIONS_ERROR;
208 static int partition_send_request(struct partition_context *ac, struct ldb_module *partition,
209 struct ldb_dn *partition_base_dn)
212 struct ldb_module *next = make_module_for_next_request(ac->module, ac->module->ldb, partition);
213 struct ldb_request *req;
214 ac->down_req = talloc_realloc(ac, ac->down_req,
215 struct ldb_request *, ac->num_requests + 1);
217 ldb_set_errstring(ac->module->ldb, "Out of Memory");
218 return LDB_ERR_OPERATIONS_ERROR;
220 req = ac->down_req[ac->num_requests] = talloc(ac, struct ldb_request);
222 ldb_set_errstring(ac->module->ldb, "Out of Memory");
223 return LDB_ERR_OPERATIONS_ERROR;
226 *ac->down_req[ac->num_requests] = *ac->orig_req; /* copy the request */
228 if (req->operation == LDB_SEARCH) {
229 /* If the search is for 'more' than this partition,
230 * then change the basedn, so a remote LDAP server
232 if (ldb_dn_compare_base(partition_base_dn, req->op.search.base) != 0) {
233 req->op.search.base = partition_base_dn;
235 req->callback = partition_search_callback;
238 req->callback = partition_other_callback;
242 /* Spray off search requests to all backends */
243 ret = ldb_next_request(next, req);
244 if (ret != LDB_SUCCESS) {
252 /* Send a request down to all the partitions */
253 static int partition_send_all(struct ldb_module *module,
254 struct partition_context *ac, struct ldb_request *req)
257 struct partition_private_data *data = talloc_get_type(module->private_data,
258 struct partition_private_data);
259 int ret = partition_send_request(ac, module->next, NULL);
260 if (ret != LDB_SUCCESS) {
263 for (i=0; data && data->partitions && data->partitions[i]; i++) {
264 ret = partition_send_request(ac, data->partitions[i]->module, data->partitions[i]->dn);
265 if (ret != LDB_SUCCESS) {
272 /* Figure out which backend a request needs to be aimed at. Some
273 * requests must be replicated to all backends */
274 static int partition_replicate(struct ldb_module *module, struct ldb_request *req, struct ldb_dn *dn)
277 struct ldb_module *backend;
278 struct partition_private_data *data = talloc_get_type(module->private_data,
279 struct partition_private_data);
281 /* Is this a special DN, we need to replicate to every backend? */
282 for (i=0; data->replicate && data->replicate[i]; i++) {
283 if (ldb_dn_compare(data->replicate[i],
285 struct partition_context *ac;
287 ac = partition_init_handle(req, module);
289 return LDB_ERR_OPERATIONS_ERROR;
292 return partition_send_all(module, ac, req);
296 /* Otherwise, we need to find the backend to fire it to */
299 backend = find_backend(module, req, dn);
302 return ldb_next_request(backend, req);
307 static int partition_search(struct ldb_module *module, struct ldb_request *req)
310 struct partition_private_data *data = talloc_get_type(module->private_data,
311 struct partition_private_data);
314 /* (later) consider if we should be searching multiple
315 * partitions (for 'invisible' partition behaviour */
316 if (ldb_get_opaque(module->ldb, "global_catalog")) {
318 struct partition_context *ac;
320 ac = partition_init_handle(req, module);
322 return LDB_ERR_OPERATIONS_ERROR;
325 /* Search from the base DN */
326 if (!req->op.search.base || ldb_dn_is_null(req->op.search.base)) {
327 return partition_send_all(module, ac, req);
329 for (i=0; data && data->partitions && data->partitions[i]; i++) {
330 /* Find all partitions under the search base */
331 if (ldb_dn_compare_base(req->op.search.base, data->partitions[i]->dn) == 0) {
332 ret = partition_send_request(ac, data->partitions[i]->module, data->partitions[i]->dn);
333 if (ret != LDB_SUCCESS) {
339 /* Perhaps we didn't match any partitions. Try the main partition, only */
340 if (ac->num_requests == 0) {
342 return ldb_next_request(module, req);
347 struct ldb_module *backend = find_backend(module, req, req->op.search.base);
349 return ldb_next_request(backend, req);
354 static int partition_add(struct ldb_module *module, struct ldb_request *req)
356 return partition_replicate(module, req, req->op.add.message->dn);
360 static int partition_modify(struct ldb_module *module, struct ldb_request *req)
362 return partition_replicate(module, req, req->op.mod.message->dn);
366 static int partition_delete(struct ldb_module *module, struct ldb_request *req)
368 return partition_replicate(module, req, req->op.del.dn);
372 static int partition_rename(struct ldb_module *module, struct ldb_request *req)
375 struct ldb_module *backend = find_backend(module, req, req->op.rename.olddn);
376 struct ldb_module *backend2 = find_backend(module, req, req->op.rename.newdn);
378 if (backend->next != backend2->next) {
379 return LDB_ERR_AFFECTS_MULTIPLE_DSAS;
382 return partition_replicate(module, req, req->op.rename.olddn);
385 /* start a transaction */
386 static int partition_start_trans(struct ldb_module *module)
389 struct partition_private_data *data = talloc_get_type(module->private_data,
390 struct partition_private_data);
391 /* Look at base DN */
392 /* Figure out which partition it is under */
393 /* Skip the lot if 'data' isn't here yet (initialistion) */
394 ret = ldb_next_start_trans(module);
395 if (ret != LDB_SUCCESS) {
399 for (i=0; data && data->partitions && data->partitions[i]; i++) {
400 struct ldb_module *next = make_module_for_next_request(module, module->ldb, data->partitions[i]->module);
402 ret = ldb_next_start_trans(next);
404 if (ret != LDB_SUCCESS) {
405 /* Back it out, if it fails on one */
406 for (i--; i >= 0; i--) {
407 next = make_module_for_next_request(module, module->ldb, data->partitions[i]->module);
408 ldb_next_del_trans(next);
417 /* end a transaction */
418 static int partition_end_trans(struct ldb_module *module)
420 int i, ret, ret2 = LDB_SUCCESS;
421 struct partition_private_data *data = talloc_get_type(module->private_data,
422 struct partition_private_data);
423 ret = ldb_next_end_trans(module);
424 if (ret != LDB_SUCCESS) {
428 /* Look at base DN */
429 /* Figure out which partition it is under */
430 /* Skip the lot if 'data' isn't here yet (initialistion) */
431 for (i=0; data && data->partitions && data->partitions[i]; i++) {
432 struct ldb_module *next = make_module_for_next_request(module, module->ldb, data->partitions[i]->module);
434 ret = ldb_next_end_trans(next);
436 if (ret != LDB_SUCCESS) {
441 if (ret != LDB_SUCCESS) {
442 /* Back it out, if it fails on one */
443 for (i=0; data && data->partitions && data->partitions[i]; i++) {
444 struct ldb_module *next = make_module_for_next_request(module, module->ldb, data->partitions[i]->module);
445 ldb_next_del_trans(next);
452 /* delete a transaction */
453 static int partition_del_trans(struct ldb_module *module)
455 int i, ret, ret2 = LDB_SUCCESS;
456 struct partition_private_data *data = talloc_get_type(module->private_data,
457 struct partition_private_data);
458 ret = ldb_next_del_trans(module);
459 if (ret != LDB_SUCCESS) {
463 /* Look at base DN */
464 /* Figure out which partition it is under */
465 /* Skip the lot if 'data' isn't here yet (initialistion) */
466 for (i=0; data && data->partitions && data->partitions[i]; i++) {
467 struct ldb_module *next = make_module_for_next_request(module, module->ldb, data->partitions[i]->module);
469 ret = ldb_next_del_trans(next);
471 if (ret != LDB_SUCCESS) {
478 static int partition_sequence_number(struct ldb_module *module, struct ldb_request *req)
481 uint64_t seq_number = 0;
482 uint64_t timestamp_sequence = 0;
483 uint64_t timestamp = 0;
484 struct partition_private_data *data = talloc_get_type(module->private_data,
485 struct partition_private_data);
487 switch (req->op.seq_num.type) {
489 case LDB_SEQ_HIGHEST_SEQ:
490 ret = ldb_next_request(module, req);
491 if (ret != LDB_SUCCESS) {
494 if (req->op.seq_num.flags & LDB_SEQ_TIMESTAMP_SEQUENCE) {
495 timestamp_sequence = req->op.seq_num.seq_num;
497 seq_number = seq_number + req->op.seq_num.seq_num;
500 /* Look at base DN */
501 /* Figure out which partition it is under */
502 /* Skip the lot if 'data' isn't here yet (initialistion) */
503 for (i=0; data && data->partitions && data->partitions[i]; i++) {
504 struct ldb_module *next = make_module_for_next_request(req, module->ldb, data->partitions[i]->module);
506 ret = ldb_next_request(next, req);
508 if (ret != LDB_SUCCESS) {
511 if (req->op.seq_num.flags & LDB_SEQ_TIMESTAMP_SEQUENCE) {
512 timestamp_sequence = MAX(timestamp_sequence, req->op.seq_num.seq_num);
514 seq_number = seq_number + req->op.seq_num.seq_num;
518 case LDB_SEQ_HIGHEST_TIMESTAMP:
520 struct ldb_request *date_req = talloc(req, struct ldb_request);
522 return LDB_ERR_OPERATIONS_ERROR;
525 date_req->op.seq_num.flags = LDB_SEQ_HIGHEST_TIMESTAMP;
527 ret = ldb_next_request(module, date_req);
528 if (ret != LDB_SUCCESS) {
531 timestamp = date_req->op.seq_num.seq_num;
533 /* Look at base DN */
534 /* Figure out which partition it is under */
535 /* Skip the lot if 'data' isn't here yet (initialistion) */
536 for (i=0; data && data->partitions && data->partitions[i]; i++) {
537 struct ldb_module *next = make_module_for_next_request(req, module->ldb, data->partitions[i]->module);
539 ret = ldb_next_request(next, date_req);
541 if (ret != LDB_SUCCESS) {
544 timestamp = MAX(timestamp, date_req->op.seq_num.seq_num);
550 switch (req->op.seq_num.flags) {
552 case LDB_SEQ_HIGHEST_SEQ:
554 req->op.seq_num.flags = 0;
556 /* Has someone above set a timebase sequence? */
557 if (timestamp_sequence) {
558 req->op.seq_num.seq_num = (((unsigned long long)timestamp << 24) | (seq_number & 0xFFFFFF));
560 req->op.seq_num.seq_num = seq_number;
563 if (timestamp_sequence > req->op.seq_num.seq_num) {
564 req->op.seq_num.seq_num = timestamp_sequence;
565 req->op.seq_num.flags |= LDB_SEQ_TIMESTAMP_SEQUENCE;
568 req->op.seq_num.flags |= LDB_SEQ_GLOBAL_SEQUENCE;
570 case LDB_SEQ_HIGHEST_TIMESTAMP:
571 req->op.seq_num.seq_num = timestamp;
575 switch (req->op.seq_num.flags) {
577 req->op.seq_num.seq_num++;
582 static int partition_extended_replicated_objects(struct ldb_module *module, struct ldb_request *req)
584 struct dsdb_extended_replicated_objects *ext;
586 ext = talloc_get_type(req->op.extended.data, struct dsdb_extended_replicated_objects);
588 ldb_debug(module->ldb, LDB_DEBUG_FATAL, "partition_extended_replicated_objects: invalid extended data\n");
589 return LDB_ERR_PROTOCOL_ERROR;
592 if (ext->version != DSDB_EXTENDED_REPLICATED_OBJECTS_VERSION) {
593 ldb_debug(module->ldb, LDB_DEBUG_FATAL, "partition_extended_replicated_objects: extended data invalid version [%u != %u]\n",
594 ext->version, DSDB_EXTENDED_REPLICATED_OBJECTS_VERSION);
595 return LDB_ERR_PROTOCOL_ERROR;
598 return partition_replicate(module, req, ext->partition_dn);
602 static int partition_extended(struct ldb_module *module, struct ldb_request *req)
604 struct partition_context *ac;
606 if (strcmp(req->op.extended.oid, DSDB_EXTENDED_REPLICATED_OBJECTS_OID) == 0) {
607 return partition_extended_replicated_objects(module, req);
611 * as the extended operation has no dn
612 * we need to send it to all partitions
615 ac = partition_init_handle(req, module);
617 return LDB_ERR_OPERATIONS_ERROR;
620 return partition_send_all(module, ac, req);
623 static int sort_compare(void *void1,
624 void *void2, void *opaque)
626 struct dsdb_control_current_partition **pp1 = void1;
627 struct dsdb_control_current_partition **pp2 = void2;
628 struct dsdb_control_current_partition *partition1 = talloc_get_type(*pp1,
629 struct dsdb_control_current_partition);
630 struct dsdb_control_current_partition *partition2 = talloc_get_type(*pp2,
631 struct dsdb_control_current_partition);
633 return ldb_dn_compare(partition1->dn, partition2->dn);
636 static int partition_init(struct ldb_module *module)
639 TALLOC_CTX *mem_ctx = talloc_new(module);
640 static const char *attrs[] = { "partition", "replicateEntries", "modules", NULL };
641 struct ldb_result *res;
642 struct ldb_message *msg;
643 struct ldb_message_element *partition_attributes;
644 struct ldb_message_element *replicate_attributes;
645 struct ldb_message_element *modules_attributes;
647 struct partition_private_data *data;
650 return LDB_ERR_OPERATIONS_ERROR;
653 data = talloc(mem_ctx, struct partition_private_data);
655 return LDB_ERR_OPERATIONS_ERROR;
658 ret = ldb_search(module->ldb, ldb_dn_new(mem_ctx, module->ldb, "@PARTITION"),
662 if (ret != LDB_SUCCESS) {
663 talloc_free(mem_ctx);
666 talloc_steal(mem_ctx, res);
667 if (res->count == 0) {
668 talloc_free(mem_ctx);
669 return ldb_next_init(module);
672 if (res->count > 1) {
673 talloc_free(mem_ctx);
674 return LDB_ERR_CONSTRAINT_VIOLATION;
679 partition_attributes = ldb_msg_find_element(msg, "partition");
680 if (!partition_attributes) {
681 ldb_set_errstring(module->ldb, "partition_init: no partitions specified");
682 talloc_free(mem_ctx);
683 return LDB_ERR_CONSTRAINT_VIOLATION;
685 data->partitions = talloc_array(data, struct dsdb_control_current_partition *, partition_attributes->num_values + 1);
686 if (!data->partitions) {
687 talloc_free(mem_ctx);
688 return LDB_ERR_OPERATIONS_ERROR;
690 for (i=0; i < partition_attributes->num_values; i++) {
691 char *base = talloc_strdup(data->partitions, (char *)partition_attributes->values[i].data);
692 char *p = strchr(base, ':');
694 ldb_asprintf_errstring(module->ldb,
696 "invalid form for partition record (missing ':'): %s", base);
697 talloc_free(mem_ctx);
698 return LDB_ERR_CONSTRAINT_VIOLATION;
703 ldb_asprintf_errstring(module->ldb,
705 "invalid form for partition record (missing backend database): %s", base);
706 talloc_free(mem_ctx);
707 return LDB_ERR_CONSTRAINT_VIOLATION;
709 data->partitions[i] = talloc(data->partitions, struct dsdb_control_current_partition);
710 if (!data->partitions[i]) {
711 talloc_free(mem_ctx);
712 return LDB_ERR_OPERATIONS_ERROR;
714 data->partitions[i]->version = DSDB_CONTROL_CURRENT_PARTITION_VERSION;
716 data->partitions[i]->dn = ldb_dn_new(data->partitions[i], module->ldb, base);
717 if (!data->partitions[i]->dn) {
718 ldb_asprintf_errstring(module->ldb,
719 "partition_init: invalid DN in partition record: %s", base);
720 talloc_free(mem_ctx);
721 return LDB_ERR_CONSTRAINT_VIOLATION;
724 data->partitions[i]->backend = private_path(data->partitions[i], p);
725 ret = ldb_connect_backend(module->ldb, data->partitions[i]->backend, NULL, &data->partitions[i]->module);
726 if (ret != LDB_SUCCESS) {
727 talloc_free(mem_ctx);
731 data->partitions[i] = NULL;
733 /* sort these into order, most to least specific */
734 ldb_qsort(data->partitions, partition_attributes->num_values, sizeof(*data->partitions),
735 module->ldb, sort_compare);
737 for (i=0; data->partitions[i]; i++) {
738 struct ldb_request *req;
739 req = talloc_zero(mem_ctx, struct ldb_request);
741 ldb_debug(module->ldb, LDB_DEBUG_ERROR, "partition: Out of memory!\n");
742 talloc_free(mem_ctx);
743 return LDB_ERR_OPERATIONS_ERROR;
746 req->operation = LDB_REQ_REGISTER_PARTITION;
747 req->op.reg_partition.dn = data->partitions[i]->dn;
749 ret = ldb_request(module->ldb, req);
750 if (ret != LDB_SUCCESS) {
751 ldb_debug(module->ldb, LDB_DEBUG_ERROR, "partition: Unable to register partition with rootdse!\n");
752 talloc_free(mem_ctx);
753 return LDB_ERR_OTHER;
758 replicate_attributes = ldb_msg_find_element(msg, "replicateEntries");
759 if (!replicate_attributes) {
760 data->replicate = NULL;
762 data->replicate = talloc_array(data, struct ldb_dn *, replicate_attributes->num_values + 1);
763 if (!data->replicate) {
764 talloc_free(mem_ctx);
765 return LDB_ERR_OPERATIONS_ERROR;
768 for (i=0; i < replicate_attributes->num_values; i++) {
769 data->replicate[i] = ldb_dn_new(data->replicate, module->ldb, (const char *)replicate_attributes->values[i].data);
770 if (!ldb_dn_validate(data->replicate[i])) {
771 ldb_asprintf_errstring(module->ldb,
773 "invalid DN in partition replicate record: %s",
774 replicate_attributes->values[i].data);
775 talloc_free(mem_ctx);
776 return LDB_ERR_CONSTRAINT_VIOLATION;
779 data->replicate[i] = NULL;
782 /* Make the private data available to any searches the modules may trigger in initialisation */
783 module->private_data = data;
784 talloc_steal(module, data);
786 modules_attributes = ldb_msg_find_element(msg, "modules");
787 if (modules_attributes) {
788 for (i=0; i < modules_attributes->num_values; i++) {
789 struct ldb_dn *base_dn;
791 struct dsdb_control_current_partition *partition = NULL;
792 const char **modules = NULL;
794 char *base = talloc_strdup(data->partitions, (char *)modules_attributes->values[i].data);
795 char *p = strchr(base, ':');
797 ldb_asprintf_errstring(module->ldb,
799 "invalid form for partition module record (missing ':'): %s", base);
800 talloc_free(mem_ctx);
801 return LDB_ERR_CONSTRAINT_VIOLATION;
806 ldb_asprintf_errstring(module->ldb,
808 "invalid form for partition module record (missing backend database): %s", base);
809 talloc_free(mem_ctx);
810 return LDB_ERR_CONSTRAINT_VIOLATION;
813 modules = ldb_modules_list_from_string(module->ldb, mem_ctx,
816 base_dn = ldb_dn_new(mem_ctx, module->ldb, base);
817 if (!ldb_dn_validate(base_dn)) {
818 talloc_free(mem_ctx);
819 return LDB_ERR_OPERATIONS_ERROR;
822 for (partition_idx = 0; data->partitions[partition_idx]; partition_idx++) {
823 if (ldb_dn_compare(data->partitions[partition_idx]->dn, base_dn) == 0) {
824 partition = data->partitions[partition_idx];
830 ldb_asprintf_errstring(module->ldb,
832 "invalid form for partition module record (no such partition): %s", base);
833 talloc_free(mem_ctx);
834 return LDB_ERR_CONSTRAINT_VIOLATION;
837 ret = ldb_load_modules_list(module->ldb, modules, partition->module, &partition->module);
838 if (ret != LDB_SUCCESS) {
839 ldb_asprintf_errstring(module->ldb,
841 "loading backend for %s failed: %s",
842 base, ldb_errstring(module->ldb));
843 talloc_free(mem_ctx);
846 ret = ldb_init_module_chain(module->ldb, partition->module);
847 if (ret != LDB_SUCCESS) {
848 ldb_asprintf_errstring(module->ldb,
850 "initialising backend for %s failed: %s",
851 base, ldb_errstring(module->ldb));
852 talloc_free(mem_ctx);
858 talloc_free(mem_ctx);
859 return ldb_next_init(module);
862 static int partition_wait_none(struct ldb_handle *handle) {
863 struct partition_context *ac;
867 if (!handle || !handle->private_data) {
868 return LDB_ERR_OPERATIONS_ERROR;
871 if (handle->state == LDB_ASYNC_DONE) {
872 return handle->status;
875 handle->state = LDB_ASYNC_PENDING;
876 handle->status = LDB_SUCCESS;
878 ac = talloc_get_type(handle->private_data, struct partition_context);
880 for (i=0; i < ac->num_requests; i++) {
881 ret = ldb_wait(ac->down_req[i]->handle, LDB_WAIT_NONE);
883 if (ret != LDB_SUCCESS) {
884 handle->status = ret;
887 if (ac->down_req[i]->handle->status != LDB_SUCCESS) {
888 handle->status = ac->down_req[i]->handle->status;
892 if (ac->down_req[i]->handle->state != LDB_ASYNC_DONE) {
900 handle->state = LDB_ASYNC_DONE;
905 static int partition_wait_all(struct ldb_handle *handle) {
909 while (handle->state != LDB_ASYNC_DONE) {
910 ret = partition_wait_none(handle);
911 if (ret != LDB_SUCCESS) {
916 return handle->status;
919 static int partition_wait(struct ldb_handle *handle, enum ldb_wait_type type)
921 if (type == LDB_WAIT_ALL) {
922 return partition_wait_all(handle);
924 return partition_wait_none(handle);
928 static const struct ldb_module_ops partition_ops = {
930 .init_context = partition_init,
931 .search = partition_search,
932 .add = partition_add,
933 .modify = partition_modify,
934 .del = partition_delete,
935 .rename = partition_rename,
936 .extended = partition_extended,
937 .sequence_number = partition_sequence_number,
938 .start_transaction = partition_start_trans,
939 .end_transaction = partition_end_trans,
940 .del_transaction = partition_del_trans,
941 .wait = partition_wait
944 int ldb_partition_init(void)
946 return ldb_register_module(&partition_ops);