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 "librpc/gen_ndr/ndr_misc.h"
32 #include "lib/cmdline/popt_common.h"
33 #include "librpc/gen_ndr/security.h"
34 #include "torture/util.h"
36 #define BASEDIR "\\composite"
38 static void loadfile_complete(struct composite_context *c)
40 int *count = talloc_get_type(c->async.private_data, int);
45 test a simple savefile/loadfile combination
47 static BOOL test_loadfile(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
49 const char *fname = BASEDIR "\\test.txt";
51 struct smb_composite_savefile io1;
52 struct smb_composite_loadfile io2;
53 struct composite_context **c;
55 size_t len = random() % 100000;
56 const int num_ops = 50;
58 int *count = talloc_zero(mem_ctx, int);
60 data = talloc_array(mem_ctx, uint8_t, len);
62 generate_random_buffer(data, len);
68 printf("testing savefile\n");
70 status = smb_composite_savefile(cli->tree, &io1);
71 if (!NT_STATUS_IS_OK(status)) {
72 printf("savefile failed: %s\n", nt_errstr(status));
78 printf("testing parallel loadfile with %d ops\n", num_ops);
80 c = talloc_array(mem_ctx, struct composite_context *, num_ops);
82 for (i=0;i<num_ops;i++) {
83 c[i] = smb_composite_loadfile_send(cli->tree, &io2);
84 c[i]->async.fn = loadfile_complete;
85 c[i]->async.private_data = count;
88 printf("waiting for completion\n");
89 while (*count != num_ops) {
90 event_loop_once(cli->transport->socket->event.ctx);
91 printf("count=%d\r", *count);
94 printf("count=%d\n", *count);
96 for (i=0;i<num_ops;i++) {
97 status = smb_composite_loadfile_recv(c[i], mem_ctx);
98 if (!NT_STATUS_IS_OK(status)) {
99 printf("loadfile[%d] failed - %s\n", i, nt_errstr(status));
103 if (io2.out.size != len) {
104 printf("wrong length in returned data - %d should be %d\n",
105 io2.out.size, (int)len);
109 if (memcmp(io2.out.data, data, len) != 0) {
110 printf("wrong data in loadfile!\n");
121 test a simple savefile/loadfile combination
123 static BOOL test_fetchfile(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
125 const char *fname = BASEDIR "\\test.txt";
127 struct smb_composite_savefile io1;
128 struct smb_composite_fetchfile io2;
129 struct composite_context **c;
132 size_t len = random() % 10000;
133 extern int torture_numops;
134 struct event_context *event_ctx;
135 int *count = talloc_zero(mem_ctx, int);
138 data = talloc_array(mem_ctx, uint8_t, len);
140 generate_random_buffer(data, len);
142 io1.in.fname = fname;
146 printf("testing savefile\n");
148 status = smb_composite_savefile(cli->tree, &io1);
149 if (!NT_STATUS_IS_OK(status)) {
150 printf("savefile failed: %s\n", nt_errstr(status));
154 io2.in.dest_host = lp_parm_string(-1, "torture", "host");
156 io2.in.called_name = lp_parm_string(-1, "torture", "host");
157 io2.in.service = lp_parm_string(-1, "torture", "share");
158 io2.in.service_type = "A:";
160 io2.in.credentials = cmdline_credentials;
161 io2.in.workgroup = lp_workgroup();
162 io2.in.filename = fname;
164 printf("testing parallel fetchfile with %d ops\n", torture_numops);
166 event_ctx = event_context_init(mem_ctx);
167 c = talloc_array(mem_ctx, struct composite_context *, torture_numops);
169 for (i=0; i<torture_numops; i++) {
170 c[i] = smb_composite_fetchfile_send(&io2, event_ctx);
171 c[i]->async.fn = loadfile_complete;
172 c[i]->async.private_data = count;
175 printf("waiting for completion\n");
177 while (*count != torture_numops) {
178 event_loop_once(event_ctx);
179 printf("count=%d\r", *count);
182 printf("count=%d\n", *count);
184 for (i=0;i<torture_numops;i++) {
185 status = smb_composite_fetchfile_recv(c[i], mem_ctx);
186 if (!NT_STATUS_IS_OK(status)) {
187 printf("loadfile[%d] failed - %s\n", i,
193 if (io2.out.size != len) {
194 printf("wrong length in returned data - %d "
196 io2.out.size, (int)len);
201 if (memcmp(io2.out.data, data, len) != 0) {
202 printf("wrong data in loadfile!\n");
214 static BOOL test_appendacl(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
216 struct smb_composite_appendacl **io;
217 struct smb_composite_appendacl **io_orig;
218 struct composite_context **c;
219 struct event_context *event_ctx;
221 struct security_descriptor *test_sd;
222 struct security_ace *ace;
223 struct dom_sid *test_sid;
225 const int num_ops = 50;
226 int *count = talloc_zero(mem_ctx, int);
227 struct smb_composite_savefile io1;
232 io_orig = talloc_array(mem_ctx, struct smb_composite_appendacl *, num_ops);
234 printf ("creating %d empty files and getting their acls with appendacl\n", num_ops);
236 for (i = 0; i < num_ops; i++) {
237 io1.in.fname = talloc_asprintf(io_orig, BASEDIR "\\test%d.txt", i);
241 status = smb_composite_savefile(cli->tree, &io1);
242 if (!NT_STATUS_IS_OK(status)) {
243 printf("savefile failed: %s\n", nt_errstr(status));
247 io_orig[i] = talloc (io_orig, struct smb_composite_appendacl);
248 io_orig[i]->in.fname = talloc_steal(io_orig[i], io1.in.fname);
249 io_orig[i]->in.sd = security_descriptor_initialise(io_orig[i]);
250 status = smb_composite_appendacl(cli->tree, io_orig[i], io_orig[i]);
251 if (!NT_STATUS_IS_OK(status)) {
252 printf("appendacl failed: %s\n", nt_errstr(status));
258 /* fill Security Descriptor with aces to be added */
260 test_sd = security_descriptor_initialise(mem_ctx);
261 test_sid = dom_sid_parse_talloc (mem_ctx, "S-1-5-32-1234-5432");
263 ace = talloc_zero(mem_ctx, struct security_ace);
265 ace->type = SEC_ACE_TYPE_ACCESS_ALLOWED;
267 ace->access_mask = SEC_STD_ALL;
268 ace->trustee = *test_sid;
270 status = security_descriptor_dacl_add(test_sd, ace);
271 if (!NT_STATUS_IS_OK(status)) {
272 printf("appendacl failed: %s\n", nt_errstr(status));
276 /* set parameters for appendacl async call */
278 printf("testing parallel appendacl with %d ops\n", num_ops);
280 c = talloc_array(mem_ctx, struct composite_context *, num_ops);
281 io = talloc_array(mem_ctx, struct smb_composite_appendacl *, num_ops);
283 for (i=0; i < num_ops; i++) {
284 io[i] = talloc (io, struct smb_composite_appendacl);
285 io[i]->in.sd = test_sd;
286 io[i]->in.fname = talloc_asprintf(io[i], BASEDIR "\\test%d.txt", i);
288 c[i] = smb_composite_appendacl_send(cli->tree, io[i]);
289 c[i]->async.fn = loadfile_complete;
290 c[i]->async.private_data = count;
293 event_ctx = talloc_reference(mem_ctx, cli->tree->session->transport->socket->event.ctx);
294 printf("waiting for completion\n");
295 while (*count != num_ops) {
296 event_loop_once(event_ctx);
297 printf("count=%d\r", *count);
300 printf("count=%d\n", *count);
302 for (i=0; i < num_ops; i++) {
303 status = smb_composite_appendacl_recv(c[i], io[i]);
304 if (!NT_STATUS_IS_OK(status)) {
305 printf("appendacl[%d] failed - %s\n", i, nt_errstr(status));
309 security_descriptor_dacl_add(io_orig[i]->out.sd, ace);
310 if (!security_acl_equal(io_orig[i]->out.sd->dacl, io[i]->out.sd->dacl)) {
311 printf("appendacl[%d] failed - needed acl isn't set\n", i);
318 talloc_free (test_sid);
319 talloc_free (test_sd);
324 /* test a query FS info by asking for share's GUID */
325 static BOOL test_fsinfo(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
329 struct smb_composite_fsinfo io1;
330 struct composite_context **c;
333 extern int torture_numops;
334 struct event_context *event_ctx;
335 int *count = talloc_zero(mem_ctx, int);
338 io1.in.dest_host = lp_parm_string(-1, "torture", "host");
340 io1.in.called_name = lp_parm_string(-1, "torture", "host");
341 io1.in.service = lp_parm_string(-1, "torture", "share");
342 io1.in.service_type = "A:";
343 io1.in.credentials = cmdline_credentials;
344 io1.in.workgroup = lp_workgroup();
345 io1.in.level = RAW_QFS_OBJECTID_INFORMATION;
347 printf("testing parallel queryfsinfo [Object ID] with %d ops\n", torture_numops);
349 event_ctx = talloc_reference(mem_ctx, cli->tree->session->transport->socket->event.ctx);
350 c = talloc_array(mem_ctx, struct composite_context *, torture_numops);
352 for (i=0; i<torture_numops; i++) {
353 c[i] = smb_composite_fsinfo_send(cli->tree,&io1);
354 c[i]->async.fn = loadfile_complete;
355 c[i]->async.private_data = count;
358 printf("waiting for completion\n");
360 while (*count < torture_numops) {
361 event_loop_once(event_ctx);
362 printf("count=%d\r", *count);
365 printf("count=%d\n", *count);
367 for (i=0;i<torture_numops;i++) {
368 status = smb_composite_fsinfo_recv(c[i], mem_ctx);
369 if (!NT_STATUS_IS_OK(status)) {
370 printf("fsinfo[%d] failed - %s\n", i, nt_errstr(status));
375 if (io1.out.fsinfo->generic.level != RAW_QFS_OBJECTID_INFORMATION) {
376 printf("wrong level in returned info - %d "
378 io1.out.fsinfo->generic.level, RAW_QFS_OBJECTID_INFORMATION);
383 guid=GUID_string(mem_ctx, &io1.out.fsinfo->objectid_information.out.guid);
384 printf("[%d] GUID: %s\n", i, guid);
394 basic testing of libcli composite calls
396 BOOL torture_raw_composite(struct torture_context *torture)
398 struct smbcli_state *cli;
402 if (!torture_open_connection(&cli)) {
406 mem_ctx = talloc_init("torture_raw_composite");
408 if (!torture_setup_dir(cli, BASEDIR)) {
412 ret &= test_fetchfile(cli, mem_ctx);
413 ret &= test_loadfile(cli, mem_ctx);
414 ret &= test_appendacl(cli, mem_ctx);
415 ret &= test_fsinfo(cli, mem_ctx);
417 smb_raw_exit(cli->session);
418 smbcli_deltree(cli->tree, BASEDIR);
420 torture_close_connection(cli);
421 talloc_free(mem_ctx);