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 "lib/events/events.h"
25 #include "libcli/raw/libcliraw.h"
26 #include "libcli/composite/composite.h"
27 #include "libcli/smb_composite/smb_composite.h"
28 #include "lib/cmdline/popt_common.h"
29 #include "librpc/gen_ndr/ndr_security.h"
31 #define BASEDIR "\\composite"
33 static void loadfile_complete(struct composite_context *c)
35 int *count = talloc_get_type(c->async.private_data, int);
40 test a simple savefile/loadfile combination
42 static BOOL test_loadfile(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
44 const char *fname = BASEDIR "\\test.txt";
46 struct smb_composite_savefile io1;
47 struct smb_composite_loadfile io2;
48 struct composite_context **c;
50 size_t len = random() % 100000;
51 const int num_ops = 50;
53 int *count = talloc_zero(mem_ctx, int);
55 data = talloc_array(mem_ctx, uint8_t, len);
57 generate_random_buffer(data, len);
63 printf("testing savefile\n");
65 status = smb_composite_savefile(cli->tree, &io1);
66 if (!NT_STATUS_IS_OK(status)) {
67 printf("savefile failed: %s\n", nt_errstr(status));
73 printf("testing parallel loadfile with %d ops\n", num_ops);
75 c = talloc_array(mem_ctx, struct composite_context *, num_ops);
77 for (i=0;i<num_ops;i++) {
78 c[i] = smb_composite_loadfile_send(cli->tree, &io2);
79 c[i]->async.fn = loadfile_complete;
80 c[i]->async.private_data = count;
83 printf("waiting for completion\n");
84 while (*count != num_ops) {
85 event_loop_once(cli->transport->socket->event.ctx);
86 printf("count=%d\r", *count);
89 printf("count=%d\n", *count);
91 for (i=0;i<num_ops;i++) {
92 status = smb_composite_loadfile_recv(c[i], mem_ctx);
93 if (!NT_STATUS_IS_OK(status)) {
94 printf("loadfile[%d] failed - %s\n", i, nt_errstr(status));
98 if (io2.out.size != len) {
99 printf("wrong length in returned data - %d should be %d\n",
100 io2.out.size, (int)len);
104 if (memcmp(io2.out.data, data, len) != 0) {
105 printf("wrong data in loadfile!\n");
116 test a simple savefile/loadfile combination
118 static BOOL test_fetchfile(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
120 const char *fname = BASEDIR "\\test.txt";
122 struct smb_composite_savefile io1;
123 struct smb_composite_fetchfile io2;
124 struct composite_context **c;
127 size_t len = random() % 10000;
128 extern int torture_numops;
129 struct event_context *event_ctx;
130 int *count = talloc_zero(mem_ctx, int);
133 data = talloc_array(mem_ctx, uint8_t, len);
135 generate_random_buffer(data, len);
137 io1.in.fname = fname;
141 printf("testing savefile\n");
143 status = smb_composite_savefile(cli->tree, &io1);
144 if (!NT_STATUS_IS_OK(status)) {
145 printf("savefile failed: %s\n", nt_errstr(status));
149 io2.in.dest_host = lp_parm_string(-1, "torture", "host");
151 io2.in.called_name = lp_parm_string(-1, "torture", "host");
152 io2.in.service = lp_parm_string(-1, "torture", "share");
153 io2.in.service_type = "A:";
155 io2.in.credentials = cmdline_credentials;
156 io2.in.workgroup = lp_workgroup();
157 io2.in.filename = fname;
159 printf("testing parallel fetchfile with %d ops\n", torture_numops);
161 event_ctx = event_context_init(mem_ctx);
162 c = talloc_array(mem_ctx, struct composite_context *, torture_numops);
164 for (i=0; i<torture_numops; i++) {
165 c[i] = smb_composite_fetchfile_send(&io2, event_ctx);
166 c[i]->async.fn = loadfile_complete;
167 c[i]->async.private_data = count;
170 printf("waiting for completion\n");
172 while (*count != torture_numops) {
173 event_loop_once(event_ctx);
174 printf("count=%d\r", *count);
177 printf("count=%d\n", *count);
179 for (i=0;i<torture_numops;i++) {
180 status = smb_composite_fetchfile_recv(c[i], mem_ctx);
181 if (!NT_STATUS_IS_OK(status)) {
182 printf("loadfile[%d] failed - %s\n", i,
188 if (io2.out.size != len) {
189 printf("wrong length in returned data - %d "
191 io2.out.size, (int)len);
196 if (memcmp(io2.out.data, data, len) != 0) {
197 printf("wrong data in loadfile!\n");
209 static BOOL test_appendacl(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
211 struct smb_composite_appendacl **io;
212 struct smb_composite_appendacl **io_orig;
213 struct composite_context **c;
214 struct event_context *event_ctx;
216 struct security_descriptor *test_sd;
217 struct security_ace *ace;
218 struct dom_sid *test_sid;
220 const int num_ops = 50;
221 int *count = talloc_zero(mem_ctx, int);
222 struct smb_composite_savefile io1;
227 io_orig = talloc_array(mem_ctx, struct smb_composite_appendacl *, num_ops);
229 printf ("creating %d empty files and getting their acls with appendacl\n", num_ops);
231 for (i = 0; i < num_ops; i++) {
232 io1.in.fname = talloc_asprintf(io_orig, BASEDIR "\\test%d.txt", i);
236 status = smb_composite_savefile(cli->tree, &io1);
237 if (!NT_STATUS_IS_OK(status)) {
238 printf("savefile failed: %s\n", nt_errstr(status));
242 io_orig[i] = talloc (io_orig, struct smb_composite_appendacl);
243 io_orig[i]->in.fname = talloc_steal(io_orig[i], io1.in.fname);
244 io_orig[i]->in.sd = security_descriptor_initialise(io_orig[i]);
245 status = smb_composite_appendacl(cli->tree, io_orig[i], io_orig[i]);
246 if (!NT_STATUS_IS_OK(status)) {
247 printf("appendacl failed: %s\n", nt_errstr(status));
253 /* fill Security Descriptor with aces to be added */
255 test_sd = security_descriptor_initialise(mem_ctx);
256 test_sid = dom_sid_parse_talloc (mem_ctx, "S-1-5-32-1234-5432");
258 ace = talloc_zero(mem_ctx, struct security_ace);
260 ace->type = SEC_ACE_TYPE_ACCESS_ALLOWED;
262 ace->access_mask = SEC_STD_ALL;
263 ace->trustee = *test_sid;
265 status = security_descriptor_dacl_add(test_sd, ace);
266 if (!NT_STATUS_IS_OK(status)) {
267 printf("appendacl failed: %s\n", nt_errstr(status));
271 /* set parameters for appendacl async call */
273 printf("testing parallel appendacl with %d ops\n", num_ops);
275 c = talloc_array(mem_ctx, struct composite_context *, num_ops);
276 io = talloc_array(mem_ctx, struct smb_composite_appendacl *, num_ops);
278 for (i=0; i < num_ops; i++) {
279 io[i] = talloc (io, struct smb_composite_appendacl);
280 io[i]->in.sd = test_sd;
281 io[i]->in.fname = talloc_asprintf(io[i], BASEDIR "\\test%d.txt", i);
283 c[i] = smb_composite_appendacl_send(cli->tree, io[i]);
284 c[i]->async.fn = loadfile_complete;
285 c[i]->async.private_data = count;
288 event_ctx = talloc_reference(mem_ctx, cli->tree->session->transport->socket->event.ctx);
289 printf("waiting for completion\n");
290 while (*count != num_ops) {
291 event_loop_once(event_ctx);
292 printf("count=%d\r", *count);
295 printf("count=%d\n", *count);
297 for (i=0; i < num_ops; i++) {
298 status = smb_composite_appendacl_recv(c[i], io[i]);
299 if (!NT_STATUS_IS_OK(status)) {
300 printf("appendacl[%d] failed - %s\n", i, nt_errstr(status));
304 security_descriptor_dacl_add(io_orig[i]->out.sd, ace);
305 if (!security_acl_equal(io_orig[i]->out.sd->dacl, io[i]->out.sd->dacl)) {
306 printf("appendacl[%d] failed - needed acl isn't set\n", i);
313 talloc_free (test_sid);
314 talloc_free (test_sd);
319 /* test a query FS info by asking for share's GUID */
320 static BOOL test_fsinfo(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
324 struct smb_composite_fsinfo io1;
325 struct composite_context **c;
328 extern int torture_numops;
329 struct event_context *event_ctx;
330 int *count = talloc_zero(mem_ctx, int);
333 io1.in.dest_host = lp_parm_string(-1, "torture", "host");
335 io1.in.called_name = lp_parm_string(-1, "torture", "host");
336 io1.in.service = lp_parm_string(-1, "torture", "share");
337 io1.in.service_type = "A:";
338 io1.in.credentials = cmdline_credentials;
339 io1.in.workgroup = lp_workgroup();
340 io1.in.level = RAW_QFS_OBJECTID_INFORMATION;
342 printf("testing parallel queryfsinfo [Object ID] with %d ops\n", torture_numops);
344 event_ctx = talloc_reference(mem_ctx, cli->tree->session->transport->socket->event.ctx);
345 c = talloc_array(mem_ctx, struct composite_context *, torture_numops);
347 for (i=0; i<torture_numops; i++) {
348 c[i] = smb_composite_fsinfo_send(cli->tree,&io1);
349 c[i]->async.fn = loadfile_complete;
350 c[i]->async.private_data = count;
353 printf("waiting for completion\n");
355 while (*count < torture_numops) {
356 event_loop_once(event_ctx);
357 printf("count=%d\r", *count);
360 printf("count=%d\n", *count);
362 for (i=0;i<torture_numops;i++) {
363 status = smb_composite_fsinfo_recv(c[i], mem_ctx);
364 if (!NT_STATUS_IS_OK(status)) {
365 printf("fsinfo[%d] failed - %s\n", i, nt_errstr(status));
370 if (io1.out.fsinfo->generic.level != RAW_QFS_OBJECTID_INFORMATION) {
371 printf("wrong level in returned info - %d "
373 io1.out.fsinfo->generic.level, RAW_QFS_OBJECTID_INFORMATION);
378 guid=GUID_string(mem_ctx, &io1.out.fsinfo->objectid_information.out.guid);
379 printf("[%d] GUID: %s\n", i, guid);
389 basic testing of libcli composite calls
391 BOOL torture_raw_composite(void)
393 struct smbcli_state *cli;
397 if (!torture_open_connection(&cli)) {
401 mem_ctx = talloc_init("torture_raw_composite");
403 if (!torture_setup_dir(cli, BASEDIR)) {
407 ret &= test_fetchfile(cli, mem_ctx);
408 ret &= test_loadfile(cli, mem_ctx);
409 ret &= test_appendacl(cli, mem_ctx);
410 ret &= test_fsinfo(cli, mem_ctx);
412 smb_raw_exit(cli->session);
413 smbcli_deltree(cli->tree, BASEDIR);
415 torture_close_connection(cli);
416 talloc_free(mem_ctx);