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";
29 int torture_numops=100;
30 static int procnum; /* records process count number when forking */
31 static struct cli_state current_cli;
32 static fstring randomfname;
33 static BOOL use_oplocks;
34 static BOOL use_level_II_oplocks;
35 static char *client_txt = "client_oplocks.txt";
36 static BOOL use_kerberos;
38 BOOL torture_showall = False;
40 static double create_procs(BOOL (*fn)(int), BOOL *result);
43 static struct timeval tp1,tp2;
45 void start_timer(void)
47 gettimeofday(&tp1,NULL);
50 double end_timer(void)
52 gettimeofday(&tp2,NULL);
53 return((tp2.tv_sec - tp1.tv_sec) +
54 (tp2.tv_usec - tp1.tv_usec)*1.0e-6);
58 /* return a pointer to a anonymous shared memory segment of size "size"
59 which will persist across fork() but will disappear when all processes
62 The memory is not zeroed
64 This function uses system5 shared memory. It takes advantage of a property
65 that the memory is not destroyed if it is attached when the id is removed
67 void *shm_setup(int size)
72 shmid = shmget(IPC_PRIVATE, size, SHM_R | SHM_W);
74 printf("can't get shared memory\n");
77 ret = (void *)shmat(shmid, 0, 0);
78 if (!ret || ret == (void *)-1) {
79 printf("can't attach to shared memory\n");
82 /* the following releases the ipc, but note that this process
83 and all its children will still have access to the memory, its
84 just that the shmid is no longer valid for other shm calls. This
85 means we don't leave behind lots of shm segments after we exit
87 See Stevens "advanced programming in unix env" for details
89 shmctl(shmid, IPC_RMID, 0);
95 static BOOL open_nbt_connection(struct cli_state *c)
97 struct nmb_name called, calling;
102 make_nmb_name(&calling, myname, 0x0);
103 make_nmb_name(&called , host, 0x20);
107 if (!cli_initialise(c) || !cli_connect(c, host, &ip)) {
108 printf("Failed to connect with %s\n", host);
112 c->use_kerberos = use_kerberos;
114 c->timeout = 120000; /* set a really long timeout (2 minutes) */
115 if (use_oplocks) c->use_oplocks = True;
116 if (use_level_II_oplocks) c->use_level_II_oplocks = True;
118 if (!cli_session_request(c, &calling, &called)) {
119 printf("%s rejected the session\n",host);
127 BOOL torture_open_connection(struct cli_state *c)
131 if (!open_nbt_connection(c)) {
135 if (!cli_negprot(c)) {
136 printf("%s rejected the negprot (%s)\n",host, cli_errstr(c));
141 if (!cli_session_setup(c, username,
142 password, strlen(password),
143 password, strlen(password),
145 printf("%s rejected the sessionsetup (%s)\n", host, cli_errstr(c));
150 if (!cli_send_tconX(c, share, "?????",
151 password, strlen(password)+1)) {
152 printf("%s refused tree connect (%s)\n", host, cli_errstr(c));
161 BOOL torture_close_connection(struct cli_state *c)
165 printf("tdis failed (%s)\n", cli_errstr(c));
175 /* check if the server produced the expected error code */
176 static BOOL check_error(int line, struct cli_state *c,
177 uint8 eclass, uint32 ecode, NTSTATUS nterr)
179 if (cli_is_dos_error(c)) {
183 /* Check DOS error */
185 cli_dos_error(c, &class, &num);
187 if (eclass != class || ecode != num) {
188 printf("unexpected error code class=%d code=%d\n",
189 (int)class, (int)num);
190 printf(" expected %d/%d %s (line=%d)\n",
191 (int)eclass, (int)ecode, nt_errstr(nterr), line);
200 status = cli_nt_error(c);
202 if (NT_STATUS_V(nterr) != NT_STATUS_V(status)) {
203 printf("unexpected error code %s\n", nt_errstr(status));
204 printf(" expected %s (line=%d)\n", nt_errstr(nterr), line);
213 static BOOL wait_lock(struct cli_state *c, int fnum, uint32 offset, uint32 len)
215 while (!cli_lock(c, fnum, offset, len, -1, WRITE_LOCK)) {
216 if (!check_error(__LINE__, c, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False;
222 static BOOL rw_torture(struct cli_state *c)
224 char *lockfname = "\\torture.lck";
228 pid_t pid2, pid = getpid();
233 fnum2 = cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
236 fnum2 = cli_open(c, lockfname, O_RDWR, DENY_NONE);
238 printf("open of %s failed (%s)\n", lockfname, cli_errstr(c));
243 for (i=0;i<torture_numops;i++) {
244 unsigned n = (unsigned)sys_random()%10;
246 printf("%d\r", i); fflush(stdout);
248 slprintf(fname, sizeof(fstring) - 1, "\\torture.%u", n);
250 if (!wait_lock(c, fnum2, n*sizeof(int), sizeof(int))) {
254 fnum = cli_open(c, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_ALL);
256 printf("open failed (%s)\n", cli_errstr(c));
261 if (cli_write(c, fnum, 0, (char *)&pid, 0, sizeof(pid)) != sizeof(pid)) {
262 printf("write failed (%s)\n", cli_errstr(c));
267 if (cli_write(c, fnum, 0, (char *)buf,
268 sizeof(pid)+(j*sizeof(buf)),
269 sizeof(buf)) != sizeof(buf)) {
270 printf("write failed (%s)\n", cli_errstr(c));
277 if (cli_read(c, fnum, (char *)&pid2, 0, sizeof(pid)) != sizeof(pid)) {
278 printf("read failed (%s)\n", cli_errstr(c));
283 printf("data corruption!\n");
287 if (!cli_close(c, fnum)) {
288 printf("close failed (%s)\n", cli_errstr(c));
292 if (!cli_unlink(c, fname)) {
293 printf("unlink failed (%s)\n", cli_errstr(c));
297 if (!cli_unlock(c, fnum2, n*sizeof(int), sizeof(int))) {
298 printf("unlock failed (%s)\n", cli_errstr(c));
304 cli_unlink(c, lockfname);
311 static BOOL run_torture(int dummy)
313 struct cli_state cli;
318 cli_sockopt(&cli, sockops);
320 ret = rw_torture(&cli);
322 if (!torture_close_connection(&cli)) {
329 static BOOL rw_torture3(struct cli_state *c, char *lockfname)
336 unsigned countprev = 0;
341 for (i = 0; i < sizeof(buf); i += sizeof(uint32))
343 SIVAL(buf, i, sys_random());
348 fnum = cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
351 printf("first open read/write of %s failed (%s)\n",
352 lockfname, cli_errstr(c));
358 for (i = 0; i < 500 && fnum == -1; i++)
360 fnum = cli_open(c, lockfname, O_RDONLY,
365 printf("second open read-only of %s failed (%s)\n",
366 lockfname, cli_errstr(c));
372 for (count = 0; count < sizeof(buf); count += sent)
374 if (count >= countprev) {
375 printf("%d %8d\r", i, count);
378 countprev += (sizeof(buf) / 20);
383 sent = ((unsigned)sys_random()%(20))+ 1;
384 if (sent > sizeof(buf) - count)
386 sent = sizeof(buf) - count;
389 if (cli_write(c, fnum, 0, buf+count, count, (size_t)sent) != sent) {
390 printf("write failed (%s)\n", cli_errstr(c));
396 sent = cli_read(c, fnum, buf_rd+count, count,
400 printf("read failed offset:%d size:%d (%s)\n",
401 count, sizeof(buf)-count,
408 if (memcmp(buf_rd+count, buf+count, sent) != 0)
410 printf("read/write compare failed\n");
411 printf("offset: %d req %d recvd %d\n",
412 count, sizeof(buf)-count, sent);
421 if (!cli_close(c, fnum)) {
422 printf("close failed (%s)\n", cli_errstr(c));
429 static BOOL rw_torture2(struct cli_state *c1, struct cli_state *c2)
431 char *lockfname = "\\torture2.lck";
436 uchar buf_rd[131072];
440 if (!cli_unlink(c1, lockfname)) {
441 printf("unlink failed (%s) (normal, this file should not exist)\n", cli_errstr(c1));
444 fnum1 = cli_open(c1, lockfname, O_RDWR | O_CREAT | O_EXCL,
447 printf("first open read/write of %s failed (%s)\n",
448 lockfname, cli_errstr(c1));
451 fnum2 = cli_open(c2, lockfname, O_RDONLY,
454 printf("second open read-only of %s failed (%s)\n",
455 lockfname, cli_errstr(c2));
456 cli_close(c1, fnum1);
460 for (i=0;i<torture_numops;i++)
462 size_t buf_size = ((unsigned)sys_random()%(sizeof(buf)-1))+ 1;
464 printf("%d\r", i); fflush(stdout);
467 generate_random_buffer(buf, buf_size, False);
469 if (cli_write(c1, fnum1, 0, buf, 0, buf_size) != buf_size) {
470 printf("write failed (%s)\n", cli_errstr(c1));
474 if ((bytes_read = cli_read(c2, fnum2, buf_rd, 0, buf_size)) != buf_size) {
475 printf("read failed (%s)\n", cli_errstr(c2));
476 printf("read %d, expected %d\n", bytes_read, buf_size);
480 if (memcmp(buf_rd, buf, buf_size) != 0)
482 printf("read/write compare failed\n");
487 if (!cli_close(c2, fnum2)) {
488 printf("close failed (%s)\n", cli_errstr(c2));
491 if (!cli_close(c1, fnum1)) {
492 printf("close failed (%s)\n", cli_errstr(c1));
496 if (!cli_unlink(c1, lockfname)) {
497 printf("unlink failed (%s)\n", cli_errstr(c1));
504 static BOOL run_readwritetest(int dummy)
506 static struct cli_state cli1, cli2;
509 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
512 cli_sockopt(&cli1, sockops);
513 cli_sockopt(&cli2, sockops);
515 printf("starting readwritetest\n");
517 test1 = rw_torture2(&cli1, &cli2);
518 printf("Passed readwritetest v1: %s\n", BOOLSTR(test1));
520 test2 = rw_torture2(&cli1, &cli1);
521 printf("Passed readwritetest v2: %s\n", BOOLSTR(test2));
523 if (!torture_close_connection(&cli1)) {
527 if (!torture_close_connection(&cli2)) {
531 return (test1 && test2);
534 static BOOL run_readwritemulti(int dummy)
536 static struct cli_state cli;
541 cli_sockopt(&cli, sockops);
543 printf("run_readwritemulti: fname %s\n", randomfname);
544 test = rw_torture3(&cli, randomfname);
546 if (!torture_close_connection(&cli)) {
553 static BOOL run_readwritelarge(int dummy)
555 static struct cli_state cli1;
557 char *lockfname = "\\large.dat";
562 if (!torture_open_connection(&cli1)) {
565 cli_sockopt(&cli1, sockops);
566 memset(buf,'\0',sizeof(buf));
568 cli1.max_xmit = 128*1024;
570 printf("starting readwritelarge\n");
572 cli_unlink(&cli1, lockfname);
574 fnum1 = cli_open(&cli1, lockfname, O_RDWR | O_CREAT | O_EXCL, DENY_NONE);
576 printf("open read/write of %s failed (%s)\n", lockfname, cli_errstr(&cli1));
580 cli_write(&cli1, fnum1, 0, buf, 0, sizeof(buf));
582 if (!cli_qfileinfo(&cli1, fnum1, NULL, &fsize, NULL, NULL, NULL, NULL, NULL)) {
583 printf("qfileinfo failed (%s)\n", cli_errstr(&cli1));
587 if (fsize == sizeof(buf))
588 printf("readwritelarge test 1 succeeded (size = %x)\n", fsize);
590 printf("readwritelarge test 1 failed (size = %x)\n", fsize);
594 if (!cli_close(&cli1, fnum1)) {
595 printf("close failed (%s)\n", cli_errstr(&cli1));
599 if (!cli_unlink(&cli1, lockfname)) {
600 printf("unlink failed (%s)\n", cli_errstr(&cli1));
604 fnum1 = cli_open(&cli1, lockfname, O_RDWR | O_CREAT | O_EXCL, DENY_NONE);
606 printf("open read/write of %s failed (%s)\n", lockfname, cli_errstr(&cli1));
610 cli1.max_xmit = 4*1024;
612 cli_smbwrite(&cli1, fnum1, buf, 0, sizeof(buf));
614 if (!cli_qfileinfo(&cli1, fnum1, NULL, &fsize, NULL, NULL, NULL, NULL, NULL)) {
615 printf("qfileinfo failed (%s)\n", cli_errstr(&cli1));
619 if (fsize == sizeof(buf))
620 printf("readwritelarge test 2 succeeded (size = %x)\n", fsize);
622 printf("readwritelarge test 2 failed (size = %x)\n", fsize);
627 /* ToDo - set allocation. JRA */
628 if(!cli_set_allocation_size(&cli1, fnum1, 0)) {
629 printf("set allocation size to zero failed (%s)\n", cli_errstr(&cli1));
632 if (!cli_qfileinfo(&cli1, fnum1, NULL, &fsize, NULL, NULL, NULL, NULL, NULL)) {
633 printf("qfileinfo failed (%s)\n", cli_errstr(&cli1));
637 printf("readwritelarge test 3 (truncate test) succeeded (size = %x)\n", fsize);
640 if (!cli_close(&cli1, fnum1)) {
641 printf("close failed (%s)\n", cli_errstr(&cli1));
645 if (!torture_close_connection(&cli1)) {
654 #define ival(s) strtol(s, NULL, 0)
656 /* run a test that simulates an approximate netbench client load */
657 static BOOL run_netbench(int client)
659 struct cli_state cli;
672 cli_sockopt(&cli, sockops);
676 slprintf(cname,sizeof(fname), "client%d", client);
678 f = fopen(client_txt, "r");
685 while (fgets(line, sizeof(line)-1, f)) {
688 line[strlen(line)-1] = 0;
690 /* printf("[%d] %s\n", line_count, line); */
692 all_string_sub(line,"client1", cname, sizeof(line));
694 /* parse the command parameters */
695 params[0] = strtok(line," ");
697 while (params[i]) params[++i] = strtok(NULL," ");
703 if (!strncmp(params[0],"SMB", 3)) {
704 printf("ERROR: You are using a dbench 1 load file\n");
708 if (!strcmp(params[0],"NTCreateX")) {
709 nb_createx(params[1], ival(params[2]), ival(params[3]),
711 } else if (!strcmp(params[0],"Close")) {
712 nb_close(ival(params[1]));
713 } else if (!strcmp(params[0],"Rename")) {
714 nb_rename(params[1], params[2]);
715 } else if (!strcmp(params[0],"Unlink")) {
716 nb_unlink(params[1]);
717 } else if (!strcmp(params[0],"Deltree")) {
718 nb_deltree(params[1]);
719 } else if (!strcmp(params[0],"Rmdir")) {
721 } else if (!strcmp(params[0],"QUERY_PATH_INFORMATION")) {
722 nb_qpathinfo(params[1]);
723 } else if (!strcmp(params[0],"QUERY_FILE_INFORMATION")) {
724 nb_qfileinfo(ival(params[1]));
725 } else if (!strcmp(params[0],"QUERY_FS_INFORMATION")) {
726 nb_qfsinfo(ival(params[1]));
727 } else if (!strcmp(params[0],"FIND_FIRST")) {
728 nb_findfirst(params[1]);
729 } else if (!strcmp(params[0],"WriteX")) {
730 nb_writex(ival(params[1]),
731 ival(params[2]), ival(params[3]), ival(params[4]));
732 } else if (!strcmp(params[0],"ReadX")) {
733 nb_readx(ival(params[1]),
734 ival(params[2]), ival(params[3]), ival(params[4]));
735 } else if (!strcmp(params[0],"Flush")) {
736 nb_flush(ival(params[1]));
738 printf("Unknown operation %s\n", params[0]);
746 if (!torture_close_connection(&cli)) {
754 /* run a test that simulates an approximate netbench client load */
755 static BOOL run_nbench(int dummy)
764 signal(SIGALRM, nb_alarm);
766 t = create_procs(run_netbench, &correct);
769 printf("\nThroughput %g MB/sec\n",
770 1.0e-6 * nbio_total() / t);
776 This test checks for two things:
778 1) correct support for retaining locks over a close (ie. the server
779 must not use posix semantics)
780 2) support for lock timeouts
782 static BOOL run_locktest1(int dummy)
784 static struct cli_state cli1, cli2;
785 char *fname = "\\lockt1.lck";
786 int fnum1, fnum2, fnum3;
789 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
792 cli_sockopt(&cli1, sockops);
793 cli_sockopt(&cli2, sockops);
795 printf("starting locktest1\n");
797 cli_unlink(&cli1, fname);
799 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
801 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
804 fnum2 = cli_open(&cli1, fname, O_RDWR, DENY_NONE);
806 printf("open2 of %s failed (%s)\n", fname, cli_errstr(&cli1));
809 fnum3 = cli_open(&cli2, fname, O_RDWR, DENY_NONE);
811 printf("open3 of %s failed (%s)\n", fname, cli_errstr(&cli2));
815 if (!cli_lock(&cli1, fnum1, 0, 4, 0, WRITE_LOCK)) {
816 printf("lock1 failed (%s)\n", cli_errstr(&cli1));
821 if (cli_lock(&cli2, fnum3, 0, 4, 0, WRITE_LOCK)) {
822 printf("lock2 succeeded! This is a locking bug\n");
825 if (!check_error(__LINE__, &cli2, ERRDOS, ERRlock,
826 NT_STATUS_LOCK_NOT_GRANTED)) return False;
830 printf("Testing lock timeouts\n");
832 if (cli_lock(&cli2, fnum3, 0, 4, 10*1000, WRITE_LOCK)) {
833 printf("lock3 succeeded! This is a locking bug\n");
836 if (!check_error(__LINE__, &cli2, ERRDOS, ERRlock,
837 NT_STATUS_FILE_LOCK_CONFLICT)) return False;
842 printf("error: This server appears not to support timed lock requests\n");
845 if (!cli_close(&cli1, fnum2)) {
846 printf("close1 failed (%s)\n", cli_errstr(&cli1));
850 if (cli_lock(&cli2, fnum3, 0, 4, 0, WRITE_LOCK)) {
851 printf("lock4 succeeded! This is a locking bug\n");
854 if (!check_error(__LINE__, &cli2, ERRDOS, ERRlock,
855 NT_STATUS_FILE_LOCK_CONFLICT)) return False;
858 if (!cli_close(&cli1, fnum1)) {
859 printf("close2 failed (%s)\n", cli_errstr(&cli1));
863 if (!cli_close(&cli2, fnum3)) {
864 printf("close3 failed (%s)\n", cli_errstr(&cli2));
868 if (!cli_unlink(&cli1, fname)) {
869 printf("unlink failed (%s)\n", cli_errstr(&cli1));
874 if (!torture_close_connection(&cli1)) {
878 if (!torture_close_connection(&cli2)) {
882 printf("Passed locktest1\n");
887 checks for correct tconX support
889 static BOOL run_tcon_test(int dummy)
891 static struct cli_state cli1;
892 char *fname = "\\tcontest.tmp";
897 if (!torture_open_connection(&cli1)) {
900 cli_sockopt(&cli1, sockops);
902 printf("starting tcontest\n");
904 cli_unlink(&cli1, fname);
906 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
909 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
915 if (cli_write(&cli1, fnum1, 0, buf, 130, 4) != 4)
917 printf("write failed (%s)", cli_errstr(&cli1));
921 if (!cli_send_tconX(&cli1, share, "?????",
922 password, strlen(password)+1)) {
923 printf("%s refused 2nd tree connect (%s)\n", host,
929 if (cli_write(&cli1, fnum1, 0, buf, 130, 4) == 4)
931 printf("write succeeded (%s)", cli_errstr(&cli1));
935 if (cli_close(&cli1, fnum1)) {
936 printf("close2 succeeded (%s)\n", cli_errstr(&cli1));
940 if (!cli_tdis(&cli1)) {
941 printf("tdis failed (%s)\n", cli_errstr(&cli1));
947 if (!cli_close(&cli1, fnum1)) {
948 printf("close2 failed (%s)\n", cli_errstr(&cli1));
952 if (!torture_close_connection(&cli1)) {
956 printf("Passed tcontest\n");
962 This test checks that
964 1) the server supports multiple locking contexts on the one SMB
965 connection, distinguished by PID.
967 2) the server correctly fails overlapping locks made by the same PID (this
968 goes against POSIX behaviour, which is why it is tricky to implement)
970 3) the server denies unlock requests by an incorrect client PID
972 static BOOL run_locktest2(int dummy)
974 static struct cli_state cli;
975 char *fname = "\\lockt2.lck";
976 int fnum1, fnum2, fnum3;
979 if (!torture_open_connection(&cli)) {
983 cli_sockopt(&cli, sockops);
985 printf("starting locktest2\n");
987 cli_unlink(&cli, fname);
991 fnum1 = cli_open(&cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
993 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli));
997 fnum2 = cli_open(&cli, fname, O_RDWR, DENY_NONE);
999 printf("open2 of %s failed (%s)\n", fname, cli_errstr(&cli));
1003 cli_setpid(&cli, 2);
1005 fnum3 = cli_open(&cli, fname, O_RDWR, DENY_NONE);
1007 printf("open3 of %s failed (%s)\n", fname, cli_errstr(&cli));
1011 cli_setpid(&cli, 1);
1013 if (!cli_lock(&cli, fnum1, 0, 4, 0, WRITE_LOCK)) {
1014 printf("lock1 failed (%s)\n", cli_errstr(&cli));
1018 if (cli_lock(&cli, fnum1, 0, 4, 0, WRITE_LOCK)) {
1019 printf("WRITE lock1 succeeded! This is a locking bug\n");
1022 if (!check_error(__LINE__, &cli, ERRDOS, ERRlock,
1023 NT_STATUS_LOCK_NOT_GRANTED)) return False;
1026 if (cli_lock(&cli, fnum2, 0, 4, 0, WRITE_LOCK)) {
1027 printf("WRITE lock2 succeeded! This is a locking bug\n");
1030 if (!check_error(__LINE__, &cli, ERRDOS, ERRlock,
1031 NT_STATUS_LOCK_NOT_GRANTED)) return False;
1034 if (cli_lock(&cli, fnum2, 0, 4, 0, READ_LOCK)) {
1035 printf("READ lock2 succeeded! This is a locking bug\n");
1038 if (!check_error(__LINE__, &cli, ERRDOS, ERRlock,
1039 NT_STATUS_FILE_LOCK_CONFLICT)) return False;
1042 if (!cli_lock(&cli, fnum1, 100, 4, 0, WRITE_LOCK)) {
1043 printf("lock at 100 failed (%s)\n", cli_errstr(&cli));
1045 cli_setpid(&cli, 2);
1046 if (cli_unlock(&cli, fnum1, 100, 4)) {
1047 printf("unlock at 100 succeeded! This is a locking bug\n");
1051 if (cli_unlock(&cli, fnum1, 0, 4)) {
1052 printf("unlock1 succeeded! This is a locking bug\n");
1055 if (!check_error(__LINE__, &cli,
1057 NT_STATUS_RANGE_NOT_LOCKED)) return False;
1060 if (cli_unlock(&cli, fnum1, 0, 8)) {
1061 printf("unlock2 succeeded! This is a locking bug\n");
1064 if (!check_error(__LINE__, &cli,
1066 NT_STATUS_RANGE_NOT_LOCKED)) return False;
1069 if (cli_lock(&cli, fnum3, 0, 4, 0, WRITE_LOCK)) {
1070 printf("lock3 succeeded! This is a locking bug\n");
1073 if (!check_error(__LINE__, &cli, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False;
1076 cli_setpid(&cli, 1);
1078 if (!cli_close(&cli, fnum1)) {
1079 printf("close1 failed (%s)\n", cli_errstr(&cli));
1083 if (!cli_close(&cli, fnum2)) {
1084 printf("close2 failed (%s)\n", cli_errstr(&cli));
1088 if (!cli_close(&cli, fnum3)) {
1089 printf("close3 failed (%s)\n", cli_errstr(&cli));
1093 if (!torture_close_connection(&cli)) {
1097 printf("locktest2 finished\n");
1104 This test checks that
1106 1) the server supports the full offset range in lock requests
1108 static BOOL run_locktest3(int dummy)
1110 static struct cli_state cli1, cli2;
1111 char *fname = "\\lockt3.lck";
1112 int fnum1, fnum2, i;
1114 BOOL correct = True;
1116 #define NEXT_OFFSET offset += (~(uint32)0) / torture_numops
1118 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
1121 cli_sockopt(&cli1, sockops);
1122 cli_sockopt(&cli2, sockops);
1124 printf("starting locktest3\n");
1126 cli_unlink(&cli1, fname);
1128 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1130 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
1133 fnum2 = cli_open(&cli2, fname, O_RDWR, DENY_NONE);
1135 printf("open2 of %s failed (%s)\n", fname, cli_errstr(&cli2));
1139 for (offset=i=0;i<torture_numops;i++) {
1141 if (!cli_lock(&cli1, fnum1, offset-1, 1, 0, WRITE_LOCK)) {
1142 printf("lock1 %d failed (%s)\n",
1148 if (!cli_lock(&cli2, fnum2, offset-2, 1, 0, WRITE_LOCK)) {
1149 printf("lock2 %d failed (%s)\n",
1156 for (offset=i=0;i<torture_numops;i++) {
1159 if (cli_lock(&cli1, fnum1, offset-2, 1, 0, WRITE_LOCK)) {
1160 printf("error: lock1 %d succeeded!\n", i);
1164 if (cli_lock(&cli2, fnum2, offset-1, 1, 0, WRITE_LOCK)) {
1165 printf("error: lock2 %d succeeded!\n", i);
1169 if (cli_lock(&cli1, fnum1, offset-1, 1, 0, WRITE_LOCK)) {
1170 printf("error: lock3 %d succeeded!\n", i);
1174 if (cli_lock(&cli2, fnum2, offset-2, 1, 0, WRITE_LOCK)) {
1175 printf("error: lock4 %d succeeded!\n", i);
1180 for (offset=i=0;i<torture_numops;i++) {
1183 if (!cli_unlock(&cli1, fnum1, offset-1, 1)) {
1184 printf("unlock1 %d failed (%s)\n",
1190 if (!cli_unlock(&cli2, fnum2, offset-2, 1)) {
1191 printf("unlock2 %d failed (%s)\n",
1198 if (!cli_close(&cli1, fnum1)) {
1199 printf("close1 failed (%s)\n", cli_errstr(&cli1));
1203 if (!cli_close(&cli2, fnum2)) {
1204 printf("close2 failed (%s)\n", cli_errstr(&cli2));
1208 if (!cli_unlink(&cli1, fname)) {
1209 printf("unlink failed (%s)\n", cli_errstr(&cli1));
1213 if (!torture_close_connection(&cli1)) {
1217 if (!torture_close_connection(&cli2)) {
1221 printf("finished locktest3\n");
1226 #define EXPECTED(ret, v) if ((ret) != (v)) { \
1227 printf("** "); correct = False; \
1231 looks at overlapping locks
1233 static BOOL run_locktest4(int dummy)
1235 static struct cli_state cli1, cli2;
1236 char *fname = "\\lockt4.lck";
1237 int fnum1, fnum2, f;
1240 BOOL correct = True;
1242 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
1246 cli_sockopt(&cli1, sockops);
1247 cli_sockopt(&cli2, sockops);
1249 printf("starting locktest4\n");
1251 cli_unlink(&cli1, fname);
1253 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1254 fnum2 = cli_open(&cli2, fname, O_RDWR, DENY_NONE);
1256 memset(buf, 0, sizeof(buf));
1258 if (cli_write(&cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
1259 printf("Failed to create file\n");
1264 ret = cli_lock(&cli1, fnum1, 0, 4, 0, WRITE_LOCK) &&
1265 cli_lock(&cli1, fnum1, 2, 4, 0, WRITE_LOCK);
1266 EXPECTED(ret, False);
1267 printf("the same process %s set overlapping write locks\n", ret?"can":"cannot");
1269 ret = cli_lock(&cli1, fnum1, 10, 4, 0, READ_LOCK) &&
1270 cli_lock(&cli1, fnum1, 12, 4, 0, READ_LOCK);
1271 EXPECTED(ret, True);
1272 printf("the same process %s set overlapping read locks\n", ret?"can":"cannot");
1274 ret = cli_lock(&cli1, fnum1, 20, 4, 0, WRITE_LOCK) &&
1275 cli_lock(&cli2, fnum2, 22, 4, 0, WRITE_LOCK);
1276 EXPECTED(ret, False);
1277 printf("a different connection %s set overlapping write locks\n", ret?"can":"cannot");
1279 ret = cli_lock(&cli1, fnum1, 30, 4, 0, READ_LOCK) &&
1280 cli_lock(&cli2, fnum2, 32, 4, 0, READ_LOCK);
1281 EXPECTED(ret, True);
1282 printf("a different connection %s set overlapping read locks\n", ret?"can":"cannot");
1284 ret = (cli_setpid(&cli1, 1), cli_lock(&cli1, fnum1, 40, 4, 0, WRITE_LOCK)) &&
1285 (cli_setpid(&cli1, 2), cli_lock(&cli1, fnum1, 42, 4, 0, WRITE_LOCK));
1286 EXPECTED(ret, False);
1287 printf("a different pid %s set overlapping write locks\n", ret?"can":"cannot");
1289 ret = (cli_setpid(&cli1, 1), cli_lock(&cli1, fnum1, 50, 4, 0, READ_LOCK)) &&
1290 (cli_setpid(&cli1, 2), cli_lock(&cli1, fnum1, 52, 4, 0, READ_LOCK));
1291 EXPECTED(ret, True);
1292 printf("a different pid %s set overlapping read locks\n", ret?"can":"cannot");
1294 ret = cli_lock(&cli1, fnum1, 60, 4, 0, READ_LOCK) &&
1295 cli_lock(&cli1, fnum1, 60, 4, 0, READ_LOCK);
1296 EXPECTED(ret, True);
1297 printf("the same process %s set the same read lock twice\n", ret?"can":"cannot");
1299 ret = cli_lock(&cli1, fnum1, 70, 4, 0, WRITE_LOCK) &&
1300 cli_lock(&cli1, fnum1, 70, 4, 0, WRITE_LOCK);
1301 EXPECTED(ret, False);
1302 printf("the same process %s set the same write lock twice\n", ret?"can":"cannot");
1304 ret = cli_lock(&cli1, fnum1, 80, 4, 0, READ_LOCK) &&
1305 cli_lock(&cli1, fnum1, 80, 4, 0, WRITE_LOCK);
1306 EXPECTED(ret, False);
1307 printf("the same process %s overlay a read lock with a write lock\n", ret?"can":"cannot");
1309 ret = cli_lock(&cli1, fnum1, 90, 4, 0, WRITE_LOCK) &&
1310 cli_lock(&cli1, fnum1, 90, 4, 0, READ_LOCK);
1311 EXPECTED(ret, True);
1312 printf("the same process %s overlay a write lock with a read lock\n", ret?"can":"cannot");
1314 ret = (cli_setpid(&cli1, 1), cli_lock(&cli1, fnum1, 100, 4, 0, WRITE_LOCK)) &&
1315 (cli_setpid(&cli1, 2), cli_lock(&cli1, fnum1, 100, 4, 0, READ_LOCK));
1316 EXPECTED(ret, False);
1317 printf("a different pid %s overlay a write lock with a read lock\n", ret?"can":"cannot");
1319 ret = cli_lock(&cli1, fnum1, 110, 4, 0, READ_LOCK) &&
1320 cli_lock(&cli1, fnum1, 112, 4, 0, READ_LOCK) &&
1321 cli_unlock(&cli1, fnum1, 110, 6);
1322 EXPECTED(ret, False);
1323 printf("the same process %s coalesce read locks\n", ret?"can":"cannot");
1326 ret = cli_lock(&cli1, fnum1, 120, 4, 0, WRITE_LOCK) &&
1327 (cli_read(&cli2, fnum2, buf, 120, 4) == 4);
1328 EXPECTED(ret, False);
1329 printf("this server %s strict write locking\n", ret?"doesn't do":"does");
1331 ret = cli_lock(&cli1, fnum1, 130, 4, 0, READ_LOCK) &&
1332 (cli_write(&cli2, fnum2, 0, buf, 130, 4) == 4);
1333 EXPECTED(ret, False);
1334 printf("this server %s strict read locking\n", ret?"doesn't do":"does");
1337 ret = cli_lock(&cli1, fnum1, 140, 4, 0, READ_LOCK) &&
1338 cli_lock(&cli1, fnum1, 140, 4, 0, READ_LOCK) &&
1339 cli_unlock(&cli1, fnum1, 140, 4) &&
1340 cli_unlock(&cli1, fnum1, 140, 4);
1341 EXPECTED(ret, True);
1342 printf("this server %s do recursive read locking\n", ret?"does":"doesn't");
1345 ret = cli_lock(&cli1, fnum1, 150, 4, 0, WRITE_LOCK) &&
1346 cli_lock(&cli1, fnum1, 150, 4, 0, READ_LOCK) &&
1347 cli_unlock(&cli1, fnum1, 150, 4) &&
1348 (cli_read(&cli2, fnum2, buf, 150, 4) == 4) &&
1349 !(cli_write(&cli2, fnum2, 0, buf, 150, 4) == 4) &&
1350 cli_unlock(&cli1, fnum1, 150, 4);
1351 EXPECTED(ret, True);
1352 printf("this server %s do recursive lock overlays\n", ret?"does":"doesn't");
1354 ret = cli_lock(&cli1, fnum1, 160, 4, 0, READ_LOCK) &&
1355 cli_unlock(&cli1, fnum1, 160, 4) &&
1356 (cli_write(&cli2, fnum2, 0, buf, 160, 4) == 4) &&
1357 (cli_read(&cli2, fnum2, buf, 160, 4) == 4);
1358 EXPECTED(ret, True);
1359 printf("the same process %s remove a read lock using write locking\n", ret?"can":"cannot");
1361 ret = cli_lock(&cli1, fnum1, 170, 4, 0, WRITE_LOCK) &&
1362 cli_unlock(&cli1, fnum1, 170, 4) &&
1363 (cli_write(&cli2, fnum2, 0, buf, 170, 4) == 4) &&
1364 (cli_read(&cli2, fnum2, buf, 170, 4) == 4);
1365 EXPECTED(ret, True);
1366 printf("the same process %s remove a write lock using read locking\n", ret?"can":"cannot");
1368 ret = cli_lock(&cli1, fnum1, 190, 4, 0, WRITE_LOCK) &&
1369 cli_lock(&cli1, fnum1, 190, 4, 0, READ_LOCK) &&
1370 cli_unlock(&cli1, fnum1, 190, 4) &&
1371 !(cli_write(&cli2, fnum2, 0, buf, 190, 4) == 4) &&
1372 (cli_read(&cli2, fnum2, buf, 190, 4) == 4);
1373 EXPECTED(ret, True);
1374 printf("the same process %s remove the first lock first\n", ret?"does":"doesn't");
1376 cli_close(&cli1, fnum1);
1377 cli_close(&cli2, fnum2);
1378 fnum1 = cli_open(&cli1, fname, O_RDWR, DENY_NONE);
1379 f = cli_open(&cli1, fname, O_RDWR, DENY_NONE);
1380 ret = cli_lock(&cli1, fnum1, 0, 8, 0, READ_LOCK) &&
1381 cli_lock(&cli1, f, 0, 1, 0, READ_LOCK) &&
1382 cli_close(&cli1, fnum1) &&
1383 ((fnum1 = cli_open(&cli1, fname, O_RDWR, DENY_NONE)) != -1) &&
1384 cli_lock(&cli1, fnum1, 7, 1, 0, WRITE_LOCK);
1385 cli_close(&cli1, f);
1386 cli_close(&cli1, fnum1);
1387 EXPECTED(ret, True);
1388 printf("the server %s have the NT byte range lock bug\n", !ret?"does":"doesn't");
1391 cli_close(&cli1, fnum1);
1392 cli_close(&cli2, fnum2);
1393 cli_unlink(&cli1, fname);
1394 torture_close_connection(&cli1);
1395 torture_close_connection(&cli2);
1397 printf("finished locktest4\n");
1402 looks at lock upgrade/downgrade.
1404 static BOOL run_locktest5(int dummy)
1406 static struct cli_state cli1, cli2;
1407 char *fname = "\\lockt5.lck";
1408 int fnum1, fnum2, fnum3;
1411 BOOL correct = True;
1413 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
1417 cli_sockopt(&cli1, sockops);
1418 cli_sockopt(&cli2, sockops);
1420 printf("starting locktest5\n");
1422 cli_unlink(&cli1, fname);
1424 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1425 fnum2 = cli_open(&cli2, fname, O_RDWR, DENY_NONE);
1426 fnum3 = cli_open(&cli1, fname, O_RDWR, DENY_NONE);
1428 memset(buf, 0, sizeof(buf));
1430 if (cli_write(&cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
1431 printf("Failed to create file\n");
1436 /* Check for NT bug... */
1437 ret = cli_lock(&cli1, fnum1, 0, 8, 0, READ_LOCK) &&
1438 cli_lock(&cli1, fnum3, 0, 1, 0, READ_LOCK);
1439 cli_close(&cli1, fnum1);
1440 fnum1 = cli_open(&cli1, fname, O_RDWR, DENY_NONE);
1441 ret = cli_lock(&cli1, fnum1, 7, 1, 0, WRITE_LOCK);
1442 EXPECTED(ret, True);
1443 printf("this server %s the NT locking bug\n", ret ? "doesn't have" : "has");
1444 cli_close(&cli1, fnum1);
1445 fnum1 = cli_open(&cli1, fname, O_RDWR, DENY_NONE);
1446 cli_unlock(&cli1, fnum3, 0, 1);
1448 ret = cli_lock(&cli1, fnum1, 0, 4, 0, WRITE_LOCK) &&
1449 cli_lock(&cli1, fnum1, 1, 1, 0, READ_LOCK);
1450 EXPECTED(ret, True);
1451 printf("the same process %s overlay a write with a read lock\n", ret?"can":"cannot");
1453 ret = cli_lock(&cli2, fnum2, 0, 4, 0, READ_LOCK);
1454 EXPECTED(ret, False);
1456 printf("a different processs %s get a read lock on the first process lock stack\n", ret?"can":"cannot");
1458 /* Unlock the process 2 lock. */
1459 cli_unlock(&cli2, fnum2, 0, 4);
1461 ret = cli_lock(&cli1, fnum3, 0, 4, 0, READ_LOCK);
1462 EXPECTED(ret, False);
1464 printf("the same processs on a different fnum %s get a read lock\n", ret?"can":"cannot");
1466 /* Unlock the process 1 fnum3 lock. */
1467 cli_unlock(&cli1, fnum3, 0, 4);
1469 /* Stack 2 more locks here. */
1470 ret = cli_lock(&cli1, fnum1, 0, 4, 0, READ_LOCK) &&
1471 cli_lock(&cli1, fnum1, 0, 4, 0, READ_LOCK);
1473 EXPECTED(ret, True);
1474 printf("the same process %s stack read locks\n", ret?"can":"cannot");
1476 /* Unlock the first process lock, then check this was the WRITE lock that was
1479 ret = cli_unlock(&cli1, fnum1, 0, 4) &&
1480 cli_lock(&cli2, fnum2, 0, 4, 0, READ_LOCK);
1482 EXPECTED(ret, True);
1483 printf("the first unlock removes the %s lock\n", ret?"WRITE":"READ");
1485 /* Unlock the process 2 lock. */
1486 cli_unlock(&cli2, fnum2, 0, 4);
1488 /* We should have 3 stacked locks here. Ensure we need to do 3 unlocks. */
1490 ret = cli_unlock(&cli1, fnum1, 1, 1) &&
1491 cli_unlock(&cli1, fnum1, 0, 4) &&
1492 cli_unlock(&cli1, fnum1, 0, 4);
1494 EXPECTED(ret, True);
1495 printf("the same process %s unlock the stack of 4 locks\n", ret?"can":"cannot");
1497 /* Ensure the next unlock fails. */
1498 ret = cli_unlock(&cli1, fnum1, 0, 4);
1499 EXPECTED(ret, False);
1500 printf("the same process %s count the lock stack\n", !ret?"can":"cannot");
1502 /* Ensure connection 2 can get a write lock. */
1503 ret = cli_lock(&cli2, fnum2, 0, 4, 0, WRITE_LOCK);
1504 EXPECTED(ret, True);
1506 printf("a different processs %s get a write lock on the unlocked stack\n", ret?"can":"cannot");
1510 cli_close(&cli1, fnum1);
1511 cli_close(&cli2, fnum2);
1512 cli_unlink(&cli1, fname);
1513 if (!torture_close_connection(&cli1)) {
1516 if (!torture_close_connection(&cli2)) {
1520 printf("finished locktest5\n");
1526 tries the unusual lockingX locktype bits
1528 static BOOL run_locktest6(int dummy)
1530 static struct cli_state cli;
1531 char *fname[1] = { "\\lock6.txt" };
1536 if (!torture_open_connection(&cli)) {
1540 cli_sockopt(&cli, sockops);
1542 printf("starting locktest6\n");
1545 printf("Testing %s\n", fname[i]);
1547 cli_unlink(&cli, fname[i]);
1549 fnum = cli_open(&cli, fname[i], O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1550 status = cli_locktype(&cli, fnum, 0, 8, 0, LOCKING_ANDX_CHANGE_LOCKTYPE);
1551 cli_close(&cli, fnum);
1552 printf("CHANGE_LOCKTYPE gave %s\n", nt_errstr(status));
1554 fnum = cli_open(&cli, fname[i], O_RDWR, DENY_NONE);
1555 status = cli_locktype(&cli, fnum, 0, 8, 0, LOCKING_ANDX_CANCEL_LOCK);
1556 cli_close(&cli, fnum);
1557 printf("CANCEL_LOCK gave %s\n", nt_errstr(status));
1559 cli_unlink(&cli, fname[i]);
1562 torture_close_connection(&cli);
1564 printf("finished locktest6\n");
1569 test whether fnums and tids open on one VC are available on another (a major
1572 static BOOL run_fdpasstest(int dummy)
1574 static struct cli_state cli1, cli2, cli3;
1575 char *fname = "\\fdpass.tst";
1579 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
1582 cli_sockopt(&cli1, sockops);
1583 cli_sockopt(&cli2, sockops);
1585 printf("starting fdpasstest\n");
1587 cli_unlink(&cli1, fname);
1589 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1591 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
1595 if (cli_write(&cli1, fnum1, 0, "hello world\n", 0, 13) != 13) {
1596 printf("write failed (%s)\n", cli_errstr(&cli1));
1601 cli3.vuid = cli1.vuid;
1602 cli3.cnum = cli1.cnum;
1603 cli3.pid = cli1.pid;
1605 if (cli_read(&cli3, fnum1, buf, 0, 13) == 13) {
1606 printf("read succeeded! nasty security hole [%s]\n",
1611 cli_close(&cli1, fnum1);
1612 cli_unlink(&cli1, fname);
1614 torture_close_connection(&cli1);
1615 torture_close_connection(&cli2);
1617 printf("finished fdpasstest\n");
1623 This test checks that
1625 1) the server does not allow an unlink on a file that is open
1627 static BOOL run_unlinktest(int dummy)
1629 static struct cli_state cli;
1630 char *fname = "\\unlink.tst";
1632 BOOL correct = True;
1634 if (!torture_open_connection(&cli)) {
1638 cli_sockopt(&cli, sockops);
1640 printf("starting unlink test\n");
1642 cli_unlink(&cli, fname);
1644 cli_setpid(&cli, 1);
1646 fnum = cli_open(&cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1648 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli));
1652 if (cli_unlink(&cli, fname)) {
1653 printf("error: server allowed unlink on an open file\n");
1656 correct = check_error(__LINE__, &cli, ERRDOS, ERRbadshare,
1657 NT_STATUS_SHARING_VIOLATION);
1660 cli_close(&cli, fnum);
1661 cli_unlink(&cli, fname);
1663 if (!torture_close_connection(&cli)) {
1667 printf("unlink test finished\n");
1674 test how many open files this server supports on the one socket
1676 static BOOL run_maxfidtest(int dummy)
1678 static struct cli_state cli;
1679 char *template = "\\maxfid.%d.%d";
1681 int fnums[0x11000], i;
1683 BOOL correct = True;
1688 printf("failed to connect\n");
1692 cli_sockopt(&cli, sockops);
1694 for (i=0; i<0x11000; i++) {
1695 slprintf(fname,sizeof(fname)-1,template, i,(int)getpid());
1696 if ((fnums[i] = cli_open(&cli, fname,
1697 O_RDWR|O_CREAT|O_TRUNC, DENY_NONE)) ==
1699 printf("open of %s failed (%s)\n",
1700 fname, cli_errstr(&cli));
1701 printf("maximum fnum is %d\n", i);
1709 printf("cleaning up\n");
1711 slprintf(fname,sizeof(fname)-1,template, i,(int)getpid());
1712 cli_close(&cli, fnums[i]);
1713 if (!cli_unlink(&cli, fname)) {
1714 printf("unlink of %s failed (%s)\n",
1715 fname, cli_errstr(&cli));
1722 printf("maxfid test finished\n");
1723 if (!torture_close_connection(&cli)) {
1729 /* generate a random buffer */
1730 static void rand_buf(char *buf, int len)
1733 *buf = (char)sys_random();
1738 /* send smb negprot commands, not reading the response */
1739 static BOOL run_negprot_nowait(int dummy)
1742 static struct cli_state cli;
1743 BOOL correct = True;
1745 printf("starting negprot nowait test\n");
1747 if (!open_nbt_connection(&cli)) {
1751 for (i=0;i<50000;i++) {
1752 cli_negprot_send(&cli);
1755 if (!torture_close_connection(&cli)) {
1759 printf("finished negprot nowait test\n");
1765 /* send random IPC commands */
1766 static BOOL run_randomipc(int dummy)
1768 char *rparam = NULL;
1772 int api, param_len, i;
1773 static struct cli_state cli;
1774 BOOL correct = True;
1777 printf("starting random ipc test\n");
1779 if (!torture_open_connection(&cli)) {
1783 for (i=0;i<count;i++) {
1784 api = sys_random() % 500;
1785 param_len = (sys_random() % 64);
1787 rand_buf(param, param_len);
1792 param, param_len, 8,
1793 NULL, 0, BUFFER_SIZE,
1797 printf("%d/%d\r", i,count);
1800 printf("%d/%d\n", i, count);
1802 if (!torture_close_connection(&cli)) {
1806 printf("finished random ipc test\n");
1813 static void browse_callback(const char *sname, uint32 stype,
1814 const char *comment, void *state)
1816 printf("\t%20.20s %08x %s\n", sname, stype, comment);
1822 This test checks the browse list code
1825 static BOOL run_browsetest(int dummy)
1827 static struct cli_state cli;
1828 BOOL correct = True;
1830 printf("starting browse test\n");
1832 if (!torture_open_connection(&cli)) {
1836 printf("domain list:\n");
1837 cli_NetServerEnum(&cli, cli.server_domain,
1838 SV_TYPE_DOMAIN_ENUM,
1839 browse_callback, NULL);
1841 printf("machine list:\n");
1842 cli_NetServerEnum(&cli, cli.server_domain,
1844 browse_callback, NULL);
1846 if (!torture_close_connection(&cli)) {
1850 printf("browse test finished\n");
1858 This checks how the getatr calls works
1860 static BOOL run_attrtest(int dummy)
1862 static struct cli_state cli;
1865 char *fname = "\\attrib.tst";
1866 BOOL correct = True;
1868 printf("starting attrib test\n");
1870 if (!torture_open_connection(&cli)) {
1874 cli_unlink(&cli, fname);
1875 fnum = cli_open(&cli, fname,
1876 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1877 cli_close(&cli, fnum);
1878 if (!cli_getatr(&cli, fname, NULL, NULL, &t)) {
1879 printf("getatr failed (%s)\n", cli_errstr(&cli));
1883 if (abs(t - time(NULL)) > 60*60*24*10) {
1884 printf("ERROR: SMBgetatr bug. time is %s",
1890 t2 = t-60*60*24; /* 1 day ago */
1892 if (!cli_setatr(&cli, fname, 0, t2)) {
1893 printf("setatr failed (%s)\n", cli_errstr(&cli));
1897 if (!cli_getatr(&cli, fname, NULL, NULL, &t)) {
1898 printf("getatr failed (%s)\n", cli_errstr(&cli));
1903 printf("ERROR: getatr/setatr bug. times are\n%s",
1905 printf("%s", ctime(&t2));
1909 cli_unlink(&cli, fname);
1911 if (!torture_close_connection(&cli)) {
1915 printf("attrib test finished\n");
1922 This checks a couple of trans2 calls
1924 static BOOL run_trans2test(int dummy)
1926 static struct cli_state cli;
1929 time_t c_time, a_time, m_time, w_time, m_time2;
1930 char *fname = "\\trans2.tst";
1931 char *dname = "\\trans2";
1932 char *fname2 = "\\trans2\\trans2.tst";
1934 BOOL correct = True;
1936 printf("starting trans2 test\n");
1938 if (!torture_open_connection(&cli)) {
1942 cli_unlink(&cli, fname);
1943 fnum = cli_open(&cli, fname,
1944 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1945 if (!cli_qfileinfo(&cli, fnum, NULL, &size, &c_time, &a_time, &m_time,
1947 printf("ERROR: qfileinfo failed (%s)\n", cli_errstr(&cli));
1951 if (!cli_qfilename(&cli, fnum, pname)) {
1952 printf("ERROR: qfilename failed (%s)\n", cli_errstr(&cli));
1956 if (strcmp(pname, fname)) {
1957 printf("qfilename gave different name? [%s] [%s]\n",
1962 cli_close(&cli, fnum);
1966 cli_unlink(&cli, fname);
1967 fnum = cli_open(&cli, fname,
1968 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1970 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli));
1973 cli_close(&cli, fnum);
1975 if (!cli_qpathinfo(&cli, fname, &c_time, &a_time, &m_time, &size, NULL)) {
1976 printf("ERROR: qpathinfo failed (%s)\n", cli_errstr(&cli));
1979 if (c_time != m_time) {
1980 printf("create time=%s", ctime(&c_time));
1981 printf("modify time=%s", ctime(&m_time));
1982 printf("This system appears to have sticky create times\n");
1985 if (a_time % (60*60) == 0) {
1986 printf("access time=%s", ctime(&a_time));
1987 printf("This system appears to set a midnight access time\n");
1991 if (abs(m_time - time(NULL)) > 60*60*24*7) {
1992 printf("ERROR: totally incorrect times - maybe word reversed? mtime=%s", ctime(&m_time));
1998 cli_unlink(&cli, fname);
1999 fnum = cli_open(&cli, fname,
2000 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2001 cli_close(&cli, fnum);
2002 if (!cli_qpathinfo2(&cli, fname, &c_time, &a_time, &m_time,
2003 &w_time, &size, NULL, NULL)) {
2004 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli));
2007 if (w_time < 60*60*24*2) {
2008 printf("write time=%s", ctime(&w_time));
2009 printf("This system appears to set a initial 0 write time\n");
2014 cli_unlink(&cli, fname);
2017 /* check if the server updates the directory modification time
2018 when creating a new file */
2019 if (!cli_mkdir(&cli, dname)) {
2020 printf("ERROR: mkdir failed (%s)\n", cli_errstr(&cli));
2024 if (!cli_qpathinfo2(&cli, "\\trans2\\", &c_time, &a_time, &m_time,
2025 &w_time, &size, NULL, NULL)) {
2026 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli));
2030 fnum = cli_open(&cli, fname2,
2031 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2032 cli_write(&cli, fnum, 0, (char *)&fnum, 0, sizeof(fnum));
2033 cli_close(&cli, fnum);
2034 if (!cli_qpathinfo2(&cli, "\\trans2\\", &c_time, &a_time, &m_time2,
2035 &w_time, &size, NULL, NULL)) {
2036 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli));
2039 if (m_time2 == m_time) {
2040 printf("This system does not update directory modification times\n");
2044 cli_unlink(&cli, fname2);
2045 cli_rmdir(&cli, dname);
2047 if (!torture_close_connection(&cli)) {
2051 printf("trans2 test finished\n");
2057 This checks new W2K calls.
2060 static BOOL new_trans(struct cli_state *pcli, int fnum, int level)
2063 BOOL correct = True;
2065 memset(buf, 0xff, sizeof(buf));
2067 if (!cli_qfileinfo_test(pcli, fnum, level, buf)) {
2068 printf("ERROR: qfileinfo (%d) failed (%s)\n", level, cli_errstr(pcli));
2071 printf("qfileinfo: level %d\n", level);
2072 dump_data(0, buf, 256);
2078 static BOOL run_w2ktest(int dummy)
2080 static struct cli_state cli;
2082 char *fname = "\\w2ktest\\w2k.tst";
2084 BOOL correct = True;
2086 printf("starting w2k test\n");
2088 if (!torture_open_connection(&cli)) {
2092 fnum = cli_open(&cli, fname,
2093 O_RDWR | O_CREAT , DENY_NONE);
2095 for (level = 1004; level < 1040; level++) {
2096 new_trans(&cli, fnum, level);
2099 cli_close(&cli, fnum);
2101 if (!torture_close_connection(&cli)) {
2105 printf("w2k test finished\n");
2112 this is a harness for some oplock tests
2114 static BOOL run_oplock1(int dummy)
2116 static struct cli_state cli1;
2117 char *fname = "\\lockt1.lck";
2119 BOOL correct = True;
2121 printf("starting oplock test 1\n");
2123 if (!torture_open_connection(&cli1)) {
2127 cli_unlink(&cli1, fname);
2129 cli_sockopt(&cli1, sockops);
2131 cli1.use_oplocks = True;
2133 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2135 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2139 cli1.use_oplocks = False;
2141 cli_unlink(&cli1, fname);
2142 cli_unlink(&cli1, fname);
2144 if (!cli_close(&cli1, fnum1)) {
2145 printf("close2 failed (%s)\n", cli_errstr(&cli1));
2149 if (!cli_unlink(&cli1, fname)) {
2150 printf("unlink failed (%s)\n", cli_errstr(&cli1));
2154 if (!torture_close_connection(&cli1)) {
2158 printf("finished oplock test 1\n");
2163 static BOOL run_oplock2(int dummy)
2165 static struct cli_state cli1, cli2;
2166 char *fname = "\\lockt2.lck";
2168 int saved_use_oplocks = use_oplocks;
2170 BOOL correct = True;
2171 volatile BOOL *shared_correct;
2173 shared_correct = (volatile BOOL *)shm_setup(sizeof(BOOL));
2174 *shared_correct = True;
2176 use_level_II_oplocks = True;
2179 printf("starting oplock test 2\n");
2181 if (!torture_open_connection(&cli1)) {
2182 use_level_II_oplocks = False;
2183 use_oplocks = saved_use_oplocks;
2187 cli1.use_oplocks = True;
2188 cli1.use_level_II_oplocks = True;
2190 if (!torture_open_connection(&cli2)) {
2191 use_level_II_oplocks = False;
2192 use_oplocks = saved_use_oplocks;
2196 cli2.use_oplocks = True;
2197 cli2.use_level_II_oplocks = True;
2199 cli_unlink(&cli1, fname);
2201 cli_sockopt(&cli1, sockops);
2202 cli_sockopt(&cli2, sockops);
2204 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2206 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2210 /* Don't need the globals any more. */
2211 use_level_II_oplocks = False;
2212 use_oplocks = saved_use_oplocks;
2216 fnum2 = cli_open(&cli2, fname, O_RDWR, DENY_NONE);
2218 printf("second open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2219 *shared_correct = False;
2225 if (!cli_close(&cli2, fnum2)) {
2226 printf("close2 failed (%s)\n", cli_errstr(&cli1));
2227 *shared_correct = False;
2235 /* Ensure cli1 processes the break. */
2237 if (cli_read(&cli1, fnum1, buf, 0, 4) != 4) {
2238 printf("read on fnum1 failed (%s)\n", cli_errstr(&cli1));
2242 /* Should now be at level II. */
2243 /* Test if sending a write locks causes a break to none. */
2245 if (!cli_lock(&cli1, fnum1, 0, 4, 0, READ_LOCK)) {
2246 printf("lock failed (%s)\n", cli_errstr(&cli1));
2250 cli_unlock(&cli1, fnum1, 0, 4);
2254 if (!cli_lock(&cli1, fnum1, 0, 4, 0, WRITE_LOCK)) {
2255 printf("lock failed (%s)\n", cli_errstr(&cli1));
2259 cli_unlock(&cli1, fnum1, 0, 4);
2263 cli_read(&cli1, fnum1, buf, 0, 4);
2266 if (cli_write(&cli1, fnum1, 0, buf, 0, 4) != 4) {
2267 printf("write on fnum1 failed (%s)\n", cli_errstr(&cli1));
2272 if (!cli_close(&cli1, fnum1)) {
2273 printf("close1 failed (%s)\n", cli_errstr(&cli1));
2279 if (!cli_unlink(&cli1, fname)) {
2280 printf("unlink failed (%s)\n", cli_errstr(&cli1));
2284 if (!torture_close_connection(&cli1)) {
2288 if (!*shared_correct) {
2292 printf("finished oplock test 2\n");
2297 /* handler for oplock 3 tests */
2298 static BOOL oplock3_handler(struct cli_state *cli, int fnum, unsigned char level)
2300 printf("got oplock break fnum=%d level=%d\n",
2302 return cli_oplock_ack(cli, fnum, level);
2305 static BOOL run_oplock3(int dummy)
2307 static struct cli_state cli;
2308 char *fname = "\\oplockt3.dat";
2310 char buf[4] = "abcd";
2311 BOOL correct = True;
2312 volatile BOOL *shared_correct;
2314 shared_correct = (volatile BOOL *)shm_setup(sizeof(BOOL));
2315 *shared_correct = True;
2317 printf("starting oplock test 3\n");
2322 use_level_II_oplocks = True;
2323 if (!torture_open_connection(&cli)) {
2324 *shared_correct = False;
2328 /* try to trigger a oplock break in parent */
2329 fnum = cli_open(&cli, fname, O_RDWR, DENY_NONE);
2330 cli_write(&cli, fnum, 0, buf, 0, 4);
2336 use_level_II_oplocks = True;
2337 if (!torture_open_connection(&cli)) {
2340 cli_oplock_handler(&cli, oplock3_handler);
2341 fnum = cli_open(&cli, fname, O_RDWR|O_CREAT, DENY_NONE);
2342 cli_write(&cli, fnum, 0, buf, 0, 4);
2343 cli_close(&cli, fnum);
2344 fnum = cli_open(&cli, fname, O_RDWR, DENY_NONE);
2345 cli.timeout = 20000;
2346 cli_receive_smb(&cli);
2347 printf("finished oplock test 3\n");
2349 return (correct && *shared_correct);
2351 /* What are we looking for here? What's sucess and what's FAILURE? */
2357 Test delete on close semantics.
2359 static BOOL run_deletetest(int dummy)
2361 static struct cli_state cli1;
2362 static struct cli_state cli2;
2363 char *fname = "\\delete.file";
2366 BOOL correct = True;
2368 printf("starting delete test\n");
2373 if (!torture_open_connection(&cli1)) {
2377 cli_sockopt(&cli1, sockops);
2379 /* Test 1 - this should *NOT* delete the file on close. */
2381 cli_setatr(&cli1, fname, 0, 0);
2382 cli_unlink(&cli1, fname);
2384 fnum1 = cli_nt_create_full(&cli1, fname, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL,
2385 FILE_SHARE_DELETE, FILE_OVERWRITE_IF,
2386 DELETE_ON_CLOSE_FLAG);
2389 printf("[1] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2394 if (!cli_close(&cli1, fnum1)) {
2395 printf("[1] close failed (%s)\n", cli_errstr(&cli1));
2400 fnum1 = cli_open(&cli1, fname, O_RDWR, DENY_NONE);
2402 printf("[1] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2407 if (!cli_close(&cli1, fnum1)) {
2408 printf("[1] close failed (%s)\n", cli_errstr(&cli1));
2413 printf("first delete on close test succeeded.\n");
2415 /* Test 2 - this should delete the file on close. */
2417 cli_setatr(&cli1, fname, 0, 0);
2418 cli_unlink(&cli1, fname);
2420 fnum1 = cli_nt_create_full(&cli1, fname, GENERIC_ALL_ACCESS,
2421 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
2422 FILE_OVERWRITE_IF, 0);
2425 printf("[2] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2430 if (!cli_nt_delete_on_close(&cli1, fnum1, True)) {
2431 printf("[2] setting delete_on_close failed (%s)\n", cli_errstr(&cli1));
2436 if (!cli_close(&cli1, fnum1)) {
2437 printf("[2] close failed (%s)\n", cli_errstr(&cli1));
2442 fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_NONE);
2444 printf("[2] open of %s succeeded should have been deleted on close !\n", fname);
2445 if (!cli_close(&cli1, fnum1)) {
2446 printf("[2] close failed (%s)\n", cli_errstr(&cli1));
2450 cli_unlink(&cli1, fname);
2452 printf("second delete on close test succeeded.\n");
2455 cli_setatr(&cli1, fname, 0, 0);
2456 cli_unlink(&cli1, fname);
2458 fnum1 = cli_nt_create_full(&cli1, fname, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL,
2459 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0);
2462 printf("[3] open - 1 of %s failed (%s)\n", fname, cli_errstr(&cli1));
2467 /* This should fail with a sharing violation - open for delete is only compatible
2468 with SHARE_DELETE. */
2470 fnum2 = cli_nt_create_full(&cli1, fname, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
2471 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0);
2474 printf("[3] open - 2 of %s succeeded - should have failed.\n", fname);
2479 /* This should succeed. */
2481 fnum2 = cli_nt_create_full(&cli1, fname, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
2482 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0);
2485 printf("[3] open - 2 of %s failed (%s)\n", fname, cli_errstr(&cli1));
2490 if (!cli_nt_delete_on_close(&cli1, fnum1, True)) {
2491 printf("[3] setting delete_on_close failed (%s)\n", cli_errstr(&cli1));
2496 if (!cli_close(&cli1, fnum1)) {
2497 printf("[3] close 1 failed (%s)\n", cli_errstr(&cli1));
2502 if (!cli_close(&cli1, fnum2)) {
2503 printf("[3] close 2 failed (%s)\n", cli_errstr(&cli1));
2508 /* This should fail - file should no longer be there. */
2510 fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_NONE);
2512 printf("[3] open of %s succeeded should have been deleted on close !\n", fname);
2513 if (!cli_close(&cli1, fnum1)) {
2514 printf("[3] close failed (%s)\n", cli_errstr(&cli1));
2516 cli_unlink(&cli1, fname);
2520 printf("third delete on close test succeeded.\n");
2523 cli_setatr(&cli1, fname, 0, 0);
2524 cli_unlink(&cli1, fname);
2526 fnum1 = cli_nt_create_full(&cli1, fname, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
2527 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0);
2530 printf("[4] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2535 /* This should succeed. */
2536 fnum2 = cli_nt_create_full(&cli1, fname, GENERIC_READ_ACCESS,
2537 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0);
2539 printf("[4] open - 2 of %s failed (%s)\n", fname, cli_errstr(&cli1));
2544 if (!cli_close(&cli1, fnum2)) {
2545 printf("[4] close - 1 failed (%s)\n", cli_errstr(&cli1));
2550 if (!cli_nt_delete_on_close(&cli1, fnum1, True)) {
2551 printf("[4] setting delete_on_close failed (%s)\n", cli_errstr(&cli1));
2556 /* This should fail - no more opens once delete on close set. */
2557 fnum2 = cli_nt_create_full(&cli1, fname, GENERIC_READ_ACCESS,
2558 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0);
2560 printf("[4] open - 3 of %s succeeded ! Should have failed.\n", fname );
2564 printf("fourth delete on close test succeeded.\n");
2566 if (!cli_close(&cli1, fnum1)) {
2567 printf("[4] close - 2 failed (%s)\n", cli_errstr(&cli1));
2573 cli_setatr(&cli1, fname, 0, 0);
2574 cli_unlink(&cli1, fname);
2576 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT, DENY_NONE);
2578 printf("[5] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2583 /* This should fail - only allowed on NT opens with DELETE access. */
2585 if (cli_nt_delete_on_close(&cli1, fnum1, True)) {
2586 printf("[5] setting delete_on_close on OpenX file succeeded - should fail !\n");
2591 if (!cli_close(&cli1, fnum1)) {
2592 printf("[5] close - 2 failed (%s)\n", cli_errstr(&cli1));
2597 printf("fifth delete on close test succeeded.\n");
2600 cli_setatr(&cli1, fname, 0, 0);
2601 cli_unlink(&cli1, fname);
2603 fnum1 = cli_nt_create_full(&cli1, fname, FILE_READ_DATA|FILE_WRITE_DATA,
2604 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
2605 FILE_OVERWRITE_IF, 0);
2608 printf("[6] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2613 /* This should fail - only allowed on NT opens with DELETE access. */
2615 if (cli_nt_delete_on_close(&cli1, fnum1, True)) {
2616 printf("[6] setting delete_on_close on file with no delete access succeeded - should fail !\n");
2621 if (!cli_close(&cli1, fnum1)) {
2622 printf("[6] close - 2 failed (%s)\n", cli_errstr(&cli1));
2627 printf("sixth delete on close test succeeded.\n");
2630 cli_setatr(&cli1, fname, 0, 0);
2631 cli_unlink(&cli1, fname);
2633 fnum1 = cli_nt_create_full(&cli1, fname, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
2634 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF, 0);
2637 printf("[7] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2642 if (!cli_nt_delete_on_close(&cli1, fnum1, True)) {
2643 printf("[7] setting delete_on_close on file failed !\n");
2648 if (!cli_nt_delete_on_close(&cli1, fnum1, False)) {
2649 printf("[7] unsetting delete_on_close on file failed !\n");
2654 if (!cli_close(&cli1, fnum1)) {
2655 printf("[7] close - 2 failed (%s)\n", cli_errstr(&cli1));
2660 /* This next open should succeed - we reset the flag. */
2662 fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_NONE);
2664 printf("[5] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2669 if (!cli_close(&cli1, fnum1)) {
2670 printf("[7] close - 2 failed (%s)\n", cli_errstr(&cli1));
2675 printf("seventh delete on close test succeeded.\n");
2678 cli_setatr(&cli1, fname, 0, 0);
2679 cli_unlink(&cli1, fname);
2681 if (!torture_open_connection(&cli2)) {
2682 printf("[8] failed to open second connection.\n");
2687 cli_sockopt(&cli1, sockops);
2689 fnum1 = cli_nt_create_full(&cli1, fname, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
2690 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0);
2693 printf("[8] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2698 fnum2 = cli_nt_create_full(&cli2, fname, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
2699 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0);
2702 printf("[8] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2707 if (!cli_nt_delete_on_close(&cli1, fnum1, True)) {
2708 printf("[8] setting delete_on_close on file failed !\n");
2713 if (!cli_close(&cli1, fnum1)) {
2714 printf("[8] close - 1 failed (%s)\n", cli_errstr(&cli1));
2719 if (!cli_close(&cli2, fnum2)) {
2720 printf("[8] close - 2 failed (%s)\n", cli_errstr(&cli2));
2725 /* This should fail.. */
2726 fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_NONE);
2728 printf("[8] open of %s succeeded should have been deleted on close !\n", fname);
2732 printf("eighth delete on close test succeeded.\n");
2734 /* This should fail - we need to set DELETE_ACCESS. */
2735 fnum1 = cli_nt_create_full(&cli1, fname, FILE_READ_DATA|FILE_WRITE_DATA,
2736 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, FILE_OVERWRITE_IF, FILE_DELETE_ON_CLOSE);
2739 printf("[9] open of %s succeeded should have failed!\n", fname);
2744 printf("ninth delete on close test succeeded.\n");
2746 fnum1 = cli_nt_create_full(&cli1, fname, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
2747 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, FILE_OVERWRITE_IF, FILE_DELETE_ON_CLOSE);
2749 printf("[10] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2754 /* This should delete the file. */
2755 if (!cli_close(&cli1, fnum1)) {
2756 printf("[10] close failed (%s)\n", cli_errstr(&cli1));
2761 /* This should fail.. */
2762 fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_NONE);
2764 printf("[10] open of %s succeeded should have been deleted on close !\n", fname);
2768 printf("tenth delete on close test succeeded.\n");
2769 printf("finished delete test\n");
2773 cli_close(&cli1, fnum1);
2774 cli_close(&cli1, fnum2);
2775 cli_setatr(&cli1, fname, 0, 0);
2776 cli_unlink(&cli1, fname);
2778 if (!torture_close_connection(&cli1)) {
2781 if (!torture_close_connection(&cli2)) {
2789 print out server properties
2791 static BOOL run_properties(int dummy)
2793 static struct cli_state cli;
2794 BOOL correct = True;
2796 printf("starting properties test\n");
2800 if (!torture_open_connection(&cli)) {
2804 cli_sockopt(&cli, sockops);
2806 d_printf("Capabilities 0x%08x\n", cli.capabilities);
2808 if (!torture_close_connection(&cli)) {
2817 /* FIRST_DESIRED_ACCESS 0xf019f */
2818 #define FIRST_DESIRED_ACCESS FILE_READ_DATA|FILE_WRITE_DATA|FILE_APPEND_DATA|\
2819 FILE_READ_EA| /* 0xf */ \
2820 FILE_WRITE_EA|FILE_READ_ATTRIBUTES| /* 0x90 */ \
2821 FILE_WRITE_ATTRIBUTES| /* 0x100 */ \
2822 DELETE_ACCESS|READ_CONTROL_ACCESS|\
2823 WRITE_DAC_ACCESS|WRITE_OWNER_ACCESS /* 0xf0000 */
2824 /* SECOND_DESIRED_ACCESS 0xe0080 */
2825 #define SECOND_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
2826 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
2827 WRITE_OWNER_ACCESS /* 0xe0000 */
2830 #define THIRD_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
2831 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
2833 WRITE_OWNER_ACCESS /* */
2837 Test ntcreate calls made by xcopy
2839 static BOOL run_xcopy(int dummy)
2841 static struct cli_state cli1;
2842 char *fname = "\\test.txt";
2843 BOOL correct = True;
2846 printf("starting xcopy test\n");
2848 if (!torture_open_connection(&cli1)) {
2852 fnum1 = cli_nt_create_full(&cli1, fname,
2853 FIRST_DESIRED_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
2854 FILE_SHARE_NONE, FILE_OVERWRITE_IF,
2858 printf("First open failed - %s\n", cli_errstr(&cli1));
2862 fnum2 = cli_nt_create_full(&cli1, fname,
2863 SECOND_DESIRED_ACCESS, 0,
2864 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN,
2867 printf("second open failed - %s\n", cli_errstr(&cli1));
2871 if (!torture_close_connection(&cli1)) {
2879 Test rename on files open with share delete and no share delete.
2881 static BOOL run_rename(int dummy)
2883 static struct cli_state cli1;
2884 char *fname = "\\test.txt";
2885 char *fname1 = "\\test1.txt";
2886 BOOL correct = True;
2889 printf("starting rename test\n");
2891 if (!torture_open_connection(&cli1)) {
2895 cli_unlink(&cli1, fname);
2896 cli_unlink(&cli1, fname1);
2897 fnum1 = cli_nt_create_full(&cli1, fname, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
2898 FILE_SHARE_READ, FILE_OVERWRITE_IF, 0);
2901 printf("First open failed - %s\n", cli_errstr(&cli1));
2905 if (!cli_rename(&cli1, fname, fname1)) {
2906 printf("First rename failed (this is correct) - %s\n", cli_errstr(&cli1));
2908 printf("First rename succeeded - this should have failed !\n");
2912 if (!cli_close(&cli1, fnum1)) {
2913 printf("close - 1 failed (%s)\n", cli_errstr(&cli1));
2917 cli_unlink(&cli1, fname);
2918 cli_unlink(&cli1, fname1);
2919 fnum1 = cli_nt_create_full(&cli1, fname,GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
2921 FILE_SHARE_DELETE|FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0);
2923 FILE_SHARE_DELETE|FILE_SHARE_READ, FILE_OVERWRITE_IF, 0);
2927 printf("Second open failed - %s\n", cli_errstr(&cli1));
2931 if (!cli_rename(&cli1, fname, fname1)) {
2932 printf("Second rename failed - this should have succeeded - %s\n", cli_errstr(&cli1));
2935 printf("Second rename succeeded\n");
2938 if (!cli_close(&cli1, fnum1)) {
2939 printf("close - 2 failed (%s)\n", cli_errstr(&cli1));
2943 cli_unlink(&cli1, fname);
2944 cli_unlink(&cli1, fname1);
2946 fnum1 = cli_nt_create_full(&cli1, fname,READ_CONTROL_ACCESS, FILE_ATTRIBUTE_NORMAL,
2947 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0);
2950 printf("Third open failed - %s\n", cli_errstr(&cli1));
2959 fnum2 = cli_nt_create_full(&cli1, fname,DELETE_ACCESS, FILE_ATTRIBUTE_NORMAL,
2960 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0);
2963 printf("Fourth open failed - %s\n", cli_errstr(&cli1));
2966 if (!cli_nt_delete_on_close(&cli1, fnum2, True)) {
2967 printf("[8] setting delete_on_close on file failed !\n");
2971 if (!cli_close(&cli1, fnum2)) {
2972 printf("close - 4 failed (%s)\n", cli_errstr(&cli1));
2978 if (!cli_rename(&cli1, fname, fname1)) {
2979 printf("Third rename failed - this should have succeeded - %s\n", cli_errstr(&cli1));
2982 printf("Third rename succeeded\n");
2985 if (!cli_close(&cli1, fnum1)) {
2986 printf("close - 3 failed (%s)\n", cli_errstr(&cli1));
2990 cli_unlink(&cli1, fname);
2991 cli_unlink(&cli1, fname1);
2993 if (!torture_close_connection(&cli1)) {
3000 static BOOL run_pipe_number(int dummy)
3002 static struct cli_state cli1;
3003 char *pipe_name = "\\SPOOLSS";
3007 printf("starting pipenumber test\n");
3008 if (!torture_open_connection(&cli1)) {
3012 cli_sockopt(&cli1, sockops);
3014 fnum = cli_nt_create_full(&cli1, pipe_name,FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
3015 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN_IF, 0);
3018 printf("Open of pipe %s failed with error (%s)\n", pipe_name, cli_errstr(&cli1));
3024 printf("pipe_number test - we can open %d %s pipes.\n", num_pipes, pipe_name );
3025 torture_close_connection(&cli1);
3030 Test open mode returns on read-only files.
3032 static BOOL run_opentest(int dummy)
3034 static struct cli_state cli1;
3035 static struct cli_state cli2;
3036 char *fname = "\\readonly.file";
3040 BOOL correct = True;
3043 printf("starting open test\n");
3045 if (!torture_open_connection(&cli1)) {
3049 cli_setatr(&cli1, fname, 0, 0);
3050 cli_unlink(&cli1, fname);
3052 cli_sockopt(&cli1, sockops);
3054 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
3056 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
3060 if (!cli_close(&cli1, fnum1)) {
3061 printf("close2 failed (%s)\n", cli_errstr(&cli1));
3065 if (!cli_setatr(&cli1, fname, aRONLY, 0)) {
3066 printf("cli_setatr failed (%s)\n", cli_errstr(&cli1));
3070 fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_WRITE);
3072 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
3076 /* This will fail - but the error should be ERRnoaccess, not ERRbadshare. */
3077 fnum2 = cli_open(&cli1, fname, O_RDWR, DENY_ALL);
3079 if (check_error(__LINE__, &cli1, ERRDOS, ERRnoaccess,
3080 NT_STATUS_ACCESS_DENIED)) {
3081 printf("correct error code ERRDOS/ERRnoaccess returned\n");
3084 printf("finished open test 1\n");
3086 cli_close(&cli1, fnum1);
3088 /* Now try not readonly and ensure ERRbadshare is returned. */
3090 cli_setatr(&cli1, fname, 0, 0);
3092 fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_WRITE);
3094 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
3098 /* This will fail - but the error should be ERRshare. */
3099 fnum2 = cli_open(&cli1, fname, O_RDWR, DENY_ALL);
3101 if (check_error(__LINE__, &cli1, ERRDOS, ERRbadshare,
3102 NT_STATUS_SHARING_VIOLATION)) {
3103 printf("correct error code ERRDOS/ERRbadshare returned\n");
3106 if (!cli_close(&cli1, fnum1)) {
3107 printf("close2 failed (%s)\n", cli_errstr(&cli1));
3111 cli_unlink(&cli1, fname);
3113 printf("finished open test 2\n");
3115 /* Test truncate open disposition on file opened for read. */
3117 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
3119 printf("(3) open (1) of %s failed (%s)\n", fname, cli_errstr(&cli1));
3123 /* write 20 bytes. */
3125 memset(buf, '\0', 20);
3127 if (cli_write(&cli1, fnum1, 0, buf, 0, 20) != 20) {
3128 printf("write failed (%s)\n", cli_errstr(&cli1));
3132 if (!cli_close(&cli1, fnum1)) {
3133 printf("(3) close1 failed (%s)\n", cli_errstr(&cli1));
3137 /* Ensure size == 20. */
3138 if (!cli_getatr(&cli1, fname, NULL, &fsize, NULL)) {
3139 printf("(3) getatr failed (%s)\n", cli_errstr(&cli1));
3144 printf("(3) file size != 20\n");
3148 /* Now test if we can truncate a file opened for readonly. */
3150 fnum1 = cli_open(&cli1, fname, O_RDONLY|O_TRUNC, DENY_NONE);
3152 printf("(3) open (2) of %s failed (%s)\n", fname, cli_errstr(&cli1));
3156 if (!cli_close(&cli1, fnum1)) {
3157 printf("close2 failed (%s)\n", cli_errstr(&cli1));
3161 /* Ensure size == 0. */
3162 if (!cli_getatr(&cli1, fname, NULL, &fsize, NULL)) {
3163 printf("(3) getatr failed (%s)\n", cli_errstr(&cli1));
3168 printf("(3) file size != 0\n");
3171 printf("finished open test 3\n");
3173 cli_unlink(&cli1, fname);
3176 printf("testing ctemp\n");
3177 fnum1 = cli_ctemp(&cli1, "\\", &tmp_path);
3179 printf("ctemp failed (%s)\n", cli_errstr(&cli1));
3182 printf("ctemp gave path %s\n", tmp_path);
3183 if (!cli_close(&cli1, fnum1)) {
3184 printf("close of temp failed (%s)\n", cli_errstr(&cli1));
3186 if (!cli_unlink(&cli1, tmp_path)) {
3187 printf("unlink of temp failed (%s)\n", cli_errstr(&cli1));
3190 /* Test the non-io opens... */
3192 if (!torture_open_connection(&cli2)) {
3196 cli_setatr(&cli2, fname, 0, 0);
3197 cli_unlink(&cli2, fname);
3199 cli_sockopt(&cli2, sockops);
3201 printf("TEST #1 testing 2 non-io opens (no delete)\n");
3203 fnum1 = cli_nt_create_full(&cli1, fname,FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3204 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0);
3207 printf("test 1 open 1 of %s failed (%s)\n", fname, cli_errstr(&cli1));
3211 fnum2 = cli_nt_create_full(&cli2, fname,FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3212 FILE_SHARE_NONE, FILE_OPEN_IF, 0);
3215 printf("test 1 open 2 of %s failed (%s)\n", fname, cli_errstr(&cli2));
3219 if (!cli_close(&cli1, fnum1)) {
3220 printf("test 1 close 1 of %s failed (%s)\n", fname, cli_errstr(&cli1));
3223 if (!cli_close(&cli2, fnum2)) {
3224 printf("test 1 close 2 of %s failed (%s)\n", fname, cli_errstr(&cli2));
3228 printf("non-io open test #1 passed.\n");
3230 cli_unlink(&cli1, fname);
3232 printf("TEST #2 testing 2 non-io opens (first with delete)\n");
3234 fnum1 = cli_nt_create_full(&cli1, fname,DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3235 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0);
3238 printf("test 2 open 1 of %s failed (%s)\n", fname, cli_errstr(&cli1));
3242 fnum2 = cli_nt_create_full(&cli2, fname,FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3243 FILE_SHARE_NONE, FILE_OPEN_IF, 0);
3246 printf("test 2 open 2 of %s failed (%s)\n", fname, cli_errstr(&cli2));
3250 if (!cli_close(&cli1, fnum1)) {
3251 printf("test 1 close 1 of %s failed (%s)\n", fname, cli_errstr(&cli1));
3254 if (!cli_close(&cli2, fnum2)) {
3255 printf("test 1 close 2 of %s failed (%s)\n", fname, cli_errstr(&cli1));
3259 printf("non-io open test #2 passed.\n");
3261 cli_unlink(&cli1, fname);
3263 printf("TEST #3 testing 2 non-io opens (second with delete)\n");
3265 fnum1 = cli_nt_create_full(&cli1, fname,FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3266 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0);
3269 printf("test 3 open 1 of %s failed (%s)\n", fname, cli_errstr(&cli1));
3273 fnum2 = cli_nt_create_full(&cli2, fname,DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3274 FILE_SHARE_NONE, FILE_OPEN_IF, 0);
3277 printf("test 3 open 2 of %s failed (%s)\n", fname, cli_errstr(&cli2));
3281 if (!cli_close(&cli1, fnum1)) {
3282 printf("test 3 close 1 of %s failed (%s)\n", fname, cli_errstr(&cli1));
3285 if (!cli_close(&cli2, fnum2)) {
3286 printf("test 3 close 2 of %s failed (%s)\n", fname, cli_errstr(&cli2));
3290 printf("non-io open test #3 passed.\n");
3292 cli_unlink(&cli1, fname);
3294 printf("TEST #4 testing 2 non-io opens (both with delete)\n");
3296 fnum1 = cli_nt_create_full(&cli1, fname,DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3297 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0);
3300 printf("test 4 open 1 of %s failed (%s)\n", fname, cli_errstr(&cli1));
3304 fnum2 = cli_nt_create_full(&cli2, fname,DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3305 FILE_SHARE_NONE, FILE_OPEN_IF, 0);
3308 printf("test 4 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, cli_errstr(&cli2));
3312 printf("test 3 open 2 of %s gave %s (correct error should be %s)\n", fname, cli_errstr(&cli2), "sharing violation");
3314 if (!cli_close(&cli1, fnum1)) {
3315 printf("test 4 close 1 of %s failed (%s)\n", fname, cli_errstr(&cli1));
3319 printf("non-io open test #4 passed.\n");
3321 cli_unlink(&cli1, fname);
3323 printf("TEST #5 testing 2 non-io opens (both with delete - both with file share delete)\n");
3325 fnum1 = cli_nt_create_full(&cli1, fname,DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3326 FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0);
3329 printf("test 5 open 1 of %s failed (%s)\n", fname, cli_errstr(&cli1));
3333 fnum2 = cli_nt_create_full(&cli2, fname,DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3334 FILE_SHARE_DELETE, FILE_OPEN_IF, 0);
3337 printf("test 5 open 2 of %s failed (%s)\n", fname, cli_errstr(&cli2));
3341 if (!cli_close(&cli1, fnum1)) {
3342 printf("test 5 close 1 of %s failed (%s)\n", fname, cli_errstr(&cli1));
3346 if (!cli_close(&cli2, fnum2)) {
3347 printf("test 5 close 2 of %s failed (%s)\n", fname, cli_errstr(&cli2));
3351 printf("non-io open test #5 passed.\n");
3353 printf("TEST #6 testing 1 non-io open, one io open\n");
3355 cli_unlink(&cli1, fname);
3357 fnum1 = cli_nt_create_full(&cli1, fname,FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
3358 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0);
3361 printf("test 6 open 1 of %s failed (%s)\n", fname, cli_errstr(&cli1));
3365 fnum2 = cli_nt_create_full(&cli2, fname,FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3366 FILE_SHARE_READ, FILE_OPEN_IF, 0);
3369 printf("test 6 open 2 of %s failed (%s)\n", fname, cli_errstr(&cli2));
3373 if (!cli_close(&cli1, fnum1)) {
3374 printf("test 6 close 1 of %s failed (%s)\n", fname, cli_errstr(&cli1));
3378 if (!cli_close(&cli2, fnum2)) {
3379 printf("test 6 close 2 of %s failed (%s)\n", fname, cli_errstr(&cli2));
3383 printf("non-io open test #6 passed.\n");
3385 printf("TEST #7 testing 1 non-io open, one io open with delete\n");
3387 cli_unlink(&cli1, fname);
3389 fnum1 = cli_nt_create_full(&cli1, fname,FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
3390 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0);
3393 printf("test 7 open 1 of %s failed (%s)\n", fname, cli_errstr(&cli1));
3397 fnum2 = cli_nt_create_full(&cli2, fname,DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3398 FILE_SHARE_READ|FILE_SHARE_DELETE, FILE_OPEN_IF, 0);
3401 printf("test 7 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, cli_errstr(&cli2));
3405 printf("test 7 open 2 of %s gave %s (correct error should be %s)\n", fname, cli_errstr(&cli2), "sharing violation");
3407 if (!cli_close(&cli1, fnum1)) {
3408 printf("test 7 close 1 of %s failed (%s)\n", fname, cli_errstr(&cli1));
3412 printf("non-io open test #7 passed.\n");
3414 cli_unlink(&cli1, fname);
3416 if (!torture_close_connection(&cli1)) {
3419 if (!torture_close_connection(&cli2)) {
3426 static void list_fn(file_info *finfo, const char *name, void *state)
3432 test directory listing speed
3434 static BOOL run_dirtest(int dummy)
3437 static struct cli_state cli;
3440 BOOL correct = True;
3442 printf("starting directory test\n");
3444 if (!torture_open_connection(&cli)) {
3448 cli_sockopt(&cli, sockops);
3451 for (i=0;i<torture_numops;i++) {
3453 slprintf(fname, sizeof(fname), "\\%x", (int)random());
3454 fnum = cli_open(&cli, fname, O_RDWR|O_CREAT, DENY_NONE);
3456 fprintf(stderr,"Failed to open %s\n", fname);
3459 cli_close(&cli, fnum);
3464 printf("Matched %d\n", cli_list(&cli, "a*.*", 0, list_fn, NULL));
3465 printf("Matched %d\n", cli_list(&cli, "b*.*", 0, list_fn, NULL));
3466 printf("Matched %d\n", cli_list(&cli, "xyzabc", 0, list_fn, NULL));
3468 printf("dirtest core %g seconds\n", end_timer() - t1);
3471 for (i=0;i<torture_numops;i++) {
3473 slprintf(fname, sizeof(fname), "\\%x", (int)random());
3474 cli_unlink(&cli, fname);
3477 if (!torture_close_connection(&cli)) {
3481 printf("finished dirtest\n");
3486 static BOOL run_error_map_extract(int dummy) {
3488 static struct cli_state c_dos;
3489 static struct cli_state c_nt;
3493 uint32 flgs2, errnum;
3500 /* NT-Error connection */
3502 if (!open_nbt_connection(&c_nt)) {
3506 c_nt.use_spnego = False;
3508 if (!cli_negprot(&c_nt)) {
3509 printf("%s rejected the NT-error negprot (%s)\n",host, cli_errstr(&c_nt));
3510 cli_shutdown(&c_nt);
3514 if (!cli_session_setup(&c_nt, "", "", 0, "", 0,
3516 printf("%s rejected the NT-error initial session setup (%s)\n",host, cli_errstr(&c_nt));
3520 /* DOS-Error connection */
3522 if (!open_nbt_connection(&c_dos)) {
3526 c_dos.use_spnego = False;
3527 c_dos.force_dos_errors = True;
3529 if (!cli_negprot(&c_dos)) {
3530 printf("%s rejected the DOS-error negprot (%s)\n",host, cli_errstr(&c_dos));
3531 cli_shutdown(&c_dos);
3535 if (!cli_session_setup(&c_dos, "", "", 0, "", 0,
3537 printf("%s rejected the DOS-error initial session setup (%s)\n",host, cli_errstr(&c_dos));
3541 for (error=(0xc0000000 | 0x1); error < (0xc0000000| 0xFFF); error++) {
3542 snprintf(user, sizeof(user), "%X", error);
3544 if (cli_session_setup(&c_nt, user,
3545 password, strlen(password),
3546 password, strlen(password),
3548 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
3551 flgs2 = SVAL(c_nt.inbuf,smb_flg2);
3553 /* Case #1: 32-bit NT errors */
3554 if (flgs2 & FLAGS2_32_BIT_ERROR_CODES) {
3555 nt_status = NT_STATUS(IVAL(c_nt.inbuf,smb_rcls));
3557 printf("/** Dos error on NT connection! (%s) */\n",
3559 nt_status = NT_STATUS(0xc0000000);
3562 if (cli_session_setup(&c_dos, user,
3563 password, strlen(password),
3564 password, strlen(password),
3566 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
3568 flgs2 = SVAL(c_dos.inbuf,smb_flg2), errnum;
3570 /* Case #1: 32-bit NT errors */
3571 if (flgs2 & FLAGS2_32_BIT_ERROR_CODES) {
3572 printf("/** NT error on DOS connection! (%s) */\n",
3574 errnum = errclass = 0;
3576 cli_dos_error(&c_dos, &errclass, &errnum);
3579 if (NT_STATUS_V(nt_status) != error) {
3580 printf("/*\t{ This NT error code was 'sqashed'\n\t from %s to %s \n\t during the session setup }\n*/\n",
3581 get_nt_error_c_code(NT_STATUS(error)),
3582 get_nt_error_c_code(nt_status));
3585 printf("\t{%s,\t%s,\t%s},\n",
3586 smb_dos_err_class(errclass),
3587 smb_dos_err_name(errclass, errnum),
3588 get_nt_error_c_code(NT_STATUS(error)));
3593 static double create_procs(BOOL (*fn)(int), BOOL *result)
3596 volatile pid_t *child_status;
3597 volatile BOOL *child_status_out;
3603 child_status = (volatile pid_t *)shm_setup(sizeof(pid_t)*nprocs);
3604 if (!child_status) {
3605 printf("Failed to setup shared memory\n");
3609 child_status_out = (volatile BOOL *)shm_setup(sizeof(BOOL)*nprocs);
3610 if (!child_status_out) {
3611 printf("Failed to setup result status shared memory\n");
3615 for (i = 0; i < nprocs; i++) {
3616 child_status[i] = 0;
3617 child_status_out[i] = True;
3622 for (i=0;i<nprocs;i++) {
3625 pid_t mypid = getpid();
3626 sys_srandom(((int)mypid) ^ ((int)time(NULL)));
3628 slprintf(myname,sizeof(myname),"CLIENT%d", i);
3631 memset(¤t_cli, 0, sizeof(current_cli));
3632 if (torture_open_connection(¤t_cli)) break;
3634 printf("pid %d failed to start\n", (int)getpid());
3640 child_status[i] = getpid();
3642 while (child_status[i] && end_timer() < 5) msleep(2);
3644 child_status_out[i] = fn(i);
3651 for (i=0;i<nprocs;i++) {
3652 if (child_status[i]) synccount++;
3654 if (synccount == nprocs) break;
3656 } while (end_timer() < 30);
3658 if (synccount != nprocs) {
3659 printf("FAILED TO START %d CLIENTS (started %d)\n", nprocs, synccount);
3664 /* start the client load */
3667 for (i=0;i<nprocs;i++) {
3668 child_status[i] = 0;
3671 printf("%d clients started\n", nprocs);
3673 for (i=0;i<nprocs;i++) {
3674 while (waitpid(0, &status, 0) == -1 && errno == EINTR) /* noop */ ;
3679 for (i=0;i<nprocs;i++) {
3680 if (!child_status_out[i]) {
3687 #define FLAG_MULTIPROC 1
3694 {"FDPASS", run_fdpasstest, 0},
3695 {"LOCK1", run_locktest1, 0},
3696 {"LOCK2", run_locktest2, 0},
3697 {"LOCK3", run_locktest3, 0},
3698 {"LOCK4", run_locktest4, 0},
3699 {"LOCK5", run_locktest5, 0},
3700 {"LOCK6", run_locktest6, 0},
3701 {"UNLINK", run_unlinktest, 0},
3702 {"BROWSE", run_browsetest, 0},
3703 {"ATTR", run_attrtest, 0},
3704 {"TRANS2", run_trans2test, 0},
3705 {"MAXFID", run_maxfidtest, FLAG_MULTIPROC},
3706 {"TORTURE",run_torture, FLAG_MULTIPROC},
3707 {"RANDOMIPC", run_randomipc, 0},
3708 {"NEGNOWAIT", run_negprot_nowait, 0},
3709 {"NBENCH", run_nbench, 0},
3710 {"OPLOCK1", run_oplock1, 0},
3711 {"OPLOCK2", run_oplock2, 0},
3712 {"OPLOCK3", run_oplock3, 0},
3713 {"DIR", run_dirtest, 0},
3714 {"DENY1", torture_denytest1, 0},
3715 {"DENY2", torture_denytest2, 0},
3716 {"TCON", run_tcon_test, 0},
3717 {"RW1", run_readwritetest, 0},
3718 {"RW2", run_readwritemulti, FLAG_MULTIPROC},
3719 {"RW3", run_readwritelarge, 0},
3720 {"OPEN", run_opentest, 0},
3721 {"XCOPY", run_xcopy, 0},
3722 {"RENAME", run_rename, 0},
3723 {"DELETE", run_deletetest, 0},
3724 {"PROPERTIES", run_properties, 0},
3725 {"MANGLE", torture_mangle, 0},
3726 {"W2K", run_w2ktest, 0},
3727 {"TRANS2SCAN", torture_trans2_scan, 0},
3728 {"NTTRANSSCAN", torture_nttrans_scan, 0},
3729 {"UTABLE", torture_utable, 0},
3730 {"CASETABLE", torture_casetable, 0},
3731 {"ERRMAPEXTRACT", run_error_map_extract, 0},
3732 {"PIPE_NUMBER", run_pipe_number, 0},
3737 /****************************************************************************
3738 run a specified test or "ALL"
3739 ****************************************************************************/
3740 static BOOL run_test(char *name)
3746 if (strequal(name,"ALL")) {
3747 for (i=0;torture_ops[i].name;i++) {
3748 run_test(torture_ops[i].name);
3752 for (i=0;torture_ops[i].name;i++) {
3753 snprintf(randomfname, sizeof(randomfname), "\\XX%x",
3754 (unsigned)random());
3756 if (strequal(name, torture_ops[i].name)) {
3757 printf("Running %s\n", name);
3758 if (torture_ops[i].flags & FLAG_MULTIPROC) {
3759 t = create_procs(torture_ops[i].fn, &result);
3762 printf("TEST %s FAILED!\n", name);
3767 if (!torture_ops[i].fn(0)) {
3769 printf("TEST %s FAILED!\n", name);
3773 printf("%s took %g secs\n\n", name, t);
3780 static void usage(void)
3784 printf("Usage: smbtorture //server/share <options> TEST1 TEST2 ...\n");
3786 printf("\t-d debuglevel\n");
3787 printf("\t-U user%%pass\n");
3788 printf("\t-k use kerberos\n");
3789 printf("\t-N numprocs\n");
3790 printf("\t-n my_netbios_name\n");
3791 printf("\t-W workgroup\n");
3792 printf("\t-o num_operations\n");
3793 printf("\t-O socket_options\n");
3794 printf("\t-m maximum protocol\n");
3795 printf("\t-L use oplocks\n");
3796 printf("\t-c CLIENT.TXT specify client load file for NBENCH\n");
3797 printf("\t-A showall\n");
3798 printf("\t-s seed\n");
3801 printf("tests are:");
3802 for (i=0;torture_ops[i].name;i++) {
3803 printf(" %s", torture_ops[i].name);
3807 printf("default test is ALL\n");
3816 /****************************************************************************
3818 ****************************************************************************/
3819 int main(int argc,char *argv[])
3824 extern char *optarg;
3826 BOOL correct = True;
3830 #ifdef HAVE_SETBUFFER
3831 setbuffer(stdout, NULL, 0);
3834 lp_load(dyn_CONFIGFILE,True,False,False);
3841 for(p = argv[1]; *p; p++)
3845 if (strncmp(argv[1], "//", 2)) {
3849 fstrcpy(host, &argv[1][2]);
3850 p = strchr_m(&host[2],'/');
3855 fstrcpy(share, p+1);
3859 if (*username == 0 && getenv("LOGNAME")) {
3860 pstrcpy(username,getenv("LOGNAME"));
3867 fstrcpy(workgroup, lp_workgroup());
3869 while ((opt = getopt(argc, argv, "hW:U:n:N:O:o:m:Ld:Ac:ks:")) != EOF) {
3872 srandom(atoi(optarg));
3875 fstrcpy(workgroup,optarg);
3878 max_protocol = interpret_protocol(optarg, max_protocol);
3881 nprocs = atoi(optarg);
3884 torture_numops = atoi(optarg);
3887 DEBUGLEVEL = atoi(optarg);
3896 torture_showall = True;
3899 fstrcpy(myname, optarg);
3902 client_txt = optarg;
3906 use_kerberos = True;
3909 d_printf("No kerberos support compiled in\n");
3914 pstrcpy(username,optarg);
3915 p = strchr_m(username,'%');
3918 pstrcpy(password, p+1);
3923 printf("Unknown option %c (%d)\n", (char)opt, opt);
3930 p = getpass("Password:");
3932 pstrcpy(password, p);
3937 printf("host=%s share=%s user=%s myname=%s\n",
3938 host, share, username, myname);
3941 correct = run_test("ALL");
3943 for (i=1;i<argc;i++) {
3944 if (!run_test(argv[i])) {