2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 1997-1998
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 static fstring host, workgroup, share, password, username, myname;
26 static int max_protocol = PROTOCOL_NT1;
27 static char *sockops="TCP_NODELAY";
28 static int nprocs=1, numops=100;
29 static int procnum; /* records process count number when forking */
30 static struct cli_state current_cli;
31 static fstring randomfname;
32 static BOOL use_oplocks;
33 static BOOL use_level_II_oplocks;
34 static char *client_txt = "client_oplocks.txt";
35 static BOOL use_kerberos;
37 BOOL torture_showall = False;
39 static double create_procs(BOOL (*fn)(int), BOOL *result);
42 static struct timeval tp1,tp2;
44 void start_timer(void)
46 gettimeofday(&tp1,NULL);
49 double end_timer(void)
51 gettimeofday(&tp2,NULL);
52 return((tp2.tv_sec - tp1.tv_sec) +
53 (tp2.tv_usec - tp1.tv_usec)*1.0e-6);
57 /* return a pointer to a anonymous shared memory segment of size "size"
58 which will persist across fork() but will disappear when all processes
61 The memory is not zeroed
63 This function uses system5 shared memory. It takes advantage of a property
64 that the memory is not destroyed if it is attached when the id is removed
66 void *shm_setup(int size)
71 shmid = shmget(IPC_PRIVATE, size, SHM_R | SHM_W);
73 printf("can't get shared memory\n");
76 ret = (void *)shmat(shmid, 0, 0);
77 if (!ret || ret == (void *)-1) {
78 printf("can't attach to shared memory\n");
81 /* the following releases the ipc, but note that this process
82 and all its children will still have access to the memory, its
83 just that the shmid is no longer valid for other shm calls. This
84 means we don't leave behind lots of shm segments after we exit
86 See Stevens "advanced programming in unix env" for details
88 shmctl(shmid, IPC_RMID, 0);
94 static BOOL open_nbt_connection(struct cli_state *c)
96 struct nmb_name called, calling;
101 make_nmb_name(&calling, myname, 0x0);
102 make_nmb_name(&called , host, 0x20);
106 if (!cli_initialise(c) || !cli_connect(c, host, &ip)) {
107 printf("Failed to connect with %s\n", host);
111 c->use_kerberos = use_kerberos;
113 c->timeout = 120000; /* set a really long timeout (2 minutes) */
114 if (use_oplocks) c->use_oplocks = True;
115 if (use_level_II_oplocks) c->use_level_II_oplocks = True;
117 if (!cli_session_request(c, &calling, &called)) {
118 printf("%s rejected the session\n",host);
126 BOOL torture_open_connection(struct cli_state *c)
130 if (!open_nbt_connection(c)) {
134 if (!cli_negprot(c)) {
135 printf("%s rejected the negprot (%s)\n",host, cli_errstr(c));
140 if (!cli_session_setup(c, username,
141 password, strlen(password),
142 password, strlen(password),
144 printf("%s rejected the sessionsetup (%s)\n", host, cli_errstr(c));
149 if (!cli_send_tconX(c, share, "?????",
150 password, strlen(password)+1)) {
151 printf("%s refused tree connect (%s)\n", host, cli_errstr(c));
160 BOOL torture_close_connection(struct cli_state *c)
164 printf("tdis failed (%s)\n", cli_errstr(c));
174 /* check if the server produced the expected error code */
175 static BOOL check_error(int line, struct cli_state *c,
176 uint8 eclass, uint32 ecode, NTSTATUS nterr)
178 if (cli_is_dos_error(c)) {
182 /* Check DOS error */
184 cli_dos_error(c, &class, &num);
186 if (eclass != class || ecode != num) {
187 printf("unexpected error code class=%d code=%d\n",
188 (int)class, (int)num);
189 printf(" expected %d/%d %s (line=%d)\n",
190 (int)eclass, (int)ecode, nt_errstr(nterr), line);
199 status = cli_nt_error(c);
201 if (NT_STATUS_V(nterr) != NT_STATUS_V(status)) {
202 printf("unexpected error code %s\n", nt_errstr(status));
203 printf(" expected %s (line=%d)\n", nt_errstr(nterr), line);
212 static BOOL wait_lock(struct cli_state *c, int fnum, uint32 offset, uint32 len)
214 while (!cli_lock(c, fnum, offset, len, -1, WRITE_LOCK)) {
215 if (!check_error(__LINE__, c, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False;
221 static BOOL rw_torture(struct cli_state *c)
223 char *lockfname = "\\torture.lck";
227 pid_t pid2, pid = getpid();
232 fnum2 = cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
235 fnum2 = cli_open(c, lockfname, O_RDWR, DENY_NONE);
237 printf("open of %s failed (%s)\n", lockfname, cli_errstr(c));
242 for (i=0;i<numops;i++) {
243 unsigned n = (unsigned)sys_random()%10;
245 printf("%d\r", i); fflush(stdout);
247 slprintf(fname, sizeof(fstring) - 1, "\\torture.%u", n);
249 if (!wait_lock(c, fnum2, n*sizeof(int), sizeof(int))) {
253 fnum = cli_open(c, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_ALL);
255 printf("open failed (%s)\n", cli_errstr(c));
260 if (cli_write(c, fnum, 0, (char *)&pid, 0, sizeof(pid)) != sizeof(pid)) {
261 printf("write failed (%s)\n", cli_errstr(c));
266 if (cli_write(c, fnum, 0, (char *)buf,
267 sizeof(pid)+(j*sizeof(buf)),
268 sizeof(buf)) != sizeof(buf)) {
269 printf("write failed (%s)\n", cli_errstr(c));
276 if (cli_read(c, fnum, (char *)&pid2, 0, sizeof(pid)) != sizeof(pid)) {
277 printf("read failed (%s)\n", cli_errstr(c));
282 printf("data corruption!\n");
286 if (!cli_close(c, fnum)) {
287 printf("close failed (%s)\n", cli_errstr(c));
291 if (!cli_unlink(c, fname)) {
292 printf("unlink failed (%s)\n", cli_errstr(c));
296 if (!cli_unlock(c, fnum2, n*sizeof(int), sizeof(int))) {
297 printf("unlock failed (%s)\n", cli_errstr(c));
303 cli_unlink(c, lockfname);
310 static BOOL run_torture(int dummy)
312 struct cli_state cli;
317 cli_sockopt(&cli, sockops);
319 ret = rw_torture(&cli);
321 if (!torture_close_connection(&cli)) {
328 static BOOL rw_torture3(struct cli_state *c, char *lockfname)
335 unsigned countprev = 0;
340 for (i = 0; i < sizeof(buf); i += sizeof(uint32))
342 SIVAL(buf, i, sys_random());
347 fnum = cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
350 printf("first open read/write of %s failed (%s)\n",
351 lockfname, cli_errstr(c));
357 for (i = 0; i < 500 && fnum == -1; i++)
359 fnum = cli_open(c, lockfname, O_RDONLY,
364 printf("second open read-only of %s failed (%s)\n",
365 lockfname, cli_errstr(c));
371 for (count = 0; count < sizeof(buf); count += sent)
373 if (count >= countprev) {
374 printf("%d %8d\r", i, count);
377 countprev += (sizeof(buf) / 20);
382 sent = ((unsigned)sys_random()%(20))+ 1;
383 if (sent > sizeof(buf) - count)
385 sent = sizeof(buf) - count;
388 if (cli_write(c, fnum, 0, buf+count, count, (size_t)sent) != sent) {
389 printf("write failed (%s)\n", cli_errstr(c));
395 sent = cli_read(c, fnum, buf_rd+count, count,
399 printf("read failed offset:%d size:%d (%s)\n",
400 count, sizeof(buf)-count,
407 if (memcmp(buf_rd+count, buf+count, sent) != 0)
409 printf("read/write compare failed\n");
410 printf("offset: %d req %d recvd %d\n",
411 count, sizeof(buf)-count, sent);
420 if (!cli_close(c, fnum)) {
421 printf("close failed (%s)\n", cli_errstr(c));
428 static BOOL rw_torture2(struct cli_state *c1, struct cli_state *c2)
430 char *lockfname = "\\torture2.lck";
435 uchar buf_rd[131072];
439 if (!cli_unlink(c1, lockfname)) {
440 printf("unlink failed (%s) (normal, this file should not exist)\n", cli_errstr(c1));
443 fnum1 = cli_open(c1, lockfname, O_RDWR | O_CREAT | O_EXCL,
446 printf("first open read/write of %s failed (%s)\n",
447 lockfname, cli_errstr(c1));
450 fnum2 = cli_open(c2, lockfname, O_RDONLY,
453 printf("second open read-only of %s failed (%s)\n",
454 lockfname, cli_errstr(c2));
455 cli_close(c1, fnum1);
459 for (i=0;i<numops;i++)
461 size_t buf_size = ((unsigned)sys_random()%(sizeof(buf)-1))+ 1;
463 printf("%d\r", i); fflush(stdout);
466 generate_random_buffer(buf, buf_size, False);
468 if (cli_write(c1, fnum1, 0, buf, 0, buf_size) != buf_size) {
469 printf("write failed (%s)\n", cli_errstr(c1));
473 if ((bytes_read = cli_read(c2, fnum2, buf_rd, 0, buf_size)) != buf_size) {
474 printf("read failed (%s)\n", cli_errstr(c2));
475 printf("read %d, expected %d\n", bytes_read, buf_size);
479 if (memcmp(buf_rd, buf, buf_size) != 0)
481 printf("read/write compare failed\n");
486 if (!cli_close(c2, fnum2)) {
487 printf("close failed (%s)\n", cli_errstr(c2));
490 if (!cli_close(c1, fnum1)) {
491 printf("close failed (%s)\n", cli_errstr(c1));
495 if (!cli_unlink(c1, lockfname)) {
496 printf("unlink failed (%s)\n", cli_errstr(c1));
503 static BOOL run_readwritetest(int dummy)
505 static struct cli_state cli1, cli2;
508 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
511 cli_sockopt(&cli1, sockops);
512 cli_sockopt(&cli2, sockops);
514 printf("starting readwritetest\n");
516 test1 = rw_torture2(&cli1, &cli2);
517 printf("Passed readwritetest v1: %s\n", BOOLSTR(test1));
519 test2 = rw_torture2(&cli1, &cli1);
520 printf("Passed readwritetest v2: %s\n", BOOLSTR(test2));
522 if (!torture_close_connection(&cli1)) {
526 if (!torture_close_connection(&cli2)) {
530 return (test1 && test2);
533 static BOOL run_readwritemulti(int dummy)
535 static struct cli_state cli;
540 cli_sockopt(&cli, sockops);
542 printf("run_readwritemulti: fname %s\n", randomfname);
543 test = rw_torture3(&cli, randomfname);
545 if (!torture_close_connection(&cli)) {
552 static BOOL run_readwritelarge(int dummy)
554 static struct cli_state cli1;
556 char *lockfname = "\\large.dat";
561 if (!torture_open_connection(&cli1)) {
564 cli_sockopt(&cli1, sockops);
565 memset(buf,'\0',sizeof(buf));
567 cli1.max_xmit = 128*1024;
569 printf("starting readwritelarge\n");
571 cli_unlink(&cli1, lockfname);
573 fnum1 = cli_open(&cli1, lockfname, O_RDWR | O_CREAT | O_EXCL, DENY_NONE);
575 printf("open read/write of %s failed (%s)\n", lockfname, cli_errstr(&cli1));
579 cli_write(&cli1, fnum1, 0, buf, 0, sizeof(buf));
581 if (!cli_qfileinfo(&cli1, fnum1, NULL, &fsize, NULL, NULL, NULL, NULL, NULL)) {
582 printf("qfileinfo failed (%s)\n", cli_errstr(&cli1));
586 if (fsize == sizeof(buf))
587 printf("readwritelarge test 1 succeeded (size = %x)\n", fsize);
589 printf("readwritelarge test 1 failed (size = %x)\n", fsize);
593 if (!cli_close(&cli1, fnum1)) {
594 printf("close failed (%s)\n", cli_errstr(&cli1));
598 if (!cli_unlink(&cli1, lockfname)) {
599 printf("unlink failed (%s)\n", cli_errstr(&cli1));
603 fnum1 = cli_open(&cli1, lockfname, O_RDWR | O_CREAT | O_EXCL, DENY_NONE);
605 printf("open read/write of %s failed (%s)\n", lockfname, cli_errstr(&cli1));
609 cli1.max_xmit = 4*1024;
611 cli_smbwrite(&cli1, fnum1, buf, 0, sizeof(buf));
613 if (!cli_qfileinfo(&cli1, fnum1, NULL, &fsize, NULL, NULL, NULL, NULL, NULL)) {
614 printf("qfileinfo failed (%s)\n", cli_errstr(&cli1));
618 if (fsize == sizeof(buf))
619 printf("readwritelarge test 2 succeeded (size = %x)\n", fsize);
621 printf("readwritelarge test 2 failed (size = %x)\n", fsize);
626 /* ToDo - set allocation. JRA */
627 if(!cli_set_allocation_size(&cli1, fnum1, 0)) {
628 printf("set allocation size to zero failed (%s)\n", cli_errstr(&cli1));
631 if (!cli_qfileinfo(&cli1, fnum1, NULL, &fsize, NULL, NULL, NULL, NULL, NULL)) {
632 printf("qfileinfo failed (%s)\n", cli_errstr(&cli1));
636 printf("readwritelarge test 3 (truncate test) succeeded (size = %x)\n", fsize);
639 if (!cli_close(&cli1, fnum1)) {
640 printf("close failed (%s)\n", cli_errstr(&cli1));
644 if (!torture_close_connection(&cli1)) {
653 #define ival(s) strtol(s, NULL, 0)
655 /* run a test that simulates an approximate netbench client load */
656 static BOOL run_netbench(int client)
658 struct cli_state cli;
671 cli_sockopt(&cli, sockops);
675 slprintf(cname,sizeof(fname), "client%d", client);
677 f = fopen(client_txt, "r");
684 while (fgets(line, sizeof(line)-1, f)) {
687 line[strlen(line)-1] = 0;
689 /* printf("[%d] %s\n", line_count, line); */
691 all_string_sub(line,"client1", cname, sizeof(line));
693 /* parse the command parameters */
694 params[0] = strtok(line," ");
696 while (params[i]) params[++i] = strtok(NULL," ");
702 if (!strncmp(params[0],"SMB", 3)) {
703 printf("ERROR: You are using a dbench 1 load file\n");
707 if (!strcmp(params[0],"NTCreateX")) {
708 nb_createx(params[1], ival(params[2]), ival(params[3]),
710 } else if (!strcmp(params[0],"Close")) {
711 nb_close(ival(params[1]));
712 } else if (!strcmp(params[0],"Rename")) {
713 nb_rename(params[1], params[2]);
714 } else if (!strcmp(params[0],"Unlink")) {
715 nb_unlink(params[1]);
716 } else if (!strcmp(params[0],"Deltree")) {
717 nb_deltree(params[1]);
718 } else if (!strcmp(params[0],"Rmdir")) {
720 } else if (!strcmp(params[0],"QUERY_PATH_INFORMATION")) {
721 nb_qpathinfo(params[1]);
722 } else if (!strcmp(params[0],"QUERY_FILE_INFORMATION")) {
723 nb_qfileinfo(ival(params[1]));
724 } else if (!strcmp(params[0],"QUERY_FS_INFORMATION")) {
725 nb_qfsinfo(ival(params[1]));
726 } else if (!strcmp(params[0],"FIND_FIRST")) {
727 nb_findfirst(params[1]);
728 } else if (!strcmp(params[0],"WriteX")) {
729 nb_writex(ival(params[1]),
730 ival(params[2]), ival(params[3]), ival(params[4]));
731 } else if (!strcmp(params[0],"ReadX")) {
732 nb_readx(ival(params[1]),
733 ival(params[2]), ival(params[3]), ival(params[4]));
734 } else if (!strcmp(params[0],"Flush")) {
735 nb_flush(ival(params[1]));
737 printf("Unknown operation %s\n", params[0]);
745 if (!torture_close_connection(&cli)) {
753 /* run a test that simulates an approximate netbench client load */
754 static BOOL run_nbench(int dummy)
763 signal(SIGALRM, nb_alarm);
765 t = create_procs(run_netbench, &correct);
768 printf("\nThroughput %g MB/sec\n",
769 1.0e-6 * nbio_total() / t);
775 This test checks for two things:
777 1) correct support for retaining locks over a close (ie. the server
778 must not use posix semantics)
779 2) support for lock timeouts
781 static BOOL run_locktest1(int dummy)
783 static struct cli_state cli1, cli2;
784 char *fname = "\\lockt1.lck";
785 int fnum1, fnum2, fnum3;
788 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
791 cli_sockopt(&cli1, sockops);
792 cli_sockopt(&cli2, sockops);
794 printf("starting locktest1\n");
796 cli_unlink(&cli1, fname);
798 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
800 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
803 fnum2 = cli_open(&cli1, fname, O_RDWR, DENY_NONE);
805 printf("open2 of %s failed (%s)\n", fname, cli_errstr(&cli1));
808 fnum3 = cli_open(&cli2, fname, O_RDWR, DENY_NONE);
810 printf("open3 of %s failed (%s)\n", fname, cli_errstr(&cli2));
814 if (!cli_lock(&cli1, fnum1, 0, 4, 0, WRITE_LOCK)) {
815 printf("lock1 failed (%s)\n", cli_errstr(&cli1));
820 if (cli_lock(&cli2, fnum3, 0, 4, 0, WRITE_LOCK)) {
821 printf("lock2 succeeded! This is a locking bug\n");
824 if (!check_error(__LINE__, &cli2, ERRDOS, ERRlock,
825 NT_STATUS_LOCK_NOT_GRANTED)) return False;
829 printf("Testing lock timeouts\n");
831 if (cli_lock(&cli2, fnum3, 0, 4, 10*1000, WRITE_LOCK)) {
832 printf("lock3 succeeded! This is a locking bug\n");
835 if (!check_error(__LINE__, &cli2, ERRDOS, ERRlock,
836 NT_STATUS_FILE_LOCK_CONFLICT)) return False;
841 printf("error: This server appears not to support timed lock requests\n");
844 if (!cli_close(&cli1, fnum2)) {
845 printf("close1 failed (%s)\n", cli_errstr(&cli1));
849 if (cli_lock(&cli2, fnum3, 0, 4, 0, WRITE_LOCK)) {
850 printf("lock4 succeeded! This is a locking bug\n");
853 if (!check_error(__LINE__, &cli2, ERRDOS, ERRlock,
854 NT_STATUS_FILE_LOCK_CONFLICT)) return False;
857 if (!cli_close(&cli1, fnum1)) {
858 printf("close2 failed (%s)\n", cli_errstr(&cli1));
862 if (!cli_close(&cli2, fnum3)) {
863 printf("close3 failed (%s)\n", cli_errstr(&cli2));
867 if (!cli_unlink(&cli1, fname)) {
868 printf("unlink failed (%s)\n", cli_errstr(&cli1));
873 if (!torture_close_connection(&cli1)) {
877 if (!torture_close_connection(&cli2)) {
881 printf("Passed locktest1\n");
886 checks for correct tconX support
888 static BOOL run_tcon_test(int dummy)
890 static struct cli_state cli1;
891 char *fname = "\\tcontest.tmp";
896 if (!torture_open_connection(&cli1)) {
899 cli_sockopt(&cli1, sockops);
901 printf("starting tcontest\n");
903 cli_unlink(&cli1, fname);
905 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
908 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
914 if (cli_write(&cli1, fnum1, 0, buf, 130, 4) != 4)
916 printf("write failed (%s)", cli_errstr(&cli1));
920 if (!cli_send_tconX(&cli1, share, "?????",
921 password, strlen(password)+1)) {
922 printf("%s refused 2nd tree connect (%s)\n", host,
928 if (cli_write(&cli1, fnum1, 0, buf, 130, 4) == 4)
930 printf("write succeeded (%s)", cli_errstr(&cli1));
934 if (cli_close(&cli1, fnum1)) {
935 printf("close2 succeeded (%s)\n", cli_errstr(&cli1));
939 if (!cli_tdis(&cli1)) {
940 printf("tdis failed (%s)\n", cli_errstr(&cli1));
946 if (!cli_close(&cli1, fnum1)) {
947 printf("close2 failed (%s)\n", cli_errstr(&cli1));
951 if (!torture_close_connection(&cli1)) {
955 printf("Passed tcontest\n");
961 This test checks that
963 1) the server supports multiple locking contexts on the one SMB
964 connection, distinguished by PID.
966 2) the server correctly fails overlapping locks made by the same PID (this
967 goes against POSIX behaviour, which is why it is tricky to implement)
969 3) the server denies unlock requests by an incorrect client PID
971 static BOOL run_locktest2(int dummy)
973 static struct cli_state cli;
974 char *fname = "\\lockt2.lck";
975 int fnum1, fnum2, fnum3;
978 if (!torture_open_connection(&cli)) {
982 cli_sockopt(&cli, sockops);
984 printf("starting locktest2\n");
986 cli_unlink(&cli, fname);
990 fnum1 = cli_open(&cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
992 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli));
996 fnum2 = cli_open(&cli, fname, O_RDWR, DENY_NONE);
998 printf("open2 of %s failed (%s)\n", fname, cli_errstr(&cli));
1002 cli_setpid(&cli, 2);
1004 fnum3 = cli_open(&cli, fname, O_RDWR, DENY_NONE);
1006 printf("open3 of %s failed (%s)\n", fname, cli_errstr(&cli));
1010 cli_setpid(&cli, 1);
1012 if (!cli_lock(&cli, fnum1, 0, 4, 0, WRITE_LOCK)) {
1013 printf("lock1 failed (%s)\n", cli_errstr(&cli));
1017 if (cli_lock(&cli, fnum1, 0, 4, 0, WRITE_LOCK)) {
1018 printf("WRITE lock1 succeeded! This is a locking bug\n");
1021 if (!check_error(__LINE__, &cli, ERRDOS, ERRlock,
1022 NT_STATUS_LOCK_NOT_GRANTED)) return False;
1025 if (cli_lock(&cli, fnum2, 0, 4, 0, WRITE_LOCK)) {
1026 printf("WRITE lock2 succeeded! This is a locking bug\n");
1029 if (!check_error(__LINE__, &cli, ERRDOS, ERRlock,
1030 NT_STATUS_LOCK_NOT_GRANTED)) return False;
1033 if (cli_lock(&cli, fnum2, 0, 4, 0, READ_LOCK)) {
1034 printf("READ lock2 succeeded! This is a locking bug\n");
1037 if (!check_error(__LINE__, &cli, ERRDOS, ERRlock,
1038 NT_STATUS_FILE_LOCK_CONFLICT)) return False;
1041 if (!cli_lock(&cli, fnum1, 100, 4, 0, WRITE_LOCK)) {
1042 printf("lock at 100 failed (%s)\n", cli_errstr(&cli));
1044 cli_setpid(&cli, 2);
1045 if (cli_unlock(&cli, fnum1, 100, 4)) {
1046 printf("unlock at 100 succeeded! This is a locking bug\n");
1050 if (cli_unlock(&cli, fnum1, 0, 4)) {
1051 printf("unlock1 succeeded! This is a locking bug\n");
1054 if (!check_error(__LINE__, &cli,
1056 NT_STATUS_RANGE_NOT_LOCKED)) return False;
1059 if (cli_unlock(&cli, fnum1, 0, 8)) {
1060 printf("unlock2 succeeded! This is a locking bug\n");
1063 if (!check_error(__LINE__, &cli,
1065 NT_STATUS_RANGE_NOT_LOCKED)) return False;
1068 if (cli_lock(&cli, fnum3, 0, 4, 0, WRITE_LOCK)) {
1069 printf("lock3 succeeded! This is a locking bug\n");
1072 if (!check_error(__LINE__, &cli, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False;
1075 cli_setpid(&cli, 1);
1077 if (!cli_close(&cli, fnum1)) {
1078 printf("close1 failed (%s)\n", cli_errstr(&cli));
1082 if (!cli_close(&cli, fnum2)) {
1083 printf("close2 failed (%s)\n", cli_errstr(&cli));
1087 if (!cli_close(&cli, fnum3)) {
1088 printf("close3 failed (%s)\n", cli_errstr(&cli));
1092 if (!torture_close_connection(&cli)) {
1096 printf("locktest2 finished\n");
1103 This test checks that
1105 1) the server supports the full offset range in lock requests
1107 static BOOL run_locktest3(int dummy)
1109 static struct cli_state cli1, cli2;
1110 char *fname = "\\lockt3.lck";
1111 int fnum1, fnum2, i;
1113 BOOL correct = True;
1115 #define NEXT_OFFSET offset += (~(uint32)0) / numops
1117 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
1120 cli_sockopt(&cli1, sockops);
1121 cli_sockopt(&cli2, sockops);
1123 printf("starting locktest3\n");
1125 cli_unlink(&cli1, fname);
1127 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1129 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
1132 fnum2 = cli_open(&cli2, fname, O_RDWR, DENY_NONE);
1134 printf("open2 of %s failed (%s)\n", fname, cli_errstr(&cli2));
1138 for (offset=i=0;i<numops;i++) {
1140 if (!cli_lock(&cli1, fnum1, offset-1, 1, 0, WRITE_LOCK)) {
1141 printf("lock1 %d failed (%s)\n",
1147 if (!cli_lock(&cli2, fnum2, offset-2, 1, 0, WRITE_LOCK)) {
1148 printf("lock2 %d failed (%s)\n",
1155 for (offset=i=0;i<numops;i++) {
1158 if (cli_lock(&cli1, fnum1, offset-2, 1, 0, WRITE_LOCK)) {
1159 printf("error: lock1 %d succeeded!\n", i);
1163 if (cli_lock(&cli2, fnum2, offset-1, 1, 0, WRITE_LOCK)) {
1164 printf("error: lock2 %d succeeded!\n", i);
1168 if (cli_lock(&cli1, fnum1, offset-1, 1, 0, WRITE_LOCK)) {
1169 printf("error: lock3 %d succeeded!\n", i);
1173 if (cli_lock(&cli2, fnum2, offset-2, 1, 0, WRITE_LOCK)) {
1174 printf("error: lock4 %d succeeded!\n", i);
1179 for (offset=i=0;i<numops;i++) {
1182 if (!cli_unlock(&cli1, fnum1, offset-1, 1)) {
1183 printf("unlock1 %d failed (%s)\n",
1189 if (!cli_unlock(&cli2, fnum2, offset-2, 1)) {
1190 printf("unlock2 %d failed (%s)\n",
1197 if (!cli_close(&cli1, fnum1)) {
1198 printf("close1 failed (%s)\n", cli_errstr(&cli1));
1202 if (!cli_close(&cli2, fnum2)) {
1203 printf("close2 failed (%s)\n", cli_errstr(&cli2));
1207 if (!cli_unlink(&cli1, fname)) {
1208 printf("unlink failed (%s)\n", cli_errstr(&cli1));
1212 if (!torture_close_connection(&cli1)) {
1216 if (!torture_close_connection(&cli2)) {
1220 printf("finished locktest3\n");
1225 #define EXPECTED(ret, v) if ((ret) != (v)) { \
1226 printf("** "); correct = False; \
1230 looks at overlapping locks
1232 static BOOL run_locktest4(int dummy)
1234 static struct cli_state cli1, cli2;
1235 char *fname = "\\lockt4.lck";
1236 int fnum1, fnum2, f;
1239 BOOL correct = True;
1241 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
1245 cli_sockopt(&cli1, sockops);
1246 cli_sockopt(&cli2, sockops);
1248 printf("starting locktest4\n");
1250 cli_unlink(&cli1, fname);
1252 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1253 fnum2 = cli_open(&cli2, fname, O_RDWR, DENY_NONE);
1255 memset(buf, 0, sizeof(buf));
1257 if (cli_write(&cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
1258 printf("Failed to create file\n");
1263 ret = cli_lock(&cli1, fnum1, 0, 4, 0, WRITE_LOCK) &&
1264 cli_lock(&cli1, fnum1, 2, 4, 0, WRITE_LOCK);
1265 EXPECTED(ret, False);
1266 printf("the same process %s set overlapping write locks\n", ret?"can":"cannot");
1268 ret = cli_lock(&cli1, fnum1, 10, 4, 0, READ_LOCK) &&
1269 cli_lock(&cli1, fnum1, 12, 4, 0, READ_LOCK);
1270 EXPECTED(ret, True);
1271 printf("the same process %s set overlapping read locks\n", ret?"can":"cannot");
1273 ret = cli_lock(&cli1, fnum1, 20, 4, 0, WRITE_LOCK) &&
1274 cli_lock(&cli2, fnum2, 22, 4, 0, WRITE_LOCK);
1275 EXPECTED(ret, False);
1276 printf("a different connection %s set overlapping write locks\n", ret?"can":"cannot");
1278 ret = cli_lock(&cli1, fnum1, 30, 4, 0, READ_LOCK) &&
1279 cli_lock(&cli2, fnum2, 32, 4, 0, READ_LOCK);
1280 EXPECTED(ret, True);
1281 printf("a different connection %s set overlapping read locks\n", ret?"can":"cannot");
1283 ret = (cli_setpid(&cli1, 1), cli_lock(&cli1, fnum1, 40, 4, 0, WRITE_LOCK)) &&
1284 (cli_setpid(&cli1, 2), cli_lock(&cli1, fnum1, 42, 4, 0, WRITE_LOCK));
1285 EXPECTED(ret, False);
1286 printf("a different pid %s set overlapping write locks\n", ret?"can":"cannot");
1288 ret = (cli_setpid(&cli1, 1), cli_lock(&cli1, fnum1, 50, 4, 0, READ_LOCK)) &&
1289 (cli_setpid(&cli1, 2), cli_lock(&cli1, fnum1, 52, 4, 0, READ_LOCK));
1290 EXPECTED(ret, True);
1291 printf("a different pid %s set overlapping read locks\n", ret?"can":"cannot");
1293 ret = cli_lock(&cli1, fnum1, 60, 4, 0, READ_LOCK) &&
1294 cli_lock(&cli1, fnum1, 60, 4, 0, READ_LOCK);
1295 EXPECTED(ret, True);
1296 printf("the same process %s set the same read lock twice\n", ret?"can":"cannot");
1298 ret = cli_lock(&cli1, fnum1, 70, 4, 0, WRITE_LOCK) &&
1299 cli_lock(&cli1, fnum1, 70, 4, 0, WRITE_LOCK);
1300 EXPECTED(ret, False);
1301 printf("the same process %s set the same write lock twice\n", ret?"can":"cannot");
1303 ret = cli_lock(&cli1, fnum1, 80, 4, 0, READ_LOCK) &&
1304 cli_lock(&cli1, fnum1, 80, 4, 0, WRITE_LOCK);
1305 EXPECTED(ret, False);
1306 printf("the same process %s overlay a read lock with a write lock\n", ret?"can":"cannot");
1308 ret = cli_lock(&cli1, fnum1, 90, 4, 0, WRITE_LOCK) &&
1309 cli_lock(&cli1, fnum1, 90, 4, 0, READ_LOCK);
1310 EXPECTED(ret, True);
1311 printf("the same process %s overlay a write lock with a read lock\n", ret?"can":"cannot");
1313 ret = (cli_setpid(&cli1, 1), cli_lock(&cli1, fnum1, 100, 4, 0, WRITE_LOCK)) &&
1314 (cli_setpid(&cli1, 2), cli_lock(&cli1, fnum1, 100, 4, 0, READ_LOCK));
1315 EXPECTED(ret, False);
1316 printf("a different pid %s overlay a write lock with a read lock\n", ret?"can":"cannot");
1318 ret = cli_lock(&cli1, fnum1, 110, 4, 0, READ_LOCK) &&
1319 cli_lock(&cli1, fnum1, 112, 4, 0, READ_LOCK) &&
1320 cli_unlock(&cli1, fnum1, 110, 6);
1321 EXPECTED(ret, False);
1322 printf("the same process %s coalesce read locks\n", ret?"can":"cannot");
1325 ret = cli_lock(&cli1, fnum1, 120, 4, 0, WRITE_LOCK) &&
1326 (cli_read(&cli2, fnum2, buf, 120, 4) == 4);
1327 EXPECTED(ret, False);
1328 printf("this server %s strict write locking\n", ret?"doesn't do":"does");
1330 ret = cli_lock(&cli1, fnum1, 130, 4, 0, READ_LOCK) &&
1331 (cli_write(&cli2, fnum2, 0, buf, 130, 4) == 4);
1332 EXPECTED(ret, False);
1333 printf("this server %s strict read locking\n", ret?"doesn't do":"does");
1336 ret = cli_lock(&cli1, fnum1, 140, 4, 0, READ_LOCK) &&
1337 cli_lock(&cli1, fnum1, 140, 4, 0, READ_LOCK) &&
1338 cli_unlock(&cli1, fnum1, 140, 4) &&
1339 cli_unlock(&cli1, fnum1, 140, 4);
1340 EXPECTED(ret, True);
1341 printf("this server %s do recursive read locking\n", ret?"does":"doesn't");
1344 ret = cli_lock(&cli1, fnum1, 150, 4, 0, WRITE_LOCK) &&
1345 cli_lock(&cli1, fnum1, 150, 4, 0, READ_LOCK) &&
1346 cli_unlock(&cli1, fnum1, 150, 4) &&
1347 (cli_read(&cli2, fnum2, buf, 150, 4) == 4) &&
1348 !(cli_write(&cli2, fnum2, 0, buf, 150, 4) == 4) &&
1349 cli_unlock(&cli1, fnum1, 150, 4);
1350 EXPECTED(ret, True);
1351 printf("this server %s do recursive lock overlays\n", ret?"does":"doesn't");
1353 ret = cli_lock(&cli1, fnum1, 160, 4, 0, READ_LOCK) &&
1354 cli_unlock(&cli1, fnum1, 160, 4) &&
1355 (cli_write(&cli2, fnum2, 0, buf, 160, 4) == 4) &&
1356 (cli_read(&cli2, fnum2, buf, 160, 4) == 4);
1357 EXPECTED(ret, True);
1358 printf("the same process %s remove a read lock using write locking\n", ret?"can":"cannot");
1360 ret = cli_lock(&cli1, fnum1, 170, 4, 0, WRITE_LOCK) &&
1361 cli_unlock(&cli1, fnum1, 170, 4) &&
1362 (cli_write(&cli2, fnum2, 0, buf, 170, 4) == 4) &&
1363 (cli_read(&cli2, fnum2, buf, 170, 4) == 4);
1364 EXPECTED(ret, True);
1365 printf("the same process %s remove a write lock using read locking\n", ret?"can":"cannot");
1367 ret = cli_lock(&cli1, fnum1, 190, 4, 0, WRITE_LOCK) &&
1368 cli_lock(&cli1, fnum1, 190, 4, 0, READ_LOCK) &&
1369 cli_unlock(&cli1, fnum1, 190, 4) &&
1370 !(cli_write(&cli2, fnum2, 0, buf, 190, 4) == 4) &&
1371 (cli_read(&cli2, fnum2, buf, 190, 4) == 4);
1372 EXPECTED(ret, True);
1373 printf("the same process %s remove the first lock first\n", ret?"does":"doesn't");
1375 cli_close(&cli1, fnum1);
1376 cli_close(&cli2, fnum2);
1377 fnum1 = cli_open(&cli1, fname, O_RDWR, DENY_NONE);
1378 f = cli_open(&cli1, fname, O_RDWR, DENY_NONE);
1379 ret = cli_lock(&cli1, fnum1, 0, 8, 0, READ_LOCK) &&
1380 cli_lock(&cli1, f, 0, 1, 0, READ_LOCK) &&
1381 cli_close(&cli1, fnum1) &&
1382 ((fnum1 = cli_open(&cli1, fname, O_RDWR, DENY_NONE)) != -1) &&
1383 cli_lock(&cli1, fnum1, 7, 1, 0, WRITE_LOCK);
1384 cli_close(&cli1, f);
1385 cli_close(&cli1, fnum1);
1386 EXPECTED(ret, True);
1387 printf("the server %s have the NT byte range lock bug\n", !ret?"does":"doesn't");
1390 cli_close(&cli1, fnum1);
1391 cli_close(&cli2, fnum2);
1392 cli_unlink(&cli1, fname);
1393 torture_close_connection(&cli1);
1394 torture_close_connection(&cli2);
1396 printf("finished locktest4\n");
1401 looks at lock upgrade/downgrade.
1403 static BOOL run_locktest5(int dummy)
1405 static struct cli_state cli1, cli2;
1406 char *fname = "\\lockt5.lck";
1407 int fnum1, fnum2, fnum3;
1410 BOOL correct = True;
1412 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
1416 cli_sockopt(&cli1, sockops);
1417 cli_sockopt(&cli2, sockops);
1419 printf("starting locktest5\n");
1421 cli_unlink(&cli1, fname);
1423 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1424 fnum2 = cli_open(&cli2, fname, O_RDWR, DENY_NONE);
1425 fnum3 = cli_open(&cli1, fname, O_RDWR, DENY_NONE);
1427 memset(buf, 0, sizeof(buf));
1429 if (cli_write(&cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
1430 printf("Failed to create file\n");
1435 /* Check for NT bug... */
1436 ret = cli_lock(&cli1, fnum1, 0, 8, 0, READ_LOCK) &&
1437 cli_lock(&cli1, fnum3, 0, 1, 0, READ_LOCK);
1438 cli_close(&cli1, fnum1);
1439 fnum1 = cli_open(&cli1, fname, O_RDWR, DENY_NONE);
1440 ret = cli_lock(&cli1, fnum1, 7, 1, 0, WRITE_LOCK);
1441 EXPECTED(ret, True);
1442 printf("this server %s the NT locking bug\n", ret ? "doesn't have" : "has");
1443 cli_close(&cli1, fnum1);
1444 fnum1 = cli_open(&cli1, fname, O_RDWR, DENY_NONE);
1445 cli_unlock(&cli1, fnum3, 0, 1);
1447 ret = cli_lock(&cli1, fnum1, 0, 4, 0, WRITE_LOCK) &&
1448 cli_lock(&cli1, fnum1, 1, 1, 0, READ_LOCK);
1449 EXPECTED(ret, True);
1450 printf("the same process %s overlay a write with a read lock\n", ret?"can":"cannot");
1452 ret = cli_lock(&cli2, fnum2, 0, 4, 0, READ_LOCK);
1453 EXPECTED(ret, False);
1455 printf("a different processs %s get a read lock on the first process lock stack\n", ret?"can":"cannot");
1457 /* Unlock the process 2 lock. */
1458 cli_unlock(&cli2, fnum2, 0, 4);
1460 ret = cli_lock(&cli1, fnum3, 0, 4, 0, READ_LOCK);
1461 EXPECTED(ret, False);
1463 printf("the same processs on a different fnum %s get a read lock\n", ret?"can":"cannot");
1465 /* Unlock the process 1 fnum3 lock. */
1466 cli_unlock(&cli1, fnum3, 0, 4);
1468 /* Stack 2 more locks here. */
1469 ret = cli_lock(&cli1, fnum1, 0, 4, 0, READ_LOCK) &&
1470 cli_lock(&cli1, fnum1, 0, 4, 0, READ_LOCK);
1472 EXPECTED(ret, True);
1473 printf("the same process %s stack read locks\n", ret?"can":"cannot");
1475 /* Unlock the first process lock, then check this was the WRITE lock that was
1478 ret = cli_unlock(&cli1, fnum1, 0, 4) &&
1479 cli_lock(&cli2, fnum2, 0, 4, 0, READ_LOCK);
1481 EXPECTED(ret, True);
1482 printf("the first unlock removes the %s lock\n", ret?"WRITE":"READ");
1484 /* Unlock the process 2 lock. */
1485 cli_unlock(&cli2, fnum2, 0, 4);
1487 /* We should have 3 stacked locks here. Ensure we need to do 3 unlocks. */
1489 ret = cli_unlock(&cli1, fnum1, 1, 1) &&
1490 cli_unlock(&cli1, fnum1, 0, 4) &&
1491 cli_unlock(&cli1, fnum1, 0, 4);
1493 EXPECTED(ret, True);
1494 printf("the same process %s unlock the stack of 4 locks\n", ret?"can":"cannot");
1496 /* Ensure the next unlock fails. */
1497 ret = cli_unlock(&cli1, fnum1, 0, 4);
1498 EXPECTED(ret, False);
1499 printf("the same process %s count the lock stack\n", !ret?"can":"cannot");
1501 /* Ensure connection 2 can get a write lock. */
1502 ret = cli_lock(&cli2, fnum2, 0, 4, 0, WRITE_LOCK);
1503 EXPECTED(ret, True);
1505 printf("a different processs %s get a write lock on the unlocked stack\n", ret?"can":"cannot");
1509 cli_close(&cli1, fnum1);
1510 cli_close(&cli2, fnum2);
1511 cli_unlink(&cli1, fname);
1512 if (!torture_close_connection(&cli1)) {
1515 if (!torture_close_connection(&cli2)) {
1519 printf("finished locktest5\n");
1525 tries the unusual lockingX locktype bits
1527 static BOOL run_locktest6(int dummy)
1529 static struct cli_state cli;
1530 char *fname[1] = { "\\lock6.txt" };
1535 if (!torture_open_connection(&cli)) {
1539 cli_sockopt(&cli, sockops);
1541 printf("starting locktest6\n");
1544 printf("Testing %s\n", fname[i]);
1546 cli_unlink(&cli, fname[i]);
1548 fnum = cli_open(&cli, fname[i], O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1549 status = cli_locktype(&cli, fnum, 0, 8, 0, LOCKING_ANDX_CHANGE_LOCKTYPE);
1550 cli_close(&cli, fnum);
1551 printf("CHANGE_LOCKTYPE gave %s\n", nt_errstr(status));
1553 fnum = cli_open(&cli, fname[i], O_RDWR, DENY_NONE);
1554 status = cli_locktype(&cli, fnum, 0, 8, 0, LOCKING_ANDX_CANCEL_LOCK);
1555 cli_close(&cli, fnum);
1556 printf("CANCEL_LOCK gave %s\n", nt_errstr(status));
1558 cli_unlink(&cli, fname[i]);
1561 torture_close_connection(&cli);
1563 printf("finished locktest6\n");
1568 test whether fnums and tids open on one VC are available on another (a major
1571 static BOOL run_fdpasstest(int dummy)
1573 static struct cli_state cli1, cli2, cli3;
1574 char *fname = "\\fdpass.tst";
1578 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
1581 cli_sockopt(&cli1, sockops);
1582 cli_sockopt(&cli2, sockops);
1584 printf("starting fdpasstest\n");
1586 cli_unlink(&cli1, fname);
1588 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1590 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
1594 if (cli_write(&cli1, fnum1, 0, "hello world\n", 0, 13) != 13) {
1595 printf("write failed (%s)\n", cli_errstr(&cli1));
1600 cli3.vuid = cli1.vuid;
1601 cli3.cnum = cli1.cnum;
1602 cli3.pid = cli1.pid;
1604 if (cli_read(&cli3, fnum1, buf, 0, 13) == 13) {
1605 printf("read succeeded! nasty security hole [%s]\n",
1610 cli_close(&cli1, fnum1);
1611 cli_unlink(&cli1, fname);
1613 torture_close_connection(&cli1);
1614 torture_close_connection(&cli2);
1616 printf("finished fdpasstest\n");
1622 This test checks that
1624 1) the server does not allow an unlink on a file that is open
1626 static BOOL run_unlinktest(int dummy)
1628 static struct cli_state cli;
1629 char *fname = "\\unlink.tst";
1631 BOOL correct = True;
1633 if (!torture_open_connection(&cli)) {
1637 cli_sockopt(&cli, sockops);
1639 printf("starting unlink test\n");
1641 cli_unlink(&cli, fname);
1643 cli_setpid(&cli, 1);
1645 fnum = cli_open(&cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1647 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli));
1651 if (cli_unlink(&cli, fname)) {
1652 printf("error: server allowed unlink on an open file\n");
1655 correct = check_error(__LINE__, &cli, ERRDOS, ERRbadshare,
1656 NT_STATUS_SHARING_VIOLATION);
1659 cli_close(&cli, fnum);
1660 cli_unlink(&cli, fname);
1662 if (!torture_close_connection(&cli)) {
1666 printf("unlink test finished\n");
1673 test how many open files this server supports on the one socket
1675 static BOOL run_maxfidtest(int dummy)
1677 static struct cli_state cli;
1678 char *template = "\\maxfid.%d.%d";
1680 int fnums[0x11000], i;
1682 BOOL correct = True;
1687 printf("failed to connect\n");
1691 cli_sockopt(&cli, sockops);
1693 for (i=0; i<0x11000; i++) {
1694 slprintf(fname,sizeof(fname)-1,template, i,(int)getpid());
1695 if ((fnums[i] = cli_open(&cli, fname,
1696 O_RDWR|O_CREAT|O_TRUNC, DENY_NONE)) ==
1698 printf("open of %s failed (%s)\n",
1699 fname, cli_errstr(&cli));
1700 printf("maximum fnum is %d\n", i);
1708 printf("cleaning up\n");
1710 slprintf(fname,sizeof(fname)-1,template, i,(int)getpid());
1711 cli_close(&cli, fnums[i]);
1712 if (!cli_unlink(&cli, fname)) {
1713 printf("unlink of %s failed (%s)\n",
1714 fname, cli_errstr(&cli));
1721 printf("maxfid test finished\n");
1722 if (!torture_close_connection(&cli)) {
1728 /* generate a random buffer */
1729 static void rand_buf(char *buf, int len)
1732 *buf = (char)sys_random();
1737 /* send smb negprot commands, not reading the response */
1738 static BOOL run_negprot_nowait(int dummy)
1741 static struct cli_state cli;
1742 BOOL correct = True;
1744 printf("starting negprot nowait test\n");
1746 if (!open_nbt_connection(&cli)) {
1750 for (i=0;i<50000;i++) {
1751 cli_negprot_send(&cli);
1754 if (!torture_close_connection(&cli)) {
1758 printf("finished negprot nowait test\n");
1764 /* send random IPC commands */
1765 static BOOL run_randomipc(int dummy)
1767 char *rparam = NULL;
1771 int api, param_len, i;
1772 static struct cli_state cli;
1773 BOOL correct = True;
1776 printf("starting random ipc test\n");
1778 if (!torture_open_connection(&cli)) {
1782 for (i=0;i<count;i++) {
1783 api = sys_random() % 500;
1784 param_len = (sys_random() % 64);
1786 rand_buf(param, param_len);
1791 param, param_len, 8,
1792 NULL, 0, BUFFER_SIZE,
1796 printf("%d/%d\r", i,count);
1799 printf("%d/%d\n", i, count);
1801 if (!torture_close_connection(&cli)) {
1805 printf("finished random ipc test\n");
1812 static void browse_callback(const char *sname, uint32 stype,
1813 const char *comment, void *state)
1815 printf("\t%20.20s %08x %s\n", sname, stype, comment);
1821 This test checks the browse list code
1824 static BOOL run_browsetest(int dummy)
1826 static struct cli_state cli;
1827 BOOL correct = True;
1829 printf("starting browse test\n");
1831 if (!torture_open_connection(&cli)) {
1835 printf("domain list:\n");
1836 cli_NetServerEnum(&cli, cli.server_domain,
1837 SV_TYPE_DOMAIN_ENUM,
1838 browse_callback, NULL);
1840 printf("machine list:\n");
1841 cli_NetServerEnum(&cli, cli.server_domain,
1843 browse_callback, NULL);
1845 if (!torture_close_connection(&cli)) {
1849 printf("browse test finished\n");
1857 This checks how the getatr calls works
1859 static BOOL run_attrtest(int dummy)
1861 static struct cli_state cli;
1864 char *fname = "\\attrib.tst";
1865 BOOL correct = True;
1867 printf("starting attrib test\n");
1869 if (!torture_open_connection(&cli)) {
1873 cli_unlink(&cli, fname);
1874 fnum = cli_open(&cli, fname,
1875 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1876 cli_close(&cli, fnum);
1877 if (!cli_getatr(&cli, fname, NULL, NULL, &t)) {
1878 printf("getatr failed (%s)\n", cli_errstr(&cli));
1882 if (abs(t - time(NULL)) > 60*60*24*10) {
1883 printf("ERROR: SMBgetatr bug. time is %s",
1889 t2 = t-60*60*24; /* 1 day ago */
1891 if (!cli_setatr(&cli, fname, 0, t2)) {
1892 printf("setatr failed (%s)\n", cli_errstr(&cli));
1896 if (!cli_getatr(&cli, fname, NULL, NULL, &t)) {
1897 printf("getatr failed (%s)\n", cli_errstr(&cli));
1902 printf("ERROR: getatr/setatr bug. times are\n%s",
1904 printf("%s", ctime(&t2));
1908 cli_unlink(&cli, fname);
1910 if (!torture_close_connection(&cli)) {
1914 printf("attrib test finished\n");
1921 This checks a couple of trans2 calls
1923 static BOOL run_trans2test(int dummy)
1925 static struct cli_state cli;
1928 time_t c_time, a_time, m_time, w_time, m_time2;
1929 char *fname = "\\trans2.tst";
1930 char *dname = "\\trans2";
1931 char *fname2 = "\\trans2\\trans2.tst";
1933 BOOL correct = True;
1935 printf("starting trans2 test\n");
1937 if (!torture_open_connection(&cli)) {
1941 cli_unlink(&cli, fname);
1942 fnum = cli_open(&cli, fname,
1943 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1944 if (!cli_qfileinfo(&cli, fnum, NULL, &size, &c_time, &a_time, &m_time,
1946 printf("ERROR: qfileinfo failed (%s)\n", cli_errstr(&cli));
1950 if (!cli_qfilename(&cli, fnum, pname)) {
1951 printf("ERROR: qfilename failed (%s)\n", cli_errstr(&cli));
1955 if (strcmp(pname, fname)) {
1956 printf("qfilename gave different name? [%s] [%s]\n",
1961 cli_close(&cli, fnum);
1965 cli_unlink(&cli, fname);
1966 fnum = cli_open(&cli, fname,
1967 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1969 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli));
1972 cli_close(&cli, fnum);
1974 if (!cli_qpathinfo(&cli, fname, &c_time, &a_time, &m_time, &size, NULL)) {
1975 printf("ERROR: qpathinfo failed (%s)\n", cli_errstr(&cli));
1978 if (c_time != m_time) {
1979 printf("create time=%s", ctime(&c_time));
1980 printf("modify time=%s", ctime(&m_time));
1981 printf("This system appears to have sticky create times\n");
1984 if (a_time % (60*60) == 0) {
1985 printf("access time=%s", ctime(&a_time));
1986 printf("This system appears to set a midnight access time\n");
1990 if (abs(m_time - time(NULL)) > 60*60*24*7) {
1991 printf("ERROR: totally incorrect times - maybe word reversed? mtime=%s", ctime(&m_time));
1997 cli_unlink(&cli, fname);
1998 fnum = cli_open(&cli, fname,
1999 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2000 cli_close(&cli, fnum);
2001 if (!cli_qpathinfo2(&cli, fname, &c_time, &a_time, &m_time,
2002 &w_time, &size, NULL, NULL)) {
2003 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli));
2006 if (w_time < 60*60*24*2) {
2007 printf("write time=%s", ctime(&w_time));
2008 printf("This system appears to set a initial 0 write time\n");
2013 cli_unlink(&cli, fname);
2016 /* check if the server updates the directory modification time
2017 when creating a new file */
2018 if (!cli_mkdir(&cli, dname)) {
2019 printf("ERROR: mkdir failed (%s)\n", cli_errstr(&cli));
2023 if (!cli_qpathinfo2(&cli, "\\trans2\\", &c_time, &a_time, &m_time,
2024 &w_time, &size, NULL, NULL)) {
2025 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli));
2029 fnum = cli_open(&cli, fname2,
2030 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2031 cli_write(&cli, fnum, 0, (char *)&fnum, 0, sizeof(fnum));
2032 cli_close(&cli, fnum);
2033 if (!cli_qpathinfo2(&cli, "\\trans2\\", &c_time, &a_time, &m_time2,
2034 &w_time, &size, NULL, NULL)) {
2035 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli));
2038 if (m_time2 == m_time) {
2039 printf("This system does not update directory modification times\n");
2043 cli_unlink(&cli, fname2);
2044 cli_rmdir(&cli, dname);
2046 if (!torture_close_connection(&cli)) {
2050 printf("trans2 test finished\n");
2056 This checks new W2K calls.
2059 static BOOL new_trans(struct cli_state *pcli, int fnum, int level)
2062 BOOL correct = True;
2064 memset(buf, 0xff, sizeof(buf));
2066 if (!cli_qfileinfo_test(pcli, fnum, level, buf)) {
2067 printf("ERROR: qfileinfo (%d) failed (%s)\n", level, cli_errstr(pcli));
2070 printf("qfileinfo: level %d\n", level);
2071 dump_data(0, buf, 256);
2077 static BOOL run_w2ktest(int dummy)
2079 static struct cli_state cli;
2081 char *fname = "\\w2ktest\\w2k.tst";
2083 BOOL correct = True;
2085 printf("starting w2k test\n");
2087 if (!torture_open_connection(&cli)) {
2091 fnum = cli_open(&cli, fname,
2092 O_RDWR | O_CREAT , DENY_NONE);
2094 for (level = 1004; level < 1040; level++) {
2095 new_trans(&cli, fnum, level);
2098 cli_close(&cli, fnum);
2100 if (!torture_close_connection(&cli)) {
2104 printf("w2k test finished\n");
2111 this is a harness for some oplock tests
2113 static BOOL run_oplock1(int dummy)
2115 static struct cli_state cli1;
2116 char *fname = "\\lockt1.lck";
2118 BOOL correct = True;
2120 printf("starting oplock test 1\n");
2122 if (!torture_open_connection(&cli1)) {
2126 cli_unlink(&cli1, fname);
2128 cli_sockopt(&cli1, sockops);
2130 cli1.use_oplocks = True;
2132 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2134 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2138 cli1.use_oplocks = False;
2140 cli_unlink(&cli1, fname);
2141 cli_unlink(&cli1, fname);
2143 if (!cli_close(&cli1, fnum1)) {
2144 printf("close2 failed (%s)\n", cli_errstr(&cli1));
2148 if (!cli_unlink(&cli1, fname)) {
2149 printf("unlink failed (%s)\n", cli_errstr(&cli1));
2153 if (!torture_close_connection(&cli1)) {
2157 printf("finished oplock test 1\n");
2162 static BOOL run_oplock2(int dummy)
2164 static struct cli_state cli1, cli2;
2165 char *fname = "\\lockt2.lck";
2167 int saved_use_oplocks = use_oplocks;
2169 BOOL correct = True;
2170 volatile BOOL *shared_correct;
2172 shared_correct = (volatile BOOL *)shm_setup(sizeof(BOOL));
2173 *shared_correct = True;
2175 use_level_II_oplocks = True;
2178 printf("starting oplock test 2\n");
2180 if (!torture_open_connection(&cli1)) {
2181 use_level_II_oplocks = False;
2182 use_oplocks = saved_use_oplocks;
2186 cli1.use_oplocks = True;
2187 cli1.use_level_II_oplocks = True;
2189 if (!torture_open_connection(&cli2)) {
2190 use_level_II_oplocks = False;
2191 use_oplocks = saved_use_oplocks;
2195 cli2.use_oplocks = True;
2196 cli2.use_level_II_oplocks = True;
2198 cli_unlink(&cli1, fname);
2200 cli_sockopt(&cli1, sockops);
2201 cli_sockopt(&cli2, sockops);
2203 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2205 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2209 /* Don't need the globals any more. */
2210 use_level_II_oplocks = False;
2211 use_oplocks = saved_use_oplocks;
2215 fnum2 = cli_open(&cli2, fname, O_RDWR, DENY_NONE);
2217 printf("second open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2218 *shared_correct = False;
2224 if (!cli_close(&cli2, fnum2)) {
2225 printf("close2 failed (%s)\n", cli_errstr(&cli1));
2226 *shared_correct = False;
2234 /* Ensure cli1 processes the break. */
2236 if (cli_read(&cli1, fnum1, buf, 0, 4) != 4) {
2237 printf("read on fnum1 failed (%s)\n", cli_errstr(&cli1));
2241 /* Should now be at level II. */
2242 /* Test if sending a write locks causes a break to none. */
2244 if (!cli_lock(&cli1, fnum1, 0, 4, 0, READ_LOCK)) {
2245 printf("lock failed (%s)\n", cli_errstr(&cli1));
2249 cli_unlock(&cli1, fnum1, 0, 4);
2253 if (!cli_lock(&cli1, fnum1, 0, 4, 0, WRITE_LOCK)) {
2254 printf("lock failed (%s)\n", cli_errstr(&cli1));
2258 cli_unlock(&cli1, fnum1, 0, 4);
2262 cli_read(&cli1, fnum1, buf, 0, 4);
2265 if (cli_write(&cli1, fnum1, 0, buf, 0, 4) != 4) {
2266 printf("write on fnum1 failed (%s)\n", cli_errstr(&cli1));
2271 if (!cli_close(&cli1, fnum1)) {
2272 printf("close1 failed (%s)\n", cli_errstr(&cli1));
2278 if (!cli_unlink(&cli1, fname)) {
2279 printf("unlink failed (%s)\n", cli_errstr(&cli1));
2283 if (!torture_close_connection(&cli1)) {
2287 if (!*shared_correct) {
2291 printf("finished oplock test 2\n");
2296 /* handler for oplock 3 tests */
2297 static BOOL oplock3_handler(struct cli_state *cli, int fnum, unsigned char level)
2299 printf("got oplock break fnum=%d level=%d\n",
2301 return cli_oplock_ack(cli, fnum, level);
2304 static BOOL run_oplock3(int dummy)
2306 static struct cli_state cli;
2307 char *fname = "\\oplockt3.dat";
2309 char buf[4] = "abcd";
2310 BOOL correct = True;
2311 volatile BOOL *shared_correct;
2313 shared_correct = (volatile BOOL *)shm_setup(sizeof(BOOL));
2314 *shared_correct = True;
2316 printf("starting oplock test 3\n");
2321 use_level_II_oplocks = True;
2322 if (!torture_open_connection(&cli)) {
2323 *shared_correct = False;
2327 /* try to trigger a oplock break in parent */
2328 fnum = cli_open(&cli, fname, O_RDWR, DENY_NONE);
2329 cli_write(&cli, fnum, 0, buf, 0, 4);
2335 use_level_II_oplocks = True;
2336 if (!torture_open_connection(&cli)) {
2339 cli_oplock_handler(&cli, oplock3_handler);
2340 fnum = cli_open(&cli, fname, O_RDWR|O_CREAT, DENY_NONE);
2341 cli_write(&cli, fnum, 0, buf, 0, 4);
2342 cli_close(&cli, fnum);
2343 fnum = cli_open(&cli, fname, O_RDWR, DENY_NONE);
2344 cli.timeout = 20000;
2345 cli_receive_smb(&cli);
2346 printf("finished oplock test 3\n");
2348 return (correct && *shared_correct);
2350 /* What are we looking for here? What's sucess and what's FAILURE? */
2356 Test delete on close semantics.
2358 static BOOL run_deletetest(int dummy)
2360 static struct cli_state cli1;
2361 static struct cli_state cli2;
2362 char *fname = "\\delete.file";
2365 BOOL correct = True;
2367 printf("starting delete test\n");
2372 if (!torture_open_connection(&cli1)) {
2376 cli_sockopt(&cli1, sockops);
2378 /* Test 1 - this should *NOT* delete the file on close. */
2380 cli_setatr(&cli1, fname, 0, 0);
2381 cli_unlink(&cli1, fname);
2383 fnum1 = cli_nt_create_full(&cli1, fname, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL,
2384 FILE_SHARE_DELETE, FILE_OVERWRITE_IF,
2385 DELETE_ON_CLOSE_FLAG);
2388 printf("[1] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2393 if (!cli_close(&cli1, fnum1)) {
2394 printf("[1] close failed (%s)\n", cli_errstr(&cli1));
2399 fnum1 = cli_open(&cli1, fname, O_RDWR, DENY_NONE);
2401 printf("[1] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2406 if (!cli_close(&cli1, fnum1)) {
2407 printf("[1] close failed (%s)\n", cli_errstr(&cli1));
2412 printf("first delete on close test succeeded.\n");
2414 /* Test 2 - this should delete the file on close. */
2416 cli_setatr(&cli1, fname, 0, 0);
2417 cli_unlink(&cli1, fname);
2419 fnum1 = cli_nt_create_full(&cli1, fname, GENERIC_ALL_ACCESS,
2420 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
2421 FILE_OVERWRITE_IF, 0);
2424 printf("[2] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2429 if (!cli_nt_delete_on_close(&cli1, fnum1, True)) {
2430 printf("[2] setting delete_on_close failed (%s)\n", cli_errstr(&cli1));
2435 if (!cli_close(&cli1, fnum1)) {
2436 printf("[2] close failed (%s)\n", cli_errstr(&cli1));
2441 fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_NONE);
2443 printf("[2] open of %s succeeded should have been deleted on close !\n", fname);
2444 if (!cli_close(&cli1, fnum1)) {
2445 printf("[2] close failed (%s)\n", cli_errstr(&cli1));
2449 cli_unlink(&cli1, fname);
2451 printf("second delete on close test succeeded.\n");
2454 cli_setatr(&cli1, fname, 0, 0);
2455 cli_unlink(&cli1, fname);
2457 fnum1 = cli_nt_create_full(&cli1, fname, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL,
2458 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0);
2461 printf("[3] open - 1 of %s failed (%s)\n", fname, cli_errstr(&cli1));
2466 /* This should fail with a sharing violation - open for delete is only compatible
2467 with SHARE_DELETE. */
2469 fnum2 = cli_nt_create_full(&cli1, fname, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
2470 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0);
2473 printf("[3] open - 2 of %s succeeded - should have failed.\n", fname);
2478 /* This should succeed. */
2480 fnum2 = cli_nt_create_full(&cli1, fname, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
2481 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0);
2484 printf("[3] open - 2 of %s failed (%s)\n", fname, cli_errstr(&cli1));
2489 if (!cli_nt_delete_on_close(&cli1, fnum1, True)) {
2490 printf("[3] setting delete_on_close failed (%s)\n", cli_errstr(&cli1));
2495 if (!cli_close(&cli1, fnum1)) {
2496 printf("[3] close 1 failed (%s)\n", cli_errstr(&cli1));
2501 if (!cli_close(&cli1, fnum2)) {
2502 printf("[3] close 2 failed (%s)\n", cli_errstr(&cli1));
2507 /* This should fail - file should no longer be there. */
2509 fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_NONE);
2511 printf("[3] open of %s succeeded should have been deleted on close !\n", fname);
2512 if (!cli_close(&cli1, fnum1)) {
2513 printf("[3] close failed (%s)\n", cli_errstr(&cli1));
2515 cli_unlink(&cli1, fname);
2519 printf("third delete on close test succeeded.\n");
2522 cli_setatr(&cli1, fname, 0, 0);
2523 cli_unlink(&cli1, fname);
2525 fnum1 = cli_nt_create_full(&cli1, fname, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
2526 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0);
2529 printf("[4] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2534 /* This should succeed. */
2535 fnum2 = cli_nt_create_full(&cli1, fname, GENERIC_READ_ACCESS,
2536 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0);
2538 printf("[4] open - 2 of %s failed (%s)\n", fname, cli_errstr(&cli1));
2543 if (!cli_close(&cli1, fnum2)) {
2544 printf("[4] close - 1 failed (%s)\n", cli_errstr(&cli1));
2549 if (!cli_nt_delete_on_close(&cli1, fnum1, True)) {
2550 printf("[4] setting delete_on_close failed (%s)\n", cli_errstr(&cli1));
2555 /* This should fail - no more opens once delete on close set. */
2556 fnum2 = cli_nt_create_full(&cli1, fname, GENERIC_READ_ACCESS,
2557 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0);
2559 printf("[4] open - 3 of %s succeeded ! Should have failed.\n", fname );
2563 printf("fourth delete on close test succeeded.\n");
2565 if (!cli_close(&cli1, fnum1)) {
2566 printf("[4] close - 2 failed (%s)\n", cli_errstr(&cli1));
2572 cli_setatr(&cli1, fname, 0, 0);
2573 cli_unlink(&cli1, fname);
2575 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT, DENY_NONE);
2577 printf("[5] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2582 /* This should fail - only allowed on NT opens with DELETE access. */
2584 if (cli_nt_delete_on_close(&cli1, fnum1, True)) {
2585 printf("[5] setting delete_on_close on OpenX file succeeded - should fail !\n");
2590 if (!cli_close(&cli1, fnum1)) {
2591 printf("[5] close - 2 failed (%s)\n", cli_errstr(&cli1));
2596 printf("fifth delete on close test succeeded.\n");
2599 cli_setatr(&cli1, fname, 0, 0);
2600 cli_unlink(&cli1, fname);
2602 fnum1 = cli_nt_create_full(&cli1, fname, FILE_READ_DATA|FILE_WRITE_DATA,
2603 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
2604 FILE_OVERWRITE_IF, 0);
2607 printf("[6] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2612 /* This should fail - only allowed on NT opens with DELETE access. */
2614 if (cli_nt_delete_on_close(&cli1, fnum1, True)) {
2615 printf("[6] setting delete_on_close on file with no delete access succeeded - should fail !\n");
2620 if (!cli_close(&cli1, fnum1)) {
2621 printf("[6] close - 2 failed (%s)\n", cli_errstr(&cli1));
2626 printf("sixth delete on close test succeeded.\n");
2629 cli_setatr(&cli1, fname, 0, 0);
2630 cli_unlink(&cli1, fname);
2632 fnum1 = cli_nt_create_full(&cli1, fname, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
2633 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF, 0);
2636 printf("[7] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2641 if (!cli_nt_delete_on_close(&cli1, fnum1, True)) {
2642 printf("[7] setting delete_on_close on file failed !\n");
2647 if (!cli_nt_delete_on_close(&cli1, fnum1, False)) {
2648 printf("[7] unsetting delete_on_close on file failed !\n");
2653 if (!cli_close(&cli1, fnum1)) {
2654 printf("[7] close - 2 failed (%s)\n", cli_errstr(&cli1));
2659 /* This next open should succeed - we reset the flag. */
2661 fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_NONE);
2663 printf("[5] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2668 if (!cli_close(&cli1, fnum1)) {
2669 printf("[7] close - 2 failed (%s)\n", cli_errstr(&cli1));
2674 printf("seventh delete on close test succeeded.\n");
2677 cli_setatr(&cli1, fname, 0, 0);
2678 cli_unlink(&cli1, fname);
2680 if (!torture_open_connection(&cli2)) {
2681 printf("[8] failed to open second connection.\n");
2686 cli_sockopt(&cli1, sockops);
2688 fnum1 = cli_nt_create_full(&cli1, fname, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
2689 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0);
2692 printf("[8] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2697 fnum2 = cli_nt_create_full(&cli2, fname, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
2698 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0);
2701 printf("[8] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2706 if (!cli_nt_delete_on_close(&cli1, fnum1, True)) {
2707 printf("[8] setting delete_on_close on file failed !\n");
2712 if (!cli_close(&cli1, fnum1)) {
2713 printf("[8] close - 1 failed (%s)\n", cli_errstr(&cli1));
2718 if (!cli_close(&cli2, fnum2)) {
2719 printf("[8] close - 2 failed (%s)\n", cli_errstr(&cli2));
2724 /* This should fail.. */
2725 fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_NONE);
2727 printf("[8] open of %s succeeded should have been deleted on close !\n", fname);
2731 printf("eighth delete on close test succeeded.\n");
2733 /* This should fail - we need to set DELETE_ACCESS. */
2734 fnum1 = cli_nt_create_full(&cli1, fname, FILE_READ_DATA|FILE_WRITE_DATA,
2735 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, FILE_OVERWRITE_IF, FILE_DELETE_ON_CLOSE);
2738 printf("[9] open of %s succeeded should have failed!\n", fname);
2743 printf("ninth delete on close test succeeded.\n");
2745 fnum1 = cli_nt_create_full(&cli1, fname, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
2746 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, FILE_OVERWRITE_IF, FILE_DELETE_ON_CLOSE);
2748 printf("[10] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2753 /* This should delete the file. */
2754 if (!cli_close(&cli1, fnum1)) {
2755 printf("[10] close failed (%s)\n", cli_errstr(&cli1));
2760 /* This should fail.. */
2761 fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_NONE);
2763 printf("[10] open of %s succeeded should have been deleted on close !\n", fname);
2767 printf("tenth delete on close test succeeded.\n");
2768 printf("finished delete test\n");
2772 cli_close(&cli1, fnum1);
2773 cli_close(&cli1, fnum2);
2774 cli_setatr(&cli1, fname, 0, 0);
2775 cli_unlink(&cli1, fname);
2777 if (!torture_close_connection(&cli1)) {
2780 if (!torture_close_connection(&cli2)) {
2788 print out server properties
2790 static BOOL run_properties(int dummy)
2792 static struct cli_state cli;
2793 BOOL correct = True;
2795 printf("starting properties test\n");
2799 if (!torture_open_connection(&cli)) {
2803 cli_sockopt(&cli, sockops);
2805 d_printf("Capabilities 0x%08x\n", cli.capabilities);
2807 if (!torture_close_connection(&cli)) {
2816 /* FIRST_DESIRED_ACCESS 0xf019f */
2817 #define FIRST_DESIRED_ACCESS FILE_READ_DATA|FILE_WRITE_DATA|FILE_APPEND_DATA|\
2818 FILE_READ_EA| /* 0xf */ \
2819 FILE_WRITE_EA|FILE_READ_ATTRIBUTES| /* 0x90 */ \
2820 FILE_WRITE_ATTRIBUTES| /* 0x100 */ \
2821 DELETE_ACCESS|READ_CONTROL_ACCESS|\
2822 WRITE_DAC_ACCESS|WRITE_OWNER_ACCESS /* 0xf0000 */
2823 /* SECOND_DESIRED_ACCESS 0xe0080 */
2824 #define SECOND_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
2825 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
2826 WRITE_OWNER_ACCESS /* 0xe0000 */
2829 #define THIRD_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
2830 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
2832 WRITE_OWNER_ACCESS /* */
2836 Test ntcreate calls made by xcopy
2838 static BOOL run_xcopy(int dummy)
2840 static struct cli_state cli1;
2841 char *fname = "\\test.txt";
2842 BOOL correct = True;
2845 printf("starting xcopy test\n");
2847 if (!torture_open_connection(&cli1)) {
2851 fnum1 = cli_nt_create_full(&cli1, fname,
2852 FIRST_DESIRED_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
2853 FILE_SHARE_NONE, FILE_OVERWRITE_IF,
2857 printf("First open failed - %s\n", cli_errstr(&cli1));
2861 fnum2 = cli_nt_create_full(&cli1, fname,
2862 SECOND_DESIRED_ACCESS, 0,
2863 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN,
2866 printf("second open failed - %s\n", cli_errstr(&cli1));
2870 if (!torture_close_connection(&cli1)) {
2878 Test rename on files open with share delete and no share delete.
2880 static BOOL run_rename(int dummy)
2882 static struct cli_state cli1;
2883 char *fname = "\\test.txt";
2884 char *fname1 = "\\test1.txt";
2885 BOOL correct = True;
2888 printf("starting rename test\n");
2890 if (!torture_open_connection(&cli1)) {
2894 cli_unlink(&cli1, fname);
2895 cli_unlink(&cli1, fname1);
2896 fnum1 = cli_nt_create_full(&cli1, fname, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
2897 FILE_SHARE_READ, FILE_OVERWRITE_IF, 0);
2900 printf("First open failed - %s\n", cli_errstr(&cli1));
2904 if (!cli_rename(&cli1, fname, fname1)) {
2905 printf("First rename failed (this is correct) - %s\n", cli_errstr(&cli1));
2907 printf("First rename succeeded - this should have failed !\n");
2911 if (!cli_close(&cli1, fnum1)) {
2912 printf("close - 1 failed (%s)\n", cli_errstr(&cli1));
2916 cli_unlink(&cli1, fname);
2917 cli_unlink(&cli1, fname1);
2918 fnum1 = cli_nt_create_full(&cli1, fname,GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
2920 FILE_SHARE_DELETE|FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0);
2922 FILE_SHARE_DELETE|FILE_SHARE_READ, FILE_OVERWRITE_IF, 0);
2926 printf("Second open failed - %s\n", cli_errstr(&cli1));
2930 if (!cli_rename(&cli1, fname, fname1)) {
2931 printf("Second rename failed - this should have succeeded - %s\n", cli_errstr(&cli1));
2934 printf("Second rename succeeded\n");
2937 if (!cli_close(&cli1, fnum1)) {
2938 printf("close - 2 failed (%s)\n", cli_errstr(&cli1));
2942 cli_unlink(&cli1, fname);
2943 cli_unlink(&cli1, fname1);
2945 fnum1 = cli_nt_create_full(&cli1, fname,READ_CONTROL_ACCESS, FILE_ATTRIBUTE_NORMAL,
2946 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0);
2949 printf("Third open failed - %s\n", cli_errstr(&cli1));
2958 fnum2 = cli_nt_create_full(&cli1, fname,DELETE_ACCESS, FILE_ATTRIBUTE_NORMAL,
2959 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0);
2962 printf("Fourth open failed - %s\n", cli_errstr(&cli1));
2965 if (!cli_nt_delete_on_close(&cli1, fnum2, True)) {
2966 printf("[8] setting delete_on_close on file failed !\n");
2970 if (!cli_close(&cli1, fnum2)) {
2971 printf("close - 4 failed (%s)\n", cli_errstr(&cli1));
2977 if (!cli_rename(&cli1, fname, fname1)) {
2978 printf("Third rename failed - this should have succeeded - %s\n", cli_errstr(&cli1));
2981 printf("Third rename succeeded\n");
2984 if (!cli_close(&cli1, fnum1)) {
2985 printf("close - 3 failed (%s)\n", cli_errstr(&cli1));
2989 cli_unlink(&cli1, fname);
2990 cli_unlink(&cli1, fname1);
2992 if (!torture_close_connection(&cli1)) {
3001 Test open mode returns on read-only files.
3003 static BOOL run_opentest(int dummy)
3005 static struct cli_state cli1;
3006 static struct cli_state cli2;
3007 char *fname = "\\readonly.file";
3011 BOOL correct = True;
3014 printf("starting open test\n");
3016 if (!torture_open_connection(&cli1)) {
3020 cli_setatr(&cli1, fname, 0, 0);
3021 cli_unlink(&cli1, fname);
3023 cli_sockopt(&cli1, sockops);
3025 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
3027 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
3031 if (!cli_close(&cli1, fnum1)) {
3032 printf("close2 failed (%s)\n", cli_errstr(&cli1));
3036 if (!cli_setatr(&cli1, fname, aRONLY, 0)) {
3037 printf("cli_setatr failed (%s)\n", cli_errstr(&cli1));
3041 fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_WRITE);
3043 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
3047 /* This will fail - but the error should be ERRnoaccess, not ERRbadshare. */
3048 fnum2 = cli_open(&cli1, fname, O_RDWR, DENY_ALL);
3050 if (check_error(__LINE__, &cli1, ERRDOS, ERRnoaccess,
3051 NT_STATUS_ACCESS_DENIED)) {
3052 printf("correct error code ERRDOS/ERRnoaccess returned\n");
3055 printf("finished open test 1\n");
3057 cli_close(&cli1, fnum1);
3059 /* Now try not readonly and ensure ERRbadshare is returned. */
3061 cli_setatr(&cli1, fname, 0, 0);
3063 fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_WRITE);
3065 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
3069 /* This will fail - but the error should be ERRshare. */
3070 fnum2 = cli_open(&cli1, fname, O_RDWR, DENY_ALL);
3072 if (check_error(__LINE__, &cli1, ERRDOS, ERRbadshare,
3073 NT_STATUS_SHARING_VIOLATION)) {
3074 printf("correct error code ERRDOS/ERRbadshare returned\n");
3077 if (!cli_close(&cli1, fnum1)) {
3078 printf("close2 failed (%s)\n", cli_errstr(&cli1));
3082 cli_unlink(&cli1, fname);
3084 printf("finished open test 2\n");
3086 /* Test truncate open disposition on file opened for read. */
3088 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
3090 printf("(3) open (1) of %s failed (%s)\n", fname, cli_errstr(&cli1));
3094 /* write 20 bytes. */
3096 memset(buf, '\0', 20);
3098 if (cli_write(&cli1, fnum1, 0, buf, 0, 20) != 20) {
3099 printf("write failed (%s)\n", cli_errstr(&cli1));
3103 if (!cli_close(&cli1, fnum1)) {
3104 printf("(3) close1 failed (%s)\n", cli_errstr(&cli1));
3108 /* Ensure size == 20. */
3109 if (!cli_getatr(&cli1, fname, NULL, &fsize, NULL)) {
3110 printf("(3) getatr failed (%s)\n", cli_errstr(&cli1));
3115 printf("(3) file size != 20\n");
3119 /* Now test if we can truncate a file opened for readonly. */
3121 fnum1 = cli_open(&cli1, fname, O_RDONLY|O_TRUNC, DENY_NONE);
3123 printf("(3) open (2) of %s failed (%s)\n", fname, cli_errstr(&cli1));
3127 if (!cli_close(&cli1, fnum1)) {
3128 printf("close2 failed (%s)\n", cli_errstr(&cli1));
3132 /* Ensure size == 0. */
3133 if (!cli_getatr(&cli1, fname, NULL, &fsize, NULL)) {
3134 printf("(3) getatr failed (%s)\n", cli_errstr(&cli1));
3139 printf("(3) file size != 0\n");
3142 printf("finished open test 3\n");
3144 cli_unlink(&cli1, fname);
3147 printf("testing ctemp\n");
3148 fnum1 = cli_ctemp(&cli1, "\\", &tmp_path);
3150 printf("ctemp failed (%s)\n", cli_errstr(&cli1));
3153 printf("ctemp gave path %s\n", tmp_path);
3154 if (!cli_close(&cli1, fnum1)) {
3155 printf("close of temp failed (%s)\n", cli_errstr(&cli1));
3157 if (!cli_unlink(&cli1, tmp_path)) {
3158 printf("unlink of temp failed (%s)\n", cli_errstr(&cli1));
3161 /* Test the non-io opens... */
3163 if (!torture_open_connection(&cli2)) {
3167 cli_setatr(&cli2, fname, 0, 0);
3168 cli_unlink(&cli2, fname);
3170 cli_sockopt(&cli2, sockops);
3172 printf("TEST #1 testing 2 non-io opens (no delete)\n");
3174 fnum1 = cli_nt_create_full(&cli1, fname,FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3175 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0);
3178 printf("test 1 open 1 of %s failed (%s)\n", fname, cli_errstr(&cli1));
3182 fnum2 = cli_nt_create_full(&cli2, fname,FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3183 FILE_SHARE_NONE, FILE_OPEN_IF, 0);
3186 printf("test 1 open 2 of %s failed (%s)\n", fname, cli_errstr(&cli2));
3190 if (!cli_close(&cli1, fnum1)) {
3191 printf("test 1 close 1 of %s failed (%s)\n", fname, cli_errstr(&cli1));
3194 if (!cli_close(&cli2, fnum2)) {
3195 printf("test 1 close 2 of %s failed (%s)\n", fname, cli_errstr(&cli2));
3199 printf("non-io open test #1 passed.\n");
3201 cli_unlink(&cli1, fname);
3203 printf("TEST #2 testing 2 non-io opens (first with delete)\n");
3205 fnum1 = cli_nt_create_full(&cli1, fname,DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3206 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0);
3209 printf("test 2 open 1 of %s failed (%s)\n", fname, cli_errstr(&cli1));
3213 fnum2 = cli_nt_create_full(&cli2, fname,FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3214 FILE_SHARE_NONE, FILE_OPEN_IF, 0);
3217 printf("test 2 open 2 of %s failed (%s)\n", fname, cli_errstr(&cli2));
3221 if (!cli_close(&cli1, fnum1)) {
3222 printf("test 1 close 1 of %s failed (%s)\n", fname, cli_errstr(&cli1));
3225 if (!cli_close(&cli2, fnum2)) {
3226 printf("test 1 close 2 of %s failed (%s)\n", fname, cli_errstr(&cli1));
3230 printf("non-io open test #2 passed.\n");
3232 cli_unlink(&cli1, fname);
3234 printf("TEST #3 testing 2 non-io opens (second with delete)\n");
3236 fnum1 = cli_nt_create_full(&cli1, fname,FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3237 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0);
3240 printf("test 3 open 1 of %s failed (%s)\n", fname, cli_errstr(&cli1));
3244 fnum2 = cli_nt_create_full(&cli2, fname,DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3245 FILE_SHARE_NONE, FILE_OPEN_IF, 0);
3248 printf("test 3 open 2 of %s failed (%s)\n", fname, cli_errstr(&cli2));
3252 if (!cli_close(&cli1, fnum1)) {
3253 printf("test 3 close 1 of %s failed (%s)\n", fname, cli_errstr(&cli1));
3256 if (!cli_close(&cli2, fnum2)) {
3257 printf("test 3 close 2 of %s failed (%s)\n", fname, cli_errstr(&cli2));
3261 printf("non-io open test #3 passed.\n");
3263 cli_unlink(&cli1, fname);
3265 printf("TEST #4 testing 2 non-io opens (both with delete)\n");
3267 fnum1 = cli_nt_create_full(&cli1, fname,DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3268 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0);
3271 printf("test 4 open 1 of %s failed (%s)\n", fname, cli_errstr(&cli1));
3275 fnum2 = cli_nt_create_full(&cli2, fname,DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3276 FILE_SHARE_NONE, FILE_OPEN_IF, 0);
3279 printf("test 4 open 2 of %s SUCCEEDED - should have failed\n", fname, cli_errstr(&cli2));
3283 printf("test 3 open 2 of %s gave %s (correct error should be %s)\n", fname, cli_errstr(&cli2), "sharing violation");
3285 if (!cli_close(&cli1, fnum1)) {
3286 printf("test 4 close 1 of %s failed (%s)\n", fname, cli_errstr(&cli1));
3290 printf("non-io open test #4 passed.\n");
3292 cli_unlink(&cli1, fname);
3294 printf("TEST #5 testing 2 non-io opens (both with delete - both with file share delete)\n");
3296 fnum1 = cli_nt_create_full(&cli1, fname,DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3297 FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0);
3300 printf("test 5 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_DELETE, FILE_OPEN_IF, 0);
3308 printf("test 5 open 2 of %s failed (%s)\n", fname, cli_errstr(&cli2));
3312 if (!cli_close(&cli1, fnum1)) {
3313 printf("test 5 close 1 of %s failed (%s)\n", fname, cli_errstr(&cli1));
3317 if (!cli_close(&cli2, fnum2)) {
3318 printf("test 5 close 2 of %s failed (%s)\n", fname, cli_errstr(&cli2));
3322 printf("non-io open test #5 passed.\n");
3324 printf("TEST #6 testing 1 non-io open, one io open\n");
3326 cli_unlink(&cli1, fname);
3328 fnum1 = cli_nt_create_full(&cli1, fname,FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
3329 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0);
3332 printf("test 6 open 1 of %s failed (%s)\n", fname, cli_errstr(&cli1));
3336 fnum2 = cli_nt_create_full(&cli2, fname,FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3337 FILE_SHARE_READ, FILE_OPEN_IF, 0);
3340 printf("test 6 open 2 of %s failed (%s)\n", fname, cli_errstr(&cli2));
3344 if (!cli_close(&cli1, fnum1)) {
3345 printf("test 6 close 1 of %s failed (%s)\n", fname, cli_errstr(&cli1));
3349 if (!cli_close(&cli2, fnum2)) {
3350 printf("test 6 close 2 of %s failed (%s)\n", fname, cli_errstr(&cli2));
3354 printf("non-io open test #6 passed.\n");
3356 printf("TEST #7 testing 1 non-io open, one io open with delete\n");
3358 cli_unlink(&cli1, fname);
3360 fnum1 = cli_nt_create_full(&cli1, fname,FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
3361 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0);
3364 printf("test 7 open 1 of %s failed (%s)\n", fname, cli_errstr(&cli1));
3368 fnum2 = cli_nt_create_full(&cli2, fname,DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3369 FILE_SHARE_READ|FILE_SHARE_DELETE, FILE_OPEN_IF, 0);
3372 printf("test 7 open 2 of %s SUCCEEDED - should have failed\n", fname, cli_errstr(&cli2));
3376 printf("test 7 open 2 of %s gave %s (correct error should be %s)\n", fname, cli_errstr(&cli2), "sharing violation");
3378 if (!cli_close(&cli1, fnum1)) {
3379 printf("test 7 close 1 of %s failed (%s)\n", fname, cli_errstr(&cli1));
3383 printf("non-io open test #7 passed.\n");
3385 cli_unlink(&cli1, fname);
3387 if (!torture_close_connection(&cli1)) {
3390 if (!torture_close_connection(&cli2)) {
3397 static void list_fn(file_info *finfo, const char *name, void *state)
3403 test directory listing speed
3405 static BOOL run_dirtest(int dummy)
3408 static struct cli_state cli;
3411 BOOL correct = True;
3413 printf("starting directory test\n");
3415 if (!torture_open_connection(&cli)) {
3419 cli_sockopt(&cli, sockops);
3422 for (i=0;i<numops;i++) {
3424 slprintf(fname, sizeof(fname), "\\%x", (int)random());
3425 fnum = cli_open(&cli, fname, O_RDWR|O_CREAT, DENY_NONE);
3427 fprintf(stderr,"Failed to open %s\n", fname);
3430 cli_close(&cli, fnum);
3435 printf("Matched %d\n", cli_list(&cli, "a*.*", 0, list_fn, NULL));
3436 printf("Matched %d\n", cli_list(&cli, "b*.*", 0, list_fn, NULL));
3437 printf("Matched %d\n", cli_list(&cli, "xyzabc", 0, list_fn, NULL));
3439 printf("dirtest core %g seconds\n", end_timer() - t1);
3442 for (i=0;i<numops;i++) {
3444 slprintf(fname, sizeof(fname), "\\%x", (int)random());
3445 cli_unlink(&cli, fname);
3448 if (!torture_close_connection(&cli)) {
3452 printf("finished dirtest\n");
3457 static BOOL run_error_map_extract(int dummy) {
3459 static struct cli_state c_dos;
3460 static struct cli_state c_nt;
3464 uint32 flgs2, errnum;
3471 /* NT-Error connection */
3473 if (!open_nbt_connection(&c_nt)) {
3477 c_nt.use_spnego = False;
3479 if (!cli_negprot(&c_nt)) {
3480 printf("%s rejected the NT-error negprot (%s)\n",host, cli_errstr(&c_nt));
3481 cli_shutdown(&c_nt);
3485 if (!cli_session_setup(&c_nt, "", "", 0, "", 0,
3487 printf("%s rejected the NT-error initial session setup (%s)\n",host, cli_errstr(&c_nt));
3491 /* DOS-Error connection */
3493 if (!open_nbt_connection(&c_dos)) {
3497 c_dos.use_spnego = False;
3498 c_dos.force_dos_errors = True;
3500 if (!cli_negprot(&c_dos)) {
3501 printf("%s rejected the DOS-error negprot (%s)\n",host, cli_errstr(&c_dos));
3502 cli_shutdown(&c_dos);
3506 if (!cli_session_setup(&c_dos, "", "", 0, "", 0,
3508 printf("%s rejected the DOS-error initial session setup (%s)\n",host, cli_errstr(&c_dos));
3512 for (error=(0xc0000000 | 0x1); error < (0xc0000000| 0xFFF); error++) {
3513 snprintf(user, sizeof(user), "%X", error);
3515 if (cli_session_setup(&c_nt, user,
3516 password, strlen(password),
3517 password, strlen(password),
3519 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
3522 flgs2 = SVAL(c_nt.inbuf,smb_flg2);
3524 /* Case #1: 32-bit NT errors */
3525 if (flgs2 & FLAGS2_32_BIT_ERROR_CODES) {
3526 nt_status = NT_STATUS(IVAL(c_nt.inbuf,smb_rcls));
3528 printf("/** Dos error on NT connection! (%s) */\n",
3530 nt_status = NT_STATUS(0xc0000000);
3533 if (cli_session_setup(&c_dos, user,
3534 password, strlen(password),
3535 password, strlen(password),
3537 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
3539 flgs2 = SVAL(c_dos.inbuf,smb_flg2), errnum;
3541 /* Case #1: 32-bit NT errors */
3542 if (flgs2 & FLAGS2_32_BIT_ERROR_CODES) {
3543 printf("/** NT error on DOS connection! (%s) */\n",
3545 errnum = errclass = 0;
3547 cli_dos_error(&c_dos, &errclass, &errnum);
3550 if (NT_STATUS_V(nt_status) != error) {
3551 printf("/*\t{ This NT error code was 'sqashed'\n\t from %s to %s \n\t during the session setup }\n*/\n",
3552 get_nt_error_c_code(NT_STATUS(error)),
3553 get_nt_error_c_code(nt_status));
3556 printf("\t{%s,\t%s,\t%s},\n",
3557 smb_dos_err_class(errclass),
3558 smb_dos_err_name(errclass, errnum),
3559 get_nt_error_c_code(NT_STATUS(error)));
3564 static double create_procs(BOOL (*fn)(int), BOOL *result)
3567 volatile pid_t *child_status;
3568 volatile BOOL *child_status_out;
3574 child_status = (volatile pid_t *)shm_setup(sizeof(pid_t)*nprocs);
3575 if (!child_status) {
3576 printf("Failed to setup shared memory\n");
3580 child_status_out = (volatile BOOL *)shm_setup(sizeof(BOOL)*nprocs);
3581 if (!child_status_out) {
3582 printf("Failed to setup result status shared memory\n");
3586 for (i = 0; i < nprocs; i++) {
3587 child_status[i] = 0;
3588 child_status_out[i] = True;
3593 for (i=0;i<nprocs;i++) {
3596 pid_t mypid = getpid();
3597 sys_srandom(((int)mypid) ^ ((int)time(NULL)));
3599 slprintf(myname,sizeof(myname),"CLIENT%d", i);
3602 memset(¤t_cli, 0, sizeof(current_cli));
3603 if (torture_open_connection(¤t_cli)) break;
3605 printf("pid %d failed to start\n", (int)getpid());
3611 child_status[i] = getpid();
3613 while (child_status[i] && end_timer() < 5) msleep(2);
3615 child_status_out[i] = fn(i);
3622 for (i=0;i<nprocs;i++) {
3623 if (child_status[i]) synccount++;
3625 if (synccount == nprocs) break;
3627 } while (end_timer() < 30);
3629 if (synccount != nprocs) {
3630 printf("FAILED TO START %d CLIENTS (started %d)\n", nprocs, synccount);
3635 /* start the client load */
3638 for (i=0;i<nprocs;i++) {
3639 child_status[i] = 0;
3642 printf("%d clients started\n", nprocs);
3644 for (i=0;i<nprocs;i++) {
3645 while (waitpid(0, &status, 0) == -1 && errno == EINTR) /* noop */ ;
3650 for (i=0;i<nprocs;i++) {
3651 if (!child_status_out[i]) {
3658 #define FLAG_MULTIPROC 1
3665 {"FDPASS", run_fdpasstest, 0},
3666 {"LOCK1", run_locktest1, 0},
3667 {"LOCK2", run_locktest2, 0},
3668 {"LOCK3", run_locktest3, 0},
3669 {"LOCK4", run_locktest4, 0},
3670 {"LOCK5", run_locktest5, 0},
3671 {"LOCK6", run_locktest6, 0},
3672 {"UNLINK", run_unlinktest, 0},
3673 {"BROWSE", run_browsetest, 0},
3674 {"ATTR", run_attrtest, 0},
3675 {"TRANS2", run_trans2test, 0},
3676 {"MAXFID", run_maxfidtest, FLAG_MULTIPROC},
3677 {"TORTURE",run_torture, FLAG_MULTIPROC},
3678 {"RANDOMIPC", run_randomipc, 0},
3679 {"NEGNOWAIT", run_negprot_nowait, 0},
3680 {"NBENCH", run_nbench, 0},
3681 {"OPLOCK1", run_oplock1, 0},
3682 {"OPLOCK2", run_oplock2, 0},
3683 {"OPLOCK3", run_oplock3, 0},
3684 {"DIR", run_dirtest, 0},
3685 {"DENY1", torture_denytest1, 0},
3686 {"DENY2", torture_denytest2, 0},
3687 {"TCON", run_tcon_test, 0},
3688 {"RW1", run_readwritetest, 0},
3689 {"RW2", run_readwritemulti, FLAG_MULTIPROC},
3690 {"RW3", run_readwritelarge, 0},
3691 {"OPEN", run_opentest, 0},
3692 {"XCOPY", run_xcopy, 0},
3693 {"RENAME", run_rename, 0},
3694 {"DELETE", run_deletetest, 0},
3695 {"PROPERTIES", run_properties, 0},
3696 {"W2K", run_w2ktest, 0},
3697 {"TRANS2SCAN", torture_trans2_scan, 0},
3698 {"NTTRANSSCAN", torture_nttrans_scan, 0},
3699 {"UTABLE", torture_utable, 0},
3700 {"CASETABLE", torture_casetable, 0},
3701 {"ERRMAPEXTRACT", run_error_map_extract, 0},
3706 /****************************************************************************
3707 run a specified test or "ALL"
3708 ****************************************************************************/
3709 static BOOL run_test(char *name)
3715 if (strequal(name,"ALL")) {
3716 for (i=0;torture_ops[i].name;i++) {
3717 run_test(torture_ops[i].name);
3721 for (i=0;torture_ops[i].name;i++) {
3722 snprintf(randomfname, sizeof(randomfname), "\\XX%x",
3723 (unsigned)random());
3725 if (strequal(name, torture_ops[i].name)) {
3726 printf("Running %s\n", name);
3727 if (torture_ops[i].flags & FLAG_MULTIPROC) {
3728 t = create_procs(torture_ops[i].fn, &result);
3731 printf("TEST %s FAILED!\n", name);
3736 if (!torture_ops[i].fn(0)) {
3738 printf("TEST %s FAILED!\n", name);
3742 printf("%s took %g secs\n\n", name, t);
3749 static void usage(void)
3753 printf("Usage: smbtorture //server/share <options> TEST1 TEST2 ...\n");
3755 printf("\t-d debuglevel\n");
3756 printf("\t-U user%%pass\n");
3757 printf("\t-k use kerberos\n");
3758 printf("\t-N numprocs\n");
3759 printf("\t-n my_netbios_name\n");
3760 printf("\t-W workgroup\n");
3761 printf("\t-o num_operations\n");
3762 printf("\t-O socket_options\n");
3763 printf("\t-m maximum protocol\n");
3764 printf("\t-L use oplocks\n");
3765 printf("\t-c CLIENT.TXT specify client load file for NBENCH\n");
3766 printf("\t-A showall\n");
3769 printf("tests are:");
3770 for (i=0;torture_ops[i].name;i++) {
3771 printf(" %s", torture_ops[i].name);
3775 printf("default test is ALL\n");
3784 /****************************************************************************
3786 ****************************************************************************/
3787 int main(int argc,char *argv[])
3792 extern char *optarg;
3794 BOOL correct = True;
3798 #ifdef HAVE_SETBUFFER
3799 setbuffer(stdout, NULL, 0);
3802 lp_load(dyn_CONFIGFILE,True,False,False);
3809 for(p = argv[1]; *p; p++)
3813 if (strncmp(argv[1], "//", 2)) {
3817 fstrcpy(host, &argv[1][2]);
3818 p = strchr_m(&host[2],'/');
3823 fstrcpy(share, p+1);
3827 if (*username == 0 && getenv("LOGNAME")) {
3828 pstrcpy(username,getenv("LOGNAME"));
3835 fstrcpy(workgroup, lp_workgroup());
3837 while ((opt = getopt(argc, argv, "hW:U:n:N:O:o:m:Ld:Ac:k")) != EOF) {
3840 fstrcpy(workgroup,optarg);
3843 max_protocol = interpret_protocol(optarg, max_protocol);
3846 nprocs = atoi(optarg);
3849 numops = atoi(optarg);
3852 DEBUGLEVEL = atoi(optarg);
3861 torture_showall = True;
3864 fstrcpy(myname, optarg);
3867 client_txt = optarg;
3871 use_kerberos = True;
3874 d_printf("No kerberos support compiled in\n");
3879 pstrcpy(username,optarg);
3880 p = strchr_m(username,'%');
3883 pstrcpy(password, p+1);
3888 printf("Unknown option %c (%d)\n", (char)opt, opt);
3895 p = getpass("Password:");
3897 pstrcpy(password, p);
3902 printf("host=%s share=%s user=%s myname=%s\n",
3903 host, share, username, myname);
3906 correct = run_test("ALL");
3908 for (i=1;i<argc;i++) {
3909 if (!run_test(argv[i])) {