2 Unix SMB/Netbios implementation.
5 Copyright (C) Andrew Tridgell 1997-1998
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 static fstring host, workgroup, share, password, username, myname;
27 static int max_protocol = PROTOCOL_NT1;
28 static char *sockops="TCP_NODELAY";
29 static int nprocs=1, 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 BOOL torture_showall = False;
37 static double create_procs(BOOL (*fn)(int), BOOL *result);
40 static struct timeval tp1,tp2;
42 static void start_timer(void)
44 gettimeofday(&tp1,NULL);
47 static double end_timer(void)
49 gettimeofday(&tp2,NULL);
50 return((tp2.tv_sec - tp1.tv_sec) +
51 (tp2.tv_usec - tp1.tv_usec)*1.0e-6);
55 /* return a pointer to a anonymous shared memory segment of size "size"
56 which will persist across fork() but will disappear when all processes
59 The memory is not zeroed
61 This function uses system5 shared memory. It takes advantage of a property
62 that the memory is not destroyed if it is attached when the id is removed
64 static void *shm_setup(int size)
69 shmid = shmget(IPC_PRIVATE, size, SHM_R | SHM_W);
71 printf("can't get shared memory\n");
74 ret = (void *)shmat(shmid, 0, 0);
75 if (!ret || ret == (void *)-1) {
76 printf("can't attach to shared memory\n");
79 /* the following releases the ipc, but note that this process
80 and all its children will still have access to the memory, its
81 just that the shmid is no longer valid for other shm calls. This
82 means we don't leave behind lots of shm segments after we exit
84 See Stevens "advanced programming in unix env" for details
86 shmctl(shmid, IPC_RMID, 0);
92 static BOOL open_nbt_connection(struct cli_state *c)
94 struct nmb_name called, calling;
96 extern struct in_addr ipzero;
100 make_nmb_name(&calling, myname, 0x0);
101 make_nmb_name(&called , host, 0x20);
105 if (!cli_initialise(c) || !cli_connect(c, host, &ip)) {
106 printf("Failed to connect with %s\n", host);
110 c->timeout = 120000; /* set a really long timeout (2 minutes) */
111 if (use_oplocks) c->use_oplocks = True;
112 if (use_level_II_oplocks) c->use_level_II_oplocks = True;
114 if (!cli_session_request(c, &calling, &called)) {
115 printf("%s rejected the session\n",host);
123 BOOL torture_open_connection(struct cli_state *c)
127 if (!open_nbt_connection(c)) {
131 if (!cli_negprot(c)) {
132 printf("%s rejected the negprot (%s)\n",host, cli_errstr(c));
137 if (!cli_session_setup(c, username,
138 password, strlen(password),
139 password, strlen(password),
141 printf("%s rejected the sessionsetup (%s)\n", host, cli_errstr(c));
146 if (!cli_send_tconX(c, share, "?????",
147 password, strlen(password)+1)) {
148 printf("%s refused tree connect (%s)\n", host, cli_errstr(c));
157 BOOL torture_close_connection(struct cli_state *c)
161 printf("tdis failed (%s)\n", cli_errstr(c));
171 /* check if the server produced the expected error code */
172 static BOOL check_error(int line, struct cli_state *c,
173 uint8 eclass, uint32 ecode, NTSTATUS nterr)
175 if (cli_is_dos_error(c)) {
179 /* Check DOS error */
181 cli_dos_error(c, &class, &num);
183 if (eclass != class || ecode != num) {
184 printf("unexpected error code class=%d code=%d\n",
185 (int)class, (int)num);
186 printf(" expected %d/%d %s (line=%d)\n",
187 (int)eclass, (int)ecode, get_nt_error_msg(nterr), line);
196 status = cli_nt_error(c);
198 if (NT_STATUS_V(nterr) != NT_STATUS_V(status)) {
199 printf("unexpected error code %s\n", get_nt_error_msg(status));
200 printf(" expected %s (line=%d)\n", get_nt_error_msg(nterr), line);
209 static BOOL wait_lock(struct cli_state *c, int fnum, uint32 offset, uint32 len)
211 while (!cli_lock(c, fnum, offset, len, -1, WRITE_LOCK)) {
212 if (!check_error(__LINE__, c, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False;
218 static BOOL rw_torture(struct cli_state *c)
220 char *lockfname = "\\torture.lck";
224 pid_t pid2, pid = getpid();
229 fnum2 = cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
232 fnum2 = cli_open(c, lockfname, O_RDWR, DENY_NONE);
234 printf("open of %s failed (%s)\n", lockfname, cli_errstr(c));
239 for (i=0;i<numops;i++) {
240 unsigned n = (unsigned)sys_random()%10;
242 printf("%d\r", i); fflush(stdout);
244 slprintf(fname, sizeof(fstring) - 1, "\\torture.%u", n);
246 if (!wait_lock(c, fnum2, n*sizeof(int), sizeof(int))) {
250 fnum = cli_open(c, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_ALL);
252 printf("open failed (%s)\n", cli_errstr(c));
257 if (cli_write(c, fnum, 0, (char *)&pid, 0, sizeof(pid)) != sizeof(pid)) {
258 printf("write failed (%s)\n", cli_errstr(c));
263 if (cli_write(c, fnum, 0, (char *)buf,
264 sizeof(pid)+(j*sizeof(buf)),
265 sizeof(buf)) != sizeof(buf)) {
266 printf("write failed (%s)\n", cli_errstr(c));
273 if (cli_read(c, fnum, (char *)&pid2, 0, sizeof(pid)) != sizeof(pid)) {
274 printf("read failed (%s)\n", cli_errstr(c));
279 printf("data corruption!\n");
283 if (!cli_close(c, fnum)) {
284 printf("close failed (%s)\n", cli_errstr(c));
288 if (!cli_unlink(c, fname)) {
289 printf("unlink failed (%s)\n", cli_errstr(c));
293 if (!cli_unlock(c, fnum2, n*sizeof(int), sizeof(int))) {
294 printf("unlock failed (%s)\n", cli_errstr(c));
300 cli_unlink(c, lockfname);
307 static BOOL run_torture(int dummy)
309 struct cli_state cli;
314 cli_sockopt(&cli, sockops);
316 ret = rw_torture(&cli);
318 if (!torture_close_connection(&cli)) {
325 static BOOL rw_torture3(struct cli_state *c, char *lockfname)
332 unsigned countprev = 0;
337 for (i = 0; i < sizeof(buf); i += sizeof(uint32))
339 SIVAL(buf, i, sys_random());
344 fnum = cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
347 printf("first open read/write of %s failed (%s)\n",
348 lockfname, cli_errstr(c));
354 for (i = 0; i < 500 && fnum == -1; i++)
356 fnum = cli_open(c, lockfname, O_RDONLY,
361 printf("second open read-only of %s failed (%s)\n",
362 lockfname, cli_errstr(c));
368 for (count = 0; count < sizeof(buf); count += sent)
370 if (count >= countprev) {
371 printf("%d %8d\r", i, count);
374 countprev += (sizeof(buf) / 20);
379 sent = ((unsigned)sys_random()%(20))+ 1;
380 if (sent > sizeof(buf) - count)
382 sent = sizeof(buf) - count;
385 if (cli_write(c, fnum, 0, buf+count, count, (size_t)sent) != sent) {
386 printf("write failed (%s)\n", cli_errstr(c));
392 sent = cli_read(c, fnum, buf_rd+count, count,
396 printf("read failed offset:%d size:%d (%s)\n",
397 count, sizeof(buf)-count,
404 if (memcmp(buf_rd+count, buf+count, sent) != 0)
406 printf("read/write compare failed\n");
407 printf("offset: %d req %d recvd %d\n",
408 count, sizeof(buf)-count, sent);
417 if (!cli_close(c, fnum)) {
418 printf("close failed (%s)\n", cli_errstr(c));
425 static BOOL rw_torture2(struct cli_state *c1, struct cli_state *c2)
427 char *lockfname = "\\torture2.lck";
432 uchar buf_rd[131072];
436 if (!cli_unlink(c1, lockfname)) {
437 printf("unlink failed (%s) (normal, this file should not exist)\n", cli_errstr(c1));
440 fnum1 = cli_open(c1, lockfname, O_RDWR | O_CREAT | O_EXCL,
443 printf("first open read/write of %s failed (%s)\n",
444 lockfname, cli_errstr(c1));
447 fnum2 = cli_open(c2, lockfname, O_RDONLY,
450 printf("second open read-only of %s failed (%s)\n",
451 lockfname, cli_errstr(c2));
452 cli_close(c1, fnum1);
456 for (i=0;i<numops;i++)
458 size_t buf_size = ((unsigned)sys_random()%(sizeof(buf)-1))+ 1;
460 printf("%d\r", i); fflush(stdout);
463 generate_random_buffer(buf, buf_size, False);
465 if (cli_write(c1, fnum1, 0, buf, 0, buf_size) != buf_size) {
466 printf("write failed (%s)\n", cli_errstr(c1));
470 if ((bytes_read = cli_read(c2, fnum2, buf_rd, 0, buf_size)) != buf_size) {
471 printf("read failed (%s)\n", cli_errstr(c2));
472 printf("read %d, expected %d\n", bytes_read, buf_size);
476 if (memcmp(buf_rd, buf, buf_size) != 0)
478 printf("read/write compare failed\n");
483 if (!cli_close(c2, fnum2)) {
484 printf("close failed (%s)\n", cli_errstr(c2));
487 if (!cli_close(c1, fnum1)) {
488 printf("close failed (%s)\n", cli_errstr(c1));
492 if (!cli_unlink(c1, lockfname)) {
493 printf("unlink failed (%s)\n", cli_errstr(c1));
500 static BOOL run_readwritetest(int dummy)
502 static struct cli_state cli1, cli2;
505 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
508 cli_sockopt(&cli1, sockops);
509 cli_sockopt(&cli2, sockops);
511 printf("starting readwritetest\n");
513 test1 = rw_torture2(&cli1, &cli2);
514 printf("Passed readwritetest v1: %s\n", BOOLSTR(test1));
516 test2 = rw_torture2(&cli1, &cli1);
517 printf("Passed readwritetest v2: %s\n", BOOLSTR(test2));
519 if (!torture_close_connection(&cli1)) {
523 if (!torture_close_connection(&cli2)) {
527 return (test1 && test2);
530 static BOOL run_readwritemulti(int dummy)
532 static struct cli_state cli;
537 cli_sockopt(&cli, sockops);
539 printf("run_readwritemulti: fname %s\n", randomfname);
540 test = rw_torture3(&cli, randomfname);
542 if (!torture_close_connection(&cli)) {
549 static BOOL run_readwritelarge(int dummy)
551 static struct cli_state cli1;
553 char *lockfname = "\\large.dat";
558 if (!torture_open_connection(&cli1)) {
561 cli_sockopt(&cli1, sockops);
562 memset(buf,'\0',sizeof(buf));
564 cli1.max_xmit = 0x11000;
566 printf("starting readwritelarge\n");
568 cli_unlink(&cli1, lockfname);
570 fnum1 = cli_open(&cli1, lockfname, O_RDWR | O_CREAT | O_EXCL, DENY_NONE);
572 printf("open read/write of %s failed (%s)\n", lockfname, cli_errstr(&cli1));
576 cli_write(&cli1, fnum1, 0, buf, 0, sizeof(buf));
578 if (!cli_close(&cli1, fnum1)) {
579 printf("close failed (%s)\n", cli_errstr(&cli1));
583 if (!cli_qpathinfo(&cli1, lockfname, NULL, NULL, NULL, &fsize, NULL)) {
584 printf("qpathinfo failed (%s)\n", cli_errstr(&cli1));
588 if (fsize == sizeof(buf))
589 printf("readwritelarge test 1 succeeded (size = %x)\n", fsize);
591 printf("readwritelarge test 1 failed (size = %x)\n", fsize);
595 if (!cli_unlink(&cli1, lockfname)) {
596 printf("unlink failed (%s)\n", cli_errstr(&cli1));
600 fnum1 = cli_open(&cli1, lockfname, O_RDWR | O_CREAT | O_EXCL, DENY_NONE);
602 printf("open read/write of %s failed (%s)\n", lockfname, cli_errstr(&cli1));
606 cli_smbwrite(&cli1, fnum1, buf, 0, sizeof(buf));
608 if (!cli_close(&cli1, fnum1)) {
609 printf("close failed (%s)\n", cli_errstr(&cli1));
613 if (!torture_close_connection(&cli1)) {
621 /* run a test that simulates an approximate netbench client load */
622 static BOOL run_netbench(int client)
624 struct cli_state cli;
635 cli_sockopt(&cli, sockops);
639 slprintf(cname,sizeof(fname), "CLIENT%d", client);
641 f = fopen("client.txt", "r");
644 perror("client.txt");
648 while (fgets(line, sizeof(line)-1, f)) {
651 line[strlen(line)-1] = 0;
653 /* printf("[%d] %s\n", line_count, line); */
655 all_string_sub(line,"CLIENT1", cname, sizeof(line));
657 for (i=0;i<20;i++) params[i] = "";
659 /* parse the command parameters */
660 params[0] = strtok(line," ");
662 while (params[i]) params[++i] = strtok(NULL," ");
668 if (strcmp(params[1],"REQUEST") == 0) {
669 if (!strcmp(params[0],"SMBopenX")) {
670 fstrcpy(fname, params[5]);
671 } else if (!strcmp(params[0],"SMBclose")) {
672 nb_close(atoi(params[3]));
673 } else if (!strcmp(params[0],"SMBmkdir")) {
675 } else if (!strcmp(params[0],"CREATE")) {
676 nb_create(params[3], atoi(params[5]));
677 } else if (!strcmp(params[0],"SMBrmdir")) {
679 } else if (!strcmp(params[0],"SMBunlink")) {
680 fstrcpy(fname, params[3]);
681 } else if (!strcmp(params[0],"SMBmv")) {
682 nb_rename(params[3], params[5]);
683 } else if (!strcmp(params[0],"SMBgetatr")) {
684 fstrcpy(fname, params[3]);
685 } else if (!strcmp(params[0],"SMBwrite")) {
686 nb_write(atoi(params[3]),
687 atoi(params[5]), atoi(params[7]));
688 } else if (!strcmp(params[0],"SMBwritebraw")) {
689 nb_write(atoi(params[3]),
690 atoi(params[7]), atoi(params[5]));
691 } else if (!strcmp(params[0],"SMBreadbraw")) {
692 nb_read(atoi(params[3]),
693 atoi(params[7]), atoi(params[5]));
694 } else if (!strcmp(params[0],"SMBread")) {
695 nb_read(atoi(params[3]),
696 atoi(params[5]), atoi(params[7]));
699 if (!strcmp(params[0],"SMBopenX")) {
700 if (!strncmp(params[2], "ERR", 3)) continue;
701 nb_open(fname, atoi(params[3]), atoi(params[5]));
702 } else if (!strcmp(params[0],"SMBgetatr")) {
703 if (!strncmp(params[2], "ERR", 3)) continue;
704 nb_stat(fname, atoi(params[3]));
705 } else if (!strcmp(params[0],"SMBunlink")) {
706 if (!strncmp(params[2], "ERR", 3)) continue;
713 slprintf(fname,sizeof(fname), "CLIENTS/CLIENT%d", client);
719 if (!torture_close_connection(&cli)) {
727 /* run a test that simulates an approximate netbench w9X client load */
728 static BOOL run_nbw95(int dummy)
732 t = create_procs(run_netbench, &correct);
733 /* to produce a netbench result we scale accoding to the
734 netbench measured throughput for the run that produced the
735 sniff that was used to produce client.txt. That run used 2
736 clients and ran for 660 seconds to produce a result of
738 printf("Throughput %g MB/sec (NB=%g MB/sec %g MBit/sec)\n",
739 132*nprocs/t, 0.5*0.5*nprocs*660/t, 2*nprocs*660/t);
743 /* run a test that simulates an approximate netbench wNT client load */
744 static BOOL run_nbwnt(int dummy)
748 t = create_procs(run_netbench, &correct);
749 printf("Throughput %g MB/sec (NB=%g MB/sec %g MBit/sec)\n",
750 132*nprocs/t, 0.5*0.5*nprocs*660/t, 2*nprocs*660/t);
757 This test checks for two things:
759 1) correct support for retaining locks over a close (ie. the server
760 must not use posix semantics)
761 2) support for lock timeouts
763 static BOOL run_locktest1(int dummy)
765 static struct cli_state cli1, cli2;
766 char *fname = "\\lockt1.lck";
767 int fnum1, fnum2, fnum3;
770 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
773 cli_sockopt(&cli1, sockops);
774 cli_sockopt(&cli2, sockops);
776 printf("starting locktest1\n");
778 cli_unlink(&cli1, fname);
780 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
782 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
785 fnum2 = cli_open(&cli1, fname, O_RDWR, DENY_NONE);
787 printf("open2 of %s failed (%s)\n", fname, cli_errstr(&cli1));
790 fnum3 = cli_open(&cli2, fname, O_RDWR, DENY_NONE);
792 printf("open3 of %s failed (%s)\n", fname, cli_errstr(&cli2));
796 if (!cli_lock(&cli1, fnum1, 0, 4, 0, WRITE_LOCK)) {
797 printf("lock1 failed (%s)\n", cli_errstr(&cli1));
802 if (cli_lock(&cli2, fnum3, 0, 4, 0, WRITE_LOCK)) {
803 printf("lock2 succeeded! This is a locking bug\n");
806 if (!check_error(__LINE__, &cli2, ERRDOS, ERRlock,
807 NT_STATUS_LOCK_NOT_GRANTED)) return False;
811 printf("Testing lock timeouts\n");
813 if (cli_lock(&cli2, fnum3, 0, 4, 10*1000, WRITE_LOCK)) {
814 printf("lock3 succeeded! This is a locking bug\n");
817 if (!check_error(__LINE__, &cli2, ERRDOS, ERRlock,
818 NT_STATUS_LOCK_NOT_GRANTED)) return False;
823 printf("error: This server appears not to support timed lock requests\n");
826 if (!cli_close(&cli1, fnum2)) {
827 printf("close1 failed (%s)\n", cli_errstr(&cli1));
831 if (cli_lock(&cli2, fnum3, 0, 4, 0, WRITE_LOCK)) {
832 printf("lock4 succeeded! This is a locking bug\n");
835 if (!check_error(__LINE__, &cli2, ERRDOS, ERRlock,
836 NT_STATUS_LOCK_NOT_GRANTED)) return False;
839 if (!cli_close(&cli1, fnum1)) {
840 printf("close2 failed (%s)\n", cli_errstr(&cli1));
844 if (!cli_close(&cli2, fnum3)) {
845 printf("close3 failed (%s)\n", cli_errstr(&cli2));
849 if (!cli_unlink(&cli1, fname)) {
850 printf("unlink failed (%s)\n", cli_errstr(&cli1));
855 if (!torture_close_connection(&cli1)) {
859 if (!torture_close_connection(&cli2)) {
863 printf("Passed locktest1\n");
868 checks for correct tconX support
870 static BOOL run_tcon_test(int dummy)
872 static struct cli_state cli1;
873 char *fname = "\\tcontest.tmp";
878 if (!torture_open_connection(&cli1)) {
881 cli_sockopt(&cli1, sockops);
883 printf("starting tcontest\n");
885 cli_unlink(&cli1, fname);
887 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
890 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
896 if (cli_write(&cli1, fnum1, 0, buf, 130, 4) != 4)
898 printf("write failed (%s)", cli_errstr(&cli1));
902 if (!cli_send_tconX(&cli1, share, "?????",
903 password, strlen(password)+1)) {
904 printf("%s refused 2nd tree connect (%s)\n", host,
910 if (cli_write(&cli1, fnum1, 0, buf, 130, 4) == 4)
912 printf("write succeeded (%s)", cli_errstr(&cli1));
916 if (cli_close(&cli1, fnum1)) {
917 printf("close2 succeeded (%s)\n", cli_errstr(&cli1));
921 if (!cli_tdis(&cli1)) {
922 printf("tdis failed (%s)\n", cli_errstr(&cli1));
928 if (!cli_close(&cli1, fnum1)) {
929 printf("close2 failed (%s)\n", cli_errstr(&cli1));
933 if (!torture_close_connection(&cli1)) {
937 printf("Passed tcontest\n");
943 This test checks that
945 1) the server supports multiple locking contexts on the one SMB
946 connection, distinguished by PID.
948 2) the server correctly fails overlapping locks made by the same PID (this
949 goes against POSIX behaviour, which is why it is tricky to implement)
951 3) the server denies unlock requests by an incorrect client PID
953 static BOOL run_locktest2(int dummy)
955 static struct cli_state cli;
956 char *fname = "\\lockt2.lck";
957 int fnum1, fnum2, fnum3;
960 if (!torture_open_connection(&cli)) {
964 cli_sockopt(&cli, sockops);
966 printf("starting locktest2\n");
968 cli_unlink(&cli, fname);
972 fnum1 = cli_open(&cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
974 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli));
978 fnum2 = cli_open(&cli, fname, O_RDWR, DENY_NONE);
980 printf("open2 of %s failed (%s)\n", fname, cli_errstr(&cli));
986 fnum3 = cli_open(&cli, fname, O_RDWR, DENY_NONE);
988 printf("open3 of %s failed (%s)\n", fname, cli_errstr(&cli));
994 if (!cli_lock(&cli, fnum1, 0, 4, 0, WRITE_LOCK)) {
995 printf("lock1 failed (%s)\n", cli_errstr(&cli));
999 if (cli_lock(&cli, fnum1, 0, 4, 0, WRITE_LOCK)) {
1000 printf("WRITE lock1 succeeded! This is a locking bug\n");
1003 if (!check_error(__LINE__, &cli, ERRDOS, ERRlock,
1004 NT_STATUS_LOCK_NOT_GRANTED)) return False;
1007 if (cli_lock(&cli, fnum2, 0, 4, 0, WRITE_LOCK)) {
1008 printf("WRITE lock2 succeeded! This is a locking bug\n");
1011 if (!check_error(__LINE__, &cli, ERRDOS, ERRlock,
1012 NT_STATUS_LOCK_NOT_GRANTED)) return False;
1015 if (cli_lock(&cli, fnum2, 0, 4, 0, READ_LOCK)) {
1016 printf("READ lock2 succeeded! This is a locking bug\n");
1019 if (!check_error(__LINE__, &cli, ERRDOS, ERRlock,
1020 NT_STATUS_LOCK_NOT_GRANTED)) return False;
1023 if (!cli_lock(&cli, fnum1, 100, 4, 0, WRITE_LOCK)) {
1024 printf("lock at 100 failed (%s)\n", cli_errstr(&cli));
1026 cli_setpid(&cli, 2);
1027 if (cli_unlock(&cli, fnum1, 100, 4)) {
1028 printf("unlock at 100 succeeded! This is a locking bug\n");
1032 if (cli_unlock(&cli, fnum1, 0, 4)) {
1033 printf("unlock1 succeeded! This is a locking bug\n");
1036 if (!check_error(__LINE__, &cli,
1038 NT_STATUS_LOCK_NOT_GRANTED)) return False;
1041 if (cli_unlock(&cli, fnum1, 0, 8)) {
1042 printf("unlock2 succeeded! This is a locking bug\n");
1045 if (!check_error(__LINE__, &cli,
1047 NT_STATUS_LOCK_NOT_GRANTED)) return False;
1050 if (cli_lock(&cli, fnum3, 0, 4, 0, WRITE_LOCK)) {
1051 printf("lock3 succeeded! This is a locking bug\n");
1054 if (!check_error(__LINE__, &cli, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False;
1057 cli_setpid(&cli, 1);
1059 if (!cli_close(&cli, fnum1)) {
1060 printf("close1 failed (%s)\n", cli_errstr(&cli));
1064 if (!cli_close(&cli, fnum2)) {
1065 printf("close2 failed (%s)\n", cli_errstr(&cli));
1069 if (!cli_close(&cli, fnum3)) {
1070 printf("close3 failed (%s)\n", cli_errstr(&cli));
1074 if (!torture_close_connection(&cli)) {
1078 printf("locktest2 finished\n");
1085 This test checks that
1087 1) the server supports the full offset range in lock requests
1089 static BOOL run_locktest3(int dummy)
1091 static struct cli_state cli1, cli2;
1092 char *fname = "\\lockt3.lck";
1093 int fnum1, fnum2, i;
1095 BOOL correct = True;
1097 #define NEXT_OFFSET offset += (~(uint32)0) / numops
1099 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
1102 cli_sockopt(&cli1, sockops);
1103 cli_sockopt(&cli2, sockops);
1105 printf("starting locktest3\n");
1107 cli_unlink(&cli1, fname);
1109 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1111 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
1114 fnum2 = cli_open(&cli2, fname, O_RDWR, DENY_NONE);
1116 printf("open2 of %s failed (%s)\n", fname, cli_errstr(&cli2));
1120 for (offset=i=0;i<numops;i++) {
1122 if (!cli_lock(&cli1, fnum1, offset-1, 1, 0, WRITE_LOCK)) {
1123 printf("lock1 %d failed (%s)\n",
1129 if (!cli_lock(&cli2, fnum2, offset-2, 1, 0, WRITE_LOCK)) {
1130 printf("lock2 %d failed (%s)\n",
1137 for (offset=i=0;i<numops;i++) {
1140 if (cli_lock(&cli1, fnum1, offset-2, 1, 0, WRITE_LOCK)) {
1141 printf("error: lock1 %d succeeded!\n", i);
1145 if (cli_lock(&cli2, fnum2, offset-1, 1, 0, WRITE_LOCK)) {
1146 printf("error: lock2 %d succeeded!\n", i);
1150 if (cli_lock(&cli1, fnum1, offset-1, 1, 0, WRITE_LOCK)) {
1151 printf("error: lock3 %d succeeded!\n", i);
1155 if (cli_lock(&cli2, fnum2, offset-2, 1, 0, WRITE_LOCK)) {
1156 printf("error: lock4 %d succeeded!\n", i);
1161 for (offset=i=0;i<numops;i++) {
1164 if (!cli_unlock(&cli1, fnum1, offset-1, 1)) {
1165 printf("unlock1 %d failed (%s)\n",
1171 if (!cli_unlock(&cli2, fnum2, offset-2, 1)) {
1172 printf("unlock2 %d failed (%s)\n",
1179 if (!cli_close(&cli1, fnum1)) {
1180 printf("close1 failed (%s)\n", cli_errstr(&cli1));
1184 if (!cli_close(&cli2, fnum2)) {
1185 printf("close2 failed (%s)\n", cli_errstr(&cli2));
1189 if (!cli_unlink(&cli1, fname)) {
1190 printf("unlink failed (%s)\n", cli_errstr(&cli1));
1194 if (!torture_close_connection(&cli1)) {
1198 if (!torture_close_connection(&cli2)) {
1202 printf("finished locktest3\n");
1207 #define EXPECTED(ret, v) if ((ret) != (v)) { \
1208 printf("** "); correct = False; \
1212 looks at overlapping locks
1214 static BOOL run_locktest4(int dummy)
1216 static struct cli_state cli1, cli2;
1217 char *fname = "\\lockt4.lck";
1218 int fnum1, fnum2, f;
1221 BOOL correct = True;
1223 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
1227 cli_sockopt(&cli1, sockops);
1228 cli_sockopt(&cli2, sockops);
1230 printf("starting locktest4\n");
1232 cli_unlink(&cli1, fname);
1234 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1235 fnum2 = cli_open(&cli2, fname, O_RDWR, DENY_NONE);
1237 memset(buf, 0, sizeof(buf));
1239 if (cli_write(&cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
1240 printf("Failed to create file\n");
1245 ret = cli_lock(&cli1, fnum1, 0, 4, 0, WRITE_LOCK) &&
1246 cli_lock(&cli1, fnum1, 2, 4, 0, WRITE_LOCK);
1247 EXPECTED(ret, False);
1248 printf("the same process %s set overlapping write locks\n", ret?"can":"cannot");
1250 ret = cli_lock(&cli1, fnum1, 10, 4, 0, READ_LOCK) &&
1251 cli_lock(&cli1, fnum1, 12, 4, 0, READ_LOCK);
1252 EXPECTED(ret, True);
1253 printf("the same process %s set overlapping read locks\n", ret?"can":"cannot");
1255 ret = cli_lock(&cli1, fnum1, 20, 4, 0, WRITE_LOCK) &&
1256 cli_lock(&cli2, fnum2, 22, 4, 0, WRITE_LOCK);
1257 EXPECTED(ret, False);
1258 printf("a different connection %s set overlapping write locks\n", ret?"can":"cannot");
1260 ret = cli_lock(&cli1, fnum1, 30, 4, 0, READ_LOCK) &&
1261 cli_lock(&cli2, fnum2, 32, 4, 0, READ_LOCK);
1262 EXPECTED(ret, True);
1263 printf("a different connection %s set overlapping read locks\n", ret?"can":"cannot");
1265 ret = (cli_setpid(&cli1, 1), cli_lock(&cli1, fnum1, 40, 4, 0, WRITE_LOCK)) &&
1266 (cli_setpid(&cli1, 2), cli_lock(&cli1, fnum1, 42, 4, 0, WRITE_LOCK));
1267 EXPECTED(ret, False);
1268 printf("a different pid %s set overlapping write locks\n", ret?"can":"cannot");
1270 ret = (cli_setpid(&cli1, 1), cli_lock(&cli1, fnum1, 50, 4, 0, READ_LOCK)) &&
1271 (cli_setpid(&cli1, 2), cli_lock(&cli1, fnum1, 52, 4, 0, READ_LOCK));
1272 EXPECTED(ret, True);
1273 printf("a different pid %s set overlapping read locks\n", ret?"can":"cannot");
1275 ret = cli_lock(&cli1, fnum1, 60, 4, 0, READ_LOCK) &&
1276 cli_lock(&cli1, fnum1, 60, 4, 0, READ_LOCK);
1277 EXPECTED(ret, True);
1278 printf("the same process %s set the same read lock twice\n", ret?"can":"cannot");
1280 ret = cli_lock(&cli1, fnum1, 70, 4, 0, WRITE_LOCK) &&
1281 cli_lock(&cli1, fnum1, 70, 4, 0, WRITE_LOCK);
1282 EXPECTED(ret, False);
1283 printf("the same process %s set the same write lock twice\n", ret?"can":"cannot");
1285 ret = cli_lock(&cli1, fnum1, 80, 4, 0, READ_LOCK) &&
1286 cli_lock(&cli1, fnum1, 80, 4, 0, WRITE_LOCK);
1287 EXPECTED(ret, False);
1288 printf("the same process %s overlay a read lock with a write lock\n", ret?"can":"cannot");
1290 ret = cli_lock(&cli1, fnum1, 90, 4, 0, WRITE_LOCK) &&
1291 cli_lock(&cli1, fnum1, 90, 4, 0, READ_LOCK);
1292 EXPECTED(ret, True);
1293 printf("the same process %s overlay a write lock with a read lock\n", ret?"can":"cannot");
1295 ret = (cli_setpid(&cli1, 1), cli_lock(&cli1, fnum1, 100, 4, 0, WRITE_LOCK)) &&
1296 (cli_setpid(&cli1, 2), cli_lock(&cli1, fnum1, 100, 4, 0, READ_LOCK));
1297 EXPECTED(ret, False);
1298 printf("a different pid %s overlay a write lock with a read lock\n", ret?"can":"cannot");
1300 ret = cli_lock(&cli1, fnum1, 110, 4, 0, READ_LOCK) &&
1301 cli_lock(&cli1, fnum1, 112, 4, 0, READ_LOCK) &&
1302 cli_unlock(&cli1, fnum1, 110, 6);
1303 EXPECTED(ret, False);
1304 printf("the same process %s coalesce read locks\n", ret?"can":"cannot");
1307 ret = cli_lock(&cli1, fnum1, 120, 4, 0, WRITE_LOCK) &&
1308 (cli_read(&cli2, fnum2, buf, 120, 4) == 4);
1309 EXPECTED(ret, False);
1310 printf("this server %s strict write locking\n", ret?"doesn't do":"does");
1312 ret = cli_lock(&cli1, fnum1, 130, 4, 0, READ_LOCK) &&
1313 (cli_write(&cli2, fnum2, 0, buf, 130, 4) == 4);
1314 EXPECTED(ret, False);
1315 printf("this server %s strict read locking\n", ret?"doesn't do":"does");
1318 ret = cli_lock(&cli1, fnum1, 140, 4, 0, READ_LOCK) &&
1319 cli_lock(&cli1, fnum1, 140, 4, 0, READ_LOCK) &&
1320 cli_unlock(&cli1, fnum1, 140, 4) &&
1321 cli_unlock(&cli1, fnum1, 140, 4);
1322 EXPECTED(ret, True);
1323 printf("this server %s do recursive read locking\n", ret?"does":"doesn't");
1326 ret = cli_lock(&cli1, fnum1, 150, 4, 0, WRITE_LOCK) &&
1327 cli_lock(&cli1, fnum1, 150, 4, 0, READ_LOCK) &&
1328 cli_unlock(&cli1, fnum1, 150, 4) &&
1329 (cli_read(&cli2, fnum2, buf, 150, 4) == 4) &&
1330 !(cli_write(&cli2, fnum2, 0, buf, 150, 4) == 4) &&
1331 cli_unlock(&cli1, fnum1, 150, 4);
1332 EXPECTED(ret, True);
1333 printf("this server %s do recursive lock overlays\n", ret?"does":"doesn't");
1335 ret = cli_lock(&cli1, fnum1, 160, 4, 0, READ_LOCK) &&
1336 cli_unlock(&cli1, fnum1, 160, 4) &&
1337 (cli_write(&cli2, fnum2, 0, buf, 160, 4) == 4) &&
1338 (cli_read(&cli2, fnum2, buf, 160, 4) == 4);
1339 EXPECTED(ret, True);
1340 printf("the same process %s remove a read lock using write locking\n", ret?"can":"cannot");
1342 ret = cli_lock(&cli1, fnum1, 170, 4, 0, WRITE_LOCK) &&
1343 cli_unlock(&cli1, fnum1, 170, 4) &&
1344 (cli_write(&cli2, fnum2, 0, buf, 170, 4) == 4) &&
1345 (cli_read(&cli2, fnum2, buf, 170, 4) == 4);
1346 EXPECTED(ret, True);
1347 printf("the same process %s remove a write lock using read locking\n", ret?"can":"cannot");
1349 ret = cli_lock(&cli1, fnum1, 190, 4, 0, WRITE_LOCK) &&
1350 cli_lock(&cli1, fnum1, 190, 4, 0, READ_LOCK) &&
1351 cli_unlock(&cli1, fnum1, 190, 4) &&
1352 !(cli_write(&cli2, fnum2, 0, buf, 190, 4) == 4) &&
1353 (cli_read(&cli2, fnum2, buf, 190, 4) == 4);
1354 EXPECTED(ret, True);
1355 printf("the same process %s remove the first lock first\n", ret?"does":"doesn't");
1357 cli_close(&cli1, fnum1);
1358 cli_close(&cli2, fnum2);
1359 fnum1 = cli_open(&cli1, fname, O_RDWR, DENY_NONE);
1360 f = cli_open(&cli1, fname, O_RDWR, DENY_NONE);
1361 ret = cli_lock(&cli1, fnum1, 0, 8, 0, READ_LOCK) &&
1362 cli_lock(&cli1, f, 0, 1, 0, READ_LOCK) &&
1363 cli_close(&cli1, fnum1) &&
1364 ((fnum1 = cli_open(&cli1, fname, O_RDWR, DENY_NONE)) != -1) &&
1365 cli_lock(&cli1, fnum1, 7, 1, 0, WRITE_LOCK);
1366 cli_close(&cli1, f);
1367 EXPECTED(ret, True);
1368 printf("the server %s have the NT byte range lock bug\n", !ret?"does":"doesn't");
1371 cli_close(&cli1, fnum1);
1372 cli_close(&cli2, fnum2);
1373 cli_unlink(&cli1, fname);
1374 torture_close_connection(&cli1);
1375 torture_close_connection(&cli2);
1377 printf("finished locktest4\n");
1382 looks at lock upgrade/downgrade.
1384 static BOOL run_locktest5(int dummy)
1386 static struct cli_state cli1, cli2;
1387 char *fname = "\\lockt5.lck";
1388 int fnum1, fnum2, fnum3;
1391 BOOL correct = True;
1393 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
1397 cli_sockopt(&cli1, sockops);
1398 cli_sockopt(&cli2, sockops);
1400 printf("starting locktest5\n");
1402 cli_unlink(&cli1, fname);
1404 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1405 fnum2 = cli_open(&cli2, fname, O_RDWR, DENY_NONE);
1406 fnum3 = cli_open(&cli1, fname, O_RDWR, DENY_NONE);
1408 memset(buf, 0, sizeof(buf));
1410 if (cli_write(&cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
1411 printf("Failed to create file\n");
1416 /* Check for NT bug... */
1417 ret = cli_lock(&cli1, fnum1, 0, 8, 0, READ_LOCK) &&
1418 cli_lock(&cli1, fnum3, 0, 1, 0, READ_LOCK);
1419 cli_close(&cli1, fnum1);
1420 fnum1 = cli_open(&cli1, fname, O_RDWR, DENY_NONE);
1421 ret = cli_lock(&cli1, fnum1, 7, 1, 0, WRITE_LOCK);
1422 EXPECTED(ret, True);
1423 printf("this server %s the NT locking bug\n", ret ? "doesn't have" : "has");
1424 cli_close(&cli1, fnum1);
1425 fnum1 = cli_open(&cli1, fname, O_RDWR, DENY_NONE);
1426 cli_unlock(&cli1, fnum3, 0, 1);
1428 ret = cli_lock(&cli1, fnum1, 0, 4, 0, WRITE_LOCK) &&
1429 cli_lock(&cli1, fnum1, 1, 1, 0, READ_LOCK);
1430 EXPECTED(ret, True);
1431 printf("the same process %s overlay a write with a read lock\n", ret?"can":"cannot");
1433 ret = cli_lock(&cli2, fnum2, 0, 4, 0, READ_LOCK);
1434 EXPECTED(ret, False);
1436 printf("a different processs %s get a read lock on the first process lock stack\n", ret?"can":"cannot");
1438 /* Unlock the process 2 lock. */
1439 cli_unlock(&cli2, fnum2, 0, 4);
1441 ret = cli_lock(&cli1, fnum3, 0, 4, 0, READ_LOCK);
1442 EXPECTED(ret, False);
1444 printf("the same processs on a different fnum %s get a read lock\n", ret?"can":"cannot");
1446 /* Unlock the process 1 fnum3 lock. */
1447 cli_unlock(&cli1, fnum3, 0, 4);
1449 /* Stack 2 more locks here. */
1450 ret = cli_lock(&cli1, fnum1, 0, 4, 0, READ_LOCK) &&
1451 cli_lock(&cli1, fnum1, 0, 4, 0, READ_LOCK);
1453 EXPECTED(ret, True);
1454 printf("the same process %s stack read locks\n", ret?"can":"cannot");
1456 /* Unlock the first process lock, then check this was the WRITE lock that was
1459 ret = cli_unlock(&cli1, fnum1, 0, 4) &&
1460 cli_lock(&cli2, fnum2, 0, 4, 0, READ_LOCK);
1462 EXPECTED(ret, True);
1463 printf("the first unlock removes the %s lock\n", ret?"WRITE":"READ");
1465 /* Unlock the process 2 lock. */
1466 cli_unlock(&cli2, fnum2, 0, 4);
1468 /* We should have 3 stacked locks here. Ensure we need to do 3 unlocks. */
1470 ret = cli_unlock(&cli1, fnum1, 1, 1) &&
1471 cli_unlock(&cli1, fnum1, 0, 4) &&
1472 cli_unlock(&cli1, fnum1, 0, 4);
1474 EXPECTED(ret, True);
1475 printf("the same process %s unlock the stack of 4 locks\n", ret?"can":"cannot");
1477 /* Ensure the next unlock fails. */
1478 ret = cli_unlock(&cli1, fnum1, 0, 4);
1479 EXPECTED(ret, False);
1480 printf("the same process %s count the lock stack\n", !ret?"can":"cannot");
1482 /* Ensure connection 2 can get a write lock. */
1483 ret = cli_lock(&cli2, fnum2, 0, 4, 0, WRITE_LOCK);
1484 EXPECTED(ret, True);
1486 printf("a different processs %s get a write lock on the unlocked stack\n", ret?"can":"cannot");
1490 cli_close(&cli1, fnum1);
1491 cli_close(&cli2, fnum2);
1492 cli_unlink(&cli1, fname);
1493 if (!torture_close_connection(&cli1)) {
1496 if (!torture_close_connection(&cli2)) {
1500 printf("finished locktest5\n");
1506 test whether fnums and tids open on one VC are available on another (a major
1509 static BOOL run_fdpasstest(int dummy)
1511 static struct cli_state cli1, cli2, cli3;
1512 char *fname = "\\fdpass.tst";
1516 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
1519 cli_sockopt(&cli1, sockops);
1520 cli_sockopt(&cli2, sockops);
1522 printf("starting fdpasstest\n");
1524 cli_unlink(&cli1, fname);
1526 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1528 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
1532 if (cli_write(&cli1, fnum1, 0, "hello world\n", 0, 13) != 13) {
1533 printf("write failed (%s)\n", cli_errstr(&cli1));
1538 cli3.vuid = cli1.vuid;
1539 cli3.cnum = cli1.cnum;
1540 cli3.pid = cli1.pid;
1542 if (cli_read(&cli3, fnum1, buf, 0, 13) == 13) {
1543 printf("read succeeded! nasty security hole [%s]\n",
1548 cli_close(&cli1, fnum1);
1549 cli_unlink(&cli1, fname);
1551 torture_close_connection(&cli1);
1552 torture_close_connection(&cli2);
1554 printf("finished fdpasstest\n");
1560 This test checks that
1562 1) the server does not allow an unlink on a file that is open
1564 static BOOL run_unlinktest(int dummy)
1566 static struct cli_state cli;
1567 char *fname = "\\unlink.tst";
1569 BOOL correct = True;
1571 if (!torture_open_connection(&cli)) {
1575 cli_sockopt(&cli, sockops);
1577 printf("starting unlink test\n");
1579 cli_unlink(&cli, fname);
1581 cli_setpid(&cli, 1);
1583 fnum = cli_open(&cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1585 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli));
1589 if (cli_unlink(&cli, fname)) {
1590 printf("error: server allowed unlink on an open file\n");
1593 correct = check_error(__LINE__, &cli, ERRDOS, ERRbadshare,
1594 NT_STATUS_SHARING_VIOLATION);
1597 cli_close(&cli, fnum);
1598 cli_unlink(&cli, fname);
1600 if (!torture_close_connection(&cli)) {
1604 printf("unlink test finished\n");
1611 test how many open files this server supports on the one socket
1613 static BOOL run_maxfidtest(int dummy)
1615 static struct cli_state cli;
1616 char *template = "\\maxfid.%d.%d";
1618 int fnums[0x11000], i;
1620 BOOL correct = True;
1625 printf("failed to connect\n");
1629 cli_sockopt(&cli, sockops);
1631 for (i=0; i<0x11000; i++) {
1632 slprintf(fname,sizeof(fname)-1,template, i,(int)getpid());
1633 if ((fnums[i] = cli_open(&cli, fname,
1634 O_RDWR|O_CREAT|O_TRUNC, DENY_NONE)) ==
1636 printf("open of %s failed (%s)\n",
1637 fname, cli_errstr(&cli));
1638 printf("maximum fnum is %d\n", i);
1646 printf("cleaning up\n");
1648 slprintf(fname,sizeof(fname)-1,template, i,(int)getpid());
1649 cli_close(&cli, fnums[i]);
1650 if (!cli_unlink(&cli, fname)) {
1651 printf("unlink of %s failed (%s)\n",
1652 fname, cli_errstr(&cli));
1659 printf("maxfid test finished\n");
1660 if (!torture_close_connection(&cli)) {
1666 /* generate a random buffer */
1667 static void rand_buf(char *buf, int len)
1670 *buf = (char)sys_random();
1675 /* send smb negprot commands, not reading the response */
1676 static BOOL run_negprot_nowait(int dummy)
1679 static struct cli_state cli;
1680 BOOL correct = True;
1682 printf("starting negprot nowait test\n");
1684 if (!open_nbt_connection(&cli)) {
1688 for (i=0;i<50000;i++) {
1689 cli_negprot_send(&cli);
1692 if (!torture_close_connection(&cli)) {
1696 printf("finished negprot nowait test\n");
1702 /* send random IPC commands */
1703 static BOOL run_randomipc(int dummy)
1705 char *rparam = NULL;
1709 int api, param_len, i;
1710 static struct cli_state cli;
1711 BOOL correct = True;
1714 printf("starting random ipc test\n");
1716 if (!torture_open_connection(&cli)) {
1720 for (i=0;i<count;i++) {
1721 api = sys_random() % 500;
1722 param_len = (sys_random() % 64);
1724 rand_buf(param, param_len);
1729 param, param_len, 8,
1730 NULL, 0, BUFFER_SIZE,
1734 printf("%d/%d\r", i,count);
1737 printf("%d/%d\n", i, count);
1739 if (!torture_close_connection(&cli)) {
1743 printf("finished random ipc test\n");
1750 static void browse_callback(const char *sname, uint32 stype,
1751 const char *comment, void *state)
1753 printf("\t%20.20s %08x %s\n", sname, stype, comment);
1759 This test checks the browse list code
1762 static BOOL run_browsetest(int dummy)
1764 static struct cli_state cli;
1765 BOOL correct = True;
1767 printf("starting browse test\n");
1769 if (!torture_open_connection(&cli)) {
1773 printf("domain list:\n");
1774 cli_NetServerEnum(&cli, cli.server_domain,
1775 SV_TYPE_DOMAIN_ENUM,
1776 browse_callback, NULL);
1778 printf("machine list:\n");
1779 cli_NetServerEnum(&cli, cli.server_domain,
1781 browse_callback, NULL);
1783 if (!torture_close_connection(&cli)) {
1787 printf("browse test finished\n");
1795 This checks how the getatr calls works
1797 static BOOL run_attrtest(int dummy)
1799 static struct cli_state cli;
1802 char *fname = "\\attrib.tst";
1803 BOOL correct = True;
1805 printf("starting attrib test\n");
1807 if (!torture_open_connection(&cli)) {
1811 cli_unlink(&cli, fname);
1812 fnum = cli_open(&cli, fname,
1813 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1814 cli_close(&cli, fnum);
1815 if (!cli_getatr(&cli, fname, NULL, NULL, &t)) {
1816 printf("getatr failed (%s)\n", cli_errstr(&cli));
1820 if (abs(t - time(NULL)) > 2) {
1821 printf("ERROR: SMBgetatr bug. time is %s",
1827 t2 = t-60*60*24; /* 1 day ago */
1829 if (!cli_setatr(&cli, fname, 0, t2)) {
1830 printf("setatr failed (%s)\n", cli_errstr(&cli));
1834 if (!cli_getatr(&cli, fname, NULL, NULL, &t)) {
1835 printf("getatr failed (%s)\n", cli_errstr(&cli));
1840 printf("ERROR: getatr/setatr bug. times are\n%s",
1842 printf("%s", ctime(&t2));
1846 cli_unlink(&cli, fname);
1848 if (!torture_close_connection(&cli)) {
1852 printf("attrib test finished\n");
1859 This checks a couple of trans2 calls
1861 static BOOL run_trans2test(int dummy)
1863 static struct cli_state cli;
1866 time_t c_time, a_time, m_time, w_time, m_time2;
1867 char *fname = "\\trans2.tst";
1868 char *dname = "\\trans2";
1869 char *fname2 = "\\trans2\\trans2.tst";
1870 BOOL correct = True;
1872 printf("starting trans2 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 if (!cli_qfileinfo(&cli, fnum, NULL, &size, &c_time, &a_time, &m_time,
1883 printf("ERROR: qfileinfo failed (%s)\n", cli_errstr(&cli));
1886 cli_close(&cli, fnum);
1890 cli_unlink(&cli, fname);
1891 fnum = cli_open(&cli, fname,
1892 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1894 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli));
1897 cli_close(&cli, fnum);
1899 if (!cli_qpathinfo(&cli, fname, &c_time, &a_time, &m_time, &size, NULL)) {
1900 printf("ERROR: qpathinfo failed (%s)\n", cli_errstr(&cli));
1903 if (c_time != m_time) {
1904 printf("create time=%s", ctime(&c_time));
1905 printf("modify time=%s", ctime(&m_time));
1906 printf("This system appears to have sticky create times\n");
1909 if (a_time % (60*60) == 0) {
1910 printf("access time=%s", ctime(&a_time));
1911 printf("This system appears to set a midnight access time\n");
1915 if (abs(m_time - time(NULL)) > 60*60*24*7) {
1916 printf("ERROR: totally incorrect times - maybe word reversed? mtime=%s", ctime(&m_time));
1922 cli_unlink(&cli, fname);
1923 fnum = cli_open(&cli, fname,
1924 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1925 cli_close(&cli, fnum);
1926 if (!cli_qpathinfo2(&cli, fname, &c_time, &a_time, &m_time,
1927 &w_time, &size, NULL, NULL)) {
1928 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli));
1931 if (w_time < 60*60*24*2) {
1932 printf("write time=%s", ctime(&w_time));
1933 printf("This system appears to set a initial 0 write time\n");
1938 cli_unlink(&cli, fname);
1941 /* check if the server updates the directory modification time
1942 when creating a new file */
1943 if (!cli_mkdir(&cli, dname)) {
1944 printf("ERROR: mkdir failed (%s)\n", cli_errstr(&cli));
1948 if (!cli_qpathinfo2(&cli, "\\trans2\\", &c_time, &a_time, &m_time,
1949 &w_time, &size, NULL, NULL)) {
1950 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli));
1954 fnum = cli_open(&cli, fname2,
1955 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1956 cli_write(&cli, fnum, 0, (char *)&fnum, 0, sizeof(fnum));
1957 cli_close(&cli, fnum);
1958 if (!cli_qpathinfo2(&cli, "\\trans2\\", &c_time, &a_time, &m_time2,
1959 &w_time, &size, NULL, NULL)) {
1960 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli));
1963 if (m_time2 == m_time) {
1964 printf("This system does not update directory modification times\n");
1968 cli_unlink(&cli, fname2);
1969 cli_rmdir(&cli, dname);
1971 if (!torture_close_connection(&cli)) {
1975 printf("trans2 test finished\n");
1981 This checks new W2K calls.
1984 static BOOL new_trans(struct cli_state *pcli, int fnum, int level)
1987 BOOL correct = True;
1989 memset(buf, 0xff, sizeof(buf));
1991 if (!cli_qfileinfo_test(pcli, fnum, level, buf)) {
1992 printf("ERROR: qfileinfo (%d) failed (%s)\n", level, cli_errstr(pcli));
1995 printf("qfileinfo: level %d\n", level);
1996 dump_data(0, buf, 256);
2002 static BOOL run_w2ktest(int dummy)
2004 static struct cli_state cli;
2006 char *fname = "\\w2ktest\\w2k.tst";
2008 BOOL correct = True;
2010 printf("starting w2k test\n");
2012 if (!torture_open_connection(&cli)) {
2016 fnum = cli_open(&cli, fname,
2017 O_RDWR | O_CREAT , DENY_NONE);
2019 for (level = 1004; level < 1040; level++) {
2020 new_trans(&cli, fnum, level);
2023 cli_close(&cli, fnum);
2025 if (!torture_close_connection(&cli)) {
2029 printf("w2k test finished\n");
2036 this is a harness for some oplock tests
2038 static BOOL run_oplock1(int dummy)
2040 static struct cli_state cli1;
2041 char *fname = "\\lockt1.lck";
2043 BOOL correct = True;
2045 printf("starting oplock test 1\n");
2047 if (!torture_open_connection(&cli1)) {
2051 cli_unlink(&cli1, fname);
2053 cli_sockopt(&cli1, sockops);
2055 cli1.use_oplocks = True;
2057 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2059 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2063 cli1.use_oplocks = False;
2065 cli_unlink(&cli1, fname);
2066 cli_unlink(&cli1, fname);
2068 if (!cli_close(&cli1, fnum1)) {
2069 printf("close2 failed (%s)\n", cli_errstr(&cli1));
2073 if (!cli_unlink(&cli1, fname)) {
2074 printf("unlink failed (%s)\n", cli_errstr(&cli1));
2078 if (!torture_close_connection(&cli1)) {
2082 printf("finished oplock test 1\n");
2087 static BOOL run_oplock2(int dummy)
2089 static struct cli_state cli1, cli2;
2090 char *fname = "\\lockt2.lck";
2092 int saved_use_oplocks = use_oplocks;
2094 BOOL correct = True;
2095 volatile BOOL *shared_correct;
2097 shared_correct = (volatile BOOL *)shm_setup(sizeof(BOOL));
2098 *shared_correct = True;
2100 use_level_II_oplocks = True;
2103 printf("starting oplock test 2\n");
2105 if (!torture_open_connection(&cli1)) {
2106 use_level_II_oplocks = False;
2107 use_oplocks = saved_use_oplocks;
2111 cli1.use_oplocks = True;
2112 cli1.use_level_II_oplocks = True;
2114 if (!torture_open_connection(&cli2)) {
2115 use_level_II_oplocks = False;
2116 use_oplocks = saved_use_oplocks;
2120 cli2.use_oplocks = True;
2121 cli2.use_level_II_oplocks = True;
2123 cli_unlink(&cli1, fname);
2125 cli_sockopt(&cli1, sockops);
2126 cli_sockopt(&cli2, sockops);
2128 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2130 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2134 /* Don't need the globals any more. */
2135 use_level_II_oplocks = False;
2136 use_oplocks = saved_use_oplocks;
2140 fnum2 = cli_open(&cli2, fname, O_RDWR, DENY_NONE);
2142 printf("second open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2143 *shared_correct = False;
2149 if (!cli_close(&cli2, fnum2)) {
2150 printf("close2 failed (%s)\n", cli_errstr(&cli1));
2151 *shared_correct = False;
2159 /* Ensure cli1 processes the break. */
2161 if (cli_read(&cli1, fnum1, buf, 0, 4) != 4) {
2162 printf("read on fnum1 failed (%s)\n", cli_errstr(&cli1));
2166 /* Should now be at level II. */
2167 /* Test if sending a write locks causes a break to none. */
2169 if (!cli_lock(&cli1, fnum1, 0, 4, 0, READ_LOCK)) {
2170 printf("lock failed (%s)\n", cli_errstr(&cli1));
2174 cli_unlock(&cli1, fnum1, 0, 4);
2178 if (!cli_lock(&cli1, fnum1, 0, 4, 0, WRITE_LOCK)) {
2179 printf("lock failed (%s)\n", cli_errstr(&cli1));
2183 cli_unlock(&cli1, fnum1, 0, 4);
2187 cli_read(&cli1, fnum1, buf, 0, 4);
2190 if (cli_write(&cli1, fnum1, 0, buf, 0, 4) != 4) {
2191 printf("write on fnum1 failed (%s)\n", cli_errstr(&cli1));
2196 if (!cli_close(&cli1, fnum1)) {
2197 printf("close1 failed (%s)\n", cli_errstr(&cli1));
2203 if (!cli_unlink(&cli1, fname)) {
2204 printf("unlink failed (%s)\n", cli_errstr(&cli1));
2208 if (!torture_close_connection(&cli1)) {
2212 if (!*shared_correct) {
2216 printf("finished oplock test 2\n");
2221 /* handler for oplock 3 tests */
2222 static BOOL oplock3_handler(struct cli_state *cli, int fnum, unsigned char level)
2224 printf("got oplock break fnum=%d level=%d\n",
2226 return cli_oplock_ack(cli, fnum, level);
2229 static BOOL run_oplock3(int dummy)
2231 static struct cli_state cli;
2232 char *fname = "\\oplockt3.dat";
2234 char buf[4] = "abcd";
2235 BOOL correct = True;
2236 volatile BOOL *shared_correct;
2238 shared_correct = (volatile BOOL *)shm_setup(sizeof(BOOL));
2239 *shared_correct = True;
2241 printf("starting oplock test 3\n");
2246 use_level_II_oplocks = True;
2247 if (!torture_open_connection(&cli)) {
2248 *shared_correct = False;
2252 /* try to trigger a oplock break in parent */
2253 fnum = cli_open(&cli, fname, O_RDWR, DENY_NONE);
2254 cli_write(&cli, fnum, 0, buf, 0, 4);
2260 use_level_II_oplocks = True;
2261 if (!torture_open_connection(&cli)) {
2264 cli_oplock_handler(&cli, oplock3_handler);
2265 fnum = cli_open(&cli, fname, O_RDWR|O_CREAT, DENY_NONE);
2266 cli_write(&cli, fnum, 0, buf, 0, 4);
2267 cli_close(&cli, fnum);
2268 fnum = cli_open(&cli, fname, O_RDWR, DENY_NONE);
2269 cli.timeout = 20000;
2270 cli_receive_smb(&cli);
2271 printf("finished oplock test 3\n");
2273 return (correct && *shared_correct);
2275 /* What are we looking for here? What's sucess and what's FAILURE? */
2281 Test delete on close semantics.
2283 static BOOL run_deletetest(int dummy)
2285 static struct cli_state cli1;
2286 static struct cli_state cli2;
2287 char *fname = "\\delete.file";
2289 BOOL correct = True;
2291 printf("starting delete test\n");
2293 if (!torture_open_connection(&cli1)) {
2297 cli_sockopt(&cli1, sockops);
2299 /* Test 1 - this should *NOT* delete the file on close. */
2301 cli_setatr(&cli1, fname, 0, 0);
2302 cli_unlink(&cli1, fname);
2304 fnum1 = cli_nt_create_full(&cli1, fname, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL,
2305 FILE_SHARE_DELETE, FILE_OVERWRITE_IF,
2306 DELETE_ON_CLOSE_FLAG);
2309 printf("[1] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2313 if (!cli_close(&cli1, fnum1)) {
2314 printf("[1] close failed (%s)\n", cli_errstr(&cli1));
2318 fnum1 = cli_open(&cli1, fname, O_RDWR, DENY_NONE);
2320 printf("[1] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2324 if (!cli_close(&cli1, fnum1)) {
2325 printf("[1] close failed (%s)\n", cli_errstr(&cli1));
2329 printf("first delete on close test succeeded.\n");
2331 /* Test 2 - this should delete the file on close. */
2333 cli_setatr(&cli1, fname, 0, 0);
2334 cli_unlink(&cli1, fname);
2336 fnum1 = cli_nt_create_full(&cli1, fname, GENERIC_ALL_ACCESS,
2337 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
2338 FILE_OVERWRITE_IF, 0);
2341 printf("[2] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2345 if (!cli_nt_delete_on_close(&cli1, fnum1, True)) {
2346 printf("[2] setting delete_on_close failed (%s)\n", cli_errstr(&cli1));
2350 if (!cli_close(&cli1, fnum1)) {
2351 printf("[2] close failed (%s)\n", cli_errstr(&cli1));
2355 fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_NONE);
2357 printf("[2] open of %s succeeded should have been deleted on close !\n", fname);
2358 if (!cli_close(&cli1, fnum1)) {
2359 printf("[2] close failed (%s)\n", cli_errstr(&cli1));
2362 cli_unlink(&cli1, fname);
2364 printf("second delete on close test succeeded.\n");
2367 cli_setatr(&cli1, fname, 0, 0);
2368 cli_unlink(&cli1, fname);
2370 fnum1 = cli_nt_create_full(&cli1, fname, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL,
2371 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0);
2374 printf("[3] open - 1 of %s failed (%s)\n", fname, cli_errstr(&cli1));
2378 /* This should fail with a sharing violation - open for delete is only compatible
2379 with SHARE_DELETE. */
2381 fnum2 = cli_nt_create_full(&cli1, fname, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
2382 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0);
2385 printf("[3] open - 2 of %s succeeded - should have failed.\n", fname);
2389 /* This should succeed. */
2391 fnum2 = cli_nt_create_full(&cli1, fname, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
2392 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0);
2395 printf("[3] open - 2 of %s failed (%s)\n", fname, cli_errstr(&cli1));
2399 if (!cli_nt_delete_on_close(&cli1, fnum1, True)) {
2400 printf("[3] setting delete_on_close failed (%s)\n", cli_errstr(&cli1));
2404 if (!cli_close(&cli1, fnum1)) {
2405 printf("[3] close 1 failed (%s)\n", cli_errstr(&cli1));
2409 if (!cli_close(&cli1, fnum2)) {
2410 printf("[3] close 2 failed (%s)\n", cli_errstr(&cli1));
2414 /* This should fail - file should no longer be there. */
2416 fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_NONE);
2418 printf("[3] open of %s succeeded should have been deleted on close !\n", fname);
2419 if (!cli_close(&cli1, fnum1)) {
2420 printf("[3] close failed (%s)\n", cli_errstr(&cli1));
2422 cli_unlink(&cli1, fname);
2425 printf("third delete on close test succeeded.\n");
2428 cli_setatr(&cli1, fname, 0, 0);
2429 cli_unlink(&cli1, fname);
2431 fnum1 = cli_nt_create_full(&cli1, fname, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
2432 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0);
2435 printf("[4] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2439 /* This should succeed. */
2440 fnum2 = cli_nt_create_full(&cli1, fname, GENERIC_READ_ACCESS,
2441 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0);
2443 printf("[4] open - 2 of %s failed (%s)\n", fname, cli_errstr(&cli1));
2447 if (!cli_close(&cli1, fnum2)) {
2448 printf("[4] close - 1 failed (%s)\n", cli_errstr(&cli1));
2452 if (!cli_nt_delete_on_close(&cli1, fnum1, True)) {
2453 printf("[4] setting delete_on_close failed (%s)\n", cli_errstr(&cli1));
2457 /* This should fail - no more opens once delete on close set. */
2458 fnum2 = cli_nt_create_full(&cli1, fname, GENERIC_READ_ACCESS,
2459 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0);
2461 printf("[4] open - 3 of %s succeeded ! Should have failed.\n", fname );
2464 printf("fourth delete on close test succeeded.\n");
2466 if (!cli_close(&cli1, fnum1)) {
2467 printf("[4] close - 2 failed (%s)\n", cli_errstr(&cli1));
2472 cli_setatr(&cli1, fname, 0, 0);
2473 cli_unlink(&cli1, fname);
2475 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT, DENY_NONE);
2477 printf("[5] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2481 /* This should fail - only allowed on NT opens with DELETE access. */
2483 if (cli_nt_delete_on_close(&cli1, fnum1, True)) {
2484 printf("[5] setting delete_on_close on OpenX file succeeded - should fail !\n");
2488 if (!cli_close(&cli1, fnum1)) {
2489 printf("[5] close - 2 failed (%s)\n", cli_errstr(&cli1));
2493 printf("fifth delete on close test succeeded.\n");
2496 cli_setatr(&cli1, fname, 0, 0);
2497 cli_unlink(&cli1, fname);
2499 fnum1 = cli_nt_create_full(&cli1, fname, FILE_READ_DATA|FILE_WRITE_DATA,
2500 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
2501 FILE_OVERWRITE_IF, 0);
2504 printf("[6] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2508 /* This should fail - only allowed on NT opens with DELETE access. */
2510 if (cli_nt_delete_on_close(&cli1, fnum1, True)) {
2511 printf("[6] setting delete_on_close on file with no delete access succeeded - should fail !\n");
2515 if (!cli_close(&cli1, fnum1)) {
2516 printf("[6] close - 2 failed (%s)\n", cli_errstr(&cli1));
2520 printf("sixth delete on close test succeeded.\n");
2523 cli_setatr(&cli1, fname, 0, 0);
2524 cli_unlink(&cli1, fname);
2526 fnum1 = cli_nt_create_full(&cli1, fname, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
2527 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF, 0);
2530 printf("[7] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2534 if (!cli_nt_delete_on_close(&cli1, fnum1, True)) {
2535 printf("[7] setting delete_on_close on file failed !\n");
2539 if (!cli_nt_delete_on_close(&cli1, fnum1, False)) {
2540 printf("[7] unsetting delete_on_close on file failed !\n");
2544 if (!cli_close(&cli1, fnum1)) {
2545 printf("[7] close - 2 failed (%s)\n", cli_errstr(&cli1));
2549 /* This next open should succeed - we reset the flag. */
2551 fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_NONE);
2553 printf("[5] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2557 if (!cli_close(&cli1, fnum1)) {
2558 printf("[7] close - 2 failed (%s)\n", cli_errstr(&cli1));
2562 printf("seventh delete on close test succeeded.\n");
2565 cli_setatr(&cli1, fname, 0, 0);
2566 cli_unlink(&cli1, fname);
2568 if (!torture_open_connection(&cli2)) {
2569 printf("[8] failed to open second connection.\n");
2573 cli_sockopt(&cli1, sockops);
2575 fnum1 = cli_nt_create_full(&cli1, fname, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
2576 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0);
2579 printf("[8] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2583 fnum2 = cli_nt_create_full(&cli2, fname, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
2584 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0);
2587 printf("[8] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2591 if (!cli_nt_delete_on_close(&cli1, fnum1, True)) {
2592 printf("[8] setting delete_on_close on file failed !\n");
2596 if (!cli_close(&cli1, fnum1)) {
2597 printf("[8] close - 1 failed (%s)\n", cli_errstr(&cli1));
2601 if (!cli_close(&cli2, fnum2)) {
2602 printf("[8] close - 2 failed (%s)\n", cli_errstr(&cli2));
2606 /* This should fail.. */
2607 fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_NONE);
2609 printf("[8] open of %s succeeded should have been deleted on close !\n", fname);
2610 if (!cli_close(&cli1, fnum1)) {
2611 printf("[8] close failed (%s)\n", cli_errstr(&cli1));
2613 cli_unlink(&cli1, fname);
2616 printf("eighth delete on close test succeeded.\n");
2618 printf("finished delete test\n");
2620 cli_setatr(&cli1, fname, 0, 0);
2621 cli_unlink(&cli1, fname);
2623 if (!torture_close_connection(&cli1)) {
2626 if (!torture_close_connection(&cli2)) {
2633 Test open mode returns on read-only files.
2635 static BOOL run_opentest(int dummy)
2637 static struct cli_state cli1;
2638 char *fname = "\\readonly.file";
2642 BOOL correct = True;
2645 printf("starting open test\n");
2647 if (!torture_open_connection(&cli1)) {
2651 cli_setatr(&cli1, fname, 0, 0);
2652 cli_unlink(&cli1, fname);
2654 cli_sockopt(&cli1, sockops);
2656 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2658 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2662 if (!cli_close(&cli1, fnum1)) {
2663 printf("close2 failed (%s)\n", cli_errstr(&cli1));
2667 if (!cli_setatr(&cli1, fname, aRONLY, 0)) {
2668 printf("cli_setatr failed (%s)\n", cli_errstr(&cli1));
2672 fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_WRITE);
2674 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2678 /* This will fail - but the error should be ERRnoaccess, not ERRbadshare. */
2679 fnum2 = cli_open(&cli1, fname, O_RDWR, DENY_ALL);
2681 if (check_error(__LINE__, &cli1, ERRDOS, ERRnoaccess,
2682 NT_STATUS_ACCESS_DENIED)) {
2683 printf("correct error code ERRDOS/ERRnoaccess returned\n");
2686 printf("finished open test 1\n");
2688 cli_close(&cli1, fnum1);
2690 /* Now try not readonly and ensure ERRbadshare is returned. */
2692 cli_setatr(&cli1, fname, 0, 0);
2694 fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_WRITE);
2696 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2700 /* This will fail - but the error should be ERRshare. */
2701 fnum2 = cli_open(&cli1, fname, O_RDWR, DENY_ALL);
2703 if (check_error(__LINE__, &cli1, ERRDOS, ERRbadshare,
2704 NT_STATUS_SHARING_VIOLATION)) {
2705 printf("correct error code ERRDOS/ERRbadshare returned\n");
2708 if (!cli_close(&cli1, fnum1)) {
2709 printf("close2 failed (%s)\n", cli_errstr(&cli1));
2713 cli_unlink(&cli1, fname);
2715 printf("finished open test 2\n");
2717 /* Test truncate open disposition on file opened for read. */
2719 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2721 printf("(3) open (1) of %s failed (%s)\n", fname, cli_errstr(&cli1));
2725 /* write 20 bytes. */
2727 memset(buf, '\0', 20);
2729 if (cli_write(&cli1, fnum1, 0, buf, 0, 20) != 20) {
2730 printf("write failed (%s)\n", cli_errstr(&cli1));
2734 if (!cli_close(&cli1, fnum1)) {
2735 printf("(3) close1 failed (%s)\n", cli_errstr(&cli1));
2739 /* Ensure size == 20. */
2740 if (!cli_getatr(&cli1, fname, NULL, &fsize, NULL)) {
2741 printf("(3) getatr failed (%s)\n", cli_errstr(&cli1));
2746 printf("(3) file size != 20\n");
2750 /* Now test if we can truncate a file opened for readonly. */
2752 fnum1 = cli_open(&cli1, fname, O_RDONLY|O_TRUNC, DENY_NONE);
2754 printf("(3) open (2) of %s failed (%s)\n", fname, cli_errstr(&cli1));
2758 if (!cli_close(&cli1, fnum1)) {
2759 printf("close2 failed (%s)\n", cli_errstr(&cli1));
2763 /* Ensure size == 0. */
2764 if (!cli_getatr(&cli1, fname, NULL, &fsize, NULL)) {
2765 printf("(3) getatr failed (%s)\n", cli_errstr(&cli1));
2770 printf("(3) file size != 0\n");
2773 printf("finished open test 3\n");
2775 cli_unlink(&cli1, fname);
2778 printf("testing ctemp\n");
2779 fnum1 = cli_ctemp(&cli1, "\\", &tmp_path);
2781 printf("ctemp failed (%s)\n", cli_errstr(&cli1));
2784 printf("ctemp gave path %s\n", tmp_path);
2785 if (!cli_close(&cli1, fnum1)) {
2786 printf("close of temp failed (%s)\n", cli_errstr(&cli1));
2788 if (!cli_unlink(&cli1, tmp_path)) {
2789 printf("unlink of temp failed (%s)\n", cli_errstr(&cli1));
2792 if (!torture_close_connection(&cli1)) {
2799 static void list_fn(file_info *finfo, const char *name, void *state)
2805 test directory listing speed
2807 static BOOL run_dirtest(int dummy)
2810 static struct cli_state cli;
2813 BOOL correct = True;
2815 printf("starting directory test\n");
2817 if (!torture_open_connection(&cli)) {
2821 cli_sockopt(&cli, sockops);
2824 for (i=0;i<numops;i++) {
2826 slprintf(fname, sizeof(fname), "%x", (int)random());
2827 fnum = cli_open(&cli, fname, O_RDWR|O_CREAT, DENY_NONE);
2829 fprintf(stderr,"Failed to open %s\n", fname);
2832 cli_close(&cli, fnum);
2837 printf("Matched %d\n", cli_list(&cli, "a*.*", 0, list_fn, NULL));
2838 printf("Matched %d\n", cli_list(&cli, "b*.*", 0, list_fn, NULL));
2839 printf("Matched %d\n", cli_list(&cli, "xyzabc", 0, list_fn, NULL));
2841 printf("dirtest core %g seconds\n", end_timer() - t1);
2844 for (i=0;i<numops;i++) {
2846 slprintf(fname, sizeof(fname), "%x", (int)random());
2847 cli_unlink(&cli, fname);
2850 if (!torture_close_connection(&cli)) {
2854 printf("finished dirtest\n");
2861 static double create_procs(BOOL (*fn)(int), BOOL *result)
2864 volatile pid_t *child_status;
2865 volatile BOOL *child_status_out;
2871 child_status = (volatile pid_t *)shm_setup(sizeof(pid_t)*nprocs);
2872 if (!child_status) {
2873 printf("Failed to setup shared memory\n");
2877 child_status_out = (volatile BOOL *)shm_setup(sizeof(BOOL)*nprocs);
2878 if (!child_status_out) {
2879 printf("Failed to setup result status shared memory\n");
2883 memset((void *)child_status, 0, sizeof(pid_t)*nprocs);
2884 memset((void *)child_status_out, True, sizeof(BOOL)*nprocs);
2888 for (i=0;i<nprocs;i++) {
2891 pid_t mypid = getpid();
2892 sys_srandom(((int)mypid) ^ ((int)time(NULL)));
2894 slprintf(myname,sizeof(myname),"CLIENT%d", i);
2897 memset(¤t_cli, 0, sizeof(current_cli));
2898 if (torture_open_connection(¤t_cli)) break;
2900 printf("pid %d failed to start\n", (int)getpid());
2906 child_status[i] = getpid();
2908 while (child_status[i]) msleep(2);
2910 child_status_out[i] = fn(i);
2917 for (i=0;i<nprocs;i++) {
2918 if (child_status[i]) synccount++;
2920 if (synccount == nprocs) break;
2922 } while (end_timer() < 30);
2924 if (synccount != nprocs) {
2925 printf("FAILED TO START %d CLIENTS (started %d)\n", nprocs, synccount);
2930 /* start the client load */
2933 for (i=0;i<nprocs;i++) {
2934 child_status[i] = 0;
2937 printf("%d clients started\n", nprocs);
2939 for (i=0;i<nprocs;i++) {
2940 waitpid(0, &status, 0);
2946 for (i=0;i<nprocs;i++) {
2947 if (!child_status_out[i]) {
2955 #define FLAG_MULTIPROC 1
2962 {"FDPASS", run_fdpasstest, 0},
2963 {"LOCK1", run_locktest1, 0},
2964 {"LOCK2", run_locktest2, 0},
2965 {"LOCK3", run_locktest3, 0},
2966 {"LOCK4", run_locktest4, 0},
2967 {"LOCK5", run_locktest5, 0},
2968 {"UNLINK", run_unlinktest, 0},
2969 {"BROWSE", run_browsetest, 0},
2970 {"ATTR", run_attrtest, 0},
2971 {"TRANS2", run_trans2test, 0},
2972 {"MAXFID", run_maxfidtest, FLAG_MULTIPROC},
2973 {"TORTURE",run_torture, FLAG_MULTIPROC},
2974 {"RANDOMIPC", run_randomipc, 0},
2975 {"NEGNOWAIT", run_negprot_nowait, 0},
2976 {"NBW95", run_nbw95, 0},
2977 {"NBWNT", run_nbwnt, 0},
2978 {"OPLOCK1", run_oplock1, 0},
2979 {"OPLOCK2", run_oplock2, 0},
2980 {"OPLOCK3", run_oplock3, 0},
2981 {"DIR", run_dirtest, 0},
2982 {"DENY1", torture_denytest1, 0},
2983 {"DENY2", torture_denytest2, 0},
2984 {"TCON", run_tcon_test, 0},
2985 {"RW1", run_readwritetest, 0},
2986 {"RW2", run_readwritemulti, FLAG_MULTIPROC},
2987 {"RW3", run_readwritelarge, 0},
2988 {"OPEN", run_opentest, 0},
2989 {"DELETE", run_deletetest, 0},
2990 {"W2K", run_w2ktest, 0},
2991 {"TRANS2SCAN", torture_trans2_scan, 0},
2992 {"NTTRANSSCAN", torture_nttrans_scan, 0},
2993 {"UTABLE", torture_utable, 0},
2994 {"CASETABLE", torture_casetable, 0},
2999 /****************************************************************************
3000 run a specified test or "ALL"
3001 ****************************************************************************/
3002 static BOOL run_test(char *name)
3008 if (strequal(name,"ALL")) {
3009 for (i=0;torture_ops[i].name;i++) {
3010 run_test(torture_ops[i].name);
3014 for (i=0;torture_ops[i].name;i++) {
3015 snprintf(randomfname, sizeof(randomfname), "\\XX%x",
3016 (unsigned)random());
3018 if (strequal(name, torture_ops[i].name)) {
3019 printf("Running %s\n", name);
3020 if (torture_ops[i].flags & FLAG_MULTIPROC) {
3021 t = create_procs(torture_ops[i].fn, &result);
3024 printf("TEST %s FAILED!\n", name);
3029 if (!torture_ops[i].fn(0)) {
3031 printf("TEST %s FAILED!\n", name);
3035 printf("%s took %g secs\n\n", name, t);
3042 static void usage(void)
3046 printf("Usage: smbtorture //server/share <options> TEST1 TEST2 ...\n");
3048 printf("\t-d debuglevel\n");
3049 printf("\t-U user%%pass\n");
3050 printf("\t-N numprocs\n");
3051 printf("\t-n my_netbios_name\n");
3052 printf("\t-W workgroup\n");
3053 printf("\t-o num_operations\n");
3054 printf("\t-O socket_options\n");
3055 printf("\t-m maximum protocol\n");
3056 printf("\t-L use oplocks\n");
3057 printf("\t-A showall\n");
3060 printf("tests are:");
3061 for (i=0;torture_ops[i].name;i++) {
3062 printf(" %s", torture_ops[i].name);
3066 printf("default test is ALL\n");
3075 /****************************************************************************
3077 ****************************************************************************/
3078 int main(int argc,char *argv[])
3083 extern char *optarg;
3085 BOOL correct = True;
3089 #ifdef HAVE_SETBUFFER
3090 setbuffer(stdout, NULL, 0);
3093 lp_load(dyn_CONFIGFILE,True,False,False);
3100 for(p = argv[1]; *p; p++)
3104 if (strncmp(argv[1], "//", 2)) {
3108 fstrcpy(host, &argv[1][2]);
3109 p = strchr_m(&host[2],'/');
3114 fstrcpy(share, p+1);
3118 if (*username == 0 && getenv("LOGNAME")) {
3119 pstrcpy(username,getenv("LOGNAME"));
3126 fstrcpy(workgroup, lp_workgroup());
3128 while ((opt = getopt(argc, argv, "hW:U:n:N:O:o:m:Ld:A")) != EOF) {
3131 fstrcpy(workgroup,optarg);
3134 max_protocol = interpret_protocol(optarg, max_protocol);
3137 nprocs = atoi(optarg);
3140 numops = atoi(optarg);
3143 DEBUGLEVEL = atoi(optarg);
3152 torture_showall = True;
3155 fstrcpy(myname, optarg);
3158 pstrcpy(username,optarg);
3159 p = strchr_m(username,'%');
3162 pstrcpy(password, p+1);
3167 printf("Unknown option %c (%d)\n", (char)opt, opt);
3174 p = getpass("Password:");
3176 pstrcpy(password, p);
3181 printf("host=%s share=%s user=%s myname=%s\n",
3182 host, share, username, myname);
3185 correct = run_test("ALL");
3187 for (i=1;i<argc;i++) {
3188 if (!run_test(argv[i])) {