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
= talloc_asprintf(expected1
->records
,
475 "%s.", lpcfg_dnsdomain(tctx
->lp_ctx
));
476 expected1
->records
[0].type
= "soa";
477 expected1
->records
[0].ttl
= 3600;
478 expected1
->records
[0].data
= talloc_asprintf(expected1
->records
,
479 "%s.%s. hostmaster.%s. 1 900 600 86400 3600",
480 torture_setting_string(tctx
, "host", NULL
),
481 lpcfg_dnsdomain(tctx
->lp_ctx
),
482 lpcfg_dnsdomain(tctx
->lp_ctx
));
483 torture_assert(tctx
, expected1
->records
[0].data
!= NULL
, "talloc failed");
485 expected1
->records
[1].name
= talloc_asprintf(expected1
->records
,
486 "%s.", lpcfg_dnsdomain(tctx
->lp_ctx
));
487 expected1
->records
[1].type
= "ns";
488 expected1
->records
[1].ttl
= 900;
489 expected1
->records
[1].data
= talloc_asprintf(expected1
->records
, "%s.%s.",
490 torture_setting_string(tctx
, "host", NULL
),
491 lpcfg_dnsdomain(tctx
->lp_ctx
));
492 torture_assert(tctx
, expected1
->records
[1].data
!= NULL
, "talloc failed");
494 expected1
->records
[2].name
= talloc_asprintf(expected1
->records
,
495 "%s.", lpcfg_dnsdomain(tctx
->lp_ctx
));
496 expected1
->records
[2].type
= "aaaa";
497 expected1
->records
[2].ttl
= 900;
499 expected1
->records
[3].name
= talloc_asprintf(expected1
->records
,
500 "%s.", lpcfg_dnsdomain(tctx
->lp_ctx
));
501 expected1
->records
[3].type
= "a";
502 expected1
->records
[3].ttl
= 900;
504 expected1
->records
[4].name
= talloc_asprintf(expected1
->records
, "%s.%s.",
505 torture_setting_string(tctx
, "host", NULL
),
506 lpcfg_dnsdomain(tctx
->lp_ctx
));
507 torture_assert(tctx
, expected1
->records
[4].name
!= NULL
, "unknown host");
508 expected1
->records
[4].type
= "aaaa";
509 expected1
->records
[4].ttl
= 900;
511 expected1
->records
[5].name
= talloc_asprintf(expected1
->records
, "%s.%s.",
512 torture_setting_string(tctx
, "host", NULL
),
513 lpcfg_dnsdomain(tctx
->lp_ctx
));
514 torture_assert(tctx
, expected1
->records
[5].name
!= NULL
, "unknown host");
515 expected1
->records
[5].type
= "a";
516 expected1
->records
[5].ttl
= 900;
519 * We expect multiple srv records
521 expected1
->records
[6].name
= NULL
;
522 expected1
->records
[6].type
= "srv";
523 expected1
->records
[6].ttl
= 900;
525 torture_assert_int_equal(tctx
, dlz_allnodes(lpcfg_dnsdomain(tctx
->lp_ctx
),
526 dbdata
, (dns_sdlzallnodes_t
*)expected1
),
528 "Failed to configure samba_dlz");
529 for (i
= 0; i
< expected1
->num_records
; i
++) {
530 torture_assert(tctx
, expected1
->records
[i
].printed
,
531 talloc_asprintf(tctx
,
532 "Failed to have putrr callback run name[%s] for type %s",
533 expected1
->records
[i
].name
,
534 expected1
->records
[i
].type
));
536 torture_assert_int_equal(tctx
, expected1
->num_rr
, 24,
537 "Got wrong record count");
547 static bool test_dlz_bind9_update01(struct torture_context
*tctx
)
550 struct gensec_security
*gensec_client_context
;
551 DATA_BLOB client_to_server
, server_to_client
;
553 void *version
= NULL
;
554 const char *argv
[] = {
557 lpcfg_private_path(tctx
, tctx
->lp_ctx
, "dns/sam.ldb"),
560 struct test_expected_rr
*expected1
= NULL
;
568 torture_assert_int_equal(tctx
, dlz_create("samba_dlz", 3, argv
, &dbdata
,
569 "log", dlz_bind9_log_wrapper
,
570 "writeable_zone", dlz_bind9_writeable_zone_hook
,
571 "putrr", dlz_bind9_putrr_hook
,
572 "putnamedrr", dlz_bind9_putnamedrr_hook
,
575 "Failed to create samba_dlz");
577 torture_assert_int_equal(tctx
, dlz_configure((void*)tctx
, dbdata
),
579 "Failed to configure samba_dlz");
581 expected1
= talloc_zero(tctx
, struct test_expected_rr
);
582 torture_assert(tctx
, expected1
!= NULL
, "talloc failed");
583 expected1
->tctx
= tctx
;
585 expected1
->query_name
= __func__
;
587 name
= talloc_asprintf(expected1
, "%s.%s",
588 expected1
->query_name
,
589 lpcfg_dnsdomain(tctx
->lp_ctx
));
590 torture_assert(tctx
, name
!= NULL
, "talloc failed");
592 expected1
->num_records
= 2;
593 expected1
->records
= talloc_zero_array(expected1
,
594 struct test_expected_record
,
595 expected1
->num_records
);
596 torture_assert(tctx
, expected1
->records
!= NULL
, "talloc failed");
598 expected1
->records
[0].name
= expected1
->query_name
;
599 expected1
->records
[0].type
= "a";
600 expected1
->records
[0].ttl
= 3600;
601 expected1
->records
[0].data
= "127.1.2.3";
602 expected1
->records
[0].printed
= false;
604 data0
= talloc_asprintf(expected1
,
605 "%s.\t" "%u\t" "%s\t" "%s\t" "%s",
607 (unsigned)expected1
->records
[0].ttl
,
609 expected1
->records
[0].type
,
610 expected1
->records
[0].data
);
611 torture_assert(tctx
, data0
!= NULL
, "talloc failed");
613 expected1
->records
[1].name
= expected1
->query_name
;
614 expected1
->records
[1].type
= "a";
615 expected1
->records
[1].ttl
= 3600;
616 expected1
->records
[1].data
= "127.3.2.1";
617 expected1
->records
[1].printed
= false;
619 data1
= talloc_asprintf(expected1
,
620 "%s.\t" "%u\t" "%s\t" "%s\t" "%s",
622 (unsigned)expected1
->records
[1].ttl
,
624 expected1
->records
[1].type
,
625 expected1
->records
[1].data
);
626 torture_assert(tctx
, data1
!= NULL
, "talloc failed");
628 data2
= talloc_asprintf(expected1
,
629 "%s.\t" "0\t" "in\t" "a\t" "127.3.3.3",
631 torture_assert(tctx
, data2
!= NULL
, "talloc failed");
634 * Prepare session info
636 status
= gensec_client_start(tctx
, &gensec_client_context
,
637 lpcfg_gensec_settings(tctx
, tctx
->lp_ctx
));
638 torture_assert_ntstatus_ok(tctx
, status
, "gensec_client_start (client) failed");
641 * dlz_bind9 use the special dns/host.domain account
643 status
= gensec_set_target_hostname(gensec_client_context
,
644 talloc_asprintf(tctx
,
646 torture_setting_string(tctx
, "host", NULL
),
647 lpcfg_dnsdomain(tctx
->lp_ctx
)));
648 torture_assert_ntstatus_ok(tctx
, status
, "gensec_set_target_hostname (client) failed");
650 status
= gensec_set_target_service(gensec_client_context
, "dns");
651 torture_assert_ntstatus_ok(tctx
, status
, "gensec_set_target_service failed");
653 status
= gensec_set_credentials(gensec_client_context
, cmdline_credentials
);
654 torture_assert_ntstatus_ok(tctx
, status
, "gensec_set_credentials (client) failed");
656 status
= gensec_start_mech_by_sasl_name(gensec_client_context
, "GSS-SPNEGO");
657 torture_assert_ntstatus_ok(tctx
, status
, "gensec_start_mech_by_sasl_name (client) failed");
659 server_to_client
= data_blob(NULL
, 0);
661 /* Do one step of the client-server update dance */
662 status
= gensec_update(gensec_client_context
, tctx
, server_to_client
, &client_to_server
);
663 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {;
664 torture_assert_ntstatus_ok(tctx
, status
, "gensec_update (client) failed");
667 torture_assert_int_equal(tctx
, dlz_ssumatch(cli_credentials_get_username(cmdline_credentials
),
670 expected1
->records
[0].type
,
672 client_to_server
.length
,
673 client_to_server
.data
,
676 "Failed to check key for update rights samba_dlz");
679 * We test the following:
681 * 1. lookup the records => NOT_FOUND
682 * 2. delete all records => NOT_FOUND
683 * 3. delete 1st record => NOT_FOUND
684 * 4. create 1st record => SUCCESS
685 * 5. lookup the records => found 1st
686 * 6. create 2nd record => SUCCESS
687 * 7. lookup the records => found 1st and 2nd
688 * 8. delete unknown record => NOT_FOUND
689 * 9. lookup the records => found 1st and 2nd
690 * 10. delete 1st record => SUCCESS
691 * 11. lookup the records => found 2nd
692 * 12. delete 2nd record => SUCCESS
693 * 13. lookup the records => NOT_FOUND
694 * 14. create 1st record => SUCCESS
695 * 15. lookup the records => found 1st
696 * 16. create 2nd record => SUCCESS
697 * 17. lookup the records => found 1st and 2nd
698 * 18. update 1st record => SUCCESS
699 * 19. lookup the records => found 1st and 2nd
700 * 20. delete all unknown type records => NOT_FOUND
701 * 21. lookup the records => found 1st and 2nd
702 * 22. delete all records => SUCCESS
703 * 23. lookup the records => NOT_FOUND
707 expected1
->num_rr
= 0;
708 expected1
->records
[0].printed
= false;
709 expected1
->records
[1].printed
= false;
710 torture_assert_int_equal(tctx
, dlz_lookup(lpcfg_dnsdomain(tctx
->lp_ctx
),
711 expected1
->query_name
, dbdata
,
712 (dns_sdlzlookup_t
*)expected1
),
715 torture_assert_int_equal(tctx
, expected1
->num_rr
, 0,
716 "Got wrong record count");
719 torture_assert_int_equal(tctx
, dlz_newversion(lpcfg_dnsdomain(tctx
->lp_ctx
),
722 "Failed to start transaction");
723 torture_assert_int_equal_goto(tctx
,
724 dlz_delrdataset(name
,
725 expected1
->records
[0].type
,
727 ISC_R_NOTFOUND
, ret
, cancel_version
,
728 talloc_asprintf(tctx
, "Deleted name[%s] type[%s]\n",
729 name
, expected1
->records
[0].type
));
730 dlz_closeversion(lpcfg_dnsdomain(tctx
->lp_ctx
), false, dbdata
, &version
);
733 torture_assert_int_equal(tctx
, dlz_newversion(lpcfg_dnsdomain(tctx
->lp_ctx
),
736 "Failed to start transaction");
737 torture_assert_int_equal_goto(tctx
,
738 dlz_subrdataset(name
, data0
, dbdata
, version
),
739 ISC_R_NOTFOUND
, ret
, cancel_version
,
740 talloc_asprintf(tctx
, "Deleted name[%s] data[%s]\n",
742 dlz_closeversion(lpcfg_dnsdomain(tctx
->lp_ctx
), false, dbdata
, &version
);
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_addrdataset(name
, data0
, dbdata
, version
),
751 ISC_R_SUCCESS
, ret
, cancel_version
,
752 talloc_asprintf(tctx
, "Failed to add name[%s] data[%s]\n",
754 dlz_closeversion(lpcfg_dnsdomain(tctx
->lp_ctx
), true, dbdata
, &version
);
757 expected1
->num_rr
= 0;
758 expected1
->records
[0].printed
= false;
759 expected1
->records
[1].printed
= false;
760 torture_assert_int_equal(tctx
, dlz_lookup(lpcfg_dnsdomain(tctx
->lp_ctx
),
761 expected1
->query_name
, dbdata
,
762 (dns_sdlzlookup_t
*)expected1
),
764 "Not found hostname");
765 torture_assert(tctx
, expected1
->records
[0].printed
,
766 talloc_asprintf(tctx
,
767 "Failed to have putrr callback run name[%s] for type %s",
768 expected1
->records
[0].name
,
769 expected1
->records
[0].type
));
770 torture_assert_int_equal(tctx
, expected1
->num_rr
, 1,
771 "Got wrong record count");
774 torture_assert_int_equal(tctx
, dlz_newversion(lpcfg_dnsdomain(tctx
->lp_ctx
),
777 "Failed to start transaction");
778 torture_assert_int_equal_goto(tctx
,
779 dlz_addrdataset(name
, data1
, dbdata
, version
),
780 ISC_R_SUCCESS
, ret
, cancel_version
,
781 talloc_asprintf(tctx
, "Failed to add name[%s] data[%s]\n",
783 dlz_closeversion(lpcfg_dnsdomain(tctx
->lp_ctx
), true, dbdata
, &version
);
786 expected1
->num_rr
= 0;
787 expected1
->records
[0].printed
= false;
788 expected1
->records
[1].printed
= false;
789 torture_assert_int_equal(tctx
, dlz_lookup(lpcfg_dnsdomain(tctx
->lp_ctx
),
790 expected1
->query_name
, dbdata
,
791 (dns_sdlzlookup_t
*)expected1
),
793 "Not found hostname");
794 torture_assert(tctx
, expected1
->records
[0].printed
,
795 talloc_asprintf(tctx
,
796 "Failed to have putrr callback run name[%s] for type %s",
797 expected1
->records
[0].name
,
798 expected1
->records
[0].type
));
799 torture_assert(tctx
, expected1
->records
[1].printed
,
800 talloc_asprintf(tctx
,
801 "Failed to have putrr callback run name[%s] for type %s",
802 expected1
->records
[1].name
,
803 expected1
->records
[1].type
));
804 torture_assert_int_equal(tctx
, expected1
->num_rr
, 2,
805 "Got wrong record count");
808 torture_assert_int_equal(tctx
, dlz_newversion(lpcfg_dnsdomain(tctx
->lp_ctx
),
811 "Failed to start transaction");
812 torture_assert_int_equal_goto(tctx
,
813 dlz_subrdataset(name
, data2
, dbdata
, version
),
814 ISC_R_NOTFOUND
, ret
, cancel_version
,
815 talloc_asprintf(tctx
, "Deleted name[%s] data[%s]\n",
817 dlz_closeversion(lpcfg_dnsdomain(tctx
->lp_ctx
), true, dbdata
, &version
);
820 expected1
->num_rr
= 0;
821 expected1
->records
[0].printed
= false;
822 expected1
->records
[1].printed
= false;
823 torture_assert_int_equal(tctx
, dlz_lookup(lpcfg_dnsdomain(tctx
->lp_ctx
),
824 expected1
->query_name
, dbdata
,
825 (dns_sdlzlookup_t
*)expected1
),
827 "Not found hostname");
828 torture_assert(tctx
, expected1
->records
[0].printed
,
829 talloc_asprintf(tctx
,
830 "Failed to have putrr callback run name[%s] for type %s",
831 expected1
->records
[0].name
,
832 expected1
->records
[0].type
));
833 torture_assert(tctx
, expected1
->records
[1].printed
,
834 talloc_asprintf(tctx
,
835 "Failed to have putrr callback run name[%s] for type %s",
836 expected1
->records
[1].name
,
837 expected1
->records
[1].type
));
838 torture_assert_int_equal(tctx
, expected1
->num_rr
, 2,
839 "Got wrong record count");
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_subrdataset(name
, data0
, dbdata
, version
),
848 ISC_R_SUCCESS
, ret
, cancel_version
,
849 talloc_asprintf(tctx
, "Failed to delete 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
[1].printed
,
863 talloc_asprintf(tctx
,
864 "Failed to have putrr callback run name[%s] for type %s",
865 expected1
->records
[1].name
,
866 expected1
->records
[1].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_subrdataset(name
, data1
, dbdata
, version
),
877 ISC_R_SUCCESS
, ret
, cancel_version
,
878 talloc_asprintf(tctx
, "Failed to delete 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
),
891 torture_assert_int_equal(tctx
, expected1
->num_rr
, 0,
892 "Got wrong record count");
895 torture_assert_int_equal(tctx
, dlz_newversion(lpcfg_dnsdomain(tctx
->lp_ctx
),
898 "Failed to start transaction");
899 torture_assert_int_equal_goto(tctx
,
900 dlz_addrdataset(name
, data0
, dbdata
, version
),
901 ISC_R_SUCCESS
, ret
, cancel_version
,
902 talloc_asprintf(tctx
, "Failed to add name[%s] data[%s]\n",
904 dlz_closeversion(lpcfg_dnsdomain(tctx
->lp_ctx
), true, dbdata
, &version
);
907 expected1
->num_rr
= 0;
908 expected1
->records
[0].printed
= false;
909 expected1
->records
[1].printed
= false;
910 torture_assert_int_equal(tctx
, dlz_lookup(lpcfg_dnsdomain(tctx
->lp_ctx
),
911 expected1
->query_name
, dbdata
,
912 (dns_sdlzlookup_t
*)expected1
),
914 "Not found hostname");
915 torture_assert(tctx
, expected1
->records
[0].printed
,
916 talloc_asprintf(tctx
,
917 "Failed to have putrr callback run name[%s] for type %s",
918 expected1
->records
[0].name
,
919 expected1
->records
[0].type
));
920 torture_assert_int_equal(tctx
, expected1
->num_rr
, 1,
921 "Got wrong record count");
924 torture_assert_int_equal(tctx
, dlz_newversion(lpcfg_dnsdomain(tctx
->lp_ctx
),
927 "Failed to start transaction");
928 torture_assert_int_equal_goto(tctx
,
929 dlz_addrdataset(name
, data1
, dbdata
, version
),
930 ISC_R_SUCCESS
, ret
, cancel_version
,
931 talloc_asprintf(tctx
, "Failed to add name[%s] data[%s]\n",
933 dlz_closeversion(lpcfg_dnsdomain(tctx
->lp_ctx
), true, dbdata
, &version
);
936 expected1
->num_rr
= 0;
937 expected1
->records
[0].printed
= false;
938 expected1
->records
[1].printed
= false;
939 torture_assert_int_equal(tctx
, dlz_lookup(lpcfg_dnsdomain(tctx
->lp_ctx
),
940 expected1
->query_name
, dbdata
,
941 (dns_sdlzlookup_t
*)expected1
),
943 "Not found hostname");
944 torture_assert(tctx
, expected1
->records
[0].printed
,
945 talloc_asprintf(tctx
,
946 "Failed to have putrr callback run name[%s] for type %s",
947 expected1
->records
[0].name
,
948 expected1
->records
[0].type
));
949 torture_assert(tctx
, expected1
->records
[1].printed
,
950 talloc_asprintf(tctx
,
951 "Failed to have putrr callback run name[%s] for type %s",
952 expected1
->records
[1].name
,
953 expected1
->records
[1].type
));
954 torture_assert_int_equal(tctx
, expected1
->num_rr
, 2,
955 "Got wrong record count");
958 torture_assert_int_equal(tctx
, dlz_newversion(lpcfg_dnsdomain(tctx
->lp_ctx
),
961 "Failed to start transaction");
962 torture_assert_int_equal_goto(tctx
,
963 dlz_addrdataset(name
, data0
, dbdata
, version
),
964 ISC_R_SUCCESS
, ret
, cancel_version
,
965 talloc_asprintf(tctx
, "Failed to update name[%s] data[%s]\n",
967 dlz_closeversion(lpcfg_dnsdomain(tctx
->lp_ctx
), true, dbdata
, &version
);
970 expected1
->num_rr
= 0;
971 expected1
->records
[0].printed
= false;
972 expected1
->records
[1].printed
= false;
973 torture_assert_int_equal(tctx
, dlz_lookup(lpcfg_dnsdomain(tctx
->lp_ctx
),
974 expected1
->query_name
, dbdata
,
975 (dns_sdlzlookup_t
*)expected1
),
977 "Not found hostname");
978 torture_assert(tctx
, expected1
->records
[0].printed
,
979 talloc_asprintf(tctx
,
980 "Failed to have putrr callback run name[%s] for type %s",
981 expected1
->records
[0].name
,
982 expected1
->records
[0].type
));
983 torture_assert(tctx
, expected1
->records
[1].printed
,
984 talloc_asprintf(tctx
,
985 "Failed to have putrr callback run name[%s] for type %s",
986 expected1
->records
[1].name
,
987 expected1
->records
[1].type
));
988 torture_assert_int_equal(tctx
, expected1
->num_rr
, 2,
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_delrdataset(name
, "txt", dbdata
, version
),
998 ISC_R_FAILURE
, ret
, cancel_version
,
999 talloc_asprintf(tctx
, "Deleted name[%s] type[%s]\n",
1001 dlz_closeversion(lpcfg_dnsdomain(tctx
->lp_ctx
), false, 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(tctx
, expected1
->records
[1].printed
,
1018 talloc_asprintf(tctx
,
1019 "Failed to have putrr callback run name[%s] for type %s",
1020 expected1
->records
[1].name
,
1021 expected1
->records
[1].type
));
1022 torture_assert_int_equal(tctx
, expected1
->num_rr
, 2,
1023 "Got wrong record count");
1026 torture_assert_int_equal(tctx
, dlz_newversion(lpcfg_dnsdomain(tctx
->lp_ctx
),
1029 "Failed to start transaction");
1030 torture_assert_int_equal_goto(tctx
,
1031 dlz_delrdataset(name
,
1032 expected1
->records
[0].type
,
1034 ISC_R_SUCCESS
, ret
, cancel_version
,
1035 talloc_asprintf(tctx
, "Failed to delete name[%s] type[%s]\n",
1036 name
, expected1
->records
[0].type
));
1037 dlz_closeversion(lpcfg_dnsdomain(tctx
->lp_ctx
), true, dbdata
, &version
);
1040 expected1
->num_rr
= 0;
1041 expected1
->records
[0].printed
= false;
1042 expected1
->records
[1].printed
= false;
1043 torture_assert_int_equal(tctx
, dlz_lookup(lpcfg_dnsdomain(tctx
->lp_ctx
),
1044 expected1
->query_name
, dbdata
,
1045 (dns_sdlzlookup_t
*)expected1
),
1048 torture_assert_int_equal(tctx
, expected1
->num_rr
, 0,
1049 "Got wrong record count");
1051 dlz_destroy(dbdata
);
1056 dlz_closeversion(lpcfg_dnsdomain(tctx
->lp_ctx
), false, dbdata
, &version
);
1060 static struct torture_suite
*dlz_bind9_suite(TALLOC_CTX
*ctx
)
1062 struct torture_suite
*suite
= torture_suite_create(ctx
, "dlz_bind9");
1064 suite
->description
= talloc_strdup(suite
,
1065 "Tests for the BIND 9 DLZ module");
1066 torture_suite_add_simple_test(suite
, "version", test_dlz_bind9_version
);
1067 torture_suite_add_simple_test(suite
, "create", test_dlz_bind9_create
);
1068 torture_suite_add_simple_test(suite
, "configure", test_dlz_bind9_configure
);
1069 torture_suite_add_simple_test(suite
, "gssapi", test_dlz_bind9_gssapi
);
1070 torture_suite_add_simple_test(suite
, "spnego", test_dlz_bind9_spnego
);
1071 torture_suite_add_simple_test(suite
, "lookup", test_dlz_bind9_lookup
);
1072 torture_suite_add_simple_test(suite
, "zonedump", test_dlz_bind9_zonedump
);
1073 torture_suite_add_simple_test(suite
, "update01", test_dlz_bind9_update01
);
1078 * DNS torture module initialization
1080 NTSTATUS
torture_bind_dns_init(void);
1081 NTSTATUS
torture_bind_dns_init(void)
1083 struct torture_suite
*suite
;
1084 TALLOC_CTX
*mem_ctx
= talloc_autofree_context();
1086 /* register DNS related test cases */
1087 suite
= dlz_bind9_suite(mem_ctx
);
1088 if (!suite
) return NT_STATUS_NO_MEMORY
;
1089 torture_register_suite(suite
);
1091 return NT_STATUS_OK
;