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 "lib/cmdline/popt_common.h"
28 #include "librpc/gen_ndr/ndr_security.h"
30 #define BASEDIR "\\composite"
32 static void loadfile_complete(struct composite_context *c)
34 int *count = talloc_get_type(c->async.private, int);
39 test a simple savefile/loadfile combination
41 static BOOL test_loadfile(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
43 const char *fname = BASEDIR "\\test.txt";
45 struct smb_composite_savefile io1;
46 struct smb_composite_loadfile io2;
47 struct composite_context **c;
49 size_t len = random() % 100000;
50 const int num_ops = 50;
52 int *count = talloc_zero(mem_ctx, int);
54 data = talloc_array(mem_ctx, uint8_t, len);
56 generate_random_buffer(data, len);
62 printf("testing savefile\n");
64 status = smb_composite_savefile(cli->tree, &io1);
65 if (!NT_STATUS_IS_OK(status)) {
66 printf("savefile failed: %s\n", nt_errstr(status));
72 printf("testing parallel loadfile with %d ops\n", num_ops);
74 c = talloc_array(mem_ctx, struct composite_context *, num_ops);
76 for (i=0;i<num_ops;i++) {
77 c[i] = smb_composite_loadfile_send(cli->tree, &io2);
78 c[i]->async.fn = loadfile_complete;
79 c[i]->async.private = count;
82 printf("waiting for completion\n");
83 while (*count != num_ops) {
84 event_loop_once(cli->transport->socket->event.ctx);
85 printf("count=%d\r", *count);
88 printf("count=%d\n", *count);
90 for (i=0;i<num_ops;i++) {
91 status = smb_composite_loadfile_recv(c[i], mem_ctx);
92 if (!NT_STATUS_IS_OK(status)) {
93 printf("loadfile[%d] failed - %s\n", i, nt_errstr(status));
97 if (io2.out.size != len) {
98 printf("wrong length in returned data - %d should be %d\n",
99 io2.out.size, (int)len);
103 if (memcmp(io2.out.data, data, len) != 0) {
104 printf("wrong data in loadfile!\n");
115 test a simple savefile/loadfile combination
117 static BOOL test_fetchfile(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
119 const char *fname = BASEDIR "\\test.txt";
121 struct smb_composite_savefile io1;
122 struct smb_composite_fetchfile io2;
123 struct composite_context **c;
126 size_t len = random() % 10000;
127 extern int torture_numops;
128 struct event_context *event_ctx;
129 int *count = talloc_zero(mem_ctx, int);
132 data = talloc_array(mem_ctx, uint8_t, len);
134 generate_random_buffer(data, len);
136 io1.in.fname = fname;
140 printf("testing savefile\n");
142 status = smb_composite_savefile(cli->tree, &io1);
143 if (!NT_STATUS_IS_OK(status)) {
144 printf("savefile failed: %s\n", nt_errstr(status));
148 io2.in.dest_host = lp_parm_string(-1, "torture", "host");
150 io2.in.called_name = lp_parm_string(-1, "torture", "host");
151 io2.in.service = lp_parm_string(-1, "torture", "share");
152 io2.in.service_type = "A:";
154 io2.in.credentials = cmdline_credentials;
155 io2.in.workgroup = lp_workgroup();
156 io2.in.filename = fname;
158 printf("testing parallel fetchfile with %d ops\n", torture_numops);
160 event_ctx = event_context_init(mem_ctx);
161 c = talloc_array(mem_ctx, struct composite_context *, torture_numops);
163 for (i=0; i<torture_numops; i++) {
164 c[i] = smb_composite_fetchfile_send(&io2, event_ctx);
165 c[i]->async.fn = loadfile_complete;
166 c[i]->async.private = count;
169 printf("waiting for completion\n");
171 while (*count != torture_numops) {
172 event_loop_once(event_ctx);
173 printf("count=%d\r", *count);
176 printf("count=%d\n", *count);
178 for (i=0;i<torture_numops;i++) {
179 status = smb_composite_fetchfile_recv(c[i], mem_ctx);
180 if (!NT_STATUS_IS_OK(status)) {
181 printf("loadfile[%d] failed - %s\n", i,
187 if (io2.out.size != len) {
188 printf("wrong length in returned data - %d "
190 io2.out.size, (int)len);
195 if (memcmp(io2.out.data, data, len) != 0) {
196 printf("wrong data in loadfile!\n");
208 static BOOL test_appendacl(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
210 struct smb_composite_appendacl **io;
211 struct smb_composite_appendacl **io_orig;
212 struct composite_context **c;
213 struct event_context *event_ctx;
215 struct security_descriptor *test_sd;
216 struct security_ace *ace;
217 struct dom_sid *test_sid;
219 const int num_ops = 50;
220 int *count = talloc_zero(mem_ctx, int);
221 struct smb_composite_savefile io1;
226 io_orig = talloc_array(mem_ctx, struct smb_composite_appendacl *, num_ops);
228 printf ("creating %d empty files and getting their acls with appendacl\n", num_ops);
230 for (i = 0; i < num_ops; i++) {
231 io1.in.fname = talloc_asprintf(io_orig, BASEDIR "\\test%d.txt", i);
235 status = smb_composite_savefile(cli->tree, &io1);
236 if (!NT_STATUS_IS_OK(status)) {
237 printf("savefile failed: %s\n", nt_errstr(status));
241 io_orig[i] = talloc (io_orig, struct smb_composite_appendacl);
242 io_orig[i]->in.fname = talloc_steal(io_orig[i], io1.in.fname);
243 io_orig[i]->in.sd = security_descriptor_initialise(io_orig[i]);
244 status = smb_composite_appendacl(cli->tree, io_orig[i], io_orig[i]);
245 if (!NT_STATUS_IS_OK(status)) {
246 printf("appendacl failed: %s\n", nt_errstr(status));
252 /* fill Security Descriptor with aces to be added */
254 test_sd = security_descriptor_initialise(mem_ctx);
255 test_sid = dom_sid_parse_talloc (mem_ctx, "S-1-5-32-1234-5432");
257 ace = talloc_zero(mem_ctx, struct security_ace);
259 ace->type = SEC_ACE_TYPE_ACCESS_ALLOWED;
261 ace->access_mask = SEC_STD_ALL;
262 ace->trustee = *test_sid;
264 status = security_descriptor_dacl_add(test_sd, ace);
265 if (!NT_STATUS_IS_OK(status)) {
266 printf("appendacl failed: %s\n", nt_errstr(status));
270 /* set parameters for appendacl async call */
272 printf("testing parallel appendacl with %d ops\n", num_ops);
274 c = talloc_array(mem_ctx, struct composite_context *, num_ops);
275 io = talloc_array(mem_ctx, struct smb_composite_appendacl *, num_ops);
277 for (i=0; i < num_ops; i++) {
278 io[i] = talloc (io, struct smb_composite_appendacl);
279 io[i]->in.sd = test_sd;
280 io[i]->in.fname = talloc_asprintf(io[i], BASEDIR "\\test%d.txt", i);
282 c[i] = smb_composite_appendacl_send(cli->tree, io[i]);
283 c[i]->async.fn = loadfile_complete;
284 c[i]->async.private = count;
287 event_ctx = talloc_reference(mem_ctx, cli->tree->session->transport->socket->event.ctx);
288 printf("waiting for completion\n");
289 while (*count != num_ops) {
290 event_loop_once(event_ctx);
291 printf("count=%d\r", *count);
294 printf("count=%d\n", *count);
296 for (i=0; i < num_ops; i++) {
297 status = smb_composite_appendacl_recv(c[i], io[i]);
298 if (!NT_STATUS_IS_OK(status)) {
299 printf("appendacl[%d] failed - %s\n", i, nt_errstr(status));
303 security_descriptor_dacl_add(io_orig[i]->out.sd, ace);
304 if (!security_acl_equal(io_orig[i]->out.sd->dacl, io[i]->out.sd->dacl)) {
305 printf("appendacl[%d] failed - needed acl isn't set\n", i);
312 talloc_free (test_sid);
313 talloc_free (test_sd);
318 /* test a query FS info by asking for share's GUID */
319 static BOOL test_fsinfo(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
323 struct smb_composite_fsinfo io1;
324 struct composite_context **c;
327 extern int torture_numops;
328 struct event_context *event_ctx;
329 int *count = talloc_zero(mem_ctx, int);
332 io1.in.dest_host = lp_parm_string(-1, "torture", "host");
334 io1.in.called_name = lp_parm_string(-1, "torture", "host");
335 io1.in.service = lp_parm_string(-1, "torture", "share");
336 io1.in.service_type = "A:";
337 io1.in.credentials = cmdline_credentials;
338 io1.in.workgroup = lp_workgroup();
339 io1.in.level = RAW_QFS_OBJECTID_INFORMATION;
341 printf("testing parallel queryfsinfo [Object ID] with %d ops\n", torture_numops);
343 event_ctx = talloc_reference(mem_ctx, cli->tree->session->transport->socket->event.ctx);
344 c = talloc_array(mem_ctx, struct composite_context *, torture_numops);
346 for (i=0; i<torture_numops; i++) {
347 c[i] = smb_composite_fsinfo_send(cli->tree,&io1);
348 c[i]->async.fn = loadfile_complete;
349 c[i]->async.private = count;
352 printf("waiting for completion\n");
354 while (*count < torture_numops) {
355 event_loop_once(event_ctx);
356 printf("count=%d\r", *count);
359 printf("count=%d\n", *count);
361 for (i=0;i<torture_numops;i++) {
362 status = smb_composite_fsinfo_recv(c[i], mem_ctx);
363 if (!NT_STATUS_IS_OK(status)) {
364 printf("fsinfo[%d] failed - %s\n", i, nt_errstr(status));
369 if (io1.out.fsinfo->generic.level != RAW_QFS_OBJECTID_INFORMATION) {
370 printf("wrong level in returned info - %d "
372 io1.out.fsinfo->generic.level, RAW_QFS_OBJECTID_INFORMATION);
377 guid=GUID_string(mem_ctx, &io1.out.fsinfo->objectid_information.out.guid);
378 printf("[%d] GUID: %s\n", i, guid);
388 basic testing of libcli composite calls
390 BOOL torture_raw_composite(void)
392 struct smbcli_state *cli;
396 if (!torture_open_connection(&cli)) {
400 mem_ctx = talloc_init("torture_raw_composite");
402 if (!torture_setup_dir(cli, BASEDIR)) {
406 ret &= test_fetchfile(cli, mem_ctx);
407 ret &= test_loadfile(cli, mem_ctx);
408 ret &= test_appendacl(cli, mem_ctx);
409 ret &= test_fsinfo(cli, mem_ctx);
411 smb_raw_exit(cli->session);
412 smbcli_deltree(cli->tree, BASEDIR);
414 torture_close_connection(cli);
415 talloc_free(mem_ctx);