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 2 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, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include "torture/torture.h"
24 #include "torture/basic/proto.h"
25 #include "libcli/libcli.h"
26 #include "torture/util.h"
27 #include "system/filesys.h"
28 #include "system/time.h"
29 #include "libcli/resolve/resolve.h"
30 #include "librpc/gen_ndr/ndr_nbt.h"
31 #include "lib/events/events.h"
32 #include "lib/cmdline/popt_common.h"
35 #define CHECK_MAX_FAILURES(label) do { if (++failures >= torture_failures) goto label; } while (0)
38 static struct smbcli_state *open_nbt_connection(void)
40 struct nbt_name called, calling;
41 struct smbcli_state *cli;
42 const char *host = lp_parm_string(-1, "torture", "host");
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 printf("Failed initialize smbcli_struct to connect with %s\n", host);
54 if (!smbcli_socket_connect(cli, host)) {
55 printf("Failed to connect with %s\n", host);
59 if (!smbcli_transport_establish(cli, &calling, &called)) {
60 printf("%s rejected the session\n",host);
71 static BOOL tcon_devtest(struct smbcli_state *cli,
72 const char *myshare, const char *devtype,
73 NTSTATUS expected_error)
77 const char *password = lp_parm_string(-1, "torture", "password");
79 status = NT_STATUS_IS_OK(smbcli_tconX(cli, myshare, devtype,
82 printf("Trying share %s with devtype %s\n", myshare, devtype);
84 if (NT_STATUS_IS_OK(expected_error)) {
88 printf("tconX to share %s with type %s "
89 "should have succeeded but failed\n",
96 printf("tconx to share %s with type %s "
97 "should have failed but succeeded\n",
101 if (NT_STATUS_EQUAL(smbcli_nt_error(cli->tree),
105 printf("Returned unexpected error\n");
116 test whether fnums and tids open on one VC are available on another (a major
119 static BOOL run_fdpasstest(struct torture_context *torture)
121 struct smbcli_state *cli1, *cli2;
122 const char *fname = "\\fdpass.tst";
126 if (!torture_open_connection(&cli1, 0) ||
127 !torture_open_connection(&cli2, 1)) {
131 printf("starting fdpasstest\n");
133 smbcli_unlink(cli1->tree, fname);
135 printf("Opening a file on connection 1\n");
137 fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
139 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
143 printf("writing to file on connection 1\n");
145 if (smbcli_write(cli1->tree, fnum1, 0, "hello world\n", 0, 13) != 13) {
146 printf("write failed (%s)\n", smbcli_errstr(cli1->tree));
150 oldtid = cli2->tree->tid;
151 cli2->session->vuid = cli1->session->vuid;
152 cli2->tree->tid = cli1->tree->tid;
153 cli2->session->pid = cli1->session->pid;
155 printf("reading from file on connection 2\n");
157 if (smbcli_read(cli2->tree, fnum1, buf, 0, 13) == 13) {
158 printf("read succeeded! nasty security hole [%s]\n",
163 smbcli_close(cli1->tree, fnum1);
164 smbcli_unlink(cli1->tree, fname);
166 cli2->tree->tid = oldtid;
168 torture_close_connection(cli1);
169 torture_close_connection(cli2);
171 printf("finished fdpasstest\n");
176 This checks how the getatr calls works
178 static BOOL run_attrtest(struct torture_context *torture)
180 struct smbcli_state *cli;
183 const char *fname = "\\attrib123456789.tst";
186 printf("starting attrib test\n");
188 if (!torture_open_connection(&cli, 0)) {
192 smbcli_unlink(cli->tree, fname);
193 fnum = smbcli_open(cli->tree, fname,
194 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
195 smbcli_close(cli->tree, fnum);
197 if (NT_STATUS_IS_ERR(smbcli_getatr(cli->tree, fname, NULL, NULL, &t))) {
198 printf("getatr failed (%s)\n", smbcli_errstr(cli->tree));
202 printf("New file time is %s", ctime(&t));
204 if (abs(t - time(NULL)) > 60*60*24*10) {
205 printf("ERROR: SMBgetatr bug. time is %s",
211 t2 = t-60*60*24; /* 1 day ago */
213 printf("Setting file time to %s", ctime(&t2));
215 if (NT_STATUS_IS_ERR(smbcli_setatr(cli->tree, fname, 0, t2))) {
216 printf("setatr failed (%s)\n", smbcli_errstr(cli->tree));
220 if (NT_STATUS_IS_ERR(smbcli_getatr(cli->tree, fname, NULL, NULL, &t))) {
221 printf("getatr failed (%s)\n", smbcli_errstr(cli->tree));
225 printf("Retrieved file time as %s", ctime(&t));
228 printf("ERROR: getatr/setatr bug. times are\n%s",
230 printf("%s", ctime(&t2));
234 smbcli_unlink(cli->tree, fname);
236 if (!torture_close_connection(cli)) {
240 printf("attrib test finished\n");
246 This checks a couple of trans2 calls
248 static BOOL run_trans2test(struct torture_context *torture)
250 struct smbcli_state *cli;
253 time_t c_time, a_time, m_time, w_time, m_time2;
254 const char *fname = "\\trans2.tst";
255 const char *dname = "\\trans2";
256 const char *fname2 = "\\trans2\\trans2.tst";
260 printf("starting trans2 test\n");
262 if (!torture_open_connection(&cli, 0)) {
266 smbcli_unlink(cli->tree, fname);
268 printf("Testing qfileinfo\n");
270 fnum = smbcli_open(cli->tree, fname,
271 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
272 if (NT_STATUS_IS_ERR(smbcli_qfileinfo(cli->tree, fnum, NULL, &size, &c_time, &a_time, &m_time,
274 printf("ERROR: qfileinfo failed (%s)\n", smbcli_errstr(cli->tree));
278 printf("Testing NAME_INFO\n");
280 if (NT_STATUS_IS_ERR(smbcli_qfilename(cli->tree, fnum, &pname))) {
281 printf("ERROR: qfilename failed (%s)\n", smbcli_errstr(cli->tree));
285 if (!pname || strcmp(pname, fname)) {
286 printf("qfilename gave different name? [%s] [%s]\n",
291 smbcli_close(cli->tree, fnum);
292 smbcli_unlink(cli->tree, fname);
294 fnum = smbcli_open(cli->tree, fname,
295 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
297 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
300 smbcli_close(cli->tree, fnum);
302 printf("Checking for sticky create times\n");
304 if (NT_STATUS_IS_ERR(smbcli_qpathinfo(cli->tree, fname, &c_time, &a_time, &m_time, &size, NULL))) {
305 printf("ERROR: qpathinfo failed (%s)\n", smbcli_errstr(cli->tree));
308 if (c_time != m_time) {
309 printf("create time=%s", ctime(&c_time));
310 printf("modify time=%s", ctime(&m_time));
311 printf("This system appears to have sticky create times\n");
313 if (a_time % (60*60) == 0) {
314 printf("access time=%s", ctime(&a_time));
315 printf("This system appears to set a midnight access time\n");
319 if (abs(m_time - time(NULL)) > 60*60*24*7) {
320 printf("ERROR: totally incorrect times - maybe word reversed? mtime=%s", ctime(&m_time));
326 smbcli_unlink(cli->tree, fname);
327 fnum = smbcli_open(cli->tree, fname,
328 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
329 smbcli_close(cli->tree, fnum);
330 if (NT_STATUS_IS_ERR(smbcli_qpathinfo2(cli->tree, fname, &c_time, &a_time, &m_time, &w_time, &size, NULL, NULL))) {
331 printf("ERROR: qpathinfo2 failed (%s)\n", smbcli_errstr(cli->tree));
334 if (w_time < 60*60*24*2) {
335 printf("write time=%s", ctime(&w_time));
336 printf("This system appears to set a initial 0 write time\n");
341 smbcli_unlink(cli->tree, fname);
344 /* check if the server updates the directory modification time
345 when creating a new file */
346 if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, dname))) {
347 printf("ERROR: mkdir failed (%s)\n", smbcli_errstr(cli->tree));
351 if (NT_STATUS_IS_ERR(smbcli_qpathinfo2(cli->tree, "\\trans2\\", &c_time, &a_time, &m_time, &w_time, &size, NULL, NULL))) {
352 printf("ERROR: qpathinfo2 failed (%s)\n", smbcli_errstr(cli->tree));
356 fnum = smbcli_open(cli->tree, fname2,
357 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
358 smbcli_write(cli->tree, fnum, 0, &fnum, 0, sizeof(fnum));
359 smbcli_close(cli->tree, fnum);
360 if (NT_STATUS_IS_ERR(smbcli_qpathinfo2(cli->tree, "\\trans2\\", &c_time, &a_time, &m_time2, &w_time, &size, NULL, NULL))) {
361 printf("ERROR: qpathinfo2 failed (%s)\n", smbcli_errstr(cli->tree));
364 if (m_time2 == m_time) {
365 printf("This system does not update directory modification times\n");
369 smbcli_unlink(cli->tree, fname2);
370 smbcli_rmdir(cli->tree, dname);
372 if (!torture_close_connection(cli)) {
376 printf("trans2 test finished\n");
381 /* send smb negprot commands, not reading the response */
382 static BOOL run_negprot_nowait(struct torture_context *torture)
385 struct smbcli_state *cli, *cli2;
388 printf("starting negprot nowait test\n");
390 cli = open_nbt_connection();
395 printf("Filling send buffer\n");
397 for (i=0;i<100;i++) {
398 struct smbcli_request *req;
399 req = smb_raw_negotiate_send(cli->transport, PROTOCOL_NT1);
400 event_loop_once(cli->transport->socket->event.ctx);
401 if (req->state == SMBCLI_REQUEST_ERROR) {
403 printf("Failed to fill pipe packet[%d] - %s (ignored)\n", i+1, nt_errstr(req->status));
406 printf("Failed to fill pipe - %s \n", nt_errstr(req->status));
407 torture_close_connection(cli);
413 printf("Opening secondary connection\n");
414 if (!torture_open_connection(&cli2, 1)) {
415 printf("Failed to open secondary connection\n");
419 if (!torture_close_connection(cli2)) {
420 printf("Failed to close secondary connection\n");
424 torture_close_connection(cli);
426 printf("finished negprot nowait test\n");
432 this checks to see if a secondary tconx can use open files from an
435 static BOOL run_tcon_test(struct torture_context *torture)
437 struct smbcli_state *cli;
438 const char *fname = "\\tcontest.tmp";
440 uint16_t cnum1, cnum2, cnum3;
441 uint16_t vuid1, vuid2;
444 struct smbcli_tree *tree1;
445 const char *host = lp_parm_string(-1, "torture", "host");
446 const char *share = lp_parm_string(-1, "torture", "share");
447 const char *password = lp_parm_string(-1, "torture", "password");
449 if (!torture_open_connection(&cli, 0)) {
453 printf("starting tcontest\n");
455 if (smbcli_deltree(cli->tree, fname) == -1) {
456 printf("unlink of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
459 fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
461 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
465 cnum1 = cli->tree->tid;
466 vuid1 = cli->session->vuid;
468 memset(&buf, 0, 4); /* init buf so valgrind won't complain */
469 if (smbcli_write(cli->tree, fnum1, 0, buf, 130, 4) != 4) {
470 printf("initial write failed (%s)\n", smbcli_errstr(cli->tree));
474 tree1 = cli->tree; /* save old tree connection */
475 if (NT_STATUS_IS_ERR(smbcli_tconX(cli, share, "?????", password))) {
476 printf("%s refused 2nd tree connect (%s)\n", host,
477 smbcli_errstr(cli->tree));
482 cnum2 = cli->tree->tid;
483 cnum3 = MAX(cnum1, cnum2) + 1; /* any invalid number */
484 vuid2 = cli->session->vuid + 1;
486 /* try a write with the wrong tid */
487 cli->tree->tid = cnum2;
489 if (smbcli_write(cli->tree, fnum1, 0, buf, 130, 4) == 4) {
490 printf("* server allows write with wrong TID\n");
493 printf("server fails write with wrong TID : %s\n", smbcli_errstr(cli->tree));
497 /* try a write with an invalid tid */
498 cli->tree->tid = cnum3;
500 if (smbcli_write(cli->tree, fnum1, 0, buf, 130, 4) == 4) {
501 printf("* server allows write with invalid TID\n");
504 printf("server fails write with invalid TID : %s\n", smbcli_errstr(cli->tree));
507 /* try a write with an invalid vuid */
508 cli->session->vuid = vuid2;
509 cli->tree->tid = cnum1;
511 if (smbcli_write(cli->tree, fnum1, 0, buf, 130, 4) == 4) {
512 printf("* server allows write with invalid VUID\n");
515 printf("server fails write with invalid VUID : %s\n", smbcli_errstr(cli->tree));
518 cli->session->vuid = vuid1;
519 cli->tree->tid = cnum1;
521 if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnum1))) {
522 printf("close failed (%s)\n", smbcli_errstr(cli->tree));
526 cli->tree->tid = cnum2;
528 if (NT_STATUS_IS_ERR(smbcli_tdis(cli))) {
529 printf("secondary tdis failed (%s)\n", smbcli_errstr(cli->tree));
533 cli->tree = tree1; /* restore initial tree */
534 cli->tree->tid = cnum1;
536 smbcli_unlink(tree1, fname);
538 if (!torture_close_connection(cli)) {
546 checks for correct tconX support
548 static BOOL run_tcon_devtype_test(struct torture_context *torture)
550 struct smbcli_state *cli1 = NULL;
553 const char *host = lp_parm_string(-1, "torture", "host");
554 const char *share = lp_parm_string(-1, "torture", "share");
556 status = smbcli_full_connection(NULL,
559 cmdline_credentials, NULL);
561 if (!NT_STATUS_IS_OK(status)) {
562 printf("could not open connection\n");
566 if (!tcon_devtest(cli1, "IPC$", "A:", NT_STATUS_BAD_DEVICE_TYPE))
569 if (!tcon_devtest(cli1, "IPC$", "?????", NT_STATUS_OK))
572 if (!tcon_devtest(cli1, "IPC$", "LPT:", NT_STATUS_BAD_DEVICE_TYPE))
575 if (!tcon_devtest(cli1, "IPC$", "IPC", NT_STATUS_OK))
578 if (!tcon_devtest(cli1, "IPC$", "FOOBA", NT_STATUS_BAD_DEVICE_TYPE))
581 if (!tcon_devtest(cli1, share, "A:", NT_STATUS_OK))
584 if (!tcon_devtest(cli1, share, "?????", NT_STATUS_OK))
587 if (!tcon_devtest(cli1, share, "LPT:", NT_STATUS_BAD_DEVICE_TYPE))
590 if (!tcon_devtest(cli1, share, "IPC", NT_STATUS_BAD_DEVICE_TYPE))
593 if (!tcon_devtest(cli1, share, "FOOBA", NT_STATUS_BAD_DEVICE_TYPE))
599 printf("Passed tcondevtest\n");
604 static BOOL rw_torture2(struct smbcli_state *c1, struct smbcli_state *c2)
606 const char *lockfname = "\\torture2.lck";
611 uint8_t buf_rd[131072];
613 ssize_t bytes_read, bytes_written;
615 if (smbcli_deltree(c1->tree, lockfname) == -1) {
616 printf("unlink failed (%s)\n", smbcli_errstr(c1->tree));
619 fnum1 = smbcli_open(c1->tree, lockfname, O_RDWR | O_CREAT | O_EXCL,
622 printf("first open read/write of %s failed (%s)\n",
623 lockfname, smbcli_errstr(c1->tree));
626 fnum2 = smbcli_open(c2->tree, lockfname, O_RDONLY,
629 printf("second open read-only of %s failed (%s)\n",
630 lockfname, smbcli_errstr(c2->tree));
631 smbcli_close(c1->tree, fnum1);
635 printf("Checking data integrity over %d ops\n", torture_numops);
637 for (i=0;i<torture_numops;i++)
639 size_t buf_size = ((uint_t)random()%(sizeof(buf)-1))+ 1;
641 printf("%d\r", i); fflush(stdout);
644 generate_random_buffer(buf, buf_size);
646 if ((bytes_written = smbcli_write(c1->tree, fnum1, 0, buf, 0, buf_size)) != buf_size) {
647 printf("write failed (%s)\n", smbcli_errstr(c1->tree));
648 printf("wrote %d, expected %d\n", (int)bytes_written, (int)buf_size);
653 if ((bytes_read = smbcli_read(c2->tree, fnum2, buf_rd, 0, buf_size)) != buf_size) {
654 printf("read failed (%s)\n", smbcli_errstr(c2->tree));
655 printf("read %d, expected %d\n", (int)bytes_read, (int)buf_size);
660 if (memcmp(buf_rd, buf, buf_size) != 0)
662 printf("read/write compare failed\n");
668 if (NT_STATUS_IS_ERR(smbcli_close(c2->tree, fnum2))) {
669 printf("close failed (%s)\n", smbcli_errstr(c2->tree));
672 if (NT_STATUS_IS_ERR(smbcli_close(c1->tree, fnum1))) {
673 printf("close failed (%s)\n", smbcli_errstr(c1->tree));
677 if (NT_STATUS_IS_ERR(smbcli_unlink(c1->tree, lockfname))) {
678 printf("unlink failed (%s)\n", smbcli_errstr(c1->tree));
687 #define BOOLSTR(b) ((b) ? "Yes" : "No")
689 static BOOL run_readwritetest(struct torture_context *torture)
691 struct smbcli_state *cli1, *cli2;
692 BOOL test1, test2 = True;
694 if (!torture_open_connection(&cli1, 0) ||
695 !torture_open_connection(&cli2, 1)) {
699 printf("starting readwritetest\n");
701 test1 = rw_torture2(cli1, cli2);
702 printf("Passed readwritetest v1: %s\n", BOOLSTR(test1));
705 test2 = rw_torture2(cli1, cli1);
706 printf("Passed readwritetest v2: %s\n", BOOLSTR(test2));
709 if (!torture_close_connection(cli1)) {
713 if (!torture_close_connection(cli2)) {
717 return (test1 && test2);
725 test the timing of deferred open requests
727 static BOOL run_deferopen(struct smbcli_state *cli, int dummy)
729 const char *fname = "\\defer_open_test.dat";
735 printf("failed to connect\n");
739 printf("Testing deferred open requests.\n");
746 tv = timeval_current();
747 fnum = smbcli_nt_create_full(cli->tree, fname, 0,
749 FILE_ATTRIBUTE_NORMAL,
750 NTCREATEX_SHARE_ACCESS_NONE,
751 NTCREATEX_DISP_OPEN_IF, 0, 0);
755 if (NT_STATUS_EQUAL(smbcli_nt_error(cli->tree),NT_STATUS_SHARING_VIOLATION)) {
756 double e = timeval_elapsed(&tv);
757 if (e < 0.5 || e > 1.5) {
758 fprintf(stderr,"Timing incorrect %.2f violation\n",
762 } while (NT_STATUS_EQUAL(smbcli_nt_error(cli->tree),NT_STATUS_SHARING_VIOLATION));
765 fprintf(stderr,"Failed to open %s, error=%s\n", fname, smbcli_errstr(cli->tree));
769 printf("pid %u open %d\n", getpid(), i);
773 if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnum))) {
774 fprintf(stderr,"Failed to close %s, error=%s\n", fname, smbcli_errstr(cli->tree));
780 if (NT_STATUS_IS_ERR(smbcli_unlink(cli->tree, fname))) {
781 /* All until the last unlink will fail with sharing violation. */
782 if (!NT_STATUS_EQUAL(smbcli_nt_error(cli->tree),NT_STATUS_SHARING_VIOLATION)) {
783 printf("unlink of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
788 printf("deferred test finished\n");
789 if (!torture_close_connection(cli)) {
796 Try with a wrong vuid and check error message.
799 static BOOL run_vuidtest(struct torture_context *torture)
801 struct smbcli_state *cli;
802 const char *fname = "\\vuid.tst";
805 time_t c_time, a_time, m_time;
811 printf("starting vuid test\n");
813 if (!torture_open_connection(&cli, 0)) {
817 smbcli_unlink(cli->tree, fname);
819 fnum = smbcli_open(cli->tree, fname,
820 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
822 orig_vuid = cli->session->vuid;
824 cli->session->vuid += 1234;
826 printf("Testing qfileinfo with wrong vuid\n");
828 if (NT_STATUS_IS_OK(result = smbcli_qfileinfo(cli->tree, fnum, NULL,
829 &size, &c_time, &a_time,
830 &m_time, NULL, NULL))) {
831 printf("ERROR: qfileinfo passed with wrong vuid\n");
835 if (!NT_STATUS_EQUAL(cli->transport->error.e.nt_status,
836 NT_STATUS_DOS(ERRSRV, ERRbaduid)) &&
837 !NT_STATUS_EQUAL(cli->transport->error.e.nt_status,
838 NT_STATUS_INVALID_HANDLE)) {
839 printf("ERROR: qfileinfo should have returned DOS error "
840 "ERRSRV:ERRbaduid\n but returned %s\n",
841 smbcli_errstr(cli->tree));
845 cli->session->vuid -= 1234;
847 if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnum))) {
848 printf("close failed (%s)\n", smbcli_errstr(cli->tree));
852 smbcli_unlink(cli->tree, fname);
854 if (!torture_close_connection(cli)) {
858 printf("vuid test finished\n");
864 Test open mode returns on read-only files.
866 static BOOL run_opentest(struct torture_context *torture)
868 static struct smbcli_state *cli1;
869 static struct smbcli_state *cli2;
870 const char *fname = "\\readonly.file";
871 char *control_char_fname;
880 printf("starting open test\n");
882 if (!torture_open_connection(&cli1, 0)) {
886 asprintf(&control_char_fname, "\\readonly.afile");
887 for (i = 1; i <= 0x1f; i++) {
888 control_char_fname[10] = i;
889 fnum1 = smbcli_nt_create_full(cli1->tree, control_char_fname, 0, SEC_FILE_WRITE_DATA, FILE_ATTRIBUTE_NORMAL,
890 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
892 if (!check_error(__location__, cli1, ERRDOS, ERRinvalidname,
893 NT_STATUS_OBJECT_NAME_INVALID)) {
894 printf("Error code should be NT_STATUS_OBJECT_NAME_INVALID, was %s for file with %d char\n",
895 smbcli_errstr(cli1->tree), i);
900 smbcli_close(cli1->tree, fnum1);
902 smbcli_setatr(cli1->tree, control_char_fname, 0, 0);
903 smbcli_unlink(cli1->tree, control_char_fname);
905 free(control_char_fname);
908 printf("Create file with control char names passed.\n");
910 smbcli_setatr(cli1->tree, fname, 0, 0);
911 smbcli_unlink(cli1->tree, fname);
913 fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
915 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
919 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
920 printf("close2 failed (%s)\n", smbcli_errstr(cli1->tree));
924 if (NT_STATUS_IS_ERR(smbcli_setatr(cli1->tree, fname, FILE_ATTRIBUTE_READONLY, 0))) {
925 printf("smbcli_setatr failed (%s)\n", smbcli_errstr(cli1->tree));
926 CHECK_MAX_FAILURES(error_test1);
930 fnum1 = smbcli_open(cli1->tree, fname, O_RDONLY, DENY_WRITE);
932 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
933 CHECK_MAX_FAILURES(error_test1);
937 /* This will fail - but the error should be ERRnoaccess, not ERRbadshare. */
938 fnum2 = smbcli_open(cli1->tree, fname, O_RDWR, DENY_ALL);
940 if (check_error(__location__, cli1, ERRDOS, ERRnoaccess,
941 NT_STATUS_ACCESS_DENIED)) {
942 printf("correct error code ERRDOS/ERRnoaccess returned\n");
945 printf("finished open test 1\n");
947 smbcli_close(cli1->tree, fnum1);
949 /* Now try not readonly and ensure ERRbadshare is returned. */
951 smbcli_setatr(cli1->tree, fname, 0, 0);
953 fnum1 = smbcli_open(cli1->tree, fname, O_RDONLY, DENY_WRITE);
955 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
959 /* This will fail - but the error should be ERRshare. */
960 fnum2 = smbcli_open(cli1->tree, fname, O_RDWR, DENY_ALL);
962 if (check_error(__location__, cli1, ERRDOS, ERRbadshare,
963 NT_STATUS_SHARING_VIOLATION)) {
964 printf("correct error code ERRDOS/ERRbadshare returned\n");
967 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
968 printf("close2 failed (%s)\n", smbcli_errstr(cli1->tree));
972 smbcli_unlink(cli1->tree, fname);
974 printf("finished open test 2\n");
976 /* Test truncate open disposition on file opened for read. */
978 fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
980 printf("(3) open (1) of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
984 /* write 20 bytes. */
986 memset(buf, '\0', 20);
988 if (smbcli_write(cli1->tree, fnum1, 0, buf, 0, 20) != 20) {
989 printf("write failed (%s)\n", smbcli_errstr(cli1->tree));
993 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
994 printf("(3) close1 failed (%s)\n", smbcli_errstr(cli1->tree));
998 /* Ensure size == 20. */
999 if (NT_STATUS_IS_ERR(smbcli_getatr(cli1->tree, fname, NULL, &fsize, NULL))) {
1000 printf("(3) getatr failed (%s)\n", smbcli_errstr(cli1->tree));
1001 CHECK_MAX_FAILURES(error_test3);
1006 printf("(3) file size != 20\n");
1007 CHECK_MAX_FAILURES(error_test3);
1011 /* Now test if we can truncate a file opened for readonly. */
1013 fnum1 = smbcli_open(cli1->tree, fname, O_RDONLY|O_TRUNC, DENY_NONE);
1015 printf("(3) open (2) of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1016 CHECK_MAX_FAILURES(error_test3);
1020 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1021 printf("close2 failed (%s)\n", smbcli_errstr(cli1->tree));
1025 /* Ensure size == 0. */
1026 if (NT_STATUS_IS_ERR(smbcli_getatr(cli1->tree, fname, NULL, &fsize, NULL))) {
1027 printf("(3) getatr failed (%s)\n", smbcli_errstr(cli1->tree));
1028 CHECK_MAX_FAILURES(error_test3);
1033 printf("(3) file size != 0\n");
1034 CHECK_MAX_FAILURES(error_test3);
1037 printf("finished open test 3\n");
1039 smbcli_unlink(cli1->tree, fname);
1042 printf("testing ctemp\n");
1043 fnum1 = smbcli_ctemp(cli1->tree, "\\", &tmp_path);
1045 printf("ctemp failed (%s)\n", smbcli_errstr(cli1->tree));
1046 CHECK_MAX_FAILURES(error_test4);
1049 printf("ctemp gave path %s\n", tmp_path);
1050 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1051 printf("close of temp failed (%s)\n", smbcli_errstr(cli1->tree));
1053 if (NT_STATUS_IS_ERR(smbcli_unlink(cli1->tree, tmp_path))) {
1054 printf("unlink of temp failed (%s)\n", smbcli_errstr(cli1->tree));
1057 /* Test the non-io opens... */
1059 if (!torture_open_connection(&cli2, 1)) {
1063 smbcli_setatr(cli2->tree, fname, 0, 0);
1064 smbcli_unlink(cli2->tree, fname);
1066 printf("TEST #1 testing 2 non-io opens (no delete)\n");
1068 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, SEC_FILE_READ_ATTRIBUTE, FILE_ATTRIBUTE_NORMAL,
1069 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1072 printf("test 1 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1073 CHECK_MAX_FAILURES(error_test10);
1077 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, SEC_FILE_READ_ATTRIBUTE, FILE_ATTRIBUTE_NORMAL,
1078 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1080 printf("test 1 open 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1081 CHECK_MAX_FAILURES(error_test10);
1085 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1086 printf("test 1 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1089 if (NT_STATUS_IS_ERR(smbcli_close(cli2->tree, fnum2))) {
1090 printf("test 1 close 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1094 printf("non-io open test #1 passed.\n");
1096 smbcli_unlink(cli1->tree, fname);
1098 printf("TEST #2 testing 2 non-io opens (first with delete)\n");
1100 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, SEC_STD_DELETE|SEC_FILE_READ_ATTRIBUTE, FILE_ATTRIBUTE_NORMAL,
1101 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1104 printf("test 2 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1105 CHECK_MAX_FAILURES(error_test20);
1109 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, SEC_FILE_READ_ATTRIBUTE, FILE_ATTRIBUTE_NORMAL,
1110 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1113 printf("test 2 open 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1114 CHECK_MAX_FAILURES(error_test20);
1118 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1119 printf("test 1 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1122 if (NT_STATUS_IS_ERR(smbcli_close(cli2->tree, fnum2))) {
1123 printf("test 1 close 2 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1127 printf("non-io open test #2 passed.\n");
1129 smbcli_unlink(cli1->tree, fname);
1131 printf("TEST #3 testing 2 non-io opens (second with delete)\n");
1133 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, SEC_FILE_READ_ATTRIBUTE, FILE_ATTRIBUTE_NORMAL,
1134 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1137 printf("test 3 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1138 CHECK_MAX_FAILURES(error_test30);
1142 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, SEC_STD_DELETE|SEC_FILE_READ_ATTRIBUTE, FILE_ATTRIBUTE_NORMAL,
1143 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1146 printf("test 3 open 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1147 CHECK_MAX_FAILURES(error_test30);
1151 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1152 printf("test 3 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1155 if (NT_STATUS_IS_ERR(smbcli_close(cli2->tree, fnum2))) {
1156 printf("test 3 close 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1160 printf("non-io open test #3 passed.\n");
1162 smbcli_unlink(cli1->tree, fname);
1164 printf("TEST #4 testing 2 non-io opens (both with delete)\n");
1166 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, SEC_STD_DELETE|SEC_FILE_READ_ATTRIBUTE, FILE_ATTRIBUTE_NORMAL,
1167 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1170 printf("test 4 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1171 CHECK_MAX_FAILURES(error_test40);
1175 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, SEC_STD_DELETE|SEC_FILE_READ_ATTRIBUTE, FILE_ATTRIBUTE_NORMAL,
1176 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1179 printf("test 4 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1180 CHECK_MAX_FAILURES(error_test40);
1184 printf("test 4 open 2 of %s gave %s (correct error should be %s)\n", fname, smbcli_errstr(cli2->tree), "sharing violation");
1186 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1187 printf("test 4 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1191 printf("non-io open test #4 passed.\n");
1193 smbcli_unlink(cli1->tree, fname);
1195 printf("TEST #5 testing 2 non-io opens (both with delete - both with file share delete)\n");
1197 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, SEC_STD_DELETE|SEC_FILE_READ_ATTRIBUTE, FILE_ATTRIBUTE_NORMAL,
1198 NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1201 printf("test 5 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1202 CHECK_MAX_FAILURES(error_test50);
1206 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, SEC_STD_DELETE|SEC_FILE_READ_ATTRIBUTE, FILE_ATTRIBUTE_NORMAL,
1207 NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1210 printf("test 5 open 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1211 CHECK_MAX_FAILURES(error_test50);
1215 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1216 printf("test 5 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1220 if (NT_STATUS_IS_ERR(smbcli_close(cli2->tree, fnum2))) {
1221 printf("test 5 close 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1225 printf("non-io open test #5 passed.\n");
1227 printf("TEST #6 testing 1 non-io open, one io open\n");
1229 smbcli_unlink(cli1->tree, fname);
1231 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, SEC_FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
1232 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1235 printf("test 6 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1236 CHECK_MAX_FAILURES(error_test60);
1240 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, SEC_FILE_READ_ATTRIBUTE, FILE_ATTRIBUTE_NORMAL,
1241 NTCREATEX_SHARE_ACCESS_READ, NTCREATEX_DISP_OPEN_IF, 0, 0);
1244 printf("test 6 open 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1245 CHECK_MAX_FAILURES(error_test60);
1249 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1250 printf("test 6 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1254 if (NT_STATUS_IS_ERR(smbcli_close(cli2->tree, fnum2))) {
1255 printf("test 6 close 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1259 printf("non-io open test #6 passed.\n");
1261 printf("TEST #7 testing 1 non-io open, one io open with delete\n");
1263 smbcli_unlink(cli1->tree, fname);
1265 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, SEC_FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
1266 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1269 printf("test 7 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1270 CHECK_MAX_FAILURES(error_test70);
1274 fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, SEC_STD_DELETE|SEC_FILE_READ_ATTRIBUTE, FILE_ATTRIBUTE_NORMAL,
1275 NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1278 printf("test 7 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1279 CHECK_MAX_FAILURES(error_test70);
1283 printf("test 7 open 2 of %s gave %s (correct error should be %s)\n", fname, smbcli_errstr(cli2->tree), "sharing violation");
1285 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1286 printf("test 7 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1290 printf("non-io open test #7 passed.\n");
1294 printf("TEST #8 testing one normal open, followed by lock, followed by open with truncate\n");
1296 smbcli_unlink(cli1->tree, fname);
1298 fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
1300 printf("(8) open (1) of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1304 /* write 20 bytes. */
1306 memset(buf, '\0', 20);
1308 if (smbcli_write(cli1->tree, fnum1, 0, buf, 0, 20) != 20) {
1309 printf("(8) write failed (%s)\n", smbcli_errstr(cli1->tree));
1313 /* Ensure size == 20. */
1314 if (NT_STATUS_IS_ERR(smbcli_getatr(cli1->tree, fname, NULL, &fsize, NULL))) {
1315 printf("(8) getatr (1) failed (%s)\n", smbcli_errstr(cli1->tree));
1316 CHECK_MAX_FAILURES(error_test80);
1321 printf("(8) file size != 20\n");
1322 CHECK_MAX_FAILURES(error_test80);
1326 /* Get an exclusive lock on the open file. */
1327 if (NT_STATUS_IS_ERR(smbcli_lock(cli1->tree, fnum1, 0, 4, 0, WRITE_LOCK))) {
1328 printf("(8) lock1 failed (%s)\n", smbcli_errstr(cli1->tree));
1329 CHECK_MAX_FAILURES(error_test80);
1333 fnum2 = smbcli_open(cli1->tree, fname, O_RDWR|O_TRUNC, DENY_NONE);
1335 printf("(8) open (2) of %s with truncate failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1339 /* Ensure size == 0. */
1340 if (NT_STATUS_IS_ERR(smbcli_getatr(cli1->tree, fname, NULL, &fsize, NULL))) {
1341 printf("(8) getatr (2) failed (%s)\n", smbcli_errstr(cli1->tree));
1342 CHECK_MAX_FAILURES(error_test80);
1347 printf("(8) file size != 0\n");
1348 CHECK_MAX_FAILURES(error_test80);
1352 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1353 printf("(8) close1 failed (%s)\n", smbcli_errstr(cli1->tree));
1357 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum2))) {
1358 printf("(8) close1 failed (%s)\n", smbcli_errstr(cli1->tree));
1364 printf("open test #8 passed.\n");
1366 smbcli_unlink(cli1->tree, fname);
1368 if (!torture_close_connection(cli1)) {
1371 if (!torture_close_connection(cli2)) {
1378 /* FIRST_DESIRED_ACCESS 0xf019f */
1379 #define FIRST_DESIRED_ACCESS SEC_FILE_READ_DATA|SEC_FILE_WRITE_DATA|SEC_FILE_APPEND_DATA|\
1380 SEC_FILE_READ_EA| /* 0xf */ \
1381 SEC_FILE_WRITE_EA|SEC_FILE_READ_ATTRIBUTE| /* 0x90 */ \
1382 SEC_FILE_WRITE_ATTRIBUTE| /* 0x100 */ \
1383 SEC_STD_DELETE|SEC_STD_READ_CONTROL|\
1384 SEC_STD_WRITE_DAC|SEC_STD_WRITE_OWNER /* 0xf0000 */
1385 /* SECOND_DESIRED_ACCESS 0xe0080 */
1386 #define SECOND_DESIRED_ACCESS SEC_FILE_READ_ATTRIBUTE| /* 0x80 */ \
1387 SEC_STD_READ_CONTROL|SEC_STD_WRITE_DAC|\
1388 SEC_STD_WRITE_OWNER /* 0xe0000 */
1391 #define THIRD_DESIRED_ACCESS FILE_READ_ATTRIBUTE| /* 0x80 */ \
1392 READ_CONTROL|WRITE_DAC|\
1393 SEC_FILE_READ_DATA|\
1400 Test ntcreate calls made by xcopy
1402 static BOOL run_xcopy(struct torture_context *torture)
1404 struct smbcli_state *cli1;
1405 const char *fname = "\\test.txt";
1406 BOOL correct = True;
1409 printf("starting xcopy test\n");
1411 if (!torture_open_connection(&cli1, 0)) {
1415 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0,
1416 FIRST_DESIRED_ACCESS,
1417 FILE_ATTRIBUTE_ARCHIVE,
1418 NTCREATEX_SHARE_ACCESS_NONE,
1419 NTCREATEX_DISP_OVERWRITE_IF,
1423 printf("First open failed - %s\n", smbcli_errstr(cli1->tree));
1427 fnum2 = smbcli_nt_create_full(cli1->tree, fname, 0,
1428 SECOND_DESIRED_ACCESS, 0,
1429 NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE|NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OPEN,
1432 printf("second open failed - %s\n", smbcli_errstr(cli1->tree));
1436 if (!torture_close_connection(cli1)) {
1443 static BOOL run_iometer(struct torture_context *torture)
1445 struct smbcli_state *cli;
1446 const char *fname = "\\iobw.tst";
1452 BOOL result = False;
1454 printf("Starting iometer test\n");
1456 memset(buf, 0, sizeof(buf));
1458 if (!torture_open_connection(&cli, 0)) {
1462 status = smbcli_getatr(cli->tree, fname, NULL, &filesize, NULL);
1463 if (!NT_STATUS_IS_OK(status)) {
1464 printf("smbcli_getatr failed: %s\n", nt_errstr(status));
1468 printf("size: %d\n", (int)filesize);
1470 filesize -= (sizeof(buf) - 1);
1472 fnum = smbcli_nt_create_full(cli->tree, fname, 0x16,
1473 0x2019f, 0, 0x3, 3, 0x42, 0x3);
1475 printf("open failed: %s\n", smbcli_errstr(cli->tree));
1482 int i, num_reads, num_writes;
1484 num_reads = random() % 10;
1485 num_writes = random() % 3;
1487 for (i=0; i<num_reads; i++) {
1489 if (ops++ > torture_numops) {
1493 res = smbcli_read(cli->tree, fnum, buf,
1494 random() % filesize, sizeof(buf));
1495 if (res != sizeof(buf)) {
1496 printf("read failed: %s\n",
1497 smbcli_errstr(cli->tree));
1501 for (i=0; i<num_writes; i++) {
1503 if (ops++ > torture_numops) {
1507 res = smbcli_write(cli->tree, fnum, 0, buf,
1508 random() % filesize, sizeof(buf));
1509 if (res != sizeof(buf)) {
1510 printf("read failed: %s\n",
1511 smbcli_errstr(cli->tree));
1520 if (!torture_close_connection(cli)) {
1521 printf("close_connection failed: %s\n",
1522 smbcli_errstr(cli->tree));
1530 tries variants of chkpath
1532 static BOOL torture_chkpath_test(struct torture_context *torture)
1534 struct smbcli_state *cli;
1538 if (!torture_open_connection(&cli, 0)) {
1542 printf("starting chkpath test\n");
1544 printf("Testing valid and invalid paths\n");
1546 /* cleanup from an old run */
1547 smbcli_rmdir(cli->tree, "\\chkpath.dir\\dir2");
1548 smbcli_unlink(cli->tree, "\\chkpath.dir\\*");
1549 smbcli_rmdir(cli->tree, "\\chkpath.dir");
1551 if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, "\\chkpath.dir"))) {
1552 printf("mkdir1 failed : %s\n", smbcli_errstr(cli->tree));
1556 if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, "\\chkpath.dir\\dir2"))) {
1557 printf("mkdir2 failed : %s\n", smbcli_errstr(cli->tree));
1561 fnum = smbcli_open(cli->tree, "\\chkpath.dir\\foo.txt", O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1563 printf("open1 failed (%s)\n", smbcli_errstr(cli->tree));
1566 smbcli_close(cli->tree, fnum);
1568 if (NT_STATUS_IS_ERR(smbcli_chkpath(cli->tree, "\\chkpath.dir"))) {
1569 printf("chkpath1 failed: %s\n", smbcli_errstr(cli->tree));
1573 if (NT_STATUS_IS_ERR(smbcli_chkpath(cli->tree, "\\chkpath.dir\\dir2"))) {
1574 printf("chkpath2 failed: %s\n", smbcli_errstr(cli->tree));
1578 if (NT_STATUS_IS_ERR(smbcli_chkpath(cli->tree, "\\chkpath.dir\\foo.txt"))) {
1579 ret = check_error(__location__, cli, ERRDOS, ERRbadpath,
1580 NT_STATUS_NOT_A_DIRECTORY);
1582 printf("* chkpath on a file should fail\n");
1586 if (NT_STATUS_IS_ERR(smbcli_chkpath(cli->tree, "\\chkpath.dir\\bar.txt"))) {
1587 ret = check_error(__location__, cli, ERRDOS, ERRbadpath,
1588 NT_STATUS_OBJECT_NAME_NOT_FOUND);
1590 printf("* chkpath on a non existent file should fail\n");
1594 if (NT_STATUS_IS_ERR(smbcli_chkpath(cli->tree, "\\chkpath.dir\\dirxx\\bar.txt"))) {
1595 ret = check_error(__location__, cli, ERRDOS, ERRbadpath,
1596 NT_STATUS_OBJECT_PATH_NOT_FOUND);
1598 printf("* chkpath on a non existent component should fail\n");
1602 smbcli_rmdir(cli->tree, "\\chkpath.dir\\dir2");
1603 smbcli_unlink(cli->tree, "\\chkpath.dir\\*");
1604 smbcli_rmdir(cli->tree, "\\chkpath.dir");
1606 if (!torture_close_connection(cli)) {
1614 * This is a test to excercise some weird Samba3 error paths.
1617 static BOOL torture_samba3_errorpaths(struct torture_context *torture)
1619 BOOL nt_status_support;
1620 struct smbcli_state *cli_nt = NULL, *cli_dos = NULL;
1621 BOOL result = False;
1623 const char *os2_fname = ".+,;=[].";
1624 const char *dname = "samba3_errordir";
1626 TALLOC_CTX *mem_ctx = talloc_init("samba3_errorpaths");
1629 if (mem_ctx == NULL) {
1630 printf("talloc_init failed\n");
1634 nt_status_support = lp_nt_status_support();
1636 if (!lp_set_cmdline("nt status support", "yes")) {
1637 printf("Could not set 'nt status support = yes'\n");
1641 if (!torture_open_connection(&cli_nt, 0)) {
1645 if (!lp_set_cmdline("nt status support", "no")) {
1646 printf("Could not set 'nt status support = yes'\n");
1650 if (!torture_open_connection(&cli_dos, 1)) {
1654 if (!lp_set_cmdline("nt status support",
1655 nt_status_support ? "yes":"no")) {
1656 printf("Could not reset 'nt status support = yes'");
1660 smbcli_unlink(cli_nt->tree, os2_fname);
1661 smbcli_rmdir(cli_nt->tree, dname);
1663 if (!NT_STATUS_IS_OK(smbcli_mkdir(cli_nt->tree, dname))) {
1664 printf("smbcli_mkdir(%s) failed: %s\n", dname,
1665 smbcli_errstr(cli_nt->tree));
1669 io.generic.level = RAW_OPEN_NTCREATEX;
1670 io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
1671 io.ntcreatex.in.root_fid = 0;
1672 io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
1673 io.ntcreatex.in.alloc_size = 1024*1024;
1674 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_DIRECTORY;
1675 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_NONE;
1676 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
1677 io.ntcreatex.in.create_options = 0;
1678 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
1679 io.ntcreatex.in.security_flags = 0;
1680 io.ntcreatex.in.fname = dname;
1682 status = smb_raw_open(cli_nt->tree, mem_ctx, &io);
1683 if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) {
1684 printf("(%s) incorrect status %s should be %s\n",
1685 __location__, nt_errstr(status),
1686 nt_errstr(NT_STATUS_OBJECT_NAME_COLLISION));
1689 status = smb_raw_open(cli_dos->tree, mem_ctx, &io);
1690 if (!NT_STATUS_EQUAL(status, NT_STATUS_DOS(ERRDOS, ERRfilexists))) {
1691 printf("(%s) incorrect status %s should be %s\n",
1692 __location__, nt_errstr(status),
1693 nt_errstr(NT_STATUS_DOS(ERRDOS, ERRfilexists)));
1697 status = smbcli_mkdir(cli_nt->tree, dname);
1698 if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) {
1699 printf("(%s) incorrect status %s should be %s\n",
1700 __location__, nt_errstr(status),
1701 nt_errstr(NT_STATUS_OBJECT_NAME_COLLISION));
1704 status = smbcli_mkdir(cli_dos->tree, dname);
1705 if (!NT_STATUS_EQUAL(status, NT_STATUS_DOS(ERRDOS, ERRnoaccess))) {
1706 printf("(%s) incorrect status %s should be %s\n",
1707 __location__, nt_errstr(status),
1708 nt_errstr(NT_STATUS_DOS(ERRDOS, ERRnoaccess)));
1712 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
1713 status = smb_raw_open(cli_nt->tree, mem_ctx, &io);
1714 if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) {
1715 printf("(%s) incorrect status %s should be %s\n",
1716 __location__, nt_errstr(status),
1717 nt_errstr(NT_STATUS_OBJECT_NAME_COLLISION));
1721 status = smb_raw_open(cli_dos->tree, mem_ctx, &io);
1722 if (!NT_STATUS_EQUAL(status, NT_STATUS_DOS(ERRDOS, ERRfilexists))) {
1723 printf("(%s) incorrect status %s should be %s\n",
1724 __location__, nt_errstr(status),
1725 nt_errstr(NT_STATUS_DOS(ERRDOS, ERRfilexists)));
1730 /* Test an invalid DOS deny mode */
1731 const char *fname = "test.txt";
1733 fnum = smbcli_open(cli_nt->tree, fname, O_RDWR | O_CREAT, 5);
1735 printf("Open(%s) with invalid deny mode succeeded -- "
1736 "expected failure\n", fname);
1737 smbcli_close(cli_nt->tree, fnum);
1740 if (!NT_STATUS_EQUAL(smbcli_nt_error(cli_nt->tree),
1741 NT_STATUS_DOS(ERRDOS,ERRbadaccess))) {
1742 printf("Expected DOS error ERRDOS/ERRbadaccess, "
1743 "got %s\n", smbcli_errstr(cli_nt->tree));
1747 fnum = smbcli_open(cli_dos->tree, fname, O_RDWR | O_CREAT, 5);
1749 printf("Open(%s) with invalid deny mode succeeded -- "
1750 "expected failure\n", fname);
1751 smbcli_close(cli_nt->tree, fnum);
1754 if (!NT_STATUS_EQUAL(smbcli_nt_error(cli_nt->tree),
1755 NT_STATUS_DOS(ERRDOS,ERRbadaccess))) {
1756 printf("Expected DOS error ERRDOS:ERRbadaccess, "
1757 "got %s\n", smbcli_errstr(cli_nt->tree));
1762 if (!lp_parm_bool(-1, "target", "samba3", False)) {
1766 fnum = smbcli_open(cli_dos->tree, os2_fname,
1767 O_RDWR | O_CREAT | O_TRUNC,
1770 printf("Open(%s) succeeded -- expected failure\n",
1772 smbcli_close(cli_dos->tree, fnum);
1776 if (!NT_STATUS_EQUAL(smbcli_nt_error(cli_dos->tree),
1777 NT_STATUS_DOS(ERRDOS, ERRcannotopen))) {
1778 printf("Expected DOS error ERRDOS/ERRcannotopen, got %s\n",
1779 smbcli_errstr(cli_dos->tree));
1783 fnum = smbcli_open(cli_nt->tree, os2_fname,
1784 O_RDWR | O_CREAT | O_TRUNC,
1787 printf("Open(%s) succeeded -- expected failure\n",
1789 smbcli_close(cli_nt->tree, fnum);
1793 if (!NT_STATUS_EQUAL(smbcli_nt_error(cli_nt->tree),
1794 NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
1795 printf("Expected error NT_STATUS_OBJECT_NAME_NOT_FOUND, "
1796 "got %s\n", smbcli_errstr(cli_nt->tree));
1804 if (cli_dos != NULL) {
1805 torture_close_connection(cli_dos);
1807 if (cli_nt != NULL) {
1808 torture_close_connection(cli_nt);
1815 NTSTATUS torture_base_init(void)
1817 register_torture_op("BASE-FDPASS", run_fdpasstest);
1818 register_torture_op("BASE-LOCK1", torture_locktest1);
1819 register_torture_op("BASE-LOCK2", torture_locktest2);
1820 register_torture_op("BASE-LOCK3", torture_locktest3);
1821 register_torture_op("BASE-LOCK4", torture_locktest4);
1822 register_torture_op("BASE-LOCK5", torture_locktest5);
1823 register_torture_op("BASE-LOCK6", torture_locktest6);
1824 register_torture_op("BASE-LOCK7", torture_locktest7);
1825 register_torture_op("BASE-UNLINK", torture_unlinktest);
1826 register_torture_op("BASE-ATTR", run_attrtest);
1827 register_torture_op("BASE-TRANS2", run_trans2test);
1828 register_torture_op("BASE-NEGNOWAIT", run_negprot_nowait);
1829 register_torture_op("BASE-DIR1", torture_dirtest1);
1830 register_torture_op("BASE-DIR2", torture_dirtest2);
1831 register_torture_op("BASE-DENY1", torture_denytest1);
1832 register_torture_op("BASE-DENY2", torture_denytest2);
1833 register_torture_op("BASE-DENY3", torture_denytest3);
1834 register_torture_op("BASE-DENYDOS", torture_denydos_sharing);
1835 register_torture_multi_op("BASE-NTDENY1", torture_ntdenytest1);
1836 register_torture_op("BASE-NTDENY2", torture_ntdenytest2);
1837 register_torture_op("BASE-TCON", run_tcon_test);
1838 register_torture_op("BASE-TCONDEV", run_tcon_devtype_test);
1839 register_torture_op("BASE-VUID", run_vuidtest);
1840 register_torture_op("BASE-RW1", run_readwritetest);
1841 register_torture_op("BASE-OPEN", run_opentest);
1842 register_torture_multi_op("BASE-DEFER_OPEN", run_deferopen);
1843 register_torture_op("BASE-XCOPY", run_xcopy);
1844 register_torture_op("BASE-IOMETER", run_iometer);
1845 register_torture_op("BASE-RENAME", torture_test_rename);
1846 register_torture_op("BASE-DELETE", torture_test_delete);
1847 register_torture_op("BASE-PROPERTIES", torture_test_properties);
1848 register_torture_op("BASE-MANGLE", torture_mangle);
1849 register_torture_op("BASE-OPENATTR", torture_openattrtest);
1850 register_torture_op("BASE-CHARSET", torture_charset);
1851 register_torture_op("BASE-CHKPATH", torture_chkpath_test);
1852 register_torture_op("BASE-SECLEAK", torture_sec_leak);
1853 register_torture_op("BASE-DISCONNECT", torture_disconnect);
1854 register_torture_op("BASE-DELAYWRITE", torture_delay_write);
1855 register_torture_op("BASE-SAMBA3ERROR", torture_samba3_errorpaths);
1857 register_torture_op("SCAN-CASETABLE", torture_casetable);
1858 register_torture_op("SCAN-UTABLE", torture_utable);
1859 register_torture_op("SCAN-SMB", torture_smb_scan);
1860 register_torture_op("SCAN-ALIASES", torture_trans2_aliases);
1861 register_torture_op("SCAN-TRANS2", torture_trans2_scan);
1862 register_torture_op("SCAN-NTTRANS", torture_nttrans_scan);
1864 return NT_STATUS_OK;