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 this checks to see if a secondary tconx can use open files from an
908 static BOOL run_tcon_test(int dummy)
910 static struct cli_state *cli;
911 const char *fname = "\\tcontest.tmp";
913 uint16 cnum1, cnum2, cnum3;
918 if (!torture_open_connection(&cli)) {
921 cli_sockopt(cli, sockops);
923 printf("starting tcontest\n");
925 cli_unlink(cli, fname);
927 fnum1 = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
929 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
936 if (cli_write(cli, fnum1, 0, buf, 130, 4) != 4) {
937 printf("initial write failed (%s)", cli_errstr(cli));
941 if (!cli_send_tconX(cli, share, "?????",
942 password, strlen(password)+1)) {
943 printf("%s refused 2nd tree connect (%s)\n", host,
950 cnum3 = MAX(cnum1, cnum2) + 1; /* any invalid number */
951 vuid2 = cli->vuid + 1;
953 /* try a write with the wrong tid */
956 if (cli_write(cli, fnum1, 0, buf, 130, 4) == 4) {
957 printf("server allows write with wrong TID\n");
959 printf("* server fails write with wrong TID : %s\n", cli_errstr(cli));
964 /* try a write with an invalid tid */
967 if (cli_write(cli, fnum1, 0, buf, 130, 4) == 4) {
968 printf("server allows write with invalid TID\n");
970 printf("* server fails write with invalid TID : %s\n", cli_errstr(cli));
974 /* try a write with an invalid vuid */
978 if (cli_write(cli, fnum1, 0, buf, 130, 4) == 4) {
979 printf("server allows write with invalid VUID\n");
981 printf("* server fails write with invalid VUID : %s\n", cli_errstr(cli));
988 if (!cli_close(cli, fnum1)) {
989 printf("close failed (%s)\n", cli_errstr(cli));
995 if (!cli_tdis(cli)) {
996 printf("secondary tdis failed (%s)\n", cli_errstr(cli));
1002 if (!torture_close_connection(cli)) {
1011 checks for old style tcon support
1013 static BOOL run_tcon2_test(int dummy)
1015 static struct cli_state *cli;
1016 uint16 cnum, max_xmit;
1020 if (!torture_open_connection(&cli)) {
1023 cli_sockopt(cli, sockops);
1025 printf("starting tcon2 test\n");
1027 asprintf(&service, "\\\\%s\\%s", host, share);
1029 status = cli_raw_tcon(cli, service, password, "?????", &max_xmit, &cnum);
1031 if (!NT_STATUS_IS_OK(status)) {
1032 printf("tcon2 failed : %s\n", cli_errstr(cli));
1034 printf("tcon OK : max_xmit=%d cnum=%d tid=%d\n",
1035 (int)max_xmit, (int)cnum, SVAL(cli->inbuf, smb_tid));
1038 if (!torture_close_connection(cli)) {
1042 printf("Passed tcon2 test\n");
1048 This test checks that
1050 1) the server supports multiple locking contexts on the one SMB
1051 connection, distinguished by PID.
1053 2) the server correctly fails overlapping locks made by the same PID (this
1054 goes against POSIX behaviour, which is why it is tricky to implement)
1056 3) the server denies unlock requests by an incorrect client PID
1058 static BOOL run_locktest2(int dummy)
1060 static struct cli_state *cli;
1061 const char *fname = "\\lockt2.lck";
1062 int fnum1, fnum2, fnum3;
1063 BOOL correct = True;
1065 if (!torture_open_connection(&cli)) {
1069 cli_sockopt(cli, sockops);
1071 printf("starting locktest2\n");
1073 cli_unlink(cli, fname);
1077 fnum1 = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1079 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
1083 fnum2 = cli_open(cli, fname, O_RDWR, DENY_NONE);
1085 printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli));
1091 fnum3 = cli_open(cli, fname, O_RDWR, DENY_NONE);
1093 printf("open3 of %s failed (%s)\n", fname, cli_errstr(cli));
1099 if (!cli_lock(cli, fnum1, 0, 4, 0, WRITE_LOCK)) {
1100 printf("lock1 failed (%s)\n", cli_errstr(cli));
1104 if (cli_lock(cli, fnum1, 0, 4, 0, WRITE_LOCK)) {
1105 printf("WRITE lock1 succeeded! This is a locking bug\n");
1108 if (!check_error(__LINE__, cli, ERRDOS, ERRlock,
1109 NT_STATUS_LOCK_NOT_GRANTED)) return False;
1112 if (cli_lock(cli, fnum2, 0, 4, 0, WRITE_LOCK)) {
1113 printf("WRITE lock2 succeeded! This is a locking bug\n");
1116 if (!check_error(__LINE__, cli, ERRDOS, ERRlock,
1117 NT_STATUS_LOCK_NOT_GRANTED)) return False;
1120 if (cli_lock(cli, fnum2, 0, 4, 0, READ_LOCK)) {
1121 printf("READ lock2 succeeded! This is a locking bug\n");
1124 if (!check_error(__LINE__, cli, ERRDOS, ERRlock,
1125 NT_STATUS_FILE_LOCK_CONFLICT)) return False;
1128 if (!cli_lock(cli, fnum1, 100, 4, 0, WRITE_LOCK)) {
1129 printf("lock at 100 failed (%s)\n", cli_errstr(cli));
1132 if (cli_unlock(cli, fnum1, 100, 4)) {
1133 printf("unlock at 100 succeeded! This is a locking bug\n");
1137 if (cli_unlock(cli, fnum1, 0, 4)) {
1138 printf("unlock1 succeeded! This is a locking bug\n");
1141 if (!check_error(__LINE__, cli,
1143 NT_STATUS_RANGE_NOT_LOCKED)) return False;
1146 if (cli_unlock(cli, fnum1, 0, 8)) {
1147 printf("unlock2 succeeded! This is a locking bug\n");
1150 if (!check_error(__LINE__, cli,
1152 NT_STATUS_RANGE_NOT_LOCKED)) return False;
1155 if (cli_lock(cli, fnum3, 0, 4, 0, WRITE_LOCK)) {
1156 printf("lock3 succeeded! This is a locking bug\n");
1159 if (!check_error(__LINE__, cli, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False;
1164 if (!cli_close(cli, fnum1)) {
1165 printf("close1 failed (%s)\n", cli_errstr(cli));
1169 if (!cli_close(cli, fnum2)) {
1170 printf("close2 failed (%s)\n", cli_errstr(cli));
1174 if (!cli_close(cli, fnum3)) {
1175 printf("close3 failed (%s)\n", cli_errstr(cli));
1179 if (!torture_close_connection(cli)) {
1183 printf("locktest2 finished\n");
1190 This test checks that
1192 1) the server supports the full offset range in lock requests
1194 static BOOL run_locktest3(int dummy)
1196 static struct cli_state *cli1, *cli2;
1197 const char *fname = "\\lockt3.lck";
1198 int fnum1, fnum2, i;
1200 BOOL correct = True;
1202 #define NEXT_OFFSET offset += (~(uint32)0) / torture_numops
1204 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
1207 cli_sockopt(cli1, sockops);
1208 cli_sockopt(cli2, sockops);
1210 printf("starting locktest3\n");
1212 cli_unlink(cli1, fname);
1214 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1216 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
1219 fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
1221 printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli2));
1225 for (offset=i=0;i<torture_numops;i++) {
1227 if (!cli_lock(cli1, fnum1, offset-1, 1, 0, WRITE_LOCK)) {
1228 printf("lock1 %d failed (%s)\n",
1234 if (!cli_lock(cli2, fnum2, offset-2, 1, 0, WRITE_LOCK)) {
1235 printf("lock2 %d failed (%s)\n",
1242 for (offset=i=0;i<torture_numops;i++) {
1245 if (cli_lock(cli1, fnum1, offset-2, 1, 0, WRITE_LOCK)) {
1246 printf("error: lock1 %d succeeded!\n", i);
1250 if (cli_lock(cli2, fnum2, offset-1, 1, 0, WRITE_LOCK)) {
1251 printf("error: lock2 %d succeeded!\n", i);
1255 if (cli_lock(cli1, fnum1, offset-1, 1, 0, WRITE_LOCK)) {
1256 printf("error: lock3 %d succeeded!\n", i);
1260 if (cli_lock(cli2, fnum2, offset-2, 1, 0, WRITE_LOCK)) {
1261 printf("error: lock4 %d succeeded!\n", i);
1266 for (offset=i=0;i<torture_numops;i++) {
1269 if (!cli_unlock(cli1, fnum1, offset-1, 1)) {
1270 printf("unlock1 %d failed (%s)\n",
1276 if (!cli_unlock(cli2, fnum2, offset-2, 1)) {
1277 printf("unlock2 %d failed (%s)\n",
1284 if (!cli_close(cli1, fnum1)) {
1285 printf("close1 failed (%s)\n", cli_errstr(cli1));
1289 if (!cli_close(cli2, fnum2)) {
1290 printf("close2 failed (%s)\n", cli_errstr(cli2));
1294 if (!cli_unlink(cli1, fname)) {
1295 printf("unlink failed (%s)\n", cli_errstr(cli1));
1299 if (!torture_close_connection(cli1)) {
1303 if (!torture_close_connection(cli2)) {
1307 printf("finished locktest3\n");
1312 #define EXPECTED(ret, v) if ((ret) != (v)) { \
1313 printf("** "); correct = False; \
1317 looks at overlapping locks
1319 static BOOL run_locktest4(int dummy)
1321 static struct cli_state *cli1, *cli2;
1322 const char *fname = "\\lockt4.lck";
1323 int fnum1, fnum2, f;
1326 BOOL correct = True;
1328 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
1332 cli_sockopt(cli1, sockops);
1333 cli_sockopt(cli2, sockops);
1335 printf("starting locktest4\n");
1337 cli_unlink(cli1, fname);
1339 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1340 fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
1342 memset(buf, 0, sizeof(buf));
1344 if (cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
1345 printf("Failed to create file\n");
1350 ret = cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK) &&
1351 cli_lock(cli1, fnum1, 2, 4, 0, WRITE_LOCK);
1352 EXPECTED(ret, False);
1353 printf("the same process %s set overlapping write locks\n", ret?"can":"cannot");
1355 ret = cli_lock(cli1, fnum1, 10, 4, 0, READ_LOCK) &&
1356 cli_lock(cli1, fnum1, 12, 4, 0, READ_LOCK);
1357 EXPECTED(ret, True);
1358 printf("the same process %s set overlapping read locks\n", ret?"can":"cannot");
1360 ret = cli_lock(cli1, fnum1, 20, 4, 0, WRITE_LOCK) &&
1361 cli_lock(cli2, fnum2, 22, 4, 0, WRITE_LOCK);
1362 EXPECTED(ret, False);
1363 printf("a different connection %s set overlapping write locks\n", ret?"can":"cannot");
1365 ret = cli_lock(cli1, fnum1, 30, 4, 0, READ_LOCK) &&
1366 cli_lock(cli2, fnum2, 32, 4, 0, READ_LOCK);
1367 EXPECTED(ret, True);
1368 printf("a different connection %s set overlapping read locks\n", ret?"can":"cannot");
1370 ret = (cli_setpid(cli1, 1), cli_lock(cli1, fnum1, 40, 4, 0, WRITE_LOCK)) &&
1371 (cli_setpid(cli1, 2), cli_lock(cli1, fnum1, 42, 4, 0, WRITE_LOCK));
1372 EXPECTED(ret, False);
1373 printf("a different pid %s set overlapping write locks\n", ret?"can":"cannot");
1375 ret = (cli_setpid(cli1, 1), cli_lock(cli1, fnum1, 50, 4, 0, READ_LOCK)) &&
1376 (cli_setpid(cli1, 2), cli_lock(cli1, fnum1, 52, 4, 0, READ_LOCK));
1377 EXPECTED(ret, True);
1378 printf("a different pid %s set overlapping read locks\n", ret?"can":"cannot");
1380 ret = cli_lock(cli1, fnum1, 60, 4, 0, READ_LOCK) &&
1381 cli_lock(cli1, fnum1, 60, 4, 0, READ_LOCK);
1382 EXPECTED(ret, True);
1383 printf("the same process %s set the same read lock twice\n", ret?"can":"cannot");
1385 ret = cli_lock(cli1, fnum1, 70, 4, 0, WRITE_LOCK) &&
1386 cli_lock(cli1, fnum1, 70, 4, 0, WRITE_LOCK);
1387 EXPECTED(ret, False);
1388 printf("the same process %s set the same write lock twice\n", ret?"can":"cannot");
1390 ret = cli_lock(cli1, fnum1, 80, 4, 0, READ_LOCK) &&
1391 cli_lock(cli1, fnum1, 80, 4, 0, WRITE_LOCK);
1392 EXPECTED(ret, False);
1393 printf("the same process %s overlay a read lock with a write lock\n", ret?"can":"cannot");
1395 ret = cli_lock(cli1, fnum1, 90, 4, 0, WRITE_LOCK) &&
1396 cli_lock(cli1, fnum1, 90, 4, 0, READ_LOCK);
1397 EXPECTED(ret, True);
1398 printf("the same process %s overlay a write lock with a read lock\n", ret?"can":"cannot");
1400 ret = (cli_setpid(cli1, 1), cli_lock(cli1, fnum1, 100, 4, 0, WRITE_LOCK)) &&
1401 (cli_setpid(cli1, 2), cli_lock(cli1, fnum1, 100, 4, 0, READ_LOCK));
1402 EXPECTED(ret, False);
1403 printf("a different pid %s overlay a write lock with a read lock\n", ret?"can":"cannot");
1405 ret = cli_lock(cli1, fnum1, 110, 4, 0, READ_LOCK) &&
1406 cli_lock(cli1, fnum1, 112, 4, 0, READ_LOCK) &&
1407 cli_unlock(cli1, fnum1, 110, 6);
1408 EXPECTED(ret, False);
1409 printf("the same process %s coalesce read locks\n", ret?"can":"cannot");
1412 ret = cli_lock(cli1, fnum1, 120, 4, 0, WRITE_LOCK) &&
1413 (cli_read(cli2, fnum2, buf, 120, 4) == 4);
1414 EXPECTED(ret, False);
1415 printf("this server %s strict write locking\n", ret?"doesn't do":"does");
1417 ret = cli_lock(cli1, fnum1, 130, 4, 0, READ_LOCK) &&
1418 (cli_write(cli2, fnum2, 0, buf, 130, 4) == 4);
1419 EXPECTED(ret, False);
1420 printf("this server %s strict read locking\n", ret?"doesn't do":"does");
1423 ret = cli_lock(cli1, fnum1, 140, 4, 0, READ_LOCK) &&
1424 cli_lock(cli1, fnum1, 140, 4, 0, READ_LOCK) &&
1425 cli_unlock(cli1, fnum1, 140, 4) &&
1426 cli_unlock(cli1, fnum1, 140, 4);
1427 EXPECTED(ret, True);
1428 printf("this server %s do recursive read locking\n", ret?"does":"doesn't");
1431 ret = cli_lock(cli1, fnum1, 150, 4, 0, WRITE_LOCK) &&
1432 cli_lock(cli1, fnum1, 150, 4, 0, READ_LOCK) &&
1433 cli_unlock(cli1, fnum1, 150, 4) &&
1434 (cli_read(cli2, fnum2, buf, 150, 4) == 4) &&
1435 !(cli_write(cli2, fnum2, 0, buf, 150, 4) == 4) &&
1436 cli_unlock(cli1, fnum1, 150, 4);
1437 EXPECTED(ret, True);
1438 printf("this server %s do recursive lock overlays\n", ret?"does":"doesn't");
1440 ret = cli_lock(cli1, fnum1, 160, 4, 0, READ_LOCK) &&
1441 cli_unlock(cli1, fnum1, 160, 4) &&
1442 (cli_write(cli2, fnum2, 0, buf, 160, 4) == 4) &&
1443 (cli_read(cli2, fnum2, buf, 160, 4) == 4);
1444 EXPECTED(ret, True);
1445 printf("the same process %s remove a read lock using write locking\n", ret?"can":"cannot");
1447 ret = cli_lock(cli1, fnum1, 170, 4, 0, WRITE_LOCK) &&
1448 cli_unlock(cli1, fnum1, 170, 4) &&
1449 (cli_write(cli2, fnum2, 0, buf, 170, 4) == 4) &&
1450 (cli_read(cli2, fnum2, buf, 170, 4) == 4);
1451 EXPECTED(ret, True);
1452 printf("the same process %s remove a write lock using read locking\n", ret?"can":"cannot");
1454 ret = cli_lock(cli1, fnum1, 190, 4, 0, WRITE_LOCK) &&
1455 cli_lock(cli1, fnum1, 190, 4, 0, READ_LOCK) &&
1456 cli_unlock(cli1, fnum1, 190, 4) &&
1457 !(cli_write(cli2, fnum2, 0, buf, 190, 4) == 4) &&
1458 (cli_read(cli2, fnum2, buf, 190, 4) == 4);
1459 EXPECTED(ret, True);
1460 printf("the same process %s remove the first lock first\n", ret?"does":"doesn't");
1462 cli_close(cli1, fnum1);
1463 cli_close(cli2, fnum2);
1464 fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1465 f = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1466 ret = cli_lock(cli1, fnum1, 0, 8, 0, READ_LOCK) &&
1467 cli_lock(cli1, f, 0, 1, 0, READ_LOCK) &&
1468 cli_close(cli1, fnum1) &&
1469 ((fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE)) != -1) &&
1470 cli_lock(cli1, fnum1, 7, 1, 0, WRITE_LOCK);
1472 cli_close(cli1, fnum1);
1473 EXPECTED(ret, True);
1474 printf("the server %s have the NT byte range lock bug\n", !ret?"does":"doesn't");
1477 cli_close(cli1, fnum1);
1478 cli_close(cli2, fnum2);
1479 cli_unlink(cli1, fname);
1480 torture_close_connection(cli1);
1481 torture_close_connection(cli2);
1483 printf("finished locktest4\n");
1488 looks at lock upgrade/downgrade.
1490 static BOOL run_locktest5(int dummy)
1492 static struct cli_state *cli1, *cli2;
1493 const char *fname = "\\lockt5.lck";
1494 int fnum1, fnum2, fnum3;
1497 BOOL correct = True;
1499 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
1503 cli_sockopt(cli1, sockops);
1504 cli_sockopt(cli2, sockops);
1506 printf("starting locktest5\n");
1508 cli_unlink(cli1, fname);
1510 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1511 fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
1512 fnum3 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1514 memset(buf, 0, sizeof(buf));
1516 if (cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
1517 printf("Failed to create file\n");
1522 /* Check for NT bug... */
1523 ret = cli_lock(cli1, fnum1, 0, 8, 0, READ_LOCK) &&
1524 cli_lock(cli1, fnum3, 0, 1, 0, READ_LOCK);
1525 cli_close(cli1, fnum1);
1526 fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1527 ret = cli_lock(cli1, fnum1, 7, 1, 0, WRITE_LOCK);
1528 EXPECTED(ret, True);
1529 printf("this server %s the NT locking bug\n", ret ? "doesn't have" : "has");
1530 cli_close(cli1, fnum1);
1531 fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1532 cli_unlock(cli1, fnum3, 0, 1);
1534 ret = cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK) &&
1535 cli_lock(cli1, fnum1, 1, 1, 0, READ_LOCK);
1536 EXPECTED(ret, True);
1537 printf("the same process %s overlay a write with a read lock\n", ret?"can":"cannot");
1539 ret = cli_lock(cli2, fnum2, 0, 4, 0, READ_LOCK);
1540 EXPECTED(ret, False);
1542 printf("a different processs %s get a read lock on the first process lock stack\n", ret?"can":"cannot");
1544 /* Unlock the process 2 lock. */
1545 cli_unlock(cli2, fnum2, 0, 4);
1547 ret = cli_lock(cli1, fnum3, 0, 4, 0, READ_LOCK);
1548 EXPECTED(ret, False);
1550 printf("the same processs on a different fnum %s get a read lock\n", ret?"can":"cannot");
1552 /* Unlock the process 1 fnum3 lock. */
1553 cli_unlock(cli1, fnum3, 0, 4);
1555 /* Stack 2 more locks here. */
1556 ret = cli_lock(cli1, fnum1, 0, 4, 0, READ_LOCK) &&
1557 cli_lock(cli1, fnum1, 0, 4, 0, READ_LOCK);
1559 EXPECTED(ret, True);
1560 printf("the same process %s stack read locks\n", ret?"can":"cannot");
1562 /* Unlock the first process lock, then check this was the WRITE lock that was
1565 ret = cli_unlock(cli1, fnum1, 0, 4) &&
1566 cli_lock(cli2, fnum2, 0, 4, 0, READ_LOCK);
1568 EXPECTED(ret, True);
1569 printf("the first unlock removes the %s lock\n", ret?"WRITE":"READ");
1571 /* Unlock the process 2 lock. */
1572 cli_unlock(cli2, fnum2, 0, 4);
1574 /* We should have 3 stacked locks here. Ensure we need to do 3 unlocks. */
1576 ret = cli_unlock(cli1, fnum1, 1, 1) &&
1577 cli_unlock(cli1, fnum1, 0, 4) &&
1578 cli_unlock(cli1, fnum1, 0, 4);
1580 EXPECTED(ret, True);
1581 printf("the same process %s unlock the stack of 4 locks\n", ret?"can":"cannot");
1583 /* Ensure the next unlock fails. */
1584 ret = cli_unlock(cli1, fnum1, 0, 4);
1585 EXPECTED(ret, False);
1586 printf("the same process %s count the lock stack\n", !ret?"can":"cannot");
1588 /* Ensure connection 2 can get a write lock. */
1589 ret = cli_lock(cli2, fnum2, 0, 4, 0, WRITE_LOCK);
1590 EXPECTED(ret, True);
1592 printf("a different processs %s get a write lock on the unlocked stack\n", ret?"can":"cannot");
1596 cli_close(cli1, fnum1);
1597 cli_close(cli2, fnum2);
1598 cli_unlink(cli1, fname);
1599 if (!torture_close_connection(cli1)) {
1602 if (!torture_close_connection(cli2)) {
1606 printf("finished locktest5\n");
1612 tries the unusual lockingX locktype bits
1614 static BOOL run_locktest6(int dummy)
1616 static struct cli_state *cli;
1617 const char *fname[1] = { "\\lock6.txt" };
1622 if (!torture_open_connection(&cli)) {
1626 cli_sockopt(cli, sockops);
1628 printf("starting locktest6\n");
1631 printf("Testing %s\n", fname[i]);
1633 cli_unlink(cli, fname[i]);
1635 fnum = cli_open(cli, fname[i], O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1636 status = cli_locktype(cli, fnum, 0, 8, 0, LOCKING_ANDX_CHANGE_LOCKTYPE);
1637 cli_close(cli, fnum);
1638 printf("CHANGE_LOCKTYPE gave %s\n", nt_errstr(status));
1640 fnum = cli_open(cli, fname[i], O_RDWR, DENY_NONE);
1641 status = cli_locktype(cli, fnum, 0, 8, 0, LOCKING_ANDX_CANCEL_LOCK);
1642 cli_close(cli, fnum);
1643 printf("CANCEL_LOCK gave %s\n", nt_errstr(status));
1645 cli_unlink(cli, fname[i]);
1648 torture_close_connection(cli);
1650 printf("finished locktest6\n");
1654 static BOOL run_locktest7(int dummy)
1656 struct cli_state *cli1;
1657 const char *fname = "\\lockt7.lck";
1660 BOOL correct = False;
1662 if (!torture_open_connection(&cli1)) {
1666 cli_sockopt(cli1, sockops);
1668 printf("starting locktest7\n");
1670 cli_unlink(cli1, fname);
1672 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1674 memset(buf, 0, sizeof(buf));
1676 if (cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
1677 printf("Failed to create file\n");
1681 cli_setpid(cli1, 1);
1683 if (!cli_lock(cli1, fnum1, 130, 4, 0, READ_LOCK)) {
1684 printf("Unable to apply read lock on range 130:4, error was %s\n", cli_errstr(cli1));
1687 printf("pid1 successfully locked range 130:4 for READ\n");
1690 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
1691 printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
1694 printf("pid1 successfully read the range 130:4\n");
1697 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
1698 printf("pid1 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
1699 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
1700 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
1704 printf("pid1 successfully wrote to the range 130:4 (should be denied)\n");
1708 cli_setpid(cli1, 2);
1710 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
1711 printf("pid2 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
1713 printf("pid2 successfully read the range 130:4\n");
1716 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
1717 printf("pid2 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
1718 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
1719 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
1723 printf("pid2 successfully wrote to the range 130:4 (should be denied)\n");
1727 cli_setpid(cli1, 1);
1728 cli_unlock(cli1, fnum1, 130, 4);
1730 if (!cli_lock(cli1, fnum1, 130, 4, 0, WRITE_LOCK)) {
1731 printf("Unable to apply write lock on range 130:4, error was %s\n", cli_errstr(cli1));
1734 printf("pid1 successfully locked range 130:4 for WRITE\n");
1737 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
1738 printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
1741 printf("pid1 successfully read the range 130:4\n");
1744 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
1745 printf("pid1 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
1748 printf("pid1 successfully wrote to the range 130:4\n");
1751 cli_setpid(cli1, 2);
1753 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
1754 printf("pid2 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
1755 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
1756 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
1760 printf("pid2 successfully read the range 130:4 (should be denied)\n");
1764 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
1765 printf("pid2 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
1766 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
1767 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
1771 printf("pid2 successfully wrote to the range 130:4 (should be denied)\n");
1775 cli_unlock(cli1, fnum1, 130, 0);
1779 cli_close(cli1, fnum1);
1780 cli_unlink(cli1, fname);
1781 torture_close_connection(cli1);
1783 printf("finished locktest7\n");
1788 test whether fnums and tids open on one VC are available on another (a major
1791 static BOOL run_fdpasstest(int dummy)
1793 struct cli_state *cli1, *cli2;
1794 const char *fname = "\\fdpass.tst";
1798 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
1801 cli_sockopt(cli1, sockops);
1802 cli_sockopt(cli2, sockops);
1804 printf("starting fdpasstest\n");
1806 cli_unlink(cli1, fname);
1808 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1810 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
1814 if (cli_write(cli1, fnum1, 0, "hello world\n", 0, 13) != 13) {
1815 printf("write failed (%s)\n", cli_errstr(cli1));
1819 cli2->vuid = cli1->vuid;
1820 cli2->cnum = cli1->cnum;
1821 cli2->pid = cli1->pid;
1823 if (cli_read(cli2, fnum1, buf, 0, 13) == 13) {
1824 printf("read succeeded! nasty security hole [%s]\n",
1829 cli_close(cli1, fnum1);
1830 cli_unlink(cli1, fname);
1832 torture_close_connection(cli1);
1833 torture_close_connection(cli2);
1835 printf("finished fdpasstest\n");
1841 This test checks that
1843 1) the server does not allow an unlink on a file that is open
1845 static BOOL run_unlinktest(int dummy)
1847 struct cli_state *cli;
1848 const char *fname = "\\unlink.tst";
1850 BOOL correct = True;
1852 if (!torture_open_connection(&cli)) {
1856 cli_sockopt(cli, sockops);
1858 printf("starting unlink test\n");
1860 cli_unlink(cli, fname);
1864 fnum = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1866 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
1870 if (cli_unlink(cli, fname)) {
1871 printf("error: server allowed unlink on an open file\n");
1874 correct = check_error(__LINE__, cli, ERRDOS, ERRbadshare,
1875 NT_STATUS_SHARING_VIOLATION);
1878 cli_close(cli, fnum);
1879 cli_unlink(cli, fname);
1881 if (!torture_close_connection(cli)) {
1885 printf("unlink test finished\n");
1892 test how many open files this server supports on the one socket
1894 static BOOL run_maxfidtest(int dummy)
1896 struct cli_state *cli;
1897 const char *template = "\\maxfid.%d.%d";
1899 int fnums[0x11000], i;
1901 BOOL correct = True;
1906 printf("failed to connect\n");
1910 cli_sockopt(cli, sockops);
1912 for (i=0; i<0x11000; i++) {
1913 slprintf(fname,sizeof(fname)-1,template, i,(int)getpid());
1914 if ((fnums[i] = cli_open(cli, fname,
1915 O_RDWR|O_CREAT|O_TRUNC, DENY_NONE)) ==
1917 printf("open of %s failed (%s)\n",
1918 fname, cli_errstr(cli));
1919 printf("maximum fnum is %d\n", i);
1927 printf("cleaning up\n");
1929 slprintf(fname,sizeof(fname)-1,template, i,(int)getpid());
1930 cli_close(cli, fnums[i]);
1931 if (!cli_unlink(cli, fname)) {
1932 printf("unlink of %s failed (%s)\n",
1933 fname, cli_errstr(cli));
1940 printf("maxfid test finished\n");
1941 if (!torture_close_connection(cli)) {
1947 /* generate a random buffer */
1948 static void rand_buf(char *buf, int len)
1951 *buf = (char)sys_random();
1956 /* send smb negprot commands, not reading the response */
1957 static BOOL run_negprot_nowait(int dummy)
1960 static struct cli_state cli;
1961 BOOL correct = True;
1963 printf("starting negprot nowait test\n");
1965 if (!open_nbt_connection(&cli)) {
1969 for (i=0;i<50000;i++) {
1970 cli_negprot_send(&cli);
1973 if (!torture_close_connection(&cli)) {
1977 printf("finished negprot nowait test\n");
1983 /* send random IPC commands */
1984 static BOOL run_randomipc(int dummy)
1986 char *rparam = NULL;
1990 int api, param_len, i;
1991 struct cli_state *cli;
1992 BOOL correct = True;
1995 printf("starting random ipc test\n");
1997 if (!torture_open_connection(&cli)) {
2001 for (i=0;i<count;i++) {
2002 api = sys_random() % 500;
2003 param_len = (sys_random() % 64);
2005 rand_buf(param, param_len);
2010 param, param_len, 8,
2011 NULL, 0, BUFFER_SIZE,
2015 printf("%d/%d\r", i,count);
2018 printf("%d/%d\n", i, count);
2020 if (!torture_close_connection(cli)) {
2024 printf("finished random ipc test\n");
2031 static void browse_callback(const char *sname, uint32 stype,
2032 const char *comment, void *state)
2034 printf("\t%20.20s %08x %s\n", sname, stype, comment);
2040 This test checks the browse list code
2043 static BOOL run_browsetest(int dummy)
2045 static struct cli_state *cli;
2046 BOOL correct = True;
2048 printf("starting browse test\n");
2050 if (!torture_open_connection(&cli)) {
2054 printf("domain list:\n");
2055 cli_NetServerEnum(cli, cli->server_domain,
2056 SV_TYPE_DOMAIN_ENUM,
2057 browse_callback, NULL);
2059 printf("machine list:\n");
2060 cli_NetServerEnum(cli, cli->server_domain,
2062 browse_callback, NULL);
2064 if (!torture_close_connection(cli)) {
2068 printf("browse test finished\n");
2076 This checks how the getatr calls works
2078 static BOOL run_attrtest(int dummy)
2080 struct cli_state *cli;
2083 const char *fname = "\\attrib.tst";
2084 BOOL correct = True;
2086 printf("starting attrib 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 cli_close(cli, fnum);
2096 if (!cli_getatr(cli, fname, NULL, NULL, &t)) {
2097 printf("getatr failed (%s)\n", cli_errstr(cli));
2101 if (abs(t - time(NULL)) > 60*60*24*10) {
2102 printf("ERROR: SMBgetatr bug. time is %s",
2108 t2 = t-60*60*24; /* 1 day ago */
2110 if (!cli_setatr(cli, fname, 0, t2)) {
2111 printf("setatr failed (%s)\n", cli_errstr(cli));
2115 if (!cli_getatr(cli, fname, NULL, NULL, &t)) {
2116 printf("getatr failed (%s)\n", cli_errstr(cli));
2121 printf("ERROR: getatr/setatr bug. times are\n%s",
2123 printf("%s", ctime(&t2));
2127 cli_unlink(cli, fname);
2129 if (!torture_close_connection(cli)) {
2133 printf("attrib test finished\n");
2140 This checks a couple of trans2 calls
2142 static BOOL run_trans2test(int dummy)
2144 struct cli_state *cli;
2147 time_t c_time, a_time, m_time, w_time, m_time2;
2148 const char *fname = "\\trans2.tst";
2149 const char *dname = "\\trans2";
2150 const char *fname2 = "\\trans2\\trans2.tst";
2152 BOOL correct = True;
2154 printf("starting trans2 test\n");
2156 if (!torture_open_connection(&cli)) {
2160 cli_unlink(cli, fname);
2161 fnum = cli_open(cli, fname,
2162 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2163 if (!cli_qfileinfo(cli, fnum, NULL, &size, &c_time, &a_time, &m_time,
2165 printf("ERROR: qfileinfo failed (%s)\n", cli_errstr(cli));
2169 if (!cli_qfilename(cli, fnum, pname)) {
2170 printf("ERROR: qfilename failed (%s)\n", cli_errstr(cli));
2174 if (strcmp(pname, fname)) {
2175 printf("qfilename gave different name? [%s] [%s]\n",
2180 cli_close(cli, fnum);
2184 cli_unlink(cli, fname);
2185 fnum = cli_open(cli, fname,
2186 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2188 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
2191 cli_close(cli, fnum);
2193 if (!cli_qpathinfo(cli, fname, &c_time, &a_time, &m_time, &size, NULL)) {
2194 printf("ERROR: qpathinfo failed (%s)\n", cli_errstr(cli));
2197 if (c_time != m_time) {
2198 printf("create time=%s", ctime(&c_time));
2199 printf("modify time=%s", ctime(&m_time));
2200 printf("This system appears to have sticky create times\n");
2202 if (a_time % (60*60) == 0) {
2203 printf("access time=%s", ctime(&a_time));
2204 printf("This system appears to set a midnight access time\n");
2208 if (abs(m_time - time(NULL)) > 60*60*24*7) {
2209 printf("ERROR: totally incorrect times - maybe word reversed? mtime=%s", ctime(&m_time));
2215 cli_unlink(cli, fname);
2216 fnum = cli_open(cli, fname,
2217 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2218 cli_close(cli, fnum);
2219 if (!cli_qpathinfo2(cli, fname, &c_time, &a_time, &m_time,
2220 &w_time, &size, NULL, NULL)) {
2221 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli));
2224 if (w_time < 60*60*24*2) {
2225 printf("write time=%s", ctime(&w_time));
2226 printf("This system appears to set a initial 0 write time\n");
2231 cli_unlink(cli, fname);
2234 /* check if the server updates the directory modification time
2235 when creating a new file */
2236 if (!cli_mkdir(cli, dname)) {
2237 printf("ERROR: mkdir failed (%s)\n", cli_errstr(cli));
2241 if (!cli_qpathinfo2(cli, "\\trans2\\", &c_time, &a_time, &m_time,
2242 &w_time, &size, NULL, NULL)) {
2243 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli));
2247 fnum = cli_open(cli, fname2,
2248 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2249 cli_write(cli, fnum, 0, (char *)&fnum, 0, sizeof(fnum));
2250 cli_close(cli, fnum);
2251 if (!cli_qpathinfo2(cli, "\\trans2\\", &c_time, &a_time, &m_time2,
2252 &w_time, &size, NULL, NULL)) {
2253 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli));
2256 if (m_time2 == m_time) {
2257 printf("This system does not update directory modification times\n");
2261 cli_unlink(cli, fname2);
2262 cli_rmdir(cli, dname);
2264 if (!torture_close_connection(cli)) {
2268 printf("trans2 test finished\n");
2274 This checks new W2K calls.
2277 static BOOL new_trans(struct cli_state *pcli, int fnum, int level)
2280 BOOL correct = True;
2282 memset(buf, 0xff, sizeof(buf));
2284 if (!cli_qfileinfo_test(pcli, fnum, level, buf)) {
2285 printf("ERROR: qfileinfo (%d) failed (%s)\n", level, cli_errstr(pcli));
2288 printf("qfileinfo: level %d\n", level);
2289 dump_data(0, buf, 256);
2295 static BOOL run_w2ktest(int dummy)
2297 struct cli_state *cli;
2299 const char *fname = "\\w2ktest\\w2k.tst";
2301 BOOL correct = True;
2303 printf("starting w2k test\n");
2305 if (!torture_open_connection(&cli)) {
2309 fnum = cli_open(cli, fname,
2310 O_RDWR | O_CREAT , DENY_NONE);
2312 for (level = 1004; level < 1040; level++) {
2313 new_trans(cli, fnum, level);
2316 cli_close(cli, fnum);
2318 if (!torture_close_connection(cli)) {
2322 printf("w2k test finished\n");
2329 this is a harness for some oplock tests
2331 static BOOL run_oplock1(int dummy)
2333 struct cli_state *cli1;
2334 const char *fname = "\\lockt1.lck";
2336 BOOL correct = True;
2338 printf("starting oplock test 1\n");
2340 if (!torture_open_connection(&cli1)) {
2344 cli_unlink(cli1, fname);
2346 cli_sockopt(cli1, sockops);
2348 cli1->use_oplocks = True;
2350 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2352 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
2356 cli1->use_oplocks = False;
2358 cli_unlink(cli1, fname);
2359 cli_unlink(cli1, fname);
2361 if (!cli_close(cli1, fnum1)) {
2362 printf("close2 failed (%s)\n", cli_errstr(cli1));
2366 if (!cli_unlink(cli1, fname)) {
2367 printf("unlink failed (%s)\n", cli_errstr(cli1));
2371 if (!torture_close_connection(cli1)) {
2375 printf("finished oplock test 1\n");
2380 static BOOL run_oplock2(int dummy)
2382 struct cli_state *cli1, *cli2;
2383 const char *fname = "\\lockt2.lck";
2385 int saved_use_oplocks = use_oplocks;
2387 BOOL correct = True;
2388 volatile BOOL *shared_correct;
2390 shared_correct = (volatile BOOL *)shm_setup(sizeof(BOOL));
2391 *shared_correct = True;
2393 use_level_II_oplocks = True;
2396 printf("starting oplock test 2\n");
2398 if (!torture_open_connection(&cli1)) {
2399 use_level_II_oplocks = False;
2400 use_oplocks = saved_use_oplocks;
2404 cli1->use_oplocks = True;
2405 cli1->use_level_II_oplocks = True;
2407 if (!torture_open_connection(&cli2)) {
2408 use_level_II_oplocks = False;
2409 use_oplocks = saved_use_oplocks;
2413 cli2->use_oplocks = True;
2414 cli2->use_level_II_oplocks = True;
2416 cli_unlink(cli1, fname);
2418 cli_sockopt(cli1, sockops);
2419 cli_sockopt(cli2, sockops);
2421 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2423 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
2427 /* Don't need the globals any more. */
2428 use_level_II_oplocks = False;
2429 use_oplocks = saved_use_oplocks;
2433 fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
2435 printf("second open of %s failed (%s)\n", fname, cli_errstr(cli1));
2436 *shared_correct = False;
2442 if (!cli_close(cli2, fnum2)) {
2443 printf("close2 failed (%s)\n", cli_errstr(cli1));
2444 *shared_correct = False;
2452 /* Ensure cli1 processes the break. */
2454 if (cli_read(cli1, fnum1, buf, 0, 4) != 4) {
2455 printf("read on fnum1 failed (%s)\n", cli_errstr(cli1));
2459 /* Should now be at level II. */
2460 /* Test if sending a write locks causes a break to none. */
2462 if (!cli_lock(cli1, fnum1, 0, 4, 0, READ_LOCK)) {
2463 printf("lock failed (%s)\n", cli_errstr(cli1));
2467 cli_unlock(cli1, fnum1, 0, 4);
2471 if (!cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK)) {
2472 printf("lock failed (%s)\n", cli_errstr(cli1));
2476 cli_unlock(cli1, fnum1, 0, 4);
2480 cli_read(cli1, fnum1, buf, 0, 4);
2483 if (cli_write(cli1, fnum1, 0, buf, 0, 4) != 4) {
2484 printf("write on fnum1 failed (%s)\n", cli_errstr(cli1));
2489 if (!cli_close(cli1, fnum1)) {
2490 printf("close1 failed (%s)\n", cli_errstr(cli1));
2496 if (!cli_unlink(cli1, fname)) {
2497 printf("unlink failed (%s)\n", cli_errstr(cli1));
2501 if (!torture_close_connection(cli1)) {
2505 if (!*shared_correct) {
2509 printf("finished oplock test 2\n");
2514 /* handler for oplock 3 tests */
2515 static BOOL oplock3_handler(struct cli_state *cli, int fnum, unsigned char level)
2517 printf("got oplock break fnum=%d level=%d\n",
2519 return cli_oplock_ack(cli, fnum, level);
2522 static BOOL run_oplock3(int dummy)
2524 struct cli_state *cli;
2525 const char *fname = "\\oplockt3.dat";
2527 char buf[4] = "abcd";
2528 BOOL correct = True;
2529 volatile BOOL *shared_correct;
2531 shared_correct = (volatile BOOL *)shm_setup(sizeof(BOOL));
2532 *shared_correct = True;
2534 printf("starting oplock test 3\n");
2539 use_level_II_oplocks = True;
2540 if (!torture_open_connection(&cli)) {
2541 *shared_correct = False;
2545 /* try to trigger a oplock break in parent */
2546 fnum = cli_open(cli, fname, O_RDWR, DENY_NONE);
2547 cli_write(cli, fnum, 0, buf, 0, 4);
2553 use_level_II_oplocks = True;
2554 if (!torture_open_connection(&cli)) {
2557 cli_oplock_handler(cli, oplock3_handler);
2558 fnum = cli_open(cli, fname, O_RDWR|O_CREAT, DENY_NONE);
2559 cli_write(cli, fnum, 0, buf, 0, 4);
2560 cli_close(cli, fnum);
2561 fnum = cli_open(cli, fname, O_RDWR, DENY_NONE);
2562 cli->timeout = 20000;
2563 cli_receive_smb(cli);
2564 printf("finished oplock test 3\n");
2566 return (correct && *shared_correct);
2568 /* What are we looking for here? What's sucess and what's FAILURE? */
2574 Test delete on close semantics.
2576 static BOOL run_deletetest(int dummy)
2578 struct cli_state *cli1;
2579 struct cli_state *cli2;
2580 const char *fname = "\\delete.file";
2583 BOOL correct = True;
2585 printf("starting delete test\n");
2587 if (!torture_open_connection(&cli1)) {
2591 cli_sockopt(cli1, sockops);
2593 /* Test 1 - this should delete the file on close. */
2595 cli_setatr(cli1, fname, 0, 0);
2596 cli_unlink(cli1, fname);
2598 fnum1 = cli_nt_create_full(cli1, fname, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL,
2599 FILE_SHARE_DELETE, FILE_OVERWRITE_IF,
2600 FILE_DELETE_ON_CLOSE);
2603 printf("[1] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2608 if (!cli_close(cli1, fnum1)) {
2609 printf("[1] close failed (%s)\n", cli_errstr(cli1));
2614 fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
2616 printf("[1] open of %s succeeded (should fail)\n", fname);
2621 printf("first delete on close test succeeded.\n");
2623 /* Test 2 - this should delete the file on close. */
2625 cli_setatr(cli1, fname, 0, 0);
2626 cli_unlink(cli1, fname);
2628 fnum1 = cli_nt_create_full(cli1, fname, GENERIC_ALL_ACCESS,
2629 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
2630 FILE_OVERWRITE_IF, 0);
2633 printf("[2] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2638 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
2639 printf("[2] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
2644 if (!cli_close(cli1, fnum1)) {
2645 printf("[2] close failed (%s)\n", cli_errstr(cli1));
2650 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
2652 printf("[2] open of %s succeeded should have been deleted on close !\n", fname);
2653 if (!cli_close(cli1, fnum1)) {
2654 printf("[2] close failed (%s)\n", cli_errstr(cli1));
2658 cli_unlink(cli1, fname);
2660 printf("second delete on close test succeeded.\n");
2663 cli_setatr(cli1, fname, 0, 0);
2664 cli_unlink(cli1, fname);
2666 fnum1 = cli_nt_create_full(cli1, fname, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL,
2667 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0);
2670 printf("[3] open - 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
2675 /* This should fail with a sharing violation - open for delete is only compatible
2676 with SHARE_DELETE. */
2678 fnum2 = cli_nt_create_full(cli1, fname, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
2679 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0);
2682 printf("[3] open - 2 of %s succeeded - should have failed.\n", fname);
2687 /* This should succeed. */
2689 fnum2 = cli_nt_create_full(cli1, fname, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
2690 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0);
2693 printf("[3] open - 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
2698 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
2699 printf("[3] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
2704 if (!cli_close(cli1, fnum1)) {
2705 printf("[3] close 1 failed (%s)\n", cli_errstr(cli1));
2710 if (!cli_close(cli1, fnum2)) {
2711 printf("[3] close 2 failed (%s)\n", cli_errstr(cli1));
2716 /* This should fail - file should no longer be there. */
2718 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
2720 printf("[3] open of %s succeeded should have been deleted on close !\n", fname);
2721 if (!cli_close(cli1, fnum1)) {
2722 printf("[3] close failed (%s)\n", cli_errstr(cli1));
2724 cli_unlink(cli1, fname);
2728 printf("third delete on close test succeeded.\n");
2731 cli_setatr(cli1, fname, 0, 0);
2732 cli_unlink(cli1, fname);
2734 fnum1 = cli_nt_create_full(cli1, fname, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
2735 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0);
2738 printf("[4] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2743 /* This should succeed. */
2744 fnum2 = cli_nt_create_full(cli1, fname, GENERIC_READ_ACCESS,
2745 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0);
2747 printf("[4] open - 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
2752 if (!cli_close(cli1, fnum2)) {
2753 printf("[4] close - 1 failed (%s)\n", cli_errstr(cli1));
2758 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
2759 printf("[4] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
2764 /* This should fail - no more opens once delete on close set. */
2765 fnum2 = cli_nt_create_full(cli1, fname, GENERIC_READ_ACCESS,
2766 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0);
2768 printf("[4] open - 3 of %s succeeded ! Should have failed.\n", fname );
2772 printf("fourth delete on close test succeeded.\n");
2774 if (!cli_close(cli1, fnum1)) {
2775 printf("[4] close - 2 failed (%s)\n", cli_errstr(cli1));
2781 cli_setatr(cli1, fname, 0, 0);
2782 cli_unlink(cli1, fname);
2784 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT, DENY_NONE);
2786 printf("[5] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2791 /* This should fail - only allowed on NT opens with DELETE access. */
2793 if (cli_nt_delete_on_close(cli1, fnum1, True)) {
2794 printf("[5] setting delete_on_close on OpenX file succeeded - should fail !\n");
2799 if (!cli_close(cli1, fnum1)) {
2800 printf("[5] close - 2 failed (%s)\n", cli_errstr(cli1));
2805 printf("fifth delete on close test succeeded.\n");
2808 cli_setatr(cli1, fname, 0, 0);
2809 cli_unlink(cli1, fname);
2811 fnum1 = cli_nt_create_full(cli1, fname, FILE_READ_DATA|FILE_WRITE_DATA,
2812 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
2813 FILE_OVERWRITE_IF, 0);
2816 printf("[6] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2821 /* This should fail - only allowed on NT opens with DELETE access. */
2823 if (cli_nt_delete_on_close(cli1, fnum1, True)) {
2824 printf("[6] setting delete_on_close on file with no delete access succeeded - should fail !\n");
2829 if (!cli_close(cli1, fnum1)) {
2830 printf("[6] close - 2 failed (%s)\n", cli_errstr(cli1));
2835 printf("sixth delete on close test succeeded.\n");
2838 cli_setatr(cli1, fname, 0, 0);
2839 cli_unlink(cli1, fname);
2841 fnum1 = cli_nt_create_full(cli1, fname, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
2842 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF, 0);
2845 printf("[7] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2850 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
2851 printf("[7] setting delete_on_close on file failed !\n");
2856 if (!cli_nt_delete_on_close(cli1, fnum1, False)) {
2857 printf("[7] unsetting delete_on_close on file failed !\n");
2862 if (!cli_close(cli1, fnum1)) {
2863 printf("[7] close - 2 failed (%s)\n", cli_errstr(cli1));
2868 /* This next open should succeed - we reset the flag. */
2870 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
2872 printf("[5] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2877 if (!cli_close(cli1, fnum1)) {
2878 printf("[7] close - 2 failed (%s)\n", cli_errstr(cli1));
2883 printf("seventh delete on close test succeeded.\n");
2886 cli_setatr(cli1, fname, 0, 0);
2887 cli_unlink(cli1, fname);
2889 if (!torture_open_connection(&cli2)) {
2890 printf("[8] failed to open second connection.\n");
2895 cli_sockopt(cli1, sockops);
2897 fnum1 = cli_nt_create_full(cli1, fname, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
2898 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0);
2901 printf("[8] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2906 fnum2 = cli_nt_create_full(cli2, fname, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
2907 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0);
2910 printf("[8] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2915 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
2916 printf("[8] setting delete_on_close on file failed !\n");
2921 if (!cli_close(cli1, fnum1)) {
2922 printf("[8] close - 1 failed (%s)\n", cli_errstr(cli1));
2927 if (!cli_close(cli2, fnum2)) {
2928 printf("[8] close - 2 failed (%s)\n", cli_errstr(cli2));
2933 /* This should fail.. */
2934 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
2936 printf("[8] open of %s succeeded should have been deleted on close !\n", fname);
2940 printf("eighth delete on close test succeeded.\n");
2942 /* This should fail - we need to set DELETE_ACCESS. */
2943 fnum1 = cli_nt_create_full(cli1, fname, FILE_READ_DATA|FILE_WRITE_DATA,
2944 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, FILE_OVERWRITE_IF, FILE_DELETE_ON_CLOSE);
2947 printf("[9] open of %s succeeded should have failed!\n", fname);
2952 printf("ninth delete on close test succeeded.\n");
2954 fnum1 = cli_nt_create_full(cli1, fname, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
2955 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, FILE_OVERWRITE_IF, FILE_DELETE_ON_CLOSE);
2957 printf("[10] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2962 /* This should delete the file. */
2963 if (!cli_close(cli1, fnum1)) {
2964 printf("[10] close failed (%s)\n", cli_errstr(cli1));
2969 /* This should fail.. */
2970 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
2972 printf("[10] open of %s succeeded should have been deleted on close !\n", fname);
2976 printf("tenth delete on close test succeeded.\n");
2977 printf("finished delete test\n");
2980 /* FIXME: This will crash if we aborted before cli2 got
2981 * intialized, because these functions don't handle
2982 * uninitialized connections. */
2984 cli_close(cli1, fnum1);
2985 cli_close(cli1, fnum2);
2986 cli_setatr(cli1, fname, 0, 0);
2987 cli_unlink(cli1, fname);
2989 if (!torture_close_connection(cli1)) {
2992 if (!torture_close_connection(cli2)) {
3000 print out server properties
3002 static BOOL run_properties(int dummy)
3004 static struct cli_state *cli;
3005 BOOL correct = True;
3007 printf("starting properties test\n");
3011 if (!torture_open_connection(&cli)) {
3015 cli_sockopt(cli, sockops);
3017 d_printf("Capabilities 0x%08x\n", cli->capabilities);
3019 if (!torture_close_connection(cli)) {
3028 /* FIRST_DESIRED_ACCESS 0xf019f */
3029 #define FIRST_DESIRED_ACCESS FILE_READ_DATA|FILE_WRITE_DATA|FILE_APPEND_DATA|\
3030 FILE_READ_EA| /* 0xf */ \
3031 FILE_WRITE_EA|FILE_READ_ATTRIBUTES| /* 0x90 */ \
3032 FILE_WRITE_ATTRIBUTES| /* 0x100 */ \
3033 DELETE_ACCESS|READ_CONTROL_ACCESS|\
3034 WRITE_DAC_ACCESS|WRITE_OWNER_ACCESS /* 0xf0000 */
3035 /* SECOND_DESIRED_ACCESS 0xe0080 */
3036 #define SECOND_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
3037 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
3038 WRITE_OWNER_ACCESS /* 0xe0000 */
3041 #define THIRD_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
3042 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
3044 WRITE_OWNER_ACCESS /* */
3048 Test ntcreate calls made by xcopy
3050 static BOOL run_xcopy(int dummy)
3052 static struct cli_state *cli1;
3053 const char *fname = "\\test.txt";
3054 BOOL correct = True;
3057 printf("starting xcopy test\n");
3059 if (!torture_open_connection(&cli1)) {
3063 fnum1 = cli_nt_create_full(cli1, fname,
3064 FIRST_DESIRED_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
3065 FILE_SHARE_NONE, FILE_OVERWRITE_IF,
3069 printf("First open failed - %s\n", cli_errstr(cli1));
3073 fnum2 = cli_nt_create_full(cli1, fname,
3074 SECOND_DESIRED_ACCESS, 0,
3075 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN,
3078 printf("second open failed - %s\n", cli_errstr(cli1));
3082 if (!torture_close_connection(cli1)) {
3090 Test rename on files open with share delete and no share delete.
3092 static BOOL run_rename(int dummy)
3094 static struct cli_state *cli1;
3095 const char *fname = "\\test.txt";
3096 const char *fname1 = "\\test1.txt";
3097 BOOL correct = True;
3100 printf("starting rename test\n");
3102 if (!torture_open_connection(&cli1)) {
3106 cli_unlink(cli1, fname);
3107 cli_unlink(cli1, fname1);
3108 fnum1 = cli_nt_create_full(cli1, fname, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3109 FILE_SHARE_READ, FILE_OVERWRITE_IF, 0);
3112 printf("First open failed - %s\n", cli_errstr(cli1));
3116 if (!cli_rename(cli1, fname, fname1)) {
3117 printf("First rename failed (this is correct) - %s\n", cli_errstr(cli1));
3119 printf("First rename succeeded - this should have failed !\n");
3123 if (!cli_close(cli1, fnum1)) {
3124 printf("close - 1 failed (%s)\n", cli_errstr(cli1));
3128 cli_unlink(cli1, fname);
3129 cli_unlink(cli1, fname1);
3130 fnum1 = cli_nt_create_full(cli1, fname,GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3132 FILE_SHARE_DELETE|FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0);
3134 FILE_SHARE_DELETE|FILE_SHARE_READ, FILE_OVERWRITE_IF, 0);
3138 printf("Second open failed - %s\n", cli_errstr(cli1));
3142 if (!cli_rename(cli1, fname, fname1)) {
3143 printf("Second rename failed - this should have succeeded - %s\n", cli_errstr(cli1));
3146 printf("Second rename succeeded\n");
3149 if (!cli_close(cli1, fnum1)) {
3150 printf("close - 2 failed (%s)\n", cli_errstr(cli1));
3154 cli_unlink(cli1, fname);
3155 cli_unlink(cli1, fname1);
3157 fnum1 = cli_nt_create_full(cli1, fname,READ_CONTROL_ACCESS, FILE_ATTRIBUTE_NORMAL,
3158 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0);
3161 printf("Third open failed - %s\n", cli_errstr(cli1));
3170 fnum2 = cli_nt_create_full(cli1, fname,DELETE_ACCESS, FILE_ATTRIBUTE_NORMAL,
3171 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0);
3174 printf("Fourth open failed - %s\n", cli_errstr(cli1));
3177 if (!cli_nt_delete_on_close(cli1, fnum2, True)) {
3178 printf("[8] setting delete_on_close on file failed !\n");
3182 if (!cli_close(cli1, fnum2)) {
3183 printf("close - 4 failed (%s)\n", cli_errstr(cli1));
3189 if (!cli_rename(cli1, fname, fname1)) {
3190 printf("Third rename failed - this should have succeeded - %s\n", cli_errstr(cli1));
3193 printf("Third rename succeeded\n");
3196 if (!cli_close(cli1, fnum1)) {
3197 printf("close - 3 failed (%s)\n", cli_errstr(cli1));
3201 cli_unlink(cli1, fname);
3202 cli_unlink(cli1, fname1);
3204 if (!torture_close_connection(cli1)) {
3211 static BOOL run_pipe_number(int dummy)
3213 struct cli_state *cli1;
3214 const char *pipe_name = "\\SPOOLSS";
3218 printf("starting pipenumber test\n");
3219 if (!torture_open_connection(&cli1)) {
3223 cli_sockopt(cli1, sockops);
3225 fnum = cli_nt_create_full(cli1, pipe_name,FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
3226 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN_IF, 0);
3229 printf("Open of pipe %s failed with error (%s)\n", pipe_name, cli_errstr(cli1));
3235 printf("pipe_number test - we can open %d %s pipes.\n", num_pipes, pipe_name );
3236 torture_close_connection(cli1);
3241 Test open mode returns on read-only files.
3243 static BOOL run_opentest(int dummy)
3245 static struct cli_state *cli1;
3246 static struct cli_state *cli2;
3247 const char *fname = "\\readonly.file";
3251 BOOL correct = True;
3254 printf("starting open test\n");
3256 if (!torture_open_connection(&cli1)) {
3260 cli_setatr(cli1, fname, 0, 0);
3261 cli_unlink(cli1, fname);
3263 cli_sockopt(cli1, sockops);
3265 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
3267 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
3271 if (!cli_close(cli1, fnum1)) {
3272 printf("close2 failed (%s)\n", cli_errstr(cli1));
3276 if (!cli_setatr(cli1, fname, aRONLY, 0)) {
3277 printf("cli_setatr failed (%s)\n", cli_errstr(cli1));
3281 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_WRITE);
3283 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
3287 /* This will fail - but the error should be ERRnoaccess, not ERRbadshare. */
3288 fnum2 = cli_open(cli1, fname, O_RDWR, DENY_ALL);
3290 if (check_error(__LINE__, cli1, ERRDOS, ERRnoaccess,
3291 NT_STATUS_ACCESS_DENIED)) {
3292 printf("correct error code ERRDOS/ERRnoaccess returned\n");
3295 printf("finished open test 1\n");
3297 cli_close(cli1, fnum1);
3299 /* Now try not readonly and ensure ERRbadshare is returned. */
3301 cli_setatr(cli1, fname, 0, 0);
3303 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_WRITE);
3305 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
3309 /* This will fail - but the error should be ERRshare. */
3310 fnum2 = cli_open(cli1, fname, O_RDWR, DENY_ALL);
3312 if (check_error(__LINE__, cli1, ERRDOS, ERRbadshare,
3313 NT_STATUS_SHARING_VIOLATION)) {
3314 printf("correct error code ERRDOS/ERRbadshare returned\n");
3317 if (!cli_close(cli1, fnum1)) {
3318 printf("close2 failed (%s)\n", cli_errstr(cli1));
3322 cli_unlink(cli1, fname);
3324 printf("finished open test 2\n");
3326 /* Test truncate open disposition on file opened for read. */
3328 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
3330 printf("(3) open (1) of %s failed (%s)\n", fname, cli_errstr(cli1));
3334 /* write 20 bytes. */
3336 memset(buf, '\0', 20);
3338 if (cli_write(cli1, fnum1, 0, buf, 0, 20) != 20) {
3339 printf("write failed (%s)\n", cli_errstr(cli1));
3343 if (!cli_close(cli1, fnum1)) {
3344 printf("(3) close1 failed (%s)\n", cli_errstr(cli1));
3348 /* Ensure size == 20. */
3349 if (!cli_getatr(cli1, fname, NULL, &fsize, NULL)) {
3350 printf("(3) getatr failed (%s)\n", cli_errstr(cli1));
3355 printf("(3) file size != 20\n");
3359 /* Now test if we can truncate a file opened for readonly. */
3361 fnum1 = cli_open(cli1, fname, O_RDONLY|O_TRUNC, DENY_NONE);
3363 printf("(3) open (2) of %s failed (%s)\n", fname, cli_errstr(cli1));
3367 if (!cli_close(cli1, fnum1)) {
3368 printf("close2 failed (%s)\n", cli_errstr(cli1));
3372 /* Ensure size == 0. */
3373 if (!cli_getatr(cli1, fname, NULL, &fsize, NULL)) {
3374 printf("(3) getatr failed (%s)\n", cli_errstr(cli1));
3379 printf("(3) file size != 0\n");
3382 printf("finished open test 3\n");
3384 cli_unlink(cli1, fname);
3387 printf("testing ctemp\n");
3388 fnum1 = cli_ctemp(cli1, "\\", &tmp_path);
3390 printf("ctemp failed (%s)\n", cli_errstr(cli1));
3393 printf("ctemp gave path %s\n", tmp_path);
3394 if (!cli_close(cli1, fnum1)) {
3395 printf("close of temp failed (%s)\n", cli_errstr(cli1));
3397 if (!cli_unlink(cli1, tmp_path)) {
3398 printf("unlink of temp failed (%s)\n", cli_errstr(cli1));
3401 /* Test the non-io opens... */
3403 if (!torture_open_connection(&cli2)) {
3407 cli_setatr(cli2, fname, 0, 0);
3408 cli_unlink(cli2, fname);
3410 cli_sockopt(cli2, sockops);
3412 printf("TEST #1 testing 2 non-io opens (no delete)\n");
3414 fnum1 = cli_nt_create_full(cli1, fname,FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3415 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0);
3418 printf("test 1 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3422 fnum2 = cli_nt_create_full(cli2, fname,FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3423 FILE_SHARE_NONE, FILE_OPEN_IF, 0);
3426 printf("test 1 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3430 if (!cli_close(cli1, fnum1)) {
3431 printf("test 1 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3434 if (!cli_close(cli2, fnum2)) {
3435 printf("test 1 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3439 printf("non-io open test #1 passed.\n");
3441 cli_unlink(cli1, fname);
3443 printf("TEST #2 testing 2 non-io opens (first with delete)\n");
3445 fnum1 = cli_nt_create_full(cli1, fname,DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3446 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0);
3449 printf("test 2 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3453 fnum2 = cli_nt_create_full(cli2, fname,FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3454 FILE_SHARE_NONE, FILE_OPEN_IF, 0);
3457 printf("test 2 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3461 if (!cli_close(cli1, fnum1)) {
3462 printf("test 1 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3465 if (!cli_close(cli2, fnum2)) {
3466 printf("test 1 close 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
3470 printf("non-io open test #2 passed.\n");
3472 cli_unlink(cli1, fname);
3474 printf("TEST #3 testing 2 non-io opens (second with delete)\n");
3476 fnum1 = cli_nt_create_full(cli1, fname,FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3477 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0);
3480 printf("test 3 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3484 fnum2 = cli_nt_create_full(cli2, fname,DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3485 FILE_SHARE_NONE, FILE_OPEN_IF, 0);
3488 printf("test 3 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3492 if (!cli_close(cli1, fnum1)) {
3493 printf("test 3 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3496 if (!cli_close(cli2, fnum2)) {
3497 printf("test 3 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3501 printf("non-io open test #3 passed.\n");
3503 cli_unlink(cli1, fname);
3505 printf("TEST #4 testing 2 non-io opens (both with delete)\n");
3507 fnum1 = cli_nt_create_full(cli1, fname,DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3508 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0);
3511 printf("test 4 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3515 fnum2 = cli_nt_create_full(cli2, fname,DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3516 FILE_SHARE_NONE, FILE_OPEN_IF, 0);
3519 printf("test 4 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, cli_errstr(cli2));
3523 printf("test 3 open 2 of %s gave %s (correct error should be %s)\n", fname, cli_errstr(cli2), "sharing violation");
3525 if (!cli_close(cli1, fnum1)) {
3526 printf("test 4 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3530 printf("non-io open test #4 passed.\n");
3532 cli_unlink(cli1, fname);
3534 printf("TEST #5 testing 2 non-io opens (both with delete - both with file share delete)\n");
3536 fnum1 = cli_nt_create_full(cli1, fname,DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3537 FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0);
3540 printf("test 5 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3544 fnum2 = cli_nt_create_full(cli2, fname,DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3545 FILE_SHARE_DELETE, FILE_OPEN_IF, 0);
3548 printf("test 5 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3552 if (!cli_close(cli1, fnum1)) {
3553 printf("test 5 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3557 if (!cli_close(cli2, fnum2)) {
3558 printf("test 5 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3562 printf("non-io open test #5 passed.\n");
3564 printf("TEST #6 testing 1 non-io open, one io open\n");
3566 cli_unlink(cli1, fname);
3568 fnum1 = cli_nt_create_full(cli1, fname,FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
3569 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0);
3572 printf("test 6 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3576 fnum2 = cli_nt_create_full(cli2, fname,FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3577 FILE_SHARE_READ, FILE_OPEN_IF, 0);
3580 printf("test 6 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3584 if (!cli_close(cli1, fnum1)) {
3585 printf("test 6 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3589 if (!cli_close(cli2, fnum2)) {
3590 printf("test 6 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3594 printf("non-io open test #6 passed.\n");
3596 printf("TEST #7 testing 1 non-io open, one io open with delete\n");
3598 cli_unlink(cli1, fname);
3600 fnum1 = cli_nt_create_full(cli1, fname,FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
3601 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0);
3604 printf("test 7 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3608 fnum2 = cli_nt_create_full(cli2, fname,DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3609 FILE_SHARE_READ|FILE_SHARE_DELETE, FILE_OPEN_IF, 0);
3612 printf("test 7 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, cli_errstr(cli2));
3616 printf("test 7 open 2 of %s gave %s (correct error should be %s)\n", fname, cli_errstr(cli2), "sharing violation");
3618 if (!cli_close(cli1, fnum1)) {
3619 printf("test 7 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3623 printf("non-io open test #7 passed.\n");
3625 cli_unlink(cli1, fname);
3627 if (!torture_close_connection(cli1)) {
3630 if (!torture_close_connection(cli2)) {
3637 static uint32 open_attrs_table[] = {
3638 FILE_ATTRIBUTE_NORMAL,
3639 FILE_ATTRIBUTE_ARCHIVE,
3640 FILE_ATTRIBUTE_READONLY,
3641 FILE_ATTRIBUTE_HIDDEN,
3642 FILE_ATTRIBUTE_SYSTEM,
3644 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY,
3645 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN,
3646 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM,
3647 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN,
3648 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM,
3649 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM,
3651 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN,
3652 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM,
3653 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM,
3654 FILE_ATTRIBUTE_HIDDEN,FILE_ATTRIBUTE_SYSTEM,
3657 struct trunc_open_results {
3664 static struct trunc_open_results attr_results[] = {
3665 { 0, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE },
3666 { 1, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE },
3667 { 2, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_READONLY, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY },
3668 { 16, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE },
3669 { 17, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE },
3670 { 18, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_READONLY, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY },
3671 { 51, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
3672 { 54, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
3673 { 56, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN },
3674 { 68, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
3675 { 71, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
3676 { 73, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM },
3677 { 99, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN,FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
3678 { 102, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
3679 { 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 },
3680 { 116, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
3681 { 119, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
3682 { 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 },
3683 { 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 },
3684 { 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 },
3685 { 227, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
3686 { 230, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
3687 { 232, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN },
3688 { 244, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
3689 { 247, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
3690 { 249, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM }
3693 static BOOL run_openattrtest(int dummy)
3695 static struct cli_state *cli1;
3696 const char *fname = "\\openattr.file";
3698 BOOL correct = True;
3700 unsigned int i, j, k, l;
3702 printf("starting open attr test\n");
3704 if (!torture_open_connection(&cli1)) {
3708 cli_sockopt(cli1, sockops);
3710 for (k = 0, i = 0; i < sizeof(open_attrs_table)/sizeof(uint32); i++) {
3711 cli_setatr(cli1, fname, 0, 0);
3712 cli_unlink(cli1, fname);
3713 fnum1 = cli_nt_create_full(cli1, fname,FILE_WRITE_DATA, open_attrs_table[i],
3714 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0);
3717 printf("open %d (1) of %s failed (%s)\n", i, fname, cli_errstr(cli1));
3721 if (!cli_close(cli1, fnum1)) {
3722 printf("close %d (1) of %s failed (%s)\n", i, fname, cli_errstr(cli1));
3726 for (j = 0; j < sizeof(open_attrs_table)/sizeof(uint32); j++) {
3727 fnum1 = cli_nt_create_full(cli1, fname,FILE_READ_DATA|FILE_WRITE_DATA, open_attrs_table[j],
3728 FILE_SHARE_NONE, FILE_OVERWRITE, 0);
3731 for (l = 0; l < sizeof(attr_results)/sizeof(struct trunc_open_results); l++) {
3732 if (attr_results[l].num == k) {
3733 printf("[%d] trunc open 0x%x -> 0x%x of %s failed - should have succeeded !(0x%x:%s)\n",
3734 k, open_attrs_table[i],
3735 open_attrs_table[j],
3736 fname, NT_STATUS_V(cli_nt_error(cli1)), cli_errstr(cli1));
3740 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_ACCESS_DENIED)) {
3741 printf("[%d] trunc open 0x%x -> 0x%x failed with wrong error code %s\n",
3742 k, open_attrs_table[i], open_attrs_table[j],
3747 printf("[%d] trunc open 0x%x -> 0x%x failed\n", k, open_attrs_table[i], open_attrs_table[j]);
3753 if (!cli_close(cli1, fnum1)) {
3754 printf("close %d (2) of %s failed (%s)\n", j, fname, cli_errstr(cli1));
3758 if (!cli_getatr(cli1, fname, &attr, NULL, NULL)) {
3759 printf("getatr(2) failed (%s)\n", cli_errstr(cli1));
3764 printf("[%d] getatr check [0x%x] trunc [0x%x] got attr 0x%x\n",
3765 k, open_attrs_table[i], open_attrs_table[j], attr );
3768 for (l = 0; l < sizeof(attr_results)/sizeof(struct trunc_open_results); l++) {
3769 if (attr_results[l].num == k) {
3770 if (attr != attr_results[l].result_attr ||
3771 open_attrs_table[i] != attr_results[l].init_attr ||
3772 open_attrs_table[j] != attr_results[l].trunc_attr) {
3773 printf("getatr check failed. [0x%x] trunc [0x%x] got attr 0x%x, should be 0x%x\n",
3774 open_attrs_table[i],
3775 open_attrs_table[j],
3777 attr_results[l].result_attr);
3787 cli_setatr(cli1, fname, 0, 0);
3788 cli_unlink(cli1, fname);
3790 printf("open attr test %s.\n", correct ? "passed" : "failed");
3792 if (!torture_close_connection(cli1)) {
3798 static void list_fn(file_info *finfo, const char *name, void *state)
3804 test directory listing speed
3806 static BOOL run_dirtest(int dummy)
3809 static struct cli_state *cli;
3812 BOOL correct = True;
3814 printf("starting directory test\n");
3816 if (!torture_open_connection(&cli)) {
3820 cli_sockopt(cli, sockops);
3823 for (i=0;i<torture_numops;i++) {
3825 slprintf(fname, sizeof(fname), "\\%x", (int)random());
3826 fnum = cli_open(cli, fname, O_RDWR|O_CREAT, DENY_NONE);
3828 fprintf(stderr,"Failed to open %s\n", fname);
3831 cli_close(cli, fnum);
3836 printf("Matched %d\n", cli_list(cli, "a*.*", 0, list_fn, NULL));
3837 printf("Matched %d\n", cli_list(cli, "b*.*", 0, list_fn, NULL));
3838 printf("Matched %d\n", cli_list(cli, "xyzabc", 0, list_fn, NULL));
3840 printf("dirtest core %g seconds\n", end_timer() - t1);
3843 for (i=0;i<torture_numops;i++) {
3845 slprintf(fname, sizeof(fname), "\\%x", (int)random());
3846 cli_unlink(cli, fname);
3849 if (!torture_close_connection(cli)) {
3853 printf("finished dirtest\n");
3858 static void del_fn(file_info *finfo, const char *mask, void *state)
3860 struct cli_state *pcli = (struct cli_state *)state;
3862 slprintf(fname, sizeof(fname), "\\LISTDIR\\%s", finfo->name);
3864 if (strcmp(finfo->name, ".") == 0 || strcmp(finfo->name, "..") == 0)
3867 if (finfo->mode & aDIR) {
3868 if (!cli_rmdir(pcli, fname))
3869 printf("del_fn: failed to rmdir %s\n,", fname );
3871 if (!cli_unlink(pcli, fname))
3872 printf("del_fn: failed to unlink %s\n,", fname );
3876 static BOOL run_dirtest1(int dummy)
3879 static struct cli_state *cli;
3881 BOOL correct = True;
3883 printf("starting directory test\n");
3885 if (!torture_open_connection(&cli)) {
3889 cli_sockopt(cli, sockops);
3891 cli_list(cli, "\\LISTDIR\\*", 0, del_fn, cli);
3892 cli_list(cli, "\\LISTDIR\\*", aDIR, del_fn, cli);
3893 cli_rmdir(cli, "\\LISTDIR");
3894 cli_mkdir(cli, "\\LISTDIR");
3896 /* Create 1000 files and 1000 directories. */
3897 for (i=0;i<1000;i++) {
3899 slprintf(fname, sizeof(fname), "\\LISTDIR\\f%d", i);
3900 fnum = cli_nt_create_full(cli, fname, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
3901 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0);
3903 fprintf(stderr,"Failed to open %s\n", fname);
3906 cli_close(cli, fnum);
3908 for (i=0;i<1000;i++) {
3910 slprintf(fname, sizeof(fname), "\\LISTDIR\\d%d", i);
3911 if (!cli_mkdir(cli, fname)) {
3912 fprintf(stderr,"Failed to open %s\n", fname);
3917 /* Now ensure that doing an old list sees both files and directories. */
3918 num_seen = cli_list_old(cli, "\\LISTDIR\\*", aDIR, list_fn, NULL);
3919 printf("num_seen = %d\n", num_seen );
3920 /* We should see 100 files + 1000 directories + . and .. */
3921 if (num_seen != 2002)
3924 /* Ensure if we have the "must have" bits we only see the
3927 num_seen = cli_list_old(cli, "\\LISTDIR\\*", (aDIR<<8)|aDIR, list_fn, NULL);
3928 printf("num_seen = %d\n", num_seen );
3929 if (num_seen != 1002)
3932 num_seen = cli_list_old(cli, "\\LISTDIR\\*", (aARCH<<8)|aDIR, list_fn, NULL);
3933 printf("num_seen = %d\n", num_seen );
3934 if (num_seen != 1000)
3937 /* Delete everything. */
3938 cli_list(cli, "\\LISTDIR\\*", 0, del_fn, cli);
3939 cli_list(cli, "\\LISTDIR\\*", aDIR, del_fn, cli);
3940 cli_rmdir(cli, "\\LISTDIR");
3943 printf("Matched %d\n", cli_list(cli, "a*.*", 0, list_fn, NULL));
3944 printf("Matched %d\n", cli_list(cli, "b*.*", 0, list_fn, NULL));
3945 printf("Matched %d\n", cli_list(cli, "xyzabc", 0, list_fn, NULL));
3948 if (!torture_close_connection(cli)) {
3952 printf("finished dirtest1\n");
3957 static BOOL run_error_map_extract(int dummy) {
3959 static struct cli_state c_dos;
3960 static struct cli_state c_nt;
3964 uint32 flgs2, errnum;
3971 /* NT-Error connection */
3973 if (!open_nbt_connection(&c_nt)) {
3977 c_nt.use_spnego = False;
3979 if (!cli_negprot(&c_nt)) {
3980 printf("%s rejected the NT-error negprot (%s)\n",host, cli_errstr(&c_nt));
3981 cli_shutdown(&c_nt);
3985 if (!cli_session_setup(&c_nt, "", "", 0, "", 0,
3987 printf("%s rejected the NT-error initial session setup (%s)\n",host, cli_errstr(&c_nt));
3991 /* DOS-Error connection */
3993 if (!open_nbt_connection(&c_dos)) {
3997 c_dos.use_spnego = False;
3998 c_dos.force_dos_errors = True;
4000 if (!cli_negprot(&c_dos)) {
4001 printf("%s rejected the DOS-error negprot (%s)\n",host, cli_errstr(&c_dos));
4002 cli_shutdown(&c_dos);
4006 if (!cli_session_setup(&c_dos, "", "", 0, "", 0,
4008 printf("%s rejected the DOS-error initial session setup (%s)\n",host, cli_errstr(&c_dos));
4012 for (error=(0xc0000000 | 0x1); error < (0xc0000000| 0xFFF); error++) {
4013 snprintf(user, sizeof(user), "%X", error);
4015 if (cli_session_setup(&c_nt, user,
4016 password, strlen(password),
4017 password, strlen(password),
4019 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
4022 flgs2 = SVAL(c_nt.inbuf,smb_flg2);
4024 /* Case #1: 32-bit NT errors */
4025 if (flgs2 & FLAGS2_32_BIT_ERROR_CODES) {
4026 nt_status = NT_STATUS(IVAL(c_nt.inbuf,smb_rcls));
4028 printf("/** Dos error on NT connection! (%s) */\n",
4030 nt_status = NT_STATUS(0xc0000000);
4033 if (cli_session_setup(&c_dos, user,
4034 password, strlen(password),
4035 password, strlen(password),
4037 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
4039 flgs2 = SVAL(c_dos.inbuf,smb_flg2), errnum;
4041 /* Case #1: 32-bit NT errors */
4042 if (flgs2 & FLAGS2_32_BIT_ERROR_CODES) {
4043 printf("/** NT error on DOS connection! (%s) */\n",
4045 errnum = errclass = 0;
4047 cli_dos_error(&c_dos, &errclass, &errnum);
4050 if (NT_STATUS_V(nt_status) != error) {
4051 printf("/*\t{ This NT error code was 'sqashed'\n\t from %s to %s \n\t during the session setup }\n*/\n",
4052 get_nt_error_c_code(NT_STATUS(error)),
4053 get_nt_error_c_code(nt_status));
4056 printf("\t{%s,\t%s,\t%s},\n",
4057 smb_dos_err_class(errclass),
4058 smb_dos_err_name(errclass, errnum),
4059 get_nt_error_c_code(NT_STATUS(error)));
4064 static double create_procs(BOOL (*fn)(int), BOOL *result)
4067 volatile pid_t *child_status;
4068 volatile BOOL *child_status_out;
4074 child_status = (volatile pid_t *)shm_setup(sizeof(pid_t)*nprocs);
4075 if (!child_status) {
4076 printf("Failed to setup shared memory\n");
4080 child_status_out = (volatile BOOL *)shm_setup(sizeof(BOOL)*nprocs);
4081 if (!child_status_out) {
4082 printf("Failed to setup result status shared memory\n");
4086 for (i = 0; i < nprocs; i++) {
4087 child_status[i] = 0;
4088 child_status_out[i] = True;
4093 for (i=0;i<nprocs;i++) {
4096 pid_t mypid = getpid();
4097 sys_srandom(((int)mypid) ^ ((int)time(NULL)));
4099 slprintf(myname,sizeof(myname),"CLIENT%d", i);
4102 if (torture_open_connection(¤t_cli)) break;
4104 printf("pid %d failed to start\n", (int)getpid());
4110 child_status[i] = getpid();
4112 while (child_status[i] && end_timer() < 5) msleep(2);
4114 child_status_out[i] = fn(i);
4121 for (i=0;i<nprocs;i++) {
4122 if (child_status[i]) synccount++;
4124 if (synccount == nprocs) break;
4126 } while (end_timer() < 30);
4128 if (synccount != nprocs) {
4129 printf("FAILED TO START %d CLIENTS (started %d)\n", nprocs, synccount);
4134 /* start the client load */
4137 for (i=0;i<nprocs;i++) {
4138 child_status[i] = 0;
4141 printf("%d clients started\n", nprocs);
4143 for (i=0;i<nprocs;i++) {
4144 while (waitpid(0, &status, 0) == -1 && errno == EINTR) /* noop */ ;
4149 for (i=0;i<nprocs;i++) {
4150 if (!child_status_out[i]) {
4157 #define FLAG_MULTIPROC 1
4164 {"FDPASS", run_fdpasstest, 0},
4165 {"LOCK1", run_locktest1, 0},
4166 {"LOCK2", run_locktest2, 0},
4167 {"LOCK3", run_locktest3, 0},
4168 {"LOCK4", run_locktest4, 0},
4169 {"LOCK5", run_locktest5, 0},
4170 {"LOCK6", run_locktest6, 0},
4171 {"LOCK7", run_locktest7, 0},
4172 {"UNLINK", run_unlinktest, 0},
4173 {"BROWSE", run_browsetest, 0},
4174 {"ATTR", run_attrtest, 0},
4175 {"TRANS2", run_trans2test, 0},
4176 {"MAXFID", run_maxfidtest, FLAG_MULTIPROC},
4177 {"TORTURE",run_torture, FLAG_MULTIPROC},
4178 {"RANDOMIPC", run_randomipc, 0},
4179 {"NEGNOWAIT", run_negprot_nowait, 0},
4180 {"NBENCH", run_nbench, 0},
4181 {"OPLOCK1", run_oplock1, 0},
4182 {"OPLOCK2", run_oplock2, 0},
4183 {"OPLOCK3", run_oplock3, 0},
4184 {"DIR", run_dirtest, 0},
4185 {"DIR1", run_dirtest1, 0},
4186 {"DENY1", torture_denytest1, 0},
4187 {"DENY2", torture_denytest2, 0},
4188 {"TCON", run_tcon_test, 0},
4189 {"RW1", run_readwritetest, 0},
4190 {"RW2", run_readwritemulti, FLAG_MULTIPROC},
4191 {"RW3", run_readwritelarge, 0},
4192 {"OPEN", run_opentest, 0},
4194 {"OPENATTR", run_openattrtest, 0},
4196 {"XCOPY", run_xcopy, 0},
4197 {"RENAME", run_rename, 0},
4198 {"DELETE", run_deletetest, 0},
4199 {"PROPERTIES", run_properties, 0},
4200 {"MANGLE", torture_mangle, 0},
4201 {"W2K", run_w2ktest, 0},
4202 {"TRANS2SCAN", torture_trans2_scan, 0},
4203 {"NTTRANSSCAN", torture_nttrans_scan, 0},
4204 {"UTABLE", torture_utable, 0},
4205 {"CASETABLE", torture_casetable, 0},
4206 {"ERRMAPEXTRACT", run_error_map_extract, 0},
4207 {"PIPE_NUMBER", run_pipe_number, 0},
4208 {"TCON2", run_tcon2_test, 0},
4213 /****************************************************************************
4214 run a specified test or "ALL"
4215 ****************************************************************************/
4216 static BOOL run_test(const char *name)
4222 if (strequal(name,"ALL")) {
4223 for (i=0;torture_ops[i].name;i++) {
4224 run_test(torture_ops[i].name);
4228 for (i=0;torture_ops[i].name;i++) {
4229 snprintf(randomfname, sizeof(randomfname), "\\XX%x",
4230 (unsigned)random());
4232 if (strequal(name, torture_ops[i].name)) {
4233 printf("Running %s\n", name);
4234 if (torture_ops[i].flags & FLAG_MULTIPROC) {
4235 t = create_procs(torture_ops[i].fn, &result);
4238 printf("TEST %s FAILED!\n", name);
4243 if (!torture_ops[i].fn(0)) {
4245 printf("TEST %s FAILED!\n", name);
4249 printf("%s took %g secs\n\n", name, t);
4256 static void usage(void)
4260 printf("Usage: smbtorture //server/share <options> TEST1 TEST2 ...\n");
4262 printf("\t-d debuglevel\n");
4263 printf("\t-U user%%pass\n");
4264 printf("\t-k use kerberos\n");
4265 printf("\t-N numprocs\n");
4266 printf("\t-n my_netbios_name\n");
4267 printf("\t-W workgroup\n");
4268 printf("\t-o num_operations\n");
4269 printf("\t-O socket_options\n");
4270 printf("\t-m maximum protocol\n");
4271 printf("\t-L use oplocks\n");
4272 printf("\t-c CLIENT.TXT specify client load file for NBENCH\n");
4273 printf("\t-A showall\n");
4274 printf("\t-p port\n");
4275 printf("\t-s seed\n");
4278 printf("tests are:");
4279 for (i=0;torture_ops[i].name;i++) {
4280 printf(" %s", torture_ops[i].name);
4284 printf("default test is ALL\n");
4289 /****************************************************************************
4291 ****************************************************************************/
4292 int main(int argc,char *argv[])
4298 extern char *optarg;
4300 BOOL correct = True;
4304 #ifdef HAVE_SETBUFFER
4305 setbuffer(stdout, NULL, 0);
4308 lp_load(dyn_CONFIGFILE,True,False,False);
4315 for(p = argv[1]; *p; p++)
4319 if (strncmp(argv[1], "//", 2)) {
4323 fstrcpy(host, &argv[1][2]);
4324 p = strchr_m(&host[2],'/');
4329 fstrcpy(share, p+1);
4333 if (*username == 0 && getenv("LOGNAME")) {
4334 fstrcpy(username,getenv("LOGNAME"));
4340 srandom(time(NULL));
4342 fstrcpy(workgroup, lp_workgroup());
4344 while ((opt = getopt(argc, argv, "p:hW:U:n:N:O:o:m:Ld:Ac:ks:")) != EOF) {
4347 port_to_use = atoi(optarg);
4350 srandom(atoi(optarg));
4353 fstrcpy(workgroup,optarg);
4356 max_protocol = interpret_protocol(optarg, max_protocol);
4359 nprocs = atoi(optarg);
4362 torture_numops = atoi(optarg);
4365 DEBUGLEVEL = atoi(optarg);
4374 torture_showall = True;
4377 fstrcpy(myname, optarg);
4380 client_txt = optarg;
4384 use_kerberos = True;
4386 d_printf("No kerberos support compiled in\n");
4392 fstrcpy(username,optarg);
4393 p = strchr_m(username,'%');
4396 fstrcpy(password, p+1);
4401 printf("Unknown option %c (%d)\n", (char)opt, opt);
4406 if(use_kerberos && !gotuser) gotpass = True;
4409 p = getpass("Password:");
4411 fstrcpy(password, p);
4416 printf("host=%s share=%s user=%s myname=%s\n",
4417 host, share, username, myname);
4420 correct = run_test("ALL");
4422 for (i=1;i<argc;i++) {
4423 if (!run_test(argv[i])) {