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 /* Tests that configure multiple DLZs will use this. Increase to add stress. */
34 #define NUM_DLZS_TO_CONFIGURE 4
36 struct torture_context *tctx_static;
38 static void dlz_bind9_log_wrapper(int level, const char *fmt, ...)
39 PRINTF_ATTRIBUTE(2,3);
41 static void dlz_bind9_log_wrapper(int level, const char *fmt, ...)
46 msg = talloc_vasprintf(NULL, fmt, ap);
47 torture_comment(tctx_static, "%s\n", msg);
52 static bool test_dlz_bind9_version(struct torture_context *tctx)
54 unsigned int flags = 0;
55 torture_assert_int_equal(tctx, dlz_version(&flags),
56 DLZ_DLOPEN_VERSION, "got wrong DLZ version");
60 static char *test_dlz_bind9_binddns_dir(struct torture_context *tctx,
63 return talloc_asprintf(tctx,
65 lpcfg_binddns_dir(tctx->lp_ctx),
69 static bool test_dlz_bind9_create(struct torture_context *tctx)
72 const char *argv[] = {
75 test_dlz_bind9_binddns_dir(tctx, "dns/sam.ldb"),
79 torture_assert_int_equal(tctx, dlz_create("samba_dlz", 3, argv, &dbdata,
80 "log", dlz_bind9_log_wrapper, NULL), ISC_R_SUCCESS,
81 "Failed to create samba_dlz");
88 static isc_result_t dlz_bind9_writeable_zone_hook(dns_view_t *view,
89 const char *zone_name)
91 struct torture_context *tctx = talloc_get_type((void *)view, struct torture_context);
92 struct ldb_context *samdb = NULL;
93 char *errstring = NULL;
94 int ret = samdb_connect_url(
98 system_session(tctx->lp_ctx),
100 test_dlz_bind9_binddns_dir(tctx, "dns/sam.ldb"),
104 struct ldb_message *msg;
105 const char *attrs[] = {
108 if (ret != LDB_SUCCESS) {
109 torture_fail(tctx, "Failed to connect to samdb");
110 return ISC_R_FAILURE;
113 ret = dsdb_search_one(samdb, tctx, &msg, NULL,
114 LDB_SCOPE_SUBTREE, attrs, DSDB_SEARCH_SEARCH_ALL_PARTITIONS,
115 "(&(objectClass=dnsZone)(name=%s))", zone_name);
116 if (ret != LDB_SUCCESS) {
117 torture_fail(tctx, talloc_asprintf(tctx, "Failed to search for %s: %s", zone_name, ldb_errstring(samdb)));
118 return ISC_R_FAILURE;
122 return ISC_R_SUCCESS;
125 static bool test_dlz_bind9_configure(struct torture_context *tctx)
128 const char *argv[] = {
131 test_dlz_bind9_binddns_dir(tctx, "dns/sam.ldb"),
135 torture_assert_int_equal(tctx, dlz_create("samba_dlz", 3, argv, &dbdata,
136 "log", dlz_bind9_log_wrapper,
137 "writeable_zone", dlz_bind9_writeable_zone_hook, NULL),
139 "Failed to create samba_dlz");
141 torture_assert_int_equal(tctx, dlz_configure((void*)tctx, dbdata),
143 "Failed to configure samba_dlz");
150 static bool test_dlz_bind9_multiple_configure(struct torture_context *tctx)
153 for(i = 0; i < NUM_DLZS_TO_CONFIGURE; i++){
154 test_dlz_bind9_configure(tctx);
159 static bool configure_multiple_dlzs(struct torture_context *tctx,
160 void **dbdata, int count)
163 const char *argv[] = {
166 test_dlz_bind9_binddns_dir(tctx, "dns/sam.ldb"),
171 for(i = 0; i < count; i++){
172 res = dlz_create("samba_dlz", 3, argv, &(dbdata[i]),
173 "log", dlz_bind9_log_wrapper,
175 dlz_bind9_writeable_zone_hook, NULL);
176 torture_assert_int_equal(tctx, res, ISC_R_SUCCESS,
177 "Failed to create samba_dlz");
179 res = dlz_configure((void*)tctx, dbdata[i]);
180 torture_assert_int_equal(tctx, res, ISC_R_SUCCESS,
181 "Failed to configure samba_dlz");
187 static bool test_dlz_bind9_destroy_oldest_first(struct torture_context *tctx)
189 void *dbdata[NUM_DLZS_TO_CONFIGURE];
192 configure_multiple_dlzs(tctx, dbdata, NUM_DLZS_TO_CONFIGURE);
194 /* Reload faults are reported to happen on the first destroy */
195 dlz_destroy(dbdata[0]);
197 for(i = 1; i < NUM_DLZS_TO_CONFIGURE; i++){
198 dlz_destroy(dbdata[i]);
204 static bool test_dlz_bind9_destroy_newest_first(struct torture_context *tctx)
206 void *dbdata[NUM_DLZS_TO_CONFIGURE];
209 configure_multiple_dlzs(tctx, dbdata, NUM_DLZS_TO_CONFIGURE);
211 for(i = NUM_DLZS_TO_CONFIGURE - 1; i >= 0; i--) {
212 dlz_destroy(dbdata[i]);
219 * Test that a ticket obtained for the DNS service will be accepted on the Samba DLZ side
222 static bool test_dlz_bind9_gensec(struct torture_context *tctx, const char *mech)
226 struct gensec_security *gensec_client_context;
228 DATA_BLOB client_to_server, server_to_client;
231 const char *argv[] = {
234 test_dlz_bind9_binddns_dir(tctx, "dns/sam.ldb"),
238 torture_assert_int_equal(tctx, dlz_create("samba_dlz", 3, argv, &dbdata,
239 "log", dlz_bind9_log_wrapper,
240 "writeable_zone", dlz_bind9_writeable_zone_hook, NULL),
242 "Failed to create samba_dlz");
244 torture_assert_int_equal(tctx, dlz_configure((void*)tctx, dbdata),
246 "Failed to configure samba_dlz");
248 status = gensec_client_start(tctx, &gensec_client_context,
249 lpcfg_gensec_settings(tctx, tctx->lp_ctx));
250 torture_assert_ntstatus_ok(tctx, status, "gensec_client_start (client) failed");
253 * dlz_bind9 use the special dns/host.domain account
255 status = gensec_set_target_hostname(gensec_client_context,
256 talloc_asprintf(tctx,
258 torture_setting_string(tctx, "host", NULL),
259 lpcfg_dnsdomain(tctx->lp_ctx)));
260 torture_assert_ntstatus_ok(tctx, status, "gensec_set_target_hostname (client) failed");
262 status = gensec_set_target_service(gensec_client_context, "dns");
263 torture_assert_ntstatus_ok(tctx, status, "gensec_set_target_service failed");
265 status = gensec_set_credentials(gensec_client_context,
266 popt_get_cmdline_credentials());
267 torture_assert_ntstatus_ok(tctx, status, "gensec_set_credentials (client) failed");
269 status = gensec_start_mech_by_sasl_name(gensec_client_context, mech);
270 torture_assert_ntstatus_ok(tctx, status, "gensec_start_mech_by_sasl_name (client) failed");
272 server_to_client = data_blob(NULL, 0);
274 /* Do one step of the client-server update dance */
275 status = gensec_update(gensec_client_context, tctx, server_to_client, &client_to_server);
276 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {;
277 torture_assert_ntstatus_ok(tctx, status, "gensec_update (client) failed");
280 torture_assert_int_equal(tctx, dlz_ssumatch(
281 cli_credentials_get_username(
282 popt_get_cmdline_credentials()),
283 lpcfg_dnsdomain(tctx->lp_ctx),
284 "127.0.0.1", "type", "key",
285 client_to_server.length,
286 client_to_server.data,
289 "Failed to check key for update rights samba_dlz");
296 static bool test_dlz_bind9_gssapi(struct torture_context *tctx)
298 return test_dlz_bind9_gensec(tctx, "GSSAPI");
301 static bool test_dlz_bind9_spnego(struct torture_context *tctx)
303 return test_dlz_bind9_gensec(tctx, "GSS-SPNEGO");
306 struct test_expected_record {
314 struct test_expected_rr {
315 struct torture_context *tctx;
316 const char *query_name;
318 struct test_expected_record *records;
322 static bool dlz_bind9_putnamedrr_torture_hook(struct test_expected_rr *expected,
330 torture_assert(expected->tctx, name != NULL,
331 talloc_asprintf(expected->tctx,
332 "Got unnamed record type[%s] data[%s]\n",
336 torture_comment(expected->tctx, "%u: name[%s] type[%s] ttl[%u] data[%s]\n",
337 (unsigned)expected->num_rr, name, type, (unsigned)ttl, data);
339 for (i = 0; i < expected->num_records; i++) {
340 if (expected->records[i].name != NULL) {
341 if (strcmp(name, expected->records[i].name) != 0) {
346 if (strcmp(type, expected->records[i].type) != 0) {
350 if (expected->records[i].data != NULL) {
351 if (strcmp(data, expected->records[i].data) != 0) {
356 torture_assert_int_equal(expected->tctx, ttl,
357 expected->records[i].ttl,
358 talloc_asprintf(expected->tctx,
359 "TTL did not match expectations for type %s",
362 expected->records[i].printed = true;
368 static isc_result_t dlz_bind9_putrr_hook(dns_sdlzlookup_t *lookup,
373 struct test_expected_rr *expected =
374 talloc_get_type_abort(lookup, struct test_expected_rr);
377 ok = dlz_bind9_putnamedrr_torture_hook(expected, expected->query_name,
380 return ISC_R_FAILURE;
383 return ISC_R_SUCCESS;
386 static isc_result_t dlz_bind9_putnamedrr_hook(dns_sdlzallnodes_t *allnodes,
392 struct test_expected_rr *expected =
393 talloc_get_type_abort(allnodes, struct test_expected_rr);
396 ok = dlz_bind9_putnamedrr_torture_hook(expected, name, type, ttl, data);
398 return ISC_R_FAILURE;
401 return ISC_R_SUCCESS;
407 static bool test_dlz_bind9_lookup(struct torture_context *tctx)
411 const char *argv[] = {
414 test_dlz_bind9_binddns_dir(tctx, "dns/sam.ldb"),
417 struct test_expected_rr *expected1 = NULL;
418 struct test_expected_rr *expected2 = NULL;
421 torture_assert_int_equal(tctx, dlz_create("samba_dlz", 3, argv, &dbdata,
422 "log", dlz_bind9_log_wrapper,
423 "writeable_zone", dlz_bind9_writeable_zone_hook,
424 "putrr", dlz_bind9_putrr_hook,
425 "putnamedrr", dlz_bind9_putnamedrr_hook,
428 "Failed to create samba_dlz");
430 torture_assert_int_equal(tctx, dlz_configure((void*)tctx, dbdata),
432 "Failed to configure samba_dlz");
434 expected1 = talloc_zero(tctx, struct test_expected_rr);
435 torture_assert(tctx, expected1 != NULL, "talloc failed");
436 expected1->tctx = tctx;
438 expected1->query_name = "@";
440 expected1->num_records = 4;
441 expected1->records = talloc_zero_array(expected1,
442 struct test_expected_record,
443 expected1->num_records);
444 torture_assert(tctx, expected1->records != NULL, "talloc failed");
446 expected1->records[0].name = expected1->query_name;
447 expected1->records[0].type = "soa";
448 expected1->records[0].ttl = 3600;
449 expected1->records[0].data = talloc_asprintf(expected1->records,
450 "%s.%s. hostmaster.%s. 1 900 600 86400 3600",
451 torture_setting_string(tctx, "host", NULL),
452 lpcfg_dnsdomain(tctx->lp_ctx),
453 lpcfg_dnsdomain(tctx->lp_ctx));
454 torture_assert(tctx, expected1->records[0].data != NULL, "talloc failed");
456 expected1->records[1].name = expected1->query_name;
457 expected1->records[1].type = "ns";
458 expected1->records[1].ttl = 900;
459 expected1->records[1].data = talloc_asprintf(expected1->records, "%s.%s.",
460 torture_setting_string(tctx, "host", NULL),
461 lpcfg_dnsdomain(tctx->lp_ctx));
462 torture_assert(tctx, expected1->records[1].data != NULL, "talloc failed");
464 expected1->records[2].name = expected1->query_name;
465 expected1->records[2].type = "aaaa";
466 expected1->records[2].ttl = 900;
468 expected1->records[3].name = expected1->query_name;
469 expected1->records[3].type = "a";
470 expected1->records[3].ttl = 900;
472 torture_assert_int_equal(tctx, dlz_lookup(lpcfg_dnsdomain(tctx->lp_ctx),
473 expected1->query_name, dbdata,
474 (dns_sdlzlookup_t *)expected1),
476 "Failed to lookup @");
477 for (i = 0; i < expected1->num_records; i++) {
478 torture_assert(tctx, expected1->records[i].printed,
479 talloc_asprintf(tctx,
480 "Failed to have putrr callback run for type %s",
481 expected1->records[i].type));
483 torture_assert_int_equal(tctx, expected1->num_rr,
484 expected1->num_records,
485 "Got too much data");
487 expected2 = talloc_zero(tctx, struct test_expected_rr);
488 torture_assert(tctx, expected2 != NULL, "talloc failed");
489 expected2->tctx = tctx;
491 expected2->query_name = torture_setting_string(tctx, "host", NULL);
492 torture_assert(tctx, expected2->query_name != NULL, "unknown host");
494 expected2->num_records = 2;
495 expected2->records = talloc_zero_array(expected2,
496 struct test_expected_record,
497 expected2->num_records);
498 torture_assert(tctx, expected2->records != NULL, "talloc failed");
500 expected2->records[0].name = expected2->query_name;
501 expected2->records[0].type = "aaaa";
502 expected2->records[0].ttl = 900;
504 expected2->records[1].name = expected2->query_name;
505 expected2->records[1].type = "a";
506 expected2->records[1].ttl = 900;
508 torture_assert_int_equal(tctx, dlz_lookup(lpcfg_dnsdomain(tctx->lp_ctx),
509 expected2->query_name, dbdata,
510 (dns_sdlzlookup_t *)expected2),
512 "Failed to lookup hostname");
513 for (i = 0; i < expected2->num_records; i++) {
514 torture_assert(tctx, expected2->records[i].printed,
515 talloc_asprintf(tctx,
516 "Failed to have putrr callback run name[%s] for type %s",
517 expected2->records[i].name,
518 expected2->records[i].type));
520 torture_assert_int_equal(tctx, expected2->num_rr,
521 expected2->num_records,
522 "Got too much data");
530 * Test some zone dumps
532 static bool test_dlz_bind9_zonedump(struct torture_context *tctx)
536 const char *argv[] = {
539 test_dlz_bind9_binddns_dir(tctx, "dns/sam.ldb"),
542 struct test_expected_rr *expected1 = NULL;
545 torture_assert_int_equal(tctx, dlz_create("samba_dlz", 3, argv, &dbdata,
546 "log", dlz_bind9_log_wrapper,
547 "writeable_zone", dlz_bind9_writeable_zone_hook,
548 "putrr", dlz_bind9_putrr_hook,
549 "putnamedrr", dlz_bind9_putnamedrr_hook,
552 "Failed to create samba_dlz");
554 torture_assert_int_equal(tctx, dlz_configure((void*)tctx, dbdata),
556 "Failed to configure samba_dlz");
558 expected1 = talloc_zero(tctx, struct test_expected_rr);
559 torture_assert(tctx, expected1 != NULL, "talloc failed");
560 expected1->tctx = tctx;
562 expected1->num_records = 7;
563 expected1->records = talloc_zero_array(expected1,
564 struct test_expected_record,
565 expected1->num_records);
566 torture_assert(tctx, expected1->records != NULL, "talloc failed");
568 expected1->records[0].name = talloc_asprintf(expected1->records,
569 "%s.", lpcfg_dnsdomain(tctx->lp_ctx));
570 expected1->records[0].type = "soa";
571 expected1->records[0].ttl = 3600;
572 expected1->records[0].data = talloc_asprintf(expected1->records,
573 "%s.%s. hostmaster.%s. 1 900 600 86400 3600",
574 torture_setting_string(tctx, "host", NULL),
575 lpcfg_dnsdomain(tctx->lp_ctx),
576 lpcfg_dnsdomain(tctx->lp_ctx));
577 torture_assert(tctx, expected1->records[0].data != NULL, "talloc failed");
579 expected1->records[1].name = talloc_asprintf(expected1->records,
580 "%s.", lpcfg_dnsdomain(tctx->lp_ctx));
581 expected1->records[1].type = "ns";
582 expected1->records[1].ttl = 900;
583 expected1->records[1].data = talloc_asprintf(expected1->records, "%s.%s.",
584 torture_setting_string(tctx, "host", NULL),
585 lpcfg_dnsdomain(tctx->lp_ctx));
586 torture_assert(tctx, expected1->records[1].data != NULL, "talloc failed");
588 expected1->records[2].name = talloc_asprintf(expected1->records,
589 "%s.", lpcfg_dnsdomain(tctx->lp_ctx));
590 expected1->records[2].type = "aaaa";
591 expected1->records[2].ttl = 900;
593 expected1->records[3].name = talloc_asprintf(expected1->records,
594 "%s.", lpcfg_dnsdomain(tctx->lp_ctx));
595 expected1->records[3].type = "a";
596 expected1->records[3].ttl = 900;
598 expected1->records[4].name = talloc_asprintf(expected1->records, "%s.%s.",
599 torture_setting_string(tctx, "host", NULL),
600 lpcfg_dnsdomain(tctx->lp_ctx));
601 torture_assert(tctx, expected1->records[4].name != NULL, "unknown host");
602 expected1->records[4].type = "aaaa";
603 expected1->records[4].ttl = 900;
605 expected1->records[5].name = talloc_asprintf(expected1->records, "%s.%s.",
606 torture_setting_string(tctx, "host", NULL),
607 lpcfg_dnsdomain(tctx->lp_ctx));
608 torture_assert(tctx, expected1->records[5].name != NULL, "unknown host");
609 expected1->records[5].type = "a";
610 expected1->records[5].ttl = 900;
613 * We expect multiple srv records
615 expected1->records[6].name = NULL;
616 expected1->records[6].type = "srv";
617 expected1->records[6].ttl = 900;
619 torture_assert_int_equal(tctx, dlz_allnodes(lpcfg_dnsdomain(tctx->lp_ctx),
620 dbdata, (dns_sdlzallnodes_t *)expected1),
622 "Failed to configure samba_dlz");
623 for (i = 0; i < expected1->num_records; i++) {
624 torture_assert(tctx, expected1->records[i].printed,
625 talloc_asprintf(tctx,
626 "Failed to have putrr callback run name[%s] for type %s",
627 expected1->records[i].name,
628 expected1->records[i].type));
630 torture_assert_int_equal(tctx, expected1->num_rr, 24,
631 "Got wrong record count");
641 static bool test_dlz_bind9_update01(struct torture_context *tctx)
644 struct gensec_security *gensec_client_context;
645 DATA_BLOB client_to_server, server_to_client;
647 void *version = NULL;
648 const char *argv[] = {
651 test_dlz_bind9_binddns_dir(tctx, "dns/sam.ldb"),
654 struct test_expected_rr *expected1 = NULL;
662 torture_assert_int_equal(tctx, dlz_create("samba_dlz", 3, argv, &dbdata,
663 "log", dlz_bind9_log_wrapper,
664 "writeable_zone", dlz_bind9_writeable_zone_hook,
665 "putrr", dlz_bind9_putrr_hook,
666 "putnamedrr", dlz_bind9_putnamedrr_hook,
669 "Failed to create samba_dlz");
671 torture_assert_int_equal(tctx, dlz_configure((void*)tctx, dbdata),
673 "Failed to configure samba_dlz");
675 expected1 = talloc_zero(tctx, struct test_expected_rr);
676 torture_assert(tctx, expected1 != NULL, "talloc failed");
677 expected1->tctx = tctx;
679 expected1->query_name = __func__;
681 name = talloc_asprintf(expected1, "%s.%s",
682 expected1->query_name,
683 lpcfg_dnsdomain(tctx->lp_ctx));
684 torture_assert(tctx, name != NULL, "talloc failed");
686 expected1->num_records = 2;
687 expected1->records = talloc_zero_array(expected1,
688 struct test_expected_record,
689 expected1->num_records);
690 torture_assert(tctx, expected1->records != NULL, "talloc failed");
692 expected1->records[0].name = expected1->query_name;
693 expected1->records[0].type = "a";
694 expected1->records[0].ttl = 3600;
695 expected1->records[0].data = "127.1.2.3";
696 expected1->records[0].printed = false;
698 data0 = talloc_asprintf(expected1,
699 "%s.\t" "%u\t" "%s\t" "%s\t" "%s",
701 (unsigned)expected1->records[0].ttl,
703 expected1->records[0].type,
704 expected1->records[0].data);
705 torture_assert(tctx, data0 != NULL, "talloc failed");
707 expected1->records[1].name = expected1->query_name;
708 expected1->records[1].type = "a";
709 expected1->records[1].ttl = 3600;
710 expected1->records[1].data = "127.3.2.1";
711 expected1->records[1].printed = false;
713 data1 = talloc_asprintf(expected1,
714 "%s.\t" "%u\t" "%s\t" "%s\t" "%s",
716 (unsigned)expected1->records[1].ttl,
718 expected1->records[1].type,
719 expected1->records[1].data);
720 torture_assert(tctx, data1 != NULL, "talloc failed");
722 data2 = talloc_asprintf(expected1,
723 "%s.\t" "0\t" "in\t" "a\t" "127.3.3.3",
725 torture_assert(tctx, data2 != NULL, "talloc failed");
728 * Prepare session info
730 status = gensec_client_start(tctx, &gensec_client_context,
731 lpcfg_gensec_settings(tctx, tctx->lp_ctx));
732 torture_assert_ntstatus_ok(tctx, status, "gensec_client_start (client) failed");
735 * dlz_bind9 use the special dns/host.domain account
737 status = gensec_set_target_hostname(gensec_client_context,
738 talloc_asprintf(tctx,
740 torture_setting_string(tctx, "host", NULL),
741 lpcfg_dnsdomain(tctx->lp_ctx)));
742 torture_assert_ntstatus_ok(tctx, status, "gensec_set_target_hostname (client) failed");
744 status = gensec_set_target_service(gensec_client_context, "dns");
745 torture_assert_ntstatus_ok(tctx, status, "gensec_set_target_service failed");
747 status = gensec_set_credentials(gensec_client_context,
748 popt_get_cmdline_credentials());
749 torture_assert_ntstatus_ok(tctx, status, "gensec_set_credentials (client) failed");
751 status = gensec_start_mech_by_sasl_name(gensec_client_context, "GSS-SPNEGO");
752 torture_assert_ntstatus_ok(tctx, status, "gensec_start_mech_by_sasl_name (client) failed");
754 server_to_client = data_blob(NULL, 0);
756 /* Do one step of the client-server update dance */
757 status = gensec_update(gensec_client_context, tctx, server_to_client, &client_to_server);
758 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {;
759 torture_assert_ntstatus_ok(tctx, status, "gensec_update (client) failed");
762 torture_assert_int_equal(tctx, dlz_ssumatch(
763 cli_credentials_get_username(
764 popt_get_cmdline_credentials()),
767 expected1->records[0].type,
769 client_to_server.length,
770 client_to_server.data,
773 "Failed to check key for update rights samba_dlz");
776 * We test the following:
778 * 1. lookup the records => NOT_FOUND
779 * 2. delete all records => NOT_FOUND
780 * 3. delete 1st record => NOT_FOUND
781 * 4. create 1st record => SUCCESS
782 * 5. lookup the records => found 1st
783 * 6. create 2nd record => SUCCESS
784 * 7. lookup the records => found 1st and 2nd
785 * 8. delete unknown record => NOT_FOUND
786 * 9. lookup the records => found 1st and 2nd
787 * 10. delete 1st record => SUCCESS
788 * 11. lookup the records => found 2nd
789 * 12. delete 2nd record => SUCCESS
790 * 13. lookup the records => NOT_FOUND
791 * 14. create 1st record => SUCCESS
792 * 15. lookup the records => found 1st
793 * 16. create 2nd record => SUCCESS
794 * 17. lookup the records => found 1st and 2nd
795 * 18. update 1st record => SUCCESS
796 * 19. lookup the records => found 1st and 2nd
797 * 20. delete all unknown type records => NOT_FOUND
798 * 21. lookup the records => found 1st and 2nd
799 * 22. delete all records => SUCCESS
800 * 23. lookup the records => NOT_FOUND
804 expected1->num_rr = 0;
805 expected1->records[0].printed = false;
806 expected1->records[1].printed = false;
807 torture_assert_int_equal(tctx, dlz_lookup(lpcfg_dnsdomain(tctx->lp_ctx),
808 expected1->query_name, dbdata,
809 (dns_sdlzlookup_t *)expected1),
812 torture_assert_int_equal(tctx, expected1->num_rr, 0,
813 "Got wrong record count");
816 torture_assert_int_equal(tctx, dlz_newversion(lpcfg_dnsdomain(tctx->lp_ctx),
819 "Failed to start transaction");
820 torture_assert_int_equal_goto(tctx,
821 dlz_delrdataset(name,
822 expected1->records[0].type,
824 ISC_R_NOTFOUND, ret, cancel_version,
825 talloc_asprintf(tctx, "Deleted name[%s] type[%s]\n",
826 name, expected1->records[0].type));
827 dlz_closeversion(lpcfg_dnsdomain(tctx->lp_ctx), false, dbdata, &version);
830 torture_assert_int_equal(tctx, dlz_newversion(lpcfg_dnsdomain(tctx->lp_ctx),
833 "Failed to start transaction");
834 torture_assert_int_equal_goto(tctx,
835 dlz_subrdataset(name, data0, dbdata, version),
836 ISC_R_NOTFOUND, ret, cancel_version,
837 talloc_asprintf(tctx, "Deleted name[%s] data[%s]\n",
839 dlz_closeversion(lpcfg_dnsdomain(tctx->lp_ctx), false, dbdata, &version);
842 torture_assert_int_equal(tctx, dlz_newversion(lpcfg_dnsdomain(tctx->lp_ctx),
845 "Failed to start transaction");
846 torture_assert_int_equal_goto(tctx,
847 dlz_addrdataset(name, data0, dbdata, version),
848 ISC_R_SUCCESS, ret, cancel_version,
849 talloc_asprintf(tctx, "Failed to add name[%s] data[%s]\n",
851 dlz_closeversion(lpcfg_dnsdomain(tctx->lp_ctx), true, dbdata, &version);
854 expected1->num_rr = 0;
855 expected1->records[0].printed = false;
856 expected1->records[1].printed = false;
857 torture_assert_int_equal(tctx, dlz_lookup(lpcfg_dnsdomain(tctx->lp_ctx),
858 expected1->query_name, dbdata,
859 (dns_sdlzlookup_t *)expected1),
861 "Not found hostname");
862 torture_assert(tctx, expected1->records[0].printed,
863 talloc_asprintf(tctx,
864 "Failed to have putrr callback run name[%s] for type %s",
865 expected1->records[0].name,
866 expected1->records[0].type));
867 torture_assert_int_equal(tctx, expected1->num_rr, 1,
868 "Got wrong record count");
871 torture_assert_int_equal(tctx, dlz_newversion(lpcfg_dnsdomain(tctx->lp_ctx),
874 "Failed to start transaction");
875 torture_assert_int_equal_goto(tctx,
876 dlz_addrdataset(name, data1, dbdata, version),
877 ISC_R_SUCCESS, ret, cancel_version,
878 talloc_asprintf(tctx, "Failed to add name[%s] data[%s]\n",
880 dlz_closeversion(lpcfg_dnsdomain(tctx->lp_ctx), true, dbdata, &version);
883 expected1->num_rr = 0;
884 expected1->records[0].printed = false;
885 expected1->records[1].printed = false;
886 torture_assert_int_equal(tctx, dlz_lookup(lpcfg_dnsdomain(tctx->lp_ctx),
887 expected1->query_name, dbdata,
888 (dns_sdlzlookup_t *)expected1),
890 "Not found hostname");
891 torture_assert(tctx, expected1->records[0].printed,
892 talloc_asprintf(tctx,
893 "Failed to have putrr callback run name[%s] for type %s",
894 expected1->records[0].name,
895 expected1->records[0].type));
896 torture_assert(tctx, expected1->records[1].printed,
897 talloc_asprintf(tctx,
898 "Failed to have putrr callback run name[%s] for type %s",
899 expected1->records[1].name,
900 expected1->records[1].type));
901 torture_assert_int_equal(tctx, expected1->num_rr, 2,
902 "Got wrong record count");
905 torture_assert_int_equal(tctx, dlz_newversion(lpcfg_dnsdomain(tctx->lp_ctx),
908 "Failed to start transaction");
909 torture_assert_int_equal_goto(tctx,
910 dlz_subrdataset(name, data2, dbdata, version),
911 ISC_R_NOTFOUND, ret, cancel_version,
912 talloc_asprintf(tctx, "Deleted name[%s] data[%s]\n",
914 dlz_closeversion(lpcfg_dnsdomain(tctx->lp_ctx), true, dbdata, &version);
917 expected1->num_rr = 0;
918 expected1->records[0].printed = false;
919 expected1->records[1].printed = false;
920 torture_assert_int_equal(tctx, dlz_lookup(lpcfg_dnsdomain(tctx->lp_ctx),
921 expected1->query_name, dbdata,
922 (dns_sdlzlookup_t *)expected1),
924 "Not found hostname");
925 torture_assert(tctx, expected1->records[0].printed,
926 talloc_asprintf(tctx,
927 "Failed to have putrr callback run name[%s] for type %s",
928 expected1->records[0].name,
929 expected1->records[0].type));
930 torture_assert(tctx, expected1->records[1].printed,
931 talloc_asprintf(tctx,
932 "Failed to have putrr callback run name[%s] for type %s",
933 expected1->records[1].name,
934 expected1->records[1].type));
935 torture_assert_int_equal(tctx, expected1->num_rr, 2,
936 "Got wrong record count");
939 torture_assert_int_equal(tctx, dlz_newversion(lpcfg_dnsdomain(tctx->lp_ctx),
942 "Failed to start transaction");
943 torture_assert_int_equal_goto(tctx,
944 dlz_subrdataset(name, data0, dbdata, version),
945 ISC_R_SUCCESS, ret, cancel_version,
946 talloc_asprintf(tctx, "Failed to delete name[%s] data[%s]\n",
948 dlz_closeversion(lpcfg_dnsdomain(tctx->lp_ctx), true, dbdata, &version);
951 expected1->num_rr = 0;
952 expected1->records[0].printed = false;
953 expected1->records[1].printed = false;
954 torture_assert_int_equal(tctx, dlz_lookup(lpcfg_dnsdomain(tctx->lp_ctx),
955 expected1->query_name, dbdata,
956 (dns_sdlzlookup_t *)expected1),
958 "Not found hostname");
959 torture_assert(tctx, expected1->records[1].printed,
960 talloc_asprintf(tctx,
961 "Failed to have putrr callback run name[%s] for type %s",
962 expected1->records[1].name,
963 expected1->records[1].type));
964 torture_assert_int_equal(tctx, expected1->num_rr, 1,
965 "Got wrong record count");
968 torture_assert_int_equal(tctx, dlz_newversion(lpcfg_dnsdomain(tctx->lp_ctx),
971 "Failed to start transaction");
972 torture_assert_int_equal_goto(tctx,
973 dlz_subrdataset(name, data1, dbdata, version),
974 ISC_R_SUCCESS, ret, cancel_version,
975 talloc_asprintf(tctx, "Failed to delete name[%s] data[%s]\n",
977 dlz_closeversion(lpcfg_dnsdomain(tctx->lp_ctx), true, dbdata, &version);
980 expected1->num_rr = 0;
981 expected1->records[0].printed = false;
982 expected1->records[1].printed = false;
983 torture_assert_int_equal(tctx, dlz_lookup(lpcfg_dnsdomain(tctx->lp_ctx),
984 expected1->query_name, dbdata,
985 (dns_sdlzlookup_t *)expected1),
988 torture_assert_int_equal(tctx, expected1->num_rr, 0,
989 "Got wrong record count");
992 torture_assert_int_equal(tctx, dlz_newversion(lpcfg_dnsdomain(tctx->lp_ctx),
995 "Failed to start transaction");
996 torture_assert_int_equal_goto(tctx,
997 dlz_addrdataset(name, data0, dbdata, version),
998 ISC_R_SUCCESS, ret, cancel_version,
999 talloc_asprintf(tctx, "Failed to add name[%s] data[%s]\n",
1001 dlz_closeversion(lpcfg_dnsdomain(tctx->lp_ctx), true, dbdata, &version);
1004 expected1->num_rr = 0;
1005 expected1->records[0].printed = false;
1006 expected1->records[1].printed = false;
1007 torture_assert_int_equal(tctx, dlz_lookup(lpcfg_dnsdomain(tctx->lp_ctx),
1008 expected1->query_name, dbdata,
1009 (dns_sdlzlookup_t *)expected1),
1011 "Not found hostname");
1012 torture_assert(tctx, expected1->records[0].printed,
1013 talloc_asprintf(tctx,
1014 "Failed to have putrr callback run name[%s] for type %s",
1015 expected1->records[0].name,
1016 expected1->records[0].type));
1017 torture_assert_int_equal(tctx, expected1->num_rr, 1,
1018 "Got wrong record count");
1021 torture_assert_int_equal(tctx, dlz_newversion(lpcfg_dnsdomain(tctx->lp_ctx),
1024 "Failed to start transaction");
1025 torture_assert_int_equal_goto(tctx,
1026 dlz_addrdataset(name, data1, dbdata, version),
1027 ISC_R_SUCCESS, ret, cancel_version,
1028 talloc_asprintf(tctx, "Failed to add name[%s] data[%s]\n",
1030 dlz_closeversion(lpcfg_dnsdomain(tctx->lp_ctx), true, dbdata, &version);
1033 expected1->num_rr = 0;
1034 expected1->records[0].printed = false;
1035 expected1->records[1].printed = false;
1036 torture_assert_int_equal(tctx, dlz_lookup(lpcfg_dnsdomain(tctx->lp_ctx),
1037 expected1->query_name, dbdata,
1038 (dns_sdlzlookup_t *)expected1),
1040 "Not found hostname");
1041 torture_assert(tctx, expected1->records[0].printed,
1042 talloc_asprintf(tctx,
1043 "Failed to have putrr callback run name[%s] for type %s",
1044 expected1->records[0].name,
1045 expected1->records[0].type));
1046 torture_assert(tctx, expected1->records[1].printed,
1047 talloc_asprintf(tctx,
1048 "Failed to have putrr callback run name[%s] for type %s",
1049 expected1->records[1].name,
1050 expected1->records[1].type));
1051 torture_assert_int_equal(tctx, expected1->num_rr, 2,
1052 "Got wrong record count");
1055 torture_assert_int_equal(tctx, dlz_newversion(lpcfg_dnsdomain(tctx->lp_ctx),
1058 "Failed to start transaction");
1059 torture_assert_int_equal_goto(tctx,
1060 dlz_addrdataset(name, data0, dbdata, version),
1061 ISC_R_SUCCESS, ret, cancel_version,
1062 talloc_asprintf(tctx, "Failed to update name[%s] data[%s]\n",
1064 dlz_closeversion(lpcfg_dnsdomain(tctx->lp_ctx), true, dbdata, &version);
1067 expected1->num_rr = 0;
1068 expected1->records[0].printed = false;
1069 expected1->records[1].printed = false;
1070 torture_assert_int_equal(tctx, dlz_lookup(lpcfg_dnsdomain(tctx->lp_ctx),
1071 expected1->query_name, dbdata,
1072 (dns_sdlzlookup_t *)expected1),
1074 "Not found hostname");
1075 torture_assert(tctx, expected1->records[0].printed,
1076 talloc_asprintf(tctx,
1077 "Failed to have putrr callback run name[%s] for type %s",
1078 expected1->records[0].name,
1079 expected1->records[0].type));
1080 torture_assert(tctx, expected1->records[1].printed,
1081 talloc_asprintf(tctx,
1082 "Failed to have putrr callback run name[%s] for type %s",
1083 expected1->records[1].name,
1084 expected1->records[1].type));
1085 torture_assert_int_equal(tctx, expected1->num_rr, 2,
1086 "Got wrong record count");
1089 torture_assert_int_equal(tctx, dlz_newversion(lpcfg_dnsdomain(tctx->lp_ctx),
1092 "Failed to start transaction");
1093 torture_assert_int_equal_goto(tctx,
1094 dlz_delrdataset(name, "txt", dbdata, version),
1095 ISC_R_FAILURE, ret, cancel_version,
1096 talloc_asprintf(tctx, "Deleted name[%s] type[%s]\n",
1098 dlz_closeversion(lpcfg_dnsdomain(tctx->lp_ctx), false, dbdata, &version);
1101 expected1->num_rr = 0;
1102 expected1->records[0].printed = false;
1103 expected1->records[1].printed = false;
1104 torture_assert_int_equal(tctx, dlz_lookup(lpcfg_dnsdomain(tctx->lp_ctx),
1105 expected1->query_name, dbdata,
1106 (dns_sdlzlookup_t *)expected1),
1108 "Not found hostname");
1109 torture_assert(tctx, expected1->records[0].printed,
1110 talloc_asprintf(tctx,
1111 "Failed to have putrr callback run name[%s] for type %s",
1112 expected1->records[0].name,
1113 expected1->records[0].type));
1114 torture_assert(tctx, expected1->records[1].printed,
1115 talloc_asprintf(tctx,
1116 "Failed to have putrr callback run name[%s] for type %s",
1117 expected1->records[1].name,
1118 expected1->records[1].type));
1119 torture_assert_int_equal(tctx, expected1->num_rr, 2,
1120 "Got wrong record count");
1123 torture_assert_int_equal(tctx, dlz_newversion(lpcfg_dnsdomain(tctx->lp_ctx),
1126 "Failed to start transaction");
1127 torture_assert_int_equal_goto(tctx,
1128 dlz_delrdataset(name,
1129 expected1->records[0].type,
1131 ISC_R_SUCCESS, ret, cancel_version,
1132 talloc_asprintf(tctx, "Failed to delete name[%s] type[%s]\n",
1133 name, expected1->records[0].type));
1134 dlz_closeversion(lpcfg_dnsdomain(tctx->lp_ctx), true, dbdata, &version);
1137 expected1->num_rr = 0;
1138 expected1->records[0].printed = false;
1139 expected1->records[1].printed = false;
1140 torture_assert_int_equal(tctx, dlz_lookup(lpcfg_dnsdomain(tctx->lp_ctx),
1141 expected1->query_name, dbdata,
1142 (dns_sdlzlookup_t *)expected1),
1145 torture_assert_int_equal(tctx, expected1->num_rr, 0,
1146 "Got wrong record count");
1148 dlz_destroy(dbdata);
1153 dlz_closeversion(lpcfg_dnsdomain(tctx->lp_ctx), false, dbdata, &version);
1157 static struct torture_suite *dlz_bind9_suite(TALLOC_CTX *ctx)
1159 struct torture_suite *suite = torture_suite_create(ctx, "dlz_bind9");
1161 suite->description = talloc_strdup(suite,
1162 "Tests for the BIND 9 DLZ module");
1163 torture_suite_add_simple_test(suite, "version", test_dlz_bind9_version);
1164 torture_suite_add_simple_test(suite, "create", test_dlz_bind9_create);
1165 torture_suite_add_simple_test(suite, "configure", test_dlz_bind9_configure);
1166 torture_suite_add_simple_test(suite, "destroyoldestfirst",
1167 test_dlz_bind9_destroy_oldest_first);
1168 torture_suite_add_simple_test(suite, "destroynewestfirst",
1169 test_dlz_bind9_destroy_newest_first);
1170 torture_suite_add_simple_test(suite, "multipleconfigure",
1171 test_dlz_bind9_multiple_configure);
1173 torture_suite_add_simple_test(suite, "gssapi", test_dlz_bind9_gssapi);
1174 torture_suite_add_simple_test(suite, "spnego", test_dlz_bind9_spnego);
1175 torture_suite_add_simple_test(suite, "lookup", test_dlz_bind9_lookup);
1176 torture_suite_add_simple_test(suite, "zonedump", test_dlz_bind9_zonedump);
1177 torture_suite_add_simple_test(suite, "update01", test_dlz_bind9_update01);
1182 * DNS torture module initialization
1184 NTSTATUS torture_bind_dns_init(TALLOC_CTX *);
1185 NTSTATUS torture_bind_dns_init(TALLOC_CTX *ctx)
1187 struct torture_suite *suite;
1189 /* register DNS related test cases */
1190 suite = dlz_bind9_suite(ctx);
1191 if (!suite) return NT_STATUS_NO_MEMORY;
1192 torture_register_suite(ctx, suite);
1194 return NT_STATUS_OK;