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"
30 struct torture_context
*tctx_static
;
32 static void dlz_bind9_log_wrapper(int level
, const char *fmt
, ...)
37 msg
= talloc_vasprintf(NULL
, fmt
, ap
);
38 torture_comment(tctx_static
, "%s\n", msg
);
43 static bool test_dlz_bind9_version(struct torture_context
*tctx
)
45 unsigned int flags
= 0;
46 torture_assert_int_equal(tctx
, dlz_version(&flags
),
47 DLZ_DLOPEN_VERSION
, "got wrong DLZ version");
51 static bool test_dlz_bind9_create(struct torture_context
*tctx
)
54 const char *argv
[] = {
57 lpcfg_private_path(tctx
, tctx
->lp_ctx
, "dns/sam.ldb"),
61 torture_assert_int_equal(tctx
, dlz_create("samba_dlz", 3, discard_const_p(char *, argv
), &dbdata
,
62 "log", dlz_bind9_log_wrapper
, NULL
), ISC_R_SUCCESS
,
63 "Failed to create samba_dlz");
70 static isc_result_t
dlz_bind9_writeable_zone_hook(dns_view_t
*view
,
71 const char *zone_name
)
73 struct torture_context
*tctx
= talloc_get_type((void *)view
, struct torture_context
);
74 struct ldb_context
*samdb
= samdb_connect_url(tctx
, NULL
, tctx
->lp_ctx
,
75 system_session(tctx
->lp_ctx
),
76 0, lpcfg_private_path(tctx
, tctx
->lp_ctx
, "dns/sam.ldb"));
77 struct ldb_message
*msg
;
79 const char *attrs
[] = {
83 torture_fail(tctx
, "Failed to connect to samdb");
87 ret
= dsdb_search_one(samdb
, tctx
, &msg
, NULL
,
88 LDB_SCOPE_SUBTREE
, attrs
, DSDB_SEARCH_SEARCH_ALL_PARTITIONS
,
89 "(&(objectClass=dnsZone)(name=%s))", zone_name
);
90 if (ret
!= LDB_SUCCESS
) {
91 torture_fail(tctx
, talloc_asprintf(tctx
, "Failed to search for %s: %s", zone_name
, ldb_errstring(samdb
)));
99 static bool test_dlz_bind9_configure(struct torture_context
*tctx
)
102 const char *argv
[] = {
105 lpcfg_private_path(tctx
, tctx
->lp_ctx
, "dns/sam.ldb"),
109 torture_assert_int_equal(tctx
, dlz_create("samba_dlz", 3, discard_const_p(char *, argv
), &dbdata
,
110 "log", dlz_bind9_log_wrapper
,
111 "writeable_zone", dlz_bind9_writeable_zone_hook
, NULL
),
113 "Failed to create samba_dlz");
115 torture_assert_int_equal(tctx
, dlz_configure((void*)tctx
, dbdata
),
117 "Failed to configure samba_dlz");
126 static struct torture_suite
*dlz_bind9_suite(TALLOC_CTX
*ctx
)
128 struct torture_suite
*suite
= torture_suite_create(ctx
, "dlz_bind9");
130 suite
->description
= talloc_strdup(suite
,
131 "Tests for the BIND 9 DLZ module");
132 torture_suite_add_simple_test(suite
, "version", test_dlz_bind9_version
);
133 torture_suite_add_simple_test(suite
, "create", test_dlz_bind9_create
);
134 torture_suite_add_simple_test(suite
, "configure", test_dlz_bind9_configure
);
139 * DNS torture module initialization
141 NTSTATUS
torture_bind_dns_init(void)
143 struct torture_suite
*suite
;
144 TALLOC_CTX
*mem_ctx
= talloc_autofree_context();
146 /* register DNS related test cases */
147 suite
= dlz_bind9_suite(mem_ctx
);
148 if (!suite
) return NT_STATUS_NO_MEMORY
;
149 torture_register_suite(suite
);