2 Unix SMB/CIFS implementation.
3 Test suite for libnet calls.
5 Copyright (C) Rafal Szczesniak 2007
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/>.
23 #include "lib/cmdline/popt_common.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"
32 #define TEST_GROUPNAME "libnetgrouptest"
35 static bool test_cleanup(struct torture_context *tctx,
36 struct dcerpc_binding_handle *b, TALLOC_CTX *mem_ctx,
37 struct policy_handle *domain_handle, const char *groupname)
39 struct samr_LookupNames r1;
40 struct samr_OpenGroup r2;
41 struct samr_DeleteDomainGroup r3;
42 struct lsa_String names[2];
44 struct policy_handle group_handle;
45 struct samr_Ids rids, types;
47 names[0].string = groupname;
49 r1.in.domain_handle = domain_handle;
53 r1.out.types = &types;
55 torture_comment(tctx, "group account lookup '%s'\n", groupname);
57 torture_assert_ntstatus_ok(tctx,
58 dcerpc_samr_LookupNames_r(b, mem_ctx, &r1),
59 "LookupNames failed");
60 torture_assert_ntstatus_ok(tctx, r1.out.result,
61 "LookupNames failed");
63 rid = r1.out.rids->ids[0];
65 r2.in.domain_handle = domain_handle;
66 r2.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
68 r2.out.group_handle = &group_handle;
70 torture_comment(tctx, "opening group account\n");
72 torture_assert_ntstatus_ok(tctx,
73 dcerpc_samr_OpenGroup_r(b, mem_ctx, &r2),
75 torture_assert_ntstatus_ok(tctx, r2.out.result,
78 r3.in.group_handle = &group_handle;
79 r3.out.group_handle = &group_handle;
81 torture_comment(tctx, "deleting group account\n");
83 torture_assert_ntstatus_ok(tctx,
84 dcerpc_samr_DeleteDomainGroup_r(b, mem_ctx, &r3),
85 "DeleteGroup failed");
86 torture_assert_ntstatus_ok(tctx, r3.out.result,
87 "DeleteGroup failed");
93 static bool test_creategroup(struct torture_context *tctx,
94 struct dcerpc_binding_handle *b, TALLOC_CTX *mem_ctx,
95 struct policy_handle *handle, const char *name)
97 struct lsa_String groupname;
98 struct samr_CreateDomainGroup r;
99 struct policy_handle group_handle;
102 groupname.string = name;
104 r.in.domain_handle = handle;
105 r.in.name = &groupname;
106 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
107 r.out.group_handle = &group_handle;
108 r.out.rid = &group_rid;
110 torture_comment(tctx, "creating group account %s\n", name);
112 torture_assert_ntstatus_ok(tctx,
113 dcerpc_samr_CreateDomainGroup_r(b, mem_ctx, &r),
114 "CreateGroup failed");
116 if (!NT_STATUS_IS_OK(r.out.result)) {
117 torture_comment(tctx, "CreateGroup failed - %s\n", nt_errstr(r.out.result));
119 if (NT_STATUS_EQUAL(r.out.result, NT_STATUS_GROUP_EXISTS)) {
120 torture_comment(tctx, "Group (%s) already exists - attempting to delete and recreate group again\n", name);
121 if (!test_cleanup(tctx, b, mem_ctx, handle, TEST_GROUPNAME)) {
125 torture_comment(tctx, "creating group account\n");
127 torture_assert_ntstatus_ok(tctx,
128 dcerpc_samr_CreateDomainGroup_r(b, mem_ctx, &r),
129 "CreateGroup failed");
130 torture_assert_ntstatus_ok(tctx, r.out.result,
131 "CreateGroup failed");
142 static bool test_lsa_close(struct torture_context *tctx,
143 struct dcerpc_binding_handle *b, TALLOC_CTX *mem_ctx,
144 struct policy_handle *domain_handle)
148 r.in.handle = domain_handle;
149 r.out.handle = domain_handle;
151 torture_assert_ntstatus_ok(tctx,
152 dcerpc_lsa_Close_r(b, mem_ctx, &r),
153 "Close lsa domain failed");
154 torture_assert_ntstatus_ok(tctx, r.out.result,
155 "Close lsa domain failed");
161 bool torture_groupinfo_api(struct torture_context *torture)
163 const char *name = TEST_GROUPNAME;
166 TALLOC_CTX *mem_ctx = NULL, *prep_mem_ctx;
167 struct libnet_context *ctx;
168 struct dcerpc_pipe *p;
169 struct policy_handle h;
170 struct lsa_String domain_name;
171 struct libnet_GroupInfo req;
173 prep_mem_ctx = talloc_init("prepare torture group info");
175 ctx = libnet_context_init(torture->ev, torture->lp_ctx);
176 ctx->cred = cmdline_credentials;
178 status = torture_rpc_connection(torture,
181 if (!NT_STATUS_IS_OK(status)) {
185 domain_name.string = lp_workgroup(torture->lp_ctx);
186 if (!test_domain_open(torture, p->binding_handle, &domain_name, prep_mem_ctx, &h, NULL)) {
191 if (!test_creategroup(torture, p->binding_handle, prep_mem_ctx, &h, name)) {
196 mem_ctx = talloc_init("torture group info");
200 req.in.domain_name = domain_name.string;
201 req.in.level = GROUP_INFO_BY_NAME;
202 req.in.data.group_name = name;
204 status = libnet_GroupInfo(ctx, mem_ctx, &req);
205 if (!NT_STATUS_IS_OK(status)) {
206 torture_comment(torture, "libnet_GroupInfo call failed: %s\n", nt_errstr(status));
211 if (!test_cleanup(torture, ctx->samr.pipe->binding_handle, mem_ctx, &ctx->samr.handle, TEST_GROUPNAME)) {
212 torture_comment(torture, "cleanup failed\n");
217 if (!test_samr_close_handle(torture,
218 ctx->samr.pipe->binding_handle, mem_ctx, &ctx->samr.handle)) {
219 torture_comment(torture, "domain close failed\n");
226 talloc_free(mem_ctx);
231 bool torture_grouplist(struct torture_context *torture)
235 TALLOC_CTX *mem_ctx = NULL;
236 struct libnet_context *ctx;
237 struct lsa_String domain_name;
238 struct libnet_GroupList req;
241 ctx = libnet_context_init(torture->ev, torture->lp_ctx);
242 ctx->cred = cmdline_credentials;
244 domain_name.string = lp_workgroup(torture->lp_ctx);
245 mem_ctx = talloc_init("torture group list");
249 torture_comment(torture, "listing group accounts:\n");
252 req.in.domain_name = domain_name.string;
253 req.in.page_size = 128;
254 req.in.resume_index = req.out.resume_index;
256 status = libnet_GroupList(ctx, mem_ctx, &req);
257 if (!NT_STATUS_IS_OK(status) &&
258 !NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES)) break;
260 for (i = 0; i < req.out.count; i++) {
261 torture_comment(torture, "\tgroup: %s, sid=%s\n",
262 req.out.groups[i].groupname, req.out.groups[i].sid);
265 } while (NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES));
267 if (!(NT_STATUS_IS_OK(status) ||
268 NT_STATUS_EQUAL(status, NT_STATUS_NO_MORE_ENTRIES))) {
269 torture_comment(torture, "libnet_GroupList call failed: %s\n", nt_errstr(status));
274 if (!test_samr_close_handle(torture,
275 ctx->samr.pipe->binding_handle, mem_ctx, &ctx->samr.handle)) {
276 torture_comment(torture, "domain close failed\n");
280 if (!test_lsa_close(torture, ctx->lsa.pipe->binding_handle, mem_ctx, &ctx->lsa.handle)) {
281 torture_comment(torture, "lsa domain close failed\n");
288 talloc_free(mem_ctx);
293 bool torture_creategroup(struct torture_context *torture)
297 TALLOC_CTX *mem_ctx = NULL;
298 struct libnet_context *ctx;
299 struct libnet_CreateGroup req;
301 mem_ctx = talloc_init("test_creategroup");
303 ctx = libnet_context_init(torture->ev, torture->lp_ctx);
304 ctx->cred = cmdline_credentials;
306 req.in.group_name = TEST_GROUPNAME;
307 req.in.domain_name = lp_workgroup(torture->lp_ctx);
308 req.out.error_string = NULL;
310 status = libnet_CreateGroup(ctx, mem_ctx, &req);
311 if (!NT_STATUS_IS_OK(status)) {
312 torture_comment(torture, "libnet_CreateGroup call failed: %s\n", nt_errstr(status));
317 if (!test_cleanup(torture, ctx->samr.pipe->binding_handle, mem_ctx, &ctx->samr.handle, TEST_GROUPNAME)) {
318 torture_comment(torture, "cleanup failed\n");
323 if (!test_samr_close_handle(torture,
324 ctx->samr.pipe->binding_handle, mem_ctx, &ctx->samr.handle)) {
325 torture_comment(torture, "domain close failed\n");
331 talloc_free(mem_ctx);