torture-krb5: Add tests for combinations of enterprise, cannon, and different input...
[Samba.git] / source4 / torture / libnet / domain.c
blob71753de826dc8648a71b044cba9a497757f3f73d
1 /*
2 Unix SMB/CIFS implementation.
3 Test suite for libnet calls.
5 Copyright (C) Rafal Szczesniak 2005
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "includes.h"
22 #include "torture/rpc/torture_rpc.h"
23 #include "libnet/libnet.h"
24 #include "librpc/gen_ndr/ndr_samr_c.h"
25 #include "param/param.h"
26 #include "torture/libnet/proto.h"
28 static bool test_domainopen(struct torture_context *tctx,
29 struct libnet_context *net_ctx, TALLOC_CTX *mem_ctx,
30 struct lsa_String *domname,
31 struct policy_handle *domain_handle)
33 NTSTATUS status;
34 struct libnet_DomainOpen io;
36 torture_comment(tctx, "opening domain\n");
38 io.in.domain_name = talloc_strdup(mem_ctx, domname->string);
39 io.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
41 status = libnet_DomainOpen(net_ctx, mem_ctx, &io);
42 if (!NT_STATUS_IS_OK(status)) {
43 torture_comment(tctx, "Composite domain open failed for domain '%s' - %s\n",
44 domname->string, nt_errstr(status));
45 return false;
48 *domain_handle = io.out.domain_handle;
49 return true;
53 static bool test_cleanup(struct torture_context *tctx,
54 struct dcerpc_binding_handle *b, TALLOC_CTX *mem_ctx,
55 struct policy_handle *domain_handle)
57 struct samr_Close r;
58 struct policy_handle handle;
60 r.in.handle = domain_handle;
61 r.out.handle = &handle;
63 torture_comment(tctx, "closing domain handle\n");
65 torture_assert_ntstatus_ok(tctx,
66 dcerpc_samr_Close_r(b, mem_ctx, &r),
67 "Close failed");
68 torture_assert_ntstatus_ok(tctx, r.out.result,
69 "Close failed");
71 return true;
75 bool torture_domainopen(struct torture_context *torture)
77 NTSTATUS status;
78 struct libnet_context *net_ctx;
79 TALLOC_CTX *mem_ctx;
80 bool ret = true;
81 struct policy_handle h;
82 struct lsa_String name;
84 mem_ctx = talloc_init("test_domain_open");
86 net_ctx = libnet_context_init(torture->ev, torture->lp_ctx);
88 status = torture_rpc_connection(torture,
89 &net_ctx->samr.pipe,
90 &ndr_table_samr);
92 if (!NT_STATUS_IS_OK(status)) {
93 return false;
96 name.string = lpcfg_workgroup(torture->lp_ctx);
99 * Testing synchronous version
101 if (!test_domainopen(torture, net_ctx, mem_ctx, &name, &h)) {
102 ret = false;
103 goto done;
106 if (!test_cleanup(torture, net_ctx->samr.pipe->binding_handle, mem_ctx, &h)) {
107 ret = false;
108 goto done;
111 done:
112 talloc_free(mem_ctx);
114 return ret;