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 = "\\lockt6.lck";
1506 if (!torture_open_connection(&cli)) {
1510 cli_sockopt(&cli, sockops);
1512 printf("starting locktest6\n");
1514 cli_unlink(&cli, fname);
1516 fnum = cli_open(&cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1517 status = cli_locktype(&cli, fnum, 0, 8, 0, LOCKING_ANDX_CHANGE_LOCKTYPE);
1518 cli_close(&cli, fnum);
1519 printf("CHANGE_LOCKTYPE gave %s\n", get_nt_error_msg(status));
1521 fnum = cli_open(&cli, fname, O_RDWR, DENY_NONE);
1522 status = cli_locktype(&cli, fnum, 0, 8, 0, LOCKING_ANDX_CANCEL_LOCK);
1523 cli_close(&cli, fnum);
1524 printf("CANCEL_LOCK gave %s\n", get_nt_error_msg(status));
1526 cli_unlink(&cli, fname);
1527 torture_close_connection(&cli);
1529 printf("finished locktest6\n");
1534 test whether fnums and tids open on one VC are available on another (a major
1537 static BOOL run_fdpasstest(int dummy)
1539 static struct cli_state cli1, cli2, cli3;
1540 char *fname = "\\fdpass.tst";
1544 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
1547 cli_sockopt(&cli1, sockops);
1548 cli_sockopt(&cli2, sockops);
1550 printf("starting fdpasstest\n");
1552 cli_unlink(&cli1, fname);
1554 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1556 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
1560 if (cli_write(&cli1, fnum1, 0, "hello world\n", 0, 13) != 13) {
1561 printf("write failed (%s)\n", cli_errstr(&cli1));
1566 cli3.vuid = cli1.vuid;
1567 cli3.cnum = cli1.cnum;
1568 cli3.pid = cli1.pid;
1570 if (cli_read(&cli3, fnum1, buf, 0, 13) == 13) {
1571 printf("read succeeded! nasty security hole [%s]\n",
1576 cli_close(&cli1, fnum1);
1577 cli_unlink(&cli1, fname);
1579 torture_close_connection(&cli1);
1580 torture_close_connection(&cli2);
1582 printf("finished fdpasstest\n");
1588 This test checks that
1590 1) the server does not allow an unlink on a file that is open
1592 static BOOL run_unlinktest(int dummy)
1594 static struct cli_state cli;
1595 char *fname = "\\unlink.tst";
1597 BOOL correct = True;
1599 if (!torture_open_connection(&cli)) {
1603 cli_sockopt(&cli, sockops);
1605 printf("starting unlink test\n");
1607 cli_unlink(&cli, fname);
1609 cli_setpid(&cli, 1);
1611 fnum = cli_open(&cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1613 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli));
1617 if (cli_unlink(&cli, fname)) {
1618 printf("error: server allowed unlink on an open file\n");
1621 correct = check_error(__LINE__, &cli, ERRDOS, ERRbadshare,
1622 NT_STATUS_SHARING_VIOLATION);
1625 cli_close(&cli, fnum);
1626 cli_unlink(&cli, fname);
1628 if (!torture_close_connection(&cli)) {
1632 printf("unlink test finished\n");
1639 test how many open files this server supports on the one socket
1641 static BOOL run_maxfidtest(int dummy)
1643 static struct cli_state cli;
1644 char *template = "\\maxfid.%d.%d";
1646 int fnums[0x11000], i;
1648 BOOL correct = True;
1653 printf("failed to connect\n");
1657 cli_sockopt(&cli, sockops);
1659 for (i=0; i<0x11000; i++) {
1660 slprintf(fname,sizeof(fname)-1,template, i,(int)getpid());
1661 if ((fnums[i] = cli_open(&cli, fname,
1662 O_RDWR|O_CREAT|O_TRUNC, DENY_NONE)) ==
1664 printf("open of %s failed (%s)\n",
1665 fname, cli_errstr(&cli));
1666 printf("maximum fnum is %d\n", i);
1674 printf("cleaning up\n");
1676 slprintf(fname,sizeof(fname)-1,template, i,(int)getpid());
1677 cli_close(&cli, fnums[i]);
1678 if (!cli_unlink(&cli, fname)) {
1679 printf("unlink of %s failed (%s)\n",
1680 fname, cli_errstr(&cli));
1687 printf("maxfid test finished\n");
1688 if (!torture_close_connection(&cli)) {
1694 /* generate a random buffer */
1695 static void rand_buf(char *buf, int len)
1698 *buf = (char)sys_random();
1703 /* send smb negprot commands, not reading the response */
1704 static BOOL run_negprot_nowait(int dummy)
1707 static struct cli_state cli;
1708 BOOL correct = True;
1710 printf("starting negprot nowait test\n");
1712 if (!open_nbt_connection(&cli)) {
1716 for (i=0;i<50000;i++) {
1717 cli_negprot_send(&cli);
1720 if (!torture_close_connection(&cli)) {
1724 printf("finished negprot nowait test\n");
1730 /* send random IPC commands */
1731 static BOOL run_randomipc(int dummy)
1733 char *rparam = NULL;
1737 int api, param_len, i;
1738 static struct cli_state cli;
1739 BOOL correct = True;
1742 printf("starting random ipc test\n");
1744 if (!torture_open_connection(&cli)) {
1748 for (i=0;i<count;i++) {
1749 api = sys_random() % 500;
1750 param_len = (sys_random() % 64);
1752 rand_buf(param, param_len);
1757 param, param_len, 8,
1758 NULL, 0, BUFFER_SIZE,
1762 printf("%d/%d\r", i,count);
1765 printf("%d/%d\n", i, count);
1767 if (!torture_close_connection(&cli)) {
1771 printf("finished random ipc test\n");
1778 static void browse_callback(const char *sname, uint32 stype,
1779 const char *comment, void *state)
1781 printf("\t%20.20s %08x %s\n", sname, stype, comment);
1787 This test checks the browse list code
1790 static BOOL run_browsetest(int dummy)
1792 static struct cli_state cli;
1793 BOOL correct = True;
1795 printf("starting browse test\n");
1797 if (!torture_open_connection(&cli)) {
1801 printf("domain list:\n");
1802 cli_NetServerEnum(&cli, cli.server_domain,
1803 SV_TYPE_DOMAIN_ENUM,
1804 browse_callback, NULL);
1806 printf("machine list:\n");
1807 cli_NetServerEnum(&cli, cli.server_domain,
1809 browse_callback, NULL);
1811 if (!torture_close_connection(&cli)) {
1815 printf("browse test finished\n");
1823 This checks how the getatr calls works
1825 static BOOL run_attrtest(int dummy)
1827 static struct cli_state cli;
1830 char *fname = "\\attrib.tst";
1831 BOOL correct = True;
1833 printf("starting attrib test\n");
1835 if (!torture_open_connection(&cli)) {
1839 cli_unlink(&cli, fname);
1840 fnum = cli_open(&cli, fname,
1841 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1842 cli_close(&cli, fnum);
1843 if (!cli_getatr(&cli, fname, NULL, NULL, &t)) {
1844 printf("getatr failed (%s)\n", cli_errstr(&cli));
1848 if (abs(t - time(NULL)) > 60*60*24*10) {
1849 printf("ERROR: SMBgetatr bug. time is %s",
1855 t2 = t-60*60*24; /* 1 day ago */
1857 if (!cli_setatr(&cli, fname, 0, t2)) {
1858 printf("setatr failed (%s)\n", cli_errstr(&cli));
1862 if (!cli_getatr(&cli, fname, NULL, NULL, &t)) {
1863 printf("getatr failed (%s)\n", cli_errstr(&cli));
1868 printf("ERROR: getatr/setatr bug. times are\n%s",
1870 printf("%s", ctime(&t2));
1874 cli_unlink(&cli, fname);
1876 if (!torture_close_connection(&cli)) {
1880 printf("attrib test finished\n");
1887 This checks a couple of trans2 calls
1889 static BOOL run_trans2test(int dummy)
1891 static struct cli_state cli;
1894 time_t c_time, a_time, m_time, w_time, m_time2;
1895 char *fname = "\\trans2.tst";
1896 char *dname = "\\trans2";
1897 char *fname2 = "\\trans2\\trans2.tst";
1899 BOOL correct = True;
1901 printf("starting trans2 test\n");
1903 if (!torture_open_connection(&cli)) {
1907 cli_unlink(&cli, fname);
1908 fnum = cli_open(&cli, fname,
1909 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1910 if (!cli_qfileinfo(&cli, fnum, NULL, &size, &c_time, &a_time, &m_time,
1912 printf("ERROR: qfileinfo failed (%s)\n", cli_errstr(&cli));
1916 if (!cli_qfilename(&cli, fnum, pname)) {
1917 printf("ERROR: qfilename failed (%s)\n", cli_errstr(&cli));
1921 if (strcmp(pname, fname)) {
1922 printf("qfilename gave different name? [%s] [%s]\n",
1927 cli_close(&cli, fnum);
1931 cli_unlink(&cli, fname);
1932 fnum = cli_open(&cli, fname,
1933 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1935 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli));
1938 cli_close(&cli, fnum);
1940 if (!cli_qpathinfo(&cli, fname, &c_time, &a_time, &m_time, &size, NULL)) {
1941 printf("ERROR: qpathinfo failed (%s)\n", cli_errstr(&cli));
1944 if (c_time != m_time) {
1945 printf("create time=%s", ctime(&c_time));
1946 printf("modify time=%s", ctime(&m_time));
1947 printf("This system appears to have sticky create times\n");
1950 if (a_time % (60*60) == 0) {
1951 printf("access time=%s", ctime(&a_time));
1952 printf("This system appears to set a midnight access time\n");
1956 if (abs(m_time - time(NULL)) > 60*60*24*7) {
1957 printf("ERROR: totally incorrect times - maybe word reversed? mtime=%s", ctime(&m_time));
1963 cli_unlink(&cli, fname);
1964 fnum = cli_open(&cli, fname,
1965 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1966 cli_close(&cli, fnum);
1967 if (!cli_qpathinfo2(&cli, fname, &c_time, &a_time, &m_time,
1968 &w_time, &size, NULL, NULL)) {
1969 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli));
1972 if (w_time < 60*60*24*2) {
1973 printf("write time=%s", ctime(&w_time));
1974 printf("This system appears to set a initial 0 write time\n");
1979 cli_unlink(&cli, fname);
1982 /* check if the server updates the directory modification time
1983 when creating a new file */
1984 if (!cli_mkdir(&cli, dname)) {
1985 printf("ERROR: mkdir failed (%s)\n", cli_errstr(&cli));
1989 if (!cli_qpathinfo2(&cli, "\\trans2\\", &c_time, &a_time, &m_time,
1990 &w_time, &size, NULL, NULL)) {
1991 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli));
1995 fnum = cli_open(&cli, fname2,
1996 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1997 cli_write(&cli, fnum, 0, (char *)&fnum, 0, sizeof(fnum));
1998 cli_close(&cli, fnum);
1999 if (!cli_qpathinfo2(&cli, "\\trans2\\", &c_time, &a_time, &m_time2,
2000 &w_time, &size, NULL, NULL)) {
2001 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli));
2004 if (m_time2 == m_time) {
2005 printf("This system does not update directory modification times\n");
2009 cli_unlink(&cli, fname2);
2010 cli_rmdir(&cli, dname);
2012 if (!torture_close_connection(&cli)) {
2016 printf("trans2 test finished\n");
2022 This checks new W2K calls.
2025 static BOOL new_trans(struct cli_state *pcli, int fnum, int level)
2028 BOOL correct = True;
2030 memset(buf, 0xff, sizeof(buf));
2032 if (!cli_qfileinfo_test(pcli, fnum, level, buf)) {
2033 printf("ERROR: qfileinfo (%d) failed (%s)\n", level, cli_errstr(pcli));
2036 printf("qfileinfo: level %d\n", level);
2037 dump_data(0, buf, 256);
2043 static BOOL run_w2ktest(int dummy)
2045 static struct cli_state cli;
2047 char *fname = "\\w2ktest\\w2k.tst";
2049 BOOL correct = True;
2051 printf("starting w2k test\n");
2053 if (!torture_open_connection(&cli)) {
2057 fnum = cli_open(&cli, fname,
2058 O_RDWR | O_CREAT , DENY_NONE);
2060 for (level = 1004; level < 1040; level++) {
2061 new_trans(&cli, fnum, level);
2064 cli_close(&cli, fnum);
2066 if (!torture_close_connection(&cli)) {
2070 printf("w2k test finished\n");
2077 this is a harness for some oplock tests
2079 static BOOL run_oplock1(int dummy)
2081 static struct cli_state cli1;
2082 char *fname = "\\lockt1.lck";
2084 BOOL correct = True;
2086 printf("starting oplock test 1\n");
2088 if (!torture_open_connection(&cli1)) {
2092 cli_unlink(&cli1, fname);
2094 cli_sockopt(&cli1, sockops);
2096 cli1.use_oplocks = True;
2098 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2100 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2104 cli1.use_oplocks = False;
2106 cli_unlink(&cli1, fname);
2107 cli_unlink(&cli1, fname);
2109 if (!cli_close(&cli1, fnum1)) {
2110 printf("close2 failed (%s)\n", cli_errstr(&cli1));
2114 if (!cli_unlink(&cli1, fname)) {
2115 printf("unlink failed (%s)\n", cli_errstr(&cli1));
2119 if (!torture_close_connection(&cli1)) {
2123 printf("finished oplock test 1\n");
2128 static BOOL run_oplock2(int dummy)
2130 static struct cli_state cli1, cli2;
2131 char *fname = "\\lockt2.lck";
2133 int saved_use_oplocks = use_oplocks;
2135 BOOL correct = True;
2136 volatile BOOL *shared_correct;
2138 shared_correct = (volatile BOOL *)shm_setup(sizeof(BOOL));
2139 *shared_correct = True;
2141 use_level_II_oplocks = True;
2144 printf("starting oplock test 2\n");
2146 if (!torture_open_connection(&cli1)) {
2147 use_level_II_oplocks = False;
2148 use_oplocks = saved_use_oplocks;
2152 cli1.use_oplocks = True;
2153 cli1.use_level_II_oplocks = True;
2155 if (!torture_open_connection(&cli2)) {
2156 use_level_II_oplocks = False;
2157 use_oplocks = saved_use_oplocks;
2161 cli2.use_oplocks = True;
2162 cli2.use_level_II_oplocks = True;
2164 cli_unlink(&cli1, fname);
2166 cli_sockopt(&cli1, sockops);
2167 cli_sockopt(&cli2, sockops);
2169 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2171 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2175 /* Don't need the globals any more. */
2176 use_level_II_oplocks = False;
2177 use_oplocks = saved_use_oplocks;
2181 fnum2 = cli_open(&cli2, fname, O_RDWR, DENY_NONE);
2183 printf("second open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2184 *shared_correct = False;
2190 if (!cli_close(&cli2, fnum2)) {
2191 printf("close2 failed (%s)\n", cli_errstr(&cli1));
2192 *shared_correct = False;
2200 /* Ensure cli1 processes the break. */
2202 if (cli_read(&cli1, fnum1, buf, 0, 4) != 4) {
2203 printf("read on fnum1 failed (%s)\n", cli_errstr(&cli1));
2207 /* Should now be at level II. */
2208 /* Test if sending a write locks causes a break to none. */
2210 if (!cli_lock(&cli1, fnum1, 0, 4, 0, READ_LOCK)) {
2211 printf("lock failed (%s)\n", cli_errstr(&cli1));
2215 cli_unlock(&cli1, fnum1, 0, 4);
2219 if (!cli_lock(&cli1, fnum1, 0, 4, 0, WRITE_LOCK)) {
2220 printf("lock failed (%s)\n", cli_errstr(&cli1));
2224 cli_unlock(&cli1, fnum1, 0, 4);
2228 cli_read(&cli1, fnum1, buf, 0, 4);
2231 if (cli_write(&cli1, fnum1, 0, buf, 0, 4) != 4) {
2232 printf("write on fnum1 failed (%s)\n", cli_errstr(&cli1));
2237 if (!cli_close(&cli1, fnum1)) {
2238 printf("close1 failed (%s)\n", cli_errstr(&cli1));
2244 if (!cli_unlink(&cli1, fname)) {
2245 printf("unlink failed (%s)\n", cli_errstr(&cli1));
2249 if (!torture_close_connection(&cli1)) {
2253 if (!*shared_correct) {
2257 printf("finished oplock test 2\n");
2262 /* handler for oplock 3 tests */
2263 static BOOL oplock3_handler(struct cli_state *cli, int fnum, unsigned char level)
2265 printf("got oplock break fnum=%d level=%d\n",
2267 return cli_oplock_ack(cli, fnum, level);
2270 static BOOL run_oplock3(int dummy)
2272 static struct cli_state cli;
2273 char *fname = "\\oplockt3.dat";
2275 char buf[4] = "abcd";
2276 BOOL correct = True;
2277 volatile BOOL *shared_correct;
2279 shared_correct = (volatile BOOL *)shm_setup(sizeof(BOOL));
2280 *shared_correct = True;
2282 printf("starting oplock test 3\n");
2287 use_level_II_oplocks = True;
2288 if (!torture_open_connection(&cli)) {
2289 *shared_correct = False;
2293 /* try to trigger a oplock break in parent */
2294 fnum = cli_open(&cli, fname, O_RDWR, DENY_NONE);
2295 cli_write(&cli, fnum, 0, buf, 0, 4);
2301 use_level_II_oplocks = True;
2302 if (!torture_open_connection(&cli)) {
2305 cli_oplock_handler(&cli, oplock3_handler);
2306 fnum = cli_open(&cli, fname, O_RDWR|O_CREAT, DENY_NONE);
2307 cli_write(&cli, fnum, 0, buf, 0, 4);
2308 cli_close(&cli, fnum);
2309 fnum = cli_open(&cli, fname, O_RDWR, DENY_NONE);
2310 cli.timeout = 20000;
2311 cli_receive_smb(&cli);
2312 printf("finished oplock test 3\n");
2314 return (correct && *shared_correct);
2316 /* What are we looking for here? What's sucess and what's FAILURE? */
2322 Test delete on close semantics.
2324 static BOOL run_deletetest(int dummy)
2326 static struct cli_state cli1;
2327 static struct cli_state cli2;
2328 char *fname = "\\delete.file";
2331 BOOL correct = True;
2333 printf("starting delete test\n");
2338 if (!torture_open_connection(&cli1)) {
2342 cli_sockopt(&cli1, sockops);
2344 /* Test 1 - this should *NOT* delete the file on close. */
2346 cli_setatr(&cli1, fname, 0, 0);
2347 cli_unlink(&cli1, fname);
2349 fnum1 = cli_nt_create_full(&cli1, fname, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL,
2350 FILE_SHARE_DELETE, FILE_OVERWRITE_IF,
2351 DELETE_ON_CLOSE_FLAG);
2354 printf("[1] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2359 if (!cli_close(&cli1, fnum1)) {
2360 printf("[1] close failed (%s)\n", cli_errstr(&cli1));
2365 fnum1 = cli_open(&cli1, fname, O_RDWR, DENY_NONE);
2367 printf("[1] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2372 if (!cli_close(&cli1, fnum1)) {
2373 printf("[1] close failed (%s)\n", cli_errstr(&cli1));
2378 printf("first delete on close test succeeded.\n");
2380 /* Test 2 - this should delete the file on close. */
2382 cli_setatr(&cli1, fname, 0, 0);
2383 cli_unlink(&cli1, fname);
2385 fnum1 = cli_nt_create_full(&cli1, fname, GENERIC_ALL_ACCESS,
2386 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
2387 FILE_OVERWRITE_IF, 0);
2390 printf("[2] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2395 if (!cli_nt_delete_on_close(&cli1, fnum1, True)) {
2396 printf("[2] setting delete_on_close failed (%s)\n", cli_errstr(&cli1));
2401 if (!cli_close(&cli1, fnum1)) {
2402 printf("[2] close failed (%s)\n", cli_errstr(&cli1));
2407 fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_NONE);
2409 printf("[2] open of %s succeeded should have been deleted on close !\n", fname);
2410 if (!cli_close(&cli1, fnum1)) {
2411 printf("[2] close failed (%s)\n", cli_errstr(&cli1));
2415 cli_unlink(&cli1, fname);
2417 printf("second delete on close test succeeded.\n");
2420 cli_setatr(&cli1, fname, 0, 0);
2421 cli_unlink(&cli1, fname);
2423 fnum1 = cli_nt_create_full(&cli1, fname, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL,
2424 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0);
2427 printf("[3] open - 1 of %s failed (%s)\n", fname, cli_errstr(&cli1));
2432 /* This should fail with a sharing violation - open for delete is only compatible
2433 with SHARE_DELETE. */
2435 fnum2 = cli_nt_create_full(&cli1, fname, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
2436 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0);
2439 printf("[3] open - 2 of %s succeeded - should have failed.\n", fname);
2444 /* This should succeed. */
2446 fnum2 = cli_nt_create_full(&cli1, fname, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
2447 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0);
2450 printf("[3] open - 2 of %s failed (%s)\n", fname, cli_errstr(&cli1));
2455 if (!cli_nt_delete_on_close(&cli1, fnum1, True)) {
2456 printf("[3] setting delete_on_close failed (%s)\n", cli_errstr(&cli1));
2461 if (!cli_close(&cli1, fnum1)) {
2462 printf("[3] close 1 failed (%s)\n", cli_errstr(&cli1));
2467 if (!cli_close(&cli1, fnum2)) {
2468 printf("[3] close 2 failed (%s)\n", cli_errstr(&cli1));
2473 /* This should fail - file should no longer be there. */
2475 fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_NONE);
2477 printf("[3] open of %s succeeded should have been deleted on close !\n", fname);
2478 if (!cli_close(&cli1, fnum1)) {
2479 printf("[3] close failed (%s)\n", cli_errstr(&cli1));
2481 cli_unlink(&cli1, fname);
2485 printf("third delete on close test succeeded.\n");
2488 cli_setatr(&cli1, fname, 0, 0);
2489 cli_unlink(&cli1, fname);
2491 fnum1 = cli_nt_create_full(&cli1, fname, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
2492 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0);
2495 printf("[4] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2500 /* This should succeed. */
2501 fnum2 = cli_nt_create_full(&cli1, fname, GENERIC_READ_ACCESS,
2502 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0);
2504 printf("[4] open - 2 of %s failed (%s)\n", fname, cli_errstr(&cli1));
2509 if (!cli_close(&cli1, fnum2)) {
2510 printf("[4] close - 1 failed (%s)\n", cli_errstr(&cli1));
2515 if (!cli_nt_delete_on_close(&cli1, fnum1, True)) {
2516 printf("[4] setting delete_on_close failed (%s)\n", cli_errstr(&cli1));
2521 /* This should fail - no more opens once delete on close set. */
2522 fnum2 = cli_nt_create_full(&cli1, fname, GENERIC_READ_ACCESS,
2523 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0);
2525 printf("[4] open - 3 of %s succeeded ! Should have failed.\n", fname );
2529 printf("fourth delete on close test succeeded.\n");
2531 if (!cli_close(&cli1, fnum1)) {
2532 printf("[4] close - 2 failed (%s)\n", cli_errstr(&cli1));
2538 cli_setatr(&cli1, fname, 0, 0);
2539 cli_unlink(&cli1, fname);
2541 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT, DENY_NONE);
2543 printf("[5] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2548 /* This should fail - only allowed on NT opens with DELETE access. */
2550 if (cli_nt_delete_on_close(&cli1, fnum1, True)) {
2551 printf("[5] setting delete_on_close on OpenX file succeeded - should fail !\n");
2556 if (!cli_close(&cli1, fnum1)) {
2557 printf("[5] close - 2 failed (%s)\n", cli_errstr(&cli1));
2562 printf("fifth delete on close test succeeded.\n");
2565 cli_setatr(&cli1, fname, 0, 0);
2566 cli_unlink(&cli1, fname);
2568 fnum1 = cli_nt_create_full(&cli1, fname, FILE_READ_DATA|FILE_WRITE_DATA,
2569 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
2570 FILE_OVERWRITE_IF, 0);
2573 printf("[6] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2578 /* This should fail - only allowed on NT opens with DELETE access. */
2580 if (cli_nt_delete_on_close(&cli1, fnum1, True)) {
2581 printf("[6] setting delete_on_close on file with no delete access succeeded - should fail !\n");
2586 if (!cli_close(&cli1, fnum1)) {
2587 printf("[6] close - 2 failed (%s)\n", cli_errstr(&cli1));
2592 printf("sixth delete on close test succeeded.\n");
2595 cli_setatr(&cli1, fname, 0, 0);
2596 cli_unlink(&cli1, fname);
2598 fnum1 = cli_nt_create_full(&cli1, fname, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
2599 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF, 0);
2602 printf("[7] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2607 if (!cli_nt_delete_on_close(&cli1, fnum1, True)) {
2608 printf("[7] setting delete_on_close on file failed !\n");
2613 if (!cli_nt_delete_on_close(&cli1, fnum1, False)) {
2614 printf("[7] unsetting delete_on_close on file failed !\n");
2619 if (!cli_close(&cli1, fnum1)) {
2620 printf("[7] close - 2 failed (%s)\n", cli_errstr(&cli1));
2625 /* This next open should succeed - we reset the flag. */
2627 fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_NONE);
2629 printf("[5] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2634 if (!cli_close(&cli1, fnum1)) {
2635 printf("[7] close - 2 failed (%s)\n", cli_errstr(&cli1));
2640 printf("seventh delete on close test succeeded.\n");
2643 cli_setatr(&cli1, fname, 0, 0);
2644 cli_unlink(&cli1, fname);
2646 if (!torture_open_connection(&cli2)) {
2647 printf("[8] failed to open second connection.\n");
2652 cli_sockopt(&cli1, sockops);
2654 fnum1 = cli_nt_create_full(&cli1, fname, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
2655 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0);
2658 printf("[8] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2663 fnum2 = cli_nt_create_full(&cli2, fname, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
2664 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0);
2667 printf("[8] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2672 if (!cli_nt_delete_on_close(&cli1, fnum1, True)) {
2673 printf("[8] setting delete_on_close on file failed !\n");
2678 if (!cli_close(&cli1, fnum1)) {
2679 printf("[8] close - 1 failed (%s)\n", cli_errstr(&cli1));
2684 if (!cli_close(&cli2, fnum2)) {
2685 printf("[8] close - 2 failed (%s)\n", cli_errstr(&cli2));
2690 /* This should fail.. */
2691 fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_NONE);
2693 printf("[8] open of %s succeeded should have been deleted on close !\n", fname);
2697 printf("eighth delete on close test succeeded.\n");
2699 /* This should fail - we need to set DELETE_ACCESS. */
2700 fnum1 = cli_nt_create_full(&cli1, fname, FILE_READ_DATA|FILE_WRITE_DATA,
2701 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, FILE_OVERWRITE_IF, FILE_DELETE_ON_CLOSE);
2704 printf("[9] open of %s succeeded should have failed!\n", fname);
2709 printf("ninth delete on close test succeeded.\n");
2711 fnum1 = cli_nt_create_full(&cli1, fname, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
2712 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, FILE_OVERWRITE_IF, FILE_DELETE_ON_CLOSE);
2714 printf("[10] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2719 /* This should delete the file. */
2720 if (!cli_close(&cli1, fnum1)) {
2721 printf("[10] close failed (%s)\n", cli_errstr(&cli1));
2726 /* This should fail.. */
2727 fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_NONE);
2729 printf("[10] open of %s succeeded should have been deleted on close !\n", fname);
2733 printf("tenth delete on close test succeeded.\n");
2734 printf("finished delete test\n");
2738 cli_close(&cli1, fnum1);
2739 cli_close(&cli1, fnum2);
2740 cli_setatr(&cli1, fname, 0, 0);
2741 cli_unlink(&cli1, fname);
2743 if (!torture_close_connection(&cli1)) {
2746 if (!torture_close_connection(&cli2)) {
2752 /* FIRST_DESIRED_ACCESS 0xf019f */
2753 #define FIRST_DESIRED_ACCESS FILE_READ_DATA|FILE_WRITE_DATA|FILE_APPEND_DATA|\
2754 FILE_READ_EA| /* 0xf */ \
2755 FILE_WRITE_EA|FILE_READ_ATTRIBUTES| /* 0x90 */ \
2756 FILE_WRITE_ATTRIBUTES| /* 0x100 */ \
2757 DELETE_ACCESS|READ_CONTROL_ACCESS|\
2758 WRITE_DAC_ACCESS|WRITE_OWNER_ACCESS /* 0xf0000 */
2759 /* SECOND_DESIRED_ACCESS 0xe0080 */
2760 #define SECOND_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
2761 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
2762 WRITE_OWNER_ACCESS /* 0xe0000 */
2765 #define THIRD_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
2766 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
2768 WRITE_OWNER_ACCESS /* */
2772 Test ntcreate calls made by xcopy
2774 static BOOL run_xcopy(int dummy)
2776 static struct cli_state cli1;
2777 char *fname = "\\test.txt";
2778 BOOL correct = True;
2781 printf("starting xcopy test\n");
2783 if (!torture_open_connection(&cli1)) {
2787 fnum1 = cli_nt_create_full(&cli1, fname,
2788 FIRST_DESIRED_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
2789 FILE_SHARE_NONE, FILE_OVERWRITE_IF,
2793 printf("First open failed - %s\n", cli_errstr(&cli1));
2797 fnum2 = cli_nt_create_full(&cli1, fname,
2798 SECOND_DESIRED_ACCESS, 0,
2799 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN,
2802 printf("second open failed - %s\n", cli_errstr(&cli1));
2806 if (!torture_close_connection(&cli1)) {
2814 Test rename on files open with share delete and no share delete.
2816 static BOOL run_rename(int dummy)
2818 static struct cli_state cli1;
2819 char *fname = "\\test.txt";
2820 char *fname1 = "\\test1.txt";
2821 BOOL correct = True;
2824 printf("starting rename test\n");
2826 if (!torture_open_connection(&cli1)) {
2830 cli_unlink(&cli1, fname);
2831 cli_unlink(&cli1, fname1);
2832 fnum1 = cli_nt_create_full(&cli1, fname, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
2833 FILE_SHARE_READ, FILE_OVERWRITE_IF, 0);
2836 printf("First open failed - %s\n", cli_errstr(&cli1));
2840 if (!cli_rename(&cli1, fname, fname1)) {
2841 printf("First rename failed (this is correct) - %s\n", cli_errstr(&cli1));
2843 printf("First rename succeeded - this should have failed !\n");
2847 if (!cli_close(&cli1, fnum1)) {
2848 printf("close - 1 failed (%s)\n", cli_errstr(&cli1));
2852 cli_unlink(&cli1, fname);
2853 cli_unlink(&cli1, fname1);
2854 fnum1 = cli_nt_create_full(&cli1, fname,GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
2855 FILE_SHARE_DELETE|FILE_SHARE_READ, FILE_OVERWRITE_IF, 0);
2858 printf("Second open failed - %s\n", cli_errstr(&cli1));
2862 if (!cli_rename(&cli1, fname, fname1)) {
2863 printf("Second rename failed - this should have succeeded - %s\n", cli_errstr(&cli1));
2866 printf("Second rename succeeded\n");
2869 if (!cli_close(&cli1, fnum1)) {
2870 printf("close - 2 failed (%s)\n", cli_errstr(&cli1));
2874 cli_unlink(&cli1, fname);
2875 cli_unlink(&cli1, fname1);
2877 if (!torture_close_connection(&cli1)) {
2886 Test open mode returns on read-only files.
2888 static BOOL run_opentest(int dummy)
2890 static struct cli_state cli1;
2891 char *fname = "\\readonly.file";
2895 BOOL correct = True;
2898 printf("starting open test\n");
2900 if (!torture_open_connection(&cli1)) {
2904 cli_setatr(&cli1, fname, 0, 0);
2905 cli_unlink(&cli1, fname);
2907 cli_sockopt(&cli1, sockops);
2909 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2911 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2915 if (!cli_close(&cli1, fnum1)) {
2916 printf("close2 failed (%s)\n", cli_errstr(&cli1));
2920 if (!cli_setatr(&cli1, fname, aRONLY, 0)) {
2921 printf("cli_setatr failed (%s)\n", cli_errstr(&cli1));
2925 fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_WRITE);
2927 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2931 /* This will fail - but the error should be ERRnoaccess, not ERRbadshare. */
2932 fnum2 = cli_open(&cli1, fname, O_RDWR, DENY_ALL);
2934 if (check_error(__LINE__, &cli1, ERRDOS, ERRnoaccess,
2935 NT_STATUS_ACCESS_DENIED)) {
2936 printf("correct error code ERRDOS/ERRnoaccess returned\n");
2939 printf("finished open test 1\n");
2941 cli_close(&cli1, fnum1);
2943 /* Now try not readonly and ensure ERRbadshare is returned. */
2945 cli_setatr(&cli1, fname, 0, 0);
2947 fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_WRITE);
2949 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2953 /* This will fail - but the error should be ERRshare. */
2954 fnum2 = cli_open(&cli1, fname, O_RDWR, DENY_ALL);
2956 if (check_error(__LINE__, &cli1, ERRDOS, ERRbadshare,
2957 NT_STATUS_SHARING_VIOLATION)) {
2958 printf("correct error code ERRDOS/ERRbadshare returned\n");
2961 if (!cli_close(&cli1, fnum1)) {
2962 printf("close2 failed (%s)\n", cli_errstr(&cli1));
2966 cli_unlink(&cli1, fname);
2968 printf("finished open test 2\n");
2970 /* Test truncate open disposition on file opened for read. */
2972 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2974 printf("(3) open (1) of %s failed (%s)\n", fname, cli_errstr(&cli1));
2978 /* write 20 bytes. */
2980 memset(buf, '\0', 20);
2982 if (cli_write(&cli1, fnum1, 0, buf, 0, 20) != 20) {
2983 printf("write failed (%s)\n", cli_errstr(&cli1));
2987 if (!cli_close(&cli1, fnum1)) {
2988 printf("(3) close1 failed (%s)\n", cli_errstr(&cli1));
2992 /* Ensure size == 20. */
2993 if (!cli_getatr(&cli1, fname, NULL, &fsize, NULL)) {
2994 printf("(3) getatr failed (%s)\n", cli_errstr(&cli1));
2999 printf("(3) file size != 20\n");
3003 /* Now test if we can truncate a file opened for readonly. */
3005 fnum1 = cli_open(&cli1, fname, O_RDONLY|O_TRUNC, DENY_NONE);
3007 printf("(3) open (2) of %s failed (%s)\n", fname, cli_errstr(&cli1));
3011 if (!cli_close(&cli1, fnum1)) {
3012 printf("close2 failed (%s)\n", cli_errstr(&cli1));
3016 /* Ensure size == 0. */
3017 if (!cli_getatr(&cli1, fname, NULL, &fsize, NULL)) {
3018 printf("(3) getatr failed (%s)\n", cli_errstr(&cli1));
3023 printf("(3) file size != 0\n");
3026 printf("finished open test 3\n");
3028 cli_unlink(&cli1, fname);
3031 printf("testing ctemp\n");
3032 fnum1 = cli_ctemp(&cli1, "\\", &tmp_path);
3034 printf("ctemp failed (%s)\n", cli_errstr(&cli1));
3037 printf("ctemp gave path %s\n", tmp_path);
3038 if (!cli_close(&cli1, fnum1)) {
3039 printf("close of temp failed (%s)\n", cli_errstr(&cli1));
3041 if (!cli_unlink(&cli1, tmp_path)) {
3042 printf("unlink of temp failed (%s)\n", cli_errstr(&cli1));
3045 if (!torture_close_connection(&cli1)) {
3052 static void list_fn(file_info *finfo, const char *name, void *state)
3058 test directory listing speed
3060 static BOOL run_dirtest(int dummy)
3063 static struct cli_state cli;
3066 BOOL correct = True;
3068 printf("starting directory test\n");
3070 if (!torture_open_connection(&cli)) {
3074 cli_sockopt(&cli, sockops);
3077 for (i=0;i<numops;i++) {
3079 slprintf(fname, sizeof(fname), "\\%x", (int)random());
3080 fnum = cli_open(&cli, fname, O_RDWR|O_CREAT, DENY_NONE);
3082 fprintf(stderr,"Failed to open %s\n", fname);
3085 cli_close(&cli, fnum);
3090 printf("Matched %d\n", cli_list(&cli, "a*.*", 0, list_fn, NULL));
3091 printf("Matched %d\n", cli_list(&cli, "b*.*", 0, list_fn, NULL));
3092 printf("Matched %d\n", cli_list(&cli, "xyzabc", 0, list_fn, NULL));
3094 printf("dirtest core %g seconds\n", end_timer() - t1);
3097 for (i=0;i<numops;i++) {
3099 slprintf(fname, sizeof(fname), "\\%x", (int)random());
3100 cli_unlink(&cli, fname);
3103 if (!torture_close_connection(&cli)) {
3107 printf("finished dirtest\n");
3112 static BOOL run_error_map_extract(int dummy) {
3114 static struct cli_state c_dos;
3115 static struct cli_state c_nt;
3119 uint32 flgs2, errnum;
3126 /* NT-Error connection */
3128 if (!open_nbt_connection(&c_nt)) {
3132 c_nt.use_spnego = False;
3134 if (!cli_negprot(&c_nt)) {
3135 printf("%s rejected the NT-error negprot (%s)\n",host, cli_errstr(&c_nt));
3136 cli_shutdown(&c_nt);
3140 if (!cli_session_setup(&c_nt, "", "", 0, "", 0,
3142 printf("%s rejected the NT-error initial session setup (%s)\n",host, cli_errstr(&c_nt));
3146 /* DOS-Error connection */
3148 if (!open_nbt_connection(&c_dos)) {
3152 c_dos.use_spnego = False;
3153 c_dos.force_dos_errors = True;
3155 if (!cli_negprot(&c_dos)) {
3156 printf("%s rejected the DOS-error negprot (%s)\n",host, cli_errstr(&c_dos));
3157 cli_shutdown(&c_dos);
3161 if (!cli_session_setup(&c_dos, "", "", 0, "", 0,
3163 printf("%s rejected the DOS-error initial session setup (%s)\n",host, cli_errstr(&c_dos));
3167 for (error=(0xc0000000 | 0x1); error < (0xc0000000| 0xFFF); error++) {
3168 snprintf(user, sizeof(user), "%X", error);
3170 if (cli_session_setup(&c_nt, user,
3171 password, strlen(password),
3172 password, strlen(password),
3174 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
3177 flgs2 = SVAL(c_nt.inbuf,smb_flg2);
3179 /* Case #1: 32-bit NT errors */
3180 if (flgs2 & FLAGS2_32_BIT_ERROR_CODES) {
3181 nt_status = NT_STATUS(IVAL(c_nt.inbuf,smb_rcls));
3183 printf("/** Dos error on NT connection! (%s) */\n",
3185 nt_status = NT_STATUS(0xc0000000);
3188 if (cli_session_setup(&c_dos, user,
3189 password, strlen(password),
3190 password, strlen(password),
3192 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
3194 flgs2 = SVAL(c_dos.inbuf,smb_flg2), errnum;
3196 /* Case #1: 32-bit NT errors */
3197 if (flgs2 & FLAGS2_32_BIT_ERROR_CODES) {
3198 printf("/** NT error on DOS connection! (%s) */\n",
3200 errnum = errclass = 0;
3202 cli_dos_error(&c_dos, &errclass, &errnum);
3205 if (NT_STATUS_V(nt_status) != error) {
3206 printf("/*\t{ This NT error code was 'sqashed'\n\t from %s to %s \n\t during the session setup }\n*/\n",
3207 get_nt_error_c_code(NT_STATUS(error)),
3208 get_nt_error_c_code(nt_status));
3211 printf("\t{%s,\t%s,\t%s},\n",
3212 smb_dos_err_class(errclass),
3213 smb_dos_err_name(errclass, errnum),
3214 get_nt_error_c_code(NT_STATUS(error)));
3219 static double create_procs(BOOL (*fn)(int), BOOL *result)
3222 volatile pid_t *child_status;
3223 volatile BOOL *child_status_out;
3229 child_status = (volatile pid_t *)shm_setup(sizeof(pid_t)*nprocs);
3230 if (!child_status) {
3231 printf("Failed to setup shared memory\n");
3235 child_status_out = (volatile BOOL *)shm_setup(sizeof(BOOL)*nprocs);
3236 if (!child_status_out) {
3237 printf("Failed to setup result status shared memory\n");
3241 for (i = 0; i < nprocs; i++) {
3242 child_status[i] = 0;
3243 child_status_out[i] = True;
3248 for (i=0;i<nprocs;i++) {
3251 pid_t mypid = getpid();
3252 sys_srandom(((int)mypid) ^ ((int)time(NULL)));
3254 slprintf(myname,sizeof(myname),"CLIENT%d", i);
3257 memset(¤t_cli, 0, sizeof(current_cli));
3258 if (torture_open_connection(¤t_cli)) break;
3260 printf("pid %d failed to start\n", (int)getpid());
3266 child_status[i] = getpid();
3268 while (child_status[i]) msleep(2);
3270 child_status_out[i] = fn(i);
3277 for (i=0;i<nprocs;i++) {
3278 if (child_status[i]) synccount++;
3280 if (synccount == nprocs) break;
3282 } while (end_timer() < 30);
3284 if (synccount != nprocs) {
3285 printf("FAILED TO START %d CLIENTS (started %d)\n", nprocs, synccount);
3290 /* start the client load */
3293 for (i=0;i<nprocs;i++) {
3294 child_status[i] = 0;
3297 printf("%d clients started\n", nprocs);
3299 for (i=0;i<nprocs;i++) {
3300 while (waitpid(0, &status, 0) == -1 && errno == EINTR) /* noop */ ;
3305 for (i=0;i<nprocs;i++) {
3306 if (!child_status_out[i]) {
3313 #define FLAG_MULTIPROC 1
3320 {"FDPASS", run_fdpasstest, 0},
3321 {"LOCK1", run_locktest1, 0},
3322 {"LOCK2", run_locktest2, 0},
3323 {"LOCK3", run_locktest3, 0},
3324 {"LOCK4", run_locktest4, 0},
3325 {"LOCK5", run_locktest5, 0},
3326 {"LOCK6", run_locktest6, 0},
3327 {"UNLINK", run_unlinktest, 0},
3328 {"BROWSE", run_browsetest, 0},
3329 {"ATTR", run_attrtest, 0},
3330 {"TRANS2", run_trans2test, 0},
3331 {"MAXFID", run_maxfidtest, FLAG_MULTIPROC},
3332 {"TORTURE",run_torture, FLAG_MULTIPROC},
3333 {"RANDOMIPC", run_randomipc, 0},
3334 {"NEGNOWAIT", run_negprot_nowait, 0},
3335 {"NBENCH", run_nbench, 0},
3336 {"OPLOCK1", run_oplock1, 0},
3337 {"OPLOCK2", run_oplock2, 0},
3338 {"OPLOCK3", run_oplock3, 0},
3339 {"DIR", run_dirtest, 0},
3340 {"DENY1", torture_denytest1, 0},
3341 {"DENY2", torture_denytest2, 0},
3342 {"TCON", run_tcon_test, 0},
3343 {"RW1", run_readwritetest, 0},
3344 {"RW2", run_readwritemulti, FLAG_MULTIPROC},
3345 {"RW3", run_readwritelarge, 0},
3346 {"OPEN", run_opentest, 0},
3347 {"XCOPY", run_xcopy, 0},
3348 {"RENAME", run_rename, 0},
3349 {"DELETE", run_deletetest, 0},
3350 {"W2K", run_w2ktest, 0},
3351 {"TRANS2SCAN", torture_trans2_scan, 0},
3352 {"NTTRANSSCAN", torture_nttrans_scan, 0},
3353 {"UTABLE", torture_utable, 0},
3354 {"CASETABLE", torture_casetable, 0},
3355 {"ERRMAPEXTRACT", run_error_map_extract, 0},
3360 /****************************************************************************
3361 run a specified test or "ALL"
3362 ****************************************************************************/
3363 static BOOL run_test(char *name)
3369 if (strequal(name,"ALL")) {
3370 for (i=0;torture_ops[i].name;i++) {
3371 run_test(torture_ops[i].name);
3375 for (i=0;torture_ops[i].name;i++) {
3376 snprintf(randomfname, sizeof(randomfname), "\\XX%x",
3377 (unsigned)random());
3379 if (strequal(name, torture_ops[i].name)) {
3380 printf("Running %s\n", name);
3381 if (torture_ops[i].flags & FLAG_MULTIPROC) {
3382 t = create_procs(torture_ops[i].fn, &result);
3385 printf("TEST %s FAILED!\n", name);
3390 if (!torture_ops[i].fn(0)) {
3392 printf("TEST %s FAILED!\n", name);
3396 printf("%s took %g secs\n\n", name, t);
3403 static void usage(void)
3407 printf("Usage: smbtorture //server/share <options> TEST1 TEST2 ...\n");
3409 printf("\t-d debuglevel\n");
3410 printf("\t-U user%%pass\n");
3411 printf("\t-k use kerberos\n");
3412 printf("\t-N numprocs\n");
3413 printf("\t-n my_netbios_name\n");
3414 printf("\t-W workgroup\n");
3415 printf("\t-o num_operations\n");
3416 printf("\t-O socket_options\n");
3417 printf("\t-m maximum protocol\n");
3418 printf("\t-L use oplocks\n");
3419 printf("\t-c CLIENT.TXT specify client load file for NBENCH\n");
3420 printf("\t-A showall\n");
3423 printf("tests are:");
3424 for (i=0;torture_ops[i].name;i++) {
3425 printf(" %s", torture_ops[i].name);
3429 printf("default test is ALL\n");
3438 /****************************************************************************
3440 ****************************************************************************/
3441 int main(int argc,char *argv[])
3446 extern char *optarg;
3448 BOOL correct = True;
3452 #ifdef HAVE_SETBUFFER
3453 setbuffer(stdout, NULL, 0);
3456 lp_load(dyn_CONFIGFILE,True,False,False);
3463 for(p = argv[1]; *p; p++)
3467 if (strncmp(argv[1], "//", 2)) {
3471 fstrcpy(host, &argv[1][2]);
3472 p = strchr_m(&host[2],'/');
3477 fstrcpy(share, p+1);
3481 if (*username == 0 && getenv("LOGNAME")) {
3482 pstrcpy(username,getenv("LOGNAME"));
3489 fstrcpy(workgroup, lp_workgroup());
3491 while ((opt = getopt(argc, argv, "hW:U:n:N:O:o:m:Ld:Ac:k")) != EOF) {
3494 fstrcpy(workgroup,optarg);
3497 max_protocol = interpret_protocol(optarg, max_protocol);
3500 nprocs = atoi(optarg);
3503 numops = atoi(optarg);
3506 DEBUGLEVEL = atoi(optarg);
3515 torture_showall = True;
3518 fstrcpy(myname, optarg);
3521 client_txt = optarg;
3525 use_kerberos = True;
3528 d_printf("No kerberos support compiled in\n");
3533 pstrcpy(username,optarg);
3534 p = strchr_m(username,'%');
3537 pstrcpy(password, p+1);
3542 printf("Unknown option %c (%d)\n", (char)opt, opt);
3549 p = getpass("Password:");
3551 pstrcpy(password, p);
3556 printf("host=%s share=%s user=%s myname=%s\n",
3557 host, share, username, myname);
3560 correct = run_test("ALL");
3562 for (i=1;i<argc;i++) {
3563 if (!run_test(argv[i])) {