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_lsa_close(struct torture_context *tctx,
36 struct dcerpc_binding_handle *b, TALLOC_CTX *mem_ctx,
37 struct policy_handle *domain_handle)
41 r.in.handle = domain_handle;
42 r.out.handle = domain_handle;
44 torture_assert_ntstatus_ok(tctx,
45 dcerpc_lsa_Close_r(b, mem_ctx, &r),
46 "Close lsa domain failed");
47 torture_assert_ntstatus_ok(tctx, r.out.result,
48 "Close lsa domain failed");
54 bool torture_groupinfo_api(struct torture_context *torture)
56 const char *name = TEST_GROUPNAME;
59 TALLOC_CTX *mem_ctx = NULL, *prep_mem_ctx;
60 struct libnet_context *ctx = NULL;
61 struct dcerpc_pipe *p;
62 struct policy_handle h;
63 struct lsa_String domain_name;
64 struct libnet_GroupInfo req;
66 prep_mem_ctx = talloc_init("prepare torture group info");
68 status = torture_rpc_connection(torture,
71 if (!NT_STATUS_IS_OK(status)) {
75 domain_name.string = lp_workgroup(torture->lp_ctx);
76 if (!test_domain_open(torture, p->binding_handle, &domain_name, prep_mem_ctx, &h, NULL)) {
81 if (!test_group_create(torture, p->binding_handle, prep_mem_ctx, &h, name, NULL)) {
86 mem_ctx = talloc_init("torture group info");
88 if (!test_libnet_context_init(torture, true, &ctx)) {
94 req.in.domain_name = domain_name.string;
95 req.in.level = GROUP_INFO_BY_NAME;
96 req.in.data.group_name = name;
98 status = libnet_GroupInfo(ctx, mem_ctx, &req);
99 if (!NT_STATUS_IS_OK(status)) {
100 torture_comment(torture, "libnet_GroupInfo call failed: %s\n", nt_errstr(status));
105 if (!test_group_cleanup(torture, ctx->samr.pipe->binding_handle, mem_ctx, &ctx->samr.handle, TEST_GROUPNAME)) {
106 torture_comment(torture, "cleanup failed\n");
111 if (!test_samr_close_handle(torture,
112 ctx->samr.pipe->binding_handle, mem_ctx, &ctx->samr.handle)) {
113 torture_comment(torture, "domain close failed\n");
119 talloc_free(mem_ctx);
124 bool torture_grouplist(struct torture_context *torture)
128 TALLOC_CTX *mem_ctx = NULL;
129 struct libnet_context *ctx;
130 struct lsa_String domain_name;
131 struct libnet_GroupList req;
134 ctx = libnet_context_init(torture->ev, torture->lp_ctx);
135 ctx->cred = cmdline_credentials;
137 domain_name.string = lp_workgroup(torture->lp_ctx);
138 mem_ctx = talloc_init("torture group list");
142 torture_comment(torture, "listing group accounts:\n");
145 req.in.domain_name = domain_name.string;
146 req.in.page_size = 128;
147 req.in.resume_index = req.out.resume_index;
149 status = libnet_GroupList(ctx, mem_ctx, &req);
150 if (!NT_STATUS_IS_OK(status) &&
151 !NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES)) break;
153 for (i = 0; i < req.out.count; i++) {
154 torture_comment(torture, "\tgroup: %s, sid=%s\n",
155 req.out.groups[i].groupname, req.out.groups[i].sid);
158 } while (NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES));
160 if (!(NT_STATUS_IS_OK(status) ||
161 NT_STATUS_EQUAL(status, NT_STATUS_NO_MORE_ENTRIES))) {
162 torture_comment(torture, "libnet_GroupList call failed: %s\n", nt_errstr(status));
167 if (!test_samr_close_handle(torture,
168 ctx->samr.pipe->binding_handle, mem_ctx, &ctx->samr.handle)) {
169 torture_comment(torture, "domain close failed\n");
173 if (!test_lsa_close(torture, ctx->lsa.pipe->binding_handle, mem_ctx, &ctx->lsa.handle)) {
174 torture_comment(torture, "lsa domain close failed\n");
181 talloc_free(mem_ctx);
186 bool torture_creategroup(struct torture_context *torture)
190 TALLOC_CTX *mem_ctx = NULL;
191 struct libnet_context *ctx;
192 struct libnet_CreateGroup req;
194 mem_ctx = talloc_init("test_creategroup");
196 ctx = libnet_context_init(torture->ev, torture->lp_ctx);
197 ctx->cred = cmdline_credentials;
199 req.in.group_name = TEST_GROUPNAME;
200 req.in.domain_name = lp_workgroup(torture->lp_ctx);
201 req.out.error_string = NULL;
203 status = libnet_CreateGroup(ctx, mem_ctx, &req);
204 if (!NT_STATUS_IS_OK(status)) {
205 torture_comment(torture, "libnet_CreateGroup call failed: %s\n", nt_errstr(status));
210 if (!test_group_cleanup(torture, ctx->samr.pipe->binding_handle, mem_ctx, &ctx->samr.handle, TEST_GROUPNAME)) {
211 torture_comment(torture, "cleanup failed\n");
216 if (!test_samr_close_handle(torture,
217 ctx->samr.pipe->binding_handle, mem_ctx, &ctx->samr.handle)) {
218 torture_comment(torture, "domain close failed\n");
224 talloc_free(mem_ctx);