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;
36 static double create_procs(BOOL (*fn)(int), BOOL *result);
39 static struct timeval tp1,tp2;
41 static void start_timer(void)
43 gettimeofday(&tp1,NULL);
46 static double end_timer(void)
48 gettimeofday(&tp2,NULL);
49 return((tp2.tv_sec - tp1.tv_sec) +
50 (tp2.tv_usec - tp1.tv_usec)*1.0e-6);
54 /* return a pointer to a anonymous shared memory segment of size "size"
55 which will persist across fork() but will disappear when all processes
58 The memory is not zeroed
60 This function uses system5 shared memory. It takes advantage of a property
61 that the memory is not destroyed if it is attached when the id is removed
63 static void *shm_setup(int size)
68 shmid = shmget(IPC_PRIVATE, size, SHM_R | SHM_W);
70 printf("can't get shared memory\n");
73 ret = (void *)shmat(shmid, 0, 0);
74 if (!ret || ret == (void *)-1) {
75 printf("can't attach to shared memory\n");
78 /* the following releases the ipc, but note that this process
79 and all its children will still have access to the memory, its
80 just that the shmid is no longer valid for other shm calls. This
81 means we don't leave behind lots of shm segments after we exit
83 See Stevens "advanced programming in unix env" for details
85 shmctl(shmid, IPC_RMID, 0);
91 static BOOL open_nbt_connection(struct cli_state *c)
93 struct nmb_name called, calling;
95 extern struct in_addr ipzero;
99 make_nmb_name(&calling, myname, 0x0);
100 make_nmb_name(&called , host, 0x20);
104 if (!cli_initialise(c) || !cli_connect(c, host, &ip)) {
105 printf("Failed to connect with %s\n", host);
109 c->timeout = 120000; /* set a really long timeout (2 minutes) */
110 if (use_oplocks) c->use_oplocks = True;
111 if (use_level_II_oplocks) c->use_level_II_oplocks = True;
113 if (!cli_session_request(c, &calling, &called)) {
114 printf("%s rejected the session\n",host);
122 static BOOL open_connection(struct cli_state *c)
126 if (!open_nbt_connection(c)) {
130 if (!cli_negprot(c)) {
131 printf("%s rejected the negprot (%s)\n",host, cli_errstr(c));
136 if (!cli_session_setup(c, username,
137 password, strlen(password),
138 password, strlen(password),
140 printf("%s rejected the sessionsetup (%s)\n", host, cli_errstr(c));
145 if (!cli_send_tconX(c, share, "?????",
146 password, strlen(password)+1)) {
147 printf("%s refused tree connect (%s)\n", host, cli_errstr(c));
156 static BOOL close_connection(struct cli_state *c)
160 printf("tdis failed (%s)\n", cli_errstr(c));
170 /* check if the server produced the expected error code */
171 static BOOL check_error(struct cli_state *c,
172 uint8 eclass, uint32 ecode, uint32 nterr)
176 (void)cli_error(c, &class, &num, NULL);
177 if ((eclass != class || ecode != num) &&
178 num != (nterr&0xFFFFFF)) {
179 printf("unexpected error code class=%d code=%d\n",
180 (int)class, (int)num);
181 printf(" expected %d/%d %d\n",
182 (int)eclass, (int)ecode, (int)nterr);
189 static BOOL wait_lock(struct cli_state *c, int fnum, uint32 offset, uint32 len)
191 while (!cli_lock(c, fnum, offset, len, -1, WRITE_LOCK)) {
192 if (!check_error(c, ERRDOS, ERRlock, 0)) return False;
198 static BOOL rw_torture(struct cli_state *c)
200 char *lockfname = "\\torture.lck";
204 pid_t pid2, pid = getpid();
209 fnum2 = cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
212 fnum2 = cli_open(c, lockfname, O_RDWR, DENY_NONE);
214 printf("open of %s failed (%s)\n", lockfname, cli_errstr(c));
219 for (i=0;i<numops;i++) {
220 unsigned n = (unsigned)sys_random()%10;
222 printf("%d\r", i); fflush(stdout);
224 slprintf(fname, sizeof(fstring) - 1, "\\torture.%u", n);
226 if (!wait_lock(c, fnum2, n*sizeof(int), sizeof(int))) {
230 fnum = cli_open(c, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_ALL);
232 printf("open failed (%s)\n", cli_errstr(c));
237 if (cli_write(c, fnum, 0, (char *)&pid, 0, sizeof(pid)) != sizeof(pid)) {
238 printf("write failed (%s)\n", cli_errstr(c));
243 if (cli_write(c, fnum, 0, (char *)buf,
244 sizeof(pid)+(j*sizeof(buf)),
245 sizeof(buf)) != sizeof(buf)) {
246 printf("write failed (%s)\n", cli_errstr(c));
253 if (cli_read(c, fnum, (char *)&pid2, 0, sizeof(pid)) != sizeof(pid)) {
254 printf("read failed (%s)\n", cli_errstr(c));
259 printf("data corruption!\n");
263 if (!cli_close(c, fnum)) {
264 printf("close failed (%s)\n", cli_errstr(c));
268 if (!cli_unlink(c, fname)) {
269 printf("unlink failed (%s)\n", cli_errstr(c));
273 if (!cli_unlock(c, fnum2, n*sizeof(int), sizeof(int))) {
274 printf("unlock failed (%s)\n", cli_errstr(c));
280 cli_unlink(c, lockfname);
287 static BOOL run_torture(int dummy)
289 struct cli_state cli;
294 cli_sockopt(&cli, sockops);
296 ret = rw_torture(&cli);
298 if (!close_connection(&cli)) {
305 static BOOL rw_torture3(struct cli_state *c, char *lockfname)
312 unsigned countprev = 0;
317 for (i = 0; i < sizeof(buf); i += sizeof(uint32))
319 SIVAL(buf, i, sys_random());
324 fnum = cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
327 printf("first open read/write of %s failed (%s)\n",
328 lockfname, cli_errstr(c));
334 for (i = 0; i < 500 && fnum == -1; i++)
336 fnum = cli_open(c, lockfname, O_RDONLY,
341 printf("second open read-only of %s failed (%s)\n",
342 lockfname, cli_errstr(c));
348 for (count = 0; count < sizeof(buf); count += sent)
350 if (count >= countprev) {
351 printf("%d %8d\r", i, count);
354 countprev += (sizeof(buf) / 20);
359 sent = ((unsigned)sys_random()%(20))+ 1;
360 if (sent > sizeof(buf) - count)
362 sent = sizeof(buf) - count;
365 if (cli_write(c, fnum, 0, buf+count, count, sent) != sent) {
366 printf("write failed (%s)\n", cli_errstr(c));
372 sent = cli_read(c, fnum, buf_rd+count, count,
376 printf("read failed offset:%d size:%d (%s)\n",
377 count, sizeof(buf)-count,
384 if (memcmp(buf_rd+count, buf+count, sent) != 0)
386 printf("read/write compare failed\n");
387 printf("offset: %d req %d recvd %d\n",
388 count, sizeof(buf)-count, sent);
397 if (!cli_close(c, fnum)) {
398 printf("close failed (%s)\n", cli_errstr(c));
405 static BOOL rw_torture2(struct cli_state *c1, struct cli_state *c2)
407 char *lockfname = "\\torture.lck";
416 if (!cli_unlink(c1, lockfname)) {
417 printf("unlink failed (%s) (normal, this file should not exist)\n", cli_errstr(c1));
420 fnum1 = cli_open(c1, lockfname, O_RDWR | O_CREAT | O_EXCL,
423 printf("first open read/write of %s failed (%s)\n",
424 lockfname, cli_errstr(c1));
427 fnum2 = cli_open(c2, lockfname, O_RDONLY,
430 printf("second open read-only of %s failed (%s)\n",
431 lockfname, cli_errstr(c2));
432 cli_close(c1, fnum1);
436 for (i=0;i<numops;i++)
438 size_t buf_size = ((unsigned)sys_random()%(sizeof(buf)-1))+ 1;
440 printf("%d\r", i); fflush(stdout);
443 generate_random_buffer(buf, buf_size, False);
445 if (cli_write(c1, fnum1, 0, buf, 0, buf_size) != buf_size) {
446 printf("write failed (%s)\n", cli_errstr(c1));
450 if ((bytes_read = cli_read(c2, fnum2, buf_rd, 0, buf_size)) != buf_size) {
451 printf("read failed (%s)\n", cli_errstr(c2));
452 printf("read %d, expected %d\n", bytes_read, buf_size);
456 if (memcmp(buf_rd, buf, buf_size) != 0)
458 printf("read/write compare failed\n");
463 if (!cli_close(c2, fnum2)) {
464 printf("close failed (%s)\n", cli_errstr(c2));
467 if (!cli_close(c1, fnum1)) {
468 printf("close failed (%s)\n", cli_errstr(c1));
472 if (!cli_unlink(c1, lockfname)) {
473 printf("unlink failed (%s)\n", cli_errstr(c1));
480 static BOOL run_readwritetest(int dummy)
482 static struct cli_state cli1, cli2;
485 if (!open_connection(&cli1) || !open_connection(&cli2)) {
488 cli_sockopt(&cli1, sockops);
489 cli_sockopt(&cli2, sockops);
491 printf("starting readwritetest\n");
493 test1 = rw_torture2(&cli1, &cli2);
494 printf("Passed readwritetest v1: %s\n", BOOLSTR(test1));
496 test2 = rw_torture2(&cli1, &cli1);
497 printf("Passed readwritetest v2: %s\n", BOOLSTR(test2));
499 if (!close_connection(&cli1)) {
503 if (!close_connection(&cli2)) {
507 return (test1 && test2);
510 static BOOL run_readwritemulti(int dummy)
512 static struct cli_state cli;
517 cli_sockopt(&cli, sockops);
519 printf("run_readwritemulti: fname %s\n", randomfname);
520 test = rw_torture3(&cli, randomfname);
522 if (!close_connection(&cli)) {
529 static BOOL run_readwritelarge(int dummy)
531 static struct cli_state cli1;
533 char *lockfname = "\\large.dat";
538 if (!open_connection(&cli1)) {
541 cli_sockopt(&cli1, sockops);
542 memset(buf,'\0',sizeof(buf));
544 cli1.max_xmit = 0x11000;
546 printf("starting readwritelarge\n");
548 cli_unlink(&cli1, lockfname);
550 fnum1 = cli_open(&cli1, lockfname, O_RDWR | O_CREAT | O_EXCL, DENY_NONE);
552 printf("open read/write of %s failed (%s)\n", lockfname, cli_errstr(&cli1));
556 cli_write(&cli1, fnum1, 0, buf, 0, sizeof(buf));
558 if (!cli_close(&cli1, fnum1)) {
559 printf("close failed (%s)\n", cli_errstr(&cli1));
563 if (!cli_qpathinfo(&cli1, lockfname, NULL, NULL, NULL, &fsize, NULL)) {
564 printf("qpathinfo failed (%s)\n", cli_errstr(&cli1));
568 if (fsize == sizeof(buf))
569 printf("readwritelarge test succeeded (size = %x)\n", fsize);
571 printf("readwritelarge test failed (size = %x)\n", fsize);
575 if (!cli_unlink(&cli1, lockfname)) {
576 printf("unlink failed (%s)\n", cli_errstr(&cli1));
580 if (!close_connection(&cli1)) {
588 /* run a test that simulates an approximate netbench client load */
589 static BOOL run_netbench(int client)
591 struct cli_state cli;
602 cli_sockopt(&cli, sockops);
606 slprintf(cname,sizeof(fname), "CLIENT%d", client);
608 f = fopen("client.txt", "r");
611 perror("client.txt");
615 while (fgets(line, sizeof(line)-1, f)) {
618 line[strlen(line)-1] = 0;
620 /* printf("[%d] %s\n", line_count, line); */
622 all_string_sub(line,"CLIENT1", cname, sizeof(line));
624 for (i=0;i<20;i++) params[i] = "";
626 /* parse the command parameters */
627 params[0] = strtok(line," ");
629 while (params[i]) params[++i] = strtok(NULL," ");
635 if (strcmp(params[1],"REQUEST") == 0) {
636 if (!strcmp(params[0],"SMBopenX")) {
637 fstrcpy(fname, params[5]);
638 } else if (!strcmp(params[0],"SMBclose")) {
639 nb_close(atoi(params[3]));
640 } else if (!strcmp(params[0],"SMBmkdir")) {
642 } else if (!strcmp(params[0],"CREATE")) {
643 nb_create(params[3], atoi(params[5]));
644 } else if (!strcmp(params[0],"SMBrmdir")) {
646 } else if (!strcmp(params[0],"SMBunlink")) {
647 fstrcpy(fname, params[3]);
648 } else if (!strcmp(params[0],"SMBmv")) {
649 nb_rename(params[3], params[5]);
650 } else if (!strcmp(params[0],"SMBgetatr")) {
651 fstrcpy(fname, params[3]);
652 } else if (!strcmp(params[0],"SMBwrite")) {
653 nb_write(atoi(params[3]),
654 atoi(params[5]), atoi(params[7]));
655 } else if (!strcmp(params[0],"SMBwritebraw")) {
656 nb_write(atoi(params[3]),
657 atoi(params[7]), atoi(params[5]));
658 } else if (!strcmp(params[0],"SMBreadbraw")) {
659 nb_read(atoi(params[3]),
660 atoi(params[7]), atoi(params[5]));
661 } else if (!strcmp(params[0],"SMBread")) {
662 nb_read(atoi(params[3]),
663 atoi(params[5]), atoi(params[7]));
666 if (!strcmp(params[0],"SMBopenX")) {
667 if (!strncmp(params[2], "ERR", 3)) continue;
668 nb_open(fname, atoi(params[3]), atoi(params[5]));
669 } else if (!strcmp(params[0],"SMBgetatr")) {
670 if (!strncmp(params[2], "ERR", 3)) continue;
671 nb_stat(fname, atoi(params[3]));
672 } else if (!strcmp(params[0],"SMBunlink")) {
673 if (!strncmp(params[2], "ERR", 3)) continue;
680 slprintf(fname,sizeof(fname), "CLIENTS/CLIENT%d", client);
686 if (!close_connection(&cli)) {
694 /* run a test that simulates an approximate netbench w9X client load */
695 static BOOL run_nbw95(int dummy)
699 t = create_procs(run_netbench, &correct);
700 /* to produce a netbench result we scale accoding to the
701 netbench measured throughput for the run that produced the
702 sniff that was used to produce client.txt. That run used 2
703 clients and ran for 660 seconds to produce a result of
705 printf("Throughput %g MB/sec (NB=%g MB/sec %g MBit/sec)\n",
706 132*nprocs/t, 0.5*0.5*nprocs*660/t, 2*nprocs*660/t);
710 /* run a test that simulates an approximate netbench wNT client load */
711 static BOOL run_nbwnt(int dummy)
715 t = create_procs(run_netbench, &correct);
716 printf("Throughput %g MB/sec (NB=%g MB/sec %g MBit/sec)\n",
717 132*nprocs/t, 0.5*0.5*nprocs*660/t, 2*nprocs*660/t);
724 This test checks for two things:
726 1) correct support for retaining locks over a close (ie. the server
727 must not use posix semantics)
728 2) support for lock timeouts
730 static BOOL run_locktest1(int dummy)
732 static struct cli_state cli1, cli2;
733 char *fname = "\\lockt1.lck";
734 int fnum1, fnum2, fnum3;
737 if (!open_connection(&cli1) || !open_connection(&cli2)) {
740 cli_sockopt(&cli1, sockops);
741 cli_sockopt(&cli2, sockops);
743 printf("starting locktest1\n");
745 cli_unlink(&cli1, fname);
747 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
749 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
752 fnum2 = cli_open(&cli1, fname, O_RDWR, DENY_NONE);
754 printf("open2 of %s failed (%s)\n", fname, cli_errstr(&cli1));
757 fnum3 = cli_open(&cli2, fname, O_RDWR, DENY_NONE);
759 printf("open3 of %s failed (%s)\n", fname, cli_errstr(&cli2));
763 if (!cli_lock(&cli1, fnum1, 0, 4, 0, WRITE_LOCK)) {
764 printf("lock1 failed (%s)\n", cli_errstr(&cli1));
769 if (cli_lock(&cli2, fnum3, 0, 4, 0, WRITE_LOCK)) {
770 printf("lock2 succeeded! This is a locking bug\n");
773 if (!check_error(&cli2, ERRDOS, ERRlock, 0)) return False;
777 printf("Testing lock timeouts\n");
779 if (cli_lock(&cli2, fnum3, 0, 4, 10*1000, WRITE_LOCK)) {
780 printf("lock3 succeeded! This is a locking bug\n");
783 if (!check_error(&cli2, ERRDOS, ERRlock, 0)) return False;
788 printf("error: This server appears not to support timed lock requests\n");
791 if (!cli_close(&cli1, fnum2)) {
792 printf("close1 failed (%s)\n", cli_errstr(&cli1));
796 if (cli_lock(&cli2, fnum3, 0, 4, 0, WRITE_LOCK)) {
797 printf("lock4 succeeded! This is a locking bug\n");
800 if (!check_error(&cli2, ERRDOS, ERRlock, 0)) return False;
803 if (!cli_close(&cli1, fnum1)) {
804 printf("close2 failed (%s)\n", cli_errstr(&cli1));
808 if (!cli_close(&cli2, fnum3)) {
809 printf("close3 failed (%s)\n", cli_errstr(&cli2));
813 if (!cli_unlink(&cli1, fname)) {
814 printf("unlink failed (%s)\n", cli_errstr(&cli1));
819 if (!close_connection(&cli1)) {
823 if (!close_connection(&cli2)) {
827 printf("Passed locktest1\n");
832 checks for correct tconX support
834 static BOOL run_tcon_test(int dummy)
836 static struct cli_state cli1;
837 char *fname = "\\tcontest.tmp";
842 if (!open_connection(&cli1)) {
845 cli_sockopt(&cli1, sockops);
847 printf("starting tcontest\n");
849 cli_unlink(&cli1, fname);
851 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
854 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
860 if (cli_write(&cli1, fnum1, 0, buf, 130, 4) != 4)
862 printf("write failed (%s)", cli_errstr(&cli1));
866 if (!cli_send_tconX(&cli1, share, "?????",
867 password, strlen(password)+1)) {
868 printf("%s refused 2nd tree connect (%s)\n", host,
874 if (cli_write(&cli1, fnum1, 0, buf, 130, 4) == 4)
876 printf("write succeeded (%s)", cli_errstr(&cli1));
880 if (cli_close(&cli1, fnum1)) {
881 printf("close2 succeeded (%s)\n", cli_errstr(&cli1));
885 if (!cli_tdis(&cli1)) {
886 printf("tdis failed (%s)\n", cli_errstr(&cli1));
892 if (!cli_close(&cli1, fnum1)) {
893 printf("close2 failed (%s)\n", cli_errstr(&cli1));
897 if (!close_connection(&cli1)) {
901 printf("Passed tcontest\n");
907 This test checks that
909 1) the server supports multiple locking contexts on the one SMB
910 connection, distinguished by PID.
912 2) the server correctly fails overlapping locks made by the same PID (this
913 goes against POSIX behaviour, which is why it is tricky to implement)
915 3) the server denies unlock requests by an incorrect client PID
917 static BOOL run_locktest2(int dummy)
919 static struct cli_state cli;
920 char *fname = "\\lockt2.lck";
921 int fnum1, fnum2, fnum3;
924 if (!open_connection(&cli)) {
928 cli_sockopt(&cli, sockops);
930 printf("starting locktest2\n");
932 cli_unlink(&cli, fname);
936 fnum1 = cli_open(&cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
938 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli));
942 fnum2 = cli_open(&cli, fname, O_RDWR, DENY_NONE);
944 printf("open2 of %s failed (%s)\n", fname, cli_errstr(&cli));
950 fnum3 = cli_open(&cli, fname, O_RDWR, DENY_NONE);
952 printf("open3 of %s failed (%s)\n", fname, cli_errstr(&cli));
958 if (!cli_lock(&cli, fnum1, 0, 4, 0, WRITE_LOCK)) {
959 printf("lock1 failed (%s)\n", cli_errstr(&cli));
963 if (cli_lock(&cli, fnum1, 0, 4, 0, WRITE_LOCK)) {
964 printf("WRITE lock1 succeeded! This is a locking bug\n");
967 if (!check_error(&cli, ERRDOS, ERRlock, 0)) return False;
970 if (cli_lock(&cli, fnum2, 0, 4, 0, WRITE_LOCK)) {
971 printf("WRITE lock2 succeeded! This is a locking bug\n");
974 if (!check_error(&cli, ERRDOS, ERRlock, 0)) return False;
977 if (cli_lock(&cli, fnum2, 0, 4, 0, READ_LOCK)) {
978 printf("READ lock2 succeeded! This is a locking bug\n");
981 if (!check_error(&cli, ERRDOS, ERRlock, 0)) return False;
986 if (cli_unlock(&cli, fnum1, 0, 8)) {
987 printf("unlock1 succeeded! This is a locking bug\n");
991 if (cli_lock(&cli, fnum3, 0, 4, 0, WRITE_LOCK)) {
992 printf("lock3 succeeded! This is a locking bug\n");
995 if (!check_error(&cli, ERRDOS, ERRlock, 0)) return False;
1000 if (!cli_close(&cli, fnum1)) {
1001 printf("close1 failed (%s)\n", cli_errstr(&cli));
1005 if (!cli_close(&cli, fnum2)) {
1006 printf("close2 failed (%s)\n", cli_errstr(&cli));
1010 if (!cli_close(&cli, fnum3)) {
1011 printf("close3 failed (%s)\n", cli_errstr(&cli));
1015 if (!close_connection(&cli)) {
1019 printf("locktest2 finished\n");
1026 This test checks that
1028 1) the server supports the full offset range in lock requests
1030 static BOOL run_locktest3(int dummy)
1032 static struct cli_state cli1, cli2;
1033 char *fname = "\\lockt3.lck";
1034 int fnum1, fnum2, i;
1036 BOOL correct = True;
1038 #define NEXT_OFFSET offset += (~(uint32)0) / numops
1040 if (!open_connection(&cli1) || !open_connection(&cli2)) {
1043 cli_sockopt(&cli1, sockops);
1044 cli_sockopt(&cli2, sockops);
1046 printf("starting locktest3\n");
1048 cli_unlink(&cli1, fname);
1050 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1052 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
1055 fnum2 = cli_open(&cli2, fname, O_RDWR, DENY_NONE);
1057 printf("open2 of %s failed (%s)\n", fname, cli_errstr(&cli2));
1061 for (offset=i=0;i<numops;i++) {
1063 if (!cli_lock(&cli1, fnum1, offset-1, 1, 0, WRITE_LOCK)) {
1064 printf("lock1 %d failed (%s)\n",
1070 if (!cli_lock(&cli2, fnum2, offset-2, 1, 0, WRITE_LOCK)) {
1071 printf("lock2 %d failed (%s)\n",
1078 for (offset=i=0;i<numops;i++) {
1081 if (cli_lock(&cli1, fnum1, offset-2, 1, 0, WRITE_LOCK)) {
1082 printf("error: lock1 %d succeeded!\n", i);
1086 if (cli_lock(&cli2, fnum2, offset-1, 1, 0, WRITE_LOCK)) {
1087 printf("error: lock2 %d succeeded!\n", i);
1091 if (cli_lock(&cli1, fnum1, offset-1, 1, 0, WRITE_LOCK)) {
1092 printf("error: lock3 %d succeeded!\n", i);
1096 if (cli_lock(&cli2, fnum2, offset-2, 1, 0, WRITE_LOCK)) {
1097 printf("error: lock4 %d succeeded!\n", i);
1102 for (offset=i=0;i<numops;i++) {
1105 if (!cli_unlock(&cli1, fnum1, offset-1, 1)) {
1106 printf("unlock1 %d failed (%s)\n",
1112 if (!cli_unlock(&cli2, fnum2, offset-2, 1)) {
1113 printf("unlock2 %d failed (%s)\n",
1120 if (!cli_close(&cli1, fnum1)) {
1121 printf("close1 failed (%s)\n", cli_errstr(&cli1));
1125 if (!cli_close(&cli2, fnum2)) {
1126 printf("close2 failed (%s)\n", cli_errstr(&cli2));
1130 if (!cli_unlink(&cli1, fname)) {
1131 printf("unlink failed (%s)\n", cli_errstr(&cli1));
1135 if (!close_connection(&cli1)) {
1139 if (!close_connection(&cli2)) {
1143 printf("finished locktest3\n");
1148 #define EXPECTED(ret, v) if ((ret) != (v)) { \
1149 printf("** "); correct = False; \
1153 looks at overlapping locks
1155 static BOOL run_locktest4(int dummy)
1157 static struct cli_state cli1, cli2;
1158 char *fname = "\\lockt4.lck";
1159 int fnum1, fnum2, f;
1162 BOOL correct = True;
1164 if (!open_connection(&cli1) || !open_connection(&cli2)) {
1168 cli_sockopt(&cli1, sockops);
1169 cli_sockopt(&cli2, sockops);
1171 printf("starting locktest4\n");
1173 cli_unlink(&cli1, fname);
1175 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1176 fnum2 = cli_open(&cli2, fname, O_RDWR, DENY_NONE);
1178 memset(buf, 0, sizeof(buf));
1180 if (cli_write(&cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
1181 printf("Failed to create file\n");
1186 ret = cli_lock(&cli1, fnum1, 0, 4, 0, WRITE_LOCK) &&
1187 cli_lock(&cli1, fnum1, 2, 4, 0, WRITE_LOCK);
1188 EXPECTED(ret, False);
1189 printf("the same process %s set overlapping write locks\n", ret?"can":"cannot");
1191 ret = cli_lock(&cli1, fnum1, 10, 4, 0, READ_LOCK) &&
1192 cli_lock(&cli1, fnum1, 12, 4, 0, READ_LOCK);
1193 EXPECTED(ret, True);
1194 printf("the same process %s set overlapping read locks\n", ret?"can":"cannot");
1196 ret = cli_lock(&cli1, fnum1, 20, 4, 0, WRITE_LOCK) &&
1197 cli_lock(&cli2, fnum2, 22, 4, 0, WRITE_LOCK);
1198 EXPECTED(ret, False);
1199 printf("a different connection %s set overlapping write locks\n", ret?"can":"cannot");
1201 ret = cli_lock(&cli1, fnum1, 30, 4, 0, READ_LOCK) &&
1202 cli_lock(&cli2, fnum2, 32, 4, 0, READ_LOCK);
1203 EXPECTED(ret, True);
1204 printf("a different connection %s set overlapping read locks\n", ret?"can":"cannot");
1206 ret = (cli_setpid(&cli1, 1), cli_lock(&cli1, fnum1, 40, 4, 0, WRITE_LOCK)) &&
1207 (cli_setpid(&cli1, 2), cli_lock(&cli1, fnum1, 42, 4, 0, WRITE_LOCK));
1208 EXPECTED(ret, False);
1209 printf("a different pid %s set overlapping write locks\n", ret?"can":"cannot");
1211 ret = (cli_setpid(&cli1, 1), cli_lock(&cli1, fnum1, 50, 4, 0, READ_LOCK)) &&
1212 (cli_setpid(&cli1, 2), cli_lock(&cli1, fnum1, 52, 4, 0, READ_LOCK));
1213 EXPECTED(ret, True);
1214 printf("a different pid %s set overlapping read locks\n", ret?"can":"cannot");
1216 ret = cli_lock(&cli1, fnum1, 60, 4, 0, READ_LOCK) &&
1217 cli_lock(&cli1, fnum1, 60, 4, 0, READ_LOCK);
1218 EXPECTED(ret, True);
1219 printf("the same process %s set the same read lock twice\n", ret?"can":"cannot");
1221 ret = cli_lock(&cli1, fnum1, 70, 4, 0, WRITE_LOCK) &&
1222 cli_lock(&cli1, fnum1, 70, 4, 0, WRITE_LOCK);
1223 EXPECTED(ret, False);
1224 printf("the same process %s set the same write lock twice\n", ret?"can":"cannot");
1226 ret = cli_lock(&cli1, fnum1, 80, 4, 0, READ_LOCK) &&
1227 cli_lock(&cli1, fnum1, 80, 4, 0, WRITE_LOCK);
1228 EXPECTED(ret, False);
1229 printf("the same process %s overlay a read lock with a write lock\n", ret?"can":"cannot");
1231 ret = cli_lock(&cli1, fnum1, 90, 4, 0, WRITE_LOCK) &&
1232 cli_lock(&cli1, fnum1, 90, 4, 0, READ_LOCK);
1233 EXPECTED(ret, True);
1234 printf("the same process %s overlay a write lock with a read lock\n", ret?"can":"cannot");
1236 ret = (cli_setpid(&cli1, 1), cli_lock(&cli1, fnum1, 100, 4, 0, WRITE_LOCK)) &&
1237 (cli_setpid(&cli1, 2), cli_lock(&cli1, fnum1, 100, 4, 0, READ_LOCK));
1238 EXPECTED(ret, False);
1239 printf("a different pid %s overlay a write lock with a read lock\n", ret?"can":"cannot");
1241 ret = cli_lock(&cli1, fnum1, 110, 4, 0, READ_LOCK) &&
1242 cli_lock(&cli1, fnum1, 112, 4, 0, READ_LOCK) &&
1243 cli_unlock(&cli1, fnum1, 110, 6);
1244 EXPECTED(ret, False);
1245 printf("the same process %s coalesce read locks\n", ret?"can":"cannot");
1248 ret = cli_lock(&cli1, fnum1, 120, 4, 0, WRITE_LOCK) &&
1249 (cli_read(&cli2, fnum2, buf, 120, 4) == 4);
1250 EXPECTED(ret, False);
1251 printf("this server %s strict write locking\n", ret?"doesn't do":"does");
1253 ret = cli_lock(&cli1, fnum1, 130, 4, 0, READ_LOCK) &&
1254 (cli_write(&cli2, fnum2, 0, buf, 130, 4) == 4);
1255 EXPECTED(ret, False);
1256 printf("this server %s strict read locking\n", ret?"doesn't do":"does");
1259 ret = cli_lock(&cli1, fnum1, 140, 4, 0, READ_LOCK) &&
1260 cli_lock(&cli1, fnum1, 140, 4, 0, READ_LOCK) &&
1261 cli_unlock(&cli1, fnum1, 140, 4) &&
1262 cli_unlock(&cli1, fnum1, 140, 4);
1263 EXPECTED(ret, True);
1264 printf("this server %s do recursive read locking\n", ret?"does":"doesn't");
1267 ret = cli_lock(&cli1, fnum1, 150, 4, 0, WRITE_LOCK) &&
1268 cli_lock(&cli1, fnum1, 150, 4, 0, READ_LOCK) &&
1269 cli_unlock(&cli1, fnum1, 150, 4) &&
1270 (cli_read(&cli2, fnum2, buf, 150, 4) == 4) &&
1271 !(cli_write(&cli2, fnum2, 0, buf, 150, 4) == 4) &&
1272 cli_unlock(&cli1, fnum1, 150, 4);
1273 EXPECTED(ret, True);
1274 printf("this server %s do recursive lock overlays\n", ret?"does":"doesn't");
1276 ret = cli_lock(&cli1, fnum1, 160, 4, 0, READ_LOCK) &&
1277 cli_unlock(&cli1, fnum1, 160, 4) &&
1278 (cli_write(&cli2, fnum2, 0, buf, 160, 4) == 4) &&
1279 (cli_read(&cli2, fnum2, buf, 160, 4) == 4);
1280 EXPECTED(ret, True);
1281 printf("the same process %s remove a read lock using write locking\n", ret?"can":"cannot");
1283 ret = cli_lock(&cli1, fnum1, 170, 4, 0, WRITE_LOCK) &&
1284 cli_unlock(&cli1, fnum1, 170, 4) &&
1285 (cli_write(&cli2, fnum2, 0, buf, 170, 4) == 4) &&
1286 (cli_read(&cli2, fnum2, buf, 170, 4) == 4);
1287 EXPECTED(ret, True);
1288 printf("the same process %s remove a write lock using read locking\n", ret?"can":"cannot");
1290 ret = cli_lock(&cli1, fnum1, 190, 4, 0, WRITE_LOCK) &&
1291 cli_lock(&cli1, fnum1, 190, 4, 0, READ_LOCK) &&
1292 cli_unlock(&cli1, fnum1, 190, 4) &&
1293 !(cli_write(&cli2, fnum2, 0, buf, 190, 4) == 4) &&
1294 (cli_read(&cli2, fnum2, buf, 190, 4) == 4);
1295 EXPECTED(ret, True);
1296 printf("the same process %s remove the first lock first\n", ret?"does":"doesn't");
1298 cli_close(&cli1, fnum1);
1299 cli_close(&cli2, fnum2);
1300 fnum1 = cli_open(&cli1, fname, O_RDWR, DENY_NONE);
1301 f = cli_open(&cli1, fname, O_RDWR, DENY_NONE);
1302 ret = cli_lock(&cli1, fnum1, 0, 8, 0, READ_LOCK) &&
1303 cli_lock(&cli1, f, 0, 1, 0, READ_LOCK) &&
1304 cli_close(&cli1, fnum1) &&
1305 ((fnum1 = cli_open(&cli1, fname, O_RDWR, DENY_NONE)) != -1) &&
1306 cli_lock(&cli1, fnum1, 7, 1, 0, WRITE_LOCK);
1307 cli_close(&cli1, f);
1308 EXPECTED(ret, True);
1309 printf("the server %s have the NT byte range lock bug\n", !ret?"does":"doesn't");
1312 cli_close(&cli1, fnum1);
1313 cli_close(&cli2, fnum2);
1314 cli_unlink(&cli1, fname);
1315 close_connection(&cli1);
1316 close_connection(&cli2);
1318 printf("finished locktest4\n");
1323 looks at lock upgrade/downgrade.
1325 static BOOL run_locktest5(int dummy)
1327 static struct cli_state cli1, cli2;
1328 char *fname = "\\lockt5.lck";
1329 int fnum1, fnum2, fnum3;
1332 BOOL correct = True;
1334 if (!open_connection(&cli1) || !open_connection(&cli2)) {
1338 cli_sockopt(&cli1, sockops);
1339 cli_sockopt(&cli2, sockops);
1341 printf("starting locktest5\n");
1343 cli_unlink(&cli1, fname);
1345 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1346 fnum2 = cli_open(&cli2, fname, O_RDWR, DENY_NONE);
1347 fnum3 = cli_open(&cli1, fname, O_RDWR, DENY_NONE);
1349 memset(buf, 0, sizeof(buf));
1351 if (cli_write(&cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
1352 printf("Failed to create file\n");
1357 /* Check for NT bug... */
1358 ret = cli_lock(&cli1, fnum1, 0, 8, 0, READ_LOCK) &&
1359 cli_lock(&cli1, fnum3, 0, 1, 0, READ_LOCK);
1360 cli_close(&cli1, fnum1);
1361 fnum1 = cli_open(&cli1, fname, O_RDWR, DENY_NONE);
1362 ret = cli_lock(&cli1, fnum1, 7, 1, 0, WRITE_LOCK);
1363 EXPECTED(ret, True);
1364 printf("this server %s the NT locking bug\n", ret ? "doesn't have" : "has");
1365 cli_close(&cli1, fnum1);
1366 fnum1 = cli_open(&cli1, fname, O_RDWR, DENY_NONE);
1367 cli_unlock(&cli1, fnum3, 0, 1);
1369 ret = cli_lock(&cli1, fnum1, 0, 4, 0, WRITE_LOCK) &&
1370 cli_lock(&cli1, fnum1, 1, 1, 0, READ_LOCK);
1371 EXPECTED(ret, True);
1372 printf("the same process %s overlay a write with a read lock\n", ret?"can":"cannot");
1374 ret = cli_lock(&cli2, fnum2, 0, 4, 0, READ_LOCK);
1375 EXPECTED(ret, False);
1377 printf("a different processs %s get a read lock on the first process lock stack\n", ret?"can":"cannot");
1379 /* Unlock the process 2 lock. */
1380 cli_unlock(&cli2, fnum2, 0, 4);
1382 ret = cli_lock(&cli1, fnum3, 0, 4, 0, READ_LOCK);
1383 EXPECTED(ret, False);
1385 printf("the same processs on a different fnum %s get a read lock\n", ret?"can":"cannot");
1387 /* Unlock the process 1 fnum3 lock. */
1388 cli_unlock(&cli1, fnum3, 0, 4);
1390 /* Stack 2 more locks here. */
1391 ret = cli_lock(&cli1, fnum1, 0, 4, 0, READ_LOCK) &&
1392 cli_lock(&cli1, fnum1, 0, 4, 0, READ_LOCK);
1394 EXPECTED(ret, True);
1395 printf("the same process %s stack read locks\n", ret?"can":"cannot");
1397 /* Unlock the first process lock, then check this was the WRITE lock that was
1400 ret = cli_unlock(&cli1, fnum1, 0, 4) &&
1401 cli_lock(&cli2, fnum2, 0, 4, 0, READ_LOCK);
1403 EXPECTED(ret, True);
1404 printf("the first unlock removes the %s lock\n", ret?"WRITE":"READ");
1406 /* Unlock the process 2 lock. */
1407 cli_unlock(&cli2, fnum2, 0, 4);
1409 /* We should have 3 stacked locks here. Ensure we need to do 3 unlocks. */
1411 ret = cli_unlock(&cli1, fnum1, 1, 1) &&
1412 cli_unlock(&cli1, fnum1, 0, 4) &&
1413 cli_unlock(&cli1, fnum1, 0, 4);
1415 EXPECTED(ret, True);
1416 printf("the same process %s unlock the stack of 4 locks\n", ret?"can":"cannot");
1418 /* Ensure the next unlock fails. */
1419 ret = cli_unlock(&cli1, fnum1, 0, 4);
1420 EXPECTED(ret, False);
1421 printf("the same process %s count the lock stack\n", !ret?"can":"cannot");
1423 /* Ensure connection 2 can get a write lock. */
1424 ret = cli_lock(&cli2, fnum2, 0, 4, 0, WRITE_LOCK);
1425 EXPECTED(ret, True);
1427 printf("a different processs %s get a write lock on the unlocked stack\n", ret?"can":"cannot");
1431 cli_close(&cli1, fnum1);
1432 cli_close(&cli2, fnum2);
1433 cli_unlink(&cli1, fname);
1434 if (!close_connection(&cli1)) {
1437 if (!close_connection(&cli2)) {
1441 printf("finished locktest5\n");
1448 this produces a matrix of deny mode behaviour
1450 static BOOL run_denytest1(int dummy)
1452 static struct cli_state cli1, cli2;
1454 int f, d1, d2, o1, o2, x=0;
1455 char *fnames[] = {"\\denytest1.exe", "\\denytest1.dat", NULL};
1460 {DENY_DOS, "DENY_DOS"},
1461 {DENY_ALL, "DENY_ALL"},
1462 {DENY_WRITE, "DENY_WRITE"},
1463 {DENY_READ, "DENY_READ"},
1464 {DENY_NONE, "DENY_NONE"},
1465 {DENY_FCB, "DENY_FCB"},
1472 {O_RDONLY, "O_RDONLY"},
1473 {O_WRONLY, "O_WRONLY"},
1475 BOOL correct = True;
1477 if (!open_connection(&cli1) || !open_connection(&cli2)) {
1480 cli_sockopt(&cli1, sockops);
1481 cli_sockopt(&cli2, sockops);
1483 printf("starting denytest1\n");
1485 for (f=0;fnames[f];f++) {
1486 cli_unlink(&cli1, fnames[f]);
1488 fnum1 = cli_open(&cli1, fnames[f], O_RDWR|O_CREAT, DENY_NONE);
1489 cli_write(&cli1, fnum1, 0, fnames[f], 0, strlen(fnames[f]));
1490 cli_close(&cli1, fnum1);
1492 for (d1=0;deny_modes[d1].name;d1++)
1493 for (o1=0;open_modes[o1].name;o1++)
1494 for (d2=0;deny_modes[d2].name;d2++)
1495 for (o2=0;open_modes[o2].name;o2++) {
1496 fnum1 = cli_open(&cli1, fnames[f],
1499 fnum2 = cli_open(&cli2, fnames[f],
1503 printf("%s %8s %10s %8s %10s ",
1505 open_modes[o1].name,
1506 deny_modes[d1].name,
1507 open_modes[o2].name,
1508 deny_modes[d2].name);
1512 } else if (fnum2 == -1) {
1515 if (cli_read(&cli2, fnum2, (void *)&x, 0, 1) == 1) {
1518 if (cli_write(&cli2, fnum2, 0, (void *)&x, 0, 1) == 1) {
1524 cli_close(&cli1, fnum1);
1525 cli_close(&cli2, fnum2);
1528 cli_unlink(&cli1, fnames[f]);
1531 if (!close_connection(&cli1)) {
1534 if (!close_connection(&cli2)) {
1538 printf("finshed denytest1\n");
1544 this produces a matrix of deny mode behaviour for two opens on the
1547 static BOOL run_denytest2(int dummy)
1549 static struct cli_state cli1;
1551 int f, d1, d2, o1, o2, x=0;
1552 char *fnames[] = {"\\denytest2.exe", "\\denytest2.dat", NULL};
1557 {DENY_DOS, "DENY_DOS"},
1558 {DENY_ALL, "DENY_ALL"},
1559 {DENY_WRITE, "DENY_WRITE"},
1560 {DENY_READ, "DENY_READ"},
1561 {DENY_NONE, "DENY_NONE"},
1562 {DENY_FCB, "DENY_FCB"},
1569 {O_RDONLY, "O_RDONLY"},
1570 {O_WRONLY, "O_WRONLY"},
1572 BOOL correct = True;
1574 if (!open_connection(&cli1)) {
1577 cli_sockopt(&cli1, sockops);
1579 printf("starting denytest2\n");
1581 for (f=0;fnames[f];f++) {
1582 cli_unlink(&cli1, fnames[f]);
1584 fnum1 = cli_open(&cli1, fnames[f], O_RDWR|O_CREAT, DENY_NONE);
1585 cli_write(&cli1, fnum1, 0, fnames[f], 0, strlen(fnames[f]));
1586 cli_close(&cli1, fnum1);
1588 for (d1=0;deny_modes[d1].name;d1++)
1589 for (o1=0;open_modes[o1].name;o1++)
1590 for (d2=0;deny_modes[d2].name;d2++)
1591 for (o2=0;open_modes[o2].name;o2++) {
1592 fnum1 = cli_open(&cli1, fnames[f],
1595 fnum2 = cli_open(&cli1, fnames[f],
1599 printf("%s %8s %10s %8s %10s ",
1601 open_modes[o1].name,
1602 deny_modes[d1].name,
1603 open_modes[o2].name,
1604 deny_modes[d2].name);
1608 } else if (fnum2 == -1) {
1611 if (cli_read(&cli1, fnum2, (void *)&x, 0, 1) == 1) {
1614 if (cli_write(&cli1, fnum2, 0, (void *)&x, 0, 1) == 1) {
1620 cli_close(&cli1, fnum1);
1621 cli_close(&cli1, fnum2);
1624 cli_unlink(&cli1, fnames[f]);
1627 if (!close_connection(&cli1)) {
1631 printf("finshed denytest2\n");
1636 test whether fnums and tids open on one VC are available on another (a major
1639 static BOOL run_fdpasstest(int dummy)
1641 static struct cli_state cli1, cli2, cli3;
1642 char *fname = "\\fdpass.tst";
1646 if (!open_connection(&cli1) || !open_connection(&cli2)) {
1649 cli_sockopt(&cli1, sockops);
1650 cli_sockopt(&cli2, sockops);
1652 printf("starting fdpasstest\n");
1654 cli_unlink(&cli1, fname);
1656 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1658 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
1662 if (cli_write(&cli1, fnum1, 0, "hello world\n", 0, 13) != 13) {
1663 printf("write failed (%s)\n", cli_errstr(&cli1));
1668 cli3.vuid = cli1.vuid;
1669 cli3.cnum = cli1.cnum;
1670 cli3.pid = cli1.pid;
1672 if (cli_read(&cli3, fnum1, buf, 0, 13) == 13) {
1673 printf("read succeeded! nasty security hole [%s]\n",
1678 cli_close(&cli1, fnum1);
1679 cli_unlink(&cli1, fname);
1681 close_connection(&cli1);
1682 close_connection(&cli2);
1684 printf("finished fdpasstest\n");
1690 This test checks that
1692 1) the server does not allow an unlink on a file that is open
1694 static BOOL run_unlinktest(int dummy)
1696 static struct cli_state cli;
1697 char *fname = "\\unlink.tst";
1699 BOOL correct = True;
1701 if (!open_connection(&cli)) {
1705 cli_sockopt(&cli, sockops);
1707 printf("starting unlink test\n");
1709 cli_unlink(&cli, fname);
1711 cli_setpid(&cli, 1);
1713 fnum = cli_open(&cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1715 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli));
1719 if (cli_unlink(&cli, fname)) {
1720 printf("error: server allowed unlink on an open file\n");
1724 cli_close(&cli, fnum);
1725 cli_unlink(&cli, fname);
1727 if (!close_connection(&cli)) {
1731 printf("unlink test finished\n");
1738 test how many open files this server supports on the one socket
1740 static BOOL run_maxfidtest(int dummy)
1742 static struct cli_state cli;
1743 char *template = "\\maxfid.%d.%d";
1747 BOOL correct = True;
1752 printf("failed to connect\n");
1756 cli_sockopt(&cli, sockops);
1760 slprintf(fname,sizeof(fname)-1,template, fnum,(int)getpid());
1761 if (cli_open(&cli, fname,
1762 O_RDWR|O_CREAT|O_TRUNC, DENY_NONE) ==
1764 printf("open of %s failed (%s)\n",
1765 fname, cli_errstr(&cli));
1766 printf("maximum fnum is %d\n", fnum);
1770 if (fnum % 100 == 0) printf("%d\r", fnum);
1772 printf("%d\n", fnum);
1774 printf("cleaning up\n");
1777 slprintf(fname,sizeof(fname)-1,template, fnum,(int)getpid());
1778 cli_close(&cli, fnum);
1779 if (!cli_unlink(&cli, fname)) {
1780 printf("unlink of %s failed (%s)\n",
1781 fname, cli_errstr(&cli));
1786 printf("maxfid test finished\n");
1787 if (!close_connection(&cli)) {
1793 /* generate a random buffer */
1794 static void rand_buf(char *buf, int len)
1797 *buf = (char)sys_random();
1802 /* send smb negprot commands, not reading the response */
1803 static BOOL run_negprot_nowait(int dummy)
1806 static struct cli_state cli;
1807 BOOL correct = True;
1809 printf("starting negprot nowait test\n");
1811 if (!open_nbt_connection(&cli)) {
1815 for (i=0;i<50000;i++) {
1816 cli_negprot_send(&cli);
1819 if (!close_connection(&cli)) {
1823 printf("finished negprot nowait test\n");
1829 /* send random IPC commands */
1830 static BOOL run_randomipc(int dummy)
1832 char *rparam = NULL;
1836 int api, param_len, i;
1837 static struct cli_state cli;
1838 BOOL correct = True;
1840 printf("starting random ipc test\n");
1842 if (!open_connection(&cli)) {
1846 for (i=0;i<50000;i++) {
1847 api = sys_random() % 500;
1848 param_len = (sys_random() % 64);
1850 rand_buf(param, param_len);
1855 param, param_len, 8,
1856 NULL, 0, BUFFER_SIZE,
1861 if (!close_connection(&cli)) {
1865 printf("finished random ipc test\n");
1872 static void browse_callback(const char *sname, uint32 stype,
1873 const char *comment, void *state)
1875 printf("\t%20.20s %08x %s\n", sname, stype, comment);
1881 This test checks the browse list code
1884 static BOOL run_browsetest(int dummy)
1886 static struct cli_state cli;
1887 BOOL correct = True;
1889 printf("starting browse test\n");
1891 if (!open_connection(&cli)) {
1895 printf("domain list:\n");
1896 cli_NetServerEnum(&cli, cli.server_domain,
1897 SV_TYPE_DOMAIN_ENUM,
1898 browse_callback, NULL);
1900 printf("machine list:\n");
1901 cli_NetServerEnum(&cli, cli.server_domain,
1903 browse_callback, NULL);
1905 if (!close_connection(&cli)) {
1909 printf("browse test finished\n");
1917 This checks how the getatr calls works
1919 static BOOL run_attrtest(int dummy)
1921 static struct cli_state cli;
1924 char *fname = "\\attrib.tst";
1925 BOOL correct = True;
1927 printf("starting attrib test\n");
1929 if (!open_connection(&cli)) {
1933 cli_unlink(&cli, fname);
1934 fnum = cli_open(&cli, fname,
1935 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
1936 cli_close(&cli, fnum);
1937 if (!cli_getatr(&cli, fname, NULL, NULL, &t)) {
1938 printf("getatr failed (%s)\n", cli_errstr(&cli));
1942 if (abs(t - time(NULL)) > 2) {
1943 printf("ERROR: SMBgetatr bug. time is %s",
1949 t2 = t-60*60*24; /* 1 day ago */
1951 if (!cli_setatr(&cli, fname, 0, t2)) {
1952 printf("setatr failed (%s)\n", cli_errstr(&cli));
1956 if (!cli_getatr(&cli, fname, NULL, NULL, &t)) {
1957 printf("getatr failed (%s)\n", cli_errstr(&cli));
1962 printf("ERROR: getatr/setatr bug. times are\n%s",
1964 printf("%s", ctime(&t2));
1968 cli_unlink(&cli, fname);
1970 if (!close_connection(&cli)) {
1974 printf("attrib test finished\n");
1981 This checks a couple of trans2 calls
1983 static BOOL run_trans2test(int dummy)
1985 static struct cli_state cli;
1988 time_t c_time, a_time, m_time, w_time, m_time2;
1989 char *fname = "\\trans2.tst";
1990 char *dname = "\\trans2";
1991 char *fname2 = "\\trans2\\trans2.tst";
1992 BOOL correct = True;
1994 printf("starting trans2 test\n");
1996 if (!open_connection(&cli)) {
2000 cli_unlink(&cli, fname);
2001 fnum = cli_open(&cli, fname,
2002 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2003 if (!cli_qfileinfo(&cli, fnum, NULL, &size, &c_time, &a_time, &m_time,
2005 printf("ERROR: qfileinfo failed (%s)\n", cli_errstr(&cli));
2008 cli_close(&cli, fnum);
2012 cli_unlink(&cli, fname);
2013 fnum = cli_open(&cli, fname,
2014 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2015 cli_close(&cli, fnum);
2017 if (!cli_qpathinfo(&cli, fname, &c_time, &a_time, &m_time, &size, NULL)) {
2018 printf("ERROR: qpathinfo failed (%s)\n", cli_errstr(&cli));
2021 if (c_time != m_time) {
2022 printf("create time=%s", ctime(&c_time));
2023 printf("modify time=%s", ctime(&m_time));
2024 printf("This system appears to have sticky create times\n");
2027 if (a_time % (60*60) == 0) {
2028 printf("access time=%s", ctime(&a_time));
2029 printf("This system appears to set a midnight access time\n");
2033 if (abs(m_time - time(NULL)) > 60*60*24*7) {
2034 printf("ERROR: totally incorrect times - maybe word reversed?\n");
2040 cli_unlink(&cli, fname);
2041 fnum = cli_open(&cli, fname,
2042 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2043 cli_close(&cli, fnum);
2044 if (!cli_qpathinfo2(&cli, fname, &c_time, &a_time, &m_time,
2045 &w_time, &size, NULL, NULL)) {
2046 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli));
2049 if (w_time < 60*60*24*2) {
2050 printf("write time=%s", ctime(&w_time));
2051 printf("This system appears to set a initial 0 write time\n");
2056 cli_unlink(&cli, fname);
2059 /* check if the server updates the directory modification time
2060 when creating a new file */
2061 if (!cli_mkdir(&cli, dname)) {
2062 printf("ERROR: mkdir failed (%s)\n", cli_errstr(&cli));
2066 if (!cli_qpathinfo2(&cli, "\\trans2\\", &c_time, &a_time, &m_time,
2067 &w_time, &size, NULL, NULL)) {
2068 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli));
2072 fnum = cli_open(&cli, fname2,
2073 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2074 cli_write(&cli, fnum, 0, (char *)&fnum, 0, sizeof(fnum));
2075 cli_close(&cli, fnum);
2076 if (!cli_qpathinfo2(&cli, "\\trans2\\", &c_time, &a_time, &m_time2,
2077 &w_time, &size, NULL, NULL)) {
2078 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli));
2081 if (m_time2 == m_time) {
2082 printf("This system does not update directory modification times\n");
2086 cli_unlink(&cli, fname2);
2087 cli_rmdir(&cli, dname);
2089 if (!close_connection(&cli)) {
2093 printf("trans2 test finished\n");
2099 This checks new W2K calls.
2102 static BOOL new_trans(struct cli_state *pcli, int fnum, int level)
2105 BOOL correct = True;
2107 memset(buf, 0xff, sizeof(buf));
2109 if (!cli_qfileinfo_test(pcli, fnum, level, buf)) {
2110 printf("ERROR: qfileinfo (%d) failed (%s)\n", level, cli_errstr(pcli));
2113 printf("qfileinfo: level %d\n", level);
2114 dump_data(0, buf, 256);
2120 static BOOL run_w2ktest(int dummy)
2122 static struct cli_state cli;
2124 char *fname = "\\w2ktest\\w2k.tst";
2126 BOOL correct = True;
2128 printf("starting w2k test\n");
2130 if (!open_connection(&cli)) {
2134 fnum = cli_open(&cli, fname,
2135 O_RDWR | O_CREAT , DENY_NONE);
2137 for (level = 1004; level < 1040; level++) {
2138 if (!new_trans(&cli, fnum, level)) {
2143 cli_close(&cli, fnum);
2145 if (!close_connection(&cli)) {
2149 printf("w2k test finished\n");
2156 this is a harness for some oplock tests
2158 static BOOL run_oplock1(int dummy)
2160 static struct cli_state cli1;
2161 char *fname = "\\lockt1.lck";
2163 BOOL correct = True;
2165 printf("starting oplock test 1\n");
2167 if (!open_connection(&cli1)) {
2171 cli_unlink(&cli1, fname);
2173 cli_sockopt(&cli1, sockops);
2175 cli1.use_oplocks = True;
2177 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2179 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2183 cli1.use_oplocks = False;
2185 cli_unlink(&cli1, fname);
2186 cli_unlink(&cli1, fname);
2188 if (!cli_close(&cli1, fnum1)) {
2189 printf("close2 failed (%s)\n", cli_errstr(&cli1));
2193 if (!cli_unlink(&cli1, fname)) {
2194 printf("unlink failed (%s)\n", cli_errstr(&cli1));
2198 if (!close_connection(&cli1)) {
2202 printf("finished oplock test 1\n");
2207 static BOOL run_oplock2(int dummy)
2209 static struct cli_state cli1, cli2;
2210 char *fname = "\\lockt2.lck";
2212 int saved_use_oplocks = use_oplocks;
2214 BOOL correct = True;
2215 volatile BOOL *shared_correct;
2217 shared_correct = (volatile BOOL *)shm_setup(sizeof(BOOL));
2218 *shared_correct = True;
2220 use_level_II_oplocks = True;
2223 printf("starting oplock test 2\n");
2225 if (!open_connection(&cli1)) {
2226 use_level_II_oplocks = False;
2227 use_oplocks = saved_use_oplocks;
2231 cli1.use_oplocks = True;
2232 cli1.use_level_II_oplocks = True;
2234 if (!open_connection(&cli2)) {
2235 use_level_II_oplocks = False;
2236 use_oplocks = saved_use_oplocks;
2240 cli2.use_oplocks = True;
2241 cli2.use_level_II_oplocks = True;
2243 cli_unlink(&cli1, fname);
2245 cli_sockopt(&cli1, sockops);
2246 cli_sockopt(&cli2, sockops);
2248 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2250 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2254 /* Don't need the globals any more. */
2255 use_level_II_oplocks = False;
2256 use_oplocks = saved_use_oplocks;
2260 fnum2 = cli_open(&cli2, fname, O_RDWR, DENY_NONE);
2262 printf("second open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2263 *shared_correct = False;
2269 if (!cli_close(&cli2, fnum2)) {
2270 printf("close2 failed (%s)\n", cli_errstr(&cli1));
2271 *shared_correct = False;
2279 /* Ensure cli1 processes the break. */
2281 if (cli_read(&cli1, fnum1, buf, 0, 4) != 4) {
2282 printf("read on fnum1 failed (%s)\n", cli_errstr(&cli1));
2286 /* Should now be at level II. */
2287 /* Test if sending a write locks causes a break to none. */
2289 if (!cli_lock(&cli1, fnum1, 0, 4, 0, READ_LOCK)) {
2290 printf("lock failed (%s)\n", cli_errstr(&cli1));
2294 cli_unlock(&cli1, fnum1, 0, 4);
2298 if (!cli_lock(&cli1, fnum1, 0, 4, 0, WRITE_LOCK)) {
2299 printf("lock failed (%s)\n", cli_errstr(&cli1));
2303 cli_unlock(&cli1, fnum1, 0, 4);
2307 cli_read(&cli1, fnum1, buf, 0, 4);
2310 if (cli_write(&cli1, fnum1, 0, buf, 0, 4) != 4) {
2311 printf("write on fnum1 failed (%s)\n", cli_errstr(&cli1));
2316 if (!cli_close(&cli1, fnum1)) {
2317 printf("close1 failed (%s)\n", cli_errstr(&cli1));
2323 if (!cli_unlink(&cli1, fname)) {
2324 printf("unlink failed (%s)\n", cli_errstr(&cli1));
2328 if (!close_connection(&cli1)) {
2332 if (!*shared_correct) {
2336 printf("finished oplock test 2\n");
2341 /* handler for oplock 3 tests */
2342 static BOOL oplock3_handler(struct cli_state *cli, int fnum, unsigned char level)
2344 printf("got oplock break fnum=%d level=%d\n",
2346 return cli_oplock_ack(cli, fnum, level);
2349 static BOOL run_oplock3(int dummy)
2351 static struct cli_state cli;
2352 char *fname = "\\oplockt3.dat";
2354 char buf[4] = "abcd";
2355 BOOL correct = True;
2356 volatile BOOL *shared_correct;
2358 shared_correct = (volatile BOOL *)shm_setup(sizeof(BOOL));
2359 *shared_correct = True;
2361 printf("starting oplock test 3\n");
2366 use_level_II_oplocks = True;
2367 if (!open_connection(&cli)) {
2368 *shared_correct = False;
2372 /* try to trigger a oplock break in parent */
2373 fnum = cli_open(&cli, fname, O_RDWR, DENY_NONE);
2374 cli_write(&cli, fnum, 0, buf, 0, 4);
2380 use_level_II_oplocks = True;
2381 if (!open_connection(&cli)) {
2384 cli_oplock_handler(&cli, oplock3_handler);
2385 fnum = cli_open(&cli, fname, O_RDWR|O_CREAT, DENY_NONE);
2386 cli_write(&cli, fnum, 0, buf, 0, 4);
2387 cli_close(&cli, fnum);
2388 fnum = cli_open(&cli, fname, O_RDWR, DENY_NONE);
2389 cli.timeout = 20000;
2390 cli_receive_smb(&cli);
2391 printf("finished oplock test 3\n");
2393 return (correct && *shared_correct);
2395 /* What are we looking for here? What's sucess and what's FAILURE? */
2401 Test delete on close semantics.
2403 static BOOL run_deletetest(int dummy)
2405 static struct cli_state cli1;
2406 static struct cli_state cli2;
2407 char *fname = "\\delete.file";
2409 BOOL correct = True;
2411 printf("starting delete test\n");
2413 if (!open_connection(&cli1)) {
2417 cli_sockopt(&cli1, sockops);
2419 /* Test 1 - this should *NOT* delete the file on close. */
2421 cli_setatr(&cli1, fname, 0, 0);
2422 cli_unlink(&cli1, fname);
2424 fnum1 = cli_nt_create_full(&cli1, fname, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL,
2425 FILE_SHARE_DELETE, FILE_OVERWRITE_IF, DELETE_ON_CLOSE_FLAG);
2428 printf("[1] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2432 if (!cli_close(&cli1, fnum1)) {
2433 printf("[1] close failed (%s)\n", cli_errstr(&cli1));
2437 fnum1 = cli_open(&cli1, fname, O_RDWR, DENY_NONE);
2439 printf("[1] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2443 if (!cli_close(&cli1, fnum1)) {
2444 printf("[1] close failed (%s)\n", cli_errstr(&cli1));
2448 printf("first delete on close test succeeded.\n");
2450 /* Test 2 - this should delete the file on close. */
2452 cli_setatr(&cli1, fname, 0, 0);
2453 cli_unlink(&cli1, fname);
2455 fnum1 = cli_nt_create_full(&cli1, fname, GENERIC_ALL_ACCESS,
2456 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0);
2459 printf("[2] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2463 if (!cli_nt_delete_on_close(&cli1, fnum1, True)) {
2464 printf("[2] setting delete_on_close failed (%s)\n", cli_errstr(&cli1));
2468 if (!cli_close(&cli1, fnum1)) {
2469 printf("[2] close failed (%s)\n", cli_errstr(&cli1));
2473 fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_NONE);
2475 printf("[2] open of %s succeeded should have been deleted on close !\n", fname);
2476 if (!cli_close(&cli1, fnum1)) {
2477 printf("[2] close failed (%s)\n", cli_errstr(&cli1));
2480 cli_unlink(&cli1, fname);
2482 printf("second delete on close test succeeded.\n");
2486 cli_setatr(&cli1, fname, 0, 0);
2487 cli_unlink(&cli1, fname);
2489 fnum1 = cli_nt_create_full(&cli1, fname, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL,
2490 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0);
2493 printf("[3] open - 1 of %s failed (%s)\n", fname, cli_errstr(&cli1));
2497 /* This should fail with a sharing violation - open for delete is only compatible
2498 with SHARE_DELETE. */
2500 fnum2 = cli_nt_create_full(&cli1, fname, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
2501 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0);
2504 printf("[3] open - 2 of %s succeeded - should have failed.\n", fname);
2508 /* This should succeed. */
2510 fnum2 = cli_nt_create_full(&cli1, fname, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
2511 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0);
2514 printf("[3] open - 2 of %s failed (%s)\n", fname, cli_errstr(&cli1));
2518 if (!cli_nt_delete_on_close(&cli1, fnum1, True)) {
2519 printf("[3] setting delete_on_close failed (%s)\n", cli_errstr(&cli1));
2523 if (!cli_close(&cli1, fnum1)) {
2524 printf("[3] close 1 failed (%s)\n", cli_errstr(&cli1));
2528 if (!cli_close(&cli1, fnum2)) {
2529 printf("[3] close 2 failed (%s)\n", cli_errstr(&cli1));
2533 /* This should fail - file should no longer be there. */
2535 fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_NONE);
2537 printf("[3] open of %s succeeded should have been deleted on close !\n", fname);
2538 if (!cli_close(&cli1, fnum1)) {
2539 printf("[3] close failed (%s)\n", cli_errstr(&cli1));
2541 cli_unlink(&cli1, fname);
2544 printf("third delete on close test succeeded.\n");
2547 cli_setatr(&cli1, fname, 0, 0);
2548 cli_unlink(&cli1, fname);
2550 fnum1 = cli_nt_create_full(&cli1, fname, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
2551 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0);
2554 printf("[4] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2558 /* This should succeed. */
2559 fnum2 = cli_nt_create_full(&cli1, fname, GENERIC_READ_ACCESS,
2560 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0);
2562 printf("[4] open - 2 of %s failed (%s)\n", fname, cli_errstr(&cli1));
2566 if (!cli_close(&cli1, fnum2)) {
2567 printf("[4] close - 1 failed (%s)\n", cli_errstr(&cli1));
2571 if (!cli_nt_delete_on_close(&cli1, fnum1, True)) {
2572 printf("[4] setting delete_on_close failed (%s)\n", cli_errstr(&cli1));
2576 /* This should fail - no more opens once delete on close set. */
2577 fnum2 = cli_nt_create_full(&cli1, fname, GENERIC_READ_ACCESS,
2578 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0);
2580 printf("[4] open - 3 of %s succeeded ! Should have failed.\n", fname );
2583 printf("fourth delete on close test succeeded.\n");
2585 if (!cli_close(&cli1, fnum1)) {
2586 printf("[4] close - 2 failed (%s)\n", cli_errstr(&cli1));
2591 cli_setatr(&cli1, fname, 0, 0);
2592 cli_unlink(&cli1, fname);
2594 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT, DENY_NONE);
2596 printf("[5] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2600 /* This should fail - only allowed on NT opens with DELETE access. */
2602 if (cli_nt_delete_on_close(&cli1, fnum1, True)) {
2603 printf("[5] setting delete_on_close on OpenX file succeeded - should fail !\n");
2607 if (!cli_close(&cli1, fnum1)) {
2608 printf("[5] close - 2 failed (%s)\n", cli_errstr(&cli1));
2612 printf("fifth delete on close test succeeded.\n");
2615 cli_setatr(&cli1, fname, 0, 0);
2616 cli_unlink(&cli1, fname);
2618 fnum1 = cli_nt_create_full(&cli1, fname, FILE_READ_DATA|FILE_WRITE_DATA,
2619 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
2620 FILE_OVERWRITE_IF, 0);
2623 printf("[6] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2627 /* This should fail - only allowed on NT opens with DELETE access. */
2629 if (cli_nt_delete_on_close(&cli1, fnum1, True)) {
2630 printf("[6] setting delete_on_close on file with no delete access succeeded - should fail !\n");
2634 if (!cli_close(&cli1, fnum1)) {
2635 printf("[6] close - 2 failed (%s)\n", cli_errstr(&cli1));
2639 printf("sixth delete on close test succeeded.\n");
2642 cli_setatr(&cli1, fname, 0, 0);
2643 cli_unlink(&cli1, fname);
2645 fnum1 = cli_nt_create_full(&cli1, fname, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
2646 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF, 0);
2649 printf("[7] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2653 if (!cli_nt_delete_on_close(&cli1, fnum1, True)) {
2654 printf("[7] setting delete_on_close on file failed !\n");
2658 if (!cli_nt_delete_on_close(&cli1, fnum1, False)) {
2659 printf("[7] unsetting delete_on_close on file failed !\n");
2663 if (!cli_close(&cli1, fnum1)) {
2664 printf("[7] close - 2 failed (%s)\n", cli_errstr(&cli1));
2668 /* This next open should succeed - we reset the flag. */
2670 fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_NONE);
2672 printf("[5] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2676 if (!cli_close(&cli1, fnum1)) {
2677 printf("[7] close - 2 failed (%s)\n", cli_errstr(&cli1));
2681 printf("seventh delete on close test succeeded.\n");
2684 cli_setatr(&cli1, fname, 0, 0);
2685 cli_unlink(&cli1, fname);
2687 if (!open_connection(&cli2)) {
2688 printf("[8] failed to open second connection.\n");
2692 cli_sockopt(&cli1, sockops);
2694 fnum1 = cli_nt_create_full(&cli1, fname, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
2695 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0);
2698 printf("[8] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2702 fnum2 = cli_nt_create_full(&cli2, fname, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
2703 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0);
2706 printf("[8] open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2710 if (!cli_nt_delete_on_close(&cli1, fnum1, True)) {
2711 printf("[8] setting delete_on_close on file failed !\n");
2715 if (!cli_close(&cli1, fnum1)) {
2716 printf("[8] close - 1 failed (%s)\n", cli_errstr(&cli1));
2720 if (!cli_close(&cli2, fnum2)) {
2721 printf("[8] close - 2 failed (%s)\n", cli_errstr(&cli2));
2725 /* This should fail.. */
2726 fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_NONE);
2728 printf("[8] open of %s succeeded should have been deleted on close !\n", fname);
2729 if (!cli_close(&cli1, fnum1)) {
2730 printf("[8] close failed (%s)\n", cli_errstr(&cli1));
2732 cli_unlink(&cli1, fname);
2735 printf("eighth delete on close test succeeded.\n");
2737 printf("finished delete test\n");
2739 cli_setatr(&cli1, fname, 0, 0);
2740 cli_unlink(&cli1, fname);
2742 if (!close_connection(&cli1)) {
2745 if (!close_connection(&cli2)) {
2752 Test open mode returns on read-only files.
2754 static BOOL run_opentest(int dummy)
2756 static struct cli_state cli1;
2757 char *fname = "\\readonly.file";
2763 BOOL correct = True;
2765 printf("starting open test\n");
2767 if (!open_connection(&cli1)) {
2771 cli_setatr(&cli1, fname, 0, 0);
2772 cli_unlink(&cli1, fname);
2774 cli_sockopt(&cli1, sockops);
2776 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2778 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2782 if (!cli_close(&cli1, fnum1)) {
2783 printf("close2 failed (%s)\n", cli_errstr(&cli1));
2787 if (!cli_setatr(&cli1, fname, aRONLY, 0)) {
2788 printf("cli_setatr failed (%s)\n", cli_errstr(&cli1));
2792 fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_WRITE);
2794 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2798 /* This will fail - but the error should be ERRnoaccess, not ERRbadshare. */
2799 fnum2 = cli_open(&cli1, fname, O_RDWR, DENY_ALL);
2801 cli_error( &cli1, &eclass, &errnum, NULL);
2803 if (eclass != ERRDOS || errnum != ERRnoaccess) {
2804 printf("wrong error code (%x,%x) = %s\n", (unsigned int)eclass,
2805 (unsigned int)errnum, cli_errstr(&cli1) );
2808 printf("correct error code ERRDOS/ERRnoaccess returned\n");
2812 printf("finished open test 1\n");
2814 cli_close(&cli1, fnum1);
2816 /* Now try not readonly and ensure ERRbadshare is returned. */
2818 cli_setatr(&cli1, fname, 0, 0);
2820 fnum1 = cli_open(&cli1, fname, O_RDONLY, DENY_WRITE);
2822 printf("open of %s failed (%s)\n", fname, cli_errstr(&cli1));
2826 /* This will fail - but the error should be ERRshare. */
2827 fnum2 = cli_open(&cli1, fname, O_RDWR, DENY_ALL);
2829 cli_error( &cli1, &eclass, &errnum, NULL);
2831 if (eclass != ERRDOS || errnum != ERRbadshare) {
2832 printf("wrong error code (%x,%x) = %s\n", (unsigned int)eclass,
2833 (unsigned int)errnum, cli_errstr(&cli1) );
2836 printf("correct error code ERRDOS/ERRbadshare returned\n");
2839 if (!cli_close(&cli1, fnum1)) {
2840 printf("close2 failed (%s)\n", cli_errstr(&cli1));
2844 cli_unlink(&cli1, fname);
2846 printf("finished open test 2\n");
2848 /* Test truncate open disposition on file opened for read. */
2850 fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2852 printf("(3) open (1) of %s failed (%s)\n", fname, cli_errstr(&cli1));
2856 /* write 20 bytes. */
2858 memset(buf, '\0', 20);
2860 if (cli_write(&cli1, fnum1, 0, buf, 0, 20) != 20) {
2861 printf("write failed (%s)\n", cli_errstr(&cli1));
2865 if (!cli_close(&cli1, fnum1)) {
2866 printf("(3) close1 failed (%s)\n", cli_errstr(&cli1));
2870 /* Ensure size == 20. */
2871 if (!cli_getatr(&cli1, fname, NULL, &fsize, NULL)) {
2872 printf("(3) getatr failed (%s)\n", cli_errstr(&cli1));
2877 printf("(3) file size != 20\n");
2881 /* Now test if we can truncate a file opened for readonly. */
2883 fnum1 = cli_open(&cli1, fname, O_RDONLY|O_TRUNC, DENY_NONE);
2885 printf("(3) open (2) of %s failed (%s)\n", fname, cli_errstr(&cli1));
2889 if (!cli_close(&cli1, fnum1)) {
2890 printf("close2 failed (%s)\n", cli_errstr(&cli1));
2894 /* Ensure size == 0. */
2895 if (!cli_getatr(&cli1, fname, NULL, &fsize, NULL)) {
2896 printf("(3) getatr failed (%s)\n", cli_errstr(&cli1));
2901 printf("(3) file size != 0\n");
2904 printf("finished open test 3\n");
2906 cli_unlink(&cli1, fname);
2909 printf("testing ctemp\n");
2912 fnum1 = cli_ctemp(&cli1, "\\", &tmp_path);
2914 printf("ctemp failed (%s)\n", cli_errstr(&cli1));
2917 printf("ctemp gave path %s\n", tmp_path);
2918 cli_close(&cli1, fnum1);
2919 cli_unlink(&cli1, tmp_path);
2922 if (!close_connection(&cli1)) {
2929 static void list_fn(file_info *finfo, const char *name, void *state)
2935 test directory listing speed
2937 static BOOL run_dirtest(int dummy)
2940 static struct cli_state cli;
2943 BOOL correct = True;
2945 printf("starting directory test\n");
2947 if (!open_connection(&cli)) {
2951 cli_sockopt(&cli, sockops);
2954 for (i=0;i<numops;i++) {
2956 slprintf(fname, sizeof(fname), "%x", (int)random());
2957 fnum = cli_open(&cli, fname, O_RDWR|O_CREAT, DENY_NONE);
2959 fprintf(stderr,"Failed to open %s\n", fname);
2962 cli_close(&cli, fnum);
2967 printf("Matched %d\n", cli_list(&cli, "a*.*", 0, list_fn, NULL));
2968 printf("Matched %d\n", cli_list(&cli, "b*.*", 0, list_fn, NULL));
2969 printf("Matched %d\n", cli_list(&cli, "xyzabc", 0, list_fn, NULL));
2971 printf("dirtest core %g seconds\n", end_timer() - t1);
2974 for (i=0;i<numops;i++) {
2976 slprintf(fname, sizeof(fname), "%x", (int)random());
2977 cli_unlink(&cli, fname);
2980 if (!close_connection(&cli)) {
2984 printf("finished dirtest\n");
2991 static double create_procs(BOOL (*fn)(int), BOOL *result)
2994 volatile pid_t *child_status;
2995 volatile BOOL *child_status_out;
3001 child_status = (volatile pid_t *)shm_setup(sizeof(pid_t)*nprocs);
3002 if (!child_status) {
3003 printf("Failed to setup shared memory\n");
3007 child_status_out = (volatile BOOL *)shm_setup(sizeof(BOOL)*nprocs);
3008 if (!child_status_out) {
3009 printf("Failed to setup result status shared memory\n");
3013 memset(child_status, 0, sizeof(pid_t)*nprocs);
3014 memset(child_status_out, True, sizeof(BOOL)*nprocs);
3018 for (i=0;i<nprocs;i++) {
3021 pid_t mypid = getpid();
3022 sys_srandom(((int)mypid) ^ ((int)time(NULL)));
3024 slprintf(myname,sizeof(myname),"CLIENT%d", i);
3027 memset(¤t_cli, 0, sizeof(current_cli));
3028 if (open_connection(¤t_cli)) break;
3030 printf("pid %d failed to start\n", (int)getpid());
3036 child_status[i] = getpid();
3038 while (child_status[i]) msleep(2);
3040 child_status_out[i] = fn(i);
3047 for (i=0;i<nprocs;i++) {
3048 if (child_status[i]) synccount++;
3050 if (synccount == nprocs) break;
3052 } while (end_timer() < 30);
3054 if (synccount != nprocs) {
3055 printf("FAILED TO START %d CLIENTS (started %d)\n", nprocs, synccount);
3060 /* start the client load */
3063 for (i=0;i<nprocs;i++) {
3064 child_status[i] = 0;
3067 printf("%d clients started\n", nprocs);
3069 for (i=0;i<nprocs;i++) {
3070 waitpid(0, &status, 0);
3076 for (i=0;i<nprocs;i++) {
3077 if (!child_status_out[i]) {
3085 #define FLAG_MULTIPROC 1
3092 {"FDPASS", run_fdpasstest, 0},
3093 {"LOCK1", run_locktest1, 0},
3094 {"LOCK2", run_locktest2, 0},
3095 {"LOCK3", run_locktest3, 0},
3096 {"LOCK4", run_locktest4, 0},
3097 {"LOCK5", run_locktest5, 0},
3098 {"UNLINK", run_unlinktest, 0},
3099 {"BROWSE", run_browsetest, 0},
3100 {"ATTR", run_attrtest, 0},
3101 {"TRANS2", run_trans2test, 0},
3102 {"MAXFID", run_maxfidtest, FLAG_MULTIPROC},
3103 {"TORTURE",run_torture, FLAG_MULTIPROC},
3104 {"RANDOMIPC", run_randomipc, 0},
3105 {"NEGNOWAIT", run_negprot_nowait, 0},
3106 {"NBW95", run_nbw95, 0},
3107 {"NBWNT", run_nbwnt, 0},
3108 {"OPLOCK1", run_oplock1, 0},
3109 {"OPLOCK2", run_oplock2, 0},
3110 {"OPLOCK3", run_oplock3, 0},
3111 {"DIR", run_dirtest, 0},
3112 {"DENY1", run_denytest1, 0},
3113 {"DENY2", run_denytest2, 0},
3114 {"TCON", run_tcon_test, 0},
3115 {"RW1", run_readwritetest, 0},
3116 {"RW2", run_readwritemulti, FLAG_MULTIPROC},
3117 {"RW3", run_readwritelarge, 0},
3118 {"OPEN", run_opentest, 0},
3119 {"DELETE", run_deletetest, 0},
3120 {"W2K", run_w2ktest, 0},
3125 /****************************************************************************
3126 run a specified test or "ALL"
3127 ****************************************************************************/
3128 static BOOL run_test(char *name)
3134 if (strequal(name,"ALL")) {
3135 for (i=0;torture_ops[i].name;i++) {
3136 run_test(torture_ops[i].name);
3140 for (i=0;torture_ops[i].name;i++) {
3141 snprintf(randomfname, sizeof(randomfname), "\\XX%x",
3142 (unsigned)random());
3144 if (strequal(name, torture_ops[i].name)) {
3145 printf("Running %s\n", name);
3146 if (torture_ops[i].flags & FLAG_MULTIPROC) {
3147 t = create_procs(torture_ops[i].fn, &result);
3150 printf("TEST %s FAILED!\n", name);
3155 if (!torture_ops[i].fn(0)) {
3157 printf("TEST %s FAILED!\n", name);
3161 printf("%s took %g secs\n\n", name, t);
3168 static void usage(void)
3172 printf("Usage: smbtorture //server/share <options> TEST1 TEST2 ...\n");
3174 printf("\t-d debuglevel\n");
3175 printf("\t-U user%%pass\n");
3176 printf("\t-N numprocs\n");
3177 printf("\t-n my_netbios_name\n");
3178 printf("\t-W workgroup\n");
3179 printf("\t-o num_operations\n");
3180 printf("\t-O socket_options\n");
3181 printf("\t-m maximum protocol\n");
3182 printf("\t-L use oplocks\n");
3185 printf("tests are:");
3186 for (i=0;torture_ops[i].name;i++) {
3187 printf(" %s", torture_ops[i].name);
3191 printf("default test is ALL\n");
3200 /****************************************************************************
3202 ****************************************************************************/
3203 int main(int argc,char *argv[])
3208 extern char *optarg;
3211 static pstring servicesf = CONFIGFILE;
3212 BOOL correct = True;
3216 #ifdef HAVE_SETBUFFER
3217 setbuffer(stdout, NULL, 0);
3220 charset_initialise();
3222 codepage_initialise(lp_client_code_page());
3224 codepage_initialise(lp_client_code_page());
3226 lp_load(servicesf,True,False,False);
3233 for(p = argv[1]; *p; p++)
3237 if (strncmp(argv[1], "//", 2)) {
3241 fstrcpy(host, &argv[1][2]);
3242 p = strchr(&host[2],'/');
3247 fstrcpy(share, p+1);
3251 if (*username == 0 && getenv("LOGNAME")) {
3252 pstrcpy(username,getenv("LOGNAME"));
3259 fstrcpy(workgroup, lp_workgroup());
3261 while ((opt = getopt(argc, argv, "hW:U:n:N:O:o:m:Ld:")) != EOF) {
3264 fstrcpy(workgroup,optarg);
3267 max_protocol = interpret_protocol(optarg, max_protocol);
3270 nprocs = atoi(optarg);
3273 numops = atoi(optarg);
3276 DEBUGLEVEL = atoi(optarg);
3285 fstrcpy(myname, optarg);
3288 pstrcpy(username,optarg);
3289 p = strchr(username,'%');
3292 pstrcpy(password, p+1);
3297 printf("Unknown option %c (%d)\n", (char)opt, opt);
3304 p = getpass("Password:");
3306 pstrcpy(password, p);
3311 printf("host=%s share=%s user=%s myname=%s\n",
3312 host, share, username, myname);
3315 correct = run_test("ALL");
3317 for (i=1;i<argc;i++) {
3318 if (!run_test(argv[i])) {