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 "dns_server/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 char *test_dlz_bind9_binddns_dir(struct torture_context *tctx,
60 return talloc_asprintf(tctx,
62 lpcfg_binddns_dir(tctx->lp_ctx),
66 static bool test_dlz_bind9_create(struct torture_context *tctx)
69 const char *argv[] = {
72 test_dlz_bind9_binddns_dir(tctx, "dns/sam.ldb"),
76 torture_assert_int_equal(tctx, dlz_create("samba_dlz", 3, argv, &dbdata,
77 "log", dlz_bind9_log_wrapper, NULL), ISC_R_SUCCESS,
78 "Failed to create samba_dlz");
85 static isc_result_t dlz_bind9_writeable_zone_hook(dns_view_t *view,
86 const char *zone_name)
88 struct torture_context *tctx = talloc_get_type((void *)view, struct torture_context);
89 struct ldb_context *samdb = NULL;
90 char *errstring = NULL;
91 int ret = samdb_connect_url(
95 system_session(tctx->lp_ctx),
97 test_dlz_bind9_binddns_dir(tctx, "dns/sam.ldb"),
101 struct ldb_message *msg;
102 const char *attrs[] = {
105 if (ret != LDB_SUCCESS) {
106 torture_fail(tctx, "Failed to connect to samdb");
107 return ISC_R_FAILURE;
110 ret = dsdb_search_one(samdb, tctx, &msg, NULL,
111 LDB_SCOPE_SUBTREE, attrs, DSDB_SEARCH_SEARCH_ALL_PARTITIONS,
112 "(&(objectClass=dnsZone)(name=%s))", zone_name);
113 if (ret != LDB_SUCCESS) {
114 torture_fail(tctx, talloc_asprintf(tctx, "Failed to search for %s: %s", zone_name, ldb_errstring(samdb)));
115 return ISC_R_FAILURE;
119 return ISC_R_SUCCESS;
122 static bool test_dlz_bind9_configure(struct torture_context *tctx)
125 const char *argv[] = {
128 test_dlz_bind9_binddns_dir(tctx, "dns/sam.ldb"),
132 torture_assert_int_equal(tctx, dlz_create("samba_dlz", 3, argv, &dbdata,
133 "log", dlz_bind9_log_wrapper,
134 "writeable_zone", dlz_bind9_writeable_zone_hook, NULL),
136 "Failed to create samba_dlz");
138 torture_assert_int_equal(tctx, dlz_configure((void*)tctx, dbdata),
140 "Failed to configure samba_dlz");
148 * Test that a ticket obtained for the DNS service will be accepted on the Samba DLZ side
151 static bool test_dlz_bind9_gensec(struct torture_context *tctx, const char *mech)
155 struct gensec_security *gensec_client_context;
157 DATA_BLOB client_to_server, server_to_client;
160 const char *argv[] = {
163 test_dlz_bind9_binddns_dir(tctx, "dns/sam.ldb"),
167 torture_assert_int_equal(tctx, dlz_create("samba_dlz", 3, argv, &dbdata,
168 "log", dlz_bind9_log_wrapper,
169 "writeable_zone", dlz_bind9_writeable_zone_hook, NULL),
171 "Failed to create samba_dlz");
173 torture_assert_int_equal(tctx, dlz_configure((void*)tctx, dbdata),
175 "Failed to configure samba_dlz");
177 status = gensec_client_start(tctx, &gensec_client_context,
178 lpcfg_gensec_settings(tctx, tctx->lp_ctx));
179 torture_assert_ntstatus_ok(tctx, status, "gensec_client_start (client) failed");
182 * dlz_bind9 use the special dns/host.domain account
184 status = gensec_set_target_hostname(gensec_client_context,
185 talloc_asprintf(tctx,
187 torture_setting_string(tctx, "host", NULL),
188 lpcfg_dnsdomain(tctx->lp_ctx)));
189 torture_assert_ntstatus_ok(tctx, status, "gensec_set_target_hostname (client) failed");
191 status = gensec_set_target_service(gensec_client_context, "dns");
192 torture_assert_ntstatus_ok(tctx, status, "gensec_set_target_service failed");
194 status = gensec_set_credentials(gensec_client_context,
195 popt_get_cmdline_credentials());
196 torture_assert_ntstatus_ok(tctx, status, "gensec_set_credentials (client) failed");
198 status = gensec_start_mech_by_sasl_name(gensec_client_context, mech);
199 torture_assert_ntstatus_ok(tctx, status, "gensec_start_mech_by_sasl_name (client) failed");
201 server_to_client = data_blob(NULL, 0);
203 /* Do one step of the client-server update dance */
204 status = gensec_update(gensec_client_context, tctx, server_to_client, &client_to_server);
205 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {;
206 torture_assert_ntstatus_ok(tctx, status, "gensec_update (client) failed");
209 torture_assert_int_equal(tctx, dlz_ssumatch(
210 cli_credentials_get_username(
211 popt_get_cmdline_credentials()),
212 lpcfg_dnsdomain(tctx->lp_ctx),
213 "127.0.0.1", "type", "key",
214 client_to_server.length,
215 client_to_server.data,
218 "Failed to check key for update rights samba_dlz");
225 static bool test_dlz_bind9_gssapi(struct torture_context *tctx)
227 return test_dlz_bind9_gensec(tctx, "GSSAPI");
230 static bool test_dlz_bind9_spnego(struct torture_context *tctx)
232 return test_dlz_bind9_gensec(tctx, "GSS-SPNEGO");
235 struct test_expected_record {
243 struct test_expected_rr {
244 struct torture_context *tctx;
245 const char *query_name;
247 struct test_expected_record *records;
251 static bool dlz_bind9_putnamedrr_torture_hook(struct test_expected_rr *expected,
259 torture_assert(expected->tctx, name != NULL,
260 talloc_asprintf(expected->tctx,
261 "Got unnamed record type[%s] data[%s]\n",
265 torture_comment(expected->tctx, "%u: name[%s] type[%s] ttl[%u] data[%s]\n",
266 (unsigned)expected->num_rr, name, type, (unsigned)ttl, data);
268 for (i = 0; i < expected->num_records; i++) {
269 if (expected->records[i].name != NULL) {
270 if (strcmp(name, expected->records[i].name) != 0) {
275 if (strcmp(type, expected->records[i].type) != 0) {
279 if (expected->records[i].data != NULL) {
280 if (strcmp(data, expected->records[i].data) != 0) {
285 torture_assert_int_equal(expected->tctx, ttl,
286 expected->records[i].ttl,
287 talloc_asprintf(expected->tctx,
288 "TTL did not match expectations for type %s",
291 expected->records[i].printed = true;
297 static isc_result_t dlz_bind9_putrr_hook(dns_sdlzlookup_t *lookup,
302 struct test_expected_rr *expected =
303 talloc_get_type_abort(lookup, struct test_expected_rr);
306 ok = dlz_bind9_putnamedrr_torture_hook(expected, expected->query_name,
309 return ISC_R_FAILURE;
312 return ISC_R_SUCCESS;
315 static isc_result_t dlz_bind9_putnamedrr_hook(dns_sdlzallnodes_t *allnodes,
321 struct test_expected_rr *expected =
322 talloc_get_type_abort(allnodes, struct test_expected_rr);
325 ok = dlz_bind9_putnamedrr_torture_hook(expected, name, type, ttl, data);
327 return ISC_R_FAILURE;
330 return ISC_R_SUCCESS;
336 static bool test_dlz_bind9_lookup(struct torture_context *tctx)
340 const char *argv[] = {
343 test_dlz_bind9_binddns_dir(tctx, "dns/sam.ldb"),
346 struct test_expected_rr *expected1 = NULL;
347 struct test_expected_rr *expected2 = NULL;
350 torture_assert_int_equal(tctx, dlz_create("samba_dlz", 3, argv, &dbdata,
351 "log", dlz_bind9_log_wrapper,
352 "writeable_zone", dlz_bind9_writeable_zone_hook,
353 "putrr", dlz_bind9_putrr_hook,
354 "putnamedrr", dlz_bind9_putnamedrr_hook,
357 "Failed to create samba_dlz");
359 torture_assert_int_equal(tctx, dlz_configure((void*)tctx, dbdata),
361 "Failed to configure samba_dlz");
363 expected1 = talloc_zero(tctx, struct test_expected_rr);
364 torture_assert(tctx, expected1 != NULL, "talloc failed");
365 expected1->tctx = tctx;
367 expected1->query_name = "@";
369 expected1->num_records = 4;
370 expected1->records = talloc_zero_array(expected1,
371 struct test_expected_record,
372 expected1->num_records);
373 torture_assert(tctx, expected1->records != NULL, "talloc failed");
375 expected1->records[0].name = expected1->query_name;
376 expected1->records[0].type = "soa";
377 expected1->records[0].ttl = 3600;
378 expected1->records[0].data = talloc_asprintf(expected1->records,
379 "%s.%s. hostmaster.%s. 1 900 600 86400 3600",
380 torture_setting_string(tctx, "host", NULL),
381 lpcfg_dnsdomain(tctx->lp_ctx),
382 lpcfg_dnsdomain(tctx->lp_ctx));
383 torture_assert(tctx, expected1->records[0].data != NULL, "talloc failed");
385 expected1->records[1].name = expected1->query_name;
386 expected1->records[1].type = "ns";
387 expected1->records[1].ttl = 900;
388 expected1->records[1].data = talloc_asprintf(expected1->records, "%s.%s.",
389 torture_setting_string(tctx, "host", NULL),
390 lpcfg_dnsdomain(tctx->lp_ctx));
391 torture_assert(tctx, expected1->records[1].data != NULL, "talloc failed");
393 expected1->records[2].name = expected1->query_name;
394 expected1->records[2].type = "aaaa";
395 expected1->records[2].ttl = 900;
397 expected1->records[3].name = expected1->query_name;
398 expected1->records[3].type = "a";
399 expected1->records[3].ttl = 900;
401 torture_assert_int_equal(tctx, dlz_lookup(lpcfg_dnsdomain(tctx->lp_ctx),
402 expected1->query_name, dbdata,
403 (dns_sdlzlookup_t *)expected1),
405 "Failed to lookup @");
406 for (i = 0; i < expected1->num_records; i++) {
407 torture_assert(tctx, expected1->records[i].printed,
408 talloc_asprintf(tctx,
409 "Failed to have putrr callback run for type %s",
410 expected1->records[i].type));
412 torture_assert_int_equal(tctx, expected1->num_rr,
413 expected1->num_records,
414 "Got too much data");
416 expected2 = talloc_zero(tctx, struct test_expected_rr);
417 torture_assert(tctx, expected2 != NULL, "talloc failed");
418 expected2->tctx = tctx;
420 expected2->query_name = torture_setting_string(tctx, "host", NULL);
421 torture_assert(tctx, expected2->query_name != NULL, "unknown host");
423 expected2->num_records = 2;
424 expected2->records = talloc_zero_array(expected2,
425 struct test_expected_record,
426 expected2->num_records);
427 torture_assert(tctx, expected2->records != NULL, "talloc failed");
429 expected2->records[0].name = expected2->query_name;
430 expected2->records[0].type = "aaaa";
431 expected2->records[0].ttl = 900;
433 expected2->records[1].name = expected2->query_name;
434 expected2->records[1].type = "a";
435 expected2->records[1].ttl = 900;
437 torture_assert_int_equal(tctx, dlz_lookup(lpcfg_dnsdomain(tctx->lp_ctx),
438 expected2->query_name, dbdata,
439 (dns_sdlzlookup_t *)expected2),
441 "Failed to lookup hostname");
442 for (i = 0; i < expected2->num_records; i++) {
443 torture_assert(tctx, expected2->records[i].printed,
444 talloc_asprintf(tctx,
445 "Failed to have putrr callback run name[%s] for type %s",
446 expected2->records[i].name,
447 expected2->records[i].type));
449 torture_assert_int_equal(tctx, expected2->num_rr,
450 expected2->num_records,
451 "Got too much data");
459 * Test some zone dumps
461 static bool test_dlz_bind9_zonedump(struct torture_context *tctx)
465 const char *argv[] = {
468 test_dlz_bind9_binddns_dir(tctx, "dns/sam.ldb"),
471 struct test_expected_rr *expected1 = NULL;
474 torture_assert_int_equal(tctx, dlz_create("samba_dlz", 3, argv, &dbdata,
475 "log", dlz_bind9_log_wrapper,
476 "writeable_zone", dlz_bind9_writeable_zone_hook,
477 "putrr", dlz_bind9_putrr_hook,
478 "putnamedrr", dlz_bind9_putnamedrr_hook,
481 "Failed to create samba_dlz");
483 torture_assert_int_equal(tctx, dlz_configure((void*)tctx, dbdata),
485 "Failed to configure samba_dlz");
487 expected1 = talloc_zero(tctx, struct test_expected_rr);
488 torture_assert(tctx, expected1 != NULL, "talloc failed");
489 expected1->tctx = tctx;
491 expected1->num_records = 7;
492 expected1->records = talloc_zero_array(expected1,
493 struct test_expected_record,
494 expected1->num_records);
495 torture_assert(tctx, expected1->records != NULL, "talloc failed");
497 expected1->records[0].name = talloc_asprintf(expected1->records,
498 "%s.", lpcfg_dnsdomain(tctx->lp_ctx));
499 expected1->records[0].type = "soa";
500 expected1->records[0].ttl = 3600;
501 expected1->records[0].data = talloc_asprintf(expected1->records,
502 "%s.%s. hostmaster.%s. 1 900 600 86400 3600",
503 torture_setting_string(tctx, "host", NULL),
504 lpcfg_dnsdomain(tctx->lp_ctx),
505 lpcfg_dnsdomain(tctx->lp_ctx));
506 torture_assert(tctx, expected1->records[0].data != NULL, "talloc failed");
508 expected1->records[1].name = talloc_asprintf(expected1->records,
509 "%s.", lpcfg_dnsdomain(tctx->lp_ctx));
510 expected1->records[1].type = "ns";
511 expected1->records[1].ttl = 900;
512 expected1->records[1].data = talloc_asprintf(expected1->records, "%s.%s.",
513 torture_setting_string(tctx, "host", NULL),
514 lpcfg_dnsdomain(tctx->lp_ctx));
515 torture_assert(tctx, expected1->records[1].data != NULL, "talloc failed");
517 expected1->records[2].name = talloc_asprintf(expected1->records,
518 "%s.", lpcfg_dnsdomain(tctx->lp_ctx));
519 expected1->records[2].type = "aaaa";
520 expected1->records[2].ttl = 900;
522 expected1->records[3].name = talloc_asprintf(expected1->records,
523 "%s.", lpcfg_dnsdomain(tctx->lp_ctx));
524 expected1->records[3].type = "a";
525 expected1->records[3].ttl = 900;
527 expected1->records[4].name = talloc_asprintf(expected1->records, "%s.%s.",
528 torture_setting_string(tctx, "host", NULL),
529 lpcfg_dnsdomain(tctx->lp_ctx));
530 torture_assert(tctx, expected1->records[4].name != NULL, "unknown host");
531 expected1->records[4].type = "aaaa";
532 expected1->records[4].ttl = 900;
534 expected1->records[5].name = talloc_asprintf(expected1->records, "%s.%s.",
535 torture_setting_string(tctx, "host", NULL),
536 lpcfg_dnsdomain(tctx->lp_ctx));
537 torture_assert(tctx, expected1->records[5].name != NULL, "unknown host");
538 expected1->records[5].type = "a";
539 expected1->records[5].ttl = 900;
542 * We expect multiple srv records
544 expected1->records[6].name = NULL;
545 expected1->records[6].type = "srv";
546 expected1->records[6].ttl = 900;
548 torture_assert_int_equal(tctx, dlz_allnodes(lpcfg_dnsdomain(tctx->lp_ctx),
549 dbdata, (dns_sdlzallnodes_t *)expected1),
551 "Failed to configure samba_dlz");
552 for (i = 0; i < expected1->num_records; i++) {
553 torture_assert(tctx, expected1->records[i].printed,
554 talloc_asprintf(tctx,
555 "Failed to have putrr callback run name[%s] for type %s",
556 expected1->records[i].name,
557 expected1->records[i].type));
559 torture_assert_int_equal(tctx, expected1->num_rr, 24,
560 "Got wrong record count");
570 static bool test_dlz_bind9_update01(struct torture_context *tctx)
573 struct gensec_security *gensec_client_context;
574 DATA_BLOB client_to_server, server_to_client;
576 void *version = NULL;
577 const char *argv[] = {
580 test_dlz_bind9_binddns_dir(tctx, "dns/sam.ldb"),
583 struct test_expected_rr *expected1 = NULL;
591 torture_assert_int_equal(tctx, dlz_create("samba_dlz", 3, argv, &dbdata,
592 "log", dlz_bind9_log_wrapper,
593 "writeable_zone", dlz_bind9_writeable_zone_hook,
594 "putrr", dlz_bind9_putrr_hook,
595 "putnamedrr", dlz_bind9_putnamedrr_hook,
598 "Failed to create samba_dlz");
600 torture_assert_int_equal(tctx, dlz_configure((void*)tctx, dbdata),
602 "Failed to configure samba_dlz");
604 expected1 = talloc_zero(tctx, struct test_expected_rr);
605 torture_assert(tctx, expected1 != NULL, "talloc failed");
606 expected1->tctx = tctx;
608 expected1->query_name = __func__;
610 name = talloc_asprintf(expected1, "%s.%s",
611 expected1->query_name,
612 lpcfg_dnsdomain(tctx->lp_ctx));
613 torture_assert(tctx, name != NULL, "talloc failed");
615 expected1->num_records = 2;
616 expected1->records = talloc_zero_array(expected1,
617 struct test_expected_record,
618 expected1->num_records);
619 torture_assert(tctx, expected1->records != NULL, "talloc failed");
621 expected1->records[0].name = expected1->query_name;
622 expected1->records[0].type = "a";
623 expected1->records[0].ttl = 3600;
624 expected1->records[0].data = "127.1.2.3";
625 expected1->records[0].printed = false;
627 data0 = talloc_asprintf(expected1,
628 "%s.\t" "%u\t" "%s\t" "%s\t" "%s",
630 (unsigned)expected1->records[0].ttl,
632 expected1->records[0].type,
633 expected1->records[0].data);
634 torture_assert(tctx, data0 != NULL, "talloc failed");
636 expected1->records[1].name = expected1->query_name;
637 expected1->records[1].type = "a";
638 expected1->records[1].ttl = 3600;
639 expected1->records[1].data = "127.3.2.1";
640 expected1->records[1].printed = false;
642 data1 = talloc_asprintf(expected1,
643 "%s.\t" "%u\t" "%s\t" "%s\t" "%s",
645 (unsigned)expected1->records[1].ttl,
647 expected1->records[1].type,
648 expected1->records[1].data);
649 torture_assert(tctx, data1 != NULL, "talloc failed");
651 data2 = talloc_asprintf(expected1,
652 "%s.\t" "0\t" "in\t" "a\t" "127.3.3.3",
654 torture_assert(tctx, data2 != NULL, "talloc failed");
657 * Prepare session info
659 status = gensec_client_start(tctx, &gensec_client_context,
660 lpcfg_gensec_settings(tctx, tctx->lp_ctx));
661 torture_assert_ntstatus_ok(tctx, status, "gensec_client_start (client) failed");
664 * dlz_bind9 use the special dns/host.domain account
666 status = gensec_set_target_hostname(gensec_client_context,
667 talloc_asprintf(tctx,
669 torture_setting_string(tctx, "host", NULL),
670 lpcfg_dnsdomain(tctx->lp_ctx)));
671 torture_assert_ntstatus_ok(tctx, status, "gensec_set_target_hostname (client) failed");
673 status = gensec_set_target_service(gensec_client_context, "dns");
674 torture_assert_ntstatus_ok(tctx, status, "gensec_set_target_service failed");
676 status = gensec_set_credentials(gensec_client_context,
677 popt_get_cmdline_credentials());
678 torture_assert_ntstatus_ok(tctx, status, "gensec_set_credentials (client) failed");
680 status = gensec_start_mech_by_sasl_name(gensec_client_context, "GSS-SPNEGO");
681 torture_assert_ntstatus_ok(tctx, status, "gensec_start_mech_by_sasl_name (client) failed");
683 server_to_client = data_blob(NULL, 0);
685 /* Do one step of the client-server update dance */
686 status = gensec_update(gensec_client_context, tctx, server_to_client, &client_to_server);
687 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {;
688 torture_assert_ntstatus_ok(tctx, status, "gensec_update (client) failed");
691 torture_assert_int_equal(tctx, dlz_ssumatch(
692 cli_credentials_get_username(
693 popt_get_cmdline_credentials()),
696 expected1->records[0].type,
698 client_to_server.length,
699 client_to_server.data,
702 "Failed to check key for update rights samba_dlz");
705 * We test the following:
707 * 1. lookup the records => NOT_FOUND
708 * 2. delete all records => NOT_FOUND
709 * 3. delete 1st record => NOT_FOUND
710 * 4. create 1st record => SUCCESS
711 * 5. lookup the records => found 1st
712 * 6. create 2nd record => SUCCESS
713 * 7. lookup the records => found 1st and 2nd
714 * 8. delete unknown record => NOT_FOUND
715 * 9. lookup the records => found 1st and 2nd
716 * 10. delete 1st record => SUCCESS
717 * 11. lookup the records => found 2nd
718 * 12. delete 2nd record => SUCCESS
719 * 13. lookup the records => NOT_FOUND
720 * 14. create 1st record => SUCCESS
721 * 15. lookup the records => found 1st
722 * 16. create 2nd record => SUCCESS
723 * 17. lookup the records => found 1st and 2nd
724 * 18. update 1st record => SUCCESS
725 * 19. lookup the records => found 1st and 2nd
726 * 20. delete all unknown type records => NOT_FOUND
727 * 21. lookup the records => found 1st and 2nd
728 * 22. delete all records => SUCCESS
729 * 23. lookup the records => NOT_FOUND
733 expected1->num_rr = 0;
734 expected1->records[0].printed = false;
735 expected1->records[1].printed = false;
736 torture_assert_int_equal(tctx, dlz_lookup(lpcfg_dnsdomain(tctx->lp_ctx),
737 expected1->query_name, dbdata,
738 (dns_sdlzlookup_t *)expected1),
741 torture_assert_int_equal(tctx, expected1->num_rr, 0,
742 "Got wrong record count");
745 torture_assert_int_equal(tctx, dlz_newversion(lpcfg_dnsdomain(tctx->lp_ctx),
748 "Failed to start transaction");
749 torture_assert_int_equal_goto(tctx,
750 dlz_delrdataset(name,
751 expected1->records[0].type,
753 ISC_R_NOTFOUND, ret, cancel_version,
754 talloc_asprintf(tctx, "Deleted name[%s] type[%s]\n",
755 name, expected1->records[0].type));
756 dlz_closeversion(lpcfg_dnsdomain(tctx->lp_ctx), false, dbdata, &version);
759 torture_assert_int_equal(tctx, dlz_newversion(lpcfg_dnsdomain(tctx->lp_ctx),
762 "Failed to start transaction");
763 torture_assert_int_equal_goto(tctx,
764 dlz_subrdataset(name, data0, dbdata, version),
765 ISC_R_NOTFOUND, ret, cancel_version,
766 talloc_asprintf(tctx, "Deleted name[%s] data[%s]\n",
768 dlz_closeversion(lpcfg_dnsdomain(tctx->lp_ctx), false, dbdata, &version);
771 torture_assert_int_equal(tctx, dlz_newversion(lpcfg_dnsdomain(tctx->lp_ctx),
774 "Failed to start transaction");
775 torture_assert_int_equal_goto(tctx,
776 dlz_addrdataset(name, data0, dbdata, version),
777 ISC_R_SUCCESS, ret, cancel_version,
778 talloc_asprintf(tctx, "Failed to add name[%s] data[%s]\n",
780 dlz_closeversion(lpcfg_dnsdomain(tctx->lp_ctx), true, dbdata, &version);
783 expected1->num_rr = 0;
784 expected1->records[0].printed = false;
785 expected1->records[1].printed = false;
786 torture_assert_int_equal(tctx, dlz_lookup(lpcfg_dnsdomain(tctx->lp_ctx),
787 expected1->query_name, dbdata,
788 (dns_sdlzlookup_t *)expected1),
790 "Not found hostname");
791 torture_assert(tctx, expected1->records[0].printed,
792 talloc_asprintf(tctx,
793 "Failed to have putrr callback run name[%s] for type %s",
794 expected1->records[0].name,
795 expected1->records[0].type));
796 torture_assert_int_equal(tctx, expected1->num_rr, 1,
797 "Got wrong record count");
800 torture_assert_int_equal(tctx, dlz_newversion(lpcfg_dnsdomain(tctx->lp_ctx),
803 "Failed to start transaction");
804 torture_assert_int_equal_goto(tctx,
805 dlz_addrdataset(name, data1, dbdata, version),
806 ISC_R_SUCCESS, ret, cancel_version,
807 talloc_asprintf(tctx, "Failed to add name[%s] data[%s]\n",
809 dlz_closeversion(lpcfg_dnsdomain(tctx->lp_ctx), true, dbdata, &version);
812 expected1->num_rr = 0;
813 expected1->records[0].printed = false;
814 expected1->records[1].printed = false;
815 torture_assert_int_equal(tctx, dlz_lookup(lpcfg_dnsdomain(tctx->lp_ctx),
816 expected1->query_name, dbdata,
817 (dns_sdlzlookup_t *)expected1),
819 "Not found hostname");
820 torture_assert(tctx, expected1->records[0].printed,
821 talloc_asprintf(tctx,
822 "Failed to have putrr callback run name[%s] for type %s",
823 expected1->records[0].name,
824 expected1->records[0].type));
825 torture_assert(tctx, expected1->records[1].printed,
826 talloc_asprintf(tctx,
827 "Failed to have putrr callback run name[%s] for type %s",
828 expected1->records[1].name,
829 expected1->records[1].type));
830 torture_assert_int_equal(tctx, expected1->num_rr, 2,
831 "Got wrong record count");
834 torture_assert_int_equal(tctx, dlz_newversion(lpcfg_dnsdomain(tctx->lp_ctx),
837 "Failed to start transaction");
838 torture_assert_int_equal_goto(tctx,
839 dlz_subrdataset(name, data2, dbdata, version),
840 ISC_R_NOTFOUND, ret, cancel_version,
841 talloc_asprintf(tctx, "Deleted name[%s] data[%s]\n",
843 dlz_closeversion(lpcfg_dnsdomain(tctx->lp_ctx), true, dbdata, &version);
846 expected1->num_rr = 0;
847 expected1->records[0].printed = false;
848 expected1->records[1].printed = false;
849 torture_assert_int_equal(tctx, dlz_lookup(lpcfg_dnsdomain(tctx->lp_ctx),
850 expected1->query_name, dbdata,
851 (dns_sdlzlookup_t *)expected1),
853 "Not found hostname");
854 torture_assert(tctx, expected1->records[0].printed,
855 talloc_asprintf(tctx,
856 "Failed to have putrr callback run name[%s] for type %s",
857 expected1->records[0].name,
858 expected1->records[0].type));
859 torture_assert(tctx, expected1->records[1].printed,
860 talloc_asprintf(tctx,
861 "Failed to have putrr callback run name[%s] for type %s",
862 expected1->records[1].name,
863 expected1->records[1].type));
864 torture_assert_int_equal(tctx, expected1->num_rr, 2,
865 "Got wrong record count");
868 torture_assert_int_equal(tctx, dlz_newversion(lpcfg_dnsdomain(tctx->lp_ctx),
871 "Failed to start transaction");
872 torture_assert_int_equal_goto(tctx,
873 dlz_subrdataset(name, data0, dbdata, version),
874 ISC_R_SUCCESS, ret, cancel_version,
875 talloc_asprintf(tctx, "Failed to delete name[%s] data[%s]\n",
877 dlz_closeversion(lpcfg_dnsdomain(tctx->lp_ctx), true, dbdata, &version);
880 expected1->num_rr = 0;
881 expected1->records[0].printed = false;
882 expected1->records[1].printed = false;
883 torture_assert_int_equal(tctx, dlz_lookup(lpcfg_dnsdomain(tctx->lp_ctx),
884 expected1->query_name, dbdata,
885 (dns_sdlzlookup_t *)expected1),
887 "Not found hostname");
888 torture_assert(tctx, expected1->records[1].printed,
889 talloc_asprintf(tctx,
890 "Failed to have putrr callback run name[%s] for type %s",
891 expected1->records[1].name,
892 expected1->records[1].type));
893 torture_assert_int_equal(tctx, expected1->num_rr, 1,
894 "Got wrong record count");
897 torture_assert_int_equal(tctx, dlz_newversion(lpcfg_dnsdomain(tctx->lp_ctx),
900 "Failed to start transaction");
901 torture_assert_int_equal_goto(tctx,
902 dlz_subrdataset(name, data1, dbdata, version),
903 ISC_R_SUCCESS, ret, cancel_version,
904 talloc_asprintf(tctx, "Failed to delete name[%s] data[%s]\n",
906 dlz_closeversion(lpcfg_dnsdomain(tctx->lp_ctx), true, dbdata, &version);
909 expected1->num_rr = 0;
910 expected1->records[0].printed = false;
911 expected1->records[1].printed = false;
912 torture_assert_int_equal(tctx, dlz_lookup(lpcfg_dnsdomain(tctx->lp_ctx),
913 expected1->query_name, dbdata,
914 (dns_sdlzlookup_t *)expected1),
917 torture_assert_int_equal(tctx, expected1->num_rr, 0,
918 "Got wrong record count");
921 torture_assert_int_equal(tctx, dlz_newversion(lpcfg_dnsdomain(tctx->lp_ctx),
924 "Failed to start transaction");
925 torture_assert_int_equal_goto(tctx,
926 dlz_addrdataset(name, data0, dbdata, version),
927 ISC_R_SUCCESS, ret, cancel_version,
928 talloc_asprintf(tctx, "Failed to add name[%s] data[%s]\n",
930 dlz_closeversion(lpcfg_dnsdomain(tctx->lp_ctx), true, dbdata, &version);
933 expected1->num_rr = 0;
934 expected1->records[0].printed = false;
935 expected1->records[1].printed = false;
936 torture_assert_int_equal(tctx, dlz_lookup(lpcfg_dnsdomain(tctx->lp_ctx),
937 expected1->query_name, dbdata,
938 (dns_sdlzlookup_t *)expected1),
940 "Not found hostname");
941 torture_assert(tctx, expected1->records[0].printed,
942 talloc_asprintf(tctx,
943 "Failed to have putrr callback run name[%s] for type %s",
944 expected1->records[0].name,
945 expected1->records[0].type));
946 torture_assert_int_equal(tctx, expected1->num_rr, 1,
947 "Got wrong record count");
950 torture_assert_int_equal(tctx, dlz_newversion(lpcfg_dnsdomain(tctx->lp_ctx),
953 "Failed to start transaction");
954 torture_assert_int_equal_goto(tctx,
955 dlz_addrdataset(name, data1, dbdata, version),
956 ISC_R_SUCCESS, ret, cancel_version,
957 talloc_asprintf(tctx, "Failed to add name[%s] data[%s]\n",
959 dlz_closeversion(lpcfg_dnsdomain(tctx->lp_ctx), true, dbdata, &version);
962 expected1->num_rr = 0;
963 expected1->records[0].printed = false;
964 expected1->records[1].printed = false;
965 torture_assert_int_equal(tctx, dlz_lookup(lpcfg_dnsdomain(tctx->lp_ctx),
966 expected1->query_name, dbdata,
967 (dns_sdlzlookup_t *)expected1),
969 "Not found hostname");
970 torture_assert(tctx, expected1->records[0].printed,
971 talloc_asprintf(tctx,
972 "Failed to have putrr callback run name[%s] for type %s",
973 expected1->records[0].name,
974 expected1->records[0].type));
975 torture_assert(tctx, expected1->records[1].printed,
976 talloc_asprintf(tctx,
977 "Failed to have putrr callback run name[%s] for type %s",
978 expected1->records[1].name,
979 expected1->records[1].type));
980 torture_assert_int_equal(tctx, expected1->num_rr, 2,
981 "Got wrong record count");
984 torture_assert_int_equal(tctx, dlz_newversion(lpcfg_dnsdomain(tctx->lp_ctx),
987 "Failed to start transaction");
988 torture_assert_int_equal_goto(tctx,
989 dlz_addrdataset(name, data0, dbdata, version),
990 ISC_R_SUCCESS, ret, cancel_version,
991 talloc_asprintf(tctx, "Failed to update name[%s] data[%s]\n",
993 dlz_closeversion(lpcfg_dnsdomain(tctx->lp_ctx), true, dbdata, &version);
996 expected1->num_rr = 0;
997 expected1->records[0].printed = false;
998 expected1->records[1].printed = false;
999 torture_assert_int_equal(tctx, dlz_lookup(lpcfg_dnsdomain(tctx->lp_ctx),
1000 expected1->query_name, dbdata,
1001 (dns_sdlzlookup_t *)expected1),
1003 "Not found hostname");
1004 torture_assert(tctx, expected1->records[0].printed,
1005 talloc_asprintf(tctx,
1006 "Failed to have putrr callback run name[%s] for type %s",
1007 expected1->records[0].name,
1008 expected1->records[0].type));
1009 torture_assert(tctx, expected1->records[1].printed,
1010 talloc_asprintf(tctx,
1011 "Failed to have putrr callback run name[%s] for type %s",
1012 expected1->records[1].name,
1013 expected1->records[1].type));
1014 torture_assert_int_equal(tctx, expected1->num_rr, 2,
1015 "Got wrong record count");
1018 torture_assert_int_equal(tctx, dlz_newversion(lpcfg_dnsdomain(tctx->lp_ctx),
1021 "Failed to start transaction");
1022 torture_assert_int_equal_goto(tctx,
1023 dlz_delrdataset(name, "txt", dbdata, version),
1024 ISC_R_FAILURE, ret, cancel_version,
1025 talloc_asprintf(tctx, "Deleted name[%s] type[%s]\n",
1027 dlz_closeversion(lpcfg_dnsdomain(tctx->lp_ctx), false, dbdata, &version);
1030 expected1->num_rr = 0;
1031 expected1->records[0].printed = false;
1032 expected1->records[1].printed = false;
1033 torture_assert_int_equal(tctx, dlz_lookup(lpcfg_dnsdomain(tctx->lp_ctx),
1034 expected1->query_name, dbdata,
1035 (dns_sdlzlookup_t *)expected1),
1037 "Not found hostname");
1038 torture_assert(tctx, expected1->records[0].printed,
1039 talloc_asprintf(tctx,
1040 "Failed to have putrr callback run name[%s] for type %s",
1041 expected1->records[0].name,
1042 expected1->records[0].type));
1043 torture_assert(tctx, expected1->records[1].printed,
1044 talloc_asprintf(tctx,
1045 "Failed to have putrr callback run name[%s] for type %s",
1046 expected1->records[1].name,
1047 expected1->records[1].type));
1048 torture_assert_int_equal(tctx, expected1->num_rr, 2,
1049 "Got wrong record count");
1052 torture_assert_int_equal(tctx, dlz_newversion(lpcfg_dnsdomain(tctx->lp_ctx),
1055 "Failed to start transaction");
1056 torture_assert_int_equal_goto(tctx,
1057 dlz_delrdataset(name,
1058 expected1->records[0].type,
1060 ISC_R_SUCCESS, ret, cancel_version,
1061 talloc_asprintf(tctx, "Failed to delete name[%s] type[%s]\n",
1062 name, expected1->records[0].type));
1063 dlz_closeversion(lpcfg_dnsdomain(tctx->lp_ctx), true, dbdata, &version);
1066 expected1->num_rr = 0;
1067 expected1->records[0].printed = false;
1068 expected1->records[1].printed = false;
1069 torture_assert_int_equal(tctx, dlz_lookup(lpcfg_dnsdomain(tctx->lp_ctx),
1070 expected1->query_name, dbdata,
1071 (dns_sdlzlookup_t *)expected1),
1074 torture_assert_int_equal(tctx, expected1->num_rr, 0,
1075 "Got wrong record count");
1077 dlz_destroy(dbdata);
1082 dlz_closeversion(lpcfg_dnsdomain(tctx->lp_ctx), false, dbdata, &version);
1086 static struct torture_suite *dlz_bind9_suite(TALLOC_CTX *ctx)
1088 struct torture_suite *suite = torture_suite_create(ctx, "dlz_bind9");
1090 suite->description = talloc_strdup(suite,
1091 "Tests for the BIND 9 DLZ module");
1092 torture_suite_add_simple_test(suite, "version", test_dlz_bind9_version);
1093 torture_suite_add_simple_test(suite, "create", test_dlz_bind9_create);
1094 torture_suite_add_simple_test(suite, "configure", test_dlz_bind9_configure);
1095 torture_suite_add_simple_test(suite, "gssapi", test_dlz_bind9_gssapi);
1096 torture_suite_add_simple_test(suite, "spnego", test_dlz_bind9_spnego);
1097 torture_suite_add_simple_test(suite, "lookup", test_dlz_bind9_lookup);
1098 torture_suite_add_simple_test(suite, "zonedump", test_dlz_bind9_zonedump);
1099 torture_suite_add_simple_test(suite, "update01", test_dlz_bind9_update01);
1104 * DNS torture module initialization
1106 NTSTATUS torture_bind_dns_init(TALLOC_CTX *);
1107 NTSTATUS torture_bind_dns_init(TALLOC_CTX *ctx)
1109 struct torture_suite *suite;
1111 /* register DNS related test cases */
1112 suite = dlz_bind9_suite(ctx);
1113 if (!suite) return NT_STATUS_NO_MEMORY;
1114 torture_register_suite(ctx, suite);
1116 return NT_STATUS_OK;