2 Unix SMB/CIFS implementation.
4 libcli composite function testing
6 Copyright (C) Andrew Tridgell 2005
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "torture/torture.h"
24 #include "lib/events/events.h"
25 #include "libcli/raw/libcliraw.h"
26 #include "libcli/libcli.h"
27 #include "libcli/security/security.h"
28 #include "libcli/composite/composite.h"
29 #include "libcli/smb_composite/smb_composite.h"
30 #include "librpc/gen_ndr/ndr_misc.h"
31 #include "lib/cmdline/popt_common.h"
32 #include "torture/util.h"
33 #include "param/param.h"
35 #define BASEDIR "\\composite"
37 static void loadfile_complete(struct composite_context *c)
39 int *count = talloc_get_type(c->async.private_data, int);
44 test a simple savefile/loadfile combination
46 static bool test_loadfile(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
48 const char *fname = BASEDIR "\\test.txt";
50 struct smb_composite_savefile io1;
51 struct smb_composite_loadfile io2;
52 struct composite_context **c;
54 size_t len = random() % 100000;
55 const int num_ops = 50;
57 int *count = talloc_zero(mem_ctx, int);
59 data = talloc_array(mem_ctx, uint8_t, len);
61 generate_random_buffer(data, len);
67 printf("testing savefile\n");
69 status = smb_composite_savefile(cli->tree, &io1);
70 if (!NT_STATUS_IS_OK(status)) {
71 printf("(%s) savefile failed: %s\n", __location__,nt_errstr(status));
77 printf("testing parallel loadfile with %d ops\n", num_ops);
79 c = talloc_array(mem_ctx, struct composite_context *, num_ops);
81 for (i=0;i<num_ops;i++) {
82 c[i] = smb_composite_loadfile_send(cli->tree, &io2);
83 c[i]->async.fn = loadfile_complete;
84 c[i]->async.private_data = count;
87 printf("waiting for completion\n");
88 while (*count != num_ops) {
89 event_loop_once(cli->transport->socket->event.ctx);
90 if (lp_parm_bool(global_loadparm, NULL, "torture", "progress", true)) {
91 printf("(%s) count=%d\r", __location__, *count);
95 printf("count=%d\n", *count);
97 for (i=0;i<num_ops;i++) {
98 status = smb_composite_loadfile_recv(c[i], mem_ctx);
99 if (!NT_STATUS_IS_OK(status)) {
100 printf("(%s) loadfile[%d] failed - %s\n", __location__, i, nt_errstr(status));
104 if (io2.out.size != len) {
105 printf("(%s) wrong length in returned data - %d should be %d\n",__location__,
106 io2.out.size, (int)len);
110 if (memcmp(io2.out.data, data, len) != 0) {
111 printf("(%s) wrong data in loadfile!\n",__location__);
122 test a simple savefile/loadfile combination
124 static bool test_fetchfile(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
126 const char *fname = BASEDIR "\\test.txt";
128 struct smb_composite_savefile io1;
129 struct smb_composite_fetchfile io2;
130 struct composite_context **c;
133 size_t len = random() % 10000;
134 extern int torture_numops;
135 struct event_context *event_ctx;
136 int *count = talloc_zero(mem_ctx, int);
139 data = talloc_array(mem_ctx, uint8_t, len);
141 generate_random_buffer(data, len);
143 io1.in.fname = fname;
147 printf("testing savefile\n");
149 status = smb_composite_savefile(cli->tree, &io1);
150 if (!NT_STATUS_IS_OK(status)) {
151 printf("(%s) savefile failed: %s\n",__location__, nt_errstr(status));
155 io2.in.dest_host = lp_parm_string(global_loadparm, NULL, "torture", "host");
157 io2.in.called_name = lp_parm_string(global_loadparm, NULL, "torture", "host");
158 io2.in.service = lp_parm_string(global_loadparm, NULL, "torture", "share");
159 io2.in.service_type = "A:";
161 io2.in.credentials = cmdline_credentials;
162 io2.in.workgroup = lp_workgroup(global_loadparm);
163 io2.in.filename = fname;
165 printf("testing parallel fetchfile with %d ops\n", torture_numops);
167 event_ctx = cli->transport->socket->event.ctx;
168 c = talloc_array(mem_ctx, struct composite_context *, torture_numops);
170 for (i=0; i<torture_numops; i++) {
171 c[i] = smb_composite_fetchfile_send(&io2, event_ctx);
172 c[i]->async.fn = loadfile_complete;
173 c[i]->async.private_data = count;
176 printf("waiting for completion\n");
178 while (*count != torture_numops) {
179 event_loop_once(event_ctx);
180 if (lp_parm_bool(global_loadparm, NULL, "torture", "progress", true)) {
181 printf("(%s) count=%d\r", __location__, *count);
185 printf("count=%d\n", *count);
187 for (i=0;i<torture_numops;i++) {
188 status = smb_composite_fetchfile_recv(c[i], mem_ctx);
189 if (!NT_STATUS_IS_OK(status)) {
190 printf("(%s) loadfile[%d] failed - %s\n", __location__, i,
196 if (io2.out.size != len) {
197 printf("(%s) wrong length in returned data - %d "
198 "should be %d\n", __location__,
199 io2.out.size, (int)len);
204 if (memcmp(io2.out.data, data, len) != 0) {
205 printf("(%s) wrong data in loadfile!\n", __location__);
217 static bool test_appendacl(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
219 struct smb_composite_appendacl **io;
220 struct smb_composite_appendacl **io_orig;
221 struct composite_context **c;
222 struct event_context *event_ctx;
224 struct security_descriptor *test_sd;
225 struct security_ace *ace;
226 struct dom_sid *test_sid;
228 const int num_ops = 50;
229 int *count = talloc_zero(mem_ctx, int);
230 struct smb_composite_savefile io1;
235 io_orig = talloc_array(mem_ctx, struct smb_composite_appendacl *, num_ops);
237 printf ("creating %d empty files and getting their acls with appendacl\n", num_ops);
239 for (i = 0; i < num_ops; i++) {
240 io1.in.fname = talloc_asprintf(io_orig, BASEDIR "\\test%d.txt", i);
244 status = smb_composite_savefile(cli->tree, &io1);
245 if (!NT_STATUS_IS_OK(status)) {
246 printf("(%s) savefile failed: %s\n", __location__, nt_errstr(status));
250 io_orig[i] = talloc (io_orig, struct smb_composite_appendacl);
251 io_orig[i]->in.fname = talloc_steal(io_orig[i], io1.in.fname);
252 io_orig[i]->in.sd = security_descriptor_initialise(io_orig[i]);
253 status = smb_composite_appendacl(cli->tree, io_orig[i], io_orig[i]);
254 if (!NT_STATUS_IS_OK(status)) {
255 printf("(%s) appendacl failed: %s\n", __location__, nt_errstr(status));
261 /* fill Security Descriptor with aces to be added */
263 test_sd = security_descriptor_initialise(mem_ctx);
264 test_sid = dom_sid_parse_talloc (mem_ctx, "S-1-5-32-1234-5432");
266 ace = talloc_zero(mem_ctx, struct security_ace);
268 ace->type = SEC_ACE_TYPE_ACCESS_ALLOWED;
270 ace->access_mask = SEC_STD_ALL;
271 ace->trustee = *test_sid;
273 status = security_descriptor_dacl_add(test_sd, ace);
274 if (!NT_STATUS_IS_OK(status)) {
275 printf("(%s) appendacl failed: %s\n", __location__, nt_errstr(status));
279 /* set parameters for appendacl async call */
281 printf("testing parallel appendacl with %d ops\n", num_ops);
283 c = talloc_array(mem_ctx, struct composite_context *, num_ops);
284 io = talloc_array(mem_ctx, struct smb_composite_appendacl *, num_ops);
286 for (i=0; i < num_ops; i++) {
287 io[i] = talloc (io, struct smb_composite_appendacl);
288 io[i]->in.sd = test_sd;
289 io[i]->in.fname = talloc_asprintf(io[i], BASEDIR "\\test%d.txt", i);
291 c[i] = smb_composite_appendacl_send(cli->tree, io[i]);
292 c[i]->async.fn = loadfile_complete;
293 c[i]->async.private_data = count;
296 event_ctx = talloc_reference(mem_ctx, cli->tree->session->transport->socket->event.ctx);
297 printf("waiting for completion\n");
298 while (*count != num_ops) {
299 event_loop_once(event_ctx);
300 if (lp_parm_bool(global_loadparm, NULL, "torture", "progress", true)) {
301 printf("(%s) count=%d\r", __location__, *count);
305 printf("count=%d\n", *count);
307 for (i=0; i < num_ops; i++) {
308 status = smb_composite_appendacl_recv(c[i], io[i]);
309 if (!NT_STATUS_IS_OK(status)) {
310 printf("(%s) appendacl[%d] failed - %s\n", __location__, i, nt_errstr(status));
314 security_descriptor_dacl_add(io_orig[i]->out.sd, ace);
315 if (!security_acl_equal(io_orig[i]->out.sd->dacl, io[i]->out.sd->dacl)) {
316 printf("(%s) appendacl[%d] failed - needed acl isn't set\n", __location__, i);
323 talloc_free (test_sid);
324 talloc_free (test_sd);
329 /* test a query FS info by asking for share's GUID */
330 static bool test_fsinfo(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
334 struct smb_composite_fsinfo io1;
335 struct composite_context **c;
338 extern int torture_numops;
339 struct event_context *event_ctx;
340 int *count = talloc_zero(mem_ctx, int);
343 io1.in.dest_host = lp_parm_string(global_loadparm, NULL, "torture", "host");
345 io1.in.called_name = lp_parm_string(global_loadparm, NULL, "torture", "host");
346 io1.in.service = lp_parm_string(global_loadparm, NULL, "torture", "share");
347 io1.in.service_type = "A:";
348 io1.in.credentials = cmdline_credentials;
349 io1.in.workgroup = lp_workgroup(global_loadparm);
350 io1.in.level = RAW_QFS_OBJECTID_INFORMATION;
352 printf("testing parallel queryfsinfo [Object ID] with %d ops\n", torture_numops);
354 event_ctx = talloc_reference(mem_ctx, cli->tree->session->transport->socket->event.ctx);
355 c = talloc_array(mem_ctx, struct composite_context *, torture_numops);
357 for (i=0; i<torture_numops; i++) {
358 c[i] = smb_composite_fsinfo_send(cli->tree,&io1);
359 c[i]->async.fn = loadfile_complete;
360 c[i]->async.private_data = count;
363 printf("waiting for completion\n");
365 while (*count < torture_numops) {
366 event_loop_once(event_ctx);
367 if (lp_parm_bool(global_loadparm, NULL, "torture", "progress", true)) {
368 printf("(%s) count=%d\r", __location__, *count);
372 printf("count=%d\n", *count);
374 for (i=0;i<torture_numops;i++) {
375 status = smb_composite_fsinfo_recv(c[i], mem_ctx);
376 if (!NT_STATUS_IS_OK(status)) {
377 printf("(%s) fsinfo[%d] failed - %s\n", __location__, i, nt_errstr(status));
382 if (io1.out.fsinfo->generic.level != RAW_QFS_OBJECTID_INFORMATION) {
383 printf("(%s) wrong level in returned info - %d "
384 "should be %d\n", __location__,
385 io1.out.fsinfo->generic.level, RAW_QFS_OBJECTID_INFORMATION);
390 guid=GUID_string(mem_ctx, &io1.out.fsinfo->objectid_information.out.guid);
391 printf("[%d] GUID: %s\n", i, guid);
401 basic testing of libcli composite calls
403 bool torture_raw_composite(struct torture_context *tctx,
404 struct smbcli_state *cli)
408 if (!torture_setup_dir(cli, BASEDIR)) {
412 ret &= test_fetchfile(cli, tctx);
413 ret &= test_loadfile(cli, tctx);
414 ret &= test_appendacl(cli, tctx);
415 ret &= test_fsinfo(cli, tctx);
417 smb_raw_exit(cli->session);
418 smbcli_deltree(cli->tree, BASEDIR);