Line data Source code
1 : /*
2 : Unix SMB/CIFS implementation.
3 : Test suite for libnet calls.
4 :
5 : Copyright (C) Rafal Szczesniak 2007
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 :
22 : #include "includes.h"
23 : #include "lib/cmdline/cmdline.h"
24 : #include "libnet/libnet.h"
25 : #include "librpc/gen_ndr/ndr_samr_c.h"
26 : #include "librpc/gen_ndr/ndr_lsa_c.h"
27 : #include "torture/rpc/torture_rpc.h"
28 : #include "torture/libnet/proto.h"
29 : #include "param/param.h"
30 :
31 :
32 : #define TEST_GROUPNAME "libnetgrouptest"
33 :
34 :
35 1 : bool torture_groupinfo_api(struct torture_context *torture)
36 : {
37 1 : const char *name = TEST_GROUPNAME;
38 1 : bool ret = true;
39 0 : NTSTATUS status;
40 1 : TALLOC_CTX *mem_ctx = NULL, *prep_mem_ctx;
41 1 : struct libnet_context *ctx = NULL;
42 0 : struct dcerpc_pipe *p;
43 0 : struct policy_handle h;
44 0 : struct lsa_String domain_name;
45 0 : struct libnet_GroupInfo req;
46 :
47 1 : prep_mem_ctx = talloc_init("prepare torture group info");
48 :
49 1 : status = torture_rpc_connection(torture,
50 : &p,
51 : &ndr_table_samr);
52 1 : if (!NT_STATUS_IS_OK(status)) {
53 0 : return false;
54 : }
55 :
56 1 : domain_name.string = lpcfg_workgroup(torture->lp_ctx);
57 1 : if (!test_domain_open(torture, p->binding_handle, &domain_name, prep_mem_ctx, &h, NULL)) {
58 0 : ret = false;
59 0 : goto done;
60 : }
61 :
62 1 : if (!test_group_create(torture, p->binding_handle, prep_mem_ctx, &h, name, NULL)) {
63 0 : ret = false;
64 0 : goto done;
65 : }
66 :
67 1 : mem_ctx = talloc_init("torture group info");
68 :
69 1 : if (!test_libnet_context_init(torture, true, &ctx)) {
70 0 : return false;
71 : }
72 :
73 1 : ZERO_STRUCT(req);
74 :
75 1 : req.in.domain_name = domain_name.string;
76 1 : req.in.level = GROUP_INFO_BY_NAME;
77 1 : req.in.data.group_name = name;
78 :
79 1 : status = libnet_GroupInfo(ctx, mem_ctx, &req);
80 1 : if (!NT_STATUS_IS_OK(status)) {
81 0 : torture_comment(torture, "libnet_GroupInfo call failed: %s\n", nt_errstr(status));
82 0 : ret = false;
83 0 : goto done;
84 : }
85 :
86 1 : if (!test_group_cleanup(torture, ctx->samr.pipe->binding_handle,
87 1 : mem_ctx, &ctx->samr.handle, TEST_GROUPNAME)) {
88 0 : torture_comment(torture, "cleanup failed\n");
89 0 : ret = false;
90 0 : goto done;
91 : }
92 :
93 1 : if (!test_samr_close_handle(torture,
94 1 : ctx->samr.pipe->binding_handle, mem_ctx, &ctx->samr.handle)) {
95 0 : torture_comment(torture, "domain close failed\n");
96 0 : ret = false;
97 : }
98 :
99 1 : done:
100 1 : talloc_free(ctx);
101 1 : talloc_free(mem_ctx);
102 1 : return ret;
103 : }
104 :
105 :
106 1 : bool torture_grouplist(struct torture_context *torture)
107 : {
108 1 : bool ret = true;
109 0 : NTSTATUS status;
110 1 : TALLOC_CTX *mem_ctx = NULL;
111 0 : struct libnet_context *ctx;
112 0 : struct lsa_String domain_name;
113 0 : struct libnet_GroupList req;
114 0 : int i;
115 :
116 1 : ctx = libnet_context_init(torture->ev, torture->lp_ctx);
117 1 : ctx->cred = samba_cmdline_get_creds();
118 :
119 1 : domain_name.string = lpcfg_workgroup(torture->lp_ctx);
120 1 : mem_ctx = talloc_init("torture group list");
121 :
122 1 : ZERO_STRUCT(req);
123 :
124 1 : torture_comment(torture, "listing group accounts:\n");
125 :
126 0 : do {
127 5 : req.in.domain_name = domain_name.string;
128 5 : req.in.page_size = 128;
129 5 : req.in.resume_index = req.out.resume_index;
130 :
131 5 : status = libnet_GroupList(ctx, mem_ctx, &req);
132 5 : if (!NT_STATUS_IS_OK(status) &&
133 4 : !NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES)) break;
134 :
135 18 : for (i = 0; i < req.out.count; i++) {
136 13 : torture_comment(torture, "\tgroup: %s, sid=%s\n",
137 13 : req.out.groups[i].groupname, req.out.groups[i].sid);
138 : }
139 :
140 5 : } while (NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES));
141 :
142 1 : if (!(NT_STATUS_IS_OK(status) ||
143 0 : NT_STATUS_EQUAL(status, NT_STATUS_NO_MORE_ENTRIES))) {
144 0 : torture_comment(torture, "libnet_GroupList call failed: %s\n", nt_errstr(status));
145 0 : ret = false;
146 0 : goto done;
147 : }
148 :
149 1 : if (!test_samr_close_handle(torture,
150 1 : ctx->samr.pipe->binding_handle, mem_ctx, &ctx->samr.handle)) {
151 0 : torture_comment(torture, "domain close failed\n");
152 0 : ret = false;
153 : }
154 :
155 1 : if (!test_lsa_close_handle(torture,
156 1 : ctx->lsa.pipe->binding_handle, mem_ctx, &ctx->lsa.handle)) {
157 0 : torture_comment(torture, "lsa domain close failed\n");
158 0 : ret = false;
159 : }
160 :
161 1 : talloc_free(ctx);
162 :
163 1 : done:
164 1 : talloc_free(mem_ctx);
165 1 : return ret;
166 : }
167 :
168 :
169 1 : bool torture_creategroup(struct torture_context *torture)
170 : {
171 1 : bool ret = true;
172 0 : NTSTATUS status;
173 1 : TALLOC_CTX *mem_ctx = NULL;
174 0 : struct libnet_context *ctx;
175 0 : struct libnet_CreateGroup req;
176 :
177 1 : mem_ctx = talloc_init("test_creategroup");
178 :
179 1 : ctx = libnet_context_init(torture->ev, torture->lp_ctx);
180 1 : ctx->cred = samba_cmdline_get_creds();
181 :
182 1 : req.in.group_name = TEST_GROUPNAME;
183 1 : req.in.domain_name = lpcfg_workgroup(torture->lp_ctx);
184 1 : req.out.error_string = NULL;
185 :
186 1 : status = libnet_CreateGroup(ctx, mem_ctx, &req);
187 1 : if (!NT_STATUS_IS_OK(status)) {
188 0 : torture_comment(torture, "libnet_CreateGroup call failed: %s\n", nt_errstr(status));
189 0 : ret = false;
190 0 : goto done;
191 : }
192 :
193 1 : if (!test_group_cleanup(torture, ctx->samr.pipe->binding_handle,
194 : mem_ctx, &ctx->samr.handle, TEST_GROUPNAME)) {
195 0 : torture_comment(torture, "cleanup failed\n");
196 0 : ret = false;
197 0 : goto done;
198 : }
199 :
200 1 : if (!test_samr_close_handle(torture,
201 1 : ctx->samr.pipe->binding_handle, mem_ctx, &ctx->samr.handle)) {
202 0 : torture_comment(torture, "domain close failed\n");
203 0 : ret = false;
204 : }
205 :
206 1 : done:
207 1 : talloc_free(ctx);
208 1 : talloc_free(mem_ctx);
209 1 : return ret;
210 : }
|