s4-smbtorture: use torture_context in libnet domain tests as well.
[gd/samba-autobuild/.git] / source4 / torture / libnet / domain.c
1 /*
2    Unix SMB/CIFS implementation.
3    Test suite for libnet calls.
4
5    Copyright (C) Rafal Szczesniak 2005
6
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.
11
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.
16
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/>.
19 */
20
21 #include "includes.h"
22 #include "torture/rpc/rpc.h"
23 #include "libnet/libnet.h"
24 #include "librpc/gen_ndr/ndr_samr_c.h"
25 #include "param/param.h"
26
27 static bool test_domainopen(struct torture_context *tctx,
28                             struct libnet_context *net_ctx, TALLOC_CTX *mem_ctx,
29                             struct lsa_String *domname,
30                             struct policy_handle *domain_handle)
31 {
32         NTSTATUS status;
33         struct libnet_DomainOpen io;
34
35         torture_comment(tctx, "opening domain\n");
36
37         io.in.domain_name  = talloc_strdup(mem_ctx, domname->string);
38         io.in.access_mask  = SEC_FLAG_MAXIMUM_ALLOWED;
39
40         status = libnet_DomainOpen(net_ctx, mem_ctx, &io);
41         if (!NT_STATUS_IS_OK(status)) {
42                 torture_comment(tctx, "Composite domain open failed - %s\n", nt_errstr(status));
43                 return false;
44         }
45
46         *domain_handle = io.out.domain_handle;
47         return true;
48 }
49
50
51 static bool test_cleanup(struct torture_context *tctx,
52                          struct dcerpc_binding_handle *b, TALLOC_CTX *mem_ctx,
53                          struct policy_handle *domain_handle)
54 {
55         NTSTATUS status;
56         struct samr_Close r;
57         struct policy_handle handle;
58
59         r.in.handle   = domain_handle;
60         r.out.handle  = &handle;
61
62         torture_comment(tctx, "closing domain handle\n");
63
64         status = dcerpc_samr_Close_r(b, mem_ctx, &r);
65         if (!NT_STATUS_IS_OK(status)) {
66                 torture_comment(tctx, "Close failed - %s\n", nt_errstr(status));
67                 return false;
68         }
69
70         return true;
71 }
72
73
74 bool torture_domainopen(struct torture_context *torture)
75 {
76         NTSTATUS status;
77         struct libnet_context *net_ctx;
78         TALLOC_CTX *mem_ctx;
79         bool ret = true;
80         struct policy_handle h;
81         struct lsa_String name;
82
83         mem_ctx = talloc_init("test_domain_open");
84
85         net_ctx = libnet_context_init(torture->ev, torture->lp_ctx);
86
87         status = torture_rpc_connection(torture,
88                                         &net_ctx->samr.pipe,
89                                         &ndr_table_samr);
90
91         if (!NT_STATUS_IS_OK(status)) {
92                 return false;
93         }
94
95         name.string = lp_workgroup(torture->lp_ctx);
96
97         /*
98          * Testing synchronous version
99          */
100         if (!test_domainopen(torture, net_ctx, mem_ctx, &name, &h)) {
101                 ret = false;
102                 goto done;
103         }
104
105         if (!test_cleanup(torture, net_ctx->samr.pipe->binding_handle, mem_ctx, &h)) {
106                 ret = false;
107                 goto done;
108         }
109
110 done:
111         talloc_free(mem_ctx);
112
113         return ret;
114 }