2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 1997-1998
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 static fstring host, workgroup, share, password, username, myname;
26 static int max_protocol = PROTOCOL_NT1;
27 static const char *sockops="TCP_NODELAY";
29 static int port_to_use=0;
30 int torture_numops=100;
31 static int procnum; /* records process count number when forking */
32 static struct cli_state *current_cli;
33 static fstring randomfname;
34 static BOOL use_oplocks;
35 static BOOL use_level_II_oplocks;
36 static const char *client_txt = "client_oplocks.txt";
37 static BOOL use_kerberos;
39 BOOL torture_showall = False;
41 static double create_procs(BOOL (*fn)(int), BOOL *result);
44 static struct timeval tp1,tp2;
46 void start_timer(void)
48 gettimeofday(&tp1,NULL);
51 double end_timer(void)
53 gettimeofday(&tp2,NULL);
54 return((tp2.tv_sec - tp1.tv_sec) +
55 (tp2.tv_usec - tp1.tv_usec)*1.0e-6);
59 /* return a pointer to a anonymous shared memory segment of size "size"
60 which will persist across fork() but will disappear when all processes
63 The memory is not zeroed
65 This function uses system5 shared memory. It takes advantage of a property
66 that the memory is not destroyed if it is attached when the id is removed
68 void *shm_setup(int size)
73 shmid = shmget(IPC_PRIVATE, size, SHM_R | SHM_W);
75 printf("can't get shared memory\n");
78 ret = (void *)shmat(shmid, 0, 0);
79 if (!ret || ret == (void *)-1) {
80 printf("can't attach to shared memory\n");
83 /* the following releases the ipc, but note that this process
84 and all its children will still have access to the memory, its
85 just that the shmid is no longer valid for other shm calls. This
86 means we don't leave behind lots of shm segments after we exit
88 See Stevens "advanced programming in unix env" for details
90 shmctl(shmid, IPC_RMID, 0);
96 static BOOL open_nbt_connection(struct cli_state *c)
98 struct nmb_name called, calling;
103 make_nmb_name(&calling, myname, 0x0);
104 make_nmb_name(&called , host, 0x20);
108 if (!cli_initialise(c)) {
109 printf("Failed initialize cli_struct to connect with %s\n", host);
113 c->port = port_to_use;
115 if (!cli_connect(c, host, &ip)) {
116 printf("Failed to connect with %s\n", host);
120 c->use_kerberos = use_kerberos;
122 c->timeout = 120000; /* set a really long timeout (2 minutes) */
123 if (use_oplocks) c->use_oplocks = True;
124 if (use_level_II_oplocks) c->use_level_II_oplocks = True;
126 if (!cli_session_request(c, &calling, &called)) {
128 * Well, that failed, try *SMBSERVER ...
129 * However, we must reconnect as well ...
131 if (!cli_connect(c, host, &ip)) {
132 printf("Failed to connect with %s\n", host);
136 make_nmb_name(&called, "*SMBSERVER", 0x20);
137 if (!cli_session_request(c, &calling, &called)) {
138 printf("%s rejected the session\n",host);
139 printf("We tried with a called name of %s & %s\n",
149 BOOL torture_open_connection(struct cli_state **c)
156 flags |= CLI_FULL_CONNECTION_USE_KERBEROS;
158 status = cli_full_connection(c, myname,
159 host, NULL, port_to_use,
162 password, flags, Undefined, &retry);
163 if (!NT_STATUS_IS_OK(status)) {
167 if (use_oplocks) (*c)->use_oplocks = True;
168 if (use_level_II_oplocks) (*c)->use_level_II_oplocks = True;
169 (*c)->timeout = 120000; /* set a really long timeout (2 minutes) */
174 BOOL torture_cli_session_setup2(struct cli_state *cli, uint16 *new_vuid)
176 uint16 old_vuid = cli->vuid;
177 fstring old_user_name;
178 size_t passlen = strlen(password);
181 fstrcpy(old_user_name, cli->user_name);
183 ret = cli_session_setup(cli, username, password, passlen, password, passlen, workgroup);
184 *new_vuid = cli->vuid;
185 cli->vuid = old_vuid;
186 fstrcpy(cli->user_name, old_user_name);
191 BOOL torture_close_connection(struct cli_state *c)
195 printf("tdis failed (%s)\n", cli_errstr(c));
205 /* check if the server produced the expected error code */
206 static BOOL check_error(int line, struct cli_state *c,
207 uint8 eclass, uint32 ecode, NTSTATUS nterr)
209 if (cli_is_dos_error(c)) {
213 /* Check DOS error */
215 cli_dos_error(c, &class, &num);
217 if (eclass != class || ecode != num) {
218 printf("unexpected error code class=%d code=%d\n",
219 (int)class, (int)num);
220 printf(" expected %d/%d %s (line=%d)\n",
221 (int)eclass, (int)ecode, nt_errstr(nterr), line);
230 status = cli_nt_error(c);
232 if (NT_STATUS_V(nterr) != NT_STATUS_V(status)) {
233 printf("unexpected error code %s\n", nt_errstr(status));
234 printf(" expected %s (line=%d)\n", nt_errstr(nterr), line);
243 static BOOL wait_lock(struct cli_state *c, int fnum, uint32 offset, uint32 len)
245 while (!cli_lock(c, fnum, offset, len, -1, WRITE_LOCK)) {
246 if (!check_error(__LINE__, c, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False;
252 static BOOL rw_torture(struct cli_state *c)
254 const char *lockfname = "\\torture.lck";
258 pid_t pid2, pid = getpid();
263 fnum2 = cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
266 fnum2 = cli_open(c, lockfname, O_RDWR, DENY_NONE);
268 printf("open of %s failed (%s)\n", lockfname, cli_errstr(c));
273 for (i=0;i<torture_numops;i++) {
274 unsigned n = (unsigned)sys_random()%10;
276 printf("%d\r", i); fflush(stdout);
278 slprintf(fname, sizeof(fstring) - 1, "\\torture.%u", n);
280 if (!wait_lock(c, fnum2, n*sizeof(int), sizeof(int))) {
284 fnum = cli_open(c, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_ALL);
286 printf("open failed (%s)\n", cli_errstr(c));
291 if (cli_write(c, fnum, 0, (char *)&pid, 0, sizeof(pid)) != sizeof(pid)) {
292 printf("write failed (%s)\n", cli_errstr(c));
297 if (cli_write(c, fnum, 0, (char *)buf,
298 sizeof(pid)+(j*sizeof(buf)),
299 sizeof(buf)) != sizeof(buf)) {
300 printf("write failed (%s)\n", cli_errstr(c));
307 if (cli_read(c, fnum, (char *)&pid2, 0, sizeof(pid)) != sizeof(pid)) {
308 printf("read failed (%s)\n", cli_errstr(c));
313 printf("data corruption!\n");
317 if (!cli_close(c, fnum)) {
318 printf("close failed (%s)\n", cli_errstr(c));
322 if (!cli_unlink(c, fname)) {
323 printf("unlink failed (%s)\n", cli_errstr(c));
327 if (!cli_unlock(c, fnum2, n*sizeof(int), sizeof(int))) {
328 printf("unlock failed (%s)\n", cli_errstr(c));
334 cli_unlink(c, lockfname);
341 static BOOL run_torture(int dummy)
343 struct cli_state *cli;
348 cli_sockopt(cli, sockops);
350 ret = rw_torture(cli);
352 if (!torture_close_connection(cli)) {
359 static BOOL rw_torture3(struct cli_state *c, char *lockfname)
366 unsigned countprev = 0;
371 for (i = 0; i < sizeof(buf); i += sizeof(uint32))
373 SIVAL(buf, i, sys_random());
378 fnum = cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
381 printf("first open read/write of %s failed (%s)\n",
382 lockfname, cli_errstr(c));
388 for (i = 0; i < 500 && fnum == -1; i++)
390 fnum = cli_open(c, lockfname, O_RDONLY,
395 printf("second open read-only of %s failed (%s)\n",
396 lockfname, cli_errstr(c));
402 for (count = 0; count < sizeof(buf); count += sent)
404 if (count >= countprev) {
405 printf("%d %8d\r", i, count);
408 countprev += (sizeof(buf) / 20);
413 sent = ((unsigned)sys_random()%(20))+ 1;
414 if (sent > sizeof(buf) - count)
416 sent = sizeof(buf) - count;
419 if (cli_write(c, fnum, 0, buf+count, count, (size_t)sent) != sent) {
420 printf("write failed (%s)\n", cli_errstr(c));
426 sent = cli_read(c, fnum, buf_rd+count, count,
430 printf("read failed offset:%d size:%d (%s)\n",
431 count, sizeof(buf)-count,
438 if (memcmp(buf_rd+count, buf+count, sent) != 0)
440 printf("read/write compare failed\n");
441 printf("offset: %d req %d recvd %d\n",
442 count, sizeof(buf)-count, sent);
451 if (!cli_close(c, fnum)) {
452 printf("close failed (%s)\n", cli_errstr(c));
459 static BOOL rw_torture2(struct cli_state *c1, struct cli_state *c2)
461 const char *lockfname = "\\torture2.lck";
466 uchar buf_rd[131072];
470 if (!cli_unlink(c1, lockfname)) {
471 printf("unlink failed (%s) (normal, this file should not exist)\n", cli_errstr(c1));
474 fnum1 = cli_open(c1, lockfname, O_RDWR | O_CREAT | O_EXCL,
477 printf("first open read/write of %s failed (%s)\n",
478 lockfname, cli_errstr(c1));
481 fnum2 = cli_open(c2, lockfname, O_RDONLY,
484 printf("second open read-only of %s failed (%s)\n",
485 lockfname, cli_errstr(c2));
486 cli_close(c1, fnum1);
490 for (i=0;i<torture_numops;i++)
492 size_t buf_size = ((unsigned)sys_random()%(sizeof(buf)-1))+ 1;
494 printf("%d\r", i); fflush(stdout);
497 generate_random_buffer(buf, buf_size, False);
499 if (cli_write(c1, fnum1, 0, buf, 0, buf_size) != buf_size) {
500 printf("write failed (%s)\n", cli_errstr(c1));
505 if ((bytes_read = cli_read(c2, fnum2, buf_rd, 0, buf_size)) != buf_size) {
506 printf("read failed (%s)\n", cli_errstr(c2));
507 printf("read %d, expected %d\n", bytes_read, buf_size);
512 if (memcmp(buf_rd, buf, buf_size) != 0)
514 printf("read/write compare failed\n");
520 if (!cli_close(c2, fnum2)) {
521 printf("close failed (%s)\n", cli_errstr(c2));
524 if (!cli_close(c1, fnum1)) {
525 printf("close failed (%s)\n", cli_errstr(c1));
529 if (!cli_unlink(c1, lockfname)) {
530 printf("unlink failed (%s)\n", cli_errstr(c1));
537 static BOOL run_readwritetest(int dummy)
539 static struct cli_state *cli1, *cli2;
542 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
545 cli_sockopt(cli1, sockops);
546 cli_sockopt(cli2, sockops);
548 printf("starting readwritetest\n");
550 test1 = rw_torture2(cli1, cli2);
551 printf("Passed readwritetest v1: %s\n", BOOLSTR(test1));
554 test2 = rw_torture2(cli1, cli1);
555 printf("Passed readwritetest v2: %s\n", BOOLSTR(test2));
558 if (!torture_close_connection(cli1)) {
562 if (!torture_close_connection(cli2)) {
566 return (test1 && test2);
569 static BOOL run_readwritemulti(int dummy)
571 struct cli_state *cli;
576 cli_sockopt(cli, sockops);
578 printf("run_readwritemulti: fname %s\n", randomfname);
579 test = rw_torture3(cli, randomfname);
581 if (!torture_close_connection(cli)) {
588 static BOOL run_readwritelarge(int dummy)
590 static struct cli_state *cli1;
592 const char *lockfname = "\\large.dat";
597 if (!torture_open_connection(&cli1)) {
600 cli_sockopt(cli1, sockops);
601 memset(buf,'\0',sizeof(buf));
603 cli1->max_xmit = 128*1024;
605 printf("starting readwritelarge\n");
607 cli_unlink(cli1, lockfname);
609 fnum1 = cli_open(cli1, lockfname, O_RDWR | O_CREAT | O_EXCL, DENY_NONE);
611 printf("open read/write of %s failed (%s)\n", lockfname, cli_errstr(cli1));
615 cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf));
617 if (!cli_qfileinfo(cli1, fnum1, NULL, &fsize, NULL, NULL, NULL, NULL, NULL)) {
618 printf("qfileinfo failed (%s)\n", cli_errstr(cli1));
622 if (fsize == sizeof(buf))
623 printf("readwritelarge test 1 succeeded (size = %x)\n", fsize);
625 printf("readwritelarge test 1 failed (size = %x)\n", fsize);
629 if (!cli_close(cli1, fnum1)) {
630 printf("close failed (%s)\n", cli_errstr(cli1));
634 if (!cli_unlink(cli1, lockfname)) {
635 printf("unlink failed (%s)\n", cli_errstr(cli1));
639 fnum1 = cli_open(cli1, lockfname, O_RDWR | O_CREAT | O_EXCL, DENY_NONE);
641 printf("open read/write of %s failed (%s)\n", lockfname, cli_errstr(cli1));
645 cli1->max_xmit = 4*1024;
647 cli_smbwrite(cli1, fnum1, buf, 0, sizeof(buf));
649 if (!cli_qfileinfo(cli1, fnum1, NULL, &fsize, NULL, NULL, NULL, NULL, NULL)) {
650 printf("qfileinfo failed (%s)\n", cli_errstr(cli1));
654 if (fsize == sizeof(buf))
655 printf("readwritelarge test 2 succeeded (size = %x)\n", fsize);
657 printf("readwritelarge test 2 failed (size = %x)\n", fsize);
662 /* ToDo - set allocation. JRA */
663 if(!cli_set_allocation_size(cli1, fnum1, 0)) {
664 printf("set allocation size to zero failed (%s)\n", cli_errstr(&cli1));
667 if (!cli_qfileinfo(cli1, fnum1, NULL, &fsize, NULL, NULL, NULL, NULL, NULL)) {
668 printf("qfileinfo failed (%s)\n", cli_errstr(cli1));
672 printf("readwritelarge test 3 (truncate test) succeeded (size = %x)\n", fsize);
675 if (!cli_close(cli1, fnum1)) {
676 printf("close failed (%s)\n", cli_errstr(cli1));
680 if (!torture_close_connection(cli1)) {
689 #define ival(s) strtol(s, NULL, 0)
691 /* run a test that simulates an approximate netbench client load */
692 static BOOL run_netbench(int client)
694 struct cli_state *cli;
700 const char *params[20];
707 cli_sockopt(cli, sockops);
711 slprintf(cname,sizeof(fname), "client%d", client);
713 f = fopen(client_txt, "r");
720 while (fgets(line, sizeof(line)-1, f)) {
723 line[strlen(line)-1] = 0;
725 /* printf("[%d] %s\n", line_count, line); */
727 all_string_sub(line,"client1", cname, sizeof(line));
729 /* parse the command parameters */
730 params[0] = strtok(line," ");
732 while (params[i]) params[++i] = strtok(NULL," ");
738 if (!strncmp(params[0],"SMB", 3)) {
739 printf("ERROR: You are using a dbench 1 load file\n");
743 if (!strcmp(params[0],"NTCreateX")) {
744 nb_createx(params[1], ival(params[2]), ival(params[3]),
746 } else if (!strcmp(params[0],"Close")) {
747 nb_close(ival(params[1]));
748 } else if (!strcmp(params[0],"Rename")) {
749 nb_rename(params[1], params[2]);
750 } else if (!strcmp(params[0],"Unlink")) {
751 nb_unlink(params[1]);
752 } else if (!strcmp(params[0],"Deltree")) {
753 nb_deltree(params[1]);
754 } else if (!strcmp(params[0],"Rmdir")) {
756 } else if (!strcmp(params[0],"QUERY_PATH_INFORMATION")) {
757 nb_qpathinfo(params[1]);
758 } else if (!strcmp(params[0],"QUERY_FILE_INFORMATION")) {
759 nb_qfileinfo(ival(params[1]));
760 } else if (!strcmp(params[0],"QUERY_FS_INFORMATION")) {
761 nb_qfsinfo(ival(params[1]));
762 } else if (!strcmp(params[0],"FIND_FIRST")) {
763 nb_findfirst(params[1]);
764 } else if (!strcmp(params[0],"WriteX")) {
765 nb_writex(ival(params[1]),
766 ival(params[2]), ival(params[3]), ival(params[4]));
767 } else if (!strcmp(params[0],"ReadX")) {
768 nb_readx(ival(params[1]),
769 ival(params[2]), ival(params[3]), ival(params[4]));
770 } else if (!strcmp(params[0],"Flush")) {
771 nb_flush(ival(params[1]));
773 printf("Unknown operation %s\n", params[0]);
781 if (!torture_close_connection(cli)) {
789 /* run a test that simulates an approximate netbench client load */
790 static BOOL run_nbench(int dummy)
799 signal(SIGALRM, nb_alarm);
801 t = create_procs(run_netbench, &correct);
804 printf("\nThroughput %g MB/sec\n",
805 1.0e-6 * nbio_total() / t);
811 This test checks for two things:
813 1) correct support for retaining locks over a close (ie. the server
814 must not use posix semantics)
815 2) support for lock timeouts
817 static BOOL run_locktest1(int dummy)
819 struct cli_state *cli1, *cli2;
820 const char *fname = "\\lockt1.lck";
821 int fnum1, fnum2, fnum3;
823 unsigned lock_timeout;
825 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
828 cli_sockopt(cli1, sockops);
829 cli_sockopt(cli2, sockops);
831 printf("starting locktest1\n");
833 cli_unlink(cli1, fname);
835 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
837 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
840 fnum2 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
842 printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli1));
845 fnum3 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
847 printf("open3 of %s failed (%s)\n", fname, cli_errstr(cli2));
851 if (!cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK)) {
852 printf("lock1 failed (%s)\n", cli_errstr(cli1));
857 if (cli_lock(cli2, fnum3, 0, 4, 0, WRITE_LOCK)) {
858 printf("lock2 succeeded! This is a locking bug\n");
861 if (!check_error(__LINE__, cli2, ERRDOS, ERRlock,
862 NT_STATUS_LOCK_NOT_GRANTED)) return False;
866 lock_timeout = (1 + (random() % 20));
867 printf("Testing lock timeout with timeout=%u\n", lock_timeout);
869 if (cli_lock(cli2, fnum3, 0, 4, lock_timeout * 500, WRITE_LOCK)) {
870 printf("lock3 succeeded! This is a locking bug\n");
873 if (!check_error(__LINE__, cli2, ERRDOS, ERRlock,
874 NT_STATUS_FILE_LOCK_CONFLICT)) return False;
878 if (ABS(t2 - t1) < lock_timeout-1) {
879 printf("error: This server appears not to support timed lock requests\n");
882 printf("server slept for %u seconds for a %u second timeout\n",
883 (unsigned int)(t2-t1), lock_timeout);
885 if (!cli_close(cli1, fnum2)) {
886 printf("close1 failed (%s)\n", cli_errstr(cli1));
890 if (cli_lock(cli2, fnum3, 0, 4, 0, WRITE_LOCK)) {
891 printf("lock4 succeeded! This is a locking bug\n");
894 if (!check_error(__LINE__, cli2, ERRDOS, ERRlock,
895 NT_STATUS_FILE_LOCK_CONFLICT)) return False;
898 if (!cli_close(cli1, fnum1)) {
899 printf("close2 failed (%s)\n", cli_errstr(cli1));
903 if (!cli_close(cli2, fnum3)) {
904 printf("close3 failed (%s)\n", cli_errstr(cli2));
908 if (!cli_unlink(cli1, fname)) {
909 printf("unlink failed (%s)\n", cli_errstr(cli1));
914 if (!torture_close_connection(cli1)) {
918 if (!torture_close_connection(cli2)) {
922 printf("Passed locktest1\n");
927 this checks to see if a secondary tconx can use open files from an
930 static BOOL run_tcon_test(int dummy)
932 static struct cli_state *cli;
933 const char *fname = "\\tcontest.tmp";
935 uint16 cnum1, cnum2, cnum3;
940 if (!torture_open_connection(&cli)) {
943 cli_sockopt(cli, sockops);
945 printf("starting tcontest\n");
947 cli_unlink(cli, fname);
949 fnum1 = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
951 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
958 if (cli_write(cli, fnum1, 0, buf, 130, 4) != 4) {
959 printf("initial write failed (%s)", cli_errstr(cli));
963 if (!cli_send_tconX(cli, share, "?????",
964 password, strlen(password)+1)) {
965 printf("%s refused 2nd tree connect (%s)\n", host,
972 cnum3 = MAX(cnum1, cnum2) + 1; /* any invalid number */
973 vuid2 = cli->vuid + 1;
975 /* try a write with the wrong tid */
978 if (cli_write(cli, fnum1, 0, buf, 130, 4) == 4) {
979 printf("* server allows write with wrong TID\n");
982 printf("server fails write with wrong TID : %s\n", cli_errstr(cli));
986 /* try a write with an invalid tid */
989 if (cli_write(cli, fnum1, 0, buf, 130, 4) == 4) {
990 printf("* server allows write with invalid TID\n");
993 printf("server fails write with invalid TID : %s\n", cli_errstr(cli));
996 /* try a write with an invalid vuid */
1000 if (cli_write(cli, fnum1, 0, buf, 130, 4) == 4) {
1001 printf("* server allows write with invalid VUID\n");
1004 printf("server fails write with invalid VUID : %s\n", cli_errstr(cli));
1010 if (!cli_close(cli, fnum1)) {
1011 printf("close failed (%s)\n", cli_errstr(cli));
1017 if (!cli_tdis(cli)) {
1018 printf("secondary tdis failed (%s)\n", cli_errstr(cli));
1024 if (!torture_close_connection(cli)) {
1033 checks for old style tcon support
1035 static BOOL run_tcon2_test(int dummy)
1037 static struct cli_state *cli;
1038 uint16 cnum, max_xmit;
1042 if (!torture_open_connection(&cli)) {
1045 cli_sockopt(cli, sockops);
1047 printf("starting tcon2 test\n");
1049 asprintf(&service, "\\\\%s\\%s", host, share);
1051 status = cli_raw_tcon(cli, service, password, "?????", &max_xmit, &cnum);
1053 if (!NT_STATUS_IS_OK(status)) {
1054 printf("tcon2 failed : %s\n", cli_errstr(cli));
1056 printf("tcon OK : max_xmit=%d cnum=%d tid=%d\n",
1057 (int)max_xmit, (int)cnum, SVAL(cli->inbuf, smb_tid));
1060 if (!torture_close_connection(cli)) {
1064 printf("Passed tcon2 test\n");
1068 static BOOL tcon_devtest(struct cli_state *cli,
1069 const char *myshare, const char *devtype,
1070 const char *return_devtype,
1071 NTSTATUS expected_error)
1076 status = cli_send_tconX(cli, myshare, devtype,
1077 password, strlen(password)+1);
1079 if (NT_STATUS_IS_OK(expected_error)) {
1081 if (strcmp(cli->dev, return_devtype) == 0) {
1084 printf("tconX to share %s with type %s "
1085 "succeeded but returned the wrong "
1086 "device type (got [%s] but should have got [%s])\n",
1087 myshare, devtype, cli->dev, return_devtype);
1091 printf("tconX to share %s with type %s "
1092 "should have succeeded but failed\n",
1099 printf("tconx to share %s with type %s "
1100 "should have failed but succeeded\n",
1104 if (NT_STATUS_EQUAL(cli_nt_error(cli),
1108 printf("Returned unexpected error\n");
1117 checks for correct tconX support
1119 static BOOL run_tcon_devtype_test(int dummy)
1121 static struct cli_state *cli1 = NULL;
1127 status = cli_full_connection(&cli1, myname,
1128 host, NULL, port_to_use,
1130 username, workgroup,
1131 password, flags, Undefined, &retry);
1133 if (!NT_STATUS_IS_OK(status)) {
1134 printf("could not open connection\n");
1138 if (!tcon_devtest(cli1, "IPC$", "A:", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1141 if (!tcon_devtest(cli1, "IPC$", "?????", "IPC", NT_STATUS_OK))
1144 if (!tcon_devtest(cli1, "IPC$", "LPT:", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1147 if (!tcon_devtest(cli1, "IPC$", "IPC", "IPC", NT_STATUS_OK))
1150 if (!tcon_devtest(cli1, "IPC$", "FOOBA", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1153 if (!tcon_devtest(cli1, share, "A:", "A:", NT_STATUS_OK))
1156 if (!tcon_devtest(cli1, share, "?????", "A:", NT_STATUS_OK))
1159 if (!tcon_devtest(cli1, share, "LPT:", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1162 if (!tcon_devtest(cli1, share, "IPC", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1165 if (!tcon_devtest(cli1, share, "FOOBA", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1171 printf("Passed tcondevtest\n");
1178 This test checks that
1180 1) the server supports multiple locking contexts on the one SMB
1181 connection, distinguished by PID.
1183 2) the server correctly fails overlapping locks made by the same PID (this
1184 goes against POSIX behaviour, which is why it is tricky to implement)
1186 3) the server denies unlock requests by an incorrect client PID
1188 static BOOL run_locktest2(int dummy)
1190 static struct cli_state *cli;
1191 const char *fname = "\\lockt2.lck";
1192 int fnum1, fnum2, fnum3;
1193 BOOL correct = True;
1195 if (!torture_open_connection(&cli)) {
1199 cli_sockopt(cli, sockops);
1201 printf("starting locktest2\n");
1203 cli_unlink(cli, fname);
1207 fnum1 = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1209 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
1213 fnum2 = cli_open(cli, fname, O_RDWR, DENY_NONE);
1215 printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli));
1221 fnum3 = cli_open(cli, fname, O_RDWR, DENY_NONE);
1223 printf("open3 of %s failed (%s)\n", fname, cli_errstr(cli));
1229 if (!cli_lock(cli, fnum1, 0, 4, 0, WRITE_LOCK)) {
1230 printf("lock1 failed (%s)\n", cli_errstr(cli));
1234 if (cli_lock(cli, fnum1, 0, 4, 0, WRITE_LOCK)) {
1235 printf("WRITE lock1 succeeded! This is a locking bug\n");
1238 if (!check_error(__LINE__, cli, ERRDOS, ERRlock,
1239 NT_STATUS_LOCK_NOT_GRANTED)) return False;
1242 if (cli_lock(cli, fnum2, 0, 4, 0, WRITE_LOCK)) {
1243 printf("WRITE lock2 succeeded! This is a locking bug\n");
1246 if (!check_error(__LINE__, cli, ERRDOS, ERRlock,
1247 NT_STATUS_LOCK_NOT_GRANTED)) return False;
1250 if (cli_lock(cli, fnum2, 0, 4, 0, READ_LOCK)) {
1251 printf("READ lock2 succeeded! This is a locking bug\n");
1254 if (!check_error(__LINE__, cli, ERRDOS, ERRlock,
1255 NT_STATUS_FILE_LOCK_CONFLICT)) return False;
1258 if (!cli_lock(cli, fnum1, 100, 4, 0, WRITE_LOCK)) {
1259 printf("lock at 100 failed (%s)\n", cli_errstr(cli));
1262 if (cli_unlock(cli, fnum1, 100, 4)) {
1263 printf("unlock at 100 succeeded! This is a locking bug\n");
1267 if (cli_unlock(cli, fnum1, 0, 4)) {
1268 printf("unlock1 succeeded! This is a locking bug\n");
1271 if (!check_error(__LINE__, cli,
1273 NT_STATUS_RANGE_NOT_LOCKED)) return False;
1276 if (cli_unlock(cli, fnum1, 0, 8)) {
1277 printf("unlock2 succeeded! This is a locking bug\n");
1280 if (!check_error(__LINE__, cli,
1282 NT_STATUS_RANGE_NOT_LOCKED)) return False;
1285 if (cli_lock(cli, fnum3, 0, 4, 0, WRITE_LOCK)) {
1286 printf("lock3 succeeded! This is a locking bug\n");
1289 if (!check_error(__LINE__, cli, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False;
1294 if (!cli_close(cli, fnum1)) {
1295 printf("close1 failed (%s)\n", cli_errstr(cli));
1299 if (!cli_close(cli, fnum2)) {
1300 printf("close2 failed (%s)\n", cli_errstr(cli));
1304 if (!cli_close(cli, fnum3)) {
1305 printf("close3 failed (%s)\n", cli_errstr(cli));
1309 if (!torture_close_connection(cli)) {
1313 printf("locktest2 finished\n");
1320 This test checks that
1322 1) the server supports the full offset range in lock requests
1324 static BOOL run_locktest3(int dummy)
1326 static struct cli_state *cli1, *cli2;
1327 const char *fname = "\\lockt3.lck";
1328 int fnum1, fnum2, i;
1330 BOOL correct = True;
1332 #define NEXT_OFFSET offset += (~(uint32)0) / torture_numops
1334 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
1337 cli_sockopt(cli1, sockops);
1338 cli_sockopt(cli2, sockops);
1340 printf("starting locktest3\n");
1342 cli_unlink(cli1, fname);
1344 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1346 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
1349 fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
1351 printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli2));
1355 for (offset=i=0;i<torture_numops;i++) {
1357 if (!cli_lock(cli1, fnum1, offset-1, 1, 0, WRITE_LOCK)) {
1358 printf("lock1 %d failed (%s)\n",
1364 if (!cli_lock(cli2, fnum2, offset-2, 1, 0, WRITE_LOCK)) {
1365 printf("lock2 %d failed (%s)\n",
1372 for (offset=i=0;i<torture_numops;i++) {
1375 if (cli_lock(cli1, fnum1, offset-2, 1, 0, WRITE_LOCK)) {
1376 printf("error: lock1 %d succeeded!\n", i);
1380 if (cli_lock(cli2, fnum2, offset-1, 1, 0, WRITE_LOCK)) {
1381 printf("error: lock2 %d succeeded!\n", i);
1385 if (cli_lock(cli1, fnum1, offset-1, 1, 0, WRITE_LOCK)) {
1386 printf("error: lock3 %d succeeded!\n", i);
1390 if (cli_lock(cli2, fnum2, offset-2, 1, 0, WRITE_LOCK)) {
1391 printf("error: lock4 %d succeeded!\n", i);
1396 for (offset=i=0;i<torture_numops;i++) {
1399 if (!cli_unlock(cli1, fnum1, offset-1, 1)) {
1400 printf("unlock1 %d failed (%s)\n",
1406 if (!cli_unlock(cli2, fnum2, offset-2, 1)) {
1407 printf("unlock2 %d failed (%s)\n",
1414 if (!cli_close(cli1, fnum1)) {
1415 printf("close1 failed (%s)\n", cli_errstr(cli1));
1419 if (!cli_close(cli2, fnum2)) {
1420 printf("close2 failed (%s)\n", cli_errstr(cli2));
1424 if (!cli_unlink(cli1, fname)) {
1425 printf("unlink failed (%s)\n", cli_errstr(cli1));
1429 if (!torture_close_connection(cli1)) {
1433 if (!torture_close_connection(cli2)) {
1437 printf("finished locktest3\n");
1442 #define EXPECTED(ret, v) if ((ret) != (v)) { \
1443 printf("** "); correct = False; \
1447 looks at overlapping locks
1449 static BOOL run_locktest4(int dummy)
1451 static struct cli_state *cli1, *cli2;
1452 const char *fname = "\\lockt4.lck";
1453 int fnum1, fnum2, f;
1456 BOOL correct = True;
1458 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
1462 cli_sockopt(cli1, sockops);
1463 cli_sockopt(cli2, sockops);
1465 printf("starting locktest4\n");
1467 cli_unlink(cli1, fname);
1469 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1470 fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
1472 memset(buf, 0, sizeof(buf));
1474 if (cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
1475 printf("Failed to create file\n");
1480 ret = cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK) &&
1481 cli_lock(cli1, fnum1, 2, 4, 0, WRITE_LOCK);
1482 EXPECTED(ret, False);
1483 printf("the same process %s set overlapping write locks\n", ret?"can":"cannot");
1485 ret = cli_lock(cli1, fnum1, 10, 4, 0, READ_LOCK) &&
1486 cli_lock(cli1, fnum1, 12, 4, 0, READ_LOCK);
1487 EXPECTED(ret, True);
1488 printf("the same process %s set overlapping read locks\n", ret?"can":"cannot");
1490 ret = cli_lock(cli1, fnum1, 20, 4, 0, WRITE_LOCK) &&
1491 cli_lock(cli2, fnum2, 22, 4, 0, WRITE_LOCK);
1492 EXPECTED(ret, False);
1493 printf("a different connection %s set overlapping write locks\n", ret?"can":"cannot");
1495 ret = cli_lock(cli1, fnum1, 30, 4, 0, READ_LOCK) &&
1496 cli_lock(cli2, fnum2, 32, 4, 0, READ_LOCK);
1497 EXPECTED(ret, True);
1498 printf("a different connection %s set overlapping read locks\n", ret?"can":"cannot");
1500 ret = (cli_setpid(cli1, 1), cli_lock(cli1, fnum1, 40, 4, 0, WRITE_LOCK)) &&
1501 (cli_setpid(cli1, 2), cli_lock(cli1, fnum1, 42, 4, 0, WRITE_LOCK));
1502 EXPECTED(ret, False);
1503 printf("a different pid %s set overlapping write locks\n", ret?"can":"cannot");
1505 ret = (cli_setpid(cli1, 1), cli_lock(cli1, fnum1, 50, 4, 0, READ_LOCK)) &&
1506 (cli_setpid(cli1, 2), cli_lock(cli1, fnum1, 52, 4, 0, READ_LOCK));
1507 EXPECTED(ret, True);
1508 printf("a different pid %s set overlapping read locks\n", ret?"can":"cannot");
1510 ret = cli_lock(cli1, fnum1, 60, 4, 0, READ_LOCK) &&
1511 cli_lock(cli1, fnum1, 60, 4, 0, READ_LOCK);
1512 EXPECTED(ret, True);
1513 printf("the same process %s set the same read lock twice\n", ret?"can":"cannot");
1515 ret = cli_lock(cli1, fnum1, 70, 4, 0, WRITE_LOCK) &&
1516 cli_lock(cli1, fnum1, 70, 4, 0, WRITE_LOCK);
1517 EXPECTED(ret, False);
1518 printf("the same process %s set the same write lock twice\n", ret?"can":"cannot");
1520 ret = cli_lock(cli1, fnum1, 80, 4, 0, READ_LOCK) &&
1521 cli_lock(cli1, fnum1, 80, 4, 0, WRITE_LOCK);
1522 EXPECTED(ret, False);
1523 printf("the same process %s overlay a read lock with a write lock\n", ret?"can":"cannot");
1525 ret = cli_lock(cli1, fnum1, 90, 4, 0, WRITE_LOCK) &&
1526 cli_lock(cli1, fnum1, 90, 4, 0, READ_LOCK);
1527 EXPECTED(ret, True);
1528 printf("the same process %s overlay a write lock with a read lock\n", ret?"can":"cannot");
1530 ret = (cli_setpid(cli1, 1), cli_lock(cli1, fnum1, 100, 4, 0, WRITE_LOCK)) &&
1531 (cli_setpid(cli1, 2), cli_lock(cli1, fnum1, 100, 4, 0, READ_LOCK));
1532 EXPECTED(ret, False);
1533 printf("a different pid %s overlay a write lock with a read lock\n", ret?"can":"cannot");
1535 ret = cli_lock(cli1, fnum1, 110, 4, 0, READ_LOCK) &&
1536 cli_lock(cli1, fnum1, 112, 4, 0, READ_LOCK) &&
1537 cli_unlock(cli1, fnum1, 110, 6);
1538 EXPECTED(ret, False);
1539 printf("the same process %s coalesce read locks\n", ret?"can":"cannot");
1542 ret = cli_lock(cli1, fnum1, 120, 4, 0, WRITE_LOCK) &&
1543 (cli_read(cli2, fnum2, buf, 120, 4) == 4);
1544 EXPECTED(ret, False);
1545 printf("this server %s strict write locking\n", ret?"doesn't do":"does");
1547 ret = cli_lock(cli1, fnum1, 130, 4, 0, READ_LOCK) &&
1548 (cli_write(cli2, fnum2, 0, buf, 130, 4) == 4);
1549 EXPECTED(ret, False);
1550 printf("this server %s strict read locking\n", ret?"doesn't do":"does");
1553 ret = cli_lock(cli1, fnum1, 140, 4, 0, READ_LOCK) &&
1554 cli_lock(cli1, fnum1, 140, 4, 0, READ_LOCK) &&
1555 cli_unlock(cli1, fnum1, 140, 4) &&
1556 cli_unlock(cli1, fnum1, 140, 4);
1557 EXPECTED(ret, True);
1558 printf("this server %s do recursive read locking\n", ret?"does":"doesn't");
1561 ret = cli_lock(cli1, fnum1, 150, 4, 0, WRITE_LOCK) &&
1562 cli_lock(cli1, fnum1, 150, 4, 0, READ_LOCK) &&
1563 cli_unlock(cli1, fnum1, 150, 4) &&
1564 (cli_read(cli2, fnum2, buf, 150, 4) == 4) &&
1565 !(cli_write(cli2, fnum2, 0, buf, 150, 4) == 4) &&
1566 cli_unlock(cli1, fnum1, 150, 4);
1567 EXPECTED(ret, True);
1568 printf("this server %s do recursive lock overlays\n", ret?"does":"doesn't");
1570 ret = cli_lock(cli1, fnum1, 160, 4, 0, READ_LOCK) &&
1571 cli_unlock(cli1, fnum1, 160, 4) &&
1572 (cli_write(cli2, fnum2, 0, buf, 160, 4) == 4) &&
1573 (cli_read(cli2, fnum2, buf, 160, 4) == 4);
1574 EXPECTED(ret, True);
1575 printf("the same process %s remove a read lock using write locking\n", ret?"can":"cannot");
1577 ret = cli_lock(cli1, fnum1, 170, 4, 0, WRITE_LOCK) &&
1578 cli_unlock(cli1, fnum1, 170, 4) &&
1579 (cli_write(cli2, fnum2, 0, buf, 170, 4) == 4) &&
1580 (cli_read(cli2, fnum2, buf, 170, 4) == 4);
1581 EXPECTED(ret, True);
1582 printf("the same process %s remove a write lock using read locking\n", ret?"can":"cannot");
1584 ret = cli_lock(cli1, fnum1, 190, 4, 0, WRITE_LOCK) &&
1585 cli_lock(cli1, fnum1, 190, 4, 0, READ_LOCK) &&
1586 cli_unlock(cli1, fnum1, 190, 4) &&
1587 !(cli_write(cli2, fnum2, 0, buf, 190, 4) == 4) &&
1588 (cli_read(cli2, fnum2, buf, 190, 4) == 4);
1589 EXPECTED(ret, True);
1590 printf("the same process %s remove the first lock first\n", ret?"does":"doesn't");
1592 cli_close(cli1, fnum1);
1593 cli_close(cli2, fnum2);
1594 fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1595 f = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1596 ret = cli_lock(cli1, fnum1, 0, 8, 0, READ_LOCK) &&
1597 cli_lock(cli1, f, 0, 1, 0, READ_LOCK) &&
1598 cli_close(cli1, fnum1) &&
1599 ((fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE)) != -1) &&
1600 cli_lock(cli1, fnum1, 7, 1, 0, WRITE_LOCK);
1602 cli_close(cli1, fnum1);
1603 EXPECTED(ret, True);
1604 printf("the server %s have the NT byte range lock bug\n", !ret?"does":"doesn't");
1607 cli_close(cli1, fnum1);
1608 cli_close(cli2, fnum2);
1609 cli_unlink(cli1, fname);
1610 torture_close_connection(cli1);
1611 torture_close_connection(cli2);
1613 printf("finished locktest4\n");
1618 looks at lock upgrade/downgrade.
1620 static BOOL run_locktest5(int dummy)
1622 static struct cli_state *cli1, *cli2;
1623 const char *fname = "\\lockt5.lck";
1624 int fnum1, fnum2, fnum3;
1627 BOOL correct = True;
1629 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
1633 cli_sockopt(cli1, sockops);
1634 cli_sockopt(cli2, sockops);
1636 printf("starting locktest5\n");
1638 cli_unlink(cli1, fname);
1640 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1641 fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
1642 fnum3 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1644 memset(buf, 0, sizeof(buf));
1646 if (cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
1647 printf("Failed to create file\n");
1652 /* Check for NT bug... */
1653 ret = cli_lock(cli1, fnum1, 0, 8, 0, READ_LOCK) &&
1654 cli_lock(cli1, fnum3, 0, 1, 0, READ_LOCK);
1655 cli_close(cli1, fnum1);
1656 fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1657 ret = cli_lock(cli1, fnum1, 7, 1, 0, WRITE_LOCK);
1658 EXPECTED(ret, True);
1659 printf("this server %s the NT locking bug\n", ret ? "doesn't have" : "has");
1660 cli_close(cli1, fnum1);
1661 fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1662 cli_unlock(cli1, fnum3, 0, 1);
1664 ret = cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK) &&
1665 cli_lock(cli1, fnum1, 1, 1, 0, READ_LOCK);
1666 EXPECTED(ret, True);
1667 printf("the same process %s overlay a write with a read lock\n", ret?"can":"cannot");
1669 ret = cli_lock(cli2, fnum2, 0, 4, 0, READ_LOCK);
1670 EXPECTED(ret, False);
1672 printf("a different processs %s get a read lock on the first process lock stack\n", ret?"can":"cannot");
1674 /* Unlock the process 2 lock. */
1675 cli_unlock(cli2, fnum2, 0, 4);
1677 ret = cli_lock(cli1, fnum3, 0, 4, 0, READ_LOCK);
1678 EXPECTED(ret, False);
1680 printf("the same processs on a different fnum %s get a read lock\n", ret?"can":"cannot");
1682 /* Unlock the process 1 fnum3 lock. */
1683 cli_unlock(cli1, fnum3, 0, 4);
1685 /* Stack 2 more locks here. */
1686 ret = cli_lock(cli1, fnum1, 0, 4, 0, READ_LOCK) &&
1687 cli_lock(cli1, fnum1, 0, 4, 0, READ_LOCK);
1689 EXPECTED(ret, True);
1690 printf("the same process %s stack read locks\n", ret?"can":"cannot");
1692 /* Unlock the first process lock, then check this was the WRITE lock that was
1695 ret = cli_unlock(cli1, fnum1, 0, 4) &&
1696 cli_lock(cli2, fnum2, 0, 4, 0, READ_LOCK);
1698 EXPECTED(ret, True);
1699 printf("the first unlock removes the %s lock\n", ret?"WRITE":"READ");
1701 /* Unlock the process 2 lock. */
1702 cli_unlock(cli2, fnum2, 0, 4);
1704 /* We should have 3 stacked locks here. Ensure we need to do 3 unlocks. */
1706 ret = cli_unlock(cli1, fnum1, 1, 1) &&
1707 cli_unlock(cli1, fnum1, 0, 4) &&
1708 cli_unlock(cli1, fnum1, 0, 4);
1710 EXPECTED(ret, True);
1711 printf("the same process %s unlock the stack of 4 locks\n", ret?"can":"cannot");
1713 /* Ensure the next unlock fails. */
1714 ret = cli_unlock(cli1, fnum1, 0, 4);
1715 EXPECTED(ret, False);
1716 printf("the same process %s count the lock stack\n", !ret?"can":"cannot");
1718 /* Ensure connection 2 can get a write lock. */
1719 ret = cli_lock(cli2, fnum2, 0, 4, 0, WRITE_LOCK);
1720 EXPECTED(ret, True);
1722 printf("a different processs %s get a write lock on the unlocked stack\n", ret?"can":"cannot");
1726 cli_close(cli1, fnum1);
1727 cli_close(cli2, fnum2);
1728 cli_unlink(cli1, fname);
1729 if (!torture_close_connection(cli1)) {
1732 if (!torture_close_connection(cli2)) {
1736 printf("finished locktest5\n");
1742 tries the unusual lockingX locktype bits
1744 static BOOL run_locktest6(int dummy)
1746 static struct cli_state *cli;
1747 const char *fname[1] = { "\\lock6.txt" };
1752 if (!torture_open_connection(&cli)) {
1756 cli_sockopt(cli, sockops);
1758 printf("starting locktest6\n");
1761 printf("Testing %s\n", fname[i]);
1763 cli_unlink(cli, fname[i]);
1765 fnum = cli_open(cli, fname[i], O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1766 status = cli_locktype(cli, fnum, 0, 8, 0, LOCKING_ANDX_CHANGE_LOCKTYPE);
1767 cli_close(cli, fnum);
1768 printf("CHANGE_LOCKTYPE gave %s\n", nt_errstr(status));
1770 fnum = cli_open(cli, fname[i], O_RDWR, DENY_NONE);
1771 status = cli_locktype(cli, fnum, 0, 8, 0, LOCKING_ANDX_CANCEL_LOCK);
1772 cli_close(cli, fnum);
1773 printf("CANCEL_LOCK gave %s\n", nt_errstr(status));
1775 cli_unlink(cli, fname[i]);
1778 torture_close_connection(cli);
1780 printf("finished locktest6\n");
1784 static BOOL run_locktest7(int dummy)
1786 struct cli_state *cli1;
1787 const char *fname = "\\lockt7.lck";
1790 BOOL correct = False;
1792 if (!torture_open_connection(&cli1)) {
1796 cli_sockopt(cli1, sockops);
1798 printf("starting locktest7\n");
1800 cli_unlink(cli1, fname);
1802 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1804 memset(buf, 0, sizeof(buf));
1806 if (cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
1807 printf("Failed to create file\n");
1811 cli_setpid(cli1, 1);
1813 if (!cli_lock(cli1, fnum1, 130, 4, 0, READ_LOCK)) {
1814 printf("Unable to apply read lock on range 130:4, error was %s\n", cli_errstr(cli1));
1817 printf("pid1 successfully locked range 130:4 for READ\n");
1820 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
1821 printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
1824 printf("pid1 successfully read the range 130:4\n");
1827 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
1828 printf("pid1 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
1829 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
1830 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
1834 printf("pid1 successfully wrote to the range 130:4 (should be denied)\n");
1838 cli_setpid(cli1, 2);
1840 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
1841 printf("pid2 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
1843 printf("pid2 successfully read the range 130:4\n");
1846 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
1847 printf("pid2 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
1848 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
1849 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
1853 printf("pid2 successfully wrote to the range 130:4 (should be denied)\n");
1857 cli_setpid(cli1, 1);
1858 cli_unlock(cli1, fnum1, 130, 4);
1860 if (!cli_lock(cli1, fnum1, 130, 4, 0, WRITE_LOCK)) {
1861 printf("Unable to apply write lock on range 130:4, error was %s\n", cli_errstr(cli1));
1864 printf("pid1 successfully locked range 130:4 for WRITE\n");
1867 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
1868 printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
1871 printf("pid1 successfully read the range 130:4\n");
1874 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
1875 printf("pid1 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
1878 printf("pid1 successfully wrote to the range 130:4\n");
1881 cli_setpid(cli1, 2);
1883 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
1884 printf("pid2 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
1885 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
1886 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
1890 printf("pid2 successfully read the range 130:4 (should be denied)\n");
1894 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
1895 printf("pid2 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
1896 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
1897 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
1901 printf("pid2 successfully wrote to the range 130:4 (should be denied)\n");
1905 cli_unlock(cli1, fnum1, 130, 0);
1909 cli_close(cli1, fnum1);
1910 cli_unlink(cli1, fname);
1911 torture_close_connection(cli1);
1913 printf("finished locktest7\n");
1918 test whether fnums and tids open on one VC are available on another (a major
1921 static BOOL run_fdpasstest(int dummy)
1923 struct cli_state *cli1, *cli2;
1924 const char *fname = "\\fdpass.tst";
1928 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
1931 cli_sockopt(cli1, sockops);
1932 cli_sockopt(cli2, sockops);
1934 printf("starting fdpasstest\n");
1936 cli_unlink(cli1, fname);
1938 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1940 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
1944 if (cli_write(cli1, fnum1, 0, "hello world\n", 0, 13) != 13) {
1945 printf("write failed (%s)\n", cli_errstr(cli1));
1949 cli2->vuid = cli1->vuid;
1950 cli2->cnum = cli1->cnum;
1951 cli2->pid = cli1->pid;
1953 if (cli_read(cli2, fnum1, buf, 0, 13) == 13) {
1954 printf("read succeeded! nasty security hole [%s]\n",
1959 cli_close(cli1, fnum1);
1960 cli_unlink(cli1, fname);
1962 torture_close_connection(cli1);
1963 torture_close_connection(cli2);
1965 printf("finished fdpasstest\n");
1969 static BOOL run_fdsesstest(int dummy)
1971 struct cli_state *cli;
1976 const char *fname = "\\fdsess.tst";
1977 const char *fname1 = "\\fdsess1.tst";
1983 if (!torture_open_connection(&cli))
1985 cli_sockopt(cli, sockops);
1987 if (!torture_cli_session_setup2(cli, &new_vuid))
1990 saved_cnum = cli->cnum;
1991 if (!cli_send_tconX(cli, share, "?????", "", 1))
1993 new_cnum = cli->cnum;
1994 cli->cnum = saved_cnum;
1996 printf("starting fdsesstest\n");
1998 cli_unlink(cli, fname);
1999 cli_unlink(cli, fname1);
2001 fnum1 = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2003 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
2007 if (cli_write(cli, fnum1, 0, "hello world\n", 0, 13) != 13) {
2008 printf("write failed (%s)\n", cli_errstr(cli));
2012 saved_vuid = cli->vuid;
2013 cli->vuid = new_vuid;
2015 if (cli_read(cli, fnum1, buf, 0, 13) == 13) {
2016 printf("read succeeded with different vuid! nasty security hole [%s]\n",
2020 /* Try to open a file with different vuid, samba cnum. */
2021 fnum2 = cli_open(cli, fname1, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2023 printf("create with different vuid, same cnum succeeded.\n");
2024 cli_close(cli, fnum2);
2025 cli_unlink(cli, fname1);
2027 printf("create with different vuid, same cnum failed.\n");
2028 printf("This will cause problems with service clients.\n");
2032 cli->vuid = saved_vuid;
2034 /* Try with same vuid, different cnum. */
2035 cli->cnum = new_cnum;
2037 if (cli_read(cli, fnum1, buf, 0, 13) == 13) {
2038 printf("read succeeded with different cnum![%s]\n",
2043 cli->cnum = saved_cnum;
2044 cli_close(cli, fnum1);
2045 cli_unlink(cli, fname);
2047 torture_close_connection(cli);
2049 printf("finished fdsesstest\n");
2054 This test checks that
2056 1) the server does not allow an unlink on a file that is open
2058 static BOOL run_unlinktest(int dummy)
2060 struct cli_state *cli;
2061 const char *fname = "\\unlink.tst";
2063 BOOL correct = True;
2065 if (!torture_open_connection(&cli)) {
2069 cli_sockopt(cli, sockops);
2071 printf("starting unlink test\n");
2073 cli_unlink(cli, fname);
2077 fnum = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2079 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
2083 if (cli_unlink(cli, fname)) {
2084 printf("error: server allowed unlink on an open file\n");
2087 correct = check_error(__LINE__, cli, ERRDOS, ERRbadshare,
2088 NT_STATUS_SHARING_VIOLATION);
2091 cli_close(cli, fnum);
2092 cli_unlink(cli, fname);
2094 if (!torture_close_connection(cli)) {
2098 printf("unlink test finished\n");
2105 test how many open files this server supports on the one socket
2107 static BOOL run_maxfidtest(int dummy)
2109 struct cli_state *cli;
2110 const char *template = "\\maxfid.%d.%d";
2112 int fnums[0x11000], i;
2114 BOOL correct = True;
2119 printf("failed to connect\n");
2123 cli_sockopt(cli, sockops);
2125 for (i=0; i<0x11000; i++) {
2126 slprintf(fname,sizeof(fname)-1,template, i,(int)getpid());
2127 if ((fnums[i] = cli_open(cli, fname,
2128 O_RDWR|O_CREAT|O_TRUNC, DENY_NONE)) ==
2130 printf("open of %s failed (%s)\n",
2131 fname, cli_errstr(cli));
2132 printf("maximum fnum is %d\n", i);
2140 printf("cleaning up\n");
2142 slprintf(fname,sizeof(fname)-1,template, i,(int)getpid());
2143 cli_close(cli, fnums[i]);
2144 if (!cli_unlink(cli, fname)) {
2145 printf("unlink of %s failed (%s)\n",
2146 fname, cli_errstr(cli));
2153 printf("maxfid test finished\n");
2154 if (!torture_close_connection(cli)) {
2160 /* generate a random buffer */
2161 static void rand_buf(char *buf, int len)
2164 *buf = (char)sys_random();
2169 /* send smb negprot commands, not reading the response */
2170 static BOOL run_negprot_nowait(int dummy)
2173 static struct cli_state cli;
2174 BOOL correct = True;
2176 printf("starting negprot nowait test\n");
2178 if (!open_nbt_connection(&cli)) {
2182 for (i=0;i<50000;i++) {
2183 cli_negprot_send(&cli);
2186 if (!torture_close_connection(&cli)) {
2190 printf("finished negprot nowait test\n");
2196 /* send random IPC commands */
2197 static BOOL run_randomipc(int dummy)
2199 char *rparam = NULL;
2203 int api, param_len, i;
2204 struct cli_state *cli;
2205 BOOL correct = True;
2208 printf("starting random ipc test\n");
2210 if (!torture_open_connection(&cli)) {
2214 for (i=0;i<count;i++) {
2215 api = sys_random() % 500;
2216 param_len = (sys_random() % 64);
2218 rand_buf(param, param_len);
2223 param, param_len, 8,
2224 NULL, 0, BUFFER_SIZE,
2228 printf("%d/%d\r", i,count);
2231 printf("%d/%d\n", i, count);
2233 if (!torture_close_connection(cli)) {
2237 printf("finished random ipc test\n");
2244 static void browse_callback(const char *sname, uint32 stype,
2245 const char *comment, void *state)
2247 printf("\t%20.20s %08x %s\n", sname, stype, comment);
2253 This test checks the browse list code
2256 static BOOL run_browsetest(int dummy)
2258 static struct cli_state *cli;
2259 BOOL correct = True;
2261 printf("starting browse test\n");
2263 if (!torture_open_connection(&cli)) {
2267 printf("domain list:\n");
2268 cli_NetServerEnum(cli, cli->server_domain,
2269 SV_TYPE_DOMAIN_ENUM,
2270 browse_callback, NULL);
2272 printf("machine list:\n");
2273 cli_NetServerEnum(cli, cli->server_domain,
2275 browse_callback, NULL);
2277 if (!torture_close_connection(cli)) {
2281 printf("browse test finished\n");
2289 This checks how the getatr calls works
2291 static BOOL run_attrtest(int dummy)
2293 struct cli_state *cli;
2296 const char *fname = "\\attrib123456789.tst";
2297 BOOL correct = True;
2299 printf("starting attrib test\n");
2301 if (!torture_open_connection(&cli)) {
2305 cli_unlink(cli, fname);
2306 fnum = cli_open(cli, fname,
2307 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2308 cli_close(cli, fnum);
2309 if (!cli_getatr(cli, fname, NULL, NULL, &t)) {
2310 printf("getatr failed (%s)\n", cli_errstr(cli));
2314 if (abs(t - time(NULL)) > 60*60*24*10) {
2315 printf("ERROR: SMBgetatr bug. time is %s",
2321 t2 = t-60*60*24; /* 1 day ago */
2323 if (!cli_setatr(cli, fname, 0, t2)) {
2324 printf("setatr failed (%s)\n", cli_errstr(cli));
2328 if (!cli_getatr(cli, fname, NULL, NULL, &t)) {
2329 printf("getatr failed (%s)\n", cli_errstr(cli));
2334 printf("ERROR: getatr/setatr bug. times are\n%s",
2336 printf("%s", ctime(&t2));
2340 cli_unlink(cli, fname);
2342 if (!torture_close_connection(cli)) {
2346 printf("attrib test finished\n");
2353 This checks a couple of trans2 calls
2355 static BOOL run_trans2test(int dummy)
2357 struct cli_state *cli;
2360 time_t c_time, a_time, m_time, w_time, m_time2;
2361 const char *fname = "\\trans2.tst";
2362 const char *dname = "\\trans2";
2363 const char *fname2 = "\\trans2\\trans2.tst";
2365 BOOL correct = True;
2367 printf("starting trans2 test\n");
2369 if (!torture_open_connection(&cli)) {
2373 cli_unlink(cli, fname);
2374 fnum = cli_open(cli, fname,
2375 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2376 if (!cli_qfileinfo(cli, fnum, NULL, &size, &c_time, &a_time, &m_time,
2378 printf("ERROR: qfileinfo failed (%s)\n", cli_errstr(cli));
2382 if (!cli_qfilename(cli, fnum, pname)) {
2383 printf("ERROR: qfilename failed (%s)\n", cli_errstr(cli));
2387 if (strcmp(pname, fname)) {
2388 printf("qfilename gave different name? [%s] [%s]\n",
2393 cli_close(cli, fnum);
2397 cli_unlink(cli, fname);
2398 fnum = cli_open(cli, fname,
2399 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2401 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
2404 cli_close(cli, fnum);
2406 if (!cli_qpathinfo(cli, fname, &c_time, &a_time, &m_time, &size, NULL)) {
2407 printf("ERROR: qpathinfo failed (%s)\n", cli_errstr(cli));
2410 if (c_time != m_time) {
2411 printf("create time=%s", ctime(&c_time));
2412 printf("modify time=%s", ctime(&m_time));
2413 printf("This system appears to have sticky create times\n");
2415 if (a_time % (60*60) == 0) {
2416 printf("access time=%s", ctime(&a_time));
2417 printf("This system appears to set a midnight access time\n");
2421 if (abs(m_time - time(NULL)) > 60*60*24*7) {
2422 printf("ERROR: totally incorrect times - maybe word reversed? mtime=%s", ctime(&m_time));
2428 cli_unlink(cli, fname);
2429 fnum = cli_open(cli, fname,
2430 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2431 cli_close(cli, fnum);
2432 if (!cli_qpathinfo2(cli, fname, &c_time, &a_time, &m_time,
2433 &w_time, &size, NULL, NULL)) {
2434 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli));
2437 if (w_time < 60*60*24*2) {
2438 printf("write time=%s", ctime(&w_time));
2439 printf("This system appears to set a initial 0 write time\n");
2444 cli_unlink(cli, fname);
2447 /* check if the server updates the directory modification time
2448 when creating a new file */
2449 if (!cli_mkdir(cli, dname)) {
2450 printf("ERROR: mkdir failed (%s)\n", cli_errstr(cli));
2454 if (!cli_qpathinfo2(cli, "\\trans2\\", &c_time, &a_time, &m_time,
2455 &w_time, &size, NULL, NULL)) {
2456 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli));
2460 fnum = cli_open(cli, fname2,
2461 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2462 cli_write(cli, fnum, 0, (char *)&fnum, 0, sizeof(fnum));
2463 cli_close(cli, fnum);
2464 if (!cli_qpathinfo2(cli, "\\trans2\\", &c_time, &a_time, &m_time2,
2465 &w_time, &size, NULL, NULL)) {
2466 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli));
2469 if (m_time2 == m_time) {
2470 printf("This system does not update directory modification times\n");
2474 cli_unlink(cli, fname2);
2475 cli_rmdir(cli, dname);
2477 if (!torture_close_connection(cli)) {
2481 printf("trans2 test finished\n");
2487 This checks new W2K calls.
2490 static BOOL new_trans(struct cli_state *pcli, int fnum, int level)
2493 BOOL correct = True;
2495 memset(buf, 0xff, sizeof(buf));
2497 if (!cli_qfileinfo_test(pcli, fnum, level, buf)) {
2498 printf("ERROR: qfileinfo (%d) failed (%s)\n", level, cli_errstr(pcli));
2501 printf("qfileinfo: level %d\n", level);
2502 dump_data(0, buf, 256);
2508 static BOOL run_w2ktest(int dummy)
2510 struct cli_state *cli;
2512 const char *fname = "\\w2ktest\\w2k.tst";
2514 BOOL correct = True;
2516 printf("starting w2k test\n");
2518 if (!torture_open_connection(&cli)) {
2522 fnum = cli_open(cli, fname,
2523 O_RDWR | O_CREAT , DENY_NONE);
2525 for (level = 1004; level < 1040; level++) {
2526 new_trans(cli, fnum, level);
2529 cli_close(cli, fnum);
2531 if (!torture_close_connection(cli)) {
2535 printf("w2k test finished\n");
2542 this is a harness for some oplock tests
2544 static BOOL run_oplock1(int dummy)
2546 struct cli_state *cli1;
2547 const char *fname = "\\lockt1.lck";
2549 BOOL correct = True;
2551 printf("starting oplock test 1\n");
2553 if (!torture_open_connection(&cli1)) {
2557 cli_unlink(cli1, fname);
2559 cli_sockopt(cli1, sockops);
2561 cli1->use_oplocks = True;
2563 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2565 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
2569 cli1->use_oplocks = False;
2571 cli_unlink(cli1, fname);
2572 cli_unlink(cli1, fname);
2574 if (!cli_close(cli1, fnum1)) {
2575 printf("close2 failed (%s)\n", cli_errstr(cli1));
2579 if (!cli_unlink(cli1, fname)) {
2580 printf("unlink failed (%s)\n", cli_errstr(cli1));
2584 if (!torture_close_connection(cli1)) {
2588 printf("finished oplock test 1\n");
2593 static BOOL run_oplock2(int dummy)
2595 struct cli_state *cli1, *cli2;
2596 const char *fname = "\\lockt2.lck";
2598 int saved_use_oplocks = use_oplocks;
2600 BOOL correct = True;
2601 volatile BOOL *shared_correct;
2603 shared_correct = (volatile BOOL *)shm_setup(sizeof(BOOL));
2604 *shared_correct = True;
2606 use_level_II_oplocks = True;
2609 printf("starting oplock test 2\n");
2611 if (!torture_open_connection(&cli1)) {
2612 use_level_II_oplocks = False;
2613 use_oplocks = saved_use_oplocks;
2617 cli1->use_oplocks = True;
2618 cli1->use_level_II_oplocks = True;
2620 if (!torture_open_connection(&cli2)) {
2621 use_level_II_oplocks = False;
2622 use_oplocks = saved_use_oplocks;
2626 cli2->use_oplocks = True;
2627 cli2->use_level_II_oplocks = True;
2629 cli_unlink(cli1, fname);
2631 cli_sockopt(cli1, sockops);
2632 cli_sockopt(cli2, sockops);
2634 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2636 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
2640 /* Don't need the globals any more. */
2641 use_level_II_oplocks = False;
2642 use_oplocks = saved_use_oplocks;
2646 fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
2648 printf("second open of %s failed (%s)\n", fname, cli_errstr(cli1));
2649 *shared_correct = False;
2655 if (!cli_close(cli2, fnum2)) {
2656 printf("close2 failed (%s)\n", cli_errstr(cli1));
2657 *shared_correct = False;
2665 /* Ensure cli1 processes the break. */
2667 if (cli_read(cli1, fnum1, buf, 0, 4) != 4) {
2668 printf("read on fnum1 failed (%s)\n", cli_errstr(cli1));
2672 /* Should now be at level II. */
2673 /* Test if sending a write locks causes a break to none. */
2675 if (!cli_lock(cli1, fnum1, 0, 4, 0, READ_LOCK)) {
2676 printf("lock failed (%s)\n", cli_errstr(cli1));
2680 cli_unlock(cli1, fnum1, 0, 4);
2684 if (!cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK)) {
2685 printf("lock failed (%s)\n", cli_errstr(cli1));
2689 cli_unlock(cli1, fnum1, 0, 4);
2693 cli_read(cli1, fnum1, buf, 0, 4);
2696 if (cli_write(cli1, fnum1, 0, buf, 0, 4) != 4) {
2697 printf("write on fnum1 failed (%s)\n", cli_errstr(cli1));
2702 if (!cli_close(cli1, fnum1)) {
2703 printf("close1 failed (%s)\n", cli_errstr(cli1));
2709 if (!cli_unlink(cli1, fname)) {
2710 printf("unlink failed (%s)\n", cli_errstr(cli1));
2714 if (!torture_close_connection(cli1)) {
2718 if (!*shared_correct) {
2722 printf("finished oplock test 2\n");
2727 /* handler for oplock 3 tests */
2728 static BOOL oplock3_handler(struct cli_state *cli, int fnum, unsigned char level)
2730 printf("got oplock break fnum=%d level=%d\n",
2732 return cli_oplock_ack(cli, fnum, level);
2735 static BOOL run_oplock3(int dummy)
2737 struct cli_state *cli;
2738 const char *fname = "\\oplockt3.dat";
2740 char buf[4] = "abcd";
2741 BOOL correct = True;
2742 volatile BOOL *shared_correct;
2744 shared_correct = (volatile BOOL *)shm_setup(sizeof(BOOL));
2745 *shared_correct = True;
2747 printf("starting oplock test 3\n");
2752 use_level_II_oplocks = True;
2753 if (!torture_open_connection(&cli)) {
2754 *shared_correct = False;
2758 /* try to trigger a oplock break in parent */
2759 fnum = cli_open(cli, fname, O_RDWR, DENY_NONE);
2760 cli_write(cli, fnum, 0, buf, 0, 4);
2766 use_level_II_oplocks = True;
2767 if (!torture_open_connection(&cli)) {
2770 cli_oplock_handler(cli, oplock3_handler);
2771 fnum = cli_open(cli, fname, O_RDWR|O_CREAT, DENY_NONE);
2772 cli_write(cli, fnum, 0, buf, 0, 4);
2773 cli_close(cli, fnum);
2774 fnum = cli_open(cli, fname, O_RDWR, DENY_NONE);
2775 cli->timeout = 20000;
2776 cli_receive_smb(cli);
2777 printf("finished oplock test 3\n");
2779 return (correct && *shared_correct);
2781 /* What are we looking for here? What's sucess and what's FAILURE? */
2787 Test delete on close semantics.
2789 static BOOL run_deletetest(int dummy)
2791 struct cli_state *cli1;
2792 struct cli_state *cli2;
2793 const char *fname = "\\delete.file";
2796 BOOL correct = True;
2798 printf("starting delete test\n");
2800 if (!torture_open_connection(&cli1)) {
2804 cli_sockopt(cli1, sockops);
2806 /* Test 1 - this should delete the file on close. */
2808 cli_setatr(cli1, fname, 0, 0);
2809 cli_unlink(cli1, fname);
2811 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL,
2812 FILE_SHARE_DELETE, FILE_OVERWRITE_IF,
2813 FILE_DELETE_ON_CLOSE, 0);
2816 printf("[1] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2821 if (!cli_close(cli1, fnum1)) {
2822 printf("[1] close failed (%s)\n", cli_errstr(cli1));
2827 fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
2829 printf("[1] open of %s succeeded (should fail)\n", fname);
2834 printf("first delete on close test succeeded.\n");
2836 /* Test 2 - this should delete the file on close. */
2838 cli_setatr(cli1, fname, 0, 0);
2839 cli_unlink(cli1, fname);
2841 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_ALL_ACCESS,
2842 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
2843 FILE_OVERWRITE_IF, 0, 0);
2846 printf("[2] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2851 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
2852 printf("[2] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
2857 if (!cli_close(cli1, fnum1)) {
2858 printf("[2] close failed (%s)\n", cli_errstr(cli1));
2863 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
2865 printf("[2] open of %s succeeded should have been deleted on close !\n", fname);
2866 if (!cli_close(cli1, fnum1)) {
2867 printf("[2] close failed (%s)\n", cli_errstr(cli1));
2871 cli_unlink(cli1, fname);
2873 printf("second delete on close test succeeded.\n");
2876 cli_setatr(cli1, fname, 0, 0);
2877 cli_unlink(cli1, fname);
2879 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL,
2880 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0);
2883 printf("[3] open - 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
2888 /* This should fail with a sharing violation - open for delete is only compatible
2889 with SHARE_DELETE. */
2891 fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
2892 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0, 0);
2895 printf("[3] open - 2 of %s succeeded - should have failed.\n", fname);
2900 /* This should succeed. */
2902 fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
2903 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0, 0);
2906 printf("[3] open - 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
2911 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
2912 printf("[3] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
2917 if (!cli_close(cli1, fnum1)) {
2918 printf("[3] close 1 failed (%s)\n", cli_errstr(cli1));
2923 if (!cli_close(cli1, fnum2)) {
2924 printf("[3] close 2 failed (%s)\n", cli_errstr(cli1));
2929 /* This should fail - file should no longer be there. */
2931 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
2933 printf("[3] open of %s succeeded should have been deleted on close !\n", fname);
2934 if (!cli_close(cli1, fnum1)) {
2935 printf("[3] close failed (%s)\n", cli_errstr(cli1));
2937 cli_unlink(cli1, fname);
2941 printf("third delete on close test succeeded.\n");
2944 cli_setatr(cli1, fname, 0, 0);
2945 cli_unlink(cli1, fname);
2947 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
2948 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0);
2951 printf("[4] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2956 /* This should succeed. */
2957 fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS,
2958 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0, 0);
2960 printf("[4] open - 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
2965 if (!cli_close(cli1, fnum2)) {
2966 printf("[4] close - 1 failed (%s)\n", cli_errstr(cli1));
2971 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
2972 printf("[4] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
2977 /* This should fail - no more opens once delete on close set. */
2978 fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS,
2979 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
2982 printf("[4] open - 3 of %s succeeded ! Should have failed.\n", fname );
2986 printf("fourth delete on close test succeeded.\n");
2988 if (!cli_close(cli1, fnum1)) {
2989 printf("[4] close - 2 failed (%s)\n", cli_errstr(cli1));
2995 cli_setatr(cli1, fname, 0, 0);
2996 cli_unlink(cli1, fname);
2998 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT, DENY_NONE);
3000 printf("[5] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3005 /* This should fail - only allowed on NT opens with DELETE access. */
3007 if (cli_nt_delete_on_close(cli1, fnum1, True)) {
3008 printf("[5] setting delete_on_close on OpenX file succeeded - should fail !\n");
3013 if (!cli_close(cli1, fnum1)) {
3014 printf("[5] close - 2 failed (%s)\n", cli_errstr(cli1));
3019 printf("fifth delete on close test succeeded.\n");
3022 cli_setatr(cli1, fname, 0, 0);
3023 cli_unlink(cli1, fname);
3025 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA,
3026 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
3027 FILE_OVERWRITE_IF, 0, 0);
3030 printf("[6] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3035 /* This should fail - only allowed on NT opens with DELETE access. */
3037 if (cli_nt_delete_on_close(cli1, fnum1, True)) {
3038 printf("[6] setting delete_on_close on file with no delete access succeeded - should fail !\n");
3043 if (!cli_close(cli1, fnum1)) {
3044 printf("[6] close - 2 failed (%s)\n", cli_errstr(cli1));
3049 printf("sixth delete on close test succeeded.\n");
3052 cli_setatr(cli1, fname, 0, 0);
3053 cli_unlink(cli1, fname);
3055 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
3056 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF, 0, 0);
3059 printf("[7] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3064 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
3065 printf("[7] setting delete_on_close on file failed !\n");
3070 if (!cli_nt_delete_on_close(cli1, fnum1, False)) {
3071 printf("[7] unsetting delete_on_close on file failed !\n");
3076 if (!cli_close(cli1, fnum1)) {
3077 printf("[7] close - 2 failed (%s)\n", cli_errstr(cli1));
3082 /* This next open should succeed - we reset the flag. */
3084 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
3086 printf("[5] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3091 if (!cli_close(cli1, fnum1)) {
3092 printf("[7] close - 2 failed (%s)\n", cli_errstr(cli1));
3097 printf("seventh delete on close test succeeded.\n");
3100 cli_setatr(cli1, fname, 0, 0);
3101 cli_unlink(cli1, fname);
3103 if (!torture_open_connection(&cli2)) {
3104 printf("[8] failed to open second connection.\n");
3109 cli_sockopt(cli1, sockops);
3111 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
3112 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
3113 FILE_OVERWRITE_IF, 0, 0);
3116 printf("[8] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3121 fnum2 = cli_nt_create_full(cli2, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
3122 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
3126 printf("[8] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3131 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
3132 printf("[8] setting delete_on_close on file failed !\n");
3137 if (!cli_close(cli1, fnum1)) {
3138 printf("[8] close - 1 failed (%s)\n", cli_errstr(cli1));
3143 if (!cli_close(cli2, fnum2)) {
3144 printf("[8] close - 2 failed (%s)\n", cli_errstr(cli2));
3149 /* This should fail.. */
3150 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
3152 printf("[8] open of %s succeeded should have been deleted on close !\n", fname);
3156 printf("eighth delete on close test succeeded.\n");
3158 /* This should fail - we need to set DELETE_ACCESS. */
3159 fnum1 = cli_nt_create_full(cli1, fname, 0,FILE_READ_DATA|FILE_WRITE_DATA,
3160 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, FILE_OVERWRITE_IF, FILE_DELETE_ON_CLOSE, 0);
3163 printf("[9] open of %s succeeded should have failed!\n", fname);
3168 printf("ninth delete on close test succeeded.\n");
3170 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
3171 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, FILE_OVERWRITE_IF, FILE_DELETE_ON_CLOSE, 0);
3173 printf("[10] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3178 /* This should delete the file. */
3179 if (!cli_close(cli1, fnum1)) {
3180 printf("[10] close failed (%s)\n", cli_errstr(cli1));
3185 /* This should fail.. */
3186 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
3188 printf("[10] open of %s succeeded should have been deleted on close !\n", fname);
3192 printf("tenth delete on close test succeeded.\n");
3193 printf("finished delete test\n");
3196 /* FIXME: This will crash if we aborted before cli2 got
3197 * intialized, because these functions don't handle
3198 * uninitialized connections. */
3200 cli_close(cli1, fnum1);
3201 cli_close(cli1, fnum2);
3202 cli_setatr(cli1, fname, 0, 0);
3203 cli_unlink(cli1, fname);
3205 if (!torture_close_connection(cli1)) {
3208 if (!torture_close_connection(cli2)) {
3216 print out server properties
3218 static BOOL run_properties(int dummy)
3220 static struct cli_state *cli;
3221 BOOL correct = True;
3223 printf("starting properties test\n");
3227 if (!torture_open_connection(&cli)) {
3231 cli_sockopt(cli, sockops);
3233 d_printf("Capabilities 0x%08x\n", cli->capabilities);
3235 if (!torture_close_connection(cli)) {
3244 /* FIRST_DESIRED_ACCESS 0xf019f */
3245 #define FIRST_DESIRED_ACCESS FILE_READ_DATA|FILE_WRITE_DATA|FILE_APPEND_DATA|\
3246 FILE_READ_EA| /* 0xf */ \
3247 FILE_WRITE_EA|FILE_READ_ATTRIBUTES| /* 0x90 */ \
3248 FILE_WRITE_ATTRIBUTES| /* 0x100 */ \
3249 DELETE_ACCESS|READ_CONTROL_ACCESS|\
3250 WRITE_DAC_ACCESS|WRITE_OWNER_ACCESS /* 0xf0000 */
3251 /* SECOND_DESIRED_ACCESS 0xe0080 */
3252 #define SECOND_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
3253 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
3254 WRITE_OWNER_ACCESS /* 0xe0000 */
3257 #define THIRD_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
3258 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
3260 WRITE_OWNER_ACCESS /* */
3264 Test ntcreate calls made by xcopy
3266 static BOOL run_xcopy(int dummy)
3268 static struct cli_state *cli1;
3269 const char *fname = "\\test.txt";
3270 BOOL correct = True;
3273 printf("starting xcopy test\n");
3275 if (!torture_open_connection(&cli1)) {
3279 fnum1 = cli_nt_create_full(cli1, fname, 0,
3280 FIRST_DESIRED_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
3281 FILE_SHARE_NONE, FILE_OVERWRITE_IF,
3285 printf("First open failed - %s\n", cli_errstr(cli1));
3289 fnum2 = cli_nt_create_full(cli1, fname, 0,
3290 SECOND_DESIRED_ACCESS, 0,
3291 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN,
3294 printf("second open failed - %s\n", cli_errstr(cli1));
3298 if (!torture_close_connection(cli1)) {
3306 Test rename on files open with share delete and no share delete.
3308 static BOOL run_rename(int dummy)
3310 static struct cli_state *cli1;
3311 const char *fname = "\\test.txt";
3312 const char *fname1 = "\\test1.txt";
3313 BOOL correct = True;
3316 printf("starting rename test\n");
3318 if (!torture_open_connection(&cli1)) {
3322 cli_unlink(cli1, fname);
3323 cli_unlink(cli1, fname1);
3324 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3325 FILE_SHARE_READ, FILE_OVERWRITE_IF, 0, 0);
3328 printf("First open failed - %s\n", cli_errstr(cli1));
3332 if (!cli_rename(cli1, fname, fname1)) {
3333 printf("First rename failed (this is correct) - %s\n", cli_errstr(cli1));
3335 printf("First rename succeeded - this should have failed !\n");
3339 if (!cli_close(cli1, fnum1)) {
3340 printf("close - 1 failed (%s)\n", cli_errstr(cli1));
3344 cli_unlink(cli1, fname);
3345 cli_unlink(cli1, fname1);
3346 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3348 FILE_SHARE_DELETE|FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
3350 FILE_SHARE_DELETE|FILE_SHARE_READ, FILE_OVERWRITE_IF, 0, 0);
3354 printf("Second open failed - %s\n", cli_errstr(cli1));
3358 if (!cli_rename(cli1, fname, fname1)) {
3359 printf("Second rename failed - this should have succeeded - %s\n", cli_errstr(cli1));
3362 printf("Second rename succeeded\n");
3365 if (!cli_close(cli1, fnum1)) {
3366 printf("close - 2 failed (%s)\n", cli_errstr(cli1));
3370 cli_unlink(cli1, fname);
3371 cli_unlink(cli1, fname1);
3373 fnum1 = cli_nt_create_full(cli1, fname, 0, READ_CONTROL_ACCESS, FILE_ATTRIBUTE_NORMAL,
3374 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
3377 printf("Third open failed - %s\n", cli_errstr(cli1));
3386 fnum2 = cli_nt_create_full(cli1, fname, 0, DELETE_ACCESS, FILE_ATTRIBUTE_NORMAL,
3387 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
3390 printf("Fourth open failed - %s\n", cli_errstr(cli1));
3393 if (!cli_nt_delete_on_close(cli1, fnum2, True)) {
3394 printf("[8] setting delete_on_close on file failed !\n");
3398 if (!cli_close(cli1, fnum2)) {
3399 printf("close - 4 failed (%s)\n", cli_errstr(cli1));
3405 if (!cli_rename(cli1, fname, fname1)) {
3406 printf("Third rename failed - this should have succeeded - %s\n", cli_errstr(cli1));
3409 printf("Third rename succeeded\n");
3412 if (!cli_close(cli1, fnum1)) {
3413 printf("close - 3 failed (%s)\n", cli_errstr(cli1));
3417 cli_unlink(cli1, fname);
3418 cli_unlink(cli1, fname1);
3420 if (!torture_close_connection(cli1)) {
3427 static BOOL run_pipe_number(int dummy)
3429 struct cli_state *cli1;
3430 const char *pipe_name = "\\SPOOLSS";
3434 printf("starting pipenumber test\n");
3435 if (!torture_open_connection(&cli1)) {
3439 cli_sockopt(cli1, sockops);
3441 fnum = cli_nt_create_full(cli1, pipe_name, 0, FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
3442 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN_IF, 0, 0);
3445 printf("Open of pipe %s failed with error (%s)\n", pipe_name, cli_errstr(cli1));
3451 printf("pipe_number test - we can open %d %s pipes.\n", num_pipes, pipe_name );
3452 torture_close_connection(cli1);
3457 Test open mode returns on read-only files.
3459 static BOOL run_opentest(int dummy)
3461 static struct cli_state *cli1;
3462 static struct cli_state *cli2;
3463 const char *fname = "\\readonly.file";
3467 BOOL correct = True;
3470 printf("starting open test\n");
3472 if (!torture_open_connection(&cli1)) {
3476 cli_setatr(cli1, fname, 0, 0);
3477 cli_unlink(cli1, fname);
3479 cli_sockopt(cli1, sockops);
3481 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
3483 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
3487 if (!cli_close(cli1, fnum1)) {
3488 printf("close2 failed (%s)\n", cli_errstr(cli1));
3492 if (!cli_setatr(cli1, fname, aRONLY, 0)) {
3493 printf("cli_setatr failed (%s)\n", cli_errstr(cli1));
3497 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_WRITE);
3499 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
3503 /* This will fail - but the error should be ERRnoaccess, not ERRbadshare. */
3504 fnum2 = cli_open(cli1, fname, O_RDWR, DENY_ALL);
3506 if (check_error(__LINE__, cli1, ERRDOS, ERRnoaccess,
3507 NT_STATUS_ACCESS_DENIED)) {
3508 printf("correct error code ERRDOS/ERRnoaccess returned\n");
3511 printf("finished open test 1\n");
3513 cli_close(cli1, fnum1);
3515 /* Now try not readonly and ensure ERRbadshare is returned. */
3517 cli_setatr(cli1, fname, 0, 0);
3519 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_WRITE);
3521 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
3525 /* This will fail - but the error should be ERRshare. */
3526 fnum2 = cli_open(cli1, fname, O_RDWR, DENY_ALL);
3528 if (check_error(__LINE__, cli1, ERRDOS, ERRbadshare,
3529 NT_STATUS_SHARING_VIOLATION)) {
3530 printf("correct error code ERRDOS/ERRbadshare returned\n");
3533 if (!cli_close(cli1, fnum1)) {
3534 printf("close2 failed (%s)\n", cli_errstr(cli1));
3538 cli_unlink(cli1, fname);
3540 printf("finished open test 2\n");
3542 /* Test truncate open disposition on file opened for read. */
3544 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
3546 printf("(3) open (1) of %s failed (%s)\n", fname, cli_errstr(cli1));
3550 /* write 20 bytes. */
3552 memset(buf, '\0', 20);
3554 if (cli_write(cli1, fnum1, 0, buf, 0, 20) != 20) {
3555 printf("write failed (%s)\n", cli_errstr(cli1));
3559 if (!cli_close(cli1, fnum1)) {
3560 printf("(3) close1 failed (%s)\n", cli_errstr(cli1));
3564 /* Ensure size == 20. */
3565 if (!cli_getatr(cli1, fname, NULL, &fsize, NULL)) {
3566 printf("(3) getatr failed (%s)\n", cli_errstr(cli1));
3571 printf("(3) file size != 20\n");
3575 /* Now test if we can truncate a file opened for readonly. */
3577 fnum1 = cli_open(cli1, fname, O_RDONLY|O_TRUNC, DENY_NONE);
3579 printf("(3) open (2) of %s failed (%s)\n", fname, cli_errstr(cli1));
3583 if (!cli_close(cli1, fnum1)) {
3584 printf("close2 failed (%s)\n", cli_errstr(cli1));
3588 /* Ensure size == 0. */
3589 if (!cli_getatr(cli1, fname, NULL, &fsize, NULL)) {
3590 printf("(3) getatr failed (%s)\n", cli_errstr(cli1));
3595 printf("(3) file size != 0\n");
3598 printf("finished open test 3\n");
3600 cli_unlink(cli1, fname);
3603 printf("testing ctemp\n");
3604 fnum1 = cli_ctemp(cli1, "\\", &tmp_path);
3606 printf("ctemp failed (%s)\n", cli_errstr(cli1));
3609 printf("ctemp gave path %s\n", tmp_path);
3610 if (!cli_close(cli1, fnum1)) {
3611 printf("close of temp failed (%s)\n", cli_errstr(cli1));
3613 if (!cli_unlink(cli1, tmp_path)) {
3614 printf("unlink of temp failed (%s)\n", cli_errstr(cli1));
3617 /* Test the non-io opens... */
3619 if (!torture_open_connection(&cli2)) {
3623 cli_setatr(cli2, fname, 0, 0);
3624 cli_unlink(cli2, fname);
3626 cli_sockopt(cli2, sockops);
3628 printf("TEST #1 testing 2 non-io opens (no delete)\n");
3630 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3631 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
3634 printf("test 1 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3638 fnum2 = cli_nt_create_full(cli2, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3639 FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0);
3642 printf("test 1 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3646 if (!cli_close(cli1, fnum1)) {
3647 printf("test 1 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3650 if (!cli_close(cli2, fnum2)) {
3651 printf("test 1 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3655 printf("non-io open test #1 passed.\n");
3657 cli_unlink(cli1, fname);
3659 printf("TEST #2 testing 2 non-io opens (first with delete)\n");
3661 fnum1 = cli_nt_create_full(cli1, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3662 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
3665 printf("test 2 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3669 fnum2 = cli_nt_create_full(cli2, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3670 FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0);
3673 printf("test 2 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3677 if (!cli_close(cli1, fnum1)) {
3678 printf("test 1 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3681 if (!cli_close(cli2, fnum2)) {
3682 printf("test 1 close 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
3686 printf("non-io open test #2 passed.\n");
3688 cli_unlink(cli1, fname);
3690 printf("TEST #3 testing 2 non-io opens (second with delete)\n");
3692 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3693 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
3696 printf("test 3 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3700 fnum2 = cli_nt_create_full(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3701 FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0);
3704 printf("test 3 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3708 if (!cli_close(cli1, fnum1)) {
3709 printf("test 3 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3712 if (!cli_close(cli2, fnum2)) {
3713 printf("test 3 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3717 printf("non-io open test #3 passed.\n");
3719 cli_unlink(cli1, fname);
3721 printf("TEST #4 testing 2 non-io opens (both with delete)\n");
3723 fnum1 = cli_nt_create_full(cli1, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3724 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
3727 printf("test 4 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3731 fnum2 = cli_nt_create_full(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3732 FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0);
3735 printf("test 4 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, cli_errstr(cli2));
3739 printf("test 3 open 2 of %s gave %s (correct error should be %s)\n", fname, cli_errstr(cli2), "sharing violation");
3741 if (!cli_close(cli1, fnum1)) {
3742 printf("test 4 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3746 printf("non-io open test #4 passed.\n");
3748 cli_unlink(cli1, fname);
3750 printf("TEST #5 testing 2 non-io opens (both with delete - both with file share delete)\n");
3752 fnum1 = cli_nt_create_full(cli1, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3753 FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0, 0);
3756 printf("test 5 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3760 fnum2 = cli_nt_create_full(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3761 FILE_SHARE_DELETE, FILE_OPEN_IF, 0, 0);
3764 printf("test 5 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3768 if (!cli_close(cli1, fnum1)) {
3769 printf("test 5 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3773 if (!cli_close(cli2, fnum2)) {
3774 printf("test 5 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3778 printf("non-io open test #5 passed.\n");
3780 printf("TEST #6 testing 1 non-io open, one io open\n");
3782 cli_unlink(cli1, fname);
3784 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
3785 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
3788 printf("test 6 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3792 fnum2 = cli_nt_create_full(cli2, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3793 FILE_SHARE_READ, FILE_OPEN_IF, 0, 0);
3796 printf("test 6 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3800 if (!cli_close(cli1, fnum1)) {
3801 printf("test 6 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3805 if (!cli_close(cli2, fnum2)) {
3806 printf("test 6 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3810 printf("non-io open test #6 passed.\n");
3812 printf("TEST #7 testing 1 non-io open, one io open with delete\n");
3814 cli_unlink(cli1, fname);
3816 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
3817 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
3820 printf("test 7 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3824 fnum2 = cli_nt_create_full(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3825 FILE_SHARE_READ|FILE_SHARE_DELETE, FILE_OPEN_IF, 0, 0);
3828 printf("test 7 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, cli_errstr(cli2));
3832 printf("test 7 open 2 of %s gave %s (correct error should be %s)\n", fname, cli_errstr(cli2), "sharing violation");
3834 if (!cli_close(cli1, fnum1)) {
3835 printf("test 7 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3839 printf("non-io open test #7 passed.\n");
3841 cli_unlink(cli1, fname);
3843 if (!torture_close_connection(cli1)) {
3846 if (!torture_close_connection(cli2)) {
3853 static uint32 open_attrs_table[] = {
3854 FILE_ATTRIBUTE_NORMAL,
3855 FILE_ATTRIBUTE_ARCHIVE,
3856 FILE_ATTRIBUTE_READONLY,
3857 FILE_ATTRIBUTE_HIDDEN,
3858 FILE_ATTRIBUTE_SYSTEM,
3860 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY,
3861 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN,
3862 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM,
3863 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN,
3864 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM,
3865 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM,
3867 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN,
3868 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM,
3869 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM,
3870 FILE_ATTRIBUTE_HIDDEN,FILE_ATTRIBUTE_SYSTEM,
3873 struct trunc_open_results {
3880 static struct trunc_open_results attr_results[] = {
3881 { 0, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE },
3882 { 1, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE },
3883 { 2, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_READONLY, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY },
3884 { 16, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE },
3885 { 17, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE },
3886 { 18, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_READONLY, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY },
3887 { 51, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
3888 { 54, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
3889 { 56, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN },
3890 { 68, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
3891 { 71, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
3892 { 73, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM },
3893 { 99, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN,FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
3894 { 102, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
3895 { 104, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN },
3896 { 116, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
3897 { 119, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
3898 { 121, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM },
3899 { 170, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM|FILE_ATTRIBUTE_HIDDEN },
3900 { 173, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM },
3901 { 227, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
3902 { 230, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
3903 { 232, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN },
3904 { 244, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
3905 { 247, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
3906 { 249, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM }
3909 static BOOL run_openattrtest(int dummy)
3911 static struct cli_state *cli1;
3912 const char *fname = "\\openattr.file";
3914 BOOL correct = True;
3916 unsigned int i, j, k, l;
3918 printf("starting open attr test\n");
3920 if (!torture_open_connection(&cli1)) {
3924 cli_sockopt(cli1, sockops);
3926 for (k = 0, i = 0; i < sizeof(open_attrs_table)/sizeof(uint32); i++) {
3927 cli_setatr(cli1, fname, 0, 0);
3928 cli_unlink(cli1, fname);
3929 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_WRITE_DATA, open_attrs_table[i],
3930 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
3933 printf("open %d (1) of %s failed (%s)\n", i, fname, cli_errstr(cli1));
3937 if (!cli_close(cli1, fnum1)) {
3938 printf("close %d (1) of %s failed (%s)\n", i, fname, cli_errstr(cli1));
3942 for (j = 0; j < sizeof(open_attrs_table)/sizeof(uint32); j++) {
3943 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA, open_attrs_table[j],
3944 FILE_SHARE_NONE, FILE_OVERWRITE, 0, 0);
3947 for (l = 0; l < sizeof(attr_results)/sizeof(struct trunc_open_results); l++) {
3948 if (attr_results[l].num == k) {
3949 printf("[%d] trunc open 0x%x -> 0x%x of %s failed - should have succeeded !(0x%x:%s)\n",
3950 k, open_attrs_table[i],
3951 open_attrs_table[j],
3952 fname, NT_STATUS_V(cli_nt_error(cli1)), cli_errstr(cli1));
3956 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_ACCESS_DENIED)) {
3957 printf("[%d] trunc open 0x%x -> 0x%x failed with wrong error code %s\n",
3958 k, open_attrs_table[i], open_attrs_table[j],
3963 printf("[%d] trunc open 0x%x -> 0x%x failed\n", k, open_attrs_table[i], open_attrs_table[j]);
3969 if (!cli_close(cli1, fnum1)) {
3970 printf("close %d (2) of %s failed (%s)\n", j, fname, cli_errstr(cli1));
3974 if (!cli_getatr(cli1, fname, &attr, NULL, NULL)) {
3975 printf("getatr(2) failed (%s)\n", cli_errstr(cli1));
3980 printf("[%d] getatr check [0x%x] trunc [0x%x] got attr 0x%x\n",
3981 k, open_attrs_table[i], open_attrs_table[j], attr );
3984 for (l = 0; l < sizeof(attr_results)/sizeof(struct trunc_open_results); l++) {
3985 if (attr_results[l].num == k) {
3986 if (attr != attr_results[l].result_attr ||
3987 open_attrs_table[i] != attr_results[l].init_attr ||
3988 open_attrs_table[j] != attr_results[l].trunc_attr) {
3989 printf("getatr check failed. [0x%x] trunc [0x%x] got attr 0x%x, should be 0x%x\n",
3990 open_attrs_table[i],
3991 open_attrs_table[j],
3993 attr_results[l].result_attr);
4003 cli_setatr(cli1, fname, 0, 0);
4004 cli_unlink(cli1, fname);
4006 printf("open attr test %s.\n", correct ? "passed" : "failed");
4008 if (!torture_close_connection(cli1)) {
4014 static void list_fn(file_info *finfo, const char *name, void *state)
4020 test directory listing speed
4022 static BOOL run_dirtest(int dummy)
4025 static struct cli_state *cli;
4028 BOOL correct = True;
4030 printf("starting directory test\n");
4032 if (!torture_open_connection(&cli)) {
4036 cli_sockopt(cli, sockops);
4039 for (i=0;i<torture_numops;i++) {
4041 slprintf(fname, sizeof(fname), "\\%x", (int)random());
4042 fnum = cli_open(cli, fname, O_RDWR|O_CREAT, DENY_NONE);
4044 fprintf(stderr,"Failed to open %s\n", fname);
4047 cli_close(cli, fnum);
4052 printf("Matched %d\n", cli_list(cli, "a*.*", 0, list_fn, NULL));
4053 printf("Matched %d\n", cli_list(cli, "b*.*", 0, list_fn, NULL));
4054 printf("Matched %d\n", cli_list(cli, "xyzabc", 0, list_fn, NULL));
4056 printf("dirtest core %g seconds\n", end_timer() - t1);
4059 for (i=0;i<torture_numops;i++) {
4061 slprintf(fname, sizeof(fname), "\\%x", (int)random());
4062 cli_unlink(cli, fname);
4065 if (!torture_close_connection(cli)) {
4069 printf("finished dirtest\n");
4074 static void del_fn(file_info *finfo, const char *mask, void *state)
4076 struct cli_state *pcli = (struct cli_state *)state;
4078 slprintf(fname, sizeof(fname), "\\LISTDIR\\%s", finfo->name);
4080 if (strcmp(finfo->name, ".") == 0 || strcmp(finfo->name, "..") == 0)
4083 if (finfo->mode & aDIR) {
4084 if (!cli_rmdir(pcli, fname))
4085 printf("del_fn: failed to rmdir %s\n,", fname );
4087 if (!cli_unlink(pcli, fname))
4088 printf("del_fn: failed to unlink %s\n,", fname );
4094 sees what IOCTLs are supported
4096 BOOL torture_ioctl_test(int dummy)
4098 static struct cli_state *cli;
4099 uint16 device, function;
4101 const char *fname = "\\ioctl.dat";
4105 if (!torture_open_connection(&cli)) {
4109 printf("starting ioctl test\n");
4111 cli_unlink(cli, fname);
4113 fnum = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
4115 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
4119 status = cli_raw_ioctl(cli, fnum, 0x2d0000 | (0x0420<<2), &blob);
4120 printf("ioctl device info: %s\n", cli_errstr(cli));
4122 status = cli_raw_ioctl(cli, fnum, IOCTL_QUERY_JOB_INFO, &blob);
4123 printf("ioctl job info: %s\n", cli_errstr(cli));
4125 for (device=0;device<0x100;device++) {
4126 printf("testing device=0x%x\n", device);
4127 for (function=0;function<0x100;function++) {
4128 uint32 code = (device<<16) | function;
4130 status = cli_raw_ioctl(cli, fnum, code, &blob);
4132 if (NT_STATUS_IS_OK(status)) {
4133 printf("ioctl 0x%x OK : %d bytes\n", code, blob.length);
4134 data_blob_free(&blob);
4139 if (!torture_close_connection(cli)) {
4148 tries varients of chkpath
4150 BOOL torture_chkpath_test(int dummy)
4152 static struct cli_state *cli;
4156 if (!torture_open_connection(&cli)) {
4160 printf("starting chkpath test\n");
4162 /* cleanup from an old run */
4163 cli_rmdir(cli, "\\chkpath.dir\\dir2");
4164 cli_unlink(cli, "\\chkpath.dir\\*");
4165 cli_rmdir(cli, "\\chkpath.dir");
4167 if (!cli_mkdir(cli, "\\chkpath.dir")) {
4168 printf("mkdir1 failed : %s\n", cli_errstr(cli));
4172 if (!cli_mkdir(cli, "\\chkpath.dir\\dir2")) {
4173 printf("mkdir2 failed : %s\n", cli_errstr(cli));
4177 fnum = cli_open(cli, "\\chkpath.dir\\foo.txt", O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
4179 printf("open1 failed (%s)\n", cli_errstr(cli));
4182 cli_close(cli, fnum);
4184 if (!cli_chkpath(cli, "\\chkpath.dir")) {
4185 printf("chkpath1 failed: %s\n", cli_errstr(cli));
4189 if (!cli_chkpath(cli, "\\chkpath.dir\\dir2")) {
4190 printf("chkpath2 failed: %s\n", cli_errstr(cli));
4194 if (!cli_chkpath(cli, "\\chkpath.dir\\foo.txt")) {
4195 ret = check_error(__LINE__, cli, ERRDOS, ERRbadpath,
4196 NT_STATUS_NOT_A_DIRECTORY);
4198 printf("* chkpath on a file should fail\n");
4202 if (!cli_chkpath(cli, "\\chkpath.dir\\bar.txt")) {
4203 ret = check_error(__LINE__, cli, ERRDOS, ERRbadfile,
4204 NT_STATUS_OBJECT_NAME_NOT_FOUND);
4206 printf("* chkpath on a non existant file should fail\n");
4210 if (!cli_chkpath(cli, "\\chkpath.dir\\dirxx\\bar.txt")) {
4211 ret = check_error(__LINE__, cli, ERRDOS, ERRbadpath,
4212 NT_STATUS_OBJECT_PATH_NOT_FOUND);
4214 printf("* chkpath on a non existent component should fail\n");
4218 cli_rmdir(cli, "\\chkpath.dir\\dir2");
4219 cli_unlink(cli, "\\chkpath.dir\\*");
4220 cli_rmdir(cli, "\\chkpath.dir");
4222 if (!torture_close_connection(cli)) {
4232 static BOOL run_dirtest1(int dummy)
4235 static struct cli_state *cli;
4237 BOOL correct = True;
4239 printf("starting directory test\n");
4241 if (!torture_open_connection(&cli)) {
4245 cli_sockopt(cli, sockops);
4247 cli_list(cli, "\\LISTDIR\\*", 0, del_fn, cli);
4248 cli_list(cli, "\\LISTDIR\\*", aDIR, del_fn, cli);
4249 cli_rmdir(cli, "\\LISTDIR");
4250 cli_mkdir(cli, "\\LISTDIR");
4252 /* Create 1000 files and 1000 directories. */
4253 for (i=0;i<1000;i++) {
4255 slprintf(fname, sizeof(fname), "\\LISTDIR\\f%d", i);
4256 fnum = cli_nt_create_full(cli, fname, 0, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
4257 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0);
4259 fprintf(stderr,"Failed to open %s\n", fname);
4262 cli_close(cli, fnum);
4264 for (i=0;i<1000;i++) {
4266 slprintf(fname, sizeof(fname), "\\LISTDIR\\d%d", i);
4267 if (!cli_mkdir(cli, fname)) {
4268 fprintf(stderr,"Failed to open %s\n", fname);
4273 /* Now ensure that doing an old list sees both files and directories. */
4274 num_seen = cli_list_old(cli, "\\LISTDIR\\*", aDIR, list_fn, NULL);
4275 printf("num_seen = %d\n", num_seen );
4276 /* We should see 100 files + 1000 directories + . and .. */
4277 if (num_seen != 2002)
4280 /* Ensure if we have the "must have" bits we only see the
4283 num_seen = cli_list_old(cli, "\\LISTDIR\\*", (aDIR<<8)|aDIR, list_fn, NULL);
4284 printf("num_seen = %d\n", num_seen );
4285 if (num_seen != 1002)
4288 num_seen = cli_list_old(cli, "\\LISTDIR\\*", (aARCH<<8)|aDIR, list_fn, NULL);
4289 printf("num_seen = %d\n", num_seen );
4290 if (num_seen != 1000)
4293 /* Delete everything. */
4294 cli_list(cli, "\\LISTDIR\\*", 0, del_fn, cli);
4295 cli_list(cli, "\\LISTDIR\\*", aDIR, del_fn, cli);
4296 cli_rmdir(cli, "\\LISTDIR");
4299 printf("Matched %d\n", cli_list(cli, "a*.*", 0, list_fn, NULL));
4300 printf("Matched %d\n", cli_list(cli, "b*.*", 0, list_fn, NULL));
4301 printf("Matched %d\n", cli_list(cli, "xyzabc", 0, list_fn, NULL));
4304 if (!torture_close_connection(cli)) {
4308 printf("finished dirtest1\n");
4313 static BOOL run_error_map_extract(int dummy) {
4315 static struct cli_state c_dos;
4316 static struct cli_state c_nt;
4320 uint32 flgs2, errnum;
4327 /* NT-Error connection */
4329 if (!open_nbt_connection(&c_nt)) {
4333 c_nt.use_spnego = False;
4335 if (!cli_negprot(&c_nt)) {
4336 printf("%s rejected the NT-error negprot (%s)\n",host, cli_errstr(&c_nt));
4337 cli_shutdown(&c_nt);
4341 if (!cli_session_setup(&c_nt, "", "", 0, "", 0,
4343 printf("%s rejected the NT-error initial session setup (%s)\n",host, cli_errstr(&c_nt));
4347 /* DOS-Error connection */
4349 if (!open_nbt_connection(&c_dos)) {
4353 c_dos.use_spnego = False;
4354 c_dos.force_dos_errors = True;
4356 if (!cli_negprot(&c_dos)) {
4357 printf("%s rejected the DOS-error negprot (%s)\n",host, cli_errstr(&c_dos));
4358 cli_shutdown(&c_dos);
4362 if (!cli_session_setup(&c_dos, "", "", 0, "", 0,
4364 printf("%s rejected the DOS-error initial session setup (%s)\n",host, cli_errstr(&c_dos));
4368 for (error=(0xc0000000 | 0x1); error < (0xc0000000| 0xFFF); error++) {
4369 fstr_sprintf(user, "%X", error);
4371 if (cli_session_setup(&c_nt, user,
4372 password, strlen(password),
4373 password, strlen(password),
4375 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
4378 flgs2 = SVAL(c_nt.inbuf,smb_flg2);
4380 /* Case #1: 32-bit NT errors */
4381 if (flgs2 & FLAGS2_32_BIT_ERROR_CODES) {
4382 nt_status = NT_STATUS(IVAL(c_nt.inbuf,smb_rcls));
4384 printf("/** Dos error on NT connection! (%s) */\n",
4386 nt_status = NT_STATUS(0xc0000000);
4389 if (cli_session_setup(&c_dos, user,
4390 password, strlen(password),
4391 password, strlen(password),
4393 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
4395 flgs2 = SVAL(c_dos.inbuf,smb_flg2), errnum;
4397 /* Case #1: 32-bit NT errors */
4398 if (flgs2 & FLAGS2_32_BIT_ERROR_CODES) {
4399 printf("/** NT error on DOS connection! (%s) */\n",
4401 errnum = errclass = 0;
4403 cli_dos_error(&c_dos, &errclass, &errnum);
4406 if (NT_STATUS_V(nt_status) != error) {
4407 printf("/*\t{ This NT error code was 'sqashed'\n\t from %s to %s \n\t during the session setup }\n*/\n",
4408 get_nt_error_c_code(NT_STATUS(error)),
4409 get_nt_error_c_code(nt_status));
4412 printf("\t{%s,\t%s,\t%s},\n",
4413 smb_dos_err_class(errclass),
4414 smb_dos_err_name(errclass, errnum),
4415 get_nt_error_c_code(NT_STATUS(error)));
4420 static double create_procs(BOOL (*fn)(int), BOOL *result)
4423 volatile pid_t *child_status;
4424 volatile BOOL *child_status_out;
4430 child_status = (volatile pid_t *)shm_setup(sizeof(pid_t)*nprocs);
4431 if (!child_status) {
4432 printf("Failed to setup shared memory\n");
4436 child_status_out = (volatile BOOL *)shm_setup(sizeof(BOOL)*nprocs);
4437 if (!child_status_out) {
4438 printf("Failed to setup result status shared memory\n");
4442 for (i = 0; i < nprocs; i++) {
4443 child_status[i] = 0;
4444 child_status_out[i] = True;
4449 for (i=0;i<nprocs;i++) {
4452 pid_t mypid = getpid();
4453 sys_srandom(((int)mypid) ^ ((int)time(NULL)));
4455 slprintf(myname,sizeof(myname),"CLIENT%d", i);
4458 if (torture_open_connection(¤t_cli)) break;
4460 printf("pid %d failed to start\n", (int)getpid());
4466 child_status[i] = getpid();
4468 while (child_status[i] && end_timer() < 5) msleep(2);
4470 child_status_out[i] = fn(i);
4477 for (i=0;i<nprocs;i++) {
4478 if (child_status[i]) synccount++;
4480 if (synccount == nprocs) break;
4482 } while (end_timer() < 30);
4484 if (synccount != nprocs) {
4485 printf("FAILED TO START %d CLIENTS (started %d)\n", nprocs, synccount);
4490 /* start the client load */
4493 for (i=0;i<nprocs;i++) {
4494 child_status[i] = 0;
4497 printf("%d clients started\n", nprocs);
4499 for (i=0;i<nprocs;i++) {
4500 while (waitpid(0, &status, 0) == -1 && errno == EINTR) /* noop */ ;
4505 for (i=0;i<nprocs;i++) {
4506 if (!child_status_out[i]) {
4513 #define FLAG_MULTIPROC 1
4520 {"FDPASS", run_fdpasstest, 0},
4521 {"LOCK1", run_locktest1, 0},
4522 {"LOCK2", run_locktest2, 0},
4523 {"LOCK3", run_locktest3, 0},
4524 {"LOCK4", run_locktest4, 0},
4525 {"LOCK5", run_locktest5, 0},
4526 {"LOCK6", run_locktest6, 0},
4527 {"LOCK7", run_locktest7, 0},
4528 {"UNLINK", run_unlinktest, 0},
4529 {"BROWSE", run_browsetest, 0},
4530 {"ATTR", run_attrtest, 0},
4531 {"TRANS2", run_trans2test, 0},
4532 {"MAXFID", run_maxfidtest, FLAG_MULTIPROC},
4533 {"TORTURE",run_torture, FLAG_MULTIPROC},
4534 {"RANDOMIPC", run_randomipc, 0},
4535 {"NEGNOWAIT", run_negprot_nowait, 0},
4536 {"NBENCH", run_nbench, 0},
4537 {"OPLOCK1", run_oplock1, 0},
4538 {"OPLOCK2", run_oplock2, 0},
4539 {"OPLOCK3", run_oplock3, 0},
4540 {"DIR", run_dirtest, 0},
4541 {"DIR1", run_dirtest1, 0},
4542 {"DENY1", torture_denytest1, 0},
4543 {"DENY2", torture_denytest2, 0},
4544 {"TCON", run_tcon_test, 0},
4545 {"TCONDEV", run_tcon_devtype_test, 0},
4546 {"RW1", run_readwritetest, 0},
4547 {"RW2", run_readwritemulti, FLAG_MULTIPROC},
4548 {"RW3", run_readwritelarge, 0},
4549 {"OPEN", run_opentest, 0},
4551 {"OPENATTR", run_openattrtest, 0},
4553 {"XCOPY", run_xcopy, 0},
4554 {"RENAME", run_rename, 0},
4555 {"DELETE", run_deletetest, 0},
4556 {"PROPERTIES", run_properties, 0},
4557 {"MANGLE", torture_mangle, 0},
4558 {"W2K", run_w2ktest, 0},
4559 {"TRANS2SCAN", torture_trans2_scan, 0},
4560 {"NTTRANSSCAN", torture_nttrans_scan, 0},
4561 {"UTABLE", torture_utable, 0},
4562 {"CASETABLE", torture_casetable, 0},
4563 {"ERRMAPEXTRACT", run_error_map_extract, 0},
4564 {"PIPE_NUMBER", run_pipe_number, 0},
4565 {"TCON2", run_tcon2_test, 0},
4566 {"IOCTL", torture_ioctl_test, 0},
4567 {"CHKPATH", torture_chkpath_test, 0},
4568 {"FDSESS", run_fdsesstest, 0},
4573 /****************************************************************************
4574 run a specified test or "ALL"
4575 ****************************************************************************/
4576 static BOOL run_test(const char *name)
4582 if (strequal(name,"ALL")) {
4583 for (i=0;torture_ops[i].name;i++) {
4584 run_test(torture_ops[i].name);
4588 for (i=0;torture_ops[i].name;i++) {
4589 fstr_sprintf(randomfname, "\\XX%x",
4590 (unsigned)random());
4592 if (strequal(name, torture_ops[i].name)) {
4593 printf("Running %s\n", name);
4594 if (torture_ops[i].flags & FLAG_MULTIPROC) {
4595 t = create_procs(torture_ops[i].fn, &result);
4598 printf("TEST %s FAILED!\n", name);
4603 if (!torture_ops[i].fn(0)) {
4605 printf("TEST %s FAILED!\n", name);
4609 printf("%s took %g secs\n\n", name, t);
4616 static void usage(void)
4620 printf("Usage: smbtorture //server/share <options> TEST1 TEST2 ...\n");
4622 printf("\t-d debuglevel\n");
4623 printf("\t-U user%%pass\n");
4624 printf("\t-k use kerberos\n");
4625 printf("\t-N numprocs\n");
4626 printf("\t-n my_netbios_name\n");
4627 printf("\t-W workgroup\n");
4628 printf("\t-o num_operations\n");
4629 printf("\t-O socket_options\n");
4630 printf("\t-m maximum protocol\n");
4631 printf("\t-L use oplocks\n");
4632 printf("\t-c CLIENT.TXT specify client load file for NBENCH\n");
4633 printf("\t-A showall\n");
4634 printf("\t-p port\n");
4635 printf("\t-s seed\n");
4638 printf("tests are:");
4639 for (i=0;torture_ops[i].name;i++) {
4640 printf(" %s", torture_ops[i].name);
4644 printf("default test is ALL\n");
4649 /****************************************************************************
4651 ****************************************************************************/
4652 int main(int argc,char *argv[])
4658 extern char *optarg;
4660 BOOL correct = True;
4664 #ifdef HAVE_SETBUFFER
4665 setbuffer(stdout, NULL, 0);
4668 lp_load(dyn_CONFIGFILE,True,False,False);
4675 for(p = argv[1]; *p; p++)
4679 if (strncmp(argv[1], "//", 2)) {
4683 fstrcpy(host, &argv[1][2]);
4684 p = strchr_m(&host[2],'/');
4689 fstrcpy(share, p+1);
4693 if (*username == 0 && getenv("LOGNAME")) {
4694 fstrcpy(username,getenv("LOGNAME"));
4700 srandom(time(NULL));
4702 fstrcpy(workgroup, lp_workgroup());
4704 while ((opt = getopt(argc, argv, "p:hW:U:n:N:O:o:m:Ld:Ac:ks:")) != EOF) {
4707 port_to_use = atoi(optarg);
4710 srandom(atoi(optarg));
4713 fstrcpy(workgroup,optarg);
4716 max_protocol = interpret_protocol(optarg, max_protocol);
4719 nprocs = atoi(optarg);
4722 torture_numops = atoi(optarg);
4725 DEBUGLEVEL = atoi(optarg);
4734 torture_showall = True;
4737 fstrcpy(myname, optarg);
4740 client_txt = optarg;
4744 use_kerberos = True;
4746 d_printf("No kerberos support compiled in\n");
4752 fstrcpy(username,optarg);
4753 p = strchr_m(username,'%');
4756 fstrcpy(password, p+1);
4761 printf("Unknown option %c (%d)\n", (char)opt, opt);
4766 if(use_kerberos && !gotuser) gotpass = True;
4769 p = getpass("Password:");
4771 fstrcpy(password, p);
4776 printf("host=%s share=%s user=%s myname=%s\n",
4777 host, share, username, myname);
4780 correct = run_test("ALL");
4782 for (i=1;i<argc;i++) {
4783 if (!run_test(argv[i])) {