3 * These headers or their equivalents should be included prior to
11 * This allows test applications to use custom definitions of C standard
12 * library functions and types.
24 #define TEVENT_DEPRECATED 1
28 #include <ldb_module.h>
29 #include <ldb_private.h>
36 #define DEFAULT_BE "tdb"
39 #define TEST_BE DEFAULT_BE
44 #include "../ldb_tdb/ldb_tdb.h"
45 #include "../ldb_mdb/ldb_mdb.h"
49 struct tevent_context
*ev
;
50 struct ldb_context
*ldb
;
53 const char *lockfile
; /* lockfile is separate */
59 static void unlink_old_db(struct ldbtest_ctx
*test_ctx
)
64 ret
= unlink(test_ctx
->lockfile
);
65 if (ret
== -1 && errno
!= ENOENT
) {
70 ret
= unlink(test_ctx
->dbfile
);
71 if (ret
== -1 && errno
!= ENOENT
) {
76 static int ldbtest_noconn_setup(void **state
)
78 struct ldbtest_ctx
*test_ctx
;
80 test_ctx
= talloc_zero(NULL
, struct ldbtest_ctx
);
81 assert_non_null(test_ctx
);
83 test_ctx
->ev
= tevent_context_init(test_ctx
);
84 assert_non_null(test_ctx
->ev
);
86 test_ctx
->ldb
= ldb_init(test_ctx
, test_ctx
->ev
);
87 assert_non_null(test_ctx
->ldb
);
89 test_ctx
->dbfile
= talloc_strdup(test_ctx
, "apitest.ldb");
90 assert_non_null(test_ctx
->dbfile
);
92 test_ctx
->lockfile
= talloc_asprintf(test_ctx
, "%s-lock",
94 assert_non_null(test_ctx
->lockfile
);
96 test_ctx
->dbpath
= talloc_asprintf(test_ctx
,
97 TEST_BE
"://%s", test_ctx
->dbfile
);
98 assert_non_null(test_ctx
->dbpath
);
100 unlink_old_db(test_ctx
);
105 static int ldbtest_noconn_teardown(void **state
)
107 struct ldbtest_ctx
*test_ctx
= talloc_get_type_abort(*state
,
110 unlink_old_db(test_ctx
);
111 talloc_free(test_ctx
);
115 static void test_connect(void **state
)
117 struct ldbtest_ctx
*test_ctx
= talloc_get_type_abort(*state
,
121 ret
= ldb_connect(test_ctx
->ldb
, test_ctx
->dbpath
, 0, NULL
);
122 assert_int_equal(ret
, 0);
125 static struct ldb_message
*get_test_ldb_message(TALLOC_CTX
*mem_ctx
,
126 struct ldb_context
*ldb
)
128 struct ldb_message
*msg
= ldb_msg_new(mem_ctx
);
130 assert_non_null(msg
);
132 msg
->dn
= ldb_dn_new(msg
, ldb
, "dc=samba,dc=org");
133 assert_non_null(msg
->dn
);
134 ret
= ldb_msg_add_string(msg
, "public", "key");
135 assert_int_equal(ret
, LDB_SUCCESS
);
136 ret
= ldb_msg_add_string(msg
, "supersecret", "password");
137 assert_int_equal(ret
, LDB_SUCCESS
);
138 ret
= ldb_msg_add_string(msg
, "binary", "\xff\xff\0");
139 assert_int_equal(ret
, LDB_SUCCESS
);
143 static void test_ldif_message(void **state
)
145 struct ldbtest_ctx
*test_ctx
= talloc_get_type_abort(*state
,
148 const char *expected_ldif
=
149 "dn: dc=samba,dc=org\n"
152 "supersecret: password\n"
156 struct ldb_message
*msg
= get_test_ldb_message(test_ctx
,
159 got_ldif
= ldb_ldif_message_string(test_ctx
->ldb
,
163 assert_string_equal(got_ldif
, expected_ldif
);
164 TALLOC_FREE(got_ldif
);
167 static void test_ldif_message_redacted(void **state
)
169 struct ldbtest_ctx
*test_ctx
= talloc_get_type_abort(*state
,
173 const char *expected_ldif
=
174 "dn: dc=samba,dc=org\n"
177 "# supersecret::: REDACTED SECRET ATTRIBUTE\n"
181 const char *secret_attrs
[] = {
186 struct ldb_message
*msg
= ldb_msg_new(test_ctx
);
188 ldb_set_opaque(test_ctx
->ldb
,
189 LDB_SECRET_ATTRIBUTE_LIST_OPAQUE
,
192 assert_non_null(msg
);
194 msg
->dn
= ldb_dn_new(msg
, test_ctx
->ldb
, "dc=samba,dc=org");
195 ret
= ldb_msg_add_string(msg
, "public", "key");
196 assert_int_equal(ret
, LDB_SUCCESS
);
197 ret
= ldb_msg_add_string(msg
, "supersecret", "password");
198 assert_int_equal(ret
, LDB_SUCCESS
);
199 ret
= ldb_msg_add_string(msg
, "binary", "\xff\xff\0");
200 assert_int_equal(ret
, LDB_SUCCESS
);
201 got_ldif
= ldb_ldif_message_redacted_string(test_ctx
->ldb
,
205 assert_string_equal(got_ldif
, expected_ldif
);
206 TALLOC_FREE(got_ldif
);
207 assert_int_equal(ret
, 0);
210 static int ldbtest_setup(void **state
)
212 struct ldbtest_ctx
*test_ctx
;
213 struct ldb_ldif
*ldif
;
215 const char *index_ldif
= \
217 "@IDXGUID: objectUUID\n"
218 "@IDX_DN_GUID: GUID\n"
221 const char *index_ldif
= "\n";
225 ldbtest_noconn_setup((void **) &test_ctx
);
227 ret
= ldb_connect(test_ctx
->ldb
, test_ctx
->dbpath
, 0, NULL
);
228 assert_int_equal(ret
, 0);
230 while ((ldif
= ldb_ldif_read_string(test_ctx
->ldb
, &index_ldif
))) {
231 ret
= ldb_add(test_ctx
->ldb
, ldif
->msg
);
232 assert_int_equal(ret
, LDB_SUCCESS
);
238 static int ldbtest_teardown(void **state
)
240 struct ldbtest_ctx
*test_ctx
= talloc_get_type_abort(*state
,
242 ldbtest_noconn_teardown((void **) &test_ctx
);
246 static void test_ldb_add(void **state
)
249 struct ldb_message
*msg
;
250 struct ldbtest_ctx
*test_ctx
= talloc_get_type_abort(*state
,
254 tmp_ctx
= talloc_new(test_ctx
);
255 assert_non_null(tmp_ctx
);
257 msg
= ldb_msg_new(tmp_ctx
);
258 assert_non_null(msg
);
260 msg
->dn
= ldb_dn_new_fmt(msg
, test_ctx
->ldb
, "dc=test");
261 assert_non_null(msg
->dn
);
263 ret
= ldb_msg_add_string(msg
, "cn", "test_cn_val");
264 assert_int_equal(ret
, 0);
266 ret
= ldb_msg_add_string(msg
, "objectUUID", "0123456789abcdef");
267 assert_int_equal(ret
, 0);
269 ret
= ldb_add(test_ctx
->ldb
, msg
);
270 assert_int_equal(ret
, 0);
272 talloc_free(tmp_ctx
);
275 static void test_ldb_search(void **state
)
278 struct ldb_message
*msg
;
279 struct ldbtest_ctx
*test_ctx
= talloc_get_type_abort(*state
,
282 struct ldb_dn
*basedn
;
283 struct ldb_dn
*basedn2
;
284 struct ldb_result
*result
= NULL
;
286 tmp_ctx
= talloc_new(test_ctx
);
287 assert_non_null(tmp_ctx
);
289 basedn
= ldb_dn_new_fmt(tmp_ctx
, test_ctx
->ldb
, "dc=test");
290 assert_non_null(basedn
);
292 ret
= ldb_search(test_ctx
->ldb
, tmp_ctx
, &result
, basedn
,
293 LDB_SCOPE_BASE
, NULL
, NULL
);
294 assert_int_equal(ret
, 0);
295 assert_non_null(result
);
296 assert_int_equal(result
->count
, 0);
298 msg
= ldb_msg_new(tmp_ctx
);
299 assert_non_null(msg
);
302 assert_non_null(msg
->dn
);
304 ret
= ldb_msg_add_string(msg
, "cn", "test_cn_val1");
305 assert_int_equal(ret
, 0);
307 ret
= ldb_msg_add_string(msg
, "objectUUID", "0123456789abcde1");
308 assert_int_equal(ret
, 0);
310 ret
= ldb_add(test_ctx
->ldb
, msg
);
311 assert_int_equal(ret
, 0);
313 basedn2
= ldb_dn_new_fmt(tmp_ctx
, test_ctx
->ldb
, "dc=test2");
314 assert_non_null(basedn2
);
316 msg
= ldb_msg_new(tmp_ctx
);
317 assert_non_null(msg
);
320 assert_non_null(msg
->dn
);
322 ret
= ldb_msg_add_string(msg
, "cn", "test_cn_val2");
323 assert_int_equal(ret
, 0);
325 ret
= ldb_msg_add_string(msg
, "objectUUID", "0123456789abcde2");
326 assert_int_equal(ret
, 0);
328 ret
= ldb_add(test_ctx
->ldb
, msg
);
329 assert_int_equal(ret
, 0);
331 ret
= ldb_search(test_ctx
->ldb
, tmp_ctx
, &result
, basedn
,
332 LDB_SCOPE_BASE
, NULL
, NULL
);
333 assert_int_equal(ret
, 0);
334 assert_non_null(result
);
335 assert_int_equal(result
->count
, 1);
336 assert_string_equal(ldb_dn_get_linearized(result
->msgs
[0]->dn
),
337 ldb_dn_get_linearized(basedn
));
339 ret
= ldb_search(test_ctx
->ldb
, tmp_ctx
, &result
, basedn2
,
340 LDB_SCOPE_BASE
, NULL
, NULL
);
341 assert_int_equal(ret
, 0);
342 assert_non_null(result
);
343 assert_int_equal(result
->count
, 1);
344 assert_string_equal(ldb_dn_get_linearized(result
->msgs
[0]->dn
),
345 ldb_dn_get_linearized(basedn2
));
347 talloc_free(tmp_ctx
);
350 static int base_search_count(struct ldbtest_ctx
*test_ctx
, const char *entry_dn
)
353 struct ldb_dn
*basedn
;
354 struct ldb_result
*result
= NULL
;
358 tmp_ctx
= talloc_new(test_ctx
);
359 assert_non_null(tmp_ctx
);
361 basedn
= ldb_dn_new_fmt(tmp_ctx
, test_ctx
->ldb
, "%s", entry_dn
);
362 assert_non_null(basedn
);
364 ret
= ldb_search(test_ctx
->ldb
, tmp_ctx
, &result
, basedn
,
365 LDB_SCOPE_BASE
, NULL
, NULL
);
366 assert_int_equal(ret
, LDB_SUCCESS
);
367 assert_non_null(result
);
369 count
= result
->count
;
370 talloc_free(tmp_ctx
);
374 static int sub_search_count(struct ldbtest_ctx
*test_ctx
,
379 struct ldb_dn
*basedn
;
380 struct ldb_result
*result
= NULL
;
384 tmp_ctx
= talloc_new(test_ctx
);
385 assert_non_null(tmp_ctx
);
387 basedn
= ldb_dn_new_fmt(tmp_ctx
, test_ctx
->ldb
, "%s", base_dn
);
388 assert_non_null(basedn
);
390 ret
= ldb_search(test_ctx
->ldb
, tmp_ctx
, &result
, basedn
,
391 LDB_SCOPE_SUBTREE
, NULL
, "%s", filter
);
392 assert_int_equal(ret
, LDB_SUCCESS
);
393 assert_non_null(result
);
395 count
= result
->count
;
396 talloc_free(tmp_ctx
);
400 /* In general it would be better if utility test functions didn't assert
401 * but only returned a value, then assert in the test shows correct
404 static void assert_dn_exists(struct ldbtest_ctx
*test_ctx
,
405 const char *entry_dn
)
409 count
= base_search_count(test_ctx
, entry_dn
);
410 assert_int_equal(count
, 1);
413 static void assert_dn_doesnt_exist(struct ldbtest_ctx
*test_ctx
,
414 const char *entry_dn
)
418 count
= base_search_count(test_ctx
, entry_dn
);
419 assert_int_equal(count
, 0);
422 static void add_dn_with_cn(struct ldbtest_ctx
*test_ctx
,
424 const char *cn_value
,
425 const char *uuid_value
)
429 struct ldb_message
*msg
;
431 tmp_ctx
= talloc_new(test_ctx
);
432 assert_non_null(tmp_ctx
);
434 assert_dn_doesnt_exist(test_ctx
,
435 ldb_dn_get_linearized(dn
));
437 msg
= ldb_msg_new(tmp_ctx
);
438 assert_non_null(msg
);
441 ret
= ldb_msg_add_string(msg
, "cn", cn_value
);
442 assert_int_equal(ret
, LDB_SUCCESS
);
444 ret
= ldb_msg_add_string(msg
, "objectUUID", uuid_value
);
445 assert_int_equal(ret
, 0);
447 ret
= ldb_add(test_ctx
->ldb
, msg
);
448 assert_int_equal(ret
, LDB_SUCCESS
);
450 assert_dn_exists(test_ctx
,
451 ldb_dn_get_linearized(dn
));
452 talloc_free(tmp_ctx
);
455 static void test_ldb_del(void **state
)
458 struct ldbtest_ctx
*test_ctx
= talloc_get_type_abort(*state
,
460 const char *basedn
= "dc=ldb_del_test";
463 dn
= ldb_dn_new_fmt(test_ctx
, test_ctx
->ldb
, "%s", basedn
);
466 add_dn_with_cn(test_ctx
, dn
,
470 ret
= ldb_delete(test_ctx
->ldb
, dn
);
471 assert_int_equal(ret
, LDB_SUCCESS
);
473 assert_dn_doesnt_exist(test_ctx
, basedn
);
476 static void test_ldb_del_noexist(void **state
)
478 struct ldbtest_ctx
*test_ctx
= talloc_get_type_abort(*state
,
480 struct ldb_dn
*basedn
;
483 basedn
= ldb_dn_new(test_ctx
, test_ctx
->ldb
, "dc=nosuchplace");
484 assert_non_null(basedn
);
486 ret
= ldb_delete(test_ctx
->ldb
, basedn
);
487 assert_int_equal(ret
, LDB_ERR_NO_SUCH_OBJECT
);
490 static void test_ldb_handle(void **state
)
493 struct ldbtest_ctx
*test_ctx
= talloc_get_type_abort(*state
,
496 struct ldb_dn
*basedn
;
497 struct ldb_request
*request
= NULL
;
498 struct ldb_request
*request2
= NULL
;
499 struct ldb_result
*res
= NULL
;
500 const char *attrs
[] = { "cn", NULL
};
502 tmp_ctx
= talloc_new(test_ctx
);
503 assert_non_null(tmp_ctx
);
505 basedn
= ldb_dn_new_fmt(tmp_ctx
, test_ctx
->ldb
, "dc=test");
506 assert_non_null(basedn
);
508 res
= talloc_zero(tmp_ctx
, struct ldb_result
);
509 assert_non_null(res
);
511 ret
= ldb_build_search_req(&request
, test_ctx
->ldb
, tmp_ctx
,
512 basedn
, LDB_SCOPE_BASE
,
513 NULL
, attrs
, NULL
, res
,
514 ldb_search_default_callback
,
516 assert_int_equal(ret
, 0);
518 /* We are against ldb_tdb, so expect private event contexts */
519 assert_ptr_not_equal(ldb_handle_get_event_context(request
->handle
),
520 ldb_get_event_context(test_ctx
->ldb
));
522 ret
= ldb_build_search_req(&request2
, test_ctx
->ldb
, tmp_ctx
,
523 basedn
, LDB_SCOPE_BASE
,
524 NULL
, attrs
, NULL
, res
,
525 ldb_search_default_callback
,
527 assert_int_equal(ret
, 0);
529 /* Expect that same event context will be chained */
530 assert_ptr_equal(ldb_handle_get_event_context(request
->handle
),
531 ldb_handle_get_event_context(request2
->handle
));
533 /* Now force this to use the global context */
534 ldb_handle_use_global_event_context(request2
->handle
);
535 assert_ptr_equal(ldb_handle_get_event_context(request2
->handle
),
536 ldb_get_event_context(test_ctx
->ldb
));
538 talloc_free(tmp_ctx
);
541 static void test_ldb_build_search_req(void **state
)
544 struct ldbtest_ctx
*test_ctx
= talloc_get_type_abort(*state
,
547 struct ldb_dn
*basedn
;
548 struct ldb_request
*request
= NULL
;
549 struct ldb_request
*request2
= NULL
;
550 struct ldb_result
*res
= NULL
;
551 const char *attrs
[] = { "cn", NULL
};
553 tmp_ctx
= talloc_new(test_ctx
);
554 assert_non_null(tmp_ctx
);
556 basedn
= ldb_dn_new_fmt(tmp_ctx
, test_ctx
->ldb
, "dc=test");
557 assert_non_null(basedn
);
559 res
= talloc_zero(tmp_ctx
, struct ldb_result
);
560 assert_non_null(res
);
562 ret
= ldb_build_search_req(&request
, test_ctx
->ldb
, tmp_ctx
,
563 basedn
, LDB_SCOPE_BASE
,
564 NULL
, attrs
, NULL
, res
,
565 ldb_search_default_callback
,
567 assert_int_equal(ret
, 0);
569 assert_int_equal(request
->operation
, LDB_SEARCH
);
570 assert_ptr_equal(request
->op
.search
.base
, basedn
);
571 assert_int_equal(request
->op
.search
.scope
, LDB_SCOPE_BASE
);
572 assert_non_null(request
->op
.search
.tree
);
573 assert_ptr_equal(request
->op
.search
.attrs
, attrs
);
574 assert_ptr_equal(request
->context
, res
);
575 assert_ptr_equal(request
->callback
, ldb_search_default_callback
);
577 ret
= ldb_build_search_req(&request2
, test_ctx
->ldb
, tmp_ctx
,
578 basedn
, LDB_SCOPE_BASE
,
579 NULL
, attrs
, NULL
, res
,
580 ldb_search_default_callback
,
582 assert_int_equal(ret
, 0);
583 assert_ptr_equal(request
, request2
->handle
->parent
);
584 assert_int_equal(request
->starttime
, request2
->starttime
);
585 assert_int_equal(request
->timeout
, request2
->timeout
);
587 talloc_free(tmp_ctx
);
590 static void add_keyval(struct ldbtest_ctx
*test_ctx
,
596 struct ldb_message
*msg
;
598 msg
= ldb_msg_new(test_ctx
);
599 assert_non_null(msg
);
601 msg
->dn
= ldb_dn_new_fmt(msg
, test_ctx
->ldb
, "%s=%s", key
, val
);
602 assert_non_null(msg
->dn
);
604 ret
= ldb_msg_add_string(msg
, key
, val
);
605 assert_int_equal(ret
, 0);
607 ret
= ldb_msg_add_string(msg
, "objectUUID", uuid
);
608 assert_int_equal(ret
, 0);
610 ret
= ldb_add(test_ctx
->ldb
, msg
);
611 assert_int_equal(ret
, 0);
616 static struct ldb_result
*get_keyval(struct ldbtest_ctx
*test_ctx
,
621 struct ldb_result
*result
;
622 struct ldb_dn
*basedn
;
624 basedn
= ldb_dn_new_fmt(test_ctx
, test_ctx
->ldb
, "%s=%s", key
, val
);
625 assert_non_null(basedn
);
627 ret
= ldb_search(test_ctx
->ldb
, test_ctx
, &result
, basedn
,
628 LDB_SCOPE_BASE
, NULL
, NULL
);
629 assert_int_equal(ret
, 0);
634 static void test_transactions(void **state
)
637 struct ldbtest_ctx
*test_ctx
= talloc_get_type_abort(*state
,
639 struct ldb_result
*res
;
641 /* start lev-0 transaction */
642 ret
= ldb_transaction_start(test_ctx
->ldb
);
643 assert_int_equal(ret
, 0);
645 add_keyval(test_ctx
, "vegetable", "carrot",
648 /* commit lev-0 transaction */
649 ret
= ldb_transaction_commit(test_ctx
->ldb
);
650 assert_int_equal(ret
, 0);
652 /* start another lev-1 nested transaction */
653 ret
= ldb_transaction_start(test_ctx
->ldb
);
654 assert_int_equal(ret
, 0);
656 add_keyval(test_ctx
, "fruit", "apple",
659 /* abort lev-1 nested transaction */
660 ret
= ldb_transaction_cancel(test_ctx
->ldb
);
661 assert_int_equal(ret
, 0);
663 res
= get_keyval(test_ctx
, "vegetable", "carrot");
664 assert_non_null(res
);
665 assert_int_equal(res
->count
, 1);
667 res
= get_keyval(test_ctx
, "fruit", "apple");
668 assert_non_null(res
);
669 assert_int_equal(res
->count
, 0);
672 static void test_nested_transactions(void **state
)
675 struct ldbtest_ctx
*test_ctx
= talloc_get_type_abort(*state
,
677 struct ldb_result
*res
;
679 /* start lev-0 transaction */
680 ret
= ldb_transaction_start(test_ctx
->ldb
);
681 assert_int_equal(ret
, 0);
683 add_keyval(test_ctx
, "vegetable", "carrot",
687 /* start another lev-1 nested transaction */
688 ret
= ldb_transaction_start(test_ctx
->ldb
);
689 assert_int_equal(ret
, 0);
691 add_keyval(test_ctx
, "fruit", "apple",
694 /* abort lev-1 nested transaction */
695 ret
= ldb_transaction_cancel(test_ctx
->ldb
);
696 assert_int_equal(ret
, 0);
698 /* commit lev-0 transaction */
699 ret
= ldb_transaction_commit(test_ctx
->ldb
);
700 assert_int_equal(ret
, 0);
702 res
= get_keyval(test_ctx
, "vegetable", "carrot");
703 assert_non_null(res
);
704 assert_int_equal(res
->count
, 1);
706 /* This documents the current ldb behaviour, i.e. nested
707 * transactions are not supported. And the cancellation of the nested
708 * transaction has no effect.
710 res
= get_keyval(test_ctx
, "fruit", "apple");
711 assert_non_null(res
);
712 assert_int_equal(res
->count
, 1);
714 struct ldb_mod_test_ctx
{
715 struct ldbtest_ctx
*ldb_test_ctx
;
716 const char *entry_dn
;
724 static struct ldb_message
*build_mod_msg(TALLOC_CTX
*mem_ctx
,
725 struct ldbtest_ctx
*test_ctx
,
730 struct ldb_message
*msg
;
734 msg
= ldb_msg_new(mem_ctx
);
735 assert_non_null(msg
);
737 msg
->dn
= ldb_dn_new_fmt(msg
, test_ctx
->ldb
, "%s", dn
);
738 assert_non_null(msg
->dn
);
740 for (i
= 0; kvs
[i
].key
!= NULL
; i
++) {
742 ret
= ldb_msg_add_empty(msg
, kvs
[i
].key
,
744 assert_int_equal(ret
, 0);
748 ret
= ldb_msg_add_string(msg
, kvs
[i
].key
, kvs
[i
].val
);
749 assert_int_equal(ret
, LDB_SUCCESS
);
756 static void ldb_test_add_data(TALLOC_CTX
*mem_ctx
,
757 struct ldbtest_ctx
*ldb_test_ctx
,
762 struct ldb_message
*msg
;
763 struct ldb_result
*result
= NULL
;
766 tmp_ctx
= talloc_new(mem_ctx
);
767 assert_non_null(tmp_ctx
);
769 msg
= build_mod_msg(tmp_ctx
, ldb_test_ctx
,
771 assert_non_null(msg
);
773 ret
= ldb_add(ldb_test_ctx
->ldb
, msg
);
774 assert_int_equal(ret
, LDB_SUCCESS
);
776 ret
= ldb_search(ldb_test_ctx
->ldb
, tmp_ctx
, &result
, msg
->dn
,
777 LDB_SCOPE_BASE
, NULL
, NULL
);
778 assert_int_equal(ret
, LDB_SUCCESS
);
779 assert_non_null(result
);
780 assert_int_equal(result
->count
, 1);
781 assert_string_equal(ldb_dn_get_linearized(result
->msgs
[0]->dn
),
782 ldb_dn_get_linearized(msg
->dn
));
784 talloc_free(tmp_ctx
);
787 static void ldb_test_remove_data(TALLOC_CTX
*mem_ctx
,
788 struct ldbtest_ctx
*ldb_test_ctx
,
792 struct ldb_dn
*basedn
;
796 tmp_ctx
= talloc_new(mem_ctx
);
797 assert_non_null(tmp_ctx
);
799 basedn
= ldb_dn_new_fmt(tmp_ctx
, ldb_test_ctx
->ldb
,
801 assert_non_null(basedn
);
803 ret
= ldb_delete(ldb_test_ctx
->ldb
, basedn
);
804 assert_true(ret
== LDB_SUCCESS
|| ret
== LDB_ERR_NO_SUCH_OBJECT
);
806 count
= base_search_count(ldb_test_ctx
, ldb_dn_get_linearized(basedn
));
807 assert_int_equal(count
, 0);
809 talloc_free(tmp_ctx
);
812 static void mod_test_add_data(struct ldb_mod_test_ctx
*mod_test_ctx
,
815 ldb_test_add_data(mod_test_ctx
,
816 mod_test_ctx
->ldb_test_ctx
,
817 mod_test_ctx
->entry_dn
,
821 static void mod_test_remove_data(struct ldb_mod_test_ctx
*mod_test_ctx
)
823 ldb_test_remove_data(mod_test_ctx
,
824 mod_test_ctx
->ldb_test_ctx
,
825 mod_test_ctx
->entry_dn
);
828 static struct ldb_result
*run_mod_test(struct ldb_mod_test_ctx
*mod_test_ctx
,
833 struct ldb_result
*res
;
834 struct ldb_message
*mod_msg
;
835 struct ldb_dn
*basedn
;
836 struct ldbtest_ctx
*ldb_test_ctx
;
839 ldb_test_ctx
= mod_test_ctx
->ldb_test_ctx
;
841 tmp_ctx
= talloc_new(mod_test_ctx
);
842 assert_non_null(tmp_ctx
);
844 mod_msg
= build_mod_msg(tmp_ctx
, ldb_test_ctx
, mod_test_ctx
->entry_dn
,
846 assert_non_null(mod_msg
);
848 ret
= ldb_modify(ldb_test_ctx
->ldb
, mod_msg
);
849 assert_int_equal(ret
, LDB_SUCCESS
);
851 basedn
= ldb_dn_new_fmt(tmp_ctx
, ldb_test_ctx
->ldb
,
852 "%s", mod_test_ctx
->entry_dn
);
853 assert_non_null(basedn
);
855 ret
= ldb_search(ldb_test_ctx
->ldb
, mod_test_ctx
, &res
, basedn
,
856 LDB_SCOPE_BASE
, NULL
, NULL
);
857 assert_int_equal(ret
, LDB_SUCCESS
);
858 assert_non_null(res
);
859 assert_int_equal(res
->count
, 1);
860 assert_string_equal(ldb_dn_get_linearized(res
->msgs
[0]->dn
),
861 ldb_dn_get_linearized(mod_msg
->dn
));
863 talloc_free(tmp_ctx
);
867 static int ldb_modify_test_setup(void **state
)
869 struct ldbtest_ctx
*ldb_test_ctx
;
870 struct ldb_mod_test_ctx
*mod_test_ctx
;
871 struct keyval kvs
[] = {
872 { "cn", "test_mod_cn" },
873 { "objectUUID", "0123456789abcdef"},
877 ldbtest_setup((void **) &ldb_test_ctx
);
879 mod_test_ctx
= talloc(ldb_test_ctx
, struct ldb_mod_test_ctx
);
880 assert_non_null(mod_test_ctx
);
882 mod_test_ctx
->entry_dn
= "dc=mod_test_entry";
883 mod_test_ctx
->ldb_test_ctx
= ldb_test_ctx
;
885 mod_test_remove_data(mod_test_ctx
);
886 mod_test_add_data(mod_test_ctx
, kvs
);
887 *state
= mod_test_ctx
;
891 static int ldb_modify_test_teardown(void **state
)
893 struct ldb_mod_test_ctx
*mod_test_ctx
= \
894 talloc_get_type_abort(*state
,
895 struct ldb_mod_test_ctx
);
896 struct ldbtest_ctx
*ldb_test_ctx
;
898 ldb_test_ctx
= mod_test_ctx
->ldb_test_ctx
;
900 mod_test_remove_data(mod_test_ctx
);
901 talloc_free(mod_test_ctx
);
903 ldbtest_teardown((void **) &ldb_test_ctx
);
907 static void test_ldb_modify_add_key(void **state
)
909 struct ldb_mod_test_ctx
*mod_test_ctx
= \
910 talloc_get_type_abort(*state
,
911 struct ldb_mod_test_ctx
);
912 struct keyval mod_kvs
[] = {
913 { "name", "test_mod_name" },
916 struct ldb_result
*res
;
917 struct ldb_message_element
*el
;
919 res
= run_mod_test(mod_test_ctx
, LDB_FLAG_MOD_ADD
, mod_kvs
);
920 assert_non_null(res
);
922 /* Check cn is intact and name was added */
923 assert_int_equal(res
->count
, 1);
924 el
= ldb_msg_find_element(res
->msgs
[0], "cn");
926 assert_int_equal(el
->num_values
, 1);
927 assert_string_equal((const char *)el
->values
[0].data
, "test_mod_cn");
929 el
= ldb_msg_find_element(res
->msgs
[0], "name");
931 assert_int_equal(el
->num_values
, 1);
932 assert_string_equal((const char *)el
->values
[0].data
, "test_mod_name");
935 static void test_ldb_modify_extend_key(void **state
)
937 struct ldb_mod_test_ctx
*mod_test_ctx
= \
938 talloc_get_type_abort(*state
,
939 struct ldb_mod_test_ctx
);
940 struct keyval mod_kvs
[] = {
941 { "cn", "test_mod_cn2" },
944 struct ldb_result
*res
;
945 struct ldb_message_element
*el
;
947 res
= run_mod_test(mod_test_ctx
, LDB_FLAG_MOD_ADD
, mod_kvs
);
948 assert_non_null(res
);
950 /* Check cn was extended with another value */
951 assert_int_equal(res
->count
, 1);
952 el
= ldb_msg_find_element(res
->msgs
[0], "cn");
954 assert_int_equal(el
->num_values
, 2);
955 assert_string_equal((const char *)el
->values
[0].data
, "test_mod_cn");
956 assert_string_equal((const char *)el
->values
[1].data
, "test_mod_cn2");
959 static void test_ldb_modify_add_key_noval(void **state
)
961 struct ldb_mod_test_ctx
*mod_test_ctx
= \
962 talloc_get_type_abort(*state
,
963 struct ldb_mod_test_ctx
);
964 struct ldb_message
*mod_msg
;
965 struct ldbtest_ctx
*ldb_test_ctx
;
966 struct ldb_message_element
*el
;
969 ldb_test_ctx
= mod_test_ctx
->ldb_test_ctx
;
971 mod_msg
= ldb_msg_new(mod_test_ctx
);
972 assert_non_null(mod_msg
);
974 mod_msg
->dn
= ldb_dn_new_fmt(mod_msg
, ldb_test_ctx
->ldb
,
975 "%s", mod_test_ctx
->entry_dn
);
976 assert_non_null(mod_msg
->dn
);
978 el
= talloc_zero(mod_msg
, struct ldb_message_element
);
979 el
->flags
= LDB_FLAG_MOD_ADD
;
981 el
->name
= talloc_strdup(el
, "cn");
982 assert_non_null(el
->name
);
984 mod_msg
->elements
= el
;
985 mod_msg
->num_elements
= 1;
987 ret
= ldb_modify(ldb_test_ctx
->ldb
, mod_msg
);
988 assert_int_equal(ret
, LDB_ERR_CONSTRAINT_VIOLATION
);
991 static void test_ldb_modify_replace_key(void **state
)
993 struct ldb_mod_test_ctx
*mod_test_ctx
= \
994 talloc_get_type_abort(*state
,
995 struct ldb_mod_test_ctx
);
996 const char *new_cn
= "new_cn";
997 struct keyval mod_kvs
[] = {
1001 struct ldb_result
*res
;
1002 struct ldb_message_element
*el
;
1004 res
= run_mod_test(mod_test_ctx
, LDB_FLAG_MOD_REPLACE
, mod_kvs
);
1005 assert_non_null(res
);
1007 /* Check cn was replaced */
1008 assert_int_equal(res
->count
, 1);
1009 el
= ldb_msg_find_element(res
->msgs
[0], "cn");
1010 assert_non_null(el
);
1011 assert_int_equal(el
->num_values
, 1);
1012 assert_string_equal((const char *)el
->values
[0].data
, new_cn
);
1015 static void test_ldb_modify_replace_noexist_key(void **state
)
1017 struct ldb_mod_test_ctx
*mod_test_ctx
= \
1018 talloc_get_type_abort(*state
,
1019 struct ldb_mod_test_ctx
);
1020 struct keyval mod_kvs
[] = {
1021 { "name", "name_val" },
1024 struct ldb_result
*res
;
1025 struct ldb_message_element
*el
;
1027 res
= run_mod_test(mod_test_ctx
, LDB_FLAG_MOD_REPLACE
, mod_kvs
);
1028 assert_non_null(res
);
1030 /* Check cn is intact and name was added */
1031 assert_int_equal(res
->count
, 1);
1032 el
= ldb_msg_find_element(res
->msgs
[0], "cn");
1033 assert_non_null(el
);
1034 assert_int_equal(el
->num_values
, 1);
1035 assert_string_equal((const char *)el
->values
[0].data
, "test_mod_cn");
1037 el
= ldb_msg_find_element(res
->msgs
[0], mod_kvs
[0].key
);
1038 assert_non_null(el
);
1039 assert_int_equal(el
->num_values
, 1);
1040 assert_string_equal((const char *)el
->values
[0].data
, mod_kvs
[0].val
);
1043 static void test_ldb_modify_replace_zero_vals(void **state
)
1045 struct ldb_mod_test_ctx
*mod_test_ctx
= \
1046 talloc_get_type_abort(*state
,
1047 struct ldb_mod_test_ctx
);
1048 struct ldb_message_element
*el
;
1049 struct ldb_result
*res
;
1050 struct keyval kvs
[] = {
1055 /* cn must be gone */
1056 res
= run_mod_test(mod_test_ctx
, LDB_FLAG_MOD_REPLACE
, kvs
);
1057 assert_non_null(res
);
1058 el
= ldb_msg_find_element(res
->msgs
[0], "cn");
1062 static void test_ldb_modify_replace_noexist_key_zero_vals(void **state
)
1064 struct ldb_mod_test_ctx
*mod_test_ctx
= \
1065 talloc_get_type_abort(*state
,
1066 struct ldb_mod_test_ctx
);
1067 struct ldb_message_element
*el
;
1068 struct ldb_result
*res
;
1069 struct keyval kvs
[] = {
1070 { "noexist_key", NULL
},
1074 /* cn must be gone */
1075 res
= run_mod_test(mod_test_ctx
, LDB_FLAG_MOD_REPLACE
, kvs
);
1076 assert_non_null(res
);
1078 /* cn should be intact */
1079 el
= ldb_msg_find_element(res
->msgs
[0], "cn");
1080 assert_non_null(el
);
1083 static void test_ldb_modify_del_key(void **state
)
1085 struct ldb_mod_test_ctx
*mod_test_ctx
= \
1086 talloc_get_type_abort(*state
,
1087 struct ldb_mod_test_ctx
);
1088 struct ldb_message_element
*el
;
1089 struct ldb_result
*res
;
1090 struct keyval kvs
[] = {
1095 /* cn must be gone */
1096 res
= run_mod_test(mod_test_ctx
, LDB_FLAG_MOD_DELETE
, kvs
);
1097 assert_non_null(res
);
1099 el
= ldb_msg_find_element(res
->msgs
[0], "cn");
1103 static void test_ldb_modify_del_keyval(void **state
)
1105 struct ldb_mod_test_ctx
*mod_test_ctx
= \
1106 talloc_get_type_abort(*state
,
1107 struct ldb_mod_test_ctx
);
1108 struct ldb_message_element
*el
;
1109 struct ldb_result
*res
;
1110 struct keyval kvs
[] = {
1111 { "cn", "test_mod_cn" },
1115 /* cn must be gone */
1116 res
= run_mod_test(mod_test_ctx
, LDB_FLAG_MOD_DELETE
, kvs
);
1117 assert_non_null(res
);
1119 el
= ldb_msg_find_element(res
->msgs
[0], "cn");
1123 struct search_test_ctx
{
1124 struct ldbtest_ctx
*ldb_test_ctx
;
1125 const char *base_dn
;
1128 static char *get_full_dn(TALLOC_CTX
*mem_ctx
,
1129 struct search_test_ctx
*search_test_ctx
,
1134 full_dn
= talloc_asprintf(mem_ctx
,
1135 "%s,%s", rdn
, search_test_ctx
->base_dn
);
1136 assert_non_null(full_dn
);
1141 static void search_test_add_data(struct search_test_ctx
*search_test_ctx
,
1147 full_dn
= get_full_dn(search_test_ctx
, search_test_ctx
, rdn
);
1149 ldb_test_add_data(search_test_ctx
,
1150 search_test_ctx
->ldb_test_ctx
,
1155 static void search_test_remove_data(struct search_test_ctx
*search_test_ctx
,
1160 full_dn
= talloc_asprintf(search_test_ctx
,
1161 "%s,%s", rdn
, search_test_ctx
->base_dn
);
1162 assert_non_null(full_dn
);
1164 ldb_test_remove_data(search_test_ctx
,
1165 search_test_ctx
->ldb_test_ctx
,
1169 static int ldb_search_test_setup(void **state
)
1171 struct ldbtest_ctx
*ldb_test_ctx
;
1172 struct search_test_ctx
*search_test_ctx
;
1173 struct keyval kvs
[] = {
1174 { "cn", "test_search_cn" },
1175 { "cn", "test_search_cn2" },
1176 { "uid", "test_search_uid" },
1177 { "uid", "test_search_uid2" },
1178 { "objectUUID", "0123456789abcde0"},
1181 struct keyval kvs2
[] = {
1182 { "cn", "test_search_2_cn" },
1183 { "cn", "test_search_2_cn2" },
1184 { "uid", "test_search_2_uid" },
1185 { "uid", "test_search_2_uid2" },
1186 { "objectUUID", "0123456789abcde1"},
1190 ldbtest_setup((void **) &ldb_test_ctx
);
1192 search_test_ctx
= talloc(ldb_test_ctx
, struct search_test_ctx
);
1193 assert_non_null(search_test_ctx
);
1195 search_test_ctx
->base_dn
= "dc=search_test_entry";
1196 search_test_ctx
->ldb_test_ctx
= ldb_test_ctx
;
1198 search_test_remove_data(search_test_ctx
, "cn=test_search_cn");
1199 search_test_add_data(search_test_ctx
, "cn=test_search_cn", kvs
);
1201 search_test_remove_data(search_test_ctx
, "cn=test_search_2_cn");
1202 search_test_add_data(search_test_ctx
, "cn=test_search_2_cn", kvs2
);
1204 *state
= search_test_ctx
;
1208 static int ldb_search_test_teardown(void **state
)
1210 struct search_test_ctx
*search_test_ctx
= talloc_get_type_abort(*state
,
1211 struct search_test_ctx
);
1212 struct ldbtest_ctx
*ldb_test_ctx
;
1214 ldb_test_ctx
= search_test_ctx
->ldb_test_ctx
;
1216 search_test_remove_data(search_test_ctx
, "cn=test_search_cn");
1217 search_test_remove_data(search_test_ctx
, "cn=test_search_2_cn");
1218 ldbtest_teardown((void **) &ldb_test_ctx
);
1222 static void assert_attr_has_vals(struct ldb_message
*msg
,
1227 struct ldb_message_element
*el
;
1230 el
= ldb_msg_find_element(msg
, attr
);
1231 assert_non_null(el
);
1233 assert_int_equal(el
->num_values
, nvals
);
1234 for (i
= 0; i
< nvals
; i
++) {
1235 assert_string_equal((const char *)el
->values
[i
].data
,
1240 static void assert_has_no_attr(struct ldb_message
*msg
,
1243 struct ldb_message_element
*el
;
1245 el
= ldb_msg_find_element(msg
, attr
);
1249 static bool has_dn(struct ldb_message
*msg
, const char *dn
)
1253 msgdn
= ldb_dn_get_linearized(msg
->dn
);
1254 if (strcmp(dn
, msgdn
) == 0) {
1261 static void test_search_match_none(void **state
)
1263 struct search_test_ctx
*search_test_ctx
= talloc_get_type_abort(*state
,
1264 struct search_test_ctx
);
1267 count
= base_search_count(search_test_ctx
->ldb_test_ctx
,
1268 "dc=no_such_entry");
1269 assert_int_equal(count
, 0);
1272 static void test_search_match_one(void **state
)
1274 struct search_test_ctx
*search_test_ctx
= talloc_get_type_abort(*state
,
1275 struct search_test_ctx
);
1277 struct ldb_dn
*basedn
;
1278 struct ldb_result
*result
= NULL
;
1279 const char *cn_vals
[] = { "test_search_cn",
1280 "test_search_cn2" };
1281 const char *uid_vals
[] = { "test_search_uid",
1282 "test_search_uid2" };
1284 basedn
= ldb_dn_new_fmt(search_test_ctx
,
1285 search_test_ctx
->ldb_test_ctx
->ldb
,
1287 search_test_ctx
->base_dn
);
1288 assert_non_null(basedn
);
1290 ret
= ldb_search(search_test_ctx
->ldb_test_ctx
->ldb
,
1294 LDB_SCOPE_SUBTREE
, NULL
,
1295 "cn=test_search_cn");
1296 assert_int_equal(ret
, 0);
1297 assert_non_null(result
);
1298 assert_int_equal(result
->count
, 1);
1300 assert_attr_has_vals(result
->msgs
[0], "cn", cn_vals
, 2);
1301 assert_attr_has_vals(result
->msgs
[0], "uid", uid_vals
, 2);
1304 static void test_search_match_filter(void **state
)
1306 struct search_test_ctx
*search_test_ctx
= talloc_get_type_abort(*state
,
1307 struct search_test_ctx
);
1309 struct ldb_dn
*basedn
;
1310 struct ldb_result
*result
= NULL
;
1311 const char *cn_vals
[] = { "test_search_cn",
1312 "test_search_cn2" };
1313 const char *attrs
[] = { "cn", NULL
};
1315 basedn
= ldb_dn_new_fmt(search_test_ctx
,
1316 search_test_ctx
->ldb_test_ctx
->ldb
,
1318 search_test_ctx
->base_dn
);
1319 assert_non_null(basedn
);
1321 ret
= ldb_search(search_test_ctx
->ldb_test_ctx
->ldb
,
1327 "cn=test_search_cn");
1328 assert_int_equal(ret
, 0);
1329 assert_non_null(result
);
1330 assert_int_equal(result
->count
, 1);
1332 assert_attr_has_vals(result
->msgs
[0], "cn", cn_vals
, 2);
1333 assert_has_no_attr(result
->msgs
[0], "uid");
1336 static void assert_expected(struct search_test_ctx
*search_test_ctx
,
1337 struct ldb_message
*msg
)
1341 const char *cn_vals
[] = { "test_search_cn",
1342 "test_search_cn2" };
1343 const char *uid_vals
[] = { "test_search_uid",
1344 "test_search_uid2" };
1345 const char *cn2_vals
[] = { "test_search_2_cn",
1346 "test_search_2_cn2" };
1347 const char *uid2_vals
[] = { "test_search_2_uid",
1348 "test_search_2_uid2" };
1350 full_dn1
= get_full_dn(search_test_ctx
,
1352 "cn=test_search_cn");
1354 full_dn2
= get_full_dn(search_test_ctx
,
1356 "cn=test_search_2_cn");
1358 if (has_dn(msg
, full_dn1
) == true) {
1359 assert_attr_has_vals(msg
, "cn", cn_vals
, 2);
1360 assert_attr_has_vals(msg
, "uid", uid_vals
, 2);
1361 } else if (has_dn(msg
, full_dn2
) == true) {
1362 assert_attr_has_vals(msg
, "cn", cn2_vals
, 2);
1363 assert_attr_has_vals(msg
, "uid", uid2_vals
, 2);
1369 static void test_search_match_both(void **state
)
1371 struct search_test_ctx
*search_test_ctx
= talloc_get_type_abort(*state
,
1372 struct search_test_ctx
);
1374 struct ldb_dn
*basedn
;
1375 struct ldb_result
*result
= NULL
;
1377 basedn
= ldb_dn_new_fmt(search_test_ctx
,
1378 search_test_ctx
->ldb_test_ctx
->ldb
,
1380 search_test_ctx
->base_dn
);
1381 assert_non_null(basedn
);
1383 ret
= ldb_search(search_test_ctx
->ldb_test_ctx
->ldb
,
1387 LDB_SCOPE_SUBTREE
, NULL
,
1388 "cn=test_search_*");
1389 assert_int_equal(ret
, 0);
1390 assert_non_null(result
);
1391 assert_int_equal(result
->count
, 2);
1393 assert_expected(search_test_ctx
, result
->msgs
[0]);
1394 assert_expected(search_test_ctx
, result
->msgs
[1]);
1397 static void test_search_match_basedn(void **state
)
1399 struct search_test_ctx
*search_test_ctx
= talloc_get_type_abort(*state
,
1400 struct search_test_ctx
);
1402 struct ldb_dn
*basedn
;
1403 struct ldb_result
*result
= NULL
;
1404 struct ldb_message
*msg
;
1406 basedn
= ldb_dn_new_fmt(search_test_ctx
,
1407 search_test_ctx
->ldb_test_ctx
->ldb
,
1409 assert_non_null(basedn
);
1411 ret
= ldb_search(search_test_ctx
->ldb_test_ctx
->ldb
,
1415 LDB_SCOPE_SUBTREE
, NULL
,
1417 assert_int_equal(ret
, 0);
1419 /* Add 'checkBaseOnSearch' to @OPTIONS */
1420 msg
= ldb_msg_new(search_test_ctx
);
1421 assert_non_null(msg
);
1423 msg
->dn
= ldb_dn_new_fmt(msg
,
1424 search_test_ctx
->ldb_test_ctx
->ldb
,
1426 assert_non_null(msg
->dn
);
1428 ret
= ldb_msg_add_string(msg
, "checkBaseOnSearch", "TRUE");
1429 assert_int_equal(ret
, 0);
1431 ret
= ldb_add(search_test_ctx
->ldb_test_ctx
->ldb
, msg
);
1432 assert_int_equal(ret
, 0);
1435 /* The search should return LDB_ERR_NO_SUCH_OBJECT */
1436 ret
= ldb_search(search_test_ctx
->ldb_test_ctx
->ldb
,
1440 LDB_SCOPE_SUBTREE
, NULL
,
1442 assert_int_equal(ret
, LDB_ERR_NO_SUCH_OBJECT
);
1444 ret
= ldb_delete(search_test_ctx
->ldb_test_ctx
->ldb
, msg
->dn
);
1445 assert_int_equal(ret
, 0);
1450 * This test is complex.
1451 * The purpose is to test for a deadlock detected between ldb_search()
1452 * and ldb_transaction_commit(). The deadlock happens if in process
1454 * - (1) the all-record lock is taken in ltdb_search()
1455 * - (2) the ldb_transaction_start() call is made
1456 * - (1) an un-indexed search starts (forced here by doing it in
1458 * - (2) the ldb_transaction_commit() is called.
1459 * This returns LDB_ERR_BUSY if the deadlock is detected
1461 * With ldb 1.1.31 and tdb 1.3.12 we avoid this only due to a missing
1462 * lock call in ltdb_search() due to a refcounting bug in
1466 struct search_against_transaction_ctx
{
1467 struct ldbtest_ctx
*test_ctx
;
1470 struct ldb_dn
*basedn
;
1473 static int test_ldb_search_against_transaction_callback2(struct ldb_request
*req
,
1474 struct ldb_reply
*ares
)
1476 struct search_against_transaction_ctx
*ctx
= req
->context
;
1477 switch (ares
->type
) {
1478 case LDB_REPLY_ENTRY
:
1480 if (ctx
->res_count
!= 1) {
1486 case LDB_REPLY_REFERRAL
:
1489 case LDB_REPLY_DONE
:
1490 return ldb_request_done(req
, LDB_SUCCESS
);
1498 * This purpose of this callback is to trigger a transaction in
1499 * the child process while the all-record lock is held, but before
1500 * we take any locks in the tdb_traverse_read() handler.
1502 * In tdb 1.3.12 tdb_traverse_read() take the read transaction lock
1503 * however in ldb 1.1.31 ltdb_search() forgets to take the all-record
1504 * lock (except the very first time) due to a ref-counting bug.
1508 static int test_ldb_search_against_transaction_callback1(struct ldb_request
*req
,
1509 struct ldb_reply
*ares
)
1514 struct search_against_transaction_ctx
*ctx
= req
->context
;
1515 switch (ares
->type
) {
1516 case LDB_REPLY_ENTRY
:
1519 case LDB_REPLY_REFERRAL
:
1522 case LDB_REPLY_DONE
:
1523 return ldb_request_done(req
, LDB_SUCCESS
);
1527 assert_int_equal(ret
, 0);
1529 ctx
->child_pid
= fork();
1530 if (ctx
->child_pid
== 0) {
1531 TALLOC_CTX
*tmp_ctx
= NULL
;
1532 struct ldb_message
*msg
;
1533 TALLOC_FREE(ctx
->test_ctx
->ldb
);
1534 TALLOC_FREE(ctx
->test_ctx
->ev
);
1536 ctx
->test_ctx
->ev
= tevent_context_init(ctx
->test_ctx
);
1537 if (ctx
->test_ctx
->ev
== NULL
) {
1538 exit(LDB_ERR_OPERATIONS_ERROR
);
1541 ctx
->test_ctx
->ldb
= ldb_init(ctx
->test_ctx
,
1543 if (ctx
->test_ctx
->ldb
== NULL
) {
1544 exit(LDB_ERR_OPERATIONS_ERROR
);
1547 ret
= ldb_connect(ctx
->test_ctx
->ldb
,
1548 ctx
->test_ctx
->dbpath
, 0, NULL
);
1549 if (ret
!= LDB_SUCCESS
) {
1553 tmp_ctx
= talloc_new(ctx
->test_ctx
);
1554 if (tmp_ctx
== NULL
) {
1555 exit(LDB_ERR_OPERATIONS_ERROR
);
1558 msg
= ldb_msg_new(tmp_ctx
);
1560 exit(LDB_ERR_OPERATIONS_ERROR
);
1563 msg
->dn
= ldb_dn_new_fmt(msg
, ctx
->test_ctx
->ldb
,
1565 if (msg
->dn
== NULL
) {
1566 exit(LDB_ERR_OPERATIONS_ERROR
);
1569 ret
= ldb_msg_add_string(msg
, "cn", "test_cn_val");
1571 exit(LDB_ERR_OPERATIONS_ERROR
);
1574 ret
= ldb_transaction_start(ctx
->test_ctx
->ldb
);
1579 ret
= write(pipes
[1], "GO", 2);
1581 exit(LDB_ERR_OPERATIONS_ERROR
);
1584 ret
= ldb_msg_add_string(msg
, "objectUUID",
1585 "0123456789abcdef");
1590 ret
= ldb_add(ctx
->test_ctx
->ldb
, msg
);
1595 ret
= ldb_transaction_commit(ctx
->test_ctx
->ldb
);
1599 ret
= read(pipes
[0], buf
, 2);
1600 assert_int_equal(ret
, 2);
1602 /* This search must be unindexed (ie traverse in tdb) */
1603 ret
= ldb_build_search_req(&req
,
1611 test_ldb_search_against_transaction_callback2
,
1614 * we don't assert on these return codes until after the search is
1615 * finished, or the clean up will fail because we hold locks.
1618 ret2
= ldb_request(ctx
->test_ctx
->ldb
, req
);
1620 if (ret2
== LDB_SUCCESS
) {
1621 ret2
= ldb_wait(req
->handle
, LDB_WAIT_ALL
);
1623 assert_int_equal(ret
, 0);
1624 assert_int_equal(ret2
, 0);
1625 assert_int_equal(ctx
->res_count
, 2);
1630 static void test_ldb_search_against_transaction(void **state
)
1632 struct search_test_ctx
*search_test_ctx
= talloc_get_type_abort(*state
,
1633 struct search_test_ctx
);
1634 struct search_against_transaction_ctx
1637 .test_ctx
= search_test_ctx
->ldb_test_ctx
1641 struct ldb_request
*req
;
1644 struct ldb_dn
*base_search_dn
;
1646 tevent_loop_allow_nesting(search_test_ctx
->ldb_test_ctx
->ev
);
1649 = ldb_dn_new_fmt(search_test_ctx
,
1650 search_test_ctx
->ldb_test_ctx
->ldb
,
1651 "cn=test_search_cn,%s",
1652 search_test_ctx
->base_dn
);
1653 assert_non_null(base_search_dn
);
1656 = ldb_dn_new_fmt(search_test_ctx
,
1657 search_test_ctx
->ldb_test_ctx
->ldb
,
1659 search_test_ctx
->base_dn
);
1660 assert_non_null(ctx
.basedn
);
1663 /* This search must be indexed (ie no traverse in tdb) */
1664 ret
= ldb_build_search_req(&req
,
1665 search_test_ctx
->ldb_test_ctx
->ldb
,
1672 test_ldb_search_against_transaction_callback1
,
1674 assert_int_equal(ret
, 0);
1675 ret
= ldb_request(search_test_ctx
->ldb_test_ctx
->ldb
, req
);
1677 if (ret
== LDB_SUCCESS
) {
1678 ret
= ldb_wait(req
->handle
, LDB_WAIT_ALL
);
1680 assert_int_equal(ret
, 0);
1681 assert_int_equal(ctx
.res_count
, 2);
1683 pid
= waitpid(ctx
.child_pid
, &wstatus
, 0);
1684 assert_int_equal(pid
, ctx
.child_pid
);
1686 assert_true(WIFEXITED(wstatus
));
1688 assert_int_equal(WEXITSTATUS(wstatus
), 0);
1694 * This test is also complex.
1695 * The purpose is to test if a modify can occur during an ldb_search()
1696 * This would be a failure if if in process
1698 * - (1) ltdb_search() starts and calls back for one entry
1699 * - (2) one of the entries to be matched is modified
1700 * - (1) the indexed search tries to return the modified entry, but
1701 * it is no longer found, either:
1702 * - despite it still matching (dn changed)
1703 * - it no longer matching (attrs changed)
1705 * We also try un-indexed to show that the behaviour differs on this
1706 * point, which it should not (an index should only impact search
1710 struct modify_during_search_test_ctx
{
1711 struct ldbtest_ctx
*test_ctx
;
1714 struct ldb_dn
*basedn
;
1721 * This purpose of this callback is to trigger a write in
1722 * the child process while a search is in progress.
1724 * In tdb 1.3.12 tdb_traverse_read() take the read transaction lock
1725 * however in ldb 1.1.31 ltdb_search() forgets to take the all-record
1726 * lock (except the very first time) due to a ref-counting bug.
1728 * We assume that if the write will proceed, it will proceed in a 3
1729 * second window after the function is called.
1732 static int test_ldb_modify_during_search_callback1(struct ldb_request
*req
,
1733 struct ldb_reply
*ares
)
1738 struct modify_during_search_test_ctx
*ctx
= req
->context
;
1739 switch (ares
->type
) {
1740 case LDB_REPLY_ENTRY
:
1742 const struct ldb_val
*cn_val
1743 = ldb_dn_get_component_val(ares
->message
->dn
, 0);
1744 const char *cn
= (char *)cn_val
->data
;
1746 if (strcmp(cn
, "test_search_cn") == 0) {
1748 } else if (strcmp(cn
, "test_search_2_cn") == 0) {
1749 ctx
->got_2_cn
= true;
1751 if (ctx
->res_count
== 2) {
1756 case LDB_REPLY_REFERRAL
:
1759 case LDB_REPLY_DONE
:
1760 return ldb_request_done(req
, LDB_SUCCESS
);
1764 assert_int_equal(ret
, 0);
1766 ctx
->child_pid
= fork();
1767 if (ctx
->child_pid
== 0 && ctx
->rename
) {
1768 TALLOC_CTX
*tmp_ctx
= NULL
;
1769 struct ldb_dn
*dn
, *new_dn
;
1770 TALLOC_FREE(ctx
->test_ctx
->ldb
);
1771 TALLOC_FREE(ctx
->test_ctx
->ev
);
1773 ctx
->test_ctx
->ev
= tevent_context_init(ctx
->test_ctx
);
1774 if (ctx
->test_ctx
->ev
== NULL
) {
1775 exit(LDB_ERR_OPERATIONS_ERROR
);
1778 ctx
->test_ctx
->ldb
= ldb_init(ctx
->test_ctx
,
1780 if (ctx
->test_ctx
->ldb
== NULL
) {
1781 exit(LDB_ERR_OPERATIONS_ERROR
);
1784 ret
= ldb_connect(ctx
->test_ctx
->ldb
,
1785 ctx
->test_ctx
->dbpath
, 0, NULL
);
1786 if (ret
!= LDB_SUCCESS
) {
1790 tmp_ctx
= talloc_new(ctx
->test_ctx
);
1791 if (tmp_ctx
== NULL
) {
1792 exit(LDB_ERR_OPERATIONS_ERROR
);
1796 /* Modify the other one */
1797 dn
= ldb_dn_new_fmt(tmp_ctx
, ctx
->test_ctx
->ldb
,
1798 "cn=test_search_2_cn,"
1799 "dc=search_test_entry");
1801 dn
= ldb_dn_new_fmt(tmp_ctx
, ctx
->test_ctx
->ldb
,
1802 "cn=test_search_cn,"
1803 "dc=search_test_entry");
1806 exit(LDB_ERR_OPERATIONS_ERROR
);
1809 new_dn
= ldb_dn_new_fmt(tmp_ctx
, ctx
->test_ctx
->ldb
,
1810 "cn=test_search_cn_renamed,"
1811 "dc=search_test_entry");
1812 if (new_dn
== NULL
) {
1813 exit(LDB_ERR_OPERATIONS_ERROR
);
1816 ret
= ldb_transaction_start(ctx
->test_ctx
->ldb
);
1821 if (write(pipes
[1], "GO", 2) != 2) {
1822 exit(LDB_ERR_OPERATIONS_ERROR
);
1825 ret
= ldb_rename(ctx
->test_ctx
->ldb
, dn
, new_dn
);
1830 ret
= ldb_transaction_commit(ctx
->test_ctx
->ldb
);
1833 } else if (ctx
->child_pid
== 0) {
1834 TALLOC_CTX
*tmp_ctx
= NULL
;
1835 struct ldb_message
*msg
;
1836 struct ldb_message_element
*el
;
1837 TALLOC_FREE(ctx
->test_ctx
->ldb
);
1838 TALLOC_FREE(ctx
->test_ctx
->ev
);
1840 ctx
->test_ctx
->ev
= tevent_context_init(ctx
->test_ctx
);
1841 if (ctx
->test_ctx
->ev
== NULL
) {
1842 exit(LDB_ERR_OPERATIONS_ERROR
);
1845 ctx
->test_ctx
->ldb
= ldb_init(ctx
->test_ctx
,
1847 if (ctx
->test_ctx
->ldb
== NULL
) {
1848 exit(LDB_ERR_OPERATIONS_ERROR
);
1851 ret
= ldb_connect(ctx
->test_ctx
->ldb
,
1852 ctx
->test_ctx
->dbpath
, 0, NULL
);
1853 if (ret
!= LDB_SUCCESS
) {
1857 tmp_ctx
= talloc_new(ctx
->test_ctx
);
1858 if (tmp_ctx
== NULL
) {
1859 exit(LDB_ERR_OPERATIONS_ERROR
);
1862 msg
= ldb_msg_new(tmp_ctx
);
1864 exit(LDB_ERR_OPERATIONS_ERROR
);
1868 /* Modify the other one */
1869 msg
->dn
= ldb_dn_new_fmt(msg
, ctx
->test_ctx
->ldb
,
1870 "cn=test_search_2_cn,"
1871 "dc=search_test_entry");
1873 msg
->dn
= ldb_dn_new_fmt(msg
, ctx
->test_ctx
->ldb
,
1874 "cn=test_search_cn,"
1875 "dc=search_test_entry");
1877 if (msg
->dn
== NULL
) {
1878 exit(LDB_ERR_OPERATIONS_ERROR
);
1881 ret
= ldb_msg_add_string(msg
, "filterAttr", "TRUE");
1883 exit(LDB_ERR_OPERATIONS_ERROR
);
1885 el
= ldb_msg_find_element(msg
, "filterAttr");
1887 exit(LDB_ERR_OPERATIONS_ERROR
);
1889 el
->flags
= LDB_FLAG_MOD_REPLACE
;
1891 ret
= ldb_transaction_start(ctx
->test_ctx
->ldb
);
1896 if (write(pipes
[1], "GO", 2) != 2) {
1897 exit(LDB_ERR_OPERATIONS_ERROR
);
1900 ret
= ldb_modify(ctx
->test_ctx
->ldb
, msg
);
1905 ret
= ldb_transaction_commit(ctx
->test_ctx
->ldb
);
1910 * With TDB 1.3.13 and before "tdb: Remove locking from tdb_traverse_read()"
1911 * we will hang here because the child process can not proceed to
1912 * sending the "GO" as it is blocked at ldb_transaction_start().
1916 ret
= read(pipes
[0], buf
, 2);
1917 assert_int_equal(ret
, 2);
1924 static void test_ldb_modify_during_search(void **state
, bool add_index
,
1927 struct search_test_ctx
*search_test_ctx
= talloc_get_type_abort(*state
,
1928 struct search_test_ctx
);
1929 struct modify_during_search_test_ctx
1932 .test_ctx
= search_test_ctx
->ldb_test_ctx
,
1937 struct ldb_request
*req
;
1942 struct ldb_message
*msg
;
1943 struct ldb_dn
*indexlist
= ldb_dn_new(search_test_ctx
,
1944 search_test_ctx
->ldb_test_ctx
->ldb
,
1946 assert_non_null(indexlist
);
1948 msg
= ldb_msg_new(search_test_ctx
);
1949 assert_non_null(msg
);
1951 msg
->dn
= indexlist
;
1953 ret
= ldb_msg_add_string(msg
, "@IDXATTR", "cn");
1954 assert_int_equal(ret
, LDB_SUCCESS
);
1955 ret
= ldb_add(search_test_ctx
->ldb_test_ctx
->ldb
,
1957 if (ret
== LDB_ERR_ENTRY_ALREADY_EXISTS
) {
1958 msg
->elements
[0].flags
= LDB_FLAG_MOD_ADD
;
1959 ret
= ldb_modify(search_test_ctx
->ldb_test_ctx
->ldb
,
1962 assert_int_equal(ret
, LDB_SUCCESS
);
1965 tevent_loop_allow_nesting(search_test_ctx
->ldb_test_ctx
->ev
);
1968 = ldb_dn_new_fmt(search_test_ctx
,
1969 search_test_ctx
->ldb_test_ctx
->ldb
,
1971 search_test_ctx
->base_dn
);
1972 assert_non_null(ctx
.basedn
);
1976 * This search must be over multiple items, and should include
1977 * the new name after a rename, to show that it would match
1978 * both before and after that modify
1980 ret
= ldb_build_search_req(&req
,
1981 search_test_ctx
->ldb_test_ctx
->ldb
,
1985 "(&(!(filterAttr=*))"
1986 "(|(cn=test_search_cn_renamed)"
1987 "(cn=test_search_cn)"
1988 "(cn=test_search_2_cn)"
1993 test_ldb_modify_during_search_callback1
,
1995 assert_int_equal(ret
, 0);
1996 ret
= ldb_request(search_test_ctx
->ldb_test_ctx
->ldb
, req
);
1998 if (ret
== LDB_SUCCESS
) {
1999 ret
= ldb_wait(req
->handle
, LDB_WAIT_ALL
);
2001 assert_int_equal(ret
, 0);
2002 assert_int_equal(ctx
.res_count
, 2);
2003 assert_int_equal(ctx
.got_cn
, true);
2004 assert_int_equal(ctx
.got_2_cn
, true);
2006 pid
= waitpid(ctx
.child_pid
, &wstatus
, 0);
2007 assert_int_equal(pid
, ctx
.child_pid
);
2009 assert_true(WIFEXITED(wstatus
));
2011 assert_int_equal(WEXITSTATUS(wstatus
), 0);
2016 static void test_ldb_modify_during_indexed_search(void **state
)
2018 test_ldb_modify_during_search(state
, true, false);
2021 static void test_ldb_modify_during_unindexed_search(void **state
)
2023 test_ldb_modify_during_search(state
, false, false);
2026 static void test_ldb_rename_during_indexed_search(void **state
)
2028 test_ldb_modify_during_search(state
, true, true);
2031 static void test_ldb_rename_during_unindexed_search(void **state
)
2033 test_ldb_modify_during_search(state
, false, true);
2037 * This test is also complex.
2039 * The purpose is to test if a modify can occur during an ldb_search()
2040 * before the end of the callback
2042 * This would be a failure if if in process
2044 * - (1) ldb_search() starts and calls back for a number of entries
2045 * - (2) an entry in the DB is allowed to change before the callback returns
2046 * - (1) the callback can see the modification
2051 * This purpose of this callback is to trigger a write in
2052 * the child process while a search DONE callback is in progress.
2054 * In ldb 1.1.31 ldb_search() omitted to take a all-record
2055 * lock for the full duration of the search and callbacks
2057 * We assume that if the write will proceed, it will proceed in a 3
2058 * second window after the function is called.
2061 static int test_ldb_modify_during_whole_search_callback1(struct ldb_request
*req
,
2062 struct ldb_reply
*ares
)
2067 struct modify_during_search_test_ctx
*ctx
= req
->context
;
2068 struct ldb_dn
*search_dn
;
2069 struct ldb_result
*res2
;
2071 switch (ares
->type
) {
2072 case LDB_REPLY_ENTRY
:
2073 case LDB_REPLY_REFERRAL
:
2076 case LDB_REPLY_DONE
:
2081 assert_int_equal(ret
, 0);
2083 ctx
->child_pid
= fork();
2084 if (ctx
->child_pid
== 0) {
2085 TALLOC_CTX
*tmp_ctx
= NULL
;
2086 struct ldb_message
*msg
;
2087 struct ldb_message_element
*el
;
2088 TALLOC_FREE(ctx
->test_ctx
->ldb
);
2089 TALLOC_FREE(ctx
->test_ctx
->ev
);
2091 ctx
->test_ctx
->ev
= tevent_context_init(ctx
->test_ctx
);
2092 if (ctx
->test_ctx
->ev
== NULL
) {
2093 exit(LDB_ERR_OPERATIONS_ERROR
);
2096 ctx
->test_ctx
->ldb
= ldb_init(ctx
->test_ctx
,
2098 if (ctx
->test_ctx
->ldb
== NULL
) {
2099 exit(LDB_ERR_OPERATIONS_ERROR
);
2102 ret
= ldb_connect(ctx
->test_ctx
->ldb
,
2103 ctx
->test_ctx
->dbpath
, 0, NULL
);
2104 if (ret
!= LDB_SUCCESS
) {
2108 tmp_ctx
= talloc_new(ctx
->test_ctx
);
2109 if (tmp_ctx
== NULL
) {
2110 exit(LDB_ERR_OPERATIONS_ERROR
);
2113 msg
= ldb_msg_new(tmp_ctx
);
2115 exit(LDB_ERR_OPERATIONS_ERROR
);
2118 msg
->dn
= ldb_dn_new_fmt(msg
, ctx
->test_ctx
->ldb
,
2119 "cn=test_search_cn,"
2120 "dc=search_test_entry");
2121 if (msg
->dn
== NULL
) {
2122 exit(LDB_ERR_OPERATIONS_ERROR
);
2125 ret
= ldb_msg_add_string(msg
, "filterAttr", "TRUE");
2127 exit(LDB_ERR_OPERATIONS_ERROR
);
2129 el
= ldb_msg_find_element(msg
, "filterAttr");
2131 exit(LDB_ERR_OPERATIONS_ERROR
);
2133 el
->flags
= LDB_FLAG_MOD_REPLACE
;
2135 ret
= ldb_transaction_start(ctx
->test_ctx
->ldb
);
2140 if (write(pipes
[1], "GO", 2) != 2) {
2141 exit(LDB_ERR_OPERATIONS_ERROR
);
2144 ret
= ldb_modify(ctx
->test_ctx
->ldb
, msg
);
2149 ret
= ldb_transaction_commit(ctx
->test_ctx
->ldb
);
2154 ret
= read(pipes
[0], buf
, 2);
2155 assert_int_equal(ret
, 2);
2160 * If writes are not blocked until after this function, we
2161 * will be able to successfully search for this modification
2165 search_dn
= ldb_dn_new_fmt(ares
, ctx
->test_ctx
->ldb
,
2166 "cn=test_search_cn,"
2167 "dc=search_test_entry");
2169 ret
= ldb_search(ctx
->test_ctx
->ldb
, ares
,
2170 &res2
, search_dn
, LDB_SCOPE_BASE
, NULL
,
2174 * We do this in an unusual order, because if we fail an assert before
2175 * ldb_request_done(), we will also fail to clean up as we hold locks.
2178 res_count
= res2
->count
;
2179 ldb_request_done(req
, LDB_SUCCESS
);
2180 assert_int_equal(ret
, 0);
2182 /* We should not have got the result */
2183 assert_int_equal(res_count
, 0);
2188 static void test_ldb_modify_during_whole_search(void **state
)
2190 struct search_test_ctx
*search_test_ctx
= talloc_get_type_abort(*state
,
2191 struct search_test_ctx
);
2192 struct modify_during_search_test_ctx
2195 .test_ctx
= search_test_ctx
->ldb_test_ctx
,
2199 struct ldb_request
*req
;
2202 struct ldb_dn
*search_dn
;
2203 struct ldb_result
*res2
;
2205 tevent_loop_allow_nesting(search_test_ctx
->ldb_test_ctx
->ev
);
2208 = ldb_dn_new_fmt(search_test_ctx
,
2209 search_test_ctx
->ldb_test_ctx
->ldb
,
2211 search_test_ctx
->base_dn
);
2212 assert_non_null(ctx
.basedn
);
2216 * The search just needs to call DONE, we don't care about the
2217 * contents of the search for this test
2219 ret
= ldb_build_search_req(&req
,
2220 search_test_ctx
->ldb_test_ctx
->ldb
,
2224 "(&(!(filterAttr=*))"
2225 "(cn=test_search_cn))",
2229 test_ldb_modify_during_whole_search_callback1
,
2231 assert_int_equal(ret
, 0);
2232 ret
= ldb_request(search_test_ctx
->ldb_test_ctx
->ldb
, req
);
2234 if (ret
== LDB_SUCCESS
) {
2235 ret
= ldb_wait(req
->handle
, LDB_WAIT_ALL
);
2237 assert_int_equal(ret
, 0);
2239 pid
= waitpid(ctx
.child_pid
, &wstatus
, 0);
2240 assert_int_equal(pid
, ctx
.child_pid
);
2242 assert_true(WIFEXITED(wstatus
));
2244 assert_int_equal(WEXITSTATUS(wstatus
), 0);
2247 * If writes are blocked until after the search function, we
2248 * will be able to successfully search for this modification
2252 search_dn
= ldb_dn_new_fmt(search_test_ctx
,
2253 search_test_ctx
->ldb_test_ctx
->ldb
,
2254 "cn=test_search_cn,"
2255 "dc=search_test_entry");
2257 ret
= ldb_search(search_test_ctx
->ldb_test_ctx
->ldb
,
2259 &res2
, search_dn
, LDB_SCOPE_BASE
, NULL
,
2261 assert_int_equal(ret
, 0);
2263 /* We got the result */
2264 assert_int_equal(res2
->count
, 1);
2268 * This test is also complex.
2270 * The purpose is to test if a modify can occur during an ldb_search()
2271 * before the request is destroyed with TALLOC_FREE()
2273 * This would be a failure if in process
2275 * - (1) ldb_search() starts and waits
2276 * - (2) an entry in the DB is allowed to change before the ldb_wait() is called
2277 * - (1) the original process can see the modification before the TALLOC_FREE()
2278 * also we check that
2279 * - (1) the original process can see the modification after the TALLOC_FREE()
2284 * This purpose of this callback is to trigger a write in
2285 * the child process before the ldb_wait() is called
2287 * In ldb 1.1.31 ldb_search() omitted to take a all-record
2288 * lock for the full duration of the search and callbacks
2290 * We assume that if the write will proceed, it will proceed in a 3
2291 * second window after the function is called.
2294 static int test_ldb_modify_before_ldb_wait_callback1(struct ldb_request
*req
,
2295 struct ldb_reply
*ares
)
2297 switch (ares
->type
) {
2298 case LDB_REPLY_ENTRY
:
2299 case LDB_REPLY_REFERRAL
:
2302 case LDB_REPLY_DONE
:
2306 return ldb_request_done(req
, LDB_SUCCESS
);
2309 static void test_ldb_modify_before_ldb_wait(void **state
)
2311 struct search_test_ctx
*search_test_ctx
= talloc_get_type_abort(*state
,
2312 struct search_test_ctx
);
2314 struct ldb_request
*req
;
2317 struct ldb_dn
*search_dn
;
2318 struct ldb_dn
*basedn
;
2319 struct ldb_result
*res2
;
2325 search_dn
= ldb_dn_new_fmt(search_test_ctx
,
2326 search_test_ctx
->ldb_test_ctx
->ldb
,
2327 "cn=test_search_cn,"
2328 "dc=search_test_entry");
2329 assert_non_null(search_dn
);
2331 basedn
= ldb_dn_new_fmt(search_test_ctx
,
2332 search_test_ctx
->ldb_test_ctx
->ldb
,
2334 search_test_ctx
->base_dn
);
2335 assert_non_null(basedn
);
2338 * The search just needs to call DONE, we don't care about the
2339 * contents of the search for this test
2341 ret
= ldb_build_search_req(&req
,
2342 search_test_ctx
->ldb_test_ctx
->ldb
,
2346 "(&(!(filterAttr=*))"
2347 "(cn=test_search_cn))",
2351 test_ldb_modify_before_ldb_wait_callback1
,
2353 assert_int_equal(ret
, 0);
2354 ret
= ldb_request(search_test_ctx
->ldb_test_ctx
->ldb
, req
);
2357 assert_int_equal(ret
, 0);
2360 if (child_pid
== 0) {
2361 TALLOC_CTX
*tmp_ctx
= NULL
;
2362 struct ldb_message
*msg
;
2363 struct ldb_message_element
*el
;
2364 TALLOC_FREE(search_test_ctx
->ldb_test_ctx
->ldb
);
2365 TALLOC_FREE(search_test_ctx
->ldb_test_ctx
->ev
);
2367 search_test_ctx
->ldb_test_ctx
->ev
= tevent_context_init(search_test_ctx
->ldb_test_ctx
);
2368 if (search_test_ctx
->ldb_test_ctx
->ev
== NULL
) {
2369 exit(LDB_ERR_OPERATIONS_ERROR
);
2372 search_test_ctx
->ldb_test_ctx
->ldb
= ldb_init(search_test_ctx
->ldb_test_ctx
,
2373 search_test_ctx
->ldb_test_ctx
->ev
);
2374 if (search_test_ctx
->ldb_test_ctx
->ldb
== NULL
) {
2375 exit(LDB_ERR_OPERATIONS_ERROR
);
2378 ret
= ldb_connect(search_test_ctx
->ldb_test_ctx
->ldb
,
2379 search_test_ctx
->ldb_test_ctx
->dbpath
, 0, NULL
);
2380 if (ret
!= LDB_SUCCESS
) {
2384 tmp_ctx
= talloc_new(search_test_ctx
->ldb_test_ctx
);
2385 if (tmp_ctx
== NULL
) {
2386 exit(LDB_ERR_OPERATIONS_ERROR
);
2389 msg
= ldb_msg_new(tmp_ctx
);
2391 exit(LDB_ERR_OPERATIONS_ERROR
);
2395 * We must re-create this DN from a string to ensure
2396 * it does not reference the now-gone LDB context of
2399 msg
->dn
= ldb_dn_new_fmt(search_test_ctx
,
2400 search_test_ctx
->ldb_test_ctx
->ldb
,
2401 "cn=test_search_cn,"
2402 "dc=search_test_entry");
2404 if (msg
->dn
== NULL
) {
2405 exit(LDB_ERR_OPERATIONS_ERROR
);
2408 ret
= ldb_msg_add_string(msg
, "filterAttr", "TRUE");
2410 exit(LDB_ERR_OPERATIONS_ERROR
);
2412 el
= ldb_msg_find_element(msg
, "filterAttr");
2414 exit(LDB_ERR_OPERATIONS_ERROR
);
2416 el
->flags
= LDB_FLAG_MOD_REPLACE
;
2418 ret
= ldb_transaction_start(search_test_ctx
->ldb_test_ctx
->ldb
);
2423 if (write(pipes
[1], "GO", 2) != 2) {
2424 exit(LDB_ERR_OPERATIONS_ERROR
);
2427 ret
= ldb_modify(search_test_ctx
->ldb_test_ctx
->ldb
, msg
);
2432 ret
= ldb_transaction_commit(search_test_ctx
->ldb_test_ctx
->ldb
);
2437 ret
= read(pipes
[0], buf
, 2);
2438 assert_int_equal(ret
, 2);
2443 * If writes are not blocked until after the (never called) ldb_wait(), we
2444 * will be able to successfully search for this modification
2448 ret
= ldb_search(search_test_ctx
->ldb_test_ctx
->ldb
, search_test_ctx
,
2449 &res2
, search_dn
, LDB_SCOPE_BASE
, NULL
,
2453 * We avoid making assertions before TALLOC_FREE()ing the request,
2454 * lest the assert fail and mess with the clean-up because we still
2457 res_count
= res2
->count
;
2460 /* We should not have got the result */
2461 assert_int_equal(res_count
, 0);
2462 assert_int_equal(ret
, 0);
2464 pid
= waitpid(child_pid
, &wstatus
, 0);
2465 assert_int_equal(pid
, child_pid
);
2467 assert_true(WIFEXITED(wstatus
));
2469 assert_int_equal(WEXITSTATUS(wstatus
), 0);
2472 * If writes are blocked until after the search request was freed, we
2473 * will be able to successfully search for this modification
2477 search_dn
= ldb_dn_new_fmt(search_test_ctx
,
2478 search_test_ctx
->ldb_test_ctx
->ldb
,
2479 "cn=test_search_cn,"
2480 "dc=search_test_entry");
2482 ret
= ldb_search(search_test_ctx
->ldb_test_ctx
->ldb
,
2484 &res2
, search_dn
, LDB_SCOPE_BASE
, NULL
,
2486 assert_int_equal(ret
, 0);
2488 /* We got the result */
2489 assert_int_equal(res2
->count
, 1);
2493 * This test is also complex.
2494 * The purpose is to test if a modify can occur during an ldb_search()
2495 * This would be a failure if if in process
2497 * - (1) ltdb_search() starts and calls back for one entry
2498 * - (2) one of the entries to be matched is modified
2499 * - (1) the indexed search tries to return the modified entry, but
2500 * it is no longer found, either:
2501 * - despite it still matching (dn changed)
2502 * - it no longer matching (attrs changed)
2504 * We also try un-indexed to show that the behaviour differs on this
2505 * point, which it should not (an index should only impact search
2510 * This purpose of this callback is to trigger a write in the callback
2511 * so as to change in in-memory index code while looping over the
2515 static int test_ldb_callback_modify_during_search_callback1(struct ldb_request
*req
,
2516 struct ldb_reply
*ares
)
2519 struct modify_during_search_test_ctx
*ctx
= req
->context
;
2520 struct ldb_dn
*dn
= NULL
, *new_dn
= NULL
;
2521 TALLOC_CTX
*tmp_ctx
= talloc_new(ctx
->test_ctx
);
2522 struct ldb_message
*msg
= NULL
;
2524 assert_non_null(tmp_ctx
);
2526 switch (ares
->type
) {
2527 case LDB_REPLY_ENTRY
:
2529 const struct ldb_val
*cn_val
2530 = ldb_dn_get_component_val(ares
->message
->dn
, 0);
2531 const char *cn
= (char *)cn_val
->data
;
2533 if (strcmp(cn
, "test_search_cn") == 0) {
2535 } else if (strcmp(cn
, "test_search_2_cn") == 0) {
2536 ctx
->got_2_cn
= true;
2538 if (ctx
->res_count
== 2) {
2543 case LDB_REPLY_REFERRAL
:
2546 case LDB_REPLY_DONE
:
2547 return ldb_request_done(req
, LDB_SUCCESS
);
2551 if (ctx
->got_2_cn
) {
2552 /* Modify this one */
2553 dn
= ldb_dn_new_fmt(tmp_ctx
,
2555 "cn=test_search_2_cn,%s",
2556 ldb_dn_get_linearized(ctx
->basedn
));
2558 dn
= ldb_dn_new_fmt(tmp_ctx
,
2560 "cn=test_search_cn,%s",
2561 ldb_dn_get_linearized(ctx
->basedn
));
2563 assert_non_null(dn
);
2565 new_dn
= ldb_dn_new_fmt(tmp_ctx
,
2567 "cn=test_search_cn_renamed,"
2568 "dc=not_search_test_entry");
2569 assert_non_null(new_dn
);
2571 ret
= ldb_rename(ctx
->test_ctx
->ldb
, dn
, new_dn
);
2572 assert_int_equal(ret
, 0);
2575 if (ctx
->got_2_cn
) {
2576 /* Delete this one */
2577 dn
= ldb_dn_new_fmt(tmp_ctx
,
2579 "cn=test_search_2_cn,%s",
2580 ldb_dn_get_linearized(ctx
->basedn
));
2582 dn
= ldb_dn_new_fmt(tmp_ctx
,
2584 "cn=test_search_cn,%s",
2585 ldb_dn_get_linearized(ctx
->basedn
));
2587 assert_non_null(dn
);
2589 ret
= ldb_delete(ctx
->test_ctx
->ldb
, dn
);
2590 assert_int_equal(ret
, 0);
2594 * Now fill in the position we just removed from the
2595 * index to ensure we fail the test (otherwise we just read
2596 * past the end of the array and find the value we wanted to
2599 msg
= ldb_msg_new(tmp_ctx
);
2600 assert_non_null(msg
);
2602 /* We deliberately use ou= not cn= here */
2603 msg
->dn
= ldb_dn_new_fmt(msg
,
2605 "ou=test_search_cn_extra,%s",
2606 ldb_dn_get_linearized(ctx
->basedn
));
2608 ret
= ldb_msg_add_string(msg
,
2610 "0123456789abcde3");
2612 ret
= ldb_add(ctx
->test_ctx
->ldb
,
2614 assert_int_equal(ret
, LDB_SUCCESS
);
2616 TALLOC_FREE(tmp_ctx
);
2620 static void test_ldb_callback_modify_during_search(void **state
, bool add_index
,
2623 struct search_test_ctx
*search_test_ctx
= talloc_get_type_abort(*state
,
2624 struct search_test_ctx
);
2625 struct modify_during_search_test_ctx
2628 .test_ctx
= search_test_ctx
->ldb_test_ctx
,
2633 struct ldb_request
*req
;
2635 ret
= ldb_transaction_start(search_test_ctx
->ldb_test_ctx
->ldb
);
2636 assert_int_equal(ret
, 0);
2639 struct ldb_message
*msg
;
2640 struct ldb_dn
*indexlist
= ldb_dn_new(search_test_ctx
,
2641 search_test_ctx
->ldb_test_ctx
->ldb
,
2643 assert_non_null(indexlist
);
2645 msg
= ldb_msg_new(search_test_ctx
);
2646 assert_non_null(msg
);
2648 msg
->dn
= indexlist
;
2650 ret
= ldb_msg_add_string(msg
, "@IDXONE", "1");
2651 assert_int_equal(ret
, LDB_SUCCESS
);
2652 ret
= ldb_msg_add_string(msg
, "@IDXATTR", "cn");
2653 assert_int_equal(ret
, LDB_SUCCESS
);
2654 ret
= ldb_add(search_test_ctx
->ldb_test_ctx
->ldb
,
2656 if (ret
== LDB_ERR_ENTRY_ALREADY_EXISTS
) {
2657 msg
->elements
[0].flags
= LDB_FLAG_MOD_ADD
;
2658 msg
->elements
[1].flags
= LDB_FLAG_MOD_ADD
;
2659 ret
= ldb_modify(search_test_ctx
->ldb_test_ctx
->ldb
,
2662 assert_int_equal(ret
, LDB_SUCCESS
);
2665 * Now bring the IDXONE index into memory by modifying
2666 * it. This exposes an issue in ldb_tdb
2668 msg
= ldb_msg_new(search_test_ctx
);
2669 assert_non_null(msg
);
2671 msg
->dn
= ldb_dn_new_fmt(search_test_ctx
,
2672 search_test_ctx
->ldb_test_ctx
->ldb
,
2673 "cn=test_search_cn_extra,%s",
2674 search_test_ctx
->base_dn
);
2676 ret
= ldb_msg_add_string(msg
,
2678 "0123456789abcde2");
2680 ret
= ldb_add(search_test_ctx
->ldb_test_ctx
->ldb
,
2682 assert_int_equal(ret
, LDB_SUCCESS
);
2684 ret
= ldb_delete(search_test_ctx
->ldb_test_ctx
->ldb
,
2686 assert_int_equal(ret
, LDB_SUCCESS
);
2689 tevent_loop_allow_nesting(search_test_ctx
->ldb_test_ctx
->ev
);
2692 = ldb_dn_new_fmt(search_test_ctx
,
2693 search_test_ctx
->ldb_test_ctx
->ldb
,
2695 search_test_ctx
->base_dn
);
2696 assert_non_null(ctx
.basedn
);
2700 * This search must be over multiple items, and should include
2701 * the new name after a rename, to show that it would match
2702 * both before and after that modify
2704 * This needs to be a search that isn't matched by an index so
2705 * that we just use the one-level index.
2707 ret
= ldb_build_search_req(&req
,
2708 search_test_ctx
->ldb_test_ctx
->ldb
,
2716 test_ldb_callback_modify_during_search_callback1
,
2718 assert_int_equal(ret
, 0);
2720 ret
= ldb_request(search_test_ctx
->ldb_test_ctx
->ldb
, req
);
2722 if (ret
== LDB_SUCCESS
) {
2723 ret
= ldb_wait(req
->handle
, LDB_WAIT_ALL
);
2725 assert_int_equal(ret
, 0);
2727 ret
= ldb_transaction_commit(search_test_ctx
->ldb_test_ctx
->ldb
);
2728 assert_int_equal(ret
, 0);
2730 assert_int_equal(ctx
.res_count
, 2);
2731 assert_int_equal(ctx
.got_cn
, true);
2732 assert_int_equal(ctx
.got_2_cn
, true);
2735 static void test_ldb_callback_delete_during_indexed_search(void **state
)
2737 test_ldb_callback_modify_during_search(state
, true, false);
2740 static void test_ldb_callback_delete_during_unindexed_search(void **state
)
2742 test_ldb_callback_modify_during_search(state
, false, false);
2745 static void test_ldb_callback_rename_during_indexed_search(void **state
)
2747 test_ldb_callback_modify_during_search(state
, true, true);
2750 static void test_ldb_callback_rename_during_unindexed_search(void **state
)
2752 test_ldb_callback_modify_during_search(state
, false, true);
2755 static int ldb_case_test_setup(void **state
)
2758 struct ldb_ldif
*ldif
;
2759 struct ldbtest_ctx
*ldb_test_ctx
;
2760 const char *attrs_ldif
= \
2762 "cn: CASE_INSENSITIVE\n"
2764 struct keyval kvs
[] = {
2765 { "cn", "CaseInsensitiveValue" },
2766 { "uid", "CaseSensitiveValue" },
2767 { "objectUUID", "0123456789abcdef" },
2772 ldbtest_setup((void **) &ldb_test_ctx
);
2774 while ((ldif
= ldb_ldif_read_string(ldb_test_ctx
->ldb
, &attrs_ldif
))) {
2775 ret
= ldb_add(ldb_test_ctx
->ldb
, ldif
->msg
);
2776 assert_int_equal(ret
, LDB_SUCCESS
);
2779 ldb_test_add_data(ldb_test_ctx
,
2781 "cn=CaseInsensitiveValue",
2784 *state
= ldb_test_ctx
;
2788 static int ldb_case_test_teardown(void **state
)
2791 struct ldbtest_ctx
*ldb_test_ctx
= talloc_get_type_abort(*state
,
2792 struct ldbtest_ctx
);
2794 struct ldb_dn
*del_dn
;
2796 del_dn
= ldb_dn_new_fmt(ldb_test_ctx
,
2799 assert_non_null(del_dn
);
2801 ret
= ldb_delete(ldb_test_ctx
->ldb
, del_dn
);
2802 assert_int_equal(ret
, LDB_SUCCESS
);
2804 assert_dn_doesnt_exist(ldb_test_ctx
,
2807 ldb_test_remove_data(ldb_test_ctx
, ldb_test_ctx
,
2808 "cn=CaseInsensitiveValue");
2810 ldbtest_teardown((void **) &ldb_test_ctx
);
2814 static void test_ldb_attrs_case_insensitive(void **state
)
2817 struct ldbtest_ctx
*ldb_test_ctx
= talloc_get_type_abort(*state
,
2818 struct ldbtest_ctx
);
2820 /* cn matches exact case */
2821 cnt
= sub_search_count(ldb_test_ctx
, "", "cn=CaseInsensitiveValue");
2822 assert_int_equal(cnt
, 1);
2824 /* cn matches lower case */
2825 cnt
= sub_search_count(ldb_test_ctx
, "", "cn=caseinsensitivevalue");
2826 assert_int_equal(cnt
, 1);
2828 /* uid matches exact case */
2829 cnt
= sub_search_count(ldb_test_ctx
, "", "uid=CaseSensitiveValue");
2830 assert_int_equal(cnt
, 1);
2832 /* uid does not match lower case */
2833 cnt
= sub_search_count(ldb_test_ctx
, "", "uid=casesensitivevalue");
2834 assert_int_equal(cnt
, 0);
2837 static struct ldb_schema_attribute cn_attr_1
;
2838 static struct ldb_schema_attribute cn_attr_2
;
2839 static struct ldb_schema_attribute default_attr
;
2842 override the name to attribute handler function
2844 static const struct ldb_schema_attribute
*ldb_test_attribute_handler_override(struct ldb_context
*ldb
,
2848 if (private_data
!= NULL
&& ldb_attr_cmp(name
, "cn") == 0) {
2850 } else if (private_data
== NULL
&& ldb_attr_cmp(name
, "cn") == 0) {
2852 } else if (ldb_attr_cmp(name
, "uid") == 0) {
2855 return &default_attr
;
2858 static void test_ldb_attrs_case_handler(void **state
)
2862 const struct ldb_schema_syntax
*syntax
;
2864 struct ldbtest_ctx
*ldb_test_ctx
= talloc_get_type_abort(*state
,
2865 struct ldbtest_ctx
);
2866 struct ldb_context
*ldb
= ldb_test_ctx
->ldb
;
2868 /* cn matches lower case */
2869 cnt
= sub_search_count(ldb_test_ctx
, "", "cn=caseinsensitivevalue");
2870 assert_int_equal(cnt
, 1);
2872 syntax
= ldb_standard_syntax_by_name(ldb
, LDB_SYNTAX_OCTET_STRING
);
2873 assert_non_null(syntax
);
2875 ret
= ldb_schema_attribute_fill_with_syntax(ldb
, ldb
,
2877 syntax
, &default_attr
);
2878 assert_int_equal(ret
, LDB_SUCCESS
);
2880 syntax
= ldb_standard_syntax_by_name(ldb
, LDB_SYNTAX_OCTET_STRING
);
2881 assert_non_null(syntax
);
2883 ret
= ldb_schema_attribute_fill_with_syntax(ldb
, ldb
,
2885 syntax
, &cn_attr_1
);
2886 assert_int_equal(ret
, LDB_SUCCESS
);
2889 * Set an attribute handler, which will fail to match as we
2890 * force case sensitive
2892 ldb_schema_attribute_set_override_handler(ldb
,
2893 ldb_test_attribute_handler_override
,
2896 /* cn does not matche lower case */
2897 cnt
= sub_search_count(ldb_test_ctx
, "", "cn=caseinsensitivevalue");
2898 assert_int_equal(cnt
, 0);
2900 syntax
= ldb_standard_syntax_by_name(ldb
, LDB_SYNTAX_DIRECTORY_STRING
);
2901 assert_non_null(syntax
);
2903 ret
= ldb_schema_attribute_fill_with_syntax(ldb
, ldb
,
2905 syntax
, &cn_attr_2
);
2906 assert_int_equal(ret
, LDB_SUCCESS
);
2909 * Set an attribute handler, which will match as we
2910 * force case insensitive
2912 ldb_schema_attribute_set_override_handler(ldb
,
2913 ldb_test_attribute_handler_override
,
2916 /* cn matches lower case */
2917 cnt
= sub_search_count(ldb_test_ctx
, "", "cn=caseinsensitivevalue");
2918 assert_int_equal(cnt
, 1);
2923 static void test_ldb_attrs_index_handler(void **state
)
2927 const struct ldb_schema_syntax
*syntax
;
2928 struct ldb_ldif
*ldif
;
2930 const char *index_ldif
= \
2935 struct ldbtest_ctx
*ldb_test_ctx
= talloc_get_type_abort(*state
,
2936 struct ldbtest_ctx
);
2937 struct ldb_context
*ldb
= ldb_test_ctx
->ldb
;
2939 /* cn matches lower case */
2940 cnt
= sub_search_count(ldb_test_ctx
, "", "cn=caseinsensitivevalue");
2941 assert_int_equal(cnt
, 1);
2943 syntax
= ldb_standard_syntax_by_name(ldb
, LDB_SYNTAX_OCTET_STRING
);
2944 assert_non_null(syntax
);
2946 ret
= ldb_schema_attribute_fill_with_syntax(ldb
, ldb
,
2948 syntax
, &cn_attr_1
);
2949 assert_int_equal(ret
, LDB_SUCCESS
);
2951 syntax
= ldb_standard_syntax_by_name(ldb
, LDB_SYNTAX_DIRECTORY_STRING
);
2952 assert_non_null(syntax
);
2954 ret
= ldb_schema_attribute_fill_with_syntax(ldb
, ldb
,
2955 "cn", LDB_ATTR_FLAG_INDEXED
,
2956 syntax
, &cn_attr_2
);
2957 assert_int_equal(ret
, LDB_SUCCESS
);
2959 syntax
= ldb_standard_syntax_by_name(ldb
, LDB_SYNTAX_OCTET_STRING
);
2960 assert_non_null(syntax
);
2962 ret
= ldb_schema_attribute_fill_with_syntax(ldb
, ldb
,
2964 syntax
, &default_attr
);
2965 assert_int_equal(ret
, LDB_SUCCESS
);
2968 * Set an attribute handler
2970 ldb_schema_attribute_set_override_handler(ldb
,
2971 ldb_test_attribute_handler_override
,
2974 /* cn matches lower case */
2975 cnt
= sub_search_count(ldb_test_ctx
, "", "cn=caseinsensitivevalue");
2976 assert_int_equal(cnt
, 1);
2978 /* Add the index (actually any modify will do) */
2979 while ((ldif
= ldb_ldif_read_string(ldb_test_ctx
->ldb
, &index_ldif
))) {
2980 ret
= ldb_add(ldb_test_ctx
->ldb
, ldif
->msg
);
2981 if (ret
== LDB_ERR_ENTRY_ALREADY_EXISTS
) {
2982 ldif
->msg
->elements
[0].flags
= LDB_FLAG_MOD_ADD
;
2983 ret
= ldb_modify(ldb_test_ctx
->ldb
,
2986 assert_int_equal(ret
, LDB_SUCCESS
);
2989 ldb_schema_set_override_indexlist(ldb
, false);
2991 /* cn does match as there is an index now */
2992 cnt
= sub_search_count(ldb_test_ctx
, "", "cn=caseinsensitivevalue");
2993 assert_int_equal(cnt
, 1);
2996 * Set an attribute handler, which will later fail to match as we
2997 * didn't re-index the DB
2999 ldb_schema_attribute_set_override_handler(ldb
,
3000 ldb_test_attribute_handler_override
,
3004 * cn does not match as we changed the case sensitivity, but
3007 * This shows that the override is in control
3009 cnt
= sub_search_count(ldb_test_ctx
, "", "cn=caseinsensitivevalue");
3010 assert_int_equal(cnt
, 0);
3014 static int ldb_case_attrs_index_test_teardown(void **state
)
3017 struct ldbtest_ctx
*ldb_test_ctx
= talloc_get_type_abort(*state
,
3018 struct ldbtest_ctx
);
3019 struct ldb_dn
*del_dn
;
3021 del_dn
= ldb_dn_new_fmt(ldb_test_ctx
,
3024 assert_non_null(del_dn
);
3026 ret
= ldb_delete(ldb_test_ctx
->ldb
, del_dn
);
3027 if (ret
!= LDB_ERR_NO_SUCH_OBJECT
) {
3028 assert_int_equal(ret
, LDB_SUCCESS
);
3031 assert_dn_doesnt_exist(ldb_test_ctx
,
3034 ldb_case_test_teardown(state
);
3039 struct rename_test_ctx
{
3040 struct ldbtest_ctx
*ldb_test_ctx
;
3042 struct ldb_dn
*basedn
;
3043 const char *str_basedn
;
3045 const char *teardown_dn
;
3048 static int ldb_rename_test_setup(void **state
)
3050 struct ldbtest_ctx
*ldb_test_ctx
;
3051 struct rename_test_ctx
*rename_test_ctx
;
3052 const char *strdn
= "dc=rename_test_entry_from";
3054 ldbtest_setup((void **) &ldb_test_ctx
);
3056 rename_test_ctx
= talloc(ldb_test_ctx
, struct rename_test_ctx
);
3057 assert_non_null(rename_test_ctx
);
3058 rename_test_ctx
->ldb_test_ctx
= ldb_test_ctx
;
3059 assert_non_null(rename_test_ctx
->ldb_test_ctx
);
3061 rename_test_ctx
->basedn
= ldb_dn_new_fmt(rename_test_ctx
,
3062 rename_test_ctx
->ldb_test_ctx
->ldb
,
3064 assert_non_null(rename_test_ctx
->basedn
);
3066 rename_test_ctx
->str_basedn
= strdn
;
3067 rename_test_ctx
->teardown_dn
= strdn
;
3069 add_dn_with_cn(ldb_test_ctx
,
3070 rename_test_ctx
->basedn
,
3071 "test_rename_cn_val",
3072 "0123456789abcde0");
3074 *state
= rename_test_ctx
;
3078 static int ldb_rename_test_teardown(void **state
)
3081 struct rename_test_ctx
*rename_test_ctx
= talloc_get_type_abort(*state
,
3082 struct rename_test_ctx
);
3083 struct ldbtest_ctx
*ldb_test_ctx
;
3084 struct ldb_dn
*del_dn
;
3086 ldb_test_ctx
= rename_test_ctx
->ldb_test_ctx
;
3088 del_dn
= ldb_dn_new_fmt(rename_test_ctx
,
3089 rename_test_ctx
->ldb_test_ctx
->ldb
,
3090 "%s", rename_test_ctx
->teardown_dn
);
3091 assert_non_null(del_dn
);
3093 ret
= ldb_delete(ldb_test_ctx
->ldb
, del_dn
);
3094 assert_int_equal(ret
, LDB_SUCCESS
);
3096 assert_dn_doesnt_exist(ldb_test_ctx
,
3097 rename_test_ctx
->teardown_dn
);
3099 ldbtest_teardown((void **) &ldb_test_ctx
);
3103 static void test_ldb_rename(void **state
)
3105 struct rename_test_ctx
*rename_test_ctx
=
3106 talloc_get_type_abort(*state
, struct rename_test_ctx
);
3108 const char *str_new_dn
= "dc=rename_test_entry_to";
3109 struct ldb_dn
*new_dn
;
3111 new_dn
= ldb_dn_new_fmt(rename_test_ctx
,
3112 rename_test_ctx
->ldb_test_ctx
->ldb
,
3114 assert_non_null(new_dn
);
3116 ret
= ldb_rename(rename_test_ctx
->ldb_test_ctx
->ldb
,
3117 rename_test_ctx
->basedn
,
3119 assert_int_equal(ret
, LDB_SUCCESS
);
3121 assert_dn_exists(rename_test_ctx
->ldb_test_ctx
, str_new_dn
);
3122 assert_dn_doesnt_exist(rename_test_ctx
->ldb_test_ctx
,
3123 rename_test_ctx
->str_basedn
);
3124 rename_test_ctx
->teardown_dn
= str_new_dn
;
3126 /* FIXME - test the values which didn't change */
3129 static void test_ldb_rename_from_doesnt_exist(void **state
)
3131 struct rename_test_ctx
*rename_test_ctx
= talloc_get_type_abort(
3133 struct rename_test_ctx
);
3135 const char *str_new_dn
= "dc=rename_test_entry_to";
3136 const char *str_bad_old_dn
= "dc=rename_test_no_such_entry";
3137 struct ldb_dn
*new_dn
;
3138 struct ldb_dn
*bad_old_dn
;
3140 new_dn
= ldb_dn_new_fmt(rename_test_ctx
,
3141 rename_test_ctx
->ldb_test_ctx
->ldb
,
3143 assert_non_null(new_dn
);
3145 bad_old_dn
= ldb_dn_new_fmt(rename_test_ctx
,
3146 rename_test_ctx
->ldb_test_ctx
->ldb
,
3147 "%s", str_bad_old_dn
);
3148 assert_non_null(bad_old_dn
);
3150 assert_dn_doesnt_exist(rename_test_ctx
->ldb_test_ctx
,
3153 ret
= ldb_rename(rename_test_ctx
->ldb_test_ctx
->ldb
,
3154 bad_old_dn
, new_dn
);
3155 assert_int_equal(ret
, LDB_ERR_NO_SUCH_OBJECT
);
3157 assert_dn_doesnt_exist(rename_test_ctx
->ldb_test_ctx
,
3161 static void test_ldb_rename_to_exists(void **state
)
3163 struct rename_test_ctx
*rename_test_ctx
= talloc_get_type_abort(
3165 struct rename_test_ctx
);
3167 const char *str_new_dn
= "dc=rename_test_already_exists";
3168 struct ldb_dn
*new_dn
;
3170 new_dn
= ldb_dn_new_fmt(rename_test_ctx
,
3171 rename_test_ctx
->ldb_test_ctx
->ldb
,
3173 assert_non_null(new_dn
);
3175 add_dn_with_cn(rename_test_ctx
->ldb_test_ctx
,
3177 "test_rename_cn_val",
3178 "0123456789abcde1");
3180 ret
= ldb_rename(rename_test_ctx
->ldb_test_ctx
->ldb
,
3181 rename_test_ctx
->basedn
,
3183 assert_int_equal(ret
, LDB_ERR_ENTRY_ALREADY_EXISTS
);
3185 /* Old object must still exist */
3186 assert_dn_exists(rename_test_ctx
->ldb_test_ctx
,
3187 rename_test_ctx
->str_basedn
);
3189 ret
= ldb_delete(rename_test_ctx
->ldb_test_ctx
->ldb
,
3191 assert_int_equal(ret
, LDB_SUCCESS
);
3193 assert_dn_exists(rename_test_ctx
->ldb_test_ctx
,
3194 rename_test_ctx
->teardown_dn
);
3197 static void test_ldb_rename_self(void **state
)
3199 struct rename_test_ctx
*rename_test_ctx
= talloc_get_type_abort(
3201 struct rename_test_ctx
);
3204 /* Oddly enough, this is a success in ldb.. */
3205 ret
= ldb_rename(rename_test_ctx
->ldb_test_ctx
->ldb
,
3206 rename_test_ctx
->basedn
,
3207 rename_test_ctx
->basedn
);
3208 assert_int_equal(ret
, LDB_SUCCESS
);
3210 /* Old object must still exist */
3211 assert_dn_exists(rename_test_ctx
->ldb_test_ctx
,
3212 rename_test_ctx
->str_basedn
);
3215 static void test_ldb_rename_dn_case_change(void **state
)
3217 struct rename_test_ctx
*rename_test_ctx
= talloc_get_type_abort(
3219 struct rename_test_ctx
);
3222 struct ldb_dn
*new_dn
;
3225 str_new_dn
= talloc_strdup(rename_test_ctx
, rename_test_ctx
->str_basedn
);
3226 assert_non_null(str_new_dn
);
3227 for (i
= 0; str_new_dn
[i
]; i
++) {
3228 str_new_dn
[i
] = toupper(str_new_dn
[i
]);
3231 new_dn
= ldb_dn_new_fmt(rename_test_ctx
,
3232 rename_test_ctx
->ldb_test_ctx
->ldb
,
3234 assert_non_null(new_dn
);
3236 ret
= ldb_rename(rename_test_ctx
->ldb_test_ctx
->ldb
,
3237 rename_test_ctx
->basedn
,
3239 assert_int_equal(ret
, LDB_SUCCESS
);
3241 /* DNs are case insensitive, so both searches will match */
3242 assert_dn_exists(rename_test_ctx
->ldb_test_ctx
, str_new_dn
);
3243 assert_dn_exists(rename_test_ctx
->ldb_test_ctx
,
3244 rename_test_ctx
->str_basedn
);
3245 /* FIXME - test the values didn't change */
3248 static int ldb_read_only_setup(void **state
)
3250 struct ldbtest_ctx
*test_ctx
;
3252 ldbtest_setup((void **) &test_ctx
);
3258 static int ldb_read_only_teardown(void **state
)
3260 struct ldbtest_ctx
*test_ctx
= talloc_get_type_abort(*state
,
3261 struct ldbtest_ctx
);
3262 ldbtest_teardown((void **) &test_ctx
);
3266 static void test_read_only(void **state
)
3268 struct ldb_context
*ro_ldb
= NULL
;
3269 struct ldb_context
*rw_ldb
= NULL
;
3271 TALLOC_CTX
*tmp_ctx
= NULL
;
3273 struct ldbtest_ctx
*test_ctx
= talloc_get_type_abort(*state
,
3274 struct ldbtest_ctx
);
3276 * Close the ldb context freeing it this will ensure it exists on
3277 * disk and can be opened in read only mode
3279 TALLOC_FREE(test_ctx
->ldb
);
3282 * Open the database in read only and read write mode,
3283 * ensure it's opened in read only mode first
3285 ro_ldb
= ldb_init(test_ctx
, test_ctx
->ev
);
3286 ret
= ldb_connect(ro_ldb
, test_ctx
->dbpath
, LDB_FLG_RDONLY
, NULL
);
3287 assert_int_equal(ret
, 0);
3289 rw_ldb
= ldb_init(test_ctx
, test_ctx
->ev
);
3290 ret
= ldb_connect(rw_ldb
, test_ctx
->dbpath
, 0, NULL
);
3291 assert_int_equal(ret
, 0);
3295 * Set up a context for the temporary variables
3297 tmp_ctx
= talloc_new(test_ctx
);
3298 assert_non_null(tmp_ctx
);
3301 * Ensure that we can search the read write database
3304 struct ldb_result
*result
= NULL
;
3305 struct ldb_dn
*dn
= ldb_dn_new_fmt(tmp_ctx
, rw_ldb
,
3307 assert_non_null(dn
);
3309 ret
= ldb_search(rw_ldb
, tmp_ctx
, &result
, dn
,
3310 LDB_SCOPE_BASE
, NULL
, NULL
);
3311 assert_int_equal(ret
, LDB_SUCCESS
);
3312 TALLOC_FREE(result
);
3317 * Ensure that we can search the read only database
3320 struct ldb_result
*result
= NULL
;
3321 struct ldb_dn
*dn
= ldb_dn_new_fmt(tmp_ctx
, ro_ldb
,
3323 assert_non_null(dn
);
3325 ret
= ldb_search(ro_ldb
, tmp_ctx
, &result
, dn
,
3326 LDB_SCOPE_BASE
, NULL
, NULL
);
3327 assert_int_equal(ret
, LDB_SUCCESS
);
3328 TALLOC_FREE(result
);
3332 * Ensure that a write to the read only database fails
3335 struct ldb_message
*msg
= NULL
;
3336 msg
= ldb_msg_new(tmp_ctx
);
3337 assert_non_null(msg
);
3339 msg
->dn
= ldb_dn_new_fmt(msg
, ro_ldb
, "dc=test");
3340 assert_non_null(msg
->dn
);
3342 ret
= ldb_msg_add_string(msg
, "cn", "test_cn_val");
3343 assert_int_equal(ret
, 0);
3345 ret
= ldb_msg_add_string(msg
, "objectUUID",
3346 "0123456789abcde1");
3347 assert_int_equal(ret
, LDB_SUCCESS
);
3349 ret
= ldb_add(ro_ldb
, msg
);
3350 assert_int_equal(ret
, LDB_ERR_UNWILLING_TO_PERFORM
);
3355 * Ensure that a write to the read write database succeeds
3358 struct ldb_message
*msg
= NULL
;
3359 msg
= ldb_msg_new(tmp_ctx
);
3360 assert_non_null(msg
);
3362 msg
->dn
= ldb_dn_new_fmt(msg
, rw_ldb
, "dc=test");
3363 assert_non_null(msg
->dn
);
3365 ret
= ldb_msg_add_string(msg
, "cn", "test_cn_val");
3366 assert_int_equal(ret
, 0);
3368 ret
= ldb_msg_add_string(msg
, "objectUUID",
3369 "0123456789abcde2");
3370 assert_int_equal(ret
, LDB_SUCCESS
);
3372 ret
= ldb_add(rw_ldb
, msg
);
3373 assert_int_equal(ret
, LDB_SUCCESS
);
3378 * Ensure that a delete from a read only database fails
3381 struct ldb_dn
*dn
= ldb_dn_new_fmt(tmp_ctx
, ro_ldb
, "dc=test");
3382 assert_non_null(dn
);
3384 ret
= ldb_delete(ro_ldb
, dn
);
3385 assert_int_equal(ret
, LDB_ERR_UNWILLING_TO_PERFORM
);
3391 * Ensure that a delete from a read write succeeds
3394 struct ldb_dn
*dn
= ldb_dn_new_fmt(tmp_ctx
, rw_ldb
, "dc=test");
3395 assert_non_null(dn
);
3397 ret
= ldb_delete(rw_ldb
, dn
);
3398 assert_int_equal(ret
, LDB_SUCCESS
);
3401 TALLOC_FREE(tmp_ctx
);
3404 static bool unique_values
= false;
3406 static int unique_index_test_module_add(
3407 struct ldb_module
*module
,
3408 struct ldb_request
*req
)
3410 if (unique_values
) {
3411 struct ldb_message
*msg
= discard_const(req
->op
.add
.message
);
3412 struct ldb_message_element
*el
= NULL
;
3413 el
= ldb_msg_find_element(msg
, "cn");
3415 el
->flags
|= LDB_FLAG_INTERNAL_FORCE_UNIQUE_INDEX
;
3419 return ldb_next_request(module
, req
);
3422 static int unique_index_test_module_init(struct ldb_module
*module
)
3424 return ldb_next_init(module
);
3427 static const struct ldb_module_ops ldb_unique_index_test_module_ops
= {
3428 .name
= "unique_index_test",
3429 .init_context
= unique_index_test_module_init
,
3430 .add
= unique_index_test_module_add
,
3433 static int ldb_unique_index_test_setup(void **state
)
3436 struct ldb_ldif
*ldif
;
3437 struct ldbtest_ctx
*ldb_test_ctx
;
3438 const char *attrs_ldif
= \
3440 "cn: UNIQUE_INDEX\n"
3442 const char *index_ldif
= \
3446 "@IDXGUID: objectUUID\n"
3447 "@IDX_DN_GUID: GUID\n"
3450 const char *options
[] = {"modules:unique_index_test", NULL
};
3453 ret
= ldb_register_module(&ldb_unique_index_test_module_ops
);
3454 assert_true(ret
== LDB_SUCCESS
|| ret
== LDB_ERR_ENTRY_ALREADY_EXISTS
);
3455 ldbtest_noconn_setup((void **) &ldb_test_ctx
);
3458 ret
= ldb_connect(ldb_test_ctx
->ldb
, ldb_test_ctx
->dbpath
, 0, options
);
3459 assert_int_equal(ret
, 0);
3461 while ((ldif
= ldb_ldif_read_string(ldb_test_ctx
->ldb
, &attrs_ldif
))) {
3462 ret
= ldb_add(ldb_test_ctx
->ldb
, ldif
->msg
);
3463 assert_int_equal(ret
, LDB_SUCCESS
);
3466 while ((ldif
= ldb_ldif_read_string(ldb_test_ctx
->ldb
, &index_ldif
))) {
3467 ret
= ldb_add(ldb_test_ctx
->ldb
, ldif
->msg
);
3468 assert_int_equal(ret
, LDB_SUCCESS
);
3471 unique_values
= true;
3473 *state
= ldb_test_ctx
;
3477 static int ldb_unique_index_test_teardown(void **state
)
3480 struct ldbtest_ctx
*ldb_test_ctx
= talloc_get_type_abort(*state
,
3481 struct ldbtest_ctx
);
3482 struct ldb_dn
*del_dn
;
3484 del_dn
= ldb_dn_new_fmt(ldb_test_ctx
,
3487 assert_non_null(del_dn
);
3489 ret
= ldb_delete(ldb_test_ctx
->ldb
, del_dn
);
3490 if (ret
!= LDB_ERR_NO_SUCH_OBJECT
) {
3491 assert_int_equal(ret
, LDB_SUCCESS
);
3494 assert_dn_doesnt_exist(ldb_test_ctx
,
3497 TALLOC_FREE(del_dn
);
3499 del_dn
= ldb_dn_new_fmt(ldb_test_ctx
,
3502 assert_non_null(del_dn
);
3504 ret
= ldb_delete(ldb_test_ctx
->ldb
, del_dn
);
3505 if (ret
!= LDB_ERR_NO_SUCH_OBJECT
) {
3506 assert_int_equal(ret
, LDB_SUCCESS
);
3509 assert_dn_doesnt_exist(ldb_test_ctx
,
3512 ldbtest_teardown((void **) &ldb_test_ctx
);
3517 static void test_ldb_add_unique_value_to_unique_index(void **state
)
3520 struct ldb_message
*msg
;
3521 struct ldbtest_ctx
*test_ctx
= talloc_get_type_abort(*state
,
3522 struct ldbtest_ctx
);
3523 TALLOC_CTX
*tmp_ctx
;
3525 tmp_ctx
= talloc_new(test_ctx
);
3526 assert_non_null(tmp_ctx
);
3528 msg
= ldb_msg_new(tmp_ctx
);
3529 assert_non_null(msg
);
3531 msg
->dn
= ldb_dn_new_fmt(msg
, test_ctx
->ldb
, "dc=test");
3532 assert_non_null(msg
->dn
);
3534 ret
= ldb_msg_add_string(msg
, "cn", "test_unique_index");
3535 assert_int_equal(ret
, LDB_SUCCESS
);
3537 ret
= ldb_msg_add_string(msg
, "objectUUID",
3538 "0123456789abcde1");
3539 assert_int_equal(ret
, LDB_SUCCESS
);
3541 ret
= ldb_add(test_ctx
->ldb
, msg
);
3542 assert_int_equal(ret
, LDB_SUCCESS
);
3544 talloc_free(tmp_ctx
);
3547 static int ldb_non_unique_index_test_setup(void **state
)
3550 struct ldb_ldif
*ldif
;
3551 struct ldbtest_ctx
*ldb_test_ctx
;
3552 const char *index_ldif
= \
3556 "@IDXGUID: objectUUID\n"
3557 "@IDX_DN_GUID: GUID\n"
3560 const char *options
[] = {"modules:unique_index_test", NULL
};
3563 ret
= ldb_register_module(&ldb_unique_index_test_module_ops
);
3564 assert_true(ret
== LDB_SUCCESS
|| ret
== LDB_ERR_ENTRY_ALREADY_EXISTS
);
3565 ldbtest_noconn_setup((void **) &ldb_test_ctx
);
3568 ret
= ldb_connect(ldb_test_ctx
->ldb
, ldb_test_ctx
->dbpath
, 0, options
);
3569 assert_int_equal(ret
, 0);
3571 while ((ldif
= ldb_ldif_read_string(ldb_test_ctx
->ldb
, &index_ldif
))) {
3572 ret
= ldb_add(ldb_test_ctx
->ldb
, ldif
->msg
);
3573 assert_int_equal(ret
, LDB_SUCCESS
);
3576 unique_values
= true;
3578 *state
= ldb_test_ctx
;
3582 static int ldb_non_unique_index_test_teardown(void **state
)
3585 struct ldbtest_ctx
*ldb_test_ctx
= talloc_get_type_abort(*state
,
3586 struct ldbtest_ctx
);
3587 struct ldb_dn
*del_dn
;
3589 del_dn
= ldb_dn_new_fmt(ldb_test_ctx
,
3592 assert_non_null(del_dn
);
3594 ret
= ldb_delete(ldb_test_ctx
->ldb
, del_dn
);
3595 if (ret
!= LDB_ERR_NO_SUCH_OBJECT
) {
3596 assert_int_equal(ret
, LDB_SUCCESS
);
3599 assert_dn_doesnt_exist(ldb_test_ctx
,
3602 TALLOC_FREE(del_dn
);
3604 ldbtest_teardown((void **) &ldb_test_ctx
);
3608 static void test_ldb_add_duplicate_value_to_unique_index(void **state
)
3611 struct ldb_message
*msg01
;
3612 struct ldb_message
*msg02
;
3613 struct ldbtest_ctx
*test_ctx
= talloc_get_type_abort(*state
,
3614 struct ldbtest_ctx
);
3615 TALLOC_CTX
*tmp_ctx
;
3617 tmp_ctx
= talloc_new(test_ctx
);
3618 assert_non_null(tmp_ctx
);
3620 msg01
= ldb_msg_new(tmp_ctx
);
3621 assert_non_null(msg01
);
3623 msg01
->dn
= ldb_dn_new_fmt(msg01
, test_ctx
->ldb
, "dc=test01");
3624 assert_non_null(msg01
->dn
);
3626 ret
= ldb_msg_add_string(msg01
, "cn", "test_unique_index");
3627 assert_int_equal(ret
, LDB_SUCCESS
);
3629 ret
= ldb_msg_add_string(msg01
, "objectUUID",
3630 "0123456789abcde1");
3631 assert_int_equal(ret
, LDB_SUCCESS
);
3633 ret
= ldb_add(test_ctx
->ldb
, msg01
);
3634 assert_int_equal(ret
, LDB_SUCCESS
);
3636 msg02
= ldb_msg_new(tmp_ctx
);
3637 assert_non_null(msg02
);
3639 msg02
->dn
= ldb_dn_new_fmt(msg02
, test_ctx
->ldb
, "dc=test02");
3640 assert_non_null(msg02
->dn
);
3642 ret
= ldb_msg_add_string(msg02
, "cn", "test_unique_index");
3643 assert_int_equal(ret
, LDB_SUCCESS
);
3645 ret
= ldb_msg_add_string(msg02
, "objectUUID",
3646 "0123456789abcde2");
3647 assert_int_equal(ret
, LDB_SUCCESS
);
3649 ret
= ldb_add(test_ctx
->ldb
, msg02
);
3650 assert_int_equal(ret
, LDB_ERR_CONSTRAINT_VIOLATION
);
3651 talloc_free(tmp_ctx
);
3654 static void test_ldb_add_to_index_duplicates_allowed(void **state
)
3657 struct ldb_message
*msg01
;
3658 struct ldb_message
*msg02
;
3659 struct ldbtest_ctx
*test_ctx
= talloc_get_type_abort(*state
,
3660 struct ldbtest_ctx
);
3661 TALLOC_CTX
*tmp_ctx
;
3663 unique_values
= false;
3665 tmp_ctx
= talloc_new(test_ctx
);
3666 assert_non_null(tmp_ctx
);
3669 msg01
= ldb_msg_new(tmp_ctx
);
3670 assert_non_null(msg01
);
3672 msg01
->dn
= ldb_dn_new_fmt(msg01
, test_ctx
->ldb
, "dc=test01");
3673 assert_non_null(msg01
->dn
);
3675 ret
= ldb_msg_add_string(msg01
, "cn", "test_unique_index");
3676 assert_int_equal(ret
, LDB_SUCCESS
);
3678 ret
= ldb_msg_add_string(msg01
, "objectUUID",
3679 "0123456789abcde1");
3681 ret
= ldb_add(test_ctx
->ldb
, msg01
);
3682 assert_int_equal(ret
, LDB_SUCCESS
);
3684 msg02
= ldb_msg_new(tmp_ctx
);
3685 assert_non_null(msg02
);
3687 msg02
->dn
= ldb_dn_new_fmt(msg02
, test_ctx
->ldb
, "dc=test02");
3688 assert_non_null(msg02
->dn
);
3690 ret
= ldb_msg_add_string(msg02
, "cn", "test_unique_index");
3691 assert_int_equal(ret
, LDB_SUCCESS
);
3693 ret
= ldb_msg_add_string(msg02
, "objectUUID",
3694 "0123456789abcde2");
3696 ret
= ldb_add(test_ctx
->ldb
, msg02
);
3697 assert_int_equal(ret
, LDB_SUCCESS
);
3698 talloc_free(tmp_ctx
);
3701 static void test_ldb_add_to_index_unique_values_required(void **state
)
3704 struct ldb_message
*msg01
;
3705 struct ldb_message
*msg02
;
3706 struct ldbtest_ctx
*test_ctx
= talloc_get_type_abort(*state
,
3707 struct ldbtest_ctx
);
3708 TALLOC_CTX
*tmp_ctx
;
3710 unique_values
= true;
3712 tmp_ctx
= talloc_new(test_ctx
);
3713 assert_non_null(tmp_ctx
);
3716 msg01
= ldb_msg_new(tmp_ctx
);
3717 assert_non_null(msg01
);
3719 msg01
->dn
= ldb_dn_new_fmt(msg01
, test_ctx
->ldb
, "dc=test01");
3720 assert_non_null(msg01
->dn
);
3722 ret
= ldb_msg_add_string(msg01
, "cn", "test_unique_index");
3723 assert_int_equal(ret
, LDB_SUCCESS
);
3725 ret
= ldb_msg_add_string(msg01
, "objectUUID",
3726 "0123456789abcde1");
3728 ret
= ldb_add(test_ctx
->ldb
, msg01
);
3729 assert_int_equal(ret
, LDB_SUCCESS
);
3731 msg02
= ldb_msg_new(tmp_ctx
);
3732 assert_non_null(msg02
);
3734 msg02
->dn
= ldb_dn_new_fmt(msg02
, test_ctx
->ldb
, "dc=test02");
3735 assert_non_null(msg02
->dn
);
3737 ret
= ldb_msg_add_string(msg02
, "cn", "test_unique_index");
3738 assert_int_equal(ret
, LDB_SUCCESS
);
3740 ret
= ldb_msg_add_string(msg02
, "objectUUID",
3741 "0123456789abcde2");
3743 ret
= ldb_add(test_ctx
->ldb
, msg02
);
3744 assert_int_equal(ret
, LDB_ERR_CONSTRAINT_VIOLATION
);
3745 talloc_free(tmp_ctx
);
3748 static void PRINTF_ATTRIBUTE(3, 0) ldb_debug_string(
3750 enum ldb_debug_level level
,
3751 const char *fmt
, va_list ap
)
3753 struct ldbtest_ctx
*test_ctx
=
3754 talloc_get_type_abort(context
, struct ldbtest_ctx
);
3756 if (level
<= LDB_DEBUG_WARNING
) {
3757 test_ctx
->debug_string
= talloc_vasprintf(test_ctx
, fmt
, ap
);
3761 static void test_ldb_unique_index_duplicate_logging(void **state
)
3764 struct ldb_message
*msg01
;
3765 struct ldb_message
*msg02
;
3766 struct ldbtest_ctx
*test_ctx
= talloc_get_type_abort(*state
,
3767 struct ldbtest_ctx
);
3768 TALLOC_CTX
*tmp_ctx
;
3771 /* The GUID mode is not compatible with this test */
3776 ldb_set_debug(test_ctx
->ldb
, ldb_debug_string
, test_ctx
);
3777 tmp_ctx
= talloc_new(test_ctx
);
3778 assert_non_null(tmp_ctx
);
3780 msg01
= ldb_msg_new(tmp_ctx
);
3781 assert_non_null(msg01
);
3783 msg01
->dn
= ldb_dn_new_fmt(msg01
, test_ctx
->ldb
, "dc=test01");
3784 assert_non_null(msg01
->dn
);
3786 ret
= ldb_msg_add_string(msg01
, "cn", "test_unique_index");
3787 assert_int_equal(ret
, LDB_SUCCESS
);
3789 ret
= ldb_msg_add_string(msg01
, "objectUUID",
3790 "0123456789abcde1");
3792 ret
= ldb_add(test_ctx
->ldb
, msg01
);
3793 assert_int_equal(ret
, LDB_SUCCESS
);
3795 msg02
= ldb_msg_new(tmp_ctx
);
3796 assert_non_null(msg02
);
3798 msg02
->dn
= ldb_dn_new_fmt(msg02
, test_ctx
->ldb
, "dc=test02");
3799 assert_non_null(msg02
->dn
);
3801 ret
= ldb_msg_add_string(msg02
, "cn", "test_unique_index");
3802 assert_int_equal(ret
, LDB_SUCCESS
);
3804 ret
= ldb_msg_add_string(msg02
, "objectUUID",
3805 "0123456789abcde2");
3807 ret
= ldb_add(test_ctx
->ldb
, msg02
);
3808 assert_int_equal(ret
, LDB_ERR_CONSTRAINT_VIOLATION
);
3810 assert_non_null(test_ctx
->debug_string
);
3812 test_ctx
->debug_string
,
3813 "unique index violation on cn "
3814 "in dc=test02, conflicts with dc=test01 in "
3815 "@INDEX:CN:test_unique_index");
3817 TALLOC_FREE(test_ctx
->debug_string
);
3818 talloc_free(tmp_ctx
);
3821 static void test_ldb_duplicate_dn_logging(void **state
)
3824 struct ldb_message
*msg01
;
3825 struct ldb_message
*msg02
;
3826 struct ldbtest_ctx
*test_ctx
= talloc_get_type_abort(*state
,
3827 struct ldbtest_ctx
);
3828 TALLOC_CTX
*tmp_ctx
;
3830 /* The GUID mode is not compatible with this test */
3835 ldb_set_debug(test_ctx
->ldb
, ldb_debug_string
, test_ctx
);
3836 tmp_ctx
= talloc_new(test_ctx
);
3837 assert_non_null(tmp_ctx
);
3839 msg01
= ldb_msg_new(tmp_ctx
);
3840 assert_non_null(msg01
);
3842 msg01
->dn
= ldb_dn_new_fmt(msg01
, test_ctx
->ldb
, "dc=test01");
3843 assert_non_null(msg01
->dn
);
3845 ret
= ldb_msg_add_string(msg01
, "cn", "test_unique_index01");
3846 assert_int_equal(ret
, LDB_SUCCESS
);
3848 ret
= ldb_msg_add_string(msg01
, "objectUUID",
3849 "0123456789abcde1");
3851 ret
= ldb_add(test_ctx
->ldb
, msg01
);
3852 assert_int_equal(ret
, LDB_SUCCESS
);
3854 msg02
= ldb_msg_new(tmp_ctx
);
3855 assert_non_null(msg02
);
3857 msg02
->dn
= ldb_dn_new_fmt(msg02
, test_ctx
->ldb
, "dc=test01");
3858 assert_non_null(msg02
->dn
);
3860 ret
= ldb_msg_add_string(msg02
, "cn", "test_unique_index02");
3861 assert_int_equal(ret
, LDB_SUCCESS
);
3863 ret
= ldb_msg_add_string(msg02
, "objectUUID",
3864 "0123456789abcde2");
3866 ret
= ldb_add(test_ctx
->ldb
, msg02
);
3867 assert_int_equal(ret
, LDB_ERR_ENTRY_ALREADY_EXISTS
);
3869 assert_null(test_ctx
->debug_string
);
3870 talloc_free(tmp_ctx
);
3873 static int ldb_guid_index_test_setup(void **state
)
3876 struct ldb_ldif
*ldif
;
3877 struct ldbtest_ctx
*ldb_test_ctx
;
3878 const char *attrs_ldif
= \
3880 "cn: UNIQUE_INDEX\n"
3882 const char *index_ldif
= \
3885 "@IDXGUID: objectUUID\n"
3886 "@IDX_DN_GUID: GUID\n"
3889 ldbtest_noconn_setup((void **) &ldb_test_ctx
);
3892 ret
= ldb_connect(ldb_test_ctx
->ldb
, ldb_test_ctx
->dbpath
, 0, NULL
);
3893 assert_int_equal(ret
, 0);
3895 while ((ldif
= ldb_ldif_read_string(ldb_test_ctx
->ldb
, &attrs_ldif
))) {
3896 ret
= ldb_add(ldb_test_ctx
->ldb
, ldif
->msg
);
3897 assert_int_equal(ret
, LDB_SUCCESS
);
3900 while ((ldif
= ldb_ldif_read_string(ldb_test_ctx
->ldb
, &index_ldif
))) {
3901 ret
= ldb_add(ldb_test_ctx
->ldb
, ldif
->msg
);
3902 assert_int_equal(ret
, LDB_SUCCESS
);
3905 *state
= ldb_test_ctx
;
3909 static int ldb_guid_index_test_teardown(void **state
)
3912 struct ldbtest_ctx
*ldb_test_ctx
= talloc_get_type_abort(*state
,
3913 struct ldbtest_ctx
);
3914 struct ldb_dn
*del_dn
;
3916 del_dn
= ldb_dn_new_fmt(ldb_test_ctx
,
3919 assert_non_null(del_dn
);
3921 ret
= ldb_delete(ldb_test_ctx
->ldb
, del_dn
);
3922 if (ret
!= LDB_ERR_NO_SUCH_OBJECT
) {
3923 assert_int_equal(ret
, LDB_SUCCESS
);
3926 assert_dn_doesnt_exist(ldb_test_ctx
,
3929 TALLOC_FREE(del_dn
);
3931 del_dn
= ldb_dn_new_fmt(ldb_test_ctx
,
3934 assert_non_null(del_dn
);
3936 ret
= ldb_delete(ldb_test_ctx
->ldb
, del_dn
);
3937 if (ret
!= LDB_ERR_NO_SUCH_OBJECT
) {
3938 assert_int_equal(ret
, LDB_SUCCESS
);
3941 assert_dn_doesnt_exist(ldb_test_ctx
,
3944 ldbtest_teardown((void **) &ldb_test_ctx
);
3949 static void test_ldb_unique_index_duplicate_with_guid(void **state
)
3952 struct ldb_message
*msg01
;
3953 struct ldb_message
*msg02
;
3954 struct ldbtest_ctx
*test_ctx
= talloc_get_type_abort(*state
,
3955 struct ldbtest_ctx
);
3956 TALLOC_CTX
*tmp_ctx
;
3959 ldb_set_debug(test_ctx
->ldb
, ldb_debug_string
, test_ctx
);
3960 tmp_ctx
= talloc_new(test_ctx
);
3961 assert_non_null(tmp_ctx
);
3963 msg01
= ldb_msg_new(tmp_ctx
);
3964 assert_non_null(msg01
);
3966 msg01
->dn
= ldb_dn_new_fmt(msg01
, test_ctx
->ldb
, "dc=test01");
3967 assert_non_null(msg01
->dn
);
3969 ret
= ldb_msg_add_string(msg01
, "cn", "test_unique_index");
3970 assert_int_equal(ret
, LDB_SUCCESS
);
3972 ret
= ldb_msg_add_string(msg01
, "objectUUID", "0123456789abcdef");
3973 assert_int_equal(ret
, LDB_SUCCESS
);
3975 ret
= ldb_add(test_ctx
->ldb
, msg01
);
3976 assert_int_equal(ret
, LDB_SUCCESS
);
3978 msg02
= ldb_msg_new(tmp_ctx
);
3979 assert_non_null(msg02
);
3981 msg02
->dn
= ldb_dn_new_fmt(msg02
, test_ctx
->ldb
, "dc=test02");
3982 assert_non_null(msg02
->dn
);
3984 ret
= ldb_msg_add_string(msg02
, "cn", "test_unique_index");
3985 assert_int_equal(ret
, LDB_SUCCESS
);
3987 ret
= ldb_msg_add_string(msg02
, "objectUUID", "0123456789abcde0");
3988 assert_int_equal(ret
, LDB_SUCCESS
);
3990 ret
= ldb_add(test_ctx
->ldb
, msg02
);
3991 assert_int_equal(ret
, LDB_ERR_CONSTRAINT_VIOLATION
);
3993 assert_non_null(test_ctx
->debug_string
);
3995 test_ctx
->debug_string
,
3996 "unique index violation on cn in dc=test02, conflicts with "
3997 "objectUUID 0123456789abcdef in @INDEX:CN:test_unique_index");
3999 TALLOC_FREE(test_ctx
->debug_string
);
4000 talloc_free(tmp_ctx
);
4003 static void test_ldb_guid_index_duplicate_dn_logging(void **state
)
4006 struct ldb_message
*msg01
;
4007 struct ldb_message
*msg02
;
4008 struct ldbtest_ctx
*test_ctx
= talloc_get_type_abort(*state
,
4009 struct ldbtest_ctx
);
4010 TALLOC_CTX
*tmp_ctx
;
4012 ldb_set_debug(test_ctx
->ldb
, ldb_debug_string
, test_ctx
);
4013 tmp_ctx
= talloc_new(test_ctx
);
4014 assert_non_null(tmp_ctx
);
4016 msg01
= ldb_msg_new(tmp_ctx
);
4017 assert_non_null(msg01
);
4019 msg01
->dn
= ldb_dn_new_fmt(msg01
, test_ctx
->ldb
, "dc=test01");
4020 assert_non_null(msg01
->dn
);
4022 ret
= ldb_msg_add_string(msg01
, "cn", "test_unique_index01");
4023 assert_int_equal(ret
, LDB_SUCCESS
);
4025 ret
= ldb_msg_add_string(msg01
, "objectUUID", "0123456789abcdef");
4026 assert_int_equal(ret
, LDB_SUCCESS
);
4028 ret
= ldb_add(test_ctx
->ldb
, msg01
);
4029 assert_int_equal(ret
, LDB_SUCCESS
);
4031 msg02
= ldb_msg_new(tmp_ctx
);
4032 assert_non_null(msg02
);
4034 msg02
->dn
= ldb_dn_new_fmt(msg02
, test_ctx
->ldb
, "dc=test01");
4035 assert_non_null(msg02
->dn
);
4037 ret
= ldb_msg_add_string(msg02
, "cn", "test_unique_index02");
4038 assert_int_equal(ret
, LDB_SUCCESS
);
4040 ret
= ldb_msg_add_string(msg02
, "objectUUID", "0123456789abcde1");
4041 assert_int_equal(ret
, LDB_SUCCESS
);
4043 ret
= ldb_add(test_ctx
->ldb
, msg02
);
4044 assert_int_equal(ret
, LDB_ERR_ENTRY_ALREADY_EXISTS
);
4046 assert_null(test_ctx
->debug_string
);
4047 talloc_free(tmp_ctx
);
4050 static void test_ldb_talloc_destructor_transaction_cleanup(void **state
)
4052 struct ldbtest_ctx
*test_ctx
= NULL
;
4054 test_ctx
= talloc_get_type_abort(*state
, struct ldbtest_ctx
);
4055 assert_non_null(test_ctx
);
4057 ldb_transaction_start(test_ctx
->ldb
);
4060 * Trigger the destructor
4062 TALLOC_FREE(test_ctx
->ldb
);
4065 * Now ensure that a new connection can be opened
4068 TALLOC_CTX
*tctx
= talloc_new(test_ctx
);
4069 struct ldbtest_ctx
*ctx
= talloc_zero(tctx
, struct ldbtest_ctx
);
4070 struct ldb_dn
*basedn
;
4071 struct ldb_result
*result
= NULL
;
4074 ldbtest_setup((void *)&ctx
);
4076 basedn
= ldb_dn_new_fmt(tctx
, ctx
->ldb
, "dc=test");
4077 assert_non_null(basedn
);
4079 ret
= ldb_search(ctx
->ldb
,
4086 assert_int_equal(ret
, 0);
4087 assert_non_null(result
);
4088 assert_int_equal(result
->count
, 0);
4090 ldbtest_teardown((void *)&ctx
);
4095 static int test_ldb_multiple_connections_callback(struct ldb_request
*req
,
4096 struct ldb_reply
*ares
)
4104 switch (ares
->type
) {
4105 case LDB_REPLY_ENTRY
:
4108 case LDB_REPLY_REFERRAL
:
4111 case LDB_REPLY_DONE
:
4112 return ldb_request_done(req
, LDB_SUCCESS
);
4117 * We open a new ldb on an ldb that is already open and
4120 * If the multiple connection wrapping is correct the
4121 * underlying MDB_env will be left open and we should see
4122 * an active reader in the child we fork next
4124 struct ldb_context
*ldb
= NULL
;
4125 struct tevent_context
*ev
= NULL
;
4126 TALLOC_CTX
*mem_ctx
= talloc_new(NULL
);
4128 ev
= tevent_context_init(mem_ctx
);
4129 assert_non_null(ev
);
4131 ldb
= ldb_init(mem_ctx
, ev
);
4132 assert_non_null(ldb
);
4134 ret
= ldb_connect(ldb
, TEST_BE
"://apitest.ldb" , 0, NULL
);
4135 if (ret
!= LDB_SUCCESS
) {
4139 TALLOC_FREE(mem_ctx
);
4143 assert_int_equal(ret
, 0);
4146 if (child_pid
== 0) {
4147 struct MDB_env
*env
= NULL
;
4148 struct MDB_envinfo stat
;
4152 * Check that there are exactly two readers on the MDB file
4156 ret
= mdb_env_create(&env
);
4158 print_error(__location__
4159 " mdb_env_create returned (%d)",
4164 ret
= mdb_env_open(env
,
4166 MDB_NOSUBDIR
| MDB_NOTLS
,
4169 print_error(__location__
4170 " mdb_env_open returned (%d)",
4175 ret
= mdb_env_info(env
, &stat
);
4177 print_error(__location__
4178 " mdb_env_info returned (%d)",
4182 if (stat
.me_numreaders
!= 2) {
4183 print_error(__location__
4184 " Incorrect number of readers (%d)",
4185 stat
.me_numreaders
);
4186 exit(LDB_ERR_CONSTRAINT_VIOLATION
);
4189 ret
= write(pipes
[1], "GO", 2);
4191 print_error(__location__
4192 " write returned (%d)",
4194 exit(LDB_ERR_OPERATIONS_ERROR
);
4199 ret
= read(pipes
[0], buf
, 2);
4200 assert_int_equal(ret
, 2);
4202 pid
= waitpid(child_pid
, &wstatus
, 0);
4203 assert_int_equal(pid
, child_pid
);
4205 assert_true(WIFEXITED(wstatus
));
4207 assert_int_equal(WEXITSTATUS(wstatus
), 0);
4212 static void test_ldb_close_with_multiple_connections(void **state
)
4214 struct search_test_ctx
*search_test_ctx
= NULL
;
4215 struct ldb_dn
*search_dn
= NULL
;
4216 struct ldb_request
*req
= NULL
;
4219 search_test_ctx
= talloc_get_type_abort(*state
, struct search_test_ctx
);
4220 assert_non_null(search_test_ctx
);
4222 search_dn
= ldb_dn_new_fmt(search_test_ctx
,
4223 search_test_ctx
->ldb_test_ctx
->ldb
,
4224 "cn=test_search_cn,"
4225 "dc=search_test_entry");
4226 assert_non_null(search_dn
);
4229 * The search just needs to call DONE, we don't care about the
4230 * contents of the search for this test
4232 ret
= ldb_build_search_req(&req
,
4233 search_test_ctx
->ldb_test_ctx
->ldb
,
4237 "(&(!(filterAttr=*))"
4238 "(cn=test_search_cn))",
4242 test_ldb_multiple_connections_callback
,
4244 assert_int_equal(ret
, 0);
4246 ret
= ldb_request(search_test_ctx
->ldb_test_ctx
->ldb
, req
);
4247 assert_int_equal(ret
, 0);
4249 ret
= ldb_wait(req
->handle
, LDB_WAIT_ALL
);
4250 assert_int_equal(ret
, 0);
4255 static void test_transaction_start_across_fork(void **state
)
4257 struct ldb_context
*ldb1
= NULL
;
4259 struct ldbtest_ctx
*test_ctx
= NULL
;
4263 pid_t pid
, child_pid
;
4265 test_ctx
= talloc_get_type_abort(*state
, struct ldbtest_ctx
);
4270 ldb1
= ldb_init(test_ctx
, test_ctx
->ev
);
4271 ret
= ldb_connect(ldb1
, test_ctx
->dbpath
, 0, NULL
);
4272 assert_int_equal(ret
, 0);
4275 assert_int_equal(ret
, 0);
4278 if (child_pid
== 0) {
4280 ret
= ldb_transaction_start(ldb1
);
4281 if (ret
!= LDB_ERR_PROTOCOL_ERROR
) {
4282 print_error(__location__
": ldb_transaction_start "
4283 "returned (%d) %s\n",
4286 exit(LDB_ERR_OTHER
);
4289 ret
= write(pipes
[1], "GO", 2);
4291 print_error(__location__
4292 " write returned (%d)",
4294 exit(LDB_ERR_OPERATIONS_ERROR
);
4299 ret
= read(pipes
[0], buf
, 2);
4300 assert_int_equal(ret
, 2);
4302 pid
= waitpid(child_pid
, &wstatus
, 0);
4303 assert_int_equal(pid
, child_pid
);
4305 assert_true(WIFEXITED(wstatus
));
4307 assert_int_equal(WEXITSTATUS(wstatus
), 0);
4310 static void test_transaction_commit_across_fork(void **state
)
4312 struct ldb_context
*ldb1
= NULL
;
4314 struct ldbtest_ctx
*test_ctx
= NULL
;
4318 pid_t pid
, child_pid
;
4320 test_ctx
= talloc_get_type_abort(*state
, struct ldbtest_ctx
);
4325 ldb1
= ldb_init(test_ctx
, test_ctx
->ev
);
4326 ret
= ldb_connect(ldb1
, test_ctx
->dbpath
, 0, NULL
);
4327 assert_int_equal(ret
, 0);
4329 ret
= ldb_transaction_start(ldb1
);
4330 assert_int_equal(ret
, 0);
4333 assert_int_equal(ret
, 0);
4336 if (child_pid
== 0) {
4338 ret
= ldb_transaction_commit(ldb1
);
4340 if (ret
!= LDB_ERR_PROTOCOL_ERROR
) {
4341 print_error(__location__
": ldb_transaction_commit "
4342 "returned (%d) %s\n",
4345 exit(LDB_ERR_OTHER
);
4348 ret
= write(pipes
[1], "GO", 2);
4350 print_error(__location__
4351 " write returned (%d)",
4353 exit(LDB_ERR_OPERATIONS_ERROR
);
4358 ret
= read(pipes
[0], buf
, 2);
4359 assert_int_equal(ret
, 2);
4361 pid
= waitpid(child_pid
, &wstatus
, 0);
4362 assert_int_equal(pid
, child_pid
);
4364 assert_true(WIFEXITED(wstatus
));
4366 assert_int_equal(WEXITSTATUS(wstatus
), 0);
4369 static void test_lock_read_across_fork(void **state
)
4371 struct ldb_context
*ldb1
= NULL
;
4373 struct ldbtest_ctx
*test_ctx
= NULL
;
4377 pid_t pid
, child_pid
;
4379 test_ctx
= talloc_get_type_abort(*state
, struct ldbtest_ctx
);
4384 ldb1
= ldb_init(test_ctx
, test_ctx
->ev
);
4385 ret
= ldb_connect(ldb1
, test_ctx
->dbpath
, 0, NULL
);
4386 assert_int_equal(ret
, 0);
4389 assert_int_equal(ret
, 0);
4392 if (child_pid
== 0) {
4393 struct ldb_dn
*basedn
;
4394 struct ldb_result
*result
= NULL
;
4398 basedn
= ldb_dn_new_fmt(test_ctx
, test_ctx
->ldb
, "dc=test");
4399 assert_non_null(basedn
);
4401 ret
= ldb_search(test_ctx
->ldb
,
4408 if (ret
!= LDB_ERR_PROTOCOL_ERROR
) {
4409 print_error(__location__
": ldb_search "
4410 "returned (%d) %s\n",
4413 exit(LDB_ERR_OTHER
);
4416 ret
= write(pipes
[1], "GO", 2);
4418 print_error(__location__
4419 " write returned (%d)",
4421 exit(LDB_ERR_OPERATIONS_ERROR
);
4426 ret
= read(pipes
[0], buf
, 2);
4427 assert_int_equal(ret
, 2);
4429 pid
= waitpid(child_pid
, &wstatus
, 0);
4430 assert_int_equal(pid
, child_pid
);
4432 assert_true(WIFEXITED(wstatus
));
4434 assert_int_equal(WEXITSTATUS(wstatus
), 0);
4438 * Ensure that the search actually succeeds on the opening
4441 struct ldb_dn
*basedn
;
4442 struct ldb_result
*result
= NULL
;
4446 basedn
= ldb_dn_new_fmt(test_ctx
, test_ctx
->ldb
, "dc=test");
4447 assert_non_null(basedn
);
4449 ret
= ldb_search(test_ctx
->ldb
,
4456 assert_int_equal(0, ret
);
4460 static void test_multiple_opens_across_fork(void **state
)
4462 struct ldb_context
*ldb1
= NULL
;
4463 struct ldb_context
*ldb2
= NULL
;
4465 struct ldbtest_ctx
*test_ctx
= NULL
;
4469 pid_t pid
, child_pid
;
4471 test_ctx
= talloc_get_type_abort(*state
, struct ldbtest_ctx
);
4474 * Open the database again
4476 ldb1
= ldb_init(test_ctx
, test_ctx
->ev
);
4477 ret
= ldb_connect(ldb1
, test_ctx
->dbpath
, LDB_FLG_RDONLY
, NULL
);
4478 assert_int_equal(ret
, 0);
4480 ldb2
= ldb_init(test_ctx
, test_ctx
->ev
);
4481 ret
= ldb_connect(ldb2
, test_ctx
->dbpath
, 0, NULL
);
4482 assert_int_equal(ret
, 0);
4485 assert_int_equal(ret
, 0);
4488 if (child_pid
== 0) {
4489 struct ldb_context
*ldb3
= NULL
;
4492 ldb3
= ldb_init(test_ctx
, test_ctx
->ev
);
4493 ret
= ldb_connect(ldb3
, test_ctx
->dbpath
, 0, NULL
);
4495 print_error(__location__
": ldb_connect returned (%d)\n",
4499 ret
= write(pipes
[1], "GO", 2);
4501 print_error(__location__
4502 " write returned (%d)",
4504 exit(LDB_ERR_OPERATIONS_ERROR
);
4509 ret
= read(pipes
[0], buf
, 2);
4510 assert_int_equal(ret
, 2);
4512 pid
= waitpid(child_pid
, &wstatus
, 0);
4513 assert_int_equal(pid
, child_pid
);
4515 assert_true(WIFEXITED(wstatus
));
4517 assert_int_equal(WEXITSTATUS(wstatus
), 0);
4520 int main(int argc
, const char **argv
)
4522 const struct CMUnitTest tests
[] = {
4523 cmocka_unit_test_setup_teardown(test_connect
,
4524 ldbtest_noconn_setup
,
4525 ldbtest_noconn_teardown
),
4526 cmocka_unit_test_setup_teardown(test_ldif_message
,
4527 ldbtest_noconn_setup
,
4528 ldbtest_noconn_teardown
),
4529 cmocka_unit_test_setup_teardown(test_ldif_message_redacted
,
4530 ldbtest_noconn_setup
,
4531 ldbtest_noconn_teardown
),
4532 cmocka_unit_test_setup_teardown(test_ldb_add
,
4535 cmocka_unit_test_setup_teardown(test_ldb_search
,
4538 cmocka_unit_test_setup_teardown(test_ldb_del
,
4541 cmocka_unit_test_setup_teardown(test_ldb_del_noexist
,
4544 cmocka_unit_test_setup_teardown(test_ldb_handle
,
4547 cmocka_unit_test_setup_teardown(test_ldb_build_search_req
,
4550 cmocka_unit_test_setup_teardown(test_transactions
,
4553 cmocka_unit_test_setup_teardown(test_nested_transactions
,
4556 cmocka_unit_test_setup_teardown(test_ldb_modify_add_key
,
4557 ldb_modify_test_setup
,
4558 ldb_modify_test_teardown
),
4559 cmocka_unit_test_setup_teardown(test_ldb_modify_extend_key
,
4560 ldb_modify_test_setup
,
4561 ldb_modify_test_teardown
),
4562 cmocka_unit_test_setup_teardown(test_ldb_modify_add_key_noval
,
4563 ldb_modify_test_setup
,
4564 ldb_modify_test_teardown
),
4565 cmocka_unit_test_setup_teardown(test_ldb_modify_replace_key
,
4566 ldb_modify_test_setup
,
4567 ldb_modify_test_teardown
),
4568 cmocka_unit_test_setup_teardown(test_ldb_modify_replace_noexist_key
,
4569 ldb_modify_test_setup
,
4570 ldb_modify_test_teardown
),
4571 cmocka_unit_test_setup_teardown(test_ldb_modify_replace_zero_vals
,
4572 ldb_modify_test_setup
,
4573 ldb_modify_test_teardown
),
4574 cmocka_unit_test_setup_teardown(test_ldb_modify_replace_noexist_key_zero_vals
,
4575 ldb_modify_test_setup
,
4576 ldb_modify_test_teardown
),
4577 cmocka_unit_test_setup_teardown(test_ldb_modify_del_key
,
4578 ldb_modify_test_setup
,
4579 ldb_modify_test_teardown
),
4580 cmocka_unit_test_setup_teardown(test_ldb_modify_del_keyval
,
4581 ldb_modify_test_setup
,
4582 ldb_modify_test_teardown
),
4583 cmocka_unit_test_setup_teardown(test_search_match_none
,
4584 ldb_search_test_setup
,
4585 ldb_search_test_teardown
),
4586 cmocka_unit_test_setup_teardown(test_search_match_one
,
4587 ldb_search_test_setup
,
4588 ldb_search_test_teardown
),
4589 cmocka_unit_test_setup_teardown(test_search_match_filter
,
4590 ldb_search_test_setup
,
4591 ldb_search_test_teardown
),
4592 cmocka_unit_test_setup_teardown(test_search_match_both
,
4593 ldb_search_test_setup
,
4594 ldb_search_test_teardown
),
4595 cmocka_unit_test_setup_teardown(test_search_match_basedn
,
4596 ldb_search_test_setup
,
4597 ldb_search_test_teardown
),
4598 cmocka_unit_test_setup_teardown(test_ldb_search_against_transaction
,
4599 ldb_search_test_setup
,
4600 ldb_search_test_teardown
),
4601 cmocka_unit_test_setup_teardown(test_ldb_modify_during_unindexed_search
,
4602 ldb_search_test_setup
,
4603 ldb_search_test_teardown
),
4604 cmocka_unit_test_setup_teardown(test_ldb_modify_during_indexed_search
,
4605 ldb_search_test_setup
,
4606 ldb_search_test_teardown
),
4607 cmocka_unit_test_setup_teardown(test_ldb_rename_during_unindexed_search
,
4608 ldb_search_test_setup
,
4609 ldb_search_test_teardown
),
4610 cmocka_unit_test_setup_teardown(test_ldb_rename_during_indexed_search
,
4611 ldb_search_test_setup
,
4612 ldb_search_test_teardown
),
4613 cmocka_unit_test_setup_teardown(test_ldb_callback_rename_during_unindexed_search
,
4614 ldb_search_test_setup
,
4615 ldb_search_test_teardown
),
4616 cmocka_unit_test_setup_teardown(test_ldb_callback_rename_during_indexed_search
,
4617 ldb_search_test_setup
,
4618 ldb_search_test_teardown
),
4619 cmocka_unit_test_setup_teardown(test_ldb_callback_delete_during_unindexed_search
,
4620 ldb_search_test_setup
,
4621 ldb_search_test_teardown
),
4622 cmocka_unit_test_setup_teardown(test_ldb_callback_delete_during_indexed_search
,
4623 ldb_search_test_setup
,
4624 ldb_search_test_teardown
),
4625 cmocka_unit_test_setup_teardown(test_ldb_modify_during_whole_search
,
4626 ldb_search_test_setup
,
4627 ldb_search_test_teardown
),
4628 cmocka_unit_test_setup_teardown(test_ldb_modify_before_ldb_wait
,
4629 ldb_search_test_setup
,
4630 ldb_search_test_teardown
),
4631 cmocka_unit_test_setup_teardown(test_ldb_attrs_case_insensitive
,
4632 ldb_case_test_setup
,
4633 ldb_case_test_teardown
),
4634 cmocka_unit_test_setup_teardown(test_ldb_attrs_case_handler
,
4635 ldb_case_test_setup
,
4636 ldb_case_test_teardown
),
4637 cmocka_unit_test_setup_teardown(test_ldb_attrs_index_handler
,
4638 ldb_case_test_setup
,
4639 ldb_case_attrs_index_test_teardown
),
4640 cmocka_unit_test_setup_teardown(test_ldb_rename
,
4641 ldb_rename_test_setup
,
4642 ldb_rename_test_teardown
),
4643 cmocka_unit_test_setup_teardown(test_ldb_rename_from_doesnt_exist
,
4644 ldb_rename_test_setup
,
4645 ldb_rename_test_teardown
),
4646 cmocka_unit_test_setup_teardown(test_ldb_rename_to_exists
,
4647 ldb_rename_test_setup
,
4648 ldb_rename_test_teardown
),
4649 cmocka_unit_test_setup_teardown(test_ldb_rename_self
,
4650 ldb_rename_test_setup
,
4651 ldb_rename_test_teardown
),
4652 cmocka_unit_test_setup_teardown(test_ldb_rename_dn_case_change
,
4653 ldb_rename_test_setup
,
4654 ldb_rename_test_teardown
),
4655 cmocka_unit_test_setup_teardown(test_read_only
,
4656 ldb_read_only_setup
,
4657 ldb_read_only_teardown
),
4658 cmocka_unit_test_setup_teardown(
4659 test_ldb_add_unique_value_to_unique_index
,
4660 ldb_unique_index_test_setup
,
4661 ldb_unique_index_test_teardown
),
4662 cmocka_unit_test_setup_teardown(
4663 test_ldb_add_duplicate_value_to_unique_index
,
4664 ldb_unique_index_test_setup
,
4665 ldb_unique_index_test_teardown
),
4666 cmocka_unit_test_setup_teardown(
4667 test_ldb_add_to_index_duplicates_allowed
,
4668 ldb_non_unique_index_test_setup
,
4669 ldb_non_unique_index_test_teardown
),
4670 cmocka_unit_test_setup_teardown(
4671 test_ldb_add_to_index_unique_values_required
,
4672 ldb_non_unique_index_test_setup
,
4673 ldb_non_unique_index_test_teardown
),
4674 /* These tests are not compatible with mdb */
4675 cmocka_unit_test_setup_teardown(
4676 test_ldb_unique_index_duplicate_logging
,
4677 ldb_unique_index_test_setup
,
4678 ldb_unique_index_test_teardown
),
4679 cmocka_unit_test_setup_teardown(
4680 test_ldb_duplicate_dn_logging
,
4681 ldb_unique_index_test_setup
,
4682 ldb_unique_index_test_teardown
),
4683 cmocka_unit_test_setup_teardown(
4684 test_ldb_guid_index_duplicate_dn_logging
,
4685 ldb_guid_index_test_setup
,
4686 ldb_guid_index_test_teardown
),
4687 cmocka_unit_test_setup_teardown(
4688 test_ldb_unique_index_duplicate_with_guid
,
4689 ldb_guid_index_test_setup
,
4690 ldb_guid_index_test_teardown
),
4691 cmocka_unit_test_setup_teardown(
4692 test_ldb_talloc_destructor_transaction_cleanup
,
4696 cmocka_unit_test_setup_teardown(
4697 test_ldb_close_with_multiple_connections
,
4698 ldb_search_test_setup
,
4699 ldb_search_test_teardown
),
4701 cmocka_unit_test_setup_teardown(
4702 test_transaction_start_across_fork
,
4705 cmocka_unit_test_setup_teardown(
4706 test_transaction_commit_across_fork
,
4709 cmocka_unit_test_setup_teardown(
4710 test_lock_read_across_fork
,
4713 cmocka_unit_test_setup_teardown(
4714 test_multiple_opens_across_fork
,
4720 cmocka_set_test_filter(argv
[1]);
4723 cmocka_set_message_output(CM_OUTPUT_SUBUNIT
);
4725 return cmocka_run_group_tests(tests
, NULL
, NULL
);