2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Bartlett 2012
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "torture/smbtorture.h"
22 #include "dlz_minimal.h"
25 #include "lib/param/param.h"
26 #include "dsdb/samdb/samdb.h"
27 #include "dsdb/common/util.h"
28 #include "auth/session.h"
29 #include "auth/gensec/gensec.h"
30 #include "auth/credentials/credentials.h"
31 #include "lib/cmdline/popt_common.h"
33 struct torture_context *tctx_static;
35 static void dlz_bind9_log_wrapper(int level, const char *fmt, ...)
36 PRINTF_ATTRIBUTE(2,3);
38 static void dlz_bind9_log_wrapper(int level, const char *fmt, ...)
43 msg = talloc_vasprintf(NULL, fmt, ap);
44 torture_comment(tctx_static, "%s\n", msg);
49 static bool test_dlz_bind9_version(struct torture_context *tctx)
51 unsigned int flags = 0;
52 torture_assert_int_equal(tctx, dlz_version(&flags),
53 DLZ_DLOPEN_VERSION, "got wrong DLZ version");
57 static bool test_dlz_bind9_create(struct torture_context *tctx)
60 const char *argv[] = {
63 lpcfg_private_path(tctx, tctx->lp_ctx, "dns/sam.ldb"),
67 torture_assert_int_equal(tctx, dlz_create("samba_dlz", 3, argv, &dbdata,
68 "log", dlz_bind9_log_wrapper, NULL), ISC_R_SUCCESS,
69 "Failed to create samba_dlz");
76 static isc_result_t dlz_bind9_writeable_zone_hook(dns_view_t *view,
77 const char *zone_name)
79 struct torture_context *tctx = talloc_get_type((void *)view, struct torture_context);
80 struct ldb_context *samdb = samdb_connect_url(tctx, NULL, tctx->lp_ctx,
81 system_session(tctx->lp_ctx),
82 0, lpcfg_private_path(tctx, tctx->lp_ctx, "dns/sam.ldb"));
83 struct ldb_message *msg;
85 const char *attrs[] = {
89 torture_fail(tctx, "Failed to connect to samdb");
93 ret = dsdb_search_one(samdb, tctx, &msg, NULL,
94 LDB_SCOPE_SUBTREE, attrs, DSDB_SEARCH_SEARCH_ALL_PARTITIONS,
95 "(&(objectClass=dnsZone)(name=%s))", zone_name);
96 if (ret != LDB_SUCCESS) {
97 torture_fail(tctx, talloc_asprintf(tctx, "Failed to search for %s: %s", zone_name, ldb_errstring(samdb)));
102 return ISC_R_SUCCESS;
105 static bool test_dlz_bind9_configure(struct torture_context *tctx)
108 const char *argv[] = {
111 lpcfg_private_path(tctx, tctx->lp_ctx, "dns/sam.ldb"),
115 torture_assert_int_equal(tctx, dlz_create("samba_dlz", 3, argv, &dbdata,
116 "log", dlz_bind9_log_wrapper,
117 "writeable_zone", dlz_bind9_writeable_zone_hook, NULL),
119 "Failed to create samba_dlz");
121 torture_assert_int_equal(tctx, dlz_configure((void*)tctx, dbdata),
123 "Failed to configure samba_dlz");
131 * Test that a ticket obtained for the DNS service will be accepted on the Samba DLZ side
134 static bool test_dlz_bind9_gensec(struct torture_context *tctx, const char *mech)
138 struct gensec_security *gensec_client_context;
140 DATA_BLOB client_to_server, server_to_client;
143 const char *argv[] = {
146 lpcfg_private_path(tctx, tctx->lp_ctx, "dns/sam.ldb"),
150 torture_assert_int_equal(tctx, dlz_create("samba_dlz", 3, argv, &dbdata,
151 "log", dlz_bind9_log_wrapper,
152 "writeable_zone", dlz_bind9_writeable_zone_hook, NULL),
154 "Failed to create samba_dlz");
156 torture_assert_int_equal(tctx, dlz_configure((void*)tctx, dbdata),
158 "Failed to configure samba_dlz");
160 status = gensec_client_start(tctx, &gensec_client_context,
161 lpcfg_gensec_settings(tctx, tctx->lp_ctx));
162 torture_assert_ntstatus_ok(tctx, status, "gensec_client_start (client) failed");
165 * dlz_bind9 use the special dns/host.domain account
167 status = gensec_set_target_hostname(gensec_client_context,
168 talloc_asprintf(tctx,
170 torture_setting_string(tctx, "host", NULL),
171 lpcfg_dnsdomain(tctx->lp_ctx)));
172 torture_assert_ntstatus_ok(tctx, status, "gensec_set_target_hostname (client) failed");
174 status = gensec_set_target_service(gensec_client_context, "dns");
175 torture_assert_ntstatus_ok(tctx, status, "gensec_set_target_service failed");
177 status = gensec_set_credentials(gensec_client_context,
178 popt_get_cmdline_credentials());
179 torture_assert_ntstatus_ok(tctx, status, "gensec_set_credentials (client) failed");
181 status = gensec_start_mech_by_sasl_name(gensec_client_context, mech);
182 torture_assert_ntstatus_ok(tctx, status, "gensec_start_mech_by_sasl_name (client) failed");
184 server_to_client = data_blob(NULL, 0);
186 /* Do one step of the client-server update dance */
187 status = gensec_update(gensec_client_context, tctx, server_to_client, &client_to_server);
188 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {;
189 torture_assert_ntstatus_ok(tctx, status, "gensec_update (client) failed");
192 torture_assert_int_equal(tctx, dlz_ssumatch(
193 cli_credentials_get_username(
194 popt_get_cmdline_credentials()),
195 lpcfg_dnsdomain(tctx->lp_ctx),
196 "127.0.0.1", "type", "key",
197 client_to_server.length,
198 client_to_server.data,
201 "Failed to check key for update rights samba_dlz");
208 static bool test_dlz_bind9_gssapi(struct torture_context *tctx)
210 return test_dlz_bind9_gensec(tctx, "GSSAPI");
213 static bool test_dlz_bind9_spnego(struct torture_context *tctx)
215 return test_dlz_bind9_gensec(tctx, "GSS-SPNEGO");
218 struct test_expected_record {
226 struct test_expected_rr {
227 struct torture_context *tctx;
228 const char *query_name;
230 struct test_expected_record *records;
234 static bool dlz_bind9_putnamedrr_torture_hook(struct test_expected_rr *expected,
242 torture_assert(expected->tctx, name != NULL,
243 talloc_asprintf(expected->tctx,
244 "Got unnamed record type[%s] data[%s]\n",
248 torture_comment(expected->tctx, "%u: name[%s] type[%s] ttl[%u] data[%s]\n",
249 (unsigned)expected->num_rr, name, type, (unsigned)ttl, data);
251 for (i = 0; i < expected->num_records; i++) {
252 if (expected->records[i].name != NULL) {
253 if (strcmp(name, expected->records[i].name) != 0) {
258 if (strcmp(type, expected->records[i].type) != 0) {
262 if (expected->records[i].data != NULL) {
263 if (strcmp(data, expected->records[i].data) != 0) {
268 torture_assert_int_equal(expected->tctx, ttl,
269 expected->records[i].ttl,
270 talloc_asprintf(expected->tctx,
271 "TTL did not match expectations for type %s",
274 expected->records[i].printed = true;
280 static isc_result_t dlz_bind9_putrr_hook(dns_sdlzlookup_t *lookup,
285 struct test_expected_rr *expected =
286 talloc_get_type_abort(lookup, struct test_expected_rr);
289 ok = dlz_bind9_putnamedrr_torture_hook(expected, expected->query_name,
292 return ISC_R_FAILURE;
295 return ISC_R_SUCCESS;
298 static isc_result_t dlz_bind9_putnamedrr_hook(dns_sdlzallnodes_t *allnodes,
304 struct test_expected_rr *expected =
305 talloc_get_type_abort(allnodes, struct test_expected_rr);
308 ok = dlz_bind9_putnamedrr_torture_hook(expected, name, type, ttl, data);
310 return ISC_R_FAILURE;
313 return ISC_R_SUCCESS;
319 static bool test_dlz_bind9_lookup(struct torture_context *tctx)
323 const char *argv[] = {
326 lpcfg_private_path(tctx, tctx->lp_ctx, "dns/sam.ldb"),
329 struct test_expected_rr *expected1 = NULL;
330 struct test_expected_rr *expected2 = NULL;
333 torture_assert_int_equal(tctx, dlz_create("samba_dlz", 3, argv, &dbdata,
334 "log", dlz_bind9_log_wrapper,
335 "writeable_zone", dlz_bind9_writeable_zone_hook,
336 "putrr", dlz_bind9_putrr_hook,
337 "putnamedrr", dlz_bind9_putnamedrr_hook,
340 "Failed to create samba_dlz");
342 torture_assert_int_equal(tctx, dlz_configure((void*)tctx, dbdata),
344 "Failed to configure samba_dlz");
346 expected1 = talloc_zero(tctx, struct test_expected_rr);
347 torture_assert(tctx, expected1 != NULL, "talloc failed");
348 expected1->tctx = tctx;
350 expected1->query_name = "@";
352 expected1->num_records = 4;
353 expected1->records = talloc_zero_array(expected1,
354 struct test_expected_record,
355 expected1->num_records);
356 torture_assert(tctx, expected1->records != NULL, "talloc failed");
358 expected1->records[0].name = expected1->query_name;
359 expected1->records[0].type = "soa";
360 expected1->records[0].ttl = 3600;
361 expected1->records[0].data = talloc_asprintf(expected1->records,
362 "%s.%s. hostmaster.%s. 1 900 600 86400 3600",
363 torture_setting_string(tctx, "host", NULL),
364 lpcfg_dnsdomain(tctx->lp_ctx),
365 lpcfg_dnsdomain(tctx->lp_ctx));
366 torture_assert(tctx, expected1->records[0].data != NULL, "talloc failed");
368 expected1->records[1].name = expected1->query_name;
369 expected1->records[1].type = "ns";
370 expected1->records[1].ttl = 900;
371 expected1->records[1].data = talloc_asprintf(expected1->records, "%s.%s.",
372 torture_setting_string(tctx, "host", NULL),
373 lpcfg_dnsdomain(tctx->lp_ctx));
374 torture_assert(tctx, expected1->records[1].data != NULL, "talloc failed");
376 expected1->records[2].name = expected1->query_name;
377 expected1->records[2].type = "aaaa";
378 expected1->records[2].ttl = 900;
380 expected1->records[3].name = expected1->query_name;
381 expected1->records[3].type = "a";
382 expected1->records[3].ttl = 900;
384 torture_assert_int_equal(tctx, dlz_lookup(lpcfg_dnsdomain(tctx->lp_ctx),
385 expected1->query_name, dbdata,
386 (dns_sdlzlookup_t *)expected1),
388 "Failed to lookup @");
389 for (i = 0; i < expected1->num_records; i++) {
390 torture_assert(tctx, expected1->records[i].printed,
391 talloc_asprintf(tctx,
392 "Failed to have putrr callback run for type %s",
393 expected1->records[i].type));
395 torture_assert_int_equal(tctx, expected1->num_rr,
396 expected1->num_records,
397 "Got too much data");
399 expected2 = talloc_zero(tctx, struct test_expected_rr);
400 torture_assert(tctx, expected2 != NULL, "talloc failed");
401 expected2->tctx = tctx;
403 expected2->query_name = torture_setting_string(tctx, "host", NULL);
404 torture_assert(tctx, expected2->query_name != NULL, "unknown host");
406 expected2->num_records = 2;
407 expected2->records = talloc_zero_array(expected2,
408 struct test_expected_record,
409 expected2->num_records);
410 torture_assert(tctx, expected2->records != NULL, "talloc failed");
412 expected2->records[0].name = expected2->query_name;
413 expected2->records[0].type = "aaaa";
414 expected2->records[0].ttl = 900;
416 expected2->records[1].name = expected2->query_name;
417 expected2->records[1].type = "a";
418 expected2->records[1].ttl = 900;
420 torture_assert_int_equal(tctx, dlz_lookup(lpcfg_dnsdomain(tctx->lp_ctx),
421 expected2->query_name, dbdata,
422 (dns_sdlzlookup_t *)expected2),
424 "Failed to lookup hostname");
425 for (i = 0; i < expected2->num_records; i++) {
426 torture_assert(tctx, expected2->records[i].printed,
427 talloc_asprintf(tctx,
428 "Failed to have putrr callback run name[%s] for type %s",
429 expected2->records[i].name,
430 expected2->records[i].type));
432 torture_assert_int_equal(tctx, expected2->num_rr,
433 expected2->num_records,
434 "Got too much data");
442 * Test some zone dumps
444 static bool test_dlz_bind9_zonedump(struct torture_context *tctx)
448 const char *argv[] = {
451 lpcfg_private_path(tctx, tctx->lp_ctx, "dns/sam.ldb"),
454 struct test_expected_rr *expected1 = NULL;
457 torture_assert_int_equal(tctx, dlz_create("samba_dlz", 3, argv, &dbdata,
458 "log", dlz_bind9_log_wrapper,
459 "writeable_zone", dlz_bind9_writeable_zone_hook,
460 "putrr", dlz_bind9_putrr_hook,
461 "putnamedrr", dlz_bind9_putnamedrr_hook,
464 "Failed to create samba_dlz");
466 torture_assert_int_equal(tctx, dlz_configure((void*)tctx, dbdata),
468 "Failed to configure samba_dlz");
470 expected1 = talloc_zero(tctx, struct test_expected_rr);
471 torture_assert(tctx, expected1 != NULL, "talloc failed");
472 expected1->tctx = tctx;
474 expected1->num_records = 7;
475 expected1->records = talloc_zero_array(expected1,
476 struct test_expected_record,
477 expected1->num_records);
478 torture_assert(tctx, expected1->records != NULL, "talloc failed");
480 expected1->records[0].name = talloc_asprintf(expected1->records,
481 "%s.", lpcfg_dnsdomain(tctx->lp_ctx));
482 expected1->records[0].type = "soa";
483 expected1->records[0].ttl = 3600;
484 expected1->records[0].data = talloc_asprintf(expected1->records,
485 "%s.%s. hostmaster.%s. 1 900 600 86400 3600",
486 torture_setting_string(tctx, "host", NULL),
487 lpcfg_dnsdomain(tctx->lp_ctx),
488 lpcfg_dnsdomain(tctx->lp_ctx));
489 torture_assert(tctx, expected1->records[0].data != NULL, "talloc failed");
491 expected1->records[1].name = talloc_asprintf(expected1->records,
492 "%s.", lpcfg_dnsdomain(tctx->lp_ctx));
493 expected1->records[1].type = "ns";
494 expected1->records[1].ttl = 900;
495 expected1->records[1].data = talloc_asprintf(expected1->records, "%s.%s.",
496 torture_setting_string(tctx, "host", NULL),
497 lpcfg_dnsdomain(tctx->lp_ctx));
498 torture_assert(tctx, expected1->records[1].data != NULL, "talloc failed");
500 expected1->records[2].name = talloc_asprintf(expected1->records,
501 "%s.", lpcfg_dnsdomain(tctx->lp_ctx));
502 expected1->records[2].type = "aaaa";
503 expected1->records[2].ttl = 900;
505 expected1->records[3].name = talloc_asprintf(expected1->records,
506 "%s.", lpcfg_dnsdomain(tctx->lp_ctx));
507 expected1->records[3].type = "a";
508 expected1->records[3].ttl = 900;
510 expected1->records[4].name = talloc_asprintf(expected1->records, "%s.%s.",
511 torture_setting_string(tctx, "host", NULL),
512 lpcfg_dnsdomain(tctx->lp_ctx));
513 torture_assert(tctx, expected1->records[4].name != NULL, "unknown host");
514 expected1->records[4].type = "aaaa";
515 expected1->records[4].ttl = 900;
517 expected1->records[5].name = talloc_asprintf(expected1->records, "%s.%s.",
518 torture_setting_string(tctx, "host", NULL),
519 lpcfg_dnsdomain(tctx->lp_ctx));
520 torture_assert(tctx, expected1->records[5].name != NULL, "unknown host");
521 expected1->records[5].type = "a";
522 expected1->records[5].ttl = 900;
525 * We expect multiple srv records
527 expected1->records[6].name = NULL;
528 expected1->records[6].type = "srv";
529 expected1->records[6].ttl = 900;
531 torture_assert_int_equal(tctx, dlz_allnodes(lpcfg_dnsdomain(tctx->lp_ctx),
532 dbdata, (dns_sdlzallnodes_t *)expected1),
534 "Failed to configure samba_dlz");
535 for (i = 0; i < expected1->num_records; i++) {
536 torture_assert(tctx, expected1->records[i].printed,
537 talloc_asprintf(tctx,
538 "Failed to have putrr callback run name[%s] for type %s",
539 expected1->records[i].name,
540 expected1->records[i].type));
542 torture_assert_int_equal(tctx, expected1->num_rr, 24,
543 "Got wrong record count");
553 static bool test_dlz_bind9_update01(struct torture_context *tctx)
556 struct gensec_security *gensec_client_context;
557 DATA_BLOB client_to_server, server_to_client;
559 void *version = NULL;
560 const char *argv[] = {
563 lpcfg_private_path(tctx, tctx->lp_ctx, "dns/sam.ldb"),
566 struct test_expected_rr *expected1 = NULL;
574 torture_assert_int_equal(tctx, dlz_create("samba_dlz", 3, argv, &dbdata,
575 "log", dlz_bind9_log_wrapper,
576 "writeable_zone", dlz_bind9_writeable_zone_hook,
577 "putrr", dlz_bind9_putrr_hook,
578 "putnamedrr", dlz_bind9_putnamedrr_hook,
581 "Failed to create samba_dlz");
583 torture_assert_int_equal(tctx, dlz_configure((void*)tctx, dbdata),
585 "Failed to configure samba_dlz");
587 expected1 = talloc_zero(tctx, struct test_expected_rr);
588 torture_assert(tctx, expected1 != NULL, "talloc failed");
589 expected1->tctx = tctx;
591 expected1->query_name = __func__;
593 name = talloc_asprintf(expected1, "%s.%s",
594 expected1->query_name,
595 lpcfg_dnsdomain(tctx->lp_ctx));
596 torture_assert(tctx, name != NULL, "talloc failed");
598 expected1->num_records = 2;
599 expected1->records = talloc_zero_array(expected1,
600 struct test_expected_record,
601 expected1->num_records);
602 torture_assert(tctx, expected1->records != NULL, "talloc failed");
604 expected1->records[0].name = expected1->query_name;
605 expected1->records[0].type = "a";
606 expected1->records[0].ttl = 3600;
607 expected1->records[0].data = "127.1.2.3";
608 expected1->records[0].printed = false;
610 data0 = talloc_asprintf(expected1,
611 "%s.\t" "%u\t" "%s\t" "%s\t" "%s",
613 (unsigned)expected1->records[0].ttl,
615 expected1->records[0].type,
616 expected1->records[0].data);
617 torture_assert(tctx, data0 != NULL, "talloc failed");
619 expected1->records[1].name = expected1->query_name;
620 expected1->records[1].type = "a";
621 expected1->records[1].ttl = 3600;
622 expected1->records[1].data = "127.3.2.1";
623 expected1->records[1].printed = false;
625 data1 = talloc_asprintf(expected1,
626 "%s.\t" "%u\t" "%s\t" "%s\t" "%s",
628 (unsigned)expected1->records[1].ttl,
630 expected1->records[1].type,
631 expected1->records[1].data);
632 torture_assert(tctx, data1 != NULL, "talloc failed");
634 data2 = talloc_asprintf(expected1,
635 "%s.\t" "0\t" "in\t" "a\t" "127.3.3.3",
637 torture_assert(tctx, data2 != NULL, "talloc failed");
640 * Prepare session info
642 status = gensec_client_start(tctx, &gensec_client_context,
643 lpcfg_gensec_settings(tctx, tctx->lp_ctx));
644 torture_assert_ntstatus_ok(tctx, status, "gensec_client_start (client) failed");
647 * dlz_bind9 use the special dns/host.domain account
649 status = gensec_set_target_hostname(gensec_client_context,
650 talloc_asprintf(tctx,
652 torture_setting_string(tctx, "host", NULL),
653 lpcfg_dnsdomain(tctx->lp_ctx)));
654 torture_assert_ntstatus_ok(tctx, status, "gensec_set_target_hostname (client) failed");
656 status = gensec_set_target_service(gensec_client_context, "dns");
657 torture_assert_ntstatus_ok(tctx, status, "gensec_set_target_service failed");
659 status = gensec_set_credentials(gensec_client_context,
660 popt_get_cmdline_credentials());
661 torture_assert_ntstatus_ok(tctx, status, "gensec_set_credentials (client) failed");
663 status = gensec_start_mech_by_sasl_name(gensec_client_context, "GSS-SPNEGO");
664 torture_assert_ntstatus_ok(tctx, status, "gensec_start_mech_by_sasl_name (client) failed");
666 server_to_client = data_blob(NULL, 0);
668 /* Do one step of the client-server update dance */
669 status = gensec_update(gensec_client_context, tctx, server_to_client, &client_to_server);
670 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {;
671 torture_assert_ntstatus_ok(tctx, status, "gensec_update (client) failed");
674 torture_assert_int_equal(tctx, dlz_ssumatch(
675 cli_credentials_get_username(
676 popt_get_cmdline_credentials()),
679 expected1->records[0].type,
681 client_to_server.length,
682 client_to_server.data,
685 "Failed to check key for update rights samba_dlz");
688 * We test the following:
690 * 1. lookup the records => NOT_FOUND
691 * 2. delete all records => NOT_FOUND
692 * 3. delete 1st record => NOT_FOUND
693 * 4. create 1st record => SUCCESS
694 * 5. lookup the records => found 1st
695 * 6. create 2nd record => SUCCESS
696 * 7. lookup the records => found 1st and 2nd
697 * 8. delete unknown record => NOT_FOUND
698 * 9. lookup the records => found 1st and 2nd
699 * 10. delete 1st record => SUCCESS
700 * 11. lookup the records => found 2nd
701 * 12. delete 2nd record => SUCCESS
702 * 13. lookup the records => NOT_FOUND
703 * 14. create 1st record => SUCCESS
704 * 15. lookup the records => found 1st
705 * 16. create 2nd record => SUCCESS
706 * 17. lookup the records => found 1st and 2nd
707 * 18. update 1st record => SUCCESS
708 * 19. lookup the records => found 1st and 2nd
709 * 20. delete all unknown type records => NOT_FOUND
710 * 21. lookup the records => found 1st and 2nd
711 * 22. delete all records => SUCCESS
712 * 23. lookup the records => NOT_FOUND
716 expected1->num_rr = 0;
717 expected1->records[0].printed = false;
718 expected1->records[1].printed = false;
719 torture_assert_int_equal(tctx, dlz_lookup(lpcfg_dnsdomain(tctx->lp_ctx),
720 expected1->query_name, dbdata,
721 (dns_sdlzlookup_t *)expected1),
724 torture_assert_int_equal(tctx, expected1->num_rr, 0,
725 "Got wrong record count");
728 torture_assert_int_equal(tctx, dlz_newversion(lpcfg_dnsdomain(tctx->lp_ctx),
731 "Failed to start transaction");
732 torture_assert_int_equal_goto(tctx,
733 dlz_delrdataset(name,
734 expected1->records[0].type,
736 ISC_R_NOTFOUND, ret, cancel_version,
737 talloc_asprintf(tctx, "Deleted name[%s] type[%s]\n",
738 name, expected1->records[0].type));
739 dlz_closeversion(lpcfg_dnsdomain(tctx->lp_ctx), false, dbdata, &version);
742 torture_assert_int_equal(tctx, dlz_newversion(lpcfg_dnsdomain(tctx->lp_ctx),
745 "Failed to start transaction");
746 torture_assert_int_equal_goto(tctx,
747 dlz_subrdataset(name, data0, dbdata, version),
748 ISC_R_NOTFOUND, ret, cancel_version,
749 talloc_asprintf(tctx, "Deleted name[%s] data[%s]\n",
751 dlz_closeversion(lpcfg_dnsdomain(tctx->lp_ctx), false, dbdata, &version);
754 torture_assert_int_equal(tctx, dlz_newversion(lpcfg_dnsdomain(tctx->lp_ctx),
757 "Failed to start transaction");
758 torture_assert_int_equal_goto(tctx,
759 dlz_addrdataset(name, data0, dbdata, version),
760 ISC_R_SUCCESS, ret, cancel_version,
761 talloc_asprintf(tctx, "Failed to add name[%s] data[%s]\n",
763 dlz_closeversion(lpcfg_dnsdomain(tctx->lp_ctx), true, dbdata, &version);
766 expected1->num_rr = 0;
767 expected1->records[0].printed = false;
768 expected1->records[1].printed = false;
769 torture_assert_int_equal(tctx, dlz_lookup(lpcfg_dnsdomain(tctx->lp_ctx),
770 expected1->query_name, dbdata,
771 (dns_sdlzlookup_t *)expected1),
773 "Not found hostname");
774 torture_assert(tctx, expected1->records[0].printed,
775 talloc_asprintf(tctx,
776 "Failed to have putrr callback run name[%s] for type %s",
777 expected1->records[0].name,
778 expected1->records[0].type));
779 torture_assert_int_equal(tctx, expected1->num_rr, 1,
780 "Got wrong record count");
783 torture_assert_int_equal(tctx, dlz_newversion(lpcfg_dnsdomain(tctx->lp_ctx),
786 "Failed to start transaction");
787 torture_assert_int_equal_goto(tctx,
788 dlz_addrdataset(name, data1, dbdata, version),
789 ISC_R_SUCCESS, ret, cancel_version,
790 talloc_asprintf(tctx, "Failed to add name[%s] data[%s]\n",
792 dlz_closeversion(lpcfg_dnsdomain(tctx->lp_ctx), true, dbdata, &version);
795 expected1->num_rr = 0;
796 expected1->records[0].printed = false;
797 expected1->records[1].printed = false;
798 torture_assert_int_equal(tctx, dlz_lookup(lpcfg_dnsdomain(tctx->lp_ctx),
799 expected1->query_name, dbdata,
800 (dns_sdlzlookup_t *)expected1),
802 "Not found hostname");
803 torture_assert(tctx, expected1->records[0].printed,
804 talloc_asprintf(tctx,
805 "Failed to have putrr callback run name[%s] for type %s",
806 expected1->records[0].name,
807 expected1->records[0].type));
808 torture_assert(tctx, expected1->records[1].printed,
809 talloc_asprintf(tctx,
810 "Failed to have putrr callback run name[%s] for type %s",
811 expected1->records[1].name,
812 expected1->records[1].type));
813 torture_assert_int_equal(tctx, expected1->num_rr, 2,
814 "Got wrong record count");
817 torture_assert_int_equal(tctx, dlz_newversion(lpcfg_dnsdomain(tctx->lp_ctx),
820 "Failed to start transaction");
821 torture_assert_int_equal_goto(tctx,
822 dlz_subrdataset(name, data2, dbdata, version),
823 ISC_R_NOTFOUND, ret, cancel_version,
824 talloc_asprintf(tctx, "Deleted name[%s] data[%s]\n",
826 dlz_closeversion(lpcfg_dnsdomain(tctx->lp_ctx), true, dbdata, &version);
829 expected1->num_rr = 0;
830 expected1->records[0].printed = false;
831 expected1->records[1].printed = false;
832 torture_assert_int_equal(tctx, dlz_lookup(lpcfg_dnsdomain(tctx->lp_ctx),
833 expected1->query_name, dbdata,
834 (dns_sdlzlookup_t *)expected1),
836 "Not found hostname");
837 torture_assert(tctx, expected1->records[0].printed,
838 talloc_asprintf(tctx,
839 "Failed to have putrr callback run name[%s] for type %s",
840 expected1->records[0].name,
841 expected1->records[0].type));
842 torture_assert(tctx, expected1->records[1].printed,
843 talloc_asprintf(tctx,
844 "Failed to have putrr callback run name[%s] for type %s",
845 expected1->records[1].name,
846 expected1->records[1].type));
847 torture_assert_int_equal(tctx, expected1->num_rr, 2,
848 "Got wrong record count");
851 torture_assert_int_equal(tctx, dlz_newversion(lpcfg_dnsdomain(tctx->lp_ctx),
854 "Failed to start transaction");
855 torture_assert_int_equal_goto(tctx,
856 dlz_subrdataset(name, data0, dbdata, version),
857 ISC_R_SUCCESS, ret, cancel_version,
858 talloc_asprintf(tctx, "Failed to delete name[%s] data[%s]\n",
860 dlz_closeversion(lpcfg_dnsdomain(tctx->lp_ctx), true, dbdata, &version);
863 expected1->num_rr = 0;
864 expected1->records[0].printed = false;
865 expected1->records[1].printed = false;
866 torture_assert_int_equal(tctx, dlz_lookup(lpcfg_dnsdomain(tctx->lp_ctx),
867 expected1->query_name, dbdata,
868 (dns_sdlzlookup_t *)expected1),
870 "Not found hostname");
871 torture_assert(tctx, expected1->records[1].printed,
872 talloc_asprintf(tctx,
873 "Failed to have putrr callback run name[%s] for type %s",
874 expected1->records[1].name,
875 expected1->records[1].type));
876 torture_assert_int_equal(tctx, expected1->num_rr, 1,
877 "Got wrong record count");
880 torture_assert_int_equal(tctx, dlz_newversion(lpcfg_dnsdomain(tctx->lp_ctx),
883 "Failed to start transaction");
884 torture_assert_int_equal_goto(tctx,
885 dlz_subrdataset(name, data1, dbdata, version),
886 ISC_R_SUCCESS, ret, cancel_version,
887 talloc_asprintf(tctx, "Failed to delete name[%s] data[%s]\n",
889 dlz_closeversion(lpcfg_dnsdomain(tctx->lp_ctx), true, dbdata, &version);
892 expected1->num_rr = 0;
893 expected1->records[0].printed = false;
894 expected1->records[1].printed = false;
895 torture_assert_int_equal(tctx, dlz_lookup(lpcfg_dnsdomain(tctx->lp_ctx),
896 expected1->query_name, dbdata,
897 (dns_sdlzlookup_t *)expected1),
900 torture_assert_int_equal(tctx, expected1->num_rr, 0,
901 "Got wrong record count");
904 torture_assert_int_equal(tctx, dlz_newversion(lpcfg_dnsdomain(tctx->lp_ctx),
907 "Failed to start transaction");
908 torture_assert_int_equal_goto(tctx,
909 dlz_addrdataset(name, data0, dbdata, version),
910 ISC_R_SUCCESS, ret, cancel_version,
911 talloc_asprintf(tctx, "Failed to add name[%s] data[%s]\n",
913 dlz_closeversion(lpcfg_dnsdomain(tctx->lp_ctx), true, dbdata, &version);
916 expected1->num_rr = 0;
917 expected1->records[0].printed = false;
918 expected1->records[1].printed = false;
919 torture_assert_int_equal(tctx, dlz_lookup(lpcfg_dnsdomain(tctx->lp_ctx),
920 expected1->query_name, dbdata,
921 (dns_sdlzlookup_t *)expected1),
923 "Not found hostname");
924 torture_assert(tctx, expected1->records[0].printed,
925 talloc_asprintf(tctx,
926 "Failed to have putrr callback run name[%s] for type %s",
927 expected1->records[0].name,
928 expected1->records[0].type));
929 torture_assert_int_equal(tctx, expected1->num_rr, 1,
930 "Got wrong record count");
933 torture_assert_int_equal(tctx, dlz_newversion(lpcfg_dnsdomain(tctx->lp_ctx),
936 "Failed to start transaction");
937 torture_assert_int_equal_goto(tctx,
938 dlz_addrdataset(name, data1, dbdata, version),
939 ISC_R_SUCCESS, ret, cancel_version,
940 talloc_asprintf(tctx, "Failed to add name[%s] data[%s]\n",
942 dlz_closeversion(lpcfg_dnsdomain(tctx->lp_ctx), true, dbdata, &version);
945 expected1->num_rr = 0;
946 expected1->records[0].printed = false;
947 expected1->records[1].printed = false;
948 torture_assert_int_equal(tctx, dlz_lookup(lpcfg_dnsdomain(tctx->lp_ctx),
949 expected1->query_name, dbdata,
950 (dns_sdlzlookup_t *)expected1),
952 "Not found hostname");
953 torture_assert(tctx, expected1->records[0].printed,
954 talloc_asprintf(tctx,
955 "Failed to have putrr callback run name[%s] for type %s",
956 expected1->records[0].name,
957 expected1->records[0].type));
958 torture_assert(tctx, expected1->records[1].printed,
959 talloc_asprintf(tctx,
960 "Failed to have putrr callback run name[%s] for type %s",
961 expected1->records[1].name,
962 expected1->records[1].type));
963 torture_assert_int_equal(tctx, expected1->num_rr, 2,
964 "Got wrong record count");
967 torture_assert_int_equal(tctx, dlz_newversion(lpcfg_dnsdomain(tctx->lp_ctx),
970 "Failed to start transaction");
971 torture_assert_int_equal_goto(tctx,
972 dlz_addrdataset(name, data0, dbdata, version),
973 ISC_R_SUCCESS, ret, cancel_version,
974 talloc_asprintf(tctx, "Failed to update name[%s] data[%s]\n",
976 dlz_closeversion(lpcfg_dnsdomain(tctx->lp_ctx), true, dbdata, &version);
979 expected1->num_rr = 0;
980 expected1->records[0].printed = false;
981 expected1->records[1].printed = false;
982 torture_assert_int_equal(tctx, dlz_lookup(lpcfg_dnsdomain(tctx->lp_ctx),
983 expected1->query_name, dbdata,
984 (dns_sdlzlookup_t *)expected1),
986 "Not found hostname");
987 torture_assert(tctx, expected1->records[0].printed,
988 talloc_asprintf(tctx,
989 "Failed to have putrr callback run name[%s] for type %s",
990 expected1->records[0].name,
991 expected1->records[0].type));
992 torture_assert(tctx, expected1->records[1].printed,
993 talloc_asprintf(tctx,
994 "Failed to have putrr callback run name[%s] for type %s",
995 expected1->records[1].name,
996 expected1->records[1].type));
997 torture_assert_int_equal(tctx, expected1->num_rr, 2,
998 "Got wrong record count");
1001 torture_assert_int_equal(tctx, dlz_newversion(lpcfg_dnsdomain(tctx->lp_ctx),
1004 "Failed to start transaction");
1005 torture_assert_int_equal_goto(tctx,
1006 dlz_delrdataset(name, "txt", dbdata, version),
1007 ISC_R_FAILURE, ret, cancel_version,
1008 talloc_asprintf(tctx, "Deleted name[%s] type[%s]\n",
1010 dlz_closeversion(lpcfg_dnsdomain(tctx->lp_ctx), false, dbdata, &version);
1013 expected1->num_rr = 0;
1014 expected1->records[0].printed = false;
1015 expected1->records[1].printed = false;
1016 torture_assert_int_equal(tctx, dlz_lookup(lpcfg_dnsdomain(tctx->lp_ctx),
1017 expected1->query_name, dbdata,
1018 (dns_sdlzlookup_t *)expected1),
1020 "Not found hostname");
1021 torture_assert(tctx, expected1->records[0].printed,
1022 talloc_asprintf(tctx,
1023 "Failed to have putrr callback run name[%s] for type %s",
1024 expected1->records[0].name,
1025 expected1->records[0].type));
1026 torture_assert(tctx, expected1->records[1].printed,
1027 talloc_asprintf(tctx,
1028 "Failed to have putrr callback run name[%s] for type %s",
1029 expected1->records[1].name,
1030 expected1->records[1].type));
1031 torture_assert_int_equal(tctx, expected1->num_rr, 2,
1032 "Got wrong record count");
1035 torture_assert_int_equal(tctx, dlz_newversion(lpcfg_dnsdomain(tctx->lp_ctx),
1038 "Failed to start transaction");
1039 torture_assert_int_equal_goto(tctx,
1040 dlz_delrdataset(name,
1041 expected1->records[0].type,
1043 ISC_R_SUCCESS, ret, cancel_version,
1044 talloc_asprintf(tctx, "Failed to delete name[%s] type[%s]\n",
1045 name, expected1->records[0].type));
1046 dlz_closeversion(lpcfg_dnsdomain(tctx->lp_ctx), true, dbdata, &version);
1049 expected1->num_rr = 0;
1050 expected1->records[0].printed = false;
1051 expected1->records[1].printed = false;
1052 torture_assert_int_equal(tctx, dlz_lookup(lpcfg_dnsdomain(tctx->lp_ctx),
1053 expected1->query_name, dbdata,
1054 (dns_sdlzlookup_t *)expected1),
1057 torture_assert_int_equal(tctx, expected1->num_rr, 0,
1058 "Got wrong record count");
1060 dlz_destroy(dbdata);
1065 dlz_closeversion(lpcfg_dnsdomain(tctx->lp_ctx), false, dbdata, &version);
1069 static struct torture_suite *dlz_bind9_suite(TALLOC_CTX *ctx)
1071 struct torture_suite *suite = torture_suite_create(ctx, "dlz_bind9");
1073 suite->description = talloc_strdup(suite,
1074 "Tests for the BIND 9 DLZ module");
1075 torture_suite_add_simple_test(suite, "version", test_dlz_bind9_version);
1076 torture_suite_add_simple_test(suite, "create", test_dlz_bind9_create);
1077 torture_suite_add_simple_test(suite, "configure", test_dlz_bind9_configure);
1078 torture_suite_add_simple_test(suite, "gssapi", test_dlz_bind9_gssapi);
1079 torture_suite_add_simple_test(suite, "spnego", test_dlz_bind9_spnego);
1080 torture_suite_add_simple_test(suite, "lookup", test_dlz_bind9_lookup);
1081 torture_suite_add_simple_test(suite, "zonedump", test_dlz_bind9_zonedump);
1082 torture_suite_add_simple_test(suite, "update01", test_dlz_bind9_update01);
1087 * DNS torture module initialization
1089 NTSTATUS torture_bind_dns_init(TALLOC_CTX *);
1090 NTSTATUS torture_bind_dns_init(TALLOC_CTX *ctx)
1092 struct torture_suite *suite;
1094 /* register DNS related test cases */
1095 suite = dlz_bind9_suite(ctx);
1096 if (!suite) return NT_STATUS_NO_MEMORY;
1097 torture_register_suite(ctx, suite);
1099 return NT_STATUS_OK;