torture: Add discard_const_p() to work around dlz_create prototype
[Samba/gebeck_regimport.git] / source4 / torture / dns / dlz_bind9.c
blob6372ca8df624d27db365819fed6a34eea8bc478a
1 /*
2 Unix SMB/CIFS implementation.
3 SMB torture tester
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/>.
20 #include "includes.h"
21 #include "torture/smbtorture.h"
22 #include "dlz_minimal.h"
23 #include <talloc.h>
24 #include <ldb.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, ...)
34 va_list ap;
35 char *msg;
36 va_start(ap, fmt);
37 msg = talloc_vasprintf(NULL, fmt, ap);
38 torture_comment(tctx_static, "%s\n", msg);
39 TALLOC_FREE(msg);
40 va_end(ap);
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");
48 return true;
51 static bool test_dlz_bind9_create(struct torture_context *tctx)
53 void *dbdata;
54 const char *argv[] = {
55 "samba_dlz",
56 "-H",
57 lpcfg_private_path(tctx, tctx->lp_ctx, "dns/sam.ldb"),
58 NULL
60 tctx_static = tctx;
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");
65 dlz_destroy(dbdata);
67 return true;
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;
78 int ret;
79 const char *attrs[] = {
80 NULL
82 if (!samdb) {
83 torture_fail(tctx, "Failed to connect to samdb");
84 return ISC_R_FAILURE;
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)));
92 return ISC_R_FAILURE;
94 talloc_free(msg);
96 return ISC_R_SUCCESS;
99 static bool test_dlz_bind9_configure(struct torture_context *tctx)
101 void *dbdata;
102 const char *argv[] = {
103 "samba_dlz",
104 "-H",
105 lpcfg_private_path(tctx, tctx->lp_ctx, "dns/sam.ldb"),
106 NULL
108 tctx_static = tctx;
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),
112 ISC_R_SUCCESS,
113 "Failed to create samba_dlz");
115 torture_assert_int_equal(tctx, dlz_configure((void*)tctx, dbdata),
116 ISC_R_SUCCESS,
117 "Failed to configure samba_dlz");
119 dlz_destroy(dbdata);
121 return true;
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);
135 return suite;
139 * DNS torture module initialization
141 NTSTATUS torture_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);
151 return NT_STATUS_OK;