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 static char *client_txt = "client_oplocks.txt";
35 static BOOL use_kerberos;
37 BOOL torture_showall = False;
39 static double create_procs(BOOL (*fn)(int), BOOL *result);
42 static struct timeval tp1,tp2;
44 void start_timer(void)
46 gettimeofday(&tp1,NULL);
49 double end_timer(void)
51 gettimeofday(&tp2,NULL);
52 return((tp2.tv_sec - tp1.tv_sec) +
53 (tp2.tv_usec - tp1.tv_usec)*1.0e-6);
57 /* return a pointer to a anonymous shared memory segment of size "size"
58 which will persist across fork() but will disappear when all processes
61 The memory is not zeroed
63 This function uses system5 shared memory. It takes advantage of a property
64 that the memory is not destroyed if it is attached when the id is removed
66 void *shm_setup(int size)
71 shmid = shmget(IPC_PRIVATE, size, SHM_R | SHM_W);
73 printf("can't get shared memory\n");
76 ret = (void *)shmat(shmid, 0, 0);
77 if (!ret || ret == (void *)-1) {
78 printf("can't attach to shared memory\n");
81 /* the following releases the ipc, but note that this process
82 and all its children will still have access to the memory, its
83 just that the shmid is no longer valid for other shm calls. This
84 means we don't leave behind lots of shm segments after we exit
86 See Stevens "advanced programming in unix env" for details
88 shmctl(shmid, IPC_RMID, 0);
94 static BOOL open_nbt_connection(struct cli_state *c)
96 struct nmb_name called, calling;
101 make_nmb_name(&calling, myname, 0x0);
102 make_nmb_name(&called , host, 0x20);
106 if (!cli_initialise(c) || !cli_connect(c, host, &ip)) {
107 printf("Failed to connect with %s\n", host);
111 c->use_kerberos = use_kerberos;
113 c->timeout = 120000; /* set a really long timeout (2 minutes) */
114 if (use_oplocks) c->use_oplocks = True;
115 if (use_level_II_oplocks) c->use_level_II_oplocks = True;
117 if (!cli_session_request(c, &calling, &called)) {
118 printf("%s rejected the session\n",host);
126 BOOL torture_open_connection(struct cli_state *c)
130 if (!open_nbt_connection(c)) {
134 if (!cli_negprot(c)) {
135 printf("%s rejected the negprot (%s)\n",host, cli_errstr(c));
140 if (!cli_session_setup(c, username,
141 password, strlen(password),
142 password, strlen(password),
144 printf("%s rejected the sessionsetup (%s)\n", host, cli_errstr(c));
149 if (!cli_send_tconX(c, share, "?????",
150 password, strlen(password)+1)) {
151 printf("%s refused tree connect (%s)\n", host, cli_errstr(c));
160 BOOL torture_close_connection(struct cli_state *c)
164 printf("tdis failed (%s)\n", cli_errstr(c));
174 /* check if the server produced the expected error code */
175 static BOOL check_error(int line, struct cli_state *c,
176 uint8 eclass, uint32 ecode, NTSTATUS nterr)
178 if (cli_is_dos_error(c)) {
182 /* Check DOS error */
184 cli_dos_error(c, &class, &num);
186 if (eclass != class || ecode != num) {
187 printf("unexpected error code class=%d code=%d\n",
188 (int)class, (int)num);
189 printf(" expected %d/%d %s (line=%d)\n",
190 (int)eclass, (int)ecode, get_nt_error_msg(nterr), line);
199 status = cli_nt_error(c);
201 if (NT_STATUS_V(nterr) != NT_STATUS_V(status)) {
202 printf("unexpected error code %s\n", get_nt_error_msg(status));
203 printf(" expected %s (line=%d)\n", get_nt_error_msg(nterr), line);
212 static BOOL wait_lock(struct cli_state *c, int fnum, uint32 offset, uint32 len)
214 while (!cli_lock(c, fnum, offset, len, -1, WRITE_LOCK)) {
215 if (!check_error(__LINE__, c, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False;
221 static BOOL rw_torture(struct cli_state *c)
223 char *lockfname = "\\torture.lck";
227 pid_t pid2, pid = getpid();
232 fnum2 = cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
235 fnum2 = cli_open(c, lockfname, O_RDWR, DENY_NONE);
237 printf("open of %s failed (%s)\n", lockfname, cli_errstr(c));
242 for (i=0;i<numops;i++) {
243 unsigned n = (unsigned)sys_random()%10;
245 printf("%d\r", i); fflush(stdout);
247 slprintf(fname, sizeof(fstring) - 1, "\\torture.%u", n);
249 if (!wait_lock(c, fnum2, n*sizeof(int), sizeof(int))) {
253 fnum = cli_open(c, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_ALL);
255 printf("open failed (%s)\n", cli_errstr(c));
260 if (cli_write(c, fnum, 0, (char *)&pid, 0, sizeof(pid)) != sizeof(pid)) {
261 printf("write failed (%s)\n", cli_errstr(c));
266 if (cli_write(c, fnum, 0, (char *)buf,
267 sizeof(pid)+(j*sizeof(buf)),
268 sizeof(buf)) != sizeof(buf)) {
269 printf("write failed (%s)\n", cli_errstr(c));
276 if (cli_read(c, fnum, (char *)&pid2, 0, sizeof(pid)) != sizeof(pid)) {
277 printf("read failed (%s)\n", cli_errstr(c));
282 printf("data corruption!\n");
286 if (!cli_close(c, fnum)) {
287 printf("close failed (%s)\n", cli_errstr(c));
291 if (!cli_unlink(c, fname)) {
292 printf("unlink failed (%s)\n", cli_errstr(c));
296 if (!cli_unlock(c, fnum2, n*sizeof(int), sizeof(int))) {
297 printf("unlock failed (%s)\n", cli_errstr(c));
303 cli_unlink(c, lockfname);
310 static BOOL run_torture(int dummy)
312 struct cli_state cli;
317 cli_sockopt(&cli, sockops);
319 ret = rw_torture(&cli);
321 if (!torture_close_connection(&cli)) {
328 static BOOL rw_torture3(struct cli_state *c, char *lockfname)
335 unsigned countprev = 0;
340 for (i = 0; i < sizeof(buf); i += sizeof(uint32))
342 SIVAL(buf, i, sys_random());
347 fnum = cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
350 printf("first open read/write of %s failed (%s)\n",
351 lockfname, cli_errstr(c));
357 for (i = 0; i < 500 && fnum == -1; i++)
359 fnum = cli_open(c, lockfname, O_RDONLY,
364 printf("second open read-only of %s failed (%s)\n",
365 lockfname, cli_errstr(c));
371 for (count = 0; count < sizeof(buf); count += sent)
373 if (count >= countprev) {
374 printf("%d %8d\r", i, count);
377 countprev += (sizeof(buf) / 20);
382 sent = ((unsigned)sys_random()%(20))+ 1;
383 if (sent > sizeof(buf) - count)
385 sent = sizeof(buf) - count;
388 if (cli_write(c, fnum, 0, buf+count, count, (size_t)sent) != sent) {
389 printf("write failed (%s)\n", cli_errstr(c));
395 sent = cli_read(c, fnum, buf_rd+count, count,
399 printf("read failed offset:%d size:%d (%s)\n",
400 count, sizeof(buf)-count,
407 if (memcmp(buf_rd+count, buf+count, sent) != 0)
409 printf("read/write compare failed\n");
410 printf("offset: %d req %d recvd %d\n",
411 count, sizeof(buf)-count, sent);
420 if (!cli_close(c, fnum)) {
421 printf("close failed (%s)\n", cli_errstr(c));
428 static BOOL rw_torture2(struct cli_state *c1, struct cli_state *c2)
430 char *lockfname = "\\torture2.lck";
435 uchar buf_rd[131072];
439 if (!cli_unlink(c1, lockfname)) {
440 printf("unlink failed (%s) (normal, this file should not exist)\n", cli_errstr(c1));
443 fnum1 = cli_open(c1, lockfname, O_RDWR | O_CREAT | O_EXCL,
446 printf("first open read/write of %s failed (%s)\n",
447 lockfname, cli_errstr(c1));
450 fnum2 = cli_open(c2, lockfname, O_RDONLY,
453 printf("second open read-only of %s failed (%s)\n",
454 lockfname, cli_errstr(c2));
455 cli_close(c1, fnum1);
459 for (i=0;i<numops;i++)
461 size_t buf_size = ((unsigned)sys_random()%(sizeof(buf)-1))+ 1;
463 printf("%d\r", i); fflush(stdout);
466 generate_random_buffer(buf, buf_size, False);
468 if (cli_write(c1, fnum1, 0, buf, 0, buf_size) != buf_size) {
469 printf("write failed (%s)\n", cli_errstr(c1));
473 if ((bytes_read = cli_read(c2, fnum2, buf_rd, 0, buf_size)) != buf_size) {
474 printf("read failed (%s)\n", cli_errstr(c2));
475 printf("read %d, expected %d\n", bytes_read, buf_size);
479 if (memcmp(buf_rd, buf, buf_size) != 0)
481 printf("read/write compare failed\n");
486 if (!cli_close(c2, fnum2)) {
487 printf("close failed (%s)\n", cli_errstr(c2));
490 if (!cli_close(c1, fnum1)) {
491 printf("close failed (%s)\n", cli_errstr(c1));
495 if (!cli_unlink(c1, lockfname)) {
496 printf("unlink failed (%s)\n", cli_errstr(c1));
503 static BOOL run_readwritetest(int dummy)
505 static struct cli_state cli1, cli2;
508 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
511 cli_sockopt(&cli1, sockops);
512 cli_sockopt(&cli2, sockops);
514 printf("starting readwritetest\n");
516 test1 = rw_torture2(&cli1, &cli2);
517 printf("Passed readwritetest v1: %s\n", BOOLSTR(test1));
519 test2 = rw_torture2(&cli1, &cli1);
520 printf("Passed readwritetest v2: %s\n", BOOLSTR(test2));
522 if (!torture_close_connection(&cli1)) {
526 if (!torture_close_connection(&cli2)) {
530 return (test1 && test2);
533 static BOOL run_readwritemulti(int dummy)
535 static struct cli_state cli;
540 cli_sockopt(&cli, sockops);
542 printf("run_readwritemulti: fname %s\n", randomfname);
543 test = rw_torture3(&cli, randomfname);
545 if (!torture_close_connection(&cli)) {
552 static BOOL run_readwritelarge(int dummy)
554 static struct cli_state cli1;
556 char *lockfname = "\\large.dat";
561 if (!torture_open_connection(&cli1)) {
564 cli_sockopt(&cli1, sockops);
565 memset(buf,'\0',sizeof(buf));
567 cli1.max_xmit = 0x11000;
569 printf("starting readwritelarge\n");
571 cli_unlink(&cli1, lockfname);
573 fnum1 = cli_open(&cli1, lockfname, O_RDWR | O_CREAT | O_EXCL, DENY_NONE);
575 printf("open read/write of %s failed (%s)\n", lockfname, cli_errstr(&cli1));
579 cli_write(&cli1, fnum1, 0, buf, 0, sizeof(buf));
581 if (!cli_close(&cli1, fnum1)) {
582 printf("close failed (%s)\n", cli_errstr(&cli1));
586 if (!cli_qpathinfo(&cli1, lockfname, NULL, NULL, NULL, &fsize, NULL)) {
587 printf("qpathinfo failed (%s)\n", cli_errstr(&cli1));
591 if (fsize == sizeof(buf))
592 printf("readwritelarge test 1 succeeded (size = %x)\n", fsize);
594 printf("readwritelarge test 1 failed (size = %x)\n", fsize);
598 if (!cli_unlink(&cli1, lockfname)) {
599 printf("unlink failed (%s)\n", cli_errstr(&cli1));
603 fnum1 = cli_open(&cli1, lockfname, O_RDWR | O_CREAT | O_EXCL, DENY_NONE);
605 printf("open read/write of %s failed (%s)\n", lockfname, cli_errstr(&cli1));
609 cli_smbwrite(&cli1, fnum1, buf, 0, sizeof(buf));
611 if (!cli_close(&cli1, fnum1)) {
612 printf("close failed (%s)\n", cli_errstr(&cli1));
616 if (!torture_close_connection(&cli1)) {
625 #define ival(s) strtol(s, NULL, 0)
627 /* run a test that simulates an approximate netbench client load */
628 static BOOL run_netbench(int client)
630 struct cli_state cli;
643 cli_sockopt(&cli, sockops);
647 slprintf(cname,sizeof(fname), "client%d", client);
649 f = fopen(client_txt, "r");
656 while (fgets(line, sizeof(line)-1, f)) {
659 line[strlen(line)-1] = 0;
661 /* printf("[%d] %s\n", line_count, line); */
663 all_string_sub(line,"client1", cname, sizeof(line));
665 /* parse the command parameters */
666 params[0] = strtok(line," ");
668 while (params[i]) params[++i] = strtok(NULL," ");
674 if (!strncmp(params[0],"SMB", 3)) {
675 printf("ERROR: You are using a dbench 1 load file\n");
679 if (!strcmp(params[0],"NTCreateX")) {
680 nb_createx(params[1], ival(params[2]), ival(params[3]),
682 } else if (!strcmp(params[0],"Close")) {
683 nb_close(ival(params[1]));
684 } else if (!strcmp(params[0],"Rename")) {
685 nb_rename(params[1], params[2]);
686 } else if (!strcmp(params[0],"Unlink")) {
687 nb_unlink(params[1]);
688 } else if (!strcmp(params[0],"Deltree")) {
689 nb_deltree(params[1]);
690 } else if (!strcmp(params[0],"Rmdir")) {
692 } else if (!strcmp(params[0],"QUERY_PATH_INFORMATION")) {
693 nb_qpathinfo(params[1]);
694 } else if (!strcmp(params[0],"QUERY_FILE_INFORMATION")) {
695 nb_qfileinfo(ival(params[1]));
696 } else if (!strcmp(params[0],"QUERY_FS_INFORMATION")) {
697 nb_qfsinfo(ival(params[1]));
698 } else if (!strcmp(params[0],"FIND_FIRST")) {
699 nb_findfirst(params[1]);
700 } else if (!strcmp(params[0],"WriteX")) {
701 nb_writex(ival(params[1]),
702 ival(params[2]), ival(params[3]), ival(params[4]));
703 } else if (!strcmp(params[0],"ReadX")) {
704 nb_readx(ival(params[1]),
705 ival(params[2]), ival(params[3]), ival(params[4]));
706 } else if (!strcmp(params[0],"Flush")) {
707 nb_flush(ival(params[1]));
709 printf("Unknown operation %s\n", params[0]);
717 if (!torture_close_connection(&cli)) {
725 /* run a test that simulates an approximate netbench client load */
726 static BOOL run_nbench(int dummy)
735 signal(SIGALRM, nb_alarm);
737 t = create_procs(run_netbench, &correct);
740 printf("\nThroughput %g MB/sec\n",
741 1.0e-6 * nbio_total() / t);
747 This test checks for two things:
749 1) correct support for retaining locks over a close (ie. the server
750 must not use posix semantics)
751 2) support for lock timeouts
753 static BOOL run_locktest1(int dummy)
755 static struct cli_state cli1, cli2;
756 char *fname = "\\lockt1.lck";
757 int fnum1, fnum2, fnum3;
760 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
763 cli_sockopt(&cli1, sockops);
764 cli_sockopt(&cli2, sockops);
766 printf("starting locktest1\n");
768 cli_unlink(&cli1, fname);
770 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
772 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
775 fnum2 = cli_open(&cli1, fname, O_RDWR, DENY_NONE);
777 printf("open2 of %s failed (%s)\n", fname, cli_errstr(&cli1));
780 fnum3 = cli_open(&cli2, fname, O_RDWR, DENY_NONE);
782 printf("open3 of %s failed (%s)\n", fname, cli_errstr(&cli2));
786 if (!cli_lock(&cli1, fnum1, 0, 4, 0, WRITE_LOCK)) {
787 printf("lock1 failed (%s)\n", cli_errstr(&cli1));
792 if (cli_lock(&cli2, fnum3, 0, 4, 0, WRITE_LOCK)) {
793 printf("lock2 succeeded! This is a locking bug\n");
796 if (!check_error(__LINE__, &cli2, ERRDOS, ERRlock,
797 NT_STATUS_LOCK_NOT_GRANTED)) return False;
801 printf("Testing lock timeouts\n");
803 if (cli_lock(&cli2, fnum3, 0, 4, 10*1000, WRITE_LOCK)) {
804 printf("lock3 succeeded! This is a locking bug\n");
807 if (!check_error(__LINE__, &cli2, ERRDOS, ERRlock,
808 NT_STATUS_FILE_LOCK_CONFLICT)) return False;
813 printf("error: This server appears not to support timed lock requests\n");
816 if (!cli_close(&cli1, fnum2)) {
817 printf("close1 failed (%s)\n", cli_errstr(&cli1));
821 if (cli_lock(&cli2, fnum3, 0, 4, 0, WRITE_LOCK)) {
822 printf("lock4 succeeded! This is a locking bug\n");
825 if (!check_error(__LINE__, &cli2, ERRDOS, ERRlock,
826 NT_STATUS_FILE_LOCK_CONFLICT)) return False;
829 if (!cli_close(&cli1, fnum1)) {
830 printf("close2 failed (%s)\n", cli_errstr(&cli1));
834 if (!cli_close(&cli2, fnum3)) {
835 printf("close3 failed (%s)\n", cli_errstr(&cli2));
839 if (!cli_unlink(&cli1, fname)) {
840 printf("unlink failed (%s)\n", cli_errstr(&cli1));
845 if (!torture_close_connection(&cli1)) {
849 if (!torture_close_connection(&cli2)) {
853 printf("Passed locktest1\n");
858 checks for correct tconX support
860 static BOOL run_tcon_test(int dummy)
862 static struct cli_state cli1;
863 char *fname = "\\tcontest.tmp";
868 if (!torture_open_connection(&cli1)) {
871 cli_sockopt(&cli1, sockops);
873 printf("starting tcontest\n");
875 cli_unlink(&cli1, fname);
877 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
880 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
886 if (cli_write(&cli1, fnum1, 0, buf, 130, 4) != 4)
888 printf("write failed (%s)", cli_errstr(&cli1));
892 if (!cli_send_tconX(&cli1, share, "?????",
893 password, strlen(password)+1)) {
894 printf("%s refused 2nd tree connect (%s)\n", host,
900 if (cli_write(&cli1, fnum1, 0, buf, 130, 4) == 4)
902 printf("write succeeded (%s)", cli_errstr(&cli1));
906 if (cli_close(&cli1, fnum1)) {
907 printf("close2 succeeded (%s)\n", cli_errstr(&cli1));
911 if (!cli_tdis(&cli1)) {
912 printf("tdis failed (%s)\n", cli_errstr(&cli1));
918 if (!cli_close(&cli1, fnum1)) {
919 printf("close2 failed (%s)\n", cli_errstr(&cli1));
923 if (!torture_close_connection(&cli1)) {
927 printf("Passed tcontest\n");
933 This test checks that
935 1) the server supports multiple locking contexts on the one SMB
936 connection, distinguished by PID.
938 2) the server correctly fails overlapping locks made by the same PID (this
939 goes against POSIX behaviour, which is why it is tricky to implement)
941 3) the server denies unlock requests by an incorrect client PID
943 static BOOL run_locktest2(int dummy)
945 static struct cli_state cli;
946 char *fname = "\\lockt2.lck";
947 int fnum1, fnum2, fnum3;
950 if (!torture_open_connection(&cli)) {
954 cli_sockopt(&cli, sockops);
956 printf("starting locktest2\n");
958 cli_unlink(&cli, fname);
962 fnum1 = cli_open(&cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
964 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli));
968 fnum2 = cli_open(&cli, fname, O_RDWR, DENY_NONE);
970 printf("open2 of %s failed (%s)\n", fname, cli_errstr(&cli));
976 fnum3 = cli_open(&cli, fname, O_RDWR, DENY_NONE);
978 printf("open3 of %s failed (%s)\n", fname, cli_errstr(&cli));
984 if (!cli_lock(&cli, fnum1, 0, 4, 0, WRITE_LOCK)) {
985 printf("lock1 failed (%s)\n", cli_errstr(&cli));
989 if (cli_lock(&cli, fnum1, 0, 4, 0, WRITE_LOCK)) {
990 printf("WRITE lock1 succeeded! This is a locking bug\n");
993 if (!check_error(__LINE__, &cli, ERRDOS, ERRlock,
994 NT_STATUS_LOCK_NOT_GRANTED)) return False;
997 if (cli_lock(&cli, fnum2, 0, 4, 0, WRITE_LOCK)) {
998 printf("WRITE lock2 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, READ_LOCK)) {
1006 printf("READ lock2 succeeded! This is a locking bug\n");
1009 if (!check_error(__LINE__, &cli, ERRDOS, ERRlock,
1010 NT_STATUS_FILE_LOCK_CONFLICT)) return False;
1013 if (!cli_lock(&cli, fnum1, 100, 4, 0, WRITE_LOCK)) {
1014 printf("lock at 100 failed (%s)\n", cli_errstr(&cli));
1016 cli_setpid(&cli, 2);
1017 if (cli_unlock(&cli, fnum1, 100, 4)) {
1018 printf("unlock at 100 succeeded! This is a locking bug\n");
1022 if (cli_unlock(&cli, fnum1, 0, 4)) {
1023 printf("unlock1 succeeded! This is a locking bug\n");
1026 if (!check_error(__LINE__, &cli,
1028 NT_STATUS_RANGE_NOT_LOCKED)) return False;
1031 if (cli_unlock(&cli, fnum1, 0, 8)) {
1032 printf("unlock2 succeeded! This is a locking bug\n");
1035 if (!check_error(__LINE__, &cli,
1037 NT_STATUS_RANGE_NOT_LOCKED)) return False;
1040 if (cli_lock(&cli, fnum3, 0, 4, 0, WRITE_LOCK)) {
1041 printf("lock3 succeeded! This is a locking bug\n");
1044 if (!check_error(__LINE__, &cli, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False;
1047 cli_setpid(&cli, 1);
1049 if (!cli_close(&cli, fnum1)) {
1050 printf("close1 failed (%s)\n", cli_errstr(&cli));
1054 if (!cli_close(&cli, fnum2)) {
1055 printf("close2 failed (%s)\n", cli_errstr(&cli));
1059 if (!cli_close(&cli, fnum3)) {
1060 printf("close3 failed (%s)\n", cli_errstr(&cli));
1064 if (!torture_close_connection(&cli)) {
1068 printf("locktest2 finished\n");
1075 This test checks that
1077 1) the server supports the full offset range in lock requests
1079 static BOOL run_locktest3(int dummy)
1081 static struct cli_state cli1, cli2;
1082 char *fname = "\\lockt3.lck";
1083 int fnum1, fnum2, i;
1085 BOOL correct = True;
1087 #define NEXT_OFFSET offset += (~(uint32)0) / numops
1089 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
1092 cli_sockopt(&cli1, sockops);
1093 cli_sockopt(&cli2, sockops);
1095 printf("starting locktest3\n");
1097 cli_unlink(&cli1, fname);
1099 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1101 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
1104 fnum2 = cli_open(&cli2, fname, O_RDWR, DENY_NONE);
1106 printf("open2 of %s failed (%s)\n", fname, cli_errstr(&cli2));
1110 for (offset=i=0;i<numops;i++) {
1112 if (!cli_lock(&cli1, fnum1, offset-1, 1, 0, WRITE_LOCK)) {
1113 printf("lock1 %d failed (%s)\n",
1119 if (!cli_lock(&cli2, fnum2, offset-2, 1, 0, WRITE_LOCK)) {
1120 printf("lock2 %d failed (%s)\n",
1127 for (offset=i=0;i<numops;i++) {
1130 if (cli_lock(&cli1, fnum1, offset-2, 1, 0, WRITE_LOCK)) {
1131 printf("error: lock1 %d succeeded!\n", i);
1135 if (cli_lock(&cli2, fnum2, offset-1, 1, 0, WRITE_LOCK)) {
1136 printf("error: lock2 %d succeeded!\n", i);
1140 if (cli_lock(&cli1, fnum1, offset-1, 1, 0, WRITE_LOCK)) {
1141 printf("error: lock3 %d succeeded!\n", i);
1145 if (cli_lock(&cli2, fnum2, offset-2, 1, 0, WRITE_LOCK)) {
1146 printf("error: lock4 %d succeeded!\n", i);
1151 for (offset=i=0;i<numops;i++) {
1154 if (!cli_unlock(&cli1, fnum1, offset-1, 1)) {
1155 printf("unlock1 %d failed (%s)\n",
1161 if (!cli_unlock(&cli2, fnum2, offset-2, 1)) {
1162 printf("unlock2 %d failed (%s)\n",
1169 if (!cli_close(&cli1, fnum1)) {
1170 printf("close1 failed (%s)\n", cli_errstr(&cli1));
1174 if (!cli_close(&cli2, fnum2)) {
1175 printf("close2 failed (%s)\n", cli_errstr(&cli2));
1179 if (!cli_unlink(&cli1, fname)) {
1180 printf("unlink failed (%s)\n", cli_errstr(&cli1));
1184 if (!torture_close_connection(&cli1)) {
1188 if (!torture_close_connection(&cli2)) {
1192 printf("finished locktest3\n");
1197 #define EXPECTED(ret, v) if ((ret) != (v)) { \
1198 printf("** "); correct = False; \
1202 looks at overlapping locks
1204 static BOOL run_locktest4(int dummy)
1206 static struct cli_state cli1, cli2;
1207 char *fname = "\\lockt4.lck";
1208 int fnum1, fnum2, f;
1211 BOOL correct = True;
1213 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
1217 cli_sockopt(&cli1, sockops);
1218 cli_sockopt(&cli2, sockops);
1220 printf("starting locktest4\n");
1222 cli_unlink(&cli1, fname);
1224 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1225 fnum2 = cli_open(&cli2, fname, O_RDWR, DENY_NONE);
1227 memset(buf, 0, sizeof(buf));
1229 if (cli_write(&cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
1230 printf("Failed to create file\n");
1235 ret = cli_lock(&cli1, fnum1, 0, 4, 0, WRITE_LOCK) &&
1236 cli_lock(&cli1, fnum1, 2, 4, 0, WRITE_LOCK);
1237 EXPECTED(ret, False);
1238 printf("the same process %s set overlapping write locks\n", ret?"can":"cannot");
1240 ret = cli_lock(&cli1, fnum1, 10, 4, 0, READ_LOCK) &&
1241 cli_lock(&cli1, fnum1, 12, 4, 0, READ_LOCK);
1242 EXPECTED(ret, True);
1243 printf("the same process %s set overlapping read locks\n", ret?"can":"cannot");
1245 ret = cli_lock(&cli1, fnum1, 20, 4, 0, WRITE_LOCK) &&
1246 cli_lock(&cli2, fnum2, 22, 4, 0, WRITE_LOCK);
1247 EXPECTED(ret, False);
1248 printf("a different connection %s set overlapping write locks\n", ret?"can":"cannot");
1250 ret = cli_lock(&cli1, fnum1, 30, 4, 0, READ_LOCK) &&
1251 cli_lock(&cli2, fnum2, 32, 4, 0, READ_LOCK);
1252 EXPECTED(ret, True);
1253 printf("a different connection %s set overlapping read locks\n", ret?"can":"cannot");
1255 ret = (cli_setpid(&cli1, 1), cli_lock(&cli1, fnum1, 40, 4, 0, WRITE_LOCK)) &&
1256 (cli_setpid(&cli1, 2), cli_lock(&cli1, fnum1, 42, 4, 0, WRITE_LOCK));
1257 EXPECTED(ret, False);
1258 printf("a different pid %s set overlapping write locks\n", ret?"can":"cannot");
1260 ret = (cli_setpid(&cli1, 1), cli_lock(&cli1, fnum1, 50, 4, 0, READ_LOCK)) &&
1261 (cli_setpid(&cli1, 2), cli_lock(&cli1, fnum1, 52, 4, 0, READ_LOCK));
1262 EXPECTED(ret, True);
1263 printf("a different pid %s set overlapping read locks\n", ret?"can":"cannot");
1265 ret = cli_lock(&cli1, fnum1, 60, 4, 0, READ_LOCK) &&
1266 cli_lock(&cli1, fnum1, 60, 4, 0, READ_LOCK);
1267 EXPECTED(ret, True);
1268 printf("the same process %s set the same read lock twice\n", ret?"can":"cannot");
1270 ret = cli_lock(&cli1, fnum1, 70, 4, 0, WRITE_LOCK) &&
1271 cli_lock(&cli1, fnum1, 70, 4, 0, WRITE_LOCK);
1272 EXPECTED(ret, False);
1273 printf("the same process %s set the same write lock twice\n", ret?"can":"cannot");
1275 ret = cli_lock(&cli1, fnum1, 80, 4, 0, READ_LOCK) &&
1276 cli_lock(&cli1, fnum1, 80, 4, 0, WRITE_LOCK);
1277 EXPECTED(ret, False);
1278 printf("the same process %s overlay a read lock with a write lock\n", ret?"can":"cannot");
1280 ret = cli_lock(&cli1, fnum1, 90, 4, 0, WRITE_LOCK) &&
1281 cli_lock(&cli1, fnum1, 90, 4, 0, READ_LOCK);
1282 EXPECTED(ret, True);
1283 printf("the same process %s overlay a write lock with a read lock\n", ret?"can":"cannot");
1285 ret = (cli_setpid(&cli1, 1), cli_lock(&cli1, fnum1, 100, 4, 0, WRITE_LOCK)) &&
1286 (cli_setpid(&cli1, 2), cli_lock(&cli1, fnum1, 100, 4, 0, READ_LOCK));
1287 EXPECTED(ret, False);
1288 printf("a different pid %s overlay a write lock with a read lock\n", ret?"can":"cannot");
1290 ret = cli_lock(&cli1, fnum1, 110, 4, 0, READ_LOCK) &&
1291 cli_lock(&cli1, fnum1, 112, 4, 0, READ_LOCK) &&
1292 cli_unlock(&cli1, fnum1, 110, 6);
1293 EXPECTED(ret, False);
1294 printf("the same process %s coalesce read locks\n", ret?"can":"cannot");
1297 ret = cli_lock(&cli1, fnum1, 120, 4, 0, WRITE_LOCK) &&
1298 (cli_read(&cli2, fnum2, buf, 120, 4) == 4);
1299 EXPECTED(ret, False);
1300 printf("this server %s strict write locking\n", ret?"doesn't do":"does");
1302 ret = cli_lock(&cli1, fnum1, 130, 4, 0, READ_LOCK) &&
1303 (cli_write(&cli2, fnum2, 0, buf, 130, 4) == 4);
1304 EXPECTED(ret, False);
1305 printf("this server %s strict read locking\n", ret?"doesn't do":"does");
1308 ret = cli_lock(&cli1, fnum1, 140, 4, 0, READ_LOCK) &&
1309 cli_lock(&cli1, fnum1, 140, 4, 0, READ_LOCK) &&
1310 cli_unlock(&cli1, fnum1, 140, 4) &&
1311 cli_unlock(&cli1, fnum1, 140, 4);
1312 EXPECTED(ret, True);
1313 printf("this server %s do recursive read locking\n", ret?"does":"doesn't");
1316 ret = cli_lock(&cli1, fnum1, 150, 4, 0, WRITE_LOCK) &&
1317 cli_lock(&cli1, fnum1, 150, 4, 0, READ_LOCK) &&
1318 cli_unlock(&cli1, fnum1, 150, 4) &&
1319 (cli_read(&cli2, fnum2, buf, 150, 4) == 4) &&
1320 !(cli_write(&cli2, fnum2, 0, buf, 150, 4) == 4) &&
1321 cli_unlock(&cli1, fnum1, 150, 4);
1322 EXPECTED(ret, True);
1323 printf("this server %s do recursive lock overlays\n", ret?"does":"doesn't");
1325 ret = cli_lock(&cli1, fnum1, 160, 4, 0, READ_LOCK) &&
1326 cli_unlock(&cli1, fnum1, 160, 4) &&
1327 (cli_write(&cli2, fnum2, 0, buf, 160, 4) == 4) &&
1328 (cli_read(&cli2, fnum2, buf, 160, 4) == 4);
1329 EXPECTED(ret, True);
1330 printf("the same process %s remove a read lock using write locking\n", ret?"can":"cannot");
1332 ret = cli_lock(&cli1, fnum1, 170, 4, 0, WRITE_LOCK) &&
1333 cli_unlock(&cli1, fnum1, 170, 4) &&
1334 (cli_write(&cli2, fnum2, 0, buf, 170, 4) == 4) &&
1335 (cli_read(&cli2, fnum2, buf, 170, 4) == 4);
1336 EXPECTED(ret, True);
1337 printf("the same process %s remove a write lock using read locking\n", ret?"can":"cannot");
1339 ret = cli_lock(&cli1, fnum1, 190, 4, 0, WRITE_LOCK) &&
1340 cli_lock(&cli1, fnum1, 190, 4, 0, READ_LOCK) &&
1341 cli_unlock(&cli1, fnum1, 190, 4) &&
1342 !(cli_write(&cli2, fnum2, 0, buf, 190, 4) == 4) &&
1343 (cli_read(&cli2, fnum2, buf, 190, 4) == 4);
1344 EXPECTED(ret, True);
1345 printf("the same process %s remove the first lock first\n", ret?"does":"doesn't");
1347 cli_close(&cli1, fnum1);
1348 cli_close(&cli2, fnum2);
1349 fnum1 = cli_open(&cli1, fname, O_RDWR, DENY_NONE);
1350 f = cli_open(&cli1, fname, O_RDWR, DENY_NONE);
1351 ret = cli_lock(&cli1, fnum1, 0, 8, 0, READ_LOCK) &&
1352 cli_lock(&cli1, f, 0, 1, 0, READ_LOCK) &&
1353 cli_close(&cli1, fnum1) &&
1354 ((fnum1 = cli_open(&cli1, fname, O_RDWR, DENY_NONE)) != -1) &&
1355 cli_lock(&cli1, fnum1, 7, 1, 0, WRITE_LOCK);
1356 cli_close(&cli1, f);
1357 cli_close(&cli1, fnum1);
1358 EXPECTED(ret, True);
1359 printf("the server %s have the NT byte range lock bug\n", !ret?"does":"doesn't");
1362 cli_close(&cli1, fnum1);
1363 cli_close(&cli2, fnum2);
1364 cli_unlink(&cli1, fname);
1365 torture_close_connection(&cli1);
1366 torture_close_connection(&cli2);
1368 printf("finished locktest4\n");
1373 looks at lock upgrade/downgrade.
1375 static BOOL run_locktest5(int dummy)
1377 static struct cli_state cli1, cli2;
1378 char *fname = "\\lockt5.lck";
1379 int fnum1, fnum2, fnum3;
1382 BOOL correct = True;
1384 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
1388 cli_sockopt(&cli1, sockops);
1389 cli_sockopt(&cli2, sockops);
1391 printf("starting locktest5\n");
1393 cli_unlink(&cli1, fname);
1395 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1396 fnum2 = cli_open(&cli2, fname, O_RDWR, DENY_NONE);
1397 fnum3 = cli_open(&cli1, fname, O_RDWR, DENY_NONE);
1399 memset(buf, 0, sizeof(buf));
1401 if (cli_write(&cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
1402 printf("Failed to create file\n");
1407 /* Check for NT bug... */
1408 ret = cli_lock(&cli1, fnum1, 0, 8, 0, READ_LOCK) &&
1409 cli_lock(&cli1, fnum3, 0, 1, 0, READ_LOCK);
1410 cli_close(&cli1, fnum1);
1411 fnum1 = cli_open(&cli1, fname, O_RDWR, DENY_NONE);
1412 ret = cli_lock(&cli1, fnum1, 7, 1, 0, WRITE_LOCK);
1413 EXPECTED(ret, True);
1414 printf("this server %s the NT locking bug\n", ret ? "doesn't have" : "has");
1415 cli_close(&cli1, fnum1);
1416 fnum1 = cli_open(&cli1, fname, O_RDWR, DENY_NONE);
1417 cli_unlock(&cli1, fnum3, 0, 1);
1419 ret = cli_lock(&cli1, fnum1, 0, 4, 0, WRITE_LOCK) &&
1420 cli_lock(&cli1, fnum1, 1, 1, 0, READ_LOCK);
1421 EXPECTED(ret, True);
1422 printf("the same process %s overlay a write with a read lock\n", ret?"can":"cannot");
1424 ret = cli_lock(&cli2, fnum2, 0, 4, 0, READ_LOCK);
1425 EXPECTED(ret, False);
1427 printf("a different processs %s get a read lock on the first process lock stack\n", ret?"can":"cannot");
1429 /* Unlock the process 2 lock. */
1430 cli_unlock(&cli2, fnum2, 0, 4);
1432 ret = cli_lock(&cli1, fnum3, 0, 4, 0, READ_LOCK);
1433 EXPECTED(ret, False);
1435 printf("the same processs on a different fnum %s get a read lock\n", ret?"can":"cannot");
1437 /* Unlock the process 1 fnum3 lock. */
1438 cli_unlock(&cli1, fnum3, 0, 4);
1440 /* Stack 2 more locks here. */
1441 ret = cli_lock(&cli1, fnum1, 0, 4, 0, READ_LOCK) &&
1442 cli_lock(&cli1, fnum1, 0, 4, 0, READ_LOCK);
1444 EXPECTED(ret, True);
1445 printf("the same process %s stack read locks\n", ret?"can":"cannot");
1447 /* Unlock the first process lock, then check this was the WRITE lock that was
1450 ret = cli_unlock(&cli1, fnum1, 0, 4) &&
1451 cli_lock(&cli2, fnum2, 0, 4, 0, READ_LOCK);
1453 EXPECTED(ret, True);
1454 printf("the first unlock removes the %s lock\n", ret?"WRITE":"READ");
1456 /* Unlock the process 2 lock. */
1457 cli_unlock(&cli2, fnum2, 0, 4);
1459 /* We should have 3 stacked locks here. Ensure we need to do 3 unlocks. */
1461 ret = cli_unlock(&cli1, fnum1, 1, 1) &&
1462 cli_unlock(&cli1, fnum1, 0, 4) &&
1463 cli_unlock(&cli1, fnum1, 0, 4);
1465 EXPECTED(ret, True);
1466 printf("the same process %s unlock the stack of 4 locks\n", ret?"can":"cannot");
1468 /* Ensure the next unlock fails. */
1469 ret = cli_unlock(&cli1, fnum1, 0, 4);
1470 EXPECTED(ret, False);
1471 printf("the same process %s count the lock stack\n", !ret?"can":"cannot");
1473 /* Ensure connection 2 can get a write lock. */
1474 ret = cli_lock(&cli2, fnum2, 0, 4, 0, WRITE_LOCK);
1475 EXPECTED(ret, True);
1477 printf("a different processs %s get a write lock on the unlocked stack\n", ret?"can":"cannot");
1481 cli_close(&cli1, fnum1);
1482 cli_close(&cli2, fnum2);
1483 cli_unlink(&cli1, fname);
1484 if (!torture_close_connection(&cli1)) {
1487 if (!torture_close_connection(&cli2)) {
1491 printf("finished locktest5\n");
1497 tries the unusual lockingX locktype bits
1499 static BOOL run_locktest6(int dummy)
1501 static struct cli_state cli;
1502 char *fname[1] = { "\\lock6.txt" };
1507 if (!torture_open_connection(&cli)) {
1511 cli_sockopt(&cli, sockops);
1513 printf("starting locktest6\n");
1516 printf("Testing %s\n", fname[i]);
1518 cli_unlink(&cli, fname[i]);
1520 fnum = cli_open(&cli, fname[i], O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1521 status = cli_locktype(&cli, fnum, 0, 8, 0, LOCKING_ANDX_CHANGE_LOCKTYPE);
1522 cli_close(&cli, fnum);
1523 printf("CHANGE_LOCKTYPE gave %s\n", get_nt_error_msg(status));
1525 fnum = cli_open(&cli, fname[i], O_RDWR, DENY_NONE);
1526 status = cli_locktype(&cli, fnum, 0, 8, 0, LOCKING_ANDX_CANCEL_LOCK);
1527 cli_close(&cli, fnum);
1528 printf("CANCEL_LOCK gave %s\n", get_nt_error_msg(status));
1530 cli_unlink(&cli, fname[i]);
1533 torture_close_connection(&cli);
1535 printf("finished locktest6\n");
1540 test whether fnums and tids open on one VC are available on another (a major
1543 static BOOL run_fdpasstest(int dummy)
1545 static struct cli_state cli1, cli2, cli3;
1546 char *fname = "\\fdpass.tst";
1550 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
1553 cli_sockopt(&cli1, sockops);
1554 cli_sockopt(&cli2, sockops);
1556 printf("starting fdpasstest\n");
1558 cli_unlink(&cli1, fname);
1560 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1562 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
1566 if (cli_write(&cli1, fnum1, 0, "hello world\n", 0, 13) != 13) {
1567 printf("write failed (%s)\n", cli_errstr(&cli1));
1572 cli3.vuid = cli1.vuid;
1573 cli3.cnum = cli1.cnum;
1574 cli3.pid = cli1.pid;
1576 if (cli_read(&cli3, fnum1, buf, 0, 13) == 13) {
1577 printf("read succeeded! nasty security hole [%s]\n",
1582 cli_close(&cli1, fnum1);
1583 cli_unlink(&cli1, fname);
1585 torture_close_connection(&cli1);
1586 torture_close_connection(&cli2);
1588 printf("finished fdpasstest\n");
1594 This test checks that
1596 1) the server does not allow an unlink on a file that is open
1598 static BOOL run_unlinktest(int dummy)
1600 static struct cli_state cli;
1601 char *fname = "\\unlink.tst";
1603 BOOL correct = True;
1605 if (!torture_open_connection(&cli)) {
1609 cli_sockopt(&cli, sockops);
1611 printf("starting unlink test\n");
1613 cli_unlink(&cli, fname);
1615 cli_setpid(&cli, 1);
1617 fnum = cli_open(&cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1619 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli));
1623 if (cli_unlink(&cli, fname)) {
1624 printf("error: server allowed unlink on an open file\n");
1627 correct = check_error(__LINE__, &cli, ERRDOS, ERRbadshare,
1628 NT_STATUS_SHARING_VIOLATION);
1631 cli_close(&cli, fnum);
1632 cli_unlink(&cli, fname);
1634 if (!torture_close_connection(&cli)) {
1638 printf("unlink test finished\n");
1645 test how many open files this server supports on the one socket
1647 static BOOL run_maxfidtest(int dummy)
1649 static struct cli_state cli;
1650 char *template = "\\maxfid.%d.%d";
1652 int fnums[0x11000], i;
1654 BOOL correct = True;
1659 printf("failed to connect\n");
1663 cli_sockopt(&cli, sockops);
1665 for (i=0; i<0x11000; i++) {
1666 slprintf(fname,sizeof(fname)-1,template, i,(int)getpid());
1667 if ((fnums[i] = cli_open(&cli, fname,
1668 O_RDWR|O_CREAT|O_TRUNC, DENY_NONE)) ==
1670 printf("open of %s failed (%s)\n",
1671 fname, cli_errstr(&cli));
1672 printf("maximum fnum is %d\n", i);
1680 printf("cleaning up\n");
1682 slprintf(fname,sizeof(fname)-1,template, i,(int)getpid());
1683 cli_close(&cli, fnums[i]);
1684 if (!cli_unlink(&cli, fname)) {
1685 printf("unlink of %s failed (%s)\n",
1686 fname, cli_errstr(&cli));
1693 printf("maxfid test finished\n");
1694 if (!torture_close_connection(&cli)) {
1700 /* generate a random buffer */
1701 static void rand_buf(char *buf, int len)
1704 *buf = (char)sys_random();
1709 /* send smb negprot commands, not reading the response */
1710 static BOOL run_negprot_nowait(int dummy)
1713 static struct cli_state cli;
1714 BOOL correct = True;
1716 printf("starting negprot nowait test\n");
1718 if (!open_nbt_connection(&cli)) {
1722 for (i=0;i<50000;i++) {
1723 cli_negprot_send(&cli);
1726 if (!torture_close_connection(&cli)) {
1730 printf("finished negprot nowait test\n");
1736 /* send random IPC commands */
1737 static BOOL run_randomipc(int dummy)
1739 char *rparam = NULL;
1743 int api, param_len, i;
1744 static struct cli_state cli;
1745 BOOL correct = True;
1748 printf("starting random ipc test\n");
1750 if (!torture_open_connection(&cli)) {
1754 for (i=0;i<count;i++) {
1755 api = sys_random() % 500;
1756 param_len = (sys_random() % 64);
1758 rand_buf(param, param_len);
1763 param, param_len, 8,
1764 NULL, 0, BUFFER_SIZE,
1768 printf("%d/%d\r", i,count);
1771 printf("%d/%d\n", i, count);
1773 if (!torture_close_connection(&cli)) {
1777 printf("finished random ipc test\n");
1784 static void browse_callback(const char *sname, uint32 stype,
1785 const char *comment, void *state)
1787 printf("\t%20.20s %08x %s\n", sname, stype, comment);
1793 This test checks the browse list code
1796 static BOOL run_browsetest(int dummy)
1798 static struct cli_state cli;
1799 BOOL correct = True;
1801 printf("starting browse test\n");
1803 if (!torture_open_connection(&cli)) {
1807 printf("domain list:\n");
1808 cli_NetServerEnum(&cli, cli.server_domain,
1809 SV_TYPE_DOMAIN_ENUM,
1810 browse_callback, NULL);
1812 printf("machine list:\n");
1813 cli_NetServerEnum(&cli, cli.server_domain,
1815 browse_callback, NULL);
1817 if (!torture_close_connection(&cli)) {
1821 printf("browse test finished\n");
1829 This checks how the getatr calls works
1831 static BOOL run_attrtest(int dummy)
1833 static struct cli_state cli;
1836 char *fname = "\\attrib.tst";
1837 BOOL correct = True;
1839 printf("starting attrib test\n");
1841 if (!torture_open_connection(&cli)) {
1845 cli_unlink(&cli, fname);
1846 fnum = cli_open(&cli, fname,
1847 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1848 cli_close(&cli, fnum);
1849 if (!cli_getatr(&cli, fname, NULL, NULL, &t)) {
1850 printf("getatr failed (%s)\n", cli_errstr(&cli));
1854 if (abs(t - time(NULL)) > 60*60*24*10) {
1855 printf("ERROR: SMBgetatr bug. time is %s",
1861 t2 = t-60*60*24; /* 1 day ago */
1863 if (!cli_setatr(&cli, fname, 0, t2)) {
1864 printf("setatr failed (%s)\n", cli_errstr(&cli));
1868 if (!cli_getatr(&cli, fname, NULL, NULL, &t)) {
1869 printf("getatr failed (%s)\n", cli_errstr(&cli));
1874 printf("ERROR: getatr/setatr bug. times are\n%s",
1876 printf("%s", ctime(&t2));
1880 cli_unlink(&cli, fname);
1882 if (!torture_close_connection(&cli)) {
1886 printf("attrib test finished\n");
1893 This checks a couple of trans2 calls
1895 static BOOL run_trans2test(int dummy)
1897 static struct cli_state cli;
1900 time_t c_time, a_time, m_time, w_time, m_time2;
1901 char *fname = "\\trans2.tst";
1902 char *dname = "\\trans2";
1903 char *fname2 = "\\trans2\\trans2.tst";
1905 BOOL correct = True;
1907 printf("starting trans2 test\n");
1909 if (!torture_open_connection(&cli)) {
1913 cli_unlink(&cli, fname);
1914 fnum = cli_open(&cli, fname,
1915 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1916 if (!cli_qfileinfo(&cli, fnum, NULL, &size, &c_time, &a_time, &m_time,
1918 printf("ERROR: qfileinfo failed (%s)\n", cli_errstr(&cli));
1922 if (!cli_qfilename(&cli, fnum, pname)) {
1923 printf("ERROR: qfilename failed (%s)\n", cli_errstr(&cli));
1927 if (strcmp(pname, fname)) {
1928 printf("qfilename gave different name? [%s] [%s]\n",
1933 cli_close(&cli, fnum);
1937 cli_unlink(&cli, fname);
1938 fnum = cli_open(&cli, fname,
1939 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1941 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli));
1944 cli_close(&cli, fnum);
1946 if (!cli_qpathinfo(&cli, fname, &c_time, &a_time, &m_time, &size, NULL)) {
1947 printf("ERROR: qpathinfo failed (%s)\n", cli_errstr(&cli));
1950 if (c_time != m_time) {
1951 printf("create time=%s", ctime(&c_time));
1952 printf("modify time=%s", ctime(&m_time));
1953 printf("This system appears to have sticky create times\n");
1956 if (a_time % (60*60) == 0) {
1957 printf("access time=%s", ctime(&a_time));
1958 printf("This system appears to set a midnight access time\n");
1962 if (abs(m_time - time(NULL)) > 60*60*24*7) {
1963 printf("ERROR: totally incorrect times - maybe word reversed? mtime=%s", ctime(&m_time));
1969 cli_unlink(&cli, fname);
1970 fnum = cli_open(&cli, fname,
1971 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1972 cli_close(&cli, fnum);
1973 if (!cli_qpathinfo2(&cli, fname, &c_time, &a_time, &m_time,
1974 &w_time, &size, NULL, NULL)) {
1975 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli));
1978 if (w_time < 60*60*24*2) {
1979 printf("write time=%s", ctime(&w_time));
1980 printf("This system appears to set a initial 0 write time\n");
1985 cli_unlink(&cli, fname);
1988 /* check if the server updates the directory modification time
1989 when creating a new file */
1990 if (!cli_mkdir(&cli, dname)) {
1991 printf("ERROR: mkdir failed (%s)\n", cli_errstr(&cli));
1995 if (!cli_qpathinfo2(&cli, "\\trans2\\", &c_time, &a_time, &m_time,
1996 &w_time, &size, NULL, NULL)) {
1997 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli));
2001 fnum = cli_open(&cli, fname2,
2002 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2003 cli_write(&cli, fnum, 0, (char *)&fnum, 0, sizeof(fnum));
2004 cli_close(&cli, fnum);
2005 if (!cli_qpathinfo2(&cli, "\\trans2\\", &c_time, &a_time, &m_time2,
2006 &w_time, &size, NULL, NULL)) {
2007 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli));
2010 if (m_time2 == m_time) {
2011 printf("This system does not update directory modification times\n");
2015 cli_unlink(&cli, fname2);
2016 cli_rmdir(&cli, dname);
2018 if (!torture_close_connection(&cli)) {
2022 printf("trans2 test finished\n");
2028 This checks new W2K calls.
2031 static BOOL new_trans(struct cli_state *pcli, int fnum, int level)
2034 BOOL correct = True;
2036 memset(buf, 0xff, sizeof(buf));
2038 if (!cli_qfileinfo_test(pcli, fnum, level, buf)) {
2039 printf("ERROR: qfileinfo (%d) failed (%s)\n", level, cli_errstr(pcli));
2042 printf("qfileinfo: level %d\n", level);
2043 dump_data(0, buf, 256);
2049 static BOOL run_w2ktest(int dummy)
2051 static struct cli_state cli;
2053 char *fname = "\\w2ktest\\w2k.tst";
2055 BOOL correct = True;
2057 printf("starting w2k test\n");
2059 if (!torture_open_connection(&cli)) {
2063 fnum = cli_open(&cli, fname,
2064 O_RDWR | O_CREAT , DENY_NONE);
2066 for (level = 1004; level < 1040; level++) {
2067 new_trans(&cli, fnum, level);
2070 cli_close(&cli, fnum);
2072 if (!torture_close_connection(&cli)) {
2076 printf("w2k test finished\n");
2083 this is a harness for some oplock tests
2085 static BOOL run_oplock1(int dummy)
2087 static struct cli_state cli1;
2088 char *fname = "\\lockt1.lck";
2090 BOOL correct = True;
2092 printf("starting oplock test 1\n");
2094 if (!torture_open_connection(&cli1)) {
2098 cli_unlink(&cli1, fname);
2100 cli_sockopt(&cli1, sockops);
2102 cli1.use_oplocks = True;
2104 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2106 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2110 cli1.use_oplocks = False;
2112 cli_unlink(&cli1, fname);
2113 cli_unlink(&cli1, fname);
2115 if (!cli_close(&cli1, fnum1)) {
2116 printf("close2 failed (%s)\n", cli_errstr(&cli1));
2120 if (!cli_unlink(&cli1, fname)) {
2121 printf("unlink failed (%s)\n", cli_errstr(&cli1));
2125 if (!torture_close_connection(&cli1)) {
2129 printf("finished oplock test 1\n");
2134 static BOOL run_oplock2(int dummy)
2136 static struct cli_state cli1, cli2;
2137 char *fname = "\\lockt2.lck";
2139 int saved_use_oplocks = use_oplocks;
2141 BOOL correct = True;
2142 volatile BOOL *shared_correct;
2144 shared_correct = (volatile BOOL *)shm_setup(sizeof(BOOL));
2145 *shared_correct = True;
2147 use_level_II_oplocks = True;
2150 printf("starting oplock test 2\n");
2152 if (!torture_open_connection(&cli1)) {
2153 use_level_II_oplocks = False;
2154 use_oplocks = saved_use_oplocks;
2158 cli1.use_oplocks = True;
2159 cli1.use_level_II_oplocks = True;
2161 if (!torture_open_connection(&cli2)) {
2162 use_level_II_oplocks = False;
2163 use_oplocks = saved_use_oplocks;
2167 cli2.use_oplocks = True;
2168 cli2.use_level_II_oplocks = True;
2170 cli_unlink(&cli1, fname);
2172 cli_sockopt(&cli1, sockops);
2173 cli_sockopt(&cli2, sockops);
2175 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2177 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2181 /* Don't need the globals any more. */
2182 use_level_II_oplocks = False;
2183 use_oplocks = saved_use_oplocks;
2187 fnum2 = cli_open(&cli2, fname, O_RDWR, DENY_NONE);
2189 printf("second open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2190 *shared_correct = False;
2196 if (!cli_close(&cli2, fnum2)) {
2197 printf("close2 failed (%s)\n", cli_errstr(&cli1));
2198 *shared_correct = False;
2206 /* Ensure cli1 processes the break. */
2208 if (cli_read(&cli1, fnum1, buf, 0, 4) != 4) {
2209 printf("read on fnum1 failed (%s)\n", cli_errstr(&cli1));
2213 /* Should now be at level II. */
2214 /* Test if sending a write locks causes a break to none. */
2216 if (!cli_lock(&cli1, fnum1, 0, 4, 0, READ_LOCK)) {
2217 printf("lock failed (%s)\n", cli_errstr(&cli1));
2221 cli_unlock(&cli1, fnum1, 0, 4);
2225 if (!cli_lock(&cli1, fnum1, 0, 4, 0, WRITE_LOCK)) {
2226 printf("lock failed (%s)\n", cli_errstr(&cli1));
2230 cli_unlock(&cli1, fnum1, 0, 4);
2234 cli_read(&cli1, fnum1, buf, 0, 4);
2237 if (cli_write(&cli1, fnum1, 0, buf, 0, 4) != 4) {
2238 printf("write on fnum1 failed (%s)\n", cli_errstr(&cli1));
2243 if (!cli_close(&cli1, fnum1)) {
2244 printf("close1 failed (%s)\n", cli_errstr(&cli1));
2250 if (!cli_unlink(&cli1, fname)) {
2251 printf("unlink failed (%s)\n", cli_errstr(&cli1));
2255 if (!torture_close_connection(&cli1)) {
2259 if (!*shared_correct) {
2263 printf("finished oplock test 2\n");
2268 /* handler for oplock 3 tests */
2269 static BOOL oplock3_handler(struct cli_state *cli, int fnum, unsigned char level)
2271 printf("got oplock break fnum=%d level=%d\n",
2273 return cli_oplock_ack(cli, fnum, level);
2276 static BOOL run_oplock3(int dummy)
2278 static struct cli_state cli;
2279 char *fname = "\\oplockt3.dat";
2281 char buf[4] = "abcd";
2282 BOOL correct = True;
2283 volatile BOOL *shared_correct;
2285 shared_correct = (volatile BOOL *)shm_setup(sizeof(BOOL));
2286 *shared_correct = True;
2288 printf("starting oplock test 3\n");
2293 use_level_II_oplocks = True;
2294 if (!torture_open_connection(&cli)) {
2295 *shared_correct = False;
2299 /* try to trigger a oplock break in parent */
2300 fnum = cli_open(&cli, fname, O_RDWR, DENY_NONE);
2301 cli_write(&cli, fnum, 0, buf, 0, 4);
2307 use_level_II_oplocks = True;
2308 if (!torture_open_connection(&cli)) {
2311 cli_oplock_handler(&cli, oplock3_handler);
2312 fnum = cli_open(&cli, fname, O_RDWR|O_CREAT, DENY_NONE);
2313 cli_write(&cli, fnum, 0, buf, 0, 4);
2314 cli_close(&cli, fnum);
2315 fnum = cli_open(&cli, fname, O_RDWR, DENY_NONE);
2316 cli.timeout = 20000;
2317 cli_receive_smb(&cli);
2318 printf("finished oplock test 3\n");
2320 return (correct && *shared_correct);
2322 /* What are we looking for here? What's sucess and what's FAILURE? */
2328 Test delete on close semantics.
2330 static BOOL run_deletetest(int dummy)
2332 static struct cli_state cli1;
2333 static struct cli_state cli2;
2334 char *fname = "\\delete.file";
2337 BOOL correct = True;
2339 printf("starting delete test\n");
2344 if (!torture_open_connection(&cli1)) {
2348 cli_sockopt(&cli1, sockops);
2350 /* Test 1 - this should *NOT* delete the file on close. */
2352 cli_setatr(&cli1, fname, 0, 0);
2353 cli_unlink(&cli1, fname);
2355 fnum1 = cli_nt_create_full(&cli1, fname, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL,
2356 FILE_SHARE_DELETE, FILE_OVERWRITE_IF,
2357 DELETE_ON_CLOSE_FLAG);
2360 printf("[1] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2365 if (!cli_close(&cli1, fnum1)) {
2366 printf("[1] close failed (%s)\n", cli_errstr(&cli1));
2371 fnum1 = cli_open(&cli1, fname, O_RDWR, DENY_NONE);
2373 printf("[1] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2378 if (!cli_close(&cli1, fnum1)) {
2379 printf("[1] close failed (%s)\n", cli_errstr(&cli1));
2384 printf("first delete on close test succeeded.\n");
2386 /* Test 2 - this should delete the file on close. */
2388 cli_setatr(&cli1, fname, 0, 0);
2389 cli_unlink(&cli1, fname);
2391 fnum1 = cli_nt_create_full(&cli1, fname, GENERIC_ALL_ACCESS,
2392 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
2393 FILE_OVERWRITE_IF, 0);
2396 printf("[2] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2401 if (!cli_nt_delete_on_close(&cli1, fnum1, True)) {
2402 printf("[2] setting delete_on_close failed (%s)\n", cli_errstr(&cli1));
2407 if (!cli_close(&cli1, fnum1)) {
2408 printf("[2] close failed (%s)\n", cli_errstr(&cli1));
2413 fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_NONE);
2415 printf("[2] open of %s succeeded should have been deleted on close !\n", fname);
2416 if (!cli_close(&cli1, fnum1)) {
2417 printf("[2] close failed (%s)\n", cli_errstr(&cli1));
2421 cli_unlink(&cli1, fname);
2423 printf("second 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, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL,
2430 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0);
2433 printf("[3] open - 1 of %s failed (%s)\n", fname, cli_errstr(&cli1));
2438 /* This should fail with a sharing violation - open for delete is only compatible
2439 with SHARE_DELETE. */
2441 fnum2 = cli_nt_create_full(&cli1, fname, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
2442 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0);
2445 printf("[3] open - 2 of %s succeeded - should have failed.\n", fname);
2450 /* This should succeed. */
2452 fnum2 = cli_nt_create_full(&cli1, fname, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
2453 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0);
2456 printf("[3] open - 2 of %s failed (%s)\n", fname, cli_errstr(&cli1));
2461 if (!cli_nt_delete_on_close(&cli1, fnum1, True)) {
2462 printf("[3] setting delete_on_close failed (%s)\n", cli_errstr(&cli1));
2467 if (!cli_close(&cli1, fnum1)) {
2468 printf("[3] close 1 failed (%s)\n", cli_errstr(&cli1));
2473 if (!cli_close(&cli1, fnum2)) {
2474 printf("[3] close 2 failed (%s)\n", cli_errstr(&cli1));
2479 /* This should fail - file should no longer be there. */
2481 fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_NONE);
2483 printf("[3] open of %s succeeded should have been deleted on close !\n", fname);
2484 if (!cli_close(&cli1, fnum1)) {
2485 printf("[3] close failed (%s)\n", cli_errstr(&cli1));
2487 cli_unlink(&cli1, fname);
2491 printf("third 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|DELETE_ACCESS,
2498 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0);
2501 printf("[4] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2506 /* This should succeed. */
2507 fnum2 = cli_nt_create_full(&cli1, fname, GENERIC_READ_ACCESS,
2508 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0);
2510 printf("[4] open - 2 of %s failed (%s)\n", fname, cli_errstr(&cli1));
2515 if (!cli_close(&cli1, fnum2)) {
2516 printf("[4] close - 1 failed (%s)\n", cli_errstr(&cli1));
2521 if (!cli_nt_delete_on_close(&cli1, fnum1, True)) {
2522 printf("[4] setting delete_on_close failed (%s)\n", cli_errstr(&cli1));
2527 /* This should fail - no more opens once delete on close set. */
2528 fnum2 = cli_nt_create_full(&cli1, fname, GENERIC_READ_ACCESS,
2529 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0);
2531 printf("[4] open - 3 of %s succeeded ! Should have failed.\n", fname );
2535 printf("fourth delete on close test succeeded.\n");
2537 if (!cli_close(&cli1, fnum1)) {
2538 printf("[4] close - 2 failed (%s)\n", cli_errstr(&cli1));
2544 cli_setatr(&cli1, fname, 0, 0);
2545 cli_unlink(&cli1, fname);
2547 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT, DENY_NONE);
2549 printf("[5] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2554 /* This should fail - only allowed on NT opens with DELETE access. */
2556 if (cli_nt_delete_on_close(&cli1, fnum1, True)) {
2557 printf("[5] setting delete_on_close on OpenX file succeeded - should fail !\n");
2562 if (!cli_close(&cli1, fnum1)) {
2563 printf("[5] close - 2 failed (%s)\n", cli_errstr(&cli1));
2568 printf("fifth delete on close test succeeded.\n");
2571 cli_setatr(&cli1, fname, 0, 0);
2572 cli_unlink(&cli1, fname);
2574 fnum1 = cli_nt_create_full(&cli1, fname, FILE_READ_DATA|FILE_WRITE_DATA,
2575 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
2576 FILE_OVERWRITE_IF, 0);
2579 printf("[6] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2584 /* This should fail - only allowed on NT opens with DELETE access. */
2586 if (cli_nt_delete_on_close(&cli1, fnum1, True)) {
2587 printf("[6] setting delete_on_close on file with no delete access succeeded - should fail !\n");
2592 if (!cli_close(&cli1, fnum1)) {
2593 printf("[6] close - 2 failed (%s)\n", cli_errstr(&cli1));
2598 printf("sixth delete on close test succeeded.\n");
2601 cli_setatr(&cli1, fname, 0, 0);
2602 cli_unlink(&cli1, fname);
2604 fnum1 = cli_nt_create_full(&cli1, fname, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
2605 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF, 0);
2608 printf("[7] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2613 if (!cli_nt_delete_on_close(&cli1, fnum1, True)) {
2614 printf("[7] setting delete_on_close on file failed !\n");
2619 if (!cli_nt_delete_on_close(&cli1, fnum1, False)) {
2620 printf("[7] unsetting delete_on_close on file failed !\n");
2625 if (!cli_close(&cli1, fnum1)) {
2626 printf("[7] close - 2 failed (%s)\n", cli_errstr(&cli1));
2631 /* This next open should succeed - we reset the flag. */
2633 fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_NONE);
2635 printf("[5] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2640 if (!cli_close(&cli1, fnum1)) {
2641 printf("[7] close - 2 failed (%s)\n", cli_errstr(&cli1));
2646 printf("seventh delete on close test succeeded.\n");
2649 cli_setatr(&cli1, fname, 0, 0);
2650 cli_unlink(&cli1, fname);
2652 if (!torture_open_connection(&cli2)) {
2653 printf("[8] failed to open second connection.\n");
2658 cli_sockopt(&cli1, sockops);
2660 fnum1 = cli_nt_create_full(&cli1, fname, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
2661 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0);
2664 printf("[8] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2669 fnum2 = cli_nt_create_full(&cli2, fname, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
2670 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0);
2673 printf("[8] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2678 if (!cli_nt_delete_on_close(&cli1, fnum1, True)) {
2679 printf("[8] setting delete_on_close on file failed !\n");
2684 if (!cli_close(&cli1, fnum1)) {
2685 printf("[8] close - 1 failed (%s)\n", cli_errstr(&cli1));
2690 if (!cli_close(&cli2, fnum2)) {
2691 printf("[8] close - 2 failed (%s)\n", cli_errstr(&cli2));
2696 /* This should fail.. */
2697 fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_NONE);
2699 printf("[8] open of %s succeeded should have been deleted on close !\n", fname);
2703 printf("eighth delete on close test succeeded.\n");
2705 /* This should fail - we need to set DELETE_ACCESS. */
2706 fnum1 = cli_nt_create_full(&cli1, fname, FILE_READ_DATA|FILE_WRITE_DATA,
2707 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, FILE_OVERWRITE_IF, FILE_DELETE_ON_CLOSE);
2710 printf("[9] open of %s succeeded should have failed!\n", fname);
2715 printf("ninth delete on close test succeeded.\n");
2717 fnum1 = cli_nt_create_full(&cli1, fname, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
2718 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, FILE_OVERWRITE_IF, FILE_DELETE_ON_CLOSE);
2720 printf("[10] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2725 /* This should delete the file. */
2726 if (!cli_close(&cli1, fnum1)) {
2727 printf("[10] close failed (%s)\n", cli_errstr(&cli1));
2732 /* This should fail.. */
2733 fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_NONE);
2735 printf("[10] open of %s succeeded should have been deleted on close !\n", fname);
2739 printf("tenth delete on close test succeeded.\n");
2740 printf("finished delete test\n");
2744 cli_close(&cli1, fnum1);
2745 cli_close(&cli1, fnum2);
2746 cli_setatr(&cli1, fname, 0, 0);
2747 cli_unlink(&cli1, fname);
2749 if (!torture_close_connection(&cli1)) {
2752 if (!torture_close_connection(&cli2)) {
2758 /* FIRST_DESIRED_ACCESS 0xf019f */
2759 #define FIRST_DESIRED_ACCESS FILE_READ_DATA|FILE_WRITE_DATA|FILE_APPEND_DATA|\
2760 FILE_READ_EA| /* 0xf */ \
2761 FILE_WRITE_EA|FILE_READ_ATTRIBUTES| /* 0x90 */ \
2762 FILE_WRITE_ATTRIBUTES| /* 0x100 */ \
2763 DELETE_ACCESS|READ_CONTROL_ACCESS|\
2764 WRITE_DAC_ACCESS|WRITE_OWNER_ACCESS /* 0xf0000 */
2765 /* SECOND_DESIRED_ACCESS 0xe0080 */
2766 #define SECOND_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
2767 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
2768 WRITE_OWNER_ACCESS /* 0xe0000 */
2771 #define THIRD_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
2772 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
2774 WRITE_OWNER_ACCESS /* */
2778 Test ntcreate calls made by xcopy
2780 static BOOL run_xcopy(int dummy)
2782 static struct cli_state cli1;
2783 char *fname = "\\test.txt";
2784 BOOL correct = True;
2787 printf("starting xcopy test\n");
2789 if (!torture_open_connection(&cli1)) {
2793 fnum1 = cli_nt_create_full(&cli1, fname,
2794 FIRST_DESIRED_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
2795 FILE_SHARE_NONE, FILE_OVERWRITE_IF,
2799 printf("First open failed - %s\n", cli_errstr(&cli1));
2803 fnum2 = cli_nt_create_full(&cli1, fname,
2804 SECOND_DESIRED_ACCESS, 0,
2805 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN,
2808 printf("second open failed - %s\n", cli_errstr(&cli1));
2812 if (!torture_close_connection(&cli1)) {
2820 Test rename on files open with share delete and no share delete.
2822 static BOOL run_rename(int dummy)
2824 static struct cli_state cli1;
2825 char *fname = "\\test.txt";
2826 char *fname1 = "\\test1.txt";
2827 BOOL correct = True;
2830 printf("starting rename test\n");
2832 if (!torture_open_connection(&cli1)) {
2836 cli_unlink(&cli1, fname);
2837 cli_unlink(&cli1, fname1);
2838 fnum1 = cli_nt_create_full(&cli1, fname, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
2839 FILE_SHARE_READ, FILE_OVERWRITE_IF, 0);
2842 printf("First open failed - %s\n", cli_errstr(&cli1));
2846 if (!cli_rename(&cli1, fname, fname1)) {
2847 printf("First rename failed (this is correct) - %s\n", cli_errstr(&cli1));
2849 printf("First rename succeeded - this should have failed !\n");
2853 if (!cli_close(&cli1, fnum1)) {
2854 printf("close - 1 failed (%s)\n", cli_errstr(&cli1));
2858 cli_unlink(&cli1, fname);
2859 cli_unlink(&cli1, fname1);
2860 fnum1 = cli_nt_create_full(&cli1, fname,GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
2861 FILE_SHARE_DELETE|FILE_SHARE_READ, FILE_OVERWRITE_IF, 0);
2864 printf("Second open failed - %s\n", cli_errstr(&cli1));
2868 if (!cli_rename(&cli1, fname, fname1)) {
2869 printf("Second rename failed - this should have succeeded - %s\n", cli_errstr(&cli1));
2872 printf("Second rename succeeded\n");
2875 if (!cli_close(&cli1, fnum1)) {
2876 printf("close - 2 failed (%s)\n", cli_errstr(&cli1));
2880 cli_unlink(&cli1, fname);
2881 cli_unlink(&cli1, fname1);
2883 if (!torture_close_connection(&cli1)) {
2892 Test open mode returns on read-only files.
2894 static BOOL run_opentest(int dummy)
2896 static struct cli_state cli1;
2897 char *fname = "\\readonly.file";
2901 BOOL correct = True;
2904 printf("starting open test\n");
2906 if (!torture_open_connection(&cli1)) {
2910 cli_setatr(&cli1, fname, 0, 0);
2911 cli_unlink(&cli1, fname);
2913 cli_sockopt(&cli1, sockops);
2915 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2917 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2921 if (!cli_close(&cli1, fnum1)) {
2922 printf("close2 failed (%s)\n", cli_errstr(&cli1));
2926 if (!cli_setatr(&cli1, fname, aRONLY, 0)) {
2927 printf("cli_setatr failed (%s)\n", cli_errstr(&cli1));
2931 fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_WRITE);
2933 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2937 /* This will fail - but the error should be ERRnoaccess, not ERRbadshare. */
2938 fnum2 = cli_open(&cli1, fname, O_RDWR, DENY_ALL);
2940 if (check_error(__LINE__, &cli1, ERRDOS, ERRnoaccess,
2941 NT_STATUS_ACCESS_DENIED)) {
2942 printf("correct error code ERRDOS/ERRnoaccess returned\n");
2945 printf("finished open test 1\n");
2947 cli_close(&cli1, fnum1);
2949 /* Now try not readonly and ensure ERRbadshare is returned. */
2951 cli_setatr(&cli1, fname, 0, 0);
2953 fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_WRITE);
2955 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2959 /* This will fail - but the error should be ERRshare. */
2960 fnum2 = cli_open(&cli1, fname, O_RDWR, DENY_ALL);
2962 if (check_error(__LINE__, &cli1, ERRDOS, ERRbadshare,
2963 NT_STATUS_SHARING_VIOLATION)) {
2964 printf("correct error code ERRDOS/ERRbadshare returned\n");
2967 if (!cli_close(&cli1, fnum1)) {
2968 printf("close2 failed (%s)\n", cli_errstr(&cli1));
2972 cli_unlink(&cli1, fname);
2974 printf("finished open test 2\n");
2976 /* Test truncate open disposition on file opened for read. */
2978 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2980 printf("(3) open (1) of %s failed (%s)\n", fname, cli_errstr(&cli1));
2984 /* write 20 bytes. */
2986 memset(buf, '\0', 20);
2988 if (cli_write(&cli1, fnum1, 0, buf, 0, 20) != 20) {
2989 printf("write failed (%s)\n", cli_errstr(&cli1));
2993 if (!cli_close(&cli1, fnum1)) {
2994 printf("(3) close1 failed (%s)\n", cli_errstr(&cli1));
2998 /* Ensure size == 20. */
2999 if (!cli_getatr(&cli1, fname, NULL, &fsize, NULL)) {
3000 printf("(3) getatr failed (%s)\n", cli_errstr(&cli1));
3005 printf("(3) file size != 20\n");
3009 /* Now test if we can truncate a file opened for readonly. */
3011 fnum1 = cli_open(&cli1, fname, O_RDONLY|O_TRUNC, DENY_NONE);
3013 printf("(3) open (2) of %s failed (%s)\n", fname, cli_errstr(&cli1));
3017 if (!cli_close(&cli1, fnum1)) {
3018 printf("close2 failed (%s)\n", cli_errstr(&cli1));
3022 /* Ensure size == 0. */
3023 if (!cli_getatr(&cli1, fname, NULL, &fsize, NULL)) {
3024 printf("(3) getatr failed (%s)\n", cli_errstr(&cli1));
3029 printf("(3) file size != 0\n");
3032 printf("finished open test 3\n");
3034 cli_unlink(&cli1, fname);
3037 printf("testing ctemp\n");
3038 fnum1 = cli_ctemp(&cli1, "\\", &tmp_path);
3040 printf("ctemp failed (%s)\n", cli_errstr(&cli1));
3043 printf("ctemp gave path %s\n", tmp_path);
3044 if (!cli_close(&cli1, fnum1)) {
3045 printf("close of temp failed (%s)\n", cli_errstr(&cli1));
3047 if (!cli_unlink(&cli1, tmp_path)) {
3048 printf("unlink of temp failed (%s)\n", cli_errstr(&cli1));
3051 if (!torture_close_connection(&cli1)) {
3058 static void list_fn(file_info *finfo, const char *name, void *state)
3064 test directory listing speed
3066 static BOOL run_dirtest(int dummy)
3069 static struct cli_state cli;
3072 BOOL correct = True;
3074 printf("starting directory test\n");
3076 if (!torture_open_connection(&cli)) {
3080 cli_sockopt(&cli, sockops);
3083 for (i=0;i<numops;i++) {
3085 slprintf(fname, sizeof(fname), "\\%x", (int)random());
3086 fnum = cli_open(&cli, fname, O_RDWR|O_CREAT, DENY_NONE);
3088 fprintf(stderr,"Failed to open %s\n", fname);
3091 cli_close(&cli, fnum);
3096 printf("Matched %d\n", cli_list(&cli, "a*.*", 0, list_fn, NULL));
3097 printf("Matched %d\n", cli_list(&cli, "b*.*", 0, list_fn, NULL));
3098 printf("Matched %d\n", cli_list(&cli, "xyzabc", 0, list_fn, NULL));
3100 printf("dirtest core %g seconds\n", end_timer() - t1);
3103 for (i=0;i<numops;i++) {
3105 slprintf(fname, sizeof(fname), "\\%x", (int)random());
3106 cli_unlink(&cli, fname);
3109 if (!torture_close_connection(&cli)) {
3113 printf("finished dirtest\n");
3118 static BOOL run_error_map_extract(int dummy) {
3120 static struct cli_state c_dos;
3121 static struct cli_state c_nt;
3125 uint32 flgs2, errnum;
3132 /* NT-Error connection */
3134 if (!open_nbt_connection(&c_nt)) {
3138 c_nt.use_spnego = False;
3140 if (!cli_negprot(&c_nt)) {
3141 printf("%s rejected the NT-error negprot (%s)\n",host, cli_errstr(&c_nt));
3142 cli_shutdown(&c_nt);
3146 if (!cli_session_setup(&c_nt, "", "", 0, "", 0,
3148 printf("%s rejected the NT-error initial session setup (%s)\n",host, cli_errstr(&c_nt));
3152 /* DOS-Error connection */
3154 if (!open_nbt_connection(&c_dos)) {
3158 c_dos.use_spnego = False;
3159 c_dos.force_dos_errors = True;
3161 if (!cli_negprot(&c_dos)) {
3162 printf("%s rejected the DOS-error negprot (%s)\n",host, cli_errstr(&c_dos));
3163 cli_shutdown(&c_dos);
3167 if (!cli_session_setup(&c_dos, "", "", 0, "", 0,
3169 printf("%s rejected the DOS-error initial session setup (%s)\n",host, cli_errstr(&c_dos));
3173 for (error=(0xc0000000 | 0x1); error < (0xc0000000| 0xFFF); error++) {
3174 snprintf(user, sizeof(user), "%X", error);
3176 if (cli_session_setup(&c_nt, user,
3177 password, strlen(password),
3178 password, strlen(password),
3180 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
3183 flgs2 = SVAL(c_nt.inbuf,smb_flg2);
3185 /* Case #1: 32-bit NT errors */
3186 if (flgs2 & FLAGS2_32_BIT_ERROR_CODES) {
3187 nt_status = NT_STATUS(IVAL(c_nt.inbuf,smb_rcls));
3189 printf("/** Dos error on NT connection! (%s) */\n",
3191 nt_status = NT_STATUS(0xc0000000);
3194 if (cli_session_setup(&c_dos, user,
3195 password, strlen(password),
3196 password, strlen(password),
3198 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
3200 flgs2 = SVAL(c_dos.inbuf,smb_flg2), errnum;
3202 /* Case #1: 32-bit NT errors */
3203 if (flgs2 & FLAGS2_32_BIT_ERROR_CODES) {
3204 printf("/** NT error on DOS connection! (%s) */\n",
3206 errnum = errclass = 0;
3208 cli_dos_error(&c_dos, &errclass, &errnum);
3211 if (NT_STATUS_V(nt_status) != error) {
3212 printf("/*\t{ This NT error code was 'sqashed'\n\t from %s to %s \n\t during the session setup }\n*/\n",
3213 get_nt_error_c_code(NT_STATUS(error)),
3214 get_nt_error_c_code(nt_status));
3217 printf("\t{%s,\t%s,\t%s},\n",
3218 smb_dos_err_class(errclass),
3219 smb_dos_err_name(errclass, errnum),
3220 get_nt_error_c_code(NT_STATUS(error)));
3225 static double create_procs(BOOL (*fn)(int), BOOL *result)
3228 volatile pid_t *child_status;
3229 volatile BOOL *child_status_out;
3235 child_status = (volatile pid_t *)shm_setup(sizeof(pid_t)*nprocs);
3236 if (!child_status) {
3237 printf("Failed to setup shared memory\n");
3241 child_status_out = (volatile BOOL *)shm_setup(sizeof(BOOL)*nprocs);
3242 if (!child_status_out) {
3243 printf("Failed to setup result status shared memory\n");
3247 for (i = 0; i < nprocs; i++) {
3248 child_status[i] = 0;
3249 child_status_out[i] = True;
3254 for (i=0;i<nprocs;i++) {
3257 pid_t mypid = getpid();
3258 sys_srandom(((int)mypid) ^ ((int)time(NULL)));
3260 slprintf(myname,sizeof(myname),"CLIENT%d", i);
3263 memset(¤t_cli, 0, sizeof(current_cli));
3264 if (torture_open_connection(¤t_cli)) break;
3266 printf("pid %d failed to start\n", (int)getpid());
3272 child_status[i] = getpid();
3274 while (child_status[i]) msleep(2);
3276 child_status_out[i] = fn(i);
3283 for (i=0;i<nprocs;i++) {
3284 if (child_status[i]) synccount++;
3286 if (synccount == nprocs) break;
3288 } while (end_timer() < 30);
3290 if (synccount != nprocs) {
3291 printf("FAILED TO START %d CLIENTS (started %d)\n", nprocs, synccount);
3296 /* start the client load */
3299 for (i=0;i<nprocs;i++) {
3300 child_status[i] = 0;
3303 printf("%d clients started\n", nprocs);
3305 for (i=0;i<nprocs;i++) {
3306 while (waitpid(0, &status, 0) == -1 && errno == EINTR) /* noop */ ;
3311 for (i=0;i<nprocs;i++) {
3312 if (!child_status_out[i]) {
3319 #define FLAG_MULTIPROC 1
3326 {"FDPASS", run_fdpasstest, 0},
3327 {"LOCK1", run_locktest1, 0},
3328 {"LOCK2", run_locktest2, 0},
3329 {"LOCK3", run_locktest3, 0},
3330 {"LOCK4", run_locktest4, 0},
3331 {"LOCK5", run_locktest5, 0},
3332 {"LOCK6", run_locktest6, 0},
3333 {"UNLINK", run_unlinktest, 0},
3334 {"BROWSE", run_browsetest, 0},
3335 {"ATTR", run_attrtest, 0},
3336 {"TRANS2", run_trans2test, 0},
3337 {"MAXFID", run_maxfidtest, FLAG_MULTIPROC},
3338 {"TORTURE",run_torture, FLAG_MULTIPROC},
3339 {"RANDOMIPC", run_randomipc, 0},
3340 {"NEGNOWAIT", run_negprot_nowait, 0},
3341 {"NBENCH", run_nbench, 0},
3342 {"OPLOCK1", run_oplock1, 0},
3343 {"OPLOCK2", run_oplock2, 0},
3344 {"OPLOCK3", run_oplock3, 0},
3345 {"DIR", run_dirtest, 0},
3346 {"DENY1", torture_denytest1, 0},
3347 {"DENY2", torture_denytest2, 0},
3348 {"TCON", run_tcon_test, 0},
3349 {"RW1", run_readwritetest, 0},
3350 {"RW2", run_readwritemulti, FLAG_MULTIPROC},
3351 {"RW3", run_readwritelarge, 0},
3352 {"OPEN", run_opentest, 0},
3353 {"XCOPY", run_xcopy, 0},
3354 {"RENAME", run_rename, 0},
3355 {"DELETE", run_deletetest, 0},
3356 {"W2K", run_w2ktest, 0},
3357 {"TRANS2SCAN", torture_trans2_scan, 0},
3358 {"NTTRANSSCAN", torture_nttrans_scan, 0},
3359 {"UTABLE", torture_utable, 0},
3360 {"CASETABLE", torture_casetable, 0},
3361 {"ERRMAPEXTRACT", run_error_map_extract, 0},
3366 /****************************************************************************
3367 run a specified test or "ALL"
3368 ****************************************************************************/
3369 static BOOL run_test(char *name)
3375 if (strequal(name,"ALL")) {
3376 for (i=0;torture_ops[i].name;i++) {
3377 run_test(torture_ops[i].name);
3381 for (i=0;torture_ops[i].name;i++) {
3382 snprintf(randomfname, sizeof(randomfname), "\\XX%x",
3383 (unsigned)random());
3385 if (strequal(name, torture_ops[i].name)) {
3386 printf("Running %s\n", name);
3387 if (torture_ops[i].flags & FLAG_MULTIPROC) {
3388 t = create_procs(torture_ops[i].fn, &result);
3391 printf("TEST %s FAILED!\n", name);
3396 if (!torture_ops[i].fn(0)) {
3398 printf("TEST %s FAILED!\n", name);
3402 printf("%s took %g secs\n\n", name, t);
3409 static void usage(void)
3413 printf("Usage: smbtorture //server/share <options> TEST1 TEST2 ...\n");
3415 printf("\t-d debuglevel\n");
3416 printf("\t-U user%%pass\n");
3417 printf("\t-k use kerberos\n");
3418 printf("\t-N numprocs\n");
3419 printf("\t-n my_netbios_name\n");
3420 printf("\t-W workgroup\n");
3421 printf("\t-o num_operations\n");
3422 printf("\t-O socket_options\n");
3423 printf("\t-m maximum protocol\n");
3424 printf("\t-L use oplocks\n");
3425 printf("\t-c CLIENT.TXT specify client load file for NBENCH\n");
3426 printf("\t-A showall\n");
3429 printf("tests are:");
3430 for (i=0;torture_ops[i].name;i++) {
3431 printf(" %s", torture_ops[i].name);
3435 printf("default test is ALL\n");
3444 /****************************************************************************
3446 ****************************************************************************/
3447 int main(int argc,char *argv[])
3452 extern char *optarg;
3454 BOOL correct = True;
3458 #ifdef HAVE_SETBUFFER
3459 setbuffer(stdout, NULL, 0);
3462 lp_load(dyn_CONFIGFILE,True,False,False);
3469 for(p = argv[1]; *p; p++)
3473 if (strncmp(argv[1], "//", 2)) {
3477 fstrcpy(host, &argv[1][2]);
3478 p = strchr_m(&host[2],'/');
3483 fstrcpy(share, p+1);
3487 if (*username == 0 && getenv("LOGNAME")) {
3488 pstrcpy(username,getenv("LOGNAME"));
3495 fstrcpy(workgroup, lp_workgroup());
3497 while ((opt = getopt(argc, argv, "hW:U:n:N:O:o:m:Ld:Ac:k")) != EOF) {
3500 fstrcpy(workgroup,optarg);
3503 max_protocol = interpret_protocol(optarg, max_protocol);
3506 nprocs = atoi(optarg);
3509 numops = atoi(optarg);
3512 DEBUGLEVEL = atoi(optarg);
3521 torture_showall = True;
3524 fstrcpy(myname, optarg);
3527 client_txt = optarg;
3531 use_kerberos = True;
3534 d_printf("No kerberos support compiled in\n");
3539 pstrcpy(username,optarg);
3540 p = strchr_m(username,'%');
3543 pstrcpy(password, p+1);
3548 printf("Unknown option %c (%d)\n", (char)opt, opt);
3555 p = getpass("Password:");
3557 pstrcpy(password, p);
3562 printf("host=%s share=%s user=%s myname=%s\n",
3563 host, share, username, myname);
3566 correct = run_test("ALL");
3568 for (i=1;i<argc;i++) {
3569 if (!run_test(argv[i])) {