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, ...)
40 msg = talloc_vasprintf(NULL, fmt, ap);
41 torture_comment(tctx_static, "%s\n", msg);
46 static bool test_dlz_bind9_version(struct torture_context *tctx)
48 unsigned int flags = 0;
49 torture_assert_int_equal(tctx, dlz_version(&flags),
50 DLZ_DLOPEN_VERSION, "got wrong DLZ version");
54 static bool test_dlz_bind9_create(struct torture_context *tctx)
57 const char *argv[] = {
60 lpcfg_private_path(tctx, tctx->lp_ctx, "dns/sam.ldb"),
64 torture_assert_int_equal(tctx, dlz_create("samba_dlz", 3, argv, &dbdata,
65 "log", dlz_bind9_log_wrapper, NULL), ISC_R_SUCCESS,
66 "Failed to create samba_dlz");
73 static isc_result_t dlz_bind9_writeable_zone_hook(dns_view_t *view,
74 const char *zone_name)
76 struct torture_context *tctx = talloc_get_type((void *)view, struct torture_context);
77 struct ldb_context *samdb = samdb_connect_url(tctx, NULL, tctx->lp_ctx,
78 system_session(tctx->lp_ctx),
79 0, lpcfg_private_path(tctx, tctx->lp_ctx, "dns/sam.ldb"));
80 struct ldb_message *msg;
82 const char *attrs[] = {
86 torture_fail(tctx, "Failed to connect to samdb");
90 ret = dsdb_search_one(samdb, tctx, &msg, NULL,
91 LDB_SCOPE_SUBTREE, attrs, DSDB_SEARCH_SEARCH_ALL_PARTITIONS,
92 "(&(objectClass=dnsZone)(name=%s))", zone_name);
93 if (ret != LDB_SUCCESS) {
94 torture_fail(tctx, talloc_asprintf(tctx, "Failed to search for %s: %s", zone_name, ldb_errstring(samdb)));
102 static bool test_dlz_bind9_configure(struct torture_context *tctx)
105 const char *argv[] = {
108 lpcfg_private_path(tctx, tctx->lp_ctx, "dns/sam.ldb"),
112 torture_assert_int_equal(tctx, dlz_create("samba_dlz", 3, argv, &dbdata,
113 "log", dlz_bind9_log_wrapper,
114 "writeable_zone", dlz_bind9_writeable_zone_hook, NULL),
116 "Failed to create samba_dlz");
118 torture_assert_int_equal(tctx, dlz_configure((void*)tctx, dbdata),
120 "Failed to configure samba_dlz");
128 * Test that a ticket obtained for the DNS service will be accepted on the Samba DLZ side
131 static bool test_dlz_bind9_gensec(struct torture_context *tctx, const char *mech)
135 struct gensec_security *gensec_client_context;
137 DATA_BLOB client_to_server, server_to_client;
140 const char *argv[] = {
143 lpcfg_private_path(tctx, tctx->lp_ctx, "dns/sam.ldb"),
147 torture_assert_int_equal(tctx, dlz_create("samba_dlz", 3, argv, &dbdata,
148 "log", dlz_bind9_log_wrapper,
149 "writeable_zone", dlz_bind9_writeable_zone_hook, NULL),
151 "Failed to create samba_dlz");
153 torture_assert_int_equal(tctx, dlz_configure((void*)tctx, dbdata),
155 "Failed to configure samba_dlz");
157 status = gensec_client_start(tctx, &gensec_client_context,
158 lpcfg_gensec_settings(tctx, tctx->lp_ctx));
159 torture_assert_ntstatus_ok(tctx, status, "gensec_client_start (client) failed");
162 * dlz_bind9 use the special dns/host.domain account
164 status = gensec_set_target_hostname(gensec_client_context,
165 talloc_asprintf(tctx,
167 torture_setting_string(tctx, "host", NULL),
168 lpcfg_dnsdomain(tctx->lp_ctx)));
169 torture_assert_ntstatus_ok(tctx, status, "gensec_set_target_hostname (client) failed");
171 status = gensec_set_target_service(gensec_client_context, "dns");
172 torture_assert_ntstatus_ok(tctx, status, "gensec_set_target_service failed");
174 status = gensec_set_credentials(gensec_client_context, cmdline_credentials);
175 torture_assert_ntstatus_ok(tctx, status, "gensec_set_credentials (client) failed");
177 status = gensec_start_mech_by_sasl_name(gensec_client_context, mech);
178 torture_assert_ntstatus_ok(tctx, status, "gensec_start_mech_by_sasl_name (client) failed");
180 server_to_client = data_blob(NULL, 0);
182 /* Do one step of the client-server update dance */
183 status = gensec_update(gensec_client_context, tctx, server_to_client, &client_to_server);
184 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {;
185 torture_assert_ntstatus_ok(tctx, status, "gensec_update (client) failed");
188 torture_assert_int_equal(tctx, dlz_ssumatch(cli_credentials_get_username(cmdline_credentials),
189 lpcfg_dnsdomain(tctx->lp_ctx),
190 "127.0.0.1", "type", "key",
191 client_to_server.length,
192 client_to_server.data,
195 "Failed to check key for update rights samba_dlz");
202 static bool test_dlz_bind9_gssapi(struct torture_context *tctx)
204 return test_dlz_bind9_gensec(tctx, "GSSAPI");
207 static bool test_dlz_bind9_spnego(struct torture_context *tctx)
209 return test_dlz_bind9_gensec(tctx, "GSS-SPNEGO");
212 struct test_expected_record {
220 struct test_expected_rr {
221 struct torture_context *tctx;
222 const char *query_name;
224 struct test_expected_record *records;
228 static bool dlz_bind9_putnamedrr_torture_hook(struct test_expected_rr *expected,
236 torture_assert(expected->tctx, name != NULL,
237 talloc_asprintf(expected->tctx,
238 "Got unnamed record type[%s] data[%s]\n",
242 torture_comment(expected->tctx, "%u: name[%s] type[%s] ttl[%u] data[%s]\n",
243 (unsigned)expected->num_rr, name, type, (unsigned)ttl, data);
245 for (i = 0; i < expected->num_records; i++) {
246 if (expected->records[i].name != NULL) {
247 if (strcmp(name, expected->records[i].name) != 0) {
252 if (strcmp(type, expected->records[i].type) != 0) {
256 if (expected->records[i].data != NULL) {
257 if (strcmp(data, expected->records[i].data) != 0) {
262 torture_assert_int_equal(expected->tctx, ttl,
263 expected->records[i].ttl,
264 talloc_asprintf(expected->tctx,
265 "TTL did not match expectations for type %s",
268 expected->records[i].printed = true;
274 static isc_result_t dlz_bind9_putrr_hook(dns_sdlzlookup_t *lookup,
279 struct test_expected_rr *expected =
280 talloc_get_type_abort(lookup, struct test_expected_rr);
283 ok = dlz_bind9_putnamedrr_torture_hook(expected, expected->query_name,
286 return ISC_R_FAILURE;
289 return ISC_R_SUCCESS;
292 static isc_result_t dlz_bind9_putnamedrr_hook(dns_sdlzallnodes_t *allnodes,
298 struct test_expected_rr *expected =
299 talloc_get_type_abort(allnodes, struct test_expected_rr);
302 ok = dlz_bind9_putnamedrr_torture_hook(expected, name, type, ttl, data);
304 return ISC_R_FAILURE;
307 return ISC_R_SUCCESS;
313 static bool test_dlz_bind9_lookup(struct torture_context *tctx)
317 const char *argv[] = {
320 lpcfg_private_path(tctx, tctx->lp_ctx, "dns/sam.ldb"),
323 struct test_expected_rr *expected1 = NULL;
324 struct test_expected_rr *expected2 = NULL;
327 torture_assert_int_equal(tctx, dlz_create("samba_dlz", 3, argv, &dbdata,
328 "log", dlz_bind9_log_wrapper,
329 "writeable_zone", dlz_bind9_writeable_zone_hook,
330 "putrr", dlz_bind9_putrr_hook,
331 "putnamedrr", dlz_bind9_putnamedrr_hook,
334 "Failed to create samba_dlz");
336 torture_assert_int_equal(tctx, dlz_configure((void*)tctx, dbdata),
338 "Failed to configure samba_dlz");
340 expected1 = talloc_zero(tctx, struct test_expected_rr);
341 torture_assert(tctx, expected1 != NULL, "talloc failed");
342 expected1->tctx = tctx;
344 expected1->query_name = "@";
346 expected1->num_records = 4;
347 expected1->records = talloc_zero_array(expected1,
348 struct test_expected_record,
349 expected1->num_records);
350 torture_assert(tctx, expected1->records != NULL, "talloc failed");
352 expected1->records[0].name = expected1->query_name;
353 expected1->records[0].type = "soa";
354 expected1->records[0].ttl = 3600;
355 expected1->records[0].data = talloc_asprintf(expected1->records,
356 "%s.%s hostmaster.%s 1 900 600 86400 3600",
357 torture_setting_string(tctx, "host", NULL),
358 lpcfg_dnsdomain(tctx->lp_ctx),
359 lpcfg_dnsdomain(tctx->lp_ctx));
360 torture_assert(tctx, expected1->records[0].data != NULL, "talloc failed");
362 expected1->records[1].name = expected1->query_name;
363 expected1->records[1].type = "ns";
364 expected1->records[1].ttl = 900;
365 expected1->records[1].data = talloc_asprintf(expected1->records, "%s.%s",
366 torture_setting_string(tctx, "host", NULL),
367 lpcfg_dnsdomain(tctx->lp_ctx));
368 torture_assert(tctx, expected1->records[1].data != NULL, "talloc failed");
370 expected1->records[2].name = expected1->query_name;
371 expected1->records[2].type = "aaaa";
372 expected1->records[2].ttl = 900;
374 expected1->records[3].name = expected1->query_name;
375 expected1->records[3].type = "a";
376 expected1->records[3].ttl = 900;
378 torture_assert_int_equal(tctx, dlz_lookup(lpcfg_dnsdomain(tctx->lp_ctx),
379 expected1->query_name, dbdata,
380 (dns_sdlzlookup_t *)expected1),
382 "Failed to lookup @");
383 for (i = 0; i < expected1->num_records; i++) {
384 torture_assert(tctx, expected1->records[i].printed,
385 talloc_asprintf(tctx,
386 "Failed to have putrr callback run for type %s",
387 expected1->records[i].type));
389 torture_assert_int_equal(tctx, expected1->num_rr,
390 expected1->num_records,
391 "Got too much data");
393 expected2 = talloc_zero(tctx, struct test_expected_rr);
394 torture_assert(tctx, expected2 != NULL, "talloc failed");
395 expected2->tctx = tctx;
397 expected2->query_name = torture_setting_string(tctx, "host", NULL);
398 torture_assert(tctx, expected2->query_name != NULL, "unknown host");
400 expected2->num_records = 2;
401 expected2->records = talloc_zero_array(expected2,
402 struct test_expected_record,
403 expected2->num_records);
404 torture_assert(tctx, expected2->records != NULL, "talloc failed");
406 expected2->records[0].name = expected2->query_name;
407 expected2->records[0].type = "aaaa";
408 expected2->records[0].ttl = 900;
410 expected2->records[1].name = expected2->query_name;
411 expected2->records[1].type = "a";
412 expected2->records[1].ttl = 900;
414 torture_assert_int_equal(tctx, dlz_lookup(lpcfg_dnsdomain(tctx->lp_ctx),
415 expected2->query_name, dbdata,
416 (dns_sdlzlookup_t *)expected2),
418 "Failed to lookup hostname");
419 for (i = 0; i < expected2->num_records; i++) {
420 torture_assert(tctx, expected2->records[i].printed,
421 talloc_asprintf(tctx,
422 "Failed to have putrr callback run name[%s] for type %s",
423 expected2->records[i].name,
424 expected2->records[i].type));
426 torture_assert_int_equal(tctx, expected2->num_rr,
427 expected2->num_records,
428 "Got too much data");
436 * Test some zone dumps
438 static bool test_dlz_bind9_zonedump(struct torture_context *tctx)
442 const char *argv[] = {
445 lpcfg_private_path(tctx, tctx->lp_ctx, "dns/sam.ldb"),
448 struct test_expected_rr *expected1 = NULL;
451 torture_assert_int_equal(tctx, dlz_create("samba_dlz", 3, argv, &dbdata,
452 "log", dlz_bind9_log_wrapper,
453 "writeable_zone", dlz_bind9_writeable_zone_hook,
454 "putrr", dlz_bind9_putrr_hook,
455 "putnamedrr", dlz_bind9_putnamedrr_hook,
458 "Failed to create samba_dlz");
460 torture_assert_int_equal(tctx, dlz_configure((void*)tctx, dbdata),
462 "Failed to configure samba_dlz");
464 expected1 = talloc_zero(tctx, struct test_expected_rr);
465 torture_assert(tctx, expected1 != NULL, "talloc failed");
466 expected1->tctx = tctx;
468 expected1->num_records = 7;
469 expected1->records = talloc_zero_array(expected1,
470 struct test_expected_record,
471 expected1->num_records);
472 torture_assert(tctx, expected1->records != NULL, "talloc failed");
474 expected1->records[0].name = lpcfg_dnsdomain(tctx->lp_ctx);
475 expected1->records[0].type = "soa";
476 expected1->records[0].ttl = 3600;
477 expected1->records[0].data = talloc_asprintf(expected1->records,
478 "%s.%s hostmaster.%s 1 900 600 86400 3600",
479 torture_setting_string(tctx, "host", NULL),
480 lpcfg_dnsdomain(tctx->lp_ctx),
481 lpcfg_dnsdomain(tctx->lp_ctx));
482 torture_assert(tctx, expected1->records[0].data != NULL, "talloc failed");
484 expected1->records[1].name = lpcfg_dnsdomain(tctx->lp_ctx);
485 expected1->records[1].type = "ns";
486 expected1->records[1].ttl = 900;
487 expected1->records[1].data = talloc_asprintf(expected1->records, "%s.%s",
488 torture_setting_string(tctx, "host", NULL),
489 lpcfg_dnsdomain(tctx->lp_ctx));
490 torture_assert(tctx, expected1->records[1].data != NULL, "talloc failed");
492 expected1->records[2].name = lpcfg_dnsdomain(tctx->lp_ctx);
493 expected1->records[2].type = "aaaa";
494 expected1->records[2].ttl = 900;
496 expected1->records[3].name = lpcfg_dnsdomain(tctx->lp_ctx);
497 expected1->records[3].type = "a";
498 expected1->records[3].ttl = 900;
500 expected1->records[4].name = talloc_asprintf(expected1->records, "%s.%s",
501 torture_setting_string(tctx, "host", NULL),
502 lpcfg_dnsdomain(tctx->lp_ctx));
503 torture_assert(tctx, expected1->records[4].name != NULL, "unknown host");
504 expected1->records[4].type = "aaaa";
505 expected1->records[4].ttl = 900;
507 expected1->records[5].name = talloc_asprintf(expected1->records, "%s.%s",
508 torture_setting_string(tctx, "host", NULL),
509 lpcfg_dnsdomain(tctx->lp_ctx));
510 torture_assert(tctx, expected1->records[5].name != NULL, "unknown host");
511 expected1->records[5].type = "a";
512 expected1->records[5].ttl = 900;
515 * We expect multiple srv records
517 expected1->records[6].name = NULL;
518 expected1->records[6].type = "srv";
519 expected1->records[6].ttl = 900;
521 torture_assert_int_equal(tctx, dlz_allnodes(lpcfg_dnsdomain(tctx->lp_ctx),
522 dbdata, (dns_sdlzallnodes_t *)expected1),
524 "Failed to configure samba_dlz");
525 for (i = 0; i < expected1->num_records; i++) {
526 torture_assert(tctx, expected1->records[i].printed,
527 talloc_asprintf(tctx,
528 "Failed to have putrr callback run name[%s] for type %s",
529 expected1->records[i].name,
530 expected1->records[i].type));
532 torture_assert_int_equal(tctx, expected1->num_rr, 24,
533 "Got wrong record count");
543 static bool test_dlz_bind9_update01(struct torture_context *tctx)
546 struct gensec_security *gensec_client_context;
547 DATA_BLOB client_to_server, server_to_client;
549 void *version = NULL;
550 const char *argv[] = {
553 lpcfg_private_path(tctx, tctx->lp_ctx, "dns/sam.ldb"),
556 struct test_expected_rr *expected1 = NULL;
564 torture_assert_int_equal(tctx, dlz_create("samba_dlz", 3, argv, &dbdata,
565 "log", dlz_bind9_log_wrapper,
566 "writeable_zone", dlz_bind9_writeable_zone_hook,
567 "putrr", dlz_bind9_putrr_hook,
568 "putnamedrr", dlz_bind9_putnamedrr_hook,
571 "Failed to create samba_dlz");
573 torture_assert_int_equal(tctx, dlz_configure((void*)tctx, dbdata),
575 "Failed to configure samba_dlz");
577 expected1 = talloc_zero(tctx, struct test_expected_rr);
578 torture_assert(tctx, expected1 != NULL, "talloc failed");
579 expected1->tctx = tctx;
581 expected1->query_name = __func__;
583 name = talloc_asprintf(expected1, "%s.%s",
584 expected1->query_name,
585 lpcfg_dnsdomain(tctx->lp_ctx));
586 torture_assert(tctx, name != NULL, "talloc failed");
588 expected1->num_records = 2;
589 expected1->records = talloc_zero_array(expected1,
590 struct test_expected_record,
591 expected1->num_records);
592 torture_assert(tctx, expected1->records != NULL, "talloc failed");
594 expected1->records[0].name = expected1->query_name;
595 expected1->records[0].type = "a";
596 expected1->records[0].ttl = 3600;
597 expected1->records[0].data = "127.1.2.3";
598 expected1->records[0].printed = false;
600 data0 = talloc_asprintf(expected1,
601 "%s.\t" "%u\t" "%s\t" "%s\t" "%s",
603 (unsigned)expected1->records[0].ttl,
605 expected1->records[0].type,
606 expected1->records[0].data);
607 torture_assert(tctx, data0 != NULL, "talloc failed");
609 expected1->records[1].name = expected1->query_name;
610 expected1->records[1].type = "a";
611 expected1->records[1].ttl = 3600;
612 expected1->records[1].data = "127.3.2.1";
613 expected1->records[1].printed = false;
615 data1 = talloc_asprintf(expected1,
616 "%s.\t" "%u\t" "%s\t" "%s\t" "%s",
618 (unsigned)expected1->records[1].ttl,
620 expected1->records[1].type,
621 expected1->records[1].data);
622 torture_assert(tctx, data1 != NULL, "talloc failed");
624 data2 = talloc_asprintf(expected1,
625 "%s.\t" "0\t" "in\t" "a\t" "127.3.3.3",
627 torture_assert(tctx, data2 != NULL, "talloc failed");
630 * Prepare session info
632 status = gensec_client_start(tctx, &gensec_client_context,
633 lpcfg_gensec_settings(tctx, tctx->lp_ctx));
634 torture_assert_ntstatus_ok(tctx, status, "gensec_client_start (client) failed");
637 * dlz_bind9 use the special dns/host.domain account
639 status = gensec_set_target_hostname(gensec_client_context,
640 talloc_asprintf(tctx,
642 torture_setting_string(tctx, "host", NULL),
643 lpcfg_dnsdomain(tctx->lp_ctx)));
644 torture_assert_ntstatus_ok(tctx, status, "gensec_set_target_hostname (client) failed");
646 status = gensec_set_target_service(gensec_client_context, "dns");
647 torture_assert_ntstatus_ok(tctx, status, "gensec_set_target_service failed");
649 status = gensec_set_credentials(gensec_client_context, cmdline_credentials);
650 torture_assert_ntstatus_ok(tctx, status, "gensec_set_credentials (client) failed");
652 status = gensec_start_mech_by_sasl_name(gensec_client_context, "GSS-SPNEGO");
653 torture_assert_ntstatus_ok(tctx, status, "gensec_start_mech_by_sasl_name (client) failed");
655 server_to_client = data_blob(NULL, 0);
657 /* Do one step of the client-server update dance */
658 status = gensec_update(gensec_client_context, tctx, server_to_client, &client_to_server);
659 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {;
660 torture_assert_ntstatus_ok(tctx, status, "gensec_update (client) failed");
663 torture_assert_int_equal(tctx, dlz_ssumatch(cli_credentials_get_username(cmdline_credentials),
666 expected1->records[0].type,
668 client_to_server.length,
669 client_to_server.data,
672 "Failed to check key for update rights samba_dlz");
675 * We test the following:
677 * 1. lookup the records => NOT_FOUND
678 * 2. delete all records => NOT_FOUND
679 * 3. delete 1st record => NOT_FOUND
680 * 4. create 1st record => SUCCESS
681 * 5. lookup the records => found 1st
682 * 6. create 2nd record => SUCCESS
683 * 7. lookup the records => found 1st and 2nd
684 * 8. delete unknown record => NOT_FOUND
685 * 9. lookup the records => found 1st and 2nd
686 * 10. delete 1st record => SUCCESS
687 * 11. lookup the records => found 2nd
688 * 12. delete 2nd record => SUCCESS
689 * 13. lookup the records => NOT_FOUND
690 * 14. create 1st record => SUCCESS
691 * 15. lookup the records => found 1st
692 * 16. create 2nd record => SUCCESS
693 * 17. lookup the records => found 1st and 2nd
694 * 18. update 1st record => SUCCESS
695 * 19. lookup the records => found 1st and 2nd
696 * 20. delete all unknown type records => NOT_FOUND
697 * 21. lookup the records => found 1st and 2nd
698 * 22. delete all records => SUCCESS
699 * 23. lookup the records => NOT_FOUND
703 expected1->num_rr = 0;
704 expected1->records[0].printed = false;
705 expected1->records[1].printed = false;
706 torture_assert_int_equal(tctx, dlz_lookup(lpcfg_dnsdomain(tctx->lp_ctx),
707 expected1->query_name, dbdata,
708 (dns_sdlzlookup_t *)expected1),
711 torture_assert_int_equal(tctx, expected1->num_rr, 0,
712 "Got wrong record count");
715 torture_assert_int_equal(tctx, dlz_newversion(lpcfg_dnsdomain(tctx->lp_ctx),
718 "Failed to start transaction");
719 torture_assert_int_equal_goto(tctx,
720 dlz_delrdataset(name,
721 expected1->records[0].type,
723 ISC_R_NOTFOUND, ret, cancel_version,
724 talloc_asprintf(tctx, "Deleted name[%s] type[%s]\n",
725 name, expected1->records[0].type));
726 dlz_closeversion(lpcfg_dnsdomain(tctx->lp_ctx), false, dbdata, &version);
729 torture_assert_int_equal(tctx, dlz_newversion(lpcfg_dnsdomain(tctx->lp_ctx),
732 "Failed to start transaction");
733 torture_assert_int_equal_goto(tctx,
734 dlz_subrdataset(name, data0, dbdata, version),
735 ISC_R_NOTFOUND, ret, cancel_version,
736 talloc_asprintf(tctx, "Deleted name[%s] data[%s]\n",
738 dlz_closeversion(lpcfg_dnsdomain(tctx->lp_ctx), false, dbdata, &version);
741 torture_assert_int_equal(tctx, dlz_newversion(lpcfg_dnsdomain(tctx->lp_ctx),
744 "Failed to start transaction");
745 torture_assert_int_equal_goto(tctx,
746 dlz_addrdataset(name, data0, dbdata, version),
747 ISC_R_SUCCESS, ret, cancel_version,
748 talloc_asprintf(tctx, "Failed to add name[%s] data[%s]\n",
750 dlz_closeversion(lpcfg_dnsdomain(tctx->lp_ctx), true, dbdata, &version);
753 expected1->num_rr = 0;
754 expected1->records[0].printed = false;
755 expected1->records[1].printed = false;
756 torture_assert_int_equal(tctx, dlz_lookup(lpcfg_dnsdomain(tctx->lp_ctx),
757 expected1->query_name, dbdata,
758 (dns_sdlzlookup_t *)expected1),
760 "Not found hostname");
761 torture_assert(tctx, expected1->records[0].printed,
762 talloc_asprintf(tctx,
763 "Failed to have putrr callback run name[%s] for type %s",
764 expected1->records[0].name,
765 expected1->records[0].type));
766 torture_assert_int_equal(tctx, expected1->num_rr, 1,
767 "Got wrong record count");
770 torture_assert_int_equal(tctx, dlz_newversion(lpcfg_dnsdomain(tctx->lp_ctx),
773 "Failed to start transaction");
774 torture_assert_int_equal_goto(tctx,
775 dlz_addrdataset(name, data1, dbdata, version),
776 ISC_R_SUCCESS, ret, cancel_version,
777 talloc_asprintf(tctx, "Failed to add name[%s] data[%s]\n",
779 dlz_closeversion(lpcfg_dnsdomain(tctx->lp_ctx), true, dbdata, &version);
782 expected1->num_rr = 0;
783 expected1->records[0].printed = false;
784 expected1->records[1].printed = false;
785 torture_assert_int_equal(tctx, dlz_lookup(lpcfg_dnsdomain(tctx->lp_ctx),
786 expected1->query_name, dbdata,
787 (dns_sdlzlookup_t *)expected1),
789 "Not found hostname");
790 torture_assert(tctx, expected1->records[0].printed,
791 talloc_asprintf(tctx,
792 "Failed to have putrr callback run name[%s] for type %s",
793 expected1->records[0].name,
794 expected1->records[0].type));
795 torture_assert(tctx, expected1->records[1].printed,
796 talloc_asprintf(tctx,
797 "Failed to have putrr callback run name[%s] for type %s",
798 expected1->records[1].name,
799 expected1->records[1].type));
800 torture_assert_int_equal(tctx, expected1->num_rr, 2,
801 "Got wrong record count");
804 torture_assert_int_equal(tctx, dlz_newversion(lpcfg_dnsdomain(tctx->lp_ctx),
807 "Failed to start transaction");
808 torture_assert_int_equal_goto(tctx,
809 dlz_subrdataset(name, data2, dbdata, version),
810 ISC_R_NOTFOUND, ret, cancel_version,
811 talloc_asprintf(tctx, "Deleted name[%s] data[%s]\n",
813 dlz_closeversion(lpcfg_dnsdomain(tctx->lp_ctx), true, dbdata, &version);
816 expected1->num_rr = 0;
817 expected1->records[0].printed = false;
818 expected1->records[1].printed = false;
819 torture_assert_int_equal(tctx, dlz_lookup(lpcfg_dnsdomain(tctx->lp_ctx),
820 expected1->query_name, dbdata,
821 (dns_sdlzlookup_t *)expected1),
823 "Not found hostname");
824 torture_assert(tctx, expected1->records[0].printed,
825 talloc_asprintf(tctx,
826 "Failed to have putrr callback run name[%s] for type %s",
827 expected1->records[0].name,
828 expected1->records[0].type));
829 torture_assert(tctx, expected1->records[1].printed,
830 talloc_asprintf(tctx,
831 "Failed to have putrr callback run name[%s] for type %s",
832 expected1->records[1].name,
833 expected1->records[1].type));
834 torture_assert_int_equal(tctx, expected1->num_rr, 2,
835 "Got wrong record count");
838 torture_assert_int_equal(tctx, dlz_newversion(lpcfg_dnsdomain(tctx->lp_ctx),
841 "Failed to start transaction");
842 torture_assert_int_equal_goto(tctx,
843 dlz_subrdataset(name, data0, dbdata, version),
844 ISC_R_SUCCESS, ret, cancel_version,
845 talloc_asprintf(tctx, "Failed to delete name[%s] data[%s]\n",
847 dlz_closeversion(lpcfg_dnsdomain(tctx->lp_ctx), true, dbdata, &version);
850 expected1->num_rr = 0;
851 expected1->records[0].printed = false;
852 expected1->records[1].printed = false;
853 torture_assert_int_equal(tctx, dlz_lookup(lpcfg_dnsdomain(tctx->lp_ctx),
854 expected1->query_name, dbdata,
855 (dns_sdlzlookup_t *)expected1),
857 "Not found hostname");
858 torture_assert(tctx, expected1->records[1].printed,
859 talloc_asprintf(tctx,
860 "Failed to have putrr callback run name[%s] for type %s",
861 expected1->records[1].name,
862 expected1->records[1].type));
863 torture_assert_int_equal(tctx, expected1->num_rr, 1,
864 "Got wrong record count");
867 torture_assert_int_equal(tctx, dlz_newversion(lpcfg_dnsdomain(tctx->lp_ctx),
870 "Failed to start transaction");
871 torture_assert_int_equal_goto(tctx,
872 dlz_subrdataset(name, data1, dbdata, version),
873 ISC_R_SUCCESS, ret, cancel_version,
874 talloc_asprintf(tctx, "Failed to delete name[%s] data[%s]\n",
876 dlz_closeversion(lpcfg_dnsdomain(tctx->lp_ctx), true, dbdata, &version);
879 expected1->num_rr = 0;
880 expected1->records[0].printed = false;
881 expected1->records[1].printed = false;
882 torture_assert_int_equal(tctx, dlz_lookup(lpcfg_dnsdomain(tctx->lp_ctx),
883 expected1->query_name, dbdata,
884 (dns_sdlzlookup_t *)expected1),
887 torture_assert_int_equal(tctx, expected1->num_rr, 0,
888 "Got wrong record count");
891 torture_assert_int_equal(tctx, dlz_newversion(lpcfg_dnsdomain(tctx->lp_ctx),
894 "Failed to start transaction");
895 torture_assert_int_equal_goto(tctx,
896 dlz_addrdataset(name, data0, dbdata, version),
897 ISC_R_SUCCESS, ret, cancel_version,
898 talloc_asprintf(tctx, "Failed to add name[%s] data[%s]\n",
900 dlz_closeversion(lpcfg_dnsdomain(tctx->lp_ctx), true, dbdata, &version);
903 expected1->num_rr = 0;
904 expected1->records[0].printed = false;
905 expected1->records[1].printed = false;
906 torture_assert_int_equal(tctx, dlz_lookup(lpcfg_dnsdomain(tctx->lp_ctx),
907 expected1->query_name, dbdata,
908 (dns_sdlzlookup_t *)expected1),
910 "Not found hostname");
911 torture_assert(tctx, expected1->records[0].printed,
912 talloc_asprintf(tctx,
913 "Failed to have putrr callback run name[%s] for type %s",
914 expected1->records[0].name,
915 expected1->records[0].type));
916 torture_assert_int_equal(tctx, expected1->num_rr, 1,
917 "Got wrong record count");
920 torture_assert_int_equal(tctx, dlz_newversion(lpcfg_dnsdomain(tctx->lp_ctx),
923 "Failed to start transaction");
924 torture_assert_int_equal_goto(tctx,
925 dlz_addrdataset(name, data1, dbdata, version),
926 ISC_R_SUCCESS, ret, cancel_version,
927 talloc_asprintf(tctx, "Failed to add name[%s] data[%s]\n",
929 dlz_closeversion(lpcfg_dnsdomain(tctx->lp_ctx), true, dbdata, &version);
932 expected1->num_rr = 0;
933 expected1->records[0].printed = false;
934 expected1->records[1].printed = false;
935 torture_assert_int_equal(tctx, dlz_lookup(lpcfg_dnsdomain(tctx->lp_ctx),
936 expected1->query_name, dbdata,
937 (dns_sdlzlookup_t *)expected1),
939 "Not found hostname");
940 torture_assert(tctx, expected1->records[0].printed,
941 talloc_asprintf(tctx,
942 "Failed to have putrr callback run name[%s] for type %s",
943 expected1->records[0].name,
944 expected1->records[0].type));
945 torture_assert(tctx, expected1->records[1].printed,
946 talloc_asprintf(tctx,
947 "Failed to have putrr callback run name[%s] for type %s",
948 expected1->records[1].name,
949 expected1->records[1].type));
950 torture_assert_int_equal(tctx, expected1->num_rr, 2,
951 "Got wrong record count");
954 torture_assert_int_equal(tctx, dlz_newversion(lpcfg_dnsdomain(tctx->lp_ctx),
957 "Failed to start transaction");
958 torture_assert_int_equal_goto(tctx,
959 dlz_addrdataset(name, data0, dbdata, version),
960 ISC_R_SUCCESS, ret, cancel_version,
961 talloc_asprintf(tctx, "Failed to update name[%s] data[%s]\n",
963 dlz_closeversion(lpcfg_dnsdomain(tctx->lp_ctx), true, dbdata, &version);
966 expected1->num_rr = 0;
967 expected1->records[0].printed = false;
968 expected1->records[1].printed = false;
969 torture_assert_int_equal(tctx, dlz_lookup(lpcfg_dnsdomain(tctx->lp_ctx),
970 expected1->query_name, dbdata,
971 (dns_sdlzlookup_t *)expected1),
973 "Not found hostname");
974 torture_assert(tctx, expected1->records[0].printed,
975 talloc_asprintf(tctx,
976 "Failed to have putrr callback run name[%s] for type %s",
977 expected1->records[0].name,
978 expected1->records[0].type));
979 torture_assert(tctx, expected1->records[1].printed,
980 talloc_asprintf(tctx,
981 "Failed to have putrr callback run name[%s] for type %s",
982 expected1->records[1].name,
983 expected1->records[1].type));
984 torture_assert_int_equal(tctx, expected1->num_rr, 2,
985 "Got wrong record count");
988 torture_assert_int_equal(tctx, dlz_newversion(lpcfg_dnsdomain(tctx->lp_ctx),
991 "Failed to start transaction");
992 torture_assert_int_equal_goto(tctx,
993 dlz_delrdataset(name, "txt", dbdata, version),
994 ISC_R_FAILURE, ret, cancel_version,
995 talloc_asprintf(tctx, "Deleted name[%s] type[%s]\n",
997 dlz_closeversion(lpcfg_dnsdomain(tctx->lp_ctx), false, dbdata, &version);
1000 expected1->num_rr = 0;
1001 expected1->records[0].printed = false;
1002 expected1->records[1].printed = false;
1003 torture_assert_int_equal(tctx, dlz_lookup(lpcfg_dnsdomain(tctx->lp_ctx),
1004 expected1->query_name, dbdata,
1005 (dns_sdlzlookup_t *)expected1),
1007 "Not found hostname");
1008 torture_assert(tctx, expected1->records[0].printed,
1009 talloc_asprintf(tctx,
1010 "Failed to have putrr callback run name[%s] for type %s",
1011 expected1->records[0].name,
1012 expected1->records[0].type));
1013 torture_assert(tctx, expected1->records[1].printed,
1014 talloc_asprintf(tctx,
1015 "Failed to have putrr callback run name[%s] for type %s",
1016 expected1->records[1].name,
1017 expected1->records[1].type));
1018 torture_assert_int_equal(tctx, expected1->num_rr, 2,
1019 "Got wrong record count");
1022 torture_assert_int_equal(tctx, dlz_newversion(lpcfg_dnsdomain(tctx->lp_ctx),
1025 "Failed to start transaction");
1026 torture_assert_int_equal_goto(tctx,
1027 dlz_delrdataset(name,
1028 expected1->records[0].type,
1030 ISC_R_SUCCESS, ret, cancel_version,
1031 talloc_asprintf(tctx, "Failed to delete name[%s] type[%s]\n",
1032 name, expected1->records[0].type));
1033 dlz_closeversion(lpcfg_dnsdomain(tctx->lp_ctx), true, dbdata, &version);
1036 expected1->num_rr = 0;
1037 expected1->records[0].printed = false;
1038 expected1->records[1].printed = false;
1039 torture_assert_int_equal(tctx, dlz_lookup(lpcfg_dnsdomain(tctx->lp_ctx),
1040 expected1->query_name, dbdata,
1041 (dns_sdlzlookup_t *)expected1),
1044 torture_assert_int_equal(tctx, expected1->num_rr, 0,
1045 "Got wrong record count");
1047 dlz_destroy(dbdata);
1052 dlz_closeversion(lpcfg_dnsdomain(tctx->lp_ctx), false, dbdata, &version);
1056 static struct torture_suite *dlz_bind9_suite(TALLOC_CTX *ctx)
1058 struct torture_suite *suite = torture_suite_create(ctx, "dlz_bind9");
1060 suite->description = talloc_strdup(suite,
1061 "Tests for the BIND 9 DLZ module");
1062 torture_suite_add_simple_test(suite, "version", test_dlz_bind9_version);
1063 torture_suite_add_simple_test(suite, "create", test_dlz_bind9_create);
1064 torture_suite_add_simple_test(suite, "configure", test_dlz_bind9_configure);
1065 torture_suite_add_simple_test(suite, "gssapi", test_dlz_bind9_gssapi);
1066 torture_suite_add_simple_test(suite, "spnego", test_dlz_bind9_spnego);
1067 torture_suite_add_simple_test(suite, "lookup", test_dlz_bind9_lookup);
1068 torture_suite_add_simple_test(suite, "zonedump", test_dlz_bind9_zonedump);
1069 torture_suite_add_simple_test(suite, "update01", test_dlz_bind9_update01);
1074 * DNS torture module initialization
1076 NTSTATUS torture_bind_dns_init(void);
1077 NTSTATUS torture_bind_dns_init(void)
1079 struct torture_suite *suite;
1080 TALLOC_CTX *mem_ctx = talloc_autofree_context();
1082 /* register DNS related test cases */
1083 suite = dlz_bind9_suite(mem_ctx);
1084 if (!suite) return NT_STATUS_NO_MEMORY;
1085 torture_register_suite(suite);
1087 return NT_STATUS_OK;