s3:vfs: change files_struct.fnum from int to uint64_t
[Samba.git] / source4 / torture / libnet / libnet_group.c
blobf76587c1083914fb43d0bd9ffabe78ce8afaec52
1 /*
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/>.
22 #include "includes.h"
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 bool torture_groupinfo_api(struct torture_context *torture)
37 const char *name = TEST_GROUPNAME;
38 bool ret = true;
39 NTSTATUS status;
40 TALLOC_CTX *mem_ctx = NULL, *prep_mem_ctx;
41 struct libnet_context *ctx = NULL;
42 struct dcerpc_pipe *p;
43 struct policy_handle h;
44 struct lsa_String domain_name;
45 struct libnet_GroupInfo req;
47 prep_mem_ctx = talloc_init("prepare torture group info");
49 status = torture_rpc_connection(torture,
50 &p,
51 &ndr_table_samr);
52 if (!NT_STATUS_IS_OK(status)) {
53 return false;
56 domain_name.string = lpcfg_workgroup(torture->lp_ctx);
57 if (!test_domain_open(torture, p->binding_handle, &domain_name, prep_mem_ctx, &h, NULL)) {
58 ret = false;
59 goto done;
62 if (!test_group_create(torture, p->binding_handle, prep_mem_ctx, &h, name, NULL)) {
63 ret = false;
64 goto done;
67 mem_ctx = talloc_init("torture group info");
69 if (!test_libnet_context_init(torture, true, &ctx)) {
70 return false;
73 ZERO_STRUCT(req);
75 req.in.domain_name = domain_name.string;
76 req.in.level = GROUP_INFO_BY_NAME;
77 req.in.data.group_name = name;
79 status = libnet_GroupInfo(ctx, mem_ctx, &req);
80 if (!NT_STATUS_IS_OK(status)) {
81 torture_comment(torture, "libnet_GroupInfo call failed: %s\n", nt_errstr(status));
82 ret = false;
83 goto done;
86 if (!test_group_cleanup(torture, ctx->samr.pipe->binding_handle,
87 mem_ctx, &ctx->samr.handle, TEST_GROUPNAME)) {
88 torture_comment(torture, "cleanup failed\n");
89 ret = false;
90 goto done;
93 if (!test_samr_close_handle(torture,
94 ctx->samr.pipe->binding_handle, mem_ctx, &ctx->samr.handle)) {
95 torture_comment(torture, "domain close failed\n");
96 ret = false;
99 done:
100 talloc_free(ctx);
101 talloc_free(mem_ctx);
102 return ret;
106 bool torture_grouplist(struct torture_context *torture)
108 bool ret = true;
109 NTSTATUS status;
110 TALLOC_CTX *mem_ctx = NULL;
111 struct libnet_context *ctx;
112 struct lsa_String domain_name;
113 struct libnet_GroupList req;
114 int i;
116 ctx = libnet_context_init(torture->ev, torture->lp_ctx);
117 ctx->cred = cmdline_credentials;
119 domain_name.string = lpcfg_workgroup(torture->lp_ctx);
120 mem_ctx = talloc_init("torture group list");
122 ZERO_STRUCT(req);
124 torture_comment(torture, "listing group accounts:\n");
126 do {
127 req.in.domain_name = domain_name.string;
128 req.in.page_size = 128;
129 req.in.resume_index = req.out.resume_index;
131 status = libnet_GroupList(ctx, mem_ctx, &req);
132 if (!NT_STATUS_IS_OK(status) &&
133 !NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES)) break;
135 for (i = 0; i < req.out.count; i++) {
136 torture_comment(torture, "\tgroup: %s, sid=%s\n",
137 req.out.groups[i].groupname, req.out.groups[i].sid);
140 } while (NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES));
142 if (!(NT_STATUS_IS_OK(status) ||
143 NT_STATUS_EQUAL(status, NT_STATUS_NO_MORE_ENTRIES))) {
144 torture_comment(torture, "libnet_GroupList call failed: %s\n", nt_errstr(status));
145 ret = false;
146 goto done;
149 if (!test_samr_close_handle(torture,
150 ctx->samr.pipe->binding_handle, mem_ctx, &ctx->samr.handle)) {
151 torture_comment(torture, "domain close failed\n");
152 ret = false;
155 if (!test_lsa_close_handle(torture,
156 ctx->lsa.pipe->binding_handle, mem_ctx, &ctx->lsa.handle)) {
157 torture_comment(torture, "lsa domain close failed\n");
158 ret = false;
161 talloc_free(ctx);
163 done:
164 talloc_free(mem_ctx);
165 return ret;
169 bool torture_creategroup(struct torture_context *torture)
171 bool ret = true;
172 NTSTATUS status;
173 TALLOC_CTX *mem_ctx = NULL;
174 struct libnet_context *ctx;
175 struct libnet_CreateGroup req;
177 mem_ctx = talloc_init("test_creategroup");
179 ctx = libnet_context_init(torture->ev, torture->lp_ctx);
180 ctx->cred = cmdline_credentials;
182 req.in.group_name = TEST_GROUPNAME;
183 req.in.domain_name = lpcfg_workgroup(torture->lp_ctx);
184 req.out.error_string = NULL;
186 status = libnet_CreateGroup(ctx, mem_ctx, &req);
187 if (!NT_STATUS_IS_OK(status)) {
188 torture_comment(torture, "libnet_CreateGroup call failed: %s\n", nt_errstr(status));
189 ret = false;
190 goto done;
193 if (!test_group_cleanup(torture, ctx->samr.pipe->binding_handle,
194 mem_ctx, &ctx->samr.handle, TEST_GROUPNAME)) {
195 torture_comment(torture, "cleanup failed\n");
196 ret = false;
197 goto done;
200 if (!test_samr_close_handle(torture,
201 ctx->samr.pipe->binding_handle, mem_ctx, &ctx->samr.handle)) {
202 torture_comment(torture, "domain close failed\n");
203 ret = false;
206 done:
207 talloc_free(ctx);
208 talloc_free(mem_ctx);
209 return ret;