2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 1997-1998
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.
25 static fstring host, workgroup, share, password, username, myname;
26 static int max_protocol = PROTOCOL_NT1;
27 static const char *sockops="TCP_NODELAY";
29 static int port_to_use=0;
30 int torture_numops=100;
31 static int procnum; /* records process count number when forking */
32 static struct cli_state *current_cli;
33 static fstring randomfname;
34 static BOOL use_oplocks;
35 static BOOL use_level_II_oplocks;
36 static const char *client_txt = "client_oplocks.txt";
37 static BOOL use_kerberos;
39 BOOL torture_showall = False;
41 static double create_procs(BOOL (*fn)(int), BOOL *result);
44 static struct timeval tp1,tp2;
46 void start_timer(void)
48 gettimeofday(&tp1,NULL);
51 double end_timer(void)
53 gettimeofday(&tp2,NULL);
54 return((tp2.tv_sec - tp1.tv_sec) +
55 (tp2.tv_usec - tp1.tv_usec)*1.0e-6);
59 /* return a pointer to a anonymous shared memory segment of size "size"
60 which will persist across fork() but will disappear when all processes
63 The memory is not zeroed
65 This function uses system5 shared memory. It takes advantage of a property
66 that the memory is not destroyed if it is attached when the id is removed
68 void *shm_setup(int size)
73 shmid = shmget(IPC_PRIVATE, size, SHM_R | SHM_W);
75 printf("can't get shared memory\n");
78 ret = (void *)shmat(shmid, 0, 0);
79 if (!ret || ret == (void *)-1) {
80 printf("can't attach to shared memory\n");
83 /* the following releases the ipc, but note that this process
84 and all its children will still have access to the memory, its
85 just that the shmid is no longer valid for other shm calls. This
86 means we don't leave behind lots of shm segments after we exit
88 See Stevens "advanced programming in unix env" for details
90 shmctl(shmid, IPC_RMID, 0);
96 static BOOL open_nbt_connection(struct cli_state *c)
98 struct nmb_name called, calling;
103 make_nmb_name(&calling, myname, 0x0);
104 make_nmb_name(&called , host, 0x20);
108 if (!cli_initialise(c)) {
109 printf("Failed initialize cli_struct to connect with %s\n", host);
113 c->port = port_to_use;
115 if (!cli_connect(c, host, &ip)) {
116 printf("Failed to connect with %s\n", host);
120 c->use_kerberos = use_kerberos;
122 c->timeout = 120000; /* set a really long timeout (2 minutes) */
123 if (use_oplocks) c->use_oplocks = True;
124 if (use_level_II_oplocks) c->use_level_II_oplocks = True;
126 if (!cli_session_request(c, &calling, &called)) {
128 * Well, that failed, try *SMBSERVER ...
129 * However, we must reconnect as well ...
131 if (!cli_connect(c, host, &ip)) {
132 printf("Failed to connect with %s\n", host);
136 make_nmb_name(&called, "*SMBSERVER", 0x20);
137 if (!cli_session_request(c, &calling, &called)) {
138 printf("%s rejected the session\n",host);
139 printf("We tried with a called name of %s & %s\n",
149 BOOL torture_open_connection(struct cli_state **c)
156 flags |= CLI_FULL_CONNECTION_USE_KERBEROS;
158 status = cli_full_connection(c, myname,
159 host, NULL, port_to_use,
162 password, flags, &retry);
163 if (!NT_STATUS_IS_OK(status)) {
167 if (use_oplocks) (*c)->use_oplocks = True;
168 if (use_level_II_oplocks) (*c)->use_level_II_oplocks = True;
169 (*c)->timeout = 120000; /* set a really long timeout (2 minutes) */
175 BOOL torture_close_connection(struct cli_state *c)
179 printf("tdis failed (%s)\n", cli_errstr(c));
189 /* check if the server produced the expected error code */
190 static BOOL check_error(int line, struct cli_state *c,
191 uint8 eclass, uint32 ecode, NTSTATUS nterr)
193 if (cli_is_dos_error(c)) {
197 /* Check DOS error */
199 cli_dos_error(c, &class, &num);
201 if (eclass != class || ecode != num) {
202 printf("unexpected error code class=%d code=%d\n",
203 (int)class, (int)num);
204 printf(" expected %d/%d %s (line=%d)\n",
205 (int)eclass, (int)ecode, nt_errstr(nterr), line);
214 status = cli_nt_error(c);
216 if (NT_STATUS_V(nterr) != NT_STATUS_V(status)) {
217 printf("unexpected error code %s\n", nt_errstr(status));
218 printf(" expected %s (line=%d)\n", nt_errstr(nterr), line);
227 static BOOL wait_lock(struct cli_state *c, int fnum, uint32 offset, uint32 len)
229 while (!cli_lock(c, fnum, offset, len, -1, WRITE_LOCK)) {
230 if (!check_error(__LINE__, c, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False;
236 static BOOL rw_torture(struct cli_state *c)
238 const char *lockfname = "\\torture.lck";
242 pid_t pid2, pid = getpid();
247 fnum2 = cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
250 fnum2 = cli_open(c, lockfname, O_RDWR, DENY_NONE);
252 printf("open of %s failed (%s)\n", lockfname, cli_errstr(c));
257 for (i=0;i<torture_numops;i++) {
258 unsigned n = (unsigned)sys_random()%10;
260 printf("%d\r", i); fflush(stdout);
262 slprintf(fname, sizeof(fstring) - 1, "\\torture.%u", n);
264 if (!wait_lock(c, fnum2, n*sizeof(int), sizeof(int))) {
268 fnum = cli_open(c, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_ALL);
270 printf("open failed (%s)\n", cli_errstr(c));
275 if (cli_write(c, fnum, 0, (char *)&pid, 0, sizeof(pid)) != sizeof(pid)) {
276 printf("write failed (%s)\n", cli_errstr(c));
281 if (cli_write(c, fnum, 0, (char *)buf,
282 sizeof(pid)+(j*sizeof(buf)),
283 sizeof(buf)) != sizeof(buf)) {
284 printf("write failed (%s)\n", cli_errstr(c));
291 if (cli_read(c, fnum, (char *)&pid2, 0, sizeof(pid)) != sizeof(pid)) {
292 printf("read failed (%s)\n", cli_errstr(c));
297 printf("data corruption!\n");
301 if (!cli_close(c, fnum)) {
302 printf("close failed (%s)\n", cli_errstr(c));
306 if (!cli_unlink(c, fname)) {
307 printf("unlink failed (%s)\n", cli_errstr(c));
311 if (!cli_unlock(c, fnum2, n*sizeof(int), sizeof(int))) {
312 printf("unlock failed (%s)\n", cli_errstr(c));
318 cli_unlink(c, lockfname);
325 static BOOL run_torture(int dummy)
327 struct cli_state *cli;
332 cli_sockopt(cli, sockops);
334 ret = rw_torture(cli);
336 if (!torture_close_connection(cli)) {
343 static BOOL rw_torture3(struct cli_state *c, char *lockfname)
350 unsigned countprev = 0;
355 for (i = 0; i < sizeof(buf); i += sizeof(uint32))
357 SIVAL(buf, i, sys_random());
362 fnum = cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
365 printf("first open read/write of %s failed (%s)\n",
366 lockfname, cli_errstr(c));
372 for (i = 0; i < 500 && fnum == -1; i++)
374 fnum = cli_open(c, lockfname, O_RDONLY,
379 printf("second open read-only of %s failed (%s)\n",
380 lockfname, cli_errstr(c));
386 for (count = 0; count < sizeof(buf); count += sent)
388 if (count >= countprev) {
389 printf("%d %8d\r", i, count);
392 countprev += (sizeof(buf) / 20);
397 sent = ((unsigned)sys_random()%(20))+ 1;
398 if (sent > sizeof(buf) - count)
400 sent = sizeof(buf) - count;
403 if (cli_write(c, fnum, 0, buf+count, count, (size_t)sent) != sent) {
404 printf("write failed (%s)\n", cli_errstr(c));
410 sent = cli_read(c, fnum, buf_rd+count, count,
414 printf("read failed offset:%d size:%d (%s)\n",
415 count, sizeof(buf)-count,
422 if (memcmp(buf_rd+count, buf+count, sent) != 0)
424 printf("read/write compare failed\n");
425 printf("offset: %d req %d recvd %d\n",
426 count, sizeof(buf)-count, sent);
435 if (!cli_close(c, fnum)) {
436 printf("close failed (%s)\n", cli_errstr(c));
443 static BOOL rw_torture2(struct cli_state *c1, struct cli_state *c2)
445 const char *lockfname = "\\torture2.lck";
450 uchar buf_rd[131072];
454 if (!cli_unlink(c1, lockfname)) {
455 printf("unlink failed (%s) (normal, this file should not exist)\n", cli_errstr(c1));
458 fnum1 = cli_open(c1, lockfname, O_RDWR | O_CREAT | O_EXCL,
461 printf("first open read/write of %s failed (%s)\n",
462 lockfname, cli_errstr(c1));
465 fnum2 = cli_open(c2, lockfname, O_RDONLY,
468 printf("second open read-only of %s failed (%s)\n",
469 lockfname, cli_errstr(c2));
470 cli_close(c1, fnum1);
474 for (i=0;i<torture_numops;i++)
476 size_t buf_size = ((unsigned)sys_random()%(sizeof(buf)-1))+ 1;
478 printf("%d\r", i); fflush(stdout);
481 generate_random_buffer(buf, buf_size, False);
483 if (cli_write(c1, fnum1, 0, buf, 0, buf_size) != buf_size) {
484 printf("write failed (%s)\n", cli_errstr(c1));
488 if ((bytes_read = cli_read(c2, fnum2, buf_rd, 0, buf_size)) != buf_size) {
489 printf("read failed (%s)\n", cli_errstr(c2));
490 printf("read %d, expected %d\n", bytes_read, buf_size);
494 if (memcmp(buf_rd, buf, buf_size) != 0)
496 printf("read/write compare failed\n");
501 if (!cli_close(c2, fnum2)) {
502 printf("close failed (%s)\n", cli_errstr(c2));
505 if (!cli_close(c1, fnum1)) {
506 printf("close failed (%s)\n", cli_errstr(c1));
510 if (!cli_unlink(c1, lockfname)) {
511 printf("unlink failed (%s)\n", cli_errstr(c1));
518 static BOOL run_readwritetest(int dummy)
520 static struct cli_state *cli1, *cli2;
523 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
526 cli_sockopt(cli1, sockops);
527 cli_sockopt(cli2, sockops);
529 printf("starting readwritetest\n");
531 test1 = rw_torture2(cli1, cli2);
532 printf("Passed readwritetest v1: %s\n", BOOLSTR(test1));
534 test2 = rw_torture2(cli1, cli1);
535 printf("Passed readwritetest v2: %s\n", BOOLSTR(test2));
537 if (!torture_close_connection(cli1)) {
541 if (!torture_close_connection(cli2)) {
545 return (test1 && test2);
548 static BOOL run_readwritemulti(int dummy)
550 struct cli_state *cli;
555 cli_sockopt(&cli, sockops);
557 printf("run_readwritemulti: fname %s\n", randomfname);
558 test = rw_torture3(&cli, randomfname);
560 if (!torture_close_connection(&cli)) {
567 static BOOL run_readwritelarge(int dummy)
569 static struct cli_state *cli1;
571 const char *lockfname = "\\large.dat";
576 if (!torture_open_connection(&cli1)) {
579 cli_sockopt(cli1, sockops);
580 memset(buf,'\0',sizeof(buf));
582 cli1->max_xmit = 128*1024;
584 printf("starting readwritelarge\n");
586 cli_unlink(cli1, lockfname);
588 fnum1 = cli_open(cli1, lockfname, O_RDWR | O_CREAT | O_EXCL, DENY_NONE);
590 printf("open read/write of %s failed (%s)\n", lockfname, cli_errstr(cli1));
594 cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf));
596 if (!cli_qfileinfo(cli1, fnum1, NULL, &fsize, NULL, NULL, NULL, NULL, NULL)) {
597 printf("qfileinfo failed (%s)\n", cli_errstr(cli1));
601 if (fsize == sizeof(buf))
602 printf("readwritelarge test 1 succeeded (size = %x)\n", fsize);
604 printf("readwritelarge test 1 failed (size = %x)\n", fsize);
608 if (!cli_close(cli1, fnum1)) {
609 printf("close failed (%s)\n", cli_errstr(cli1));
613 if (!cli_unlink(cli1, lockfname)) {
614 printf("unlink failed (%s)\n", cli_errstr(cli1));
618 fnum1 = cli_open(cli1, lockfname, O_RDWR | O_CREAT | O_EXCL, DENY_NONE);
620 printf("open read/write of %s failed (%s)\n", lockfname, cli_errstr(cli1));
624 cli1->max_xmit = 4*1024;
626 cli_smbwrite(cli1, fnum1, buf, 0, sizeof(buf));
628 if (!cli_qfileinfo(cli1, fnum1, NULL, &fsize, NULL, NULL, NULL, NULL, NULL)) {
629 printf("qfileinfo failed (%s)\n", cli_errstr(cli1));
633 if (fsize == sizeof(buf))
634 printf("readwritelarge test 2 succeeded (size = %x)\n", fsize);
636 printf("readwritelarge test 2 failed (size = %x)\n", fsize);
641 /* ToDo - set allocation. JRA */
642 if(!cli_set_allocation_size(cli1, fnum1, 0)) {
643 printf("set allocation size to zero failed (%s)\n", cli_errstr(&cli1));
646 if (!cli_qfileinfo(cli1, fnum1, NULL, &fsize, NULL, NULL, NULL, NULL, NULL)) {
647 printf("qfileinfo failed (%s)\n", cli_errstr(cli1));
651 printf("readwritelarge test 3 (truncate test) succeeded (size = %x)\n", fsize);
654 if (!cli_close(cli1, fnum1)) {
655 printf("close failed (%s)\n", cli_errstr(cli1));
659 if (!torture_close_connection(cli1)) {
668 #define ival(s) strtol(s, NULL, 0)
670 /* run a test that simulates an approximate netbench client load */
671 static BOOL run_netbench(int client)
673 struct cli_state *cli;
686 cli_sockopt(cli, sockops);
690 slprintf(cname,sizeof(fname), "client%d", client);
692 f = fopen(client_txt, "r");
699 while (fgets(line, sizeof(line)-1, f)) {
702 line[strlen(line)-1] = 0;
704 /* printf("[%d] %s\n", line_count, line); */
706 all_string_sub(line,"client1", cname, sizeof(line));
708 /* parse the command parameters */
709 params[0] = strtok(line," ");
711 while (params[i]) params[++i] = strtok(NULL," ");
717 if (!strncmp(params[0],"SMB", 3)) {
718 printf("ERROR: You are using a dbench 1 load file\n");
722 if (!strcmp(params[0],"NTCreateX")) {
723 nb_createx(params[1], ival(params[2]), ival(params[3]),
725 } else if (!strcmp(params[0],"Close")) {
726 nb_close(ival(params[1]));
727 } else if (!strcmp(params[0],"Rename")) {
728 nb_rename(params[1], params[2]);
729 } else if (!strcmp(params[0],"Unlink")) {
730 nb_unlink(params[1]);
731 } else if (!strcmp(params[0],"Deltree")) {
732 nb_deltree(params[1]);
733 } else if (!strcmp(params[0],"Rmdir")) {
735 } else if (!strcmp(params[0],"QUERY_PATH_INFORMATION")) {
736 nb_qpathinfo(params[1]);
737 } else if (!strcmp(params[0],"QUERY_FILE_INFORMATION")) {
738 nb_qfileinfo(ival(params[1]));
739 } else if (!strcmp(params[0],"QUERY_FS_INFORMATION")) {
740 nb_qfsinfo(ival(params[1]));
741 } else if (!strcmp(params[0],"FIND_FIRST")) {
742 nb_findfirst(params[1]);
743 } else if (!strcmp(params[0],"WriteX")) {
744 nb_writex(ival(params[1]),
745 ival(params[2]), ival(params[3]), ival(params[4]));
746 } else if (!strcmp(params[0],"ReadX")) {
747 nb_readx(ival(params[1]),
748 ival(params[2]), ival(params[3]), ival(params[4]));
749 } else if (!strcmp(params[0],"Flush")) {
750 nb_flush(ival(params[1]));
752 printf("Unknown operation %s\n", params[0]);
760 if (!torture_close_connection(cli)) {
768 /* run a test that simulates an approximate netbench client load */
769 static BOOL run_nbench(int dummy)
778 signal(SIGALRM, nb_alarm);
780 t = create_procs(run_netbench, &correct);
783 printf("\nThroughput %g MB/sec\n",
784 1.0e-6 * nbio_total() / t);
790 This test checks for two things:
792 1) correct support for retaining locks over a close (ie. the server
793 must not use posix semantics)
794 2) support for lock timeouts
796 static BOOL run_locktest1(int dummy)
798 struct cli_state *cli1, *cli2;
799 const char *fname = "\\lockt1.lck";
800 int fnum1, fnum2, fnum3;
802 unsigned lock_timeout;
804 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
807 cli_sockopt(cli1, sockops);
808 cli_sockopt(cli2, sockops);
810 printf("starting locktest1\n");
812 cli_unlink(cli1, fname);
814 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
816 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
819 fnum2 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
821 printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli1));
824 fnum3 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
826 printf("open3 of %s failed (%s)\n", fname, cli_errstr(cli2));
830 if (!cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK)) {
831 printf("lock1 failed (%s)\n", cli_errstr(cli1));
836 if (cli_lock(cli2, fnum3, 0, 4, 0, WRITE_LOCK)) {
837 printf("lock2 succeeded! This is a locking bug\n");
840 if (!check_error(__LINE__, cli2, ERRDOS, ERRlock,
841 NT_STATUS_LOCK_NOT_GRANTED)) return False;
845 lock_timeout = (1 + (random() % 20));
846 printf("Testing lock timeout with timeout=%u\n", lock_timeout);
848 if (cli_lock(cli2, fnum3, 0, 4, lock_timeout * 1000, WRITE_LOCK)) {
849 printf("lock3 succeeded! This is a locking bug\n");
852 if (!check_error(__LINE__, cli2, ERRDOS, ERRlock,
853 NT_STATUS_FILE_LOCK_CONFLICT)) return False;
858 printf("error: This server appears not to support timed lock requests\n");
860 printf("server slept for %u seconds for a %u second timeout\n",
861 (unsigned int)(t2-t1), lock_timeout);
863 if (!cli_close(cli1, fnum2)) {
864 printf("close1 failed (%s)\n", cli_errstr(cli1));
868 if (cli_lock(cli2, fnum3, 0, 4, 0, WRITE_LOCK)) {
869 printf("lock4 succeeded! This is a locking bug\n");
872 if (!check_error(__LINE__, cli2, ERRDOS, ERRlock,
873 NT_STATUS_FILE_LOCK_CONFLICT)) return False;
876 if (!cli_close(cli1, fnum1)) {
877 printf("close2 failed (%s)\n", cli_errstr(cli1));
881 if (!cli_close(cli2, fnum3)) {
882 printf("close3 failed (%s)\n", cli_errstr(cli2));
886 if (!cli_unlink(cli1, fname)) {
887 printf("unlink failed (%s)\n", cli_errstr(cli1));
892 if (!torture_close_connection(cli1)) {
896 if (!torture_close_connection(cli2)) {
900 printf("Passed locktest1\n");
905 checks for correct tconX support
907 static BOOL run_tcon_test(int dummy)
909 static struct cli_state *cli1;
910 const char *fname = "\\tcontest.tmp";
915 if (!torture_open_connection(&cli1)) {
918 cli_sockopt(cli1, sockops);
920 printf("starting tcontest\n");
922 cli_unlink(cli1, fname);
924 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
927 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
933 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4)
935 printf("write failed (%s)", cli_errstr(cli1));
939 if (!cli_send_tconX(cli1, share, "?????",
940 password, strlen(password)+1)) {
941 printf("%s refused 2nd tree connect (%s)\n", host,
947 if (cli_write(cli1, fnum1, 0, buf, 130, 4) == 4)
949 printf("write succeeded (%s)", cli_errstr(cli1));
953 if (cli_close(cli1, fnum1)) {
954 printf("close2 succeeded (%s)\n", cli_errstr(cli1));
958 if (!cli_tdis(cli1)) {
959 printf("tdis failed (%s)\n", cli_errstr(cli1));
965 if (!cli_close(cli1, fnum1)) {
966 printf("close2 failed (%s)\n", cli_errstr(cli1));
970 if (!torture_close_connection(cli1)) {
974 printf("Passed tcontest\n");
980 This test checks that
982 1) the server supports multiple locking contexts on the one SMB
983 connection, distinguished by PID.
985 2) the server correctly fails overlapping locks made by the same PID (this
986 goes against POSIX behaviour, which is why it is tricky to implement)
988 3) the server denies unlock requests by an incorrect client PID
990 static BOOL run_locktest2(int dummy)
992 static struct cli_state *cli;
993 const char *fname = "\\lockt2.lck";
994 int fnum1, fnum2, fnum3;
997 if (!torture_open_connection(&cli)) {
1001 cli_sockopt(cli, sockops);
1003 printf("starting locktest2\n");
1005 cli_unlink(cli, fname);
1009 fnum1 = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1011 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
1015 fnum2 = cli_open(cli, fname, O_RDWR, DENY_NONE);
1017 printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli));
1023 fnum3 = cli_open(cli, fname, O_RDWR, DENY_NONE);
1025 printf("open3 of %s failed (%s)\n", fname, cli_errstr(cli));
1031 if (!cli_lock(cli, fnum1, 0, 4, 0, WRITE_LOCK)) {
1032 printf("lock1 failed (%s)\n", cli_errstr(cli));
1036 if (cli_lock(cli, fnum1, 0, 4, 0, WRITE_LOCK)) {
1037 printf("WRITE lock1 succeeded! This is a locking bug\n");
1040 if (!check_error(__LINE__, cli, ERRDOS, ERRlock,
1041 NT_STATUS_LOCK_NOT_GRANTED)) return False;
1044 if (cli_lock(cli, fnum2, 0, 4, 0, WRITE_LOCK)) {
1045 printf("WRITE lock2 succeeded! This is a locking bug\n");
1048 if (!check_error(__LINE__, cli, ERRDOS, ERRlock,
1049 NT_STATUS_LOCK_NOT_GRANTED)) return False;
1052 if (cli_lock(cli, fnum2, 0, 4, 0, READ_LOCK)) {
1053 printf("READ lock2 succeeded! This is a locking bug\n");
1056 if (!check_error(__LINE__, cli, ERRDOS, ERRlock,
1057 NT_STATUS_FILE_LOCK_CONFLICT)) return False;
1060 if (!cli_lock(cli, fnum1, 100, 4, 0, WRITE_LOCK)) {
1061 printf("lock at 100 failed (%s)\n", cli_errstr(cli));
1064 if (cli_unlock(cli, fnum1, 100, 4)) {
1065 printf("unlock at 100 succeeded! This is a locking bug\n");
1069 if (cli_unlock(cli, fnum1, 0, 4)) {
1070 printf("unlock1 succeeded! This is a locking bug\n");
1073 if (!check_error(__LINE__, cli,
1075 NT_STATUS_RANGE_NOT_LOCKED)) return False;
1078 if (cli_unlock(cli, fnum1, 0, 8)) {
1079 printf("unlock2 succeeded! This is a locking bug\n");
1082 if (!check_error(__LINE__, cli,
1084 NT_STATUS_RANGE_NOT_LOCKED)) return False;
1087 if (cli_lock(cli, fnum3, 0, 4, 0, WRITE_LOCK)) {
1088 printf("lock3 succeeded! This is a locking bug\n");
1091 if (!check_error(__LINE__, cli, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False;
1096 if (!cli_close(cli, fnum1)) {
1097 printf("close1 failed (%s)\n", cli_errstr(cli));
1101 if (!cli_close(cli, fnum2)) {
1102 printf("close2 failed (%s)\n", cli_errstr(cli));
1106 if (!cli_close(cli, fnum3)) {
1107 printf("close3 failed (%s)\n", cli_errstr(cli));
1111 if (!torture_close_connection(cli)) {
1115 printf("locktest2 finished\n");
1122 This test checks that
1124 1) the server supports the full offset range in lock requests
1126 static BOOL run_locktest3(int dummy)
1128 static struct cli_state *cli1, *cli2;
1129 const char *fname = "\\lockt3.lck";
1130 int fnum1, fnum2, i;
1132 BOOL correct = True;
1134 #define NEXT_OFFSET offset += (~(uint32)0) / torture_numops
1136 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
1139 cli_sockopt(cli1, sockops);
1140 cli_sockopt(cli2, sockops);
1142 printf("starting locktest3\n");
1144 cli_unlink(cli1, fname);
1146 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1148 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
1151 fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
1153 printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli2));
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 for (offset=i=0;i<torture_numops;i++) {
1177 if (cli_lock(cli1, fnum1, offset-2, 1, 0, WRITE_LOCK)) {
1178 printf("error: lock1 %d succeeded!\n", i);
1182 if (cli_lock(cli2, fnum2, offset-1, 1, 0, WRITE_LOCK)) {
1183 printf("error: lock2 %d succeeded!\n", i);
1187 if (cli_lock(cli1, fnum1, offset-1, 1, 0, WRITE_LOCK)) {
1188 printf("error: lock3 %d succeeded!\n", i);
1192 if (cli_lock(cli2, fnum2, offset-2, 1, 0, WRITE_LOCK)) {
1193 printf("error: lock4 %d succeeded!\n", i);
1198 for (offset=i=0;i<torture_numops;i++) {
1201 if (!cli_unlock(cli1, fnum1, offset-1, 1)) {
1202 printf("unlock1 %d failed (%s)\n",
1208 if (!cli_unlock(cli2, fnum2, offset-2, 1)) {
1209 printf("unlock2 %d failed (%s)\n",
1216 if (!cli_close(cli1, fnum1)) {
1217 printf("close1 failed (%s)\n", cli_errstr(cli1));
1221 if (!cli_close(cli2, fnum2)) {
1222 printf("close2 failed (%s)\n", cli_errstr(cli2));
1226 if (!cli_unlink(cli1, fname)) {
1227 printf("unlink failed (%s)\n", cli_errstr(cli1));
1231 if (!torture_close_connection(cli1)) {
1235 if (!torture_close_connection(cli2)) {
1239 printf("finished locktest3\n");
1244 #define EXPECTED(ret, v) if ((ret) != (v)) { \
1245 printf("** "); correct = False; \
1249 looks at overlapping locks
1251 static BOOL run_locktest4(int dummy)
1253 static struct cli_state *cli1, *cli2;
1254 const char *fname = "\\lockt4.lck";
1255 int fnum1, fnum2, f;
1258 BOOL correct = True;
1260 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
1264 cli_sockopt(cli1, sockops);
1265 cli_sockopt(cli2, sockops);
1267 printf("starting locktest4\n");
1269 cli_unlink(cli1, fname);
1271 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1272 fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
1274 memset(buf, 0, sizeof(buf));
1276 if (cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
1277 printf("Failed to create file\n");
1282 ret = cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK) &&
1283 cli_lock(cli1, fnum1, 2, 4, 0, WRITE_LOCK);
1284 EXPECTED(ret, False);
1285 printf("the same process %s set overlapping write locks\n", ret?"can":"cannot");
1287 ret = cli_lock(cli1, fnum1, 10, 4, 0, READ_LOCK) &&
1288 cli_lock(cli1, fnum1, 12, 4, 0, READ_LOCK);
1289 EXPECTED(ret, True);
1290 printf("the same process %s set overlapping read locks\n", ret?"can":"cannot");
1292 ret = cli_lock(cli1, fnum1, 20, 4, 0, WRITE_LOCK) &&
1293 cli_lock(cli2, fnum2, 22, 4, 0, WRITE_LOCK);
1294 EXPECTED(ret, False);
1295 printf("a different connection %s set overlapping write locks\n", ret?"can":"cannot");
1297 ret = cli_lock(cli1, fnum1, 30, 4, 0, READ_LOCK) &&
1298 cli_lock(cli2, fnum2, 32, 4, 0, READ_LOCK);
1299 EXPECTED(ret, True);
1300 printf("a different connection %s set overlapping read locks\n", ret?"can":"cannot");
1302 ret = (cli_setpid(cli1, 1), cli_lock(cli1, fnum1, 40, 4, 0, WRITE_LOCK)) &&
1303 (cli_setpid(cli1, 2), cli_lock(cli1, fnum1, 42, 4, 0, WRITE_LOCK));
1304 EXPECTED(ret, False);
1305 printf("a different pid %s set overlapping write locks\n", ret?"can":"cannot");
1307 ret = (cli_setpid(cli1, 1), cli_lock(cli1, fnum1, 50, 4, 0, READ_LOCK)) &&
1308 (cli_setpid(cli1, 2), cli_lock(cli1, fnum1, 52, 4, 0, READ_LOCK));
1309 EXPECTED(ret, True);
1310 printf("a different pid %s set overlapping read locks\n", ret?"can":"cannot");
1312 ret = cli_lock(cli1, fnum1, 60, 4, 0, READ_LOCK) &&
1313 cli_lock(cli1, fnum1, 60, 4, 0, READ_LOCK);
1314 EXPECTED(ret, True);
1315 printf("the same process %s set the same read lock twice\n", ret?"can":"cannot");
1317 ret = cli_lock(cli1, fnum1, 70, 4, 0, WRITE_LOCK) &&
1318 cli_lock(cli1, fnum1, 70, 4, 0, WRITE_LOCK);
1319 EXPECTED(ret, False);
1320 printf("the same process %s set the same write lock twice\n", ret?"can":"cannot");
1322 ret = cli_lock(cli1, fnum1, 80, 4, 0, READ_LOCK) &&
1323 cli_lock(cli1, fnum1, 80, 4, 0, WRITE_LOCK);
1324 EXPECTED(ret, False);
1325 printf("the same process %s overlay a read lock with a write lock\n", ret?"can":"cannot");
1327 ret = cli_lock(cli1, fnum1, 90, 4, 0, WRITE_LOCK) &&
1328 cli_lock(cli1, fnum1, 90, 4, 0, READ_LOCK);
1329 EXPECTED(ret, True);
1330 printf("the same process %s overlay a write lock with a read lock\n", ret?"can":"cannot");
1332 ret = (cli_setpid(cli1, 1), cli_lock(cli1, fnum1, 100, 4, 0, WRITE_LOCK)) &&
1333 (cli_setpid(cli1, 2), cli_lock(cli1, fnum1, 100, 4, 0, READ_LOCK));
1334 EXPECTED(ret, False);
1335 printf("a different pid %s overlay a write lock with a read lock\n", ret?"can":"cannot");
1337 ret = cli_lock(cli1, fnum1, 110, 4, 0, READ_LOCK) &&
1338 cli_lock(cli1, fnum1, 112, 4, 0, READ_LOCK) &&
1339 cli_unlock(cli1, fnum1, 110, 6);
1340 EXPECTED(ret, False);
1341 printf("the same process %s coalesce read locks\n", ret?"can":"cannot");
1344 ret = cli_lock(cli1, fnum1, 120, 4, 0, WRITE_LOCK) &&
1345 (cli_read(cli2, fnum2, buf, 120, 4) == 4);
1346 EXPECTED(ret, False);
1347 printf("this server %s strict write locking\n", ret?"doesn't do":"does");
1349 ret = cli_lock(cli1, fnum1, 130, 4, 0, READ_LOCK) &&
1350 (cli_write(cli2, fnum2, 0, buf, 130, 4) == 4);
1351 EXPECTED(ret, False);
1352 printf("this server %s strict read locking\n", ret?"doesn't do":"does");
1355 ret = cli_lock(cli1, fnum1, 140, 4, 0, READ_LOCK) &&
1356 cli_lock(cli1, fnum1, 140, 4, 0, READ_LOCK) &&
1357 cli_unlock(cli1, fnum1, 140, 4) &&
1358 cli_unlock(cli1, fnum1, 140, 4);
1359 EXPECTED(ret, True);
1360 printf("this server %s do recursive read locking\n", ret?"does":"doesn't");
1363 ret = cli_lock(cli1, fnum1, 150, 4, 0, WRITE_LOCK) &&
1364 cli_lock(cli1, fnum1, 150, 4, 0, READ_LOCK) &&
1365 cli_unlock(cli1, fnum1, 150, 4) &&
1366 (cli_read(cli2, fnum2, buf, 150, 4) == 4) &&
1367 !(cli_write(cli2, fnum2, 0, buf, 150, 4) == 4) &&
1368 cli_unlock(cli1, fnum1, 150, 4);
1369 EXPECTED(ret, True);
1370 printf("this server %s do recursive lock overlays\n", ret?"does":"doesn't");
1372 ret = cli_lock(cli1, fnum1, 160, 4, 0, READ_LOCK) &&
1373 cli_unlock(cli1, fnum1, 160, 4) &&
1374 (cli_write(cli2, fnum2, 0, buf, 160, 4) == 4) &&
1375 (cli_read(cli2, fnum2, buf, 160, 4) == 4);
1376 EXPECTED(ret, True);
1377 printf("the same process %s remove a read lock using write locking\n", ret?"can":"cannot");
1379 ret = cli_lock(cli1, fnum1, 170, 4, 0, WRITE_LOCK) &&
1380 cli_unlock(cli1, fnum1, 170, 4) &&
1381 (cli_write(cli2, fnum2, 0, buf, 170, 4) == 4) &&
1382 (cli_read(cli2, fnum2, buf, 170, 4) == 4);
1383 EXPECTED(ret, True);
1384 printf("the same process %s remove a write lock using read locking\n", ret?"can":"cannot");
1386 ret = cli_lock(cli1, fnum1, 190, 4, 0, WRITE_LOCK) &&
1387 cli_lock(cli1, fnum1, 190, 4, 0, READ_LOCK) &&
1388 cli_unlock(cli1, fnum1, 190, 4) &&
1389 !(cli_write(cli2, fnum2, 0, buf, 190, 4) == 4) &&
1390 (cli_read(cli2, fnum2, buf, 190, 4) == 4);
1391 EXPECTED(ret, True);
1392 printf("the same process %s remove the first lock first\n", ret?"does":"doesn't");
1394 cli_close(cli1, fnum1);
1395 cli_close(cli2, fnum2);
1396 fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1397 f = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1398 ret = cli_lock(cli1, fnum1, 0, 8, 0, READ_LOCK) &&
1399 cli_lock(cli1, f, 0, 1, 0, READ_LOCK) &&
1400 cli_close(cli1, fnum1) &&
1401 ((fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE)) != -1) &&
1402 cli_lock(cli1, fnum1, 7, 1, 0, WRITE_LOCK);
1404 cli_close(cli1, fnum1);
1405 EXPECTED(ret, True);
1406 printf("the server %s have the NT byte range lock bug\n", !ret?"does":"doesn't");
1409 cli_close(cli1, fnum1);
1410 cli_close(cli2, fnum2);
1411 cli_unlink(cli1, fname);
1412 torture_close_connection(cli1);
1413 torture_close_connection(cli2);
1415 printf("finished locktest4\n");
1420 looks at lock upgrade/downgrade.
1422 static BOOL run_locktest5(int dummy)
1424 static struct cli_state *cli1, *cli2;
1425 const char *fname = "\\lockt5.lck";
1426 int fnum1, fnum2, fnum3;
1429 BOOL correct = True;
1431 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
1435 cli_sockopt(cli1, sockops);
1436 cli_sockopt(cli2, sockops);
1438 printf("starting locktest5\n");
1440 cli_unlink(cli1, fname);
1442 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1443 fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
1444 fnum3 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1446 memset(buf, 0, sizeof(buf));
1448 if (cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
1449 printf("Failed to create file\n");
1454 /* Check for NT bug... */
1455 ret = cli_lock(cli1, fnum1, 0, 8, 0, READ_LOCK) &&
1456 cli_lock(cli1, fnum3, 0, 1, 0, READ_LOCK);
1457 cli_close(cli1, fnum1);
1458 fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1459 ret = cli_lock(cli1, fnum1, 7, 1, 0, WRITE_LOCK);
1460 EXPECTED(ret, True);
1461 printf("this server %s the NT locking bug\n", ret ? "doesn't have" : "has");
1462 cli_close(cli1, fnum1);
1463 fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1464 cli_unlock(cli1, fnum3, 0, 1);
1466 ret = cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK) &&
1467 cli_lock(cli1, fnum1, 1, 1, 0, READ_LOCK);
1468 EXPECTED(ret, True);
1469 printf("the same process %s overlay a write with a read lock\n", ret?"can":"cannot");
1471 ret = cli_lock(cli2, fnum2, 0, 4, 0, READ_LOCK);
1472 EXPECTED(ret, False);
1474 printf("a different processs %s get a read lock on the first process lock stack\n", ret?"can":"cannot");
1476 /* Unlock the process 2 lock. */
1477 cli_unlock(cli2, fnum2, 0, 4);
1479 ret = cli_lock(cli1, fnum3, 0, 4, 0, READ_LOCK);
1480 EXPECTED(ret, False);
1482 printf("the same processs on a different fnum %s get a read lock\n", ret?"can":"cannot");
1484 /* Unlock the process 1 fnum3 lock. */
1485 cli_unlock(cli1, fnum3, 0, 4);
1487 /* Stack 2 more locks here. */
1488 ret = cli_lock(cli1, fnum1, 0, 4, 0, READ_LOCK) &&
1489 cli_lock(cli1, fnum1, 0, 4, 0, READ_LOCK);
1491 EXPECTED(ret, True);
1492 printf("the same process %s stack read locks\n", ret?"can":"cannot");
1494 /* Unlock the first process lock, then check this was the WRITE lock that was
1497 ret = cli_unlock(cli1, fnum1, 0, 4) &&
1498 cli_lock(cli2, fnum2, 0, 4, 0, READ_LOCK);
1500 EXPECTED(ret, True);
1501 printf("the first unlock removes the %s lock\n", ret?"WRITE":"READ");
1503 /* Unlock the process 2 lock. */
1504 cli_unlock(cli2, fnum2, 0, 4);
1506 /* We should have 3 stacked locks here. Ensure we need to do 3 unlocks. */
1508 ret = cli_unlock(cli1, fnum1, 1, 1) &&
1509 cli_unlock(cli1, fnum1, 0, 4) &&
1510 cli_unlock(cli1, fnum1, 0, 4);
1512 EXPECTED(ret, True);
1513 printf("the same process %s unlock the stack of 4 locks\n", ret?"can":"cannot");
1515 /* Ensure the next unlock fails. */
1516 ret = cli_unlock(cli1, fnum1, 0, 4);
1517 EXPECTED(ret, False);
1518 printf("the same process %s count the lock stack\n", !ret?"can":"cannot");
1520 /* Ensure connection 2 can get a write lock. */
1521 ret = cli_lock(cli2, fnum2, 0, 4, 0, WRITE_LOCK);
1522 EXPECTED(ret, True);
1524 printf("a different processs %s get a write lock on the unlocked stack\n", ret?"can":"cannot");
1528 cli_close(cli1, fnum1);
1529 cli_close(cli2, fnum2);
1530 cli_unlink(cli1, fname);
1531 if (!torture_close_connection(cli1)) {
1534 if (!torture_close_connection(cli2)) {
1538 printf("finished locktest5\n");
1544 tries the unusual lockingX locktype bits
1546 static BOOL run_locktest6(int dummy)
1548 static struct cli_state *cli;
1549 const char *fname[1] = { "\\lock6.txt" };
1554 if (!torture_open_connection(&cli)) {
1558 cli_sockopt(cli, sockops);
1560 printf("starting locktest6\n");
1563 printf("Testing %s\n", fname[i]);
1565 cli_unlink(cli, fname[i]);
1567 fnum = cli_open(cli, fname[i], O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1568 status = cli_locktype(cli, fnum, 0, 8, 0, LOCKING_ANDX_CHANGE_LOCKTYPE);
1569 cli_close(cli, fnum);
1570 printf("CHANGE_LOCKTYPE gave %s\n", nt_errstr(status));
1572 fnum = cli_open(cli, fname[i], O_RDWR, DENY_NONE);
1573 status = cli_locktype(cli, fnum, 0, 8, 0, LOCKING_ANDX_CANCEL_LOCK);
1574 cli_close(cli, fnum);
1575 printf("CANCEL_LOCK gave %s\n", nt_errstr(status));
1577 cli_unlink(cli, fname[i]);
1580 torture_close_connection(cli);
1582 printf("finished locktest6\n");
1586 static BOOL run_locktest7(int dummy)
1588 struct cli_state *cli1;
1589 const char *fname = "\\lockt7.lck";
1592 BOOL correct = False;
1594 if (!torture_open_connection(&cli1)) {
1598 cli_sockopt(cli1, sockops);
1600 printf("starting locktest7\n");
1602 cli_unlink(cli1, fname);
1604 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1606 memset(buf, 0, sizeof(buf));
1608 if (cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
1609 printf("Failed to create file\n");
1613 cli_setpid(cli1, 1);
1615 if (!cli_lock(cli1, fnum1, 130, 4, 0, READ_LOCK)) {
1616 printf("Unable to apply read lock on range 130:4, error was %s\n", cli_errstr(cli1));
1619 printf("pid1 successfully locked range 130:4 for READ\n");
1622 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
1623 printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
1626 printf("pid1 successfully read the range 130:4\n");
1629 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
1630 printf("pid1 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
1631 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
1632 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
1636 printf("pid1 successfully wrote to the range 130:4 (should be denied)\n");
1640 cli_setpid(cli1, 2);
1642 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
1643 printf("pid2 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
1645 printf("pid2 successfully read the range 130:4\n");
1648 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
1649 printf("pid2 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
1650 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
1651 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
1655 printf("pid2 successfully wrote to the range 130:4 (should be denied)\n");
1659 cli_setpid(cli1, 1);
1660 cli_unlock(cli1, fnum1, 130, 4);
1662 if (!cli_lock(cli1, fnum1, 130, 4, 0, WRITE_LOCK)) {
1663 printf("Unable to apply write lock on range 130:4, error was %s\n", cli_errstr(cli1));
1666 printf("pid1 successfully locked range 130:4 for WRITE\n");
1669 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
1670 printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
1673 printf("pid1 successfully read the range 130:4\n");
1676 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
1677 printf("pid1 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
1680 printf("pid1 successfully wrote to the range 130:4\n");
1683 cli_setpid(cli1, 2);
1685 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
1686 printf("pid2 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
1687 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
1688 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
1692 printf("pid2 successfully read the range 130:4 (should be denied)\n");
1696 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
1697 printf("pid2 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
1698 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
1699 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
1703 printf("pid2 successfully wrote to the range 130:4 (should be denied)\n");
1707 cli_unlock(cli1, fnum1, 130, 0);
1711 cli_close(cli1, fnum1);
1712 cli_unlink(cli1, fname);
1713 torture_close_connection(cli1);
1715 printf("finished locktest7\n");
1720 test whether fnums and tids open on one VC are available on another (a major
1723 static BOOL run_fdpasstest(int dummy)
1725 struct cli_state *cli1, *cli2;
1726 const char *fname = "\\fdpass.tst";
1730 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
1733 cli_sockopt(cli1, sockops);
1734 cli_sockopt(cli2, sockops);
1736 printf("starting fdpasstest\n");
1738 cli_unlink(cli1, fname);
1740 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1742 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
1746 if (cli_write(cli1, fnum1, 0, "hello world\n", 0, 13) != 13) {
1747 printf("write failed (%s)\n", cli_errstr(cli1));
1751 cli2->vuid = cli1->vuid;
1752 cli2->cnum = cli1->cnum;
1753 cli2->pid = cli1->pid;
1755 if (cli_read(cli2, fnum1, buf, 0, 13) == 13) {
1756 printf("read succeeded! nasty security hole [%s]\n",
1761 cli_close(cli1, fnum1);
1762 cli_unlink(cli1, fname);
1764 torture_close_connection(cli1);
1765 torture_close_connection(cli2);
1767 printf("finished fdpasstest\n");
1773 This test checks that
1775 1) the server does not allow an unlink on a file that is open
1777 static BOOL run_unlinktest(int dummy)
1779 struct cli_state *cli;
1780 const char *fname = "\\unlink.tst";
1782 BOOL correct = True;
1784 if (!torture_open_connection(&cli)) {
1788 cli_sockopt(cli, sockops);
1790 printf("starting unlink test\n");
1792 cli_unlink(cli, fname);
1796 fnum = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1798 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
1802 if (cli_unlink(cli, fname)) {
1803 printf("error: server allowed unlink on an open file\n");
1806 correct = check_error(__LINE__, cli, ERRDOS, ERRbadshare,
1807 NT_STATUS_SHARING_VIOLATION);
1810 cli_close(cli, fnum);
1811 cli_unlink(cli, fname);
1813 if (!torture_close_connection(cli)) {
1817 printf("unlink test finished\n");
1824 test how many open files this server supports on the one socket
1826 static BOOL run_maxfidtest(int dummy)
1828 struct cli_state *cli;
1829 const char *template = "\\maxfid.%d.%d";
1831 int fnums[0x11000], i;
1833 BOOL correct = True;
1838 printf("failed to connect\n");
1842 cli_sockopt(cli, sockops);
1844 for (i=0; i<0x11000; i++) {
1845 slprintf(fname,sizeof(fname)-1,template, i,(int)getpid());
1846 if ((fnums[i] = cli_open(cli, fname,
1847 O_RDWR|O_CREAT|O_TRUNC, DENY_NONE)) ==
1849 printf("open of %s failed (%s)\n",
1850 fname, cli_errstr(cli));
1851 printf("maximum fnum is %d\n", i);
1859 printf("cleaning up\n");
1861 slprintf(fname,sizeof(fname)-1,template, i,(int)getpid());
1862 cli_close(cli, fnums[i]);
1863 if (!cli_unlink(cli, fname)) {
1864 printf("unlink of %s failed (%s)\n",
1865 fname, cli_errstr(cli));
1872 printf("maxfid test finished\n");
1873 if (!torture_close_connection(cli)) {
1879 /* generate a random buffer */
1880 static void rand_buf(char *buf, int len)
1883 *buf = (char)sys_random();
1888 /* send smb negprot commands, not reading the response */
1889 static BOOL run_negprot_nowait(int dummy)
1892 static struct cli_state cli;
1893 BOOL correct = True;
1895 printf("starting negprot nowait test\n");
1897 if (!open_nbt_connection(&cli)) {
1901 for (i=0;i<50000;i++) {
1902 cli_negprot_send(&cli);
1905 if (!torture_close_connection(&cli)) {
1909 printf("finished negprot nowait test\n");
1915 /* send random IPC commands */
1916 static BOOL run_randomipc(int dummy)
1918 char *rparam = NULL;
1922 int api, param_len, i;
1923 struct cli_state *cli;
1924 BOOL correct = True;
1927 printf("starting random ipc test\n");
1929 if (!torture_open_connection(&cli)) {
1933 for (i=0;i<count;i++) {
1934 api = sys_random() % 500;
1935 param_len = (sys_random() % 64);
1937 rand_buf(param, param_len);
1942 param, param_len, 8,
1943 NULL, 0, BUFFER_SIZE,
1947 printf("%d/%d\r", i,count);
1950 printf("%d/%d\n", i, count);
1952 if (!torture_close_connection(cli)) {
1956 printf("finished random ipc test\n");
1963 static void browse_callback(const char *sname, uint32 stype,
1964 const char *comment, void *state)
1966 printf("\t%20.20s %08x %s\n", sname, stype, comment);
1972 This test checks the browse list code
1975 static BOOL run_browsetest(int dummy)
1977 static struct cli_state *cli;
1978 BOOL correct = True;
1980 printf("starting browse test\n");
1982 if (!torture_open_connection(&cli)) {
1986 printf("domain list:\n");
1987 cli_NetServerEnum(cli, cli->server_domain,
1988 SV_TYPE_DOMAIN_ENUM,
1989 browse_callback, NULL);
1991 printf("machine list:\n");
1992 cli_NetServerEnum(cli, cli->server_domain,
1994 browse_callback, NULL);
1996 if (!torture_close_connection(cli)) {
2000 printf("browse test finished\n");
2008 This checks how the getatr calls works
2010 static BOOL run_attrtest(int dummy)
2012 struct cli_state *cli;
2015 const char *fname = "\\attrib.tst";
2016 BOOL correct = True;
2018 printf("starting attrib test\n");
2020 if (!torture_open_connection(&cli)) {
2024 cli_unlink(cli, fname);
2025 fnum = cli_open(cli, fname,
2026 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2027 cli_close(cli, fnum);
2028 if (!cli_getatr(cli, fname, NULL, NULL, &t)) {
2029 printf("getatr failed (%s)\n", cli_errstr(cli));
2033 if (abs(t - time(NULL)) > 60*60*24*10) {
2034 printf("ERROR: SMBgetatr bug. time is %s",
2040 t2 = t-60*60*24; /* 1 day ago */
2042 if (!cli_setatr(cli, fname, 0, t2)) {
2043 printf("setatr failed (%s)\n", cli_errstr(cli));
2047 if (!cli_getatr(cli, fname, NULL, NULL, &t)) {
2048 printf("getatr failed (%s)\n", cli_errstr(cli));
2053 printf("ERROR: getatr/setatr bug. times are\n%s",
2055 printf("%s", ctime(&t2));
2059 cli_unlink(cli, fname);
2061 if (!torture_close_connection(cli)) {
2065 printf("attrib test finished\n");
2072 This checks a couple of trans2 calls
2074 static BOOL run_trans2test(int dummy)
2076 struct cli_state *cli;
2079 time_t c_time, a_time, m_time, w_time, m_time2;
2080 const char *fname = "\\trans2.tst";
2081 const char *dname = "\\trans2";
2082 const char *fname2 = "\\trans2\\trans2.tst";
2084 BOOL correct = True;
2086 printf("starting trans2 test\n");
2088 if (!torture_open_connection(&cli)) {
2092 cli_unlink(cli, fname);
2093 fnum = cli_open(cli, fname,
2094 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2095 if (!cli_qfileinfo(cli, fnum, NULL, &size, &c_time, &a_time, &m_time,
2097 printf("ERROR: qfileinfo failed (%s)\n", cli_errstr(cli));
2101 if (!cli_qfilename(cli, fnum, pname)) {
2102 printf("ERROR: qfilename failed (%s)\n", cli_errstr(cli));
2106 if (strcmp(pname, fname)) {
2107 printf("qfilename gave different name? [%s] [%s]\n",
2112 cli_close(cli, fnum);
2116 cli_unlink(cli, fname);
2117 fnum = cli_open(cli, fname,
2118 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2120 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
2123 cli_close(cli, fnum);
2125 if (!cli_qpathinfo(cli, fname, &c_time, &a_time, &m_time, &size, NULL)) {
2126 printf("ERROR: qpathinfo failed (%s)\n", cli_errstr(cli));
2129 if (c_time != m_time) {
2130 printf("create time=%s", ctime(&c_time));
2131 printf("modify time=%s", ctime(&m_time));
2132 printf("This system appears to have sticky create times\n");
2135 if (a_time % (60*60) == 0) {
2136 printf("access time=%s", ctime(&a_time));
2137 printf("This system appears to set a midnight access time\n");
2141 if (abs(m_time - time(NULL)) > 60*60*24*7) {
2142 printf("ERROR: totally incorrect times - maybe word reversed? mtime=%s", ctime(&m_time));
2148 cli_unlink(cli, fname);
2149 fnum = cli_open(cli, fname,
2150 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2151 cli_close(cli, fnum);
2152 if (!cli_qpathinfo2(cli, fname, &c_time, &a_time, &m_time,
2153 &w_time, &size, NULL, NULL)) {
2154 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli));
2157 if (w_time < 60*60*24*2) {
2158 printf("write time=%s", ctime(&w_time));
2159 printf("This system appears to set a initial 0 write time\n");
2164 cli_unlink(cli, fname);
2167 /* check if the server updates the directory modification time
2168 when creating a new file */
2169 if (!cli_mkdir(cli, dname)) {
2170 printf("ERROR: mkdir failed (%s)\n", cli_errstr(cli));
2174 if (!cli_qpathinfo2(cli, "\\trans2\\", &c_time, &a_time, &m_time,
2175 &w_time, &size, NULL, NULL)) {
2176 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli));
2180 fnum = cli_open(cli, fname2,
2181 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2182 cli_write(cli, fnum, 0, (char *)&fnum, 0, sizeof(fnum));
2183 cli_close(cli, fnum);
2184 if (!cli_qpathinfo2(cli, "\\trans2\\", &c_time, &a_time, &m_time2,
2185 &w_time, &size, NULL, NULL)) {
2186 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli));
2189 if (m_time2 == m_time) {
2190 printf("This system does not update directory modification times\n");
2194 cli_unlink(cli, fname2);
2195 cli_rmdir(cli, dname);
2197 if (!torture_close_connection(cli)) {
2201 printf("trans2 test finished\n");
2207 This checks new W2K calls.
2210 static BOOL new_trans(struct cli_state *pcli, int fnum, int level)
2213 BOOL correct = True;
2215 memset(buf, 0xff, sizeof(buf));
2217 if (!cli_qfileinfo_test(pcli, fnum, level, buf)) {
2218 printf("ERROR: qfileinfo (%d) failed (%s)\n", level, cli_errstr(pcli));
2221 printf("qfileinfo: level %d\n", level);
2222 dump_data(0, buf, 256);
2228 static BOOL run_w2ktest(int dummy)
2230 struct cli_state *cli;
2232 const char *fname = "\\w2ktest\\w2k.tst";
2234 BOOL correct = True;
2236 printf("starting w2k test\n");
2238 if (!torture_open_connection(&cli)) {
2242 fnum = cli_open(cli, fname,
2243 O_RDWR | O_CREAT , DENY_NONE);
2245 for (level = 1004; level < 1040; level++) {
2246 new_trans(cli, fnum, level);
2249 cli_close(cli, fnum);
2251 if (!torture_close_connection(cli)) {
2255 printf("w2k test finished\n");
2262 this is a harness for some oplock tests
2264 static BOOL run_oplock1(int dummy)
2266 struct cli_state *cli1;
2267 const char *fname = "\\lockt1.lck";
2269 BOOL correct = True;
2271 printf("starting oplock test 1\n");
2273 if (!torture_open_connection(&cli1)) {
2277 cli_unlink(cli1, fname);
2279 cli_sockopt(cli1, sockops);
2281 cli1->use_oplocks = True;
2283 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2285 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
2289 cli1->use_oplocks = False;
2291 cli_unlink(cli1, fname);
2292 cli_unlink(cli1, fname);
2294 if (!cli_close(cli1, fnum1)) {
2295 printf("close2 failed (%s)\n", cli_errstr(cli1));
2299 if (!cli_unlink(cli1, fname)) {
2300 printf("unlink failed (%s)\n", cli_errstr(cli1));
2304 if (!torture_close_connection(cli1)) {
2308 printf("finished oplock test 1\n");
2313 static BOOL run_oplock2(int dummy)
2315 struct cli_state *cli1, *cli2;
2316 const char *fname = "\\lockt2.lck";
2318 int saved_use_oplocks = use_oplocks;
2320 BOOL correct = True;
2321 volatile BOOL *shared_correct;
2323 shared_correct = (volatile BOOL *)shm_setup(sizeof(BOOL));
2324 *shared_correct = True;
2326 use_level_II_oplocks = True;
2329 printf("starting oplock test 2\n");
2331 if (!torture_open_connection(&cli1)) {
2332 use_level_II_oplocks = False;
2333 use_oplocks = saved_use_oplocks;
2337 cli1->use_oplocks = True;
2338 cli1->use_level_II_oplocks = True;
2340 if (!torture_open_connection(&cli2)) {
2341 use_level_II_oplocks = False;
2342 use_oplocks = saved_use_oplocks;
2346 cli2->use_oplocks = True;
2347 cli2->use_level_II_oplocks = True;
2349 cli_unlink(cli1, fname);
2351 cli_sockopt(cli1, sockops);
2352 cli_sockopt(cli2, sockops);
2354 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2356 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
2360 /* Don't need the globals any more. */
2361 use_level_II_oplocks = False;
2362 use_oplocks = saved_use_oplocks;
2366 fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
2368 printf("second open of %s failed (%s)\n", fname, cli_errstr(cli1));
2369 *shared_correct = False;
2375 if (!cli_close(cli2, fnum2)) {
2376 printf("close2 failed (%s)\n", cli_errstr(cli1));
2377 *shared_correct = False;
2385 /* Ensure cli1 processes the break. */
2387 if (cli_read(cli1, fnum1, buf, 0, 4) != 4) {
2388 printf("read on fnum1 failed (%s)\n", cli_errstr(cli1));
2392 /* Should now be at level II. */
2393 /* Test if sending a write locks causes a break to none. */
2395 if (!cli_lock(cli1, fnum1, 0, 4, 0, READ_LOCK)) {
2396 printf("lock failed (%s)\n", cli_errstr(cli1));
2400 cli_unlock(cli1, fnum1, 0, 4);
2404 if (!cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK)) {
2405 printf("lock failed (%s)\n", cli_errstr(cli1));
2409 cli_unlock(cli1, fnum1, 0, 4);
2413 cli_read(cli1, fnum1, buf, 0, 4);
2416 if (cli_write(cli1, fnum1, 0, buf, 0, 4) != 4) {
2417 printf("write on fnum1 failed (%s)\n", cli_errstr(cli1));
2422 if (!cli_close(cli1, fnum1)) {
2423 printf("close1 failed (%s)\n", cli_errstr(cli1));
2429 if (!cli_unlink(cli1, fname)) {
2430 printf("unlink failed (%s)\n", cli_errstr(cli1));
2434 if (!torture_close_connection(cli1)) {
2438 if (!*shared_correct) {
2442 printf("finished oplock test 2\n");
2447 /* handler for oplock 3 tests */
2448 static BOOL oplock3_handler(struct cli_state *cli, int fnum, unsigned char level)
2450 printf("got oplock break fnum=%d level=%d\n",
2452 return cli_oplock_ack(cli, fnum, level);
2455 static BOOL run_oplock3(int dummy)
2457 struct cli_state *cli;
2458 const char *fname = "\\oplockt3.dat";
2460 char buf[4] = "abcd";
2461 BOOL correct = True;
2462 volatile BOOL *shared_correct;
2464 shared_correct = (volatile BOOL *)shm_setup(sizeof(BOOL));
2465 *shared_correct = True;
2467 printf("starting oplock test 3\n");
2472 use_level_II_oplocks = True;
2473 if (!torture_open_connection(&cli)) {
2474 *shared_correct = False;
2478 /* try to trigger a oplock break in parent */
2479 fnum = cli_open(cli, fname, O_RDWR, DENY_NONE);
2480 cli_write(cli, fnum, 0, buf, 0, 4);
2486 use_level_II_oplocks = True;
2487 if (!torture_open_connection(&cli)) {
2490 cli_oplock_handler(cli, oplock3_handler);
2491 fnum = cli_open(cli, fname, O_RDWR|O_CREAT, DENY_NONE);
2492 cli_write(cli, fnum, 0, buf, 0, 4);
2493 cli_close(cli, fnum);
2494 fnum = cli_open(cli, fname, O_RDWR, DENY_NONE);
2495 cli->timeout = 20000;
2496 cli_receive_smb(cli);
2497 printf("finished oplock test 3\n");
2499 return (correct && *shared_correct);
2501 /* What are we looking for here? What's sucess and what's FAILURE? */
2507 Test delete on close semantics.
2509 static BOOL run_deletetest(int dummy)
2511 struct cli_state *cli1;
2512 struct cli_state *cli2;
2513 const char *fname = "\\delete.file";
2516 BOOL correct = True;
2518 printf("starting delete test\n");
2520 if (!torture_open_connection(&cli1)) {
2524 cli_sockopt(cli1, sockops);
2526 /* Test 1 - this should delete the file on close. */
2528 cli_setatr(cli1, fname, 0, 0);
2529 cli_unlink(cli1, fname);
2531 fnum1 = cli_nt_create_full(cli1, fname, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL,
2532 FILE_SHARE_DELETE, FILE_OVERWRITE_IF,
2533 FILE_DELETE_ON_CLOSE);
2536 printf("[1] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2541 if (!cli_close(cli1, fnum1)) {
2542 printf("[1] close failed (%s)\n", cli_errstr(cli1));
2547 fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
2549 printf("[1] open of %s succeeded (should fail)\n", fname);
2554 printf("first delete on close test succeeded.\n");
2556 /* Test 2 - this should delete the file on close. */
2558 cli_setatr(cli1, fname, 0, 0);
2559 cli_unlink(cli1, fname);
2561 fnum1 = cli_nt_create_full(cli1, fname, GENERIC_ALL_ACCESS,
2562 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
2563 FILE_OVERWRITE_IF, 0);
2566 printf("[2] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2571 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
2572 printf("[2] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
2577 if (!cli_close(cli1, fnum1)) {
2578 printf("[2] close failed (%s)\n", cli_errstr(cli1));
2583 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
2585 printf("[2] open of %s succeeded should have been deleted on close !\n", fname);
2586 if (!cli_close(cli1, fnum1)) {
2587 printf("[2] close failed (%s)\n", cli_errstr(cli1));
2591 cli_unlink(cli1, fname);
2593 printf("second delete on close test succeeded.\n");
2596 cli_setatr(cli1, fname, 0, 0);
2597 cli_unlink(cli1, fname);
2599 fnum1 = cli_nt_create_full(cli1, fname, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL,
2600 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0);
2603 printf("[3] open - 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
2608 /* This should fail with a sharing violation - open for delete is only compatible
2609 with SHARE_DELETE. */
2611 fnum2 = cli_nt_create_full(cli1, fname, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
2612 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0);
2615 printf("[3] open - 2 of %s succeeded - should have failed.\n", fname);
2620 /* This should succeed. */
2622 fnum2 = cli_nt_create_full(cli1, fname, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
2623 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0);
2626 printf("[3] open - 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
2631 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
2632 printf("[3] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
2637 if (!cli_close(cli1, fnum1)) {
2638 printf("[3] close 1 failed (%s)\n", cli_errstr(cli1));
2643 if (!cli_close(cli1, fnum2)) {
2644 printf("[3] close 2 failed (%s)\n", cli_errstr(cli1));
2649 /* This should fail - file should no longer be there. */
2651 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
2653 printf("[3] open of %s succeeded should have been deleted on close !\n", fname);
2654 if (!cli_close(cli1, fnum1)) {
2655 printf("[3] close failed (%s)\n", cli_errstr(cli1));
2657 cli_unlink(cli1, fname);
2661 printf("third delete on close test succeeded.\n");
2664 cli_setatr(cli1, fname, 0, 0);
2665 cli_unlink(cli1, fname);
2667 fnum1 = cli_nt_create_full(cli1, fname, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
2668 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0);
2671 printf("[4] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2676 /* This should succeed. */
2677 fnum2 = cli_nt_create_full(cli1, fname, GENERIC_READ_ACCESS,
2678 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0);
2680 printf("[4] open - 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
2685 if (!cli_close(cli1, fnum2)) {
2686 printf("[4] close - 1 failed (%s)\n", cli_errstr(cli1));
2691 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
2692 printf("[4] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
2697 /* This should fail - no more opens once delete on close set. */
2698 fnum2 = cli_nt_create_full(cli1, fname, GENERIC_READ_ACCESS,
2699 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0);
2701 printf("[4] open - 3 of %s succeeded ! Should have failed.\n", fname );
2705 printf("fourth delete on close test succeeded.\n");
2707 if (!cli_close(cli1, fnum1)) {
2708 printf("[4] close - 2 failed (%s)\n", cli_errstr(cli1));
2714 cli_setatr(cli1, fname, 0, 0);
2715 cli_unlink(cli1, fname);
2717 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT, DENY_NONE);
2719 printf("[5] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2724 /* This should fail - only allowed on NT opens with DELETE access. */
2726 if (cli_nt_delete_on_close(cli1, fnum1, True)) {
2727 printf("[5] setting delete_on_close on OpenX file succeeded - should fail !\n");
2732 if (!cli_close(cli1, fnum1)) {
2733 printf("[5] close - 2 failed (%s)\n", cli_errstr(cli1));
2738 printf("fifth delete on close test succeeded.\n");
2741 cli_setatr(cli1, fname, 0, 0);
2742 cli_unlink(cli1, fname);
2744 fnum1 = cli_nt_create_full(cli1, fname, FILE_READ_DATA|FILE_WRITE_DATA,
2745 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
2746 FILE_OVERWRITE_IF, 0);
2749 printf("[6] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2754 /* This should fail - only allowed on NT opens with DELETE access. */
2756 if (cli_nt_delete_on_close(cli1, fnum1, True)) {
2757 printf("[6] setting delete_on_close on file with no delete access succeeded - should fail !\n");
2762 if (!cli_close(cli1, fnum1)) {
2763 printf("[6] close - 2 failed (%s)\n", cli_errstr(cli1));
2768 printf("sixth delete on close test succeeded.\n");
2771 cli_setatr(cli1, fname, 0, 0);
2772 cli_unlink(cli1, fname);
2774 fnum1 = cli_nt_create_full(cli1, fname, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
2775 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF, 0);
2778 printf("[7] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2783 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
2784 printf("[7] setting delete_on_close on file failed !\n");
2789 if (!cli_nt_delete_on_close(cli1, fnum1, False)) {
2790 printf("[7] unsetting delete_on_close on file failed !\n");
2795 if (!cli_close(cli1, fnum1)) {
2796 printf("[7] close - 2 failed (%s)\n", cli_errstr(cli1));
2801 /* This next open should succeed - we reset the flag. */
2803 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
2805 printf("[5] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2810 if (!cli_close(cli1, fnum1)) {
2811 printf("[7] close - 2 failed (%s)\n", cli_errstr(cli1));
2816 printf("seventh delete on close test succeeded.\n");
2819 cli_setatr(cli1, fname, 0, 0);
2820 cli_unlink(cli1, fname);
2822 if (!torture_open_connection(&cli2)) {
2823 printf("[8] failed to open second connection.\n");
2828 cli_sockopt(cli1, sockops);
2830 fnum1 = cli_nt_create_full(cli1, fname, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
2831 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0);
2834 printf("[8] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2839 fnum2 = cli_nt_create_full(cli2, fname, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
2840 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0);
2843 printf("[8] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2848 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
2849 printf("[8] setting delete_on_close on file failed !\n");
2854 if (!cli_close(cli1, fnum1)) {
2855 printf("[8] close - 1 failed (%s)\n", cli_errstr(cli1));
2860 if (!cli_close(cli2, fnum2)) {
2861 printf("[8] close - 2 failed (%s)\n", cli_errstr(cli2));
2866 /* This should fail.. */
2867 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
2869 printf("[8] open of %s succeeded should have been deleted on close !\n", fname);
2873 printf("eighth delete on close test succeeded.\n");
2875 /* This should fail - we need to set DELETE_ACCESS. */
2876 fnum1 = cli_nt_create_full(cli1, fname, FILE_READ_DATA|FILE_WRITE_DATA,
2877 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, FILE_OVERWRITE_IF, FILE_DELETE_ON_CLOSE);
2880 printf("[9] open of %s succeeded should have failed!\n", fname);
2885 printf("ninth delete on close test succeeded.\n");
2887 fnum1 = cli_nt_create_full(cli1, fname, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
2888 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, FILE_OVERWRITE_IF, FILE_DELETE_ON_CLOSE);
2890 printf("[10] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2895 /* This should delete the file. */
2896 if (!cli_close(cli1, fnum1)) {
2897 printf("[10] close failed (%s)\n", cli_errstr(cli1));
2902 /* This should fail.. */
2903 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
2905 printf("[10] open of %s succeeded should have been deleted on close !\n", fname);
2909 printf("tenth delete on close test succeeded.\n");
2910 printf("finished delete test\n");
2913 /* FIXME: This will crash if we aborted before cli2 got
2914 * intialized, because these functions don't handle
2915 * uninitialized connections. */
2917 cli_close(cli1, fnum1);
2918 cli_close(cli1, fnum2);
2919 cli_setatr(cli1, fname, 0, 0);
2920 cli_unlink(cli1, fname);
2922 if (!torture_close_connection(cli1)) {
2925 if (!torture_close_connection(cli2)) {
2933 print out server properties
2935 static BOOL run_properties(int dummy)
2937 static struct cli_state *cli;
2938 BOOL correct = True;
2940 printf("starting properties test\n");
2944 if (!torture_open_connection(&cli)) {
2948 cli_sockopt(cli, sockops);
2950 d_printf("Capabilities 0x%08x\n", cli->capabilities);
2952 if (!torture_close_connection(cli)) {
2961 /* FIRST_DESIRED_ACCESS 0xf019f */
2962 #define FIRST_DESIRED_ACCESS FILE_READ_DATA|FILE_WRITE_DATA|FILE_APPEND_DATA|\
2963 FILE_READ_EA| /* 0xf */ \
2964 FILE_WRITE_EA|FILE_READ_ATTRIBUTES| /* 0x90 */ \
2965 FILE_WRITE_ATTRIBUTES| /* 0x100 */ \
2966 DELETE_ACCESS|READ_CONTROL_ACCESS|\
2967 WRITE_DAC_ACCESS|WRITE_OWNER_ACCESS /* 0xf0000 */
2968 /* SECOND_DESIRED_ACCESS 0xe0080 */
2969 #define SECOND_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
2970 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
2971 WRITE_OWNER_ACCESS /* 0xe0000 */
2974 #define THIRD_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
2975 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
2977 WRITE_OWNER_ACCESS /* */
2981 Test ntcreate calls made by xcopy
2983 static BOOL run_xcopy(int dummy)
2985 static struct cli_state *cli1;
2986 const char *fname = "\\test.txt";
2987 BOOL correct = True;
2990 printf("starting xcopy test\n");
2992 if (!torture_open_connection(&cli1)) {
2996 fnum1 = cli_nt_create_full(cli1, fname,
2997 FIRST_DESIRED_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
2998 FILE_SHARE_NONE, FILE_OVERWRITE_IF,
3002 printf("First open failed - %s\n", cli_errstr(cli1));
3006 fnum2 = cli_nt_create_full(cli1, fname,
3007 SECOND_DESIRED_ACCESS, 0,
3008 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN,
3011 printf("second open failed - %s\n", cli_errstr(cli1));
3015 if (!torture_close_connection(cli1)) {
3023 Test rename on files open with share delete and no share delete.
3025 static BOOL run_rename(int dummy)
3027 static struct cli_state *cli1;
3028 const char *fname = "\\test.txt";
3029 const char *fname1 = "\\test1.txt";
3030 BOOL correct = True;
3033 printf("starting rename test\n");
3035 if (!torture_open_connection(&cli1)) {
3039 cli_unlink(cli1, fname);
3040 cli_unlink(cli1, fname1);
3041 fnum1 = cli_nt_create_full(cli1, fname, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3042 FILE_SHARE_READ, FILE_OVERWRITE_IF, 0);
3045 printf("First open failed - %s\n", cli_errstr(cli1));
3049 if (!cli_rename(cli1, fname, fname1)) {
3050 printf("First rename failed (this is correct) - %s\n", cli_errstr(cli1));
3052 printf("First rename succeeded - this should have failed !\n");
3056 if (!cli_close(cli1, fnum1)) {
3057 printf("close - 1 failed (%s)\n", cli_errstr(cli1));
3061 cli_unlink(cli1, fname);
3062 cli_unlink(cli1, fname1);
3063 fnum1 = cli_nt_create_full(cli1, fname,GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3065 FILE_SHARE_DELETE|FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0);
3067 FILE_SHARE_DELETE|FILE_SHARE_READ, FILE_OVERWRITE_IF, 0);
3071 printf("Second open failed - %s\n", cli_errstr(cli1));
3075 if (!cli_rename(cli1, fname, fname1)) {
3076 printf("Second rename failed - this should have succeeded - %s\n", cli_errstr(cli1));
3079 printf("Second rename succeeded\n");
3082 if (!cli_close(cli1, fnum1)) {
3083 printf("close - 2 failed (%s)\n", cli_errstr(cli1));
3087 cli_unlink(cli1, fname);
3088 cli_unlink(cli1, fname1);
3090 fnum1 = cli_nt_create_full(cli1, fname,READ_CONTROL_ACCESS, FILE_ATTRIBUTE_NORMAL,
3091 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0);
3094 printf("Third open failed - %s\n", cli_errstr(cli1));
3103 fnum2 = cli_nt_create_full(cli1, fname,DELETE_ACCESS, FILE_ATTRIBUTE_NORMAL,
3104 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0);
3107 printf("Fourth open failed - %s\n", cli_errstr(cli1));
3110 if (!cli_nt_delete_on_close(cli1, fnum2, True)) {
3111 printf("[8] setting delete_on_close on file failed !\n");
3115 if (!cli_close(cli1, fnum2)) {
3116 printf("close - 4 failed (%s)\n", cli_errstr(cli1));
3122 if (!cli_rename(cli1, fname, fname1)) {
3123 printf("Third rename failed - this should have succeeded - %s\n", cli_errstr(cli1));
3126 printf("Third rename succeeded\n");
3129 if (!cli_close(cli1, fnum1)) {
3130 printf("close - 3 failed (%s)\n", cli_errstr(cli1));
3134 cli_unlink(cli1, fname);
3135 cli_unlink(cli1, fname1);
3137 if (!torture_close_connection(cli1)) {
3144 static BOOL run_pipe_number(int dummy)
3146 struct cli_state *cli1;
3147 const char *pipe_name = "\\SPOOLSS";
3151 printf("starting pipenumber test\n");
3152 if (!torture_open_connection(&cli1)) {
3156 cli_sockopt(cli1, sockops);
3158 fnum = cli_nt_create_full(cli1, pipe_name,FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
3159 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN_IF, 0);
3162 printf("Open of pipe %s failed with error (%s)\n", pipe_name, cli_errstr(cli1));
3168 printf("pipe_number test - we can open %d %s pipes.\n", num_pipes, pipe_name );
3169 torture_close_connection(cli1);
3174 Test open mode returns on read-only files.
3176 static BOOL run_opentest(int dummy)
3178 static struct cli_state *cli1;
3179 static struct cli_state *cli2;
3180 const char *fname = "\\readonly.file";
3184 BOOL correct = True;
3187 printf("starting open test\n");
3189 if (!torture_open_connection(&cli1)) {
3193 cli_setatr(cli1, fname, 0, 0);
3194 cli_unlink(cli1, fname);
3196 cli_sockopt(cli1, sockops);
3198 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
3200 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
3204 if (!cli_close(cli1, fnum1)) {
3205 printf("close2 failed (%s)\n", cli_errstr(cli1));
3209 if (!cli_setatr(cli1, fname, aRONLY, 0)) {
3210 printf("cli_setatr failed (%s)\n", cli_errstr(cli1));
3214 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_WRITE);
3216 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
3220 /* This will fail - but the error should be ERRnoaccess, not ERRbadshare. */
3221 fnum2 = cli_open(cli1, fname, O_RDWR, DENY_ALL);
3223 if (check_error(__LINE__, cli1, ERRDOS, ERRnoaccess,
3224 NT_STATUS_ACCESS_DENIED)) {
3225 printf("correct error code ERRDOS/ERRnoaccess returned\n");
3228 printf("finished open test 1\n");
3230 cli_close(cli1, fnum1);
3232 /* Now try not readonly and ensure ERRbadshare is returned. */
3234 cli_setatr(cli1, fname, 0, 0);
3236 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_WRITE);
3238 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
3242 /* This will fail - but the error should be ERRshare. */
3243 fnum2 = cli_open(cli1, fname, O_RDWR, DENY_ALL);
3245 if (check_error(__LINE__, cli1, ERRDOS, ERRbadshare,
3246 NT_STATUS_SHARING_VIOLATION)) {
3247 printf("correct error code ERRDOS/ERRbadshare returned\n");
3250 if (!cli_close(cli1, fnum1)) {
3251 printf("close2 failed (%s)\n", cli_errstr(cli1));
3255 cli_unlink(cli1, fname);
3257 printf("finished open test 2\n");
3259 /* Test truncate open disposition on file opened for read. */
3261 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
3263 printf("(3) open (1) of %s failed (%s)\n", fname, cli_errstr(cli1));
3267 /* write 20 bytes. */
3269 memset(buf, '\0', 20);
3271 if (cli_write(cli1, fnum1, 0, buf, 0, 20) != 20) {
3272 printf("write failed (%s)\n", cli_errstr(cli1));
3276 if (!cli_close(cli1, fnum1)) {
3277 printf("(3) close1 failed (%s)\n", cli_errstr(cli1));
3281 /* Ensure size == 20. */
3282 if (!cli_getatr(cli1, fname, NULL, &fsize, NULL)) {
3283 printf("(3) getatr failed (%s)\n", cli_errstr(cli1));
3288 printf("(3) file size != 20\n");
3292 /* Now test if we can truncate a file opened for readonly. */
3294 fnum1 = cli_open(cli1, fname, O_RDONLY|O_TRUNC, DENY_NONE);
3296 printf("(3) open (2) of %s failed (%s)\n", fname, cli_errstr(cli1));
3300 if (!cli_close(cli1, fnum1)) {
3301 printf("close2 failed (%s)\n", cli_errstr(cli1));
3305 /* Ensure size == 0. */
3306 if (!cli_getatr(cli1, fname, NULL, &fsize, NULL)) {
3307 printf("(3) getatr failed (%s)\n", cli_errstr(cli1));
3312 printf("(3) file size != 0\n");
3315 printf("finished open test 3\n");
3317 cli_unlink(cli1, fname);
3320 printf("testing ctemp\n");
3321 fnum1 = cli_ctemp(cli1, "\\", &tmp_path);
3323 printf("ctemp failed (%s)\n", cli_errstr(cli1));
3326 printf("ctemp gave path %s\n", tmp_path);
3327 if (!cli_close(cli1, fnum1)) {
3328 printf("close of temp failed (%s)\n", cli_errstr(cli1));
3330 if (!cli_unlink(cli1, tmp_path)) {
3331 printf("unlink of temp failed (%s)\n", cli_errstr(cli1));
3334 /* Test the non-io opens... */
3336 if (!torture_open_connection(&cli2)) {
3340 cli_setatr(cli2, fname, 0, 0);
3341 cli_unlink(cli2, fname);
3343 cli_sockopt(cli2, sockops);
3345 printf("TEST #1 testing 2 non-io opens (no delete)\n");
3347 fnum1 = cli_nt_create_full(cli1, fname,FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3348 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0);
3351 printf("test 1 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3355 fnum2 = cli_nt_create_full(cli2, fname,FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3356 FILE_SHARE_NONE, FILE_OPEN_IF, 0);
3359 printf("test 1 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3363 if (!cli_close(cli1, fnum1)) {
3364 printf("test 1 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3367 if (!cli_close(cli2, fnum2)) {
3368 printf("test 1 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3372 printf("non-io open test #1 passed.\n");
3374 cli_unlink(cli1, fname);
3376 printf("TEST #2 testing 2 non-io opens (first with delete)\n");
3378 fnum1 = cli_nt_create_full(cli1, fname,DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3379 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0);
3382 printf("test 2 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3386 fnum2 = cli_nt_create_full(cli2, fname,FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3387 FILE_SHARE_NONE, FILE_OPEN_IF, 0);
3390 printf("test 2 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3394 if (!cli_close(cli1, fnum1)) {
3395 printf("test 1 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3398 if (!cli_close(cli2, fnum2)) {
3399 printf("test 1 close 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
3403 printf("non-io open test #2 passed.\n");
3405 cli_unlink(cli1, fname);
3407 printf("TEST #3 testing 2 non-io opens (second with delete)\n");
3409 fnum1 = cli_nt_create_full(cli1, fname,FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3410 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0);
3413 printf("test 3 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3417 fnum2 = cli_nt_create_full(cli2, fname,DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3418 FILE_SHARE_NONE, FILE_OPEN_IF, 0);
3421 printf("test 3 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3425 if (!cli_close(cli1, fnum1)) {
3426 printf("test 3 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3429 if (!cli_close(cli2, fnum2)) {
3430 printf("test 3 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3434 printf("non-io open test #3 passed.\n");
3436 cli_unlink(cli1, fname);
3438 printf("TEST #4 testing 2 non-io opens (both with delete)\n");
3440 fnum1 = cli_nt_create_full(cli1, fname,DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3441 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0);
3444 printf("test 4 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3448 fnum2 = cli_nt_create_full(cli2, fname,DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3449 FILE_SHARE_NONE, FILE_OPEN_IF, 0);
3452 printf("test 4 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, cli_errstr(cli2));
3456 printf("test 3 open 2 of %s gave %s (correct error should be %s)\n", fname, cli_errstr(cli2), "sharing violation");
3458 if (!cli_close(cli1, fnum1)) {
3459 printf("test 4 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3463 printf("non-io open test #4 passed.\n");
3465 cli_unlink(cli1, fname);
3467 printf("TEST #5 testing 2 non-io opens (both with delete - both with file share delete)\n");
3469 fnum1 = cli_nt_create_full(cli1, fname,DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3470 FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0);
3473 printf("test 5 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3477 fnum2 = cli_nt_create_full(cli2, fname,DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3478 FILE_SHARE_DELETE, FILE_OPEN_IF, 0);
3481 printf("test 5 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3485 if (!cli_close(cli1, fnum1)) {
3486 printf("test 5 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3490 if (!cli_close(cli2, fnum2)) {
3491 printf("test 5 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3495 printf("non-io open test #5 passed.\n");
3497 printf("TEST #6 testing 1 non-io open, one io open\n");
3499 cli_unlink(cli1, fname);
3501 fnum1 = cli_nt_create_full(cli1, fname,FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
3502 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0);
3505 printf("test 6 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3509 fnum2 = cli_nt_create_full(cli2, fname,FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3510 FILE_SHARE_READ, FILE_OPEN_IF, 0);
3513 printf("test 6 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3517 if (!cli_close(cli1, fnum1)) {
3518 printf("test 6 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3522 if (!cli_close(cli2, fnum2)) {
3523 printf("test 6 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3527 printf("non-io open test #6 passed.\n");
3529 printf("TEST #7 testing 1 non-io open, one io open with delete\n");
3531 cli_unlink(cli1, fname);
3533 fnum1 = cli_nt_create_full(cli1, fname,FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
3534 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0);
3537 printf("test 7 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3541 fnum2 = cli_nt_create_full(cli2, fname,DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3542 FILE_SHARE_READ|FILE_SHARE_DELETE, FILE_OPEN_IF, 0);
3545 printf("test 7 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, cli_errstr(cli2));
3549 printf("test 7 open 2 of %s gave %s (correct error should be %s)\n", fname, cli_errstr(cli2), "sharing violation");
3551 if (!cli_close(cli1, fnum1)) {
3552 printf("test 7 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3556 printf("non-io open test #7 passed.\n");
3558 cli_unlink(cli1, fname);
3560 if (!torture_close_connection(cli1)) {
3563 if (!torture_close_connection(cli2)) {
3570 static uint32 open_attrs_table[] = {
3571 FILE_ATTRIBUTE_NORMAL,
3572 FILE_ATTRIBUTE_ARCHIVE,
3573 FILE_ATTRIBUTE_READONLY,
3574 FILE_ATTRIBUTE_HIDDEN,
3575 FILE_ATTRIBUTE_SYSTEM,
3577 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY,
3578 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN,
3579 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM,
3580 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN,
3581 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM,
3582 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM,
3584 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN,
3585 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM,
3586 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM,
3587 FILE_ATTRIBUTE_HIDDEN,FILE_ATTRIBUTE_SYSTEM,
3590 struct trunc_open_results {
3597 static struct trunc_open_results attr_results[] = {
3598 { 0, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE },
3599 { 1, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE },
3600 { 2, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_READONLY, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY },
3601 { 16, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE },
3602 { 17, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE },
3603 { 18, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_READONLY, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY },
3604 { 51, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
3605 { 54, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
3606 { 56, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN },
3607 { 68, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
3608 { 71, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
3609 { 73, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM },
3610 { 99, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN,FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
3611 { 102, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
3612 { 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 },
3613 { 116, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
3614 { 119, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
3615 { 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 },
3616 { 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 },
3617 { 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 },
3618 { 227, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
3619 { 230, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
3620 { 232, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN },
3621 { 244, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
3622 { 247, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
3623 { 249, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM }
3626 static BOOL run_openattrtest(int dummy)
3628 static struct cli_state *cli1;
3629 const char *fname = "\\openattr.file";
3631 BOOL correct = True;
3633 unsigned int i, j, k, l;
3635 printf("starting open attr test\n");
3637 if (!torture_open_connection(&cli1)) {
3641 cli_sockopt(cli1, sockops);
3643 for (k = 0, i = 0; i < sizeof(open_attrs_table)/sizeof(uint32); i++) {
3644 cli_setatr(cli1, fname, 0, 0);
3645 cli_unlink(cli1, fname);
3646 fnum1 = cli_nt_create_full(cli1, fname,FILE_WRITE_DATA, open_attrs_table[i],
3647 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0);
3650 printf("open %d (1) of %s failed (%s)\n", i, fname, cli_errstr(cli1));
3654 if (!cli_close(cli1, fnum1)) {
3655 printf("close %d (1) of %s failed (%s)\n", i, fname, cli_errstr(cli1));
3659 for (j = 0; j < sizeof(open_attrs_table)/sizeof(uint32); j++) {
3660 fnum1 = cli_nt_create_full(cli1, fname,FILE_READ_DATA|FILE_WRITE_DATA, open_attrs_table[j],
3661 FILE_SHARE_NONE, FILE_OVERWRITE, 0);
3664 for (l = 0; l < sizeof(attr_results)/sizeof(struct trunc_open_results); l++) {
3665 if (attr_results[l].num == k) {
3666 printf("[%d] trunc open 0x%x -> 0x%x of %s failed - should have succeeded !(0x%x:%s)\n",
3667 k, open_attrs_table[i],
3668 open_attrs_table[j],
3669 fname, NT_STATUS_V(cli_nt_error(cli1)), cli_errstr(cli1));
3673 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_ACCESS_DENIED)) {
3674 printf("[%d] trunc open 0x%x -> 0x%x failed with wrong error code %s\n",
3675 k, open_attrs_table[i], open_attrs_table[j],
3680 printf("[%d] trunc open 0x%x -> 0x%x failed\n", k, open_attrs_table[i], open_attrs_table[j]);
3686 if (!cli_close(cli1, fnum1)) {
3687 printf("close %d (2) of %s failed (%s)\n", j, fname, cli_errstr(cli1));
3691 if (!cli_getatr(cli1, fname, &attr, NULL, NULL)) {
3692 printf("getatr(2) failed (%s)\n", cli_errstr(cli1));
3697 printf("[%d] getatr check [0x%x] trunc [0x%x] got attr 0x%x\n",
3698 k, open_attrs_table[i], open_attrs_table[j], attr );
3701 for (l = 0; l < sizeof(attr_results)/sizeof(struct trunc_open_results); l++) {
3702 if (attr_results[l].num == k) {
3703 if (attr != attr_results[l].result_attr ||
3704 open_attrs_table[i] != attr_results[l].init_attr ||
3705 open_attrs_table[j] != attr_results[l].trunc_attr) {
3706 printf("getatr check failed. [0x%x] trunc [0x%x] got attr 0x%x, should be 0x%x\n",
3707 open_attrs_table[i],
3708 open_attrs_table[j],
3710 attr_results[l].result_attr);
3720 cli_setatr(cli1, fname, 0, 0);
3721 cli_unlink(cli1, fname);
3723 printf("open attr test %s.\n", correct ? "passed" : "failed");
3725 if (!torture_close_connection(cli1)) {
3731 static void list_fn(file_info *finfo, const char *name, void *state)
3737 test directory listing speed
3739 static BOOL run_dirtest(int dummy)
3742 static struct cli_state *cli;
3745 BOOL correct = True;
3747 printf("starting directory test\n");
3749 if (!torture_open_connection(&cli)) {
3753 cli_sockopt(cli, sockops);
3756 for (i=0;i<torture_numops;i++) {
3758 slprintf(fname, sizeof(fname), "\\%x", (int)random());
3759 fnum = cli_open(cli, fname, O_RDWR|O_CREAT, DENY_NONE);
3761 fprintf(stderr,"Failed to open %s\n", fname);
3764 cli_close(cli, fnum);
3769 printf("Matched %d\n", cli_list(cli, "a*.*", 0, list_fn, NULL));
3770 printf("Matched %d\n", cli_list(cli, "b*.*", 0, list_fn, NULL));
3771 printf("Matched %d\n", cli_list(cli, "xyzabc", 0, list_fn, NULL));
3773 printf("dirtest core %g seconds\n", end_timer() - t1);
3776 for (i=0;i<torture_numops;i++) {
3778 slprintf(fname, sizeof(fname), "\\%x", (int)random());
3779 cli_unlink(cli, fname);
3782 if (!torture_close_connection(cli)) {
3786 printf("finished dirtest\n");
3791 static void del_fn(file_info *finfo, const char *mask, void *state)
3793 struct cli_state *pcli = (struct cli_state *)state;
3795 slprintf(fname, sizeof(fname), "\\LISTDIR\\%s", finfo->name);
3797 if (strcmp(finfo->name, ".") == 0 || strcmp(finfo->name, "..") == 0)
3800 if (finfo->mode & aDIR) {
3801 if (!cli_rmdir(pcli, fname))
3802 printf("del_fn: failed to rmdir %s\n,", fname );
3804 if (!cli_unlink(pcli, fname))
3805 printf("del_fn: failed to unlink %s\n,", fname );
3809 static BOOL run_dirtest1(int dummy)
3812 static struct cli_state *cli;
3814 BOOL correct = True;
3816 printf("starting directory test\n");
3818 if (!torture_open_connection(&cli)) {
3822 cli_sockopt(cli, sockops);
3824 cli_list(cli, "\\LISTDIR\\*", 0, del_fn, cli);
3825 cli_list(cli, "\\LISTDIR\\*", aDIR, del_fn, cli);
3826 cli_rmdir(cli, "\\LISTDIR");
3827 cli_mkdir(cli, "\\LISTDIR");
3829 /* Create 1000 files and 1000 directories. */
3830 for (i=0;i<1000;i++) {
3832 slprintf(fname, sizeof(fname), "\\LISTDIR\\f%d", i);
3833 fnum = cli_nt_create_full(cli, fname, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
3834 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0);
3836 fprintf(stderr,"Failed to open %s\n", fname);
3839 cli_close(cli, fnum);
3841 for (i=0;i<1000;i++) {
3843 slprintf(fname, sizeof(fname), "\\LISTDIR\\d%d", i);
3844 if (!cli_mkdir(cli, fname)) {
3845 fprintf(stderr,"Failed to open %s\n", fname);
3850 /* Now ensure that doing an old list sees both files and directories. */
3851 num_seen = cli_list_old(cli, "\\LISTDIR\\*", aDIR, list_fn, NULL);
3852 printf("num_seen = %d\n", num_seen );
3853 /* We should see 100 files + 1000 directories + . and .. */
3854 if (num_seen != 2002)
3857 /* Ensure if we have the "must have" bits we only see the
3860 num_seen = cli_list_old(cli, "\\LISTDIR\\*", (aDIR<<8)|aDIR, list_fn, NULL);
3861 printf("num_seen = %d\n", num_seen );
3862 if (num_seen != 1002)
3865 num_seen = cli_list_old(cli, "\\LISTDIR\\*", (aARCH<<8)|aDIR, list_fn, NULL);
3866 printf("num_seen = %d\n", num_seen );
3867 if (num_seen != 1000)
3870 /* Delete everything. */
3871 cli_list(cli, "\\LISTDIR\\*", 0, del_fn, cli);
3872 cli_list(cli, "\\LISTDIR\\*", aDIR, del_fn, cli);
3873 cli_rmdir(cli, "\\LISTDIR");
3876 printf("Matched %d\n", cli_list(cli, "a*.*", 0, list_fn, NULL));
3877 printf("Matched %d\n", cli_list(cli, "b*.*", 0, list_fn, NULL));
3878 printf("Matched %d\n", cli_list(cli, "xyzabc", 0, list_fn, NULL));
3881 if (!torture_close_connection(cli)) {
3885 printf("finished dirtest1\n");
3890 static BOOL run_error_map_extract(int dummy) {
3892 static struct cli_state c_dos;
3893 static struct cli_state c_nt;
3897 uint32 flgs2, errnum;
3904 /* NT-Error connection */
3906 if (!open_nbt_connection(&c_nt)) {
3910 c_nt.use_spnego = False;
3912 if (!cli_negprot(&c_nt)) {
3913 printf("%s rejected the NT-error negprot (%s)\n",host, cli_errstr(&c_nt));
3914 cli_shutdown(&c_nt);
3918 if (!cli_session_setup(&c_nt, "", "", 0, "", 0,
3920 printf("%s rejected the NT-error initial session setup (%s)\n",host, cli_errstr(&c_nt));
3924 /* DOS-Error connection */
3926 if (!open_nbt_connection(&c_dos)) {
3930 c_dos.use_spnego = False;
3931 c_dos.force_dos_errors = True;
3933 if (!cli_negprot(&c_dos)) {
3934 printf("%s rejected the DOS-error negprot (%s)\n",host, cli_errstr(&c_dos));
3935 cli_shutdown(&c_dos);
3939 if (!cli_session_setup(&c_dos, "", "", 0, "", 0,
3941 printf("%s rejected the DOS-error initial session setup (%s)\n",host, cli_errstr(&c_dos));
3945 for (error=(0xc0000000 | 0x1); error < (0xc0000000| 0xFFF); error++) {
3946 snprintf(user, sizeof(user), "%X", error);
3948 if (cli_session_setup(&c_nt, user,
3949 password, strlen(password),
3950 password, strlen(password),
3952 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
3955 flgs2 = SVAL(c_nt.inbuf,smb_flg2);
3957 /* Case #1: 32-bit NT errors */
3958 if (flgs2 & FLAGS2_32_BIT_ERROR_CODES) {
3959 nt_status = NT_STATUS(IVAL(c_nt.inbuf,smb_rcls));
3961 printf("/** Dos error on NT connection! (%s) */\n",
3963 nt_status = NT_STATUS(0xc0000000);
3966 if (cli_session_setup(&c_dos, user,
3967 password, strlen(password),
3968 password, strlen(password),
3970 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
3972 flgs2 = SVAL(c_dos.inbuf,smb_flg2), errnum;
3974 /* Case #1: 32-bit NT errors */
3975 if (flgs2 & FLAGS2_32_BIT_ERROR_CODES) {
3976 printf("/** NT error on DOS connection! (%s) */\n",
3978 errnum = errclass = 0;
3980 cli_dos_error(&c_dos, &errclass, &errnum);
3983 if (NT_STATUS_V(nt_status) != error) {
3984 printf("/*\t{ This NT error code was 'sqashed'\n\t from %s to %s \n\t during the session setup }\n*/\n",
3985 get_nt_error_c_code(NT_STATUS(error)),
3986 get_nt_error_c_code(nt_status));
3989 printf("\t{%s,\t%s,\t%s},\n",
3990 smb_dos_err_class(errclass),
3991 smb_dos_err_name(errclass, errnum),
3992 get_nt_error_c_code(NT_STATUS(error)));
3997 static double create_procs(BOOL (*fn)(int), BOOL *result)
4000 volatile pid_t *child_status;
4001 volatile BOOL *child_status_out;
4007 child_status = (volatile pid_t *)shm_setup(sizeof(pid_t)*nprocs);
4008 if (!child_status) {
4009 printf("Failed to setup shared memory\n");
4013 child_status_out = (volatile BOOL *)shm_setup(sizeof(BOOL)*nprocs);
4014 if (!child_status_out) {
4015 printf("Failed to setup result status shared memory\n");
4019 for (i = 0; i < nprocs; i++) {
4020 child_status[i] = 0;
4021 child_status_out[i] = True;
4026 for (i=0;i<nprocs;i++) {
4029 pid_t mypid = getpid();
4030 sys_srandom(((int)mypid) ^ ((int)time(NULL)));
4032 slprintf(myname,sizeof(myname),"CLIENT%d", i);
4035 if (torture_open_connection(¤t_cli)) break;
4037 printf("pid %d failed to start\n", (int)getpid());
4043 child_status[i] = getpid();
4045 while (child_status[i] && end_timer() < 5) msleep(2);
4047 child_status_out[i] = fn(i);
4054 for (i=0;i<nprocs;i++) {
4055 if (child_status[i]) synccount++;
4057 if (synccount == nprocs) break;
4059 } while (end_timer() < 30);
4061 if (synccount != nprocs) {
4062 printf("FAILED TO START %d CLIENTS (started %d)\n", nprocs, synccount);
4067 /* start the client load */
4070 for (i=0;i<nprocs;i++) {
4071 child_status[i] = 0;
4074 printf("%d clients started\n", nprocs);
4076 for (i=0;i<nprocs;i++) {
4077 while (waitpid(0, &status, 0) == -1 && errno == EINTR) /* noop */ ;
4082 for (i=0;i<nprocs;i++) {
4083 if (!child_status_out[i]) {
4090 #define FLAG_MULTIPROC 1
4097 {"FDPASS", run_fdpasstest, 0},
4098 {"LOCK1", run_locktest1, 0},
4099 {"LOCK2", run_locktest2, 0},
4100 {"LOCK3", run_locktest3, 0},
4101 {"LOCK4", run_locktest4, 0},
4102 {"LOCK5", run_locktest5, 0},
4103 {"LOCK6", run_locktest6, 0},
4104 {"LOCK7", run_locktest7, 0},
4105 {"UNLINK", run_unlinktest, 0},
4106 {"BROWSE", run_browsetest, 0},
4107 {"ATTR", run_attrtest, 0},
4108 {"TRANS2", run_trans2test, 0},
4109 {"MAXFID", run_maxfidtest, FLAG_MULTIPROC},
4110 {"TORTURE",run_torture, FLAG_MULTIPROC},
4111 {"RANDOMIPC", run_randomipc, 0},
4112 {"NEGNOWAIT", run_negprot_nowait, 0},
4113 {"NBENCH", run_nbench, 0},
4114 {"OPLOCK1", run_oplock1, 0},
4115 {"OPLOCK2", run_oplock2, 0},
4116 {"OPLOCK3", run_oplock3, 0},
4117 {"DIR", run_dirtest, 0},
4118 {"DIR1", run_dirtest1, 0},
4119 {"DENY1", torture_denytest1, 0},
4120 {"DENY2", torture_denytest2, 0},
4121 {"TCON", run_tcon_test, 0},
4122 {"RW1", run_readwritetest, 0},
4123 {"RW2", run_readwritemulti, FLAG_MULTIPROC},
4124 {"RW3", run_readwritelarge, 0},
4125 {"OPEN", run_opentest, 0},
4127 {"OPENATTR", run_openattrtest, 0},
4129 {"XCOPY", run_xcopy, 0},
4130 {"RENAME", run_rename, 0},
4131 {"DELETE", run_deletetest, 0},
4132 {"PROPERTIES", run_properties, 0},
4133 {"MANGLE", torture_mangle, 0},
4134 {"W2K", run_w2ktest, 0},
4135 {"TRANS2SCAN", torture_trans2_scan, 0},
4136 {"NTTRANSSCAN", torture_nttrans_scan, 0},
4137 {"UTABLE", torture_utable, 0},
4138 {"CASETABLE", torture_casetable, 0},
4139 {"ERRMAPEXTRACT", run_error_map_extract, 0},
4140 {"PIPE_NUMBER", run_pipe_number, 0},
4145 /****************************************************************************
4146 run a specified test or "ALL"
4147 ****************************************************************************/
4148 static BOOL run_test(const char *name)
4154 if (strequal(name,"ALL")) {
4155 for (i=0;torture_ops[i].name;i++) {
4156 run_test(torture_ops[i].name);
4160 for (i=0;torture_ops[i].name;i++) {
4161 snprintf(randomfname, sizeof(randomfname), "\\XX%x",
4162 (unsigned)random());
4164 if (strequal(name, torture_ops[i].name)) {
4165 printf("Running %s\n", name);
4166 if (torture_ops[i].flags & FLAG_MULTIPROC) {
4167 t = create_procs(torture_ops[i].fn, &result);
4170 printf("TEST %s FAILED!\n", name);
4175 if (!torture_ops[i].fn(0)) {
4177 printf("TEST %s FAILED!\n", name);
4181 printf("%s took %g secs\n\n", name, t);
4188 static void usage(void)
4192 printf("Usage: smbtorture //server/share <options> TEST1 TEST2 ...\n");
4194 printf("\t-d debuglevel\n");
4195 printf("\t-U user%%pass\n");
4196 printf("\t-k use kerberos\n");
4197 printf("\t-N numprocs\n");
4198 printf("\t-n my_netbios_name\n");
4199 printf("\t-W workgroup\n");
4200 printf("\t-o num_operations\n");
4201 printf("\t-O socket_options\n");
4202 printf("\t-m maximum protocol\n");
4203 printf("\t-L use oplocks\n");
4204 printf("\t-c CLIENT.TXT specify client load file for NBENCH\n");
4205 printf("\t-A showall\n");
4206 printf("\t-p port\n");
4207 printf("\t-s seed\n");
4210 printf("tests are:");
4211 for (i=0;torture_ops[i].name;i++) {
4212 printf(" %s", torture_ops[i].name);
4216 printf("default test is ALL\n");
4221 /****************************************************************************
4223 ****************************************************************************/
4224 int main(int argc,char *argv[])
4230 extern char *optarg;
4232 BOOL correct = True;
4236 #ifdef HAVE_SETBUFFER
4237 setbuffer(stdout, NULL, 0);
4240 lp_load(dyn_CONFIGFILE,True,False,False);
4247 for(p = argv[1]; *p; p++)
4251 if (strncmp(argv[1], "//", 2)) {
4255 fstrcpy(host, &argv[1][2]);
4256 p = strchr_m(&host[2],'/');
4261 fstrcpy(share, p+1);
4265 if (*username == 0 && getenv("LOGNAME")) {
4266 fstrcpy(username,getenv("LOGNAME"));
4272 srandom(time(NULL));
4274 fstrcpy(workgroup, lp_workgroup());
4276 while ((opt = getopt(argc, argv, "p:hW:U:n:N:O:o:m:Ld:Ac:ks:")) != EOF) {
4279 port_to_use = atoi(optarg);
4282 srandom(atoi(optarg));
4285 fstrcpy(workgroup,optarg);
4288 max_protocol = interpret_protocol(optarg, max_protocol);
4291 nprocs = atoi(optarg);
4294 torture_numops = atoi(optarg);
4297 DEBUGLEVEL = atoi(optarg);
4306 torture_showall = True;
4309 fstrcpy(myname, optarg);
4312 client_txt = optarg;
4316 use_kerberos = True;
4318 d_printf("No kerberos support compiled in\n");
4324 fstrcpy(username,optarg);
4325 p = strchr_m(username,'%');
4328 fstrcpy(password, p+1);
4333 printf("Unknown option %c (%d)\n", (char)opt, opt);
4338 if(use_kerberos && !gotuser) gotpass = True;
4341 p = getpass("Password:");
4343 fstrcpy(password, p);
4348 printf("host=%s share=%s user=%s myname=%s\n",
4349 host, share, username, myname);
4352 correct = run_test("ALL");
4354 for (i=1;i<argc;i++) {
4355 if (!run_test(argv[i])) {