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 BOOL use_oplocks;
30 static BOOL use_level_II_oplocks;
31 static const char *client_txt = "client_oplocks.txt";
32 static BOOL use_kerberos;
34 BOOL torture_showall = False;
36 static double create_procs(BOOL (*fn)(int), BOOL *result);
38 #define CHECK_MAX_FAILURES(label) do { if (++failures >= torture_failures) goto label; } while (0)
40 static struct cli_state *open_nbt_connection(void)
42 struct nmb_name called, calling;
44 struct cli_state *cli;
45 char *host = lp_parm_string(-1, "torture", "host");
47 make_nmb_name(&calling, lp_netbios_name(), 0x0);
48 make_nmb_name(&called , host, 0x20);
52 cli = cli_state_init();
54 printf("Failed initialize cli_struct to connect with %s\n", host);
58 if (!cli_socket_connect(cli, host, &ip)) {
59 printf("Failed to connect with %s\n", host);
63 cli->transport->socket->timeout = 120000; /* set a really long timeout (2 minutes) */
65 if (!cli_transport_establish(cli, &calling, &called)) {
67 * Well, that failed, try *SMBSERVER ...
68 * However, we must reconnect as well ...
70 if (!cli_socket_connect(cli, host, &ip)) {
71 printf("Failed to connect with %s\n", host);
75 make_nmb_name(&called, "*SMBSERVER", 0x20);
76 if (!cli_transport_establish(cli, &calling, &called)) {
77 printf("%s rejected the session\n",host);
78 printf("We tried with a called name of %s & %s\n",
88 BOOL torture_open_connection(struct cli_state **c)
93 char *host = lp_parm_string(-1, "torture", "host");
94 char *share = lp_parm_string(-1, "torture", "share");
95 char *username = lp_parm_string(-1, "torture", "username");
96 char *password = lp_parm_string(-1, "torture", "password");
99 flags |= CLI_FULL_CONNECTION_USE_KERBEROS;
101 status = cli_full_connection(c, lp_netbios_name(),
104 username, username[0]?lp_workgroup():"",
105 password, flags, &retry);
106 if (!NT_STATUS_IS_OK(status)) {
107 printf("Failed to open connection - %s\n", nt_errstr(status));
111 (*c)->transport->options.use_oplocks = use_oplocks;
112 (*c)->transport->options.use_level2_oplocks = use_level_II_oplocks;
113 (*c)->transport->socket->timeout = 120000;
118 BOOL torture_close_connection(struct cli_state *c)
121 DEBUG(9,("torture_close_connection: cli_state@%p\n", c));
124 printf("tdis failed (%s)\n", cli_errstr(c));
127 DEBUG(9,("torture_close_connection: call cli_shutdown\n"));
129 DEBUG(9,("torture_close_connection: exit\n"));
133 /* open a rpc connection to a named pipe */
134 static NTSTATUS torture_rpc_tcp(struct dcerpc_pipe **p,
135 const char *pipe_name,
136 const char *pipe_uuid,
140 char *host = lp_parm_string(-1, "torture", "host");
141 const char *port_str = lp_parm_string(-1, "torture", "share");
142 uint32 port = atoi(port_str);
145 status = dcerpc_epm_map_tcp_port(host,
146 pipe_uuid, pipe_version,
148 if (!NT_STATUS_IS_OK(status)) {
149 DEBUG(0,("Failed to map DCERPC/TCP port for '%s' - %s\n",
150 pipe_name, nt_errstr(status)));
153 DEBUG(1,("Mapped to DCERPC/TCP port %u\n", port));
156 DEBUG(2,("Connecting to dcerpc server %s:%u\n", host, port));
158 status = dcerpc_pipe_open_tcp(p, host, port);
159 if (!NT_STATUS_IS_OK(status)) {
160 printf("Open of pipe '%s' failed with error (%s)\n",
161 pipe_name, nt_errstr(status));
165 /* always do NDR validation in smbtorture */
166 (*p)->flags |= DCERPC_DEBUG_VALIDATE_BOTH;
169 status = dcerpc_bind_auth_none(*p, pipe_uuid, pipe_version);
171 /* enable signing on tcp connections */
172 (*p)->flags |= DCERPC_SIGN;
174 /* bind to the pipe, using the uuid as the key */
175 status = dcerpc_bind_auth_ntlm(*p, pipe_uuid, pipe_version,
177 lp_parm_string(-1, "torture", "username"),
178 lp_parm_string(-1, "torture", "password"));
179 if (!NT_STATUS_IS_OK(status)) {
180 dcerpc_pipe_close(*p);
189 /* open a rpc connection to a named pipe */
190 NTSTATUS torture_rpc_connection(struct dcerpc_pipe **p,
191 const char *pipe_name,
192 const char *pipe_uuid,
195 struct cli_state *cli;
197 char *transport = lp_parm_string(-1, "torture", "transport");
199 if (strcmp(transport, "ncacn_ip_tcp") == 0) {
200 return torture_rpc_tcp(p, pipe_name, pipe_uuid, pipe_version);
203 if (strcmp(transport, "ncacn_np") != 0) {
204 printf("Unsupported RPC transport '%s'\n", transport);
205 return NT_STATUS_UNSUCCESSFUL;
208 if (! *lp_parm_string(-1, "torture", "share")) {
209 lp_set_cmdline("torture:share", "ipc$");
212 if (!torture_open_connection(&cli)) {
213 return NT_STATUS_UNSUCCESSFUL;
216 status = dcerpc_pipe_open_smb(p, cli->tree, pipe_name);
217 if (!NT_STATUS_IS_OK(status)) {
218 printf("Open of pipe '%s' failed with error (%s)\n",
219 pipe_name, nt_errstr(status));
220 torture_close_connection(cli);
224 /* this ensures that the reference count is decremented so
225 a pipe close will really close the link */
226 cli_tree_close(cli->tree);
228 /* bind to the pipe, using the uuid as the key */
229 status = dcerpc_bind_auth_none(*p, pipe_uuid, pipe_version);
230 if (!NT_STATUS_IS_OK(status)) {
231 dcerpc_pipe_close(*p);
235 /* always do NDR validation in smbtorture */
236 (*p)->flags |= DCERPC_DEBUG_VALIDATE_BOTH;
241 /* close a rpc connection to a named pipe */
242 NTSTATUS torture_rpc_close(struct dcerpc_pipe *p)
244 dcerpc_pipe_close(p);
249 /* check if the server produced the expected error code */
250 static BOOL check_error(int line, struct cli_state *c,
251 uint8 eclass, uint32 ecode, NTSTATUS nterr)
253 if (cli_is_dos_error(c)) {
257 /* Check DOS error */
259 cli_dos_error(c, &class, &num);
261 if (eclass != class || ecode != num) {
262 printf("unexpected error code class=%d code=%d\n",
263 (int)class, (int)num);
264 printf(" expected %d/%d %s (line=%d)\n",
265 (int)eclass, (int)ecode, nt_errstr(nterr), line);
274 status = cli_nt_error(c);
276 if (NT_STATUS_V(nterr) != NT_STATUS_V(status)) {
277 printf("unexpected error code %s\n", nt_errstr(status));
278 printf(" expected %s (line=%d)\n", nt_errstr(nterr), line);
287 static BOOL wait_lock(struct cli_state *c, int fnum, uint32 offset, uint32 len)
289 while (!cli_lock(c, fnum, offset, len, -1, WRITE_LOCK)) {
290 if (!check_error(__LINE__, c, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False;
296 static BOOL rw_torture(struct cli_state *c)
298 const char *lockfname = "\\torture.lck";
302 pid_t pid2, pid = getpid();
307 fnum2 = cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
310 fnum2 = cli_open(c, lockfname, O_RDWR, DENY_NONE);
312 printf("open of %s failed (%s)\n", lockfname, cli_errstr(c));
317 for (i=0;i<torture_numops;i++) {
318 unsigned n = (unsigned)sys_random()%10;
320 printf("%d\r", i); fflush(stdout);
322 asprintf(&fname, "\\torture.%u", n);
324 if (!wait_lock(c, fnum2, n*sizeof(int), sizeof(int))) {
328 fnum = cli_open(c, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_ALL);
330 printf("open failed (%s)\n", cli_errstr(c));
335 if (cli_write(c, fnum, 0, (char *)&pid, 0, sizeof(pid)) != sizeof(pid)) {
336 printf("write failed (%s)\n", cli_errstr(c));
341 if (cli_write(c, fnum, 0, (char *)buf,
342 sizeof(pid)+(j*sizeof(buf)),
343 sizeof(buf)) != sizeof(buf)) {
344 printf("write failed (%s)\n", cli_errstr(c));
351 if (cli_read(c, fnum, (char *)&pid2, 0, sizeof(pid)) != sizeof(pid)) {
352 printf("read failed (%s)\n", cli_errstr(c));
357 printf("data corruption!\n");
361 if (!cli_close(c, fnum)) {
362 printf("close failed (%s)\n", cli_errstr(c));
366 if (!cli_unlink(c, fname)) {
367 printf("unlink failed (%s)\n", cli_errstr(c));
371 if (!cli_unlock(c, fnum2, n*sizeof(int), sizeof(int))) {
372 printf("unlock failed (%s)\n", cli_errstr(c));
379 cli_unlink(c, lockfname);
386 static BOOL run_torture(int dummy)
388 struct cli_state *cli;
393 ret = rw_torture(cli);
395 if (!torture_close_connection(cli)) {
402 static BOOL rw_torture3(struct cli_state *c, const char *lockfname)
409 unsigned countprev = 0;
414 for (i = 0; i < sizeof(buf); i += sizeof(uint32))
416 SIVAL(buf, i, sys_random());
421 fnum = cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
424 printf("first open read/write of %s failed (%s)\n",
425 lockfname, cli_errstr(c));
431 for (i = 0; i < 500 && fnum == -1; i++)
433 fnum = cli_open(c, lockfname, O_RDONLY,
438 printf("second open read-only of %s failed (%s)\n",
439 lockfname, cli_errstr(c));
445 for (count = 0; count < sizeof(buf); count += sent)
447 if (count >= countprev) {
448 printf("%d %8d\r", i, count);
451 countprev += (sizeof(buf) / 20);
456 sent = ((unsigned)sys_random()%(20))+ 1;
457 if (sent > sizeof(buf) - count)
459 sent = sizeof(buf) - count;
462 if (cli_write(c, fnum, 0, buf+count, count, (size_t)sent) != sent) {
463 printf("write failed (%s)\n", cli_errstr(c));
469 sent = cli_read(c, fnum, buf_rd+count, count,
473 printf("read failed offset:%d size:%d (%s)\n",
474 count, sizeof(buf)-count,
481 if (memcmp(buf_rd+count, buf+count, sent) != 0)
483 printf("read/write compare failed\n");
484 printf("offset: %d req %d recvd %d\n",
485 count, sizeof(buf)-count, sent);
494 if (!cli_close(c, fnum)) {
495 printf("close failed (%s)\n", cli_errstr(c));
502 static BOOL rw_torture2(struct cli_state *c1, struct cli_state *c2)
504 const char *lockfname = "\\torture2.lck";
509 uchar buf_rd[131072];
511 ssize_t bytes_read, bytes_written;
513 if (cli_deltree(c1, lockfname) == -1) {
514 printf("unlink failed (%s)\n", cli_errstr(c1));
517 fnum1 = cli_open(c1, lockfname, O_RDWR | O_CREAT | O_EXCL,
520 printf("first open read/write of %s failed (%s)\n",
521 lockfname, cli_errstr(c1));
524 fnum2 = cli_open(c2, lockfname, O_RDONLY,
527 printf("second open read-only of %s failed (%s)\n",
528 lockfname, cli_errstr(c2));
529 cli_close(c1, fnum1);
533 printf("Checking data integrity over %d ops\n", torture_numops);
535 for (i=0;i<torture_numops;i++)
537 size_t buf_size = ((unsigned)sys_random()%(sizeof(buf)-1))+ 1;
539 printf("%d\r", i); fflush(stdout);
542 generate_random_buffer(buf, buf_size, False);
544 if ((bytes_written = cli_write(c1, fnum1, 0, buf, 0, buf_size)) != buf_size) {
545 printf("write failed (%s)\n", cli_errstr(c1));
546 printf("wrote %d, expected %d\n", bytes_written, buf_size);
551 if ((bytes_read = cli_read(c2, fnum2, buf_rd, 0, buf_size)) != buf_size) {
552 printf("read failed (%s)\n", cli_errstr(c2));
553 printf("read %d, expected %d\n", bytes_read, buf_size);
558 if (memcmp(buf_rd, buf, buf_size) != 0)
560 printf("read/write compare failed\n");
566 if (!cli_close(c2, fnum2)) {
567 printf("close failed (%s)\n", cli_errstr(c2));
570 if (!cli_close(c1, fnum1)) {
571 printf("close failed (%s)\n", cli_errstr(c1));
575 if (!cli_unlink(c1, lockfname)) {
576 printf("unlink failed (%s)\n", cli_errstr(c1));
583 static BOOL run_readwritetest(int dummy)
585 struct cli_state *cli1, *cli2;
586 BOOL test1, test2 = True;
588 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
592 printf("starting readwritetest\n");
594 test1 = rw_torture2(cli1, cli2);
595 printf("Passed readwritetest v1: %s\n", BOOLSTR(test1));
598 test2 = rw_torture2(cli1, cli1);
599 printf("Passed readwritetest v2: %s\n", BOOLSTR(test2));
602 if (!torture_close_connection(cli1)) {
606 if (!torture_close_connection(cli2)) {
610 return (test1 && test2);
613 static BOOL run_readwritemulti(int dummy)
615 struct cli_state *cli;
620 test = rw_torture3(cli, "\\multitest.txt");
622 if (!torture_close_connection(cli)) {
633 #define ival(s) strtol(s, NULL, 0)
635 /* run a test that simulates an approximate netbench client load */
636 static BOOL run_netbench(int client)
638 struct cli_state *cli;
643 const char *params[20];
652 asprintf(&cname, "client%d", client);
654 f = fopen(client_txt, "r");
661 while (fgets(line, sizeof(line)-1, f)) {
664 line[strlen(line)-1] = 0;
666 /* printf("[%d] %s\n", line_count, line); */
668 all_string_sub(line,"client1", cname, sizeof(line));
670 /* parse the command parameters */
671 params[0] = strtok(line," ");
673 while (params[i]) params[++i] = strtok(NULL," ");
679 if (!strncmp(params[0],"SMB", 3)) {
680 printf("ERROR: You are using a dbench 1 load file\n");
683 DEBUG(9,("run_netbench(%d): %s %s\n", client, params[0], params[1]));
685 if (!strcmp(params[0],"NTCreateX")) {
686 nb_createx(params[1], ival(params[2]), ival(params[3]),
688 } else if (!strcmp(params[0],"Close")) {
689 nb_close(ival(params[1]));
690 } else if (!strcmp(params[0],"Rename")) {
691 nb_rename(params[1], params[2]);
692 } else if (!strcmp(params[0],"Unlink")) {
693 nb_unlink(params[1]);
694 } else if (!strcmp(params[0],"Deltree")) {
695 nb_deltree(params[1]);
696 } else if (!strcmp(params[0],"Rmdir")) {
698 } else if (!strcmp(params[0],"QUERY_PATH_INFORMATION")) {
699 nb_qpathinfo(params[1]);
700 } else if (!strcmp(params[0],"QUERY_FILE_INFORMATION")) {
701 nb_qfileinfo(ival(params[1]));
702 } else if (!strcmp(params[0],"QUERY_FS_INFORMATION")) {
703 nb_qfsinfo(ival(params[1]));
704 } else if (!strcmp(params[0],"FIND_FIRST")) {
705 nb_findfirst(params[1]);
706 } else if (!strcmp(params[0],"WriteX")) {
707 nb_writex(ival(params[1]),
708 ival(params[2]), ival(params[3]), ival(params[4]));
709 } else if (!strcmp(params[0],"ReadX")) {
710 nb_readx(ival(params[1]),
711 ival(params[2]), ival(params[3]), ival(params[4]));
712 } else if (!strcmp(params[0],"Flush")) {
713 nb_flush(ival(params[1]));
715 printf("Unknown operation %s\n", params[0]);
723 if (!torture_close_connection(cli)) {
731 /* run a test that simulates an approximate netbench client load */
732 static BOOL run_nbench(int dummy)
741 signal(SIGALRM, SIGNAL_CAST nb_alarm);
743 t = create_procs(run_netbench, &correct);
746 printf("\nThroughput %g MB/sec\n",
747 1.0e-6 * nbio_total() / t);
753 This test checks for two things:
755 1) correct support for retaining locks over a close (ie. the server
756 must not use posix semantics)
757 2) support for lock timeouts
759 static BOOL run_locktest1(int dummy)
761 struct cli_state *cli1, *cli2;
762 const char *fname = "\\lockt1.lck";
763 int fnum1, fnum2, fnum3;
765 unsigned lock_timeout;
767 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
771 printf("starting locktest1\n");
773 cli_unlink(cli1, fname);
775 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
777 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
780 fnum2 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
782 printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli1));
785 fnum3 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
787 printf("open3 of %s failed (%s)\n", fname, cli_errstr(cli2));
791 if (!cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK)) {
792 printf("lock1 failed (%s)\n", cli_errstr(cli1));
797 if (cli_lock(cli2, fnum3, 0, 4, 0, WRITE_LOCK)) {
798 printf("lock2 succeeded! This is a locking bug\n");
801 if (!check_error(__LINE__, cli2, ERRDOS, ERRlock,
802 NT_STATUS_LOCK_NOT_GRANTED)) return False;
806 lock_timeout = (6 + (random() % 20));
807 printf("Testing lock timeout with timeout=%u\n", lock_timeout);
809 if (cli_lock(cli2, fnum3, 0, 4, lock_timeout * 1000, WRITE_LOCK)) {
810 printf("lock3 succeeded! This is a locking bug\n");
813 if (!check_error(__LINE__, cli2, ERRDOS, ERRlock,
814 NT_STATUS_FILE_LOCK_CONFLICT)) return False;
819 printf("error: This server appears not to support timed lock requests\n");
821 printf("server slept for %u seconds for a %u second timeout\n",
822 (unsigned int)(t2-t1), lock_timeout);
824 if (!cli_close(cli1, fnum2)) {
825 printf("close1 failed (%s)\n", cli_errstr(cli1));
829 if (cli_lock(cli2, fnum3, 0, 4, 0, WRITE_LOCK)) {
830 printf("lock4 succeeded! This is a locking bug\n");
833 if (!check_error(__LINE__, cli2, ERRDOS, ERRlock,
834 NT_STATUS_FILE_LOCK_CONFLICT)) return False;
837 if (!cli_close(cli1, fnum1)) {
838 printf("close2 failed (%s)\n", cli_errstr(cli1));
842 if (!cli_close(cli2, fnum3)) {
843 printf("close3 failed (%s)\n", cli_errstr(cli2));
847 if (!cli_unlink(cli1, fname)) {
848 printf("unlink failed (%s)\n", cli_errstr(cli1));
853 if (!torture_close_connection(cli1)) {
857 if (!torture_close_connection(cli2)) {
861 printf("Passed locktest1\n");
866 this checks to see if a secondary tconx can use open files from an
869 static BOOL run_tcon_test(int dummy)
871 struct cli_state *cli;
872 const char *fname = "\\tcontest.tmp";
874 uint16 cnum1, cnum2, cnum3;
878 struct cli_tree *tree1;
879 char *host = lp_parm_string(-1, "torture", "host");
880 char *share = lp_parm_string(-1, "torture", "share");
881 char *password = lp_parm_string(-1, "torture", "password");
883 if (!torture_open_connection(&cli)) {
887 printf("starting tcontest\n");
889 if (cli_deltree(cli, fname) == -1) {
890 printf("unlink of %s failed (%s)\n", fname, cli_errstr(cli));
893 fnum1 = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
895 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
899 cnum1 = cli->tree->tid;
900 vuid1 = cli->session->vuid;
902 memset(&buf, 0, 4); /* init buf so valgrind won't complain */
903 if (cli_write(cli, fnum1, 0, buf, 130, 4) != 4) {
904 printf("initial write failed (%s)\n", cli_errstr(cli));
908 tree1 = cli->tree; /* save old tree connection */
909 if (!cli_send_tconX(cli, share, "?????",
911 printf("%s refused 2nd tree connect (%s)\n", host,
917 cnum2 = cli->tree->tid;
918 cnum3 = MAX(cnum1, cnum2) + 1; /* any invalid number */
919 vuid2 = cli->session->vuid + 1;
921 /* try a write with the wrong tid */
922 cli->tree->tid = cnum2;
924 if (cli_write(cli, fnum1, 0, buf, 130, 4) == 4) {
925 printf("* server allows write with wrong TID\n");
928 printf("server fails write with wrong TID : %s\n", cli_errstr(cli));
932 /* try a write with an invalid tid */
933 cli->tree->tid = cnum3;
935 if (cli_write(cli, fnum1, 0, buf, 130, 4) == 4) {
936 printf("* server allows write with invalid TID\n");
939 printf("server fails write with invalid TID : %s\n", cli_errstr(cli));
942 /* try a write with an invalid vuid */
943 cli->session->vuid = vuid2;
944 cli->tree->tid = cnum1;
946 if (cli_write(cli, fnum1, 0, buf, 130, 4) == 4) {
947 printf("* server allows write with invalid VUID\n");
950 printf("server fails write with invalid VUID : %s\n", cli_errstr(cli));
953 cli->session->vuid = vuid1;
954 cli->tree->tid = cnum1;
956 if (!cli_close(cli, fnum1)) {
957 printf("close failed (%s)\n", cli_errstr(cli));
961 cli->tree->tid = cnum2;
963 if (!cli_tdis(cli)) {
964 printf("secondary tdis failed (%s)\n", cli_errstr(cli));
968 cli->tree = tree1; /* restore initial tree */
969 cli->tree->tid = cnum1;
971 if (!torture_close_connection(cli)) {
980 static BOOL tcon_devtest(struct cli_state *cli,
981 const char *myshare, const char *devtype,
982 NTSTATUS expected_error)
986 char *password = lp_parm_string(-1, "torture", "password");
988 status = cli_send_tconX(cli, myshare, devtype,
991 printf("Trying share %s with devtype %s\n", myshare, devtype);
993 if (NT_STATUS_IS_OK(expected_error)) {
997 printf("tconX to share %s with type %s "
998 "should have succeeded but failed\n",
1005 printf("tconx to share %s with type %s "
1006 "should have failed but succeeded\n",
1010 if (NT_STATUS_EQUAL(cli_nt_error(cli),
1014 printf("Returned unexpected error\n");
1023 checks for correct tconX support
1025 static BOOL run_tcon_devtype_test(int dummy)
1027 struct cli_state *cli1 = NULL;
1032 char *host = lp_parm_string(-1, "torture", "host");
1033 char *share = lp_parm_string(-1, "torture", "share");
1034 char *username = lp_parm_string(-1, "torture", "username");
1035 char *password = lp_parm_string(-1, "torture", "password");
1037 status = cli_full_connection(&cli1, lp_netbios_name(),
1040 username, lp_workgroup(),
1041 password, flags, &retry);
1043 if (!NT_STATUS_IS_OK(status)) {
1044 printf("could not open connection\n");
1048 if (!tcon_devtest(cli1, "IPC$", "A:", NT_STATUS_BAD_DEVICE_TYPE))
1051 if (!tcon_devtest(cli1, "IPC$", "?????", NT_STATUS_OK))
1054 if (!tcon_devtest(cli1, "IPC$", "LPT:", NT_STATUS_BAD_DEVICE_TYPE))
1057 if (!tcon_devtest(cli1, "IPC$", "IPC", NT_STATUS_OK))
1060 if (!tcon_devtest(cli1, "IPC$", "FOOBA", NT_STATUS_BAD_DEVICE_TYPE))
1063 if (!tcon_devtest(cli1, share, "A:", NT_STATUS_OK))
1066 if (!tcon_devtest(cli1, share, "?????", NT_STATUS_OK))
1069 if (!tcon_devtest(cli1, share, "LPT:", NT_STATUS_BAD_DEVICE_TYPE))
1072 if (!tcon_devtest(cli1, share, "IPC", NT_STATUS_BAD_DEVICE_TYPE))
1075 if (!tcon_devtest(cli1, share, "FOOBA", NT_STATUS_BAD_DEVICE_TYPE))
1081 printf("Passed tcondevtest\n");
1088 This test checks that
1090 1) the server supports multiple locking contexts on the one SMB
1091 connection, distinguished by PID.
1093 2) the server correctly fails overlapping locks made by the same PID (this
1094 goes against POSIX behaviour, which is why it is tricky to implement)
1096 3) the server denies unlock requests by an incorrect client PID
1098 static BOOL run_locktest2(int dummy)
1100 struct cli_state *cli;
1101 const char *fname = "\\lockt2.lck";
1102 int fnum1, fnum2, fnum3;
1103 BOOL correct = True;
1105 if (!torture_open_connection(&cli)) {
1109 printf("starting locktest2\n");
1111 cli_unlink(cli, fname);
1113 printf("Testing pid context\n");
1115 cli->session->pid = 1;
1117 fnum1 = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1119 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
1123 fnum2 = cli_open(cli, fname, O_RDWR, DENY_NONE);
1125 printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli));
1129 cli->session->pid = 2;
1131 fnum3 = cli_open(cli, fname, O_RDWR, DENY_NONE);
1133 printf("open3 of %s failed (%s)\n", fname, cli_errstr(cli));
1137 cli->session->pid = 1;
1139 if (!cli_lock(cli, fnum1, 0, 4, 0, WRITE_LOCK)) {
1140 printf("lock1 failed (%s)\n", cli_errstr(cli));
1144 if (cli_lock(cli, fnum1, 0, 4, 0, WRITE_LOCK)) {
1145 printf("WRITE lock1 succeeded! This is a locking bug\n");
1148 if (!check_error(__LINE__, cli, ERRDOS, ERRlock,
1149 NT_STATUS_LOCK_NOT_GRANTED)) return False;
1152 if (cli_lock(cli, fnum2, 0, 4, 0, WRITE_LOCK)) {
1153 printf("WRITE lock2 succeeded! This is a locking bug\n");
1156 if (!check_error(__LINE__, cli, ERRDOS, ERRlock,
1157 NT_STATUS_LOCK_NOT_GRANTED)) return False;
1160 if (cli_lock(cli, fnum2, 0, 4, 0, READ_LOCK)) {
1161 printf("READ lock2 succeeded! This is a locking bug\n");
1164 if (!check_error(__LINE__, cli, ERRDOS, ERRlock,
1165 NT_STATUS_FILE_LOCK_CONFLICT)) return False;
1168 if (!cli_lock(cli, fnum1, 100, 4, 0, WRITE_LOCK)) {
1169 printf("lock at 100 failed (%s)\n", cli_errstr(cli));
1172 cli->session->pid = 2;
1174 if (cli_unlock(cli, fnum1, 100, 4)) {
1175 printf("unlock at 100 succeeded! This is a locking bug\n");
1179 if (cli_unlock(cli, fnum1, 0, 4)) {
1180 printf("unlock1 succeeded! This is a locking bug\n");
1183 if (!check_error(__LINE__, cli,
1185 NT_STATUS_RANGE_NOT_LOCKED)) return False;
1188 if (cli_unlock(cli, fnum1, 0, 8)) {
1189 printf("unlock2 succeeded! This is a locking bug\n");
1192 if (!check_error(__LINE__, cli,
1194 NT_STATUS_RANGE_NOT_LOCKED)) return False;
1197 if (cli_lock(cli, fnum3, 0, 4, 0, WRITE_LOCK)) {
1198 printf("lock3 succeeded! This is a locking bug\n");
1201 if (!check_error(__LINE__, cli, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False;
1204 cli->session->pid = 1;
1206 if (!cli_close(cli, fnum1)) {
1207 printf("close1 failed (%s)\n", cli_errstr(cli));
1211 if (!cli_close(cli, fnum2)) {
1212 printf("close2 failed (%s)\n", cli_errstr(cli));
1216 if (!cli_close(cli, fnum3)) {
1217 printf("close3 failed (%s)\n", cli_errstr(cli));
1221 if (!torture_close_connection(cli)) {
1225 printf("locktest2 finished\n");
1232 This test checks that
1234 1) the server supports the full offset range in lock requests
1236 static BOOL run_locktest3(int dummy)
1238 struct cli_state *cli1, *cli2;
1239 const char *fname = "\\lockt3.lck";
1240 int fnum1, fnum2, i;
1242 BOOL correct = True;
1244 #define NEXT_OFFSET offset += (~(uint32)0) / torture_numops
1246 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
1250 printf("starting locktest3\n");
1252 printf("Testing 32 bit offset ranges\n");
1254 cli_unlink(cli1, fname);
1256 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1258 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
1261 fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
1263 printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli2));
1267 printf("Establishing %d locks\n", torture_numops);
1269 for (offset=i=0;i<torture_numops;i++) {
1271 if (!cli_lock(cli1, fnum1, offset-1, 1, 0, WRITE_LOCK)) {
1272 printf("lock1 %d failed (%s)\n",
1278 if (!cli_lock(cli2, fnum2, offset-2, 1, 0, WRITE_LOCK)) {
1279 printf("lock2 %d failed (%s)\n",
1286 printf("Testing %d locks\n", torture_numops);
1288 for (offset=i=0;i<torture_numops;i++) {
1291 if (cli_lock(cli1, fnum1, offset-2, 1, 0, WRITE_LOCK)) {
1292 printf("error: lock1 %d succeeded!\n", i);
1296 if (cli_lock(cli2, fnum2, offset-1, 1, 0, WRITE_LOCK)) {
1297 printf("error: lock2 %d succeeded!\n", i);
1301 if (cli_lock(cli1, fnum1, offset-1, 1, 0, WRITE_LOCK)) {
1302 printf("error: lock3 %d succeeded!\n", i);
1306 if (cli_lock(cli2, fnum2, offset-2, 1, 0, WRITE_LOCK)) {
1307 printf("error: lock4 %d succeeded!\n", i);
1312 printf("Removing %d locks\n", torture_numops);
1314 for (offset=i=0;i<torture_numops;i++) {
1317 if (!cli_unlock(cli1, fnum1, offset-1, 1)) {
1318 printf("unlock1 %d failed (%s)\n",
1324 if (!cli_unlock(cli2, fnum2, offset-2, 1)) {
1325 printf("unlock2 %d failed (%s)\n",
1332 if (!cli_close(cli1, fnum1)) {
1333 printf("close1 failed (%s)\n", cli_errstr(cli1));
1337 if (!cli_close(cli2, fnum2)) {
1338 printf("close2 failed (%s)\n", cli_errstr(cli2));
1342 if (!cli_unlink(cli1, fname)) {
1343 printf("unlink failed (%s)\n", cli_errstr(cli1));
1347 if (!torture_close_connection(cli1)) {
1351 if (!torture_close_connection(cli2)) {
1355 printf("finished locktest3\n");
1360 #define EXPECTED(ret, v) if ((ret) != (v)) { \
1361 printf("** "); correct = False; \
1365 looks at overlapping locks
1367 static BOOL run_locktest4(int dummy)
1369 struct cli_state *cli1, *cli2;
1370 const char *fname = "\\lockt4.lck";
1371 int fnum1, fnum2, f;
1374 BOOL correct = True;
1376 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
1380 printf("starting locktest4\n");
1382 cli_unlink(cli1, fname);
1384 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1385 fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
1387 memset(buf, 0, sizeof(buf));
1389 if (cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
1390 printf("Failed to create file\n");
1395 ret = cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK) &&
1396 cli_lock(cli1, fnum1, 2, 4, 0, WRITE_LOCK);
1397 EXPECTED(ret, False);
1398 printf("the same process %s set overlapping write locks\n", ret?"can":"cannot");
1400 ret = cli_lock(cli1, fnum1, 10, 4, 0, READ_LOCK) &&
1401 cli_lock(cli1, fnum1, 12, 4, 0, READ_LOCK);
1402 EXPECTED(ret, True);
1403 printf("the same process %s set overlapping read locks\n", ret?"can":"cannot");
1405 ret = cli_lock(cli1, fnum1, 20, 4, 0, WRITE_LOCK) &&
1406 cli_lock(cli2, fnum2, 22, 4, 0, WRITE_LOCK);
1407 EXPECTED(ret, False);
1408 printf("a different connection %s set overlapping write locks\n", ret?"can":"cannot");
1410 ret = cli_lock(cli1, fnum1, 30, 4, 0, READ_LOCK) &&
1411 cli_lock(cli2, fnum2, 32, 4, 0, READ_LOCK);
1412 EXPECTED(ret, True);
1413 printf("a different connection %s set overlapping read locks\n", ret?"can":"cannot");
1415 ret = (cli1->session->pid = 1, cli_lock(cli1, fnum1, 40, 4, 0, WRITE_LOCK)) &&
1416 (cli1->session->pid = 2, cli_lock(cli1, fnum1, 42, 4, 0, WRITE_LOCK));
1417 EXPECTED(ret, False);
1418 printf("a different pid %s set overlapping write locks\n", ret?"can":"cannot");
1420 ret = (cli1->session->pid = 1, cli_lock(cli1, fnum1, 50, 4, 0, READ_LOCK)) &&
1421 (cli1->session->pid = 2, cli_lock(cli1, fnum1, 52, 4, 0, READ_LOCK));
1422 EXPECTED(ret, True);
1423 printf("a different pid %s set overlapping read locks\n", ret?"can":"cannot");
1425 ret = cli_lock(cli1, fnum1, 60, 4, 0, READ_LOCK) &&
1426 cli_lock(cli1, fnum1, 60, 4, 0, READ_LOCK);
1427 EXPECTED(ret, True);
1428 printf("the same process %s set the same read lock twice\n", ret?"can":"cannot");
1430 ret = cli_lock(cli1, fnum1, 70, 4, 0, WRITE_LOCK) &&
1431 cli_lock(cli1, fnum1, 70, 4, 0, WRITE_LOCK);
1432 EXPECTED(ret, False);
1433 printf("the same process %s set the same write lock twice\n", ret?"can":"cannot");
1435 ret = cli_lock(cli1, fnum1, 80, 4, 0, READ_LOCK) &&
1436 cli_lock(cli1, fnum1, 80, 4, 0, WRITE_LOCK);
1437 EXPECTED(ret, False);
1438 printf("the same process %s overlay a read lock with a write lock\n", ret?"can":"cannot");
1440 ret = cli_lock(cli1, fnum1, 90, 4, 0, WRITE_LOCK) &&
1441 cli_lock(cli1, fnum1, 90, 4, 0, READ_LOCK);
1442 EXPECTED(ret, True);
1443 printf("the same process %s overlay a write lock with a read lock\n", ret?"can":"cannot");
1445 ret = (cli1->session->pid = 1, cli_lock(cli1, fnum1, 100, 4, 0, WRITE_LOCK)) &&
1446 (cli1->session->pid = 2, cli_lock(cli1, fnum1, 100, 4, 0, READ_LOCK));
1447 EXPECTED(ret, False);
1448 printf("a different pid %s overlay a write lock with a read lock\n", ret?"can":"cannot");
1450 ret = cli_lock(cli1, fnum1, 110, 4, 0, READ_LOCK) &&
1451 cli_lock(cli1, fnum1, 112, 4, 0, READ_LOCK) &&
1452 cli_unlock(cli1, fnum1, 110, 6);
1453 EXPECTED(ret, False);
1454 printf("the same process %s coalesce read locks\n", ret?"can":"cannot");
1457 ret = cli_lock(cli1, fnum1, 120, 4, 0, WRITE_LOCK) &&
1458 (cli_read(cli2, fnum2, buf, 120, 4) == 4);
1459 EXPECTED(ret, False);
1460 printf("this server %s strict write locking\n", ret?"doesn't do":"does");
1462 ret = cli_lock(cli1, fnum1, 130, 4, 0, READ_LOCK) &&
1463 (cli_write(cli2, fnum2, 0, buf, 130, 4) == 4);
1464 EXPECTED(ret, False);
1465 printf("this server %s strict read locking\n", ret?"doesn't do":"does");
1468 ret = cli_lock(cli1, fnum1, 140, 4, 0, READ_LOCK) &&
1469 cli_lock(cli1, fnum1, 140, 4, 0, READ_LOCK) &&
1470 cli_unlock(cli1, fnum1, 140, 4) &&
1471 cli_unlock(cli1, fnum1, 140, 4);
1472 EXPECTED(ret, True);
1473 printf("this server %s do recursive read locking\n", ret?"does":"doesn't");
1476 ret = cli_lock(cli1, fnum1, 150, 4, 0, WRITE_LOCK) &&
1477 cli_lock(cli1, fnum1, 150, 4, 0, READ_LOCK) &&
1478 cli_unlock(cli1, fnum1, 150, 4) &&
1479 (cli_read(cli2, fnum2, buf, 150, 4) == 4) &&
1480 !(cli_write(cli2, fnum2, 0, buf, 150, 4) == 4) &&
1481 cli_unlock(cli1, fnum1, 150, 4);
1482 EXPECTED(ret, True);
1483 printf("this server %s do recursive lock overlays\n", ret?"does":"doesn't");
1485 ret = cli_lock(cli1, fnum1, 160, 4, 0, READ_LOCK) &&
1486 cli_unlock(cli1, fnum1, 160, 4) &&
1487 (cli_write(cli2, fnum2, 0, buf, 160, 4) == 4) &&
1488 (cli_read(cli2, fnum2, buf, 160, 4) == 4);
1489 EXPECTED(ret, True);
1490 printf("the same process %s remove a read lock using write locking\n", ret?"can":"cannot");
1492 ret = cli_lock(cli1, fnum1, 170, 4, 0, WRITE_LOCK) &&
1493 cli_unlock(cli1, fnum1, 170, 4) &&
1494 (cli_write(cli2, fnum2, 0, buf, 170, 4) == 4) &&
1495 (cli_read(cli2, fnum2, buf, 170, 4) == 4);
1496 EXPECTED(ret, True);
1497 printf("the same process %s remove a write lock using read locking\n", ret?"can":"cannot");
1499 ret = cli_lock(cli1, fnum1, 190, 4, 0, WRITE_LOCK) &&
1500 cli_lock(cli1, fnum1, 190, 4, 0, READ_LOCK) &&
1501 cli_unlock(cli1, fnum1, 190, 4) &&
1502 !(cli_write(cli2, fnum2, 0, buf, 190, 4) == 4) &&
1503 (cli_read(cli2, fnum2, buf, 190, 4) == 4);
1504 EXPECTED(ret, True);
1505 printf("the same process %s remove the first lock first\n", ret?"does":"doesn't");
1507 cli_close(cli1, fnum1);
1508 cli_close(cli2, fnum2);
1509 fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1510 f = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1511 ret = cli_lock(cli1, fnum1, 0, 8, 0, READ_LOCK) &&
1512 cli_lock(cli1, f, 0, 1, 0, READ_LOCK) &&
1513 cli_close(cli1, fnum1) &&
1514 ((fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE)) != -1) &&
1515 cli_lock(cli1, fnum1, 7, 1, 0, WRITE_LOCK);
1517 cli_close(cli1, fnum1);
1518 EXPECTED(ret, True);
1519 printf("the server %s have the NT byte range lock bug\n", !ret?"does":"doesn't");
1522 cli_close(cli1, fnum1);
1523 cli_close(cli2, fnum2);
1524 cli_unlink(cli1, fname);
1525 torture_close_connection(cli1);
1526 torture_close_connection(cli2);
1528 printf("finished locktest4\n");
1533 looks at lock upgrade/downgrade.
1535 static BOOL run_locktest5(int dummy)
1537 struct cli_state *cli1, *cli2;
1538 const char *fname = "\\lockt5.lck";
1539 int fnum1, fnum2, fnum3;
1542 BOOL correct = True;
1544 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
1548 printf("starting locktest5\n");
1550 cli_unlink(cli1, fname);
1552 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1553 fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
1554 fnum3 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1556 memset(buf, 0, sizeof(buf));
1558 if (cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
1559 printf("Failed to create file\n");
1564 /* Check for NT bug... */
1565 ret = cli_lock(cli1, fnum1, 0, 8, 0, READ_LOCK) &&
1566 cli_lock(cli1, fnum3, 0, 1, 0, READ_LOCK);
1567 cli_close(cli1, fnum1);
1568 fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1569 ret = cli_lock(cli1, fnum1, 7, 1, 0, WRITE_LOCK);
1570 EXPECTED(ret, True);
1571 printf("this server %s the NT locking bug\n", ret ? "doesn't have" : "has");
1572 cli_close(cli1, fnum1);
1573 fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1574 cli_unlock(cli1, fnum3, 0, 1);
1576 ret = cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK) &&
1577 cli_lock(cli1, fnum1, 1, 1, 0, READ_LOCK);
1578 EXPECTED(ret, True);
1579 printf("the same process %s overlay a write with a read lock\n", ret?"can":"cannot");
1581 ret = cli_lock(cli2, fnum2, 0, 4, 0, READ_LOCK);
1582 EXPECTED(ret, False);
1584 printf("a different processs %s get a read lock on the first process lock stack\n", ret?"can":"cannot");
1586 /* Unlock the process 2 lock. */
1587 cli_unlock(cli2, fnum2, 0, 4);
1589 ret = cli_lock(cli1, fnum3, 0, 4, 0, READ_LOCK);
1590 EXPECTED(ret, False);
1592 printf("the same processs on a different fnum %s get a read lock\n", ret?"can":"cannot");
1594 /* Unlock the process 1 fnum3 lock. */
1595 cli_unlock(cli1, fnum3, 0, 4);
1597 /* Stack 2 more locks here. */
1598 ret = cli_lock(cli1, fnum1, 0, 4, 0, READ_LOCK) &&
1599 cli_lock(cli1, fnum1, 0, 4, 0, READ_LOCK);
1601 EXPECTED(ret, True);
1602 printf("the same process %s stack read locks\n", ret?"can":"cannot");
1604 /* Unlock the first process lock, then check this was the WRITE lock that was
1607 ret = cli_unlock(cli1, fnum1, 0, 4) &&
1608 cli_lock(cli2, fnum2, 0, 4, 0, READ_LOCK);
1610 EXPECTED(ret, True);
1611 printf("the first unlock removes the %s lock\n", ret?"WRITE":"READ");
1613 /* Unlock the process 2 lock. */
1614 cli_unlock(cli2, fnum2, 0, 4);
1616 /* We should have 3 stacked locks here. Ensure we need to do 3 unlocks. */
1618 ret = cli_unlock(cli1, fnum1, 1, 1) &&
1619 cli_unlock(cli1, fnum1, 0, 4) &&
1620 cli_unlock(cli1, fnum1, 0, 4);
1622 EXPECTED(ret, True);
1623 printf("the same process %s unlock the stack of 4 locks\n", ret?"can":"cannot");
1625 /* Ensure the next unlock fails. */
1626 ret = cli_unlock(cli1, fnum1, 0, 4);
1627 EXPECTED(ret, False);
1628 printf("the same process %s count the lock stack\n", !ret?"can":"cannot");
1630 /* Ensure connection 2 can get a write lock. */
1631 ret = cli_lock(cli2, fnum2, 0, 4, 0, WRITE_LOCK);
1632 EXPECTED(ret, True);
1634 printf("a different processs %s get a write lock on the unlocked stack\n", ret?"can":"cannot");
1638 cli_close(cli1, fnum1);
1639 cli_close(cli2, fnum2);
1640 cli_unlink(cli1, fname);
1641 if (!torture_close_connection(cli1)) {
1644 if (!torture_close_connection(cli2)) {
1648 printf("finished locktest5\n");
1654 tries the unusual lockingX locktype bits
1656 static BOOL run_locktest6(int dummy)
1658 struct cli_state *cli;
1659 const char *fname[1] = { "\\lock6.txt" };
1664 if (!torture_open_connection(&cli)) {
1668 printf("starting locktest6\n");
1671 printf("Testing %s\n", fname[i]);
1673 cli_unlink(cli, fname[i]);
1675 fnum = cli_open(cli, fname[i], O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1676 status = cli_locktype(cli, fnum, 0, 8, 0, LOCKING_ANDX_CHANGE_LOCKTYPE);
1677 cli_close(cli, fnum);
1678 printf("CHANGE_LOCKTYPE gave %s\n", nt_errstr(status));
1680 fnum = cli_open(cli, fname[i], O_RDWR, DENY_NONE);
1681 status = cli_locktype(cli, fnum, 0, 8, 0, LOCKING_ANDX_CANCEL_LOCK);
1682 cli_close(cli, fnum);
1683 printf("CANCEL_LOCK gave %s\n", nt_errstr(status));
1685 cli_unlink(cli, fname[i]);
1688 torture_close_connection(cli);
1690 printf("finished locktest6\n");
1694 static BOOL run_locktest7(int dummy)
1696 struct cli_state *cli1;
1697 const char *fname = "\\lockt7.lck";
1700 BOOL correct = False;
1702 if (!torture_open_connection(&cli1)) {
1706 printf("starting locktest7\n");
1708 cli_unlink(cli1, fname);
1710 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1712 memset(buf, 0, sizeof(buf));
1714 if (cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
1715 printf("Failed to create file\n");
1719 cli1->session->pid = 1;
1721 if (!cli_lock(cli1, fnum1, 130, 4, 0, READ_LOCK)) {
1722 printf("Unable to apply read lock on range 130:4, error was %s\n", cli_errstr(cli1));
1725 printf("pid1 successfully locked range 130:4 for READ\n");
1728 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
1729 printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
1732 printf("pid1 successfully read the range 130:4\n");
1735 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
1736 printf("pid1 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
1737 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
1738 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
1742 printf("pid1 successfully wrote to the range 130:4 (should be denied)\n");
1746 cli1->session->pid = 2;
1748 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
1749 printf("pid2 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
1751 printf("pid2 successfully read the range 130:4\n");
1754 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
1755 printf("pid2 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
1756 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
1757 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
1761 printf("pid2 successfully wrote to the range 130:4 (should be denied)\n");
1765 cli1->session->pid = 1;
1766 cli_unlock(cli1, fnum1, 130, 4);
1768 if (!cli_lock(cli1, fnum1, 130, 4, 0, WRITE_LOCK)) {
1769 printf("Unable to apply write lock on range 130:4, error was %s\n", cli_errstr(cli1));
1772 printf("pid1 successfully locked range 130:4 for WRITE\n");
1775 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
1776 printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
1779 printf("pid1 successfully read the range 130:4\n");
1782 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
1783 printf("pid1 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
1786 printf("pid1 successfully wrote to the range 130:4\n");
1789 cli1->session->pid = 2;
1791 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
1792 printf("pid2 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
1793 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
1794 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
1798 printf("pid2 successfully read the range 130:4 (should be denied)\n");
1802 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
1803 printf("pid2 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
1804 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
1805 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
1809 printf("pid2 successfully wrote to the range 130:4 (should be denied)\n");
1813 cli_unlock(cli1, fnum1, 130, 0);
1817 cli_close(cli1, fnum1);
1818 cli_unlink(cli1, fname);
1819 torture_close_connection(cli1);
1821 printf("finished locktest7\n");
1826 test whether fnums and tids open on one VC are available on another (a major
1829 static BOOL run_fdpasstest(int dummy)
1831 struct cli_state *cli1, *cli2;
1832 const char *fname = "\\fdpass.tst";
1836 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
1840 printf("starting fdpasstest\n");
1842 cli_unlink(cli1, fname);
1844 printf("Opening a file on connection 1\n");
1846 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1848 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
1852 printf("writing to file on connection 1\n");
1854 if (cli_write(cli1, fnum1, 0, "hello world\n", 0, 13) != 13) {
1855 printf("write failed (%s)\n", cli_errstr(cli1));
1859 oldtid = cli2->tree->tid;
1860 cli2->session->vuid = cli1->session->vuid;
1861 cli2->tree->tid = cli1->tree->tid;
1862 cli2->session->pid = cli1->session->pid;
1864 printf("reading from file on connection 2\n");
1866 if (cli_read(cli2, fnum1, buf, 0, 13) == 13) {
1867 printf("read succeeded! nasty security hole [%s]\n",
1872 cli_close(cli1, fnum1);
1873 cli_unlink(cli1, fname);
1875 cli2->tree->tid = oldtid;
1877 torture_close_connection(cli1);
1878 torture_close_connection(cli2);
1880 printf("finished fdpasstest\n");
1886 This test checks that
1888 1) the server does not allow an unlink on a file that is open
1890 static BOOL run_unlinktest(int dummy)
1892 struct cli_state *cli;
1893 const char *fname = "\\unlink.tst";
1895 BOOL correct = True;
1897 if (!torture_open_connection(&cli)) {
1901 printf("starting unlink test\n");
1903 cli_unlink(cli, fname);
1905 cli->session->pid = 1;
1907 printf("Opening a file\n");
1909 fnum = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1911 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
1915 printf("Unlinking a open file\n");
1917 if (cli_unlink(cli, fname)) {
1918 printf("error: server allowed unlink on an open file\n");
1921 correct = check_error(__LINE__, cli, ERRDOS, ERRbadshare,
1922 NT_STATUS_SHARING_VIOLATION);
1925 cli_close(cli, fnum);
1926 cli_unlink(cli, fname);
1928 if (!torture_close_connection(cli)) {
1932 printf("unlink test finished\n");
1939 test how many open files this server supports on the one socket
1941 static BOOL run_maxfidtest(int dummy)
1943 struct cli_state *cli;
1944 const char *template = "\\maxfid.%d.%d";
1946 int fnums[0x11000], i;
1948 BOOL correct = True;
1953 printf("failed to connect\n");
1957 printf("Testing maximum number of open files\n");
1959 for (i=0; i<0x11000; i++) {
1960 asprintf(&fname, template, i,(int)getpid());
1961 if ((fnums[i] = cli_open(cli, fname,
1962 O_RDWR|O_CREAT|O_TRUNC, DENY_NONE)) ==
1964 printf("open of %s failed (%s)\n",
1965 fname, cli_errstr(cli));
1966 printf("maximum fnum is %d\n", i);
1975 printf("cleaning up\n");
1977 asprintf(&fname, template, i,(int)getpid());
1978 if (!cli_close(cli, fnums[i])) {
1979 printf("Close of fnum %d failed - %s\n", fnums[i], cli_errstr(cli));
1981 if (!cli_unlink(cli, fname)) {
1982 printf("unlink of %s failed (%s)\n",
1983 fname, cli_errstr(cli));
1991 printf("maxfid test finished\n");
1992 if (!torture_close_connection(cli)) {
1998 /* send smb negprot commands, not reading the response */
1999 static BOOL run_negprot_nowait(int dummy)
2002 struct cli_state *cli;
2003 BOOL correct = True;
2005 printf("starting negprot nowait test\n");
2007 cli = open_nbt_connection();
2012 printf("Establishing protocol negotiations - connect with another client\n");
2014 for (i=0;i<50000;i++) {
2015 smb_negprot_send(cli->transport, PROTOCOL_NT1);
2018 if (!torture_close_connection(cli)) {
2022 printf("finished negprot nowait test\n");
2029 This checks how the getatr calls works
2031 static BOOL run_attrtest(int dummy)
2033 struct cli_state *cli;
2036 const char *fname = "\\attrib123456789.tst";
2037 BOOL correct = True;
2039 printf("starting attrib test\n");
2041 if (!torture_open_connection(&cli)) {
2045 cli_unlink(cli, fname);
2046 fnum = cli_open(cli, fname,
2047 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2048 cli_close(cli, fnum);
2050 if (!cli_getatr(cli, fname, NULL, NULL, &t)) {
2051 printf("getatr failed (%s)\n", cli_errstr(cli));
2055 printf("New file time is %s", ctime(&t));
2057 if (abs(t - time(NULL)) > 60*60*24*10) {
2058 printf("ERROR: SMBgetatr bug. time is %s",
2064 t2 = t-60*60*24; /* 1 day ago */
2066 printf("Setting file time to %s", ctime(&t2));
2068 if (!cli_setatr(cli, fname, 0, t2)) {
2069 printf("setatr failed (%s)\n", cli_errstr(cli));
2073 if (!cli_getatr(cli, fname, NULL, NULL, &t)) {
2074 printf("getatr failed (%s)\n", cli_errstr(cli));
2078 printf("Retrieved file time as %s", ctime(&t));
2081 printf("ERROR: getatr/setatr bug. times are\n%s",
2083 printf("%s", ctime(&t2));
2087 cli_unlink(cli, fname);
2089 if (!torture_close_connection(cli)) {
2093 printf("attrib test finished\n");
2100 This checks a couple of trans2 calls
2102 static BOOL run_trans2test(int dummy)
2104 struct cli_state *cli;
2107 time_t c_time, a_time, m_time, w_time, m_time2;
2108 const char *fname = "\\trans2.tst";
2109 const char *dname = "\\trans2";
2110 const char *fname2 = "\\trans2\\trans2.tst";
2112 BOOL correct = True;
2114 printf("starting trans2 test\n");
2116 if (!torture_open_connection(&cli)) {
2120 cli_unlink(cli, fname);
2122 printf("Testing qfileinfo\n");
2124 fnum = cli_open(cli, fname,
2125 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2126 if (!cli_qfileinfo(cli, fnum, NULL, &size, &c_time, &a_time, &m_time,
2128 printf("ERROR: qfileinfo failed (%s)\n", cli_errstr(cli));
2132 printf("Testing NAME_INFO\n");
2134 if (!cli_qfilename(cli, fnum, &pname)) {
2135 printf("ERROR: qfilename failed (%s)\n", cli_errstr(cli));
2139 if (!pname || strcmp(pname, fname)) {
2140 printf("qfilename gave different name? [%s] [%s]\n",
2145 cli_close(cli, fnum);
2146 cli_unlink(cli, fname);
2148 fnum = cli_open(cli, fname,
2149 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2151 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
2154 cli_close(cli, fnum);
2156 printf("Checking for sticky create times\n");
2158 if (!cli_qpathinfo(cli, fname, &c_time, &a_time, &m_time, &size, NULL)) {
2159 printf("ERROR: qpathinfo failed (%s)\n", cli_errstr(cli));
2162 if (c_time != m_time) {
2163 printf("create time=%s", ctime(&c_time));
2164 printf("modify time=%s", ctime(&m_time));
2165 printf("This system appears to have sticky create times\n");
2167 if (a_time % (60*60) == 0) {
2168 printf("access time=%s", ctime(&a_time));
2169 printf("This system appears to set a midnight access time\n");
2173 if (abs(m_time - time(NULL)) > 60*60*24*7) {
2174 printf("ERROR: totally incorrect times - maybe word reversed? mtime=%s", ctime(&m_time));
2180 cli_unlink(cli, fname);
2181 fnum = cli_open(cli, fname,
2182 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2183 cli_close(cli, fnum);
2184 if (!cli_qpathinfo2(cli, fname, &c_time, &a_time, &m_time,
2185 &w_time, &size, NULL, NULL)) {
2186 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli));
2189 if (w_time < 60*60*24*2) {
2190 printf("write time=%s", ctime(&w_time));
2191 printf("This system appears to set a initial 0 write time\n");
2196 cli_unlink(cli, fname);
2199 /* check if the server updates the directory modification time
2200 when creating a new file */
2201 if (!cli_mkdir(cli, dname)) {
2202 printf("ERROR: mkdir failed (%s)\n", cli_errstr(cli));
2206 if (!cli_qpathinfo2(cli, "\\trans2\\", &c_time, &a_time, &m_time,
2207 &w_time, &size, NULL, NULL)) {
2208 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli));
2212 fnum = cli_open(cli, fname2,
2213 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2214 cli_write(cli, fnum, 0, (char *)&fnum, 0, sizeof(fnum));
2215 cli_close(cli, fnum);
2216 if (!cli_qpathinfo2(cli, "\\trans2\\", &c_time, &a_time, &m_time2,
2217 &w_time, &size, NULL, NULL)) {
2218 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli));
2221 if (m_time2 == m_time) {
2222 printf("This system does not update directory modification times\n");
2226 cli_unlink(cli, fname2);
2227 cli_rmdir(cli, dname);
2229 if (!torture_close_connection(cli)) {
2233 printf("trans2 test finished\n");
2239 Test delete on close semantics.
2241 static BOOL run_deletetest(int dummy)
2243 struct cli_state *cli1;
2244 struct cli_state *cli2 = NULL;
2245 const char *fname = "\\delete.file";
2248 BOOL correct = True;
2250 printf("starting delete test\n");
2252 if (!torture_open_connection(&cli1)) {
2256 /* Test 1 - this should delete the file on close. */
2258 cli_setatr(cli1, fname, 0, 0);
2259 cli_unlink(cli1, fname);
2261 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_RIGHTS_FILE_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL,
2262 NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OVERWRITE_IF,
2263 NTCREATEX_OPTIONS_DELETE_ON_CLOSE, 0);
2266 printf("[1] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2271 if (!cli_close(cli1, fnum1)) {
2272 printf("[1] close failed (%s)\n", cli_errstr(cli1));
2277 fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
2279 printf("[1] open of %s succeeded (should fail)\n", fname);
2284 printf("first delete on close test succeeded.\n");
2286 /* Test 2 - this should delete the file on close. */
2288 cli_setatr(cli1, fname, 0, 0);
2289 cli_unlink(cli1, fname);
2291 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_RIGHTS_FILE_ALL_ACCESS,
2292 FILE_ATTRIBUTE_NORMAL, NTCREATEX_SHARE_ACCESS_NONE,
2293 NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
2296 printf("[2] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2301 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
2302 printf("[2] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
2307 if (!cli_close(cli1, fnum1)) {
2308 printf("[2] close failed (%s)\n", cli_errstr(cli1));
2313 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
2315 printf("[2] open of %s succeeded should have been deleted on close !\n", fname);
2316 if (!cli_close(cli1, fnum1)) {
2317 printf("[2] close failed (%s)\n", cli_errstr(cli1));
2321 cli_unlink(cli1, fname);
2323 printf("second delete on close test succeeded.\n");
2326 cli_setatr(cli1, fname, 0, 0);
2327 cli_unlink(cli1, fname);
2329 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_RIGHTS_FILE_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL,
2330 NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
2333 printf("[3] open - 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
2338 /* This should fail with a sharing violation - open for delete is only compatible
2339 with SHARE_DELETE. */
2341 fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_RIGHTS_FILE_READ, FILE_ATTRIBUTE_NORMAL,
2342 NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE,
2343 NTCREATEX_DISP_OPEN, 0, 0);
2346 printf("[3] open - 2 of %s succeeded - should have failed.\n", fname);
2351 /* This should succeed. */
2353 fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_RIGHTS_FILE_READ, FILE_ATTRIBUTE_NORMAL,
2354 NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE|NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OPEN, 0, 0);
2357 printf("[3] open - 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
2362 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
2363 printf("[3] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
2368 if (!cli_close(cli1, fnum1)) {
2369 printf("[3] close 1 failed (%s)\n", cli_errstr(cli1));
2374 if (!cli_close(cli1, fnum2)) {
2375 printf("[3] close 2 failed (%s)\n", cli_errstr(cli1));
2380 /* This should fail - file should no longer be there. */
2382 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
2384 printf("[3] open of %s succeeded should have been deleted on close !\n", fname);
2385 if (!cli_close(cli1, fnum1)) {
2386 printf("[3] close failed (%s)\n", cli_errstr(cli1));
2388 cli_unlink(cli1, fname);
2392 printf("third delete on close test succeeded.\n");
2395 cli_setatr(cli1, fname, 0, 0);
2396 cli_unlink(cli1, fname);
2398 fnum1 = cli_nt_create_full(cli1, fname, 0,
2399 SA_RIGHT_FILE_READ_DATA |
2400 SA_RIGHT_FILE_WRITE_DATA |
2401 STD_RIGHT_DELETE_ACCESS,
2402 FILE_ATTRIBUTE_NORMAL,
2403 NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE,
2404 NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
2407 printf("[4] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2412 /* This should succeed. */
2413 fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_RIGHTS_FILE_READ,
2414 FILE_ATTRIBUTE_NORMAL,
2415 NTCREATEX_SHARE_ACCESS_READ |
2416 NTCREATEX_SHARE_ACCESS_WRITE |
2417 NTCREATEX_SHARE_ACCESS_DELETE,
2418 NTCREATEX_DISP_OPEN, 0, 0);
2420 printf("[4] open - 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
2425 if (!cli_close(cli1, fnum2)) {
2426 printf("[4] close - 1 failed (%s)\n", cli_errstr(cli1));
2431 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
2432 printf("[4] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
2437 /* This should fail - no more opens once delete on close set. */
2438 fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_RIGHTS_FILE_READ,
2439 FILE_ATTRIBUTE_NORMAL, NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE|NTCREATEX_SHARE_ACCESS_DELETE,
2440 NTCREATEX_DISP_OPEN, 0, 0);
2442 printf("[4] open - 3 of %s succeeded ! Should have failed.\n", fname );
2446 printf("fourth delete on close test succeeded.\n");
2448 if (!cli_close(cli1, fnum1)) {
2449 printf("[4] close - 2 failed (%s)\n", cli_errstr(cli1));
2455 cli_setatr(cli1, fname, 0, 0);
2456 cli_unlink(cli1, fname);
2458 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT, DENY_NONE);
2460 printf("[5] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2465 /* This should fail - only allowed on NT opens with DELETE access. */
2467 if (cli_nt_delete_on_close(cli1, fnum1, True)) {
2468 printf("[5] setting delete_on_close on OpenX file succeeded - should fail !\n");
2473 if (!cli_close(cli1, fnum1)) {
2474 printf("[5] close - 2 failed (%s)\n", cli_errstr(cli1));
2479 printf("fifth delete on close test succeeded.\n");
2482 cli_setatr(cli1, fname, 0, 0);
2483 cli_unlink(cli1, fname);
2485 fnum1 = cli_nt_create_full(cli1, fname, 0,
2486 SA_RIGHT_FILE_READ_DATA | SA_RIGHT_FILE_WRITE_DATA,
2487 FILE_ATTRIBUTE_NORMAL,
2488 NTCREATEX_SHARE_ACCESS_READ |
2489 NTCREATEX_SHARE_ACCESS_WRITE |
2490 NTCREATEX_SHARE_ACCESS_DELETE,
2491 NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
2494 printf("[6] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2499 /* This should fail - only allowed on NT opens with DELETE access. */
2501 if (cli_nt_delete_on_close(cli1, fnum1, True)) {
2502 printf("[6] setting delete_on_close on file with no delete access succeeded - should fail !\n");
2507 if (!cli_close(cli1, fnum1)) {
2508 printf("[6] close - 2 failed (%s)\n", cli_errstr(cli1));
2513 printf("sixth delete on close test succeeded.\n");
2516 cli_setatr(cli1, fname, 0, 0);
2517 cli_unlink(cli1, fname);
2519 fnum1 = cli_nt_create_full(cli1, fname, 0,
2520 SA_RIGHT_FILE_READ_DATA |
2521 SA_RIGHT_FILE_WRITE_DATA |
2522 STD_RIGHT_DELETE_ACCESS,
2523 FILE_ATTRIBUTE_NORMAL, 0, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
2526 printf("[7] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2531 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
2532 printf("[7] setting delete_on_close on file failed !\n");
2537 if (!cli_nt_delete_on_close(cli1, fnum1, False)) {
2538 printf("[7] unsetting delete_on_close on file failed !\n");
2543 if (!cli_close(cli1, fnum1)) {
2544 printf("[7] close - 2 failed (%s)\n", cli_errstr(cli1));
2549 /* This next open should succeed - we reset the flag. */
2551 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
2553 printf("[5] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2558 if (!cli_close(cli1, fnum1)) {
2559 printf("[7] close - 2 failed (%s)\n", cli_errstr(cli1));
2564 printf("seventh delete on close test succeeded.\n");
2567 cli_setatr(cli1, fname, 0, 0);
2568 cli_unlink(cli1, fname);
2570 if (!torture_open_connection(&cli2)) {
2571 printf("[8] failed to open second connection.\n");
2576 fnum1 = cli_nt_create_full(cli1, fname, 0, SA_RIGHT_FILE_READ_DATA|SA_RIGHT_FILE_WRITE_DATA|STD_RIGHT_DELETE_ACCESS,
2577 FILE_ATTRIBUTE_NORMAL, NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE|NTCREATEX_SHARE_ACCESS_DELETE,
2578 NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
2581 printf("[8] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2586 fnum2 = cli_nt_create_full(cli2, fname, 0, SA_RIGHT_FILE_READ_DATA|SA_RIGHT_FILE_WRITE_DATA|STD_RIGHT_DELETE_ACCESS,
2587 FILE_ATTRIBUTE_NORMAL, NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE|NTCREATEX_SHARE_ACCESS_DELETE,
2588 NTCREATEX_DISP_OPEN, 0, 0);
2591 printf("[8] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2596 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
2597 printf("[8] setting delete_on_close on file failed !\n");
2602 if (!cli_close(cli1, fnum1)) {
2603 printf("[8] close - 1 failed (%s)\n", cli_errstr(cli1));
2608 if (!cli_close(cli2, fnum2)) {
2609 printf("[8] close - 2 failed (%s)\n", cli_errstr(cli2));
2614 /* This should fail.. */
2615 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
2617 printf("[8] open of %s succeeded should have been deleted on close !\n", fname);
2621 printf("eighth delete on close test succeeded.\n");
2623 /* This should fail - we need to set DELETE_ACCESS. */
2624 fnum1 = cli_nt_create_full(cli1, fname, 0,SA_RIGHT_FILE_READ_DATA|SA_RIGHT_FILE_WRITE_DATA,
2625 FILE_ATTRIBUTE_NORMAL, NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, NTCREATEX_OPTIONS_DELETE_ON_CLOSE, 0);
2628 printf("[9] open of %s succeeded should have failed!\n", fname);
2633 printf("ninth delete on close test succeeded.\n");
2635 fnum1 = cli_nt_create_full(cli1, fname, 0, SA_RIGHT_FILE_READ_DATA|SA_RIGHT_FILE_WRITE_DATA|STD_RIGHT_DELETE_ACCESS,
2636 FILE_ATTRIBUTE_NORMAL, NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, NTCREATEX_OPTIONS_DELETE_ON_CLOSE, 0);
2638 printf("[10] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2643 /* This should delete the file. */
2644 if (!cli_close(cli1, fnum1)) {
2645 printf("[10] close failed (%s)\n", cli_errstr(cli1));
2650 /* This should fail.. */
2651 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
2653 printf("[10] open of %s succeeded should have been deleted on close !\n", fname);
2657 printf("tenth delete on close test succeeded.\n");
2658 printf("finished delete test\n");
2661 /* FIXME: This will crash if we aborted before cli2 got
2662 * intialized, because these functions don't handle
2663 * uninitialized connections. */
2665 cli_close(cli1, fnum1);
2666 cli_close(cli1, fnum2);
2667 cli_setatr(cli1, fname, 0, 0);
2668 cli_unlink(cli1, fname);
2670 if (!torture_close_connection(cli1)) {
2673 if (!torture_close_connection(cli2)) {
2681 print out server properties
2683 static BOOL run_properties(int dummy)
2685 struct cli_state *cli;
2686 BOOL correct = True;
2688 printf("starting properties test\n");
2692 if (!torture_open_connection(&cli)) {
2696 d_printf("Capabilities 0x%08x\n", cli->transport->negotiate.capabilities);
2698 if (!torture_close_connection(cli)) {
2707 /* FIRST_DESIRED_ACCESS 0xf019f */
2708 #define FIRST_DESIRED_ACCESS SA_RIGHT_FILE_READ_DATA|SA_RIGHT_FILE_WRITE_DATA|SA_RIGHT_FILE_APPEND_DATA|\
2709 SA_RIGHT_FILE_READ_EA| /* 0xf */ \
2710 SA_RIGHT_FILE_WRITE_EA|SA_RIGHT_FILE_READ_ATTRIBUTES| /* 0x90 */ \
2711 SA_RIGHT_FILE_WRITE_ATTRIBUTES| /* 0x100 */ \
2712 STD_RIGHT_DELETE_ACCESS|STD_RIGHT_READ_CONTROL_ACCESS|\
2713 STD_RIGHT_WRITE_DAC_ACCESS|STD_RIGHT_WRITE_OWNER_ACCESS /* 0xf0000 */
2714 /* SECOND_DESIRED_ACCESS 0xe0080 */
2715 #define SECOND_DESIRED_ACCESS SA_RIGHT_FILE_READ_ATTRIBUTES| /* 0x80 */ \
2716 STD_RIGHT_READ_CONTROL_ACCESS|STD_RIGHT_WRITE_DAC_ACCESS|\
2717 STD_RIGHT_WRITE_OWNER_ACCESS /* 0xe0000 */
2720 #define THIRD_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
2721 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
2722 SA_RIGHT_FILE_READ_DATA|\
2723 WRITE_OWNER_ACCESS /* */
2727 Test ntcreate calls made by xcopy
2729 static BOOL run_xcopy(int dummy)
2731 struct cli_state *cli1;
2732 const char *fname = "\\test.txt";
2733 BOOL correct = True;
2736 printf("starting xcopy test\n");
2738 if (!torture_open_connection(&cli1)) {
2742 fnum1 = cli_nt_create_full(cli1, fname, 0,
2743 FIRST_DESIRED_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
2744 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF,
2748 printf("First open failed - %s\n", cli_errstr(cli1));
2752 fnum2 = cli_nt_create_full(cli1, fname, 0,
2753 SECOND_DESIRED_ACCESS, 0,
2754 NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE|NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OPEN,
2757 printf("second open failed - %s\n", cli_errstr(cli1));
2761 if (!torture_close_connection(cli1)) {
2769 Test rename on files open with share delete and no share delete.
2771 static BOOL run_rename(int dummy)
2773 struct cli_state *cli1;
2774 const char *fname = "\\test.txt";
2775 const char *fname1 = "\\test1.txt";
2776 BOOL correct = True;
2779 printf("starting rename test\n");
2781 if (!torture_open_connection(&cli1)) {
2785 cli_unlink(cli1, fname);
2786 cli_unlink(cli1, fname1);
2787 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_RIGHTS_FILE_READ, FILE_ATTRIBUTE_NORMAL,
2788 NTCREATEX_SHARE_ACCESS_READ, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
2791 printf("First open failed - %s\n", cli_errstr(cli1));
2795 if (!cli_rename(cli1, fname, fname1)) {
2796 printf("First rename failed (this is correct) - %s\n", cli_errstr(cli1));
2798 printf("First rename succeeded - this should have failed !\n");
2802 if (!cli_close(cli1, fnum1)) {
2803 printf("close - 1 failed (%s)\n", cli_errstr(cli1));
2807 cli_unlink(cli1, fname);
2808 cli_unlink(cli1, fname1);
2809 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_RIGHTS_FILE_READ, FILE_ATTRIBUTE_NORMAL,
2811 NTCREATEX_SHARE_ACCESS_DELETE|NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
2813 NTCREATEX_SHARE_ACCESS_DELETE|NTCREATEX_SHARE_ACCESS_READ, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
2817 printf("Second open failed - %s\n", cli_errstr(cli1));
2821 if (!cli_rename(cli1, fname, fname1)) {
2822 printf("Second rename failed - this should have succeeded - %s\n", cli_errstr(cli1));
2825 printf("Second rename succeeded\n");
2828 if (!cli_close(cli1, fnum1)) {
2829 printf("close - 2 failed (%s)\n", cli_errstr(cli1));
2833 cli_unlink(cli1, fname);
2834 cli_unlink(cli1, fname1);
2836 fnum1 = cli_nt_create_full(cli1, fname, 0, STD_RIGHT_READ_CONTROL_ACCESS, FILE_ATTRIBUTE_NORMAL,
2837 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
2840 printf("Third open failed - %s\n", cli_errstr(cli1));
2849 fnum2 = cli_nt_create_full(cli1, fname, 0, DELETE_ACCESS, FILE_ATTRIBUTE_NORMAL,
2850 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
2853 printf("Fourth open failed - %s\n", cli_errstr(cli1));
2856 if (!cli_nt_delete_on_close(cli1, fnum2, True)) {
2857 printf("[8] setting delete_on_close on file failed !\n");
2861 if (!cli_close(cli1, fnum2)) {
2862 printf("close - 4 failed (%s)\n", cli_errstr(cli1));
2868 if (!cli_rename(cli1, fname, fname1)) {
2869 printf("Third rename failed - this should have succeeded - %s\n", cli_errstr(cli1));
2872 printf("Third rename succeeded\n");
2875 if (!cli_close(cli1, fnum1)) {
2876 printf("close - 3 failed (%s)\n", cli_errstr(cli1));
2880 cli_unlink(cli1, fname);
2881 cli_unlink(cli1, fname1);
2883 if (!torture_close_connection(cli1)) {
2890 static BOOL run_pipe_number(int dummy)
2892 struct cli_state *cli1;
2893 const char *pipe_name = "\\WKSSVC";
2897 printf("starting pipenumber test\n");
2898 if (!torture_open_connection(&cli1)) {
2903 fnum = cli_nt_create_full(cli1, pipe_name, 0, SA_RIGHT_FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
2904 NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE, NTCREATEX_DISP_OPEN_IF, 0, 0);
2907 printf("Open of pipe %s failed with error (%s)\n", pipe_name, cli_errstr(cli1));
2913 printf("pipe_number test - we can open %d %s pipes.\n", num_pipes, pipe_name );
2914 torture_close_connection(cli1);
2920 Test open mode returns on read-only files.
2922 static BOOL run_opentest(int dummy)
2924 static struct cli_state *cli1;
2925 static struct cli_state *cli2;
2926 const char *fname = "\\readonly.file";
2930 BOOL correct = True;
2934 printf("starting open test\n");
2936 if (!torture_open_connection(&cli1)) {
2940 cli_setatr(cli1, fname, 0, 0);
2941 cli_unlink(cli1, fname);
2943 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2945 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
2949 if (!cli_close(cli1, fnum1)) {
2950 printf("close2 failed (%s)\n", cli_errstr(cli1));
2954 if (!cli_setatr(cli1, fname, FILE_ATTRIBUTE_READONLY, 0)) {
2955 printf("cli_setatr failed (%s)\n", cli_errstr(cli1));
2956 CHECK_MAX_FAILURES(error_test1);
2960 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_WRITE);
2962 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
2963 CHECK_MAX_FAILURES(error_test1);
2967 /* This will fail - but the error should be ERRnoaccess, not ERRbadshare. */
2968 fnum2 = cli_open(cli1, fname, O_RDWR, DENY_ALL);
2970 if (check_error(__LINE__, cli1, ERRDOS, ERRnoaccess,
2971 NT_STATUS_ACCESS_DENIED)) {
2972 printf("correct error code ERRDOS/ERRnoaccess returned\n");
2975 printf("finished open test 1\n");
2977 cli_close(cli1, fnum1);
2979 /* Now try not readonly and ensure ERRbadshare is returned. */
2981 cli_setatr(cli1, fname, 0, 0);
2983 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_WRITE);
2985 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
2989 /* This will fail - but the error should be ERRshare. */
2990 fnum2 = cli_open(cli1, fname, O_RDWR, DENY_ALL);
2992 if (check_error(__LINE__, cli1, ERRDOS, ERRbadshare,
2993 NT_STATUS_SHARING_VIOLATION)) {
2994 printf("correct error code ERRDOS/ERRbadshare returned\n");
2997 if (!cli_close(cli1, fnum1)) {
2998 printf("close2 failed (%s)\n", cli_errstr(cli1));
3002 cli_unlink(cli1, fname);
3004 printf("finished open test 2\n");
3006 /* Test truncate open disposition on file opened for read. */
3008 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
3010 printf("(3) open (1) of %s failed (%s)\n", fname, cli_errstr(cli1));
3014 /* write 20 bytes. */
3016 memset(buf, '\0', 20);
3018 if (cli_write(cli1, fnum1, 0, buf, 0, 20) != 20) {
3019 printf("write failed (%s)\n", cli_errstr(cli1));
3023 if (!cli_close(cli1, fnum1)) {
3024 printf("(3) close1 failed (%s)\n", cli_errstr(cli1));
3028 /* Ensure size == 20. */
3029 if (!cli_getatr(cli1, fname, NULL, &fsize, NULL)) {
3030 printf("(3) getatr failed (%s)\n", cli_errstr(cli1));
3031 CHECK_MAX_FAILURES(error_test3);
3036 printf("(3) file size != 20\n");
3037 CHECK_MAX_FAILURES(error_test3);
3041 /* Now test if we can truncate a file opened for readonly. */
3043 fnum1 = cli_open(cli1, fname, O_RDONLY|O_TRUNC, DENY_NONE);
3045 printf("(3) open (2) of %s failed (%s)\n", fname, cli_errstr(cli1));
3046 CHECK_MAX_FAILURES(error_test3);
3050 if (!cli_close(cli1, fnum1)) {
3051 printf("close2 failed (%s)\n", cli_errstr(cli1));
3055 /* Ensure size == 0. */
3056 if (!cli_getatr(cli1, fname, NULL, &fsize, NULL)) {
3057 printf("(3) getatr failed (%s)\n", cli_errstr(cli1));
3058 CHECK_MAX_FAILURES(error_test3);
3063 printf("(3) file size != 0\n");
3064 CHECK_MAX_FAILURES(error_test3);
3067 printf("finished open test 3\n");
3069 cli_unlink(cli1, fname);
3072 printf("testing ctemp\n");
3073 fnum1 = cli_ctemp(cli1, "\\", &tmp_path);
3075 printf("ctemp failed (%s)\n", cli_errstr(cli1));
3076 CHECK_MAX_FAILURES(error_test4);
3079 printf("ctemp gave path %s\n", tmp_path);
3080 if (!cli_close(cli1, fnum1)) {
3081 printf("close of temp failed (%s)\n", cli_errstr(cli1));
3083 if (!cli_unlink(cli1, tmp_path)) {
3084 printf("unlink of temp failed (%s)\n", cli_errstr(cli1));
3087 /* Test the non-io opens... */
3089 if (!torture_open_connection(&cli2)) {
3093 cli_setatr(cli2, fname, 0, 0);
3094 cli_unlink(cli2, fname);
3096 printf("TEST #1 testing 2 non-io opens (no delete)\n");
3098 fnum1 = cli_nt_create_full(cli1, fname, 0, SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3099 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
3102 printf("test 1 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3103 CHECK_MAX_FAILURES(error_test10);
3107 fnum2 = cli_nt_create_full(cli2, fname, 0, SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3108 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OPEN_IF, 0, 0);
3110 printf("test 1 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3111 CHECK_MAX_FAILURES(error_test10);
3115 if (!cli_close(cli1, fnum1)) {
3116 printf("test 1 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3119 if (!cli_close(cli2, fnum2)) {
3120 printf("test 1 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3124 printf("non-io open test #1 passed.\n");
3126 cli_unlink(cli1, fname);
3128 printf("TEST #2 testing 2 non-io opens (first with delete)\n");
3130 fnum1 = cli_nt_create_full(cli1, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3131 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
3134 printf("test 2 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3135 CHECK_MAX_FAILURES(error_test20);
3139 fnum2 = cli_nt_create_full(cli2, fname, 0, SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3140 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OPEN_IF, 0, 0);
3143 printf("test 2 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3144 CHECK_MAX_FAILURES(error_test20);
3148 if (!cli_close(cli1, fnum1)) {
3149 printf("test 1 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3152 if (!cli_close(cli2, fnum2)) {
3153 printf("test 1 close 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
3157 printf("non-io open test #2 passed.\n");
3159 cli_unlink(cli1, fname);
3161 printf("TEST #3 testing 2 non-io opens (second with delete)\n");
3163 fnum1 = cli_nt_create_full(cli1, fname, 0, SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3164 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
3167 printf("test 3 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3168 CHECK_MAX_FAILURES(error_test30);
3172 fnum2 = cli_nt_create_full(cli2, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3173 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OPEN_IF, 0, 0);
3176 printf("test 3 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3177 CHECK_MAX_FAILURES(error_test30);
3181 if (!cli_close(cli1, fnum1)) {
3182 printf("test 3 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3185 if (!cli_close(cli2, fnum2)) {
3186 printf("test 3 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3190 printf("non-io open test #3 passed.\n");
3192 cli_unlink(cli1, fname);
3194 printf("TEST #4 testing 2 non-io opens (both with delete)\n");
3196 fnum1 = cli_nt_create_full(cli1, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3197 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
3200 printf("test 4 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3201 CHECK_MAX_FAILURES(error_test40);
3205 fnum2 = cli_nt_create_full(cli2, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3206 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OPEN_IF, 0, 0);
3209 printf("test 4 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, cli_errstr(cli2));
3210 CHECK_MAX_FAILURES(error_test40);
3214 printf("test 4 open 2 of %s gave %s (correct error should be %s)\n", fname, cli_errstr(cli2), "sharing violation");
3216 if (!cli_close(cli1, fnum1)) {
3217 printf("test 4 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3221 printf("non-io open test #4 passed.\n");
3223 cli_unlink(cli1, fname);
3225 printf("TEST #5 testing 2 non-io opens (both with delete - both with file share delete)\n");
3227 fnum1 = cli_nt_create_full(cli1, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3228 NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
3231 printf("test 5 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3232 CHECK_MAX_FAILURES(error_test50);
3236 fnum2 = cli_nt_create_full(cli2, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3237 NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OPEN_IF, 0, 0);
3240 printf("test 5 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3241 CHECK_MAX_FAILURES(error_test50);
3245 if (!cli_close(cli1, fnum1)) {
3246 printf("test 5 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3250 if (!cli_close(cli2, fnum2)) {
3251 printf("test 5 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3255 printf("non-io open test #5 passed.\n");
3257 printf("TEST #6 testing 1 non-io open, one io open\n");
3259 cli_unlink(cli1, fname);
3261 fnum1 = cli_nt_create_full(cli1, fname, 0, SA_RIGHT_FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
3262 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
3265 printf("test 6 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3266 CHECK_MAX_FAILURES(error_test60);
3270 fnum2 = cli_nt_create_full(cli2, fname, 0, SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3271 NTCREATEX_SHARE_ACCESS_READ, NTCREATEX_DISP_OPEN_IF, 0, 0);
3274 printf("test 6 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3275 CHECK_MAX_FAILURES(error_test60);
3279 if (!cli_close(cli1, fnum1)) {
3280 printf("test 6 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3284 if (!cli_close(cli2, fnum2)) {
3285 printf("test 6 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3289 printf("non-io open test #6 passed.\n");
3291 printf("TEST #7 testing 1 non-io open, one io open with delete\n");
3293 cli_unlink(cli1, fname);
3295 fnum1 = cli_nt_create_full(cli1, fname, 0, SA_RIGHT_FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
3296 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
3299 printf("test 7 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3300 CHECK_MAX_FAILURES(error_test70);
3304 fnum2 = cli_nt_create_full(cli2, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3305 NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OPEN_IF, 0, 0);
3308 printf("test 7 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, cli_errstr(cli2));
3309 CHECK_MAX_FAILURES(error_test70);
3313 printf("test 7 open 2 of %s gave %s (correct error should be %s)\n", fname, cli_errstr(cli2), "sharing violation");
3315 if (!cli_close(cli1, fnum1)) {
3316 printf("test 7 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3320 printf("non-io open test #7 passed.\n");
3322 cli_unlink(cli1, fname);
3324 if (!torture_close_connection(cli1)) {
3327 if (!torture_close_connection(cli2)) {
3335 static uint32 open_attrs_table[] = {
3336 FILE_ATTRIBUTE_NORMAL,
3337 FILE_ATTRIBUTE_ARCHIVE,
3338 FILE_ATTRIBUTE_READONLY,
3339 FILE_ATTRIBUTE_HIDDEN,
3340 FILE_ATTRIBUTE_SYSTEM,
3342 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY,
3343 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN,
3344 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM,
3345 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN,
3346 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM,
3347 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM,
3349 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN,
3350 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM,
3351 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM,
3352 FILE_ATTRIBUTE_HIDDEN,FILE_ATTRIBUTE_SYSTEM,
3355 struct trunc_open_results {
3362 static struct trunc_open_results attr_results[] = {
3363 { 0, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE },
3364 { 1, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE },
3365 { 2, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_READONLY, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY },
3366 { 16, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE },
3367 { 17, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE },
3368 { 18, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_READONLY, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY },
3369 { 51, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
3370 { 54, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
3371 { 56, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN },
3372 { 68, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
3373 { 71, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
3374 { 73, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM },
3375 { 99, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN,FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
3376 { 102, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
3377 { 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 },
3378 { 116, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
3379 { 119, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
3380 { 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 },
3381 { 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 },
3382 { 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 },
3383 { 227, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
3384 { 230, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
3385 { 232, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN },
3386 { 244, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
3387 { 247, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
3388 { 249, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM }
3391 static BOOL run_openattrtest(int dummy)
3393 struct cli_state *cli1;
3394 const char *fname = "\\openattr.file";
3396 BOOL correct = True;
3398 unsigned int i, j, k, l;
3401 printf("starting open attr test\n");
3403 if (!torture_open_connection(&cli1)) {
3407 for (k = 0, i = 0; i < sizeof(open_attrs_table)/sizeof(uint32); i++) {
3408 cli_setatr(cli1, fname, 0, 0);
3409 cli_unlink(cli1, fname);
3410 fnum1 = cli_nt_create_full(cli1, fname, 0, SA_RIGHT_FILE_WRITE_DATA, open_attrs_table[i],
3411 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
3414 printf("open %d (1) of %s failed (%s)\n", i, fname, cli_errstr(cli1));
3418 if (!cli_close(cli1, fnum1)) {
3419 printf("close %d (1) of %s failed (%s)\n", i, fname, cli_errstr(cli1));
3423 for (j = 0; j < ARRAY_SIZE(open_attrs_table); j++) {
3424 fnum1 = cli_nt_create_full(cli1, fname, 0,
3425 SA_RIGHT_FILE_READ_DATA|SA_RIGHT_FILE_WRITE_DATA,
3426 open_attrs_table[j],
3427 NTCREATEX_SHARE_ACCESS_NONE,
3428 NTCREATEX_DISP_OVERWRITE, 0, 0);
3431 for (l = 0; l < ARRAY_SIZE(attr_results); l++) {
3432 if (attr_results[l].num == k) {
3433 printf("[%d] trunc open 0x%x -> 0x%x of %s failed - should have succeeded !(0x%x:%s)\n",
3434 k, open_attrs_table[i],
3435 open_attrs_table[j],
3436 fname, NT_STATUS_V(cli_nt_error(cli1)), cli_errstr(cli1));
3438 CHECK_MAX_FAILURES(error_exit);
3441 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_ACCESS_DENIED)) {
3442 printf("[%d] trunc open 0x%x -> 0x%x failed with wrong error code %s\n",
3443 k, open_attrs_table[i], open_attrs_table[j],
3446 CHECK_MAX_FAILURES(error_exit);
3449 printf("[%d] trunc open 0x%x -> 0x%x failed\n", k, open_attrs_table[i], open_attrs_table[j]);
3455 if (!cli_close(cli1, fnum1)) {
3456 printf("close %d (2) of %s failed (%s)\n", j, fname, cli_errstr(cli1));
3460 if (!cli_getatr(cli1, fname, &attr, NULL, NULL)) {
3461 printf("getatr(2) failed (%s)\n", cli_errstr(cli1));
3466 printf("[%d] getatr check [0x%x] trunc [0x%x] got attr 0x%x\n",
3467 k, open_attrs_table[i], open_attrs_table[j], attr );
3470 for (l = 0; l < ARRAY_SIZE(attr_results); l++) {
3471 if (attr_results[l].num == k) {
3472 if (attr != attr_results[l].result_attr ||
3473 open_attrs_table[i] != attr_results[l].init_attr ||
3474 open_attrs_table[j] != attr_results[l].trunc_attr) {
3475 printf("[%d] getatr check failed. [0x%x] trunc [0x%x] got attr 0x%x, should be 0x%x\n",
3476 k, open_attrs_table[i],
3477 open_attrs_table[j],
3479 attr_results[l].result_attr);
3481 CHECK_MAX_FAILURES(error_exit);
3490 cli_setatr(cli1, fname, 0, 0);
3491 cli_unlink(cli1, fname);
3493 printf("open attr test %s.\n", correct ? "passed" : "failed");
3495 if (!torture_close_connection(cli1)) {
3501 static void list_fn(file_info *finfo, const char *name, void *state)
3507 test directory listing speed
3509 static BOOL run_dirtest(int dummy)
3512 struct cli_state *cli;
3515 BOOL correct = True;
3517 printf("starting directory test\n");
3519 if (!torture_open_connection(&cli)) {
3523 printf("Creating %d random filenames\n", torture_numops);
3526 for (i=0;i<torture_numops;i++) {
3528 asprintf(&fname, "\\%x", (int)random());
3529 fnum = cli_open(cli, fname, O_RDWR|O_CREAT, DENY_NONE);
3531 fprintf(stderr,"Failed to open %s\n", fname);
3534 cli_close(cli, fnum);
3540 printf("Matched %d\n", cli_list(cli, "a*.*", 0, list_fn, NULL));
3541 printf("Matched %d\n", cli_list(cli, "b*.*", 0, list_fn, NULL));
3542 printf("Matched %d\n", cli_list(cli, "xyzabc", 0, list_fn, NULL));
3544 printf("dirtest core %g seconds\n", end_timer() - t1);
3547 for (i=0;i<torture_numops;i++) {
3549 asprintf(&fname, "\\%x", (int)random());
3550 cli_unlink(cli, fname);
3554 if (!torture_close_connection(cli)) {
3558 printf("finished dirtest\n");
3563 static void del_fn(file_info *finfo, const char *mask, void *state)
3565 struct cli_state *pcli = (struct cli_state *)state;
3567 asprintf(&fname, "\\LISTDIR\\%s", finfo->name);
3569 if (strcmp(finfo->name, ".") == 0 || strcmp(finfo->name, "..") == 0)
3572 if (finfo->mode & FILE_ATTRIBUTE_DIRECTORY) {
3573 if (!cli_rmdir(pcli, fname))
3574 printf("del_fn: failed to rmdir %s, error=%s\n", fname, cli_errstr(pcli) );
3576 if (!cli_unlink(pcli, fname))
3577 printf("del_fn: failed to unlink %s, error=%s\n", fname, cli_errstr(pcli) );
3584 sees what IOCTLs are supported
3586 BOOL torture_ioctl_test(int dummy)
3588 struct cli_state *cli;
3589 uint16 device, function;
3591 const char *fname = "\\ioctl.dat";
3594 struct smb_ioctl parms;
3595 TALLOC_CTX *mem_ctx;
3597 if (!torture_open_connection(&cli)) {
3601 mem_ctx = talloc_init("ioctl_test");
3603 printf("starting ioctl test\n");
3605 cli_unlink(cli, fname);
3607 fnum = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
3609 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
3613 parms.in.request = IOCTL_QUERY_JOB_INFO;
3614 status = smb_raw_ioctl(cli->tree, mem_ctx, &parms);
3615 printf("ioctl job info: %s\n", cli_errstr(cli));
3617 for (device=0;device<0x100;device++) {
3618 printf("testing device=0x%x\n", device);
3619 for (function=0;function<0x100;function++) {
3620 parms.in.request = (device << 16) | function;
3621 status = smb_raw_ioctl(cli->tree, mem_ctx, &parms);
3623 if (NT_STATUS_IS_OK(status)) {
3624 printf("ioctl device=0x%x function=0x%x OK : %d bytes\n",
3625 device, function, blob.length);
3626 data_blob_free(&parms.out.blob);
3631 if (!torture_close_connection(cli)) {
3640 tries variants of chkpath
3642 BOOL torture_chkpath_test(int dummy)
3644 struct cli_state *cli;
3648 if (!torture_open_connection(&cli)) {
3652 printf("starting chkpath test\n");
3654 printf("Testing valid and invalid paths\n");
3656 /* cleanup from an old run */
3657 cli_rmdir(cli, "\\chkpath.dir\\dir2");
3658 cli_unlink(cli, "\\chkpath.dir\\*");
3659 cli_rmdir(cli, "\\chkpath.dir");
3661 if (!cli_mkdir(cli, "\\chkpath.dir")) {
3662 printf("mkdir1 failed : %s\n", cli_errstr(cli));
3666 if (!cli_mkdir(cli, "\\chkpath.dir\\dir2")) {
3667 printf("mkdir2 failed : %s\n", cli_errstr(cli));
3671 fnum = cli_open(cli, "\\chkpath.dir\\foo.txt", O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
3673 printf("open1 failed (%s)\n", cli_errstr(cli));
3676 cli_close(cli, fnum);
3678 if (!cli_chkpath(cli, "\\chkpath.dir")) {
3679 printf("chkpath1 failed: %s\n", cli_errstr(cli));
3683 if (!cli_chkpath(cli, "\\chkpath.dir\\dir2")) {
3684 printf("chkpath2 failed: %s\n", cli_errstr(cli));
3688 if (!cli_chkpath(cli, "\\chkpath.dir\\foo.txt")) {
3689 ret = check_error(__LINE__, cli, ERRDOS, ERRbadpath,
3690 NT_STATUS_NOT_A_DIRECTORY);
3692 printf("* chkpath on a file should fail\n");
3696 if (!cli_chkpath(cli, "\\chkpath.dir\\bar.txt")) {
3697 ret = check_error(__LINE__, cli, ERRDOS, ERRbadfile,
3698 NT_STATUS_OBJECT_NAME_NOT_FOUND);
3700 printf("* chkpath on a non existent file should fail\n");
3704 if (!cli_chkpath(cli, "\\chkpath.dir\\dirxx\\bar.txt")) {
3705 ret = check_error(__LINE__, cli, ERRDOS, ERRbadpath,
3706 NT_STATUS_OBJECT_PATH_NOT_FOUND);
3708 printf("* chkpath on a non existent component should fail\n");
3712 cli_rmdir(cli, "\\chkpath.dir\\dir2");
3713 cli_unlink(cli, "\\chkpath.dir\\*");
3714 cli_rmdir(cli, "\\chkpath.dir");
3716 if (!torture_close_connection(cli)) {
3723 static BOOL run_dirtest1(int dummy)
3726 struct cli_state *cli;
3728 BOOL correct = True;
3730 printf("starting directory test\n");
3732 if (!torture_open_connection(&cli)) {
3736 cli_list(cli, "\\LISTDIR\\*", 0, del_fn, cli);
3737 cli_list(cli, "\\LISTDIR\\*", FILE_ATTRIBUTE_DIRECTORY, del_fn, cli);
3738 if (cli_deltree(cli, "\\LISTDIR") == -1) {
3739 fprintf(stderr,"Failed to deltree %s, error=%s\n", "\\LISTDIR", cli_errstr(cli));
3742 if (!cli_mkdir(cli, "\\LISTDIR")) {
3743 fprintf(stderr,"Failed to mkdir %s, error=%s\n", "\\LISTDIR", cli_errstr(cli));
3747 printf("Creating %d files\n", torture_entries);
3749 /* Create torture_entries files and torture_entries directories. */
3750 for (i=0;i<torture_entries;i++) {
3752 asprintf(&fname, "\\LISTDIR\\f%d", i);
3753 fnum = cli_nt_create_full(cli, fname, 0, GENERIC_RIGHTS_FILE_ALL_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
3754 NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
3756 fprintf(stderr,"Failed to open %s, error=%s\n", fname, cli_errstr(cli));
3760 cli_close(cli, fnum);
3762 for (i=0;i<torture_entries;i++) {
3764 asprintf(&fname, "\\LISTDIR\\d%d", i);
3765 if (!cli_mkdir(cli, fname)) {
3766 fprintf(stderr,"Failed to open %s, error=%s\n", fname, cli_errstr(cli));
3772 /* Now ensure that doing an old list sees both files and directories. */
3773 num_seen = cli_list_old(cli, "\\LISTDIR\\*", FILE_ATTRIBUTE_DIRECTORY, list_fn, NULL);
3774 printf("num_seen = %d\n", num_seen );
3775 /* We should see (torture_entries) each of files & directories + . and .. */
3776 if (num_seen != (2*torture_entries)+2) {
3778 fprintf(stderr,"entry count mismatch, should be %d, was %d\n",
3779 (2*torture_entries)+2, num_seen);
3783 /* Ensure if we have the "must have" bits we only see the
3786 num_seen = cli_list_old(cli, "\\LISTDIR\\*", (FILE_ATTRIBUTE_DIRECTORY<<8)|FILE_ATTRIBUTE_DIRECTORY, list_fn, NULL);
3787 printf("num_seen = %d\n", num_seen );
3788 if (num_seen != torture_entries+2) {
3790 fprintf(stderr,"entry count mismatch, should be %d, was %d\n",
3791 torture_entries+2, num_seen);
3794 num_seen = cli_list_old(cli, "\\LISTDIR\\*", (FILE_ATTRIBUTE_ARCHIVE<<8)|FILE_ATTRIBUTE_DIRECTORY, list_fn, NULL);
3795 printf("num_seen = %d\n", num_seen );
3796 if (num_seen != torture_entries) {
3798 fprintf(stderr,"entry count mismatch, should be %d, was %d\n",
3799 torture_entries, num_seen);
3802 /* Delete everything. */
3803 cli_list(cli, "\\LISTDIR\\*", 0, del_fn, cli);
3804 cli_list(cli, "\\LISTDIR\\*", FILE_ATTRIBUTE_DIRECTORY, del_fn, cli);
3805 cli_rmdir(cli, "\\LISTDIR");
3808 printf("Matched %d\n", cli_list(cli, "a*.*", 0, list_fn, NULL));
3809 printf("Matched %d\n", cli_list(cli, "b*.*", 0, list_fn, NULL));
3810 printf("Matched %d\n", cli_list(cli, "xyzabc", 0, list_fn, NULL));
3813 if (!torture_close_connection(cli)) {
3817 printf("finished dirtest1\n");
3824 simple test harness for playing with deny modes
3826 static BOOL run_deny3test(int dummy)
3828 struct cli_state *cli1, *cli2;
3832 printf("starting deny3 test\n");
3834 printf("Testing simple deny modes\n");
3836 if (!torture_open_connection(&cli1)) {
3839 if (!torture_open_connection(&cli2)) {
3843 fname = "\\deny_dos1.dat";
3845 cli_unlink(cli1, fname);
3846 fnum1 = cli_open(cli1, fname, O_CREAT|O_TRUNC|O_WRONLY, DENY_DOS);
3847 fnum2 = cli_open(cli1, fname, O_CREAT|O_TRUNC|O_WRONLY, DENY_DOS);
3848 if (fnum1 != -1) cli_close(cli1, fnum1);
3849 if (fnum2 != -1) cli_close(cli1, fnum2);
3850 cli_unlink(cli1, fname);
3851 printf("fnum1=%d fnum2=%d\n", fnum1, fnum2);
3854 fname = "\\deny_dos2.dat";
3856 cli_unlink(cli1, fname);
3857 fnum1 = cli_open(cli1, fname, O_CREAT|O_TRUNC|O_WRONLY, DENY_DOS);
3858 fnum2 = cli_open(cli2, fname, O_CREAT|O_TRUNC|O_WRONLY, DENY_DOS);
3859 if (fnum1 != -1) cli_close(cli1, fnum1);
3860 if (fnum2 != -1) cli_close(cli2, fnum2);
3861 cli_unlink(cli1, fname);
3862 printf("fnum1=%d fnum2=%d\n", fnum1, fnum2);
3865 torture_close_connection(cli1);
3866 torture_close_connection(cli2);
3871 static void sigcont(void)
3875 static double create_procs(BOOL (*fn)(int), BOOL *result)
3878 volatile pid_t *child_status;
3879 volatile BOOL *child_status_out;
3882 double start_time_limit = 10 + (nprocs * 1.5);
3886 signal(SIGCONT, sigcont);
3888 child_status = (volatile pid_t *)shm_setup(sizeof(pid_t)*nprocs);
3889 if (!child_status) {
3890 printf("Failed to setup shared memory\n");
3894 child_status_out = (volatile BOOL *)shm_setup(sizeof(BOOL)*nprocs);
3895 if (!child_status_out) {
3896 printf("Failed to setup result status shared memory\n");
3900 for (i = 0; i < nprocs; i++) {
3901 child_status[i] = 0;
3902 child_status_out[i] = True;
3907 for (i=0;i<nprocs;i++) {
3911 pid_t mypid = getpid();
3912 sys_srandom(((int)mypid) ^ ((int)time(NULL)));
3914 asprintf(&myname, "CLIENT%d", i);
3915 lp_set_cmdline("netbios name", myname);
3919 if (torture_open_connection(¤t_cli)) break;
3921 printf("pid %d failed to start\n", (int)getpid());
3927 child_status[i] = getpid();
3931 if (child_status[i]) {
3932 printf("Child %d failed to start!\n", i);
3933 child_status_out[i] = 1;
3937 child_status_out[i] = fn(i);
3944 for (i=0;i<nprocs;i++) {
3945 if (child_status[i]) synccount++;
3947 if (synccount == nprocs) break;
3949 } while (end_timer() < start_time_limit);
3951 if (synccount != nprocs) {
3952 printf("FAILED TO START %d CLIENTS (started %d)\n", nprocs, synccount);
3957 printf("Starting %d clients\n", nprocs);
3959 /* start the client load */
3961 for (i=0;i<nprocs;i++) {
3962 child_status[i] = 0;
3966 printf("%d clients started\n", nprocs);
3968 for (i=0;i<nprocs;i++) {
3970 while ((ret=waitpid(0, &status, 0)) == -1 && errno == EINTR) /* noop */ ;
3971 if (ret == -1 || WEXITSTATUS(status) != 0) {
3978 for (i=0;i<nprocs;i++) {
3979 if (!child_status_out[i]) {
3986 #define FLAG_MULTIPROC 1
3993 {"FDPASS", run_fdpasstest, 0},
3994 {"LOCK1", run_locktest1, 0},
3995 {"LOCK2", run_locktest2, 0},
3996 {"LOCK3", run_locktest3, 0},
3997 {"LOCK4", run_locktest4, 0},
3998 {"LOCK5", run_locktest5, 0},
3999 {"LOCK6", run_locktest6, 0},
4000 {"LOCK7", run_locktest7, 0},
4001 {"UNLINK", run_unlinktest, 0},
4002 {"ATTR", run_attrtest, 0},
4003 {"TRANS2", run_trans2test, 0},
4004 {"MAXFID", run_maxfidtest, FLAG_MULTIPROC},
4005 {"TORTURE",run_torture, FLAG_MULTIPROC},
4006 {"NEGNOWAIT", run_negprot_nowait, 0},
4007 {"NBENCH", run_nbench, 0},
4008 {"DIR", run_dirtest, 0},
4009 {"DIR1", run_dirtest1, 0},
4010 {"DENY1", torture_denytest1, 0},
4011 {"DENY2", torture_denytest2, 0},
4012 {"TCON", run_tcon_test, 0},
4013 {"TCONDEV", run_tcon_devtype_test, 0},
4015 {"DFSBASIC", torture_dfs_basic, 0},
4016 {"DFSRENAME", torture_dfs_rename, 0},
4017 {"DFSRANDOM", torture_dfs_random, 0},
4019 {"RW1", run_readwritetest, 0},
4020 {"RW2", run_readwritemulti, FLAG_MULTIPROC},
4021 {"OPEN", run_opentest, 0},
4022 {"DENY3", run_deny3test, 0},
4024 {"OPENATTR", run_openattrtest, 0},
4026 {"XCOPY", run_xcopy, 0},
4027 {"RENAME", run_rename, 0},
4028 {"DELETE", run_deletetest, 0},
4029 {"PROPERTIES", run_properties, 0},
4030 {"MANGLE", torture_mangle, 0},
4031 {"UTABLE", torture_utable, 0},
4032 {"CASETABLE", torture_casetable, 0},
4033 {"PIPE_NUMBER", run_pipe_number, 0},
4034 {"IOCTL", torture_ioctl_test, 0},
4035 {"CHKPATH", torture_chkpath_test, 0},
4036 {"RAW-QFSINFO", torture_raw_qfsinfo, 0},
4037 {"RAW-QFILEINFO", torture_raw_qfileinfo, 0},
4038 {"RAW-SFILEINFO", torture_raw_sfileinfo, 0},
4039 {"RAW-SFILEINFO-BUG", torture_raw_sfileinfo_bug, 0},
4040 {"RAW-SEARCH", torture_raw_search, 0},
4041 {"RAW-CLOSE", torture_raw_close, 0},
4042 {"RAW-OPEN", torture_raw_open, 0},
4043 {"RAW-MKDIR", torture_raw_mkdir, 0},
4044 {"RAW-OPLOCK", torture_raw_oplock, 0},
4045 {"RAW-NOTIFY", torture_raw_notify, 0},
4046 {"RAW-MUX", torture_raw_mux, 0},
4047 {"RAW-IOCTL", torture_raw_ioctl, 0},
4048 {"RAW-CHKPATH", torture_raw_chkpath, 0},
4049 {"RAW-UNLINK", torture_raw_unlink, 0},
4050 {"RAW-READ", torture_raw_read, 0},
4051 {"RAW-WRITE", torture_raw_write, 0},
4052 {"RAW-LOCK", torture_raw_lock, 0},
4053 {"RAW-CONTEXT", torture_raw_context, 0},
4054 {"RAW-RENAME", torture_raw_rename, 0},
4055 {"RAW-SEEK", torture_raw_seek, 0},
4056 {"SCAN-TRANS2", torture_trans2_scan, 0},
4057 {"SCAN-NTTRANS", torture_nttrans_scan, 0},
4058 {"SCAN-ALIASES", torture_trans2_aliases, 0},
4059 {"SCAN-SMB", torture_smb_scan, 0},
4060 {"RPC-LSA", torture_rpc_lsa, 0},
4061 {"RPC-ECHO", torture_rpc_echo, 0},
4062 {"RPC-DFS", torture_rpc_dfs, 0},
4063 {"RPC-SPOOLSS", torture_rpc_spoolss, 0},
4064 {"RPC-SAMR", torture_rpc_samr, 0},
4065 {"RPC-NETLOGON", torture_rpc_netlogon, 0},
4066 {"RPC-WKSSVC", torture_rpc_wkssvc, 0},
4067 {"RPC-SRVSVC", torture_rpc_srvsvc, 0},
4068 {"RPC-ATSVC", torture_rpc_atsvc, 0},
4069 {"RPC-EVENTLOG", torture_rpc_eventlog, 0},
4070 {"RPC-EPMAPPER", torture_rpc_epmapper, 0},
4071 {"RPC-WINREG", torture_rpc_winreg, 0},
4072 {"RPC-MGMT", torture_rpc_mgmt, 0},
4073 {"RPC-SCANNER", torture_rpc_scanner, 0},
4074 {"RPC-AUTOIDL", torture_rpc_autoidl, 0},
4079 /****************************************************************************
4080 run a specified test or "ALL"
4081 ****************************************************************************/
4082 static BOOL run_test(const char *name)
4086 BOOL matched = False;
4088 if (strequal(name,"ALL")) {
4089 for (i=0;torture_ops[i].name;i++) {
4090 if (!run_test(torture_ops[i].name)) {
4097 for (i=0;torture_ops[i].name;i++) {
4098 if (gen_fnmatch(name, torture_ops[i].name) == 0) {
4101 printf("Running %s\n", torture_ops[i].name);
4102 if (torture_ops[i].flags & FLAG_MULTIPROC) {
4104 t = create_procs(torture_ops[i].fn, &result);
4107 printf("TEST %s FAILED!\n", torture_ops[i].name);
4112 if (!torture_ops[i].fn(0)) {
4114 printf("TEST %s FAILED!\n", torture_ops[i].name);
4118 printf("%s took %g secs\n\n", torture_ops[i].name, t);
4123 printf("Unknown torture operation '%s'\n", name);
4131 parse a username%password
4133 static void parse_user(const char *user)
4135 char *username, *password, *p;
4137 username = strdup(user);
4138 p = strchr_m(username,'%');
4141 password = strdup(p+1);
4144 lp_set_cmdline("torture:username", username);
4145 lp_set_cmdline("torture:password", password);
4149 static void usage(void)
4153 printf("Usage: smbtorture //server/share <options> TEST1 TEST2 ...\n");
4155 printf("\t-d debuglevel\n");
4156 printf("\t-U user%%pass\n");
4157 printf("\t-k use kerberos\n");
4158 printf("\t-N numprocs\n");
4159 printf("\t-n my_netbios_name\n");
4160 printf("\t-W workgroup\n");
4161 printf("\t-o num_operations\n");
4162 printf("\t-e num files(entries)\n");
4163 printf("\t-O socket_options\n");
4164 printf("\t-m maximum protocol\n");
4165 printf("\t-L use oplocks\n");
4166 printf("\t-c CLIENT.TXT specify client load file for NBENCH\n");
4167 printf("\t-A showall\n");
4168 printf("\t-p port\n");
4169 printf("\t-s seed\n");
4170 printf("\t-f max failures\n");
4171 printf("\t-b bypass I/O (NBENCH)\n");
4174 printf("tests are:");
4175 for (i=0;torture_ops[i].name;i++) {
4176 printf(" %s", torture_ops[i].name);
4180 printf("default test is ALL\n");
4185 /****************************************************************************
4187 ****************************************************************************/
4188 int main(int argc,char *argv[])
4192 BOOL correct = True;
4193 char *host, *share, *username;
4195 setup_logging("smbtorture", DEBUG_STDOUT);
4197 #ifdef HAVE_SETBUFFER
4198 setbuffer(stdout, NULL, 0);
4201 lp_load(dyn_CONFIGFILE,True,False,False);
4208 for(p = argv[1]; *p; p++)
4213 /* see if its a RPC transport specifier */
4214 if (strncmp(argv[1], "ncacn", 5) == 0) {
4215 char *transport = strdup(argv[1]);
4216 p = strchr_m(transport, ':');
4220 p = strchr_m(host, ':');
4224 lp_set_cmdline("torture:share", share);
4227 lp_set_cmdline("torture:share", share);
4229 lp_set_cmdline("torture:host", host);
4230 lp_set_cmdline("torture:transport", transport);
4232 if (strncmp(argv[1], "//", 2)) {
4236 host = strdup(&argv[1][2]);
4237 p = strchr_m(&host[2],'/');
4242 share = strdup(p+1);
4244 lp_set_cmdline("torture:host", host);
4245 lp_set_cmdline("torture:share", share);
4246 lp_set_cmdline("torture:password", "");
4247 lp_set_cmdline("torture:transport", "ncacn_np");
4250 if (getenv("LOGNAME")) {
4251 username = strdup(getenv("LOGNAME"));
4253 lp_set_cmdline("torture:username", username);
4259 srandom(time(NULL));
4261 while ((opt = getopt(argc, argv, "p:hW:U:n:N:O:o:e:m:Ld:Ac:ks:f:s:")) != EOF) {
4264 lp_set_cmdline("smb ports", optarg);
4267 lp_set_cmdline("workgroup", optarg);
4270 lp_set_cmdline("protocol", optarg);
4273 lp_set_cmdline("netbios name", optarg);
4276 lp_set_cmdline("debug level", optarg);
4277 setup_logging(NULL, DEBUG_STDOUT);
4280 lp_set_cmdline("socket options", optarg);
4283 srandom(atoi(optarg));
4286 nprocs = atoi(optarg);
4289 torture_numops = atoi(optarg);
4292 torture_entries = atoi(optarg);
4298 torture_showall = True;
4301 client_txt = optarg;
4305 use_kerberos = True;
4307 d_printf("No kerberos support compiled in\n");
4315 torture_failures = atoi(optarg);
4319 printf("Unknown option %c (%d)\n", (char)opt, opt);
4324 printf("host=%s share=%s user=%s myname=%s\n",
4325 host, share, lp_parm_string(-1, "torture", "username"),
4328 if (argc == optind) {
4329 printf("You must specify a test to run, or 'ALL'\n");
4331 for (i=optind;i<argc;i++) {
4332 if (!run_test(argv[i])) {