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/composite/composite.h"
29 #include "libcli/smb_composite/smb_composite.h"
30 #include "lib/cmdline/popt_common.h"
31 #include "librpc/gen_ndr/ndr_security.h"
33 #define BASEDIR "\\composite"
35 static void loadfile_complete(struct composite_context *c)
37 int *count = talloc_get_type(c->async.private_data, int);
42 test a simple savefile/loadfile combination
44 static BOOL test_loadfile(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
46 const char *fname = BASEDIR "\\test.txt";
48 struct smb_composite_savefile io1;
49 struct smb_composite_loadfile io2;
50 struct composite_context **c;
52 size_t len = random() % 100000;
53 const int num_ops = 50;
55 int *count = talloc_zero(mem_ctx, int);
57 data = talloc_array(mem_ctx, uint8_t, len);
59 generate_random_buffer(data, len);
65 printf("testing savefile\n");
67 status = smb_composite_savefile(cli->tree, &io1);
68 if (!NT_STATUS_IS_OK(status)) {
69 printf("savefile failed: %s\n", nt_errstr(status));
75 printf("testing parallel loadfile with %d ops\n", num_ops);
77 c = talloc_array(mem_ctx, struct composite_context *, num_ops);
79 for (i=0;i<num_ops;i++) {
80 c[i] = smb_composite_loadfile_send(cli->tree, &io2);
81 c[i]->async.fn = loadfile_complete;
82 c[i]->async.private_data = count;
85 printf("waiting for completion\n");
86 while (*count != num_ops) {
87 event_loop_once(cli->transport->socket->event.ctx);
88 printf("count=%d\r", *count);
91 printf("count=%d\n", *count);
93 for (i=0;i<num_ops;i++) {
94 status = smb_composite_loadfile_recv(c[i], mem_ctx);
95 if (!NT_STATUS_IS_OK(status)) {
96 printf("loadfile[%d] failed - %s\n", i, nt_errstr(status));
100 if (io2.out.size != len) {
101 printf("wrong length in returned data - %d should be %d\n",
102 io2.out.size, (int)len);
106 if (memcmp(io2.out.data, data, len) != 0) {
107 printf("wrong data in loadfile!\n");
118 test a simple savefile/loadfile combination
120 static BOOL test_fetchfile(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
122 const char *fname = BASEDIR "\\test.txt";
124 struct smb_composite_savefile io1;
125 struct smb_composite_fetchfile io2;
126 struct composite_context **c;
129 size_t len = random() % 10000;
130 extern int torture_numops;
131 struct event_context *event_ctx;
132 int *count = talloc_zero(mem_ctx, int);
135 data = talloc_array(mem_ctx, uint8_t, len);
137 generate_random_buffer(data, len);
139 io1.in.fname = fname;
143 printf("testing savefile\n");
145 status = smb_composite_savefile(cli->tree, &io1);
146 if (!NT_STATUS_IS_OK(status)) {
147 printf("savefile failed: %s\n", nt_errstr(status));
151 io2.in.dest_host = lp_parm_string(-1, "torture", "host");
153 io2.in.called_name = lp_parm_string(-1, "torture", "host");
154 io2.in.service = lp_parm_string(-1, "torture", "share");
155 io2.in.service_type = "A:";
157 io2.in.credentials = cmdline_credentials;
158 io2.in.workgroup = lp_workgroup();
159 io2.in.filename = fname;
161 printf("testing parallel fetchfile with %d ops\n", torture_numops);
163 event_ctx = event_context_init(mem_ctx);
164 c = talloc_array(mem_ctx, struct composite_context *, torture_numops);
166 for (i=0; i<torture_numops; i++) {
167 c[i] = smb_composite_fetchfile_send(&io2, event_ctx);
168 c[i]->async.fn = loadfile_complete;
169 c[i]->async.private_data = count;
172 printf("waiting for completion\n");
174 while (*count != torture_numops) {
175 event_loop_once(event_ctx);
176 printf("count=%d\r", *count);
179 printf("count=%d\n", *count);
181 for (i=0;i<torture_numops;i++) {
182 status = smb_composite_fetchfile_recv(c[i], mem_ctx);
183 if (!NT_STATUS_IS_OK(status)) {
184 printf("loadfile[%d] failed - %s\n", i,
190 if (io2.out.size != len) {
191 printf("wrong length in returned data - %d "
193 io2.out.size, (int)len);
198 if (memcmp(io2.out.data, data, len) != 0) {
199 printf("wrong data in loadfile!\n");
211 static BOOL test_appendacl(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
213 struct smb_composite_appendacl **io;
214 struct smb_composite_appendacl **io_orig;
215 struct composite_context **c;
216 struct event_context *event_ctx;
218 struct security_descriptor *test_sd;
219 struct security_ace *ace;
220 struct dom_sid *test_sid;
222 const int num_ops = 50;
223 int *count = talloc_zero(mem_ctx, int);
224 struct smb_composite_savefile io1;
229 io_orig = talloc_array(mem_ctx, struct smb_composite_appendacl *, num_ops);
231 printf ("creating %d empty files and getting their acls with appendacl\n", num_ops);
233 for (i = 0; i < num_ops; i++) {
234 io1.in.fname = talloc_asprintf(io_orig, BASEDIR "\\test%d.txt", i);
238 status = smb_composite_savefile(cli->tree, &io1);
239 if (!NT_STATUS_IS_OK(status)) {
240 printf("savefile failed: %s\n", nt_errstr(status));
244 io_orig[i] = talloc (io_orig, struct smb_composite_appendacl);
245 io_orig[i]->in.fname = talloc_steal(io_orig[i], io1.in.fname);
246 io_orig[i]->in.sd = security_descriptor_initialise(io_orig[i]);
247 status = smb_composite_appendacl(cli->tree, io_orig[i], io_orig[i]);
248 if (!NT_STATUS_IS_OK(status)) {
249 printf("appendacl failed: %s\n", nt_errstr(status));
255 /* fill Security Descriptor with aces to be added */
257 test_sd = security_descriptor_initialise(mem_ctx);
258 test_sid = dom_sid_parse_talloc (mem_ctx, "S-1-5-32-1234-5432");
260 ace = talloc_zero(mem_ctx, struct security_ace);
262 ace->type = SEC_ACE_TYPE_ACCESS_ALLOWED;
264 ace->access_mask = SEC_STD_ALL;
265 ace->trustee = *test_sid;
267 status = security_descriptor_dacl_add(test_sd, ace);
268 if (!NT_STATUS_IS_OK(status)) {
269 printf("appendacl failed: %s\n", nt_errstr(status));
273 /* set parameters for appendacl async call */
275 printf("testing parallel appendacl with %d ops\n", num_ops);
277 c = talloc_array(mem_ctx, struct composite_context *, num_ops);
278 io = talloc_array(mem_ctx, struct smb_composite_appendacl *, num_ops);
280 for (i=0; i < num_ops; i++) {
281 io[i] = talloc (io, struct smb_composite_appendacl);
282 io[i]->in.sd = test_sd;
283 io[i]->in.fname = talloc_asprintf(io[i], BASEDIR "\\test%d.txt", i);
285 c[i] = smb_composite_appendacl_send(cli->tree, io[i]);
286 c[i]->async.fn = loadfile_complete;
287 c[i]->async.private_data = count;
290 event_ctx = talloc_reference(mem_ctx, cli->tree->session->transport->socket->event.ctx);
291 printf("waiting for completion\n");
292 while (*count != num_ops) {
293 event_loop_once(event_ctx);
294 printf("count=%d\r", *count);
297 printf("count=%d\n", *count);
299 for (i=0; i < num_ops; i++) {
300 status = smb_composite_appendacl_recv(c[i], io[i]);
301 if (!NT_STATUS_IS_OK(status)) {
302 printf("appendacl[%d] failed - %s\n", i, nt_errstr(status));
306 security_descriptor_dacl_add(io_orig[i]->out.sd, ace);
307 if (!security_acl_equal(io_orig[i]->out.sd->dacl, io[i]->out.sd->dacl)) {
308 printf("appendacl[%d] failed - needed acl isn't set\n", i);
315 talloc_free (test_sid);
316 talloc_free (test_sd);
321 /* test a query FS info by asking for share's GUID */
322 static BOOL test_fsinfo(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
326 struct smb_composite_fsinfo io1;
327 struct composite_context **c;
330 extern int torture_numops;
331 struct event_context *event_ctx;
332 int *count = talloc_zero(mem_ctx, int);
335 io1.in.dest_host = lp_parm_string(-1, "torture", "host");
337 io1.in.called_name = lp_parm_string(-1, "torture", "host");
338 io1.in.service = lp_parm_string(-1, "torture", "share");
339 io1.in.service_type = "A:";
340 io1.in.credentials = cmdline_credentials;
341 io1.in.workgroup = lp_workgroup();
342 io1.in.level = RAW_QFS_OBJECTID_INFORMATION;
344 printf("testing parallel queryfsinfo [Object ID] with %d ops\n", torture_numops);
346 event_ctx = talloc_reference(mem_ctx, cli->tree->session->transport->socket->event.ctx);
347 c = talloc_array(mem_ctx, struct composite_context *, torture_numops);
349 for (i=0; i<torture_numops; i++) {
350 c[i] = smb_composite_fsinfo_send(cli->tree,&io1);
351 c[i]->async.fn = loadfile_complete;
352 c[i]->async.private_data = count;
355 printf("waiting for completion\n");
357 while (*count < torture_numops) {
358 event_loop_once(event_ctx);
359 printf("count=%d\r", *count);
362 printf("count=%d\n", *count);
364 for (i=0;i<torture_numops;i++) {
365 status = smb_composite_fsinfo_recv(c[i], mem_ctx);
366 if (!NT_STATUS_IS_OK(status)) {
367 printf("fsinfo[%d] failed - %s\n", i, nt_errstr(status));
372 if (io1.out.fsinfo->generic.level != RAW_QFS_OBJECTID_INFORMATION) {
373 printf("wrong level in returned info - %d "
375 io1.out.fsinfo->generic.level, RAW_QFS_OBJECTID_INFORMATION);
380 guid=GUID_string(mem_ctx, &io1.out.fsinfo->objectid_information.out.guid);
381 printf("[%d] GUID: %s\n", i, guid);
391 basic testing of libcli composite calls
393 BOOL torture_raw_composite(void)
395 struct smbcli_state *cli;
399 if (!torture_open_connection(&cli)) {
403 mem_ctx = talloc_init("torture_raw_composite");
405 if (!torture_setup_dir(cli, BASEDIR)) {
409 ret &= test_fetchfile(cli, mem_ctx);
410 ret &= test_loadfile(cli, mem_ctx);
411 ret &= test_appendacl(cli, mem_ctx);
412 ret &= test_fsinfo(cli, mem_ctx);
414 smb_raw_exit(cli->session);
415 smbcli_deltree(cli->tree, BASEDIR);
417 torture_close_connection(cli);
418 talloc_free(mem_ctx);