4 Copyright (C) Andrew Tridgell 2004
5 Copyright (C) Stefan Metzmacher 2004
6 Copyright (C) Simo Sorce 2006
9 ** NOTE! The following LGPL license applies to the ldb
10 ** library. This does NOT imply that all of Samba is released
13 This library is free software; you can redistribute it and/or
14 modify it under the terms of the GNU Lesser General Public
15 License as published by the Free Software Foundation; either
16 version 2 of the License, or (at your option) any later version.
18 This library is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 Lesser General Public License for more details.
23 You should have received a copy of the GNU Lesser General Public
24 License along with this library; if not, write to the Free Software
25 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 * Component: ldb tdb backend
33 * Description: core functions for tdb backend
35 * Author: Andrew Tridgell
36 * Author: Stefan Metzmacher
40 * - description: make the module use asyncronous calls
46 #include "ldb/include/includes.h"
48 #include "ldb/ldb_tdb/ldb_tdb.h"
52 map a tdb error code to a ldb error code
54 static int ltdb_err_map(enum TDB_ERROR tdb_code)
62 return LDB_ERR_OPERATIONS_ERROR;
64 return LDB_ERR_PROTOCOL_ERROR;
68 case TDB_ERR_LOCK_TIMEOUT:
69 return LDB_ERR_TIME_LIMIT_EXCEEDED;
71 return LDB_ERR_ENTRY_ALREADY_EXISTS;
73 return LDB_ERR_NO_SUCH_OBJECT;
75 return LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS;
81 struct ldb_handle *init_ltdb_handle(struct ltdb_private *ltdb, struct ldb_module *module,
83 int (*callback)(struct ldb_context *, void *, struct ldb_reply *))
85 struct ltdb_context *ac;
88 h = talloc_zero(ltdb, struct ldb_handle);
90 ldb_set_errstring(module->ldb, "Out of Memory");
96 ac = talloc_zero(h, struct ltdb_context);
98 ldb_set_errstring(module->ldb, "Out of Memory");
103 h->private_data = (void *)ac;
105 h->state = LDB_ASYNC_INIT;
106 h->status = LDB_SUCCESS;
109 ac->context = context;
110 ac->callback = callback;
116 form a TDB_DATA for a record key
119 note that the key for a record can depend on whether the
120 dn refers to a case sensitive index record or not
122 struct TDB_DATA ltdb_key(struct ldb_module *module, const struct ldb_dn *dn)
124 struct ldb_context *ldb = module->ldb;
126 char *key_str = NULL;
127 char *dn_folded = NULL;
130 most DNs are case insensitive. The exception is index DNs for
131 case sensitive attributes
133 there are 3 cases dealt with in this code:
135 1) if the dn doesn't start with @ then uppercase the attribute
136 names and the attributes values of case insensitive attributes
137 2) if the dn starts with @ then leave it alone - the indexing code handles
141 dn_folded = ldb_dn_linearize_casefold(ldb, dn);
146 key_str = talloc_asprintf(ldb, "DN=%s", dn_folded);
148 talloc_free(dn_folded);
154 key.dptr = (uint8_t *)key_str;
155 key.dsize = strlen(key_str) + 1;
167 check special dn's have valid attributes
168 currently only @ATTRIBUTES is checked
170 int ltdb_check_special_dn(struct ldb_module *module, const struct ldb_message *msg)
174 if (! ldb_dn_is_special(msg->dn) ||
175 ! ldb_dn_check_special(msg->dn, LTDB_ATTRIBUTES)) {
179 /* we have @ATTRIBUTES, let's check attributes are fine */
180 /* should we check that we deny multivalued attributes ? */
181 for (i = 0; i < msg->num_elements; i++) {
182 for (j = 0; j < msg->elements[i].num_values; j++) {
183 if (ltdb_check_at_attributes_values(&msg->elements[i].values[j]) != 0) {
184 ldb_set_errstring(module->ldb, "Invalid attribute value in an @ATTRIBUTES entry");
185 return LDB_ERR_INVALID_ATTRIBUTE_SYNTAX;
195 we've made a modification to a dn - possibly reindex and
196 update sequence number
198 static int ltdb_modified(struct ldb_module *module, const struct ldb_dn *dn)
202 if (ldb_dn_is_special(dn) &&
203 (ldb_dn_check_special(dn, LTDB_INDEXLIST) ||
204 ldb_dn_check_special(dn, LTDB_ATTRIBUTES)) ) {
205 ret = ltdb_reindex(module);
209 !(ldb_dn_is_special(dn) &&
210 ldb_dn_check_special(dn, LTDB_BASEINFO)) ) {
211 ret = ltdb_increase_sequence_number(module);
218 store a record into the db
220 int ltdb_store(struct ldb_module *module, const struct ldb_message *msg, int flgs)
222 struct ltdb_private *ltdb = module->private_data;
223 TDB_DATA tdb_key, tdb_data;
226 tdb_key = ltdb_key(module, msg->dn);
228 return LDB_ERR_OTHER;
231 ret = ltdb_pack_data(module, msg, &tdb_data);
233 talloc_free(tdb_key.dptr);
234 return LDB_ERR_OTHER;
237 ret = tdb_store(ltdb->tdb, tdb_key, tdb_data, flgs);
239 ret = ltdb_err_map(tdb_error(ltdb->tdb));
243 ret = ltdb_index_add(module, msg);
245 tdb_delete(ltdb->tdb, tdb_key);
249 talloc_free(tdb_key.dptr);
250 talloc_free(tdb_data.dptr);
256 static int ltdb_add_internal(struct ldb_module *module, const struct ldb_message *msg)
261 ret = ltdb_check_special_dn(module, msg);
262 if (ret != LDB_SUCCESS) {
266 if (ltdb_cache_load(module) != 0) {
267 return LDB_ERR_OPERATIONS_ERROR;
270 ret = ltdb_store(module, msg, TDB_INSERT);
272 if (ret == LDB_ERR_ENTRY_ALREADY_EXISTS) {
275 dn = ldb_dn_linearize(module, msg->dn);
279 ldb_asprintf_errstring(module->ldb, "Entry %s already exists", dn);
284 if (ret == LDB_SUCCESS) {
285 ret = ltdb_modified(module, msg->dn);
286 if (ret != LDB_SUCCESS) {
287 return LDB_ERR_OPERATIONS_ERROR;
295 add a record to the database
297 static int ltdb_add(struct ldb_module *module, struct ldb_request *req)
299 struct ltdb_private *ltdb = talloc_get_type(module->private_data, struct ltdb_private);
300 struct ltdb_context *ltdb_ac;
301 int tret, ret = LDB_SUCCESS;
303 if (req->controls != NULL) {
304 ldb_debug(module->ldb, LDB_DEBUG_WARNING, "Controls should not reach the ldb_tdb backend!\n");
305 if (check_critical_controls(req->controls)) {
306 return LDB_ERR_UNSUPPORTED_CRITICAL_EXTENSION;
310 req->handle = init_ltdb_handle(ltdb, module, req->context, req->callback);
311 if (req->handle == NULL) {
312 return LDB_ERR_OPERATIONS_ERROR;
314 ltdb_ac = talloc_get_type(req->handle->private_data, struct ltdb_context);
316 tret = ltdb_add_internal(module, req->op.add.message);
317 if (tret != LDB_SUCCESS) {
318 req->handle->status = tret;
322 if (ltdb_ac->callback) {
323 ret = ltdb_ac->callback(module->ldb, ltdb_ac->context, NULL);
326 req->handle->state = LDB_ASYNC_DONE;
331 delete a record from the database, not updating indexes (used for deleting
334 int ltdb_delete_noindex(struct ldb_module *module, const struct ldb_dn *dn)
336 struct ltdb_private *ltdb = module->private_data;
340 tdb_key = ltdb_key(module, dn);
342 return LDB_ERR_OTHER;
345 ret = tdb_delete(ltdb->tdb, tdb_key);
346 talloc_free(tdb_key.dptr);
349 ret = ltdb_err_map(tdb_error(ltdb->tdb));
355 static int ltdb_delete_internal(struct ldb_module *module, const struct ldb_dn *dn)
357 struct ldb_message *msg;
360 msg = talloc(module, struct ldb_message);
362 return LDB_ERR_OPERATIONS_ERROR;
365 /* in case any attribute of the message was indexed, we need
366 to fetch the old record */
367 ret = ltdb_search_dn1(module, dn, msg);
369 /* not finding the old record is an error */
371 return LDB_ERR_NO_SUCH_OBJECT;
374 ret = ltdb_delete_noindex(module, dn);
375 if (ret != LDB_SUCCESS) {
377 return LDB_ERR_NO_SUCH_OBJECT;
380 /* remove any indexed attributes */
381 ret = ltdb_index_del(module, msg);
382 if (ret != LDB_SUCCESS) {
384 return LDB_ERR_OPERATIONS_ERROR;
387 ret = ltdb_modified(module, dn);
388 if (ret != LDB_SUCCESS) {
389 return LDB_ERR_OPERATIONS_ERROR;
397 delete a record from the database
399 static int ltdb_delete(struct ldb_module *module, struct ldb_request *req)
401 struct ltdb_private *ltdb = talloc_get_type(module->private_data, struct ltdb_private);
402 struct ltdb_context *ltdb_ac;
403 int tret, ret = LDB_SUCCESS;
405 if (req->controls != NULL) {
406 ldb_debug(module->ldb, LDB_DEBUG_WARNING, "Controls should not reach the ldb_tdb backend!\n");
407 if (check_critical_controls(req->controls)) {
408 return LDB_ERR_UNSUPPORTED_CRITICAL_EXTENSION;
414 if (ltdb_cache_load(module) != 0) {
415 return LDB_ERR_OPERATIONS_ERROR;
418 req->handle = init_ltdb_handle(ltdb, module, req->context, req->callback);
419 if (req->handle == NULL) {
420 return LDB_ERR_OPERATIONS_ERROR;
422 ltdb_ac = talloc_get_type(req->handle->private_data, struct ltdb_context);
424 tret = ltdb_delete_internal(module, req->op.del.dn);
425 if (tret != LDB_SUCCESS) {
426 req->handle->status = tret;
430 if (ltdb_ac->callback) {
431 ret = ltdb_ac->callback(module->ldb, ltdb_ac->context, NULL);
434 req->handle->state = LDB_ASYNC_DONE;
439 find an element by attribute name. At the moment this does a linear search, it should
440 be re-coded to use a binary search once all places that modify records guarantee
443 return the index of the first matching element if found, otherwise -1
445 static int find_element(const struct ldb_message *msg, const char *name)
448 for (i=0;i<msg->num_elements;i++) {
449 if (ldb_attr_cmp(msg->elements[i].name, name) == 0) {
458 add an element to an existing record. Assumes a elements array that we
459 can call re-alloc on, and assumed that we can re-use the data pointers from the
460 passed in additional values. Use with care!
462 returns 0 on success, -1 on failure (and sets errno)
464 static int msg_add_element(struct ldb_context *ldb,
465 struct ldb_message *msg, struct ldb_message_element *el)
467 struct ldb_message_element *e2;
470 e2 = talloc_realloc(msg, msg->elements, struct ldb_message_element,
471 msg->num_elements+1);
479 e2 = &msg->elements[msg->num_elements];
482 e2->flags = el->flags;
484 if (el->num_values != 0) {
485 e2->values = talloc_array(msg->elements, struct ldb_val, el->num_values);
491 for (i=0;i<el->num_values;i++) {
492 e2->values[i] = el->values[i];
494 e2->num_values = el->num_values;
502 delete all elements having a specified attribute name
504 static int msg_delete_attribute(struct ldb_module *module,
505 struct ldb_context *ldb,
506 struct ldb_message *msg, const char *name)
511 dn = ldb_dn_linearize(ldb, msg->dn);
516 for (i=0;i<msg->num_elements;i++) {
517 if (ldb_attr_cmp(msg->elements[i].name, name) == 0) {
518 for (j=0;j<msg->elements[i].num_values;j++) {
519 ltdb_index_del_value(module, dn, &msg->elements[i], j);
521 talloc_free(msg->elements[i].values);
522 if (msg->num_elements > (i+1)) {
523 memmove(&msg->elements[i],
525 sizeof(struct ldb_message_element)*
526 (msg->num_elements - (i+1)));
530 msg->elements = talloc_realloc(msg, msg->elements,
531 struct ldb_message_element,
541 delete all elements matching an attribute name/value
543 return 0 on success, -1 on failure
545 static int msg_delete_element(struct ldb_module *module,
546 struct ldb_message *msg,
548 const struct ldb_val *val)
550 struct ldb_context *ldb = module->ldb;
553 struct ldb_message_element *el;
554 const struct ldb_attrib_handler *h;
556 found = find_element(msg, name);
561 el = &msg->elements[found];
563 h = ldb_attrib_handler(ldb, el->name);
565 for (i=0;i<el->num_values;i++) {
566 if (h->comparison_fn(ldb, ldb, &el->values[i], val) == 0) {
567 if (i<el->num_values-1) {
568 memmove(&el->values[i], &el->values[i+1],
569 sizeof(el->values[i])*(el->num_values-(i+1)));
572 if (el->num_values == 0) {
573 return msg_delete_attribute(module, ldb, msg, name);
584 modify a record - internal interface
586 yuck - this is O(n^2). Luckily n is usually small so we probably
587 get away with it, but if we ever have really large attribute lists
588 then we'll need to look at this again
590 int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *msg)
592 struct ldb_context *ldb = module->ldb;
593 struct ltdb_private *ltdb = module->private_data;
594 TDB_DATA tdb_key, tdb_data;
595 struct ldb_message *msg2;
599 tdb_key = ltdb_key(module, msg->dn);
601 return LDB_ERR_OTHER;
604 tdb_data = tdb_fetch(ltdb->tdb, tdb_key);
605 if (!tdb_data.dptr) {
606 talloc_free(tdb_key.dptr);
607 return ltdb_err_map(tdb_error(ltdb->tdb));
610 msg2 = talloc(tdb_key.dptr, struct ldb_message);
612 talloc_free(tdb_key.dptr);
613 return LDB_ERR_OTHER;
616 ret = ltdb_unpack_data(module, &tdb_data, msg2);
626 for (i=0;i<msg->num_elements;i++) {
627 struct ldb_message_element *el = &msg->elements[i];
628 struct ldb_message_element *el2;
629 struct ldb_val *vals;
632 switch (msg->elements[i].flags & LDB_FLAG_MOD_MASK) {
634 case LDB_FLAG_MOD_ADD:
635 /* add this element to the message. fail if it
637 ret = find_element(msg2, el->name);
640 if (msg_add_element(ldb, msg2, el) != 0) {
647 el2 = &msg2->elements[ret];
649 /* An attribute with this name already exists, add all
650 * values if they don't already exist. */
652 for (j=0;j<el->num_values;j++) {
653 if (ldb_msg_find_val(el2, &el->values[j])) {
654 ldb_set_errstring(module->ldb, "Type or value exists");
655 ret = LDB_ERR_ATTRIBUTE_OR_VALUE_EXISTS;
660 vals = talloc_realloc(msg2->elements, el2->values, struct ldb_val,
661 el2->num_values + el->num_values);
668 for (j=0;j<el->num_values;j++) {
669 vals[el2->num_values + j] =
670 ldb_val_dup(vals, &el->values[j]);
674 el2->num_values += el->num_values;
678 case LDB_FLAG_MOD_REPLACE:
679 /* replace all elements of this attribute name with the elements
680 listed. The attribute not existing is not an error */
681 msg_delete_attribute(module, ldb, msg2, msg->elements[i].name);
683 /* add the replacement element, if not empty */
684 if (msg->elements[i].num_values != 0 &&
685 msg_add_element(ldb, msg2, &msg->elements[i]) != 0) {
691 case LDB_FLAG_MOD_DELETE:
693 dn = ldb_dn_linearize(msg2, msg->dn);
699 /* we could be being asked to delete all
700 values or just some values */
701 if (msg->elements[i].num_values == 0) {
702 if (msg_delete_attribute(module, ldb, msg2,
703 msg->elements[i].name) != 0) {
704 ldb_asprintf_errstring(module->ldb, "No such attribute: %s for delete on %s", msg->elements[i].name, dn);
705 ret = LDB_ERR_NO_SUCH_ATTRIBUTE;
710 for (j=0;j<msg->elements[i].num_values;j++) {
711 if (msg_delete_element(module,
713 msg->elements[i].name,
714 &msg->elements[i].values[j]) != 0) {
715 ldb_asprintf_errstring(module->ldb, "No matching attribute value when deleting attribute: %s on %s", msg->elements[i].name, dn);
716 ret = LDB_ERR_NO_SUCH_ATTRIBUTE;
719 if (ltdb_index_del_value(module, dn, &msg->elements[i], j) != 0) {
726 ldb_asprintf_errstring(module->ldb, "Invalid ldb_modify flags on %s: 0x%x",
727 msg->elements[i].name,
728 msg->elements[i].flags & LDB_FLAG_MOD_MASK);
729 ret = LDB_ERR_PROTOCOL_ERROR;
734 /* we've made all the mods - save the modified record back into the database */
735 ret = ltdb_store(module, msg2, TDB_MODIFY);
736 if (ret != LDB_SUCCESS) {
740 if (ltdb_modified(module, msg->dn) != LDB_SUCCESS) {
741 ret = LDB_ERR_OPERATIONS_ERROR;
745 talloc_free(tdb_key.dptr);
750 talloc_free(tdb_key.dptr);
758 static int ltdb_modify(struct ldb_module *module, struct ldb_request *req)
760 struct ltdb_private *ltdb = talloc_get_type(module->private_data, struct ltdb_private);
761 struct ltdb_context *ltdb_ac;
762 int tret, ret = LDB_SUCCESS;
764 if (req->controls != NULL) {
765 ldb_debug(module->ldb, LDB_DEBUG_WARNING, "Controls should not reach the ldb_tdb backend!\n");
766 if (check_critical_controls(req->controls)) {
767 return LDB_ERR_UNSUPPORTED_CRITICAL_EXTENSION;
773 req->handle = init_ltdb_handle(ltdb, module, req->context, req->callback);
774 if (req->handle == NULL) {
775 return LDB_ERR_OPERATIONS_ERROR;
777 ltdb_ac = talloc_get_type(req->handle->private_data, struct ltdb_context);
779 tret = ltdb_check_special_dn(module, req->op.mod.message);
780 if (tret != LDB_SUCCESS) {
781 req->handle->status = tret;
785 if (ltdb_cache_load(module) != 0) {
786 ret = LDB_ERR_OPERATIONS_ERROR;
790 tret = ltdb_modify_internal(module, req->op.mod.message);
791 if (tret != LDB_SUCCESS) {
792 req->handle->status = tret;
796 if (ltdb_ac->callback) {
797 ret = ltdb_ac->callback(module->ldb, ltdb_ac->context, NULL);
800 req->handle->state = LDB_ASYNC_DONE;
807 static int ltdb_rename(struct ldb_module *module, struct ldb_request *req)
809 struct ltdb_private *ltdb = talloc_get_type(module->private_data, struct ltdb_private);
810 struct ltdb_context *ltdb_ac;
811 struct ldb_message *msg;
812 int tret, ret = LDB_SUCCESS;
814 if (req->controls != NULL) {
815 ldb_debug(module->ldb, LDB_DEBUG_WARNING, "Controls should not reach the ldb_tdb backend!\n");
816 if (check_critical_controls(req->controls)) {
817 return LDB_ERR_UNSUPPORTED_CRITICAL_EXTENSION;
823 if (ltdb_cache_load(module) != 0) {
824 return LDB_ERR_OPERATIONS_ERROR;
827 req->handle = init_ltdb_handle(ltdb, module, req->context, req->callback);
828 if (req->handle == NULL) {
829 return LDB_ERR_OPERATIONS_ERROR;
831 ltdb_ac = talloc_get_type(req->handle->private_data, struct ltdb_context);
833 msg = talloc(ltdb_ac, struct ldb_message);
835 ret = LDB_ERR_OPERATIONS_ERROR;
839 /* in case any attribute of the message was indexed, we need
840 to fetch the old record */
841 tret = ltdb_search_dn1(module, req->op.rename.olddn, msg);
843 /* not finding the old record is an error */
844 req->handle->status = LDB_ERR_NO_SUCH_OBJECT;
848 msg->dn = ldb_dn_copy(msg, req->op.rename.newdn);
850 ret = LDB_ERR_OPERATIONS_ERROR;
854 tret = ltdb_add_internal(module, msg);
855 if (tret != LDB_SUCCESS) {
856 ret = LDB_ERR_OPERATIONS_ERROR;
860 tret = ltdb_delete_internal(module, req->op.rename.olddn);
861 if (tret != LDB_SUCCESS) {
862 ltdb_delete_internal(module, req->op.rename.newdn);
863 ret = LDB_ERR_OPERATIONS_ERROR;
867 if (ltdb_ac->callback) {
868 ret = ltdb_ac->callback(module->ldb, ltdb_ac->context, NULL);
871 req->handle->state = LDB_ASYNC_DONE;
875 static int ltdb_start_trans(struct ldb_module *module)
877 struct ltdb_private *ltdb = module->private_data;
879 if (tdb_transaction_start(ltdb->tdb) != 0) {
880 return ltdb_err_map(tdb_error(ltdb->tdb));
886 static int ltdb_end_trans(struct ldb_module *module)
888 struct ltdb_private *ltdb = module->private_data;
890 if (tdb_transaction_commit(ltdb->tdb) != 0) {
891 return ltdb_err_map(tdb_error(ltdb->tdb));
897 static int ltdb_del_trans(struct ldb_module *module)
899 struct ltdb_private *ltdb = module->private_data;
901 if (tdb_transaction_cancel(ltdb->tdb) != 0) {
902 return ltdb_err_map(tdb_error(ltdb->tdb));
908 static int ltdb_wait(struct ldb_handle *handle, enum ldb_wait_type type)
910 return handle->status;
913 static int ltdb_request(struct ldb_module *module, struct ldb_request *req)
915 /* check for oustanding critical controls and return an error if found */
916 if (req->controls != NULL) {
917 ldb_debug(module->ldb, LDB_DEBUG_WARNING, "Controls should not reach the ldb_tdb backend!\n");
918 if (check_critical_controls(req->controls)) {
919 return LDB_ERR_UNSUPPORTED_CRITICAL_EXTENSION;
923 /* search, add, modify, delete, rename are handled by their own, no other op supported */
924 return LDB_ERR_OPERATIONS_ERROR;
928 return sequenceNumber from @BASEINFO
930 static int ltdb_sequence_number(struct ldb_module *module, struct ldb_request *req)
932 TALLOC_CTX *tmp_ctx = talloc_new(req);
933 struct ldb_message *msg = NULL;
934 struct ldb_dn *dn = ldb_dn_explode(tmp_ctx, LTDB_BASEINFO);
937 if (tmp_ctx == NULL) {
938 talloc_free(tmp_ctx);
939 return LDB_ERR_OPERATIONS_ERROR;
942 msg = talloc(tmp_ctx, struct ldb_message);
944 talloc_free(tmp_ctx);
945 return LDB_ERR_OPERATIONS_ERROR;
948 tret = ltdb_search_dn1(module, dn, msg);
950 talloc_free(tmp_ctx);
951 req->op.seq_num.seq_num = 0;
952 /* zero is as good as anything when we don't know */
956 req->op.seq_num.seq_num = ldb_msg_find_attr_as_uint64(msg, LTDB_SEQUENCE_NUMBER, 0);
957 talloc_free(tmp_ctx);
961 static const struct ldb_module_ops ltdb_ops = {
963 .search = ltdb_search,
965 .modify = ltdb_modify,
967 .rename = ltdb_rename,
968 .request = ltdb_request,
969 .start_transaction = ltdb_start_trans,
970 .end_transaction = ltdb_end_trans,
971 .del_transaction = ltdb_del_trans,
973 .sequence_number = ltdb_sequence_number
977 connect to the database
979 static int ltdb_connect(struct ldb_context *ldb, const char *url,
980 unsigned int flags, const char *options[],
981 struct ldb_module **module)
984 int tdb_flags, open_flags;
985 struct ltdb_private *ltdb;
988 if (strchr(url, ':')) {
989 if (strncmp(url, "tdb://", 6) != 0) {
990 ldb_debug(ldb, LDB_DEBUG_ERROR, "Invalid tdb URL '%s'", url);
998 tdb_flags = TDB_DEFAULT;
1000 /* check for the 'nosync' option */
1001 if (flags & LDB_FLG_NOSYNC) {
1002 tdb_flags |= TDB_NOSYNC;
1005 if (flags & LDB_FLG_RDONLY) {
1006 open_flags = O_RDONLY;
1008 open_flags = O_CREAT | O_RDWR;
1011 ltdb = talloc_zero(ldb, struct ltdb_private);
1017 /* note that we use quite a large default hash size */
1018 ltdb->tdb = ltdb_wrap_open(ltdb, path, 10000,
1019 tdb_flags, open_flags, 0666, ldb);
1021 ldb_debug(ldb, LDB_DEBUG_ERROR, "Unable to open tdb '%s'\n", path);
1026 ltdb->sequence_number = 0;
1028 *module = talloc(ldb, struct ldb_module);
1034 (*module)->ldb = ldb;
1035 (*module)->prev = (*module)->next = NULL;
1036 (*module)->private_data = ltdb;
1037 (*module)->ops = <db_ops;
1042 int ldb_tdb_init(void)
1044 return ldb_register_backend("tdb", ltdb_connect);