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 char *sockops="TCP_NODELAY";
28 static int nprocs=1, numops=100;
29 static int procnum; /* records process count number when forking */
30 static struct cli_state current_cli;
31 static fstring randomfname;
32 static BOOL use_oplocks;
33 static BOOL use_level_II_oplocks;
34 BOOL torture_showall = False;
36 static double create_procs(BOOL (*fn)(int), BOOL *result);
39 static struct timeval tp1,tp2;
41 static void start_timer(void)
43 gettimeofday(&tp1,NULL);
46 static double end_timer(void)
48 gettimeofday(&tp2,NULL);
49 return((tp2.tv_sec - tp1.tv_sec) +
50 (tp2.tv_usec - tp1.tv_usec)*1.0e-6);
54 /* return a pointer to a anonymous shared memory segment of size "size"
55 which will persist across fork() but will disappear when all processes
58 The memory is not zeroed
60 This function uses system5 shared memory. It takes advantage of a property
61 that the memory is not destroyed if it is attached when the id is removed
63 static void *shm_setup(int size)
68 shmid = shmget(IPC_PRIVATE, size, SHM_R | SHM_W);
70 printf("can't get shared memory\n");
73 ret = (void *)shmat(shmid, 0, 0);
74 if (!ret || ret == (void *)-1) {
75 printf("can't attach to shared memory\n");
78 /* the following releases the ipc, but note that this process
79 and all its children will still have access to the memory, its
80 just that the shmid is no longer valid for other shm calls. This
81 means we don't leave behind lots of shm segments after we exit
83 See Stevens "advanced programming in unix env" for details
85 shmctl(shmid, IPC_RMID, 0);
91 static BOOL open_nbt_connection(struct cli_state *c)
93 struct nmb_name called, calling;
98 make_nmb_name(&calling, myname, 0x0);
99 make_nmb_name(&called , host, 0x20);
103 if (!cli_initialise(c) || !cli_connect(c, host, &ip)) {
104 printf("Failed to connect with %s\n", host);
108 c->timeout = 120000; /* set a really long timeout (2 minutes) */
109 if (use_oplocks) c->use_oplocks = True;
110 if (use_level_II_oplocks) c->use_level_II_oplocks = True;
112 if (!cli_session_request(c, &calling, &called)) {
113 printf("%s rejected the session\n",host);
121 BOOL torture_open_connection(struct cli_state *c)
125 if (!open_nbt_connection(c)) {
129 if (!cli_negprot(c)) {
130 printf("%s rejected the negprot (%s)\n",host, cli_errstr(c));
135 if (!cli_session_setup(c, username,
136 password, strlen(password),
137 password, strlen(password),
139 printf("%s rejected the sessionsetup (%s)\n", host, cli_errstr(c));
144 if (!cli_send_tconX(c, share, "?????",
145 password, strlen(password)+1)) {
146 printf("%s refused tree connect (%s)\n", host, cli_errstr(c));
155 BOOL torture_close_connection(struct cli_state *c)
159 printf("tdis failed (%s)\n", cli_errstr(c));
169 /* check if the server produced the expected error code */
170 static BOOL check_error(int line, struct cli_state *c,
171 uint8 eclass, uint32 ecode, NTSTATUS nterr)
173 if (cli_is_dos_error(c)) {
177 /* Check DOS error */
179 cli_dos_error(c, &class, &num);
181 if (eclass != class || ecode != num) {
182 printf("unexpected error code class=%d code=%d\n",
183 (int)class, (int)num);
184 printf(" expected %d/%d %s (line=%d)\n",
185 (int)eclass, (int)ecode, get_nt_error_msg(nterr), line);
194 status = cli_nt_error(c);
196 if (NT_STATUS_V(nterr) != NT_STATUS_V(status)) {
197 printf("unexpected error code %s\n", get_nt_error_msg(status));
198 printf(" expected %s (line=%d)\n", get_nt_error_msg(nterr), line);
207 static BOOL wait_lock(struct cli_state *c, int fnum, uint32 offset, uint32 len)
209 while (!cli_lock(c, fnum, offset, len, -1, WRITE_LOCK)) {
210 if (!check_error(__LINE__, c, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False;
216 static BOOL rw_torture(struct cli_state *c)
218 char *lockfname = "\\torture.lck";
222 pid_t pid2, pid = getpid();
227 fnum2 = cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
230 fnum2 = cli_open(c, lockfname, O_RDWR, DENY_NONE);
232 printf("open of %s failed (%s)\n", lockfname, cli_errstr(c));
237 for (i=0;i<numops;i++) {
238 unsigned n = (unsigned)sys_random()%10;
240 printf("%d\r", i); fflush(stdout);
242 slprintf(fname, sizeof(fstring) - 1, "\\torture.%u", n);
244 if (!wait_lock(c, fnum2, n*sizeof(int), sizeof(int))) {
248 fnum = cli_open(c, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_ALL);
250 printf("open failed (%s)\n", cli_errstr(c));
255 if (cli_write(c, fnum, 0, (char *)&pid, 0, sizeof(pid)) != sizeof(pid)) {
256 printf("write failed (%s)\n", cli_errstr(c));
261 if (cli_write(c, fnum, 0, (char *)buf,
262 sizeof(pid)+(j*sizeof(buf)),
263 sizeof(buf)) != sizeof(buf)) {
264 printf("write failed (%s)\n", cli_errstr(c));
271 if (cli_read(c, fnum, (char *)&pid2, 0, sizeof(pid)) != sizeof(pid)) {
272 printf("read failed (%s)\n", cli_errstr(c));
277 printf("data corruption!\n");
281 if (!cli_close(c, fnum)) {
282 printf("close failed (%s)\n", cli_errstr(c));
286 if (!cli_unlink(c, fname)) {
287 printf("unlink failed (%s)\n", cli_errstr(c));
291 if (!cli_unlock(c, fnum2, n*sizeof(int), sizeof(int))) {
292 printf("unlock failed (%s)\n", cli_errstr(c));
298 cli_unlink(c, lockfname);
305 static BOOL run_torture(int dummy)
307 struct cli_state cli;
312 cli_sockopt(&cli, sockops);
314 ret = rw_torture(&cli);
316 if (!torture_close_connection(&cli)) {
323 static BOOL rw_torture3(struct cli_state *c, char *lockfname)
330 unsigned countprev = 0;
335 for (i = 0; i < sizeof(buf); i += sizeof(uint32))
337 SIVAL(buf, i, sys_random());
342 fnum = cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
345 printf("first open read/write of %s failed (%s)\n",
346 lockfname, cli_errstr(c));
352 for (i = 0; i < 500 && fnum == -1; i++)
354 fnum = cli_open(c, lockfname, O_RDONLY,
359 printf("second open read-only of %s failed (%s)\n",
360 lockfname, cli_errstr(c));
366 for (count = 0; count < sizeof(buf); count += sent)
368 if (count >= countprev) {
369 printf("%d %8d\r", i, count);
372 countprev += (sizeof(buf) / 20);
377 sent = ((unsigned)sys_random()%(20))+ 1;
378 if (sent > sizeof(buf) - count)
380 sent = sizeof(buf) - count;
383 if (cli_write(c, fnum, 0, buf+count, count, (size_t)sent) != sent) {
384 printf("write failed (%s)\n", cli_errstr(c));
390 sent = cli_read(c, fnum, buf_rd+count, count,
394 printf("read failed offset:%d size:%d (%s)\n",
395 count, sizeof(buf)-count,
402 if (memcmp(buf_rd+count, buf+count, sent) != 0)
404 printf("read/write compare failed\n");
405 printf("offset: %d req %d recvd %d\n",
406 count, sizeof(buf)-count, sent);
415 if (!cli_close(c, fnum)) {
416 printf("close failed (%s)\n", cli_errstr(c));
423 static BOOL rw_torture2(struct cli_state *c1, struct cli_state *c2)
425 char *lockfname = "\\torture2.lck";
430 uchar buf_rd[131072];
434 if (!cli_unlink(c1, lockfname)) {
435 printf("unlink failed (%s) (normal, this file should not exist)\n", cli_errstr(c1));
438 fnum1 = cli_open(c1, lockfname, O_RDWR | O_CREAT | O_EXCL,
441 printf("first open read/write of %s failed (%s)\n",
442 lockfname, cli_errstr(c1));
445 fnum2 = cli_open(c2, lockfname, O_RDONLY,
448 printf("second open read-only of %s failed (%s)\n",
449 lockfname, cli_errstr(c2));
450 cli_close(c1, fnum1);
454 for (i=0;i<numops;i++)
456 size_t buf_size = ((unsigned)sys_random()%(sizeof(buf)-1))+ 1;
458 printf("%d\r", i); fflush(stdout);
461 generate_random_buffer(buf, buf_size, False);
463 if (cli_write(c1, fnum1, 0, buf, 0, buf_size) != buf_size) {
464 printf("write failed (%s)\n", cli_errstr(c1));
468 if ((bytes_read = cli_read(c2, fnum2, buf_rd, 0, buf_size)) != buf_size) {
469 printf("read failed (%s)\n", cli_errstr(c2));
470 printf("read %d, expected %d\n", bytes_read, buf_size);
474 if (memcmp(buf_rd, buf, buf_size) != 0)
476 printf("read/write compare failed\n");
481 if (!cli_close(c2, fnum2)) {
482 printf("close failed (%s)\n", cli_errstr(c2));
485 if (!cli_close(c1, fnum1)) {
486 printf("close failed (%s)\n", cli_errstr(c1));
490 if (!cli_unlink(c1, lockfname)) {
491 printf("unlink failed (%s)\n", cli_errstr(c1));
498 static BOOL run_readwritetest(int dummy)
500 static struct cli_state cli1, cli2;
503 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
506 cli_sockopt(&cli1, sockops);
507 cli_sockopt(&cli2, sockops);
509 printf("starting readwritetest\n");
511 test1 = rw_torture2(&cli1, &cli2);
512 printf("Passed readwritetest v1: %s\n", BOOLSTR(test1));
514 test2 = rw_torture2(&cli1, &cli1);
515 printf("Passed readwritetest v2: %s\n", BOOLSTR(test2));
517 if (!torture_close_connection(&cli1)) {
521 if (!torture_close_connection(&cli2)) {
525 return (test1 && test2);
528 static BOOL run_readwritemulti(int dummy)
530 static struct cli_state cli;
535 cli_sockopt(&cli, sockops);
537 printf("run_readwritemulti: fname %s\n", randomfname);
538 test = rw_torture3(&cli, randomfname);
540 if (!torture_close_connection(&cli)) {
547 static BOOL run_readwritelarge(int dummy)
549 static struct cli_state cli1;
551 char *lockfname = "\\large.dat";
556 if (!torture_open_connection(&cli1)) {
559 cli_sockopt(&cli1, sockops);
560 memset(buf,'\0',sizeof(buf));
562 cli1.max_xmit = 0x11000;
564 printf("starting readwritelarge\n");
566 cli_unlink(&cli1, lockfname);
568 fnum1 = cli_open(&cli1, lockfname, O_RDWR | O_CREAT | O_EXCL, DENY_NONE);
570 printf("open read/write of %s failed (%s)\n", lockfname, cli_errstr(&cli1));
574 cli_write(&cli1, fnum1, 0, buf, 0, sizeof(buf));
576 if (!cli_close(&cli1, fnum1)) {
577 printf("close failed (%s)\n", cli_errstr(&cli1));
581 if (!cli_qpathinfo(&cli1, lockfname, NULL, NULL, NULL, &fsize, NULL)) {
582 printf("qpathinfo failed (%s)\n", cli_errstr(&cli1));
586 if (fsize == sizeof(buf))
587 printf("readwritelarge test 1 succeeded (size = %x)\n", fsize);
589 printf("readwritelarge test 1 failed (size = %x)\n", fsize);
593 if (!cli_unlink(&cli1, lockfname)) {
594 printf("unlink failed (%s)\n", cli_errstr(&cli1));
598 fnum1 = cli_open(&cli1, lockfname, O_RDWR | O_CREAT | O_EXCL, DENY_NONE);
600 printf("open read/write of %s failed (%s)\n", lockfname, cli_errstr(&cli1));
604 cli_smbwrite(&cli1, fnum1, buf, 0, sizeof(buf));
606 if (!cli_close(&cli1, fnum1)) {
607 printf("close failed (%s)\n", cli_errstr(&cli1));
611 if (!torture_close_connection(&cli1)) {
619 /* run a test that simulates an approximate netbench client load */
620 static BOOL run_netbench(int client)
622 struct cli_state cli;
633 cli_sockopt(&cli, sockops);
637 slprintf(cname,sizeof(fname), "CLIENT%d", client);
639 f = fopen("client.txt", "r");
642 perror("client.txt");
646 while (fgets(line, sizeof(line)-1, f)) {
649 line[strlen(line)-1] = 0;
651 /* printf("[%d] %s\n", line_count, line); */
653 all_string_sub(line,"CLIENT1", cname, sizeof(line));
655 for (i=0;i<20;i++) params[i] = "";
657 /* parse the command parameters */
658 params[0] = strtok(line," ");
660 while (params[i]) params[++i] = strtok(NULL," ");
666 if (strcmp(params[1],"REQUEST") == 0) {
667 if (!strcmp(params[0],"SMBopenX")) {
668 fstrcpy(fname, params[5]);
669 } else if (!strcmp(params[0],"SMBclose")) {
670 nb_close(atoi(params[3]));
671 } else if (!strcmp(params[0],"SMBmkdir")) {
673 } else if (!strcmp(params[0],"CREATE")) {
674 nb_create(params[3], atoi(params[5]));
675 } else if (!strcmp(params[0],"SMBrmdir")) {
677 } else if (!strcmp(params[0],"SMBunlink")) {
678 fstrcpy(fname, params[3]);
679 } else if (!strcmp(params[0],"SMBmv")) {
680 nb_rename(params[3], params[5]);
681 } else if (!strcmp(params[0],"SMBgetatr")) {
682 fstrcpy(fname, params[3]);
683 } else if (!strcmp(params[0],"SMBwrite")) {
684 nb_write(atoi(params[3]),
685 atoi(params[5]), atoi(params[7]));
686 } else if (!strcmp(params[0],"SMBwritebraw")) {
687 nb_write(atoi(params[3]),
688 atoi(params[7]), atoi(params[5]));
689 } else if (!strcmp(params[0],"SMBreadbraw")) {
690 nb_read(atoi(params[3]),
691 atoi(params[7]), atoi(params[5]));
692 } else if (!strcmp(params[0],"SMBread")) {
693 nb_read(atoi(params[3]),
694 atoi(params[5]), atoi(params[7]));
697 if (!strcmp(params[0],"SMBopenX")) {
698 if (!strncmp(params[2], "ERR", 3)) continue;
699 nb_open(fname, atoi(params[3]), atoi(params[5]));
700 } else if (!strcmp(params[0],"SMBgetatr")) {
701 if (!strncmp(params[2], "ERR", 3)) continue;
702 nb_stat(fname, atoi(params[3]));
703 } else if (!strcmp(params[0],"SMBunlink")) {
704 if (!strncmp(params[2], "ERR", 3)) continue;
711 slprintf(fname,sizeof(fname), "CLIENTS/CLIENT%d", client);
717 if (!torture_close_connection(&cli)) {
725 /* run a test that simulates an approximate netbench w9X client load */
726 static BOOL run_nbw95(int dummy)
730 t = create_procs(run_netbench, &correct);
731 /* to produce a netbench result we scale accoding to the
732 netbench measured throughput for the run that produced the
733 sniff that was used to produce client.txt. That run used 2
734 clients and ran for 660 seconds to produce a result of
736 printf("Throughput %g MB/sec (NB=%g MB/sec %g MBit/sec)\n",
737 132*nprocs/t, 0.5*0.5*nprocs*660/t, 2*nprocs*660/t);
741 /* run a test that simulates an approximate netbench wNT client load */
742 static BOOL run_nbwnt(int dummy)
746 t = create_procs(run_netbench, &correct);
747 printf("Throughput %g MB/sec (NB=%g MB/sec %g MBit/sec)\n",
748 132*nprocs/t, 0.5*0.5*nprocs*660/t, 2*nprocs*660/t);
755 This test checks for two things:
757 1) correct support for retaining locks over a close (ie. the server
758 must not use posix semantics)
759 2) support for lock timeouts
761 static BOOL run_locktest1(int dummy)
763 static struct cli_state cli1, cli2;
764 char *fname = "\\lockt1.lck";
765 int fnum1, fnum2, fnum3;
768 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
771 cli_sockopt(&cli1, sockops);
772 cli_sockopt(&cli2, sockops);
774 printf("starting locktest1\n");
776 cli_unlink(&cli1, fname);
778 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
780 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
783 fnum2 = cli_open(&cli1, fname, O_RDWR, DENY_NONE);
785 printf("open2 of %s failed (%s)\n", fname, cli_errstr(&cli1));
788 fnum3 = cli_open(&cli2, fname, O_RDWR, DENY_NONE);
790 printf("open3 of %s failed (%s)\n", fname, cli_errstr(&cli2));
794 if (!cli_lock(&cli1, fnum1, 0, 4, 0, WRITE_LOCK)) {
795 printf("lock1 failed (%s)\n", cli_errstr(&cli1));
800 if (cli_lock(&cli2, fnum3, 0, 4, 0, WRITE_LOCK)) {
801 printf("lock2 succeeded! This is a locking bug\n");
804 if (!check_error(__LINE__, &cli2, ERRDOS, ERRlock,
805 NT_STATUS_LOCK_NOT_GRANTED)) return False;
809 printf("Testing lock timeouts\n");
811 if (cli_lock(&cli2, fnum3, 0, 4, 10*1000, WRITE_LOCK)) {
812 printf("lock3 succeeded! This is a locking bug\n");
815 if (!check_error(__LINE__, &cli2, ERRDOS, ERRlock,
816 NT_STATUS_LOCK_NOT_GRANTED)) return False;
821 printf("error: This server appears not to support timed lock requests\n");
824 if (!cli_close(&cli1, fnum2)) {
825 printf("close1 failed (%s)\n", cli_errstr(&cli1));
829 if (cli_lock(&cli2, fnum3, 0, 4, 0, WRITE_LOCK)) {
830 printf("lock4 succeeded! This is a locking bug\n");
833 if (!check_error(__LINE__, &cli2, ERRDOS, ERRlock,
834 NT_STATUS_LOCK_NOT_GRANTED)) return False;
837 if (!cli_close(&cli1, fnum1)) {
838 printf("close2 failed (%s)\n", cli_errstr(&cli1));
842 if (!cli_close(&cli2, fnum3)) {
843 printf("close3 failed (%s)\n", cli_errstr(&cli2));
847 if (!cli_unlink(&cli1, fname)) {
848 printf("unlink failed (%s)\n", cli_errstr(&cli1));
853 if (!torture_close_connection(&cli1)) {
857 if (!torture_close_connection(&cli2)) {
861 printf("Passed locktest1\n");
866 checks for correct tconX support
868 static BOOL run_tcon_test(int dummy)
870 static struct cli_state cli1;
871 char *fname = "\\tcontest.tmp";
876 if (!torture_open_connection(&cli1)) {
879 cli_sockopt(&cli1, sockops);
881 printf("starting tcontest\n");
883 cli_unlink(&cli1, fname);
885 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
888 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
894 if (cli_write(&cli1, fnum1, 0, buf, 130, 4) != 4)
896 printf("write failed (%s)", cli_errstr(&cli1));
900 if (!cli_send_tconX(&cli1, share, "?????",
901 password, strlen(password)+1)) {
902 printf("%s refused 2nd tree connect (%s)\n", host,
908 if (cli_write(&cli1, fnum1, 0, buf, 130, 4) == 4)
910 printf("write succeeded (%s)", cli_errstr(&cli1));
914 if (cli_close(&cli1, fnum1)) {
915 printf("close2 succeeded (%s)\n", cli_errstr(&cli1));
919 if (!cli_tdis(&cli1)) {
920 printf("tdis failed (%s)\n", cli_errstr(&cli1));
926 if (!cli_close(&cli1, fnum1)) {
927 printf("close2 failed (%s)\n", cli_errstr(&cli1));
931 if (!torture_close_connection(&cli1)) {
935 printf("Passed tcontest\n");
941 This test checks that
943 1) the server supports multiple locking contexts on the one SMB
944 connection, distinguished by PID.
946 2) the server correctly fails overlapping locks made by the same PID (this
947 goes against POSIX behaviour, which is why it is tricky to implement)
949 3) the server denies unlock requests by an incorrect client PID
951 static BOOL run_locktest2(int dummy)
953 static struct cli_state cli;
954 char *fname = "\\lockt2.lck";
955 int fnum1, fnum2, fnum3;
958 if (!torture_open_connection(&cli)) {
962 cli_sockopt(&cli, sockops);
964 printf("starting locktest2\n");
966 cli_unlink(&cli, fname);
970 fnum1 = cli_open(&cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
972 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli));
976 fnum2 = cli_open(&cli, fname, O_RDWR, DENY_NONE);
978 printf("open2 of %s failed (%s)\n", fname, cli_errstr(&cli));
984 fnum3 = cli_open(&cli, fname, O_RDWR, DENY_NONE);
986 printf("open3 of %s failed (%s)\n", fname, cli_errstr(&cli));
992 if (!cli_lock(&cli, fnum1, 0, 4, 0, WRITE_LOCK)) {
993 printf("lock1 failed (%s)\n", cli_errstr(&cli));
997 if (cli_lock(&cli, fnum1, 0, 4, 0, WRITE_LOCK)) {
998 printf("WRITE lock1 succeeded! This is a locking bug\n");
1001 if (!check_error(__LINE__, &cli, ERRDOS, ERRlock,
1002 NT_STATUS_LOCK_NOT_GRANTED)) return False;
1005 if (cli_lock(&cli, fnum2, 0, 4, 0, WRITE_LOCK)) {
1006 printf("WRITE lock2 succeeded! This is a locking bug\n");
1009 if (!check_error(__LINE__, &cli, ERRDOS, ERRlock,
1010 NT_STATUS_LOCK_NOT_GRANTED)) return False;
1013 if (cli_lock(&cli, fnum2, 0, 4, 0, READ_LOCK)) {
1014 printf("READ lock2 succeeded! This is a locking bug\n");
1017 if (!check_error(__LINE__, &cli, ERRDOS, ERRlock,
1018 NT_STATUS_LOCK_NOT_GRANTED)) return False;
1021 if (!cli_lock(&cli, fnum1, 100, 4, 0, WRITE_LOCK)) {
1022 printf("lock at 100 failed (%s)\n", cli_errstr(&cli));
1024 cli_setpid(&cli, 2);
1025 if (cli_unlock(&cli, fnum1, 100, 4)) {
1026 printf("unlock at 100 succeeded! This is a locking bug\n");
1030 if (cli_unlock(&cli, fnum1, 0, 4)) {
1031 printf("unlock1 succeeded! This is a locking bug\n");
1034 if (!check_error(__LINE__, &cli,
1036 NT_STATUS_LOCK_NOT_GRANTED)) return False;
1039 if (cli_unlock(&cli, fnum1, 0, 8)) {
1040 printf("unlock2 succeeded! This is a locking bug\n");
1043 if (!check_error(__LINE__, &cli,
1045 NT_STATUS_LOCK_NOT_GRANTED)) return False;
1048 if (cli_lock(&cli, fnum3, 0, 4, 0, WRITE_LOCK)) {
1049 printf("lock3 succeeded! This is a locking bug\n");
1052 if (!check_error(__LINE__, &cli, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False;
1055 cli_setpid(&cli, 1);
1057 if (!cli_close(&cli, fnum1)) {
1058 printf("close1 failed (%s)\n", cli_errstr(&cli));
1062 if (!cli_close(&cli, fnum2)) {
1063 printf("close2 failed (%s)\n", cli_errstr(&cli));
1067 if (!cli_close(&cli, fnum3)) {
1068 printf("close3 failed (%s)\n", cli_errstr(&cli));
1072 if (!torture_close_connection(&cli)) {
1076 printf("locktest2 finished\n");
1083 This test checks that
1085 1) the server supports the full offset range in lock requests
1087 static BOOL run_locktest3(int dummy)
1089 static struct cli_state cli1, cli2;
1090 char *fname = "\\lockt3.lck";
1091 int fnum1, fnum2, i;
1093 BOOL correct = True;
1095 #define NEXT_OFFSET offset += (~(uint32)0) / numops
1097 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
1100 cli_sockopt(&cli1, sockops);
1101 cli_sockopt(&cli2, sockops);
1103 printf("starting locktest3\n");
1105 cli_unlink(&cli1, fname);
1107 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1109 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
1112 fnum2 = cli_open(&cli2, fname, O_RDWR, DENY_NONE);
1114 printf("open2 of %s failed (%s)\n", fname, cli_errstr(&cli2));
1118 for (offset=i=0;i<numops;i++) {
1120 if (!cli_lock(&cli1, fnum1, offset-1, 1, 0, WRITE_LOCK)) {
1121 printf("lock1 %d failed (%s)\n",
1127 if (!cli_lock(&cli2, fnum2, offset-2, 1, 0, WRITE_LOCK)) {
1128 printf("lock2 %d failed (%s)\n",
1135 for (offset=i=0;i<numops;i++) {
1138 if (cli_lock(&cli1, fnum1, offset-2, 1, 0, WRITE_LOCK)) {
1139 printf("error: lock1 %d succeeded!\n", i);
1143 if (cli_lock(&cli2, fnum2, offset-1, 1, 0, WRITE_LOCK)) {
1144 printf("error: lock2 %d succeeded!\n", i);
1148 if (cli_lock(&cli1, fnum1, offset-1, 1, 0, WRITE_LOCK)) {
1149 printf("error: lock3 %d succeeded!\n", i);
1153 if (cli_lock(&cli2, fnum2, offset-2, 1, 0, WRITE_LOCK)) {
1154 printf("error: lock4 %d succeeded!\n", i);
1159 for (offset=i=0;i<numops;i++) {
1162 if (!cli_unlock(&cli1, fnum1, offset-1, 1)) {
1163 printf("unlock1 %d failed (%s)\n",
1169 if (!cli_unlock(&cli2, fnum2, offset-2, 1)) {
1170 printf("unlock2 %d failed (%s)\n",
1177 if (!cli_close(&cli1, fnum1)) {
1178 printf("close1 failed (%s)\n", cli_errstr(&cli1));
1182 if (!cli_close(&cli2, fnum2)) {
1183 printf("close2 failed (%s)\n", cli_errstr(&cli2));
1187 if (!cli_unlink(&cli1, fname)) {
1188 printf("unlink failed (%s)\n", cli_errstr(&cli1));
1192 if (!torture_close_connection(&cli1)) {
1196 if (!torture_close_connection(&cli2)) {
1200 printf("finished locktest3\n");
1205 #define EXPECTED(ret, v) if ((ret) != (v)) { \
1206 printf("** "); correct = False; \
1210 looks at overlapping locks
1212 static BOOL run_locktest4(int dummy)
1214 static struct cli_state cli1, cli2;
1215 char *fname = "\\lockt4.lck";
1216 int fnum1, fnum2, f;
1219 BOOL correct = True;
1221 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
1225 cli_sockopt(&cli1, sockops);
1226 cli_sockopt(&cli2, sockops);
1228 printf("starting locktest4\n");
1230 cli_unlink(&cli1, fname);
1232 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1233 fnum2 = cli_open(&cli2, fname, O_RDWR, DENY_NONE);
1235 memset(buf, 0, sizeof(buf));
1237 if (cli_write(&cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
1238 printf("Failed to create file\n");
1243 ret = cli_lock(&cli1, fnum1, 0, 4, 0, WRITE_LOCK) &&
1244 cli_lock(&cli1, fnum1, 2, 4, 0, WRITE_LOCK);
1245 EXPECTED(ret, False);
1246 printf("the same process %s set overlapping write locks\n", ret?"can":"cannot");
1248 ret = cli_lock(&cli1, fnum1, 10, 4, 0, READ_LOCK) &&
1249 cli_lock(&cli1, fnum1, 12, 4, 0, READ_LOCK);
1250 EXPECTED(ret, True);
1251 printf("the same process %s set overlapping read locks\n", ret?"can":"cannot");
1253 ret = cli_lock(&cli1, fnum1, 20, 4, 0, WRITE_LOCK) &&
1254 cli_lock(&cli2, fnum2, 22, 4, 0, WRITE_LOCK);
1255 EXPECTED(ret, False);
1256 printf("a different connection %s set overlapping write locks\n", ret?"can":"cannot");
1258 ret = cli_lock(&cli1, fnum1, 30, 4, 0, READ_LOCK) &&
1259 cli_lock(&cli2, fnum2, 32, 4, 0, READ_LOCK);
1260 EXPECTED(ret, True);
1261 printf("a different connection %s set overlapping read locks\n", ret?"can":"cannot");
1263 ret = (cli_setpid(&cli1, 1), cli_lock(&cli1, fnum1, 40, 4, 0, WRITE_LOCK)) &&
1264 (cli_setpid(&cli1, 2), cli_lock(&cli1, fnum1, 42, 4, 0, WRITE_LOCK));
1265 EXPECTED(ret, False);
1266 printf("a different pid %s set overlapping write locks\n", ret?"can":"cannot");
1268 ret = (cli_setpid(&cli1, 1), cli_lock(&cli1, fnum1, 50, 4, 0, READ_LOCK)) &&
1269 (cli_setpid(&cli1, 2), cli_lock(&cli1, fnum1, 52, 4, 0, READ_LOCK));
1270 EXPECTED(ret, True);
1271 printf("a different pid %s set overlapping read locks\n", ret?"can":"cannot");
1273 ret = cli_lock(&cli1, fnum1, 60, 4, 0, READ_LOCK) &&
1274 cli_lock(&cli1, fnum1, 60, 4, 0, READ_LOCK);
1275 EXPECTED(ret, True);
1276 printf("the same process %s set the same read lock twice\n", ret?"can":"cannot");
1278 ret = cli_lock(&cli1, fnum1, 70, 4, 0, WRITE_LOCK) &&
1279 cli_lock(&cli1, fnum1, 70, 4, 0, WRITE_LOCK);
1280 EXPECTED(ret, False);
1281 printf("the same process %s set the same write lock twice\n", ret?"can":"cannot");
1283 ret = cli_lock(&cli1, fnum1, 80, 4, 0, READ_LOCK) &&
1284 cli_lock(&cli1, fnum1, 80, 4, 0, WRITE_LOCK);
1285 EXPECTED(ret, False);
1286 printf("the same process %s overlay a read lock with a write lock\n", ret?"can":"cannot");
1288 ret = cli_lock(&cli1, fnum1, 90, 4, 0, WRITE_LOCK) &&
1289 cli_lock(&cli1, fnum1, 90, 4, 0, READ_LOCK);
1290 EXPECTED(ret, True);
1291 printf("the same process %s overlay a write lock with a read lock\n", ret?"can":"cannot");
1293 ret = (cli_setpid(&cli1, 1), cli_lock(&cli1, fnum1, 100, 4, 0, WRITE_LOCK)) &&
1294 (cli_setpid(&cli1, 2), cli_lock(&cli1, fnum1, 100, 4, 0, READ_LOCK));
1295 EXPECTED(ret, False);
1296 printf("a different pid %s overlay a write lock with a read lock\n", ret?"can":"cannot");
1298 ret = cli_lock(&cli1, fnum1, 110, 4, 0, READ_LOCK) &&
1299 cli_lock(&cli1, fnum1, 112, 4, 0, READ_LOCK) &&
1300 cli_unlock(&cli1, fnum1, 110, 6);
1301 EXPECTED(ret, False);
1302 printf("the same process %s coalesce read locks\n", ret?"can":"cannot");
1305 ret = cli_lock(&cli1, fnum1, 120, 4, 0, WRITE_LOCK) &&
1306 (cli_read(&cli2, fnum2, buf, 120, 4) == 4);
1307 EXPECTED(ret, False);
1308 printf("this server %s strict write locking\n", ret?"doesn't do":"does");
1310 ret = cli_lock(&cli1, fnum1, 130, 4, 0, READ_LOCK) &&
1311 (cli_write(&cli2, fnum2, 0, buf, 130, 4) == 4);
1312 EXPECTED(ret, False);
1313 printf("this server %s strict read locking\n", ret?"doesn't do":"does");
1316 ret = cli_lock(&cli1, fnum1, 140, 4, 0, READ_LOCK) &&
1317 cli_lock(&cli1, fnum1, 140, 4, 0, READ_LOCK) &&
1318 cli_unlock(&cli1, fnum1, 140, 4) &&
1319 cli_unlock(&cli1, fnum1, 140, 4);
1320 EXPECTED(ret, True);
1321 printf("this server %s do recursive read locking\n", ret?"does":"doesn't");
1324 ret = cli_lock(&cli1, fnum1, 150, 4, 0, WRITE_LOCK) &&
1325 cli_lock(&cli1, fnum1, 150, 4, 0, READ_LOCK) &&
1326 cli_unlock(&cli1, fnum1, 150, 4) &&
1327 (cli_read(&cli2, fnum2, buf, 150, 4) == 4) &&
1328 !(cli_write(&cli2, fnum2, 0, buf, 150, 4) == 4) &&
1329 cli_unlock(&cli1, fnum1, 150, 4);
1330 EXPECTED(ret, True);
1331 printf("this server %s do recursive lock overlays\n", ret?"does":"doesn't");
1333 ret = cli_lock(&cli1, fnum1, 160, 4, 0, READ_LOCK) &&
1334 cli_unlock(&cli1, fnum1, 160, 4) &&
1335 (cli_write(&cli2, fnum2, 0, buf, 160, 4) == 4) &&
1336 (cli_read(&cli2, fnum2, buf, 160, 4) == 4);
1337 EXPECTED(ret, True);
1338 printf("the same process %s remove a read lock using write locking\n", ret?"can":"cannot");
1340 ret = cli_lock(&cli1, fnum1, 170, 4, 0, WRITE_LOCK) &&
1341 cli_unlock(&cli1, fnum1, 170, 4) &&
1342 (cli_write(&cli2, fnum2, 0, buf, 170, 4) == 4) &&
1343 (cli_read(&cli2, fnum2, buf, 170, 4) == 4);
1344 EXPECTED(ret, True);
1345 printf("the same process %s remove a write lock using read locking\n", ret?"can":"cannot");
1347 ret = cli_lock(&cli1, fnum1, 190, 4, 0, WRITE_LOCK) &&
1348 cli_lock(&cli1, fnum1, 190, 4, 0, READ_LOCK) &&
1349 cli_unlock(&cli1, fnum1, 190, 4) &&
1350 !(cli_write(&cli2, fnum2, 0, buf, 190, 4) == 4) &&
1351 (cli_read(&cli2, fnum2, buf, 190, 4) == 4);
1352 EXPECTED(ret, True);
1353 printf("the same process %s remove the first lock first\n", ret?"does":"doesn't");
1355 cli_close(&cli1, fnum1);
1356 cli_close(&cli2, fnum2);
1357 fnum1 = cli_open(&cli1, fname, O_RDWR, DENY_NONE);
1358 f = cli_open(&cli1, fname, O_RDWR, DENY_NONE);
1359 ret = cli_lock(&cli1, fnum1, 0, 8, 0, READ_LOCK) &&
1360 cli_lock(&cli1, f, 0, 1, 0, READ_LOCK) &&
1361 cli_close(&cli1, fnum1) &&
1362 ((fnum1 = cli_open(&cli1, fname, O_RDWR, DENY_NONE)) != -1) &&
1363 cli_lock(&cli1, fnum1, 7, 1, 0, WRITE_LOCK);
1364 cli_close(&cli1, f);
1365 EXPECTED(ret, True);
1366 printf("the server %s have the NT byte range lock bug\n", !ret?"does":"doesn't");
1369 cli_close(&cli1, fnum1);
1370 cli_close(&cli2, fnum2);
1371 cli_unlink(&cli1, fname);
1372 torture_close_connection(&cli1);
1373 torture_close_connection(&cli2);
1375 printf("finished locktest4\n");
1380 looks at lock upgrade/downgrade.
1382 static BOOL run_locktest5(int dummy)
1384 static struct cli_state cli1, cli2;
1385 char *fname = "\\lockt5.lck";
1386 int fnum1, fnum2, fnum3;
1389 BOOL correct = True;
1391 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
1395 cli_sockopt(&cli1, sockops);
1396 cli_sockopt(&cli2, sockops);
1398 printf("starting locktest5\n");
1400 cli_unlink(&cli1, fname);
1402 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1403 fnum2 = cli_open(&cli2, fname, O_RDWR, DENY_NONE);
1404 fnum3 = cli_open(&cli1, fname, O_RDWR, DENY_NONE);
1406 memset(buf, 0, sizeof(buf));
1408 if (cli_write(&cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
1409 printf("Failed to create file\n");
1414 /* Check for NT bug... */
1415 ret = cli_lock(&cli1, fnum1, 0, 8, 0, READ_LOCK) &&
1416 cli_lock(&cli1, fnum3, 0, 1, 0, READ_LOCK);
1417 cli_close(&cli1, fnum1);
1418 fnum1 = cli_open(&cli1, fname, O_RDWR, DENY_NONE);
1419 ret = cli_lock(&cli1, fnum1, 7, 1, 0, WRITE_LOCK);
1420 EXPECTED(ret, True);
1421 printf("this server %s the NT locking bug\n", ret ? "doesn't have" : "has");
1422 cli_close(&cli1, fnum1);
1423 fnum1 = cli_open(&cli1, fname, O_RDWR, DENY_NONE);
1424 cli_unlock(&cli1, fnum3, 0, 1);
1426 ret = cli_lock(&cli1, fnum1, 0, 4, 0, WRITE_LOCK) &&
1427 cli_lock(&cli1, fnum1, 1, 1, 0, READ_LOCK);
1428 EXPECTED(ret, True);
1429 printf("the same process %s overlay a write with a read lock\n", ret?"can":"cannot");
1431 ret = cli_lock(&cli2, fnum2, 0, 4, 0, READ_LOCK);
1432 EXPECTED(ret, False);
1434 printf("a different processs %s get a read lock on the first process lock stack\n", ret?"can":"cannot");
1436 /* Unlock the process 2 lock. */
1437 cli_unlock(&cli2, fnum2, 0, 4);
1439 ret = cli_lock(&cli1, fnum3, 0, 4, 0, READ_LOCK);
1440 EXPECTED(ret, False);
1442 printf("the same processs on a different fnum %s get a read lock\n", ret?"can":"cannot");
1444 /* Unlock the process 1 fnum3 lock. */
1445 cli_unlock(&cli1, fnum3, 0, 4);
1447 /* Stack 2 more locks here. */
1448 ret = cli_lock(&cli1, fnum1, 0, 4, 0, READ_LOCK) &&
1449 cli_lock(&cli1, fnum1, 0, 4, 0, READ_LOCK);
1451 EXPECTED(ret, True);
1452 printf("the same process %s stack read locks\n", ret?"can":"cannot");
1454 /* Unlock the first process lock, then check this was the WRITE lock that was
1457 ret = cli_unlock(&cli1, fnum1, 0, 4) &&
1458 cli_lock(&cli2, fnum2, 0, 4, 0, READ_LOCK);
1460 EXPECTED(ret, True);
1461 printf("the first unlock removes the %s lock\n", ret?"WRITE":"READ");
1463 /* Unlock the process 2 lock. */
1464 cli_unlock(&cli2, fnum2, 0, 4);
1466 /* We should have 3 stacked locks here. Ensure we need to do 3 unlocks. */
1468 ret = cli_unlock(&cli1, fnum1, 1, 1) &&
1469 cli_unlock(&cli1, fnum1, 0, 4) &&
1470 cli_unlock(&cli1, fnum1, 0, 4);
1472 EXPECTED(ret, True);
1473 printf("the same process %s unlock the stack of 4 locks\n", ret?"can":"cannot");
1475 /* Ensure the next unlock fails. */
1476 ret = cli_unlock(&cli1, fnum1, 0, 4);
1477 EXPECTED(ret, False);
1478 printf("the same process %s count the lock stack\n", !ret?"can":"cannot");
1480 /* Ensure connection 2 can get a write lock. */
1481 ret = cli_lock(&cli2, fnum2, 0, 4, 0, WRITE_LOCK);
1482 EXPECTED(ret, True);
1484 printf("a different processs %s get a write lock on the unlocked stack\n", ret?"can":"cannot");
1488 cli_close(&cli1, fnum1);
1489 cli_close(&cli2, fnum2);
1490 cli_unlink(&cli1, fname);
1491 if (!torture_close_connection(&cli1)) {
1494 if (!torture_close_connection(&cli2)) {
1498 printf("finished locktest5\n");
1504 test whether fnums and tids open on one VC are available on another (a major
1507 static BOOL run_fdpasstest(int dummy)
1509 static struct cli_state cli1, cli2, cli3;
1510 char *fname = "\\fdpass.tst";
1514 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
1517 cli_sockopt(&cli1, sockops);
1518 cli_sockopt(&cli2, sockops);
1520 printf("starting fdpasstest\n");
1522 cli_unlink(&cli1, fname);
1524 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1526 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
1530 if (cli_write(&cli1, fnum1, 0, "hello world\n", 0, 13) != 13) {
1531 printf("write failed (%s)\n", cli_errstr(&cli1));
1536 cli3.vuid = cli1.vuid;
1537 cli3.cnum = cli1.cnum;
1538 cli3.pid = cli1.pid;
1540 if (cli_read(&cli3, fnum1, buf, 0, 13) == 13) {
1541 printf("read succeeded! nasty security hole [%s]\n",
1546 cli_close(&cli1, fnum1);
1547 cli_unlink(&cli1, fname);
1549 torture_close_connection(&cli1);
1550 torture_close_connection(&cli2);
1552 printf("finished fdpasstest\n");
1558 This test checks that
1560 1) the server does not allow an unlink on a file that is open
1562 static BOOL run_unlinktest(int dummy)
1564 static struct cli_state cli;
1565 char *fname = "\\unlink.tst";
1567 BOOL correct = True;
1569 if (!torture_open_connection(&cli)) {
1573 cli_sockopt(&cli, sockops);
1575 printf("starting unlink test\n");
1577 cli_unlink(&cli, fname);
1579 cli_setpid(&cli, 1);
1581 fnum = cli_open(&cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1583 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli));
1587 if (cli_unlink(&cli, fname)) {
1588 printf("error: server allowed unlink on an open file\n");
1591 correct = check_error(__LINE__, &cli, ERRDOS, ERRbadshare,
1592 NT_STATUS_SHARING_VIOLATION);
1595 cli_close(&cli, fnum);
1596 cli_unlink(&cli, fname);
1598 if (!torture_close_connection(&cli)) {
1602 printf("unlink test finished\n");
1609 test how many open files this server supports on the one socket
1611 static BOOL run_maxfidtest(int dummy)
1613 static struct cli_state cli;
1614 char *template = "\\maxfid.%d.%d";
1616 int fnums[0x11000], i;
1618 BOOL correct = True;
1623 printf("failed to connect\n");
1627 cli_sockopt(&cli, sockops);
1629 for (i=0; i<0x11000; i++) {
1630 slprintf(fname,sizeof(fname)-1,template, i,(int)getpid());
1631 if ((fnums[i] = cli_open(&cli, fname,
1632 O_RDWR|O_CREAT|O_TRUNC, DENY_NONE)) ==
1634 printf("open of %s failed (%s)\n",
1635 fname, cli_errstr(&cli));
1636 printf("maximum fnum is %d\n", i);
1644 printf("cleaning up\n");
1646 slprintf(fname,sizeof(fname)-1,template, i,(int)getpid());
1647 cli_close(&cli, fnums[i]);
1648 if (!cli_unlink(&cli, fname)) {
1649 printf("unlink of %s failed (%s)\n",
1650 fname, cli_errstr(&cli));
1657 printf("maxfid test finished\n");
1658 if (!torture_close_connection(&cli)) {
1664 /* generate a random buffer */
1665 static void rand_buf(char *buf, int len)
1668 *buf = (char)sys_random();
1673 /* send smb negprot commands, not reading the response */
1674 static BOOL run_negprot_nowait(int dummy)
1677 static struct cli_state cli;
1678 BOOL correct = True;
1680 printf("starting negprot nowait test\n");
1682 if (!open_nbt_connection(&cli)) {
1686 for (i=0;i<50000;i++) {
1687 cli_negprot_send(&cli);
1690 if (!torture_close_connection(&cli)) {
1694 printf("finished negprot nowait test\n");
1700 /* send random IPC commands */
1701 static BOOL run_randomipc(int dummy)
1703 char *rparam = NULL;
1707 int api, param_len, i;
1708 static struct cli_state cli;
1709 BOOL correct = True;
1712 printf("starting random ipc test\n");
1714 if (!torture_open_connection(&cli)) {
1718 for (i=0;i<count;i++) {
1719 api = sys_random() % 500;
1720 param_len = (sys_random() % 64);
1722 rand_buf(param, param_len);
1727 param, param_len, 8,
1728 NULL, 0, BUFFER_SIZE,
1732 printf("%d/%d\r", i,count);
1735 printf("%d/%d\n", i, count);
1737 if (!torture_close_connection(&cli)) {
1741 printf("finished random ipc test\n");
1748 static void browse_callback(const char *sname, uint32 stype,
1749 const char *comment, void *state)
1751 printf("\t%20.20s %08x %s\n", sname, stype, comment);
1757 This test checks the browse list code
1760 static BOOL run_browsetest(int dummy)
1762 static struct cli_state cli;
1763 BOOL correct = True;
1765 printf("starting browse test\n");
1767 if (!torture_open_connection(&cli)) {
1771 printf("domain list:\n");
1772 cli_NetServerEnum(&cli, cli.server_domain,
1773 SV_TYPE_DOMAIN_ENUM,
1774 browse_callback, NULL);
1776 printf("machine list:\n");
1777 cli_NetServerEnum(&cli, cli.server_domain,
1779 browse_callback, NULL);
1781 if (!torture_close_connection(&cli)) {
1785 printf("browse test finished\n");
1793 This checks how the getatr calls works
1795 static BOOL run_attrtest(int dummy)
1797 static struct cli_state cli;
1800 char *fname = "\\attrib.tst";
1801 BOOL correct = True;
1803 printf("starting attrib test\n");
1805 if (!torture_open_connection(&cli)) {
1809 cli_unlink(&cli, fname);
1810 fnum = cli_open(&cli, fname,
1811 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1812 cli_close(&cli, fnum);
1813 if (!cli_getatr(&cli, fname, NULL, NULL, &t)) {
1814 printf("getatr failed (%s)\n", cli_errstr(&cli));
1818 if (abs(t - time(NULL)) > 2) {
1819 printf("ERROR: SMBgetatr bug. time is %s",
1825 t2 = t-60*60*24; /* 1 day ago */
1827 if (!cli_setatr(&cli, fname, 0, t2)) {
1828 printf("setatr failed (%s)\n", cli_errstr(&cli));
1832 if (!cli_getatr(&cli, fname, NULL, NULL, &t)) {
1833 printf("getatr failed (%s)\n", cli_errstr(&cli));
1838 printf("ERROR: getatr/setatr bug. times are\n%s",
1840 printf("%s", ctime(&t2));
1844 cli_unlink(&cli, fname);
1846 if (!torture_close_connection(&cli)) {
1850 printf("attrib test finished\n");
1857 This checks a couple of trans2 calls
1859 static BOOL run_trans2test(int dummy)
1861 static struct cli_state cli;
1864 time_t c_time, a_time, m_time, w_time, m_time2;
1865 char *fname = "\\trans2.tst";
1866 char *dname = "\\trans2";
1867 char *fname2 = "\\trans2\\trans2.tst";
1868 BOOL correct = True;
1870 printf("starting trans2 test\n");
1872 if (!torture_open_connection(&cli)) {
1876 cli_unlink(&cli, fname);
1877 fnum = cli_open(&cli, fname,
1878 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1879 if (!cli_qfileinfo(&cli, fnum, NULL, &size, &c_time, &a_time, &m_time,
1881 printf("ERROR: qfileinfo failed (%s)\n", cli_errstr(&cli));
1884 cli_close(&cli, fnum);
1888 cli_unlink(&cli, fname);
1889 fnum = cli_open(&cli, fname,
1890 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1892 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli));
1895 cli_close(&cli, fnum);
1897 if (!cli_qpathinfo(&cli, fname, &c_time, &a_time, &m_time, &size, NULL)) {
1898 printf("ERROR: qpathinfo failed (%s)\n", cli_errstr(&cli));
1901 if (c_time != m_time) {
1902 printf("create time=%s", ctime(&c_time));
1903 printf("modify time=%s", ctime(&m_time));
1904 printf("This system appears to have sticky create times\n");
1907 if (a_time % (60*60) == 0) {
1908 printf("access time=%s", ctime(&a_time));
1909 printf("This system appears to set a midnight access time\n");
1913 if (abs(m_time - time(NULL)) > 60*60*24*7) {
1914 printf("ERROR: totally incorrect times - maybe word reversed? mtime=%s", ctime(&m_time));
1920 cli_unlink(&cli, fname);
1921 fnum = cli_open(&cli, fname,
1922 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1923 cli_close(&cli, fnum);
1924 if (!cli_qpathinfo2(&cli, fname, &c_time, &a_time, &m_time,
1925 &w_time, &size, NULL, NULL)) {
1926 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli));
1929 if (w_time < 60*60*24*2) {
1930 printf("write time=%s", ctime(&w_time));
1931 printf("This system appears to set a initial 0 write time\n");
1936 cli_unlink(&cli, fname);
1939 /* check if the server updates the directory modification time
1940 when creating a new file */
1941 if (!cli_mkdir(&cli, dname)) {
1942 printf("ERROR: mkdir failed (%s)\n", cli_errstr(&cli));
1946 if (!cli_qpathinfo2(&cli, "\\trans2\\", &c_time, &a_time, &m_time,
1947 &w_time, &size, NULL, NULL)) {
1948 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli));
1952 fnum = cli_open(&cli, fname2,
1953 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1954 cli_write(&cli, fnum, 0, (char *)&fnum, 0, sizeof(fnum));
1955 cli_close(&cli, fnum);
1956 if (!cli_qpathinfo2(&cli, "\\trans2\\", &c_time, &a_time, &m_time2,
1957 &w_time, &size, NULL, NULL)) {
1958 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli));
1961 if (m_time2 == m_time) {
1962 printf("This system does not update directory modification times\n");
1966 cli_unlink(&cli, fname2);
1967 cli_rmdir(&cli, dname);
1969 if (!torture_close_connection(&cli)) {
1973 printf("trans2 test finished\n");
1979 This checks new W2K calls.
1982 static BOOL new_trans(struct cli_state *pcli, int fnum, int level)
1985 BOOL correct = True;
1987 memset(buf, 0xff, sizeof(buf));
1989 if (!cli_qfileinfo_test(pcli, fnum, level, buf)) {
1990 printf("ERROR: qfileinfo (%d) failed (%s)\n", level, cli_errstr(pcli));
1993 printf("qfileinfo: level %d\n", level);
1994 dump_data(0, buf, 256);
2000 static BOOL run_w2ktest(int dummy)
2002 static struct cli_state cli;
2004 char *fname = "\\w2ktest\\w2k.tst";
2006 BOOL correct = True;
2008 printf("starting w2k test\n");
2010 if (!torture_open_connection(&cli)) {
2014 fnum = cli_open(&cli, fname,
2015 O_RDWR | O_CREAT , DENY_NONE);
2017 for (level = 1004; level < 1040; level++) {
2018 new_trans(&cli, fnum, level);
2021 cli_close(&cli, fnum);
2023 if (!torture_close_connection(&cli)) {
2027 printf("w2k test finished\n");
2034 this is a harness for some oplock tests
2036 static BOOL run_oplock1(int dummy)
2038 static struct cli_state cli1;
2039 char *fname = "\\lockt1.lck";
2041 BOOL correct = True;
2043 printf("starting oplock test 1\n");
2045 if (!torture_open_connection(&cli1)) {
2049 cli_unlink(&cli1, fname);
2051 cli_sockopt(&cli1, sockops);
2053 cli1.use_oplocks = True;
2055 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2057 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2061 cli1.use_oplocks = False;
2063 cli_unlink(&cli1, fname);
2064 cli_unlink(&cli1, fname);
2066 if (!cli_close(&cli1, fnum1)) {
2067 printf("close2 failed (%s)\n", cli_errstr(&cli1));
2071 if (!cli_unlink(&cli1, fname)) {
2072 printf("unlink failed (%s)\n", cli_errstr(&cli1));
2076 if (!torture_close_connection(&cli1)) {
2080 printf("finished oplock test 1\n");
2085 static BOOL run_oplock2(int dummy)
2087 static struct cli_state cli1, cli2;
2088 char *fname = "\\lockt2.lck";
2090 int saved_use_oplocks = use_oplocks;
2092 BOOL correct = True;
2093 volatile BOOL *shared_correct;
2095 shared_correct = (volatile BOOL *)shm_setup(sizeof(BOOL));
2096 *shared_correct = True;
2098 use_level_II_oplocks = True;
2101 printf("starting oplock test 2\n");
2103 if (!torture_open_connection(&cli1)) {
2104 use_level_II_oplocks = False;
2105 use_oplocks = saved_use_oplocks;
2109 cli1.use_oplocks = True;
2110 cli1.use_level_II_oplocks = True;
2112 if (!torture_open_connection(&cli2)) {
2113 use_level_II_oplocks = False;
2114 use_oplocks = saved_use_oplocks;
2118 cli2.use_oplocks = True;
2119 cli2.use_level_II_oplocks = True;
2121 cli_unlink(&cli1, fname);
2123 cli_sockopt(&cli1, sockops);
2124 cli_sockopt(&cli2, sockops);
2126 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2128 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2132 /* Don't need the globals any more. */
2133 use_level_II_oplocks = False;
2134 use_oplocks = saved_use_oplocks;
2138 fnum2 = cli_open(&cli2, fname, O_RDWR, DENY_NONE);
2140 printf("second open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2141 *shared_correct = False;
2147 if (!cli_close(&cli2, fnum2)) {
2148 printf("close2 failed (%s)\n", cli_errstr(&cli1));
2149 *shared_correct = False;
2157 /* Ensure cli1 processes the break. */
2159 if (cli_read(&cli1, fnum1, buf, 0, 4) != 4) {
2160 printf("read on fnum1 failed (%s)\n", cli_errstr(&cli1));
2164 /* Should now be at level II. */
2165 /* Test if sending a write locks causes a break to none. */
2167 if (!cli_lock(&cli1, fnum1, 0, 4, 0, READ_LOCK)) {
2168 printf("lock failed (%s)\n", cli_errstr(&cli1));
2172 cli_unlock(&cli1, fnum1, 0, 4);
2176 if (!cli_lock(&cli1, fnum1, 0, 4, 0, WRITE_LOCK)) {
2177 printf("lock failed (%s)\n", cli_errstr(&cli1));
2181 cli_unlock(&cli1, fnum1, 0, 4);
2185 cli_read(&cli1, fnum1, buf, 0, 4);
2188 if (cli_write(&cli1, fnum1, 0, buf, 0, 4) != 4) {
2189 printf("write on fnum1 failed (%s)\n", cli_errstr(&cli1));
2194 if (!cli_close(&cli1, fnum1)) {
2195 printf("close1 failed (%s)\n", cli_errstr(&cli1));
2201 if (!cli_unlink(&cli1, fname)) {
2202 printf("unlink failed (%s)\n", cli_errstr(&cli1));
2206 if (!torture_close_connection(&cli1)) {
2210 if (!*shared_correct) {
2214 printf("finished oplock test 2\n");
2219 /* handler for oplock 3 tests */
2220 static BOOL oplock3_handler(struct cli_state *cli, int fnum, unsigned char level)
2222 printf("got oplock break fnum=%d level=%d\n",
2224 return cli_oplock_ack(cli, fnum, level);
2227 static BOOL run_oplock3(int dummy)
2229 static struct cli_state cli;
2230 char *fname = "\\oplockt3.dat";
2232 char buf[4] = "abcd";
2233 BOOL correct = True;
2234 volatile BOOL *shared_correct;
2236 shared_correct = (volatile BOOL *)shm_setup(sizeof(BOOL));
2237 *shared_correct = True;
2239 printf("starting oplock test 3\n");
2244 use_level_II_oplocks = True;
2245 if (!torture_open_connection(&cli)) {
2246 *shared_correct = False;
2250 /* try to trigger a oplock break in parent */
2251 fnum = cli_open(&cli, fname, O_RDWR, DENY_NONE);
2252 cli_write(&cli, fnum, 0, buf, 0, 4);
2258 use_level_II_oplocks = True;
2259 if (!torture_open_connection(&cli)) {
2262 cli_oplock_handler(&cli, oplock3_handler);
2263 fnum = cli_open(&cli, fname, O_RDWR|O_CREAT, DENY_NONE);
2264 cli_write(&cli, fnum, 0, buf, 0, 4);
2265 cli_close(&cli, fnum);
2266 fnum = cli_open(&cli, fname, O_RDWR, DENY_NONE);
2267 cli.timeout = 20000;
2268 cli_receive_smb(&cli);
2269 printf("finished oplock test 3\n");
2271 return (correct && *shared_correct);
2273 /* What are we looking for here? What's sucess and what's FAILURE? */
2279 Test delete on close semantics.
2281 static BOOL run_deletetest(int dummy)
2283 static struct cli_state cli1;
2284 static struct cli_state cli2;
2285 char *fname = "\\delete.file";
2287 BOOL correct = True;
2289 printf("starting delete test\n");
2291 if (!torture_open_connection(&cli1)) {
2295 cli_sockopt(&cli1, sockops);
2297 /* Test 1 - this should *NOT* delete the file on close. */
2299 cli_setatr(&cli1, fname, 0, 0);
2300 cli_unlink(&cli1, fname);
2302 fnum1 = cli_nt_create_full(&cli1, fname, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL,
2303 FILE_SHARE_DELETE, FILE_OVERWRITE_IF,
2304 DELETE_ON_CLOSE_FLAG);
2307 printf("[1] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2311 if (!cli_close(&cli1, fnum1)) {
2312 printf("[1] close failed (%s)\n", cli_errstr(&cli1));
2316 fnum1 = cli_open(&cli1, fname, O_RDWR, DENY_NONE);
2318 printf("[1] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2322 if (!cli_close(&cli1, fnum1)) {
2323 printf("[1] close failed (%s)\n", cli_errstr(&cli1));
2327 printf("first delete on close test succeeded.\n");
2329 /* Test 2 - this should delete the file on close. */
2331 cli_setatr(&cli1, fname, 0, 0);
2332 cli_unlink(&cli1, fname);
2334 fnum1 = cli_nt_create_full(&cli1, fname, GENERIC_ALL_ACCESS,
2335 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
2336 FILE_OVERWRITE_IF, 0);
2339 printf("[2] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2343 if (!cli_nt_delete_on_close(&cli1, fnum1, True)) {
2344 printf("[2] setting delete_on_close failed (%s)\n", cli_errstr(&cli1));
2348 if (!cli_close(&cli1, fnum1)) {
2349 printf("[2] close failed (%s)\n", cli_errstr(&cli1));
2353 fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_NONE);
2355 printf("[2] open of %s succeeded should have been deleted on close !\n", fname);
2356 if (!cli_close(&cli1, fnum1)) {
2357 printf("[2] close failed (%s)\n", cli_errstr(&cli1));
2360 cli_unlink(&cli1, fname);
2362 printf("second delete on close test succeeded.\n");
2365 cli_setatr(&cli1, fname, 0, 0);
2366 cli_unlink(&cli1, fname);
2368 fnum1 = cli_nt_create_full(&cli1, fname, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL,
2369 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0);
2372 printf("[3] open - 1 of %s failed (%s)\n", fname, cli_errstr(&cli1));
2376 /* This should fail with a sharing violation - open for delete is only compatible
2377 with SHARE_DELETE. */
2379 fnum2 = cli_nt_create_full(&cli1, fname, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
2380 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0);
2383 printf("[3] open - 2 of %s succeeded - should have failed.\n", fname);
2387 /* This should succeed. */
2389 fnum2 = cli_nt_create_full(&cli1, fname, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
2390 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0);
2393 printf("[3] open - 2 of %s failed (%s)\n", fname, cli_errstr(&cli1));
2397 if (!cli_nt_delete_on_close(&cli1, fnum1, True)) {
2398 printf("[3] setting delete_on_close failed (%s)\n", cli_errstr(&cli1));
2402 if (!cli_close(&cli1, fnum1)) {
2403 printf("[3] close 1 failed (%s)\n", cli_errstr(&cli1));
2407 if (!cli_close(&cli1, fnum2)) {
2408 printf("[3] close 2 failed (%s)\n", cli_errstr(&cli1));
2412 /* This should fail - file should no longer be there. */
2414 fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_NONE);
2416 printf("[3] open of %s succeeded should have been deleted on close !\n", fname);
2417 if (!cli_close(&cli1, fnum1)) {
2418 printf("[3] close failed (%s)\n", cli_errstr(&cli1));
2420 cli_unlink(&cli1, fname);
2423 printf("third delete on close test succeeded.\n");
2426 cli_setatr(&cli1, fname, 0, 0);
2427 cli_unlink(&cli1, fname);
2429 fnum1 = cli_nt_create_full(&cli1, fname, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
2430 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0);
2433 printf("[4] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2437 /* This should succeed. */
2438 fnum2 = cli_nt_create_full(&cli1, fname, GENERIC_READ_ACCESS,
2439 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0);
2441 printf("[4] open - 2 of %s failed (%s)\n", fname, cli_errstr(&cli1));
2445 if (!cli_close(&cli1, fnum2)) {
2446 printf("[4] close - 1 failed (%s)\n", cli_errstr(&cli1));
2450 if (!cli_nt_delete_on_close(&cli1, fnum1, True)) {
2451 printf("[4] setting delete_on_close failed (%s)\n", cli_errstr(&cli1));
2455 /* This should fail - no more opens once delete on close set. */
2456 fnum2 = cli_nt_create_full(&cli1, fname, GENERIC_READ_ACCESS,
2457 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0);
2459 printf("[4] open - 3 of %s succeeded ! Should have failed.\n", fname );
2462 printf("fourth delete on close test succeeded.\n");
2464 if (!cli_close(&cli1, fnum1)) {
2465 printf("[4] close - 2 failed (%s)\n", cli_errstr(&cli1));
2470 cli_setatr(&cli1, fname, 0, 0);
2471 cli_unlink(&cli1, fname);
2473 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT, DENY_NONE);
2475 printf("[5] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2479 /* This should fail - only allowed on NT opens with DELETE access. */
2481 if (cli_nt_delete_on_close(&cli1, fnum1, True)) {
2482 printf("[5] setting delete_on_close on OpenX file succeeded - should fail !\n");
2486 if (!cli_close(&cli1, fnum1)) {
2487 printf("[5] close - 2 failed (%s)\n", cli_errstr(&cli1));
2491 printf("fifth delete on close test succeeded.\n");
2494 cli_setatr(&cli1, fname, 0, 0);
2495 cli_unlink(&cli1, fname);
2497 fnum1 = cli_nt_create_full(&cli1, fname, FILE_READ_DATA|FILE_WRITE_DATA,
2498 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
2499 FILE_OVERWRITE_IF, 0);
2502 printf("[6] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2506 /* This should fail - only allowed on NT opens with DELETE access. */
2508 if (cli_nt_delete_on_close(&cli1, fnum1, True)) {
2509 printf("[6] setting delete_on_close on file with no delete access succeeded - should fail !\n");
2513 if (!cli_close(&cli1, fnum1)) {
2514 printf("[6] close - 2 failed (%s)\n", cli_errstr(&cli1));
2518 printf("sixth delete on close test succeeded.\n");
2521 cli_setatr(&cli1, fname, 0, 0);
2522 cli_unlink(&cli1, fname);
2524 fnum1 = cli_nt_create_full(&cli1, fname, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
2525 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF, 0);
2528 printf("[7] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2532 if (!cli_nt_delete_on_close(&cli1, fnum1, True)) {
2533 printf("[7] setting delete_on_close on file failed !\n");
2537 if (!cli_nt_delete_on_close(&cli1, fnum1, False)) {
2538 printf("[7] unsetting delete_on_close on file failed !\n");
2542 if (!cli_close(&cli1, fnum1)) {
2543 printf("[7] close - 2 failed (%s)\n", cli_errstr(&cli1));
2547 /* This next open should succeed - we reset the flag. */
2549 fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_NONE);
2551 printf("[5] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2555 if (!cli_close(&cli1, fnum1)) {
2556 printf("[7] close - 2 failed (%s)\n", cli_errstr(&cli1));
2560 printf("seventh delete on close test succeeded.\n");
2563 cli_setatr(&cli1, fname, 0, 0);
2564 cli_unlink(&cli1, fname);
2566 if (!torture_open_connection(&cli2)) {
2567 printf("[8] failed to open second connection.\n");
2571 cli_sockopt(&cli1, sockops);
2573 fnum1 = cli_nt_create_full(&cli1, fname, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
2574 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0);
2577 printf("[8] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2581 fnum2 = cli_nt_create_full(&cli2, fname, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
2582 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0);
2585 printf("[8] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2589 if (!cli_nt_delete_on_close(&cli1, fnum1, True)) {
2590 printf("[8] setting delete_on_close on file failed !\n");
2594 if (!cli_close(&cli1, fnum1)) {
2595 printf("[8] close - 1 failed (%s)\n", cli_errstr(&cli1));
2599 if (!cli_close(&cli2, fnum2)) {
2600 printf("[8] close - 2 failed (%s)\n", cli_errstr(&cli2));
2604 /* This should fail.. */
2605 fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_NONE);
2607 printf("[8] open of %s succeeded should have been deleted on close !\n", fname);
2608 if (!cli_close(&cli1, fnum1)) {
2609 printf("[8] close failed (%s)\n", cli_errstr(&cli1));
2611 cli_unlink(&cli1, fname);
2614 printf("eighth delete on close test succeeded.\n");
2616 printf("finished delete test\n");
2618 cli_setatr(&cli1, fname, 0, 0);
2619 cli_unlink(&cli1, fname);
2621 if (!torture_close_connection(&cli1)) {
2624 if (!torture_close_connection(&cli2)) {
2631 Test open mode returns on read-only files.
2633 static BOOL run_opentest(int dummy)
2635 static struct cli_state cli1;
2636 char *fname = "\\readonly.file";
2640 BOOL correct = True;
2643 printf("starting open test\n");
2645 if (!torture_open_connection(&cli1)) {
2649 cli_setatr(&cli1, fname, 0, 0);
2650 cli_unlink(&cli1, fname);
2652 cli_sockopt(&cli1, sockops);
2654 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2656 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2660 if (!cli_close(&cli1, fnum1)) {
2661 printf("close2 failed (%s)\n", cli_errstr(&cli1));
2665 if (!cli_setatr(&cli1, fname, aRONLY, 0)) {
2666 printf("cli_setatr failed (%s)\n", cli_errstr(&cli1));
2670 fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_WRITE);
2672 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2676 /* This will fail - but the error should be ERRnoaccess, not ERRbadshare. */
2677 fnum2 = cli_open(&cli1, fname, O_RDWR, DENY_ALL);
2679 if (check_error(__LINE__, &cli1, ERRDOS, ERRnoaccess,
2680 NT_STATUS_ACCESS_DENIED)) {
2681 printf("correct error code ERRDOS/ERRnoaccess returned\n");
2684 printf("finished open test 1\n");
2686 cli_close(&cli1, fnum1);
2688 /* Now try not readonly and ensure ERRbadshare is returned. */
2690 cli_setatr(&cli1, fname, 0, 0);
2692 fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_WRITE);
2694 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2698 /* This will fail - but the error should be ERRshare. */
2699 fnum2 = cli_open(&cli1, fname, O_RDWR, DENY_ALL);
2701 if (check_error(__LINE__, &cli1, ERRDOS, ERRbadshare,
2702 NT_STATUS_SHARING_VIOLATION)) {
2703 printf("correct error code ERRDOS/ERRbadshare returned\n");
2706 if (!cli_close(&cli1, fnum1)) {
2707 printf("close2 failed (%s)\n", cli_errstr(&cli1));
2711 cli_unlink(&cli1, fname);
2713 printf("finished open test 2\n");
2715 /* Test truncate open disposition on file opened for read. */
2717 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2719 printf("(3) open (1) of %s failed (%s)\n", fname, cli_errstr(&cli1));
2723 /* write 20 bytes. */
2725 memset(buf, '\0', 20);
2727 if (cli_write(&cli1, fnum1, 0, buf, 0, 20) != 20) {
2728 printf("write failed (%s)\n", cli_errstr(&cli1));
2732 if (!cli_close(&cli1, fnum1)) {
2733 printf("(3) close1 failed (%s)\n", cli_errstr(&cli1));
2737 /* Ensure size == 20. */
2738 if (!cli_getatr(&cli1, fname, NULL, &fsize, NULL)) {
2739 printf("(3) getatr failed (%s)\n", cli_errstr(&cli1));
2744 printf("(3) file size != 20\n");
2748 /* Now test if we can truncate a file opened for readonly. */
2750 fnum1 = cli_open(&cli1, fname, O_RDONLY|O_TRUNC, DENY_NONE);
2752 printf("(3) open (2) of %s failed (%s)\n", fname, cli_errstr(&cli1));
2756 if (!cli_close(&cli1, fnum1)) {
2757 printf("close2 failed (%s)\n", cli_errstr(&cli1));
2761 /* Ensure size == 0. */
2762 if (!cli_getatr(&cli1, fname, NULL, &fsize, NULL)) {
2763 printf("(3) getatr failed (%s)\n", cli_errstr(&cli1));
2768 printf("(3) file size != 0\n");
2771 printf("finished open test 3\n");
2773 cli_unlink(&cli1, fname);
2776 printf("testing ctemp\n");
2777 fnum1 = cli_ctemp(&cli1, "\\", &tmp_path);
2779 printf("ctemp failed (%s)\n", cli_errstr(&cli1));
2782 printf("ctemp gave path %s\n", tmp_path);
2783 if (!cli_close(&cli1, fnum1)) {
2784 printf("close of temp failed (%s)\n", cli_errstr(&cli1));
2786 if (!cli_unlink(&cli1, tmp_path)) {
2787 printf("unlink of temp failed (%s)\n", cli_errstr(&cli1));
2790 if (!torture_close_connection(&cli1)) {
2797 static void list_fn(file_info *finfo, const char *name, void *state)
2803 test directory listing speed
2805 static BOOL run_dirtest(int dummy)
2808 static struct cli_state cli;
2811 BOOL correct = True;
2813 printf("starting directory test\n");
2815 if (!torture_open_connection(&cli)) {
2819 cli_sockopt(&cli, sockops);
2822 for (i=0;i<numops;i++) {
2824 slprintf(fname, sizeof(fname), "%x", (int)random());
2825 fnum = cli_open(&cli, fname, O_RDWR|O_CREAT, DENY_NONE);
2827 fprintf(stderr,"Failed to open %s\n", fname);
2830 cli_close(&cli, fnum);
2835 printf("Matched %d\n", cli_list(&cli, "a*.*", 0, list_fn, NULL));
2836 printf("Matched %d\n", cli_list(&cli, "b*.*", 0, list_fn, NULL));
2837 printf("Matched %d\n", cli_list(&cli, "xyzabc", 0, list_fn, NULL));
2839 printf("dirtest core %g seconds\n", end_timer() - t1);
2842 for (i=0;i<numops;i++) {
2844 slprintf(fname, sizeof(fname), "%x", (int)random());
2845 cli_unlink(&cli, fname);
2848 if (!torture_close_connection(&cli)) {
2852 printf("finished dirtest\n");
2857 static BOOL run_error_map_extract(int dummy) {
2859 static struct cli_state c_dos;
2860 static struct cli_state c_nt;
2864 uint32 flgs2, errnum;
2871 /* NT-Error connection */
2873 if (!open_nbt_connection(&c_nt)) {
2877 c_nt.use_spnego = False;
2879 if (!cli_negprot(&c_nt)) {
2880 printf("%s rejected the NT-error negprot (%s)\n",host, cli_errstr(&c_nt));
2881 cli_shutdown(&c_nt);
2885 if (!cli_session_setup(&c_nt, "", "", 0, "", 0,
2887 printf("%s rejected the NT-error initial session setup (%s)\n",host, cli_errstr(&c_nt));
2891 /* DOS-Error connection */
2893 if (!open_nbt_connection(&c_dos)) {
2897 c_dos.use_spnego = False;
2898 c_dos.force_dos_errors = True;
2900 if (!cli_negprot(&c_dos)) {
2901 printf("%s rejected the DOS-error negprot (%s)\n",host, cli_errstr(&c_dos));
2902 cli_shutdown(&c_dos);
2906 if (!cli_session_setup(&c_dos, "", "", 0, "", 0,
2908 printf("%s rejected the DOS-error initial session setup (%s)\n",host, cli_errstr(&c_dos));
2912 for (error=(0xc0000000 | 0x1); error < (0xc0000000| 0xFFF); error++) {
2913 snprintf(user, sizeof(user), "%X", error);
2915 if (cli_session_setup(&c_nt, user,
2916 password, strlen(password),
2917 password, strlen(password),
2919 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
2922 flgs2 = SVAL(c_nt.inbuf,smb_flg2);
2924 /* Case #1: 32-bit NT errors */
2925 if (flgs2 & FLAGS2_32_BIT_ERROR_CODES) {
2926 nt_status = NT_STATUS(IVAL(c_nt.inbuf,smb_rcls));
2928 printf("/** Dos error on NT connection! (%s) */\n",
2930 nt_status = NT_STATUS(0xc0000000);
2933 if (cli_session_setup(&c_dos, user,
2934 password, strlen(password),
2935 password, strlen(password),
2937 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
2939 flgs2 = SVAL(c_dos.inbuf,smb_flg2), errnum;
2941 /* Case #1: 32-bit NT errors */
2942 if (flgs2 & FLAGS2_32_BIT_ERROR_CODES) {
2943 printf("/** NT error on DOS connection! (%s) */\n",
2945 errnum = errclass = 0;
2947 cli_dos_error(&c_dos, &errclass, &errnum);
2950 if (NT_STATUS_V(nt_status) != error) {
2951 printf("/*\t{ This NT error code was 'sqashed'\n\t from %s to %s \n\t during the session setup }\n*/\n",
2952 get_nt_error_c_code(NT_STATUS(error)),
2953 get_nt_error_c_code(nt_status));
2956 printf("\t{%s,\t%s,\t%s},\n",
2957 smb_dos_err_class(errclass),
2958 smb_dos_err_name(errclass, errnum),
2959 get_nt_error_c_code(NT_STATUS(error)));
2964 static double create_procs(BOOL (*fn)(int), BOOL *result)
2967 volatile pid_t *child_status;
2968 volatile BOOL *child_status_out;
2974 child_status = (volatile pid_t *)shm_setup(sizeof(pid_t)*nprocs);
2975 if (!child_status) {
2976 printf("Failed to setup shared memory\n");
2980 child_status_out = (volatile BOOL *)shm_setup(sizeof(BOOL)*nprocs);
2981 if (!child_status_out) {
2982 printf("Failed to setup result status shared memory\n");
2986 for (i = 0; i < nprocs; i++) {
2987 child_status[i] = 0;
2988 child_status_out[i] = True;
2993 for (i=0;i<nprocs;i++) {
2996 pid_t mypid = getpid();
2997 sys_srandom(((int)mypid) ^ ((int)time(NULL)));
2999 slprintf(myname,sizeof(myname),"CLIENT%d", i);
3002 memset(¤t_cli, 0, sizeof(current_cli));
3003 if (torture_open_connection(¤t_cli)) break;
3005 printf("pid %d failed to start\n", (int)getpid());
3011 child_status[i] = getpid();
3013 while (child_status[i]) msleep(2);
3015 child_status_out[i] = fn(i);
3022 for (i=0;i<nprocs;i++) {
3023 if (child_status[i]) synccount++;
3025 if (synccount == nprocs) break;
3027 } while (end_timer() < 30);
3029 if (synccount != nprocs) {
3030 printf("FAILED TO START %d CLIENTS (started %d)\n", nprocs, synccount);
3035 /* start the client load */
3038 for (i=0;i<nprocs;i++) {
3039 child_status[i] = 0;
3042 printf("%d clients started\n", nprocs);
3044 for (i=0;i<nprocs;i++) {
3045 waitpid(0, &status, 0);
3051 for (i=0;i<nprocs;i++) {
3052 if (!child_status_out[i]) {
3059 #define FLAG_MULTIPROC 1
3066 {"FDPASS", run_fdpasstest, 0},
3067 {"LOCK1", run_locktest1, 0},
3068 {"LOCK2", run_locktest2, 0},
3069 {"LOCK3", run_locktest3, 0},
3070 {"LOCK4", run_locktest4, 0},
3071 {"LOCK5", run_locktest5, 0},
3072 {"UNLINK", run_unlinktest, 0},
3073 {"BROWSE", run_browsetest, 0},
3074 {"ATTR", run_attrtest, 0},
3075 {"TRANS2", run_trans2test, 0},
3076 {"MAXFID", run_maxfidtest, FLAG_MULTIPROC},
3077 {"TORTURE",run_torture, FLAG_MULTIPROC},
3078 {"RANDOMIPC", run_randomipc, 0},
3079 {"NEGNOWAIT", run_negprot_nowait, 0},
3080 {"NBW95", run_nbw95, 0},
3081 {"NBWNT", run_nbwnt, 0},
3082 {"OPLOCK1", run_oplock1, 0},
3083 {"OPLOCK2", run_oplock2, 0},
3084 {"OPLOCK3", run_oplock3, 0},
3085 {"DIR", run_dirtest, 0},
3086 {"DENY1", torture_denytest1, 0},
3087 {"DENY2", torture_denytest2, 0},
3088 {"TCON", run_tcon_test, 0},
3089 {"RW1", run_readwritetest, 0},
3090 {"RW2", run_readwritemulti, FLAG_MULTIPROC},
3091 {"RW3", run_readwritelarge, 0},
3092 {"OPEN", run_opentest, 0},
3093 {"DELETE", run_deletetest, 0},
3094 {"W2K", run_w2ktest, 0},
3095 {"TRANS2SCAN", torture_trans2_scan, 0},
3096 {"NTTRANSSCAN", torture_nttrans_scan, 0},
3097 {"UTABLE", torture_utable, 0},
3098 {"CASETABLE", torture_casetable, 0},
3099 {"ERRMAPEXTRACT", run_error_map_extract, 0},
3104 /****************************************************************************
3105 run a specified test or "ALL"
3106 ****************************************************************************/
3107 static BOOL run_test(char *name)
3113 if (strequal(name,"ALL")) {
3114 for (i=0;torture_ops[i].name;i++) {
3115 run_test(torture_ops[i].name);
3119 for (i=0;torture_ops[i].name;i++) {
3120 snprintf(randomfname, sizeof(randomfname), "\\XX%x",
3121 (unsigned)random());
3123 if (strequal(name, torture_ops[i].name)) {
3124 printf("Running %s\n", name);
3125 if (torture_ops[i].flags & FLAG_MULTIPROC) {
3126 t = create_procs(torture_ops[i].fn, &result);
3129 printf("TEST %s FAILED!\n", name);
3134 if (!torture_ops[i].fn(0)) {
3136 printf("TEST %s FAILED!\n", name);
3140 printf("%s took %g secs\n\n", name, t);
3147 static void usage(void)
3151 printf("Usage: smbtorture //server/share <options> TEST1 TEST2 ...\n");
3153 printf("\t-d debuglevel\n");
3154 printf("\t-U user%%pass\n");
3155 printf("\t-N numprocs\n");
3156 printf("\t-n my_netbios_name\n");
3157 printf("\t-W workgroup\n");
3158 printf("\t-o num_operations\n");
3159 printf("\t-O socket_options\n");
3160 printf("\t-m maximum protocol\n");
3161 printf("\t-L use oplocks\n");
3162 printf("\t-A showall\n");
3165 printf("tests are:");
3166 for (i=0;torture_ops[i].name;i++) {
3167 printf(" %s", torture_ops[i].name);
3171 printf("default test is ALL\n");
3180 /****************************************************************************
3182 ****************************************************************************/
3183 int main(int argc,char *argv[])
3188 extern char *optarg;
3190 BOOL correct = True;
3194 #ifdef HAVE_SETBUFFER
3195 setbuffer(stdout, NULL, 0);
3198 lp_load(dyn_CONFIGFILE,True,False,False);
3205 for(p = argv[1]; *p; p++)
3209 if (strncmp(argv[1], "//", 2)) {
3213 fstrcpy(host, &argv[1][2]);
3214 p = strchr_m(&host[2],'/');
3219 fstrcpy(share, p+1);
3223 if (*username == 0 && getenv("LOGNAME")) {
3224 pstrcpy(username,getenv("LOGNAME"));
3231 fstrcpy(workgroup, lp_workgroup());
3233 while ((opt = getopt(argc, argv, "hW:U:n:N:O:o:m:Ld:A")) != EOF) {
3236 fstrcpy(workgroup,optarg);
3239 max_protocol = interpret_protocol(optarg, max_protocol);
3242 nprocs = atoi(optarg);
3245 numops = atoi(optarg);
3248 DEBUGLEVEL = atoi(optarg);
3257 torture_showall = True;
3260 fstrcpy(myname, optarg);
3263 pstrcpy(username,optarg);
3264 p = strchr_m(username,'%');
3267 pstrcpy(password, p+1);
3272 printf("Unknown option %c (%d)\n", (char)opt, opt);
3279 p = getpass("Password:");
3281 pstrcpy(password, p);
3286 printf("host=%s share=%s user=%s myname=%s\n",
3287 host, share, username, myname);
3290 correct = run_test("ALL");
3292 for (i=1;i<argc;i++) {
3293 if (!run_test(argv[i])) {