2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 1997-2003
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 int torture_numops=100;
25 int torture_entries=1000;
26 int torture_failures=1;
27 static int procnum; /* records process count number when forking */
28 static struct cli_state *current_cli;
29 static char *randomfname;
30 static BOOL use_oplocks;
31 static BOOL use_level_II_oplocks;
32 static const char *client_txt = "client_oplocks.txt";
33 static BOOL use_kerberos;
35 BOOL torture_showall = False;
37 static double create_procs(BOOL (*fn)(int), BOOL *result);
39 #define CHECK_MAX_FAILURES(label) do { if (++failures >= torture_failures) goto label; } while (0)
41 static struct cli_state *open_nbt_connection(void)
43 struct nmb_name called, calling;
45 struct cli_state *cli;
46 char *host = lp_parm_string(-1, "torture", "host");
48 make_nmb_name(&calling, lp_netbios_name(), 0x0);
49 make_nmb_name(&called , host, 0x20);
53 cli = cli_state_init();
55 printf("Failed initialize cli_struct to connect with %s\n", host);
59 if (!cli_socket_connect(cli, host, &ip)) {
60 printf("Failed to connect with %s\n", host);
64 cli->transport->socket->timeout = 120000; /* set a really long timeout (2 minutes) */
66 if (!cli_transport_establish(cli, &calling, &called)) {
68 * Well, that failed, try *SMBSERVER ...
69 * However, we must reconnect as well ...
71 if (!cli_socket_connect(cli, host, &ip)) {
72 printf("Failed to connect with %s\n", host);
76 make_nmb_name(&called, "*SMBSERVER", 0x20);
77 if (!cli_transport_establish(cli, &calling, &called)) {
78 printf("%s rejected the session\n",host);
79 printf("We tried with a called name of %s & %s\n",
89 BOOL torture_open_connection(struct cli_state **c)
94 char *host = lp_parm_string(-1, "torture", "host");
95 char *share = lp_parm_string(-1, "torture", "share");
96 char *username = lp_parm_string(-1, "torture", "username");
97 char *password = lp_parm_string(-1, "torture", "password");
100 flags |= CLI_FULL_CONNECTION_USE_KERBEROS;
102 status = cli_full_connection(c, lp_netbios_name(),
105 username, username[0]?lp_workgroup():"",
106 password, flags, &retry);
107 if (!NT_STATUS_IS_OK(status)) {
108 printf("Failed to open connection - %s\n", nt_errstr(status));
112 (*c)->transport->options.use_oplocks = use_oplocks;
113 (*c)->transport->options.use_level2_oplocks = use_level_II_oplocks;
114 (*c)->transport->socket->timeout = 120000;
119 BOOL torture_close_connection(struct cli_state *c)
122 DEBUG(9,("torture_close_connection: cli_state@%p\n", c));
125 printf("tdis failed (%s)\n", cli_errstr(c));
128 DEBUG(9,("torture_close_connection: call cli_shutdown\n"));
130 DEBUG(9,("torture_close_connection: exit\n"));
134 /* open a rpc connection to a named pipe */
135 NTSTATUS torture_rpc_connection(struct dcerpc_pipe **p,
136 const char *pipe_name,
137 const char *pipe_uuid,
140 struct cli_state *cli;
143 if (!torture_open_connection(&cli)) {
144 return NT_STATUS_UNSUCCESSFUL;
147 if (!(*p = dcerpc_pipe_init(cli->tree))) {
148 return NT_STATUS_NO_MEMORY;
151 status = dcerpc_pipe_open_smb(*p, pipe_name, pipe_uuid, pipe_version);
152 if (!NT_STATUS_IS_OK(status)) {
153 printf("Open of pipe '%s' failed with error (%s)\n",
154 pipe_name, nt_errstr(status));
161 /* close a rpc connection to a named pipe */
162 NTSTATUS torture_rpc_close(struct dcerpc_pipe *p)
167 io.close.level = RAW_CLOSE_CLOSE;
168 io.close.in.fnum = p->fnum;
169 io.close.in.write_time = 0;
170 status = smb_raw_close(p->tree, &io);
172 dcerpc_pipe_close(p);
178 /* check if the server produced the expected error code */
179 static BOOL check_error(int line, struct cli_state *c,
180 uint8 eclass, uint32 ecode, NTSTATUS nterr)
182 if (cli_is_dos_error(c)) {
186 /* Check DOS error */
188 cli_dos_error(c, &class, &num);
190 if (eclass != class || ecode != num) {
191 printf("unexpected error code class=%d code=%d\n",
192 (int)class, (int)num);
193 printf(" expected %d/%d %s (line=%d)\n",
194 (int)eclass, (int)ecode, nt_errstr(nterr), line);
203 status = cli_nt_error(c);
205 if (NT_STATUS_V(nterr) != NT_STATUS_V(status)) {
206 printf("unexpected error code %s\n", nt_errstr(status));
207 printf(" expected %s (line=%d)\n", nt_errstr(nterr), line);
216 static BOOL wait_lock(struct cli_state *c, int fnum, uint32 offset, uint32 len)
218 while (!cli_lock(c, fnum, offset, len, -1, WRITE_LOCK)) {
219 if (!check_error(__LINE__, c, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False;
225 static BOOL rw_torture(struct cli_state *c)
227 const char *lockfname = "\\torture.lck";
231 pid_t pid2, pid = getpid();
236 fnum2 = cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
239 fnum2 = cli_open(c, lockfname, O_RDWR, DENY_NONE);
241 printf("open of %s failed (%s)\n", lockfname, cli_errstr(c));
246 for (i=0;i<torture_numops;i++) {
247 unsigned n = (unsigned)sys_random()%10;
249 printf("%d\r", i); fflush(stdout);
251 asprintf(&fname, "\\torture.%u", n);
253 if (!wait_lock(c, fnum2, n*sizeof(int), sizeof(int))) {
257 fnum = cli_open(c, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_ALL);
259 printf("open failed (%s)\n", cli_errstr(c));
264 if (cli_write(c, fnum, 0, (char *)&pid, 0, sizeof(pid)) != sizeof(pid)) {
265 printf("write failed (%s)\n", cli_errstr(c));
270 if (cli_write(c, fnum, 0, (char *)buf,
271 sizeof(pid)+(j*sizeof(buf)),
272 sizeof(buf)) != sizeof(buf)) {
273 printf("write failed (%s)\n", cli_errstr(c));
280 if (cli_read(c, fnum, (char *)&pid2, 0, sizeof(pid)) != sizeof(pid)) {
281 printf("read failed (%s)\n", cli_errstr(c));
286 printf("data corruption!\n");
290 if (!cli_close(c, fnum)) {
291 printf("close failed (%s)\n", cli_errstr(c));
295 if (!cli_unlink(c, fname)) {
296 printf("unlink failed (%s)\n", cli_errstr(c));
300 if (!cli_unlock(c, fnum2, n*sizeof(int), sizeof(int))) {
301 printf("unlock failed (%s)\n", cli_errstr(c));
308 cli_unlink(c, lockfname);
315 static BOOL run_torture(int dummy)
317 struct cli_state *cli;
322 ret = rw_torture(cli);
324 if (!torture_close_connection(cli)) {
331 static BOOL rw_torture3(struct cli_state *c, char *lockfname)
338 unsigned countprev = 0;
343 for (i = 0; i < sizeof(buf); i += sizeof(uint32))
345 SIVAL(buf, i, sys_random());
350 fnum = cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
353 printf("first open read/write of %s failed (%s)\n",
354 lockfname, cli_errstr(c));
360 for (i = 0; i < 500 && fnum == -1; i++)
362 fnum = cli_open(c, lockfname, O_RDONLY,
367 printf("second open read-only of %s failed (%s)\n",
368 lockfname, cli_errstr(c));
374 for (count = 0; count < sizeof(buf); count += sent)
376 if (count >= countprev) {
377 printf("%d %8d\r", i, count);
380 countprev += (sizeof(buf) / 20);
385 sent = ((unsigned)sys_random()%(20))+ 1;
386 if (sent > sizeof(buf) - count)
388 sent = sizeof(buf) - count;
391 if (cli_write(c, fnum, 0, buf+count, count, (size_t)sent) != sent) {
392 printf("write failed (%s)\n", cli_errstr(c));
398 sent = cli_read(c, fnum, buf_rd+count, count,
402 printf("read failed offset:%d size:%d (%s)\n",
403 count, sizeof(buf)-count,
410 if (memcmp(buf_rd+count, buf+count, sent) != 0)
412 printf("read/write compare failed\n");
413 printf("offset: %d req %d recvd %d\n",
414 count, sizeof(buf)-count, sent);
423 if (!cli_close(c, fnum)) {
424 printf("close failed (%s)\n", cli_errstr(c));
431 static BOOL rw_torture2(struct cli_state *c1, struct cli_state *c2)
433 const char *lockfname = "\\torture2.lck";
438 uchar buf_rd[131072];
440 ssize_t bytes_read, bytes_written;
442 if (cli_deltree(c1, lockfname) == -1) {
443 printf("unlink failed (%s)\n", cli_errstr(c1));
446 fnum1 = cli_open(c1, lockfname, O_RDWR | O_CREAT | O_EXCL,
449 printf("first open read/write of %s failed (%s)\n",
450 lockfname, cli_errstr(c1));
453 fnum2 = cli_open(c2, lockfname, O_RDONLY,
456 printf("second open read-only of %s failed (%s)\n",
457 lockfname, cli_errstr(c2));
458 cli_close(c1, fnum1);
462 printf("Checking data integrity over %d ops\n", torture_numops);
464 for (i=0;i<torture_numops;i++)
466 size_t buf_size = ((unsigned)sys_random()%(sizeof(buf)-1))+ 1;
468 printf("%d\r", i); fflush(stdout);
471 generate_random_buffer(buf, buf_size, False);
473 if ((bytes_written = cli_write(c1, fnum1, 0, buf, 0, buf_size)) != buf_size) {
474 printf("write failed (%s)\n", cli_errstr(c1));
475 printf("wrote %d, expected %d\n", bytes_written, buf_size);
480 if ((bytes_read = cli_read(c2, fnum2, buf_rd, 0, buf_size)) != buf_size) {
481 printf("read failed (%s)\n", cli_errstr(c2));
482 printf("read %d, expected %d\n", bytes_read, buf_size);
487 if (memcmp(buf_rd, buf, buf_size) != 0)
489 printf("read/write compare failed\n");
495 if (!cli_close(c2, fnum2)) {
496 printf("close failed (%s)\n", cli_errstr(c2));
499 if (!cli_close(c1, fnum1)) {
500 printf("close failed (%s)\n", cli_errstr(c1));
504 if (!cli_unlink(c1, lockfname)) {
505 printf("unlink failed (%s)\n", cli_errstr(c1));
512 static BOOL run_readwritetest(int dummy)
514 struct cli_state *cli1, *cli2;
515 BOOL test1, test2 = True;
517 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
521 printf("starting readwritetest\n");
523 test1 = rw_torture2(cli1, cli2);
524 printf("Passed readwritetest v1: %s\n", BOOLSTR(test1));
527 test2 = rw_torture2(cli1, cli1);
528 printf("Passed readwritetest v2: %s\n", BOOLSTR(test2));
531 if (!torture_close_connection(cli1)) {
535 if (!torture_close_connection(cli2)) {
539 return (test1 && test2);
542 static BOOL run_readwritemulti(int dummy)
544 struct cli_state *cli;
549 printf("run_readwritemulti: fname %s\n", randomfname);
550 test = rw_torture3(cli, randomfname);
552 if (!torture_close_connection(cli)) {
563 #define ival(s) strtol(s, NULL, 0)
565 /* run a test that simulates an approximate netbench client load */
566 static BOOL run_netbench(int client)
568 struct cli_state *cli;
573 const char *params[20];
582 asprintf(&cname, "client%d", client);
584 f = fopen(client_txt, "r");
591 while (fgets(line, sizeof(line)-1, f)) {
594 line[strlen(line)-1] = 0;
596 /* printf("[%d] %s\n", line_count, line); */
598 all_string_sub(line,"client1", cname, sizeof(line));
600 /* parse the command parameters */
601 params[0] = strtok(line," ");
603 while (params[i]) params[++i] = strtok(NULL," ");
609 if (!strncmp(params[0],"SMB", 3)) {
610 printf("ERROR: You are using a dbench 1 load file\n");
613 DEBUG(9,("run_netbench(%d): %s %s\n", client, params[0], params[1]));
615 if (!strcmp(params[0],"NTCreateX")) {
616 nb_createx(params[1], ival(params[2]), ival(params[3]),
618 } else if (!strcmp(params[0],"Close")) {
619 nb_close(ival(params[1]));
620 } else if (!strcmp(params[0],"Rename")) {
621 nb_rename(params[1], params[2]);
622 } else if (!strcmp(params[0],"Unlink")) {
623 nb_unlink(params[1]);
624 } else if (!strcmp(params[0],"Deltree")) {
625 nb_deltree(params[1]);
626 } else if (!strcmp(params[0],"Rmdir")) {
628 } else if (!strcmp(params[0],"QUERY_PATH_INFORMATION")) {
629 nb_qpathinfo(params[1]);
630 } else if (!strcmp(params[0],"QUERY_FILE_INFORMATION")) {
631 nb_qfileinfo(ival(params[1]));
632 } else if (!strcmp(params[0],"QUERY_FS_INFORMATION")) {
633 nb_qfsinfo(ival(params[1]));
634 } else if (!strcmp(params[0],"FIND_FIRST")) {
635 nb_findfirst(params[1]);
636 } else if (!strcmp(params[0],"WriteX")) {
637 nb_writex(ival(params[1]),
638 ival(params[2]), ival(params[3]), ival(params[4]));
639 } else if (!strcmp(params[0],"ReadX")) {
640 nb_readx(ival(params[1]),
641 ival(params[2]), ival(params[3]), ival(params[4]));
642 } else if (!strcmp(params[0],"Flush")) {
643 nb_flush(ival(params[1]));
645 printf("Unknown operation %s\n", params[0]);
653 if (!torture_close_connection(cli)) {
661 /* run a test that simulates an approximate netbench client load */
662 static BOOL run_nbench(int dummy)
671 signal(SIGALRM, SIGNAL_CAST nb_alarm);
673 t = create_procs(run_netbench, &correct);
676 printf("\nThroughput %g MB/sec\n",
677 1.0e-6 * nbio_total() / t);
683 This test checks for two things:
685 1) correct support for retaining locks over a close (ie. the server
686 must not use posix semantics)
687 2) support for lock timeouts
689 static BOOL run_locktest1(int dummy)
691 struct cli_state *cli1, *cli2;
692 const char *fname = "\\lockt1.lck";
693 int fnum1, fnum2, fnum3;
695 unsigned lock_timeout;
697 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
701 printf("starting locktest1\n");
703 cli_unlink(cli1, fname);
705 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
707 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
710 fnum2 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
712 printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli1));
715 fnum3 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
717 printf("open3 of %s failed (%s)\n", fname, cli_errstr(cli2));
721 if (!cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK)) {
722 printf("lock1 failed (%s)\n", cli_errstr(cli1));
727 if (cli_lock(cli2, fnum3, 0, 4, 0, WRITE_LOCK)) {
728 printf("lock2 succeeded! This is a locking bug\n");
731 if (!check_error(__LINE__, cli2, ERRDOS, ERRlock,
732 NT_STATUS_LOCK_NOT_GRANTED)) return False;
736 lock_timeout = (6 + (random() % 20));
737 printf("Testing lock timeout with timeout=%u\n", lock_timeout);
739 if (cli_lock(cli2, fnum3, 0, 4, lock_timeout * 1000, WRITE_LOCK)) {
740 printf("lock3 succeeded! This is a locking bug\n");
743 if (!check_error(__LINE__, cli2, ERRDOS, ERRlock,
744 NT_STATUS_FILE_LOCK_CONFLICT)) return False;
749 printf("error: This server appears not to support timed lock requests\n");
751 printf("server slept for %u seconds for a %u second timeout\n",
752 (unsigned int)(t2-t1), lock_timeout);
754 if (!cli_close(cli1, fnum2)) {
755 printf("close1 failed (%s)\n", cli_errstr(cli1));
759 if (cli_lock(cli2, fnum3, 0, 4, 0, WRITE_LOCK)) {
760 printf("lock4 succeeded! This is a locking bug\n");
763 if (!check_error(__LINE__, cli2, ERRDOS, ERRlock,
764 NT_STATUS_FILE_LOCK_CONFLICT)) return False;
767 if (!cli_close(cli1, fnum1)) {
768 printf("close2 failed (%s)\n", cli_errstr(cli1));
772 if (!cli_close(cli2, fnum3)) {
773 printf("close3 failed (%s)\n", cli_errstr(cli2));
777 if (!cli_unlink(cli1, fname)) {
778 printf("unlink failed (%s)\n", cli_errstr(cli1));
783 if (!torture_close_connection(cli1)) {
787 if (!torture_close_connection(cli2)) {
791 printf("Passed locktest1\n");
796 this checks to see if a secondary tconx can use open files from an
799 static BOOL run_tcon_test(int dummy)
801 struct cli_state *cli;
802 const char *fname = "\\tcontest.tmp";
804 uint16 cnum1, cnum2, cnum3;
808 struct cli_tree *tree1;
809 char *host = lp_parm_string(-1, "torture", "host");
810 char *share = lp_parm_string(-1, "torture", "share");
811 char *password = lp_parm_string(-1, "torture", "password");
813 if (!torture_open_connection(&cli)) {
817 printf("starting tcontest\n");
819 if (cli_deltree(cli, fname) == -1) {
820 printf("unlink of %s failed (%s)\n", fname, cli_errstr(cli));
823 fnum1 = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
825 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
829 cnum1 = cli->tree->tid;
830 vuid1 = cli->session->vuid;
832 memset(&buf, 0, 4); /* init buf so valgrind won't complain */
833 if (cli_write(cli, fnum1, 0, buf, 130, 4) != 4) {
834 printf("initial write failed (%s)\n", cli_errstr(cli));
838 tree1 = cli->tree; /* save old tree connection */
839 if (!cli_send_tconX(cli, share, "?????",
841 printf("%s refused 2nd tree connect (%s)\n", host,
847 cnum2 = cli->tree->tid;
848 cnum3 = MAX(cnum1, cnum2) + 1; /* any invalid number */
849 vuid2 = cli->session->vuid + 1;
851 /* try a write with the wrong tid */
852 cli->tree->tid = cnum2;
854 if (cli_write(cli, fnum1, 0, buf, 130, 4) == 4) {
855 printf("* server allows write with wrong TID\n");
858 printf("server fails write with wrong TID : %s\n", cli_errstr(cli));
862 /* try a write with an invalid tid */
863 cli->tree->tid = cnum3;
865 if (cli_write(cli, fnum1, 0, buf, 130, 4) == 4) {
866 printf("* server allows write with invalid TID\n");
869 printf("server fails write with invalid TID : %s\n", cli_errstr(cli));
872 /* try a write with an invalid vuid */
873 cli->session->vuid = vuid2;
874 cli->tree->tid = cnum1;
876 if (cli_write(cli, fnum1, 0, buf, 130, 4) == 4) {
877 printf("* server allows write with invalid VUID\n");
880 printf("server fails write with invalid VUID : %s\n", cli_errstr(cli));
883 cli->session->vuid = vuid1;
884 cli->tree->tid = cnum1;
886 if (!cli_close(cli, fnum1)) {
887 printf("close failed (%s)\n", cli_errstr(cli));
891 cli->tree->tid = cnum2;
893 if (!cli_tdis(cli)) {
894 printf("secondary tdis failed (%s)\n", cli_errstr(cli));
898 cli->tree = tree1; /* restore initial tree */
899 cli->tree->tid = cnum1;
901 if (!torture_close_connection(cli)) {
910 static BOOL tcon_devtest(struct cli_state *cli,
911 const char *myshare, const char *devtype,
912 NTSTATUS expected_error)
916 char *password = lp_parm_string(-1, "torture", "password");
918 status = cli_send_tconX(cli, myshare, devtype,
921 printf("Trying share %s with devtype %s\n", myshare, devtype);
923 if (NT_STATUS_IS_OK(expected_error)) {
927 printf("tconX to share %s with type %s "
928 "should have succeeded but failed\n",
935 printf("tconx to share %s with type %s "
936 "should have failed but succeeded\n",
940 if (NT_STATUS_EQUAL(cli_nt_error(cli),
944 printf("Returned unexpected error\n");
953 checks for correct tconX support
955 static BOOL run_tcon_devtype_test(int dummy)
957 struct cli_state *cli1 = NULL;
962 char *host = lp_parm_string(-1, "torture", "host");
963 char *share = lp_parm_string(-1, "torture", "share");
964 char *username = lp_parm_string(-1, "torture", "username");
965 char *password = lp_parm_string(-1, "torture", "password");
967 status = cli_full_connection(&cli1, lp_netbios_name(),
970 username, lp_workgroup(),
971 password, flags, &retry);
973 if (!NT_STATUS_IS_OK(status)) {
974 printf("could not open connection\n");
978 if (!tcon_devtest(cli1, "IPC$", "A:", NT_STATUS_BAD_DEVICE_TYPE))
981 if (!tcon_devtest(cli1, "IPC$", "?????", NT_STATUS_OK))
984 if (!tcon_devtest(cli1, "IPC$", "LPT:", NT_STATUS_BAD_DEVICE_TYPE))
987 if (!tcon_devtest(cli1, "IPC$", "IPC", NT_STATUS_OK))
990 if (!tcon_devtest(cli1, "IPC$", "FOOBA", NT_STATUS_BAD_DEVICE_TYPE))
993 if (!tcon_devtest(cli1, share, "A:", NT_STATUS_OK))
996 if (!tcon_devtest(cli1, share, "?????", NT_STATUS_OK))
999 if (!tcon_devtest(cli1, share, "LPT:", NT_STATUS_BAD_DEVICE_TYPE))
1002 if (!tcon_devtest(cli1, share, "IPC", NT_STATUS_BAD_DEVICE_TYPE))
1005 if (!tcon_devtest(cli1, share, "FOOBA", NT_STATUS_BAD_DEVICE_TYPE))
1011 printf("Passed tcondevtest\n");
1018 This test checks that
1020 1) the server supports multiple locking contexts on the one SMB
1021 connection, distinguished by PID.
1023 2) the server correctly fails overlapping locks made by the same PID (this
1024 goes against POSIX behaviour, which is why it is tricky to implement)
1026 3) the server denies unlock requests by an incorrect client PID
1028 static BOOL run_locktest2(int dummy)
1030 struct cli_state *cli;
1031 const char *fname = "\\lockt2.lck";
1032 int fnum1, fnum2, fnum3;
1033 BOOL correct = True;
1035 if (!torture_open_connection(&cli)) {
1039 printf("starting locktest2\n");
1041 cli_unlink(cli, fname);
1043 printf("Testing pid context\n");
1045 cli->session->pid = 1;
1047 fnum1 = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1049 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
1053 fnum2 = cli_open(cli, fname, O_RDWR, DENY_NONE);
1055 printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli));
1059 cli->session->pid = 2;
1061 fnum3 = cli_open(cli, fname, O_RDWR, DENY_NONE);
1063 printf("open3 of %s failed (%s)\n", fname, cli_errstr(cli));
1067 cli->session->pid = 1;
1069 if (!cli_lock(cli, fnum1, 0, 4, 0, WRITE_LOCK)) {
1070 printf("lock1 failed (%s)\n", cli_errstr(cli));
1074 if (cli_lock(cli, fnum1, 0, 4, 0, WRITE_LOCK)) {
1075 printf("WRITE lock1 succeeded! This is a locking bug\n");
1078 if (!check_error(__LINE__, cli, ERRDOS, ERRlock,
1079 NT_STATUS_LOCK_NOT_GRANTED)) return False;
1082 if (cli_lock(cli, fnum2, 0, 4, 0, WRITE_LOCK)) {
1083 printf("WRITE lock2 succeeded! This is a locking bug\n");
1086 if (!check_error(__LINE__, cli, ERRDOS, ERRlock,
1087 NT_STATUS_LOCK_NOT_GRANTED)) return False;
1090 if (cli_lock(cli, fnum2, 0, 4, 0, READ_LOCK)) {
1091 printf("READ lock2 succeeded! This is a locking bug\n");
1094 if (!check_error(__LINE__, cli, ERRDOS, ERRlock,
1095 NT_STATUS_FILE_LOCK_CONFLICT)) return False;
1098 if (!cli_lock(cli, fnum1, 100, 4, 0, WRITE_LOCK)) {
1099 printf("lock at 100 failed (%s)\n", cli_errstr(cli));
1102 cli->session->pid = 2;
1104 if (cli_unlock(cli, fnum1, 100, 4)) {
1105 printf("unlock at 100 succeeded! This is a locking bug\n");
1109 if (cli_unlock(cli, fnum1, 0, 4)) {
1110 printf("unlock1 succeeded! This is a locking bug\n");
1113 if (!check_error(__LINE__, cli,
1115 NT_STATUS_RANGE_NOT_LOCKED)) return False;
1118 if (cli_unlock(cli, fnum1, 0, 8)) {
1119 printf("unlock2 succeeded! This is a locking bug\n");
1122 if (!check_error(__LINE__, cli,
1124 NT_STATUS_RANGE_NOT_LOCKED)) return False;
1127 if (cli_lock(cli, fnum3, 0, 4, 0, WRITE_LOCK)) {
1128 printf("lock3 succeeded! This is a locking bug\n");
1131 if (!check_error(__LINE__, cli, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False;
1134 cli->session->pid = 1;
1136 if (!cli_close(cli, fnum1)) {
1137 printf("close1 failed (%s)\n", cli_errstr(cli));
1141 if (!cli_close(cli, fnum2)) {
1142 printf("close2 failed (%s)\n", cli_errstr(cli));
1146 if (!cli_close(cli, fnum3)) {
1147 printf("close3 failed (%s)\n", cli_errstr(cli));
1151 if (!torture_close_connection(cli)) {
1155 printf("locktest2 finished\n");
1162 This test checks that
1164 1) the server supports the full offset range in lock requests
1166 static BOOL run_locktest3(int dummy)
1168 struct cli_state *cli1, *cli2;
1169 const char *fname = "\\lockt3.lck";
1170 int fnum1, fnum2, i;
1172 BOOL correct = True;
1174 #define NEXT_OFFSET offset += (~(uint32)0) / torture_numops
1176 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
1180 printf("starting locktest3\n");
1182 printf("Testing 32 bit offset ranges\n");
1184 cli_unlink(cli1, fname);
1186 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1188 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
1191 fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
1193 printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli2));
1197 printf("Establishing %d locks\n", torture_numops);
1199 for (offset=i=0;i<torture_numops;i++) {
1201 if (!cli_lock(cli1, fnum1, offset-1, 1, 0, WRITE_LOCK)) {
1202 printf("lock1 %d failed (%s)\n",
1208 if (!cli_lock(cli2, fnum2, offset-2, 1, 0, WRITE_LOCK)) {
1209 printf("lock2 %d failed (%s)\n",
1216 printf("Testing %d locks\n", torture_numops);
1218 for (offset=i=0;i<torture_numops;i++) {
1221 if (cli_lock(cli1, fnum1, offset-2, 1, 0, WRITE_LOCK)) {
1222 printf("error: lock1 %d succeeded!\n", i);
1226 if (cli_lock(cli2, fnum2, offset-1, 1, 0, WRITE_LOCK)) {
1227 printf("error: lock2 %d succeeded!\n", i);
1231 if (cli_lock(cli1, fnum1, offset-1, 1, 0, WRITE_LOCK)) {
1232 printf("error: lock3 %d succeeded!\n", i);
1236 if (cli_lock(cli2, fnum2, offset-2, 1, 0, WRITE_LOCK)) {
1237 printf("error: lock4 %d succeeded!\n", i);
1242 printf("Removing %d locks\n", torture_numops);
1244 for (offset=i=0;i<torture_numops;i++) {
1247 if (!cli_unlock(cli1, fnum1, offset-1, 1)) {
1248 printf("unlock1 %d failed (%s)\n",
1254 if (!cli_unlock(cli2, fnum2, offset-2, 1)) {
1255 printf("unlock2 %d failed (%s)\n",
1262 if (!cli_close(cli1, fnum1)) {
1263 printf("close1 failed (%s)\n", cli_errstr(cli1));
1267 if (!cli_close(cli2, fnum2)) {
1268 printf("close2 failed (%s)\n", cli_errstr(cli2));
1272 if (!cli_unlink(cli1, fname)) {
1273 printf("unlink failed (%s)\n", cli_errstr(cli1));
1277 if (!torture_close_connection(cli1)) {
1281 if (!torture_close_connection(cli2)) {
1285 printf("finished locktest3\n");
1290 #define EXPECTED(ret, v) if ((ret) != (v)) { \
1291 printf("** "); correct = False; \
1295 looks at overlapping locks
1297 static BOOL run_locktest4(int dummy)
1299 struct cli_state *cli1, *cli2;
1300 const char *fname = "\\lockt4.lck";
1301 int fnum1, fnum2, f;
1304 BOOL correct = True;
1306 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
1310 printf("starting locktest4\n");
1312 cli_unlink(cli1, fname);
1314 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1315 fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
1317 memset(buf, 0, sizeof(buf));
1319 if (cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
1320 printf("Failed to create file\n");
1325 ret = cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK) &&
1326 cli_lock(cli1, fnum1, 2, 4, 0, WRITE_LOCK);
1327 EXPECTED(ret, False);
1328 printf("the same process %s set overlapping write locks\n", ret?"can":"cannot");
1330 ret = cli_lock(cli1, fnum1, 10, 4, 0, READ_LOCK) &&
1331 cli_lock(cli1, fnum1, 12, 4, 0, READ_LOCK);
1332 EXPECTED(ret, True);
1333 printf("the same process %s set overlapping read locks\n", ret?"can":"cannot");
1335 ret = cli_lock(cli1, fnum1, 20, 4, 0, WRITE_LOCK) &&
1336 cli_lock(cli2, fnum2, 22, 4, 0, WRITE_LOCK);
1337 EXPECTED(ret, False);
1338 printf("a different connection %s set overlapping write locks\n", ret?"can":"cannot");
1340 ret = cli_lock(cli1, fnum1, 30, 4, 0, READ_LOCK) &&
1341 cli_lock(cli2, fnum2, 32, 4, 0, READ_LOCK);
1342 EXPECTED(ret, True);
1343 printf("a different connection %s set overlapping read locks\n", ret?"can":"cannot");
1345 ret = (cli1->session->pid = 1, cli_lock(cli1, fnum1, 40, 4, 0, WRITE_LOCK)) &&
1346 (cli1->session->pid = 2, cli_lock(cli1, fnum1, 42, 4, 0, WRITE_LOCK));
1347 EXPECTED(ret, False);
1348 printf("a different pid %s set overlapping write locks\n", ret?"can":"cannot");
1350 ret = (cli1->session->pid = 1, cli_lock(cli1, fnum1, 50, 4, 0, READ_LOCK)) &&
1351 (cli1->session->pid = 2, cli_lock(cli1, fnum1, 52, 4, 0, READ_LOCK));
1352 EXPECTED(ret, True);
1353 printf("a different pid %s set overlapping read locks\n", ret?"can":"cannot");
1355 ret = cli_lock(cli1, fnum1, 60, 4, 0, READ_LOCK) &&
1356 cli_lock(cli1, fnum1, 60, 4, 0, READ_LOCK);
1357 EXPECTED(ret, True);
1358 printf("the same process %s set the same read lock twice\n", ret?"can":"cannot");
1360 ret = cli_lock(cli1, fnum1, 70, 4, 0, WRITE_LOCK) &&
1361 cli_lock(cli1, fnum1, 70, 4, 0, WRITE_LOCK);
1362 EXPECTED(ret, False);
1363 printf("the same process %s set the same write lock twice\n", ret?"can":"cannot");
1365 ret = cli_lock(cli1, fnum1, 80, 4, 0, READ_LOCK) &&
1366 cli_lock(cli1, fnum1, 80, 4, 0, WRITE_LOCK);
1367 EXPECTED(ret, False);
1368 printf("the same process %s overlay a read lock with a write lock\n", ret?"can":"cannot");
1370 ret = cli_lock(cli1, fnum1, 90, 4, 0, WRITE_LOCK) &&
1371 cli_lock(cli1, fnum1, 90, 4, 0, READ_LOCK);
1372 EXPECTED(ret, True);
1373 printf("the same process %s overlay a write lock with a read lock\n", ret?"can":"cannot");
1375 ret = (cli1->session->pid = 1, cli_lock(cli1, fnum1, 100, 4, 0, WRITE_LOCK)) &&
1376 (cli1->session->pid = 2, cli_lock(cli1, fnum1, 100, 4, 0, READ_LOCK));
1377 EXPECTED(ret, False);
1378 printf("a different pid %s overlay a write lock with a read lock\n", ret?"can":"cannot");
1380 ret = cli_lock(cli1, fnum1, 110, 4, 0, READ_LOCK) &&
1381 cli_lock(cli1, fnum1, 112, 4, 0, READ_LOCK) &&
1382 cli_unlock(cli1, fnum1, 110, 6);
1383 EXPECTED(ret, False);
1384 printf("the same process %s coalesce read locks\n", ret?"can":"cannot");
1387 ret = cli_lock(cli1, fnum1, 120, 4, 0, WRITE_LOCK) &&
1388 (cli_read(cli2, fnum2, buf, 120, 4) == 4);
1389 EXPECTED(ret, False);
1390 printf("this server %s strict write locking\n", ret?"doesn't do":"does");
1392 ret = cli_lock(cli1, fnum1, 130, 4, 0, READ_LOCK) &&
1393 (cli_write(cli2, fnum2, 0, buf, 130, 4) == 4);
1394 EXPECTED(ret, False);
1395 printf("this server %s strict read locking\n", ret?"doesn't do":"does");
1398 ret = cli_lock(cli1, fnum1, 140, 4, 0, READ_LOCK) &&
1399 cli_lock(cli1, fnum1, 140, 4, 0, READ_LOCK) &&
1400 cli_unlock(cli1, fnum1, 140, 4) &&
1401 cli_unlock(cli1, fnum1, 140, 4);
1402 EXPECTED(ret, True);
1403 printf("this server %s do recursive read locking\n", ret?"does":"doesn't");
1406 ret = cli_lock(cli1, fnum1, 150, 4, 0, WRITE_LOCK) &&
1407 cli_lock(cli1, fnum1, 150, 4, 0, READ_LOCK) &&
1408 cli_unlock(cli1, fnum1, 150, 4) &&
1409 (cli_read(cli2, fnum2, buf, 150, 4) == 4) &&
1410 !(cli_write(cli2, fnum2, 0, buf, 150, 4) == 4) &&
1411 cli_unlock(cli1, fnum1, 150, 4);
1412 EXPECTED(ret, True);
1413 printf("this server %s do recursive lock overlays\n", ret?"does":"doesn't");
1415 ret = cli_lock(cli1, fnum1, 160, 4, 0, READ_LOCK) &&
1416 cli_unlock(cli1, fnum1, 160, 4) &&
1417 (cli_write(cli2, fnum2, 0, buf, 160, 4) == 4) &&
1418 (cli_read(cli2, fnum2, buf, 160, 4) == 4);
1419 EXPECTED(ret, True);
1420 printf("the same process %s remove a read lock using write locking\n", ret?"can":"cannot");
1422 ret = cli_lock(cli1, fnum1, 170, 4, 0, WRITE_LOCK) &&
1423 cli_unlock(cli1, fnum1, 170, 4) &&
1424 (cli_write(cli2, fnum2, 0, buf, 170, 4) == 4) &&
1425 (cli_read(cli2, fnum2, buf, 170, 4) == 4);
1426 EXPECTED(ret, True);
1427 printf("the same process %s remove a write lock using read locking\n", ret?"can":"cannot");
1429 ret = cli_lock(cli1, fnum1, 190, 4, 0, WRITE_LOCK) &&
1430 cli_lock(cli1, fnum1, 190, 4, 0, READ_LOCK) &&
1431 cli_unlock(cli1, fnum1, 190, 4) &&
1432 !(cli_write(cli2, fnum2, 0, buf, 190, 4) == 4) &&
1433 (cli_read(cli2, fnum2, buf, 190, 4) == 4);
1434 EXPECTED(ret, True);
1435 printf("the same process %s remove the first lock first\n", ret?"does":"doesn't");
1437 cli_close(cli1, fnum1);
1438 cli_close(cli2, fnum2);
1439 fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1440 f = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1441 ret = cli_lock(cli1, fnum1, 0, 8, 0, READ_LOCK) &&
1442 cli_lock(cli1, f, 0, 1, 0, READ_LOCK) &&
1443 cli_close(cli1, fnum1) &&
1444 ((fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE)) != -1) &&
1445 cli_lock(cli1, fnum1, 7, 1, 0, WRITE_LOCK);
1447 cli_close(cli1, fnum1);
1448 EXPECTED(ret, True);
1449 printf("the server %s have the NT byte range lock bug\n", !ret?"does":"doesn't");
1452 cli_close(cli1, fnum1);
1453 cli_close(cli2, fnum2);
1454 cli_unlink(cli1, fname);
1455 torture_close_connection(cli1);
1456 torture_close_connection(cli2);
1458 printf("finished locktest4\n");
1463 looks at lock upgrade/downgrade.
1465 static BOOL run_locktest5(int dummy)
1467 struct cli_state *cli1, *cli2;
1468 const char *fname = "\\lockt5.lck";
1469 int fnum1, fnum2, fnum3;
1472 BOOL correct = True;
1474 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
1478 printf("starting locktest5\n");
1480 cli_unlink(cli1, fname);
1482 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1483 fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
1484 fnum3 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1486 memset(buf, 0, sizeof(buf));
1488 if (cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
1489 printf("Failed to create file\n");
1494 /* Check for NT bug... */
1495 ret = cli_lock(cli1, fnum1, 0, 8, 0, READ_LOCK) &&
1496 cli_lock(cli1, fnum3, 0, 1, 0, READ_LOCK);
1497 cli_close(cli1, fnum1);
1498 fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1499 ret = cli_lock(cli1, fnum1, 7, 1, 0, WRITE_LOCK);
1500 EXPECTED(ret, True);
1501 printf("this server %s the NT locking bug\n", ret ? "doesn't have" : "has");
1502 cli_close(cli1, fnum1);
1503 fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1504 cli_unlock(cli1, fnum3, 0, 1);
1506 ret = cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK) &&
1507 cli_lock(cli1, fnum1, 1, 1, 0, READ_LOCK);
1508 EXPECTED(ret, True);
1509 printf("the same process %s overlay a write with a read lock\n", ret?"can":"cannot");
1511 ret = cli_lock(cli2, fnum2, 0, 4, 0, READ_LOCK);
1512 EXPECTED(ret, False);
1514 printf("a different processs %s get a read lock on the first process lock stack\n", ret?"can":"cannot");
1516 /* Unlock the process 2 lock. */
1517 cli_unlock(cli2, fnum2, 0, 4);
1519 ret = cli_lock(cli1, fnum3, 0, 4, 0, READ_LOCK);
1520 EXPECTED(ret, False);
1522 printf("the same processs on a different fnum %s get a read lock\n", ret?"can":"cannot");
1524 /* Unlock the process 1 fnum3 lock. */
1525 cli_unlock(cli1, fnum3, 0, 4);
1527 /* Stack 2 more locks here. */
1528 ret = cli_lock(cli1, fnum1, 0, 4, 0, READ_LOCK) &&
1529 cli_lock(cli1, fnum1, 0, 4, 0, READ_LOCK);
1531 EXPECTED(ret, True);
1532 printf("the same process %s stack read locks\n", ret?"can":"cannot");
1534 /* Unlock the first process lock, then check this was the WRITE lock that was
1537 ret = cli_unlock(cli1, fnum1, 0, 4) &&
1538 cli_lock(cli2, fnum2, 0, 4, 0, READ_LOCK);
1540 EXPECTED(ret, True);
1541 printf("the first unlock removes the %s lock\n", ret?"WRITE":"READ");
1543 /* Unlock the process 2 lock. */
1544 cli_unlock(cli2, fnum2, 0, 4);
1546 /* We should have 3 stacked locks here. Ensure we need to do 3 unlocks. */
1548 ret = cli_unlock(cli1, fnum1, 1, 1) &&
1549 cli_unlock(cli1, fnum1, 0, 4) &&
1550 cli_unlock(cli1, fnum1, 0, 4);
1552 EXPECTED(ret, True);
1553 printf("the same process %s unlock the stack of 4 locks\n", ret?"can":"cannot");
1555 /* Ensure the next unlock fails. */
1556 ret = cli_unlock(cli1, fnum1, 0, 4);
1557 EXPECTED(ret, False);
1558 printf("the same process %s count the lock stack\n", !ret?"can":"cannot");
1560 /* Ensure connection 2 can get a write lock. */
1561 ret = cli_lock(cli2, fnum2, 0, 4, 0, WRITE_LOCK);
1562 EXPECTED(ret, True);
1564 printf("a different processs %s get a write lock on the unlocked stack\n", ret?"can":"cannot");
1568 cli_close(cli1, fnum1);
1569 cli_close(cli2, fnum2);
1570 cli_unlink(cli1, fname);
1571 if (!torture_close_connection(cli1)) {
1574 if (!torture_close_connection(cli2)) {
1578 printf("finished locktest5\n");
1584 tries the unusual lockingX locktype bits
1586 static BOOL run_locktest6(int dummy)
1588 struct cli_state *cli;
1589 const char *fname[1] = { "\\lock6.txt" };
1594 if (!torture_open_connection(&cli)) {
1598 printf("starting locktest6\n");
1601 printf("Testing %s\n", fname[i]);
1603 cli_unlink(cli, fname[i]);
1605 fnum = cli_open(cli, fname[i], O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1606 status = cli_locktype(cli, fnum, 0, 8, 0, LOCKING_ANDX_CHANGE_LOCKTYPE);
1607 cli_close(cli, fnum);
1608 printf("CHANGE_LOCKTYPE gave %s\n", nt_errstr(status));
1610 fnum = cli_open(cli, fname[i], O_RDWR, DENY_NONE);
1611 status = cli_locktype(cli, fnum, 0, 8, 0, LOCKING_ANDX_CANCEL_LOCK);
1612 cli_close(cli, fnum);
1613 printf("CANCEL_LOCK gave %s\n", nt_errstr(status));
1615 cli_unlink(cli, fname[i]);
1618 torture_close_connection(cli);
1620 printf("finished locktest6\n");
1624 static BOOL run_locktest7(int dummy)
1626 struct cli_state *cli1;
1627 const char *fname = "\\lockt7.lck";
1630 BOOL correct = False;
1632 if (!torture_open_connection(&cli1)) {
1636 printf("starting locktest7\n");
1638 cli_unlink(cli1, fname);
1640 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1642 memset(buf, 0, sizeof(buf));
1644 if (cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
1645 printf("Failed to create file\n");
1649 cli1->session->pid = 1;
1651 if (!cli_lock(cli1, fnum1, 130, 4, 0, READ_LOCK)) {
1652 printf("Unable to apply read lock on range 130:4, error was %s\n", cli_errstr(cli1));
1655 printf("pid1 successfully locked range 130:4 for READ\n");
1658 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
1659 printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
1662 printf("pid1 successfully read the range 130:4\n");
1665 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
1666 printf("pid1 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
1667 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
1668 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
1672 printf("pid1 successfully wrote to the range 130:4 (should be denied)\n");
1676 cli1->session->pid = 2;
1678 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
1679 printf("pid2 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
1681 printf("pid2 successfully read the range 130:4\n");
1684 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
1685 printf("pid2 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
1686 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
1687 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
1691 printf("pid2 successfully wrote to the range 130:4 (should be denied)\n");
1695 cli1->session->pid = 1;
1696 cli_unlock(cli1, fnum1, 130, 4);
1698 if (!cli_lock(cli1, fnum1, 130, 4, 0, WRITE_LOCK)) {
1699 printf("Unable to apply write lock on range 130:4, error was %s\n", cli_errstr(cli1));
1702 printf("pid1 successfully locked range 130:4 for WRITE\n");
1705 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
1706 printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
1709 printf("pid1 successfully read the range 130:4\n");
1712 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
1713 printf("pid1 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
1716 printf("pid1 successfully wrote to the range 130:4\n");
1719 cli1->session->pid = 2;
1721 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
1722 printf("pid2 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
1723 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
1724 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
1728 printf("pid2 successfully read the range 130:4 (should be denied)\n");
1732 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
1733 printf("pid2 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
1734 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
1735 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
1739 printf("pid2 successfully wrote to the range 130:4 (should be denied)\n");
1743 cli_unlock(cli1, fnum1, 130, 0);
1747 cli_close(cli1, fnum1);
1748 cli_unlink(cli1, fname);
1749 torture_close_connection(cli1);
1751 printf("finished locktest7\n");
1756 test whether fnums and tids open on one VC are available on another (a major
1759 static BOOL run_fdpasstest(int dummy)
1761 struct cli_state *cli1, *cli2;
1762 const char *fname = "\\fdpass.tst";
1766 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
1770 printf("starting fdpasstest\n");
1772 cli_unlink(cli1, fname);
1774 printf("Opening a file on connection 1\n");
1776 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1778 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
1782 printf("writing to file on connection 1\n");
1784 if (cli_write(cli1, fnum1, 0, "hello world\n", 0, 13) != 13) {
1785 printf("write failed (%s)\n", cli_errstr(cli1));
1789 oldtid = cli2->tree->tid;
1790 cli2->session->vuid = cli1->session->vuid;
1791 cli2->tree->tid = cli1->tree->tid;
1792 cli2->session->pid = cli1->session->pid;
1794 printf("reading from file on connection 2\n");
1796 if (cli_read(cli2, fnum1, buf, 0, 13) == 13) {
1797 printf("read succeeded! nasty security hole [%s]\n",
1802 cli_close(cli1, fnum1);
1803 cli_unlink(cli1, fname);
1805 cli2->tree->tid = oldtid;
1807 torture_close_connection(cli1);
1808 torture_close_connection(cli2);
1810 printf("finished fdpasstest\n");
1816 This test checks that
1818 1) the server does not allow an unlink on a file that is open
1820 static BOOL run_unlinktest(int dummy)
1822 struct cli_state *cli;
1823 const char *fname = "\\unlink.tst";
1825 BOOL correct = True;
1827 if (!torture_open_connection(&cli)) {
1831 printf("starting unlink test\n");
1833 cli_unlink(cli, fname);
1835 cli->session->pid = 1;
1837 printf("Opening a file\n");
1839 fnum = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1841 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
1845 printf("Unlinking a open file\n");
1847 if (cli_unlink(cli, fname)) {
1848 printf("error: server allowed unlink on an open file\n");
1851 correct = check_error(__LINE__, cli, ERRDOS, ERRbadshare,
1852 NT_STATUS_SHARING_VIOLATION);
1855 cli_close(cli, fnum);
1856 cli_unlink(cli, fname);
1858 if (!torture_close_connection(cli)) {
1862 printf("unlink test finished\n");
1869 test how many open files this server supports on the one socket
1871 static BOOL run_maxfidtest(int dummy)
1873 struct cli_state *cli;
1874 const char *template = "\\maxfid.%d.%d";
1876 int fnums[0x11000], i;
1878 BOOL correct = True;
1883 printf("failed to connect\n");
1887 printf("Testing maximum number of open files\n");
1889 for (i=0; i<0x11000; i++) {
1890 asprintf(&fname, template, i,(int)getpid());
1891 if ((fnums[i] = cli_open(cli, fname,
1892 O_RDWR|O_CREAT|O_TRUNC, DENY_NONE)) ==
1894 printf("open of %s failed (%s)\n",
1895 fname, cli_errstr(cli));
1896 printf("maximum fnum is %d\n", i);
1905 printf("cleaning up\n");
1907 asprintf(&fname, template, i,(int)getpid());
1908 if (!cli_close(cli, fnums[i])) {
1909 printf("Close of fnum %d failed - %s\n", fnums[i], cli_errstr(cli));
1911 if (!cli_unlink(cli, fname)) {
1912 printf("unlink of %s failed (%s)\n",
1913 fname, cli_errstr(cli));
1921 printf("maxfid test finished\n");
1922 if (!torture_close_connection(cli)) {
1928 /* send smb negprot commands, not reading the response */
1929 static BOOL run_negprot_nowait(int dummy)
1932 struct cli_state *cli;
1933 BOOL correct = True;
1935 printf("starting negprot nowait test\n");
1937 cli = open_nbt_connection();
1942 printf("Establishing protocol negotiations - connect with another client\n");
1944 for (i=0;i<50000;i++) {
1945 smb_negprot_send(cli->transport, PROTOCOL_NT1);
1948 if (!torture_close_connection(cli)) {
1952 printf("finished negprot nowait test\n");
1959 This checks how the getatr calls works
1961 static BOOL run_attrtest(int dummy)
1963 struct cli_state *cli;
1966 const char *fname = "\\attrib123456789.tst";
1967 BOOL correct = True;
1969 printf("starting attrib test\n");
1971 if (!torture_open_connection(&cli)) {
1975 cli_unlink(cli, fname);
1976 fnum = cli_open(cli, fname,
1977 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1978 cli_close(cli, fnum);
1980 if (!cli_getatr(cli, fname, NULL, NULL, &t)) {
1981 printf("getatr failed (%s)\n", cli_errstr(cli));
1985 printf("New file time is %s", ctime(&t));
1987 if (abs(t - time(NULL)) > 60*60*24*10) {
1988 printf("ERROR: SMBgetatr bug. time is %s",
1994 t2 = t-60*60*24; /* 1 day ago */
1996 printf("Setting file time to %s", ctime(&t2));
1998 if (!cli_setatr(cli, fname, 0, t2)) {
1999 printf("setatr failed (%s)\n", cli_errstr(cli));
2003 if (!cli_getatr(cli, fname, NULL, NULL, &t)) {
2004 printf("getatr failed (%s)\n", cli_errstr(cli));
2008 printf("Retrieved file time as %s", ctime(&t));
2011 printf("ERROR: getatr/setatr bug. times are\n%s",
2013 printf("%s", ctime(&t2));
2017 cli_unlink(cli, fname);
2019 if (!torture_close_connection(cli)) {
2023 printf("attrib test finished\n");
2030 This checks a couple of trans2 calls
2032 static BOOL run_trans2test(int dummy)
2034 struct cli_state *cli;
2037 time_t c_time, a_time, m_time, w_time, m_time2;
2038 const char *fname = "\\trans2.tst";
2039 const char *dname = "\\trans2";
2040 const char *fname2 = "\\trans2\\trans2.tst";
2042 BOOL correct = True;
2044 printf("starting trans2 test\n");
2046 if (!torture_open_connection(&cli)) {
2050 cli_unlink(cli, fname);
2052 printf("Testing qfileinfo\n");
2054 fnum = cli_open(cli, fname,
2055 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2056 if (!cli_qfileinfo(cli, fnum, NULL, &size, &c_time, &a_time, &m_time,
2058 printf("ERROR: qfileinfo failed (%s)\n", cli_errstr(cli));
2062 printf("Testing NAME_INFO\n");
2064 if (!cli_qfilename(cli, fnum, &pname)) {
2065 printf("ERROR: qfilename failed (%s)\n", cli_errstr(cli));
2069 if (!pname || strcmp(pname, fname)) {
2070 printf("qfilename gave different name? [%s] [%s]\n",
2075 cli_close(cli, fnum);
2076 cli_unlink(cli, fname);
2078 fnum = cli_open(cli, fname,
2079 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2081 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
2084 cli_close(cli, fnum);
2086 printf("Checking for sticky create times\n");
2088 if (!cli_qpathinfo(cli, fname, &c_time, &a_time, &m_time, &size, NULL)) {
2089 printf("ERROR: qpathinfo failed (%s)\n", cli_errstr(cli));
2092 if (c_time != m_time) {
2093 printf("create time=%s", ctime(&c_time));
2094 printf("modify time=%s", ctime(&m_time));
2095 printf("This system appears to have sticky create times\n");
2097 if (a_time % (60*60) == 0) {
2098 printf("access time=%s", ctime(&a_time));
2099 printf("This system appears to set a midnight access time\n");
2103 if (abs(m_time - time(NULL)) > 60*60*24*7) {
2104 printf("ERROR: totally incorrect times - maybe word reversed? mtime=%s", ctime(&m_time));
2110 cli_unlink(cli, fname);
2111 fnum = cli_open(cli, fname,
2112 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2113 cli_close(cli, fnum);
2114 if (!cli_qpathinfo2(cli, fname, &c_time, &a_time, &m_time,
2115 &w_time, &size, NULL, NULL)) {
2116 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli));
2119 if (w_time < 60*60*24*2) {
2120 printf("write time=%s", ctime(&w_time));
2121 printf("This system appears to set a initial 0 write time\n");
2126 cli_unlink(cli, fname);
2129 /* check if the server updates the directory modification time
2130 when creating a new file */
2131 if (!cli_mkdir(cli, dname)) {
2132 printf("ERROR: mkdir failed (%s)\n", cli_errstr(cli));
2136 if (!cli_qpathinfo2(cli, "\\trans2\\", &c_time, &a_time, &m_time,
2137 &w_time, &size, NULL, NULL)) {
2138 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli));
2142 fnum = cli_open(cli, fname2,
2143 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2144 cli_write(cli, fnum, 0, (char *)&fnum, 0, sizeof(fnum));
2145 cli_close(cli, fnum);
2146 if (!cli_qpathinfo2(cli, "\\trans2\\", &c_time, &a_time, &m_time2,
2147 &w_time, &size, NULL, NULL)) {
2148 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli));
2151 if (m_time2 == m_time) {
2152 printf("This system does not update directory modification times\n");
2156 cli_unlink(cli, fname2);
2157 cli_rmdir(cli, dname);
2159 if (!torture_close_connection(cli)) {
2163 printf("trans2 test finished\n");
2169 Test delete on close semantics.
2171 static BOOL run_deletetest(int dummy)
2173 struct cli_state *cli1;
2174 struct cli_state *cli2 = NULL;
2175 const char *fname = "\\delete.file";
2178 BOOL correct = True;
2180 printf("starting delete test\n");
2182 if (!torture_open_connection(&cli1)) {
2186 /* Test 1 - this should delete the file on close. */
2188 cli_setatr(cli1, fname, 0, 0);
2189 cli_unlink(cli1, fname);
2191 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_RIGHTS_FILE_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL,
2192 NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OVERWRITE_IF,
2193 NTCREATEX_OPTIONS_DELETE_ON_CLOSE, 0);
2196 printf("[1] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2201 if (!cli_close(cli1, fnum1)) {
2202 printf("[1] close failed (%s)\n", cli_errstr(cli1));
2207 fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
2209 printf("[1] open of %s succeeded (should fail)\n", fname);
2214 printf("first delete on close test succeeded.\n");
2216 /* Test 2 - this should delete the file on close. */
2218 cli_setatr(cli1, fname, 0, 0);
2219 cli_unlink(cli1, fname);
2221 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_RIGHTS_FILE_ALL_ACCESS,
2222 FILE_ATTRIBUTE_NORMAL, NTCREATEX_SHARE_ACCESS_NONE,
2223 NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
2226 printf("[2] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2231 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
2232 printf("[2] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
2237 if (!cli_close(cli1, fnum1)) {
2238 printf("[2] close failed (%s)\n", cli_errstr(cli1));
2243 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
2245 printf("[2] open of %s succeeded should have been deleted on close !\n", fname);
2246 if (!cli_close(cli1, fnum1)) {
2247 printf("[2] close failed (%s)\n", cli_errstr(cli1));
2251 cli_unlink(cli1, fname);
2253 printf("second delete on close test succeeded.\n");
2256 cli_setatr(cli1, fname, 0, 0);
2257 cli_unlink(cli1, fname);
2259 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_RIGHTS_FILE_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL,
2260 NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
2263 printf("[3] open - 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
2268 /* This should fail with a sharing violation - open for delete is only compatible
2269 with SHARE_DELETE. */
2271 fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_RIGHTS_FILE_READ, FILE_ATTRIBUTE_NORMAL,
2272 NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE,
2273 NTCREATEX_DISP_OPEN, 0, 0);
2276 printf("[3] open - 2 of %s succeeded - should have failed.\n", fname);
2281 /* This should succeed. */
2283 fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_RIGHTS_FILE_READ, FILE_ATTRIBUTE_NORMAL,
2284 NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE|NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OPEN, 0, 0);
2287 printf("[3] open - 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
2292 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
2293 printf("[3] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
2298 if (!cli_close(cli1, fnum1)) {
2299 printf("[3] close 1 failed (%s)\n", cli_errstr(cli1));
2304 if (!cli_close(cli1, fnum2)) {
2305 printf("[3] close 2 failed (%s)\n", cli_errstr(cli1));
2310 /* This should fail - file should no longer be there. */
2312 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
2314 printf("[3] open of %s succeeded should have been deleted on close !\n", fname);
2315 if (!cli_close(cli1, fnum1)) {
2316 printf("[3] close failed (%s)\n", cli_errstr(cli1));
2318 cli_unlink(cli1, fname);
2322 printf("third delete on close test succeeded.\n");
2325 cli_setatr(cli1, fname, 0, 0);
2326 cli_unlink(cli1, fname);
2328 fnum1 = cli_nt_create_full(cli1, fname, 0,
2329 SA_RIGHT_FILE_READ_DATA |
2330 SA_RIGHT_FILE_WRITE_DATA |
2331 STD_RIGHT_DELETE_ACCESS,
2332 FILE_ATTRIBUTE_NORMAL,
2333 NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE,
2334 NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
2337 printf("[4] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2342 /* This should succeed. */
2343 fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_RIGHTS_FILE_READ,
2344 FILE_ATTRIBUTE_NORMAL,
2345 NTCREATEX_SHARE_ACCESS_READ |
2346 NTCREATEX_SHARE_ACCESS_WRITE |
2347 NTCREATEX_SHARE_ACCESS_DELETE,
2348 NTCREATEX_DISP_OPEN, 0, 0);
2350 printf("[4] open - 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
2355 if (!cli_close(cli1, fnum2)) {
2356 printf("[4] close - 1 failed (%s)\n", cli_errstr(cli1));
2361 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
2362 printf("[4] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
2367 /* This should fail - no more opens once delete on close set. */
2368 fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_RIGHTS_FILE_READ,
2369 FILE_ATTRIBUTE_NORMAL, NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE|NTCREATEX_SHARE_ACCESS_DELETE,
2370 NTCREATEX_DISP_OPEN, 0, 0);
2372 printf("[4] open - 3 of %s succeeded ! Should have failed.\n", fname );
2376 printf("fourth delete on close test succeeded.\n");
2378 if (!cli_close(cli1, fnum1)) {
2379 printf("[4] close - 2 failed (%s)\n", cli_errstr(cli1));
2385 cli_setatr(cli1, fname, 0, 0);
2386 cli_unlink(cli1, fname);
2388 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT, DENY_NONE);
2390 printf("[5] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2395 /* This should fail - only allowed on NT opens with DELETE access. */
2397 if (cli_nt_delete_on_close(cli1, fnum1, True)) {
2398 printf("[5] setting delete_on_close on OpenX file succeeded - should fail !\n");
2403 if (!cli_close(cli1, fnum1)) {
2404 printf("[5] close - 2 failed (%s)\n", cli_errstr(cli1));
2409 printf("fifth delete on close test succeeded.\n");
2412 cli_setatr(cli1, fname, 0, 0);
2413 cli_unlink(cli1, fname);
2415 fnum1 = cli_nt_create_full(cli1, fname, 0,
2416 SA_RIGHT_FILE_READ_DATA | SA_RIGHT_FILE_WRITE_DATA,
2417 FILE_ATTRIBUTE_NORMAL,
2418 NTCREATEX_SHARE_ACCESS_READ |
2419 NTCREATEX_SHARE_ACCESS_WRITE |
2420 NTCREATEX_SHARE_ACCESS_DELETE,
2421 NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
2424 printf("[6] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2429 /* This should fail - only allowed on NT opens with DELETE access. */
2431 if (cli_nt_delete_on_close(cli1, fnum1, True)) {
2432 printf("[6] setting delete_on_close on file with no delete access succeeded - should fail !\n");
2437 if (!cli_close(cli1, fnum1)) {
2438 printf("[6] close - 2 failed (%s)\n", cli_errstr(cli1));
2443 printf("sixth delete on close test succeeded.\n");
2446 cli_setatr(cli1, fname, 0, 0);
2447 cli_unlink(cli1, fname);
2449 fnum1 = cli_nt_create_full(cli1, fname, 0,
2450 SA_RIGHT_FILE_READ_DATA |
2451 SA_RIGHT_FILE_WRITE_DATA |
2452 STD_RIGHT_DELETE_ACCESS,
2453 FILE_ATTRIBUTE_NORMAL, 0, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
2456 printf("[7] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2461 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
2462 printf("[7] setting delete_on_close on file failed !\n");
2467 if (!cli_nt_delete_on_close(cli1, fnum1, False)) {
2468 printf("[7] unsetting delete_on_close on file failed !\n");
2473 if (!cli_close(cli1, fnum1)) {
2474 printf("[7] close - 2 failed (%s)\n", cli_errstr(cli1));
2479 /* This next open should succeed - we reset the flag. */
2481 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
2483 printf("[5] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2488 if (!cli_close(cli1, fnum1)) {
2489 printf("[7] close - 2 failed (%s)\n", cli_errstr(cli1));
2494 printf("seventh delete on close test succeeded.\n");
2497 cli_setatr(cli1, fname, 0, 0);
2498 cli_unlink(cli1, fname);
2500 if (!torture_open_connection(&cli2)) {
2501 printf("[8] failed to open second connection.\n");
2506 fnum1 = cli_nt_create_full(cli1, fname, 0, SA_RIGHT_FILE_READ_DATA|SA_RIGHT_FILE_WRITE_DATA|STD_RIGHT_DELETE_ACCESS,
2507 FILE_ATTRIBUTE_NORMAL, NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE|NTCREATEX_SHARE_ACCESS_DELETE,
2508 NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
2511 printf("[8] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2516 fnum2 = cli_nt_create_full(cli2, fname, 0, SA_RIGHT_FILE_READ_DATA|SA_RIGHT_FILE_WRITE_DATA|STD_RIGHT_DELETE_ACCESS,
2517 FILE_ATTRIBUTE_NORMAL, NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE|NTCREATEX_SHARE_ACCESS_DELETE,
2518 NTCREATEX_DISP_OPEN, 0, 0);
2521 printf("[8] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2526 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
2527 printf("[8] setting delete_on_close on file failed !\n");
2532 if (!cli_close(cli1, fnum1)) {
2533 printf("[8] close - 1 failed (%s)\n", cli_errstr(cli1));
2538 if (!cli_close(cli2, fnum2)) {
2539 printf("[8] close - 2 failed (%s)\n", cli_errstr(cli2));
2544 /* This should fail.. */
2545 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
2547 printf("[8] open of %s succeeded should have been deleted on close !\n", fname);
2551 printf("eighth delete on close test succeeded.\n");
2553 /* This should fail - we need to set DELETE_ACCESS. */
2554 fnum1 = cli_nt_create_full(cli1, fname, 0,SA_RIGHT_FILE_READ_DATA|SA_RIGHT_FILE_WRITE_DATA,
2555 FILE_ATTRIBUTE_NORMAL, NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, NTCREATEX_OPTIONS_DELETE_ON_CLOSE, 0);
2558 printf("[9] open of %s succeeded should have failed!\n", fname);
2563 printf("ninth delete on close test succeeded.\n");
2565 fnum1 = cli_nt_create_full(cli1, fname, 0, SA_RIGHT_FILE_READ_DATA|SA_RIGHT_FILE_WRITE_DATA|STD_RIGHT_DELETE_ACCESS,
2566 FILE_ATTRIBUTE_NORMAL, NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, NTCREATEX_OPTIONS_DELETE_ON_CLOSE, 0);
2568 printf("[10] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2573 /* This should delete the file. */
2574 if (!cli_close(cli1, fnum1)) {
2575 printf("[10] close failed (%s)\n", cli_errstr(cli1));
2580 /* This should fail.. */
2581 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
2583 printf("[10] open of %s succeeded should have been deleted on close !\n", fname);
2587 printf("tenth delete on close test succeeded.\n");
2588 printf("finished delete test\n");
2591 /* FIXME: This will crash if we aborted before cli2 got
2592 * intialized, because these functions don't handle
2593 * uninitialized connections. */
2595 cli_close(cli1, fnum1);
2596 cli_close(cli1, fnum2);
2597 cli_setatr(cli1, fname, 0, 0);
2598 cli_unlink(cli1, fname);
2600 if (!torture_close_connection(cli1)) {
2603 if (!torture_close_connection(cli2)) {
2611 print out server properties
2613 static BOOL run_properties(int dummy)
2615 struct cli_state *cli;
2616 BOOL correct = True;
2618 printf("starting properties test\n");
2622 if (!torture_open_connection(&cli)) {
2626 d_printf("Capabilities 0x%08x\n", cli->transport->negotiate.capabilities);
2628 if (!torture_close_connection(cli)) {
2637 /* FIRST_DESIRED_ACCESS 0xf019f */
2638 #define FIRST_DESIRED_ACCESS SA_RIGHT_FILE_READ_DATA|SA_RIGHT_FILE_WRITE_DATA|SA_RIGHT_FILE_APPEND_DATA|\
2639 SA_RIGHT_FILE_READ_EA| /* 0xf */ \
2640 SA_RIGHT_FILE_WRITE_EA|SA_RIGHT_FILE_READ_ATTRIBUTES| /* 0x90 */ \
2641 SA_RIGHT_FILE_WRITE_ATTRIBUTES| /* 0x100 */ \
2642 STD_RIGHT_DELETE_ACCESS|STD_RIGHT_READ_CONTROL_ACCESS|\
2643 STD_RIGHT_WRITE_DAC_ACCESS|STD_RIGHT_WRITE_OWNER_ACCESS /* 0xf0000 */
2644 /* SECOND_DESIRED_ACCESS 0xe0080 */
2645 #define SECOND_DESIRED_ACCESS SA_RIGHT_FILE_READ_ATTRIBUTES| /* 0x80 */ \
2646 STD_RIGHT_READ_CONTROL_ACCESS|STD_RIGHT_WRITE_DAC_ACCESS|\
2647 STD_RIGHT_WRITE_OWNER_ACCESS /* 0xe0000 */
2650 #define THIRD_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
2651 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
2652 SA_RIGHT_FILE_READ_DATA|\
2653 WRITE_OWNER_ACCESS /* */
2657 Test ntcreate calls made by xcopy
2659 static BOOL run_xcopy(int dummy)
2661 struct cli_state *cli1;
2662 const char *fname = "\\test.txt";
2663 BOOL correct = True;
2666 printf("starting xcopy test\n");
2668 if (!torture_open_connection(&cli1)) {
2672 fnum1 = cli_nt_create_full(cli1, fname, 0,
2673 FIRST_DESIRED_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
2674 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF,
2678 printf("First open failed - %s\n", cli_errstr(cli1));
2682 fnum2 = cli_nt_create_full(cli1, fname, 0,
2683 SECOND_DESIRED_ACCESS, 0,
2684 NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE|NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OPEN,
2687 printf("second open failed - %s\n", cli_errstr(cli1));
2691 if (!torture_close_connection(cli1)) {
2699 Test rename on files open with share delete and no share delete.
2701 static BOOL run_rename(int dummy)
2703 struct cli_state *cli1;
2704 const char *fname = "\\test.txt";
2705 const char *fname1 = "\\test1.txt";
2706 BOOL correct = True;
2709 printf("starting rename test\n");
2711 if (!torture_open_connection(&cli1)) {
2715 cli_unlink(cli1, fname);
2716 cli_unlink(cli1, fname1);
2717 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_RIGHTS_FILE_READ, FILE_ATTRIBUTE_NORMAL,
2718 NTCREATEX_SHARE_ACCESS_READ, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
2721 printf("First open failed - %s\n", cli_errstr(cli1));
2725 if (!cli_rename(cli1, fname, fname1)) {
2726 printf("First rename failed (this is correct) - %s\n", cli_errstr(cli1));
2728 printf("First rename succeeded - this should have failed !\n");
2732 if (!cli_close(cli1, fnum1)) {
2733 printf("close - 1 failed (%s)\n", cli_errstr(cli1));
2737 cli_unlink(cli1, fname);
2738 cli_unlink(cli1, fname1);
2739 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_RIGHTS_FILE_READ, FILE_ATTRIBUTE_NORMAL,
2741 NTCREATEX_SHARE_ACCESS_DELETE|NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
2743 NTCREATEX_SHARE_ACCESS_DELETE|NTCREATEX_SHARE_ACCESS_READ, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
2747 printf("Second open failed - %s\n", cli_errstr(cli1));
2751 if (!cli_rename(cli1, fname, fname1)) {
2752 printf("Second rename failed - this should have succeeded - %s\n", cli_errstr(cli1));
2755 printf("Second rename succeeded\n");
2758 if (!cli_close(cli1, fnum1)) {
2759 printf("close - 2 failed (%s)\n", cli_errstr(cli1));
2763 cli_unlink(cli1, fname);
2764 cli_unlink(cli1, fname1);
2766 fnum1 = cli_nt_create_full(cli1, fname, 0, STD_RIGHT_READ_CONTROL_ACCESS, FILE_ATTRIBUTE_NORMAL,
2767 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
2770 printf("Third open failed - %s\n", cli_errstr(cli1));
2779 fnum2 = cli_nt_create_full(cli1, fname, 0, DELETE_ACCESS, FILE_ATTRIBUTE_NORMAL,
2780 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
2783 printf("Fourth open failed - %s\n", cli_errstr(cli1));
2786 if (!cli_nt_delete_on_close(cli1, fnum2, True)) {
2787 printf("[8] setting delete_on_close on file failed !\n");
2791 if (!cli_close(cli1, fnum2)) {
2792 printf("close - 4 failed (%s)\n", cli_errstr(cli1));
2798 if (!cli_rename(cli1, fname, fname1)) {
2799 printf("Third rename failed - this should have succeeded - %s\n", cli_errstr(cli1));
2802 printf("Third rename succeeded\n");
2805 if (!cli_close(cli1, fnum1)) {
2806 printf("close - 3 failed (%s)\n", cli_errstr(cli1));
2810 cli_unlink(cli1, fname);
2811 cli_unlink(cli1, fname1);
2813 if (!torture_close_connection(cli1)) {
2820 static BOOL run_pipe_number(int dummy)
2822 struct cli_state *cli1;
2823 const char *pipe_name = "\\WKSSVC";
2827 printf("starting pipenumber test\n");
2828 if (!torture_open_connection(&cli1)) {
2833 fnum = cli_nt_create_full(cli1, pipe_name, 0, SA_RIGHT_FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
2834 NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE, NTCREATEX_DISP_OPEN_IF, 0, 0);
2837 printf("Open of pipe %s failed with error (%s)\n", pipe_name, cli_errstr(cli1));
2843 printf("pipe_number test - we can open %d %s pipes.\n", num_pipes, pipe_name );
2844 torture_close_connection(cli1);
2850 Test open mode returns on read-only files.
2852 static BOOL run_opentest(int dummy)
2854 static struct cli_state *cli1;
2855 static struct cli_state *cli2;
2856 const char *fname = "\\readonly.file";
2860 BOOL correct = True;
2864 printf("starting open test\n");
2866 if (!torture_open_connection(&cli1)) {
2870 cli_setatr(cli1, fname, 0, 0);
2871 cli_unlink(cli1, fname);
2873 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2875 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
2879 if (!cli_close(cli1, fnum1)) {
2880 printf("close2 failed (%s)\n", cli_errstr(cli1));
2884 if (!cli_setatr(cli1, fname, FILE_ATTRIBUTE_READONLY, 0)) {
2885 printf("cli_setatr failed (%s)\n", cli_errstr(cli1));
2886 CHECK_MAX_FAILURES(error_test1);
2890 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_WRITE);
2892 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
2893 CHECK_MAX_FAILURES(error_test1);
2897 /* This will fail - but the error should be ERRnoaccess, not ERRbadshare. */
2898 fnum2 = cli_open(cli1, fname, O_RDWR, DENY_ALL);
2900 if (check_error(__LINE__, cli1, ERRDOS, ERRnoaccess,
2901 NT_STATUS_ACCESS_DENIED)) {
2902 printf("correct error code ERRDOS/ERRnoaccess returned\n");
2905 printf("finished open test 1\n");
2907 cli_close(cli1, fnum1);
2909 /* Now try not readonly and ensure ERRbadshare is returned. */
2911 cli_setatr(cli1, fname, 0, 0);
2913 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_WRITE);
2915 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
2919 /* This will fail - but the error should be ERRshare. */
2920 fnum2 = cli_open(cli1, fname, O_RDWR, DENY_ALL);
2922 if (check_error(__LINE__, cli1, ERRDOS, ERRbadshare,
2923 NT_STATUS_SHARING_VIOLATION)) {
2924 printf("correct error code ERRDOS/ERRbadshare returned\n");
2927 if (!cli_close(cli1, fnum1)) {
2928 printf("close2 failed (%s)\n", cli_errstr(cli1));
2932 cli_unlink(cli1, fname);
2934 printf("finished open test 2\n");
2936 /* Test truncate open disposition on file opened for read. */
2938 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2940 printf("(3) open (1) of %s failed (%s)\n", fname, cli_errstr(cli1));
2944 /* write 20 bytes. */
2946 memset(buf, '\0', 20);
2948 if (cli_write(cli1, fnum1, 0, buf, 0, 20) != 20) {
2949 printf("write failed (%s)\n", cli_errstr(cli1));
2953 if (!cli_close(cli1, fnum1)) {
2954 printf("(3) close1 failed (%s)\n", cli_errstr(cli1));
2958 /* Ensure size == 20. */
2959 if (!cli_getatr(cli1, fname, NULL, &fsize, NULL)) {
2960 printf("(3) getatr failed (%s)\n", cli_errstr(cli1));
2961 CHECK_MAX_FAILURES(error_test3);
2966 printf("(3) file size != 20\n");
2967 CHECK_MAX_FAILURES(error_test3);
2971 /* Now test if we can truncate a file opened for readonly. */
2973 fnum1 = cli_open(cli1, fname, O_RDONLY|O_TRUNC, DENY_NONE);
2975 printf("(3) open (2) of %s failed (%s)\n", fname, cli_errstr(cli1));
2976 CHECK_MAX_FAILURES(error_test3);
2980 if (!cli_close(cli1, fnum1)) {
2981 printf("close2 failed (%s)\n", cli_errstr(cli1));
2985 /* Ensure size == 0. */
2986 if (!cli_getatr(cli1, fname, NULL, &fsize, NULL)) {
2987 printf("(3) getatr failed (%s)\n", cli_errstr(cli1));
2988 CHECK_MAX_FAILURES(error_test3);
2993 printf("(3) file size != 0\n");
2994 CHECK_MAX_FAILURES(error_test3);
2997 printf("finished open test 3\n");
2999 cli_unlink(cli1, fname);
3002 printf("testing ctemp\n");
3003 fnum1 = cli_ctemp(cli1, "\\", &tmp_path);
3005 printf("ctemp failed (%s)\n", cli_errstr(cli1));
3006 CHECK_MAX_FAILURES(error_test4);
3009 printf("ctemp gave path %s\n", tmp_path);
3010 if (!cli_close(cli1, fnum1)) {
3011 printf("close of temp failed (%s)\n", cli_errstr(cli1));
3013 if (!cli_unlink(cli1, tmp_path)) {
3014 printf("unlink of temp failed (%s)\n", cli_errstr(cli1));
3017 /* Test the non-io opens... */
3019 if (!torture_open_connection(&cli2)) {
3023 cli_setatr(cli2, fname, 0, 0);
3024 cli_unlink(cli2, fname);
3026 printf("TEST #1 testing 2 non-io opens (no delete)\n");
3028 fnum1 = cli_nt_create_full(cli1, fname, 0, SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3029 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
3032 printf("test 1 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3033 CHECK_MAX_FAILURES(error_test10);
3037 fnum2 = cli_nt_create_full(cli2, fname, 0, SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3038 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OPEN_IF, 0, 0);
3040 printf("test 1 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3041 CHECK_MAX_FAILURES(error_test10);
3045 if (!cli_close(cli1, fnum1)) {
3046 printf("test 1 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3049 if (!cli_close(cli2, fnum2)) {
3050 printf("test 1 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3054 printf("non-io open test #1 passed.\n");
3056 cli_unlink(cli1, fname);
3058 printf("TEST #2 testing 2 non-io opens (first with delete)\n");
3060 fnum1 = cli_nt_create_full(cli1, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3061 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
3064 printf("test 2 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3065 CHECK_MAX_FAILURES(error_test20);
3069 fnum2 = cli_nt_create_full(cli2, fname, 0, SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3070 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OPEN_IF, 0, 0);
3073 printf("test 2 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3074 CHECK_MAX_FAILURES(error_test20);
3078 if (!cli_close(cli1, fnum1)) {
3079 printf("test 1 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3082 if (!cli_close(cli2, fnum2)) {
3083 printf("test 1 close 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
3087 printf("non-io open test #2 passed.\n");
3089 cli_unlink(cli1, fname);
3091 printf("TEST #3 testing 2 non-io opens (second with delete)\n");
3093 fnum1 = cli_nt_create_full(cli1, fname, 0, SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3094 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
3097 printf("test 3 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3098 CHECK_MAX_FAILURES(error_test30);
3102 fnum2 = cli_nt_create_full(cli2, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3103 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OPEN_IF, 0, 0);
3106 printf("test 3 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3107 CHECK_MAX_FAILURES(error_test30);
3111 if (!cli_close(cli1, fnum1)) {
3112 printf("test 3 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3115 if (!cli_close(cli2, fnum2)) {
3116 printf("test 3 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3120 printf("non-io open test #3 passed.\n");
3122 cli_unlink(cli1, fname);
3124 printf("TEST #4 testing 2 non-io opens (both with delete)\n");
3126 fnum1 = cli_nt_create_full(cli1, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3127 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
3130 printf("test 4 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3131 CHECK_MAX_FAILURES(error_test40);
3135 fnum2 = cli_nt_create_full(cli2, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3136 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OPEN_IF, 0, 0);
3139 printf("test 4 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, cli_errstr(cli2));
3140 CHECK_MAX_FAILURES(error_test40);
3144 printf("test 4 open 2 of %s gave %s (correct error should be %s)\n", fname, cli_errstr(cli2), "sharing violation");
3146 if (!cli_close(cli1, fnum1)) {
3147 printf("test 4 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3151 printf("non-io open test #4 passed.\n");
3153 cli_unlink(cli1, fname);
3155 printf("TEST #5 testing 2 non-io opens (both with delete - both with file share delete)\n");
3157 fnum1 = cli_nt_create_full(cli1, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3158 NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
3161 printf("test 5 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3162 CHECK_MAX_FAILURES(error_test50);
3166 fnum2 = cli_nt_create_full(cli2, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3167 NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OPEN_IF, 0, 0);
3170 printf("test 5 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3171 CHECK_MAX_FAILURES(error_test50);
3175 if (!cli_close(cli1, fnum1)) {
3176 printf("test 5 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3180 if (!cli_close(cli2, fnum2)) {
3181 printf("test 5 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3185 printf("non-io open test #5 passed.\n");
3187 printf("TEST #6 testing 1 non-io open, one io open\n");
3189 cli_unlink(cli1, fname);
3191 fnum1 = cli_nt_create_full(cli1, fname, 0, SA_RIGHT_FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
3192 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
3195 printf("test 6 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3196 CHECK_MAX_FAILURES(error_test60);
3200 fnum2 = cli_nt_create_full(cli2, fname, 0, SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3201 NTCREATEX_SHARE_ACCESS_READ, NTCREATEX_DISP_OPEN_IF, 0, 0);
3204 printf("test 6 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3205 CHECK_MAX_FAILURES(error_test60);
3209 if (!cli_close(cli1, fnum1)) {
3210 printf("test 6 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3214 if (!cli_close(cli2, fnum2)) {
3215 printf("test 6 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3219 printf("non-io open test #6 passed.\n");
3221 printf("TEST #7 testing 1 non-io open, one io open with delete\n");
3223 cli_unlink(cli1, fname);
3225 fnum1 = cli_nt_create_full(cli1, fname, 0, SA_RIGHT_FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
3226 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
3229 printf("test 7 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3230 CHECK_MAX_FAILURES(error_test70);
3234 fnum2 = cli_nt_create_full(cli2, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3235 NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OPEN_IF, 0, 0);
3238 printf("test 7 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, cli_errstr(cli2));
3239 CHECK_MAX_FAILURES(error_test70);
3243 printf("test 7 open 2 of %s gave %s (correct error should be %s)\n", fname, cli_errstr(cli2), "sharing violation");
3245 if (!cli_close(cli1, fnum1)) {
3246 printf("test 7 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3250 printf("non-io open test #7 passed.\n");
3252 cli_unlink(cli1, fname);
3254 if (!torture_close_connection(cli1)) {
3257 if (!torture_close_connection(cli2)) {
3265 static uint32 open_attrs_table[] = {
3266 FILE_ATTRIBUTE_NORMAL,
3267 FILE_ATTRIBUTE_ARCHIVE,
3268 FILE_ATTRIBUTE_READONLY,
3269 FILE_ATTRIBUTE_HIDDEN,
3270 FILE_ATTRIBUTE_SYSTEM,
3272 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY,
3273 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN,
3274 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM,
3275 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN,
3276 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM,
3277 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM,
3279 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN,
3280 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM,
3281 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM,
3282 FILE_ATTRIBUTE_HIDDEN,FILE_ATTRIBUTE_SYSTEM,
3285 struct trunc_open_results {
3292 static struct trunc_open_results attr_results[] = {
3293 { 0, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE },
3294 { 1, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE },
3295 { 2, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_READONLY, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY },
3296 { 16, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE },
3297 { 17, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE },
3298 { 18, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_READONLY, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY },
3299 { 51, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
3300 { 54, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
3301 { 56, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN },
3302 { 68, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
3303 { 71, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
3304 { 73, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM },
3305 { 99, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN,FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
3306 { 102, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
3307 { 104, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN },
3308 { 116, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
3309 { 119, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
3310 { 121, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM },
3311 { 170, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM|FILE_ATTRIBUTE_HIDDEN },
3312 { 173, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM },
3313 { 227, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
3314 { 230, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
3315 { 232, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN },
3316 { 244, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
3317 { 247, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
3318 { 249, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM }
3321 static BOOL run_openattrtest(int dummy)
3323 struct cli_state *cli1;
3324 const char *fname = "\\openattr.file";
3326 BOOL correct = True;
3328 unsigned int i, j, k, l;
3331 printf("starting open attr test\n");
3333 if (!torture_open_connection(&cli1)) {
3337 for (k = 0, i = 0; i < sizeof(open_attrs_table)/sizeof(uint32); i++) {
3338 cli_setatr(cli1, fname, 0, 0);
3339 cli_unlink(cli1, fname);
3340 fnum1 = cli_nt_create_full(cli1, fname, 0, SA_RIGHT_FILE_WRITE_DATA, open_attrs_table[i],
3341 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
3344 printf("open %d (1) of %s failed (%s)\n", i, fname, cli_errstr(cli1));
3348 if (!cli_close(cli1, fnum1)) {
3349 printf("close %d (1) of %s failed (%s)\n", i, fname, cli_errstr(cli1));
3353 for (j = 0; j < ARRAY_SIZE(open_attrs_table); j++) {
3354 fnum1 = cli_nt_create_full(cli1, fname, 0,
3355 SA_RIGHT_FILE_READ_DATA|SA_RIGHT_FILE_WRITE_DATA,
3356 open_attrs_table[j],
3357 NTCREATEX_SHARE_ACCESS_NONE,
3358 NTCREATEX_DISP_OVERWRITE, 0, 0);
3361 for (l = 0; l < ARRAY_SIZE(attr_results); l++) {
3362 if (attr_results[l].num == k) {
3363 printf("[%d] trunc open 0x%x -> 0x%x of %s failed - should have succeeded !(0x%x:%s)\n",
3364 k, open_attrs_table[i],
3365 open_attrs_table[j],
3366 fname, NT_STATUS_V(cli_nt_error(cli1)), cli_errstr(cli1));
3368 CHECK_MAX_FAILURES(error_exit);
3371 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_ACCESS_DENIED)) {
3372 printf("[%d] trunc open 0x%x -> 0x%x failed with wrong error code %s\n",
3373 k, open_attrs_table[i], open_attrs_table[j],
3376 CHECK_MAX_FAILURES(error_exit);
3379 printf("[%d] trunc open 0x%x -> 0x%x failed\n", k, open_attrs_table[i], open_attrs_table[j]);
3385 if (!cli_close(cli1, fnum1)) {
3386 printf("close %d (2) of %s failed (%s)\n", j, fname, cli_errstr(cli1));
3390 if (!cli_getatr(cli1, fname, &attr, NULL, NULL)) {
3391 printf("getatr(2) failed (%s)\n", cli_errstr(cli1));
3396 printf("[%d] getatr check [0x%x] trunc [0x%x] got attr 0x%x\n",
3397 k, open_attrs_table[i], open_attrs_table[j], attr );
3400 for (l = 0; l < ARRAY_SIZE(attr_results); l++) {
3401 if (attr_results[l].num == k) {
3402 if (attr != attr_results[l].result_attr ||
3403 open_attrs_table[i] != attr_results[l].init_attr ||
3404 open_attrs_table[j] != attr_results[l].trunc_attr) {
3405 printf("[%d] getatr check failed. [0x%x] trunc [0x%x] got attr 0x%x, should be 0x%x\n",
3406 k, open_attrs_table[i],
3407 open_attrs_table[j],
3409 attr_results[l].result_attr);
3411 CHECK_MAX_FAILURES(error_exit);
3420 cli_setatr(cli1, fname, 0, 0);
3421 cli_unlink(cli1, fname);
3423 printf("open attr test %s.\n", correct ? "passed" : "failed");
3425 if (!torture_close_connection(cli1)) {
3431 static void list_fn(file_info *finfo, const char *name, void *state)
3437 test directory listing speed
3439 static BOOL run_dirtest(int dummy)
3442 struct cli_state *cli;
3445 BOOL correct = True;
3447 printf("starting directory test\n");
3449 if (!torture_open_connection(&cli)) {
3453 printf("Creating %d random filenames\n", torture_numops);
3456 for (i=0;i<torture_numops;i++) {
3458 asprintf(&fname, "\\%x", (int)random());
3459 fnum = cli_open(cli, fname, O_RDWR|O_CREAT, DENY_NONE);
3461 fprintf(stderr,"Failed to open %s\n", fname);
3464 cli_close(cli, fnum);
3470 printf("Matched %d\n", cli_list(cli, "a*.*", 0, list_fn, NULL));
3471 printf("Matched %d\n", cli_list(cli, "b*.*", 0, list_fn, NULL));
3472 printf("Matched %d\n", cli_list(cli, "xyzabc", 0, list_fn, NULL));
3474 printf("dirtest core %g seconds\n", end_timer() - t1);
3477 for (i=0;i<torture_numops;i++) {
3479 asprintf(&fname, "\\%x", (int)random());
3480 cli_unlink(cli, fname);
3484 if (!torture_close_connection(cli)) {
3488 printf("finished dirtest\n");
3493 static void del_fn(file_info *finfo, const char *mask, void *state)
3495 struct cli_state *pcli = (struct cli_state *)state;
3497 asprintf(&fname, "\\LISTDIR\\%s", finfo->name);
3499 if (strcmp(finfo->name, ".") == 0 || strcmp(finfo->name, "..") == 0)
3502 if (finfo->mode & FILE_ATTRIBUTE_DIRECTORY) {
3503 if (!cli_rmdir(pcli, fname))
3504 printf("del_fn: failed to rmdir %s, error=%s\n", fname, cli_errstr(pcli) );
3506 if (!cli_unlink(pcli, fname))
3507 printf("del_fn: failed to unlink %s, error=%s\n", fname, cli_errstr(pcli) );
3514 sees what IOCTLs are supported
3516 BOOL torture_ioctl_test(int dummy)
3518 struct cli_state *cli;
3519 uint16 device, function;
3521 const char *fname = "\\ioctl.dat";
3524 struct smb_ioctl parms;
3525 TALLOC_CTX *mem_ctx;
3527 if (!torture_open_connection(&cli)) {
3531 mem_ctx = talloc_init("ioctl_test");
3533 printf("starting ioctl test\n");
3535 cli_unlink(cli, fname);
3537 fnum = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
3539 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
3543 parms.in.request = IOCTL_QUERY_JOB_INFO;
3544 status = smb_raw_ioctl(cli->tree, mem_ctx, &parms);
3545 printf("ioctl job info: %s\n", cli_errstr(cli));
3547 for (device=0;device<0x100;device++) {
3548 printf("testing device=0x%x\n", device);
3549 for (function=0;function<0x100;function++) {
3550 parms.in.request = (device << 16) | function;
3551 status = smb_raw_ioctl(cli->tree, mem_ctx, &parms);
3553 if (NT_STATUS_IS_OK(status)) {
3554 printf("ioctl device=0x%x function=0x%x OK : %d bytes\n",
3555 device, function, blob.length);
3556 data_blob_free(&parms.out.blob);
3561 if (!torture_close_connection(cli)) {
3570 tries variants of chkpath
3572 BOOL torture_chkpath_test(int dummy)
3574 struct cli_state *cli;
3578 if (!torture_open_connection(&cli)) {
3582 printf("starting chkpath test\n");
3584 printf("Testing valid and invalid paths\n");
3586 /* cleanup from an old run */
3587 cli_rmdir(cli, "\\chkpath.dir\\dir2");
3588 cli_unlink(cli, "\\chkpath.dir\\*");
3589 cli_rmdir(cli, "\\chkpath.dir");
3591 if (!cli_mkdir(cli, "\\chkpath.dir")) {
3592 printf("mkdir1 failed : %s\n", cli_errstr(cli));
3596 if (!cli_mkdir(cli, "\\chkpath.dir\\dir2")) {
3597 printf("mkdir2 failed : %s\n", cli_errstr(cli));
3601 fnum = cli_open(cli, "\\chkpath.dir\\foo.txt", O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
3603 printf("open1 failed (%s)\n", cli_errstr(cli));
3606 cli_close(cli, fnum);
3608 if (!cli_chkpath(cli, "\\chkpath.dir")) {
3609 printf("chkpath1 failed: %s\n", cli_errstr(cli));
3613 if (!cli_chkpath(cli, "\\chkpath.dir\\dir2")) {
3614 printf("chkpath2 failed: %s\n", cli_errstr(cli));
3618 if (!cli_chkpath(cli, "\\chkpath.dir\\foo.txt")) {
3619 ret = check_error(__LINE__, cli, ERRDOS, ERRbadpath,
3620 NT_STATUS_NOT_A_DIRECTORY);
3622 printf("* chkpath on a file should fail\n");
3626 if (!cli_chkpath(cli, "\\chkpath.dir\\bar.txt")) {
3627 ret = check_error(__LINE__, cli, ERRDOS, ERRbadfile,
3628 NT_STATUS_OBJECT_NAME_NOT_FOUND);
3630 printf("* chkpath on a non existent file should fail\n");
3634 if (!cli_chkpath(cli, "\\chkpath.dir\\dirxx\\bar.txt")) {
3635 ret = check_error(__LINE__, cli, ERRDOS, ERRbadpath,
3636 NT_STATUS_OBJECT_PATH_NOT_FOUND);
3638 printf("* chkpath on a non existent component should fail\n");
3642 cli_rmdir(cli, "\\chkpath.dir\\dir2");
3643 cli_unlink(cli, "\\chkpath.dir\\*");
3644 cli_rmdir(cli, "\\chkpath.dir");
3646 if (!torture_close_connection(cli)) {
3653 static BOOL run_dirtest1(int dummy)
3656 struct cli_state *cli;
3658 BOOL correct = True;
3660 printf("starting directory test\n");
3662 if (!torture_open_connection(&cli)) {
3666 cli_list(cli, "\\LISTDIR\\*", 0, del_fn, cli);
3667 cli_list(cli, "\\LISTDIR\\*", FILE_ATTRIBUTE_DIRECTORY, del_fn, cli);
3668 if (cli_deltree(cli, "\\LISTDIR") == -1) {
3669 fprintf(stderr,"Failed to deltree %s, error=%s\n", "\\LISTDIR", cli_errstr(cli));
3672 if (!cli_mkdir(cli, "\\LISTDIR")) {
3673 fprintf(stderr,"Failed to mkdir %s, error=%s\n", "\\LISTDIR", cli_errstr(cli));
3677 printf("Creating %d files\n", torture_entries);
3679 /* Create torture_entries files and torture_entries directories. */
3680 for (i=0;i<torture_entries;i++) {
3682 asprintf(&fname, "\\LISTDIR\\f%d", i);
3683 fnum = cli_nt_create_full(cli, fname, 0, GENERIC_RIGHTS_FILE_ALL_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
3684 NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
3686 fprintf(stderr,"Failed to open %s, error=%s\n", fname, cli_errstr(cli));
3690 cli_close(cli, fnum);
3692 for (i=0;i<torture_entries;i++) {
3694 asprintf(&fname, "\\LISTDIR\\d%d", i);
3695 if (!cli_mkdir(cli, fname)) {
3696 fprintf(stderr,"Failed to open %s, error=%s\n", fname, cli_errstr(cli));
3702 /* Now ensure that doing an old list sees both files and directories. */
3703 num_seen = cli_list_old(cli, "\\LISTDIR\\*", FILE_ATTRIBUTE_DIRECTORY, list_fn, NULL);
3704 printf("num_seen = %d\n", num_seen );
3705 /* We should see (torture_entries) each of files & directories + . and .. */
3706 if (num_seen != (2*torture_entries)+2) {
3708 fprintf(stderr,"entry count mismatch, should be %d, was %d\n",
3709 (2*torture_entries)+2, num_seen);
3713 /* Ensure if we have the "must have" bits we only see the
3716 num_seen = cli_list_old(cli, "\\LISTDIR\\*", (FILE_ATTRIBUTE_DIRECTORY<<8)|FILE_ATTRIBUTE_DIRECTORY, list_fn, NULL);
3717 printf("num_seen = %d\n", num_seen );
3718 if (num_seen != torture_entries+2) {
3720 fprintf(stderr,"entry count mismatch, should be %d, was %d\n",
3721 torture_entries+2, num_seen);
3724 num_seen = cli_list_old(cli, "\\LISTDIR\\*", (FILE_ATTRIBUTE_ARCHIVE<<8)|FILE_ATTRIBUTE_DIRECTORY, list_fn, NULL);
3725 printf("num_seen = %d\n", num_seen );
3726 if (num_seen != torture_entries) {
3728 fprintf(stderr,"entry count mismatch, should be %d, was %d\n",
3729 torture_entries, num_seen);
3732 /* Delete everything. */
3733 cli_list(cli, "\\LISTDIR\\*", 0, del_fn, cli);
3734 cli_list(cli, "\\LISTDIR\\*", FILE_ATTRIBUTE_DIRECTORY, del_fn, cli);
3735 cli_rmdir(cli, "\\LISTDIR");
3738 printf("Matched %d\n", cli_list(cli, "a*.*", 0, list_fn, NULL));
3739 printf("Matched %d\n", cli_list(cli, "b*.*", 0, list_fn, NULL));
3740 printf("Matched %d\n", cli_list(cli, "xyzabc", 0, list_fn, NULL));
3743 if (!torture_close_connection(cli)) {
3747 printf("finished dirtest1\n");
3754 simple test harness for playing with deny modes
3756 static BOOL run_deny3test(int dummy)
3758 struct cli_state *cli1, *cli2;
3762 printf("starting deny3 test\n");
3764 printf("Testing simple deny modes\n");
3766 if (!torture_open_connection(&cli1)) {
3769 if (!torture_open_connection(&cli2)) {
3773 fname = "\\deny_dos1.dat";
3775 cli_unlink(cli1, fname);
3776 fnum1 = cli_open(cli1, fname, O_CREAT|O_TRUNC|O_WRONLY, DENY_DOS);
3777 fnum2 = cli_open(cli1, fname, O_CREAT|O_TRUNC|O_WRONLY, DENY_DOS);
3778 if (fnum1 != -1) cli_close(cli1, fnum1);
3779 if (fnum2 != -1) cli_close(cli1, fnum2);
3780 cli_unlink(cli1, fname);
3781 printf("fnum1=%d fnum2=%d\n", fnum1, fnum2);
3784 fname = "\\deny_dos2.dat";
3786 cli_unlink(cli1, fname);
3787 fnum1 = cli_open(cli1, fname, O_CREAT|O_TRUNC|O_WRONLY, DENY_DOS);
3788 fnum2 = cli_open(cli2, fname, O_CREAT|O_TRUNC|O_WRONLY, DENY_DOS);
3789 if (fnum1 != -1) cli_close(cli1, fnum1);
3790 if (fnum2 != -1) cli_close(cli2, fnum2);
3791 cli_unlink(cli1, fname);
3792 printf("fnum1=%d fnum2=%d\n", fnum1, fnum2);
3795 torture_close_connection(cli1);
3796 torture_close_connection(cli2);
3801 static void sigcont(void)
3805 static double create_procs(BOOL (*fn)(int), BOOL *result)
3808 volatile pid_t *child_status;
3809 volatile BOOL *child_status_out;
3812 double start_time_limit = 10 + (nprocs * 1.5);
3816 signal(SIGCONT, sigcont);
3818 child_status = (volatile pid_t *)shm_setup(sizeof(pid_t)*nprocs);
3819 if (!child_status) {
3820 printf("Failed to setup shared memory\n");
3824 child_status_out = (volatile BOOL *)shm_setup(sizeof(BOOL)*nprocs);
3825 if (!child_status_out) {
3826 printf("Failed to setup result status shared memory\n");
3830 for (i = 0; i < nprocs; i++) {
3831 child_status[i] = 0;
3832 child_status_out[i] = True;
3837 for (i=0;i<nprocs;i++) {
3841 pid_t mypid = getpid();
3842 sys_srandom(((int)mypid) ^ ((int)time(NULL)));
3844 asprintf(&myname, "CLIENT%d", i);
3845 lp_set_cmdline("netbios name", myname);
3849 if (torture_open_connection(¤t_cli)) break;
3851 printf("pid %d failed to start\n", (int)getpid());
3857 child_status[i] = getpid();
3861 if (child_status[i]) {
3862 printf("Child %d failed to start!\n", i);
3863 child_status_out[i] = 1;
3867 child_status_out[i] = fn(i);
3874 for (i=0;i<nprocs;i++) {
3875 if (child_status[i]) synccount++;
3877 if (synccount == nprocs) break;
3879 } while (end_timer() < start_time_limit);
3881 if (synccount != nprocs) {
3882 printf("FAILED TO START %d CLIENTS (started %d)\n", nprocs, synccount);
3887 printf("Starting %d clients\n", nprocs);
3889 /* start the client load */
3891 for (i=0;i<nprocs;i++) {
3892 child_status[i] = 0;
3896 printf("%d clients started\n", nprocs);
3898 for (i=0;i<nprocs;i++) {
3900 while ((ret=waitpid(0, &status, 0)) == -1 && errno == EINTR) /* noop */ ;
3901 if (ret == -1 || WEXITSTATUS(status) != 0) {
3908 for (i=0;i<nprocs;i++) {
3909 if (!child_status_out[i]) {
3916 #define FLAG_MULTIPROC 1
3923 {"FDPASS", run_fdpasstest, 0},
3924 {"LOCK1", run_locktest1, 0},
3925 {"LOCK2", run_locktest2, 0},
3926 {"LOCK3", run_locktest3, 0},
3927 {"LOCK4", run_locktest4, 0},
3928 {"LOCK5", run_locktest5, 0},
3929 {"LOCK6", run_locktest6, 0},
3930 {"LOCK7", run_locktest7, 0},
3931 {"UNLINK", run_unlinktest, 0},
3932 {"ATTR", run_attrtest, 0},
3933 {"TRANS2", run_trans2test, 0},
3934 {"MAXFID", run_maxfidtest, FLAG_MULTIPROC},
3935 {"TORTURE",run_torture, FLAG_MULTIPROC},
3936 {"NEGNOWAIT", run_negprot_nowait, 0},
3937 {"NBENCH", run_nbench, 0},
3938 {"DIR", run_dirtest, 0},
3939 {"DIR1", run_dirtest1, 0},
3940 {"DENY1", torture_denytest1, 0},
3941 {"DENY2", torture_denytest2, 0},
3942 {"TCON", run_tcon_test, 0},
3943 {"TCONDEV", run_tcon_devtype_test, 0},
3945 {"DFSBASIC", torture_dfs_basic, 0},
3946 {"DFSRENAME", torture_dfs_rename, 0},
3947 {"DFSRANDOM", torture_dfs_random, 0},
3949 {"RW1", run_readwritetest, 0},
3950 {"RW2", run_readwritemulti, FLAG_MULTIPROC},
3951 {"OPEN", run_opentest, 0},
3952 {"DENY3", run_deny3test, 0},
3954 {"OPENATTR", run_openattrtest, 0},
3956 {"XCOPY", run_xcopy, 0},
3957 {"RENAME", run_rename, 0},
3958 {"DELETE", run_deletetest, 0},
3959 {"PROPERTIES", run_properties, 0},
3960 {"MANGLE", torture_mangle, 0},
3961 {"UTABLE", torture_utable, 0},
3962 {"CASETABLE", torture_casetable, 0},
3963 {"PIPE_NUMBER", run_pipe_number, 0},
3964 {"IOCTL", torture_ioctl_test, 0},
3965 {"CHKPATH", torture_chkpath_test, 0},
3966 {"RAW-QFSINFO", torture_raw_qfsinfo, 0},
3967 {"RAW-QFILEINFO", torture_raw_qfileinfo, 0},
3968 {"RAW-SFILEINFO", torture_raw_sfileinfo, 0},
3969 {"RAW-SFILEINFO-BUG", torture_raw_sfileinfo_bug, 0},
3970 {"RAW-SEARCH", torture_raw_search, 0},
3971 {"RAW-CLOSE", torture_raw_close, 0},
3972 {"RAW-OPEN", torture_raw_open, 0},
3973 {"RAW-MKDIR", torture_raw_mkdir, 0},
3974 {"RAW-OPLOCK", torture_raw_oplock, 0},
3975 {"RAW-NOTIFY", torture_raw_notify, 0},
3976 {"RAW-MUX", torture_raw_mux, 0},
3977 {"RAW-IOCTL", torture_raw_ioctl, 0},
3978 {"RAW-CHKPATH", torture_raw_chkpath, 0},
3979 {"RAW-UNLINK", torture_raw_unlink, 0},
3980 {"RAW-READ", torture_raw_read, 0},
3981 {"RAW-WRITE", torture_raw_write, 0},
3982 {"RAW-LOCK", torture_raw_lock, 0},
3983 {"RAW-CONTEXT", torture_raw_context, 0},
3984 {"RAW-RENAME", torture_raw_rename, 0},
3985 {"RAW-SEEK", torture_raw_seek, 0},
3986 {"SCAN-TRANS2", torture_trans2_scan, 0},
3987 {"SCAN-NTTRANS", torture_nttrans_scan, 0},
3988 {"SCAN-ALIASES", torture_trans2_aliases, 0},
3989 {"SCAN-SMB", torture_smb_scan, 0},
3990 {"RPC-LSA", torture_rpc_lsa, 0},
3991 {"RPC-ECHO", torture_rpc_echo, 0},
3992 {"RPC-DFS", torture_rpc_dfs, 0},
3993 {"RPC-SPOOLSS", torture_rpc_spoolss, 0},
3994 {"RPC-SAMR", torture_rpc_samr, 0},
3995 {"RPC-WKSSVC", torture_rpc_wkssvc, 0},
4000 /****************************************************************************
4001 run a specified test or "ALL"
4002 ****************************************************************************/
4003 static BOOL run_test(const char *name)
4007 BOOL matched = False;
4009 if (strequal(name,"ALL")) {
4010 for (i=0;torture_ops[i].name;i++) {
4011 if (!run_test(torture_ops[i].name)) {
4018 for (i=0;torture_ops[i].name;i++) {
4019 asprintf(&randomfname, "\\XX%x",
4020 (unsigned)random());
4022 if (gen_fnmatch(name, torture_ops[i].name) == 0) {
4025 printf("Running %s\n", torture_ops[i].name);
4026 if (torture_ops[i].flags & FLAG_MULTIPROC) {
4028 t = create_procs(torture_ops[i].fn, &result);
4031 printf("TEST %s FAILED!\n", torture_ops[i].name);
4036 if (!torture_ops[i].fn(0)) {
4038 printf("TEST %s FAILED!\n", torture_ops[i].name);
4042 printf("%s took %g secs\n\n", torture_ops[i].name, t);
4047 printf("Unknown torture operation '%s'\n", name);
4055 parse a username%password
4057 static void parse_user(const char *user)
4059 char *username, *password, *p;
4061 username = strdup(user);
4062 p = strchr_m(username,'%');
4065 password = strdup(p+1);
4068 lp_set_cmdline("torture:username", username);
4069 lp_set_cmdline("torture:password", password);
4073 static void usage(void)
4077 printf("Usage: smbtorture //server/share <options> TEST1 TEST2 ...\n");
4079 printf("\t-d debuglevel\n");
4080 printf("\t-U user%%pass\n");
4081 printf("\t-k use kerberos\n");
4082 printf("\t-N numprocs\n");
4083 printf("\t-n my_netbios_name\n");
4084 printf("\t-W workgroup\n");
4085 printf("\t-o num_operations\n");
4086 printf("\t-e num files(entries)\n");
4087 printf("\t-O socket_options\n");
4088 printf("\t-m maximum protocol\n");
4089 printf("\t-L use oplocks\n");
4090 printf("\t-c CLIENT.TXT specify client load file for NBENCH\n");
4091 printf("\t-A showall\n");
4092 printf("\t-p port\n");
4093 printf("\t-s seed\n");
4094 printf("\t-f max failures\n");
4095 printf("\t-b bypass I/O (NBENCH)\n");
4098 printf("tests are:");
4099 for (i=0;torture_ops[i].name;i++) {
4100 printf(" %s", torture_ops[i].name);
4104 printf("default test is ALL\n");
4109 /****************************************************************************
4111 ****************************************************************************/
4112 int main(int argc,char *argv[])
4116 BOOL correct = True;
4117 char *host, *share, *username;
4119 setup_logging("smbtorture", DEBUG_STDOUT);
4121 #ifdef HAVE_SETBUFFER
4122 setbuffer(stdout, NULL, 0);
4125 lp_load(dyn_CONFIGFILE,True,False,False);
4132 for(p = argv[1]; *p; p++)
4136 if (strncmp(argv[1], "//", 2)) {
4140 host = strdup(&argv[1][2]);
4141 p = strchr_m(&host[2],'/');
4146 share = strdup(p+1);
4148 if (getenv("LOGNAME")) {
4149 username = strdup(getenv("LOGNAME"));
4152 lp_set_cmdline("torture:host", host);
4153 lp_set_cmdline("torture:share", share);
4154 lp_set_cmdline("torture:username", username);
4155 lp_set_cmdline("torture:password", "");
4160 srandom(time(NULL));
4162 while ((opt = getopt(argc, argv, "p:hW:U:n:N:O:o:e:m:Ld:Ac:ks:f:s:")) != EOF) {
4165 lp_set_cmdline("smb ports", optarg);
4168 lp_set_cmdline("workgroup", optarg);
4171 lp_set_cmdline("protocol", optarg);
4174 lp_set_cmdline("netbios name", optarg);
4177 lp_set_cmdline("debug level", optarg);
4178 setup_logging(NULL, DEBUG_STDOUT);
4181 lp_set_cmdline("socket options", optarg);
4184 srandom(atoi(optarg));
4187 nprocs = atoi(optarg);
4190 torture_numops = atoi(optarg);
4193 torture_entries = atoi(optarg);
4199 torture_showall = True;
4202 client_txt = optarg;
4206 use_kerberos = True;
4208 d_printf("No kerberos support compiled in\n");
4216 torture_failures = atoi(optarg);
4220 printf("Unknown option %c (%d)\n", (char)opt, opt);
4225 printf("host=%s share=%s user=%s myname=%s\n",
4226 host, share, lp_parm_string(-1, "torture", "username"),
4229 if (argc == optind) {
4230 printf("You must specify a test to run, or 'ALL'\n");
4232 for (i=optind;i<argc;i++) {
4233 if (!run_test(argv[i])) {