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 2 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, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "torture/torture.h"
25 #include "lib/events/events.h"
26 #include "libcli/raw/libcliraw.h"
27 #include "libcli/libcli.h"
28 #include "libcli/security/proto.h"
29 #include "libcli/composite/composite.h"
30 #include "libcli/smb_composite/smb_composite.h"
31 #include "lib/cmdline/popt_common.h"
32 #include "librpc/gen_ndr/ndr_security.h"
34 #define BASEDIR "\\composite"
36 static void loadfile_complete(struct composite_context *c)
38 int *count = talloc_get_type(c->async.private_data, int);
43 test a simple savefile/loadfile combination
45 static BOOL test_loadfile(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
47 const char *fname = BASEDIR "\\test.txt";
49 struct smb_composite_savefile io1;
50 struct smb_composite_loadfile io2;
51 struct composite_context **c;
53 size_t len = random() % 100000;
54 const int num_ops = 50;
56 int *count = talloc_zero(mem_ctx, int);
58 data = talloc_array(mem_ctx, uint8_t, len);
60 generate_random_buffer(data, len);
66 printf("testing savefile\n");
68 status = smb_composite_savefile(cli->tree, &io1);
69 if (!NT_STATUS_IS_OK(status)) {
70 printf("savefile failed: %s\n", nt_errstr(status));
76 printf("testing parallel loadfile with %d ops\n", num_ops);
78 c = talloc_array(mem_ctx, struct composite_context *, num_ops);
80 for (i=0;i<num_ops;i++) {
81 c[i] = smb_composite_loadfile_send(cli->tree, &io2);
82 c[i]->async.fn = loadfile_complete;
83 c[i]->async.private_data = count;
86 printf("waiting for completion\n");
87 while (*count != num_ops) {
88 event_loop_once(cli->transport->socket->event.ctx);
89 printf("count=%d\r", *count);
92 printf("count=%d\n", *count);
94 for (i=0;i<num_ops;i++) {
95 status = smb_composite_loadfile_recv(c[i], mem_ctx);
96 if (!NT_STATUS_IS_OK(status)) {
97 printf("loadfile[%d] failed - %s\n", i, nt_errstr(status));
101 if (io2.out.size != len) {
102 printf("wrong length in returned data - %d should be %d\n",
103 io2.out.size, (int)len);
107 if (memcmp(io2.out.data, data, len) != 0) {
108 printf("wrong data in loadfile!\n");
119 test a simple savefile/loadfile combination
121 static BOOL test_fetchfile(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
123 const char *fname = BASEDIR "\\test.txt";
125 struct smb_composite_savefile io1;
126 struct smb_composite_fetchfile io2;
127 struct composite_context **c;
130 size_t len = random() % 10000;
131 extern int torture_numops;
132 struct event_context *event_ctx;
133 int *count = talloc_zero(mem_ctx, int);
136 data = talloc_array(mem_ctx, uint8_t, len);
138 generate_random_buffer(data, len);
140 io1.in.fname = fname;
144 printf("testing savefile\n");
146 status = smb_composite_savefile(cli->tree, &io1);
147 if (!NT_STATUS_IS_OK(status)) {
148 printf("savefile failed: %s\n", nt_errstr(status));
152 io2.in.dest_host = lp_parm_string(-1, "torture", "host");
154 io2.in.called_name = lp_parm_string(-1, "torture", "host");
155 io2.in.service = lp_parm_string(-1, "torture", "share");
156 io2.in.service_type = "A:";
158 io2.in.credentials = cmdline_credentials;
159 io2.in.workgroup = lp_workgroup();
160 io2.in.filename = fname;
162 printf("testing parallel fetchfile with %d ops\n", torture_numops);
164 event_ctx = event_context_init(mem_ctx);
165 c = talloc_array(mem_ctx, struct composite_context *, torture_numops);
167 for (i=0; i<torture_numops; i++) {
168 c[i] = smb_composite_fetchfile_send(&io2, event_ctx);
169 c[i]->async.fn = loadfile_complete;
170 c[i]->async.private_data = count;
173 printf("waiting for completion\n");
175 while (*count != torture_numops) {
176 event_loop_once(event_ctx);
177 printf("count=%d\r", *count);
180 printf("count=%d\n", *count);
182 for (i=0;i<torture_numops;i++) {
183 status = smb_composite_fetchfile_recv(c[i], mem_ctx);
184 if (!NT_STATUS_IS_OK(status)) {
185 printf("loadfile[%d] failed - %s\n", i,
191 if (io2.out.size != len) {
192 printf("wrong length in returned data - %d "
194 io2.out.size, (int)len);
199 if (memcmp(io2.out.data, data, len) != 0) {
200 printf("wrong data in loadfile!\n");
212 static BOOL test_appendacl(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
214 struct smb_composite_appendacl **io;
215 struct smb_composite_appendacl **io_orig;
216 struct composite_context **c;
217 struct event_context *event_ctx;
219 struct security_descriptor *test_sd;
220 struct security_ace *ace;
221 struct dom_sid *test_sid;
223 const int num_ops = 50;
224 int *count = talloc_zero(mem_ctx, int);
225 struct smb_composite_savefile io1;
230 io_orig = talloc_array(mem_ctx, struct smb_composite_appendacl *, num_ops);
232 printf ("creating %d empty files and getting their acls with appendacl\n", num_ops);
234 for (i = 0; i < num_ops; i++) {
235 io1.in.fname = talloc_asprintf(io_orig, BASEDIR "\\test%d.txt", i);
239 status = smb_composite_savefile(cli->tree, &io1);
240 if (!NT_STATUS_IS_OK(status)) {
241 printf("savefile failed: %s\n", nt_errstr(status));
245 io_orig[i] = talloc (io_orig, struct smb_composite_appendacl);
246 io_orig[i]->in.fname = talloc_steal(io_orig[i], io1.in.fname);
247 io_orig[i]->in.sd = security_descriptor_initialise(io_orig[i]);
248 status = smb_composite_appendacl(cli->tree, io_orig[i], io_orig[i]);
249 if (!NT_STATUS_IS_OK(status)) {
250 printf("appendacl failed: %s\n", nt_errstr(status));
256 /* fill Security Descriptor with aces to be added */
258 test_sd = security_descriptor_initialise(mem_ctx);
259 test_sid = dom_sid_parse_talloc (mem_ctx, "S-1-5-32-1234-5432");
261 ace = talloc_zero(mem_ctx, struct security_ace);
263 ace->type = SEC_ACE_TYPE_ACCESS_ALLOWED;
265 ace->access_mask = SEC_STD_ALL;
266 ace->trustee = *test_sid;
268 status = security_descriptor_dacl_add(test_sd, ace);
269 if (!NT_STATUS_IS_OK(status)) {
270 printf("appendacl failed: %s\n", nt_errstr(status));
274 /* set parameters for appendacl async call */
276 printf("testing parallel appendacl with %d ops\n", num_ops);
278 c = talloc_array(mem_ctx, struct composite_context *, num_ops);
279 io = talloc_array(mem_ctx, struct smb_composite_appendacl *, num_ops);
281 for (i=0; i < num_ops; i++) {
282 io[i] = talloc (io, struct smb_composite_appendacl);
283 io[i]->in.sd = test_sd;
284 io[i]->in.fname = talloc_asprintf(io[i], BASEDIR "\\test%d.txt", i);
286 c[i] = smb_composite_appendacl_send(cli->tree, io[i]);
287 c[i]->async.fn = loadfile_complete;
288 c[i]->async.private_data = count;
291 event_ctx = talloc_reference(mem_ctx, cli->tree->session->transport->socket->event.ctx);
292 printf("waiting for completion\n");
293 while (*count != num_ops) {
294 event_loop_once(event_ctx);
295 printf("count=%d\r", *count);
298 printf("count=%d\n", *count);
300 for (i=0; i < num_ops; i++) {
301 status = smb_composite_appendacl_recv(c[i], io[i]);
302 if (!NT_STATUS_IS_OK(status)) {
303 printf("appendacl[%d] failed - %s\n", i, nt_errstr(status));
307 security_descriptor_dacl_add(io_orig[i]->out.sd, ace);
308 if (!security_acl_equal(io_orig[i]->out.sd->dacl, io[i]->out.sd->dacl)) {
309 printf("appendacl[%d] failed - needed acl isn't set\n", i);
316 talloc_free (test_sid);
317 talloc_free (test_sd);
322 /* test a query FS info by asking for share's GUID */
323 static BOOL test_fsinfo(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
327 struct smb_composite_fsinfo io1;
328 struct composite_context **c;
331 extern int torture_numops;
332 struct event_context *event_ctx;
333 int *count = talloc_zero(mem_ctx, int);
336 io1.in.dest_host = lp_parm_string(-1, "torture", "host");
338 io1.in.called_name = lp_parm_string(-1, "torture", "host");
339 io1.in.service = lp_parm_string(-1, "torture", "share");
340 io1.in.service_type = "A:";
341 io1.in.credentials = cmdline_credentials;
342 io1.in.workgroup = lp_workgroup();
343 io1.in.level = RAW_QFS_OBJECTID_INFORMATION;
345 printf("testing parallel queryfsinfo [Object ID] with %d ops\n", torture_numops);
347 event_ctx = talloc_reference(mem_ctx, cli->tree->session->transport->socket->event.ctx);
348 c = talloc_array(mem_ctx, struct composite_context *, torture_numops);
350 for (i=0; i<torture_numops; i++) {
351 c[i] = smb_composite_fsinfo_send(cli->tree,&io1);
352 c[i]->async.fn = loadfile_complete;
353 c[i]->async.private_data = count;
356 printf("waiting for completion\n");
358 while (*count < torture_numops) {
359 event_loop_once(event_ctx);
360 printf("count=%d\r", *count);
363 printf("count=%d\n", *count);
365 for (i=0;i<torture_numops;i++) {
366 status = smb_composite_fsinfo_recv(c[i], mem_ctx);
367 if (!NT_STATUS_IS_OK(status)) {
368 printf("fsinfo[%d] failed - %s\n", i, nt_errstr(status));
373 if (io1.out.fsinfo->generic.level != RAW_QFS_OBJECTID_INFORMATION) {
374 printf("wrong level in returned info - %d "
376 io1.out.fsinfo->generic.level, RAW_QFS_OBJECTID_INFORMATION);
381 guid=GUID_string(mem_ctx, &io1.out.fsinfo->objectid_information.out.guid);
382 printf("[%d] GUID: %s\n", i, guid);
392 basic testing of libcli composite calls
394 BOOL torture_raw_composite(void)
396 struct smbcli_state *cli;
400 if (!torture_open_connection(&cli)) {
404 mem_ctx = talloc_init("torture_raw_composite");
406 if (!torture_setup_dir(cli, BASEDIR)) {
410 ret &= test_fetchfile(cli, mem_ctx);
411 ret &= test_loadfile(cli, mem_ctx);
412 ret &= test_appendacl(cli, mem_ctx);
413 ret &= test_fsinfo(cli, mem_ctx);
415 smb_raw_exit(cli->session);
416 smbcli_deltree(cli->tree, BASEDIR);
418 torture_close_connection(cli);
419 talloc_free(mem_ctx);