2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 1997-2003
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 int torture_numops=100;
25 int torture_entries=1000;
26 int torture_failures=1;
27 static int procnum; /* records process count number when forking */
28 static struct cli_state *current_cli;
29 static char *randomfname;
30 static BOOL use_oplocks;
31 static BOOL use_level_II_oplocks;
32 static const char *client_txt = "client_oplocks.txt";
33 static BOOL use_kerberos;
34 static BOOL bypass_io;
36 BOOL torture_showall = False;
38 static double create_procs(BOOL (*fn)(int), BOOL *result);
40 #define CHECK_MAX_FAILURES(label) do { if (++failures >= torture_failures) goto label; } while (0)
42 static struct cli_state *open_nbt_connection(void)
44 struct nmb_name called, calling;
46 struct cli_state *cli;
47 char *host = lp_parm_string(-1, "torture", "host");
49 make_nmb_name(&calling, lp_netbios_name(), 0x0);
50 make_nmb_name(&called , host, 0x20);
54 cli = cli_state_init();
56 printf("Failed initialize cli_struct to connect with %s\n", host);
60 if (!cli_socket_connect(cli, host, &ip)) {
61 printf("Failed to connect with %s\n", host);
65 cli->transport->socket->timeout = 120000; /* set a really long timeout (2 minutes) */
67 if (!cli_transport_establish(cli, &calling, &called)) {
69 * Well, that failed, try *SMBSERVER ...
70 * However, we must reconnect as well ...
72 if (!cli_socket_connect(cli, host, &ip)) {
73 printf("Failed to connect with %s\n", host);
77 make_nmb_name(&called, "*SMBSERVER", 0x20);
78 if (!cli_transport_establish(cli, &calling, &called)) {
79 printf("%s rejected the session\n",host);
80 printf("We tried with a called name of %s & %s\n",
90 BOOL torture_open_connection(struct cli_state **c)
95 char *host = lp_parm_string(-1, "torture", "host");
96 char *share = lp_parm_string(-1, "torture", "share");
97 char *username = lp_parm_string(-1, "torture", "username");
98 char *password = lp_parm_string(-1, "torture", "password");
101 flags |= CLI_FULL_CONNECTION_USE_KERBEROS;
103 status = cli_full_connection(c, lp_netbios_name(),
106 username, lp_workgroup(),
107 password, flags, &retry);
108 if (!NT_STATUS_IS_OK(status)) {
109 printf("Failed to open connection - %s\n", nt_errstr(status));
113 (*c)->transport->options.use_oplocks = use_oplocks;
114 (*c)->transport->options.use_level2_oplocks = use_level_II_oplocks;
115 (*c)->transport->socket->timeout = 120000;
120 BOOL torture_close_connection(struct cli_state *c)
123 DEBUG(9,("torture_close_connection: cli_state@%p\n", c));
126 printf("tdis failed (%s)\n", cli_errstr(c));
129 DEBUG(9,("torture_close_connection: call cli_shutdown\n"));
131 DEBUG(9,("torture_close_connection: exit\n"));
136 /* check if the server produced the expected error code */
137 static BOOL check_error(int line, struct cli_state *c,
138 uint8 eclass, uint32 ecode, NTSTATUS nterr)
140 if (cli_is_dos_error(c)) {
144 /* Check DOS error */
146 cli_dos_error(c, &class, &num);
148 if (eclass != class || ecode != num) {
149 printf("unexpected error code class=%d code=%d\n",
150 (int)class, (int)num);
151 printf(" expected %d/%d %s (line=%d)\n",
152 (int)eclass, (int)ecode, nt_errstr(nterr), line);
161 status = cli_nt_error(c);
163 if (NT_STATUS_V(nterr) != NT_STATUS_V(status)) {
164 printf("unexpected error code %s\n", nt_errstr(status));
165 printf(" expected %s (line=%d)\n", nt_errstr(nterr), line);
174 static BOOL wait_lock(struct cli_state *c, int fnum, uint32 offset, uint32 len)
176 while (!cli_lock(c, fnum, offset, len, -1, WRITE_LOCK)) {
177 if (!check_error(__LINE__, c, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False;
183 static BOOL rw_torture(struct cli_state *c)
185 const char *lockfname = "\\torture.lck";
189 pid_t pid2, pid = getpid();
194 fnum2 = cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
197 fnum2 = cli_open(c, lockfname, O_RDWR, DENY_NONE);
199 printf("open of %s failed (%s)\n", lockfname, cli_errstr(c));
204 for (i=0;i<torture_numops;i++) {
205 unsigned n = (unsigned)sys_random()%10;
207 printf("%d\r", i); fflush(stdout);
209 asprintf(&fname, "\\torture.%u", n);
211 if (!wait_lock(c, fnum2, n*sizeof(int), sizeof(int))) {
215 fnum = cli_open(c, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_ALL);
217 printf("open failed (%s)\n", cli_errstr(c));
222 if (cli_write(c, fnum, 0, (char *)&pid, 0, sizeof(pid)) != sizeof(pid)) {
223 printf("write failed (%s)\n", cli_errstr(c));
228 if (cli_write(c, fnum, 0, (char *)buf,
229 sizeof(pid)+(j*sizeof(buf)),
230 sizeof(buf)) != sizeof(buf)) {
231 printf("write failed (%s)\n", cli_errstr(c));
238 if (cli_read(c, fnum, (char *)&pid2, 0, sizeof(pid)) != sizeof(pid)) {
239 printf("read failed (%s)\n", cli_errstr(c));
244 printf("data corruption!\n");
248 if (!cli_close(c, fnum)) {
249 printf("close failed (%s)\n", cli_errstr(c));
253 if (!cli_unlink(c, fname)) {
254 printf("unlink failed (%s)\n", cli_errstr(c));
258 if (!cli_unlock(c, fnum2, n*sizeof(int), sizeof(int))) {
259 printf("unlock failed (%s)\n", cli_errstr(c));
266 cli_unlink(c, lockfname);
273 static BOOL run_torture(int dummy)
275 struct cli_state *cli;
280 ret = rw_torture(cli);
282 if (!torture_close_connection(cli)) {
289 static BOOL rw_torture3(struct cli_state *c, char *lockfname)
296 unsigned countprev = 0;
301 for (i = 0; i < sizeof(buf); i += sizeof(uint32))
303 SIVAL(buf, i, sys_random());
308 fnum = cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
311 printf("first open read/write of %s failed (%s)\n",
312 lockfname, cli_errstr(c));
318 for (i = 0; i < 500 && fnum == -1; i++)
320 fnum = cli_open(c, lockfname, O_RDONLY,
325 printf("second open read-only of %s failed (%s)\n",
326 lockfname, cli_errstr(c));
332 for (count = 0; count < sizeof(buf); count += sent)
334 if (count >= countprev) {
335 printf("%d %8d\r", i, count);
338 countprev += (sizeof(buf) / 20);
343 sent = ((unsigned)sys_random()%(20))+ 1;
344 if (sent > sizeof(buf) - count)
346 sent = sizeof(buf) - count;
349 if (cli_write(c, fnum, 0, buf+count, count, (size_t)sent) != sent) {
350 printf("write failed (%s)\n", cli_errstr(c));
356 sent = cli_read(c, fnum, buf_rd+count, count,
360 printf("read failed offset:%d size:%d (%s)\n",
361 count, sizeof(buf)-count,
368 if (memcmp(buf_rd+count, buf+count, sent) != 0)
370 printf("read/write compare failed\n");
371 printf("offset: %d req %d recvd %d\n",
372 count, sizeof(buf)-count, sent);
381 if (!cli_close(c, fnum)) {
382 printf("close failed (%s)\n", cli_errstr(c));
389 static BOOL rw_torture2(struct cli_state *c1, struct cli_state *c2)
391 const char *lockfname = "\\torture2.lck";
396 uchar buf_rd[131072];
398 ssize_t bytes_read, bytes_written;
400 if (cli_deltree(c1, lockfname) == -1) {
401 printf("unlink failed (%s)\n", cli_errstr(c1));
404 fnum1 = cli_open(c1, lockfname, O_RDWR | O_CREAT | O_EXCL,
407 printf("first open read/write of %s failed (%s)\n",
408 lockfname, cli_errstr(c1));
411 fnum2 = cli_open(c2, lockfname, O_RDONLY,
414 printf("second open read-only of %s failed (%s)\n",
415 lockfname, cli_errstr(c2));
416 cli_close(c1, fnum1);
420 printf("Checking data integrity over %d ops\n", torture_numops);
422 for (i=0;i<torture_numops;i++)
424 size_t buf_size = ((unsigned)sys_random()%(sizeof(buf)-1))+ 1;
426 printf("%d\r", i); fflush(stdout);
429 generate_random_buffer(buf, buf_size, False);
431 if ((bytes_written = cli_write(c1, fnum1, 0, buf, 0, buf_size)) != buf_size) {
432 printf("write failed (%s)\n", cli_errstr(c1));
433 printf("wrote %d, expected %d\n", bytes_written, buf_size);
438 if ((bytes_read = cli_read(c2, fnum2, buf_rd, 0, buf_size)) != buf_size) {
439 printf("read failed (%s)\n", cli_errstr(c2));
440 printf("read %d, expected %d\n", bytes_read, buf_size);
445 if (memcmp(buf_rd, buf, buf_size) != 0)
447 printf("read/write compare failed\n");
453 if (!cli_close(c2, fnum2)) {
454 printf("close failed (%s)\n", cli_errstr(c2));
457 if (!cli_close(c1, fnum1)) {
458 printf("close failed (%s)\n", cli_errstr(c1));
462 if (!cli_unlink(c1, lockfname)) {
463 printf("unlink failed (%s)\n", cli_errstr(c1));
470 static BOOL run_readwritetest(int dummy)
472 struct cli_state *cli1, *cli2;
473 BOOL test1, test2 = True;
475 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
479 printf("starting readwritetest\n");
481 test1 = rw_torture2(cli1, cli2);
482 printf("Passed readwritetest v1: %s\n", BOOLSTR(test1));
485 test2 = rw_torture2(cli1, cli1);
486 printf("Passed readwritetest v2: %s\n", BOOLSTR(test2));
489 if (!torture_close_connection(cli1)) {
493 if (!torture_close_connection(cli2)) {
497 return (test1 && test2);
500 static BOOL run_readwritemulti(int dummy)
502 struct cli_state *cli;
507 printf("run_readwritemulti: fname %s\n", randomfname);
508 test = rw_torture3(cli, randomfname);
510 if (!torture_close_connection(cli)) {
521 #define ival(s) strtol(s, NULL, 0)
523 /* run a test that simulates an approximate netbench client load */
524 static BOOL run_netbench(int client)
526 struct cli_state *cli;
531 const char *params[20];
540 asprintf(&cname, "client%d", client);
542 f = fopen(client_txt, "r");
549 while (fgets(line, sizeof(line)-1, f)) {
552 line[strlen(line)-1] = 0;
554 /* printf("[%d] %s\n", line_count, line); */
556 all_string_sub(line,"client1", cname, sizeof(line));
558 /* parse the command parameters */
559 params[0] = strtok(line," ");
561 while (params[i]) params[++i] = strtok(NULL," ");
567 if (!strncmp(params[0],"SMB", 3)) {
568 printf("ERROR: You are using a dbench 1 load file\n");
571 DEBUG(9,("run_netbench(%d): %s %s\n", client, params[0], params[1]));
573 if (!strcmp(params[0],"NTCreateX")) {
574 nb_createx(params[1], ival(params[2]), ival(params[3]),
576 } else if (!strcmp(params[0],"Close")) {
577 nb_close(ival(params[1]));
578 } else if (!strcmp(params[0],"Rename")) {
579 nb_rename(params[1], params[2]);
580 } else if (!strcmp(params[0],"Unlink")) {
581 nb_unlink(params[1]);
582 } else if (!strcmp(params[0],"Deltree")) {
583 nb_deltree(params[1]);
584 } else if (!strcmp(params[0],"Rmdir")) {
586 } else if (!strcmp(params[0],"QUERY_PATH_INFORMATION")) {
587 nb_qpathinfo(params[1]);
588 } else if (!strcmp(params[0],"QUERY_FILE_INFORMATION")) {
589 nb_qfileinfo(ival(params[1]));
590 } else if (!strcmp(params[0],"QUERY_FS_INFORMATION")) {
591 nb_qfsinfo(ival(params[1]));
592 } else if (!strcmp(params[0],"FIND_FIRST")) {
593 nb_findfirst(params[1]);
594 } else if (!strcmp(params[0],"WriteX")) {
595 nb_writex(ival(params[1]),
596 ival(params[2]), ival(params[3]), ival(params[4]));
597 } else if (!strcmp(params[0],"ReadX")) {
598 nb_readx(ival(params[1]),
599 ival(params[2]), ival(params[3]), ival(params[4]));
600 } else if (!strcmp(params[0],"Flush")) {
601 nb_flush(ival(params[1]));
603 printf("Unknown operation %s\n", params[0]);
611 if (!torture_close_connection(cli)) {
619 /* run a test that simulates an approximate netbench client load */
620 static BOOL run_nbench(int dummy)
629 signal(SIGALRM, SIGNAL_CAST nb_alarm);
631 t = create_procs(run_netbench, &correct);
634 printf("\nThroughput %g MB/sec\n",
635 1.0e-6 * nbio_total() / t);
641 This test checks for two things:
643 1) correct support for retaining locks over a close (ie. the server
644 must not use posix semantics)
645 2) support for lock timeouts
647 static BOOL run_locktest1(int dummy)
649 struct cli_state *cli1, *cli2;
650 const char *fname = "\\lockt1.lck";
651 int fnum1, fnum2, fnum3;
653 unsigned lock_timeout;
655 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
659 printf("starting locktest1\n");
661 cli_unlink(cli1, fname);
663 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
665 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
668 fnum2 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
670 printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli1));
673 fnum3 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
675 printf("open3 of %s failed (%s)\n", fname, cli_errstr(cli2));
679 if (!cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK)) {
680 printf("lock1 failed (%s)\n", cli_errstr(cli1));
685 if (cli_lock(cli2, fnum3, 0, 4, 0, WRITE_LOCK)) {
686 printf("lock2 succeeded! This is a locking bug\n");
689 if (!check_error(__LINE__, cli2, ERRDOS, ERRlock,
690 NT_STATUS_LOCK_NOT_GRANTED)) return False;
694 lock_timeout = (6 + (random() % 20));
695 printf("Testing lock timeout with timeout=%u\n", lock_timeout);
697 if (cli_lock(cli2, fnum3, 0, 4, lock_timeout * 1000, WRITE_LOCK)) {
698 printf("lock3 succeeded! This is a locking bug\n");
701 if (!check_error(__LINE__, cli2, ERRDOS, ERRlock,
702 NT_STATUS_FILE_LOCK_CONFLICT)) return False;
707 printf("error: This server appears not to support timed lock requests\n");
709 printf("server slept for %u seconds for a %u second timeout\n",
710 (unsigned int)(t2-t1), lock_timeout);
712 if (!cli_close(cli1, fnum2)) {
713 printf("close1 failed (%s)\n", cli_errstr(cli1));
717 if (cli_lock(cli2, fnum3, 0, 4, 0, WRITE_LOCK)) {
718 printf("lock4 succeeded! This is a locking bug\n");
721 if (!check_error(__LINE__, cli2, ERRDOS, ERRlock,
722 NT_STATUS_FILE_LOCK_CONFLICT)) return False;
725 if (!cli_close(cli1, fnum1)) {
726 printf("close2 failed (%s)\n", cli_errstr(cli1));
730 if (!cli_close(cli2, fnum3)) {
731 printf("close3 failed (%s)\n", cli_errstr(cli2));
735 if (!cli_unlink(cli1, fname)) {
736 printf("unlink failed (%s)\n", cli_errstr(cli1));
741 if (!torture_close_connection(cli1)) {
745 if (!torture_close_connection(cli2)) {
749 printf("Passed locktest1\n");
754 this checks to see if a secondary tconx can use open files from an
757 static BOOL run_tcon_test(int dummy)
759 struct cli_state *cli;
760 const char *fname = "\\tcontest.tmp";
762 uint16 cnum1, cnum2, cnum3;
766 struct cli_tree *tree1;
767 char *host = lp_parm_string(-1, "torture", "host");
768 char *share = lp_parm_string(-1, "torture", "share");
769 char *password = lp_parm_string(-1, "torture", "password");
771 if (!torture_open_connection(&cli)) {
775 printf("starting tcontest\n");
777 if (cli_deltree(cli, fname) == -1) {
778 printf("unlink of %s failed (%s)\n", fname, cli_errstr(cli));
781 fnum1 = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
783 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
787 cnum1 = cli->tree->tid;
788 vuid1 = cli->session->vuid;
790 memset(&buf, 0, 4); /* init buf so valgrind won't complain */
791 if (cli_write(cli, fnum1, 0, buf, 130, 4) != 4) {
792 printf("initial write failed (%s)\n", cli_errstr(cli));
796 tree1 = cli->tree; /* save old tree connection */
797 if (!cli_send_tconX(cli, share, "?????",
799 printf("%s refused 2nd tree connect (%s)\n", host,
805 cnum2 = cli->tree->tid;
806 cnum3 = MAX(cnum1, cnum2) + 1; /* any invalid number */
807 vuid2 = cli->session->vuid + 1;
809 /* try a write with the wrong tid */
810 cli->tree->tid = cnum2;
812 if (cli_write(cli, fnum1, 0, buf, 130, 4) == 4) {
813 printf("* server allows write with wrong TID\n");
816 printf("server fails write with wrong TID : %s\n", cli_errstr(cli));
820 /* try a write with an invalid tid */
821 cli->tree->tid = cnum3;
823 if (cli_write(cli, fnum1, 0, buf, 130, 4) == 4) {
824 printf("* server allows write with invalid TID\n");
827 printf("server fails write with invalid TID : %s\n", cli_errstr(cli));
830 /* try a write with an invalid vuid */
831 cli->session->vuid = vuid2;
832 cli->tree->tid = cnum1;
834 if (cli_write(cli, fnum1, 0, buf, 130, 4) == 4) {
835 printf("* server allows write with invalid VUID\n");
838 printf("server fails write with invalid VUID : %s\n", cli_errstr(cli));
841 cli->session->vuid = vuid1;
842 cli->tree->tid = cnum1;
844 if (!cli_close(cli, fnum1)) {
845 printf("close failed (%s)\n", cli_errstr(cli));
849 cli->tree->tid = cnum2;
851 if (!cli_tdis(cli)) {
852 printf("secondary tdis failed (%s)\n", cli_errstr(cli));
856 cli->tree = tree1; /* restore initial tree */
857 cli->tree->tid = cnum1;
859 if (!torture_close_connection(cli)) {
868 static BOOL tcon_devtest(struct cli_state *cli,
869 const char *myshare, const char *devtype,
870 NTSTATUS expected_error)
874 char *password = lp_parm_string(-1, "torture", "password");
876 status = cli_send_tconX(cli, myshare, devtype,
879 printf("Trying share %s with devtype %s\n", myshare, devtype);
881 if (NT_STATUS_IS_OK(expected_error)) {
885 printf("tconX to share %s with type %s "
886 "should have succeeded but failed\n",
893 printf("tconx to share %s with type %s "
894 "should have failed but succeeded\n",
898 if (NT_STATUS_EQUAL(cli_nt_error(cli),
902 printf("Returned unexpected error\n");
911 checks for correct tconX support
913 static BOOL run_tcon_devtype_test(int dummy)
915 struct cli_state *cli1 = NULL;
920 char *host = lp_parm_string(-1, "torture", "host");
921 char *share = lp_parm_string(-1, "torture", "share");
922 char *username = lp_parm_string(-1, "torture", "username");
923 char *password = lp_parm_string(-1, "torture", "password");
925 status = cli_full_connection(&cli1, lp_netbios_name(),
928 username, lp_workgroup(),
929 password, flags, &retry);
931 if (!NT_STATUS_IS_OK(status)) {
932 printf("could not open connection\n");
936 if (!tcon_devtest(cli1, "IPC$", "A:", NT_STATUS_BAD_DEVICE_TYPE))
939 if (!tcon_devtest(cli1, "IPC$", "?????", NT_STATUS_OK))
942 if (!tcon_devtest(cli1, "IPC$", "LPT:", NT_STATUS_BAD_DEVICE_TYPE))
945 if (!tcon_devtest(cli1, "IPC$", "IPC", NT_STATUS_OK))
948 if (!tcon_devtest(cli1, "IPC$", "FOOBA", NT_STATUS_BAD_DEVICE_TYPE))
951 if (!tcon_devtest(cli1, share, "A:", NT_STATUS_OK))
954 if (!tcon_devtest(cli1, share, "?????", NT_STATUS_OK))
957 if (!tcon_devtest(cli1, share, "LPT:", NT_STATUS_BAD_DEVICE_TYPE))
960 if (!tcon_devtest(cli1, share, "IPC", NT_STATUS_BAD_DEVICE_TYPE))
963 if (!tcon_devtest(cli1, share, "FOOBA", NT_STATUS_BAD_DEVICE_TYPE))
969 printf("Passed tcondevtest\n");
976 This test checks that
978 1) the server supports multiple locking contexts on the one SMB
979 connection, distinguished by PID.
981 2) the server correctly fails overlapping locks made by the same PID (this
982 goes against POSIX behaviour, which is why it is tricky to implement)
984 3) the server denies unlock requests by an incorrect client PID
986 static BOOL run_locktest2(int dummy)
988 struct cli_state *cli;
989 const char *fname = "\\lockt2.lck";
990 int fnum1, fnum2, fnum3;
993 if (!torture_open_connection(&cli)) {
997 printf("starting locktest2\n");
999 cli_unlink(cli, fname);
1001 printf("Testing pid context\n");
1003 cli->session->pid = 1;
1005 fnum1 = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1007 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
1011 fnum2 = cli_open(cli, fname, O_RDWR, DENY_NONE);
1013 printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli));
1017 cli->session->pid = 2;
1019 fnum3 = cli_open(cli, fname, O_RDWR, DENY_NONE);
1021 printf("open3 of %s failed (%s)\n", fname, cli_errstr(cli));
1025 cli->session->pid = 1;
1027 if (!cli_lock(cli, fnum1, 0, 4, 0, WRITE_LOCK)) {
1028 printf("lock1 failed (%s)\n", cli_errstr(cli));
1032 if (cli_lock(cli, fnum1, 0, 4, 0, WRITE_LOCK)) {
1033 printf("WRITE lock1 succeeded! This is a locking bug\n");
1036 if (!check_error(__LINE__, cli, ERRDOS, ERRlock,
1037 NT_STATUS_LOCK_NOT_GRANTED)) return False;
1040 if (cli_lock(cli, fnum2, 0, 4, 0, WRITE_LOCK)) {
1041 printf("WRITE lock2 succeeded! This is a locking bug\n");
1044 if (!check_error(__LINE__, cli, ERRDOS, ERRlock,
1045 NT_STATUS_LOCK_NOT_GRANTED)) return False;
1048 if (cli_lock(cli, fnum2, 0, 4, 0, READ_LOCK)) {
1049 printf("READ lock2 succeeded! This is a locking bug\n");
1052 if (!check_error(__LINE__, cli, ERRDOS, ERRlock,
1053 NT_STATUS_FILE_LOCK_CONFLICT)) return False;
1056 if (!cli_lock(cli, fnum1, 100, 4, 0, WRITE_LOCK)) {
1057 printf("lock at 100 failed (%s)\n", cli_errstr(cli));
1060 cli->session->pid = 2;
1062 if (cli_unlock(cli, fnum1, 100, 4)) {
1063 printf("unlock at 100 succeeded! This is a locking bug\n");
1067 if (cli_unlock(cli, fnum1, 0, 4)) {
1068 printf("unlock1 succeeded! This is a locking bug\n");
1071 if (!check_error(__LINE__, cli,
1073 NT_STATUS_RANGE_NOT_LOCKED)) return False;
1076 if (cli_unlock(cli, fnum1, 0, 8)) {
1077 printf("unlock2 succeeded! This is a locking bug\n");
1080 if (!check_error(__LINE__, cli,
1082 NT_STATUS_RANGE_NOT_LOCKED)) return False;
1085 if (cli_lock(cli, fnum3, 0, 4, 0, WRITE_LOCK)) {
1086 printf("lock3 succeeded! This is a locking bug\n");
1089 if (!check_error(__LINE__, cli, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False;
1092 cli->session->pid = 1;
1094 if (!cli_close(cli, fnum1)) {
1095 printf("close1 failed (%s)\n", cli_errstr(cli));
1099 if (!cli_close(cli, fnum2)) {
1100 printf("close2 failed (%s)\n", cli_errstr(cli));
1104 if (!cli_close(cli, fnum3)) {
1105 printf("close3 failed (%s)\n", cli_errstr(cli));
1109 if (!torture_close_connection(cli)) {
1113 printf("locktest2 finished\n");
1120 This test checks that
1122 1) the server supports the full offset range in lock requests
1124 static BOOL run_locktest3(int dummy)
1126 struct cli_state *cli1, *cli2;
1127 const char *fname = "\\lockt3.lck";
1128 int fnum1, fnum2, i;
1130 BOOL correct = True;
1132 #define NEXT_OFFSET offset += (~(uint32)0) / torture_numops
1134 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
1138 printf("starting locktest3\n");
1140 printf("Testing 32 bit offset ranges\n");
1142 cli_unlink(cli1, fname);
1144 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1146 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
1149 fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
1151 printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli2));
1155 printf("Establishing %d locks\n", torture_numops);
1157 for (offset=i=0;i<torture_numops;i++) {
1159 if (!cli_lock(cli1, fnum1, offset-1, 1, 0, WRITE_LOCK)) {
1160 printf("lock1 %d failed (%s)\n",
1166 if (!cli_lock(cli2, fnum2, offset-2, 1, 0, WRITE_LOCK)) {
1167 printf("lock2 %d failed (%s)\n",
1174 printf("Testing %d locks\n", torture_numops);
1176 for (offset=i=0;i<torture_numops;i++) {
1179 if (cli_lock(cli1, fnum1, offset-2, 1, 0, WRITE_LOCK)) {
1180 printf("error: lock1 %d succeeded!\n", i);
1184 if (cli_lock(cli2, fnum2, offset-1, 1, 0, WRITE_LOCK)) {
1185 printf("error: lock2 %d succeeded!\n", i);
1189 if (cli_lock(cli1, fnum1, offset-1, 1, 0, WRITE_LOCK)) {
1190 printf("error: lock3 %d succeeded!\n", i);
1194 if (cli_lock(cli2, fnum2, offset-2, 1, 0, WRITE_LOCK)) {
1195 printf("error: lock4 %d succeeded!\n", i);
1200 printf("Removing %d locks\n", torture_numops);
1202 for (offset=i=0;i<torture_numops;i++) {
1205 if (!cli_unlock(cli1, fnum1, offset-1, 1)) {
1206 printf("unlock1 %d failed (%s)\n",
1212 if (!cli_unlock(cli2, fnum2, offset-2, 1)) {
1213 printf("unlock2 %d failed (%s)\n",
1220 if (!cli_close(cli1, fnum1)) {
1221 printf("close1 failed (%s)\n", cli_errstr(cli1));
1225 if (!cli_close(cli2, fnum2)) {
1226 printf("close2 failed (%s)\n", cli_errstr(cli2));
1230 if (!cli_unlink(cli1, fname)) {
1231 printf("unlink failed (%s)\n", cli_errstr(cli1));
1235 if (!torture_close_connection(cli1)) {
1239 if (!torture_close_connection(cli2)) {
1243 printf("finished locktest3\n");
1248 #define EXPECTED(ret, v) if ((ret) != (v)) { \
1249 printf("** "); correct = False; \
1253 looks at overlapping locks
1255 static BOOL run_locktest4(int dummy)
1257 struct cli_state *cli1, *cli2;
1258 const char *fname = "\\lockt4.lck";
1259 int fnum1, fnum2, f;
1262 BOOL correct = True;
1264 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
1268 printf("starting locktest4\n");
1270 cli_unlink(cli1, fname);
1272 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1273 fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
1275 memset(buf, 0, sizeof(buf));
1277 if (cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
1278 printf("Failed to create file\n");
1283 ret = cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK) &&
1284 cli_lock(cli1, fnum1, 2, 4, 0, WRITE_LOCK);
1285 EXPECTED(ret, False);
1286 printf("the same process %s set overlapping write locks\n", ret?"can":"cannot");
1288 ret = cli_lock(cli1, fnum1, 10, 4, 0, READ_LOCK) &&
1289 cli_lock(cli1, fnum1, 12, 4, 0, READ_LOCK);
1290 EXPECTED(ret, True);
1291 printf("the same process %s set overlapping read locks\n", ret?"can":"cannot");
1293 ret = cli_lock(cli1, fnum1, 20, 4, 0, WRITE_LOCK) &&
1294 cli_lock(cli2, fnum2, 22, 4, 0, WRITE_LOCK);
1295 EXPECTED(ret, False);
1296 printf("a different connection %s set overlapping write locks\n", ret?"can":"cannot");
1298 ret = cli_lock(cli1, fnum1, 30, 4, 0, READ_LOCK) &&
1299 cli_lock(cli2, fnum2, 32, 4, 0, READ_LOCK);
1300 EXPECTED(ret, True);
1301 printf("a different connection %s set overlapping read locks\n", ret?"can":"cannot");
1303 ret = (cli1->session->pid = 1, cli_lock(cli1, fnum1, 40, 4, 0, WRITE_LOCK)) &&
1304 (cli1->session->pid = 2, cli_lock(cli1, fnum1, 42, 4, 0, WRITE_LOCK));
1305 EXPECTED(ret, False);
1306 printf("a different pid %s set overlapping write locks\n", ret?"can":"cannot");
1308 ret = (cli1->session->pid = 1, cli_lock(cli1, fnum1, 50, 4, 0, READ_LOCK)) &&
1309 (cli1->session->pid = 2, cli_lock(cli1, fnum1, 52, 4, 0, READ_LOCK));
1310 EXPECTED(ret, True);
1311 printf("a different pid %s set overlapping read locks\n", ret?"can":"cannot");
1313 ret = cli_lock(cli1, fnum1, 60, 4, 0, READ_LOCK) &&
1314 cli_lock(cli1, fnum1, 60, 4, 0, READ_LOCK);
1315 EXPECTED(ret, True);
1316 printf("the same process %s set the same read lock twice\n", ret?"can":"cannot");
1318 ret = cli_lock(cli1, fnum1, 70, 4, 0, WRITE_LOCK) &&
1319 cli_lock(cli1, fnum1, 70, 4, 0, WRITE_LOCK);
1320 EXPECTED(ret, False);
1321 printf("the same process %s set the same write lock twice\n", ret?"can":"cannot");
1323 ret = cli_lock(cli1, fnum1, 80, 4, 0, READ_LOCK) &&
1324 cli_lock(cli1, fnum1, 80, 4, 0, WRITE_LOCK);
1325 EXPECTED(ret, False);
1326 printf("the same process %s overlay a read lock with a write lock\n", ret?"can":"cannot");
1328 ret = cli_lock(cli1, fnum1, 90, 4, 0, WRITE_LOCK) &&
1329 cli_lock(cli1, fnum1, 90, 4, 0, READ_LOCK);
1330 EXPECTED(ret, True);
1331 printf("the same process %s overlay a write lock with a read lock\n", ret?"can":"cannot");
1333 ret = (cli1->session->pid = 1, cli_lock(cli1, fnum1, 100, 4, 0, WRITE_LOCK)) &&
1334 (cli1->session->pid = 2, cli_lock(cli1, fnum1, 100, 4, 0, READ_LOCK));
1335 EXPECTED(ret, False);
1336 printf("a different pid %s overlay a write lock with a read lock\n", ret?"can":"cannot");
1338 ret = cli_lock(cli1, fnum1, 110, 4, 0, READ_LOCK) &&
1339 cli_lock(cli1, fnum1, 112, 4, 0, READ_LOCK) &&
1340 cli_unlock(cli1, fnum1, 110, 6);
1341 EXPECTED(ret, False);
1342 printf("the same process %s coalesce read locks\n", ret?"can":"cannot");
1345 ret = cli_lock(cli1, fnum1, 120, 4, 0, WRITE_LOCK) &&
1346 (cli_read(cli2, fnum2, buf, 120, 4) == 4);
1347 EXPECTED(ret, False);
1348 printf("this server %s strict write locking\n", ret?"doesn't do":"does");
1350 ret = cli_lock(cli1, fnum1, 130, 4, 0, READ_LOCK) &&
1351 (cli_write(cli2, fnum2, 0, buf, 130, 4) == 4);
1352 EXPECTED(ret, False);
1353 printf("this server %s strict read locking\n", ret?"doesn't do":"does");
1356 ret = cli_lock(cli1, fnum1, 140, 4, 0, READ_LOCK) &&
1357 cli_lock(cli1, fnum1, 140, 4, 0, READ_LOCK) &&
1358 cli_unlock(cli1, fnum1, 140, 4) &&
1359 cli_unlock(cli1, fnum1, 140, 4);
1360 EXPECTED(ret, True);
1361 printf("this server %s do recursive read locking\n", ret?"does":"doesn't");
1364 ret = cli_lock(cli1, fnum1, 150, 4, 0, WRITE_LOCK) &&
1365 cli_lock(cli1, fnum1, 150, 4, 0, READ_LOCK) &&
1366 cli_unlock(cli1, fnum1, 150, 4) &&
1367 (cli_read(cli2, fnum2, buf, 150, 4) == 4) &&
1368 !(cli_write(cli2, fnum2, 0, buf, 150, 4) == 4) &&
1369 cli_unlock(cli1, fnum1, 150, 4);
1370 EXPECTED(ret, True);
1371 printf("this server %s do recursive lock overlays\n", ret?"does":"doesn't");
1373 ret = cli_lock(cli1, fnum1, 160, 4, 0, READ_LOCK) &&
1374 cli_unlock(cli1, fnum1, 160, 4) &&
1375 (cli_write(cli2, fnum2, 0, buf, 160, 4) == 4) &&
1376 (cli_read(cli2, fnum2, buf, 160, 4) == 4);
1377 EXPECTED(ret, True);
1378 printf("the same process %s remove a read lock using write locking\n", ret?"can":"cannot");
1380 ret = cli_lock(cli1, fnum1, 170, 4, 0, WRITE_LOCK) &&
1381 cli_unlock(cli1, fnum1, 170, 4) &&
1382 (cli_write(cli2, fnum2, 0, buf, 170, 4) == 4) &&
1383 (cli_read(cli2, fnum2, buf, 170, 4) == 4);
1384 EXPECTED(ret, True);
1385 printf("the same process %s remove a write lock using read locking\n", ret?"can":"cannot");
1387 ret = cli_lock(cli1, fnum1, 190, 4, 0, WRITE_LOCK) &&
1388 cli_lock(cli1, fnum1, 190, 4, 0, READ_LOCK) &&
1389 cli_unlock(cli1, fnum1, 190, 4) &&
1390 !(cli_write(cli2, fnum2, 0, buf, 190, 4) == 4) &&
1391 (cli_read(cli2, fnum2, buf, 190, 4) == 4);
1392 EXPECTED(ret, True);
1393 printf("the same process %s remove the first lock first\n", ret?"does":"doesn't");
1395 cli_close(cli1, fnum1);
1396 cli_close(cli2, fnum2);
1397 fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1398 f = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1399 ret = cli_lock(cli1, fnum1, 0, 8, 0, READ_LOCK) &&
1400 cli_lock(cli1, f, 0, 1, 0, READ_LOCK) &&
1401 cli_close(cli1, fnum1) &&
1402 ((fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE)) != -1) &&
1403 cli_lock(cli1, fnum1, 7, 1, 0, WRITE_LOCK);
1405 cli_close(cli1, fnum1);
1406 EXPECTED(ret, True);
1407 printf("the server %s have the NT byte range lock bug\n", !ret?"does":"doesn't");
1410 cli_close(cli1, fnum1);
1411 cli_close(cli2, fnum2);
1412 cli_unlink(cli1, fname);
1413 torture_close_connection(cli1);
1414 torture_close_connection(cli2);
1416 printf("finished locktest4\n");
1421 looks at lock upgrade/downgrade.
1423 static BOOL run_locktest5(int dummy)
1425 struct cli_state *cli1, *cli2;
1426 const char *fname = "\\lockt5.lck";
1427 int fnum1, fnum2, fnum3;
1430 BOOL correct = True;
1432 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
1436 printf("starting locktest5\n");
1438 cli_unlink(cli1, fname);
1440 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1441 fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
1442 fnum3 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1444 memset(buf, 0, sizeof(buf));
1446 if (cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
1447 printf("Failed to create file\n");
1452 /* Check for NT bug... */
1453 ret = cli_lock(cli1, fnum1, 0, 8, 0, READ_LOCK) &&
1454 cli_lock(cli1, fnum3, 0, 1, 0, READ_LOCK);
1455 cli_close(cli1, fnum1);
1456 fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1457 ret = cli_lock(cli1, fnum1, 7, 1, 0, WRITE_LOCK);
1458 EXPECTED(ret, True);
1459 printf("this server %s the NT locking bug\n", ret ? "doesn't have" : "has");
1460 cli_close(cli1, fnum1);
1461 fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1462 cli_unlock(cli1, fnum3, 0, 1);
1464 ret = cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK) &&
1465 cli_lock(cli1, fnum1, 1, 1, 0, READ_LOCK);
1466 EXPECTED(ret, True);
1467 printf("the same process %s overlay a write with a read lock\n", ret?"can":"cannot");
1469 ret = cli_lock(cli2, fnum2, 0, 4, 0, READ_LOCK);
1470 EXPECTED(ret, False);
1472 printf("a different processs %s get a read lock on the first process lock stack\n", ret?"can":"cannot");
1474 /* Unlock the process 2 lock. */
1475 cli_unlock(cli2, fnum2, 0, 4);
1477 ret = cli_lock(cli1, fnum3, 0, 4, 0, READ_LOCK);
1478 EXPECTED(ret, False);
1480 printf("the same processs on a different fnum %s get a read lock\n", ret?"can":"cannot");
1482 /* Unlock the process 1 fnum3 lock. */
1483 cli_unlock(cli1, fnum3, 0, 4);
1485 /* Stack 2 more locks here. */
1486 ret = cli_lock(cli1, fnum1, 0, 4, 0, READ_LOCK) &&
1487 cli_lock(cli1, fnum1, 0, 4, 0, READ_LOCK);
1489 EXPECTED(ret, True);
1490 printf("the same process %s stack read locks\n", ret?"can":"cannot");
1492 /* Unlock the first process lock, then check this was the WRITE lock that was
1495 ret = cli_unlock(cli1, fnum1, 0, 4) &&
1496 cli_lock(cli2, fnum2, 0, 4, 0, READ_LOCK);
1498 EXPECTED(ret, True);
1499 printf("the first unlock removes the %s lock\n", ret?"WRITE":"READ");
1501 /* Unlock the process 2 lock. */
1502 cli_unlock(cli2, fnum2, 0, 4);
1504 /* We should have 3 stacked locks here. Ensure we need to do 3 unlocks. */
1506 ret = cli_unlock(cli1, fnum1, 1, 1) &&
1507 cli_unlock(cli1, fnum1, 0, 4) &&
1508 cli_unlock(cli1, fnum1, 0, 4);
1510 EXPECTED(ret, True);
1511 printf("the same process %s unlock the stack of 4 locks\n", ret?"can":"cannot");
1513 /* Ensure the next unlock fails. */
1514 ret = cli_unlock(cli1, fnum1, 0, 4);
1515 EXPECTED(ret, False);
1516 printf("the same process %s count the lock stack\n", !ret?"can":"cannot");
1518 /* Ensure connection 2 can get a write lock. */
1519 ret = cli_lock(cli2, fnum2, 0, 4, 0, WRITE_LOCK);
1520 EXPECTED(ret, True);
1522 printf("a different processs %s get a write lock on the unlocked stack\n", ret?"can":"cannot");
1526 cli_close(cli1, fnum1);
1527 cli_close(cli2, fnum2);
1528 cli_unlink(cli1, fname);
1529 if (!torture_close_connection(cli1)) {
1532 if (!torture_close_connection(cli2)) {
1536 printf("finished locktest5\n");
1542 tries the unusual lockingX locktype bits
1544 static BOOL run_locktest6(int dummy)
1546 struct cli_state *cli;
1547 const char *fname[1] = { "\\lock6.txt" };
1552 if (!torture_open_connection(&cli)) {
1556 printf("starting locktest6\n");
1559 printf("Testing %s\n", fname[i]);
1561 cli_unlink(cli, fname[i]);
1563 fnum = cli_open(cli, fname[i], O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1564 status = cli_locktype(cli, fnum, 0, 8, 0, LOCKING_ANDX_CHANGE_LOCKTYPE);
1565 cli_close(cli, fnum);
1566 printf("CHANGE_LOCKTYPE gave %s\n", nt_errstr(status));
1568 fnum = cli_open(cli, fname[i], O_RDWR, DENY_NONE);
1569 status = cli_locktype(cli, fnum, 0, 8, 0, LOCKING_ANDX_CANCEL_LOCK);
1570 cli_close(cli, fnum);
1571 printf("CANCEL_LOCK gave %s\n", nt_errstr(status));
1573 cli_unlink(cli, fname[i]);
1576 torture_close_connection(cli);
1578 printf("finished locktest6\n");
1582 static BOOL run_locktest7(int dummy)
1584 struct cli_state *cli1;
1585 const char *fname = "\\lockt7.lck";
1588 BOOL correct = False;
1590 if (!torture_open_connection(&cli1)) {
1594 printf("starting locktest7\n");
1596 cli_unlink(cli1, fname);
1598 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1600 memset(buf, 0, sizeof(buf));
1602 if (cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
1603 printf("Failed to create file\n");
1607 cli1->session->pid = 1;
1609 if (!cli_lock(cli1, fnum1, 130, 4, 0, READ_LOCK)) {
1610 printf("Unable to apply read lock on range 130:4, error was %s\n", cli_errstr(cli1));
1613 printf("pid1 successfully locked range 130:4 for READ\n");
1616 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
1617 printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
1620 printf("pid1 successfully read the range 130:4\n");
1623 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
1624 printf("pid1 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
1625 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
1626 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
1630 printf("pid1 successfully wrote to the range 130:4 (should be denied)\n");
1634 cli1->session->pid = 2;
1636 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
1637 printf("pid2 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
1639 printf("pid2 successfully read the range 130:4\n");
1642 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
1643 printf("pid2 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
1644 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
1645 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
1649 printf("pid2 successfully wrote to the range 130:4 (should be denied)\n");
1653 cli1->session->pid = 1;
1654 cli_unlock(cli1, fnum1, 130, 4);
1656 if (!cli_lock(cli1, fnum1, 130, 4, 0, WRITE_LOCK)) {
1657 printf("Unable to apply write lock on range 130:4, error was %s\n", cli_errstr(cli1));
1660 printf("pid1 successfully locked range 130:4 for WRITE\n");
1663 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
1664 printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
1667 printf("pid1 successfully read the range 130:4\n");
1670 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
1671 printf("pid1 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
1674 printf("pid1 successfully wrote to the range 130:4\n");
1677 cli1->session->pid = 2;
1679 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
1680 printf("pid2 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
1681 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
1682 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
1686 printf("pid2 successfully read the range 130:4 (should be denied)\n");
1690 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
1691 printf("pid2 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
1692 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
1693 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
1697 printf("pid2 successfully wrote to the range 130:4 (should be denied)\n");
1701 cli_unlock(cli1, fnum1, 130, 0);
1705 cli_close(cli1, fnum1);
1706 cli_unlink(cli1, fname);
1707 torture_close_connection(cli1);
1709 printf("finished locktest7\n");
1714 test whether fnums and tids open on one VC are available on another (a major
1717 static BOOL run_fdpasstest(int dummy)
1719 struct cli_state *cli1, *cli2;
1720 const char *fname = "\\fdpass.tst";
1724 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
1728 printf("starting fdpasstest\n");
1730 cli_unlink(cli1, fname);
1732 printf("Opening a file on connection 1\n");
1734 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1736 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
1740 printf("writing to file on connection 1\n");
1742 if (cli_write(cli1, fnum1, 0, "hello world\n", 0, 13) != 13) {
1743 printf("write failed (%s)\n", cli_errstr(cli1));
1747 oldtid = cli2->tree->tid;
1748 cli2->session->vuid = cli1->session->vuid;
1749 cli2->tree->tid = cli1->tree->tid;
1750 cli2->session->pid = cli1->session->pid;
1752 printf("reading from file on connection 2\n");
1754 if (cli_read(cli2, fnum1, buf, 0, 13) == 13) {
1755 printf("read succeeded! nasty security hole [%s]\n",
1760 cli_close(cli1, fnum1);
1761 cli_unlink(cli1, fname);
1763 cli2->tree->tid = oldtid;
1765 torture_close_connection(cli1);
1766 torture_close_connection(cli2);
1768 printf("finished fdpasstest\n");
1774 This test checks that
1776 1) the server does not allow an unlink on a file that is open
1778 static BOOL run_unlinktest(int dummy)
1780 struct cli_state *cli;
1781 const char *fname = "\\unlink.tst";
1783 BOOL correct = True;
1785 if (!torture_open_connection(&cli)) {
1789 printf("starting unlink test\n");
1791 cli_unlink(cli, fname);
1793 cli->session->pid = 1;
1795 printf("Opening a file\n");
1797 fnum = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1799 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
1803 printf("Unlinking a open file\n");
1805 if (cli_unlink(cli, fname)) {
1806 printf("error: server allowed unlink on an open file\n");
1809 correct = check_error(__LINE__, cli, ERRDOS, ERRbadshare,
1810 NT_STATUS_SHARING_VIOLATION);
1813 cli_close(cli, fnum);
1814 cli_unlink(cli, fname);
1816 if (!torture_close_connection(cli)) {
1820 printf("unlink test finished\n");
1827 test how many open files this server supports on the one socket
1829 static BOOL run_maxfidtest(int dummy)
1831 struct cli_state *cli;
1832 const char *template = "\\maxfid.%d.%d";
1834 int fnums[0x11000], i;
1836 BOOL correct = True;
1841 printf("failed to connect\n");
1845 printf("Testing maximum number of open files\n");
1847 for (i=0; i<0x11000; i++) {
1848 asprintf(&fname, template, i,(int)getpid());
1849 if ((fnums[i] = cli_open(cli, fname,
1850 O_RDWR|O_CREAT|O_TRUNC, DENY_NONE)) ==
1852 printf("open of %s failed (%s)\n",
1853 fname, cli_errstr(cli));
1854 printf("maximum fnum is %d\n", i);
1863 printf("cleaning up\n");
1865 asprintf(&fname, template, i,(int)getpid());
1866 if (!cli_close(cli, fnums[i])) {
1867 printf("Close of fnum %d failed - %s\n", fnums[i], cli_errstr(cli));
1869 if (!cli_unlink(cli, fname)) {
1870 printf("unlink of %s failed (%s)\n",
1871 fname, cli_errstr(cli));
1879 printf("maxfid test finished\n");
1880 if (!torture_close_connection(cli)) {
1886 /* send smb negprot commands, not reading the response */
1887 static BOOL run_negprot_nowait(int dummy)
1890 struct cli_state *cli;
1891 BOOL correct = True;
1893 printf("starting negprot nowait test\n");
1895 cli = open_nbt_connection();
1900 printf("Establishing protocol negotiations - connect with another client\n");
1902 for (i=0;i<50000;i++) {
1903 smb_negprot_send(cli->transport, PROTOCOL_NT1);
1906 if (!torture_close_connection(cli)) {
1910 printf("finished negprot nowait test\n");
1917 This checks how the getatr calls works
1919 static BOOL run_attrtest(int dummy)
1921 struct cli_state *cli;
1924 const char *fname = "\\attrib123456789.tst";
1925 BOOL correct = True;
1927 printf("starting attrib test\n");
1929 if (!torture_open_connection(&cli)) {
1933 cli_unlink(cli, fname);
1934 fnum = cli_open(cli, fname,
1935 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1936 cli_close(cli, fnum);
1938 if (!cli_getatr(cli, fname, NULL, NULL, &t)) {
1939 printf("getatr failed (%s)\n", cli_errstr(cli));
1943 printf("New file time is %s", ctime(&t));
1945 if (abs(t - time(NULL)) > 60*60*24*10) {
1946 printf("ERROR: SMBgetatr bug. time is %s",
1952 t2 = t-60*60*24; /* 1 day ago */
1954 printf("Setting file time to %s", ctime(&t2));
1956 if (!cli_setatr(cli, fname, 0, t2)) {
1957 printf("setatr failed (%s)\n", cli_errstr(cli));
1961 if (!cli_getatr(cli, fname, NULL, NULL, &t)) {
1962 printf("getatr failed (%s)\n", cli_errstr(cli));
1966 printf("Retrieved file time as %s", ctime(&t));
1969 printf("ERROR: getatr/setatr bug. times are\n%s",
1971 printf("%s", ctime(&t2));
1975 cli_unlink(cli, fname);
1977 if (!torture_close_connection(cli)) {
1981 printf("attrib test finished\n");
1988 This checks a couple of trans2 calls
1990 static BOOL run_trans2test(int dummy)
1992 struct cli_state *cli;
1995 time_t c_time, a_time, m_time, w_time, m_time2;
1996 const char *fname = "\\trans2.tst";
1997 const char *dname = "\\trans2";
1998 const char *fname2 = "\\trans2\\trans2.tst";
2000 BOOL correct = True;
2002 printf("starting trans2 test\n");
2004 if (!torture_open_connection(&cli)) {
2008 cli_unlink(cli, fname);
2010 printf("Testing qfileinfo\n");
2012 fnum = cli_open(cli, fname,
2013 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2014 if (!cli_qfileinfo(cli, fnum, NULL, &size, &c_time, &a_time, &m_time,
2016 printf("ERROR: qfileinfo failed (%s)\n", cli_errstr(cli));
2020 printf("Testing NAME_INFO\n");
2022 if (!cli_qfilename(cli, fnum, &pname)) {
2023 printf("ERROR: qfilename failed (%s)\n", cli_errstr(cli));
2027 if (!pname || strcmp(pname, fname)) {
2028 printf("qfilename gave different name? [%s] [%s]\n",
2033 cli_close(cli, fnum);
2034 cli_unlink(cli, fname);
2036 fnum = cli_open(cli, fname,
2037 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2039 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
2042 cli_close(cli, fnum);
2044 printf("Checking for sticky create times\n");
2046 if (!cli_qpathinfo(cli, fname, &c_time, &a_time, &m_time, &size, NULL)) {
2047 printf("ERROR: qpathinfo failed (%s)\n", cli_errstr(cli));
2050 if (c_time != m_time) {
2051 printf("create time=%s", ctime(&c_time));
2052 printf("modify time=%s", ctime(&m_time));
2053 printf("This system appears to have sticky create times\n");
2055 if (a_time % (60*60) == 0) {
2056 printf("access time=%s", ctime(&a_time));
2057 printf("This system appears to set a midnight access time\n");
2061 if (abs(m_time - time(NULL)) > 60*60*24*7) {
2062 printf("ERROR: totally incorrect times - maybe word reversed? mtime=%s", ctime(&m_time));
2068 cli_unlink(cli, fname);
2069 fnum = cli_open(cli, fname,
2070 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2071 cli_close(cli, fnum);
2072 if (!cli_qpathinfo2(cli, fname, &c_time, &a_time, &m_time,
2073 &w_time, &size, NULL, NULL)) {
2074 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli));
2077 if (w_time < 60*60*24*2) {
2078 printf("write time=%s", ctime(&w_time));
2079 printf("This system appears to set a initial 0 write time\n");
2084 cli_unlink(cli, fname);
2087 /* check if the server updates the directory modification time
2088 when creating a new file */
2089 if (!cli_mkdir(cli, dname)) {
2090 printf("ERROR: mkdir failed (%s)\n", cli_errstr(cli));
2094 if (!cli_qpathinfo2(cli, "\\trans2\\", &c_time, &a_time, &m_time,
2095 &w_time, &size, NULL, NULL)) {
2096 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli));
2100 fnum = cli_open(cli, fname2,
2101 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2102 cli_write(cli, fnum, 0, (char *)&fnum, 0, sizeof(fnum));
2103 cli_close(cli, fnum);
2104 if (!cli_qpathinfo2(cli, "\\trans2\\", &c_time, &a_time, &m_time2,
2105 &w_time, &size, NULL, NULL)) {
2106 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli));
2109 if (m_time2 == m_time) {
2110 printf("This system does not update directory modification times\n");
2114 cli_unlink(cli, fname2);
2115 cli_rmdir(cli, dname);
2117 if (!torture_close_connection(cli)) {
2121 printf("trans2 test finished\n");
2127 Test delete on close semantics.
2129 static BOOL run_deletetest(int dummy)
2131 struct cli_state *cli1;
2132 struct cli_state *cli2 = NULL;
2133 const char *fname = "\\delete.file";
2136 BOOL correct = True;
2138 printf("starting delete test\n");
2140 if (!torture_open_connection(&cli1)) {
2144 /* Test 1 - this should delete the file on close. */
2146 cli_setatr(cli1, fname, 0, 0);
2147 cli_unlink(cli1, fname);
2149 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_RIGHTS_FILE_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL,
2150 NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OVERWRITE_IF,
2151 NTCREATEX_OPTIONS_DELETE_ON_CLOSE, 0);
2154 printf("[1] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2159 if (!cli_close(cli1, fnum1)) {
2160 printf("[1] close failed (%s)\n", cli_errstr(cli1));
2165 fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
2167 printf("[1] open of %s succeeded (should fail)\n", fname);
2172 printf("first delete on close test succeeded.\n");
2174 /* Test 2 - this should delete the file on close. */
2176 cli_setatr(cli1, fname, 0, 0);
2177 cli_unlink(cli1, fname);
2179 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_RIGHTS_FILE_ALL_ACCESS,
2180 FILE_ATTRIBUTE_NORMAL, NTCREATEX_SHARE_ACCESS_NONE,
2181 NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
2184 printf("[2] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2189 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
2190 printf("[2] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
2195 if (!cli_close(cli1, fnum1)) {
2196 printf("[2] close failed (%s)\n", cli_errstr(cli1));
2201 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
2203 printf("[2] open of %s succeeded should have been deleted on close !\n", fname);
2204 if (!cli_close(cli1, fnum1)) {
2205 printf("[2] close failed (%s)\n", cli_errstr(cli1));
2209 cli_unlink(cli1, fname);
2211 printf("second delete on close test succeeded.\n");
2214 cli_setatr(cli1, fname, 0, 0);
2215 cli_unlink(cli1, fname);
2217 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_RIGHTS_FILE_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL,
2218 NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
2221 printf("[3] open - 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
2226 /* This should fail with a sharing violation - open for delete is only compatible
2227 with SHARE_DELETE. */
2229 fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_RIGHTS_FILE_READ, FILE_ATTRIBUTE_NORMAL,
2230 NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE,
2231 NTCREATEX_DISP_OPEN, 0, 0);
2234 printf("[3] open - 2 of %s succeeded - should have failed.\n", fname);
2239 /* This should succeed. */
2241 fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_RIGHTS_FILE_READ, FILE_ATTRIBUTE_NORMAL,
2242 NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE|NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OPEN, 0, 0);
2245 printf("[3] open - 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
2250 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
2251 printf("[3] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
2256 if (!cli_close(cli1, fnum1)) {
2257 printf("[3] close 1 failed (%s)\n", cli_errstr(cli1));
2262 if (!cli_close(cli1, fnum2)) {
2263 printf("[3] close 2 failed (%s)\n", cli_errstr(cli1));
2268 /* This should fail - file should no longer be there. */
2270 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
2272 printf("[3] open of %s succeeded should have been deleted on close !\n", fname);
2273 if (!cli_close(cli1, fnum1)) {
2274 printf("[3] close failed (%s)\n", cli_errstr(cli1));
2276 cli_unlink(cli1, fname);
2280 printf("third delete on close test succeeded.\n");
2283 cli_setatr(cli1, fname, 0, 0);
2284 cli_unlink(cli1, fname);
2286 fnum1 = cli_nt_create_full(cli1, fname, 0,
2287 SA_RIGHT_FILE_READ_DATA |
2288 SA_RIGHT_FILE_WRITE_DATA |
2289 STD_RIGHT_DELETE_ACCESS,
2290 FILE_ATTRIBUTE_NORMAL,
2291 NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE,
2292 NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
2295 printf("[4] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2300 /* This should succeed. */
2301 fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_RIGHTS_FILE_READ,
2302 FILE_ATTRIBUTE_NORMAL,
2303 NTCREATEX_SHARE_ACCESS_READ |
2304 NTCREATEX_SHARE_ACCESS_WRITE |
2305 NTCREATEX_SHARE_ACCESS_DELETE,
2306 NTCREATEX_DISP_OPEN, 0, 0);
2308 printf("[4] open - 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
2313 if (!cli_close(cli1, fnum2)) {
2314 printf("[4] close - 1 failed (%s)\n", cli_errstr(cli1));
2319 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
2320 printf("[4] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
2325 /* This should fail - no more opens once delete on close set. */
2326 fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_RIGHTS_FILE_READ,
2327 FILE_ATTRIBUTE_NORMAL, NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE|NTCREATEX_SHARE_ACCESS_DELETE,
2328 NTCREATEX_DISP_OPEN, 0, 0);
2330 printf("[4] open - 3 of %s succeeded ! Should have failed.\n", fname );
2334 printf("fourth delete on close test succeeded.\n");
2336 if (!cli_close(cli1, fnum1)) {
2337 printf("[4] close - 2 failed (%s)\n", cli_errstr(cli1));
2343 cli_setatr(cli1, fname, 0, 0);
2344 cli_unlink(cli1, fname);
2346 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT, DENY_NONE);
2348 printf("[5] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2353 /* This should fail - only allowed on NT opens with DELETE access. */
2355 if (cli_nt_delete_on_close(cli1, fnum1, True)) {
2356 printf("[5] setting delete_on_close on OpenX file succeeded - should fail !\n");
2361 if (!cli_close(cli1, fnum1)) {
2362 printf("[5] close - 2 failed (%s)\n", cli_errstr(cli1));
2367 printf("fifth delete on close test succeeded.\n");
2370 cli_setatr(cli1, fname, 0, 0);
2371 cli_unlink(cli1, fname);
2373 fnum1 = cli_nt_create_full(cli1, fname, 0,
2374 SA_RIGHT_FILE_READ_DATA | SA_RIGHT_FILE_WRITE_DATA,
2375 FILE_ATTRIBUTE_NORMAL,
2376 NTCREATEX_SHARE_ACCESS_READ |
2377 NTCREATEX_SHARE_ACCESS_WRITE |
2378 NTCREATEX_SHARE_ACCESS_DELETE,
2379 NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
2382 printf("[6] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2387 /* This should fail - only allowed on NT opens with DELETE access. */
2389 if (cli_nt_delete_on_close(cli1, fnum1, True)) {
2390 printf("[6] setting delete_on_close on file with no delete access succeeded - should fail !\n");
2395 if (!cli_close(cli1, fnum1)) {
2396 printf("[6] close - 2 failed (%s)\n", cli_errstr(cli1));
2401 printf("sixth delete on close test succeeded.\n");
2404 cli_setatr(cli1, fname, 0, 0);
2405 cli_unlink(cli1, fname);
2407 fnum1 = cli_nt_create_full(cli1, fname, 0,
2408 SA_RIGHT_FILE_READ_DATA |
2409 SA_RIGHT_FILE_WRITE_DATA |
2410 STD_RIGHT_DELETE_ACCESS,
2411 FILE_ATTRIBUTE_NORMAL, 0, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
2414 printf("[7] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2419 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
2420 printf("[7] setting delete_on_close on file failed !\n");
2425 if (!cli_nt_delete_on_close(cli1, fnum1, False)) {
2426 printf("[7] unsetting delete_on_close on file failed !\n");
2431 if (!cli_close(cli1, fnum1)) {
2432 printf("[7] close - 2 failed (%s)\n", cli_errstr(cli1));
2437 /* This next open should succeed - we reset the flag. */
2439 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
2441 printf("[5] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2446 if (!cli_close(cli1, fnum1)) {
2447 printf("[7] close - 2 failed (%s)\n", cli_errstr(cli1));
2452 printf("seventh delete on close test succeeded.\n");
2455 cli_setatr(cli1, fname, 0, 0);
2456 cli_unlink(cli1, fname);
2458 if (!torture_open_connection(&cli2)) {
2459 printf("[8] failed to open second connection.\n");
2464 fnum1 = cli_nt_create_full(cli1, fname, 0, SA_RIGHT_FILE_READ_DATA|SA_RIGHT_FILE_WRITE_DATA|STD_RIGHT_DELETE_ACCESS,
2465 FILE_ATTRIBUTE_NORMAL, NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE|NTCREATEX_SHARE_ACCESS_DELETE,
2466 NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
2469 printf("[8] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2474 fnum2 = cli_nt_create_full(cli2, fname, 0, SA_RIGHT_FILE_READ_DATA|SA_RIGHT_FILE_WRITE_DATA|STD_RIGHT_DELETE_ACCESS,
2475 FILE_ATTRIBUTE_NORMAL, NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE|NTCREATEX_SHARE_ACCESS_DELETE,
2476 NTCREATEX_DISP_OPEN, 0, 0);
2479 printf("[8] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2484 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
2485 printf("[8] setting delete_on_close on file failed !\n");
2490 if (!cli_close(cli1, fnum1)) {
2491 printf("[8] close - 1 failed (%s)\n", cli_errstr(cli1));
2496 if (!cli_close(cli2, fnum2)) {
2497 printf("[8] close - 2 failed (%s)\n", cli_errstr(cli2));
2502 /* This should fail.. */
2503 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
2505 printf("[8] open of %s succeeded should have been deleted on close !\n", fname);
2509 printf("eighth delete on close test succeeded.\n");
2511 /* This should fail - we need to set DELETE_ACCESS. */
2512 fnum1 = cli_nt_create_full(cli1, fname, 0,SA_RIGHT_FILE_READ_DATA|SA_RIGHT_FILE_WRITE_DATA,
2513 FILE_ATTRIBUTE_NORMAL, NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, NTCREATEX_OPTIONS_DELETE_ON_CLOSE, 0);
2516 printf("[9] open of %s succeeded should have failed!\n", fname);
2521 printf("ninth delete on close test succeeded.\n");
2523 fnum1 = cli_nt_create_full(cli1, fname, 0, SA_RIGHT_FILE_READ_DATA|SA_RIGHT_FILE_WRITE_DATA|STD_RIGHT_DELETE_ACCESS,
2524 FILE_ATTRIBUTE_NORMAL, NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, NTCREATEX_OPTIONS_DELETE_ON_CLOSE, 0);
2526 printf("[10] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2531 /* This should delete the file. */
2532 if (!cli_close(cli1, fnum1)) {
2533 printf("[10] close failed (%s)\n", cli_errstr(cli1));
2538 /* This should fail.. */
2539 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
2541 printf("[10] open of %s succeeded should have been deleted on close !\n", fname);
2545 printf("tenth delete on close test succeeded.\n");
2546 printf("finished delete test\n");
2549 /* FIXME: This will crash if we aborted before cli2 got
2550 * intialized, because these functions don't handle
2551 * uninitialized connections. */
2553 cli_close(cli1, fnum1);
2554 cli_close(cli1, fnum2);
2555 cli_setatr(cli1, fname, 0, 0);
2556 cli_unlink(cli1, fname);
2558 if (!torture_close_connection(cli1)) {
2561 if (!torture_close_connection(cli2)) {
2569 print out server properties
2571 static BOOL run_properties(int dummy)
2573 struct cli_state *cli;
2574 BOOL correct = True;
2576 printf("starting properties test\n");
2580 if (!torture_open_connection(&cli)) {
2584 d_printf("Capabilities 0x%08x\n", cli->transport->negotiate.capabilities);
2586 if (!torture_close_connection(cli)) {
2595 /* FIRST_DESIRED_ACCESS 0xf019f */
2596 #define FIRST_DESIRED_ACCESS SA_RIGHT_FILE_READ_DATA|SA_RIGHT_FILE_WRITE_DATA|SA_RIGHT_FILE_APPEND_DATA|\
2597 SA_RIGHT_FILE_READ_EA| /* 0xf */ \
2598 SA_RIGHT_FILE_WRITE_EA|SA_RIGHT_FILE_READ_ATTRIBUTES| /* 0x90 */ \
2599 SA_RIGHT_FILE_WRITE_ATTRIBUTES| /* 0x100 */ \
2600 STD_RIGHT_DELETE_ACCESS|STD_RIGHT_READ_CONTROL_ACCESS|\
2601 STD_RIGHT_WRITE_DAC_ACCESS|STD_RIGHT_WRITE_OWNER_ACCESS /* 0xf0000 */
2602 /* SECOND_DESIRED_ACCESS 0xe0080 */
2603 #define SECOND_DESIRED_ACCESS SA_RIGHT_FILE_READ_ATTRIBUTES| /* 0x80 */ \
2604 STD_RIGHT_READ_CONTROL_ACCESS|STD_RIGHT_WRITE_DAC_ACCESS|\
2605 STD_RIGHT_WRITE_OWNER_ACCESS /* 0xe0000 */
2608 #define THIRD_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
2609 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
2610 SA_RIGHT_FILE_READ_DATA|\
2611 WRITE_OWNER_ACCESS /* */
2615 Test ntcreate calls made by xcopy
2617 static BOOL run_xcopy(int dummy)
2619 struct cli_state *cli1;
2620 const char *fname = "\\test.txt";
2621 BOOL correct = True;
2624 printf("starting xcopy test\n");
2626 if (!torture_open_connection(&cli1)) {
2630 fnum1 = cli_nt_create_full(cli1, fname, 0,
2631 FIRST_DESIRED_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
2632 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF,
2636 printf("First open failed - %s\n", cli_errstr(cli1));
2640 fnum2 = cli_nt_create_full(cli1, fname, 0,
2641 SECOND_DESIRED_ACCESS, 0,
2642 NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE|NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OPEN,
2645 printf("second open failed - %s\n", cli_errstr(cli1));
2649 if (!torture_close_connection(cli1)) {
2657 Test rename on files open with share delete and no share delete.
2659 static BOOL run_rename(int dummy)
2661 struct cli_state *cli1;
2662 const char *fname = "\\test.txt";
2663 const char *fname1 = "\\test1.txt";
2664 BOOL correct = True;
2667 printf("starting rename test\n");
2669 if (!torture_open_connection(&cli1)) {
2673 cli_unlink(cli1, fname);
2674 cli_unlink(cli1, fname1);
2675 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_RIGHTS_FILE_READ, FILE_ATTRIBUTE_NORMAL,
2676 NTCREATEX_SHARE_ACCESS_READ, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
2679 printf("First open failed - %s\n", cli_errstr(cli1));
2683 if (!cli_rename(cli1, fname, fname1)) {
2684 printf("First rename failed (this is correct) - %s\n", cli_errstr(cli1));
2686 printf("First rename succeeded - this should have failed !\n");
2690 if (!cli_close(cli1, fnum1)) {
2691 printf("close - 1 failed (%s)\n", cli_errstr(cli1));
2695 cli_unlink(cli1, fname);
2696 cli_unlink(cli1, fname1);
2697 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_RIGHTS_FILE_READ, FILE_ATTRIBUTE_NORMAL,
2699 NTCREATEX_SHARE_ACCESS_DELETE|NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
2701 NTCREATEX_SHARE_ACCESS_DELETE|NTCREATEX_SHARE_ACCESS_READ, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
2705 printf("Second open failed - %s\n", cli_errstr(cli1));
2709 if (!cli_rename(cli1, fname, fname1)) {
2710 printf("Second rename failed - this should have succeeded - %s\n", cli_errstr(cli1));
2713 printf("Second rename succeeded\n");
2716 if (!cli_close(cli1, fnum1)) {
2717 printf("close - 2 failed (%s)\n", cli_errstr(cli1));
2721 cli_unlink(cli1, fname);
2722 cli_unlink(cli1, fname1);
2724 fnum1 = cli_nt_create_full(cli1, fname, 0, STD_RIGHT_READ_CONTROL_ACCESS, FILE_ATTRIBUTE_NORMAL,
2725 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
2728 printf("Third open failed - %s\n", cli_errstr(cli1));
2737 fnum2 = cli_nt_create_full(cli1, fname, 0, DELETE_ACCESS, FILE_ATTRIBUTE_NORMAL,
2738 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
2741 printf("Fourth open failed - %s\n", cli_errstr(cli1));
2744 if (!cli_nt_delete_on_close(cli1, fnum2, True)) {
2745 printf("[8] setting delete_on_close on file failed !\n");
2749 if (!cli_close(cli1, fnum2)) {
2750 printf("close - 4 failed (%s)\n", cli_errstr(cli1));
2756 if (!cli_rename(cli1, fname, fname1)) {
2757 printf("Third rename failed - this should have succeeded - %s\n", cli_errstr(cli1));
2760 printf("Third rename succeeded\n");
2763 if (!cli_close(cli1, fnum1)) {
2764 printf("close - 3 failed (%s)\n", cli_errstr(cli1));
2768 cli_unlink(cli1, fname);
2769 cli_unlink(cli1, fname1);
2771 if (!torture_close_connection(cli1)) {
2778 static BOOL run_pipe_number(int dummy)
2780 struct cli_state *cli1;
2781 const char *pipe_name = "\\SPOOLSS";
2785 printf("starting pipenumber test\n");
2786 if (!torture_open_connection(&cli1)) {
2791 fnum = cli_nt_create_full(cli1, pipe_name, 0, SA_RIGHT_FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
2792 NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE, NTCREATEX_DISP_OPEN_IF, 0, 0);
2795 printf("Open of pipe %s failed with error (%s)\n", pipe_name, cli_errstr(cli1));
2801 printf("pipe_number test - we can open %d %s pipes.\n", num_pipes, pipe_name );
2802 torture_close_connection(cli1);
2808 Test open mode returns on read-only files.
2810 static BOOL run_opentest(int dummy)
2812 static struct cli_state *cli1;
2813 static struct cli_state *cli2;
2814 const char *fname = "\\readonly.file";
2818 BOOL correct = True;
2822 printf("starting open test\n");
2824 if (!torture_open_connection(&cli1)) {
2828 cli_setatr(cli1, fname, 0, 0);
2829 cli_unlink(cli1, fname);
2831 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2833 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
2837 if (!cli_close(cli1, fnum1)) {
2838 printf("close2 failed (%s)\n", cli_errstr(cli1));
2842 if (!cli_setatr(cli1, fname, FILE_ATTRIBUTE_READONLY, 0)) {
2843 printf("cli_setatr failed (%s)\n", cli_errstr(cli1));
2844 CHECK_MAX_FAILURES(error_test1);
2848 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_WRITE);
2850 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
2851 CHECK_MAX_FAILURES(error_test1);
2855 /* This will fail - but the error should be ERRnoaccess, not ERRbadshare. */
2856 fnum2 = cli_open(cli1, fname, O_RDWR, DENY_ALL);
2858 if (check_error(__LINE__, cli1, ERRDOS, ERRnoaccess,
2859 NT_STATUS_ACCESS_DENIED)) {
2860 printf("correct error code ERRDOS/ERRnoaccess returned\n");
2863 printf("finished open test 1\n");
2865 cli_close(cli1, fnum1);
2867 /* Now try not readonly and ensure ERRbadshare is returned. */
2869 cli_setatr(cli1, fname, 0, 0);
2871 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_WRITE);
2873 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
2877 /* This will fail - but the error should be ERRshare. */
2878 fnum2 = cli_open(cli1, fname, O_RDWR, DENY_ALL);
2880 if (check_error(__LINE__, cli1, ERRDOS, ERRbadshare,
2881 NT_STATUS_SHARING_VIOLATION)) {
2882 printf("correct error code ERRDOS/ERRbadshare returned\n");
2885 if (!cli_close(cli1, fnum1)) {
2886 printf("close2 failed (%s)\n", cli_errstr(cli1));
2890 cli_unlink(cli1, fname);
2892 printf("finished open test 2\n");
2894 /* Test truncate open disposition on file opened for read. */
2896 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2898 printf("(3) open (1) of %s failed (%s)\n", fname, cli_errstr(cli1));
2902 /* write 20 bytes. */
2904 memset(buf, '\0', 20);
2906 if (cli_write(cli1, fnum1, 0, buf, 0, 20) != 20) {
2907 printf("write failed (%s)\n", cli_errstr(cli1));
2911 if (!cli_close(cli1, fnum1)) {
2912 printf("(3) close1 failed (%s)\n", cli_errstr(cli1));
2916 /* Ensure size == 20. */
2917 if (!cli_getatr(cli1, fname, NULL, &fsize, NULL)) {
2918 printf("(3) getatr failed (%s)\n", cli_errstr(cli1));
2919 CHECK_MAX_FAILURES(error_test3);
2924 printf("(3) file size != 20\n");
2925 CHECK_MAX_FAILURES(error_test3);
2929 /* Now test if we can truncate a file opened for readonly. */
2931 fnum1 = cli_open(cli1, fname, O_RDONLY|O_TRUNC, DENY_NONE);
2933 printf("(3) open (2) of %s failed (%s)\n", fname, cli_errstr(cli1));
2934 CHECK_MAX_FAILURES(error_test3);
2938 if (!cli_close(cli1, fnum1)) {
2939 printf("close2 failed (%s)\n", cli_errstr(cli1));
2943 /* Ensure size == 0. */
2944 if (!cli_getatr(cli1, fname, NULL, &fsize, NULL)) {
2945 printf("(3) getatr failed (%s)\n", cli_errstr(cli1));
2946 CHECK_MAX_FAILURES(error_test3);
2951 printf("(3) file size != 0\n");
2952 CHECK_MAX_FAILURES(error_test3);
2955 printf("finished open test 3\n");
2957 cli_unlink(cli1, fname);
2960 printf("testing ctemp\n");
2961 fnum1 = cli_ctemp(cli1, "\\", &tmp_path);
2963 printf("ctemp failed (%s)\n", cli_errstr(cli1));
2964 CHECK_MAX_FAILURES(error_test4);
2967 printf("ctemp gave path %s\n", tmp_path);
2968 if (!cli_close(cli1, fnum1)) {
2969 printf("close of temp failed (%s)\n", cli_errstr(cli1));
2971 if (!cli_unlink(cli1, tmp_path)) {
2972 printf("unlink of temp failed (%s)\n", cli_errstr(cli1));
2975 /* Test the non-io opens... */
2977 if (!torture_open_connection(&cli2)) {
2981 cli_setatr(cli2, fname, 0, 0);
2982 cli_unlink(cli2, fname);
2984 printf("TEST #1 testing 2 non-io opens (no delete)\n");
2986 fnum1 = cli_nt_create_full(cli1, fname, 0, SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
2987 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
2990 printf("test 1 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
2991 CHECK_MAX_FAILURES(error_test10);
2995 fnum2 = cli_nt_create_full(cli2, fname, 0, SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
2996 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OPEN_IF, 0, 0);
2998 printf("test 1 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
2999 CHECK_MAX_FAILURES(error_test10);
3003 if (!cli_close(cli1, fnum1)) {
3004 printf("test 1 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3007 if (!cli_close(cli2, fnum2)) {
3008 printf("test 1 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3012 printf("non-io open test #1 passed.\n");
3014 cli_unlink(cli1, fname);
3016 printf("TEST #2 testing 2 non-io opens (first with delete)\n");
3018 fnum1 = cli_nt_create_full(cli1, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3019 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
3022 printf("test 2 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3023 CHECK_MAX_FAILURES(error_test20);
3027 fnum2 = cli_nt_create_full(cli2, fname, 0, SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3028 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OPEN_IF, 0, 0);
3031 printf("test 2 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3032 CHECK_MAX_FAILURES(error_test20);
3036 if (!cli_close(cli1, fnum1)) {
3037 printf("test 1 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3040 if (!cli_close(cli2, fnum2)) {
3041 printf("test 1 close 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
3045 printf("non-io open test #2 passed.\n");
3047 cli_unlink(cli1, fname);
3049 printf("TEST #3 testing 2 non-io opens (second with delete)\n");
3051 fnum1 = cli_nt_create_full(cli1, fname, 0, SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3052 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
3055 printf("test 3 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3056 CHECK_MAX_FAILURES(error_test30);
3060 fnum2 = cli_nt_create_full(cli2, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3061 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OPEN_IF, 0, 0);
3064 printf("test 3 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3065 CHECK_MAX_FAILURES(error_test30);
3069 if (!cli_close(cli1, fnum1)) {
3070 printf("test 3 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3073 if (!cli_close(cli2, fnum2)) {
3074 printf("test 3 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3078 printf("non-io open test #3 passed.\n");
3080 cli_unlink(cli1, fname);
3082 printf("TEST #4 testing 2 non-io opens (both with delete)\n");
3084 fnum1 = cli_nt_create_full(cli1, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3085 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
3088 printf("test 4 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3089 CHECK_MAX_FAILURES(error_test40);
3093 fnum2 = cli_nt_create_full(cli2, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3094 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OPEN_IF, 0, 0);
3097 printf("test 4 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, cli_errstr(cli2));
3098 CHECK_MAX_FAILURES(error_test40);
3102 printf("test 4 open 2 of %s gave %s (correct error should be %s)\n", fname, cli_errstr(cli2), "sharing violation");
3104 if (!cli_close(cli1, fnum1)) {
3105 printf("test 4 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3109 printf("non-io open test #4 passed.\n");
3111 cli_unlink(cli1, fname);
3113 printf("TEST #5 testing 2 non-io opens (both with delete - both with file share delete)\n");
3115 fnum1 = cli_nt_create_full(cli1, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3116 NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
3119 printf("test 5 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3120 CHECK_MAX_FAILURES(error_test50);
3124 fnum2 = cli_nt_create_full(cli2, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3125 NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OPEN_IF, 0, 0);
3128 printf("test 5 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3129 CHECK_MAX_FAILURES(error_test50);
3133 if (!cli_close(cli1, fnum1)) {
3134 printf("test 5 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3138 if (!cli_close(cli2, fnum2)) {
3139 printf("test 5 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3143 printf("non-io open test #5 passed.\n");
3145 printf("TEST #6 testing 1 non-io open, one io open\n");
3147 cli_unlink(cli1, fname);
3149 fnum1 = cli_nt_create_full(cli1, fname, 0, SA_RIGHT_FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
3150 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
3153 printf("test 6 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3154 CHECK_MAX_FAILURES(error_test60);
3158 fnum2 = cli_nt_create_full(cli2, fname, 0, SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3159 NTCREATEX_SHARE_ACCESS_READ, NTCREATEX_DISP_OPEN_IF, 0, 0);
3162 printf("test 6 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3163 CHECK_MAX_FAILURES(error_test60);
3167 if (!cli_close(cli1, fnum1)) {
3168 printf("test 6 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3172 if (!cli_close(cli2, fnum2)) {
3173 printf("test 6 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3177 printf("non-io open test #6 passed.\n");
3179 printf("TEST #7 testing 1 non-io open, one io open with delete\n");
3181 cli_unlink(cli1, fname);
3183 fnum1 = cli_nt_create_full(cli1, fname, 0, SA_RIGHT_FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
3184 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
3187 printf("test 7 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3188 CHECK_MAX_FAILURES(error_test70);
3192 fnum2 = cli_nt_create_full(cli2, fname, 0, STD_RIGHT_DELETE_ACCESS|SA_RIGHT_FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3193 NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OPEN_IF, 0, 0);
3196 printf("test 7 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, cli_errstr(cli2));
3197 CHECK_MAX_FAILURES(error_test70);
3201 printf("test 7 open 2 of %s gave %s (correct error should be %s)\n", fname, cli_errstr(cli2), "sharing violation");
3203 if (!cli_close(cli1, fnum1)) {
3204 printf("test 7 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3208 printf("non-io open test #7 passed.\n");
3210 cli_unlink(cli1, fname);
3212 if (!torture_close_connection(cli1)) {
3215 if (!torture_close_connection(cli2)) {
3223 static uint32 open_attrs_table[] = {
3224 FILE_ATTRIBUTE_NORMAL,
3225 FILE_ATTRIBUTE_ARCHIVE,
3226 FILE_ATTRIBUTE_READONLY,
3227 FILE_ATTRIBUTE_HIDDEN,
3228 FILE_ATTRIBUTE_SYSTEM,
3230 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY,
3231 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN,
3232 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM,
3233 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN,
3234 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM,
3235 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM,
3237 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN,
3238 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM,
3239 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM,
3240 FILE_ATTRIBUTE_HIDDEN,FILE_ATTRIBUTE_SYSTEM,
3243 struct trunc_open_results {
3250 static struct trunc_open_results attr_results[] = {
3251 { 0, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE },
3252 { 1, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE },
3253 { 2, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_READONLY, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY },
3254 { 16, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE },
3255 { 17, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE },
3256 { 18, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_READONLY, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY },
3257 { 51, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
3258 { 54, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
3259 { 56, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN },
3260 { 68, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
3261 { 71, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
3262 { 73, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM },
3263 { 99, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN,FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
3264 { 102, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
3265 { 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 },
3266 { 116, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
3267 { 119, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
3268 { 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 },
3269 { 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 },
3270 { 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 },
3271 { 227, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
3272 { 230, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
3273 { 232, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN },
3274 { 244, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
3275 { 247, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
3276 { 249, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM }
3279 static BOOL run_openattrtest(int dummy)
3281 struct cli_state *cli1;
3282 const char *fname = "\\openattr.file";
3284 BOOL correct = True;
3286 unsigned int i, j, k, l;
3289 printf("starting open attr test\n");
3291 if (!torture_open_connection(&cli1)) {
3295 for (k = 0, i = 0; i < sizeof(open_attrs_table)/sizeof(uint32); i++) {
3296 cli_setatr(cli1, fname, 0, 0);
3297 cli_unlink(cli1, fname);
3298 fnum1 = cli_nt_create_full(cli1, fname, 0, SA_RIGHT_FILE_WRITE_DATA, open_attrs_table[i],
3299 NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
3302 printf("open %d (1) of %s failed (%s)\n", i, fname, cli_errstr(cli1));
3306 if (!cli_close(cli1, fnum1)) {
3307 printf("close %d (1) of %s failed (%s)\n", i, fname, cli_errstr(cli1));
3311 for (j = 0; j < ARRAY_SIZE(open_attrs_table); j++) {
3312 fnum1 = cli_nt_create_full(cli1, fname, 0,
3313 SA_RIGHT_FILE_READ_DATA|SA_RIGHT_FILE_WRITE_DATA,
3314 open_attrs_table[j],
3315 NTCREATEX_SHARE_ACCESS_NONE,
3316 NTCREATEX_DISP_OVERWRITE, 0, 0);
3319 for (l = 0; l < ARRAY_SIZE(attr_results); l++) {
3320 if (attr_results[l].num == k) {
3321 printf("[%d] trunc open 0x%x -> 0x%x of %s failed - should have succeeded !(0x%x:%s)\n",
3322 k, open_attrs_table[i],
3323 open_attrs_table[j],
3324 fname, NT_STATUS_V(cli_nt_error(cli1)), cli_errstr(cli1));
3326 CHECK_MAX_FAILURES(error_exit);
3329 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_ACCESS_DENIED)) {
3330 printf("[%d] trunc open 0x%x -> 0x%x failed with wrong error code %s\n",
3331 k, open_attrs_table[i], open_attrs_table[j],
3334 CHECK_MAX_FAILURES(error_exit);
3337 printf("[%d] trunc open 0x%x -> 0x%x failed\n", k, open_attrs_table[i], open_attrs_table[j]);
3343 if (!cli_close(cli1, fnum1)) {
3344 printf("close %d (2) of %s failed (%s)\n", j, fname, cli_errstr(cli1));
3348 if (!cli_getatr(cli1, fname, &attr, NULL, NULL)) {
3349 printf("getatr(2) failed (%s)\n", cli_errstr(cli1));
3354 printf("[%d] getatr check [0x%x] trunc [0x%x] got attr 0x%x\n",
3355 k, open_attrs_table[i], open_attrs_table[j], attr );
3358 for (l = 0; l < ARRAY_SIZE(attr_results); l++) {
3359 if (attr_results[l].num == k) {
3360 if (attr != attr_results[l].result_attr ||
3361 open_attrs_table[i] != attr_results[l].init_attr ||
3362 open_attrs_table[j] != attr_results[l].trunc_attr) {
3363 printf("[%d] getatr check failed. [0x%x] trunc [0x%x] got attr 0x%x, should be 0x%x\n",
3364 k, open_attrs_table[i],
3365 open_attrs_table[j],
3367 attr_results[l].result_attr);
3369 CHECK_MAX_FAILURES(error_exit);
3378 cli_setatr(cli1, fname, 0, 0);
3379 cli_unlink(cli1, fname);
3381 printf("open attr test %s.\n", correct ? "passed" : "failed");
3383 if (!torture_close_connection(cli1)) {
3389 static void list_fn(file_info *finfo, const char *name, void *state)
3395 test directory listing speed
3397 static BOOL run_dirtest(int dummy)
3400 struct cli_state *cli;
3403 BOOL correct = True;
3405 printf("starting directory test\n");
3407 if (!torture_open_connection(&cli)) {
3411 printf("Creating %d random filenames\n", torture_numops);
3414 for (i=0;i<torture_numops;i++) {
3416 asprintf(&fname, "\\%x", (int)random());
3417 fnum = cli_open(cli, fname, O_RDWR|O_CREAT, DENY_NONE);
3419 fprintf(stderr,"Failed to open %s\n", fname);
3422 cli_close(cli, fnum);
3428 printf("Matched %d\n", cli_list(cli, "a*.*", 0, list_fn, NULL));
3429 printf("Matched %d\n", cli_list(cli, "b*.*", 0, list_fn, NULL));
3430 printf("Matched %d\n", cli_list(cli, "xyzabc", 0, list_fn, NULL));
3432 printf("dirtest core %g seconds\n", end_timer() - t1);
3435 for (i=0;i<torture_numops;i++) {
3437 asprintf(&fname, "\\%x", (int)random());
3438 cli_unlink(cli, fname);
3442 if (!torture_close_connection(cli)) {
3446 printf("finished dirtest\n");
3451 static void del_fn(file_info *finfo, const char *mask, void *state)
3453 struct cli_state *pcli = (struct cli_state *)state;
3455 asprintf(&fname, "\\LISTDIR\\%s", finfo->name);
3457 if (strcmp(finfo->name, ".") == 0 || strcmp(finfo->name, "..") == 0)
3460 if (finfo->mode & FILE_ATTRIBUTE_DIRECTORY) {
3461 if (!cli_rmdir(pcli, fname))
3462 printf("del_fn: failed to rmdir %s, error=%s\n", fname, cli_errstr(pcli) );
3464 if (!cli_unlink(pcli, fname))
3465 printf("del_fn: failed to unlink %s, error=%s\n", fname, cli_errstr(pcli) );
3472 sees what IOCTLs are supported
3474 BOOL torture_ioctl_test(int dummy)
3476 struct cli_state *cli;
3477 uint16 device, function;
3479 const char *fname = "\\ioctl.dat";
3482 struct smb_ioctl parms;
3483 TALLOC_CTX *mem_ctx;
3485 if (!torture_open_connection(&cli)) {
3489 mem_ctx = talloc_init("ioctl_test");
3491 printf("starting ioctl test\n");
3493 cli_unlink(cli, fname);
3495 fnum = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
3497 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
3501 parms.in.request = IOCTL_QUERY_JOB_INFO;
3502 status = smb_raw_ioctl(cli->tree, mem_ctx, &parms);
3503 printf("ioctl job info: %s\n", cli_errstr(cli));
3505 for (device=0;device<0x100;device++) {
3506 printf("testing device=0x%x\n", device);
3507 for (function=0;function<0x100;function++) {
3508 parms.in.request = (device << 16) | function;
3509 status = smb_raw_ioctl(cli->tree, mem_ctx, &parms);
3511 if (NT_STATUS_IS_OK(status)) {
3512 printf("ioctl device=0x%x function=0x%x OK : %d bytes\n",
3513 device, function, blob.length);
3514 data_blob_free(&parms.out.blob);
3519 if (!torture_close_connection(cli)) {
3528 tries variants of chkpath
3530 BOOL torture_chkpath_test(int dummy)
3532 struct cli_state *cli;
3536 if (!torture_open_connection(&cli)) {
3540 printf("starting chkpath test\n");
3542 printf("Testing valid and invalid paths\n");
3544 /* cleanup from an old run */
3545 cli_rmdir(cli, "\\chkpath.dir\\dir2");
3546 cli_unlink(cli, "\\chkpath.dir\\*");
3547 cli_rmdir(cli, "\\chkpath.dir");
3549 if (!cli_mkdir(cli, "\\chkpath.dir")) {
3550 printf("mkdir1 failed : %s\n", cli_errstr(cli));
3554 if (!cli_mkdir(cli, "\\chkpath.dir\\dir2")) {
3555 printf("mkdir2 failed : %s\n", cli_errstr(cli));
3559 fnum = cli_open(cli, "\\chkpath.dir\\foo.txt", O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
3561 printf("open1 failed (%s)\n", cli_errstr(cli));
3564 cli_close(cli, fnum);
3566 if (!cli_chkpath(cli, "\\chkpath.dir")) {
3567 printf("chkpath1 failed: %s\n", cli_errstr(cli));
3571 if (!cli_chkpath(cli, "\\chkpath.dir\\dir2")) {
3572 printf("chkpath2 failed: %s\n", cli_errstr(cli));
3576 if (!cli_chkpath(cli, "\\chkpath.dir\\foo.txt")) {
3577 ret = check_error(__LINE__, cli, ERRDOS, ERRbadpath,
3578 NT_STATUS_NOT_A_DIRECTORY);
3580 printf("* chkpath on a file should fail\n");
3584 if (!cli_chkpath(cli, "\\chkpath.dir\\bar.txt")) {
3585 ret = check_error(__LINE__, cli, ERRDOS, ERRbadfile,
3586 NT_STATUS_OBJECT_NAME_NOT_FOUND);
3588 printf("* chkpath on a non existent file should fail\n");
3592 if (!cli_chkpath(cli, "\\chkpath.dir\\dirxx\\bar.txt")) {
3593 ret = check_error(__LINE__, cli, ERRDOS, ERRbadpath,
3594 NT_STATUS_OBJECT_PATH_NOT_FOUND);
3596 printf("* chkpath on a non existent component should fail\n");
3600 cli_rmdir(cli, "\\chkpath.dir\\dir2");
3601 cli_unlink(cli, "\\chkpath.dir\\*");
3602 cli_rmdir(cli, "\\chkpath.dir");
3604 if (!torture_close_connection(cli)) {
3614 static BOOL run_dirtest1(int dummy)
3617 struct cli_state *cli;
3619 BOOL correct = True;
3621 printf("starting directory test\n");
3623 if (!torture_open_connection(&cli)) {
3627 cli_list(cli, "\\LISTDIR\\*", 0, del_fn, cli);
3628 cli_list(cli, "\\LISTDIR\\*", FILE_ATTRIBUTE_DIRECTORY, del_fn, cli);
3629 if (cli_deltree(cli, "\\LISTDIR") == -1) {
3630 fprintf(stderr,"Failed to deltree %s, error=%s\n", "\\LISTDIR", cli_errstr(cli));
3633 if (!cli_mkdir(cli, "\\LISTDIR")) {
3634 fprintf(stderr,"Failed to mkdir %s, error=%s\n", "\\LISTDIR", cli_errstr(cli));
3638 printf("Creating %d files\n", torture_entries);
3640 /* Create torture_entries files and torture_entries directories. */
3641 for (i=0;i<torture_entries;i++) {
3643 asprintf(&fname, "\\LISTDIR\\f%d", i);
3644 fnum = cli_nt_create_full(cli, fname, 0, GENERIC_RIGHTS_FILE_ALL_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
3645 NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
3647 fprintf(stderr,"Failed to open %s, error=%s\n", fname, cli_errstr(cli));
3651 cli_close(cli, fnum);
3653 for (i=0;i<torture_entries;i++) {
3655 asprintf(&fname, "\\LISTDIR\\d%d", i);
3656 if (!cli_mkdir(cli, fname)) {
3657 fprintf(stderr,"Failed to open %s, error=%s\n", fname, cli_errstr(cli));
3663 /* Now ensure that doing an old list sees both files and directories. */
3664 num_seen = cli_list_old(cli, "\\LISTDIR\\*", FILE_ATTRIBUTE_DIRECTORY, list_fn, NULL);
3665 printf("num_seen = %d\n", num_seen );
3666 /* We should see (torture_entries) each of files & directories + . and .. */
3667 if (num_seen != (2*torture_entries)+2) {
3669 fprintf(stderr,"entry count mismatch, should be %d, was %d\n",
3670 (2*torture_entries)+2, num_seen);
3674 /* Ensure if we have the "must have" bits we only see the
3677 num_seen = cli_list_old(cli, "\\LISTDIR\\*", (FILE_ATTRIBUTE_DIRECTORY<<8)|FILE_ATTRIBUTE_DIRECTORY, list_fn, NULL);
3678 printf("num_seen = %d\n", num_seen );
3679 if (num_seen != torture_entries+2) {
3681 fprintf(stderr,"entry count mismatch, should be %d, was %d\n",
3682 torture_entries+2, num_seen);
3685 num_seen = cli_list_old(cli, "\\LISTDIR\\*", (FILE_ATTRIBUTE_ARCHIVE<<8)|FILE_ATTRIBUTE_DIRECTORY, list_fn, NULL);
3686 printf("num_seen = %d\n", num_seen );
3687 if (num_seen != torture_entries) {
3689 fprintf(stderr,"entry count mismatch, should be %d, was %d\n",
3690 torture_entries, num_seen);
3693 /* Delete everything. */
3694 cli_list(cli, "\\LISTDIR\\*", 0, del_fn, cli);
3695 cli_list(cli, "\\LISTDIR\\*", FILE_ATTRIBUTE_DIRECTORY, del_fn, cli);
3696 cli_rmdir(cli, "\\LISTDIR");
3699 printf("Matched %d\n", cli_list(cli, "a*.*", 0, list_fn, NULL));
3700 printf("Matched %d\n", cli_list(cli, "b*.*", 0, list_fn, NULL));
3701 printf("Matched %d\n", cli_list(cli, "xyzabc", 0, list_fn, NULL));
3704 if (!torture_close_connection(cli)) {
3708 printf("finished dirtest1\n");
3715 simple test harness for playing with deny modes
3717 static BOOL run_deny3test(int dummy)
3719 struct cli_state *cli1, *cli2;
3723 printf("starting deny3 test\n");
3725 printf("Testing simple deny modes\n");
3727 if (!torture_open_connection(&cli1)) {
3730 if (!torture_open_connection(&cli2)) {
3734 fname = "\\deny_dos1.dat";
3736 cli_unlink(cli1, fname);
3737 fnum1 = cli_open(cli1, fname, O_CREAT|O_TRUNC|O_WRONLY, DENY_DOS);
3738 fnum2 = cli_open(cli1, fname, O_CREAT|O_TRUNC|O_WRONLY, DENY_DOS);
3739 if (fnum1 != -1) cli_close(cli1, fnum1);
3740 if (fnum2 != -1) cli_close(cli1, fnum2);
3741 cli_unlink(cli1, fname);
3742 printf("fnum1=%d fnum2=%d\n", fnum1, fnum2);
3745 fname = "\\deny_dos2.dat";
3747 cli_unlink(cli1, fname);
3748 fnum1 = cli_open(cli1, fname, O_CREAT|O_TRUNC|O_WRONLY, DENY_DOS);
3749 fnum2 = cli_open(cli2, fname, O_CREAT|O_TRUNC|O_WRONLY, DENY_DOS);
3750 if (fnum1 != -1) cli_close(cli1, fnum1);
3751 if (fnum2 != -1) cli_close(cli2, fnum2);
3752 cli_unlink(cli1, fname);
3753 printf("fnum1=%d fnum2=%d\n", fnum1, fnum2);
3756 torture_close_connection(cli1);
3757 torture_close_connection(cli2);
3763 static double create_procs(BOOL (*fn)(int), BOOL *result)
3766 volatile pid_t *child_status;
3767 volatile BOOL *child_status_out;
3773 child_status = (volatile pid_t *)shm_setup(sizeof(pid_t)*nprocs);
3774 if (!child_status) {
3775 printf("Failed to setup shared memory\n");
3779 child_status_out = (volatile BOOL *)shm_setup(sizeof(BOOL)*nprocs);
3780 if (!child_status_out) {
3781 printf("Failed to setup result status shared memory\n");
3785 for (i = 0; i < nprocs; i++) {
3786 child_status[i] = 0;
3787 child_status_out[i] = True;
3792 for (i=0;i<nprocs;i++) {
3796 pid_t mypid = getpid();
3797 sys_srandom(((int)mypid) ^ ((int)time(NULL)));
3799 asprintf(&myname, "CLIENT%d", i);
3800 lp_set_cmdline("netbios name", myname);
3804 if (torture_open_connection(¤t_cli)) break;
3806 printf("pid %d failed to start\n", (int)getpid());
3812 child_status[i] = getpid();
3814 while (child_status[i] && end_timer() < 5) msleep(2);
3816 child_status_out[i] = fn(i);
3823 for (i=0;i<nprocs;i++) {
3824 if (child_status[i]) synccount++;
3826 if (synccount == nprocs) break;
3828 } while (end_timer() < 30);
3830 if (synccount != nprocs) {
3831 printf("FAILED TO START %d CLIENTS (started %d)\n", nprocs, synccount);
3836 /* start the client load */
3839 for (i=0;i<nprocs;i++) {
3840 child_status[i] = 0;
3843 printf("%d clients started\n", nprocs);
3845 for (i=0;i<nprocs;i++) {
3846 while (waitpid(0, &status, 0) == -1 && errno == EINTR) /* noop */ ;
3851 for (i=0;i<nprocs;i++) {
3852 if (!child_status_out[i]) {
3859 #define FLAG_MULTIPROC 1
3866 {"FDPASS", run_fdpasstest, 0},
3867 {"LOCK1", run_locktest1, 0},
3868 {"LOCK2", run_locktest2, 0},
3869 {"LOCK3", run_locktest3, 0},
3870 {"LOCK4", run_locktest4, 0},
3871 {"LOCK5", run_locktest5, 0},
3872 {"LOCK6", run_locktest6, 0},
3873 {"LOCK7", run_locktest7, 0},
3874 {"UNLINK", run_unlinktest, 0},
3875 {"ATTR", run_attrtest, 0},
3876 {"TRANS2", run_trans2test, 0},
3877 {"MAXFID", run_maxfidtest, FLAG_MULTIPROC},
3878 {"TORTURE",run_torture, FLAG_MULTIPROC},
3879 {"NEGNOWAIT", run_negprot_nowait, 0},
3880 {"NBENCH", run_nbench, 0},
3881 {"DIR", run_dirtest, 0},
3882 {"DIR1", run_dirtest1, 0},
3883 {"DENY1", torture_denytest1, 0},
3884 {"DENY2", torture_denytest2, 0},
3885 {"TCON", run_tcon_test, 0},
3886 {"TCONDEV", run_tcon_devtype_test, 0},
3888 {"DFSBASIC", torture_dfs_basic, 0},
3889 {"DFSRENAME", torture_dfs_rename, 0},
3890 {"DFSRANDOM", torture_dfs_random, 0},
3892 {"RW1", run_readwritetest, 0},
3893 {"RW2", run_readwritemulti, FLAG_MULTIPROC},
3894 {"OPEN", run_opentest, 0},
3895 {"DENY3", run_deny3test, 0},
3897 {"OPENATTR", run_openattrtest, 0},
3899 {"XCOPY", run_xcopy, 0},
3900 {"RENAME", run_rename, 0},
3901 {"DELETE", run_deletetest, 0},
3902 {"PROPERTIES", run_properties, 0},
3903 {"MANGLE", torture_mangle, 0},
3904 {"UTABLE", torture_utable, 0},
3905 {"CASETABLE", torture_casetable, 0},
3906 {"PIPE_NUMBER", run_pipe_number, 0},
3907 {"IOCTL", torture_ioctl_test, 0},
3908 {"CHKPATH", torture_chkpath_test, 0},
3909 {"RAW-QFSINFO", torture_raw_qfsinfo, 0},
3910 {"RAW-QFILEINFO", torture_raw_qfileinfo, 0},
3911 {"RAW-SFILEINFO", torture_raw_sfileinfo, 0},
3912 {"RAW-SFILEINFO-BUG", torture_raw_sfileinfo_bug, 0},
3913 {"RAW-SEARCH", torture_raw_search, 0},
3914 {"RAW-CLOSE", torture_raw_close, 0},
3915 {"RAW-OPEN", torture_raw_open, 0},
3916 {"RAW-MKDIR", torture_raw_mkdir, 0},
3917 {"RAW-OPLOCK", torture_raw_oplock, 0},
3918 {"RAW-NOTIFY", torture_raw_notify, 0},
3919 {"RAW-MUX", torture_raw_mux, 0},
3920 {"RAW-IOCTL", torture_raw_ioctl, 0},
3921 {"RAW-CHKPATH", torture_raw_chkpath, 0},
3922 {"RAW-UNLINK", torture_raw_unlink, 0},
3923 {"RAW-READ", torture_raw_read, 0},
3924 {"RAW-WRITE", torture_raw_write, 0},
3925 {"RAW-LOCK", torture_raw_lock, 0},
3926 {"RAW-CONTEXT", torture_raw_context, 0},
3927 {"RAW-RENAME", torture_raw_rename, 0},
3928 {"RAW-SEEK", torture_raw_seek, 0},
3929 {"SCAN-TRANS2", torture_trans2_scan, 0},
3930 {"SCAN-NTTRANS", torture_nttrans_scan, 0},
3931 {"SCAN-ALIASES", torture_trans2_aliases, 0},
3932 {"SCAN-SMB", torture_smb_scan, 0},
3937 /****************************************************************************
3938 run a specified test or "ALL"
3939 ****************************************************************************/
3940 static BOOL run_test(const char *name)
3944 BOOL matched = False;
3946 if (strequal(name,"ALL")) {
3947 for (i=0;torture_ops[i].name;i++) {
3948 if (!run_test(torture_ops[i].name)) {
3955 for (i=0;torture_ops[i].name;i++) {
3956 asprintf(&randomfname, "\\XX%x",
3957 (unsigned)random());
3959 if (gen_fnmatch(name, torture_ops[i].name) == 0) {
3962 printf("Running %s\n", torture_ops[i].name);
3963 if (torture_ops[i].flags & FLAG_MULTIPROC) {
3965 t = create_procs(torture_ops[i].fn, &result);
3968 printf("TEST %s FAILED!\n", torture_ops[i].name);
3973 if (!torture_ops[i].fn(0)) {
3975 printf("TEST %s FAILED!\n", torture_ops[i].name);
3979 printf("%s took %g secs\n\n", torture_ops[i].name, t);
3984 printf("Unknown torture operation '%s'\n", name);
3992 parse a username%password
3994 static void parse_user(const char *user)
3996 char *username, *password, *p;
3998 username = strdup(user);
3999 p = strchr_m(username,'%');
4002 password = strdup(p+1);
4005 lp_set_cmdline("torture:username", username);
4006 lp_set_cmdline("torture:password", password);
4010 static void usage(void)
4014 printf("Usage: smbtorture //server/share <options> TEST1 TEST2 ...\n");
4016 printf("\t-d debuglevel\n");
4017 printf("\t-U user%%pass\n");
4018 printf("\t-k use kerberos\n");
4019 printf("\t-N numprocs\n");
4020 printf("\t-n my_netbios_name\n");
4021 printf("\t-W workgroup\n");
4022 printf("\t-o num_operations\n");
4023 printf("\t-e num files(entries)\n");
4024 printf("\t-O socket_options\n");
4025 printf("\t-m maximum protocol\n");
4026 printf("\t-L use oplocks\n");
4027 printf("\t-c CLIENT.TXT specify client load file for NBENCH\n");
4028 printf("\t-A showall\n");
4029 printf("\t-p port\n");
4030 printf("\t-s seed\n");
4031 printf("\t-f max failures\n");
4032 printf("\t-b bypass I/O (NBENCH)\n");
4035 printf("tests are:");
4036 for (i=0;torture_ops[i].name;i++) {
4037 printf(" %s", torture_ops[i].name);
4041 printf("default test is ALL\n");
4046 /****************************************************************************
4048 ****************************************************************************/
4049 int main(int argc,char *argv[])
4054 BOOL correct = True;
4055 char *host, *share, *username;
4057 setup_logging("smbtorture", DEBUG_STDOUT);
4059 #ifdef HAVE_SETBUFFER
4060 setbuffer(stdout, NULL, 0);
4063 lp_load(dyn_CONFIGFILE,True,False,False);
4070 for(p = argv[1]; *p; p++)
4074 if (strncmp(argv[1], "//", 2)) {
4078 host = strdup(&argv[1][2]);
4079 p = strchr_m(&host[2],'/');
4084 share = strdup(p+1);
4086 if (getenv("LOGNAME")) {
4087 username = strdup(getenv("LOGNAME"));
4090 lp_set_cmdline("torture:host", host);
4091 lp_set_cmdline("torture:share", share);
4092 lp_set_cmdline("torture:username", username);
4093 lp_set_cmdline("torture:password", "");
4098 srandom(time(NULL));
4100 while ((opt = getopt(argc, argv, "p:hW:U:n:N:O:o:e:m:Ld:Ac:ks:f:bs:")) != EOF) {
4103 lp_set_cmdline("smb ports", optarg);
4106 lp_set_cmdline("workgroup", optarg);
4109 lp_set_cmdline("protocol", optarg);
4112 lp_set_cmdline("netbios name", optarg);
4115 lp_set_cmdline("debug level", optarg);
4116 setup_logging(NULL,True);
4119 lp_set_cmdline("socket options", optarg);
4122 srandom(atoi(optarg));
4125 nprocs = atoi(optarg);
4128 torture_numops = atoi(optarg);
4131 torture_entries = atoi(optarg);
4137 torture_showall = True;
4140 client_txt = optarg;
4144 use_kerberos = True;
4146 d_printf("No kerberos support compiled in\n");
4155 torture_failures = atoi(optarg);
4162 printf("Unknown option %c (%d)\n", (char)opt, opt);
4167 printf("host=%s share=%s user=%s myname=%s\n",
4168 host, share, lp_parm_string(-1, "torture", "username"),
4171 if (argc == optind) {
4172 printf("You must specify a test to run, or 'ALL'\n");
4174 for (i=optind;i<argc;i++) {
4175 if (!run_test(argv[i])) {