2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 1997-2003
5 Copyright (C) Jelmer Vernooij 2006
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "torture/torture.h"
23 #include "torture/basic/proto.h"
24 #include "libcli/libcli.h"
25 #include "torture/util.h"
26 #include "system/filesys.h"
27 #include "system/time.h"
28 #include "libcli/resolve/resolve.h"
29 #include "librpc/gen_ndr/ndr_nbt.h"
30 #include "lib/events/events.h"
31 #include "lib/cmdline/popt_common.h"
32 #include "param/param.h"
35 #define CHECK_MAX_FAILURES(label) do { if (++failures >= torture_failures) goto label; } while (0)
38 static struct smbcli_state *open_nbt_connection(struct torture_context *tctx)
40 struct nbt_name called, calling;
41 struct smbcli_state *cli;
42 const char *host = torture_setting_string(tctx, "host", NULL);
44 make_nbt_name_client(&calling, lp_netbios_name());
46 nbt_choose_called_name(NULL, &called, host, NBT_NAME_SERVER);
48 cli = smbcli_state_init(NULL);
50 torture_comment(tctx, "Failed initialize smbcli_struct to connect with %s\n", host);
54 if (!smbcli_socket_connect(cli, host)) {
55 torture_comment(tctx, "Failed to connect with %s\n", host);
59 if (!smbcli_transport_establish(cli, &calling, &called)) {
60 torture_comment(tctx, "%s rejected the session\n",host);
71 static BOOL tcon_devtest(struct torture_context *tctx,
72 struct smbcli_state *cli,
73 const char *myshare, const char *devtype,
74 NTSTATUS expected_error)
77 const char *password = torture_setting_string(tctx, "password", NULL);
79 status = NT_STATUS_IS_OK(smbcli_tconX(cli, myshare, devtype,
82 torture_comment(tctx, "Trying share %s with devtype %s\n", myshare, devtype);
84 if (NT_STATUS_IS_OK(expected_error)) {
86 torture_fail(tctx, talloc_asprintf(tctx,
87 "tconX to share %s with type %s "
88 "should have succeeded but failed",
94 torture_fail(tctx, talloc_asprintf(tctx,
95 "tconx to share %s with type %s "
96 "should have failed but succeeded",
99 if (NT_STATUS_EQUAL(smbcli_nt_error(cli->tree),
102 torture_fail(tctx, "Returned unexpected error");
112 test whether fnums and tids open on one VC are available on another (a major
115 static bool run_fdpasstest(struct torture_context *tctx,
116 struct smbcli_state *cli1,
117 struct smbcli_state *cli2)
119 const char *fname = "\\fdpass.tst";
123 smbcli_unlink(cli1->tree, fname);
125 torture_comment(tctx, "Opening a file on connection 1\n");
127 fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
128 torture_assert(tctx, fnum1 != -1,
129 talloc_asprintf(tctx,
130 "open of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree)));
132 torture_comment(tctx, "writing to file on connection 1\n");
135 smbcli_write(cli1->tree, fnum1, 0, "hello world\n", 0, 13) == 13,
136 talloc_asprintf(tctx,
137 "write failed (%s)\n", smbcli_errstr(cli1->tree)));
139 oldtid = cli2->tree->tid;
140 cli2->session->vuid = cli1->session->vuid;
141 cli2->tree->tid = cli1->tree->tid;
142 cli2->session->pid = cli1->session->pid;
144 torture_comment(tctx, "reading from file on connection 2\n");
146 torture_assert(tctx, smbcli_read(cli2->tree, fnum1, buf, 0, 13) != 13,
147 talloc_asprintf(tctx,
148 "read succeeded! nasty security hole [%s]\n", buf));
150 smbcli_close(cli1->tree, fnum1);
151 smbcli_unlink(cli1->tree, fname);
153 cli2->tree->tid = oldtid;
159 This checks how the getatr calls works
161 static BOOL run_attrtest(struct torture_context *tctx,
162 struct smbcli_state *cli)
166 const char *fname = "\\attrib123456789.tst";
169 smbcli_unlink(cli->tree, fname);
170 fnum = smbcli_open(cli->tree, fname,
171 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
172 smbcli_close(cli->tree, fnum);
174 if (NT_STATUS_IS_ERR(smbcli_getatr(cli->tree, fname, NULL, NULL, &t))) {
175 torture_comment(tctx, "getatr failed (%s)\n", smbcli_errstr(cli->tree));
179 torture_comment(tctx, "New file time is %s", ctime(&t));
181 if (abs(t - time(NULL)) > 60*60*24*10) {
182 torture_comment(tctx, "ERROR: SMBgetatr bug. time is %s",
188 t2 = t-60*60*24; /* 1 day ago */
190 torture_comment(tctx, "Setting file time to %s", ctime(&t2));
192 if (NT_STATUS_IS_ERR(smbcli_setatr(cli->tree, fname, 0, t2))) {
193 torture_comment(tctx, "setatr failed (%s)\n", smbcli_errstr(cli->tree));
197 if (NT_STATUS_IS_ERR(smbcli_getatr(cli->tree, fname, NULL, NULL, &t))) {
198 torture_comment(tctx, "getatr failed (%s)\n", smbcli_errstr(cli->tree));
202 torture_comment(tctx, "Retrieved file time as %s", ctime(&t));
205 torture_comment(tctx, "ERROR: getatr/setatr bug. times are\n%s",
207 torture_comment(tctx, "%s", ctime(&t2));
211 smbcli_unlink(cli->tree, fname);
217 This checks a couple of trans2 calls
219 static BOOL run_trans2test(struct torture_context *tctx,
220 struct smbcli_state *cli)
224 time_t c_time, a_time, m_time, w_time, m_time2;
225 const char *fname = "\\trans2.tst";
226 const char *dname = "\\trans2";
227 const char *fname2 = "\\trans2\\trans2.tst";
231 smbcli_unlink(cli->tree, fname);
233 torture_comment(tctx, "Testing qfileinfo\n");
235 fnum = smbcli_open(cli->tree, fname,
236 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
237 if (NT_STATUS_IS_ERR(smbcli_qfileinfo(cli->tree, fnum, NULL, &size, &c_time, &a_time, &m_time,
239 torture_comment(tctx, "ERROR: qfileinfo failed (%s)\n", smbcli_errstr(cli->tree));
243 torture_comment(tctx, "Testing NAME_INFO\n");
245 if (NT_STATUS_IS_ERR(smbcli_qfilename(cli->tree, fnum, &pname))) {
246 torture_comment(tctx, "ERROR: qfilename failed (%s)\n", smbcli_errstr(cli->tree));
250 if (!pname || strcmp(pname, fname)) {
251 torture_comment(tctx, "qfilename gave different name? [%s] [%s]\n",
256 smbcli_close(cli->tree, fnum);
257 smbcli_unlink(cli->tree, fname);
259 fnum = smbcli_open(cli->tree, fname,
260 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
262 torture_comment(tctx, "open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
265 smbcli_close(cli->tree, fnum);
267 torture_comment(tctx, "Checking for sticky create times\n");
269 if (NT_STATUS_IS_ERR(smbcli_qpathinfo(cli->tree, fname, &c_time, &a_time, &m_time, &size, NULL))) {
270 torture_comment(tctx, "ERROR: qpathinfo failed (%s)\n", smbcli_errstr(cli->tree));
273 if (c_time != m_time) {
274 torture_comment(tctx, "create time=%s", ctime(&c_time));
275 torture_comment(tctx, "modify time=%s", ctime(&m_time));
276 torture_comment(tctx, "This system appears to have sticky create times\n");
278 if (a_time % (60*60) == 0) {
279 torture_comment(tctx, "access time=%s", ctime(&a_time));
280 torture_comment(tctx, "This system appears to set a midnight access time\n");
284 if (abs(m_time - time(NULL)) > 60*60*24*7) {
285 torture_comment(tctx, "ERROR: totally incorrect times - maybe word reversed? mtime=%s", ctime(&m_time));
291 smbcli_unlink(cli->tree, fname);
292 fnum = smbcli_open(cli->tree, fname,
293 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
294 smbcli_close(cli->tree, fnum);
295 if (NT_STATUS_IS_ERR(smbcli_qpathinfo2(cli->tree, fname, &c_time, &a_time, &m_time, &w_time, &size, NULL, NULL))) {
296 torture_comment(tctx, "ERROR: qpathinfo2 failed (%s)\n", smbcli_errstr(cli->tree));
299 if (w_time < 60*60*24*2) {
300 torture_comment(tctx, "write time=%s", ctime(&w_time));
301 torture_comment(tctx, "This system appears to set a initial 0 write time\n");
306 smbcli_unlink(cli->tree, fname);
309 /* check if the server updates the directory modification time
310 when creating a new file */
311 if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, dname))) {
312 torture_comment(tctx, "ERROR: mkdir failed (%s)\n", smbcli_errstr(cli->tree));
316 if (NT_STATUS_IS_ERR(smbcli_qpathinfo2(cli->tree, "\\trans2\\", &c_time, &a_time, &m_time, &w_time, &size, NULL, NULL))) {
317 torture_comment(tctx, "ERROR: qpathinfo2 failed (%s)\n", smbcli_errstr(cli->tree));
321 fnum = smbcli_open(cli->tree, fname2,
322 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
323 smbcli_write(cli->tree, fnum, 0, &fnum, 0, sizeof(fnum));
324 smbcli_close(cli->tree, fnum);
325 if (NT_STATUS_IS_ERR(smbcli_qpathinfo2(cli->tree, "\\trans2\\", &c_time, &a_time, &m_time2, &w_time, &size, NULL, NULL))) {
326 torture_comment(tctx, "ERROR: qpathinfo2 failed (%s)\n", smbcli_errstr(cli->tree));
329 if (m_time2 == m_time) {
330 torture_comment(tctx, "This system does not update directory modification times\n");
334 smbcli_unlink(cli->tree, fname2);
335 smbcli_rmdir(cli->tree, dname);
340 /* send smb negprot commands, not reading the response */
341 static BOOL run_negprot_nowait(struct torture_context *tctx)
344 struct smbcli_state *cli, *cli2;
347 torture_comment(tctx, "starting negprot nowait test\n");
349 cli = open_nbt_connection(tctx);
354 torture_comment(tctx, "Filling send buffer\n");
356 for (i=0;i<100;i++) {
357 struct smbcli_request *req;
358 req = smb_raw_negotiate_send(cli->transport, PROTOCOL_NT1);
359 event_loop_once(cli->transport->socket->event.ctx);
360 if (req->state == SMBCLI_REQUEST_ERROR) {
362 torture_comment(tctx, "Failed to fill pipe packet[%d] - %s (ignored)\n", i+1, nt_errstr(req->status));
365 torture_comment(tctx, "Failed to fill pipe - %s \n", nt_errstr(req->status));
366 torture_close_connection(cli);
372 torture_comment(tctx, "Opening secondary connection\n");
373 if (!torture_open_connection(&cli2, 1)) {
374 torture_comment(tctx, "Failed to open secondary connection\n");
378 if (!torture_close_connection(cli2)) {
379 torture_comment(tctx, "Failed to close secondary connection\n");
383 torture_close_connection(cli);
389 this checks to see if a secondary tconx can use open files from an
392 static BOOL run_tcon_test(struct torture_context *tctx, struct smbcli_state *cli)
394 const char *fname = "\\tcontest.tmp";
396 uint16_t cnum1, cnum2, cnum3;
397 uint16_t vuid1, vuid2;
400 struct smbcli_tree *tree1;
401 const char *host = torture_setting_string(tctx, "host", NULL);
402 const char *share = torture_setting_string(tctx, "share", NULL);
403 const char *password = torture_setting_string(tctx, "password", NULL);
405 if (smbcli_deltree(cli->tree, fname) == -1) {
406 torture_comment(tctx, "unlink of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
409 fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
411 torture_comment(tctx, "open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
415 cnum1 = cli->tree->tid;
416 vuid1 = cli->session->vuid;
418 memset(&buf, 0, 4); /* init buf so valgrind won't complain */
419 if (smbcli_write(cli->tree, fnum1, 0, buf, 130, 4) != 4) {
420 torture_comment(tctx, "initial write failed (%s)\n", smbcli_errstr(cli->tree));
424 tree1 = cli->tree; /* save old tree connection */
425 if (NT_STATUS_IS_ERR(smbcli_tconX(cli, share, "?????", password))) {
426 torture_comment(tctx, "%s refused 2nd tree connect (%s)\n", host,
427 smbcli_errstr(cli->tree));
432 cnum2 = cli->tree->tid;
433 cnum3 = MAX(cnum1, cnum2) + 1; /* any invalid number */
434 vuid2 = cli->session->vuid + 1;
436 /* try a write with the wrong tid */
437 cli->tree->tid = cnum2;
439 if (smbcli_write(cli->tree, fnum1, 0, buf, 130, 4) == 4) {
440 torture_comment(tctx, "* server allows write with wrong TID\n");
443 torture_comment(tctx, "server fails write with wrong TID : %s\n", smbcli_errstr(cli->tree));
447 /* try a write with an invalid tid */
448 cli->tree->tid = cnum3;
450 if (smbcli_write(cli->tree, fnum1, 0, buf, 130, 4) == 4) {
451 torture_comment(tctx, "* server allows write with invalid TID\n");
454 torture_comment(tctx, "server fails write with invalid TID : %s\n", smbcli_errstr(cli->tree));
457 /* try a write with an invalid vuid */
458 cli->session->vuid = vuid2;
459 cli->tree->tid = cnum1;
461 if (smbcli_write(cli->tree, fnum1, 0, buf, 130, 4) == 4) {
462 torture_comment(tctx, "* server allows write with invalid VUID\n");
465 torture_comment(tctx, "server fails write with invalid VUID : %s\n", smbcli_errstr(cli->tree));
468 cli->session->vuid = vuid1;
469 cli->tree->tid = cnum1;
471 if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnum1))) {
472 torture_comment(tctx, "close failed (%s)\n", smbcli_errstr(cli->tree));
476 cli->tree->tid = cnum2;
478 if (NT_STATUS_IS_ERR(smbcli_tdis(cli))) {
479 torture_comment(tctx, "secondary tdis failed (%s)\n", smbcli_errstr(cli->tree));
483 cli->tree = tree1; /* restore initial tree */
484 cli->tree->tid = cnum1;
486 smbcli_unlink(tree1, fname);
492 checks for correct tconX support
494 static BOOL run_tcon_devtype_test(struct torture_context *tctx,
495 struct smbcli_state *cli1)
497 const char *share = torture_setting_string(tctx, "share", NULL);
499 if (!tcon_devtest(tctx, cli1, "IPC$", "A:", NT_STATUS_BAD_DEVICE_TYPE))
502 if (!tcon_devtest(tctx, cli1, "IPC$", "?????", NT_STATUS_OK))
505 if (!tcon_devtest(tctx, cli1, "IPC$", "LPT:", NT_STATUS_BAD_DEVICE_TYPE))
508 if (!tcon_devtest(tctx, cli1, "IPC$", "IPC", NT_STATUS_OK))
511 if (!tcon_devtest(tctx, cli1, "IPC$", "FOOBA", NT_STATUS_BAD_DEVICE_TYPE))
514 if (!tcon_devtest(tctx, cli1, share, "A:", NT_STATUS_OK))
517 if (!tcon_devtest(tctx, cli1, share, "?????", NT_STATUS_OK))
520 if (!tcon_devtest(tctx, cli1, share, "LPT:", NT_STATUS_BAD_DEVICE_TYPE))
523 if (!tcon_devtest(tctx, cli1, share, "IPC", NT_STATUS_BAD_DEVICE_TYPE))
526 if (!tcon_devtest(tctx, cli1, share, "FOOBA", NT_STATUS_BAD_DEVICE_TYPE))
532 static BOOL rw_torture2(struct torture_context *tctx,
533 struct smbcli_state *c1, struct smbcli_state *c2)
535 const char *lockfname = "\\torture2.lck";
540 uint8_t buf_rd[131072];
542 ssize_t bytes_read, bytes_written;
544 torture_assert(tctx, smbcli_deltree(c1->tree, lockfname) != -1,
545 talloc_asprintf(tctx,
546 "unlink failed (%s)", smbcli_errstr(c1->tree)));
548 fnum1 = smbcli_open(c1->tree, lockfname, O_RDWR | O_CREAT | O_EXCL,
550 torture_assert(tctx, fnum1 != -1,
551 talloc_asprintf(tctx,
552 "first open read/write of %s failed (%s)",
553 lockfname, smbcli_errstr(c1->tree)));
554 fnum2 = smbcli_open(c2->tree, lockfname, O_RDONLY,
556 torture_assert(tctx, fnum2 != -1,
557 talloc_asprintf(tctx,
558 "second open read-only of %s failed (%s)",
559 lockfname, smbcli_errstr(c2->tree)));
561 torture_comment(tctx, "Checking data integrity over %d ops\n",
564 for (i=0;i<torture_numops;i++)
566 size_t buf_size = ((uint_t)random()%(sizeof(buf)-1))+ 1;
568 if (torture_setting_bool(tctx, "progress", true)) {
569 torture_comment(tctx, "%d\r", i); fflush(stdout);
573 generate_random_buffer(buf, buf_size);
575 if ((bytes_written = smbcli_write(c1->tree, fnum1, 0, buf, 0, buf_size)) != buf_size) {
576 torture_comment(tctx, "write failed (%s)\n", smbcli_errstr(c1->tree));
577 torture_comment(tctx, "wrote %d, expected %d\n", (int)bytes_written, (int)buf_size);
582 if ((bytes_read = smbcli_read(c2->tree, fnum2, buf_rd, 0, buf_size)) != buf_size) {
583 torture_comment(tctx, "read failed (%s)\n", smbcli_errstr(c2->tree));
584 torture_comment(tctx, "read %d, expected %d\n", (int)bytes_read, (int)buf_size);
589 torture_assert(tctx, memcmp(buf_rd, buf, buf_size) == 0,
590 "read/write compare failed\n");
593 torture_assert_ntstatus_ok(tctx, smbcli_close(c2->tree, fnum2),
594 talloc_asprintf(tctx, "close failed (%s)", smbcli_errstr(c2->tree)));
595 torture_assert_ntstatus_ok(tctx, smbcli_close(c1->tree, fnum1),
596 talloc_asprintf(tctx, "close failed (%s)", smbcli_errstr(c1->tree)));
598 torture_assert_ntstatus_ok(tctx, smbcli_unlink(c1->tree, lockfname),
599 talloc_asprintf(tctx, "unlink failed (%s)", smbcli_errstr(c1->tree)));
601 torture_comment(tctx, "\n");
608 static bool run_readwritetest(struct torture_context *tctx,
609 struct smbcli_state *cli1,
610 struct smbcli_state *cli2)
612 torture_comment(tctx, "Running readwritetest v1\n");
613 if (!rw_torture2(tctx, cli1, cli2))
616 torture_comment(tctx, "Running readwritetest v2\n");
618 if (!rw_torture2(tctx, cli1, cli1))
625 test the timing of deferred open requests
627 static BOOL run_deferopen(struct torture_context *tctx, struct smbcli_state *cli, int dummy)
629 const char *fname = "\\defer_open_test.dat";
635 torture_comment(tctx, "failed to connect\n");
639 torture_comment(tctx, "Testing deferred open requests.\n");
646 tv = timeval_current();
647 fnum = smbcli_nt_create_full(cli->tree, fname, 0,
649 FILE_ATTRIBUTE_NORMAL,
650 NTCREATEX_SHARE_ACCESS_NONE,
651 NTCREATEX_DISP_OPEN_IF, 0, 0);
655 if (NT_STATUS_EQUAL(smbcli_nt_error(cli->tree),NT_STATUS_SHARING_VIOLATION)) {
656 double e = timeval_elapsed(&tv);
657 if (e < 0.5 || e > 1.5) {
658 torture_comment(tctx,"Timing incorrect %.2f violation\n",
662 } while (NT_STATUS_EQUAL(smbcli_nt_error(cli->tree),NT_STATUS_SHARING_VIOLATION));
665 torture_comment(tctx,"Failed to open %s, error=%s\n", fname, smbcli_errstr(cli->tree));
669 torture_comment(tctx, "pid %u open %d\n", (unsigned)getpid(), i);
673 if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnum))) {
674 torture_comment(tctx,"Failed to close %s, error=%s\n", fname, smbcli_errstr(cli->tree));
680 if (NT_STATUS_IS_ERR(smbcli_unlink(cli->tree, fname))) {
681 /* All until the last unlink will fail with sharing violation. */
682 if (!NT_STATUS_EQUAL(smbcli_nt_error(cli->tree),NT_STATUS_SHARING_VIOLATION)) {
683 torture_comment(tctx, "unlink of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
688 torture_comment(tctx, "deferred test finished\n");
693 Try with a wrong vuid and check error message.
696 static BOOL run_vuidtest(struct torture_context *tctx,
697 struct smbcli_state *cli)
699 const char *fname = "\\vuid.tst";
702 time_t c_time, a_time, m_time;
707 smbcli_unlink(cli->tree, fname);
709 fnum = smbcli_open(cli->tree, fname,
710 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
712 orig_vuid = cli->session->vuid;
714 cli->session->vuid += 1234;
716 torture_comment(tctx, "Testing qfileinfo with wrong vuid\n");
718 if (NT_STATUS_IS_OK(result = smbcli_qfileinfo(cli->tree, fnum, NULL,
719 &size, &c_time, &a_time,
720 &m_time, NULL, NULL))) {
721 torture_fail(tctx, "qfileinfo passed with wrong vuid");
724 if (!NT_STATUS_EQUAL(cli->transport->error.e.nt_status,
725 NT_STATUS_DOS(ERRSRV, ERRbaduid)) &&
726 !NT_STATUS_EQUAL(cli->transport->error.e.nt_status,
727 NT_STATUS_INVALID_HANDLE)) {
728 torture_fail(tctx, talloc_asprintf(tctx,
729 "qfileinfo should have returned DOS error "
730 "ERRSRV:ERRbaduid\n but returned %s",
731 smbcli_errstr(cli->tree)));
734 cli->session->vuid -= 1234;
736 torture_assert_ntstatus_ok(tctx, smbcli_close(cli->tree, fnum),
737 talloc_asprintf(tctx, "close failed (%s)", smbcli_errstr(cli->tree)));
739 smbcli_unlink(cli->tree, fname);
745 Test open mode returns on read-only files.
747 static BOOL run_opentest(struct torture_context *tctx, struct smbcli_state *cli1,
748 struct smbcli_state *cli2)
750 const char *fname = "\\readonly.file";
751 char *control_char_fname;
760 asprintf(&control_char_fname, "\\readonly.afile");
761 for (i = 1; i <= 0x1f; i++) {
762 control_char_fname[10] = i;
763 fnum1 = smbcli_nt_create_full(cli1->tree, control_char_fname, 0, SEC_FILE_WRITE_DATA, FILE_ATTRIBUTE_NORMAL,
764 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
766 if (!check_error(__location__, cli1, ERRDOS, ERRinvalidname,
767 NT_STATUS_OBJECT_NAME_INVALID)) {
768 torture_comment(tctx, "Error code should be NT_STATUS_OBJECT_NAME_INVALID, was %s for file with %d char\n",
769 smbcli_errstr(cli1->tree), i);
774 smbcli_close(cli1->tree, fnum1);
776 smbcli_setatr(cli1->tree, control_char_fname, 0, 0);
777 smbcli_unlink(cli1->tree, control_char_fname);
779 free(control_char_fname);
782 torture_comment(tctx, "Create file with control char names passed.\n");
784 smbcli_setatr(cli1->tree, fname, 0, 0);
785 smbcli_unlink(cli1->tree, fname);
787 fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
789 torture_comment(tctx, "open of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
793 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
794 torture_comment(tctx, "close2 failed (%s)\n", smbcli_errstr(cli1->tree));
798 if (NT_STATUS_IS_ERR(smbcli_setatr(cli1->tree, fname, FILE_ATTRIBUTE_READONLY, 0))) {
799 torture_comment(tctx, "smbcli_setatr failed (%s)\n", smbcli_errstr(cli1->tree));
800 CHECK_MAX_FAILURES(error_test1);
804 fnum1 = smbcli_open(cli1->tree, fname, O_RDONLY, DENY_WRITE);
806 torture_comment(tctx, "open of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
807 CHECK_MAX_FAILURES(error_test1);
811 /* This will fail - but the error should be ERRnoaccess, not ERRbadshare. */
812 fnum2 = smbcli_open(cli1->tree, fname, O_RDWR, DENY_ALL);
814 if (check_error(__location__, cli1, ERRDOS, ERRnoaccess,
815 NT_STATUS_ACCESS_DENIED)) {
816 torture_comment(tctx, "correct error code ERRDOS/ERRnoaccess returned\n");
819 torture_comment(tctx, "finished open test 1\n");
821 smbcli_close(cli1->tree, fnum1);
823 /* Now try not readonly and ensure ERRbadshare is returned. */
825 smbcli_setatr(cli1->tree, fname, 0, 0);
827 fnum1 = smbcli_open(cli1->tree, fname, O_RDONLY, DENY_WRITE);
829 torture_comment(tctx, "open of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
833 /* This will fail - but the error should be ERRshare. */
834 fnum2 = smbcli_open(cli1->tree, fname, O_RDWR, DENY_ALL);
836 if (check_error(__location__, cli1, ERRDOS, ERRbadshare,
837 NT_STATUS_SHARING_VIOLATION)) {
838 torture_comment(tctx, "correct error code ERRDOS/ERRbadshare returned\n");
841 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
842 torture_comment(tctx, "close2 failed (%s)\n", smbcli_errstr(cli1->tree));
846 smbcli_unlink(cli1->tree, fname);
848 torture_comment(tctx, "finished open test 2\n");
850 /* Test truncate open disposition on file opened for read. */
852 fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
854 torture_comment(tctx, "(3) open (1) of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
858 /* write 20 bytes. */
860 memset(buf, '\0', 20);
862 if (smbcli_write(cli1->tree, fnum1, 0, buf, 0, 20) != 20) {
863 torture_comment(tctx, "write failed (%s)\n", smbcli_errstr(cli1->tree));
867 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
868 torture_comment(tctx, "(3) close1 failed (%s)\n", smbcli_errstr(cli1->tree));
872 /* Ensure size == 20. */
873 if (NT_STATUS_IS_ERR(smbcli_getatr(cli1->tree, fname, NULL, &fsize, NULL))) {
874 torture_comment(tctx, "(3) getatr failed (%s)\n", smbcli_errstr(cli1->tree));
875 CHECK_MAX_FAILURES(error_test3);
880 torture_comment(tctx, "(3) file size != 20\n");
881 CHECK_MAX_FAILURES(error_test3);
885 /* Now test if we can truncate a file opened for readonly. */
887 fnum1 = smbcli_open(cli1->tree, fname, O_RDONLY|O_TRUNC, DENY_NONE);
889 torture_comment(tctx, "(3) open (2) of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
890 CHECK_MAX_FAILURES(error_test3);
894 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
895 torture_comment(tctx, "close2 failed (%s)\n", smbcli_errstr(cli1->tree));
899 /* Ensure size == 0. */
900 if (NT_STATUS_IS_ERR(smbcli_getatr(cli1->tree, fname, NULL, &fsize, NULL))) {
901 torture_comment(tctx, "(3) getatr failed (%s)\n", smbcli_errstr(cli1->tree));
902 CHECK_MAX_FAILURES(error_test3);
907 torture_comment(tctx, "(3) file size != 0\n");
908 CHECK_MAX_FAILURES(error_test3);
911 torture_comment(tctx, "finished open test 3\n");
913 smbcli_unlink(cli1->tree, fname);
916 torture_comment(tctx, "testing ctemp\n");
917 fnum1 = smbcli_ctemp(cli1->tree, "\\", &tmp_path);
919 torture_comment(tctx, "ctemp failed (%s)\n", smbcli_errstr(cli1->tree));
920 CHECK_MAX_FAILURES(error_test4);
923 torture_comment(tctx, "ctemp gave path %s\n", tmp_path);
924 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
925 torture_comment(tctx, "close of temp failed (%s)\n", smbcli_errstr(cli1->tree));
927 if (NT_STATUS_IS_ERR(smbcli_unlink(cli1->tree, tmp_path))) {
928 torture_comment(tctx, "unlink of temp failed (%s)\n", smbcli_errstr(cli1->tree));
931 /* Test the non-io opens... */
933 smbcli_setatr(cli2->tree, fname, 0, 0);
934 smbcli_unlink(cli2->tree, fname);
936 torture_comment(tctx, "TEST #1 testing 2 non-io opens (no delete)\n");
938 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, SEC_FILE_READ_ATTRIBUTE, FILE_ATTRIBUTE_NORMAL,
939 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
942 torture_comment(tctx, "test 1 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
943 CHECK_MAX_FAILURES(error_test10);
947 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, SEC_FILE_READ_ATTRIBUTE, FILE_ATTRIBUTE_NORMAL,
948 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OPEN_IF, 0, 0);
950 torture_comment(tctx, "test 1 open 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
951 CHECK_MAX_FAILURES(error_test10);
955 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
956 torture_comment(tctx, "test 1 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
959 if (NT_STATUS_IS_ERR(smbcli_close(cli2->tree, fnum2))) {
960 torture_comment(tctx, "test 1 close 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
964 torture_comment(tctx, "non-io open test #1 passed.\n");
966 smbcli_unlink(cli1->tree, fname);
968 torture_comment(tctx, "TEST #2 testing 2 non-io opens (first with delete)\n");
970 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, SEC_STD_DELETE|SEC_FILE_READ_ATTRIBUTE, FILE_ATTRIBUTE_NORMAL,
971 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
974 torture_comment(tctx, "test 2 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
975 CHECK_MAX_FAILURES(error_test20);
979 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, SEC_FILE_READ_ATTRIBUTE, FILE_ATTRIBUTE_NORMAL,
980 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OPEN_IF, 0, 0);
983 torture_comment(tctx, "test 2 open 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
984 CHECK_MAX_FAILURES(error_test20);
988 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
989 torture_comment(tctx, "test 1 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
992 if (NT_STATUS_IS_ERR(smbcli_close(cli2->tree, fnum2))) {
993 torture_comment(tctx, "test 1 close 2 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
997 torture_comment(tctx, "non-io open test #2 passed.\n");
999 smbcli_unlink(cli1->tree, fname);
1001 torture_comment(tctx, "TEST #3 testing 2 non-io opens (second with delete)\n");
1003 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, SEC_FILE_READ_ATTRIBUTE, FILE_ATTRIBUTE_NORMAL,
1004 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1007 torture_comment(tctx, "test 3 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1008 CHECK_MAX_FAILURES(error_test30);
1012 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, SEC_STD_DELETE|SEC_FILE_READ_ATTRIBUTE, FILE_ATTRIBUTE_NORMAL,
1013 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1016 torture_comment(tctx, "test 3 open 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1017 CHECK_MAX_FAILURES(error_test30);
1021 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1022 torture_comment(tctx, "test 3 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1025 if (NT_STATUS_IS_ERR(smbcli_close(cli2->tree, fnum2))) {
1026 torture_comment(tctx, "test 3 close 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1030 torture_comment(tctx, "non-io open test #3 passed.\n");
1032 smbcli_unlink(cli1->tree, fname);
1034 torture_comment(tctx, "TEST #4 testing 2 non-io opens (both with delete)\n");
1036 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, SEC_STD_DELETE|SEC_FILE_READ_ATTRIBUTE, FILE_ATTRIBUTE_NORMAL,
1037 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1040 torture_comment(tctx, "test 4 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1041 CHECK_MAX_FAILURES(error_test40);
1045 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, SEC_STD_DELETE|SEC_FILE_READ_ATTRIBUTE, FILE_ATTRIBUTE_NORMAL,
1046 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1049 torture_comment(tctx, "test 4 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1050 CHECK_MAX_FAILURES(error_test40);
1054 torture_comment(tctx, "test 4 open 2 of %s gave %s (correct error should be %s)\n", fname, smbcli_errstr(cli2->tree), "sharing violation");
1056 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1057 torture_comment(tctx, "test 4 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1061 torture_comment(tctx, "non-io open test #4 passed.\n");
1063 smbcli_unlink(cli1->tree, fname);
1065 torture_comment(tctx, "TEST #5 testing 2 non-io opens (both with delete - both with file share delete)\n");
1067 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, SEC_STD_DELETE|SEC_FILE_READ_ATTRIBUTE, FILE_ATTRIBUTE_NORMAL,
1068 NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1071 torture_comment(tctx, "test 5 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1072 CHECK_MAX_FAILURES(error_test50);
1076 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, SEC_STD_DELETE|SEC_FILE_READ_ATTRIBUTE, FILE_ATTRIBUTE_NORMAL,
1077 NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1080 torture_comment(tctx, "test 5 open 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1081 CHECK_MAX_FAILURES(error_test50);
1085 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1086 torture_comment(tctx, "test 5 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1090 if (NT_STATUS_IS_ERR(smbcli_close(cli2->tree, fnum2))) {
1091 torture_comment(tctx, "test 5 close 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1095 torture_comment(tctx, "non-io open test #5 passed.\n");
1097 torture_comment(tctx, "TEST #6 testing 1 non-io open, one io open\n");
1099 smbcli_unlink(cli1->tree, fname);
1101 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, SEC_FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
1102 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1105 torture_comment(tctx, "test 6 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1106 CHECK_MAX_FAILURES(error_test60);
1110 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, SEC_FILE_READ_ATTRIBUTE, FILE_ATTRIBUTE_NORMAL,
1111 NTCREATEX_SHARE_ACCESS_READ, NTCREATEX_DISP_OPEN_IF, 0, 0);
1114 torture_comment(tctx, "test 6 open 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1115 CHECK_MAX_FAILURES(error_test60);
1119 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1120 torture_comment(tctx, "test 6 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1124 if (NT_STATUS_IS_ERR(smbcli_close(cli2->tree, fnum2))) {
1125 torture_comment(tctx, "test 6 close 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1129 torture_comment(tctx, "non-io open test #6 passed.\n");
1131 torture_comment(tctx, "TEST #7 testing 1 non-io open, one io open with delete\n");
1133 smbcli_unlink(cli1->tree, fname);
1135 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, SEC_FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
1136 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1139 torture_comment(tctx, "test 7 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1140 CHECK_MAX_FAILURES(error_test70);
1144 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, SEC_STD_DELETE|SEC_FILE_READ_ATTRIBUTE, FILE_ATTRIBUTE_NORMAL,
1145 NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1148 torture_comment(tctx, "test 7 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1149 CHECK_MAX_FAILURES(error_test70);
1153 torture_comment(tctx, "test 7 open 2 of %s gave %s (correct error should be %s)\n", fname, smbcli_errstr(cli2->tree), "sharing violation");
1155 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1156 torture_comment(tctx, "test 7 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1160 torture_comment(tctx, "non-io open test #7 passed.\n");
1164 torture_comment(tctx, "TEST #8 testing one normal open, followed by lock, followed by open with truncate\n");
1166 smbcli_unlink(cli1->tree, fname);
1168 fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
1170 torture_comment(tctx, "(8) open (1) of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1174 /* write 20 bytes. */
1176 memset(buf, '\0', 20);
1178 if (smbcli_write(cli1->tree, fnum1, 0, buf, 0, 20) != 20) {
1179 torture_comment(tctx, "(8) write failed (%s)\n", smbcli_errstr(cli1->tree));
1183 /* Ensure size == 20. */
1184 if (NT_STATUS_IS_ERR(smbcli_getatr(cli1->tree, fname, NULL, &fsize, NULL))) {
1185 torture_comment(tctx, "(8) getatr (1) failed (%s)\n", smbcli_errstr(cli1->tree));
1186 CHECK_MAX_FAILURES(error_test80);
1191 torture_comment(tctx, "(8) file size != 20\n");
1192 CHECK_MAX_FAILURES(error_test80);
1196 /* Get an exclusive lock on the open file. */
1197 if (NT_STATUS_IS_ERR(smbcli_lock(cli1->tree, fnum1, 0, 4, 0, WRITE_LOCK))) {
1198 torture_comment(tctx, "(8) lock1 failed (%s)\n", smbcli_errstr(cli1->tree));
1199 CHECK_MAX_FAILURES(error_test80);
1203 fnum2 = smbcli_open(cli1->tree, fname, O_RDWR|O_TRUNC, DENY_NONE);
1205 torture_comment(tctx, "(8) open (2) of %s with truncate failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1209 /* Ensure size == 0. */
1210 if (NT_STATUS_IS_ERR(smbcli_getatr(cli1->tree, fname, NULL, &fsize, NULL))) {
1211 torture_comment(tctx, "(8) getatr (2) failed (%s)\n", smbcli_errstr(cli1->tree));
1212 CHECK_MAX_FAILURES(error_test80);
1217 torture_comment(tctx, "(8) file size != 0\n");
1218 CHECK_MAX_FAILURES(error_test80);
1222 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1223 torture_comment(tctx, "(8) close1 failed (%s)\n", smbcli_errstr(cli1->tree));
1227 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum2))) {
1228 torture_comment(tctx, "(8) close1 failed (%s)\n", smbcli_errstr(cli1->tree));
1234 torture_comment(tctx, "open test #8 passed.\n");
1236 smbcli_unlink(cli1->tree, fname);
1241 /* FIRST_DESIRED_ACCESS 0xf019f */
1242 #define FIRST_DESIRED_ACCESS SEC_FILE_READ_DATA|SEC_FILE_WRITE_DATA|SEC_FILE_APPEND_DATA|\
1243 SEC_FILE_READ_EA| /* 0xf */ \
1244 SEC_FILE_WRITE_EA|SEC_FILE_READ_ATTRIBUTE| /* 0x90 */ \
1245 SEC_FILE_WRITE_ATTRIBUTE| /* 0x100 */ \
1246 SEC_STD_DELETE|SEC_STD_READ_CONTROL|\
1247 SEC_STD_WRITE_DAC|SEC_STD_WRITE_OWNER /* 0xf0000 */
1248 /* SECOND_DESIRED_ACCESS 0xe0080 */
1249 #define SECOND_DESIRED_ACCESS SEC_FILE_READ_ATTRIBUTE| /* 0x80 */ \
1250 SEC_STD_READ_CONTROL|SEC_STD_WRITE_DAC|\
1251 SEC_STD_WRITE_OWNER /* 0xe0000 */
1254 #define THIRD_DESIRED_ACCESS FILE_READ_ATTRIBUTE| /* 0x80 */ \
1255 READ_CONTROL|WRITE_DAC|\
1256 SEC_FILE_READ_DATA|\
1263 Test ntcreate calls made by xcopy
1265 static bool run_xcopy(struct torture_context *tctx,
1266 struct smbcli_state *cli1)
1268 const char *fname = "\\test.txt";
1271 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0,
1272 FIRST_DESIRED_ACCESS,
1273 FILE_ATTRIBUTE_ARCHIVE,
1274 NTCREATEX_SHARE_ACCESS_NONE,
1275 NTCREATEX_DISP_OVERWRITE_IF,
1278 torture_assert(tctx, fnum1 != -1, talloc_asprintf(tctx,
1279 "First open failed - %s", smbcli_errstr(cli1->tree)));
1281 fnum2 = smbcli_nt_create_full(cli1->tree, fname, 0,
1282 SECOND_DESIRED_ACCESS, 0,
1283 NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE|NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OPEN,
1285 torture_assert(tctx, fnum2 != -1, talloc_asprintf(tctx,
1286 "second open failed - %s", smbcli_errstr(cli1->tree)));
1291 static bool run_iometer(struct torture_context *tctx,
1292 struct smbcli_state *cli)
1294 const char *fname = "\\iobw.tst";
1301 memset(buf, 0, sizeof(buf));
1303 status = smbcli_getatr(cli->tree, fname, NULL, &filesize, NULL);
1304 torture_assert_ntstatus_ok(tctx, status,
1305 talloc_asprintf(tctx, "smbcli_getatr failed: %s", nt_errstr(status)));
1307 torture_comment(tctx, "size: %d\n", (int)filesize);
1309 filesize -= (sizeof(buf) - 1);
1311 fnum = smbcli_nt_create_full(cli->tree, fname, 0x16,
1312 0x2019f, 0, 0x3, 3, 0x42, 0x3);
1313 torture_assert(tctx, fnum != -1, talloc_asprintf(tctx, "open failed: %s",
1314 smbcli_errstr(cli->tree)));
1319 int i, num_reads, num_writes;
1321 num_reads = random() % 10;
1322 num_writes = random() % 3;
1324 for (i=0; i<num_reads; i++) {
1326 if (ops++ > torture_numops) {
1329 res = smbcli_read(cli->tree, fnum, buf,
1330 random() % filesize, sizeof(buf));
1331 torture_assert(tctx, res == sizeof(buf),
1332 talloc_asprintf(tctx, "read failed: %s",
1333 smbcli_errstr(cli->tree)));
1335 for (i=0; i<num_writes; i++) {
1337 if (ops++ > torture_numops) {
1340 res = smbcli_write(cli->tree, fnum, 0, buf,
1341 random() % filesize, sizeof(buf));
1342 torture_assert(tctx, res == sizeof(buf),
1343 talloc_asprintf(tctx, "read failed: %s",
1344 smbcli_errstr(cli->tree)));
1352 tries variants of chkpath
1354 static BOOL torture_chkpath_test(struct torture_context *tctx,
1355 struct smbcli_state *cli)
1360 torture_comment(tctx, "Testing valid and invalid paths\n");
1362 /* cleanup from an old run */
1363 smbcli_rmdir(cli->tree, "\\chkpath.dir\\dir2");
1364 smbcli_unlink(cli->tree, "\\chkpath.dir\\*");
1365 smbcli_rmdir(cli->tree, "\\chkpath.dir");
1367 if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, "\\chkpath.dir"))) {
1368 torture_comment(tctx, "mkdir1 failed : %s\n", smbcli_errstr(cli->tree));
1372 if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, "\\chkpath.dir\\dir2"))) {
1373 torture_comment(tctx, "mkdir2 failed : %s\n", smbcli_errstr(cli->tree));
1377 fnum = smbcli_open(cli->tree, "\\chkpath.dir\\foo.txt", O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1379 torture_comment(tctx, "open1 failed (%s)\n", smbcli_errstr(cli->tree));
1382 smbcli_close(cli->tree, fnum);
1384 if (NT_STATUS_IS_ERR(smbcli_chkpath(cli->tree, "\\chkpath.dir"))) {
1385 torture_comment(tctx, "chkpath1 failed: %s\n", smbcli_errstr(cli->tree));
1389 if (NT_STATUS_IS_ERR(smbcli_chkpath(cli->tree, "\\chkpath.dir\\dir2"))) {
1390 torture_comment(tctx, "chkpath2 failed: %s\n", smbcli_errstr(cli->tree));
1394 if (NT_STATUS_IS_ERR(smbcli_chkpath(cli->tree, "\\chkpath.dir\\foo.txt"))) {
1395 ret = check_error(__location__, cli, ERRDOS, ERRbadpath,
1396 NT_STATUS_NOT_A_DIRECTORY);
1398 torture_comment(tctx, "* chkpath on a file should fail\n");
1402 if (NT_STATUS_IS_ERR(smbcli_chkpath(cli->tree, "\\chkpath.dir\\bar.txt"))) {
1403 ret = check_error(__location__, cli, ERRDOS, ERRbadpath,
1404 NT_STATUS_OBJECT_NAME_NOT_FOUND);
1406 torture_comment(tctx, "* chkpath on a non existent file should fail\n");
1410 if (NT_STATUS_IS_ERR(smbcli_chkpath(cli->tree, "\\chkpath.dir\\dirxx\\bar.txt"))) {
1411 ret = check_error(__location__, cli, ERRDOS, ERRbadpath,
1412 NT_STATUS_OBJECT_PATH_NOT_FOUND);
1414 torture_comment(tctx, "* chkpath on a non existent component should fail\n");
1418 smbcli_rmdir(cli->tree, "\\chkpath.dir\\dir2");
1419 smbcli_unlink(cli->tree, "\\chkpath.dir\\*");
1420 smbcli_rmdir(cli->tree, "\\chkpath.dir");
1426 * This is a test to excercise some weird Samba3 error paths.
1429 static BOOL torture_samba3_errorpaths(struct torture_context *tctx)
1431 BOOL nt_status_support;
1432 struct smbcli_state *cli_nt = NULL, *cli_dos = NULL;
1433 BOOL result = False;
1435 const char *os2_fname = ".+,;=[].";
1436 const char *dname = "samba3_errordir";
1438 TALLOC_CTX *mem_ctx = talloc_init("samba3_errorpaths");
1441 if (mem_ctx == NULL) {
1442 torture_comment(tctx, "talloc_init failed\n");
1446 nt_status_support = lp_nt_status_support();
1448 if (!lp_set_cmdline("nt status support", "yes")) {
1449 torture_comment(tctx, "Could not set 'nt status support = yes'\n");
1453 if (!torture_open_connection(&cli_nt, 0)) {
1457 if (!lp_set_cmdline("nt status support", "no")) {
1458 torture_comment(tctx, "Could not set 'nt status support = yes'\n");
1462 if (!torture_open_connection(&cli_dos, 1)) {
1466 if (!lp_set_cmdline("nt status support",
1467 nt_status_support ? "yes":"no")) {
1468 torture_comment(tctx, "Could not reset 'nt status support = yes'");
1472 smbcli_unlink(cli_nt->tree, os2_fname);
1473 smbcli_rmdir(cli_nt->tree, dname);
1475 if (!NT_STATUS_IS_OK(smbcli_mkdir(cli_nt->tree, dname))) {
1476 torture_comment(tctx, "smbcli_mkdir(%s) failed: %s\n", dname,
1477 smbcli_errstr(cli_nt->tree));
1481 io.generic.level = RAW_OPEN_NTCREATEX;
1482 io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
1483 io.ntcreatex.in.root_fid = 0;
1484 io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
1485 io.ntcreatex.in.alloc_size = 1024*1024;
1486 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_DIRECTORY;
1487 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_NONE;
1488 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
1489 io.ntcreatex.in.create_options = 0;
1490 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
1491 io.ntcreatex.in.security_flags = 0;
1492 io.ntcreatex.in.fname = dname;
1494 status = smb_raw_open(cli_nt->tree, mem_ctx, &io);
1495 if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) {
1496 torture_comment(tctx, "(%s) incorrect status %s should be %s\n",
1497 __location__, nt_errstr(status),
1498 nt_errstr(NT_STATUS_OBJECT_NAME_COLLISION));
1501 status = smb_raw_open(cli_dos->tree, mem_ctx, &io);
1502 if (!NT_STATUS_EQUAL(status, NT_STATUS_DOS(ERRDOS, ERRfilexists))) {
1503 torture_comment(tctx, "(%s) incorrect status %s should be %s\n",
1504 __location__, nt_errstr(status),
1505 nt_errstr(NT_STATUS_DOS(ERRDOS, ERRfilexists)));
1509 status = smbcli_mkdir(cli_nt->tree, dname);
1510 if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) {
1511 torture_comment(tctx, "(%s) incorrect status %s should be %s\n",
1512 __location__, nt_errstr(status),
1513 nt_errstr(NT_STATUS_OBJECT_NAME_COLLISION));
1516 status = smbcli_mkdir(cli_dos->tree, dname);
1517 if (!NT_STATUS_EQUAL(status, NT_STATUS_DOS(ERRDOS, ERRnoaccess))) {
1518 torture_comment(tctx, "(%s) incorrect status %s should be %s\n",
1519 __location__, nt_errstr(status),
1520 nt_errstr(NT_STATUS_DOS(ERRDOS, ERRnoaccess)));
1526 md.t2mkdir.level = RAW_MKDIR_T2MKDIR;
1527 md.t2mkdir.in.path = dname;
1528 md.t2mkdir.in.num_eas = 0;
1529 md.t2mkdir.in.eas = NULL;
1531 status = smb_raw_mkdir(cli_nt->tree, &md);
1532 if (!NT_STATUS_EQUAL(status,
1533 NT_STATUS_OBJECT_NAME_COLLISION)) {
1535 tctx, "(%s) incorrect status %s should be "
1536 "NT_STATUS_OBJECT_NAME_COLLISION\n",
1537 __location__, nt_errstr(status));
1540 status = smb_raw_mkdir(cli_dos->tree, &md);
1541 if (!NT_STATUS_EQUAL(status,
1542 NT_STATUS_DOS(ERRDOS, ERRrename))) {
1543 torture_comment(tctx, "(%s) incorrect status %s "
1544 "should be ERRDOS:ERRrename\n",
1545 __location__, nt_errstr(status));
1550 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
1551 status = smb_raw_open(cli_nt->tree, mem_ctx, &io);
1552 if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) {
1553 torture_comment(tctx, "(%s) incorrect status %s should be %s\n",
1554 __location__, nt_errstr(status),
1555 nt_errstr(NT_STATUS_OBJECT_NAME_COLLISION));
1559 status = smb_raw_open(cli_dos->tree, mem_ctx, &io);
1560 if (!NT_STATUS_EQUAL(status, NT_STATUS_DOS(ERRDOS, ERRfilexists))) {
1561 torture_comment(tctx, "(%s) incorrect status %s should be %s\n",
1562 __location__, nt_errstr(status),
1563 nt_errstr(NT_STATUS_DOS(ERRDOS, ERRfilexists)));
1568 /* Test an invalid DOS deny mode */
1569 const char *fname = "test.txt";
1571 fnum = smbcli_open(cli_nt->tree, fname, O_RDWR | O_CREAT, 5);
1573 torture_comment(tctx, "Open(%s) with invalid deny mode succeeded -- "
1574 "expected failure\n", fname);
1575 smbcli_close(cli_nt->tree, fnum);
1578 if (!NT_STATUS_EQUAL(smbcli_nt_error(cli_nt->tree),
1579 NT_STATUS_DOS(ERRDOS,ERRbadaccess))) {
1580 torture_comment(tctx, "Expected DOS error ERRDOS/ERRbadaccess, "
1581 "got %s\n", smbcli_errstr(cli_nt->tree));
1585 fnum = smbcli_open(cli_dos->tree, fname, O_RDWR | O_CREAT, 5);
1587 torture_comment(tctx, "Open(%s) with invalid deny mode succeeded -- "
1588 "expected failure\n", fname);
1589 smbcli_close(cli_nt->tree, fnum);
1592 if (!NT_STATUS_EQUAL(smbcli_nt_error(cli_nt->tree),
1593 NT_STATUS_DOS(ERRDOS,ERRbadaccess))) {
1594 torture_comment(tctx, "Expected DOS error ERRDOS:ERRbadaccess, "
1595 "got %s\n", smbcli_errstr(cli_nt->tree));
1602 * Samba 3.0.23 has a bug that an existing file can be opened
1603 * as a directory using ntcreate&x. Test this.
1606 const char *fname = "\\test_dir.txt";
1608 fnum = smbcli_open(cli_nt->tree, fname, O_RDWR|O_CREAT,
1611 d_printf("(%s) smbcli_open failed: %s\n", __location__,
1612 smbcli_errstr(cli_nt->tree));
1614 smbcli_close(cli_nt->tree, fnum);
1616 io.generic.level = RAW_OPEN_NTCREATEX;
1617 io.ntcreatex.in.root_fid = 0;
1618 io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
1619 io.ntcreatex.in.alloc_size = 0;
1620 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_DIRECTORY;
1621 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ|
1622 NTCREATEX_SHARE_ACCESS_WRITE|
1623 NTCREATEX_SHARE_ACCESS_DELETE;
1624 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
1625 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
1626 io.ntcreatex.in.impersonation =
1627 NTCREATEX_IMPERSONATION_ANONYMOUS;
1628 io.ntcreatex.in.security_flags = 0;
1629 io.ntcreatex.in.fname = fname;
1630 io.ntcreatex.in.flags = 0;
1632 status = smb_raw_open(cli_nt->tree, mem_ctx, &io);
1633 if (!NT_STATUS_EQUAL(status, NT_STATUS_NOT_A_DIRECTORY)) {
1634 torture_comment(tctx, "ntcreate as dir gave %s, "
1635 "expected NT_STATUS_NOT_A_DIRECTORY\n",
1640 if (NT_STATUS_IS_OK(status)) {
1641 smbcli_close(cli_nt->tree, io.ntcreatex.out.file.fnum);
1644 status = smb_raw_open(cli_dos->tree, mem_ctx, &io);
1645 if (!NT_STATUS_EQUAL(status, NT_STATUS_DOS(ERRDOS,
1646 ERRbaddirectory))) {
1647 torture_comment(tctx, "ntcreate as dir gave %s, "
1648 "expected NT_STATUS_NOT_A_DIRECTORY\n",
1653 if (NT_STATUS_IS_OK(status)) {
1654 smbcli_close(cli_dos->tree,
1655 io.ntcreatex.out.file.fnum);
1658 smbcli_unlink(cli_nt->tree, fname);
1661 if (!torture_setting_bool(tctx, "samba3", False)) {
1665 fnum = smbcli_open(cli_dos->tree, os2_fname,
1666 O_RDWR | O_CREAT | O_TRUNC,
1669 torture_comment(tctx, "Open(%s) succeeded -- expected failure\n",
1671 smbcli_close(cli_dos->tree, fnum);
1675 if (!NT_STATUS_EQUAL(smbcli_nt_error(cli_dos->tree),
1676 NT_STATUS_DOS(ERRDOS, ERRcannotopen))) {
1677 torture_comment(tctx, "Expected DOS error ERRDOS/ERRcannotopen, got %s\n",
1678 smbcli_errstr(cli_dos->tree));
1682 fnum = smbcli_open(cli_nt->tree, os2_fname,
1683 O_RDWR | O_CREAT | O_TRUNC,
1686 torture_comment(tctx, "Open(%s) succeeded -- expected failure\n",
1688 smbcli_close(cli_nt->tree, fnum);
1692 if (!NT_STATUS_EQUAL(smbcli_nt_error(cli_nt->tree),
1693 NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
1694 torture_comment(tctx, "Expected error NT_STATUS_OBJECT_NAME_NOT_FOUND, "
1695 "got %s\n", smbcli_errstr(cli_nt->tree));
1703 if (cli_dos != NULL) {
1704 torture_close_connection(cli_dos);
1706 if (cli_nt != NULL) {
1707 torture_close_connection(cli_nt);
1714 NTSTATUS torture_base_init(void)
1716 struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), "BASE");
1718 torture_suite_add_2smb_test(suite, "FDPASS", run_fdpasstest);
1719 torture_suite_add_suite(suite, torture_base_locktest(suite));
1720 torture_suite_add_1smb_test(suite, "UNLINK", torture_unlinktest);
1721 torture_suite_add_1smb_test(suite, "ATTR", run_attrtest);
1722 torture_suite_add_1smb_test(suite, "TRANS2", run_trans2test);
1723 torture_suite_add_simple_test(suite, "NEGNOWAIT", run_negprot_nowait);
1724 torture_suite_add_1smb_test(suite, "DIR1", torture_dirtest1);
1725 torture_suite_add_1smb_test(suite, "DIR2", torture_dirtest2);
1726 torture_suite_add_1smb_test(suite, "DENY1", torture_denytest1);
1727 torture_suite_add_2smb_test(suite, "DENY2", torture_denytest2);
1728 torture_suite_add_2smb_test(suite, "DENY3", torture_denytest3);
1729 torture_suite_add_1smb_test(suite, "DENYDOS", torture_denydos_sharing);
1730 torture_suite_add_smb_multi_test(suite, "NTDENY1", torture_ntdenytest1);
1731 torture_suite_add_2smb_test(suite, "NTDENY2", torture_ntdenytest2);
1732 torture_suite_add_1smb_test(suite, "TCON", run_tcon_test);
1733 torture_suite_add_1smb_test(suite, "TCONDEV", run_tcon_devtype_test);
1734 torture_suite_add_1smb_test(suite, "VUID", run_vuidtest);
1735 torture_suite_add_2smb_test(suite, "RW1", run_readwritetest);
1736 torture_suite_add_2smb_test(suite, "OPEN", run_opentest);
1737 torture_suite_add_smb_multi_test(suite, "DEFER_OPEN", run_deferopen);
1738 torture_suite_add_1smb_test(suite, "XCOPY", run_xcopy);
1739 torture_suite_add_1smb_test(suite, "IOMETER", run_iometer);
1740 torture_suite_add_1smb_test(suite, "RENAME", torture_test_rename);
1741 torture_suite_add_suite(suite, torture_test_delete());
1742 torture_suite_add_1smb_test(suite, "PROPERTIES", torture_test_properties);
1743 torture_suite_add_1smb_test(suite, "MANGLE", torture_mangle);
1744 torture_suite_add_1smb_test(suite, "OPENATTR", torture_openattrtest);
1745 torture_suite_add_suite(suite, torture_charset(suite));
1746 torture_suite_add_1smb_test(suite, "CHKPATH", torture_chkpath_test);
1747 torture_suite_add_1smb_test(suite, "SECLEAK", torture_sec_leak);
1748 torture_suite_add_simple_test(suite, "DISCONNECT", torture_disconnect);
1749 torture_suite_add_suite(suite, torture_delay_write());
1750 torture_suite_add_simple_test(suite, "SAMBA3ERROR", torture_samba3_errorpaths);
1751 torture_suite_add_1smb_test(suite, "CASETABLE", torture_casetable);
1752 torture_suite_add_1smb_test(suite, "UTABLE", torture_utable);
1753 torture_suite_add_simple_test(suite, "SMB", torture_smb_scan);
1754 torture_suite_add_suite(suite, torture_trans2_aliases(suite));
1755 torture_suite_add_1smb_test(suite, "TRANS2-SCAN", torture_trans2_scan);
1756 torture_suite_add_1smb_test(suite, "NTTRANS", torture_nttrans_scan);
1758 torture_suite_add_simple_test(suite, "BENCH-HOLDCON", torture_holdcon);
1759 torture_suite_add_simple_test(suite, "BENCH-READWRITE", run_benchrw);
1760 torture_suite_add_smb_multi_test(suite, "BENCH-TORTURE", run_torture);
1761 torture_suite_add_1smb_test(suite, "SCAN-PIPE_NUMBER", run_pipe_number);
1762 torture_suite_add_1smb_test(suite, "SCAN-IOCTL", torture_ioctl_test);
1763 torture_suite_add_smb_multi_test(suite, "SCAN-MAXFID", run_maxfidtest);
1765 suite->description = talloc_strdup(suite,
1766 "Basic SMB tests (imported from the original smbtorture)");
1768 torture_register_suite(suite);
1770 return NT_STATUS_OK;