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/security.h"
29 #include "libcli/composite/composite.h"
30 #include "libcli/smb_composite/smb_composite.h"
31 #include "librpc/gen_ndr/ndr_misc.h"
32 #include "lib/cmdline/popt_common.h"
33 #include "torture/util.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("savefile failed: %s\n", 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 printf("count=%d\r", *count);
93 printf("count=%d\n", *count);
95 for (i=0;i<num_ops;i++) {
96 status = smb_composite_loadfile_recv(c[i], mem_ctx);
97 if (!NT_STATUS_IS_OK(status)) {
98 printf("loadfile[%d] failed - %s\n", i, nt_errstr(status));
102 if (io2.out.size != len) {
103 printf("wrong length in returned data - %d should be %d\n",
104 io2.out.size, (int)len);
108 if (memcmp(io2.out.data, data, len) != 0) {
109 printf("wrong data in loadfile!\n");
120 test a simple savefile/loadfile combination
122 static BOOL test_fetchfile(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
124 const char *fname = BASEDIR "\\test.txt";
126 struct smb_composite_savefile io1;
127 struct smb_composite_fetchfile io2;
128 struct composite_context **c;
131 size_t len = random() % 10000;
132 extern int torture_numops;
133 struct event_context *event_ctx;
134 int *count = talloc_zero(mem_ctx, int);
137 data = talloc_array(mem_ctx, uint8_t, len);
139 generate_random_buffer(data, len);
141 io1.in.fname = fname;
145 printf("testing savefile\n");
147 status = smb_composite_savefile(cli->tree, &io1);
148 if (!NT_STATUS_IS_OK(status)) {
149 printf("savefile failed: %s\n", nt_errstr(status));
153 io2.in.dest_host = lp_parm_string(-1, "torture", "host");
155 io2.in.called_name = lp_parm_string(-1, "torture", "host");
156 io2.in.service = lp_parm_string(-1, "torture", "share");
157 io2.in.service_type = "A:";
159 io2.in.credentials = cmdline_credentials;
160 io2.in.workgroup = lp_workgroup();
161 io2.in.filename = fname;
163 printf("testing parallel fetchfile with %d ops\n", torture_numops);
165 event_ctx = event_context_init(mem_ctx);
166 c = talloc_array(mem_ctx, struct composite_context *, torture_numops);
168 for (i=0; i<torture_numops; i++) {
169 c[i] = smb_composite_fetchfile_send(&io2, event_ctx);
170 c[i]->async.fn = loadfile_complete;
171 c[i]->async.private_data = count;
174 printf("waiting for completion\n");
176 while (*count != torture_numops) {
177 event_loop_once(event_ctx);
178 printf("count=%d\r", *count);
181 printf("count=%d\n", *count);
183 for (i=0;i<torture_numops;i++) {
184 status = smb_composite_fetchfile_recv(c[i], mem_ctx);
185 if (!NT_STATUS_IS_OK(status)) {
186 printf("loadfile[%d] failed - %s\n", i,
192 if (io2.out.size != len) {
193 printf("wrong length in returned data - %d "
195 io2.out.size, (int)len);
200 if (memcmp(io2.out.data, data, len) != 0) {
201 printf("wrong data in loadfile!\n");
213 static BOOL test_appendacl(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
215 struct smb_composite_appendacl **io;
216 struct smb_composite_appendacl **io_orig;
217 struct composite_context **c;
218 struct event_context *event_ctx;
220 struct security_descriptor *test_sd;
221 struct security_ace *ace;
222 struct dom_sid *test_sid;
224 const int num_ops = 50;
225 int *count = talloc_zero(mem_ctx, int);
226 struct smb_composite_savefile io1;
231 io_orig = talloc_array(mem_ctx, struct smb_composite_appendacl *, num_ops);
233 printf ("creating %d empty files and getting their acls with appendacl\n", num_ops);
235 for (i = 0; i < num_ops; i++) {
236 io1.in.fname = talloc_asprintf(io_orig, BASEDIR "\\test%d.txt", i);
240 status = smb_composite_savefile(cli->tree, &io1);
241 if (!NT_STATUS_IS_OK(status)) {
242 printf("savefile failed: %s\n", nt_errstr(status));
246 io_orig[i] = talloc (io_orig, struct smb_composite_appendacl);
247 io_orig[i]->in.fname = talloc_steal(io_orig[i], io1.in.fname);
248 io_orig[i]->in.sd = security_descriptor_initialise(io_orig[i]);
249 status = smb_composite_appendacl(cli->tree, io_orig[i], io_orig[i]);
250 if (!NT_STATUS_IS_OK(status)) {
251 printf("appendacl failed: %s\n", nt_errstr(status));
257 /* fill Security Descriptor with aces to be added */
259 test_sd = security_descriptor_initialise(mem_ctx);
260 test_sid = dom_sid_parse_talloc (mem_ctx, "S-1-5-32-1234-5432");
262 ace = talloc_zero(mem_ctx, struct security_ace);
264 ace->type = SEC_ACE_TYPE_ACCESS_ALLOWED;
266 ace->access_mask = SEC_STD_ALL;
267 ace->trustee = *test_sid;
269 status = security_descriptor_dacl_add(test_sd, ace);
270 if (!NT_STATUS_IS_OK(status)) {
271 printf("appendacl failed: %s\n", nt_errstr(status));
275 /* set parameters for appendacl async call */
277 printf("testing parallel appendacl with %d ops\n", num_ops);
279 c = talloc_array(mem_ctx, struct composite_context *, num_ops);
280 io = talloc_array(mem_ctx, struct smb_composite_appendacl *, num_ops);
282 for (i=0; i < num_ops; i++) {
283 io[i] = talloc (io, struct smb_composite_appendacl);
284 io[i]->in.sd = test_sd;
285 io[i]->in.fname = talloc_asprintf(io[i], BASEDIR "\\test%d.txt", i);
287 c[i] = smb_composite_appendacl_send(cli->tree, io[i]);
288 c[i]->async.fn = loadfile_complete;
289 c[i]->async.private_data = count;
292 event_ctx = talloc_reference(mem_ctx, cli->tree->session->transport->socket->event.ctx);
293 printf("waiting for completion\n");
294 while (*count != num_ops) {
295 event_loop_once(event_ctx);
296 printf("count=%d\r", *count);
299 printf("count=%d\n", *count);
301 for (i=0; i < num_ops; i++) {
302 status = smb_composite_appendacl_recv(c[i], io[i]);
303 if (!NT_STATUS_IS_OK(status)) {
304 printf("appendacl[%d] failed - %s\n", i, nt_errstr(status));
308 security_descriptor_dacl_add(io_orig[i]->out.sd, ace);
309 if (!security_acl_equal(io_orig[i]->out.sd->dacl, io[i]->out.sd->dacl)) {
310 printf("appendacl[%d] failed - needed acl isn't set\n", i);
317 talloc_free (test_sid);
318 talloc_free (test_sd);
323 /* test a query FS info by asking for share's GUID */
324 static BOOL test_fsinfo(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
328 struct smb_composite_fsinfo io1;
329 struct composite_context **c;
332 extern int torture_numops;
333 struct event_context *event_ctx;
334 int *count = talloc_zero(mem_ctx, int);
337 io1.in.dest_host = lp_parm_string(-1, "torture", "host");
339 io1.in.called_name = lp_parm_string(-1, "torture", "host");
340 io1.in.service = lp_parm_string(-1, "torture", "share");
341 io1.in.service_type = "A:";
342 io1.in.credentials = cmdline_credentials;
343 io1.in.workgroup = lp_workgroup();
344 io1.in.level = RAW_QFS_OBJECTID_INFORMATION;
346 printf("testing parallel queryfsinfo [Object ID] with %d ops\n", torture_numops);
348 event_ctx = talloc_reference(mem_ctx, cli->tree->session->transport->socket->event.ctx);
349 c = talloc_array(mem_ctx, struct composite_context *, torture_numops);
351 for (i=0; i<torture_numops; i++) {
352 c[i] = smb_composite_fsinfo_send(cli->tree,&io1);
353 c[i]->async.fn = loadfile_complete;
354 c[i]->async.private_data = count;
357 printf("waiting for completion\n");
359 while (*count < torture_numops) {
360 event_loop_once(event_ctx);
361 printf("count=%d\r", *count);
364 printf("count=%d\n", *count);
366 for (i=0;i<torture_numops;i++) {
367 status = smb_composite_fsinfo_recv(c[i], mem_ctx);
368 if (!NT_STATUS_IS_OK(status)) {
369 printf("fsinfo[%d] failed - %s\n", i, nt_errstr(status));
374 if (io1.out.fsinfo->generic.level != RAW_QFS_OBJECTID_INFORMATION) {
375 printf("wrong level in returned info - %d "
377 io1.out.fsinfo->generic.level, RAW_QFS_OBJECTID_INFORMATION);
382 guid=GUID_string(mem_ctx, &io1.out.fsinfo->objectid_information.out.guid);
383 printf("[%d] GUID: %s\n", i, guid);
393 basic testing of libcli composite calls
395 BOOL torture_raw_composite(struct torture_context *torture)
397 struct smbcli_state *cli;
401 if (!torture_open_connection(&cli, 0)) {
405 mem_ctx = talloc_init("torture_raw_composite");
407 if (!torture_setup_dir(cli, BASEDIR)) {
411 ret &= test_fetchfile(cli, mem_ctx);
412 ret &= test_loadfile(cli, mem_ctx);
413 ret &= test_appendacl(cli, mem_ctx);
414 ret &= test_fsinfo(cli, mem_ctx);
416 smb_raw_exit(cli->session);
417 smbcli_deltree(cli->tree, BASEDIR);
419 torture_close_connection(cli);
420 talloc_free(mem_ctx);