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 const 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 const 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 const 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 const 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 const 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 const char *fname = "\\lockt1.lck";
786 int fnum1, fnum2, fnum3;
788 unsigned lock_timeout;
790 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
793 cli_sockopt(&cli1, sockops);
794 cli_sockopt(&cli2, sockops);
796 printf("starting locktest1\n");
798 cli_unlink(&cli1, fname);
800 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
802 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
805 fnum2 = cli_open(&cli1, fname, O_RDWR, DENY_NONE);
807 printf("open2 of %s failed (%s)\n", fname, cli_errstr(&cli1));
810 fnum3 = cli_open(&cli2, fname, O_RDWR, DENY_NONE);
812 printf("open3 of %s failed (%s)\n", fname, cli_errstr(&cli2));
816 if (!cli_lock(&cli1, fnum1, 0, 4, 0, WRITE_LOCK)) {
817 printf("lock1 failed (%s)\n", cli_errstr(&cli1));
822 if (cli_lock(&cli2, fnum3, 0, 4, 0, WRITE_LOCK)) {
823 printf("lock2 succeeded! This is a locking bug\n");
826 if (!check_error(__LINE__, &cli2, ERRDOS, ERRlock,
827 NT_STATUS_LOCK_NOT_GRANTED)) return False;
831 lock_timeout = (1 + (random() % 20));
832 printf("Testing lock timeout with timeout=%u\n", lock_timeout);
834 if (cli_lock(&cli2, fnum3, 0, 4, lock_timeout * 1000, WRITE_LOCK)) {
835 printf("lock3 succeeded! This is a locking bug\n");
838 if (!check_error(__LINE__, &cli2, ERRDOS, ERRlock,
839 NT_STATUS_FILE_LOCK_CONFLICT)) return False;
844 printf("error: This server appears not to support timed lock requests\n");
846 printf("server slept for %u seconds for a %u second timeout\n",
847 (unsigned int)(t2-t1), lock_timeout);
849 if (!cli_close(&cli1, fnum2)) {
850 printf("close1 failed (%s)\n", cli_errstr(&cli1));
854 if (cli_lock(&cli2, fnum3, 0, 4, 0, WRITE_LOCK)) {
855 printf("lock4 succeeded! This is a locking bug\n");
858 if (!check_error(__LINE__, &cli2, ERRDOS, ERRlock,
859 NT_STATUS_FILE_LOCK_CONFLICT)) return False;
862 if (!cli_close(&cli1, fnum1)) {
863 printf("close2 failed (%s)\n", cli_errstr(&cli1));
867 if (!cli_close(&cli2, fnum3)) {
868 printf("close3 failed (%s)\n", cli_errstr(&cli2));
872 if (!cli_unlink(&cli1, fname)) {
873 printf("unlink failed (%s)\n", cli_errstr(&cli1));
878 if (!torture_close_connection(&cli1)) {
882 if (!torture_close_connection(&cli2)) {
886 printf("Passed locktest1\n");
891 checks for correct tconX support
893 static BOOL run_tcon_test(int dummy)
895 static struct cli_state cli1;
896 const char *fname = "\\tcontest.tmp";
901 if (!torture_open_connection(&cli1)) {
904 cli_sockopt(&cli1, sockops);
906 printf("starting tcontest\n");
908 cli_unlink(&cli1, fname);
910 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
913 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
919 if (cli_write(&cli1, fnum1, 0, buf, 130, 4) != 4)
921 printf("write failed (%s)", cli_errstr(&cli1));
925 if (!cli_send_tconX(&cli1, share, "?????",
926 password, strlen(password)+1)) {
927 printf("%s refused 2nd tree connect (%s)\n", host,
933 if (cli_write(&cli1, fnum1, 0, buf, 130, 4) == 4)
935 printf("write succeeded (%s)", cli_errstr(&cli1));
939 if (cli_close(&cli1, fnum1)) {
940 printf("close2 succeeded (%s)\n", cli_errstr(&cli1));
944 if (!cli_tdis(&cli1)) {
945 printf("tdis failed (%s)\n", cli_errstr(&cli1));
951 if (!cli_close(&cli1, fnum1)) {
952 printf("close2 failed (%s)\n", cli_errstr(&cli1));
956 if (!torture_close_connection(&cli1)) {
960 printf("Passed tcontest\n");
966 This test checks that
968 1) the server supports multiple locking contexts on the one SMB
969 connection, distinguished by PID.
971 2) the server correctly fails overlapping locks made by the same PID (this
972 goes against POSIX behaviour, which is why it is tricky to implement)
974 3) the server denies unlock requests by an incorrect client PID
976 static BOOL run_locktest2(int dummy)
978 static struct cli_state cli;
979 const char *fname = "\\lockt2.lck";
980 int fnum1, fnum2, fnum3;
983 if (!torture_open_connection(&cli)) {
987 cli_sockopt(&cli, sockops);
989 printf("starting locktest2\n");
991 cli_unlink(&cli, fname);
995 fnum1 = cli_open(&cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
997 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli));
1001 fnum2 = cli_open(&cli, fname, O_RDWR, DENY_NONE);
1003 printf("open2 of %s failed (%s)\n", fname, cli_errstr(&cli));
1007 cli_setpid(&cli, 2);
1009 fnum3 = cli_open(&cli, fname, O_RDWR, DENY_NONE);
1011 printf("open3 of %s failed (%s)\n", fname, cli_errstr(&cli));
1015 cli_setpid(&cli, 1);
1017 if (!cli_lock(&cli, fnum1, 0, 4, 0, WRITE_LOCK)) {
1018 printf("lock1 failed (%s)\n", cli_errstr(&cli));
1022 if (cli_lock(&cli, fnum1, 0, 4, 0, WRITE_LOCK)) {
1023 printf("WRITE lock1 succeeded! This is a locking bug\n");
1026 if (!check_error(__LINE__, &cli, ERRDOS, ERRlock,
1027 NT_STATUS_LOCK_NOT_GRANTED)) return False;
1030 if (cli_lock(&cli, fnum2, 0, 4, 0, WRITE_LOCK)) {
1031 printf("WRITE lock2 succeeded! This is a locking bug\n");
1034 if (!check_error(__LINE__, &cli, ERRDOS, ERRlock,
1035 NT_STATUS_LOCK_NOT_GRANTED)) return False;
1038 if (cli_lock(&cli, fnum2, 0, 4, 0, READ_LOCK)) {
1039 printf("READ lock2 succeeded! This is a locking bug\n");
1042 if (!check_error(__LINE__, &cli, ERRDOS, ERRlock,
1043 NT_STATUS_FILE_LOCK_CONFLICT)) return False;
1046 if (!cli_lock(&cli, fnum1, 100, 4, 0, WRITE_LOCK)) {
1047 printf("lock at 100 failed (%s)\n", cli_errstr(&cli));
1049 cli_setpid(&cli, 2);
1050 if (cli_unlock(&cli, fnum1, 100, 4)) {
1051 printf("unlock at 100 succeeded! This is a locking bug\n");
1055 if (cli_unlock(&cli, fnum1, 0, 4)) {
1056 printf("unlock1 succeeded! This is a locking bug\n");
1059 if (!check_error(__LINE__, &cli,
1061 NT_STATUS_RANGE_NOT_LOCKED)) return False;
1064 if (cli_unlock(&cli, fnum1, 0, 8)) {
1065 printf("unlock2 succeeded! This is a locking bug\n");
1068 if (!check_error(__LINE__, &cli,
1070 NT_STATUS_RANGE_NOT_LOCKED)) return False;
1073 if (cli_lock(&cli, fnum3, 0, 4, 0, WRITE_LOCK)) {
1074 printf("lock3 succeeded! This is a locking bug\n");
1077 if (!check_error(__LINE__, &cli, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False;
1080 cli_setpid(&cli, 1);
1082 if (!cli_close(&cli, fnum1)) {
1083 printf("close1 failed (%s)\n", cli_errstr(&cli));
1087 if (!cli_close(&cli, fnum2)) {
1088 printf("close2 failed (%s)\n", cli_errstr(&cli));
1092 if (!cli_close(&cli, fnum3)) {
1093 printf("close3 failed (%s)\n", cli_errstr(&cli));
1097 if (!torture_close_connection(&cli)) {
1101 printf("locktest2 finished\n");
1108 This test checks that
1110 1) the server supports the full offset range in lock requests
1112 static BOOL run_locktest3(int dummy)
1114 static struct cli_state cli1, cli2;
1115 const char *fname = "\\lockt3.lck";
1116 int fnum1, fnum2, i;
1118 BOOL correct = True;
1120 #define NEXT_OFFSET offset += (~(uint32)0) / torture_numops
1122 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
1125 cli_sockopt(&cli1, sockops);
1126 cli_sockopt(&cli2, sockops);
1128 printf("starting locktest3\n");
1130 cli_unlink(&cli1, fname);
1132 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1134 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
1137 fnum2 = cli_open(&cli2, fname, O_RDWR, DENY_NONE);
1139 printf("open2 of %s failed (%s)\n", fname, cli_errstr(&cli2));
1143 for (offset=i=0;i<torture_numops;i++) {
1145 if (!cli_lock(&cli1, fnum1, offset-1, 1, 0, WRITE_LOCK)) {
1146 printf("lock1 %d failed (%s)\n",
1152 if (!cli_lock(&cli2, fnum2, offset-2, 1, 0, WRITE_LOCK)) {
1153 printf("lock2 %d failed (%s)\n",
1160 for (offset=i=0;i<torture_numops;i++) {
1163 if (cli_lock(&cli1, fnum1, offset-2, 1, 0, WRITE_LOCK)) {
1164 printf("error: lock1 %d succeeded!\n", i);
1168 if (cli_lock(&cli2, fnum2, offset-1, 1, 0, WRITE_LOCK)) {
1169 printf("error: lock2 %d succeeded!\n", i);
1173 if (cli_lock(&cli1, fnum1, offset-1, 1, 0, WRITE_LOCK)) {
1174 printf("error: lock3 %d succeeded!\n", i);
1178 if (cli_lock(&cli2, fnum2, offset-2, 1, 0, WRITE_LOCK)) {
1179 printf("error: lock4 %d succeeded!\n", i);
1184 for (offset=i=0;i<torture_numops;i++) {
1187 if (!cli_unlock(&cli1, fnum1, offset-1, 1)) {
1188 printf("unlock1 %d failed (%s)\n",
1194 if (!cli_unlock(&cli2, fnum2, offset-2, 1)) {
1195 printf("unlock2 %d failed (%s)\n",
1202 if (!cli_close(&cli1, fnum1)) {
1203 printf("close1 failed (%s)\n", cli_errstr(&cli1));
1207 if (!cli_close(&cli2, fnum2)) {
1208 printf("close2 failed (%s)\n", cli_errstr(&cli2));
1212 if (!cli_unlink(&cli1, fname)) {
1213 printf("unlink failed (%s)\n", cli_errstr(&cli1));
1217 if (!torture_close_connection(&cli1)) {
1221 if (!torture_close_connection(&cli2)) {
1225 printf("finished locktest3\n");
1230 #define EXPECTED(ret, v) if ((ret) != (v)) { \
1231 printf("** "); correct = False; \
1235 looks at overlapping locks
1237 static BOOL run_locktest4(int dummy)
1239 static struct cli_state cli1, cli2;
1240 const char *fname = "\\lockt4.lck";
1241 int fnum1, fnum2, f;
1244 BOOL correct = True;
1246 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
1250 cli_sockopt(&cli1, sockops);
1251 cli_sockopt(&cli2, sockops);
1253 printf("starting locktest4\n");
1255 cli_unlink(&cli1, fname);
1257 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1258 fnum2 = cli_open(&cli2, fname, O_RDWR, DENY_NONE);
1260 memset(buf, 0, sizeof(buf));
1262 if (cli_write(&cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
1263 printf("Failed to create file\n");
1268 ret = cli_lock(&cli1, fnum1, 0, 4, 0, WRITE_LOCK) &&
1269 cli_lock(&cli1, fnum1, 2, 4, 0, WRITE_LOCK);
1270 EXPECTED(ret, False);
1271 printf("the same process %s set overlapping write locks\n", ret?"can":"cannot");
1273 ret = cli_lock(&cli1, fnum1, 10, 4, 0, READ_LOCK) &&
1274 cli_lock(&cli1, fnum1, 12, 4, 0, READ_LOCK);
1275 EXPECTED(ret, True);
1276 printf("the same process %s set overlapping read locks\n", ret?"can":"cannot");
1278 ret = cli_lock(&cli1, fnum1, 20, 4, 0, WRITE_LOCK) &&
1279 cli_lock(&cli2, fnum2, 22, 4, 0, WRITE_LOCK);
1280 EXPECTED(ret, False);
1281 printf("a different connection %s set overlapping write locks\n", ret?"can":"cannot");
1283 ret = cli_lock(&cli1, fnum1, 30, 4, 0, READ_LOCK) &&
1284 cli_lock(&cli2, fnum2, 32, 4, 0, READ_LOCK);
1285 EXPECTED(ret, True);
1286 printf("a different connection %s set overlapping read locks\n", ret?"can":"cannot");
1288 ret = (cli_setpid(&cli1, 1), cli_lock(&cli1, fnum1, 40, 4, 0, WRITE_LOCK)) &&
1289 (cli_setpid(&cli1, 2), cli_lock(&cli1, fnum1, 42, 4, 0, WRITE_LOCK));
1290 EXPECTED(ret, False);
1291 printf("a different pid %s set overlapping write locks\n", ret?"can":"cannot");
1293 ret = (cli_setpid(&cli1, 1), cli_lock(&cli1, fnum1, 50, 4, 0, READ_LOCK)) &&
1294 (cli_setpid(&cli1, 2), cli_lock(&cli1, fnum1, 52, 4, 0, READ_LOCK));
1295 EXPECTED(ret, True);
1296 printf("a different pid %s set overlapping read locks\n", ret?"can":"cannot");
1298 ret = cli_lock(&cli1, fnum1, 60, 4, 0, READ_LOCK) &&
1299 cli_lock(&cli1, fnum1, 60, 4, 0, READ_LOCK);
1300 EXPECTED(ret, True);
1301 printf("the same process %s set the same read lock twice\n", ret?"can":"cannot");
1303 ret = cli_lock(&cli1, fnum1, 70, 4, 0, WRITE_LOCK) &&
1304 cli_lock(&cli1, fnum1, 70, 4, 0, WRITE_LOCK);
1305 EXPECTED(ret, False);
1306 printf("the same process %s set the same write lock twice\n", ret?"can":"cannot");
1308 ret = cli_lock(&cli1, fnum1, 80, 4, 0, READ_LOCK) &&
1309 cli_lock(&cli1, fnum1, 80, 4, 0, WRITE_LOCK);
1310 EXPECTED(ret, False);
1311 printf("the same process %s overlay a read lock with a write lock\n", ret?"can":"cannot");
1313 ret = cli_lock(&cli1, fnum1, 90, 4, 0, WRITE_LOCK) &&
1314 cli_lock(&cli1, fnum1, 90, 4, 0, READ_LOCK);
1315 EXPECTED(ret, True);
1316 printf("the same process %s overlay a write lock with a read lock\n", ret?"can":"cannot");
1318 ret = (cli_setpid(&cli1, 1), cli_lock(&cli1, fnum1, 100, 4, 0, WRITE_LOCK)) &&
1319 (cli_setpid(&cli1, 2), cli_lock(&cli1, fnum1, 100, 4, 0, READ_LOCK));
1320 EXPECTED(ret, False);
1321 printf("a different pid %s overlay a write lock with a read lock\n", ret?"can":"cannot");
1323 ret = cli_lock(&cli1, fnum1, 110, 4, 0, READ_LOCK) &&
1324 cli_lock(&cli1, fnum1, 112, 4, 0, READ_LOCK) &&
1325 cli_unlock(&cli1, fnum1, 110, 6);
1326 EXPECTED(ret, False);
1327 printf("the same process %s coalesce read locks\n", ret?"can":"cannot");
1330 ret = cli_lock(&cli1, fnum1, 120, 4, 0, WRITE_LOCK) &&
1331 (cli_read(&cli2, fnum2, buf, 120, 4) == 4);
1332 EXPECTED(ret, False);
1333 printf("this server %s strict write locking\n", ret?"doesn't do":"does");
1335 ret = cli_lock(&cli1, fnum1, 130, 4, 0, READ_LOCK) &&
1336 (cli_write(&cli2, fnum2, 0, buf, 130, 4) == 4);
1337 EXPECTED(ret, False);
1338 printf("this server %s strict read locking\n", ret?"doesn't do":"does");
1341 ret = cli_lock(&cli1, fnum1, 140, 4, 0, READ_LOCK) &&
1342 cli_lock(&cli1, fnum1, 140, 4, 0, READ_LOCK) &&
1343 cli_unlock(&cli1, fnum1, 140, 4) &&
1344 cli_unlock(&cli1, fnum1, 140, 4);
1345 EXPECTED(ret, True);
1346 printf("this server %s do recursive read locking\n", ret?"does":"doesn't");
1349 ret = cli_lock(&cli1, fnum1, 150, 4, 0, WRITE_LOCK) &&
1350 cli_lock(&cli1, fnum1, 150, 4, 0, READ_LOCK) &&
1351 cli_unlock(&cli1, fnum1, 150, 4) &&
1352 (cli_read(&cli2, fnum2, buf, 150, 4) == 4) &&
1353 !(cli_write(&cli2, fnum2, 0, buf, 150, 4) == 4) &&
1354 cli_unlock(&cli1, fnum1, 150, 4);
1355 EXPECTED(ret, True);
1356 printf("this server %s do recursive lock overlays\n", ret?"does":"doesn't");
1358 ret = cli_lock(&cli1, fnum1, 160, 4, 0, READ_LOCK) &&
1359 cli_unlock(&cli1, fnum1, 160, 4) &&
1360 (cli_write(&cli2, fnum2, 0, buf, 160, 4) == 4) &&
1361 (cli_read(&cli2, fnum2, buf, 160, 4) == 4);
1362 EXPECTED(ret, True);
1363 printf("the same process %s remove a read lock using write locking\n", ret?"can":"cannot");
1365 ret = cli_lock(&cli1, fnum1, 170, 4, 0, WRITE_LOCK) &&
1366 cli_unlock(&cli1, fnum1, 170, 4) &&
1367 (cli_write(&cli2, fnum2, 0, buf, 170, 4) == 4) &&
1368 (cli_read(&cli2, fnum2, buf, 170, 4) == 4);
1369 EXPECTED(ret, True);
1370 printf("the same process %s remove a write lock using read locking\n", ret?"can":"cannot");
1372 ret = cli_lock(&cli1, fnum1, 190, 4, 0, WRITE_LOCK) &&
1373 cli_lock(&cli1, fnum1, 190, 4, 0, READ_LOCK) &&
1374 cli_unlock(&cli1, fnum1, 190, 4) &&
1375 !(cli_write(&cli2, fnum2, 0, buf, 190, 4) == 4) &&
1376 (cli_read(&cli2, fnum2, buf, 190, 4) == 4);
1377 EXPECTED(ret, True);
1378 printf("the same process %s remove the first lock first\n", ret?"does":"doesn't");
1380 cli_close(&cli1, fnum1);
1381 cli_close(&cli2, fnum2);
1382 fnum1 = cli_open(&cli1, fname, O_RDWR, DENY_NONE);
1383 f = cli_open(&cli1, fname, O_RDWR, DENY_NONE);
1384 ret = cli_lock(&cli1, fnum1, 0, 8, 0, READ_LOCK) &&
1385 cli_lock(&cli1, f, 0, 1, 0, READ_LOCK) &&
1386 cli_close(&cli1, fnum1) &&
1387 ((fnum1 = cli_open(&cli1, fname, O_RDWR, DENY_NONE)) != -1) &&
1388 cli_lock(&cli1, fnum1, 7, 1, 0, WRITE_LOCK);
1389 cli_close(&cli1, f);
1390 cli_close(&cli1, fnum1);
1391 EXPECTED(ret, True);
1392 printf("the server %s have the NT byte range lock bug\n", !ret?"does":"doesn't");
1395 cli_close(&cli1, fnum1);
1396 cli_close(&cli2, fnum2);
1397 cli_unlink(&cli1, fname);
1398 torture_close_connection(&cli1);
1399 torture_close_connection(&cli2);
1401 printf("finished locktest4\n");
1406 looks at lock upgrade/downgrade.
1408 static BOOL run_locktest5(int dummy)
1410 static struct cli_state cli1, cli2;
1411 const char *fname = "\\lockt5.lck";
1412 int fnum1, fnum2, fnum3;
1415 BOOL correct = True;
1417 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
1421 cli_sockopt(&cli1, sockops);
1422 cli_sockopt(&cli2, sockops);
1424 printf("starting locktest5\n");
1426 cli_unlink(&cli1, fname);
1428 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1429 fnum2 = cli_open(&cli2, fname, O_RDWR, DENY_NONE);
1430 fnum3 = cli_open(&cli1, fname, O_RDWR, DENY_NONE);
1432 memset(buf, 0, sizeof(buf));
1434 if (cli_write(&cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
1435 printf("Failed to create file\n");
1440 /* Check for NT bug... */
1441 ret = cli_lock(&cli1, fnum1, 0, 8, 0, READ_LOCK) &&
1442 cli_lock(&cli1, fnum3, 0, 1, 0, READ_LOCK);
1443 cli_close(&cli1, fnum1);
1444 fnum1 = cli_open(&cli1, fname, O_RDWR, DENY_NONE);
1445 ret = cli_lock(&cli1, fnum1, 7, 1, 0, WRITE_LOCK);
1446 EXPECTED(ret, True);
1447 printf("this server %s the NT locking bug\n", ret ? "doesn't have" : "has");
1448 cli_close(&cli1, fnum1);
1449 fnum1 = cli_open(&cli1, fname, O_RDWR, DENY_NONE);
1450 cli_unlock(&cli1, fnum3, 0, 1);
1452 ret = cli_lock(&cli1, fnum1, 0, 4, 0, WRITE_LOCK) &&
1453 cli_lock(&cli1, fnum1, 1, 1, 0, READ_LOCK);
1454 EXPECTED(ret, True);
1455 printf("the same process %s overlay a write with a read lock\n", ret?"can":"cannot");
1457 ret = cli_lock(&cli2, fnum2, 0, 4, 0, READ_LOCK);
1458 EXPECTED(ret, False);
1460 printf("a different processs %s get a read lock on the first process lock stack\n", ret?"can":"cannot");
1462 /* Unlock the process 2 lock. */
1463 cli_unlock(&cli2, fnum2, 0, 4);
1465 ret = cli_lock(&cli1, fnum3, 0, 4, 0, READ_LOCK);
1466 EXPECTED(ret, False);
1468 printf("the same processs on a different fnum %s get a read lock\n", ret?"can":"cannot");
1470 /* Unlock the process 1 fnum3 lock. */
1471 cli_unlock(&cli1, fnum3, 0, 4);
1473 /* Stack 2 more locks here. */
1474 ret = cli_lock(&cli1, fnum1, 0, 4, 0, READ_LOCK) &&
1475 cli_lock(&cli1, fnum1, 0, 4, 0, READ_LOCK);
1477 EXPECTED(ret, True);
1478 printf("the same process %s stack read locks\n", ret?"can":"cannot");
1480 /* Unlock the first process lock, then check this was the WRITE lock that was
1483 ret = cli_unlock(&cli1, fnum1, 0, 4) &&
1484 cli_lock(&cli2, fnum2, 0, 4, 0, READ_LOCK);
1486 EXPECTED(ret, True);
1487 printf("the first unlock removes the %s lock\n", ret?"WRITE":"READ");
1489 /* Unlock the process 2 lock. */
1490 cli_unlock(&cli2, fnum2, 0, 4);
1492 /* We should have 3 stacked locks here. Ensure we need to do 3 unlocks. */
1494 ret = cli_unlock(&cli1, fnum1, 1, 1) &&
1495 cli_unlock(&cli1, fnum1, 0, 4) &&
1496 cli_unlock(&cli1, fnum1, 0, 4);
1498 EXPECTED(ret, True);
1499 printf("the same process %s unlock the stack of 4 locks\n", ret?"can":"cannot");
1501 /* Ensure the next unlock fails. */
1502 ret = cli_unlock(&cli1, fnum1, 0, 4);
1503 EXPECTED(ret, False);
1504 printf("the same process %s count the lock stack\n", !ret?"can":"cannot");
1506 /* Ensure connection 2 can get a write lock. */
1507 ret = cli_lock(&cli2, fnum2, 0, 4, 0, WRITE_LOCK);
1508 EXPECTED(ret, True);
1510 printf("a different processs %s get a write lock on the unlocked stack\n", ret?"can":"cannot");
1514 cli_close(&cli1, fnum1);
1515 cli_close(&cli2, fnum2);
1516 cli_unlink(&cli1, fname);
1517 if (!torture_close_connection(&cli1)) {
1520 if (!torture_close_connection(&cli2)) {
1524 printf("finished locktest5\n");
1530 tries the unusual lockingX locktype bits
1532 static BOOL run_locktest6(int dummy)
1534 static struct cli_state cli;
1535 const char *fname[1] = { "\\lock6.txt" };
1540 if (!torture_open_connection(&cli)) {
1544 cli_sockopt(&cli, sockops);
1546 printf("starting locktest6\n");
1549 printf("Testing %s\n", fname[i]);
1551 cli_unlink(&cli, fname[i]);
1553 fnum = cli_open(&cli, fname[i], O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1554 status = cli_locktype(&cli, fnum, 0, 8, 0, LOCKING_ANDX_CHANGE_LOCKTYPE);
1555 cli_close(&cli, fnum);
1556 printf("CHANGE_LOCKTYPE gave %s\n", nt_errstr(status));
1558 fnum = cli_open(&cli, fname[i], O_RDWR, DENY_NONE);
1559 status = cli_locktype(&cli, fnum, 0, 8, 0, LOCKING_ANDX_CANCEL_LOCK);
1560 cli_close(&cli, fnum);
1561 printf("CANCEL_LOCK gave %s\n", nt_errstr(status));
1563 cli_unlink(&cli, fname[i]);
1566 torture_close_connection(&cli);
1568 printf("finished locktest6\n");
1573 test whether fnums and tids open on one VC are available on another (a major
1576 static BOOL run_fdpasstest(int dummy)
1578 static struct cli_state cli1, cli2, cli3;
1579 const char *fname = "\\fdpass.tst";
1583 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
1586 cli_sockopt(&cli1, sockops);
1587 cli_sockopt(&cli2, sockops);
1589 printf("starting fdpasstest\n");
1591 cli_unlink(&cli1, fname);
1593 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1595 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
1599 if (cli_write(&cli1, fnum1, 0, "hello world\n", 0, 13) != 13) {
1600 printf("write failed (%s)\n", cli_errstr(&cli1));
1605 cli3.vuid = cli1.vuid;
1606 cli3.cnum = cli1.cnum;
1607 cli3.pid = cli1.pid;
1609 if (cli_read(&cli3, fnum1, buf, 0, 13) == 13) {
1610 printf("read succeeded! nasty security hole [%s]\n",
1615 cli_close(&cli1, fnum1);
1616 cli_unlink(&cli1, fname);
1618 torture_close_connection(&cli1);
1619 torture_close_connection(&cli2);
1621 printf("finished fdpasstest\n");
1627 This test checks that
1629 1) the server does not allow an unlink on a file that is open
1631 static BOOL run_unlinktest(int dummy)
1633 static struct cli_state cli;
1634 const char *fname = "\\unlink.tst";
1636 BOOL correct = True;
1638 if (!torture_open_connection(&cli)) {
1642 cli_sockopt(&cli, sockops);
1644 printf("starting unlink test\n");
1646 cli_unlink(&cli, fname);
1648 cli_setpid(&cli, 1);
1650 fnum = cli_open(&cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1652 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli));
1656 if (cli_unlink(&cli, fname)) {
1657 printf("error: server allowed unlink on an open file\n");
1660 correct = check_error(__LINE__, &cli, ERRDOS, ERRbadshare,
1661 NT_STATUS_SHARING_VIOLATION);
1664 cli_close(&cli, fnum);
1665 cli_unlink(&cli, fname);
1667 if (!torture_close_connection(&cli)) {
1671 printf("unlink test finished\n");
1678 test how many open files this server supports on the one socket
1680 static BOOL run_maxfidtest(int dummy)
1682 static struct cli_state cli;
1683 const char *template = "\\maxfid.%d.%d";
1685 int fnums[0x11000], i;
1687 BOOL correct = True;
1692 printf("failed to connect\n");
1696 cli_sockopt(&cli, sockops);
1698 for (i=0; i<0x11000; i++) {
1699 slprintf(fname,sizeof(fname)-1,template, i,(int)getpid());
1700 if ((fnums[i] = cli_open(&cli, fname,
1701 O_RDWR|O_CREAT|O_TRUNC, DENY_NONE)) ==
1703 printf("open of %s failed (%s)\n",
1704 fname, cli_errstr(&cli));
1705 printf("maximum fnum is %d\n", i);
1713 printf("cleaning up\n");
1715 slprintf(fname,sizeof(fname)-1,template, i,(int)getpid());
1716 cli_close(&cli, fnums[i]);
1717 if (!cli_unlink(&cli, fname)) {
1718 printf("unlink of %s failed (%s)\n",
1719 fname, cli_errstr(&cli));
1726 printf("maxfid test finished\n");
1727 if (!torture_close_connection(&cli)) {
1733 /* generate a random buffer */
1734 static void rand_buf(char *buf, int len)
1737 *buf = (char)sys_random();
1742 /* send smb negprot commands, not reading the response */
1743 static BOOL run_negprot_nowait(int dummy)
1746 static struct cli_state cli;
1747 BOOL correct = True;
1749 printf("starting negprot nowait test\n");
1751 if (!open_nbt_connection(&cli)) {
1755 for (i=0;i<50000;i++) {
1756 cli_negprot_send(&cli);
1759 if (!torture_close_connection(&cli)) {
1763 printf("finished negprot nowait test\n");
1769 /* send random IPC commands */
1770 static BOOL run_randomipc(int dummy)
1772 char *rparam = NULL;
1776 int api, param_len, i;
1777 static struct cli_state cli;
1778 BOOL correct = True;
1781 printf("starting random ipc test\n");
1783 if (!torture_open_connection(&cli)) {
1787 for (i=0;i<count;i++) {
1788 api = sys_random() % 500;
1789 param_len = (sys_random() % 64);
1791 rand_buf(param, param_len);
1796 param, param_len, 8,
1797 NULL, 0, BUFFER_SIZE,
1801 printf("%d/%d\r", i,count);
1804 printf("%d/%d\n", i, count);
1806 if (!torture_close_connection(&cli)) {
1810 printf("finished random ipc test\n");
1817 static void browse_callback(const char *sname, uint32 stype,
1818 const char *comment, void *state)
1820 printf("\t%20.20s %08x %s\n", sname, stype, comment);
1826 This test checks the browse list code
1829 static BOOL run_browsetest(int dummy)
1831 static struct cli_state cli;
1832 BOOL correct = True;
1834 printf("starting browse test\n");
1836 if (!torture_open_connection(&cli)) {
1840 printf("domain list:\n");
1841 cli_NetServerEnum(&cli, cli.server_domain,
1842 SV_TYPE_DOMAIN_ENUM,
1843 browse_callback, NULL);
1845 printf("machine list:\n");
1846 cli_NetServerEnum(&cli, cli.server_domain,
1848 browse_callback, NULL);
1850 if (!torture_close_connection(&cli)) {
1854 printf("browse test finished\n");
1862 This checks how the getatr calls works
1864 static BOOL run_attrtest(int dummy)
1866 static struct cli_state cli;
1869 const char *fname = "\\attrib.tst";
1870 BOOL correct = True;
1872 printf("starting attrib test\n");
1874 if (!torture_open_connection(&cli)) {
1878 cli_unlink(&cli, fname);
1879 fnum = cli_open(&cli, fname,
1880 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1881 cli_close(&cli, fnum);
1882 if (!cli_getatr(&cli, fname, NULL, NULL, &t)) {
1883 printf("getatr failed (%s)\n", cli_errstr(&cli));
1887 if (abs(t - time(NULL)) > 60*60*24*10) {
1888 printf("ERROR: SMBgetatr bug. time is %s",
1894 t2 = t-60*60*24; /* 1 day ago */
1896 if (!cli_setatr(&cli, fname, 0, t2)) {
1897 printf("setatr failed (%s)\n", cli_errstr(&cli));
1901 if (!cli_getatr(&cli, fname, NULL, NULL, &t)) {
1902 printf("getatr failed (%s)\n", cli_errstr(&cli));
1907 printf("ERROR: getatr/setatr bug. times are\n%s",
1909 printf("%s", ctime(&t2));
1913 cli_unlink(&cli, fname);
1915 if (!torture_close_connection(&cli)) {
1919 printf("attrib test finished\n");
1926 This checks a couple of trans2 calls
1928 static BOOL run_trans2test(int dummy)
1930 static struct cli_state cli;
1933 time_t c_time, a_time, m_time, w_time, m_time2;
1934 const char *fname = "\\trans2.tst";
1935 const char *dname = "\\trans2";
1936 const char *fname2 = "\\trans2\\trans2.tst";
1938 BOOL correct = True;
1940 printf("starting trans2 test\n");
1942 if (!torture_open_connection(&cli)) {
1946 cli_unlink(&cli, fname);
1947 fnum = cli_open(&cli, fname,
1948 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1949 if (!cli_qfileinfo(&cli, fnum, NULL, &size, &c_time, &a_time, &m_time,
1951 printf("ERROR: qfileinfo failed (%s)\n", cli_errstr(&cli));
1955 if (!cli_qfilename(&cli, fnum, pname)) {
1956 printf("ERROR: qfilename failed (%s)\n", cli_errstr(&cli));
1960 if (strcmp(pname, fname)) {
1961 printf("qfilename gave different name? [%s] [%s]\n",
1966 cli_close(&cli, fnum);
1970 cli_unlink(&cli, fname);
1971 fnum = cli_open(&cli, fname,
1972 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1974 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli));
1977 cli_close(&cli, fnum);
1979 if (!cli_qpathinfo(&cli, fname, &c_time, &a_time, &m_time, &size, NULL)) {
1980 printf("ERROR: qpathinfo failed (%s)\n", cli_errstr(&cli));
1983 if (c_time != m_time) {
1984 printf("create time=%s", ctime(&c_time));
1985 printf("modify time=%s", ctime(&m_time));
1986 printf("This system appears to have sticky create times\n");
1989 if (a_time % (60*60) == 0) {
1990 printf("access time=%s", ctime(&a_time));
1991 printf("This system appears to set a midnight access time\n");
1995 if (abs(m_time - time(NULL)) > 60*60*24*7) {
1996 printf("ERROR: totally incorrect times - maybe word reversed? mtime=%s", ctime(&m_time));
2002 cli_unlink(&cli, fname);
2003 fnum = cli_open(&cli, fname,
2004 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2005 cli_close(&cli, fnum);
2006 if (!cli_qpathinfo2(&cli, fname, &c_time, &a_time, &m_time,
2007 &w_time, &size, NULL, NULL)) {
2008 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli));
2011 if (w_time < 60*60*24*2) {
2012 printf("write time=%s", ctime(&w_time));
2013 printf("This system appears to set a initial 0 write time\n");
2018 cli_unlink(&cli, fname);
2021 /* check if the server updates the directory modification time
2022 when creating a new file */
2023 if (!cli_mkdir(&cli, dname)) {
2024 printf("ERROR: mkdir failed (%s)\n", cli_errstr(&cli));
2028 if (!cli_qpathinfo2(&cli, "\\trans2\\", &c_time, &a_time, &m_time,
2029 &w_time, &size, NULL, NULL)) {
2030 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli));
2034 fnum = cli_open(&cli, fname2,
2035 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2036 cli_write(&cli, fnum, 0, (char *)&fnum, 0, sizeof(fnum));
2037 cli_close(&cli, fnum);
2038 if (!cli_qpathinfo2(&cli, "\\trans2\\", &c_time, &a_time, &m_time2,
2039 &w_time, &size, NULL, NULL)) {
2040 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli));
2043 if (m_time2 == m_time) {
2044 printf("This system does not update directory modification times\n");
2048 cli_unlink(&cli, fname2);
2049 cli_rmdir(&cli, dname);
2051 if (!torture_close_connection(&cli)) {
2055 printf("trans2 test finished\n");
2061 This checks new W2K calls.
2064 static BOOL new_trans(struct cli_state *pcli, int fnum, int level)
2067 BOOL correct = True;
2069 memset(buf, 0xff, sizeof(buf));
2071 if (!cli_qfileinfo_test(pcli, fnum, level, buf)) {
2072 printf("ERROR: qfileinfo (%d) failed (%s)\n", level, cli_errstr(pcli));
2075 printf("qfileinfo: level %d\n", level);
2076 dump_data(0, buf, 256);
2082 static BOOL run_w2ktest(int dummy)
2084 static struct cli_state cli;
2086 const char *fname = "\\w2ktest\\w2k.tst";
2088 BOOL correct = True;
2090 printf("starting w2k test\n");
2092 if (!torture_open_connection(&cli)) {
2096 fnum = cli_open(&cli, fname,
2097 O_RDWR | O_CREAT , DENY_NONE);
2099 for (level = 1004; level < 1040; level++) {
2100 new_trans(&cli, fnum, level);
2103 cli_close(&cli, fnum);
2105 if (!torture_close_connection(&cli)) {
2109 printf("w2k test finished\n");
2116 this is a harness for some oplock tests
2118 static BOOL run_oplock1(int dummy)
2120 static struct cli_state cli1;
2121 const char *fname = "\\lockt1.lck";
2123 BOOL correct = True;
2125 printf("starting oplock test 1\n");
2127 if (!torture_open_connection(&cli1)) {
2131 cli_unlink(&cli1, fname);
2133 cli_sockopt(&cli1, sockops);
2135 cli1.use_oplocks = True;
2137 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2139 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2143 cli1.use_oplocks = False;
2145 cli_unlink(&cli1, fname);
2146 cli_unlink(&cli1, fname);
2148 if (!cli_close(&cli1, fnum1)) {
2149 printf("close2 failed (%s)\n", cli_errstr(&cli1));
2153 if (!cli_unlink(&cli1, fname)) {
2154 printf("unlink failed (%s)\n", cli_errstr(&cli1));
2158 if (!torture_close_connection(&cli1)) {
2162 printf("finished oplock test 1\n");
2167 static BOOL run_oplock2(int dummy)
2169 static struct cli_state cli1, cli2;
2170 const char *fname = "\\lockt2.lck";
2172 int saved_use_oplocks = use_oplocks;
2174 BOOL correct = True;
2175 volatile BOOL *shared_correct;
2177 shared_correct = (volatile BOOL *)shm_setup(sizeof(BOOL));
2178 *shared_correct = True;
2180 use_level_II_oplocks = True;
2183 printf("starting oplock test 2\n");
2185 if (!torture_open_connection(&cli1)) {
2186 use_level_II_oplocks = False;
2187 use_oplocks = saved_use_oplocks;
2191 cli1.use_oplocks = True;
2192 cli1.use_level_II_oplocks = True;
2194 if (!torture_open_connection(&cli2)) {
2195 use_level_II_oplocks = False;
2196 use_oplocks = saved_use_oplocks;
2200 cli2.use_oplocks = True;
2201 cli2.use_level_II_oplocks = True;
2203 cli_unlink(&cli1, fname);
2205 cli_sockopt(&cli1, sockops);
2206 cli_sockopt(&cli2, sockops);
2208 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2210 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2214 /* Don't need the globals any more. */
2215 use_level_II_oplocks = False;
2216 use_oplocks = saved_use_oplocks;
2220 fnum2 = cli_open(&cli2, fname, O_RDWR, DENY_NONE);
2222 printf("second open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2223 *shared_correct = False;
2229 if (!cli_close(&cli2, fnum2)) {
2230 printf("close2 failed (%s)\n", cli_errstr(&cli1));
2231 *shared_correct = False;
2239 /* Ensure cli1 processes the break. */
2241 if (cli_read(&cli1, fnum1, buf, 0, 4) != 4) {
2242 printf("read on fnum1 failed (%s)\n", cli_errstr(&cli1));
2246 /* Should now be at level II. */
2247 /* Test if sending a write locks causes a break to none. */
2249 if (!cli_lock(&cli1, fnum1, 0, 4, 0, READ_LOCK)) {
2250 printf("lock failed (%s)\n", cli_errstr(&cli1));
2254 cli_unlock(&cli1, fnum1, 0, 4);
2258 if (!cli_lock(&cli1, fnum1, 0, 4, 0, WRITE_LOCK)) {
2259 printf("lock failed (%s)\n", cli_errstr(&cli1));
2263 cli_unlock(&cli1, fnum1, 0, 4);
2267 cli_read(&cli1, fnum1, buf, 0, 4);
2270 if (cli_write(&cli1, fnum1, 0, buf, 0, 4) != 4) {
2271 printf("write on fnum1 failed (%s)\n", cli_errstr(&cli1));
2276 if (!cli_close(&cli1, fnum1)) {
2277 printf("close1 failed (%s)\n", cli_errstr(&cli1));
2283 if (!cli_unlink(&cli1, fname)) {
2284 printf("unlink failed (%s)\n", cli_errstr(&cli1));
2288 if (!torture_close_connection(&cli1)) {
2292 if (!*shared_correct) {
2296 printf("finished oplock test 2\n");
2301 /* handler for oplock 3 tests */
2302 static BOOL oplock3_handler(struct cli_state *cli, int fnum, unsigned char level)
2304 printf("got oplock break fnum=%d level=%d\n",
2306 return cli_oplock_ack(cli, fnum, level);
2309 static BOOL run_oplock3(int dummy)
2311 static struct cli_state cli;
2312 const char *fname = "\\oplockt3.dat";
2314 char buf[4] = "abcd";
2315 BOOL correct = True;
2316 volatile BOOL *shared_correct;
2318 shared_correct = (volatile BOOL *)shm_setup(sizeof(BOOL));
2319 *shared_correct = True;
2321 printf("starting oplock test 3\n");
2326 use_level_II_oplocks = True;
2327 if (!torture_open_connection(&cli)) {
2328 *shared_correct = False;
2332 /* try to trigger a oplock break in parent */
2333 fnum = cli_open(&cli, fname, O_RDWR, DENY_NONE);
2334 cli_write(&cli, fnum, 0, buf, 0, 4);
2340 use_level_II_oplocks = True;
2341 if (!torture_open_connection(&cli)) {
2344 cli_oplock_handler(&cli, oplock3_handler);
2345 fnum = cli_open(&cli, fname, O_RDWR|O_CREAT, DENY_NONE);
2346 cli_write(&cli, fnum, 0, buf, 0, 4);
2347 cli_close(&cli, fnum);
2348 fnum = cli_open(&cli, fname, O_RDWR, DENY_NONE);
2349 cli.timeout = 20000;
2350 cli_receive_smb(&cli);
2351 printf("finished oplock test 3\n");
2353 return (correct && *shared_correct);
2355 /* What are we looking for here? What's sucess and what's FAILURE? */
2361 Test delete on close semantics.
2363 static BOOL run_deletetest(int dummy)
2365 static struct cli_state cli1;
2366 static struct cli_state cli2;
2367 const char *fname = "\\delete.file";
2370 BOOL correct = True;
2372 printf("starting delete test\n");
2377 if (!torture_open_connection(&cli1)) {
2381 cli_sockopt(&cli1, sockops);
2383 /* Test 1 - this should *NOT* delete the file on close. */
2385 cli_setatr(&cli1, fname, 0, 0);
2386 cli_unlink(&cli1, fname);
2388 fnum1 = cli_nt_create_full(&cli1, fname, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL,
2389 FILE_SHARE_DELETE, FILE_OVERWRITE_IF,
2390 DELETE_ON_CLOSE_FLAG);
2393 printf("[1] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2398 if (!cli_close(&cli1, fnum1)) {
2399 printf("[1] close failed (%s)\n", cli_errstr(&cli1));
2404 fnum1 = cli_open(&cli1, fname, O_RDWR, DENY_NONE);
2406 printf("[1] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2411 if (!cli_close(&cli1, fnum1)) {
2412 printf("[1] close failed (%s)\n", cli_errstr(&cli1));
2417 printf("first delete on close test succeeded.\n");
2419 /* Test 2 - this should delete the file on close. */
2421 cli_setatr(&cli1, fname, 0, 0);
2422 cli_unlink(&cli1, fname);
2424 fnum1 = cli_nt_create_full(&cli1, fname, GENERIC_ALL_ACCESS,
2425 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
2426 FILE_OVERWRITE_IF, 0);
2429 printf("[2] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2434 if (!cli_nt_delete_on_close(&cli1, fnum1, True)) {
2435 printf("[2] setting delete_on_close failed (%s)\n", cli_errstr(&cli1));
2440 if (!cli_close(&cli1, fnum1)) {
2441 printf("[2] close failed (%s)\n", cli_errstr(&cli1));
2446 fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_NONE);
2448 printf("[2] open of %s succeeded should have been deleted on close !\n", fname);
2449 if (!cli_close(&cli1, fnum1)) {
2450 printf("[2] close failed (%s)\n", cli_errstr(&cli1));
2454 cli_unlink(&cli1, fname);
2456 printf("second delete on close test succeeded.\n");
2459 cli_setatr(&cli1, fname, 0, 0);
2460 cli_unlink(&cli1, fname);
2462 fnum1 = cli_nt_create_full(&cli1, fname, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL,
2463 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0);
2466 printf("[3] open - 1 of %s failed (%s)\n", fname, cli_errstr(&cli1));
2471 /* This should fail with a sharing violation - open for delete is only compatible
2472 with SHARE_DELETE. */
2474 fnum2 = cli_nt_create_full(&cli1, fname, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
2475 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0);
2478 printf("[3] open - 2 of %s succeeded - should have failed.\n", fname);
2483 /* This should succeed. */
2485 fnum2 = cli_nt_create_full(&cli1, fname, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
2486 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0);
2489 printf("[3] open - 2 of %s failed (%s)\n", fname, cli_errstr(&cli1));
2494 if (!cli_nt_delete_on_close(&cli1, fnum1, True)) {
2495 printf("[3] setting delete_on_close failed (%s)\n", cli_errstr(&cli1));
2500 if (!cli_close(&cli1, fnum1)) {
2501 printf("[3] close 1 failed (%s)\n", cli_errstr(&cli1));
2506 if (!cli_close(&cli1, fnum2)) {
2507 printf("[3] close 2 failed (%s)\n", cli_errstr(&cli1));
2512 /* This should fail - file should no longer be there. */
2514 fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_NONE);
2516 printf("[3] open of %s succeeded should have been deleted on close !\n", fname);
2517 if (!cli_close(&cli1, fnum1)) {
2518 printf("[3] close failed (%s)\n", cli_errstr(&cli1));
2520 cli_unlink(&cli1, fname);
2524 printf("third delete on close test succeeded.\n");
2527 cli_setatr(&cli1, fname, 0, 0);
2528 cli_unlink(&cli1, fname);
2530 fnum1 = cli_nt_create_full(&cli1, fname, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
2531 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0);
2534 printf("[4] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2539 /* This should succeed. */
2540 fnum2 = cli_nt_create_full(&cli1, fname, GENERIC_READ_ACCESS,
2541 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0);
2543 printf("[4] open - 2 of %s failed (%s)\n", fname, cli_errstr(&cli1));
2548 if (!cli_close(&cli1, fnum2)) {
2549 printf("[4] close - 1 failed (%s)\n", cli_errstr(&cli1));
2554 if (!cli_nt_delete_on_close(&cli1, fnum1, True)) {
2555 printf("[4] setting delete_on_close failed (%s)\n", cli_errstr(&cli1));
2560 /* This should fail - no more opens once delete on close set. */
2561 fnum2 = cli_nt_create_full(&cli1, fname, GENERIC_READ_ACCESS,
2562 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0);
2564 printf("[4] open - 3 of %s succeeded ! Should have failed.\n", fname );
2568 printf("fourth delete on close test succeeded.\n");
2570 if (!cli_close(&cli1, fnum1)) {
2571 printf("[4] close - 2 failed (%s)\n", cli_errstr(&cli1));
2577 cli_setatr(&cli1, fname, 0, 0);
2578 cli_unlink(&cli1, fname);
2580 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT, DENY_NONE);
2582 printf("[5] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2587 /* This should fail - only allowed on NT opens with DELETE access. */
2589 if (cli_nt_delete_on_close(&cli1, fnum1, True)) {
2590 printf("[5] setting delete_on_close on OpenX file succeeded - should fail !\n");
2595 if (!cli_close(&cli1, fnum1)) {
2596 printf("[5] close - 2 failed (%s)\n", cli_errstr(&cli1));
2601 printf("fifth delete on close test succeeded.\n");
2604 cli_setatr(&cli1, fname, 0, 0);
2605 cli_unlink(&cli1, fname);
2607 fnum1 = cli_nt_create_full(&cli1, fname, FILE_READ_DATA|FILE_WRITE_DATA,
2608 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
2609 FILE_OVERWRITE_IF, 0);
2612 printf("[6] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2617 /* This should fail - only allowed on NT opens with DELETE access. */
2619 if (cli_nt_delete_on_close(&cli1, fnum1, True)) {
2620 printf("[6] setting delete_on_close on file with no delete access succeeded - should fail !\n");
2625 if (!cli_close(&cli1, fnum1)) {
2626 printf("[6] close - 2 failed (%s)\n", cli_errstr(&cli1));
2631 printf("sixth delete on close test succeeded.\n");
2634 cli_setatr(&cli1, fname, 0, 0);
2635 cli_unlink(&cli1, fname);
2637 fnum1 = cli_nt_create_full(&cli1, fname, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
2638 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF, 0);
2641 printf("[7] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2646 if (!cli_nt_delete_on_close(&cli1, fnum1, True)) {
2647 printf("[7] setting delete_on_close on file failed !\n");
2652 if (!cli_nt_delete_on_close(&cli1, fnum1, False)) {
2653 printf("[7] unsetting delete_on_close on file failed !\n");
2658 if (!cli_close(&cli1, fnum1)) {
2659 printf("[7] close - 2 failed (%s)\n", cli_errstr(&cli1));
2664 /* This next open should succeed - we reset the flag. */
2666 fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_NONE);
2668 printf("[5] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2673 if (!cli_close(&cli1, fnum1)) {
2674 printf("[7] close - 2 failed (%s)\n", cli_errstr(&cli1));
2679 printf("seventh delete on close test succeeded.\n");
2682 cli_setatr(&cli1, fname, 0, 0);
2683 cli_unlink(&cli1, fname);
2685 if (!torture_open_connection(&cli2)) {
2686 printf("[8] failed to open second connection.\n");
2691 cli_sockopt(&cli1, sockops);
2693 fnum1 = cli_nt_create_full(&cli1, fname, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
2694 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0);
2697 printf("[8] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2702 fnum2 = cli_nt_create_full(&cli2, fname, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
2703 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0);
2706 printf("[8] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2711 if (!cli_nt_delete_on_close(&cli1, fnum1, True)) {
2712 printf("[8] setting delete_on_close on file failed !\n");
2717 if (!cli_close(&cli1, fnum1)) {
2718 printf("[8] close - 1 failed (%s)\n", cli_errstr(&cli1));
2723 if (!cli_close(&cli2, fnum2)) {
2724 printf("[8] close - 2 failed (%s)\n", cli_errstr(&cli2));
2729 /* This should fail.. */
2730 fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_NONE);
2732 printf("[8] open of %s succeeded should have been deleted on close !\n", fname);
2736 printf("eighth delete on close test succeeded.\n");
2738 /* This should fail - we need to set DELETE_ACCESS. */
2739 fnum1 = cli_nt_create_full(&cli1, fname, FILE_READ_DATA|FILE_WRITE_DATA,
2740 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, FILE_OVERWRITE_IF, FILE_DELETE_ON_CLOSE);
2743 printf("[9] open of %s succeeded should have failed!\n", fname);
2748 printf("ninth delete on close test succeeded.\n");
2750 fnum1 = cli_nt_create_full(&cli1, fname, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
2751 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, FILE_OVERWRITE_IF, FILE_DELETE_ON_CLOSE);
2753 printf("[10] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2758 /* This should delete the file. */
2759 if (!cli_close(&cli1, fnum1)) {
2760 printf("[10] close failed (%s)\n", cli_errstr(&cli1));
2765 /* This should fail.. */
2766 fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_NONE);
2768 printf("[10] open of %s succeeded should have been deleted on close !\n", fname);
2772 printf("tenth delete on close test succeeded.\n");
2773 printf("finished delete test\n");
2777 cli_close(&cli1, fnum1);
2778 cli_close(&cli1, fnum2);
2779 cli_setatr(&cli1, fname, 0, 0);
2780 cli_unlink(&cli1, fname);
2782 if (!torture_close_connection(&cli1)) {
2785 if (!torture_close_connection(&cli2)) {
2793 print out server properties
2795 static BOOL run_properties(int dummy)
2797 static struct cli_state cli;
2798 BOOL correct = True;
2800 printf("starting properties test\n");
2804 if (!torture_open_connection(&cli)) {
2808 cli_sockopt(&cli, sockops);
2810 d_printf("Capabilities 0x%08x\n", cli.capabilities);
2812 if (!torture_close_connection(&cli)) {
2821 /* FIRST_DESIRED_ACCESS 0xf019f */
2822 #define FIRST_DESIRED_ACCESS FILE_READ_DATA|FILE_WRITE_DATA|FILE_APPEND_DATA|\
2823 FILE_READ_EA| /* 0xf */ \
2824 FILE_WRITE_EA|FILE_READ_ATTRIBUTES| /* 0x90 */ \
2825 FILE_WRITE_ATTRIBUTES| /* 0x100 */ \
2826 DELETE_ACCESS|READ_CONTROL_ACCESS|\
2827 WRITE_DAC_ACCESS|WRITE_OWNER_ACCESS /* 0xf0000 */
2828 /* SECOND_DESIRED_ACCESS 0xe0080 */
2829 #define SECOND_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
2830 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
2831 WRITE_OWNER_ACCESS /* 0xe0000 */
2834 #define THIRD_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
2835 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
2837 WRITE_OWNER_ACCESS /* */
2841 Test ntcreate calls made by xcopy
2843 static BOOL run_xcopy(int dummy)
2845 static struct cli_state cli1;
2846 const char *fname = "\\test.txt";
2847 BOOL correct = True;
2850 printf("starting xcopy test\n");
2852 if (!torture_open_connection(&cli1)) {
2856 fnum1 = cli_nt_create_full(&cli1, fname,
2857 FIRST_DESIRED_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
2858 FILE_SHARE_NONE, FILE_OVERWRITE_IF,
2862 printf("First open failed - %s\n", cli_errstr(&cli1));
2866 fnum2 = cli_nt_create_full(&cli1, fname,
2867 SECOND_DESIRED_ACCESS, 0,
2868 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN,
2871 printf("second open failed - %s\n", cli_errstr(&cli1));
2875 if (!torture_close_connection(&cli1)) {
2883 Test rename on files open with share delete and no share delete.
2885 static BOOL run_rename(int dummy)
2887 static struct cli_state cli1;
2888 const char *fname = "\\test.txt";
2889 const char *fname1 = "\\test1.txt";
2890 BOOL correct = True;
2893 printf("starting rename test\n");
2895 if (!torture_open_connection(&cli1)) {
2899 cli_unlink(&cli1, fname);
2900 cli_unlink(&cli1, fname1);
2901 fnum1 = cli_nt_create_full(&cli1, fname, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
2902 FILE_SHARE_READ, FILE_OVERWRITE_IF, 0);
2905 printf("First open failed - %s\n", cli_errstr(&cli1));
2909 if (!cli_rename(&cli1, fname, fname1)) {
2910 printf("First rename failed (this is correct) - %s\n", cli_errstr(&cli1));
2912 printf("First rename succeeded - this should have failed !\n");
2916 if (!cli_close(&cli1, fnum1)) {
2917 printf("close - 1 failed (%s)\n", cli_errstr(&cli1));
2921 cli_unlink(&cli1, fname);
2922 cli_unlink(&cli1, fname1);
2923 fnum1 = cli_nt_create_full(&cli1, fname,GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
2925 FILE_SHARE_DELETE|FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0);
2927 FILE_SHARE_DELETE|FILE_SHARE_READ, FILE_OVERWRITE_IF, 0);
2931 printf("Second open failed - %s\n", cli_errstr(&cli1));
2935 if (!cli_rename(&cli1, fname, fname1)) {
2936 printf("Second rename failed - this should have succeeded - %s\n", cli_errstr(&cli1));
2939 printf("Second rename succeeded\n");
2942 if (!cli_close(&cli1, fnum1)) {
2943 printf("close - 2 failed (%s)\n", cli_errstr(&cli1));
2947 cli_unlink(&cli1, fname);
2948 cli_unlink(&cli1, fname1);
2950 fnum1 = cli_nt_create_full(&cli1, fname,READ_CONTROL_ACCESS, FILE_ATTRIBUTE_NORMAL,
2951 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0);
2954 printf("Third open failed - %s\n", cli_errstr(&cli1));
2963 fnum2 = cli_nt_create_full(&cli1, fname,DELETE_ACCESS, FILE_ATTRIBUTE_NORMAL,
2964 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0);
2967 printf("Fourth open failed - %s\n", cli_errstr(&cli1));
2970 if (!cli_nt_delete_on_close(&cli1, fnum2, True)) {
2971 printf("[8] setting delete_on_close on file failed !\n");
2975 if (!cli_close(&cli1, fnum2)) {
2976 printf("close - 4 failed (%s)\n", cli_errstr(&cli1));
2982 if (!cli_rename(&cli1, fname, fname1)) {
2983 printf("Third rename failed - this should have succeeded - %s\n", cli_errstr(&cli1));
2986 printf("Third rename succeeded\n");
2989 if (!cli_close(&cli1, fnum1)) {
2990 printf("close - 3 failed (%s)\n", cli_errstr(&cli1));
2994 cli_unlink(&cli1, fname);
2995 cli_unlink(&cli1, fname1);
2997 if (!torture_close_connection(&cli1)) {
3004 static BOOL run_pipe_number(int dummy)
3006 static struct cli_state cli1;
3007 const char *pipe_name = "\\SPOOLSS";
3011 printf("starting pipenumber test\n");
3012 if (!torture_open_connection(&cli1)) {
3016 cli_sockopt(&cli1, sockops);
3018 fnum = cli_nt_create_full(&cli1, pipe_name,FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
3019 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN_IF, 0);
3022 printf("Open of pipe %s failed with error (%s)\n", pipe_name, cli_errstr(&cli1));
3028 printf("pipe_number test - we can open %d %s pipes.\n", num_pipes, pipe_name );
3029 torture_close_connection(&cli1);
3034 Test open mode returns on read-only files.
3036 static BOOL run_opentest(int dummy)
3038 static struct cli_state cli1;
3039 static struct cli_state cli2;
3040 const char *fname = "\\readonly.file";
3044 BOOL correct = True;
3048 printf("starting open test\n");
3050 if (!torture_open_connection(&cli1)) {
3054 cli_setatr(&cli1, fname, 0, 0);
3055 cli_unlink(&cli1, fname);
3057 cli_sockopt(&cli1, sockops);
3059 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
3061 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
3065 if (!cli_close(&cli1, fnum1)) {
3066 printf("close2 failed (%s)\n", cli_errstr(&cli1));
3070 if (!cli_setatr(&cli1, fname, aRONLY, 0)) {
3071 printf("cli_setatr failed (%s)\n", cli_errstr(&cli1));
3075 fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_WRITE);
3077 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
3081 /* This will fail - but the error should be ERRnoaccess, not ERRbadshare. */
3082 fnum2 = cli_open(&cli1, fname, O_RDWR, DENY_ALL);
3084 if (check_error(__LINE__, &cli1, ERRDOS, ERRnoaccess,
3085 NT_STATUS_ACCESS_DENIED)) {
3086 printf("correct error code ERRDOS/ERRnoaccess returned\n");
3089 printf("finished open test 1\n");
3091 cli_close(&cli1, fnum1);
3093 /* Now try not readonly and ensure ERRbadshare is returned. */
3095 cli_setatr(&cli1, fname, 0, 0);
3097 fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_WRITE);
3099 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
3103 /* This will fail - but the error should be ERRshare. */
3104 fnum2 = cli_open(&cli1, fname, O_RDWR, DENY_ALL);
3106 if (check_error(__LINE__, &cli1, ERRDOS, ERRbadshare,
3107 NT_STATUS_SHARING_VIOLATION)) {
3108 printf("correct error code ERRDOS/ERRbadshare returned\n");
3111 if (!cli_close(&cli1, fnum1)) {
3112 printf("close2 failed (%s)\n", cli_errstr(&cli1));
3116 cli_unlink(&cli1, fname);
3118 printf("finished open test 2\n");
3120 /* Test truncate open disposition on file opened for read. */
3122 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
3124 printf("(3) open (1) of %s failed (%s)\n", fname, cli_errstr(&cli1));
3128 /* write 20 bytes. */
3130 memset(buf, '\0', 20);
3132 if (cli_write(&cli1, fnum1, 0, buf, 0, 20) != 20) {
3133 printf("write failed (%s)\n", cli_errstr(&cli1));
3137 if (!cli_close(&cli1, fnum1)) {
3138 printf("(3) close1 failed (%s)\n", cli_errstr(&cli1));
3142 /* Ensure size == 20. */
3143 if (!cli_getatr(&cli1, fname, NULL, &fsize, NULL)) {
3144 printf("(3) getatr failed (%s)\n", cli_errstr(&cli1));
3149 printf("(3) file size != 20\n");
3153 /* Now test if we can truncate a file opened for readonly. */
3155 fnum1 = cli_open(&cli1, fname, O_RDONLY|O_TRUNC, DENY_NONE);
3157 printf("(3) open (2) of %s failed (%s)\n", fname, cli_errstr(&cli1));
3161 if (!cli_close(&cli1, fnum1)) {
3162 printf("close2 failed (%s)\n", cli_errstr(&cli1));
3166 /* Ensure size == 0. */
3167 if (!cli_getatr(&cli1, fname, NULL, &fsize, NULL)) {
3168 printf("(3) getatr failed (%s)\n", cli_errstr(&cli1));
3173 printf("(3) file size != 0\n");
3176 printf("finished open test 3\n");
3178 cli_unlink(&cli1, fname);
3181 printf("testing ctemp\n");
3182 fnum1 = cli_ctemp(&cli1, "\\", &tmp_path);
3184 printf("ctemp failed (%s)\n", cli_errstr(&cli1));
3187 printf("ctemp gave path %s\n", tmp_path);
3188 if (!cli_close(&cli1, fnum1)) {
3189 printf("close of temp failed (%s)\n", cli_errstr(&cli1));
3191 if (!cli_unlink(&cli1, tmp_path)) {
3192 printf("unlink of temp failed (%s)\n", cli_errstr(&cli1));
3195 /* Test the non-io opens... */
3197 if (!torture_open_connection(&cli2)) {
3201 cli_setatr(&cli2, fname, 0, 0);
3202 cli_unlink(&cli2, fname);
3204 cli_sockopt(&cli2, sockops);
3206 printf("TEST #1 testing 2 non-io opens (no delete)\n");
3208 fnum1 = cli_nt_create_full(&cli1, fname,FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3209 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0);
3212 printf("test 1 open 1 of %s failed (%s)\n", fname, cli_errstr(&cli1));
3216 fnum2 = cli_nt_create_full(&cli2, fname,FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3217 FILE_SHARE_NONE, FILE_OPEN_IF, 0);
3220 printf("test 1 open 2 of %s failed (%s)\n", fname, cli_errstr(&cli2));
3224 if (!cli_close(&cli1, fnum1)) {
3225 printf("test 1 close 1 of %s failed (%s)\n", fname, cli_errstr(&cli1));
3228 if (!cli_close(&cli2, fnum2)) {
3229 printf("test 1 close 2 of %s failed (%s)\n", fname, cli_errstr(&cli2));
3233 printf("non-io open test #1 passed.\n");
3235 cli_unlink(&cli1, fname);
3237 printf("TEST #2 testing 2 non-io opens (first with delete)\n");
3239 fnum1 = cli_nt_create_full(&cli1, fname,DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3240 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0);
3243 printf("test 2 open 1 of %s failed (%s)\n", fname, cli_errstr(&cli1));
3247 fnum2 = cli_nt_create_full(&cli2, fname,FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3248 FILE_SHARE_NONE, FILE_OPEN_IF, 0);
3251 printf("test 2 open 2 of %s failed (%s)\n", fname, cli_errstr(&cli2));
3255 if (!cli_close(&cli1, fnum1)) {
3256 printf("test 1 close 1 of %s failed (%s)\n", fname, cli_errstr(&cli1));
3259 if (!cli_close(&cli2, fnum2)) {
3260 printf("test 1 close 2 of %s failed (%s)\n", fname, cli_errstr(&cli1));
3264 printf("non-io open test #2 passed.\n");
3266 cli_unlink(&cli1, fname);
3268 printf("TEST #3 testing 2 non-io opens (second with delete)\n");
3270 fnum1 = cli_nt_create_full(&cli1, fname,FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3271 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0);
3274 printf("test 3 open 1 of %s failed (%s)\n", fname, cli_errstr(&cli1));
3278 fnum2 = cli_nt_create_full(&cli2, fname,DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3279 FILE_SHARE_NONE, FILE_OPEN_IF, 0);
3282 printf("test 3 open 2 of %s failed (%s)\n", fname, cli_errstr(&cli2));
3286 if (!cli_close(&cli1, fnum1)) {
3287 printf("test 3 close 1 of %s failed (%s)\n", fname, cli_errstr(&cli1));
3290 if (!cli_close(&cli2, fnum2)) {
3291 printf("test 3 close 2 of %s failed (%s)\n", fname, cli_errstr(&cli2));
3295 printf("non-io open test #3 passed.\n");
3297 cli_unlink(&cli1, fname);
3299 printf("TEST #4 testing 2 non-io opens (both with delete)\n");
3301 fnum1 = cli_nt_create_full(&cli1, fname,DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3302 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0);
3305 printf("test 4 open 1 of %s failed (%s)\n", fname, cli_errstr(&cli1));
3309 fnum2 = cli_nt_create_full(&cli2, fname,DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3310 FILE_SHARE_NONE, FILE_OPEN_IF, 0);
3313 printf("test 4 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, cli_errstr(&cli2));
3317 printf("test 3 open 2 of %s gave %s (correct error should be %s)\n", fname, cli_errstr(&cli2), "sharing violation");
3319 if (!cli_close(&cli1, fnum1)) {
3320 printf("test 4 close 1 of %s failed (%s)\n", fname, cli_errstr(&cli1));
3324 printf("non-io open test #4 passed.\n");
3326 cli_unlink(&cli1, fname);
3328 printf("TEST #5 testing 2 non-io opens (both with delete - both with file share delete)\n");
3330 fnum1 = cli_nt_create_full(&cli1, fname,DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3331 FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0);
3334 printf("test 5 open 1 of %s failed (%s)\n", fname, cli_errstr(&cli1));
3338 fnum2 = cli_nt_create_full(&cli2, fname,DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3339 FILE_SHARE_DELETE, FILE_OPEN_IF, 0);
3342 printf("test 5 open 2 of %s failed (%s)\n", fname, cli_errstr(&cli2));
3346 if (!cli_close(&cli1, fnum1)) {
3347 printf("test 5 close 1 of %s failed (%s)\n", fname, cli_errstr(&cli1));
3351 if (!cli_close(&cli2, fnum2)) {
3352 printf("test 5 close 2 of %s failed (%s)\n", fname, cli_errstr(&cli2));
3356 printf("non-io open test #5 passed.\n");
3358 printf("TEST #6 testing 1 non-io open, one io open\n");
3360 cli_unlink(&cli1, fname);
3362 fnum1 = cli_nt_create_full(&cli1, fname,FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
3363 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0);
3366 printf("test 6 open 1 of %s failed (%s)\n", fname, cli_errstr(&cli1));
3370 fnum2 = cli_nt_create_full(&cli2, fname,FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3371 FILE_SHARE_READ, FILE_OPEN_IF, 0);
3374 printf("test 6 open 2 of %s failed (%s)\n", fname, cli_errstr(&cli2));
3378 if (!cli_close(&cli1, fnum1)) {
3379 printf("test 6 close 1 of %s failed (%s)\n", fname, cli_errstr(&cli1));
3383 if (!cli_close(&cli2, fnum2)) {
3384 printf("test 6 close 2 of %s failed (%s)\n", fname, cli_errstr(&cli2));
3388 printf("non-io open test #6 passed.\n");
3390 printf("TEST #7 testing 1 non-io open, one io open with delete\n");
3392 cli_unlink(&cli1, fname);
3394 fnum1 = cli_nt_create_full(&cli1, fname,FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
3395 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0);
3398 printf("test 7 open 1 of %s failed (%s)\n", fname, cli_errstr(&cli1));
3402 fnum2 = cli_nt_create_full(&cli2, fname,DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3403 FILE_SHARE_READ|FILE_SHARE_DELETE, FILE_OPEN_IF, 0);
3406 printf("test 7 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, cli_errstr(&cli2));
3410 printf("test 7 open 2 of %s gave %s (correct error should be %s)\n", fname, cli_errstr(&cli2), "sharing violation");
3412 if (!cli_close(&cli1, fnum1)) {
3413 printf("test 7 close 1 of %s failed (%s)\n", fname, cli_errstr(&cli1));
3417 printf("non-io open test #7 passed.\n");
3419 cli_unlink(&cli1, fname);
3421 /* Test 8 - attributes test #1... */
3422 fnum1 = cli_nt_create_full(&cli1, fname,FILE_WRITE_DATA, FILE_ATTRIBUTE_HIDDEN,
3423 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0);
3426 printf("test 8 open 1 of %s failed (%s)\n", fname, cli_errstr(&cli1));
3430 if (!cli_close(&cli1, fnum1)) {
3431 printf("test 8 close 1 of %s failed (%s)\n", fname, cli_errstr(&cli1));
3435 /* FILE_SUPERSEDE && FILE_OVERWRITE_IF have the same effect here. */
3436 fnum1 = cli_nt_create_full(&cli1, fname,FILE_READ_DATA, FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_NORMAL,
3437 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0);
3440 printf("test 8 open 2 of %s failed (%s)\n", fname, cli_errstr(&cli1));
3444 if (!cli_close(&cli1, fnum1)) {
3445 printf("test 8 close 2 of %s failed (%s)\n", fname, cli_errstr(&cli1));
3449 /* This open should fail with ACCESS_DENIED for FILE_SUPERSEDE, FILE_OVERWRITE and FILE_OVERWRITE_IF. */
3450 fnum1 = cli_nt_create_full(&cli1, fname,FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
3451 FILE_SHARE_NONE, FILE_OVERWRITE, 0);
3454 printf("test 8 open 3 of %s succeeded - should have failed with (NT_STATUS_ACCESS_DENIED)\n", fname);
3456 cli_close(&cli1, fnum1);
3458 if (check_error(__LINE__, &cli1, ERRDOS, ERRnoaccess, NT_STATUS_ACCESS_DENIED)) {
3459 printf("correct error code NT_STATUS_ACCESS_DENIED/ERRDOS:ERRnoaccess returned\n");
3463 printf("Attribute open test #8 %s.\n", correct ? "passed" : "failed");
3465 cli_unlink(&cli1, fname);
3468 * Test #9. Open with NORMAL, close, then re-open with attribute
3469 * HIDDEN and request to truncate.
3472 fnum1 = cli_nt_create_full(&cli1, fname,FILE_WRITE_DATA, FILE_ATTRIBUTE_NORMAL,
3473 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0);
3476 printf("test 9 open 1 of %s failed (%s)\n", fname, cli_errstr(&cli1));
3480 if (!cli_close(&cli1, fnum1)) {
3481 printf("test 9 close 1 of %s failed (%s)\n", fname, cli_errstr(&cli1));
3485 fnum1 = cli_nt_create_full(&cli1, fname,FILE_READ_DATA|FILE_WRITE_DATA, FILE_ATTRIBUTE_HIDDEN,
3486 FILE_SHARE_NONE, FILE_OVERWRITE, 0);
3489 printf("test 9 open 2 of %s failed (%s)\n", fname, cli_errstr(&cli1));
3493 if (!cli_close(&cli1, fnum1)) {
3494 printf("test 9 close 2 of %s failed (%s)\n", fname, cli_errstr(&cli1));
3498 /* Ensure we have attr hidden. */
3499 if (!cli_getatr(&cli1, fname, &attr, NULL, NULL)) {
3500 printf("test 9 getatr(2) failed (%s)\n", cli_errstr(&cli1));
3504 if (!(attr & FILE_ATTRIBUTE_HIDDEN)) {
3505 printf("test 9 getatr didn't have HIDDEN attribute\n");
3506 cli_unlink(&cli1, fname);
3510 printf("Attribute open test #9 %s.\n", correct ? "passed" : "failed");
3512 cli_unlink(&cli1, fname);
3514 if (!torture_close_connection(&cli1)) {
3517 if (!torture_close_connection(&cli2)) {
3524 static void list_fn(file_info *finfo, const char *name, void *state)
3530 test directory listing speed
3532 static BOOL run_dirtest(int dummy)
3535 static struct cli_state cli;
3538 BOOL correct = True;
3540 printf("starting directory test\n");
3542 if (!torture_open_connection(&cli)) {
3546 cli_sockopt(&cli, sockops);
3549 for (i=0;i<torture_numops;i++) {
3551 slprintf(fname, sizeof(fname), "\\%x", (int)random());
3552 fnum = cli_open(&cli, fname, O_RDWR|O_CREAT, DENY_NONE);
3554 fprintf(stderr,"Failed to open %s\n", fname);
3557 cli_close(&cli, fnum);
3562 printf("Matched %d\n", cli_list(&cli, "a*.*", 0, list_fn, NULL));
3563 printf("Matched %d\n", cli_list(&cli, "b*.*", 0, list_fn, NULL));
3564 printf("Matched %d\n", cli_list(&cli, "xyzabc", 0, list_fn, NULL));
3566 printf("dirtest core %g seconds\n", end_timer() - t1);
3569 for (i=0;i<torture_numops;i++) {
3571 slprintf(fname, sizeof(fname), "\\%x", (int)random());
3572 cli_unlink(&cli, fname);
3575 if (!torture_close_connection(&cli)) {
3579 printf("finished dirtest\n");
3584 static void del_fn(file_info *finfo, const char *mask, void *state)
3586 struct cli_state *pcli = (struct cli_state *)state;
3588 slprintf(fname, sizeof(fname), "\\LISTDIR\\%s", finfo->name);
3590 if (strcmp(finfo->name, ".") == 0 || strcmp(finfo->name, "..") == 0)
3593 if (finfo->mode & aDIR) {
3594 if (!cli_rmdir(pcli, fname))
3595 printf("del_fn: failed to rmdir %s\n,", fname );
3597 if (!cli_unlink(pcli, fname))
3598 printf("del_fn: failed to unlink %s\n,", fname );
3602 static BOOL run_dirtest1(int dummy)
3605 static struct cli_state cli;
3607 BOOL correct = True;
3609 printf("starting directory test\n");
3611 if (!torture_open_connection(&cli)) {
3615 cli_sockopt(&cli, sockops);
3617 cli_list(&cli, "\\LISTDIR\\*", 0, del_fn, &cli);
3618 cli_list(&cli, "\\LISTDIR\\*", aDIR, del_fn, &cli);
3619 cli_rmdir(&cli, "\\LISTDIR");
3620 cli_mkdir(&cli, "\\LISTDIR");
3622 /* Create 1000 files and 1000 directories. */
3623 for (i=0;i<1000;i++) {
3625 slprintf(fname, sizeof(fname), "\\LISTDIR\\f%d", i);
3626 fnum = cli_nt_create_full(&cli, fname, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
3627 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0);
3629 fprintf(stderr,"Failed to open %s\n", fname);
3632 cli_close(&cli, fnum);
3634 for (i=0;i<1000;i++) {
3636 slprintf(fname, sizeof(fname), "\\LISTDIR\\d%d", i);
3637 if (!cli_mkdir(&cli, fname)) {
3638 fprintf(stderr,"Failed to open %s\n", fname);
3643 /* Now ensure that doing an old list sees both files and directories. */
3644 num_seen = cli_list_old(&cli, "\\LISTDIR\\*", aDIR, list_fn, NULL);
3645 printf("num_seen = %d\n", num_seen );
3646 /* We should see 100 files + 1000 directories + . and .. */
3647 if (num_seen != 2002)
3650 /* Ensure if we have the "must have" bits we only see the
3653 num_seen = cli_list_old(&cli, "\\LISTDIR\\*", (aDIR<<8)|aDIR, list_fn, NULL);
3654 printf("num_seen = %d\n", num_seen );
3655 if (num_seen != 1002)
3658 num_seen = cli_list_old(&cli, "\\LISTDIR\\*", (aARCH<<8)|aDIR, list_fn, NULL);
3659 printf("num_seen = %d\n", num_seen );
3660 if (num_seen != 1000)
3663 /* Delete everything. */
3664 cli_list(&cli, "\\LISTDIR\\*", 0, del_fn, &cli);
3665 cli_list(&cli, "\\LISTDIR\\*", aDIR, del_fn, &cli);
3666 cli_rmdir(&cli, "\\LISTDIR");
3669 printf("Matched %d\n", cli_list(&cli, "a*.*", 0, list_fn, NULL));
3670 printf("Matched %d\n", cli_list(&cli, "b*.*", 0, list_fn, NULL));
3671 printf("Matched %d\n", cli_list(&cli, "xyzabc", 0, list_fn, NULL));
3674 if (!torture_close_connection(&cli)) {
3678 printf("finished dirtest1\n");
3683 static BOOL run_error_map_extract(int dummy) {
3685 static struct cli_state c_dos;
3686 static struct cli_state c_nt;
3690 uint32 flgs2, errnum;
3697 /* NT-Error connection */
3699 if (!open_nbt_connection(&c_nt)) {
3703 c_nt.use_spnego = False;
3705 if (!cli_negprot(&c_nt)) {
3706 printf("%s rejected the NT-error negprot (%s)\n",host, cli_errstr(&c_nt));
3707 cli_shutdown(&c_nt);
3711 if (!cli_session_setup(&c_nt, "", "", 0, "", 0,
3713 printf("%s rejected the NT-error initial session setup (%s)\n",host, cli_errstr(&c_nt));
3717 /* DOS-Error connection */
3719 if (!open_nbt_connection(&c_dos)) {
3723 c_dos.use_spnego = False;
3724 c_dos.force_dos_errors = True;
3726 if (!cli_negprot(&c_dos)) {
3727 printf("%s rejected the DOS-error negprot (%s)\n",host, cli_errstr(&c_dos));
3728 cli_shutdown(&c_dos);
3732 if (!cli_session_setup(&c_dos, "", "", 0, "", 0,
3734 printf("%s rejected the DOS-error initial session setup (%s)\n",host, cli_errstr(&c_dos));
3738 for (error=(0xc0000000 | 0x1); error < (0xc0000000| 0xFFF); error++) {
3739 snprintf(user, sizeof(user), "%X", error);
3741 if (cli_session_setup(&c_nt, user,
3742 password, strlen(password),
3743 password, strlen(password),
3745 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
3748 flgs2 = SVAL(c_nt.inbuf,smb_flg2);
3750 /* Case #1: 32-bit NT errors */
3751 if (flgs2 & FLAGS2_32_BIT_ERROR_CODES) {
3752 nt_status = NT_STATUS(IVAL(c_nt.inbuf,smb_rcls));
3754 printf("/** Dos error on NT connection! (%s) */\n",
3756 nt_status = NT_STATUS(0xc0000000);
3759 if (cli_session_setup(&c_dos, user,
3760 password, strlen(password),
3761 password, strlen(password),
3763 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
3765 flgs2 = SVAL(c_dos.inbuf,smb_flg2), errnum;
3767 /* Case #1: 32-bit NT errors */
3768 if (flgs2 & FLAGS2_32_BIT_ERROR_CODES) {
3769 printf("/** NT error on DOS connection! (%s) */\n",
3771 errnum = errclass = 0;
3773 cli_dos_error(&c_dos, &errclass, &errnum);
3776 if (NT_STATUS_V(nt_status) != error) {
3777 printf("/*\t{ This NT error code was 'sqashed'\n\t from %s to %s \n\t during the session setup }\n*/\n",
3778 get_nt_error_c_code(NT_STATUS(error)),
3779 get_nt_error_c_code(nt_status));
3782 printf("\t{%s,\t%s,\t%s},\n",
3783 smb_dos_err_class(errclass),
3784 smb_dos_err_name(errclass, errnum),
3785 get_nt_error_c_code(NT_STATUS(error)));
3790 static double create_procs(BOOL (*fn)(int), BOOL *result)
3793 volatile pid_t *child_status;
3794 volatile BOOL *child_status_out;
3800 child_status = (volatile pid_t *)shm_setup(sizeof(pid_t)*nprocs);
3801 if (!child_status) {
3802 printf("Failed to setup shared memory\n");
3806 child_status_out = (volatile BOOL *)shm_setup(sizeof(BOOL)*nprocs);
3807 if (!child_status_out) {
3808 printf("Failed to setup result status shared memory\n");
3812 for (i = 0; i < nprocs; i++) {
3813 child_status[i] = 0;
3814 child_status_out[i] = True;
3819 for (i=0;i<nprocs;i++) {
3822 pid_t mypid = getpid();
3823 sys_srandom(((int)mypid) ^ ((int)time(NULL)));
3825 slprintf(myname,sizeof(myname),"CLIENT%d", i);
3828 memset(¤t_cli, 0, sizeof(current_cli));
3829 if (torture_open_connection(¤t_cli)) break;
3831 printf("pid %d failed to start\n", (int)getpid());
3837 child_status[i] = getpid();
3839 while (child_status[i] && end_timer() < 5) msleep(2);
3841 child_status_out[i] = fn(i);
3848 for (i=0;i<nprocs;i++) {
3849 if (child_status[i]) synccount++;
3851 if (synccount == nprocs) break;
3853 } while (end_timer() < 30);
3855 if (synccount != nprocs) {
3856 printf("FAILED TO START %d CLIENTS (started %d)\n", nprocs, synccount);
3861 /* start the client load */
3864 for (i=0;i<nprocs;i++) {
3865 child_status[i] = 0;
3868 printf("%d clients started\n", nprocs);
3870 for (i=0;i<nprocs;i++) {
3871 while (waitpid(0, &status, 0) == -1 && errno == EINTR) /* noop */ ;
3876 for (i=0;i<nprocs;i++) {
3877 if (!child_status_out[i]) {
3884 #define FLAG_MULTIPROC 1
3891 {"FDPASS", run_fdpasstest, 0},
3892 {"LOCK1", run_locktest1, 0},
3893 {"LOCK2", run_locktest2, 0},
3894 {"LOCK3", run_locktest3, 0},
3895 {"LOCK4", run_locktest4, 0},
3896 {"LOCK5", run_locktest5, 0},
3897 {"LOCK6", run_locktest6, 0},
3898 {"UNLINK", run_unlinktest, 0},
3899 {"BROWSE", run_browsetest, 0},
3900 {"ATTR", run_attrtest, 0},
3901 {"TRANS2", run_trans2test, 0},
3902 {"MAXFID", run_maxfidtest, FLAG_MULTIPROC},
3903 {"TORTURE",run_torture, FLAG_MULTIPROC},
3904 {"RANDOMIPC", run_randomipc, 0},
3905 {"NEGNOWAIT", run_negprot_nowait, 0},
3906 {"NBENCH", run_nbench, 0},
3907 {"OPLOCK1", run_oplock1, 0},
3908 {"OPLOCK2", run_oplock2, 0},
3909 {"OPLOCK3", run_oplock3, 0},
3910 {"DIR", run_dirtest, 0},
3911 {"DIR1", run_dirtest1, 0},
3912 {"DENY1", torture_denytest1, 0},
3913 {"DENY2", torture_denytest2, 0},
3914 {"TCON", run_tcon_test, 0},
3915 {"RW1", run_readwritetest, 0},
3916 {"RW2", run_readwritemulti, FLAG_MULTIPROC},
3917 {"RW3", run_readwritelarge, 0},
3918 {"OPEN", run_opentest, 0},
3919 {"XCOPY", run_xcopy, 0},
3920 {"RENAME", run_rename, 0},
3921 {"DELETE", run_deletetest, 0},
3922 {"PROPERTIES", run_properties, 0},
3923 {"MANGLE", torture_mangle, 0},
3924 {"W2K", run_w2ktest, 0},
3925 {"TRANS2SCAN", torture_trans2_scan, 0},
3926 {"NTTRANSSCAN", torture_nttrans_scan, 0},
3927 {"UTABLE", torture_utable, 0},
3928 {"CASETABLE", torture_casetable, 0},
3929 {"ERRMAPEXTRACT", run_error_map_extract, 0},
3930 {"PIPE_NUMBER", run_pipe_number, 0},
3935 /****************************************************************************
3936 run a specified test or "ALL"
3937 ****************************************************************************/
3938 static BOOL run_test(const char *name)
3944 if (strequal(name,"ALL")) {
3945 for (i=0;torture_ops[i].name;i++) {
3946 run_test(torture_ops[i].name);
3950 for (i=0;torture_ops[i].name;i++) {
3951 snprintf(randomfname, sizeof(randomfname), "\\XX%x",
3952 (unsigned)random());
3954 if (strequal(name, torture_ops[i].name)) {
3955 printf("Running %s\n", name);
3956 if (torture_ops[i].flags & FLAG_MULTIPROC) {
3957 t = create_procs(torture_ops[i].fn, &result);
3960 printf("TEST %s FAILED!\n", name);
3965 if (!torture_ops[i].fn(0)) {
3967 printf("TEST %s FAILED!\n", name);
3971 printf("%s took %g secs\n\n", name, t);
3978 static void usage(void)
3982 printf("Usage: smbtorture //server/share <options> TEST1 TEST2 ...\n");
3984 printf("\t-d debuglevel\n");
3985 printf("\t-U user%%pass\n");
3986 printf("\t-k use kerberos\n");
3987 printf("\t-N numprocs\n");
3988 printf("\t-n my_netbios_name\n");
3989 printf("\t-W workgroup\n");
3990 printf("\t-o num_operations\n");
3991 printf("\t-O socket_options\n");
3992 printf("\t-m maximum protocol\n");
3993 printf("\t-L use oplocks\n");
3994 printf("\t-c CLIENT.TXT specify client load file for NBENCH\n");
3995 printf("\t-A showall\n");
3996 printf("\t-s seed\n");
3999 printf("tests are:");
4000 for (i=0;torture_ops[i].name;i++) {
4001 printf(" %s", torture_ops[i].name);
4005 printf("default test is ALL\n");
4014 /****************************************************************************
4016 ****************************************************************************/
4017 int main(int argc,char *argv[])
4022 extern char *optarg;
4024 BOOL correct = True;
4028 #ifdef HAVE_SETBUFFER
4029 setbuffer(stdout, NULL, 0);
4032 lp_load(dyn_CONFIGFILE,True,False,False);
4039 for(p = argv[1]; *p; p++)
4043 if (strncmp(argv[1], "//", 2)) {
4047 fstrcpy(host, &argv[1][2]);
4048 p = strchr_m(&host[2],'/');
4053 fstrcpy(share, p+1);
4057 if (*username == 0 && getenv("LOGNAME")) {
4058 fstrcpy(username,getenv("LOGNAME"));
4064 srandom(time(NULL));
4066 fstrcpy(workgroup, lp_workgroup());
4068 while ((opt = getopt(argc, argv, "hW:U:n:N:O:o:m:Ld:Ac:ks:")) != EOF) {
4071 srandom(atoi(optarg));
4074 fstrcpy(workgroup,optarg);
4077 max_protocol = interpret_protocol(optarg, max_protocol);
4080 nprocs = atoi(optarg);
4083 torture_numops = atoi(optarg);
4086 DEBUGLEVEL = atoi(optarg);
4095 torture_showall = True;
4098 fstrcpy(myname, optarg);
4101 client_txt = optarg;
4105 use_kerberos = True;
4108 d_printf("No kerberos support compiled in\n");
4113 fstrcpy(username,optarg);
4114 p = strchr_m(username,'%');
4117 fstrcpy(password, p+1);
4122 printf("Unknown option %c (%d)\n", (char)opt, opt);
4129 p = getpass("Password:");
4131 fstrcpy(password, p);
4136 printf("host=%s share=%s user=%s myname=%s\n",
4137 host, share, username, myname);
4140 correct = run_test("ALL");
4142 for (i=1;i<argc;i++) {
4143 if (!run_test(argv[i])) {