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_LOCK_NOT_GRANTED)) 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_LOCK_NOT_GRANTED)) 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_LOCK_NOT_GRANTED)) 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_LOCK_NOT_GRANTED)) 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_LOCK_NOT_GRANTED)) 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 EXPECTED(ret, True);
1358 printf("the server %s have the NT byte range lock bug\n", !ret?"does":"doesn't");
1361 cli_close(&cli1, fnum1);
1362 cli_close(&cli2, fnum2);
1363 cli_unlink(&cli1, fname);
1364 torture_close_connection(&cli1);
1365 torture_close_connection(&cli2);
1367 printf("finished locktest4\n");
1372 looks at lock upgrade/downgrade.
1374 static BOOL run_locktest5(int dummy)
1376 static struct cli_state cli1, cli2;
1377 char *fname = "\\lockt5.lck";
1378 int fnum1, fnum2, fnum3;
1381 BOOL correct = True;
1383 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
1387 cli_sockopt(&cli1, sockops);
1388 cli_sockopt(&cli2, sockops);
1390 printf("starting locktest5\n");
1392 cli_unlink(&cli1, fname);
1394 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1395 fnum2 = cli_open(&cli2, fname, O_RDWR, DENY_NONE);
1396 fnum3 = cli_open(&cli1, fname, O_RDWR, DENY_NONE);
1398 memset(buf, 0, sizeof(buf));
1400 if (cli_write(&cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
1401 printf("Failed to create file\n");
1406 /* Check for NT bug... */
1407 ret = cli_lock(&cli1, fnum1, 0, 8, 0, READ_LOCK) &&
1408 cli_lock(&cli1, fnum3, 0, 1, 0, READ_LOCK);
1409 cli_close(&cli1, fnum1);
1410 fnum1 = cli_open(&cli1, fname, O_RDWR, DENY_NONE);
1411 ret = cli_lock(&cli1, fnum1, 7, 1, 0, WRITE_LOCK);
1412 EXPECTED(ret, True);
1413 printf("this server %s the NT locking bug\n", ret ? "doesn't have" : "has");
1414 cli_close(&cli1, fnum1);
1415 fnum1 = cli_open(&cli1, fname, O_RDWR, DENY_NONE);
1416 cli_unlock(&cli1, fnum3, 0, 1);
1418 ret = cli_lock(&cli1, fnum1, 0, 4, 0, WRITE_LOCK) &&
1419 cli_lock(&cli1, fnum1, 1, 1, 0, READ_LOCK);
1420 EXPECTED(ret, True);
1421 printf("the same process %s overlay a write with a read lock\n", ret?"can":"cannot");
1423 ret = cli_lock(&cli2, fnum2, 0, 4, 0, READ_LOCK);
1424 EXPECTED(ret, False);
1426 printf("a different processs %s get a read lock on the first process lock stack\n", ret?"can":"cannot");
1428 /* Unlock the process 2 lock. */
1429 cli_unlock(&cli2, fnum2, 0, 4);
1431 ret = cli_lock(&cli1, fnum3, 0, 4, 0, READ_LOCK);
1432 EXPECTED(ret, False);
1434 printf("the same processs on a different fnum %s get a read lock\n", ret?"can":"cannot");
1436 /* Unlock the process 1 fnum3 lock. */
1437 cli_unlock(&cli1, fnum3, 0, 4);
1439 /* Stack 2 more locks here. */
1440 ret = cli_lock(&cli1, fnum1, 0, 4, 0, READ_LOCK) &&
1441 cli_lock(&cli1, fnum1, 0, 4, 0, READ_LOCK);
1443 EXPECTED(ret, True);
1444 printf("the same process %s stack read locks\n", ret?"can":"cannot");
1446 /* Unlock the first process lock, then check this was the WRITE lock that was
1449 ret = cli_unlock(&cli1, fnum1, 0, 4) &&
1450 cli_lock(&cli2, fnum2, 0, 4, 0, READ_LOCK);
1452 EXPECTED(ret, True);
1453 printf("the first unlock removes the %s lock\n", ret?"WRITE":"READ");
1455 /* Unlock the process 2 lock. */
1456 cli_unlock(&cli2, fnum2, 0, 4);
1458 /* We should have 3 stacked locks here. Ensure we need to do 3 unlocks. */
1460 ret = cli_unlock(&cli1, fnum1, 1, 1) &&
1461 cli_unlock(&cli1, fnum1, 0, 4) &&
1462 cli_unlock(&cli1, fnum1, 0, 4);
1464 EXPECTED(ret, True);
1465 printf("the same process %s unlock the stack of 4 locks\n", ret?"can":"cannot");
1467 /* Ensure the next unlock fails. */
1468 ret = cli_unlock(&cli1, fnum1, 0, 4);
1469 EXPECTED(ret, False);
1470 printf("the same process %s count the lock stack\n", !ret?"can":"cannot");
1472 /* Ensure connection 2 can get a write lock. */
1473 ret = cli_lock(&cli2, fnum2, 0, 4, 0, WRITE_LOCK);
1474 EXPECTED(ret, True);
1476 printf("a different processs %s get a write lock on the unlocked stack\n", ret?"can":"cannot");
1480 cli_close(&cli1, fnum1);
1481 cli_close(&cli2, fnum2);
1482 cli_unlink(&cli1, fname);
1483 if (!torture_close_connection(&cli1)) {
1486 if (!torture_close_connection(&cli2)) {
1490 printf("finished locktest5\n");
1496 test whether fnums and tids open on one VC are available on another (a major
1499 static BOOL run_fdpasstest(int dummy)
1501 static struct cli_state cli1, cli2, cli3;
1502 char *fname = "\\fdpass.tst";
1506 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
1509 cli_sockopt(&cli1, sockops);
1510 cli_sockopt(&cli2, sockops);
1512 printf("starting fdpasstest\n");
1514 cli_unlink(&cli1, fname);
1516 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1518 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
1522 if (cli_write(&cli1, fnum1, 0, "hello world\n", 0, 13) != 13) {
1523 printf("write failed (%s)\n", cli_errstr(&cli1));
1528 cli3.vuid = cli1.vuid;
1529 cli3.cnum = cli1.cnum;
1530 cli3.pid = cli1.pid;
1532 if (cli_read(&cli3, fnum1, buf, 0, 13) == 13) {
1533 printf("read succeeded! nasty security hole [%s]\n",
1538 cli_close(&cli1, fnum1);
1539 cli_unlink(&cli1, fname);
1541 torture_close_connection(&cli1);
1542 torture_close_connection(&cli2);
1544 printf("finished fdpasstest\n");
1550 This test checks that
1552 1) the server does not allow an unlink on a file that is open
1554 static BOOL run_unlinktest(int dummy)
1556 static struct cli_state cli;
1557 char *fname = "\\unlink.tst";
1559 BOOL correct = True;
1561 if (!torture_open_connection(&cli)) {
1565 cli_sockopt(&cli, sockops);
1567 printf("starting unlink test\n");
1569 cli_unlink(&cli, fname);
1571 cli_setpid(&cli, 1);
1573 fnum = cli_open(&cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1575 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli));
1579 if (cli_unlink(&cli, fname)) {
1580 printf("error: server allowed unlink on an open file\n");
1583 correct = check_error(__LINE__, &cli, ERRDOS, ERRbadshare,
1584 NT_STATUS_SHARING_VIOLATION);
1587 cli_close(&cli, fnum);
1588 cli_unlink(&cli, fname);
1590 if (!torture_close_connection(&cli)) {
1594 printf("unlink test finished\n");
1601 test how many open files this server supports on the one socket
1603 static BOOL run_maxfidtest(int dummy)
1605 static struct cli_state cli;
1606 char *template = "\\maxfid.%d.%d";
1608 int fnums[0x11000], i;
1610 BOOL correct = True;
1615 printf("failed to connect\n");
1619 cli_sockopt(&cli, sockops);
1621 for (i=0; i<0x11000; i++) {
1622 slprintf(fname,sizeof(fname)-1,template, i,(int)getpid());
1623 if ((fnums[i] = cli_open(&cli, fname,
1624 O_RDWR|O_CREAT|O_TRUNC, DENY_NONE)) ==
1626 printf("open of %s failed (%s)\n",
1627 fname, cli_errstr(&cli));
1628 printf("maximum fnum is %d\n", i);
1636 printf("cleaning up\n");
1638 slprintf(fname,sizeof(fname)-1,template, i,(int)getpid());
1639 cli_close(&cli, fnums[i]);
1640 if (!cli_unlink(&cli, fname)) {
1641 printf("unlink of %s failed (%s)\n",
1642 fname, cli_errstr(&cli));
1649 printf("maxfid test finished\n");
1650 if (!torture_close_connection(&cli)) {
1656 /* generate a random buffer */
1657 static void rand_buf(char *buf, int len)
1660 *buf = (char)sys_random();
1665 /* send smb negprot commands, not reading the response */
1666 static BOOL run_negprot_nowait(int dummy)
1669 static struct cli_state cli;
1670 BOOL correct = True;
1672 printf("starting negprot nowait test\n");
1674 if (!open_nbt_connection(&cli)) {
1678 for (i=0;i<50000;i++) {
1679 cli_negprot_send(&cli);
1682 if (!torture_close_connection(&cli)) {
1686 printf("finished negprot nowait test\n");
1692 /* send random IPC commands */
1693 static BOOL run_randomipc(int dummy)
1695 char *rparam = NULL;
1699 int api, param_len, i;
1700 static struct cli_state cli;
1701 BOOL correct = True;
1704 printf("starting random ipc test\n");
1706 if (!torture_open_connection(&cli)) {
1710 for (i=0;i<count;i++) {
1711 api = sys_random() % 500;
1712 param_len = (sys_random() % 64);
1714 rand_buf(param, param_len);
1719 param, param_len, 8,
1720 NULL, 0, BUFFER_SIZE,
1724 printf("%d/%d\r", i,count);
1727 printf("%d/%d\n", i, count);
1729 if (!torture_close_connection(&cli)) {
1733 printf("finished random ipc test\n");
1740 static void browse_callback(const char *sname, uint32 stype,
1741 const char *comment, void *state)
1743 printf("\t%20.20s %08x %s\n", sname, stype, comment);
1749 This test checks the browse list code
1752 static BOOL run_browsetest(int dummy)
1754 static struct cli_state cli;
1755 BOOL correct = True;
1757 printf("starting browse test\n");
1759 if (!torture_open_connection(&cli)) {
1763 printf("domain list:\n");
1764 cli_NetServerEnum(&cli, cli.server_domain,
1765 SV_TYPE_DOMAIN_ENUM,
1766 browse_callback, NULL);
1768 printf("machine list:\n");
1769 cli_NetServerEnum(&cli, cli.server_domain,
1771 browse_callback, NULL);
1773 if (!torture_close_connection(&cli)) {
1777 printf("browse test finished\n");
1785 This checks how the getatr calls works
1787 static BOOL run_attrtest(int dummy)
1789 static struct cli_state cli;
1792 char *fname = "\\attrib.tst";
1793 BOOL correct = True;
1795 printf("starting attrib test\n");
1797 if (!torture_open_connection(&cli)) {
1801 cli_unlink(&cli, fname);
1802 fnum = cli_open(&cli, fname,
1803 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1804 cli_close(&cli, fnum);
1805 if (!cli_getatr(&cli, fname, NULL, NULL, &t)) {
1806 printf("getatr failed (%s)\n", cli_errstr(&cli));
1810 if (abs(t - time(NULL)) > 60*60*24*10) {
1811 printf("ERROR: SMBgetatr bug. time is %s",
1817 t2 = t-60*60*24; /* 1 day ago */
1819 if (!cli_setatr(&cli, fname, 0, t2)) {
1820 printf("setatr failed (%s)\n", cli_errstr(&cli));
1824 if (!cli_getatr(&cli, fname, NULL, NULL, &t)) {
1825 printf("getatr failed (%s)\n", cli_errstr(&cli));
1830 printf("ERROR: getatr/setatr bug. times are\n%s",
1832 printf("%s", ctime(&t2));
1836 cli_unlink(&cli, fname);
1838 if (!torture_close_connection(&cli)) {
1842 printf("attrib test finished\n");
1849 This checks a couple of trans2 calls
1851 static BOOL run_trans2test(int dummy)
1853 static struct cli_state cli;
1856 time_t c_time, a_time, m_time, w_time, m_time2;
1857 char *fname = "\\trans2.tst";
1858 char *dname = "\\trans2";
1859 char *fname2 = "\\trans2\\trans2.tst";
1861 BOOL correct = True;
1863 printf("starting trans2 test\n");
1865 if (!torture_open_connection(&cli)) {
1869 cli_unlink(&cli, fname);
1870 fnum = cli_open(&cli, fname,
1871 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1872 if (!cli_qfileinfo(&cli, fnum, NULL, &size, &c_time, &a_time, &m_time,
1874 printf("ERROR: qfileinfo failed (%s)\n", cli_errstr(&cli));
1878 if (!cli_qfilename(&cli, fnum, pname)) {
1879 printf("ERROR: qfilename failed (%s)\n", cli_errstr(&cli));
1883 if (strcmp(pname, fname)) {
1884 printf("qfilename gave different name? [%s] [%s]\n",
1889 cli_close(&cli, fnum);
1893 cli_unlink(&cli, fname);
1894 fnum = cli_open(&cli, fname,
1895 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1897 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli));
1900 cli_close(&cli, fnum);
1902 if (!cli_qpathinfo(&cli, fname, &c_time, &a_time, &m_time, &size, NULL)) {
1903 printf("ERROR: qpathinfo failed (%s)\n", cli_errstr(&cli));
1906 if (c_time != m_time) {
1907 printf("create time=%s", ctime(&c_time));
1908 printf("modify time=%s", ctime(&m_time));
1909 printf("This system appears to have sticky create times\n");
1912 if (a_time % (60*60) == 0) {
1913 printf("access time=%s", ctime(&a_time));
1914 printf("This system appears to set a midnight access time\n");
1918 if (abs(m_time - time(NULL)) > 60*60*24*7) {
1919 printf("ERROR: totally incorrect times - maybe word reversed? mtime=%s", ctime(&m_time));
1925 cli_unlink(&cli, fname);
1926 fnum = cli_open(&cli, fname,
1927 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1928 cli_close(&cli, fnum);
1929 if (!cli_qpathinfo2(&cli, fname, &c_time, &a_time, &m_time,
1930 &w_time, &size, NULL, NULL)) {
1931 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli));
1934 if (w_time < 60*60*24*2) {
1935 printf("write time=%s", ctime(&w_time));
1936 printf("This system appears to set a initial 0 write time\n");
1941 cli_unlink(&cli, fname);
1944 /* check if the server updates the directory modification time
1945 when creating a new file */
1946 if (!cli_mkdir(&cli, dname)) {
1947 printf("ERROR: mkdir failed (%s)\n", cli_errstr(&cli));
1951 if (!cli_qpathinfo2(&cli, "\\trans2\\", &c_time, &a_time, &m_time,
1952 &w_time, &size, NULL, NULL)) {
1953 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli));
1957 fnum = cli_open(&cli, fname2,
1958 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1959 cli_write(&cli, fnum, 0, (char *)&fnum, 0, sizeof(fnum));
1960 cli_close(&cli, fnum);
1961 if (!cli_qpathinfo2(&cli, "\\trans2\\", &c_time, &a_time, &m_time2,
1962 &w_time, &size, NULL, NULL)) {
1963 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli));
1966 if (m_time2 == m_time) {
1967 printf("This system does not update directory modification times\n");
1971 cli_unlink(&cli, fname2);
1972 cli_rmdir(&cli, dname);
1974 if (!torture_close_connection(&cli)) {
1978 printf("trans2 test finished\n");
1984 This checks new W2K calls.
1987 static BOOL new_trans(struct cli_state *pcli, int fnum, int level)
1990 BOOL correct = True;
1992 memset(buf, 0xff, sizeof(buf));
1994 if (!cli_qfileinfo_test(pcli, fnum, level, buf)) {
1995 printf("ERROR: qfileinfo (%d) failed (%s)\n", level, cli_errstr(pcli));
1998 printf("qfileinfo: level %d\n", level);
1999 dump_data(0, buf, 256);
2005 static BOOL run_w2ktest(int dummy)
2007 static struct cli_state cli;
2009 char *fname = "\\w2ktest\\w2k.tst";
2011 BOOL correct = True;
2013 printf("starting w2k test\n");
2015 if (!torture_open_connection(&cli)) {
2019 fnum = cli_open(&cli, fname,
2020 O_RDWR | O_CREAT , DENY_NONE);
2022 for (level = 1004; level < 1040; level++) {
2023 new_trans(&cli, fnum, level);
2026 cli_close(&cli, fnum);
2028 if (!torture_close_connection(&cli)) {
2032 printf("w2k test finished\n");
2039 this is a harness for some oplock tests
2041 static BOOL run_oplock1(int dummy)
2043 static struct cli_state cli1;
2044 char *fname = "\\lockt1.lck";
2046 BOOL correct = True;
2048 printf("starting oplock test 1\n");
2050 if (!torture_open_connection(&cli1)) {
2054 cli_unlink(&cli1, fname);
2056 cli_sockopt(&cli1, sockops);
2058 cli1.use_oplocks = True;
2060 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2062 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2066 cli1.use_oplocks = False;
2068 cli_unlink(&cli1, fname);
2069 cli_unlink(&cli1, fname);
2071 if (!cli_close(&cli1, fnum1)) {
2072 printf("close2 failed (%s)\n", cli_errstr(&cli1));
2076 if (!cli_unlink(&cli1, fname)) {
2077 printf("unlink failed (%s)\n", cli_errstr(&cli1));
2081 if (!torture_close_connection(&cli1)) {
2085 printf("finished oplock test 1\n");
2090 static BOOL run_oplock2(int dummy)
2092 static struct cli_state cli1, cli2;
2093 char *fname = "\\lockt2.lck";
2095 int saved_use_oplocks = use_oplocks;
2097 BOOL correct = True;
2098 volatile BOOL *shared_correct;
2100 shared_correct = (volatile BOOL *)shm_setup(sizeof(BOOL));
2101 *shared_correct = True;
2103 use_level_II_oplocks = True;
2106 printf("starting oplock test 2\n");
2108 if (!torture_open_connection(&cli1)) {
2109 use_level_II_oplocks = False;
2110 use_oplocks = saved_use_oplocks;
2114 cli1.use_oplocks = True;
2115 cli1.use_level_II_oplocks = True;
2117 if (!torture_open_connection(&cli2)) {
2118 use_level_II_oplocks = False;
2119 use_oplocks = saved_use_oplocks;
2123 cli2.use_oplocks = True;
2124 cli2.use_level_II_oplocks = True;
2126 cli_unlink(&cli1, fname);
2128 cli_sockopt(&cli1, sockops);
2129 cli_sockopt(&cli2, sockops);
2131 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2133 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2137 /* Don't need the globals any more. */
2138 use_level_II_oplocks = False;
2139 use_oplocks = saved_use_oplocks;
2143 fnum2 = cli_open(&cli2, fname, O_RDWR, DENY_NONE);
2145 printf("second open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2146 *shared_correct = False;
2152 if (!cli_close(&cli2, fnum2)) {
2153 printf("close2 failed (%s)\n", cli_errstr(&cli1));
2154 *shared_correct = False;
2162 /* Ensure cli1 processes the break. */
2164 if (cli_read(&cli1, fnum1, buf, 0, 4) != 4) {
2165 printf("read on fnum1 failed (%s)\n", cli_errstr(&cli1));
2169 /* Should now be at level II. */
2170 /* Test if sending a write locks causes a break to none. */
2172 if (!cli_lock(&cli1, fnum1, 0, 4, 0, READ_LOCK)) {
2173 printf("lock failed (%s)\n", cli_errstr(&cli1));
2177 cli_unlock(&cli1, fnum1, 0, 4);
2181 if (!cli_lock(&cli1, fnum1, 0, 4, 0, WRITE_LOCK)) {
2182 printf("lock failed (%s)\n", cli_errstr(&cli1));
2186 cli_unlock(&cli1, fnum1, 0, 4);
2190 cli_read(&cli1, fnum1, buf, 0, 4);
2193 if (cli_write(&cli1, fnum1, 0, buf, 0, 4) != 4) {
2194 printf("write on fnum1 failed (%s)\n", cli_errstr(&cli1));
2199 if (!cli_close(&cli1, fnum1)) {
2200 printf("close1 failed (%s)\n", cli_errstr(&cli1));
2206 if (!cli_unlink(&cli1, fname)) {
2207 printf("unlink failed (%s)\n", cli_errstr(&cli1));
2211 if (!torture_close_connection(&cli1)) {
2215 if (!*shared_correct) {
2219 printf("finished oplock test 2\n");
2224 /* handler for oplock 3 tests */
2225 static BOOL oplock3_handler(struct cli_state *cli, int fnum, unsigned char level)
2227 printf("got oplock break fnum=%d level=%d\n",
2229 return cli_oplock_ack(cli, fnum, level);
2232 static BOOL run_oplock3(int dummy)
2234 static struct cli_state cli;
2235 char *fname = "\\oplockt3.dat";
2237 char buf[4] = "abcd";
2238 BOOL correct = True;
2239 volatile BOOL *shared_correct;
2241 shared_correct = (volatile BOOL *)shm_setup(sizeof(BOOL));
2242 *shared_correct = True;
2244 printf("starting oplock test 3\n");
2249 use_level_II_oplocks = True;
2250 if (!torture_open_connection(&cli)) {
2251 *shared_correct = False;
2255 /* try to trigger a oplock break in parent */
2256 fnum = cli_open(&cli, fname, O_RDWR, DENY_NONE);
2257 cli_write(&cli, fnum, 0, buf, 0, 4);
2263 use_level_II_oplocks = True;
2264 if (!torture_open_connection(&cli)) {
2267 cli_oplock_handler(&cli, oplock3_handler);
2268 fnum = cli_open(&cli, fname, O_RDWR|O_CREAT, DENY_NONE);
2269 cli_write(&cli, fnum, 0, buf, 0, 4);
2270 cli_close(&cli, fnum);
2271 fnum = cli_open(&cli, fname, O_RDWR, DENY_NONE);
2272 cli.timeout = 20000;
2273 cli_receive_smb(&cli);
2274 printf("finished oplock test 3\n");
2276 return (correct && *shared_correct);
2278 /* What are we looking for here? What's sucess and what's FAILURE? */
2284 Test delete on close semantics.
2286 static BOOL run_deletetest(int dummy)
2288 static struct cli_state cli1;
2289 static struct cli_state cli2;
2290 char *fname = "\\delete.file";
2292 BOOL correct = True;
2294 printf("starting delete test\n");
2296 if (!torture_open_connection(&cli1)) {
2300 cli_sockopt(&cli1, sockops);
2302 /* Test 1 - this should *NOT* delete the file on close. */
2304 cli_setatr(&cli1, fname, 0, 0);
2305 cli_unlink(&cli1, fname);
2307 fnum1 = cli_nt_create_full(&cli1, fname, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL,
2308 FILE_SHARE_DELETE, FILE_OVERWRITE_IF,
2309 DELETE_ON_CLOSE_FLAG);
2312 printf("[1] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2316 if (!cli_close(&cli1, fnum1)) {
2317 printf("[1] close failed (%s)\n", cli_errstr(&cli1));
2321 fnum1 = cli_open(&cli1, fname, O_RDWR, DENY_NONE);
2323 printf("[1] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2327 if (!cli_close(&cli1, fnum1)) {
2328 printf("[1] close failed (%s)\n", cli_errstr(&cli1));
2332 printf("first delete on close test succeeded.\n");
2334 /* Test 2 - this should delete the file on close. */
2336 cli_setatr(&cli1, fname, 0, 0);
2337 cli_unlink(&cli1, fname);
2339 fnum1 = cli_nt_create_full(&cli1, fname, GENERIC_ALL_ACCESS,
2340 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
2341 FILE_OVERWRITE_IF, 0);
2344 printf("[2] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2348 if (!cli_nt_delete_on_close(&cli1, fnum1, True)) {
2349 printf("[2] setting delete_on_close failed (%s)\n", cli_errstr(&cli1));
2353 if (!cli_close(&cli1, fnum1)) {
2354 printf("[2] close failed (%s)\n", cli_errstr(&cli1));
2358 fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_NONE);
2360 printf("[2] open of %s succeeded should have been deleted on close !\n", fname);
2361 if (!cli_close(&cli1, fnum1)) {
2362 printf("[2] close failed (%s)\n", cli_errstr(&cli1));
2365 cli_unlink(&cli1, fname);
2367 printf("second delete on close test succeeded.\n");
2370 cli_setatr(&cli1, fname, 0, 0);
2371 cli_unlink(&cli1, fname);
2373 fnum1 = cli_nt_create_full(&cli1, fname, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL,
2374 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0);
2377 printf("[3] open - 1 of %s failed (%s)\n", fname, cli_errstr(&cli1));
2381 /* This should fail with a sharing violation - open for delete is only compatible
2382 with SHARE_DELETE. */
2384 fnum2 = cli_nt_create_full(&cli1, fname, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
2385 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0);
2388 printf("[3] open - 2 of %s succeeded - should have failed.\n", fname);
2392 /* This should succeed. */
2394 fnum2 = cli_nt_create_full(&cli1, fname, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
2395 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0);
2398 printf("[3] open - 2 of %s failed (%s)\n", fname, cli_errstr(&cli1));
2402 if (!cli_nt_delete_on_close(&cli1, fnum1, True)) {
2403 printf("[3] setting delete_on_close failed (%s)\n", cli_errstr(&cli1));
2407 if (!cli_close(&cli1, fnum1)) {
2408 printf("[3] close 1 failed (%s)\n", cli_errstr(&cli1));
2412 if (!cli_close(&cli1, fnum2)) {
2413 printf("[3] close 2 failed (%s)\n", cli_errstr(&cli1));
2417 /* This should fail - file should no longer be there. */
2419 fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_NONE);
2421 printf("[3] open of %s succeeded should have been deleted on close !\n", fname);
2422 if (!cli_close(&cli1, fnum1)) {
2423 printf("[3] close failed (%s)\n", cli_errstr(&cli1));
2425 cli_unlink(&cli1, fname);
2428 printf("third delete on close test succeeded.\n");
2431 cli_setatr(&cli1, fname, 0, 0);
2432 cli_unlink(&cli1, fname);
2434 fnum1 = cli_nt_create_full(&cli1, fname, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
2435 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0);
2438 printf("[4] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2442 /* This should succeed. */
2443 fnum2 = cli_nt_create_full(&cli1, fname, GENERIC_READ_ACCESS,
2444 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0);
2446 printf("[4] open - 2 of %s failed (%s)\n", fname, cli_errstr(&cli1));
2450 if (!cli_close(&cli1, fnum2)) {
2451 printf("[4] close - 1 failed (%s)\n", cli_errstr(&cli1));
2455 if (!cli_nt_delete_on_close(&cli1, fnum1, True)) {
2456 printf("[4] setting delete_on_close failed (%s)\n", cli_errstr(&cli1));
2460 /* This should fail - no more opens once delete on close set. */
2461 fnum2 = cli_nt_create_full(&cli1, fname, GENERIC_READ_ACCESS,
2462 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0);
2464 printf("[4] open - 3 of %s succeeded ! Should have failed.\n", fname );
2467 printf("fourth delete on close test succeeded.\n");
2469 if (!cli_close(&cli1, fnum1)) {
2470 printf("[4] close - 2 failed (%s)\n", cli_errstr(&cli1));
2475 cli_setatr(&cli1, fname, 0, 0);
2476 cli_unlink(&cli1, fname);
2478 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT, DENY_NONE);
2480 printf("[5] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2484 /* This should fail - only allowed on NT opens with DELETE access. */
2486 if (cli_nt_delete_on_close(&cli1, fnum1, True)) {
2487 printf("[5] setting delete_on_close on OpenX file succeeded - should fail !\n");
2491 if (!cli_close(&cli1, fnum1)) {
2492 printf("[5] close - 2 failed (%s)\n", cli_errstr(&cli1));
2496 printf("fifth delete on close test succeeded.\n");
2499 cli_setatr(&cli1, fname, 0, 0);
2500 cli_unlink(&cli1, fname);
2502 fnum1 = cli_nt_create_full(&cli1, fname, FILE_READ_DATA|FILE_WRITE_DATA,
2503 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
2504 FILE_OVERWRITE_IF, 0);
2507 printf("[6] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2511 /* This should fail - only allowed on NT opens with DELETE access. */
2513 if (cli_nt_delete_on_close(&cli1, fnum1, True)) {
2514 printf("[6] setting delete_on_close on file with no delete access succeeded - should fail !\n");
2518 if (!cli_close(&cli1, fnum1)) {
2519 printf("[6] close - 2 failed (%s)\n", cli_errstr(&cli1));
2523 printf("sixth delete on close test succeeded.\n");
2526 cli_setatr(&cli1, fname, 0, 0);
2527 cli_unlink(&cli1, fname);
2529 fnum1 = cli_nt_create_full(&cli1, fname, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
2530 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF, 0);
2533 printf("[7] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2537 if (!cli_nt_delete_on_close(&cli1, fnum1, True)) {
2538 printf("[7] setting delete_on_close on file failed !\n");
2542 if (!cli_nt_delete_on_close(&cli1, fnum1, False)) {
2543 printf("[7] unsetting delete_on_close on file failed !\n");
2547 if (!cli_close(&cli1, fnum1)) {
2548 printf("[7] close - 2 failed (%s)\n", cli_errstr(&cli1));
2552 /* This next open should succeed - we reset the flag. */
2554 fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_NONE);
2556 printf("[5] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2560 if (!cli_close(&cli1, fnum1)) {
2561 printf("[7] close - 2 failed (%s)\n", cli_errstr(&cli1));
2565 printf("seventh delete on close test succeeded.\n");
2568 cli_setatr(&cli1, fname, 0, 0);
2569 cli_unlink(&cli1, fname);
2571 if (!torture_open_connection(&cli2)) {
2572 printf("[8] failed to open second connection.\n");
2576 cli_sockopt(&cli1, sockops);
2578 fnum1 = cli_nt_create_full(&cli1, fname, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
2579 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0);
2582 printf("[8] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2586 fnum2 = cli_nt_create_full(&cli2, fname, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
2587 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0);
2590 printf("[8] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2594 if (!cli_nt_delete_on_close(&cli1, fnum1, True)) {
2595 printf("[8] setting delete_on_close on file failed !\n");
2599 if (!cli_close(&cli1, fnum1)) {
2600 printf("[8] close - 1 failed (%s)\n", cli_errstr(&cli1));
2604 if (!cli_close(&cli2, fnum2)) {
2605 printf("[8] close - 2 failed (%s)\n", cli_errstr(&cli2));
2609 /* This should fail.. */
2610 fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_NONE);
2612 printf("[8] open of %s succeeded should have been deleted on close !\n", fname);
2613 if (!cli_close(&cli1, fnum1)) {
2614 printf("[8] close failed (%s)\n", cli_errstr(&cli1));
2616 cli_unlink(&cli1, fname);
2619 printf("eighth delete on close test succeeded.\n");
2621 printf("finished delete test\n");
2623 cli_setatr(&cli1, fname, 0, 0);
2624 cli_unlink(&cli1, fname);
2626 if (!torture_close_connection(&cli1)) {
2629 if (!torture_close_connection(&cli2)) {
2637 Test ntcreate calls made by xcopy
2639 static BOOL run_xcopy(int dummy)
2641 static struct cli_state cli1;
2642 char *fname = "\\test.txt";
2643 BOOL correct = True;
2646 printf("starting xcopy test\n");
2648 if (!torture_open_connection(&cli1)) {
2652 fnum1 = cli_nt_create_full(&cli1, fname,
2658 printf("First open failed - %s\n", cli_errstr(&cli1));
2662 fnum2 = cli_nt_create_full(&cli1, fname,
2667 printf("second open failed - %s\n", cli_errstr(&cli1));
2671 if (!torture_close_connection(&cli1)) {
2679 Test rename on files open with share delete and no share delete.
2681 static BOOL run_rename(int dummy)
2683 static struct cli_state cli1;
2684 char *fname = "\\test.txt";
2685 char *fname1 = "\\test1.txt";
2686 BOOL correct = True;
2689 printf("starting rename test\n");
2691 if (!torture_open_connection(&cli1)) {
2695 cli_unlink(&cli1, fname);
2696 cli_unlink(&cli1, fname1);
2697 fnum1 = cli_nt_create_full(&cli1, fname, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
2698 FILE_SHARE_READ, FILE_OVERWRITE_IF, 0);
2701 printf("First open failed - %s\n", cli_errstr(&cli1));
2705 if (!cli_rename(&cli1, fname, fname1)) {
2706 printf("First rename failed (this is correct) - %s\n", cli_errstr(&cli1));
2708 printf("First rename succeeded - this should have failed !\n");
2712 if (!cli_close(&cli1, fnum1)) {
2713 printf("close - 1 failed (%s)\n", cli_errstr(&cli1));
2717 cli_unlink(&cli1, fname);
2718 cli_unlink(&cli1, fname1);
2719 fnum1 = cli_nt_create_full(&cli1, fname,GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
2720 FILE_SHARE_DELETE|FILE_SHARE_READ, FILE_OVERWRITE_IF, 0);
2723 printf("Second open failed - %s\n", cli_errstr(&cli1));
2727 if (!cli_rename(&cli1, fname, fname1)) {
2728 printf("Second rename failed - this should have succeeded - %s\n", cli_errstr(&cli1));
2731 printf("Second rename succeeded\n");
2734 if (!cli_close(&cli1, fnum1)) {
2735 printf("close - 2 failed (%s)\n", cli_errstr(&cli1));
2739 cli_unlink(&cli1, fname);
2740 cli_unlink(&cli1, fname1);
2742 if (!torture_close_connection(&cli1)) {
2751 Test open mode returns on read-only files.
2753 static BOOL run_opentest(int dummy)
2755 static struct cli_state cli1;
2756 char *fname = "\\readonly.file";
2760 BOOL correct = True;
2763 printf("starting open test\n");
2765 if (!torture_open_connection(&cli1)) {
2769 cli_setatr(&cli1, fname, 0, 0);
2770 cli_unlink(&cli1, fname);
2772 cli_sockopt(&cli1, sockops);
2774 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2776 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2780 if (!cli_close(&cli1, fnum1)) {
2781 printf("close2 failed (%s)\n", cli_errstr(&cli1));
2785 if (!cli_setatr(&cli1, fname, aRONLY, 0)) {
2786 printf("cli_setatr failed (%s)\n", cli_errstr(&cli1));
2790 fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_WRITE);
2792 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2796 /* This will fail - but the error should be ERRnoaccess, not ERRbadshare. */
2797 fnum2 = cli_open(&cli1, fname, O_RDWR, DENY_ALL);
2799 if (check_error(__LINE__, &cli1, ERRDOS, ERRnoaccess,
2800 NT_STATUS_ACCESS_DENIED)) {
2801 printf("correct error code ERRDOS/ERRnoaccess returned\n");
2804 printf("finished open test 1\n");
2806 cli_close(&cli1, fnum1);
2808 /* Now try not readonly and ensure ERRbadshare is returned. */
2810 cli_setatr(&cli1, fname, 0, 0);
2812 fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_WRITE);
2814 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2818 /* This will fail - but the error should be ERRshare. */
2819 fnum2 = cli_open(&cli1, fname, O_RDWR, DENY_ALL);
2821 if (check_error(__LINE__, &cli1, ERRDOS, ERRbadshare,
2822 NT_STATUS_SHARING_VIOLATION)) {
2823 printf("correct error code ERRDOS/ERRbadshare returned\n");
2826 if (!cli_close(&cli1, fnum1)) {
2827 printf("close2 failed (%s)\n", cli_errstr(&cli1));
2831 cli_unlink(&cli1, fname);
2833 printf("finished open test 2\n");
2835 /* Test truncate open disposition on file opened for read. */
2837 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2839 printf("(3) open (1) of %s failed (%s)\n", fname, cli_errstr(&cli1));
2843 /* write 20 bytes. */
2845 memset(buf, '\0', 20);
2847 if (cli_write(&cli1, fnum1, 0, buf, 0, 20) != 20) {
2848 printf("write failed (%s)\n", cli_errstr(&cli1));
2852 if (!cli_close(&cli1, fnum1)) {
2853 printf("(3) close1 failed (%s)\n", cli_errstr(&cli1));
2857 /* Ensure size == 20. */
2858 if (!cli_getatr(&cli1, fname, NULL, &fsize, NULL)) {
2859 printf("(3) getatr failed (%s)\n", cli_errstr(&cli1));
2864 printf("(3) file size != 20\n");
2868 /* Now test if we can truncate a file opened for readonly. */
2870 fnum1 = cli_open(&cli1, fname, O_RDONLY|O_TRUNC, DENY_NONE);
2872 printf("(3) open (2) of %s failed (%s)\n", fname, cli_errstr(&cli1));
2876 if (!cli_close(&cli1, fnum1)) {
2877 printf("close2 failed (%s)\n", cli_errstr(&cli1));
2881 /* Ensure size == 0. */
2882 if (!cli_getatr(&cli1, fname, NULL, &fsize, NULL)) {
2883 printf("(3) getatr failed (%s)\n", cli_errstr(&cli1));
2888 printf("(3) file size != 0\n");
2891 printf("finished open test 3\n");
2893 cli_unlink(&cli1, fname);
2896 printf("testing ctemp\n");
2897 fnum1 = cli_ctemp(&cli1, "\\", &tmp_path);
2899 printf("ctemp failed (%s)\n", cli_errstr(&cli1));
2902 printf("ctemp gave path %s\n", tmp_path);
2903 if (!cli_close(&cli1, fnum1)) {
2904 printf("close of temp failed (%s)\n", cli_errstr(&cli1));
2906 if (!cli_unlink(&cli1, tmp_path)) {
2907 printf("unlink of temp failed (%s)\n", cli_errstr(&cli1));
2910 if (!torture_close_connection(&cli1)) {
2917 static void list_fn(file_info *finfo, const char *name, void *state)
2923 test directory listing speed
2925 static BOOL run_dirtest(int dummy)
2928 static struct cli_state cli;
2931 BOOL correct = True;
2933 printf("starting directory test\n");
2935 if (!torture_open_connection(&cli)) {
2939 cli_sockopt(&cli, sockops);
2942 for (i=0;i<numops;i++) {
2944 slprintf(fname, sizeof(fname), "\\%x", (int)random());
2945 fnum = cli_open(&cli, fname, O_RDWR|O_CREAT, DENY_NONE);
2947 fprintf(stderr,"Failed to open %s\n", fname);
2950 cli_close(&cli, fnum);
2955 printf("Matched %d\n", cli_list(&cli, "a*.*", 0, list_fn, NULL));
2956 printf("Matched %d\n", cli_list(&cli, "b*.*", 0, list_fn, NULL));
2957 printf("Matched %d\n", cli_list(&cli, "xyzabc", 0, list_fn, NULL));
2959 printf("dirtest core %g seconds\n", end_timer() - t1);
2962 for (i=0;i<numops;i++) {
2964 slprintf(fname, sizeof(fname), "\\%x", (int)random());
2965 cli_unlink(&cli, fname);
2968 if (!torture_close_connection(&cli)) {
2972 printf("finished dirtest\n");
2977 static BOOL run_error_map_extract(int dummy) {
2979 static struct cli_state c_dos;
2980 static struct cli_state c_nt;
2984 uint32 flgs2, errnum;
2991 /* NT-Error connection */
2993 if (!open_nbt_connection(&c_nt)) {
2997 c_nt.use_spnego = False;
2999 if (!cli_negprot(&c_nt)) {
3000 printf("%s rejected the NT-error negprot (%s)\n",host, cli_errstr(&c_nt));
3001 cli_shutdown(&c_nt);
3005 if (!cli_session_setup(&c_nt, "", "", 0, "", 0,
3007 printf("%s rejected the NT-error initial session setup (%s)\n",host, cli_errstr(&c_nt));
3011 /* DOS-Error connection */
3013 if (!open_nbt_connection(&c_dos)) {
3017 c_dos.use_spnego = False;
3018 c_dos.force_dos_errors = True;
3020 if (!cli_negprot(&c_dos)) {
3021 printf("%s rejected the DOS-error negprot (%s)\n",host, cli_errstr(&c_dos));
3022 cli_shutdown(&c_dos);
3026 if (!cli_session_setup(&c_dos, "", "", 0, "", 0,
3028 printf("%s rejected the DOS-error initial session setup (%s)\n",host, cli_errstr(&c_dos));
3032 for (error=(0xc0000000 | 0x1); error < (0xc0000000| 0xFFF); error++) {
3033 snprintf(user, sizeof(user), "%X", error);
3035 if (cli_session_setup(&c_nt, user,
3036 password, strlen(password),
3037 password, strlen(password),
3039 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
3042 flgs2 = SVAL(c_nt.inbuf,smb_flg2);
3044 /* Case #1: 32-bit NT errors */
3045 if (flgs2 & FLAGS2_32_BIT_ERROR_CODES) {
3046 nt_status = NT_STATUS(IVAL(c_nt.inbuf,smb_rcls));
3048 printf("/** Dos error on NT connection! (%s) */\n",
3050 nt_status = NT_STATUS(0xc0000000);
3053 if (cli_session_setup(&c_dos, user,
3054 password, strlen(password),
3055 password, strlen(password),
3057 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
3059 flgs2 = SVAL(c_dos.inbuf,smb_flg2), errnum;
3061 /* Case #1: 32-bit NT errors */
3062 if (flgs2 & FLAGS2_32_BIT_ERROR_CODES) {
3063 printf("/** NT error on DOS connection! (%s) */\n",
3065 errnum = errclass = 0;
3067 cli_dos_error(&c_dos, &errclass, &errnum);
3070 if (NT_STATUS_V(nt_status) != error) {
3071 printf("/*\t{ This NT error code was 'sqashed'\n\t from %s to %s \n\t during the session setup }\n*/\n",
3072 get_nt_error_c_code(NT_STATUS(error)),
3073 get_nt_error_c_code(nt_status));
3076 printf("\t{%s,\t%s,\t%s},\n",
3077 smb_dos_err_class(errclass),
3078 smb_dos_err_name(errclass, errnum),
3079 get_nt_error_c_code(NT_STATUS(error)));
3084 static double create_procs(BOOL (*fn)(int), BOOL *result)
3087 volatile pid_t *child_status;
3088 volatile BOOL *child_status_out;
3094 child_status = (volatile pid_t *)shm_setup(sizeof(pid_t)*nprocs);
3095 if (!child_status) {
3096 printf("Failed to setup shared memory\n");
3100 child_status_out = (volatile BOOL *)shm_setup(sizeof(BOOL)*nprocs);
3101 if (!child_status_out) {
3102 printf("Failed to setup result status shared memory\n");
3106 for (i = 0; i < nprocs; i++) {
3107 child_status[i] = 0;
3108 child_status_out[i] = True;
3113 for (i=0;i<nprocs;i++) {
3116 pid_t mypid = getpid();
3117 sys_srandom(((int)mypid) ^ ((int)time(NULL)));
3119 slprintf(myname,sizeof(myname),"CLIENT%d", i);
3122 memset(¤t_cli, 0, sizeof(current_cli));
3123 if (torture_open_connection(¤t_cli)) break;
3125 printf("pid %d failed to start\n", (int)getpid());
3131 child_status[i] = getpid();
3133 while (child_status[i]) msleep(2);
3135 child_status_out[i] = fn(i);
3142 for (i=0;i<nprocs;i++) {
3143 if (child_status[i]) synccount++;
3145 if (synccount == nprocs) break;
3147 } while (end_timer() < 30);
3149 if (synccount != nprocs) {
3150 printf("FAILED TO START %d CLIENTS (started %d)\n", nprocs, synccount);
3155 /* start the client load */
3158 for (i=0;i<nprocs;i++) {
3159 child_status[i] = 0;
3162 printf("%d clients started\n", nprocs);
3164 for (i=0;i<nprocs;i++) {
3165 waitpid(0, &status, 0);
3170 for (i=0;i<nprocs;i++) {
3171 if (!child_status_out[i]) {
3178 #define FLAG_MULTIPROC 1
3185 {"FDPASS", run_fdpasstest, 0},
3186 {"LOCK1", run_locktest1, 0},
3187 {"LOCK2", run_locktest2, 0},
3188 {"LOCK3", run_locktest3, 0},
3189 {"LOCK4", run_locktest4, 0},
3190 {"LOCK5", run_locktest5, 0},
3191 {"UNLINK", run_unlinktest, 0},
3192 {"BROWSE", run_browsetest, 0},
3193 {"ATTR", run_attrtest, 0},
3194 {"TRANS2", run_trans2test, 0},
3195 {"MAXFID", run_maxfidtest, FLAG_MULTIPROC},
3196 {"TORTURE",run_torture, FLAG_MULTIPROC},
3197 {"RANDOMIPC", run_randomipc, 0},
3198 {"NEGNOWAIT", run_negprot_nowait, 0},
3199 {"NBENCH", run_nbench, 0},
3200 {"OPLOCK1", run_oplock1, 0},
3201 {"OPLOCK2", run_oplock2, 0},
3202 {"OPLOCK3", run_oplock3, 0},
3203 {"DIR", run_dirtest, 0},
3204 {"DENY1", torture_denytest1, 0},
3205 {"DENY2", torture_denytest2, 0},
3206 {"TCON", run_tcon_test, 0},
3207 {"RW1", run_readwritetest, 0},
3208 {"RW2", run_readwritemulti, FLAG_MULTIPROC},
3209 {"RW3", run_readwritelarge, 0},
3210 {"OPEN", run_opentest, 0},
3211 {"XCOPY", run_xcopy, 0},
3212 {"RENAME", run_rename, 0},
3213 {"DELETE", run_deletetest, 0},
3214 {"W2K", run_w2ktest, 0},
3215 {"TRANS2SCAN", torture_trans2_scan, 0},
3216 {"NTTRANSSCAN", torture_nttrans_scan, 0},
3217 {"UTABLE", torture_utable, 0},
3218 {"CASETABLE", torture_casetable, 0},
3219 {"ERRMAPEXTRACT", run_error_map_extract, 0},
3224 /****************************************************************************
3225 run a specified test or "ALL"
3226 ****************************************************************************/
3227 static BOOL run_test(char *name)
3233 if (strequal(name,"ALL")) {
3234 for (i=0;torture_ops[i].name;i++) {
3235 run_test(torture_ops[i].name);
3239 for (i=0;torture_ops[i].name;i++) {
3240 snprintf(randomfname, sizeof(randomfname), "\\XX%x",
3241 (unsigned)random());
3243 if (strequal(name, torture_ops[i].name)) {
3244 printf("Running %s\n", name);
3245 if (torture_ops[i].flags & FLAG_MULTIPROC) {
3246 t = create_procs(torture_ops[i].fn, &result);
3249 printf("TEST %s FAILED!\n", name);
3254 if (!torture_ops[i].fn(0)) {
3256 printf("TEST %s FAILED!\n", name);
3260 printf("%s took %g secs\n\n", name, t);
3267 static void usage(void)
3271 printf("Usage: smbtorture //server/share <options> TEST1 TEST2 ...\n");
3273 printf("\t-d debuglevel\n");
3274 printf("\t-U user%%pass\n");
3275 printf("\t-k use kerberos\n");
3276 printf("\t-N numprocs\n");
3277 printf("\t-n my_netbios_name\n");
3278 printf("\t-W workgroup\n");
3279 printf("\t-o num_operations\n");
3280 printf("\t-O socket_options\n");
3281 printf("\t-m maximum protocol\n");
3282 printf("\t-L use oplocks\n");
3283 printf("\t-c CLIENT.TXT specify client load file for NBENCH\n");
3284 printf("\t-A showall\n");
3287 printf("tests are:");
3288 for (i=0;torture_ops[i].name;i++) {
3289 printf(" %s", torture_ops[i].name);
3293 printf("default test is ALL\n");
3302 /****************************************************************************
3304 ****************************************************************************/
3305 int main(int argc,char *argv[])
3310 extern char *optarg;
3312 BOOL correct = True;
3316 #ifdef HAVE_SETBUFFER
3317 setbuffer(stdout, NULL, 0);
3320 lp_load(dyn_CONFIGFILE,True,False,False);
3327 for(p = argv[1]; *p; p++)
3331 if (strncmp(argv[1], "//", 2)) {
3335 fstrcpy(host, &argv[1][2]);
3336 p = strchr_m(&host[2],'/');
3341 fstrcpy(share, p+1);
3345 if (*username == 0 && getenv("LOGNAME")) {
3346 pstrcpy(username,getenv("LOGNAME"));
3353 fstrcpy(workgroup, lp_workgroup());
3355 while ((opt = getopt(argc, argv, "hW:U:n:N:O:o:m:Ld:Ac:k")) != EOF) {
3358 fstrcpy(workgroup,optarg);
3361 max_protocol = interpret_protocol(optarg, max_protocol);
3364 nprocs = atoi(optarg);
3367 numops = atoi(optarg);
3370 DEBUGLEVEL = atoi(optarg);
3379 torture_showall = True;
3382 fstrcpy(myname, optarg);
3385 client_txt = optarg;
3389 use_kerberos = True;
3392 d_printf("No kerberos support compiled in\n");
3397 pstrcpy(username,optarg);
3398 p = strchr_m(username,'%');
3401 pstrcpy(password, p+1);
3406 printf("Unknown option %c (%d)\n", (char)opt, opt);
3413 p = getpass("Password:");
3415 pstrcpy(password, p);
3420 printf("host=%s share=%s user=%s myname=%s\n",
3421 host, share, username, myname);
3424 correct = run_test("ALL");
3426 for (i=1;i<argc;i++) {
3427 if (!run_test(argv[i])) {