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 #include "module_dummy.h"
27 static fstring host, workgroup, share, password, username, myname;
28 static int max_protocol = PROTOCOL_NT1;
29 static const char *sockops="TCP_NODELAY";
31 static int port_to_use=0;
32 int torture_numops=100;
33 static int procnum; /* records process count number when forking */
34 static struct cli_state *current_cli;
35 static fstring randomfname;
36 static BOOL use_oplocks;
37 static BOOL use_level_II_oplocks;
38 static const char *client_txt = "client_oplocks.txt";
39 static BOOL use_kerberos;
41 BOOL torture_showall = False;
43 static double create_procs(BOOL (*fn)(int), BOOL *result);
46 static struct timeval tp1,tp2;
48 void start_timer(void)
50 gettimeofday(&tp1,NULL);
53 double end_timer(void)
55 gettimeofday(&tp2,NULL);
56 return((tp2.tv_sec - tp1.tv_sec) +
57 (tp2.tv_usec - tp1.tv_usec)*1.0e-6);
61 /* return a pointer to a anonymous shared memory segment of size "size"
62 which will persist across fork() but will disappear when all processes
65 The memory is not zeroed
67 This function uses system5 shared memory. It takes advantage of a property
68 that the memory is not destroyed if it is attached when the id is removed
70 void *shm_setup(int size)
75 shmid = shmget(IPC_PRIVATE, size, SHM_R | SHM_W);
77 printf("can't get shared memory\n");
80 ret = (void *)shmat(shmid, 0, 0);
81 if (!ret || ret == (void *)-1) {
82 printf("can't attach to shared memory\n");
85 /* the following releases the ipc, but note that this process
86 and all its children will still have access to the memory, its
87 just that the shmid is no longer valid for other shm calls. This
88 means we don't leave behind lots of shm segments after we exit
90 See Stevens "advanced programming in unix env" for details
92 shmctl(shmid, IPC_RMID, 0);
98 static BOOL open_nbt_connection(struct cli_state *c)
100 struct nmb_name called, calling;
105 make_nmb_name(&calling, myname, 0x0);
106 make_nmb_name(&called , host, 0x20);
110 if (!cli_initialise(c)) {
111 printf("Failed initialize cli_struct to connect with %s\n", host);
115 c->port = port_to_use;
117 if (!cli_connect(c, host, &ip)) {
118 printf("Failed to connect with %s\n", host);
122 c->use_kerberos = use_kerberos;
124 c->timeout = 120000; /* set a really long timeout (2 minutes) */
125 if (use_oplocks) c->use_oplocks = True;
126 if (use_level_II_oplocks) c->use_level_II_oplocks = True;
128 if (!cli_session_request(c, &calling, &called)) {
130 * Well, that failed, try *SMBSERVER ...
131 * However, we must reconnect as well ...
133 if (!cli_connect(c, host, &ip)) {
134 printf("Failed to connect with %s\n", host);
138 make_nmb_name(&called, "*SMBSERVER", 0x20);
139 if (!cli_session_request(c, &calling, &called)) {
140 printf("%s rejected the session\n",host);
141 printf("We tried with a called name of %s & %s\n",
151 BOOL torture_open_connection(struct cli_state **c)
158 flags |= CLI_FULL_CONNECTION_USE_KERBEROS;
160 status = cli_full_connection(c, myname,
161 host, NULL, port_to_use,
164 password, flags, &retry);
165 if (!NT_STATUS_IS_OK(status)) {
169 if (use_oplocks) (*c)->use_oplocks = True;
170 if (use_level_II_oplocks) (*c)->use_level_II_oplocks = True;
171 (*c)->timeout = 120000; /* set a really long timeout (2 minutes) */
176 BOOL torture_cli_session_setup2(struct cli_state *cli, uint16 *new_vuid)
178 uint16 old_vuid = cli->vuid;
179 fstring old_user_name;
180 size_t passlen = strlen(password);
183 fstrcpy(old_user_name, cli->user_name);
185 ret = cli_session_setup(cli, username, password, passlen, password, passlen, workgroup);
186 *new_vuid = cli->vuid;
187 cli->vuid = old_vuid;
188 fstrcpy(cli->user_name, old_user_name);
193 BOOL torture_close_connection(struct cli_state *c)
197 printf("tdis failed (%s)\n", cli_errstr(c));
207 /* check if the server produced the expected error code */
208 static BOOL check_error(int line, struct cli_state *c,
209 uint8 eclass, uint32 ecode, NTSTATUS nterr)
211 if (cli_is_dos_error(c)) {
215 /* Check DOS error */
217 cli_dos_error(c, &class, &num);
219 if (eclass != class || ecode != num) {
220 printf("unexpected error code class=%d code=%d\n",
221 (int)class, (int)num);
222 printf(" expected %d/%d %s (line=%d)\n",
223 (int)eclass, (int)ecode, nt_errstr(nterr), line);
232 status = cli_nt_error(c);
234 if (NT_STATUS_V(nterr) != NT_STATUS_V(status)) {
235 printf("unexpected error code %s\n", nt_errstr(status));
236 printf(" expected %s (line=%d)\n", nt_errstr(nterr), line);
245 static BOOL wait_lock(struct cli_state *c, int fnum, uint32 offset, uint32 len)
247 while (!cli_lock(c, fnum, offset, len, -1, WRITE_LOCK)) {
248 if (!check_error(__LINE__, c, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False;
254 static BOOL rw_torture(struct cli_state *c)
256 const char *lockfname = "\\torture.lck";
260 pid_t pid2, pid = getpid();
265 fnum2 = cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
268 fnum2 = cli_open(c, lockfname, O_RDWR, DENY_NONE);
270 printf("open of %s failed (%s)\n", lockfname, cli_errstr(c));
275 for (i=0;i<torture_numops;i++) {
276 unsigned n = (unsigned)sys_random()%10;
278 printf("%d\r", i); fflush(stdout);
280 slprintf(fname, sizeof(fstring) - 1, "\\torture.%u", n);
282 if (!wait_lock(c, fnum2, n*sizeof(int), sizeof(int))) {
286 fnum = cli_open(c, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_ALL);
288 printf("open failed (%s)\n", cli_errstr(c));
293 if (cli_write(c, fnum, 0, (char *)&pid, 0, sizeof(pid)) != sizeof(pid)) {
294 printf("write failed (%s)\n", cli_errstr(c));
299 if (cli_write(c, fnum, 0, (char *)buf,
300 sizeof(pid)+(j*sizeof(buf)),
301 sizeof(buf)) != sizeof(buf)) {
302 printf("write failed (%s)\n", cli_errstr(c));
309 if (cli_read(c, fnum, (char *)&pid2, 0, sizeof(pid)) != sizeof(pid)) {
310 printf("read failed (%s)\n", cli_errstr(c));
315 printf("data corruption!\n");
319 if (!cli_close(c, fnum)) {
320 printf("close failed (%s)\n", cli_errstr(c));
324 if (!cli_unlink(c, fname)) {
325 printf("unlink failed (%s)\n", cli_errstr(c));
329 if (!cli_unlock(c, fnum2, n*sizeof(int), sizeof(int))) {
330 printf("unlock failed (%s)\n", cli_errstr(c));
336 cli_unlink(c, lockfname);
343 static BOOL run_torture(int dummy)
345 struct cli_state *cli;
350 cli_sockopt(cli, sockops);
352 ret = rw_torture(cli);
354 if (!torture_close_connection(cli)) {
361 static BOOL rw_torture3(struct cli_state *c, char *lockfname)
368 unsigned countprev = 0;
373 for (i = 0; i < sizeof(buf); i += sizeof(uint32))
375 SIVAL(buf, i, sys_random());
380 fnum = cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
383 printf("first open read/write of %s failed (%s)\n",
384 lockfname, cli_errstr(c));
390 for (i = 0; i < 500 && fnum == -1; i++)
392 fnum = cli_open(c, lockfname, O_RDONLY,
397 printf("second open read-only of %s failed (%s)\n",
398 lockfname, cli_errstr(c));
404 for (count = 0; count < sizeof(buf); count += sent)
406 if (count >= countprev) {
407 printf("%d %8d\r", i, count);
410 countprev += (sizeof(buf) / 20);
415 sent = ((unsigned)sys_random()%(20))+ 1;
416 if (sent > sizeof(buf) - count)
418 sent = sizeof(buf) - count;
421 if (cli_write(c, fnum, 0, buf+count, count, (size_t)sent) != sent) {
422 printf("write failed (%s)\n", cli_errstr(c));
428 sent = cli_read(c, fnum, buf_rd+count, count,
432 printf("read failed offset:%d size:%d (%s)\n",
433 count, sizeof(buf)-count,
440 if (memcmp(buf_rd+count, buf+count, sent) != 0)
442 printf("read/write compare failed\n");
443 printf("offset: %d req %d recvd %d\n",
444 count, sizeof(buf)-count, sent);
453 if (!cli_close(c, fnum)) {
454 printf("close failed (%s)\n", cli_errstr(c));
461 static BOOL rw_torture2(struct cli_state *c1, struct cli_state *c2)
463 const char *lockfname = "\\torture2.lck";
468 uchar buf_rd[131072];
472 if (!cli_unlink(c1, lockfname)) {
473 printf("unlink failed (%s) (normal, this file should not exist)\n", cli_errstr(c1));
476 fnum1 = cli_open(c1, lockfname, O_RDWR | O_CREAT | O_EXCL,
479 printf("first open read/write of %s failed (%s)\n",
480 lockfname, cli_errstr(c1));
483 fnum2 = cli_open(c2, lockfname, O_RDONLY,
486 printf("second open read-only of %s failed (%s)\n",
487 lockfname, cli_errstr(c2));
488 cli_close(c1, fnum1);
492 for (i=0;i<torture_numops;i++)
494 size_t buf_size = ((unsigned)sys_random()%(sizeof(buf)-1))+ 1;
496 printf("%d\r", i); fflush(stdout);
499 generate_random_buffer(buf, buf_size, False);
501 if (cli_write(c1, fnum1, 0, buf, 0, buf_size) != buf_size) {
502 printf("write failed (%s)\n", cli_errstr(c1));
507 if ((bytes_read = cli_read(c2, fnum2, buf_rd, 0, buf_size)) != buf_size) {
508 printf("read failed (%s)\n", cli_errstr(c2));
509 printf("read %d, expected %d\n", bytes_read, buf_size);
514 if (memcmp(buf_rd, buf, buf_size) != 0)
516 printf("read/write compare failed\n");
522 if (!cli_close(c2, fnum2)) {
523 printf("close failed (%s)\n", cli_errstr(c2));
526 if (!cli_close(c1, fnum1)) {
527 printf("close failed (%s)\n", cli_errstr(c1));
531 if (!cli_unlink(c1, lockfname)) {
532 printf("unlink failed (%s)\n", cli_errstr(c1));
539 static BOOL run_readwritetest(int dummy)
541 static struct cli_state *cli1, *cli2;
544 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
547 cli_sockopt(cli1, sockops);
548 cli_sockopt(cli2, sockops);
550 printf("starting readwritetest\n");
552 test1 = rw_torture2(cli1, cli2);
553 printf("Passed readwritetest v1: %s\n", BOOLSTR(test1));
556 test2 = rw_torture2(cli1, cli1);
557 printf("Passed readwritetest v2: %s\n", BOOLSTR(test2));
560 if (!torture_close_connection(cli1)) {
564 if (!torture_close_connection(cli2)) {
568 return (test1 && test2);
571 static BOOL run_readwritemulti(int dummy)
573 struct cli_state *cli;
578 cli_sockopt(cli, sockops);
580 printf("run_readwritemulti: fname %s\n", randomfname);
581 test = rw_torture3(cli, randomfname);
583 if (!torture_close_connection(cli)) {
590 static BOOL run_readwritelarge(int dummy)
592 static struct cli_state *cli1;
594 const char *lockfname = "\\large.dat";
599 if (!torture_open_connection(&cli1)) {
602 cli_sockopt(cli1, sockops);
603 memset(buf,'\0',sizeof(buf));
605 cli1->max_xmit = 128*1024;
607 printf("starting readwritelarge\n");
609 cli_unlink(cli1, lockfname);
611 fnum1 = cli_open(cli1, lockfname, O_RDWR | O_CREAT | O_EXCL, DENY_NONE);
613 printf("open read/write of %s failed (%s)\n", lockfname, cli_errstr(cli1));
617 cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf));
619 if (!cli_qfileinfo(cli1, fnum1, NULL, &fsize, NULL, NULL, NULL, NULL, NULL)) {
620 printf("qfileinfo failed (%s)\n", cli_errstr(cli1));
624 if (fsize == sizeof(buf))
625 printf("readwritelarge test 1 succeeded (size = %x)\n", fsize);
627 printf("readwritelarge test 1 failed (size = %x)\n", fsize);
631 if (!cli_close(cli1, fnum1)) {
632 printf("close failed (%s)\n", cli_errstr(cli1));
636 if (!cli_unlink(cli1, lockfname)) {
637 printf("unlink failed (%s)\n", cli_errstr(cli1));
641 fnum1 = cli_open(cli1, lockfname, O_RDWR | O_CREAT | O_EXCL, DENY_NONE);
643 printf("open read/write of %s failed (%s)\n", lockfname, cli_errstr(cli1));
647 cli1->max_xmit = 4*1024;
649 cli_smbwrite(cli1, fnum1, buf, 0, sizeof(buf));
651 if (!cli_qfileinfo(cli1, fnum1, NULL, &fsize, NULL, NULL, NULL, NULL, NULL)) {
652 printf("qfileinfo failed (%s)\n", cli_errstr(cli1));
656 if (fsize == sizeof(buf))
657 printf("readwritelarge test 2 succeeded (size = %x)\n", fsize);
659 printf("readwritelarge test 2 failed (size = %x)\n", fsize);
664 /* ToDo - set allocation. JRA */
665 if(!cli_set_allocation_size(cli1, fnum1, 0)) {
666 printf("set allocation size to zero failed (%s)\n", cli_errstr(&cli1));
669 if (!cli_qfileinfo(cli1, fnum1, NULL, &fsize, NULL, NULL, NULL, NULL, NULL)) {
670 printf("qfileinfo failed (%s)\n", cli_errstr(cli1));
674 printf("readwritelarge test 3 (truncate test) succeeded (size = %x)\n", fsize);
677 if (!cli_close(cli1, fnum1)) {
678 printf("close failed (%s)\n", cli_errstr(cli1));
682 if (!torture_close_connection(cli1)) {
691 #define ival(s) strtol(s, NULL, 0)
693 /* run a test that simulates an approximate netbench client load */
694 static BOOL run_netbench(int client)
696 struct cli_state *cli;
702 const char *params[20];
709 cli_sockopt(cli, sockops);
713 slprintf(cname,sizeof(fname), "client%d", client);
715 f = fopen(client_txt, "r");
722 while (fgets(line, sizeof(line)-1, f)) {
725 line[strlen(line)-1] = 0;
727 /* printf("[%d] %s\n", line_count, line); */
729 all_string_sub(line,"client1", cname, sizeof(line));
731 /* parse the command parameters */
732 params[0] = strtok(line," ");
734 while (params[i]) params[++i] = strtok(NULL," ");
740 if (!strncmp(params[0],"SMB", 3)) {
741 printf("ERROR: You are using a dbench 1 load file\n");
745 if (!strcmp(params[0],"NTCreateX")) {
746 nb_createx(params[1], ival(params[2]), ival(params[3]),
748 } else if (!strcmp(params[0],"Close")) {
749 nb_close(ival(params[1]));
750 } else if (!strcmp(params[0],"Rename")) {
751 nb_rename(params[1], params[2]);
752 } else if (!strcmp(params[0],"Unlink")) {
753 nb_unlink(params[1]);
754 } else if (!strcmp(params[0],"Deltree")) {
755 nb_deltree(params[1]);
756 } else if (!strcmp(params[0],"Rmdir")) {
758 } else if (!strcmp(params[0],"QUERY_PATH_INFORMATION")) {
759 nb_qpathinfo(params[1]);
760 } else if (!strcmp(params[0],"QUERY_FILE_INFORMATION")) {
761 nb_qfileinfo(ival(params[1]));
762 } else if (!strcmp(params[0],"QUERY_FS_INFORMATION")) {
763 nb_qfsinfo(ival(params[1]));
764 } else if (!strcmp(params[0],"FIND_FIRST")) {
765 nb_findfirst(params[1]);
766 } else if (!strcmp(params[0],"WriteX")) {
767 nb_writex(ival(params[1]),
768 ival(params[2]), ival(params[3]), ival(params[4]));
769 } else if (!strcmp(params[0],"ReadX")) {
770 nb_readx(ival(params[1]),
771 ival(params[2]), ival(params[3]), ival(params[4]));
772 } else if (!strcmp(params[0],"Flush")) {
773 nb_flush(ival(params[1]));
775 printf("Unknown operation %s\n", params[0]);
783 if (!torture_close_connection(cli)) {
791 /* run a test that simulates an approximate netbench client load */
792 static BOOL run_nbench(int dummy)
801 signal(SIGALRM, nb_alarm);
803 t = create_procs(run_netbench, &correct);
806 printf("\nThroughput %g MB/sec\n",
807 1.0e-6 * nbio_total() / t);
813 This test checks for two things:
815 1) correct support for retaining locks over a close (ie. the server
816 must not use posix semantics)
817 2) support for lock timeouts
819 static BOOL run_locktest1(int dummy)
821 struct cli_state *cli1, *cli2;
822 const char *fname = "\\lockt1.lck";
823 int fnum1, fnum2, fnum3;
825 unsigned lock_timeout;
827 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
830 cli_sockopt(cli1, sockops);
831 cli_sockopt(cli2, sockops);
833 printf("starting locktest1\n");
835 cli_unlink(cli1, fname);
837 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
839 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
842 fnum2 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
844 printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli1));
847 fnum3 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
849 printf("open3 of %s failed (%s)\n", fname, cli_errstr(cli2));
853 if (!cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK)) {
854 printf("lock1 failed (%s)\n", cli_errstr(cli1));
859 if (cli_lock(cli2, fnum3, 0, 4, 0, WRITE_LOCK)) {
860 printf("lock2 succeeded! This is a locking bug\n");
863 if (!check_error(__LINE__, cli2, ERRDOS, ERRlock,
864 NT_STATUS_LOCK_NOT_GRANTED)) return False;
868 lock_timeout = (1 + (random() % 20));
869 printf("Testing lock timeout with timeout=%u\n", lock_timeout);
871 if (cli_lock(cli2, fnum3, 0, 4, lock_timeout * 1000, WRITE_LOCK)) {
872 printf("lock3 succeeded! This is a locking bug\n");
875 if (!check_error(__LINE__, cli2, ERRDOS, ERRlock,
876 NT_STATUS_FILE_LOCK_CONFLICT)) return False;
881 printf("error: This server appears not to support timed lock requests\n");
883 printf("server slept for %u seconds for a %u second timeout\n",
884 (unsigned int)(t2-t1), lock_timeout);
886 if (!cli_close(cli1, fnum2)) {
887 printf("close1 failed (%s)\n", cli_errstr(cli1));
891 if (cli_lock(cli2, fnum3, 0, 4, 0, WRITE_LOCK)) {
892 printf("lock4 succeeded! This is a locking bug\n");
895 if (!check_error(__LINE__, cli2, ERRDOS, ERRlock,
896 NT_STATUS_FILE_LOCK_CONFLICT)) return False;
899 if (!cli_close(cli1, fnum1)) {
900 printf("close2 failed (%s)\n", cli_errstr(cli1));
904 if (!cli_close(cli2, fnum3)) {
905 printf("close3 failed (%s)\n", cli_errstr(cli2));
909 if (!cli_unlink(cli1, fname)) {
910 printf("unlink failed (%s)\n", cli_errstr(cli1));
915 if (!torture_close_connection(cli1)) {
919 if (!torture_close_connection(cli2)) {
923 printf("Passed locktest1\n");
928 this checks to see if a secondary tconx can use open files from an
931 static BOOL run_tcon_test(int dummy)
933 static struct cli_state *cli;
934 const char *fname = "\\tcontest.tmp";
936 uint16 cnum1, cnum2, cnum3;
941 if (!torture_open_connection(&cli)) {
944 cli_sockopt(cli, sockops);
946 printf("starting tcontest\n");
948 cli_unlink(cli, fname);
950 fnum1 = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
952 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
959 if (cli_write(cli, fnum1, 0, buf, 130, 4) != 4) {
960 printf("initial write failed (%s)", cli_errstr(cli));
964 if (!cli_send_tconX(cli, share, "?????",
965 password, strlen(password)+1)) {
966 printf("%s refused 2nd tree connect (%s)\n", host,
973 cnum3 = MAX(cnum1, cnum2) + 1; /* any invalid number */
974 vuid2 = cli->vuid + 1;
976 /* try a write with the wrong tid */
979 if (cli_write(cli, fnum1, 0, buf, 130, 4) == 4) {
980 printf("* server allows write with wrong TID\n");
983 printf("server fails write with wrong TID : %s\n", cli_errstr(cli));
987 /* try a write with an invalid tid */
990 if (cli_write(cli, fnum1, 0, buf, 130, 4) == 4) {
991 printf("* server allows write with invalid TID\n");
994 printf("server fails write with invalid TID : %s\n", cli_errstr(cli));
997 /* try a write with an invalid vuid */
1001 if (cli_write(cli, fnum1, 0, buf, 130, 4) == 4) {
1002 printf("* server allows write with invalid VUID\n");
1005 printf("server fails write with invalid VUID : %s\n", cli_errstr(cli));
1011 if (!cli_close(cli, fnum1)) {
1012 printf("close failed (%s)\n", cli_errstr(cli));
1018 if (!cli_tdis(cli)) {
1019 printf("secondary tdis failed (%s)\n", cli_errstr(cli));
1025 if (!torture_close_connection(cli)) {
1034 checks for old style tcon support
1036 static BOOL run_tcon2_test(int dummy)
1038 static struct cli_state *cli;
1039 uint16 cnum, max_xmit;
1043 if (!torture_open_connection(&cli)) {
1046 cli_sockopt(cli, sockops);
1048 printf("starting tcon2 test\n");
1050 asprintf(&service, "\\\\%s\\%s", host, share);
1052 status = cli_raw_tcon(cli, service, password, "?????", &max_xmit, &cnum);
1054 if (!NT_STATUS_IS_OK(status)) {
1055 printf("tcon2 failed : %s\n", cli_errstr(cli));
1057 printf("tcon OK : max_xmit=%d cnum=%d tid=%d\n",
1058 (int)max_xmit, (int)cnum, SVAL(cli->inbuf, smb_tid));
1061 if (!torture_close_connection(cli)) {
1065 printf("Passed tcon2 test\n");
1069 static BOOL tcon_devtest(struct cli_state *cli,
1070 const char *myshare, const char *devtype,
1071 const char *return_devtype,
1072 NTSTATUS expected_error)
1077 status = cli_send_tconX(cli, myshare, devtype,
1078 password, strlen(password)+1);
1080 if (NT_STATUS_IS_OK(expected_error)) {
1082 if (strcmp(cli->dev, return_devtype) == 0) {
1085 printf("tconX to share %s with type %s "
1086 "succeeded but returned the wrong "
1087 "device type (got [%s] but should have got [%s])\n",
1088 myshare, devtype, cli->dev, return_devtype);
1092 printf("tconX to share %s with type %s "
1093 "should have succeeded but failed\n",
1100 printf("tconx to share %s with type %s "
1101 "should have failed but succeeded\n",
1105 if (NT_STATUS_EQUAL(cli_nt_error(cli),
1109 printf("Returned unexpected error\n");
1118 checks for correct tconX support
1120 static BOOL run_tcon_devtype_test(int dummy)
1122 static struct cli_state *cli1 = NULL;
1128 status = cli_full_connection(&cli1, myname,
1129 host, NULL, port_to_use,
1131 username, workgroup,
1132 password, flags, &retry);
1134 if (!NT_STATUS_IS_OK(status)) {
1135 printf("could not open connection\n");
1139 if (!tcon_devtest(cli1, "IPC$", "A:", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1142 if (!tcon_devtest(cli1, "IPC$", "?????", "IPC", NT_STATUS_OK))
1145 if (!tcon_devtest(cli1, "IPC$", "LPT:", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1148 if (!tcon_devtest(cli1, "IPC$", "IPC", "IPC", NT_STATUS_OK))
1151 if (!tcon_devtest(cli1, "IPC$", "FOOBA", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1154 if (!tcon_devtest(cli1, share, "A:", "A:", NT_STATUS_OK))
1157 if (!tcon_devtest(cli1, share, "?????", "A:", NT_STATUS_OK))
1160 if (!tcon_devtest(cli1, share, "LPT:", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1163 if (!tcon_devtest(cli1, share, "IPC", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1166 if (!tcon_devtest(cli1, share, "FOOBA", NULL, NT_STATUS_BAD_DEVICE_TYPE))
1172 printf("Passed tcondevtest\n");
1179 This test checks that
1181 1) the server supports multiple locking contexts on the one SMB
1182 connection, distinguished by PID.
1184 2) the server correctly fails overlapping locks made by the same PID (this
1185 goes against POSIX behaviour, which is why it is tricky to implement)
1187 3) the server denies unlock requests by an incorrect client PID
1189 static BOOL run_locktest2(int dummy)
1191 static struct cli_state *cli;
1192 const char *fname = "\\lockt2.lck";
1193 int fnum1, fnum2, fnum3;
1194 BOOL correct = True;
1196 if (!torture_open_connection(&cli)) {
1200 cli_sockopt(cli, sockops);
1202 printf("starting locktest2\n");
1204 cli_unlink(cli, fname);
1208 fnum1 = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1210 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
1214 fnum2 = cli_open(cli, fname, O_RDWR, DENY_NONE);
1216 printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli));
1222 fnum3 = cli_open(cli, fname, O_RDWR, DENY_NONE);
1224 printf("open3 of %s failed (%s)\n", fname, cli_errstr(cli));
1230 if (!cli_lock(cli, fnum1, 0, 4, 0, WRITE_LOCK)) {
1231 printf("lock1 failed (%s)\n", cli_errstr(cli));
1235 if (cli_lock(cli, fnum1, 0, 4, 0, WRITE_LOCK)) {
1236 printf("WRITE lock1 succeeded! This is a locking bug\n");
1239 if (!check_error(__LINE__, cli, ERRDOS, ERRlock,
1240 NT_STATUS_LOCK_NOT_GRANTED)) return False;
1243 if (cli_lock(cli, fnum2, 0, 4, 0, WRITE_LOCK)) {
1244 printf("WRITE lock2 succeeded! This is a locking bug\n");
1247 if (!check_error(__LINE__, cli, ERRDOS, ERRlock,
1248 NT_STATUS_LOCK_NOT_GRANTED)) return False;
1251 if (cli_lock(cli, fnum2, 0, 4, 0, READ_LOCK)) {
1252 printf("READ lock2 succeeded! This is a locking bug\n");
1255 if (!check_error(__LINE__, cli, ERRDOS, ERRlock,
1256 NT_STATUS_FILE_LOCK_CONFLICT)) return False;
1259 if (!cli_lock(cli, fnum1, 100, 4, 0, WRITE_LOCK)) {
1260 printf("lock at 100 failed (%s)\n", cli_errstr(cli));
1263 if (cli_unlock(cli, fnum1, 100, 4)) {
1264 printf("unlock at 100 succeeded! This is a locking bug\n");
1268 if (cli_unlock(cli, fnum1, 0, 4)) {
1269 printf("unlock1 succeeded! This is a locking bug\n");
1272 if (!check_error(__LINE__, cli,
1274 NT_STATUS_RANGE_NOT_LOCKED)) return False;
1277 if (cli_unlock(cli, fnum1, 0, 8)) {
1278 printf("unlock2 succeeded! This is a locking bug\n");
1281 if (!check_error(__LINE__, cli,
1283 NT_STATUS_RANGE_NOT_LOCKED)) return False;
1286 if (cli_lock(cli, fnum3, 0, 4, 0, WRITE_LOCK)) {
1287 printf("lock3 succeeded! This is a locking bug\n");
1290 if (!check_error(__LINE__, cli, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False;
1295 if (!cli_close(cli, fnum1)) {
1296 printf("close1 failed (%s)\n", cli_errstr(cli));
1300 if (!cli_close(cli, fnum2)) {
1301 printf("close2 failed (%s)\n", cli_errstr(cli));
1305 if (!cli_close(cli, fnum3)) {
1306 printf("close3 failed (%s)\n", cli_errstr(cli));
1310 if (!torture_close_connection(cli)) {
1314 printf("locktest2 finished\n");
1321 This test checks that
1323 1) the server supports the full offset range in lock requests
1325 static BOOL run_locktest3(int dummy)
1327 static struct cli_state *cli1, *cli2;
1328 const char *fname = "\\lockt3.lck";
1329 int fnum1, fnum2, i;
1331 BOOL correct = True;
1333 #define NEXT_OFFSET offset += (~(uint32)0) / torture_numops
1335 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
1338 cli_sockopt(cli1, sockops);
1339 cli_sockopt(cli2, sockops);
1341 printf("starting locktest3\n");
1343 cli_unlink(cli1, fname);
1345 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1347 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
1350 fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
1352 printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli2));
1356 for (offset=i=0;i<torture_numops;i++) {
1358 if (!cli_lock(cli1, fnum1, offset-1, 1, 0, WRITE_LOCK)) {
1359 printf("lock1 %d failed (%s)\n",
1365 if (!cli_lock(cli2, fnum2, offset-2, 1, 0, WRITE_LOCK)) {
1366 printf("lock2 %d failed (%s)\n",
1373 for (offset=i=0;i<torture_numops;i++) {
1376 if (cli_lock(cli1, fnum1, offset-2, 1, 0, WRITE_LOCK)) {
1377 printf("error: lock1 %d succeeded!\n", i);
1381 if (cli_lock(cli2, fnum2, offset-1, 1, 0, WRITE_LOCK)) {
1382 printf("error: lock2 %d succeeded!\n", i);
1386 if (cli_lock(cli1, fnum1, offset-1, 1, 0, WRITE_LOCK)) {
1387 printf("error: lock3 %d succeeded!\n", i);
1391 if (cli_lock(cli2, fnum2, offset-2, 1, 0, WRITE_LOCK)) {
1392 printf("error: lock4 %d succeeded!\n", i);
1397 for (offset=i=0;i<torture_numops;i++) {
1400 if (!cli_unlock(cli1, fnum1, offset-1, 1)) {
1401 printf("unlock1 %d failed (%s)\n",
1407 if (!cli_unlock(cli2, fnum2, offset-2, 1)) {
1408 printf("unlock2 %d failed (%s)\n",
1415 if (!cli_close(cli1, fnum1)) {
1416 printf("close1 failed (%s)\n", cli_errstr(cli1));
1420 if (!cli_close(cli2, fnum2)) {
1421 printf("close2 failed (%s)\n", cli_errstr(cli2));
1425 if (!cli_unlink(cli1, fname)) {
1426 printf("unlink failed (%s)\n", cli_errstr(cli1));
1430 if (!torture_close_connection(cli1)) {
1434 if (!torture_close_connection(cli2)) {
1438 printf("finished locktest3\n");
1443 #define EXPECTED(ret, v) if ((ret) != (v)) { \
1444 printf("** "); correct = False; \
1448 looks at overlapping locks
1450 static BOOL run_locktest4(int dummy)
1452 static struct cli_state *cli1, *cli2;
1453 const char *fname = "\\lockt4.lck";
1454 int fnum1, fnum2, f;
1457 BOOL correct = True;
1459 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
1463 cli_sockopt(cli1, sockops);
1464 cli_sockopt(cli2, sockops);
1466 printf("starting locktest4\n");
1468 cli_unlink(cli1, fname);
1470 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1471 fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
1473 memset(buf, 0, sizeof(buf));
1475 if (cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
1476 printf("Failed to create file\n");
1481 ret = cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK) &&
1482 cli_lock(cli1, fnum1, 2, 4, 0, WRITE_LOCK);
1483 EXPECTED(ret, False);
1484 printf("the same process %s set overlapping write locks\n", ret?"can":"cannot");
1486 ret = cli_lock(cli1, fnum1, 10, 4, 0, READ_LOCK) &&
1487 cli_lock(cli1, fnum1, 12, 4, 0, READ_LOCK);
1488 EXPECTED(ret, True);
1489 printf("the same process %s set overlapping read locks\n", ret?"can":"cannot");
1491 ret = cli_lock(cli1, fnum1, 20, 4, 0, WRITE_LOCK) &&
1492 cli_lock(cli2, fnum2, 22, 4, 0, WRITE_LOCK);
1493 EXPECTED(ret, False);
1494 printf("a different connection %s set overlapping write locks\n", ret?"can":"cannot");
1496 ret = cli_lock(cli1, fnum1, 30, 4, 0, READ_LOCK) &&
1497 cli_lock(cli2, fnum2, 32, 4, 0, READ_LOCK);
1498 EXPECTED(ret, True);
1499 printf("a different connection %s set overlapping read locks\n", ret?"can":"cannot");
1501 ret = (cli_setpid(cli1, 1), cli_lock(cli1, fnum1, 40, 4, 0, WRITE_LOCK)) &&
1502 (cli_setpid(cli1, 2), cli_lock(cli1, fnum1, 42, 4, 0, WRITE_LOCK));
1503 EXPECTED(ret, False);
1504 printf("a different pid %s set overlapping write locks\n", ret?"can":"cannot");
1506 ret = (cli_setpid(cli1, 1), cli_lock(cli1, fnum1, 50, 4, 0, READ_LOCK)) &&
1507 (cli_setpid(cli1, 2), cli_lock(cli1, fnum1, 52, 4, 0, READ_LOCK));
1508 EXPECTED(ret, True);
1509 printf("a different pid %s set overlapping read locks\n", ret?"can":"cannot");
1511 ret = cli_lock(cli1, fnum1, 60, 4, 0, READ_LOCK) &&
1512 cli_lock(cli1, fnum1, 60, 4, 0, READ_LOCK);
1513 EXPECTED(ret, True);
1514 printf("the same process %s set the same read lock twice\n", ret?"can":"cannot");
1516 ret = cli_lock(cli1, fnum1, 70, 4, 0, WRITE_LOCK) &&
1517 cli_lock(cli1, fnum1, 70, 4, 0, WRITE_LOCK);
1518 EXPECTED(ret, False);
1519 printf("the same process %s set the same write lock twice\n", ret?"can":"cannot");
1521 ret = cli_lock(cli1, fnum1, 80, 4, 0, READ_LOCK) &&
1522 cli_lock(cli1, fnum1, 80, 4, 0, WRITE_LOCK);
1523 EXPECTED(ret, False);
1524 printf("the same process %s overlay a read lock with a write lock\n", ret?"can":"cannot");
1526 ret = cli_lock(cli1, fnum1, 90, 4, 0, WRITE_LOCK) &&
1527 cli_lock(cli1, fnum1, 90, 4, 0, READ_LOCK);
1528 EXPECTED(ret, True);
1529 printf("the same process %s overlay a write lock with a read lock\n", ret?"can":"cannot");
1531 ret = (cli_setpid(cli1, 1), cli_lock(cli1, fnum1, 100, 4, 0, WRITE_LOCK)) &&
1532 (cli_setpid(cli1, 2), cli_lock(cli1, fnum1, 100, 4, 0, READ_LOCK));
1533 EXPECTED(ret, False);
1534 printf("a different pid %s overlay a write lock with a read lock\n", ret?"can":"cannot");
1536 ret = cli_lock(cli1, fnum1, 110, 4, 0, READ_LOCK) &&
1537 cli_lock(cli1, fnum1, 112, 4, 0, READ_LOCK) &&
1538 cli_unlock(cli1, fnum1, 110, 6);
1539 EXPECTED(ret, False);
1540 printf("the same process %s coalesce read locks\n", ret?"can":"cannot");
1543 ret = cli_lock(cli1, fnum1, 120, 4, 0, WRITE_LOCK) &&
1544 (cli_read(cli2, fnum2, buf, 120, 4) == 4);
1545 EXPECTED(ret, False);
1546 printf("this server %s strict write locking\n", ret?"doesn't do":"does");
1548 ret = cli_lock(cli1, fnum1, 130, 4, 0, READ_LOCK) &&
1549 (cli_write(cli2, fnum2, 0, buf, 130, 4) == 4);
1550 EXPECTED(ret, False);
1551 printf("this server %s strict read locking\n", ret?"doesn't do":"does");
1554 ret = cli_lock(cli1, fnum1, 140, 4, 0, READ_LOCK) &&
1555 cli_lock(cli1, fnum1, 140, 4, 0, READ_LOCK) &&
1556 cli_unlock(cli1, fnum1, 140, 4) &&
1557 cli_unlock(cli1, fnum1, 140, 4);
1558 EXPECTED(ret, True);
1559 printf("this server %s do recursive read locking\n", ret?"does":"doesn't");
1562 ret = cli_lock(cli1, fnum1, 150, 4, 0, WRITE_LOCK) &&
1563 cli_lock(cli1, fnum1, 150, 4, 0, READ_LOCK) &&
1564 cli_unlock(cli1, fnum1, 150, 4) &&
1565 (cli_read(cli2, fnum2, buf, 150, 4) == 4) &&
1566 !(cli_write(cli2, fnum2, 0, buf, 150, 4) == 4) &&
1567 cli_unlock(cli1, fnum1, 150, 4);
1568 EXPECTED(ret, True);
1569 printf("this server %s do recursive lock overlays\n", ret?"does":"doesn't");
1571 ret = cli_lock(cli1, fnum1, 160, 4, 0, READ_LOCK) &&
1572 cli_unlock(cli1, fnum1, 160, 4) &&
1573 (cli_write(cli2, fnum2, 0, buf, 160, 4) == 4) &&
1574 (cli_read(cli2, fnum2, buf, 160, 4) == 4);
1575 EXPECTED(ret, True);
1576 printf("the same process %s remove a read lock using write locking\n", ret?"can":"cannot");
1578 ret = cli_lock(cli1, fnum1, 170, 4, 0, WRITE_LOCK) &&
1579 cli_unlock(cli1, fnum1, 170, 4) &&
1580 (cli_write(cli2, fnum2, 0, buf, 170, 4) == 4) &&
1581 (cli_read(cli2, fnum2, buf, 170, 4) == 4);
1582 EXPECTED(ret, True);
1583 printf("the same process %s remove a write lock using read locking\n", ret?"can":"cannot");
1585 ret = cli_lock(cli1, fnum1, 190, 4, 0, WRITE_LOCK) &&
1586 cli_lock(cli1, fnum1, 190, 4, 0, READ_LOCK) &&
1587 cli_unlock(cli1, fnum1, 190, 4) &&
1588 !(cli_write(cli2, fnum2, 0, buf, 190, 4) == 4) &&
1589 (cli_read(cli2, fnum2, buf, 190, 4) == 4);
1590 EXPECTED(ret, True);
1591 printf("the same process %s remove the first lock first\n", ret?"does":"doesn't");
1593 cli_close(cli1, fnum1);
1594 cli_close(cli2, fnum2);
1595 fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1596 f = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1597 ret = cli_lock(cli1, fnum1, 0, 8, 0, READ_LOCK) &&
1598 cli_lock(cli1, f, 0, 1, 0, READ_LOCK) &&
1599 cli_close(cli1, fnum1) &&
1600 ((fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE)) != -1) &&
1601 cli_lock(cli1, fnum1, 7, 1, 0, WRITE_LOCK);
1603 cli_close(cli1, fnum1);
1604 EXPECTED(ret, True);
1605 printf("the server %s have the NT byte range lock bug\n", !ret?"does":"doesn't");
1608 cli_close(cli1, fnum1);
1609 cli_close(cli2, fnum2);
1610 cli_unlink(cli1, fname);
1611 torture_close_connection(cli1);
1612 torture_close_connection(cli2);
1614 printf("finished locktest4\n");
1619 looks at lock upgrade/downgrade.
1621 static BOOL run_locktest5(int dummy)
1623 static struct cli_state *cli1, *cli2;
1624 const char *fname = "\\lockt5.lck";
1625 int fnum1, fnum2, fnum3;
1628 BOOL correct = True;
1630 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
1634 cli_sockopt(cli1, sockops);
1635 cli_sockopt(cli2, sockops);
1637 printf("starting locktest5\n");
1639 cli_unlink(cli1, fname);
1641 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1642 fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
1643 fnum3 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1645 memset(buf, 0, sizeof(buf));
1647 if (cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
1648 printf("Failed to create file\n");
1653 /* Check for NT bug... */
1654 ret = cli_lock(cli1, fnum1, 0, 8, 0, READ_LOCK) &&
1655 cli_lock(cli1, fnum3, 0, 1, 0, READ_LOCK);
1656 cli_close(cli1, fnum1);
1657 fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1658 ret = cli_lock(cli1, fnum1, 7, 1, 0, WRITE_LOCK);
1659 EXPECTED(ret, True);
1660 printf("this server %s the NT locking bug\n", ret ? "doesn't have" : "has");
1661 cli_close(cli1, fnum1);
1662 fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1663 cli_unlock(cli1, fnum3, 0, 1);
1665 ret = cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK) &&
1666 cli_lock(cli1, fnum1, 1, 1, 0, READ_LOCK);
1667 EXPECTED(ret, True);
1668 printf("the same process %s overlay a write with a read lock\n", ret?"can":"cannot");
1670 ret = cli_lock(cli2, fnum2, 0, 4, 0, READ_LOCK);
1671 EXPECTED(ret, False);
1673 printf("a different processs %s get a read lock on the first process lock stack\n", ret?"can":"cannot");
1675 /* Unlock the process 2 lock. */
1676 cli_unlock(cli2, fnum2, 0, 4);
1678 ret = cli_lock(cli1, fnum3, 0, 4, 0, READ_LOCK);
1679 EXPECTED(ret, False);
1681 printf("the same processs on a different fnum %s get a read lock\n", ret?"can":"cannot");
1683 /* Unlock the process 1 fnum3 lock. */
1684 cli_unlock(cli1, fnum3, 0, 4);
1686 /* Stack 2 more locks here. */
1687 ret = cli_lock(cli1, fnum1, 0, 4, 0, READ_LOCK) &&
1688 cli_lock(cli1, fnum1, 0, 4, 0, READ_LOCK);
1690 EXPECTED(ret, True);
1691 printf("the same process %s stack read locks\n", ret?"can":"cannot");
1693 /* Unlock the first process lock, then check this was the WRITE lock that was
1696 ret = cli_unlock(cli1, fnum1, 0, 4) &&
1697 cli_lock(cli2, fnum2, 0, 4, 0, READ_LOCK);
1699 EXPECTED(ret, True);
1700 printf("the first unlock removes the %s lock\n", ret?"WRITE":"READ");
1702 /* Unlock the process 2 lock. */
1703 cli_unlock(cli2, fnum2, 0, 4);
1705 /* We should have 3 stacked locks here. Ensure we need to do 3 unlocks. */
1707 ret = cli_unlock(cli1, fnum1, 1, 1) &&
1708 cli_unlock(cli1, fnum1, 0, 4) &&
1709 cli_unlock(cli1, fnum1, 0, 4);
1711 EXPECTED(ret, True);
1712 printf("the same process %s unlock the stack of 4 locks\n", ret?"can":"cannot");
1714 /* Ensure the next unlock fails. */
1715 ret = cli_unlock(cli1, fnum1, 0, 4);
1716 EXPECTED(ret, False);
1717 printf("the same process %s count the lock stack\n", !ret?"can":"cannot");
1719 /* Ensure connection 2 can get a write lock. */
1720 ret = cli_lock(cli2, fnum2, 0, 4, 0, WRITE_LOCK);
1721 EXPECTED(ret, True);
1723 printf("a different processs %s get a write lock on the unlocked stack\n", ret?"can":"cannot");
1727 cli_close(cli1, fnum1);
1728 cli_close(cli2, fnum2);
1729 cli_unlink(cli1, fname);
1730 if (!torture_close_connection(cli1)) {
1733 if (!torture_close_connection(cli2)) {
1737 printf("finished locktest5\n");
1743 tries the unusual lockingX locktype bits
1745 static BOOL run_locktest6(int dummy)
1747 static struct cli_state *cli;
1748 const char *fname[1] = { "\\lock6.txt" };
1753 if (!torture_open_connection(&cli)) {
1757 cli_sockopt(cli, sockops);
1759 printf("starting locktest6\n");
1762 printf("Testing %s\n", fname[i]);
1764 cli_unlink(cli, fname[i]);
1766 fnum = cli_open(cli, fname[i], O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1767 status = cli_locktype(cli, fnum, 0, 8, 0, LOCKING_ANDX_CHANGE_LOCKTYPE);
1768 cli_close(cli, fnum);
1769 printf("CHANGE_LOCKTYPE gave %s\n", nt_errstr(status));
1771 fnum = cli_open(cli, fname[i], O_RDWR, DENY_NONE);
1772 status = cli_locktype(cli, fnum, 0, 8, 0, LOCKING_ANDX_CANCEL_LOCK);
1773 cli_close(cli, fnum);
1774 printf("CANCEL_LOCK gave %s\n", nt_errstr(status));
1776 cli_unlink(cli, fname[i]);
1779 torture_close_connection(cli);
1781 printf("finished locktest6\n");
1785 static BOOL run_locktest7(int dummy)
1787 struct cli_state *cli1;
1788 const char *fname = "\\lockt7.lck";
1791 BOOL correct = False;
1793 if (!torture_open_connection(&cli1)) {
1797 cli_sockopt(cli1, sockops);
1799 printf("starting locktest7\n");
1801 cli_unlink(cli1, fname);
1803 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1805 memset(buf, 0, sizeof(buf));
1807 if (cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
1808 printf("Failed to create file\n");
1812 cli_setpid(cli1, 1);
1814 if (!cli_lock(cli1, fnum1, 130, 4, 0, READ_LOCK)) {
1815 printf("Unable to apply read lock on range 130:4, error was %s\n", cli_errstr(cli1));
1818 printf("pid1 successfully locked range 130:4 for READ\n");
1821 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
1822 printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
1825 printf("pid1 successfully read the range 130:4\n");
1828 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
1829 printf("pid1 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
1830 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
1831 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
1835 printf("pid1 successfully wrote to the range 130:4 (should be denied)\n");
1839 cli_setpid(cli1, 2);
1841 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
1842 printf("pid2 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
1844 printf("pid2 successfully read the range 130:4\n");
1847 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
1848 printf("pid2 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
1849 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
1850 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
1854 printf("pid2 successfully wrote to the range 130:4 (should be denied)\n");
1858 cli_setpid(cli1, 1);
1859 cli_unlock(cli1, fnum1, 130, 4);
1861 if (!cli_lock(cli1, fnum1, 130, 4, 0, WRITE_LOCK)) {
1862 printf("Unable to apply write lock on range 130:4, error was %s\n", cli_errstr(cli1));
1865 printf("pid1 successfully locked range 130:4 for WRITE\n");
1868 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
1869 printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
1872 printf("pid1 successfully read the range 130:4\n");
1875 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
1876 printf("pid1 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
1879 printf("pid1 successfully wrote to the range 130:4\n");
1882 cli_setpid(cli1, 2);
1884 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
1885 printf("pid2 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
1886 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
1887 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
1891 printf("pid2 successfully read the range 130:4 (should be denied)\n");
1895 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
1896 printf("pid2 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
1897 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
1898 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
1902 printf("pid2 successfully wrote to the range 130:4 (should be denied)\n");
1906 cli_unlock(cli1, fnum1, 130, 0);
1910 cli_close(cli1, fnum1);
1911 cli_unlink(cli1, fname);
1912 torture_close_connection(cli1);
1914 printf("finished locktest7\n");
1919 test whether fnums and tids open on one VC are available on another (a major
1922 static BOOL run_fdpasstest(int dummy)
1924 struct cli_state *cli1, *cli2;
1925 const char *fname = "\\fdpass.tst";
1929 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
1932 cli_sockopt(cli1, sockops);
1933 cli_sockopt(cli2, sockops);
1935 printf("starting fdpasstest\n");
1937 cli_unlink(cli1, fname);
1939 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1941 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
1945 if (cli_write(cli1, fnum1, 0, "hello world\n", 0, 13) != 13) {
1946 printf("write failed (%s)\n", cli_errstr(cli1));
1950 cli2->vuid = cli1->vuid;
1951 cli2->cnum = cli1->cnum;
1952 cli2->pid = cli1->pid;
1954 if (cli_read(cli2, fnum1, buf, 0, 13) == 13) {
1955 printf("read succeeded! nasty security hole [%s]\n",
1960 cli_close(cli1, fnum1);
1961 cli_unlink(cli1, fname);
1963 torture_close_connection(cli1);
1964 torture_close_connection(cli2);
1966 printf("finished fdpasstest\n");
1970 static BOOL run_fdsesstest(int dummy)
1972 struct cli_state *cli;
1977 const char *fname = "\\fdsess.tst";
1978 const char *fname1 = "\\fdsess1.tst";
1984 if (!torture_open_connection(&cli))
1986 cli_sockopt(cli, sockops);
1988 if (!torture_cli_session_setup2(cli, &new_vuid))
1991 saved_cnum = cli->cnum;
1992 if (!cli_send_tconX(cli, share, "?????", "", 1))
1994 new_cnum = cli->cnum;
1995 cli->cnum = saved_cnum;
1997 printf("starting fdsesstest\n");
1999 cli_unlink(cli, fname);
2000 cli_unlink(cli, fname1);
2002 fnum1 = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2004 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
2008 if (cli_write(cli, fnum1, 0, "hello world\n", 0, 13) != 13) {
2009 printf("write failed (%s)\n", cli_errstr(cli));
2013 saved_vuid = cli->vuid;
2014 cli->vuid = new_vuid;
2016 if (cli_read(cli, fnum1, buf, 0, 13) == 13) {
2017 printf("read succeeded with different vuid! nasty security hole [%s]\n",
2021 /* Try to open a file with different vuid, samba cnum. */
2022 fnum2 = cli_open(cli, fname1, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2024 printf("create with different vuid, same cnum succeeded.\n");
2025 cli_close(cli, fnum2);
2026 cli_unlink(cli, fname1);
2028 printf("create with different vuid, same cnum failed.\n");
2029 printf("This will cause problems with service clients.\n");
2033 cli->vuid = saved_vuid;
2035 /* Try with same vuid, different cnum. */
2036 cli->cnum = new_cnum;
2038 if (cli_read(cli, fnum1, buf, 0, 13) == 13) {
2039 printf("read succeeded with different cnum![%s]\n",
2044 cli->cnum = saved_cnum;
2045 cli_close(cli, fnum1);
2046 cli_unlink(cli, fname);
2048 torture_close_connection(cli);
2050 printf("finished fdsesstest\n");
2055 This test checks that
2057 1) the server does not allow an unlink on a file that is open
2059 static BOOL run_unlinktest(int dummy)
2061 struct cli_state *cli;
2062 const char *fname = "\\unlink.tst";
2064 BOOL correct = True;
2066 if (!torture_open_connection(&cli)) {
2070 cli_sockopt(cli, sockops);
2072 printf("starting unlink test\n");
2074 cli_unlink(cli, fname);
2078 fnum = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2080 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
2084 if (cli_unlink(cli, fname)) {
2085 printf("error: server allowed unlink on an open file\n");
2088 correct = check_error(__LINE__, cli, ERRDOS, ERRbadshare,
2089 NT_STATUS_SHARING_VIOLATION);
2092 cli_close(cli, fnum);
2093 cli_unlink(cli, fname);
2095 if (!torture_close_connection(cli)) {
2099 printf("unlink test finished\n");
2106 test how many open files this server supports on the one socket
2108 static BOOL run_maxfidtest(int dummy)
2110 struct cli_state *cli;
2111 const char *template = "\\maxfid.%d.%d";
2113 int fnums[0x11000], i;
2115 BOOL correct = True;
2120 printf("failed to connect\n");
2124 cli_sockopt(cli, sockops);
2126 for (i=0; i<0x11000; i++) {
2127 slprintf(fname,sizeof(fname)-1,template, i,(int)getpid());
2128 if ((fnums[i] = cli_open(cli, fname,
2129 O_RDWR|O_CREAT|O_TRUNC, DENY_NONE)) ==
2131 printf("open of %s failed (%s)\n",
2132 fname, cli_errstr(cli));
2133 printf("maximum fnum is %d\n", i);
2141 printf("cleaning up\n");
2143 slprintf(fname,sizeof(fname)-1,template, i,(int)getpid());
2144 cli_close(cli, fnums[i]);
2145 if (!cli_unlink(cli, fname)) {
2146 printf("unlink of %s failed (%s)\n",
2147 fname, cli_errstr(cli));
2154 printf("maxfid test finished\n");
2155 if (!torture_close_connection(cli)) {
2161 /* generate a random buffer */
2162 static void rand_buf(char *buf, int len)
2165 *buf = (char)sys_random();
2170 /* send smb negprot commands, not reading the response */
2171 static BOOL run_negprot_nowait(int dummy)
2174 static struct cli_state cli;
2175 BOOL correct = True;
2177 printf("starting negprot nowait test\n");
2179 if (!open_nbt_connection(&cli)) {
2183 for (i=0;i<50000;i++) {
2184 cli_negprot_send(&cli);
2187 if (!torture_close_connection(&cli)) {
2191 printf("finished negprot nowait test\n");
2197 /* send random IPC commands */
2198 static BOOL run_randomipc(int dummy)
2200 char *rparam = NULL;
2204 int api, param_len, i;
2205 struct cli_state *cli;
2206 BOOL correct = True;
2209 printf("starting random ipc test\n");
2211 if (!torture_open_connection(&cli)) {
2215 for (i=0;i<count;i++) {
2216 api = sys_random() % 500;
2217 param_len = (sys_random() % 64);
2219 rand_buf(param, param_len);
2224 param, param_len, 8,
2225 NULL, 0, BUFFER_SIZE,
2229 printf("%d/%d\r", i,count);
2232 printf("%d/%d\n", i, count);
2234 if (!torture_close_connection(cli)) {
2238 printf("finished random ipc test\n");
2245 static void browse_callback(const char *sname, uint32 stype,
2246 const char *comment, void *state)
2248 printf("\t%20.20s %08x %s\n", sname, stype, comment);
2254 This test checks the browse list code
2257 static BOOL run_browsetest(int dummy)
2259 static struct cli_state *cli;
2260 BOOL correct = True;
2262 printf("starting browse test\n");
2264 if (!torture_open_connection(&cli)) {
2268 printf("domain list:\n");
2269 cli_NetServerEnum(cli, cli->server_domain,
2270 SV_TYPE_DOMAIN_ENUM,
2271 browse_callback, NULL);
2273 printf("machine list:\n");
2274 cli_NetServerEnum(cli, cli->server_domain,
2276 browse_callback, NULL);
2278 if (!torture_close_connection(cli)) {
2282 printf("browse test finished\n");
2290 This checks how the getatr calls works
2292 static BOOL run_attrtest(int dummy)
2294 struct cli_state *cli;
2297 const char *fname = "\\attrib123456789.tst";
2298 BOOL correct = True;
2300 printf("starting attrib test\n");
2302 if (!torture_open_connection(&cli)) {
2306 cli_unlink(cli, fname);
2307 fnum = cli_open(cli, fname,
2308 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2309 cli_close(cli, fnum);
2310 if (!cli_getatr(cli, fname, NULL, NULL, &t)) {
2311 printf("getatr failed (%s)\n", cli_errstr(cli));
2315 if (abs(t - time(NULL)) > 60*60*24*10) {
2316 printf("ERROR: SMBgetatr bug. time is %s",
2322 t2 = t-60*60*24; /* 1 day ago */
2324 if (!cli_setatr(cli, fname, 0, t2)) {
2325 printf("setatr failed (%s)\n", cli_errstr(cli));
2329 if (!cli_getatr(cli, fname, NULL, NULL, &t)) {
2330 printf("getatr failed (%s)\n", cli_errstr(cli));
2335 printf("ERROR: getatr/setatr bug. times are\n%s",
2337 printf("%s", ctime(&t2));
2341 cli_unlink(cli, fname);
2343 if (!torture_close_connection(cli)) {
2347 printf("attrib test finished\n");
2354 This checks a couple of trans2 calls
2356 static BOOL run_trans2test(int dummy)
2358 struct cli_state *cli;
2361 time_t c_time, a_time, m_time, w_time, m_time2;
2362 const char *fname = "\\trans2.tst";
2363 const char *dname = "\\trans2";
2364 const char *fname2 = "\\trans2\\trans2.tst";
2366 BOOL correct = True;
2368 printf("starting trans2 test\n");
2370 if (!torture_open_connection(&cli)) {
2374 cli_unlink(cli, fname);
2375 fnum = cli_open(cli, fname,
2376 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2377 if (!cli_qfileinfo(cli, fnum, NULL, &size, &c_time, &a_time, &m_time,
2379 printf("ERROR: qfileinfo failed (%s)\n", cli_errstr(cli));
2383 if (!cli_qfilename(cli, fnum, pname)) {
2384 printf("ERROR: qfilename failed (%s)\n", cli_errstr(cli));
2388 if (strcmp(pname, fname)) {
2389 printf("qfilename gave different name? [%s] [%s]\n",
2394 cli_close(cli, fnum);
2398 cli_unlink(cli, fname);
2399 fnum = cli_open(cli, fname,
2400 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2402 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
2405 cli_close(cli, fnum);
2407 if (!cli_qpathinfo(cli, fname, &c_time, &a_time, &m_time, &size, NULL)) {
2408 printf("ERROR: qpathinfo failed (%s)\n", cli_errstr(cli));
2411 if (c_time != m_time) {
2412 printf("create time=%s", ctime(&c_time));
2413 printf("modify time=%s", ctime(&m_time));
2414 printf("This system appears to have sticky create times\n");
2416 if (a_time % (60*60) == 0) {
2417 printf("access time=%s", ctime(&a_time));
2418 printf("This system appears to set a midnight access time\n");
2422 if (abs(m_time - time(NULL)) > 60*60*24*7) {
2423 printf("ERROR: totally incorrect times - maybe word reversed? mtime=%s", ctime(&m_time));
2429 cli_unlink(cli, fname);
2430 fnum = cli_open(cli, fname,
2431 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2432 cli_close(cli, fnum);
2433 if (!cli_qpathinfo2(cli, fname, &c_time, &a_time, &m_time,
2434 &w_time, &size, NULL, NULL)) {
2435 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli));
2438 if (w_time < 60*60*24*2) {
2439 printf("write time=%s", ctime(&w_time));
2440 printf("This system appears to set a initial 0 write time\n");
2445 cli_unlink(cli, fname);
2448 /* check if the server updates the directory modification time
2449 when creating a new file */
2450 if (!cli_mkdir(cli, dname)) {
2451 printf("ERROR: mkdir failed (%s)\n", cli_errstr(cli));
2455 if (!cli_qpathinfo2(cli, "\\trans2\\", &c_time, &a_time, &m_time,
2456 &w_time, &size, NULL, NULL)) {
2457 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli));
2461 fnum = cli_open(cli, fname2,
2462 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2463 cli_write(cli, fnum, 0, (char *)&fnum, 0, sizeof(fnum));
2464 cli_close(cli, fnum);
2465 if (!cli_qpathinfo2(cli, "\\trans2\\", &c_time, &a_time, &m_time2,
2466 &w_time, &size, NULL, NULL)) {
2467 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli));
2470 if (m_time2 == m_time) {
2471 printf("This system does not update directory modification times\n");
2475 cli_unlink(cli, fname2);
2476 cli_rmdir(cli, dname);
2478 if (!torture_close_connection(cli)) {
2482 printf("trans2 test finished\n");
2488 This checks new W2K calls.
2491 static BOOL new_trans(struct cli_state *pcli, int fnum, int level)
2494 BOOL correct = True;
2496 memset(buf, 0xff, sizeof(buf));
2498 if (!cli_qfileinfo_test(pcli, fnum, level, buf)) {
2499 printf("ERROR: qfileinfo (%d) failed (%s)\n", level, cli_errstr(pcli));
2502 printf("qfileinfo: level %d\n", level);
2503 dump_data(0, buf, 256);
2509 static BOOL run_w2ktest(int dummy)
2511 struct cli_state *cli;
2513 const char *fname = "\\w2ktest\\w2k.tst";
2515 BOOL correct = True;
2517 printf("starting w2k test\n");
2519 if (!torture_open_connection(&cli)) {
2523 fnum = cli_open(cli, fname,
2524 O_RDWR | O_CREAT , DENY_NONE);
2526 for (level = 1004; level < 1040; level++) {
2527 new_trans(cli, fnum, level);
2530 cli_close(cli, fnum);
2532 if (!torture_close_connection(cli)) {
2536 printf("w2k test finished\n");
2543 this is a harness for some oplock tests
2545 static BOOL run_oplock1(int dummy)
2547 struct cli_state *cli1;
2548 const char *fname = "\\lockt1.lck";
2550 BOOL correct = True;
2552 printf("starting oplock test 1\n");
2554 if (!torture_open_connection(&cli1)) {
2558 cli_unlink(cli1, fname);
2560 cli_sockopt(cli1, sockops);
2562 cli1->use_oplocks = True;
2564 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2566 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
2570 cli1->use_oplocks = False;
2572 cli_unlink(cli1, fname);
2573 cli_unlink(cli1, fname);
2575 if (!cli_close(cli1, fnum1)) {
2576 printf("close2 failed (%s)\n", cli_errstr(cli1));
2580 if (!cli_unlink(cli1, fname)) {
2581 printf("unlink failed (%s)\n", cli_errstr(cli1));
2585 if (!torture_close_connection(cli1)) {
2589 printf("finished oplock test 1\n");
2594 static BOOL run_oplock2(int dummy)
2596 struct cli_state *cli1, *cli2;
2597 const char *fname = "\\lockt2.lck";
2599 int saved_use_oplocks = use_oplocks;
2601 BOOL correct = True;
2602 volatile BOOL *shared_correct;
2604 shared_correct = (volatile BOOL *)shm_setup(sizeof(BOOL));
2605 *shared_correct = True;
2607 use_level_II_oplocks = True;
2610 printf("starting oplock test 2\n");
2612 if (!torture_open_connection(&cli1)) {
2613 use_level_II_oplocks = False;
2614 use_oplocks = saved_use_oplocks;
2618 cli1->use_oplocks = True;
2619 cli1->use_level_II_oplocks = True;
2621 if (!torture_open_connection(&cli2)) {
2622 use_level_II_oplocks = False;
2623 use_oplocks = saved_use_oplocks;
2627 cli2->use_oplocks = True;
2628 cli2->use_level_II_oplocks = True;
2630 cli_unlink(cli1, fname);
2632 cli_sockopt(cli1, sockops);
2633 cli_sockopt(cli2, sockops);
2635 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2637 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
2641 /* Don't need the globals any more. */
2642 use_level_II_oplocks = False;
2643 use_oplocks = saved_use_oplocks;
2647 fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
2649 printf("second open of %s failed (%s)\n", fname, cli_errstr(cli1));
2650 *shared_correct = False;
2656 if (!cli_close(cli2, fnum2)) {
2657 printf("close2 failed (%s)\n", cli_errstr(cli1));
2658 *shared_correct = False;
2666 /* Ensure cli1 processes the break. */
2668 if (cli_read(cli1, fnum1, buf, 0, 4) != 4) {
2669 printf("read on fnum1 failed (%s)\n", cli_errstr(cli1));
2673 /* Should now be at level II. */
2674 /* Test if sending a write locks causes a break to none. */
2676 if (!cli_lock(cli1, fnum1, 0, 4, 0, READ_LOCK)) {
2677 printf("lock failed (%s)\n", cli_errstr(cli1));
2681 cli_unlock(cli1, fnum1, 0, 4);
2685 if (!cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK)) {
2686 printf("lock failed (%s)\n", cli_errstr(cli1));
2690 cli_unlock(cli1, fnum1, 0, 4);
2694 cli_read(cli1, fnum1, buf, 0, 4);
2697 if (cli_write(cli1, fnum1, 0, buf, 0, 4) != 4) {
2698 printf("write on fnum1 failed (%s)\n", cli_errstr(cli1));
2703 if (!cli_close(cli1, fnum1)) {
2704 printf("close1 failed (%s)\n", cli_errstr(cli1));
2710 if (!cli_unlink(cli1, fname)) {
2711 printf("unlink failed (%s)\n", cli_errstr(cli1));
2715 if (!torture_close_connection(cli1)) {
2719 if (!*shared_correct) {
2723 printf("finished oplock test 2\n");
2728 /* handler for oplock 3 tests */
2729 static BOOL oplock3_handler(struct cli_state *cli, int fnum, unsigned char level)
2731 printf("got oplock break fnum=%d level=%d\n",
2733 return cli_oplock_ack(cli, fnum, level);
2736 static BOOL run_oplock3(int dummy)
2738 struct cli_state *cli;
2739 const char *fname = "\\oplockt3.dat";
2741 char buf[4] = "abcd";
2742 BOOL correct = True;
2743 volatile BOOL *shared_correct;
2745 shared_correct = (volatile BOOL *)shm_setup(sizeof(BOOL));
2746 *shared_correct = True;
2748 printf("starting oplock test 3\n");
2753 use_level_II_oplocks = True;
2754 if (!torture_open_connection(&cli)) {
2755 *shared_correct = False;
2759 /* try to trigger a oplock break in parent */
2760 fnum = cli_open(cli, fname, O_RDWR, DENY_NONE);
2761 cli_write(cli, fnum, 0, buf, 0, 4);
2767 use_level_II_oplocks = True;
2768 if (!torture_open_connection(&cli)) {
2771 cli_oplock_handler(cli, oplock3_handler);
2772 fnum = cli_open(cli, fname, O_RDWR|O_CREAT, DENY_NONE);
2773 cli_write(cli, fnum, 0, buf, 0, 4);
2774 cli_close(cli, fnum);
2775 fnum = cli_open(cli, fname, O_RDWR, DENY_NONE);
2776 cli->timeout = 20000;
2777 cli_receive_smb(cli);
2778 printf("finished oplock test 3\n");
2780 return (correct && *shared_correct);
2782 /* What are we looking for here? What's sucess and what's FAILURE? */
2788 Test delete on close semantics.
2790 static BOOL run_deletetest(int dummy)
2792 struct cli_state *cli1;
2793 struct cli_state *cli2;
2794 const char *fname = "\\delete.file";
2797 BOOL correct = True;
2799 printf("starting delete test\n");
2801 if (!torture_open_connection(&cli1)) {
2805 cli_sockopt(cli1, sockops);
2807 /* Test 1 - this should delete the file on close. */
2809 cli_setatr(cli1, fname, 0, 0);
2810 cli_unlink(cli1, fname);
2812 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL,
2813 FILE_SHARE_DELETE, FILE_OVERWRITE_IF,
2814 FILE_DELETE_ON_CLOSE, 0);
2817 printf("[1] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2822 if (!cli_close(cli1, fnum1)) {
2823 printf("[1] close failed (%s)\n", cli_errstr(cli1));
2828 fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
2830 printf("[1] open of %s succeeded (should fail)\n", fname);
2835 printf("first delete on close test succeeded.\n");
2837 /* Test 2 - this should delete the file on close. */
2839 cli_setatr(cli1, fname, 0, 0);
2840 cli_unlink(cli1, fname);
2842 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_ALL_ACCESS,
2843 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
2844 FILE_OVERWRITE_IF, 0, 0);
2847 printf("[2] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2852 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
2853 printf("[2] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
2858 if (!cli_close(cli1, fnum1)) {
2859 printf("[2] close failed (%s)\n", cli_errstr(cli1));
2864 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
2866 printf("[2] open of %s succeeded should have been deleted on close !\n", fname);
2867 if (!cli_close(cli1, fnum1)) {
2868 printf("[2] close failed (%s)\n", cli_errstr(cli1));
2872 cli_unlink(cli1, fname);
2874 printf("second delete on close test succeeded.\n");
2877 cli_setatr(cli1, fname, 0, 0);
2878 cli_unlink(cli1, fname);
2880 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL,
2881 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0);
2884 printf("[3] open - 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
2889 /* This should fail with a sharing violation - open for delete is only compatible
2890 with SHARE_DELETE. */
2892 fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
2893 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0, 0);
2896 printf("[3] open - 2 of %s succeeded - should have failed.\n", fname);
2901 /* This should succeed. */
2903 fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
2904 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0, 0);
2907 printf("[3] open - 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
2912 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
2913 printf("[3] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
2918 if (!cli_close(cli1, fnum1)) {
2919 printf("[3] close 1 failed (%s)\n", cli_errstr(cli1));
2924 if (!cli_close(cli1, fnum2)) {
2925 printf("[3] close 2 failed (%s)\n", cli_errstr(cli1));
2930 /* This should fail - file should no longer be there. */
2932 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
2934 printf("[3] open of %s succeeded should have been deleted on close !\n", fname);
2935 if (!cli_close(cli1, fnum1)) {
2936 printf("[3] close failed (%s)\n", cli_errstr(cli1));
2938 cli_unlink(cli1, fname);
2942 printf("third delete on close test succeeded.\n");
2945 cli_setatr(cli1, fname, 0, 0);
2946 cli_unlink(cli1, fname);
2948 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
2949 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0);
2952 printf("[4] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2957 /* This should succeed. */
2958 fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS,
2959 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0, 0);
2961 printf("[4] open - 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
2966 if (!cli_close(cli1, fnum2)) {
2967 printf("[4] close - 1 failed (%s)\n", cli_errstr(cli1));
2972 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
2973 printf("[4] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
2978 /* This should fail - no more opens once delete on close set. */
2979 fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS,
2980 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
2983 printf("[4] open - 3 of %s succeeded ! Should have failed.\n", fname );
2987 printf("fourth delete on close test succeeded.\n");
2989 if (!cli_close(cli1, fnum1)) {
2990 printf("[4] close - 2 failed (%s)\n", cli_errstr(cli1));
2996 cli_setatr(cli1, fname, 0, 0);
2997 cli_unlink(cli1, fname);
2999 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT, DENY_NONE);
3001 printf("[5] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3006 /* This should fail - only allowed on NT opens with DELETE access. */
3008 if (cli_nt_delete_on_close(cli1, fnum1, True)) {
3009 printf("[5] setting delete_on_close on OpenX file succeeded - should fail !\n");
3014 if (!cli_close(cli1, fnum1)) {
3015 printf("[5] close - 2 failed (%s)\n", cli_errstr(cli1));
3020 printf("fifth delete on close test succeeded.\n");
3023 cli_setatr(cli1, fname, 0, 0);
3024 cli_unlink(cli1, fname);
3026 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA,
3027 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
3028 FILE_OVERWRITE_IF, 0, 0);
3031 printf("[6] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3036 /* This should fail - only allowed on NT opens with DELETE access. */
3038 if (cli_nt_delete_on_close(cli1, fnum1, True)) {
3039 printf("[6] setting delete_on_close on file with no delete access succeeded - should fail !\n");
3044 if (!cli_close(cli1, fnum1)) {
3045 printf("[6] close - 2 failed (%s)\n", cli_errstr(cli1));
3050 printf("sixth delete on close test succeeded.\n");
3053 cli_setatr(cli1, fname, 0, 0);
3054 cli_unlink(cli1, fname);
3056 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
3057 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF, 0, 0);
3060 printf("[7] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3065 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
3066 printf("[7] setting delete_on_close on file failed !\n");
3071 if (!cli_nt_delete_on_close(cli1, fnum1, False)) {
3072 printf("[7] unsetting delete_on_close on file failed !\n");
3077 if (!cli_close(cli1, fnum1)) {
3078 printf("[7] close - 2 failed (%s)\n", cli_errstr(cli1));
3083 /* This next open should succeed - we reset the flag. */
3085 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
3087 printf("[5] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3092 if (!cli_close(cli1, fnum1)) {
3093 printf("[7] close - 2 failed (%s)\n", cli_errstr(cli1));
3098 printf("seventh delete on close test succeeded.\n");
3101 cli_setatr(cli1, fname, 0, 0);
3102 cli_unlink(cli1, fname);
3104 if (!torture_open_connection(&cli2)) {
3105 printf("[8] failed to open second connection.\n");
3110 cli_sockopt(cli1, sockops);
3112 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
3113 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
3114 FILE_OVERWRITE_IF, 0, 0);
3117 printf("[8] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3122 fnum2 = cli_nt_create_full(cli2, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
3123 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
3127 printf("[8] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3132 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
3133 printf("[8] setting delete_on_close on file failed !\n");
3138 if (!cli_close(cli1, fnum1)) {
3139 printf("[8] close - 1 failed (%s)\n", cli_errstr(cli1));
3144 if (!cli_close(cli2, fnum2)) {
3145 printf("[8] close - 2 failed (%s)\n", cli_errstr(cli2));
3150 /* This should fail.. */
3151 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
3153 printf("[8] open of %s succeeded should have been deleted on close !\n", fname);
3157 printf("eighth delete on close test succeeded.\n");
3159 /* This should fail - we need to set DELETE_ACCESS. */
3160 fnum1 = cli_nt_create_full(cli1, fname, 0,FILE_READ_DATA|FILE_WRITE_DATA,
3161 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, FILE_OVERWRITE_IF, FILE_DELETE_ON_CLOSE, 0);
3164 printf("[9] open of %s succeeded should have failed!\n", fname);
3169 printf("ninth delete on close test succeeded.\n");
3171 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
3172 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, FILE_OVERWRITE_IF, FILE_DELETE_ON_CLOSE, 0);
3174 printf("[10] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3179 /* This should delete the file. */
3180 if (!cli_close(cli1, fnum1)) {
3181 printf("[10] close failed (%s)\n", cli_errstr(cli1));
3186 /* This should fail.. */
3187 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
3189 printf("[10] open of %s succeeded should have been deleted on close !\n", fname);
3193 printf("tenth delete on close test succeeded.\n");
3194 printf("finished delete test\n");
3197 /* FIXME: This will crash if we aborted before cli2 got
3198 * intialized, because these functions don't handle
3199 * uninitialized connections. */
3201 cli_close(cli1, fnum1);
3202 cli_close(cli1, fnum2);
3203 cli_setatr(cli1, fname, 0, 0);
3204 cli_unlink(cli1, fname);
3206 if (!torture_close_connection(cli1)) {
3209 if (!torture_close_connection(cli2)) {
3217 print out server properties
3219 static BOOL run_properties(int dummy)
3221 static struct cli_state *cli;
3222 BOOL correct = True;
3224 printf("starting properties test\n");
3228 if (!torture_open_connection(&cli)) {
3232 cli_sockopt(cli, sockops);
3234 d_printf("Capabilities 0x%08x\n", cli->capabilities);
3236 if (!torture_close_connection(cli)) {
3245 /* FIRST_DESIRED_ACCESS 0xf019f */
3246 #define FIRST_DESIRED_ACCESS FILE_READ_DATA|FILE_WRITE_DATA|FILE_APPEND_DATA|\
3247 FILE_READ_EA| /* 0xf */ \
3248 FILE_WRITE_EA|FILE_READ_ATTRIBUTES| /* 0x90 */ \
3249 FILE_WRITE_ATTRIBUTES| /* 0x100 */ \
3250 DELETE_ACCESS|READ_CONTROL_ACCESS|\
3251 WRITE_DAC_ACCESS|WRITE_OWNER_ACCESS /* 0xf0000 */
3252 /* SECOND_DESIRED_ACCESS 0xe0080 */
3253 #define SECOND_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
3254 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
3255 WRITE_OWNER_ACCESS /* 0xe0000 */
3258 #define THIRD_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
3259 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
3261 WRITE_OWNER_ACCESS /* */
3265 Test ntcreate calls made by xcopy
3267 static BOOL run_xcopy(int dummy)
3269 static struct cli_state *cli1;
3270 const char *fname = "\\test.txt";
3271 BOOL correct = True;
3274 printf("starting xcopy test\n");
3276 if (!torture_open_connection(&cli1)) {
3280 fnum1 = cli_nt_create_full(cli1, fname, 0,
3281 FIRST_DESIRED_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
3282 FILE_SHARE_NONE, FILE_OVERWRITE_IF,
3286 printf("First open failed - %s\n", cli_errstr(cli1));
3290 fnum2 = cli_nt_create_full(cli1, fname, 0,
3291 SECOND_DESIRED_ACCESS, 0,
3292 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN,
3295 printf("second open failed - %s\n", cli_errstr(cli1));
3299 if (!torture_close_connection(cli1)) {
3307 Test rename on files open with share delete and no share delete.
3309 static BOOL run_rename(int dummy)
3311 static struct cli_state *cli1;
3312 const char *fname = "\\test.txt";
3313 const char *fname1 = "\\test1.txt";
3314 BOOL correct = True;
3317 printf("starting rename test\n");
3319 if (!torture_open_connection(&cli1)) {
3323 cli_unlink(cli1, fname);
3324 cli_unlink(cli1, fname1);
3325 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3326 FILE_SHARE_READ, FILE_OVERWRITE_IF, 0, 0);
3329 printf("First open failed - %s\n", cli_errstr(cli1));
3333 if (!cli_rename(cli1, fname, fname1)) {
3334 printf("First rename failed (this is correct) - %s\n", cli_errstr(cli1));
3336 printf("First rename succeeded - this should have failed !\n");
3340 if (!cli_close(cli1, fnum1)) {
3341 printf("close - 1 failed (%s)\n", cli_errstr(cli1));
3345 cli_unlink(cli1, fname);
3346 cli_unlink(cli1, fname1);
3347 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3349 FILE_SHARE_DELETE|FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
3351 FILE_SHARE_DELETE|FILE_SHARE_READ, FILE_OVERWRITE_IF, 0, 0);
3355 printf("Second open failed - %s\n", cli_errstr(cli1));
3359 if (!cli_rename(cli1, fname, fname1)) {
3360 printf("Second rename failed - this should have succeeded - %s\n", cli_errstr(cli1));
3363 printf("Second rename succeeded\n");
3366 if (!cli_close(cli1, fnum1)) {
3367 printf("close - 2 failed (%s)\n", cli_errstr(cli1));
3371 cli_unlink(cli1, fname);
3372 cli_unlink(cli1, fname1);
3374 fnum1 = cli_nt_create_full(cli1, fname, 0, READ_CONTROL_ACCESS, FILE_ATTRIBUTE_NORMAL,
3375 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
3378 printf("Third open failed - %s\n", cli_errstr(cli1));
3387 fnum2 = cli_nt_create_full(cli1, fname, 0, DELETE_ACCESS, FILE_ATTRIBUTE_NORMAL,
3388 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
3391 printf("Fourth open failed - %s\n", cli_errstr(cli1));
3394 if (!cli_nt_delete_on_close(cli1, fnum2, True)) {
3395 printf("[8] setting delete_on_close on file failed !\n");
3399 if (!cli_close(cli1, fnum2)) {
3400 printf("close - 4 failed (%s)\n", cli_errstr(cli1));
3406 if (!cli_rename(cli1, fname, fname1)) {
3407 printf("Third rename failed - this should have succeeded - %s\n", cli_errstr(cli1));
3410 printf("Third rename succeeded\n");
3413 if (!cli_close(cli1, fnum1)) {
3414 printf("close - 3 failed (%s)\n", cli_errstr(cli1));
3418 cli_unlink(cli1, fname);
3419 cli_unlink(cli1, fname1);
3421 if (!torture_close_connection(cli1)) {
3428 static BOOL run_pipe_number(int dummy)
3430 struct cli_state *cli1;
3431 const char *pipe_name = "\\SPOOLSS";
3435 printf("starting pipenumber test\n");
3436 if (!torture_open_connection(&cli1)) {
3440 cli_sockopt(cli1, sockops);
3442 fnum = cli_nt_create_full(cli1, pipe_name, 0, FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
3443 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN_IF, 0, 0);
3446 printf("Open of pipe %s failed with error (%s)\n", pipe_name, cli_errstr(cli1));
3452 printf("pipe_number test - we can open %d %s pipes.\n", num_pipes, pipe_name );
3453 torture_close_connection(cli1);
3458 Test open mode returns on read-only files.
3460 static BOOL run_opentest(int dummy)
3462 static struct cli_state *cli1;
3463 static struct cli_state *cli2;
3464 const char *fname = "\\readonly.file";
3468 BOOL correct = True;
3471 printf("starting open test\n");
3473 if (!torture_open_connection(&cli1)) {
3477 cli_setatr(cli1, fname, 0, 0);
3478 cli_unlink(cli1, fname);
3480 cli_sockopt(cli1, sockops);
3482 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
3484 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
3488 if (!cli_close(cli1, fnum1)) {
3489 printf("close2 failed (%s)\n", cli_errstr(cli1));
3493 if (!cli_setatr(cli1, fname, aRONLY, 0)) {
3494 printf("cli_setatr failed (%s)\n", cli_errstr(cli1));
3498 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_WRITE);
3500 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
3504 /* This will fail - but the error should be ERRnoaccess, not ERRbadshare. */
3505 fnum2 = cli_open(cli1, fname, O_RDWR, DENY_ALL);
3507 if (check_error(__LINE__, cli1, ERRDOS, ERRnoaccess,
3508 NT_STATUS_ACCESS_DENIED)) {
3509 printf("correct error code ERRDOS/ERRnoaccess returned\n");
3512 printf("finished open test 1\n");
3514 cli_close(cli1, fnum1);
3516 /* Now try not readonly and ensure ERRbadshare is returned. */
3518 cli_setatr(cli1, fname, 0, 0);
3520 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_WRITE);
3522 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
3526 /* This will fail - but the error should be ERRshare. */
3527 fnum2 = cli_open(cli1, fname, O_RDWR, DENY_ALL);
3529 if (check_error(__LINE__, cli1, ERRDOS, ERRbadshare,
3530 NT_STATUS_SHARING_VIOLATION)) {
3531 printf("correct error code ERRDOS/ERRbadshare returned\n");
3534 if (!cli_close(cli1, fnum1)) {
3535 printf("close2 failed (%s)\n", cli_errstr(cli1));
3539 cli_unlink(cli1, fname);
3541 printf("finished open test 2\n");
3543 /* Test truncate open disposition on file opened for read. */
3545 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
3547 printf("(3) open (1) of %s failed (%s)\n", fname, cli_errstr(cli1));
3551 /* write 20 bytes. */
3553 memset(buf, '\0', 20);
3555 if (cli_write(cli1, fnum1, 0, buf, 0, 20) != 20) {
3556 printf("write failed (%s)\n", cli_errstr(cli1));
3560 if (!cli_close(cli1, fnum1)) {
3561 printf("(3) close1 failed (%s)\n", cli_errstr(cli1));
3565 /* Ensure size == 20. */
3566 if (!cli_getatr(cli1, fname, NULL, &fsize, NULL)) {
3567 printf("(3) getatr failed (%s)\n", cli_errstr(cli1));
3572 printf("(3) file size != 20\n");
3576 /* Now test if we can truncate a file opened for readonly. */
3578 fnum1 = cli_open(cli1, fname, O_RDONLY|O_TRUNC, DENY_NONE);
3580 printf("(3) open (2) of %s failed (%s)\n", fname, cli_errstr(cli1));
3584 if (!cli_close(cli1, fnum1)) {
3585 printf("close2 failed (%s)\n", cli_errstr(cli1));
3589 /* Ensure size == 0. */
3590 if (!cli_getatr(cli1, fname, NULL, &fsize, NULL)) {
3591 printf("(3) getatr failed (%s)\n", cli_errstr(cli1));
3596 printf("(3) file size != 0\n");
3599 printf("finished open test 3\n");
3601 cli_unlink(cli1, fname);
3604 printf("testing ctemp\n");
3605 fnum1 = cli_ctemp(cli1, "\\", &tmp_path);
3607 printf("ctemp failed (%s)\n", cli_errstr(cli1));
3610 printf("ctemp gave path %s\n", tmp_path);
3611 if (!cli_close(cli1, fnum1)) {
3612 printf("close of temp failed (%s)\n", cli_errstr(cli1));
3614 if (!cli_unlink(cli1, tmp_path)) {
3615 printf("unlink of temp failed (%s)\n", cli_errstr(cli1));
3618 /* Test the non-io opens... */
3620 if (!torture_open_connection(&cli2)) {
3624 cli_setatr(cli2, fname, 0, 0);
3625 cli_unlink(cli2, fname);
3627 cli_sockopt(cli2, sockops);
3629 printf("TEST #1 testing 2 non-io opens (no delete)\n");
3631 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3632 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
3635 printf("test 1 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3639 fnum2 = cli_nt_create_full(cli2, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3640 FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0);
3643 printf("test 1 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3647 if (!cli_close(cli1, fnum1)) {
3648 printf("test 1 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3651 if (!cli_close(cli2, fnum2)) {
3652 printf("test 1 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3656 printf("non-io open test #1 passed.\n");
3658 cli_unlink(cli1, fname);
3660 printf("TEST #2 testing 2 non-io opens (first with delete)\n");
3662 fnum1 = cli_nt_create_full(cli1, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3663 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
3666 printf("test 2 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3670 fnum2 = cli_nt_create_full(cli2, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3671 FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0);
3674 printf("test 2 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3678 if (!cli_close(cli1, fnum1)) {
3679 printf("test 1 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3682 if (!cli_close(cli2, fnum2)) {
3683 printf("test 1 close 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
3687 printf("non-io open test #2 passed.\n");
3689 cli_unlink(cli1, fname);
3691 printf("TEST #3 testing 2 non-io opens (second with delete)\n");
3693 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3694 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
3697 printf("test 3 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3701 fnum2 = cli_nt_create_full(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3702 FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0);
3705 printf("test 3 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3709 if (!cli_close(cli1, fnum1)) {
3710 printf("test 3 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3713 if (!cli_close(cli2, fnum2)) {
3714 printf("test 3 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3718 printf("non-io open test #3 passed.\n");
3720 cli_unlink(cli1, fname);
3722 printf("TEST #4 testing 2 non-io opens (both with delete)\n");
3724 fnum1 = cli_nt_create_full(cli1, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3725 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
3728 printf("test 4 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3732 fnum2 = cli_nt_create_full(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3733 FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0);
3736 printf("test 4 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, cli_errstr(cli2));
3740 printf("test 3 open 2 of %s gave %s (correct error should be %s)\n", fname, cli_errstr(cli2), "sharing violation");
3742 if (!cli_close(cli1, fnum1)) {
3743 printf("test 4 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3747 printf("non-io open test #4 passed.\n");
3749 cli_unlink(cli1, fname);
3751 printf("TEST #5 testing 2 non-io opens (both with delete - both with file share delete)\n");
3753 fnum1 = cli_nt_create_full(cli1, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3754 FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0, 0);
3757 printf("test 5 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3761 fnum2 = cli_nt_create_full(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3762 FILE_SHARE_DELETE, FILE_OPEN_IF, 0, 0);
3765 printf("test 5 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3769 if (!cli_close(cli1, fnum1)) {
3770 printf("test 5 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3774 if (!cli_close(cli2, fnum2)) {
3775 printf("test 5 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3779 printf("non-io open test #5 passed.\n");
3781 printf("TEST #6 testing 1 non-io open, one io open\n");
3783 cli_unlink(cli1, fname);
3785 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
3786 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
3789 printf("test 6 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3793 fnum2 = cli_nt_create_full(cli2, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3794 FILE_SHARE_READ, FILE_OPEN_IF, 0, 0);
3797 printf("test 6 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3801 if (!cli_close(cli1, fnum1)) {
3802 printf("test 6 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3806 if (!cli_close(cli2, fnum2)) {
3807 printf("test 6 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3811 printf("non-io open test #6 passed.\n");
3813 printf("TEST #7 testing 1 non-io open, one io open with delete\n");
3815 cli_unlink(cli1, fname);
3817 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
3818 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
3821 printf("test 7 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3825 fnum2 = cli_nt_create_full(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3826 FILE_SHARE_READ|FILE_SHARE_DELETE, FILE_OPEN_IF, 0, 0);
3829 printf("test 7 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, cli_errstr(cli2));
3833 printf("test 7 open 2 of %s gave %s (correct error should be %s)\n", fname, cli_errstr(cli2), "sharing violation");
3835 if (!cli_close(cli1, fnum1)) {
3836 printf("test 7 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3840 printf("non-io open test #7 passed.\n");
3842 cli_unlink(cli1, fname);
3844 if (!torture_close_connection(cli1)) {
3847 if (!torture_close_connection(cli2)) {
3854 static uint32 open_attrs_table[] = {
3855 FILE_ATTRIBUTE_NORMAL,
3856 FILE_ATTRIBUTE_ARCHIVE,
3857 FILE_ATTRIBUTE_READONLY,
3858 FILE_ATTRIBUTE_HIDDEN,
3859 FILE_ATTRIBUTE_SYSTEM,
3861 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY,
3862 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN,
3863 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM,
3864 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN,
3865 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM,
3866 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM,
3868 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN,
3869 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM,
3870 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM,
3871 FILE_ATTRIBUTE_HIDDEN,FILE_ATTRIBUTE_SYSTEM,
3874 struct trunc_open_results {
3881 static struct trunc_open_results attr_results[] = {
3882 { 0, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE },
3883 { 1, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE },
3884 { 2, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_READONLY, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY },
3885 { 16, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE },
3886 { 17, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE },
3887 { 18, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_READONLY, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY },
3888 { 51, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
3889 { 54, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
3890 { 56, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN },
3891 { 68, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
3892 { 71, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
3893 { 73, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM },
3894 { 99, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN,FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
3895 { 102, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
3896 { 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 },
3897 { 116, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
3898 { 119, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
3899 { 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 },
3900 { 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 },
3901 { 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 },
3902 { 227, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
3903 { 230, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
3904 { 232, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN },
3905 { 244, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
3906 { 247, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
3907 { 249, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM }
3910 static BOOL run_openattrtest(int dummy)
3912 static struct cli_state *cli1;
3913 const char *fname = "\\openattr.file";
3915 BOOL correct = True;
3917 unsigned int i, j, k, l;
3919 printf("starting open attr test\n");
3921 if (!torture_open_connection(&cli1)) {
3925 cli_sockopt(cli1, sockops);
3927 for (k = 0, i = 0; i < sizeof(open_attrs_table)/sizeof(uint32); i++) {
3928 cli_setatr(cli1, fname, 0, 0);
3929 cli_unlink(cli1, fname);
3930 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_WRITE_DATA, open_attrs_table[i],
3931 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
3934 printf("open %d (1) of %s failed (%s)\n", i, fname, cli_errstr(cli1));
3938 if (!cli_close(cli1, fnum1)) {
3939 printf("close %d (1) of %s failed (%s)\n", i, fname, cli_errstr(cli1));
3943 for (j = 0; j < sizeof(open_attrs_table)/sizeof(uint32); j++) {
3944 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA, open_attrs_table[j],
3945 FILE_SHARE_NONE, FILE_OVERWRITE, 0, 0);
3948 for (l = 0; l < sizeof(attr_results)/sizeof(struct trunc_open_results); l++) {
3949 if (attr_results[l].num == k) {
3950 printf("[%d] trunc open 0x%x -> 0x%x of %s failed - should have succeeded !(0x%x:%s)\n",
3951 k, open_attrs_table[i],
3952 open_attrs_table[j],
3953 fname, NT_STATUS_V(cli_nt_error(cli1)), cli_errstr(cli1));
3957 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_ACCESS_DENIED)) {
3958 printf("[%d] trunc open 0x%x -> 0x%x failed with wrong error code %s\n",
3959 k, open_attrs_table[i], open_attrs_table[j],
3964 printf("[%d] trunc open 0x%x -> 0x%x failed\n", k, open_attrs_table[i], open_attrs_table[j]);
3970 if (!cli_close(cli1, fnum1)) {
3971 printf("close %d (2) of %s failed (%s)\n", j, fname, cli_errstr(cli1));
3975 if (!cli_getatr(cli1, fname, &attr, NULL, NULL)) {
3976 printf("getatr(2) failed (%s)\n", cli_errstr(cli1));
3981 printf("[%d] getatr check [0x%x] trunc [0x%x] got attr 0x%x\n",
3982 k, open_attrs_table[i], open_attrs_table[j], attr );
3985 for (l = 0; l < sizeof(attr_results)/sizeof(struct trunc_open_results); l++) {
3986 if (attr_results[l].num == k) {
3987 if (attr != attr_results[l].result_attr ||
3988 open_attrs_table[i] != attr_results[l].init_attr ||
3989 open_attrs_table[j] != attr_results[l].trunc_attr) {
3990 printf("getatr check failed. [0x%x] trunc [0x%x] got attr 0x%x, should be 0x%x\n",
3991 open_attrs_table[i],
3992 open_attrs_table[j],
3994 attr_results[l].result_attr);
4004 cli_setatr(cli1, fname, 0, 0);
4005 cli_unlink(cli1, fname);
4007 printf("open attr test %s.\n", correct ? "passed" : "failed");
4009 if (!torture_close_connection(cli1)) {
4015 static void list_fn(file_info *finfo, const char *name, void *state)
4021 test directory listing speed
4023 static BOOL run_dirtest(int dummy)
4026 static struct cli_state *cli;
4029 BOOL correct = True;
4031 printf("starting directory test\n");
4033 if (!torture_open_connection(&cli)) {
4037 cli_sockopt(cli, sockops);
4040 for (i=0;i<torture_numops;i++) {
4042 slprintf(fname, sizeof(fname), "\\%x", (int)random());
4043 fnum = cli_open(cli, fname, O_RDWR|O_CREAT, DENY_NONE);
4045 fprintf(stderr,"Failed to open %s\n", fname);
4048 cli_close(cli, fnum);
4053 printf("Matched %d\n", cli_list(cli, "a*.*", 0, list_fn, NULL));
4054 printf("Matched %d\n", cli_list(cli, "b*.*", 0, list_fn, NULL));
4055 printf("Matched %d\n", cli_list(cli, "xyzabc", 0, list_fn, NULL));
4057 printf("dirtest core %g seconds\n", end_timer() - t1);
4060 for (i=0;i<torture_numops;i++) {
4062 slprintf(fname, sizeof(fname), "\\%x", (int)random());
4063 cli_unlink(cli, fname);
4066 if (!torture_close_connection(cli)) {
4070 printf("finished dirtest\n");
4075 static void del_fn(file_info *finfo, const char *mask, void *state)
4077 struct cli_state *pcli = (struct cli_state *)state;
4079 slprintf(fname, sizeof(fname), "\\LISTDIR\\%s", finfo->name);
4081 if (strcmp(finfo->name, ".") == 0 || strcmp(finfo->name, "..") == 0)
4084 if (finfo->mode & aDIR) {
4085 if (!cli_rmdir(pcli, fname))
4086 printf("del_fn: failed to rmdir %s\n,", fname );
4088 if (!cli_unlink(pcli, fname))
4089 printf("del_fn: failed to unlink %s\n,", fname );
4095 sees what IOCTLs are supported
4097 BOOL torture_ioctl_test(int dummy)
4099 static struct cli_state *cli;
4100 uint16 device, function;
4102 const char *fname = "\\ioctl.dat";
4106 if (!torture_open_connection(&cli)) {
4110 printf("starting ioctl test\n");
4112 cli_unlink(cli, fname);
4114 fnum = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
4116 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
4120 status = cli_raw_ioctl(cli, fnum, 0x2d0000 | (0x0420<<2), &blob);
4121 printf("ioctl device info: %s\n", cli_errstr(cli));
4123 status = cli_raw_ioctl(cli, fnum, IOCTL_QUERY_JOB_INFO, &blob);
4124 printf("ioctl job info: %s\n", cli_errstr(cli));
4126 for (device=0;device<0x100;device++) {
4127 printf("testing device=0x%x\n", device);
4128 for (function=0;function<0x100;function++) {
4129 uint32 code = (device<<16) | function;
4131 status = cli_raw_ioctl(cli, fnum, code, &blob);
4133 if (NT_STATUS_IS_OK(status)) {
4134 printf("ioctl 0x%x OK : %d bytes\n", code, blob.length);
4135 data_blob_free(&blob);
4140 if (!torture_close_connection(cli)) {
4149 tries varients of chkpath
4151 BOOL torture_chkpath_test(int dummy)
4153 static struct cli_state *cli;
4157 if (!torture_open_connection(&cli)) {
4161 printf("starting chkpath test\n");
4163 /* cleanup from an old run */
4164 cli_rmdir(cli, "\\chkpath.dir\\dir2");
4165 cli_unlink(cli, "\\chkpath.dir\\*");
4166 cli_rmdir(cli, "\\chkpath.dir");
4168 if (!cli_mkdir(cli, "\\chkpath.dir")) {
4169 printf("mkdir1 failed : %s\n", cli_errstr(cli));
4173 if (!cli_mkdir(cli, "\\chkpath.dir\\dir2")) {
4174 printf("mkdir2 failed : %s\n", cli_errstr(cli));
4178 fnum = cli_open(cli, "\\chkpath.dir\\foo.txt", O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
4180 printf("open1 failed (%s)\n", cli_errstr(cli));
4183 cli_close(cli, fnum);
4185 if (!cli_chkpath(cli, "\\chkpath.dir")) {
4186 printf("chkpath1 failed: %s\n", cli_errstr(cli));
4190 if (!cli_chkpath(cli, "\\chkpath.dir\\dir2")) {
4191 printf("chkpath2 failed: %s\n", cli_errstr(cli));
4195 if (!cli_chkpath(cli, "\\chkpath.dir\\foo.txt")) {
4196 ret = check_error(__LINE__, cli, ERRDOS, ERRbadpath,
4197 NT_STATUS_NOT_A_DIRECTORY);
4199 printf("* chkpath on a file should fail\n");
4203 if (!cli_chkpath(cli, "\\chkpath.dir\\bar.txt")) {
4204 ret = check_error(__LINE__, cli, ERRDOS, ERRbadfile,
4205 NT_STATUS_OBJECT_NAME_NOT_FOUND);
4207 printf("* chkpath on a non existant file should fail\n");
4211 if (!cli_chkpath(cli, "\\chkpath.dir\\dirxx\\bar.txt")) {
4212 ret = check_error(__LINE__, cli, ERRDOS, ERRbadpath,
4213 NT_STATUS_OBJECT_PATH_NOT_FOUND);
4215 printf("* chkpath on a non existent component should fail\n");
4219 cli_rmdir(cli, "\\chkpath.dir\\dir2");
4220 cli_unlink(cli, "\\chkpath.dir\\*");
4221 cli_rmdir(cli, "\\chkpath.dir");
4223 if (!torture_close_connection(cli)) {
4233 static BOOL run_dirtest1(int dummy)
4236 static struct cli_state *cli;
4238 BOOL correct = True;
4240 printf("starting directory test\n");
4242 if (!torture_open_connection(&cli)) {
4246 cli_sockopt(cli, sockops);
4248 cli_list(cli, "\\LISTDIR\\*", 0, del_fn, cli);
4249 cli_list(cli, "\\LISTDIR\\*", aDIR, del_fn, cli);
4250 cli_rmdir(cli, "\\LISTDIR");
4251 cli_mkdir(cli, "\\LISTDIR");
4253 /* Create 1000 files and 1000 directories. */
4254 for (i=0;i<1000;i++) {
4256 slprintf(fname, sizeof(fname), "\\LISTDIR\\f%d", i);
4257 fnum = cli_nt_create_full(cli, fname, 0, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
4258 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0);
4260 fprintf(stderr,"Failed to open %s\n", fname);
4263 cli_close(cli, fnum);
4265 for (i=0;i<1000;i++) {
4267 slprintf(fname, sizeof(fname), "\\LISTDIR\\d%d", i);
4268 if (!cli_mkdir(cli, fname)) {
4269 fprintf(stderr,"Failed to open %s\n", fname);
4274 /* Now ensure that doing an old list sees both files and directories. */
4275 num_seen = cli_list_old(cli, "\\LISTDIR\\*", aDIR, list_fn, NULL);
4276 printf("num_seen = %d\n", num_seen );
4277 /* We should see 100 files + 1000 directories + . and .. */
4278 if (num_seen != 2002)
4281 /* Ensure if we have the "must have" bits we only see the
4284 num_seen = cli_list_old(cli, "\\LISTDIR\\*", (aDIR<<8)|aDIR, list_fn, NULL);
4285 printf("num_seen = %d\n", num_seen );
4286 if (num_seen != 1002)
4289 num_seen = cli_list_old(cli, "\\LISTDIR\\*", (aARCH<<8)|aDIR, list_fn, NULL);
4290 printf("num_seen = %d\n", num_seen );
4291 if (num_seen != 1000)
4294 /* Delete everything. */
4295 cli_list(cli, "\\LISTDIR\\*", 0, del_fn, cli);
4296 cli_list(cli, "\\LISTDIR\\*", aDIR, del_fn, cli);
4297 cli_rmdir(cli, "\\LISTDIR");
4300 printf("Matched %d\n", cli_list(cli, "a*.*", 0, list_fn, NULL));
4301 printf("Matched %d\n", cli_list(cli, "b*.*", 0, list_fn, NULL));
4302 printf("Matched %d\n", cli_list(cli, "xyzabc", 0, list_fn, NULL));
4305 if (!torture_close_connection(cli)) {
4309 printf("finished dirtest1\n");
4314 static BOOL run_error_map_extract(int dummy) {
4316 static struct cli_state c_dos;
4317 static struct cli_state c_nt;
4321 uint32 flgs2, errnum;
4328 /* NT-Error connection */
4330 if (!open_nbt_connection(&c_nt)) {
4334 c_nt.use_spnego = False;
4336 if (!cli_negprot(&c_nt)) {
4337 printf("%s rejected the NT-error negprot (%s)\n",host, cli_errstr(&c_nt));
4338 cli_shutdown(&c_nt);
4342 if (!cli_session_setup(&c_nt, "", "", 0, "", 0,
4344 printf("%s rejected the NT-error initial session setup (%s)\n",host, cli_errstr(&c_nt));
4348 /* DOS-Error connection */
4350 if (!open_nbt_connection(&c_dos)) {
4354 c_dos.use_spnego = False;
4355 c_dos.force_dos_errors = True;
4357 if (!cli_negprot(&c_dos)) {
4358 printf("%s rejected the DOS-error negprot (%s)\n",host, cli_errstr(&c_dos));
4359 cli_shutdown(&c_dos);
4363 if (!cli_session_setup(&c_dos, "", "", 0, "", 0,
4365 printf("%s rejected the DOS-error initial session setup (%s)\n",host, cli_errstr(&c_dos));
4369 for (error=(0xc0000000 | 0x1); error < (0xc0000000| 0xFFF); error++) {
4370 snprintf(user, sizeof(user), "%X", error);
4372 if (cli_session_setup(&c_nt, user,
4373 password, strlen(password),
4374 password, strlen(password),
4376 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
4379 flgs2 = SVAL(c_nt.inbuf,smb_flg2);
4381 /* Case #1: 32-bit NT errors */
4382 if (flgs2 & FLAGS2_32_BIT_ERROR_CODES) {
4383 nt_status = NT_STATUS(IVAL(c_nt.inbuf,smb_rcls));
4385 printf("/** Dos error on NT connection! (%s) */\n",
4387 nt_status = NT_STATUS(0xc0000000);
4390 if (cli_session_setup(&c_dos, user,
4391 password, strlen(password),
4392 password, strlen(password),
4394 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
4396 flgs2 = SVAL(c_dos.inbuf,smb_flg2), errnum;
4398 /* Case #1: 32-bit NT errors */
4399 if (flgs2 & FLAGS2_32_BIT_ERROR_CODES) {
4400 printf("/** NT error on DOS connection! (%s) */\n",
4402 errnum = errclass = 0;
4404 cli_dos_error(&c_dos, &errclass, &errnum);
4407 if (NT_STATUS_V(nt_status) != error) {
4408 printf("/*\t{ This NT error code was 'sqashed'\n\t from %s to %s \n\t during the session setup }\n*/\n",
4409 get_nt_error_c_code(NT_STATUS(error)),
4410 get_nt_error_c_code(nt_status));
4413 printf("\t{%s,\t%s,\t%s},\n",
4414 smb_dos_err_class(errclass),
4415 smb_dos_err_name(errclass, errnum),
4416 get_nt_error_c_code(NT_STATUS(error)));
4421 static double create_procs(BOOL (*fn)(int), BOOL *result)
4424 volatile pid_t *child_status;
4425 volatile BOOL *child_status_out;
4431 child_status = (volatile pid_t *)shm_setup(sizeof(pid_t)*nprocs);
4432 if (!child_status) {
4433 printf("Failed to setup shared memory\n");
4437 child_status_out = (volatile BOOL *)shm_setup(sizeof(BOOL)*nprocs);
4438 if (!child_status_out) {
4439 printf("Failed to setup result status shared memory\n");
4443 for (i = 0; i < nprocs; i++) {
4444 child_status[i] = 0;
4445 child_status_out[i] = True;
4450 for (i=0;i<nprocs;i++) {
4453 pid_t mypid = getpid();
4454 sys_srandom(((int)mypid) ^ ((int)time(NULL)));
4456 slprintf(myname,sizeof(myname),"CLIENT%d", i);
4459 if (torture_open_connection(¤t_cli)) break;
4461 printf("pid %d failed to start\n", (int)getpid());
4467 child_status[i] = getpid();
4469 while (child_status[i] && end_timer() < 5) msleep(2);
4471 child_status_out[i] = fn(i);
4478 for (i=0;i<nprocs;i++) {
4479 if (child_status[i]) synccount++;
4481 if (synccount == nprocs) break;
4483 } while (end_timer() < 30);
4485 if (synccount != nprocs) {
4486 printf("FAILED TO START %d CLIENTS (started %d)\n", nprocs, synccount);
4491 /* start the client load */
4494 for (i=0;i<nprocs;i++) {
4495 child_status[i] = 0;
4498 printf("%d clients started\n", nprocs);
4500 for (i=0;i<nprocs;i++) {
4501 while (waitpid(0, &status, 0) == -1 && errno == EINTR) /* noop */ ;
4506 for (i=0;i<nprocs;i++) {
4507 if (!child_status_out[i]) {
4514 #define FLAG_MULTIPROC 1
4521 {"FDPASS", run_fdpasstest, 0},
4522 {"LOCK1", run_locktest1, 0},
4523 {"LOCK2", run_locktest2, 0},
4524 {"LOCK3", run_locktest3, 0},
4525 {"LOCK4", run_locktest4, 0},
4526 {"LOCK5", run_locktest5, 0},
4527 {"LOCK6", run_locktest6, 0},
4528 {"LOCK7", run_locktest7, 0},
4529 {"UNLINK", run_unlinktest, 0},
4530 {"BROWSE", run_browsetest, 0},
4531 {"ATTR", run_attrtest, 0},
4532 {"TRANS2", run_trans2test, 0},
4533 {"MAXFID", run_maxfidtest, FLAG_MULTIPROC},
4534 {"TORTURE",run_torture, FLAG_MULTIPROC},
4535 {"RANDOMIPC", run_randomipc, 0},
4536 {"NEGNOWAIT", run_negprot_nowait, 0},
4537 {"NBENCH", run_nbench, 0},
4538 {"OPLOCK1", run_oplock1, 0},
4539 {"OPLOCK2", run_oplock2, 0},
4540 {"OPLOCK3", run_oplock3, 0},
4541 {"DIR", run_dirtest, 0},
4542 {"DIR1", run_dirtest1, 0},
4543 {"DENY1", torture_denytest1, 0},
4544 {"DENY2", torture_denytest2, 0},
4545 {"TCON", run_tcon_test, 0},
4546 {"TCONDEV", run_tcon_devtype_test, 0},
4547 {"RW1", run_readwritetest, 0},
4548 {"RW2", run_readwritemulti, FLAG_MULTIPROC},
4549 {"RW3", run_readwritelarge, 0},
4550 {"OPEN", run_opentest, 0},
4552 {"OPENATTR", run_openattrtest, 0},
4554 {"XCOPY", run_xcopy, 0},
4555 {"RENAME", run_rename, 0},
4556 {"DELETE", run_deletetest, 0},
4557 {"PROPERTIES", run_properties, 0},
4558 {"MANGLE", torture_mangle, 0},
4559 {"W2K", run_w2ktest, 0},
4560 {"TRANS2SCAN", torture_trans2_scan, 0},
4561 {"NTTRANSSCAN", torture_nttrans_scan, 0},
4562 {"UTABLE", torture_utable, 0},
4563 {"CASETABLE", torture_casetable, 0},
4564 {"ERRMAPEXTRACT", run_error_map_extract, 0},
4565 {"PIPE_NUMBER", run_pipe_number, 0},
4566 {"TCON2", run_tcon2_test, 0},
4567 {"IOCTL", torture_ioctl_test, 0},
4568 {"CHKPATH", torture_chkpath_test, 0},
4569 {"FDSESS", run_fdsesstest, 0},
4574 /****************************************************************************
4575 run a specified test or "ALL"
4576 ****************************************************************************/
4577 static BOOL run_test(const char *name)
4583 if (strequal(name,"ALL")) {
4584 for (i=0;torture_ops[i].name;i++) {
4585 run_test(torture_ops[i].name);
4589 for (i=0;torture_ops[i].name;i++) {
4590 snprintf(randomfname, sizeof(randomfname), "\\XX%x",
4591 (unsigned)random());
4593 if (strequal(name, torture_ops[i].name)) {
4594 printf("Running %s\n", name);
4595 if (torture_ops[i].flags & FLAG_MULTIPROC) {
4596 t = create_procs(torture_ops[i].fn, &result);
4599 printf("TEST %s FAILED!\n", name);
4604 if (!torture_ops[i].fn(0)) {
4606 printf("TEST %s FAILED!\n", name);
4610 printf("%s took %g secs\n\n", name, t);
4617 static void usage(void)
4621 printf("Usage: smbtorture //server/share <options> TEST1 TEST2 ...\n");
4623 printf("\t-d debuglevel\n");
4624 printf("\t-U user%%pass\n");
4625 printf("\t-k use kerberos\n");
4626 printf("\t-N numprocs\n");
4627 printf("\t-n my_netbios_name\n");
4628 printf("\t-W workgroup\n");
4629 printf("\t-o num_operations\n");
4630 printf("\t-O socket_options\n");
4631 printf("\t-m maximum protocol\n");
4632 printf("\t-L use oplocks\n");
4633 printf("\t-c CLIENT.TXT specify client load file for NBENCH\n");
4634 printf("\t-A showall\n");
4635 printf("\t-p port\n");
4636 printf("\t-s seed\n");
4639 printf("tests are:");
4640 for (i=0;torture_ops[i].name;i++) {
4641 printf(" %s", torture_ops[i].name);
4645 printf("default test is ALL\n");
4650 /****************************************************************************
4652 ****************************************************************************/
4653 int main(int argc,char *argv[])
4659 extern char *optarg;
4661 BOOL correct = True;
4665 #ifdef HAVE_SETBUFFER
4666 setbuffer(stdout, NULL, 0);
4669 lp_load(dyn_CONFIGFILE,True,False,False);
4676 for(p = argv[1]; *p; p++)
4680 if (strncmp(argv[1], "//", 2)) {
4684 fstrcpy(host, &argv[1][2]);
4685 p = strchr_m(&host[2],'/');
4690 fstrcpy(share, p+1);
4694 if (*username == 0 && getenv("LOGNAME")) {
4695 fstrcpy(username,getenv("LOGNAME"));
4701 srandom(time(NULL));
4703 fstrcpy(workgroup, lp_workgroup());
4705 while ((opt = getopt(argc, argv, "p:hW:U:n:N:O:o:m:Ld:Ac:ks:")) != EOF) {
4708 port_to_use = atoi(optarg);
4711 srandom(atoi(optarg));
4714 fstrcpy(workgroup,optarg);
4717 max_protocol = interpret_protocol(optarg, max_protocol);
4720 nprocs = atoi(optarg);
4723 torture_numops = atoi(optarg);
4726 DEBUGLEVEL = atoi(optarg);
4735 torture_showall = True;
4738 fstrcpy(myname, optarg);
4741 client_txt = optarg;
4745 use_kerberos = True;
4747 d_printf("No kerberos support compiled in\n");
4753 fstrcpy(username,optarg);
4754 p = strchr_m(username,'%');
4757 fstrcpy(password, p+1);
4762 printf("Unknown option %c (%d)\n", (char)opt, opt);
4767 if(use_kerberos && !gotuser) gotpass = True;
4770 p = getpass("Password:");
4772 fstrcpy(password, p);
4777 printf("host=%s share=%s user=%s myname=%s\n",
4778 host, share, username, myname);
4781 correct = run_test("ALL");
4783 for (i=1;i<argc;i++) {
4784 if (!run_test(argv[i])) {