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 3 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, see <http://www.gnu.org/licenses/>.
23 #include "torture/torture.h"
24 #include "lib/events/events.h"
25 #include "libcli/raw/libcliraw.h"
26 #include "libcli/libcli.h"
27 #include "libcli/security/security.h"
28 #include "libcli/composite/composite.h"
29 #include "libcli/smb_composite/smb_composite.h"
30 #include "librpc/gen_ndr/ndr_misc.h"
31 #include "lib/cmdline/popt_common.h"
32 #include "torture/util.h"
33 #include "param/param.h"
34 #include "libcli/resolve/resolve.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, struct torture_context *tctx)
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(tctx, int);
60 data = talloc_array(tctx, 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("(%s) savefile failed: %s\n", __location__,nt_errstr(status));
78 printf("testing parallel loadfile with %d ops\n", num_ops);
80 c = talloc_array(tctx, 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 if (torture_setting_bool(tctx, "progress", true)) {
92 printf("(%s) count=%d\r", __location__, *count);
96 printf("count=%d\n", *count);
98 for (i=0;i<num_ops;i++) {
99 status = smb_composite_loadfile_recv(c[i], tctx);
100 if (!NT_STATUS_IS_OK(status)) {
101 printf("(%s) loadfile[%d] failed - %s\n", __location__, i, nt_errstr(status));
105 if (io2.out.size != len) {
106 printf("(%s) wrong length in returned data - %d should be %d\n",__location__,
107 io2.out.size, (int)len);
111 if (memcmp(io2.out.data, data, len) != 0) {
112 printf("(%s) wrong data in loadfile!\n",__location__);
123 test a simple savefile/loadfile combination
125 static bool test_fetchfile(struct smbcli_state *cli, struct torture_context *tctx)
127 const char *fname = BASEDIR "\\test.txt";
129 struct smb_composite_savefile io1;
130 struct smb_composite_fetchfile io2;
131 struct composite_context **c;
134 size_t len = random() % 10000;
135 extern int torture_numops;
136 struct event_context *event_ctx;
137 int *count = talloc_zero(tctx, int);
140 data = talloc_array(tctx, uint8_t, len);
142 generate_random_buffer(data, len);
144 io1.in.fname = fname;
148 printf("testing savefile\n");
150 status = smb_composite_savefile(cli->tree, &io1);
151 if (!NT_STATUS_IS_OK(status)) {
152 printf("(%s) savefile failed: %s\n",__location__, nt_errstr(status));
156 io2.in.dest_host = torture_setting_string(tctx, "host", NULL);
157 io2.in.ports = lp_smb_ports(tctx->lp_ctx);
158 io2.in.called_name = torture_setting_string(tctx, "host", NULL);
159 io2.in.service = torture_setting_string(tctx, "share", NULL);
160 io2.in.service_type = "A:";
162 io2.in.credentials = cmdline_credentials;
163 io2.in.workgroup = lp_workgroup(tctx->lp_ctx);
164 io2.in.filename = fname;
165 io2.in.resolve_ctx = lp_resolve_context(tctx->lp_ctx);
166 lp_smbcli_options(tctx->lp_ctx, &io2.in.options);
168 printf("testing parallel fetchfile with %d ops\n", torture_numops);
170 event_ctx = cli->transport->socket->event.ctx;
171 c = talloc_array(tctx, struct composite_context *, torture_numops);
173 for (i=0; i<torture_numops; i++) {
174 c[i] = smb_composite_fetchfile_send(&io2, event_ctx);
175 c[i]->async.fn = loadfile_complete;
176 c[i]->async.private_data = count;
179 printf("waiting for completion\n");
181 while (*count != torture_numops) {
182 event_loop_once(event_ctx);
183 if (torture_setting_bool(tctx, "progress", true)) {
184 printf("(%s) count=%d\r", __location__, *count);
188 printf("count=%d\n", *count);
190 for (i=0;i<torture_numops;i++) {
191 status = smb_composite_fetchfile_recv(c[i], tctx);
192 if (!NT_STATUS_IS_OK(status)) {
193 printf("(%s) loadfile[%d] failed - %s\n", __location__, i,
199 if (io2.out.size != len) {
200 printf("(%s) wrong length in returned data - %d "
201 "should be %d\n", __location__,
202 io2.out.size, (int)len);
207 if (memcmp(io2.out.data, data, len) != 0) {
208 printf("(%s) wrong data in loadfile!\n", __location__);
220 static bool test_appendacl(struct smbcli_state *cli, struct torture_context *tctx)
222 struct smb_composite_appendacl **io;
223 struct smb_composite_appendacl **io_orig;
224 struct composite_context **c;
225 struct event_context *event_ctx;
227 struct security_descriptor *test_sd;
228 struct security_ace *ace;
229 struct dom_sid *test_sid;
231 const int num_ops = 50;
232 int *count = talloc_zero(tctx, int);
233 struct smb_composite_savefile io1;
238 io_orig = talloc_array(tctx, struct smb_composite_appendacl *, num_ops);
240 printf ("creating %d empty files and getting their acls with appendacl\n", num_ops);
242 for (i = 0; i < num_ops; i++) {
243 io1.in.fname = talloc_asprintf(io_orig, BASEDIR "\\test%d.txt", i);
247 status = smb_composite_savefile(cli->tree, &io1);
248 if (!NT_STATUS_IS_OK(status)) {
249 printf("(%s) savefile failed: %s\n", __location__, nt_errstr(status));
253 io_orig[i] = talloc (io_orig, struct smb_composite_appendacl);
254 io_orig[i]->in.fname = talloc_steal(io_orig[i], io1.in.fname);
255 io_orig[i]->in.sd = security_descriptor_initialise(io_orig[i]);
256 status = smb_composite_appendacl(cli->tree, io_orig[i], io_orig[i]);
257 if (!NT_STATUS_IS_OK(status)) {
258 printf("(%s) appendacl failed: %s\n", __location__, nt_errstr(status));
264 /* fill Security Descriptor with aces to be added */
266 test_sd = security_descriptor_initialise(tctx);
267 test_sid = dom_sid_parse_talloc (tctx, "S-1-5-32-1234-5432");
269 ace = talloc_zero(tctx, struct security_ace);
271 ace->type = SEC_ACE_TYPE_ACCESS_ALLOWED;
273 ace->access_mask = SEC_STD_ALL;
274 ace->trustee = *test_sid;
276 status = security_descriptor_dacl_add(test_sd, ace);
277 if (!NT_STATUS_IS_OK(status)) {
278 printf("(%s) appendacl failed: %s\n", __location__, nt_errstr(status));
282 /* set parameters for appendacl async call */
284 printf("testing parallel appendacl with %d ops\n", num_ops);
286 c = talloc_array(tctx, struct composite_context *, num_ops);
287 io = talloc_array(tctx, struct smb_composite_appendacl *, num_ops);
289 for (i=0; i < num_ops; i++) {
290 io[i] = talloc (io, struct smb_composite_appendacl);
291 io[i]->in.sd = test_sd;
292 io[i]->in.fname = talloc_asprintf(io[i], BASEDIR "\\test%d.txt", i);
294 c[i] = smb_composite_appendacl_send(cli->tree, io[i]);
295 c[i]->async.fn = loadfile_complete;
296 c[i]->async.private_data = count;
299 event_ctx = tctx->ev;
300 printf("waiting for completion\n");
301 while (*count != num_ops) {
302 event_loop_once(event_ctx);
303 if (torture_setting_bool(tctx, "progress", true)) {
304 printf("(%s) count=%d\r", __location__, *count);
308 printf("count=%d\n", *count);
310 for (i=0; i < num_ops; i++) {
311 status = smb_composite_appendacl_recv(c[i], io[i]);
312 if (!NT_STATUS_IS_OK(status)) {
313 printf("(%s) appendacl[%d] failed - %s\n", __location__, i, nt_errstr(status));
317 security_descriptor_dacl_add(io_orig[i]->out.sd, ace);
318 if (!security_acl_equal(io_orig[i]->out.sd->dacl, io[i]->out.sd->dacl)) {
319 printf("(%s) appendacl[%d] failed - needed acl isn't set\n", __location__, i);
326 talloc_free (test_sid);
327 talloc_free (test_sd);
332 /* test a query FS info by asking for share's GUID */
333 static bool test_fsinfo(struct smbcli_state *cli, struct torture_context *tctx)
337 struct smb_composite_fsinfo io1;
338 struct composite_context **c;
341 extern int torture_numops;
342 struct event_context *event_ctx;
343 int *count = talloc_zero(tctx, int);
346 io1.in.dest_host = torture_setting_string(tctx, "host", NULL);
347 io1.in.dest_ports = lp_smb_ports(tctx->lp_ctx);
348 io1.in.called_name = torture_setting_string(tctx, "host", NULL);
349 io1.in.service = torture_setting_string(tctx, "share", NULL);
350 io1.in.service_type = "A:";
351 io1.in.credentials = cmdline_credentials;
352 io1.in.workgroup = lp_workgroup(tctx->lp_ctx);
353 io1.in.level = RAW_QFS_OBJECTID_INFORMATION;
355 printf("testing parallel queryfsinfo [Object ID] with %d ops\n", torture_numops);
357 event_ctx = tctx->ev;
358 c = talloc_array(tctx, struct composite_context *, torture_numops);
360 for (i=0; i<torture_numops; i++) {
361 c[i] = smb_composite_fsinfo_send(cli->tree,&io1);
362 c[i]->async.fn = loadfile_complete;
363 c[i]->async.private_data = count;
366 printf("waiting for completion\n");
368 while (*count < torture_numops) {
369 event_loop_once(event_ctx);
370 if (torture_setting_bool(tctx, "progress", true)) {
371 printf("(%s) count=%d\r", __location__, *count);
375 printf("count=%d\n", *count);
377 for (i=0;i<torture_numops;i++) {
378 status = smb_composite_fsinfo_recv(c[i], tctx);
379 if (!NT_STATUS_IS_OK(status)) {
380 printf("(%s) fsinfo[%d] failed - %s\n", __location__, i, nt_errstr(status));
385 if (io1.out.fsinfo->generic.level != RAW_QFS_OBJECTID_INFORMATION) {
386 printf("(%s) wrong level in returned info - %d "
387 "should be %d\n", __location__,
388 io1.out.fsinfo->generic.level, RAW_QFS_OBJECTID_INFORMATION);
393 guid=GUID_string(tctx, &io1.out.fsinfo->objectid_information.out.guid);
394 printf("[%d] GUID: %s\n", i, guid);
404 basic testing of libcli composite calls
406 bool torture_raw_composite(struct torture_context *tctx,
407 struct smbcli_state *cli)
411 if (!torture_setup_dir(cli, BASEDIR)) {
415 ret &= test_fetchfile(cli, tctx);
416 ret &= test_loadfile(cli, tctx);
417 ret &= test_appendacl(cli, tctx);
418 ret &= test_fsinfo(cli, tctx);
420 smb_raw_exit(cli->session);
421 smbcli_deltree(cli->tree, BASEDIR);