2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 1997-1998
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 static fstring host, workgroup, share, password, username, myname;
26 static int max_protocol = PROTOCOL_NT1;
27 static const char *sockops="TCP_NODELAY";
29 static int port_to_use=0;
30 int torture_numops=100;
31 static int procnum; /* records process count number when forking */
32 static struct cli_state *current_cli;
33 static fstring randomfname;
34 static BOOL use_oplocks;
35 static BOOL use_level_II_oplocks;
36 static const char *client_txt = "client_oplocks.txt";
37 static BOOL use_kerberos;
39 BOOL torture_showall = False;
41 static double create_procs(BOOL (*fn)(int), BOOL *result);
44 static struct timeval tp1,tp2;
46 void start_timer(void)
48 gettimeofday(&tp1,NULL);
51 double end_timer(void)
53 gettimeofday(&tp2,NULL);
54 return((tp2.tv_sec - tp1.tv_sec) +
55 (tp2.tv_usec - tp1.tv_usec)*1.0e-6);
59 /* return a pointer to a anonymous shared memory segment of size "size"
60 which will persist across fork() but will disappear when all processes
63 The memory is not zeroed
65 This function uses system5 shared memory. It takes advantage of a property
66 that the memory is not destroyed if it is attached when the id is removed
68 void *shm_setup(int size)
73 shmid = shmget(IPC_PRIVATE, size, SHM_R | SHM_W);
75 printf("can't get shared memory\n");
78 ret = (void *)shmat(shmid, 0, 0);
79 if (!ret || ret == (void *)-1) {
80 printf("can't attach to shared memory\n");
83 /* the following releases the ipc, but note that this process
84 and all its children will still have access to the memory, its
85 just that the shmid is no longer valid for other shm calls. This
86 means we don't leave behind lots of shm segments after we exit
88 See Stevens "advanced programming in unix env" for details
90 shmctl(shmid, IPC_RMID, 0);
96 static BOOL open_nbt_connection(struct cli_state *c)
98 struct nmb_name called, calling;
103 make_nmb_name(&calling, myname, 0x0);
104 make_nmb_name(&called , host, 0x20);
108 if (!cli_initialise(c)) {
109 printf("Failed initialize cli_struct to connect with %s\n", host);
113 c->port = port_to_use;
115 if (!cli_connect(c, host, &ip)) {
116 printf("Failed to connect with %s\n", host);
120 c->use_kerberos = use_kerberos;
122 c->timeout = 120000; /* set a really long timeout (2 minutes) */
123 if (use_oplocks) c->use_oplocks = True;
124 if (use_level_II_oplocks) c->use_level_II_oplocks = True;
126 if (!cli_session_request(c, &calling, &called)) {
128 * Well, that failed, try *SMBSERVER ...
129 * However, we must reconnect as well ...
131 if (!cli_connect(c, host, &ip)) {
132 printf("Failed to connect with %s\n", host);
136 make_nmb_name(&called, "*SMBSERVER", 0x20);
137 if (!cli_session_request(c, &calling, &called)) {
138 printf("%s rejected the session\n",host);
139 printf("We tried with a called name of %s & %s\n",
149 BOOL torture_open_connection(struct cli_state **c)
156 flags |= CLI_FULL_CONNECTION_USE_KERBEROS;
158 status = cli_full_connection(c, myname,
159 host, NULL, port_to_use,
162 password, flags, &retry);
163 if (!NT_STATUS_IS_OK(status)) {
167 if (use_oplocks) (*c)->use_oplocks = True;
168 if (use_level_II_oplocks) (*c)->use_level_II_oplocks = True;
169 (*c)->timeout = 120000; /* set a really long timeout (2 minutes) */
174 BOOL torture_cli_session_setup2(struct cli_state *cli, uint16 *new_vuid)
176 uint16 old_vuid = cli->vuid;
177 fstring old_user_name;
178 size_t passlen = strlen(password);
181 fstrcpy(old_user_name, cli->user_name);
183 ret = cli_session_setup(cli, username, password, passlen, password, passlen, workgroup);
184 *new_vuid = cli->vuid;
185 cli->vuid = old_vuid;
186 fstrcpy(cli->user_name, old_user_name);
191 BOOL torture_close_connection(struct cli_state *c)
195 printf("tdis failed (%s)\n", cli_errstr(c));
205 /* check if the server produced the expected error code */
206 static BOOL check_error(int line, struct cli_state *c,
207 uint8 eclass, uint32 ecode, NTSTATUS nterr)
209 if (cli_is_dos_error(c)) {
213 /* Check DOS error */
215 cli_dos_error(c, &class, &num);
217 if (eclass != class || ecode != num) {
218 printf("unexpected error code class=%d code=%d\n",
219 (int)class, (int)num);
220 printf(" expected %d/%d %s (line=%d)\n",
221 (int)eclass, (int)ecode, nt_errstr(nterr), line);
230 status = cli_nt_error(c);
232 if (NT_STATUS_V(nterr) != NT_STATUS_V(status)) {
233 printf("unexpected error code %s\n", nt_errstr(status));
234 printf(" expected %s (line=%d)\n", nt_errstr(nterr), line);
243 static BOOL wait_lock(struct cli_state *c, int fnum, uint32 offset, uint32 len)
245 while (!cli_lock(c, fnum, offset, len, -1, WRITE_LOCK)) {
246 if (!check_error(__LINE__, c, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False;
252 static BOOL rw_torture(struct cli_state *c)
254 const char *lockfname = "\\torture.lck";
258 pid_t pid2, pid = getpid();
263 fnum2 = cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
266 fnum2 = cli_open(c, lockfname, O_RDWR, DENY_NONE);
268 printf("open of %s failed (%s)\n", lockfname, cli_errstr(c));
273 for (i=0;i<torture_numops;i++) {
274 unsigned n = (unsigned)sys_random()%10;
276 printf("%d\r", i); fflush(stdout);
278 slprintf(fname, sizeof(fstring) - 1, "\\torture.%u", n);
280 if (!wait_lock(c, fnum2, n*sizeof(int), sizeof(int))) {
284 fnum = cli_open(c, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_ALL);
286 printf("open failed (%s)\n", cli_errstr(c));
291 if (cli_write(c, fnum, 0, (char *)&pid, 0, sizeof(pid)) != sizeof(pid)) {
292 printf("write failed (%s)\n", cli_errstr(c));
297 if (cli_write(c, fnum, 0, (char *)buf,
298 sizeof(pid)+(j*sizeof(buf)),
299 sizeof(buf)) != sizeof(buf)) {
300 printf("write failed (%s)\n", cli_errstr(c));
307 if (cli_read(c, fnum, (char *)&pid2, 0, sizeof(pid)) != sizeof(pid)) {
308 printf("read failed (%s)\n", cli_errstr(c));
313 printf("data corruption!\n");
317 if (!cli_close(c, fnum)) {
318 printf("close failed (%s)\n", cli_errstr(c));
322 if (!cli_unlink(c, fname)) {
323 printf("unlink failed (%s)\n", cli_errstr(c));
327 if (!cli_unlock(c, fnum2, n*sizeof(int), sizeof(int))) {
328 printf("unlock failed (%s)\n", cli_errstr(c));
334 cli_unlink(c, lockfname);
341 static BOOL run_torture(int dummy)
343 struct cli_state *cli;
348 cli_sockopt(cli, sockops);
350 ret = rw_torture(cli);
352 if (!torture_close_connection(cli)) {
359 static BOOL rw_torture3(struct cli_state *c, char *lockfname)
366 unsigned countprev = 0;
371 for (i = 0; i < sizeof(buf); i += sizeof(uint32))
373 SIVAL(buf, i, sys_random());
378 fnum = cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
381 printf("first open read/write of %s failed (%s)\n",
382 lockfname, cli_errstr(c));
388 for (i = 0; i < 500 && fnum == -1; i++)
390 fnum = cli_open(c, lockfname, O_RDONLY,
395 printf("second open read-only of %s failed (%s)\n",
396 lockfname, cli_errstr(c));
402 for (count = 0; count < sizeof(buf); count += sent)
404 if (count >= countprev) {
405 printf("%d %8d\r", i, count);
408 countprev += (sizeof(buf) / 20);
413 sent = ((unsigned)sys_random()%(20))+ 1;
414 if (sent > sizeof(buf) - count)
416 sent = sizeof(buf) - count;
419 if (cli_write(c, fnum, 0, buf+count, count, (size_t)sent) != sent) {
420 printf("write failed (%s)\n", cli_errstr(c));
426 sent = cli_read(c, fnum, buf_rd+count, count,
430 printf("read failed offset:%d size:%d (%s)\n",
431 count, sizeof(buf)-count,
438 if (memcmp(buf_rd+count, buf+count, sent) != 0)
440 printf("read/write compare failed\n");
441 printf("offset: %d req %d recvd %d\n",
442 count, sizeof(buf)-count, sent);
451 if (!cli_close(c, fnum)) {
452 printf("close failed (%s)\n", cli_errstr(c));
459 static BOOL rw_torture2(struct cli_state *c1, struct cli_state *c2)
461 const char *lockfname = "\\torture2.lck";
466 uchar buf_rd[131072];
470 if (!cli_unlink(c1, lockfname)) {
471 printf("unlink failed (%s) (normal, this file should not exist)\n", cli_errstr(c1));
474 fnum1 = cli_open(c1, lockfname, O_RDWR | O_CREAT | O_EXCL,
477 printf("first open read/write of %s failed (%s)\n",
478 lockfname, cli_errstr(c1));
481 fnum2 = cli_open(c2, lockfname, O_RDONLY,
484 printf("second open read-only of %s failed (%s)\n",
485 lockfname, cli_errstr(c2));
486 cli_close(c1, fnum1);
490 for (i=0;i<torture_numops;i++)
492 size_t buf_size = ((unsigned)sys_random()%(sizeof(buf)-1))+ 1;
494 printf("%d\r", i); fflush(stdout);
497 generate_random_buffer(buf, buf_size, False);
499 if (cli_write(c1, fnum1, 0, buf, 0, buf_size) != buf_size) {
500 printf("write failed (%s)\n", cli_errstr(c1));
504 if ((bytes_read = cli_read(c2, fnum2, buf_rd, 0, buf_size)) != buf_size) {
505 printf("read failed (%s)\n", cli_errstr(c2));
506 printf("read %d, expected %d\n", bytes_read, buf_size);
510 if (memcmp(buf_rd, buf, buf_size) != 0)
512 printf("read/write compare failed\n");
517 if (!cli_close(c2, fnum2)) {
518 printf("close failed (%s)\n", cli_errstr(c2));
521 if (!cli_close(c1, fnum1)) {
522 printf("close failed (%s)\n", cli_errstr(c1));
526 if (!cli_unlink(c1, lockfname)) {
527 printf("unlink failed (%s)\n", cli_errstr(c1));
534 static BOOL run_readwritetest(int dummy)
536 static struct cli_state *cli1, *cli2;
539 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
542 cli_sockopt(cli1, sockops);
543 cli_sockopt(cli2, sockops);
545 printf("starting readwritetest\n");
547 test1 = rw_torture2(cli1, cli2);
548 printf("Passed readwritetest v1: %s\n", BOOLSTR(test1));
550 test2 = rw_torture2(cli1, cli1);
551 printf("Passed readwritetest v2: %s\n", BOOLSTR(test2));
553 if (!torture_close_connection(cli1)) {
557 if (!torture_close_connection(cli2)) {
561 return (test1 && test2);
564 static BOOL run_readwritemulti(int dummy)
566 struct cli_state *cli;
571 cli_sockopt(&cli, sockops);
573 printf("run_readwritemulti: fname %s\n", randomfname);
574 test = rw_torture3(&cli, randomfname);
576 if (!torture_close_connection(&cli)) {
583 static BOOL run_readwritelarge(int dummy)
585 static struct cli_state *cli1;
587 const char *lockfname = "\\large.dat";
592 if (!torture_open_connection(&cli1)) {
595 cli_sockopt(cli1, sockops);
596 memset(buf,'\0',sizeof(buf));
598 cli1->max_xmit = 128*1024;
600 printf("starting readwritelarge\n");
602 cli_unlink(cli1, lockfname);
604 fnum1 = cli_open(cli1, lockfname, O_RDWR | O_CREAT | O_EXCL, DENY_NONE);
606 printf("open read/write of %s failed (%s)\n", lockfname, cli_errstr(cli1));
610 cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf));
612 if (!cli_qfileinfo(cli1, fnum1, NULL, &fsize, NULL, NULL, NULL, NULL, NULL)) {
613 printf("qfileinfo failed (%s)\n", cli_errstr(cli1));
617 if (fsize == sizeof(buf))
618 printf("readwritelarge test 1 succeeded (size = %x)\n", fsize);
620 printf("readwritelarge test 1 failed (size = %x)\n", fsize);
624 if (!cli_close(cli1, fnum1)) {
625 printf("close failed (%s)\n", cli_errstr(cli1));
629 if (!cli_unlink(cli1, lockfname)) {
630 printf("unlink failed (%s)\n", cli_errstr(cli1));
634 fnum1 = cli_open(cli1, lockfname, O_RDWR | O_CREAT | O_EXCL, DENY_NONE);
636 printf("open read/write of %s failed (%s)\n", lockfname, cli_errstr(cli1));
640 cli1->max_xmit = 4*1024;
642 cli_smbwrite(cli1, fnum1, buf, 0, sizeof(buf));
644 if (!cli_qfileinfo(cli1, fnum1, NULL, &fsize, NULL, NULL, NULL, NULL, NULL)) {
645 printf("qfileinfo failed (%s)\n", cli_errstr(cli1));
649 if (fsize == sizeof(buf))
650 printf("readwritelarge test 2 succeeded (size = %x)\n", fsize);
652 printf("readwritelarge test 2 failed (size = %x)\n", fsize);
657 /* ToDo - set allocation. JRA */
658 if(!cli_set_allocation_size(cli1, fnum1, 0)) {
659 printf("set allocation size to zero failed (%s)\n", cli_errstr(&cli1));
662 if (!cli_qfileinfo(cli1, fnum1, NULL, &fsize, NULL, NULL, NULL, NULL, NULL)) {
663 printf("qfileinfo failed (%s)\n", cli_errstr(cli1));
667 printf("readwritelarge test 3 (truncate test) succeeded (size = %x)\n", fsize);
670 if (!cli_close(cli1, fnum1)) {
671 printf("close failed (%s)\n", cli_errstr(cli1));
675 if (!torture_close_connection(cli1)) {
684 #define ival(s) strtol(s, NULL, 0)
686 /* run a test that simulates an approximate netbench client load */
687 static BOOL run_netbench(int client)
689 struct cli_state *cli;
702 cli_sockopt(cli, sockops);
706 slprintf(cname,sizeof(fname), "client%d", client);
708 f = fopen(client_txt, "r");
715 while (fgets(line, sizeof(line)-1, f)) {
718 line[strlen(line)-1] = 0;
720 /* printf("[%d] %s\n", line_count, line); */
722 all_string_sub(line,"client1", cname, sizeof(line));
724 /* parse the command parameters */
725 params[0] = strtok(line," ");
727 while (params[i]) params[++i] = strtok(NULL," ");
733 if (!strncmp(params[0],"SMB", 3)) {
734 printf("ERROR: You are using a dbench 1 load file\n");
738 if (!strcmp(params[0],"NTCreateX")) {
739 nb_createx(params[1], ival(params[2]), ival(params[3]),
741 } else if (!strcmp(params[0],"Close")) {
742 nb_close(ival(params[1]));
743 } else if (!strcmp(params[0],"Rename")) {
744 nb_rename(params[1], params[2]);
745 } else if (!strcmp(params[0],"Unlink")) {
746 nb_unlink(params[1]);
747 } else if (!strcmp(params[0],"Deltree")) {
748 nb_deltree(params[1]);
749 } else if (!strcmp(params[0],"Rmdir")) {
751 } else if (!strcmp(params[0],"QUERY_PATH_INFORMATION")) {
752 nb_qpathinfo(params[1]);
753 } else if (!strcmp(params[0],"QUERY_FILE_INFORMATION")) {
754 nb_qfileinfo(ival(params[1]));
755 } else if (!strcmp(params[0],"QUERY_FS_INFORMATION")) {
756 nb_qfsinfo(ival(params[1]));
757 } else if (!strcmp(params[0],"FIND_FIRST")) {
758 nb_findfirst(params[1]);
759 } else if (!strcmp(params[0],"WriteX")) {
760 nb_writex(ival(params[1]),
761 ival(params[2]), ival(params[3]), ival(params[4]));
762 } else if (!strcmp(params[0],"ReadX")) {
763 nb_readx(ival(params[1]),
764 ival(params[2]), ival(params[3]), ival(params[4]));
765 } else if (!strcmp(params[0],"Flush")) {
766 nb_flush(ival(params[1]));
768 printf("Unknown operation %s\n", params[0]);
776 if (!torture_close_connection(cli)) {
784 /* run a test that simulates an approximate netbench client load */
785 static BOOL run_nbench(int dummy)
794 signal(SIGALRM, nb_alarm);
796 t = create_procs(run_netbench, &correct);
799 printf("\nThroughput %g MB/sec\n",
800 1.0e-6 * nbio_total() / t);
806 This test checks for two things:
808 1) correct support for retaining locks over a close (ie. the server
809 must not use posix semantics)
810 2) support for lock timeouts
812 static BOOL run_locktest1(int dummy)
814 struct cli_state *cli1, *cli2;
815 const char *fname = "\\lockt1.lck";
816 int fnum1, fnum2, fnum3;
818 unsigned lock_timeout;
820 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
823 cli_sockopt(cli1, sockops);
824 cli_sockopt(cli2, sockops);
826 printf("starting locktest1\n");
828 cli_unlink(cli1, fname);
830 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
832 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
835 fnum2 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
837 printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli1));
840 fnum3 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
842 printf("open3 of %s failed (%s)\n", fname, cli_errstr(cli2));
846 if (!cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK)) {
847 printf("lock1 failed (%s)\n", cli_errstr(cli1));
852 if (cli_lock(cli2, fnum3, 0, 4, 0, WRITE_LOCK)) {
853 printf("lock2 succeeded! This is a locking bug\n");
856 if (!check_error(__LINE__, cli2, ERRDOS, ERRlock,
857 NT_STATUS_LOCK_NOT_GRANTED)) return False;
861 lock_timeout = (1 + (random() % 20));
862 printf("Testing lock timeout with timeout=%u\n", lock_timeout);
864 if (cli_lock(cli2, fnum3, 0, 4, lock_timeout * 1000, WRITE_LOCK)) {
865 printf("lock3 succeeded! This is a locking bug\n");
868 if (!check_error(__LINE__, cli2, ERRDOS, ERRlock,
869 NT_STATUS_FILE_LOCK_CONFLICT)) return False;
874 printf("error: This server appears not to support timed lock requests\n");
876 printf("server slept for %u seconds for a %u second timeout\n",
877 (unsigned int)(t2-t1), lock_timeout);
879 if (!cli_close(cli1, fnum2)) {
880 printf("close1 failed (%s)\n", cli_errstr(cli1));
884 if (cli_lock(cli2, fnum3, 0, 4, 0, WRITE_LOCK)) {
885 printf("lock4 succeeded! This is a locking bug\n");
888 if (!check_error(__LINE__, cli2, ERRDOS, ERRlock,
889 NT_STATUS_FILE_LOCK_CONFLICT)) return False;
892 if (!cli_close(cli1, fnum1)) {
893 printf("close2 failed (%s)\n", cli_errstr(cli1));
897 if (!cli_close(cli2, fnum3)) {
898 printf("close3 failed (%s)\n", cli_errstr(cli2));
902 if (!cli_unlink(cli1, fname)) {
903 printf("unlink failed (%s)\n", cli_errstr(cli1));
908 if (!torture_close_connection(cli1)) {
912 if (!torture_close_connection(cli2)) {
916 printf("Passed locktest1\n");
921 this checks to see if a secondary tconx can use open files from an
924 static BOOL run_tcon_test(int dummy)
926 static struct cli_state *cli;
927 const char *fname = "\\tcontest.tmp";
929 uint16 cnum1, cnum2, cnum3;
934 if (!torture_open_connection(&cli)) {
937 cli_sockopt(cli, sockops);
939 printf("starting tcontest\n");
941 cli_unlink(cli, fname);
943 fnum1 = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
945 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
952 if (cli_write(cli, fnum1, 0, buf, 130, 4) != 4) {
953 printf("initial write failed (%s)", cli_errstr(cli));
957 if (!cli_send_tconX(cli, share, "?????",
958 password, strlen(password)+1)) {
959 printf("%s refused 2nd tree connect (%s)\n", host,
966 cnum3 = MAX(cnum1, cnum2) + 1; /* any invalid number */
967 vuid2 = cli->vuid + 1;
969 /* try a write with the wrong tid */
972 if (cli_write(cli, fnum1, 0, buf, 130, 4) == 4) {
973 printf("* server allows write with wrong TID\n");
976 printf("server fails write with wrong TID : %s\n", cli_errstr(cli));
980 /* try a write with an invalid tid */
983 if (cli_write(cli, fnum1, 0, buf, 130, 4) == 4) {
984 printf("* server allows write with invalid TID\n");
987 printf("server fails write with invalid TID : %s\n", cli_errstr(cli));
990 /* try a write with an invalid vuid */
994 if (cli_write(cli, fnum1, 0, buf, 130, 4) == 4) {
995 printf("* server allows write with invalid VUID\n");
998 printf("server fails write with invalid VUID : %s\n", cli_errstr(cli));
1004 if (!cli_close(cli, fnum1)) {
1005 printf("close failed (%s)\n", cli_errstr(cli));
1011 if (!cli_tdis(cli)) {
1012 printf("secondary tdis failed (%s)\n", cli_errstr(cli));
1018 if (!torture_close_connection(cli)) {
1027 checks for old style tcon support
1029 static BOOL run_tcon2_test(int dummy)
1031 static struct cli_state *cli;
1032 uint16 cnum, max_xmit;
1036 if (!torture_open_connection(&cli)) {
1039 cli_sockopt(cli, sockops);
1041 printf("starting tcon2 test\n");
1043 asprintf(&service, "\\\\%s\\%s", host, share);
1045 status = cli_raw_tcon(cli, service, password, "?????", &max_xmit, &cnum);
1047 if (!NT_STATUS_IS_OK(status)) {
1048 printf("tcon2 failed : %s\n", cli_errstr(cli));
1050 printf("tcon OK : max_xmit=%d cnum=%d tid=%d\n",
1051 (int)max_xmit, (int)cnum, SVAL(cli->inbuf, smb_tid));
1054 if (!torture_close_connection(cli)) {
1058 printf("Passed tcon2 test\n");
1062 static BOOL tcon_devtest(struct cli_state *cli,
1063 const char *myshare, const char *devtype,
1064 NTSTATUS expected_error)
1069 status = cli_send_tconX(cli, myshare, devtype,
1070 password, strlen(password)+1);
1072 if (NT_STATUS_IS_OK(expected_error)) {
1076 printf("tconX to share %s with type %s "
1077 "should have succeeded but failed\n",
1084 printf("tconx to share %s with type %s "
1085 "should have failed but succeeded\n",
1089 if (NT_STATUS_EQUAL(cli_nt_error(cli),
1093 printf("Returned unexpected error\n");
1102 checks for correct tconX support
1104 static BOOL run_tcon_devtype_test(int dummy)
1106 static struct cli_state *cli1 = NULL;
1112 status = cli_full_connection(&cli1, myname,
1113 host, NULL, port_to_use,
1115 username, workgroup,
1116 password, flags, &retry);
1118 if (!NT_STATUS_IS_OK(status)) {
1119 printf("could not open connection\n");
1123 if (!tcon_devtest(cli1, "IPC$", "A:", NT_STATUS_BAD_DEVICE_TYPE))
1126 if (!tcon_devtest(cli1, "IPC$", "?????", NT_STATUS_OK))
1129 if (!tcon_devtest(cli1, "IPC$", "LPT:", NT_STATUS_BAD_DEVICE_TYPE))
1132 if (!tcon_devtest(cli1, "IPC$", "IPC", NT_STATUS_OK))
1135 if (!tcon_devtest(cli1, "IPC$", "FOOBA", NT_STATUS_BAD_DEVICE_TYPE))
1138 if (!tcon_devtest(cli1, share, "A:", NT_STATUS_OK))
1141 if (!tcon_devtest(cli1, share, "?????", NT_STATUS_OK))
1144 if (!tcon_devtest(cli1, share, "LPT:", NT_STATUS_BAD_DEVICE_TYPE))
1147 if (!tcon_devtest(cli1, share, "IPC", NT_STATUS_BAD_DEVICE_TYPE))
1150 if (!tcon_devtest(cli1, share, "FOOBA", NT_STATUS_BAD_DEVICE_TYPE))
1156 printf("Passed tcondevtest\n");
1163 This test checks that
1165 1) the server supports multiple locking contexts on the one SMB
1166 connection, distinguished by PID.
1168 2) the server correctly fails overlapping locks made by the same PID (this
1169 goes against POSIX behaviour, which is why it is tricky to implement)
1171 3) the server denies unlock requests by an incorrect client PID
1173 static BOOL run_locktest2(int dummy)
1175 static struct cli_state *cli;
1176 const char *fname = "\\lockt2.lck";
1177 int fnum1, fnum2, fnum3;
1178 BOOL correct = True;
1180 if (!torture_open_connection(&cli)) {
1184 cli_sockopt(cli, sockops);
1186 printf("starting locktest2\n");
1188 cli_unlink(cli, fname);
1192 fnum1 = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1194 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
1198 fnum2 = cli_open(cli, fname, O_RDWR, DENY_NONE);
1200 printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli));
1206 fnum3 = cli_open(cli, fname, O_RDWR, DENY_NONE);
1208 printf("open3 of %s failed (%s)\n", fname, cli_errstr(cli));
1214 if (!cli_lock(cli, fnum1, 0, 4, 0, WRITE_LOCK)) {
1215 printf("lock1 failed (%s)\n", cli_errstr(cli));
1219 if (cli_lock(cli, fnum1, 0, 4, 0, WRITE_LOCK)) {
1220 printf("WRITE lock1 succeeded! This is a locking bug\n");
1223 if (!check_error(__LINE__, cli, ERRDOS, ERRlock,
1224 NT_STATUS_LOCK_NOT_GRANTED)) return False;
1227 if (cli_lock(cli, fnum2, 0, 4, 0, WRITE_LOCK)) {
1228 printf("WRITE lock2 succeeded! This is a locking bug\n");
1231 if (!check_error(__LINE__, cli, ERRDOS, ERRlock,
1232 NT_STATUS_LOCK_NOT_GRANTED)) return False;
1235 if (cli_lock(cli, fnum2, 0, 4, 0, READ_LOCK)) {
1236 printf("READ lock2 succeeded! This is a locking bug\n");
1239 if (!check_error(__LINE__, cli, ERRDOS, ERRlock,
1240 NT_STATUS_FILE_LOCK_CONFLICT)) return False;
1243 if (!cli_lock(cli, fnum1, 100, 4, 0, WRITE_LOCK)) {
1244 printf("lock at 100 failed (%s)\n", cli_errstr(cli));
1247 if (cli_unlock(cli, fnum1, 100, 4)) {
1248 printf("unlock at 100 succeeded! This is a locking bug\n");
1252 if (cli_unlock(cli, fnum1, 0, 4)) {
1253 printf("unlock1 succeeded! This is a locking bug\n");
1256 if (!check_error(__LINE__, cli,
1258 NT_STATUS_RANGE_NOT_LOCKED)) return False;
1261 if (cli_unlock(cli, fnum1, 0, 8)) {
1262 printf("unlock2 succeeded! This is a locking bug\n");
1265 if (!check_error(__LINE__, cli,
1267 NT_STATUS_RANGE_NOT_LOCKED)) return False;
1270 if (cli_lock(cli, fnum3, 0, 4, 0, WRITE_LOCK)) {
1271 printf("lock3 succeeded! This is a locking bug\n");
1274 if (!check_error(__LINE__, cli, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False;
1279 if (!cli_close(cli, fnum1)) {
1280 printf("close1 failed (%s)\n", cli_errstr(cli));
1284 if (!cli_close(cli, fnum2)) {
1285 printf("close2 failed (%s)\n", cli_errstr(cli));
1289 if (!cli_close(cli, fnum3)) {
1290 printf("close3 failed (%s)\n", cli_errstr(cli));
1294 if (!torture_close_connection(cli)) {
1298 printf("locktest2 finished\n");
1305 This test checks that
1307 1) the server supports the full offset range in lock requests
1309 static BOOL run_locktest3(int dummy)
1311 static struct cli_state *cli1, *cli2;
1312 const char *fname = "\\lockt3.lck";
1313 int fnum1, fnum2, i;
1315 BOOL correct = True;
1317 #define NEXT_OFFSET offset += (~(uint32)0) / torture_numops
1319 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
1322 cli_sockopt(cli1, sockops);
1323 cli_sockopt(cli2, sockops);
1325 printf("starting locktest3\n");
1327 cli_unlink(cli1, fname);
1329 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1331 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
1334 fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
1336 printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli2));
1340 for (offset=i=0;i<torture_numops;i++) {
1342 if (!cli_lock(cli1, fnum1, offset-1, 1, 0, WRITE_LOCK)) {
1343 printf("lock1 %d failed (%s)\n",
1349 if (!cli_lock(cli2, fnum2, offset-2, 1, 0, WRITE_LOCK)) {
1350 printf("lock2 %d failed (%s)\n",
1357 for (offset=i=0;i<torture_numops;i++) {
1360 if (cli_lock(cli1, fnum1, offset-2, 1, 0, WRITE_LOCK)) {
1361 printf("error: lock1 %d succeeded!\n", i);
1365 if (cli_lock(cli2, fnum2, offset-1, 1, 0, WRITE_LOCK)) {
1366 printf("error: lock2 %d succeeded!\n", i);
1370 if (cli_lock(cli1, fnum1, offset-1, 1, 0, WRITE_LOCK)) {
1371 printf("error: lock3 %d succeeded!\n", i);
1375 if (cli_lock(cli2, fnum2, offset-2, 1, 0, WRITE_LOCK)) {
1376 printf("error: lock4 %d succeeded!\n", i);
1381 for (offset=i=0;i<torture_numops;i++) {
1384 if (!cli_unlock(cli1, fnum1, offset-1, 1)) {
1385 printf("unlock1 %d failed (%s)\n",
1391 if (!cli_unlock(cli2, fnum2, offset-2, 1)) {
1392 printf("unlock2 %d failed (%s)\n",
1399 if (!cli_close(cli1, fnum1)) {
1400 printf("close1 failed (%s)\n", cli_errstr(cli1));
1404 if (!cli_close(cli2, fnum2)) {
1405 printf("close2 failed (%s)\n", cli_errstr(cli2));
1409 if (!cli_unlink(cli1, fname)) {
1410 printf("unlink failed (%s)\n", cli_errstr(cli1));
1414 if (!torture_close_connection(cli1)) {
1418 if (!torture_close_connection(cli2)) {
1422 printf("finished locktest3\n");
1427 #define EXPECTED(ret, v) if ((ret) != (v)) { \
1428 printf("** "); correct = False; \
1432 looks at overlapping locks
1434 static BOOL run_locktest4(int dummy)
1436 static struct cli_state *cli1, *cli2;
1437 const char *fname = "\\lockt4.lck";
1438 int fnum1, fnum2, f;
1441 BOOL correct = True;
1443 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
1447 cli_sockopt(cli1, sockops);
1448 cli_sockopt(cli2, sockops);
1450 printf("starting locktest4\n");
1452 cli_unlink(cli1, fname);
1454 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1455 fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
1457 memset(buf, 0, sizeof(buf));
1459 if (cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
1460 printf("Failed to create file\n");
1465 ret = cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK) &&
1466 cli_lock(cli1, fnum1, 2, 4, 0, WRITE_LOCK);
1467 EXPECTED(ret, False);
1468 printf("the same process %s set overlapping write locks\n", ret?"can":"cannot");
1470 ret = cli_lock(cli1, fnum1, 10, 4, 0, READ_LOCK) &&
1471 cli_lock(cli1, fnum1, 12, 4, 0, READ_LOCK);
1472 EXPECTED(ret, True);
1473 printf("the same process %s set overlapping read locks\n", ret?"can":"cannot");
1475 ret = cli_lock(cli1, fnum1, 20, 4, 0, WRITE_LOCK) &&
1476 cli_lock(cli2, fnum2, 22, 4, 0, WRITE_LOCK);
1477 EXPECTED(ret, False);
1478 printf("a different connection %s set overlapping write locks\n", ret?"can":"cannot");
1480 ret = cli_lock(cli1, fnum1, 30, 4, 0, READ_LOCK) &&
1481 cli_lock(cli2, fnum2, 32, 4, 0, READ_LOCK);
1482 EXPECTED(ret, True);
1483 printf("a different connection %s set overlapping read locks\n", ret?"can":"cannot");
1485 ret = (cli_setpid(cli1, 1), cli_lock(cli1, fnum1, 40, 4, 0, WRITE_LOCK)) &&
1486 (cli_setpid(cli1, 2), cli_lock(cli1, fnum1, 42, 4, 0, WRITE_LOCK));
1487 EXPECTED(ret, False);
1488 printf("a different pid %s set overlapping write locks\n", ret?"can":"cannot");
1490 ret = (cli_setpid(cli1, 1), cli_lock(cli1, fnum1, 50, 4, 0, READ_LOCK)) &&
1491 (cli_setpid(cli1, 2), cli_lock(cli1, fnum1, 52, 4, 0, READ_LOCK));
1492 EXPECTED(ret, True);
1493 printf("a different pid %s set overlapping read locks\n", ret?"can":"cannot");
1495 ret = cli_lock(cli1, fnum1, 60, 4, 0, READ_LOCK) &&
1496 cli_lock(cli1, fnum1, 60, 4, 0, READ_LOCK);
1497 EXPECTED(ret, True);
1498 printf("the same process %s set the same read lock twice\n", ret?"can":"cannot");
1500 ret = cli_lock(cli1, fnum1, 70, 4, 0, WRITE_LOCK) &&
1501 cli_lock(cli1, fnum1, 70, 4, 0, WRITE_LOCK);
1502 EXPECTED(ret, False);
1503 printf("the same process %s set the same write lock twice\n", ret?"can":"cannot");
1505 ret = cli_lock(cli1, fnum1, 80, 4, 0, READ_LOCK) &&
1506 cli_lock(cli1, fnum1, 80, 4, 0, WRITE_LOCK);
1507 EXPECTED(ret, False);
1508 printf("the same process %s overlay a read lock with a write lock\n", ret?"can":"cannot");
1510 ret = cli_lock(cli1, fnum1, 90, 4, 0, WRITE_LOCK) &&
1511 cli_lock(cli1, fnum1, 90, 4, 0, READ_LOCK);
1512 EXPECTED(ret, True);
1513 printf("the same process %s overlay a write lock with a read lock\n", ret?"can":"cannot");
1515 ret = (cli_setpid(cli1, 1), cli_lock(cli1, fnum1, 100, 4, 0, WRITE_LOCK)) &&
1516 (cli_setpid(cli1, 2), cli_lock(cli1, fnum1, 100, 4, 0, READ_LOCK));
1517 EXPECTED(ret, False);
1518 printf("a different pid %s overlay a write lock with a read lock\n", ret?"can":"cannot");
1520 ret = cli_lock(cli1, fnum1, 110, 4, 0, READ_LOCK) &&
1521 cli_lock(cli1, fnum1, 112, 4, 0, READ_LOCK) &&
1522 cli_unlock(cli1, fnum1, 110, 6);
1523 EXPECTED(ret, False);
1524 printf("the same process %s coalesce read locks\n", ret?"can":"cannot");
1527 ret = cli_lock(cli1, fnum1, 120, 4, 0, WRITE_LOCK) &&
1528 (cli_read(cli2, fnum2, buf, 120, 4) == 4);
1529 EXPECTED(ret, False);
1530 printf("this server %s strict write locking\n", ret?"doesn't do":"does");
1532 ret = cli_lock(cli1, fnum1, 130, 4, 0, READ_LOCK) &&
1533 (cli_write(cli2, fnum2, 0, buf, 130, 4) == 4);
1534 EXPECTED(ret, False);
1535 printf("this server %s strict read locking\n", ret?"doesn't do":"does");
1538 ret = cli_lock(cli1, fnum1, 140, 4, 0, READ_LOCK) &&
1539 cli_lock(cli1, fnum1, 140, 4, 0, READ_LOCK) &&
1540 cli_unlock(cli1, fnum1, 140, 4) &&
1541 cli_unlock(cli1, fnum1, 140, 4);
1542 EXPECTED(ret, True);
1543 printf("this server %s do recursive read locking\n", ret?"does":"doesn't");
1546 ret = cli_lock(cli1, fnum1, 150, 4, 0, WRITE_LOCK) &&
1547 cli_lock(cli1, fnum1, 150, 4, 0, READ_LOCK) &&
1548 cli_unlock(cli1, fnum1, 150, 4) &&
1549 (cli_read(cli2, fnum2, buf, 150, 4) == 4) &&
1550 !(cli_write(cli2, fnum2, 0, buf, 150, 4) == 4) &&
1551 cli_unlock(cli1, fnum1, 150, 4);
1552 EXPECTED(ret, True);
1553 printf("this server %s do recursive lock overlays\n", ret?"does":"doesn't");
1555 ret = cli_lock(cli1, fnum1, 160, 4, 0, READ_LOCK) &&
1556 cli_unlock(cli1, fnum1, 160, 4) &&
1557 (cli_write(cli2, fnum2, 0, buf, 160, 4) == 4) &&
1558 (cli_read(cli2, fnum2, buf, 160, 4) == 4);
1559 EXPECTED(ret, True);
1560 printf("the same process %s remove a read lock using write locking\n", ret?"can":"cannot");
1562 ret = cli_lock(cli1, fnum1, 170, 4, 0, WRITE_LOCK) &&
1563 cli_unlock(cli1, fnum1, 170, 4) &&
1564 (cli_write(cli2, fnum2, 0, buf, 170, 4) == 4) &&
1565 (cli_read(cli2, fnum2, buf, 170, 4) == 4);
1566 EXPECTED(ret, True);
1567 printf("the same process %s remove a write lock using read locking\n", ret?"can":"cannot");
1569 ret = cli_lock(cli1, fnum1, 190, 4, 0, WRITE_LOCK) &&
1570 cli_lock(cli1, fnum1, 190, 4, 0, READ_LOCK) &&
1571 cli_unlock(cli1, fnum1, 190, 4) &&
1572 !(cli_write(cli2, fnum2, 0, buf, 190, 4) == 4) &&
1573 (cli_read(cli2, fnum2, buf, 190, 4) == 4);
1574 EXPECTED(ret, True);
1575 printf("the same process %s remove the first lock first\n", ret?"does":"doesn't");
1577 cli_close(cli1, fnum1);
1578 cli_close(cli2, fnum2);
1579 fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1580 f = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1581 ret = cli_lock(cli1, fnum1, 0, 8, 0, READ_LOCK) &&
1582 cli_lock(cli1, f, 0, 1, 0, READ_LOCK) &&
1583 cli_close(cli1, fnum1) &&
1584 ((fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE)) != -1) &&
1585 cli_lock(cli1, fnum1, 7, 1, 0, WRITE_LOCK);
1587 cli_close(cli1, fnum1);
1588 EXPECTED(ret, True);
1589 printf("the server %s have the NT byte range lock bug\n", !ret?"does":"doesn't");
1592 cli_close(cli1, fnum1);
1593 cli_close(cli2, fnum2);
1594 cli_unlink(cli1, fname);
1595 torture_close_connection(cli1);
1596 torture_close_connection(cli2);
1598 printf("finished locktest4\n");
1603 looks at lock upgrade/downgrade.
1605 static BOOL run_locktest5(int dummy)
1607 static struct cli_state *cli1, *cli2;
1608 const char *fname = "\\lockt5.lck";
1609 int fnum1, fnum2, fnum3;
1612 BOOL correct = True;
1614 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
1618 cli_sockopt(cli1, sockops);
1619 cli_sockopt(cli2, sockops);
1621 printf("starting locktest5\n");
1623 cli_unlink(cli1, fname);
1625 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1626 fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
1627 fnum3 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1629 memset(buf, 0, sizeof(buf));
1631 if (cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
1632 printf("Failed to create file\n");
1637 /* Check for NT bug... */
1638 ret = cli_lock(cli1, fnum1, 0, 8, 0, READ_LOCK) &&
1639 cli_lock(cli1, fnum3, 0, 1, 0, READ_LOCK);
1640 cli_close(cli1, fnum1);
1641 fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1642 ret = cli_lock(cli1, fnum1, 7, 1, 0, WRITE_LOCK);
1643 EXPECTED(ret, True);
1644 printf("this server %s the NT locking bug\n", ret ? "doesn't have" : "has");
1645 cli_close(cli1, fnum1);
1646 fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
1647 cli_unlock(cli1, fnum3, 0, 1);
1649 ret = cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK) &&
1650 cli_lock(cli1, fnum1, 1, 1, 0, READ_LOCK);
1651 EXPECTED(ret, True);
1652 printf("the same process %s overlay a write with a read lock\n", ret?"can":"cannot");
1654 ret = cli_lock(cli2, fnum2, 0, 4, 0, READ_LOCK);
1655 EXPECTED(ret, False);
1657 printf("a different processs %s get a read lock on the first process lock stack\n", ret?"can":"cannot");
1659 /* Unlock the process 2 lock. */
1660 cli_unlock(cli2, fnum2, 0, 4);
1662 ret = cli_lock(cli1, fnum3, 0, 4, 0, READ_LOCK);
1663 EXPECTED(ret, False);
1665 printf("the same processs on a different fnum %s get a read lock\n", ret?"can":"cannot");
1667 /* Unlock the process 1 fnum3 lock. */
1668 cli_unlock(cli1, fnum3, 0, 4);
1670 /* Stack 2 more locks here. */
1671 ret = cli_lock(cli1, fnum1, 0, 4, 0, READ_LOCK) &&
1672 cli_lock(cli1, fnum1, 0, 4, 0, READ_LOCK);
1674 EXPECTED(ret, True);
1675 printf("the same process %s stack read locks\n", ret?"can":"cannot");
1677 /* Unlock the first process lock, then check this was the WRITE lock that was
1680 ret = cli_unlock(cli1, fnum1, 0, 4) &&
1681 cli_lock(cli2, fnum2, 0, 4, 0, READ_LOCK);
1683 EXPECTED(ret, True);
1684 printf("the first unlock removes the %s lock\n", ret?"WRITE":"READ");
1686 /* Unlock the process 2 lock. */
1687 cli_unlock(cli2, fnum2, 0, 4);
1689 /* We should have 3 stacked locks here. Ensure we need to do 3 unlocks. */
1691 ret = cli_unlock(cli1, fnum1, 1, 1) &&
1692 cli_unlock(cli1, fnum1, 0, 4) &&
1693 cli_unlock(cli1, fnum1, 0, 4);
1695 EXPECTED(ret, True);
1696 printf("the same process %s unlock the stack of 4 locks\n", ret?"can":"cannot");
1698 /* Ensure the next unlock fails. */
1699 ret = cli_unlock(cli1, fnum1, 0, 4);
1700 EXPECTED(ret, False);
1701 printf("the same process %s count the lock stack\n", !ret?"can":"cannot");
1703 /* Ensure connection 2 can get a write lock. */
1704 ret = cli_lock(cli2, fnum2, 0, 4, 0, WRITE_LOCK);
1705 EXPECTED(ret, True);
1707 printf("a different processs %s get a write lock on the unlocked stack\n", ret?"can":"cannot");
1711 cli_close(cli1, fnum1);
1712 cli_close(cli2, fnum2);
1713 cli_unlink(cli1, fname);
1714 if (!torture_close_connection(cli1)) {
1717 if (!torture_close_connection(cli2)) {
1721 printf("finished locktest5\n");
1727 tries the unusual lockingX locktype bits
1729 static BOOL run_locktest6(int dummy)
1731 static struct cli_state *cli;
1732 const char *fname[1] = { "\\lock6.txt" };
1737 if (!torture_open_connection(&cli)) {
1741 cli_sockopt(cli, sockops);
1743 printf("starting locktest6\n");
1746 printf("Testing %s\n", fname[i]);
1748 cli_unlink(cli, fname[i]);
1750 fnum = cli_open(cli, fname[i], O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1751 status = cli_locktype(cli, fnum, 0, 8, 0, LOCKING_ANDX_CHANGE_LOCKTYPE);
1752 cli_close(cli, fnum);
1753 printf("CHANGE_LOCKTYPE gave %s\n", nt_errstr(status));
1755 fnum = cli_open(cli, fname[i], O_RDWR, DENY_NONE);
1756 status = cli_locktype(cli, fnum, 0, 8, 0, LOCKING_ANDX_CANCEL_LOCK);
1757 cli_close(cli, fnum);
1758 printf("CANCEL_LOCK gave %s\n", nt_errstr(status));
1760 cli_unlink(cli, fname[i]);
1763 torture_close_connection(cli);
1765 printf("finished locktest6\n");
1769 static BOOL run_locktest7(int dummy)
1771 struct cli_state *cli1;
1772 const char *fname = "\\lockt7.lck";
1775 BOOL correct = False;
1777 if (!torture_open_connection(&cli1)) {
1781 cli_sockopt(cli1, sockops);
1783 printf("starting locktest7\n");
1785 cli_unlink(cli1, fname);
1787 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1789 memset(buf, 0, sizeof(buf));
1791 if (cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
1792 printf("Failed to create file\n");
1796 cli_setpid(cli1, 1);
1798 if (!cli_lock(cli1, fnum1, 130, 4, 0, READ_LOCK)) {
1799 printf("Unable to apply read lock on range 130:4, error was %s\n", cli_errstr(cli1));
1802 printf("pid1 successfully locked range 130:4 for READ\n");
1805 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
1806 printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
1809 printf("pid1 successfully read the range 130:4\n");
1812 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
1813 printf("pid1 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
1814 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
1815 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
1819 printf("pid1 successfully wrote to the range 130:4 (should be denied)\n");
1823 cli_setpid(cli1, 2);
1825 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
1826 printf("pid2 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
1828 printf("pid2 successfully read the range 130:4\n");
1831 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
1832 printf("pid2 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
1833 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
1834 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
1838 printf("pid2 successfully wrote to the range 130:4 (should be denied)\n");
1842 cli_setpid(cli1, 1);
1843 cli_unlock(cli1, fnum1, 130, 4);
1845 if (!cli_lock(cli1, fnum1, 130, 4, 0, WRITE_LOCK)) {
1846 printf("Unable to apply write lock on range 130:4, error was %s\n", cli_errstr(cli1));
1849 printf("pid1 successfully locked range 130:4 for WRITE\n");
1852 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
1853 printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
1856 printf("pid1 successfully read the range 130:4\n");
1859 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
1860 printf("pid1 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
1863 printf("pid1 successfully wrote to the range 130:4\n");
1866 cli_setpid(cli1, 2);
1868 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
1869 printf("pid2 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
1870 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
1871 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
1875 printf("pid2 successfully read the range 130:4 (should be denied)\n");
1879 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
1880 printf("pid2 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
1881 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
1882 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
1886 printf("pid2 successfully wrote to the range 130:4 (should be denied)\n");
1890 cli_unlock(cli1, fnum1, 130, 0);
1894 cli_close(cli1, fnum1);
1895 cli_unlink(cli1, fname);
1896 torture_close_connection(cli1);
1898 printf("finished locktest7\n");
1903 test whether fnums and tids open on one VC are available on another (a major
1906 static BOOL run_fdpasstest(int dummy)
1908 struct cli_state *cli1, *cli2;
1909 const char *fname = "\\fdpass.tst";
1913 if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
1916 cli_sockopt(cli1, sockops);
1917 cli_sockopt(cli2, sockops);
1919 printf("starting fdpasstest\n");
1921 cli_unlink(cli1, fname);
1923 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1925 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
1929 if (cli_write(cli1, fnum1, 0, "hello world\n", 0, 13) != 13) {
1930 printf("write failed (%s)\n", cli_errstr(cli1));
1934 cli2->vuid = cli1->vuid;
1935 cli2->cnum = cli1->cnum;
1936 cli2->pid = cli1->pid;
1938 if (cli_read(cli2, fnum1, buf, 0, 13) == 13) {
1939 printf("read succeeded! nasty security hole [%s]\n",
1944 cli_close(cli1, fnum1);
1945 cli_unlink(cli1, fname);
1947 torture_close_connection(cli1);
1948 torture_close_connection(cli2);
1950 printf("finished fdpasstest\n");
1954 static BOOL run_fdsesstest(int dummy)
1956 struct cli_state *cli;
1961 const char *fname = "\\fdsess.tst";
1962 const char *fname1 = "\\fdsess1.tst";
1968 if (!torture_open_connection(&cli))
1970 cli_sockopt(cli, sockops);
1972 if (!torture_cli_session_setup2(cli, &new_vuid))
1975 saved_cnum = cli->cnum;
1976 if (!cli_send_tconX(cli, share, "?????", "", 1))
1978 new_cnum = cli->cnum;
1979 cli->cnum = saved_cnum;
1981 printf("starting fdsesstest\n");
1983 cli_unlink(cli, fname);
1984 cli_unlink(cli, fname1);
1986 fnum1 = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1988 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
1992 if (cli_write(cli, fnum1, 0, "hello world\n", 0, 13) != 13) {
1993 printf("write failed (%s)\n", cli_errstr(cli));
1997 saved_vuid = cli->vuid;
1998 cli->vuid = new_vuid;
2000 if (cli_read(cli, fnum1, buf, 0, 13) == 13) {
2001 printf("read succeeded with different vuid! nasty security hole [%s]\n",
2005 /* Try to open a file with different vuid, samba cnum. */
2006 fnum2 = cli_open(cli, fname1, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2008 printf("create with different vuid, same cnum succeeded.\n");
2009 cli_close(cli, fnum2);
2010 cli_unlink(cli, fname1);
2012 printf("create with different vuid, same cnum failed.\n");
2013 printf("This will cause problems with service clients.\n");
2017 cli->vuid = saved_vuid;
2019 /* Try with same vuid, different cnum. */
2020 cli->cnum = new_cnum;
2022 if (cli_read(cli, fnum1, buf, 0, 13) == 13) {
2023 printf("read succeeded with different cnum![%s]\n",
2028 cli->cnum = saved_cnum;
2029 cli_close(cli, fnum1);
2030 cli_unlink(cli, fname);
2032 torture_close_connection(cli);
2034 printf("finished fdsesstest\n");
2039 This test checks that
2041 1) the server does not allow an unlink on a file that is open
2043 static BOOL run_unlinktest(int dummy)
2045 struct cli_state *cli;
2046 const char *fname = "\\unlink.tst";
2048 BOOL correct = True;
2050 if (!torture_open_connection(&cli)) {
2054 cli_sockopt(cli, sockops);
2056 printf("starting unlink test\n");
2058 cli_unlink(cli, fname);
2062 fnum = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2064 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
2068 if (cli_unlink(cli, fname)) {
2069 printf("error: server allowed unlink on an open file\n");
2072 correct = check_error(__LINE__, cli, ERRDOS, ERRbadshare,
2073 NT_STATUS_SHARING_VIOLATION);
2076 cli_close(cli, fnum);
2077 cli_unlink(cli, fname);
2079 if (!torture_close_connection(cli)) {
2083 printf("unlink test finished\n");
2090 test how many open files this server supports on the one socket
2092 static BOOL run_maxfidtest(int dummy)
2094 struct cli_state *cli;
2095 const char *template = "\\maxfid.%d.%d";
2097 int fnums[0x11000], i;
2099 BOOL correct = True;
2104 printf("failed to connect\n");
2108 cli_sockopt(cli, sockops);
2110 for (i=0; i<0x11000; i++) {
2111 slprintf(fname,sizeof(fname)-1,template, i,(int)getpid());
2112 if ((fnums[i] = cli_open(cli, fname,
2113 O_RDWR|O_CREAT|O_TRUNC, DENY_NONE)) ==
2115 printf("open of %s failed (%s)\n",
2116 fname, cli_errstr(cli));
2117 printf("maximum fnum is %d\n", i);
2125 printf("cleaning up\n");
2127 slprintf(fname,sizeof(fname)-1,template, i,(int)getpid());
2128 cli_close(cli, fnums[i]);
2129 if (!cli_unlink(cli, fname)) {
2130 printf("unlink of %s failed (%s)\n",
2131 fname, cli_errstr(cli));
2138 printf("maxfid test finished\n");
2139 if (!torture_close_connection(cli)) {
2145 /* generate a random buffer */
2146 static void rand_buf(char *buf, int len)
2149 *buf = (char)sys_random();
2154 /* send smb negprot commands, not reading the response */
2155 static BOOL run_negprot_nowait(int dummy)
2158 static struct cli_state cli;
2159 BOOL correct = True;
2161 printf("starting negprot nowait test\n");
2163 if (!open_nbt_connection(&cli)) {
2167 for (i=0;i<50000;i++) {
2168 cli_negprot_send(&cli);
2171 if (!torture_close_connection(&cli)) {
2175 printf("finished negprot nowait test\n");
2181 /* send random IPC commands */
2182 static BOOL run_randomipc(int dummy)
2184 char *rparam = NULL;
2188 int api, param_len, i;
2189 struct cli_state *cli;
2190 BOOL correct = True;
2193 printf("starting random ipc test\n");
2195 if (!torture_open_connection(&cli)) {
2199 for (i=0;i<count;i++) {
2200 api = sys_random() % 500;
2201 param_len = (sys_random() % 64);
2203 rand_buf(param, param_len);
2208 param, param_len, 8,
2209 NULL, 0, BUFFER_SIZE,
2213 printf("%d/%d\r", i,count);
2216 printf("%d/%d\n", i, count);
2218 if (!torture_close_connection(cli)) {
2222 printf("finished random ipc test\n");
2229 static void browse_callback(const char *sname, uint32 stype,
2230 const char *comment, void *state)
2232 printf("\t%20.20s %08x %s\n", sname, stype, comment);
2238 This test checks the browse list code
2241 static BOOL run_browsetest(int dummy)
2243 static struct cli_state *cli;
2244 BOOL correct = True;
2246 printf("starting browse test\n");
2248 if (!torture_open_connection(&cli)) {
2252 printf("domain list:\n");
2253 cli_NetServerEnum(cli, cli->server_domain,
2254 SV_TYPE_DOMAIN_ENUM,
2255 browse_callback, NULL);
2257 printf("machine list:\n");
2258 cli_NetServerEnum(cli, cli->server_domain,
2260 browse_callback, NULL);
2262 if (!torture_close_connection(cli)) {
2266 printf("browse test finished\n");
2274 This checks how the getatr calls works
2276 static BOOL run_attrtest(int dummy)
2278 struct cli_state *cli;
2281 const char *fname = "\\attrib123456789.tst";
2282 BOOL correct = True;
2284 printf("starting attrib test\n");
2286 if (!torture_open_connection(&cli)) {
2290 cli_unlink(cli, fname);
2291 fnum = cli_open(cli, fname,
2292 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2293 cli_close(cli, fnum);
2294 if (!cli_getatr(cli, fname, NULL, NULL, &t)) {
2295 printf("getatr failed (%s)\n", cli_errstr(cli));
2299 if (abs(t - time(NULL)) > 60*60*24*10) {
2300 printf("ERROR: SMBgetatr bug. time is %s",
2306 t2 = t-60*60*24; /* 1 day ago */
2308 if (!cli_setatr(cli, fname, 0, t2)) {
2309 printf("setatr failed (%s)\n", cli_errstr(cli));
2313 if (!cli_getatr(cli, fname, NULL, NULL, &t)) {
2314 printf("getatr failed (%s)\n", cli_errstr(cli));
2319 printf("ERROR: getatr/setatr bug. times are\n%s",
2321 printf("%s", ctime(&t2));
2325 cli_unlink(cli, fname);
2327 if (!torture_close_connection(cli)) {
2331 printf("attrib test finished\n");
2338 This checks a couple of trans2 calls
2340 static BOOL run_trans2test(int dummy)
2342 struct cli_state *cli;
2345 time_t c_time, a_time, m_time, w_time, m_time2;
2346 const char *fname = "\\trans2.tst";
2347 const char *dname = "\\trans2";
2348 const char *fname2 = "\\trans2\\trans2.tst";
2350 BOOL correct = True;
2352 printf("starting trans2 test\n");
2354 if (!torture_open_connection(&cli)) {
2358 cli_unlink(cli, fname);
2359 fnum = cli_open(cli, fname,
2360 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2361 if (!cli_qfileinfo(cli, fnum, NULL, &size, &c_time, &a_time, &m_time,
2363 printf("ERROR: qfileinfo failed (%s)\n", cli_errstr(cli));
2367 if (!cli_qfilename(cli, fnum, pname)) {
2368 printf("ERROR: qfilename failed (%s)\n", cli_errstr(cli));
2372 if (strcmp(pname, fname)) {
2373 printf("qfilename gave different name? [%s] [%s]\n",
2378 cli_close(cli, fnum);
2382 cli_unlink(cli, fname);
2383 fnum = cli_open(cli, fname,
2384 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2386 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
2389 cli_close(cli, fnum);
2391 if (!cli_qpathinfo(cli, fname, &c_time, &a_time, &m_time, &size, NULL)) {
2392 printf("ERROR: qpathinfo failed (%s)\n", cli_errstr(cli));
2395 if (c_time != m_time) {
2396 printf("create time=%s", ctime(&c_time));
2397 printf("modify time=%s", ctime(&m_time));
2398 printf("This system appears to have sticky create times\n");
2400 if (a_time % (60*60) == 0) {
2401 printf("access time=%s", ctime(&a_time));
2402 printf("This system appears to set a midnight access time\n");
2406 if (abs(m_time - time(NULL)) > 60*60*24*7) {
2407 printf("ERROR: totally incorrect times - maybe word reversed? mtime=%s", ctime(&m_time));
2413 cli_unlink(cli, fname);
2414 fnum = cli_open(cli, fname,
2415 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2416 cli_close(cli, fnum);
2417 if (!cli_qpathinfo2(cli, fname, &c_time, &a_time, &m_time,
2418 &w_time, &size, NULL, NULL)) {
2419 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli));
2422 if (w_time < 60*60*24*2) {
2423 printf("write time=%s", ctime(&w_time));
2424 printf("This system appears to set a initial 0 write time\n");
2429 cli_unlink(cli, fname);
2432 /* check if the server updates the directory modification time
2433 when creating a new file */
2434 if (!cli_mkdir(cli, dname)) {
2435 printf("ERROR: mkdir failed (%s)\n", cli_errstr(cli));
2439 if (!cli_qpathinfo2(cli, "\\trans2\\", &c_time, &a_time, &m_time,
2440 &w_time, &size, NULL, NULL)) {
2441 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli));
2445 fnum = cli_open(cli, fname2,
2446 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
2447 cli_write(cli, fnum, 0, (char *)&fnum, 0, sizeof(fnum));
2448 cli_close(cli, fnum);
2449 if (!cli_qpathinfo2(cli, "\\trans2\\", &c_time, &a_time, &m_time2,
2450 &w_time, &size, NULL, NULL)) {
2451 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli));
2454 if (m_time2 == m_time) {
2455 printf("This system does not update directory modification times\n");
2459 cli_unlink(cli, fname2);
2460 cli_rmdir(cli, dname);
2462 if (!torture_close_connection(cli)) {
2466 printf("trans2 test finished\n");
2472 This checks new W2K calls.
2475 static BOOL new_trans(struct cli_state *pcli, int fnum, int level)
2478 BOOL correct = True;
2480 memset(buf, 0xff, sizeof(buf));
2482 if (!cli_qfileinfo_test(pcli, fnum, level, buf)) {
2483 printf("ERROR: qfileinfo (%d) failed (%s)\n", level, cli_errstr(pcli));
2486 printf("qfileinfo: level %d\n", level);
2487 dump_data(0, buf, 256);
2493 static BOOL run_w2ktest(int dummy)
2495 struct cli_state *cli;
2497 const char *fname = "\\w2ktest\\w2k.tst";
2499 BOOL correct = True;
2501 printf("starting w2k test\n");
2503 if (!torture_open_connection(&cli)) {
2507 fnum = cli_open(cli, fname,
2508 O_RDWR | O_CREAT , DENY_NONE);
2510 for (level = 1004; level < 1040; level++) {
2511 new_trans(cli, fnum, level);
2514 cli_close(cli, fnum);
2516 if (!torture_close_connection(cli)) {
2520 printf("w2k test finished\n");
2527 this is a harness for some oplock tests
2529 static BOOL run_oplock1(int dummy)
2531 struct cli_state *cli1;
2532 const char *fname = "\\lockt1.lck";
2534 BOOL correct = True;
2536 printf("starting oplock test 1\n");
2538 if (!torture_open_connection(&cli1)) {
2542 cli_unlink(cli1, fname);
2544 cli_sockopt(cli1, sockops);
2546 cli1->use_oplocks = True;
2548 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2550 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
2554 cli1->use_oplocks = False;
2556 cli_unlink(cli1, fname);
2557 cli_unlink(cli1, fname);
2559 if (!cli_close(cli1, fnum1)) {
2560 printf("close2 failed (%s)\n", cli_errstr(cli1));
2564 if (!cli_unlink(cli1, fname)) {
2565 printf("unlink failed (%s)\n", cli_errstr(cli1));
2569 if (!torture_close_connection(cli1)) {
2573 printf("finished oplock test 1\n");
2578 static BOOL run_oplock2(int dummy)
2580 struct cli_state *cli1, *cli2;
2581 const char *fname = "\\lockt2.lck";
2583 int saved_use_oplocks = use_oplocks;
2585 BOOL correct = True;
2586 volatile BOOL *shared_correct;
2588 shared_correct = (volatile BOOL *)shm_setup(sizeof(BOOL));
2589 *shared_correct = True;
2591 use_level_II_oplocks = True;
2594 printf("starting oplock test 2\n");
2596 if (!torture_open_connection(&cli1)) {
2597 use_level_II_oplocks = False;
2598 use_oplocks = saved_use_oplocks;
2602 cli1->use_oplocks = True;
2603 cli1->use_level_II_oplocks = True;
2605 if (!torture_open_connection(&cli2)) {
2606 use_level_II_oplocks = False;
2607 use_oplocks = saved_use_oplocks;
2611 cli2->use_oplocks = True;
2612 cli2->use_level_II_oplocks = True;
2614 cli_unlink(cli1, fname);
2616 cli_sockopt(cli1, sockops);
2617 cli_sockopt(cli2, sockops);
2619 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
2621 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
2625 /* Don't need the globals any more. */
2626 use_level_II_oplocks = False;
2627 use_oplocks = saved_use_oplocks;
2631 fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
2633 printf("second open of %s failed (%s)\n", fname, cli_errstr(cli1));
2634 *shared_correct = False;
2640 if (!cli_close(cli2, fnum2)) {
2641 printf("close2 failed (%s)\n", cli_errstr(cli1));
2642 *shared_correct = False;
2650 /* Ensure cli1 processes the break. */
2652 if (cli_read(cli1, fnum1, buf, 0, 4) != 4) {
2653 printf("read on fnum1 failed (%s)\n", cli_errstr(cli1));
2657 /* Should now be at level II. */
2658 /* Test if sending a write locks causes a break to none. */
2660 if (!cli_lock(cli1, fnum1, 0, 4, 0, READ_LOCK)) {
2661 printf("lock failed (%s)\n", cli_errstr(cli1));
2665 cli_unlock(cli1, fnum1, 0, 4);
2669 if (!cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK)) {
2670 printf("lock failed (%s)\n", cli_errstr(cli1));
2674 cli_unlock(cli1, fnum1, 0, 4);
2678 cli_read(cli1, fnum1, buf, 0, 4);
2681 if (cli_write(cli1, fnum1, 0, buf, 0, 4) != 4) {
2682 printf("write on fnum1 failed (%s)\n", cli_errstr(cli1));
2687 if (!cli_close(cli1, fnum1)) {
2688 printf("close1 failed (%s)\n", cli_errstr(cli1));
2694 if (!cli_unlink(cli1, fname)) {
2695 printf("unlink failed (%s)\n", cli_errstr(cli1));
2699 if (!torture_close_connection(cli1)) {
2703 if (!*shared_correct) {
2707 printf("finished oplock test 2\n");
2712 /* handler for oplock 3 tests */
2713 static BOOL oplock3_handler(struct cli_state *cli, int fnum, unsigned char level)
2715 printf("got oplock break fnum=%d level=%d\n",
2717 return cli_oplock_ack(cli, fnum, level);
2720 static BOOL run_oplock3(int dummy)
2722 struct cli_state *cli;
2723 const char *fname = "\\oplockt3.dat";
2725 char buf[4] = "abcd";
2726 BOOL correct = True;
2727 volatile BOOL *shared_correct;
2729 shared_correct = (volatile BOOL *)shm_setup(sizeof(BOOL));
2730 *shared_correct = True;
2732 printf("starting oplock test 3\n");
2737 use_level_II_oplocks = True;
2738 if (!torture_open_connection(&cli)) {
2739 *shared_correct = False;
2743 /* try to trigger a oplock break in parent */
2744 fnum = cli_open(cli, fname, O_RDWR, DENY_NONE);
2745 cli_write(cli, fnum, 0, buf, 0, 4);
2751 use_level_II_oplocks = True;
2752 if (!torture_open_connection(&cli)) {
2755 cli_oplock_handler(cli, oplock3_handler);
2756 fnum = cli_open(cli, fname, O_RDWR|O_CREAT, DENY_NONE);
2757 cli_write(cli, fnum, 0, buf, 0, 4);
2758 cli_close(cli, fnum);
2759 fnum = cli_open(cli, fname, O_RDWR, DENY_NONE);
2760 cli->timeout = 20000;
2761 cli_receive_smb(cli);
2762 printf("finished oplock test 3\n");
2764 return (correct && *shared_correct);
2766 /* What are we looking for here? What's sucess and what's FAILURE? */
2772 Test delete on close semantics.
2774 static BOOL run_deletetest(int dummy)
2776 struct cli_state *cli1;
2777 struct cli_state *cli2;
2778 const char *fname = "\\delete.file";
2781 BOOL correct = True;
2783 printf("starting delete test\n");
2785 if (!torture_open_connection(&cli1)) {
2789 cli_sockopt(cli1, sockops);
2791 /* Test 1 - this should delete the file on close. */
2793 cli_setatr(cli1, fname, 0, 0);
2794 cli_unlink(cli1, fname);
2796 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL,
2797 FILE_SHARE_DELETE, FILE_OVERWRITE_IF,
2798 FILE_DELETE_ON_CLOSE, 0);
2801 printf("[1] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2806 if (!cli_close(cli1, fnum1)) {
2807 printf("[1] close failed (%s)\n", cli_errstr(cli1));
2812 fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
2814 printf("[1] open of %s succeeded (should fail)\n", fname);
2819 printf("first delete on close test succeeded.\n");
2821 /* Test 2 - this should delete the file on close. */
2823 cli_setatr(cli1, fname, 0, 0);
2824 cli_unlink(cli1, fname);
2826 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_ALL_ACCESS,
2827 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
2828 FILE_OVERWRITE_IF, 0, 0);
2831 printf("[2] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2836 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
2837 printf("[2] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
2842 if (!cli_close(cli1, fnum1)) {
2843 printf("[2] close failed (%s)\n", cli_errstr(cli1));
2848 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
2850 printf("[2] open of %s succeeded should have been deleted on close !\n", fname);
2851 if (!cli_close(cli1, fnum1)) {
2852 printf("[2] close failed (%s)\n", cli_errstr(cli1));
2856 cli_unlink(cli1, fname);
2858 printf("second delete on close test succeeded.\n");
2861 cli_setatr(cli1, fname, 0, 0);
2862 cli_unlink(cli1, fname);
2864 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL,
2865 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0);
2868 printf("[3] open - 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
2873 /* This should fail with a sharing violation - open for delete is only compatible
2874 with SHARE_DELETE. */
2876 fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
2877 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0, 0);
2880 printf("[3] open - 2 of %s succeeded - should have failed.\n", fname);
2885 /* This should succeed. */
2887 fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
2888 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0, 0);
2891 printf("[3] open - 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
2896 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
2897 printf("[3] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
2902 if (!cli_close(cli1, fnum1)) {
2903 printf("[3] close 1 failed (%s)\n", cli_errstr(cli1));
2908 if (!cli_close(cli1, fnum2)) {
2909 printf("[3] close 2 failed (%s)\n", cli_errstr(cli1));
2914 /* This should fail - file should no longer be there. */
2916 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
2918 printf("[3] open of %s succeeded should have been deleted on close !\n", fname);
2919 if (!cli_close(cli1, fnum1)) {
2920 printf("[3] close failed (%s)\n", cli_errstr(cli1));
2922 cli_unlink(cli1, fname);
2926 printf("third delete on close test succeeded.\n");
2929 cli_setatr(cli1, fname, 0, 0);
2930 cli_unlink(cli1, fname);
2932 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
2933 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0);
2936 printf("[4] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2941 /* This should succeed. */
2942 fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS,
2943 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0, 0);
2945 printf("[4] open - 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
2950 if (!cli_close(cli1, fnum2)) {
2951 printf("[4] close - 1 failed (%s)\n", cli_errstr(cli1));
2956 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
2957 printf("[4] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
2962 /* This should fail - no more opens once delete on close set. */
2963 fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS,
2964 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
2967 printf("[4] open - 3 of %s succeeded ! Should have failed.\n", fname );
2971 printf("fourth delete on close test succeeded.\n");
2973 if (!cli_close(cli1, fnum1)) {
2974 printf("[4] close - 2 failed (%s)\n", cli_errstr(cli1));
2980 cli_setatr(cli1, fname, 0, 0);
2981 cli_unlink(cli1, fname);
2983 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT, DENY_NONE);
2985 printf("[5] open of %s failed (%s)\n", fname, cli_errstr(cli1));
2990 /* This should fail - only allowed on NT opens with DELETE access. */
2992 if (cli_nt_delete_on_close(cli1, fnum1, True)) {
2993 printf("[5] setting delete_on_close on OpenX file succeeded - should fail !\n");
2998 if (!cli_close(cli1, fnum1)) {
2999 printf("[5] close - 2 failed (%s)\n", cli_errstr(cli1));
3004 printf("fifth delete on close test succeeded.\n");
3007 cli_setatr(cli1, fname, 0, 0);
3008 cli_unlink(cli1, fname);
3010 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA,
3011 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
3012 FILE_OVERWRITE_IF, 0, 0);
3015 printf("[6] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3020 /* This should fail - only allowed on NT opens with DELETE access. */
3022 if (cli_nt_delete_on_close(cli1, fnum1, True)) {
3023 printf("[6] setting delete_on_close on file with no delete access succeeded - should fail !\n");
3028 if (!cli_close(cli1, fnum1)) {
3029 printf("[6] close - 2 failed (%s)\n", cli_errstr(cli1));
3034 printf("sixth delete on close test succeeded.\n");
3037 cli_setatr(cli1, fname, 0, 0);
3038 cli_unlink(cli1, fname);
3040 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
3041 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF, 0, 0);
3044 printf("[7] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3049 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
3050 printf("[7] setting delete_on_close on file failed !\n");
3055 if (!cli_nt_delete_on_close(cli1, fnum1, False)) {
3056 printf("[7] unsetting delete_on_close on file failed !\n");
3061 if (!cli_close(cli1, fnum1)) {
3062 printf("[7] close - 2 failed (%s)\n", cli_errstr(cli1));
3067 /* This next open should succeed - we reset the flag. */
3069 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
3071 printf("[5] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3076 if (!cli_close(cli1, fnum1)) {
3077 printf("[7] close - 2 failed (%s)\n", cli_errstr(cli1));
3082 printf("seventh delete on close test succeeded.\n");
3085 cli_setatr(cli1, fname, 0, 0);
3086 cli_unlink(cli1, fname);
3088 if (!torture_open_connection(&cli2)) {
3089 printf("[8] failed to open second connection.\n");
3094 cli_sockopt(cli1, sockops);
3096 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
3097 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
3098 FILE_OVERWRITE_IF, 0, 0);
3101 printf("[8] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3106 fnum2 = cli_nt_create_full(cli2, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
3107 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
3111 printf("[8] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3116 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
3117 printf("[8] setting delete_on_close on file failed !\n");
3122 if (!cli_close(cli1, fnum1)) {
3123 printf("[8] close - 1 failed (%s)\n", cli_errstr(cli1));
3128 if (!cli_close(cli2, fnum2)) {
3129 printf("[8] close - 2 failed (%s)\n", cli_errstr(cli2));
3134 /* This should fail.. */
3135 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
3137 printf("[8] open of %s succeeded should have been deleted on close !\n", fname);
3141 printf("eighth delete on close test succeeded.\n");
3143 /* This should fail - we need to set DELETE_ACCESS. */
3144 fnum1 = cli_nt_create_full(cli1, fname, 0,FILE_READ_DATA|FILE_WRITE_DATA,
3145 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, FILE_OVERWRITE_IF, FILE_DELETE_ON_CLOSE, 0);
3148 printf("[9] open of %s succeeded should have failed!\n", fname);
3153 printf("ninth delete on close test succeeded.\n");
3155 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
3156 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, FILE_OVERWRITE_IF, FILE_DELETE_ON_CLOSE, 0);
3158 printf("[10] open of %s failed (%s)\n", fname, cli_errstr(cli1));
3163 /* This should delete the file. */
3164 if (!cli_close(cli1, fnum1)) {
3165 printf("[10] close failed (%s)\n", cli_errstr(cli1));
3170 /* This should fail.. */
3171 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
3173 printf("[10] open of %s succeeded should have been deleted on close !\n", fname);
3177 printf("tenth delete on close test succeeded.\n");
3178 printf("finished delete test\n");
3181 /* FIXME: This will crash if we aborted before cli2 got
3182 * intialized, because these functions don't handle
3183 * uninitialized connections. */
3185 cli_close(cli1, fnum1);
3186 cli_close(cli1, fnum2);
3187 cli_setatr(cli1, fname, 0, 0);
3188 cli_unlink(cli1, fname);
3190 if (!torture_close_connection(cli1)) {
3193 if (!torture_close_connection(cli2)) {
3201 print out server properties
3203 static BOOL run_properties(int dummy)
3205 static struct cli_state *cli;
3206 BOOL correct = True;
3208 printf("starting properties test\n");
3212 if (!torture_open_connection(&cli)) {
3216 cli_sockopt(cli, sockops);
3218 d_printf("Capabilities 0x%08x\n", cli->capabilities);
3220 if (!torture_close_connection(cli)) {
3229 /* FIRST_DESIRED_ACCESS 0xf019f */
3230 #define FIRST_DESIRED_ACCESS FILE_READ_DATA|FILE_WRITE_DATA|FILE_APPEND_DATA|\
3231 FILE_READ_EA| /* 0xf */ \
3232 FILE_WRITE_EA|FILE_READ_ATTRIBUTES| /* 0x90 */ \
3233 FILE_WRITE_ATTRIBUTES| /* 0x100 */ \
3234 DELETE_ACCESS|READ_CONTROL_ACCESS|\
3235 WRITE_DAC_ACCESS|WRITE_OWNER_ACCESS /* 0xf0000 */
3236 /* SECOND_DESIRED_ACCESS 0xe0080 */
3237 #define SECOND_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
3238 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
3239 WRITE_OWNER_ACCESS /* 0xe0000 */
3242 #define THIRD_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
3243 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
3245 WRITE_OWNER_ACCESS /* */
3249 Test ntcreate calls made by xcopy
3251 static BOOL run_xcopy(int dummy)
3253 static struct cli_state *cli1;
3254 const char *fname = "\\test.txt";
3255 BOOL correct = True;
3258 printf("starting xcopy test\n");
3260 if (!torture_open_connection(&cli1)) {
3264 fnum1 = cli_nt_create_full(cli1, fname, 0,
3265 FIRST_DESIRED_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
3266 FILE_SHARE_NONE, FILE_OVERWRITE_IF,
3270 printf("First open failed - %s\n", cli_errstr(cli1));
3274 fnum2 = cli_nt_create_full(cli1, fname, 0,
3275 SECOND_DESIRED_ACCESS, 0,
3276 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN,
3279 printf("second open failed - %s\n", cli_errstr(cli1));
3283 if (!torture_close_connection(cli1)) {
3291 Test rename on files open with share delete and no share delete.
3293 static BOOL run_rename(int dummy)
3295 static struct cli_state *cli1;
3296 const char *fname = "\\test.txt";
3297 const char *fname1 = "\\test1.txt";
3298 BOOL correct = True;
3301 printf("starting rename test\n");
3303 if (!torture_open_connection(&cli1)) {
3307 cli_unlink(cli1, fname);
3308 cli_unlink(cli1, fname1);
3309 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3310 FILE_SHARE_READ, FILE_OVERWRITE_IF, 0, 0);
3313 printf("First open failed - %s\n", cli_errstr(cli1));
3317 if (!cli_rename(cli1, fname, fname1)) {
3318 printf("First rename failed (this is correct) - %s\n", cli_errstr(cli1));
3320 printf("First rename succeeded - this should have failed !\n");
3324 if (!cli_close(cli1, fnum1)) {
3325 printf("close - 1 failed (%s)\n", cli_errstr(cli1));
3329 cli_unlink(cli1, fname);
3330 cli_unlink(cli1, fname1);
3331 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3333 FILE_SHARE_DELETE|FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
3335 FILE_SHARE_DELETE|FILE_SHARE_READ, FILE_OVERWRITE_IF, 0, 0);
3339 printf("Second open failed - %s\n", cli_errstr(cli1));
3343 if (!cli_rename(cli1, fname, fname1)) {
3344 printf("Second rename failed - this should have succeeded - %s\n", cli_errstr(cli1));
3347 printf("Second rename succeeded\n");
3350 if (!cli_close(cli1, fnum1)) {
3351 printf("close - 2 failed (%s)\n", cli_errstr(cli1));
3355 cli_unlink(cli1, fname);
3356 cli_unlink(cli1, fname1);
3358 fnum1 = cli_nt_create_full(cli1, fname, 0, READ_CONTROL_ACCESS, FILE_ATTRIBUTE_NORMAL,
3359 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
3362 printf("Third open failed - %s\n", cli_errstr(cli1));
3371 fnum2 = cli_nt_create_full(cli1, fname, 0, DELETE_ACCESS, FILE_ATTRIBUTE_NORMAL,
3372 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
3375 printf("Fourth open failed - %s\n", cli_errstr(cli1));
3378 if (!cli_nt_delete_on_close(cli1, fnum2, True)) {
3379 printf("[8] setting delete_on_close on file failed !\n");
3383 if (!cli_close(cli1, fnum2)) {
3384 printf("close - 4 failed (%s)\n", cli_errstr(cli1));
3390 if (!cli_rename(cli1, fname, fname1)) {
3391 printf("Third rename failed - this should have succeeded - %s\n", cli_errstr(cli1));
3394 printf("Third rename succeeded\n");
3397 if (!cli_close(cli1, fnum1)) {
3398 printf("close - 3 failed (%s)\n", cli_errstr(cli1));
3402 cli_unlink(cli1, fname);
3403 cli_unlink(cli1, fname1);
3405 if (!torture_close_connection(cli1)) {
3412 static BOOL run_pipe_number(int dummy)
3414 struct cli_state *cli1;
3415 const char *pipe_name = "\\SPOOLSS";
3419 printf("starting pipenumber test\n");
3420 if (!torture_open_connection(&cli1)) {
3424 cli_sockopt(cli1, sockops);
3426 fnum = cli_nt_create_full(cli1, pipe_name, 0, FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
3427 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN_IF, 0, 0);
3430 printf("Open of pipe %s failed with error (%s)\n", pipe_name, cli_errstr(cli1));
3436 printf("pipe_number test - we can open %d %s pipes.\n", num_pipes, pipe_name );
3437 torture_close_connection(cli1);
3442 Test open mode returns on read-only files.
3444 static BOOL run_opentest(int dummy)
3446 static struct cli_state *cli1;
3447 static struct cli_state *cli2;
3448 const char *fname = "\\readonly.file";
3452 BOOL correct = True;
3455 printf("starting open test\n");
3457 if (!torture_open_connection(&cli1)) {
3461 cli_setatr(cli1, fname, 0, 0);
3462 cli_unlink(cli1, fname);
3464 cli_sockopt(cli1, sockops);
3466 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
3468 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
3472 if (!cli_close(cli1, fnum1)) {
3473 printf("close2 failed (%s)\n", cli_errstr(cli1));
3477 if (!cli_setatr(cli1, fname, aRONLY, 0)) {
3478 printf("cli_setatr failed (%s)\n", cli_errstr(cli1));
3482 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_WRITE);
3484 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
3488 /* This will fail - but the error should be ERRnoaccess, not ERRbadshare. */
3489 fnum2 = cli_open(cli1, fname, O_RDWR, DENY_ALL);
3491 if (check_error(__LINE__, cli1, ERRDOS, ERRnoaccess,
3492 NT_STATUS_ACCESS_DENIED)) {
3493 printf("correct error code ERRDOS/ERRnoaccess returned\n");
3496 printf("finished open test 1\n");
3498 cli_close(cli1, fnum1);
3500 /* Now try not readonly and ensure ERRbadshare is returned. */
3502 cli_setatr(cli1, fname, 0, 0);
3504 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_WRITE);
3506 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
3510 /* This will fail - but the error should be ERRshare. */
3511 fnum2 = cli_open(cli1, fname, O_RDWR, DENY_ALL);
3513 if (check_error(__LINE__, cli1, ERRDOS, ERRbadshare,
3514 NT_STATUS_SHARING_VIOLATION)) {
3515 printf("correct error code ERRDOS/ERRbadshare returned\n");
3518 if (!cli_close(cli1, fnum1)) {
3519 printf("close2 failed (%s)\n", cli_errstr(cli1));
3523 cli_unlink(cli1, fname);
3525 printf("finished open test 2\n");
3527 /* Test truncate open disposition on file opened for read. */
3529 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
3531 printf("(3) open (1) of %s failed (%s)\n", fname, cli_errstr(cli1));
3535 /* write 20 bytes. */
3537 memset(buf, '\0', 20);
3539 if (cli_write(cli1, fnum1, 0, buf, 0, 20) != 20) {
3540 printf("write failed (%s)\n", cli_errstr(cli1));
3544 if (!cli_close(cli1, fnum1)) {
3545 printf("(3) close1 failed (%s)\n", cli_errstr(cli1));
3549 /* Ensure size == 20. */
3550 if (!cli_getatr(cli1, fname, NULL, &fsize, NULL)) {
3551 printf("(3) getatr failed (%s)\n", cli_errstr(cli1));
3556 printf("(3) file size != 20\n");
3560 /* Now test if we can truncate a file opened for readonly. */
3562 fnum1 = cli_open(cli1, fname, O_RDONLY|O_TRUNC, DENY_NONE);
3564 printf("(3) open (2) of %s failed (%s)\n", fname, cli_errstr(cli1));
3568 if (!cli_close(cli1, fnum1)) {
3569 printf("close2 failed (%s)\n", cli_errstr(cli1));
3573 /* Ensure size == 0. */
3574 if (!cli_getatr(cli1, fname, NULL, &fsize, NULL)) {
3575 printf("(3) getatr failed (%s)\n", cli_errstr(cli1));
3580 printf("(3) file size != 0\n");
3583 printf("finished open test 3\n");
3585 cli_unlink(cli1, fname);
3588 printf("testing ctemp\n");
3589 fnum1 = cli_ctemp(cli1, "\\", &tmp_path);
3591 printf("ctemp failed (%s)\n", cli_errstr(cli1));
3594 printf("ctemp gave path %s\n", tmp_path);
3595 if (!cli_close(cli1, fnum1)) {
3596 printf("close of temp failed (%s)\n", cli_errstr(cli1));
3598 if (!cli_unlink(cli1, tmp_path)) {
3599 printf("unlink of temp failed (%s)\n", cli_errstr(cli1));
3602 /* Test the non-io opens... */
3604 if (!torture_open_connection(&cli2)) {
3608 cli_setatr(cli2, fname, 0, 0);
3609 cli_unlink(cli2, fname);
3611 cli_sockopt(cli2, sockops);
3613 printf("TEST #1 testing 2 non-io opens (no delete)\n");
3615 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3616 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
3619 printf("test 1 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3623 fnum2 = cli_nt_create_full(cli2, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3624 FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0);
3627 printf("test 1 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3631 if (!cli_close(cli1, fnum1)) {
3632 printf("test 1 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3635 if (!cli_close(cli2, fnum2)) {
3636 printf("test 1 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3640 printf("non-io open test #1 passed.\n");
3642 cli_unlink(cli1, fname);
3644 printf("TEST #2 testing 2 non-io opens (first with delete)\n");
3646 fnum1 = cli_nt_create_full(cli1, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3647 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
3650 printf("test 2 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3654 fnum2 = cli_nt_create_full(cli2, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3655 FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0);
3658 printf("test 2 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3662 if (!cli_close(cli1, fnum1)) {
3663 printf("test 1 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3666 if (!cli_close(cli2, fnum2)) {
3667 printf("test 1 close 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
3671 printf("non-io open test #2 passed.\n");
3673 cli_unlink(cli1, fname);
3675 printf("TEST #3 testing 2 non-io opens (second with delete)\n");
3677 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3678 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
3681 printf("test 3 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3685 fnum2 = cli_nt_create_full(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3686 FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0);
3689 printf("test 3 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3693 if (!cli_close(cli1, fnum1)) {
3694 printf("test 3 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3697 if (!cli_close(cli2, fnum2)) {
3698 printf("test 3 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3702 printf("non-io open test #3 passed.\n");
3704 cli_unlink(cli1, fname);
3706 printf("TEST #4 testing 2 non-io opens (both with delete)\n");
3708 fnum1 = cli_nt_create_full(cli1, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3709 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
3712 printf("test 4 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3716 fnum2 = cli_nt_create_full(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3717 FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0);
3720 printf("test 4 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, cli_errstr(cli2));
3724 printf("test 3 open 2 of %s gave %s (correct error should be %s)\n", fname, cli_errstr(cli2), "sharing violation");
3726 if (!cli_close(cli1, fnum1)) {
3727 printf("test 4 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3731 printf("non-io open test #4 passed.\n");
3733 cli_unlink(cli1, fname);
3735 printf("TEST #5 testing 2 non-io opens (both with delete - both with file share delete)\n");
3737 fnum1 = cli_nt_create_full(cli1, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3738 FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0, 0);
3741 printf("test 5 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3745 fnum2 = cli_nt_create_full(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3746 FILE_SHARE_DELETE, FILE_OPEN_IF, 0, 0);
3749 printf("test 5 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3753 if (!cli_close(cli1, fnum1)) {
3754 printf("test 5 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3758 if (!cli_close(cli2, fnum2)) {
3759 printf("test 5 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3763 printf("non-io open test #5 passed.\n");
3765 printf("TEST #6 testing 1 non-io open, one io open\n");
3767 cli_unlink(cli1, fname);
3769 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
3770 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
3773 printf("test 6 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3777 fnum2 = cli_nt_create_full(cli2, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3778 FILE_SHARE_READ, FILE_OPEN_IF, 0, 0);
3781 printf("test 6 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3785 if (!cli_close(cli1, fnum1)) {
3786 printf("test 6 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3790 if (!cli_close(cli2, fnum2)) {
3791 printf("test 6 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
3795 printf("non-io open test #6 passed.\n");
3797 printf("TEST #7 testing 1 non-io open, one io open with delete\n");
3799 cli_unlink(cli1, fname);
3801 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
3802 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
3805 printf("test 7 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3809 fnum2 = cli_nt_create_full(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
3810 FILE_SHARE_READ|FILE_SHARE_DELETE, FILE_OPEN_IF, 0, 0);
3813 printf("test 7 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, cli_errstr(cli2));
3817 printf("test 7 open 2 of %s gave %s (correct error should be %s)\n", fname, cli_errstr(cli2), "sharing violation");
3819 if (!cli_close(cli1, fnum1)) {
3820 printf("test 7 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
3824 printf("non-io open test #7 passed.\n");
3826 cli_unlink(cli1, fname);
3828 if (!torture_close_connection(cli1)) {
3831 if (!torture_close_connection(cli2)) {
3838 static uint32 open_attrs_table[] = {
3839 FILE_ATTRIBUTE_NORMAL,
3840 FILE_ATTRIBUTE_ARCHIVE,
3841 FILE_ATTRIBUTE_READONLY,
3842 FILE_ATTRIBUTE_HIDDEN,
3843 FILE_ATTRIBUTE_SYSTEM,
3845 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY,
3846 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN,
3847 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM,
3848 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN,
3849 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM,
3850 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM,
3852 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN,
3853 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM,
3854 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM,
3855 FILE_ATTRIBUTE_HIDDEN,FILE_ATTRIBUTE_SYSTEM,
3858 struct trunc_open_results {
3865 static struct trunc_open_results attr_results[] = {
3866 { 0, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE },
3867 { 1, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE },
3868 { 2, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_READONLY, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY },
3869 { 16, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE },
3870 { 17, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE },
3871 { 18, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_READONLY, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY },
3872 { 51, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
3873 { 54, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
3874 { 56, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN },
3875 { 68, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
3876 { 71, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
3877 { 73, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM },
3878 { 99, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN,FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
3879 { 102, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
3880 { 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 },
3881 { 116, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
3882 { 119, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
3883 { 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 },
3884 { 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 },
3885 { 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 },
3886 { 227, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
3887 { 230, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
3888 { 232, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN },
3889 { 244, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
3890 { 247, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
3891 { 249, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM }
3894 static BOOL run_openattrtest(int dummy)
3896 static struct cli_state *cli1;
3897 const char *fname = "\\openattr.file";
3899 BOOL correct = True;
3901 unsigned int i, j, k, l;
3903 printf("starting open attr test\n");
3905 if (!torture_open_connection(&cli1)) {
3909 cli_sockopt(cli1, sockops);
3911 for (k = 0, i = 0; i < sizeof(open_attrs_table)/sizeof(uint32); i++) {
3912 cli_setatr(cli1, fname, 0, 0);
3913 cli_unlink(cli1, fname);
3914 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_WRITE_DATA, open_attrs_table[i],
3915 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
3918 printf("open %d (1) of %s failed (%s)\n", i, fname, cli_errstr(cli1));
3922 if (!cli_close(cli1, fnum1)) {
3923 printf("close %d (1) of %s failed (%s)\n", i, fname, cli_errstr(cli1));
3927 for (j = 0; j < sizeof(open_attrs_table)/sizeof(uint32); j++) {
3928 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA, open_attrs_table[j],
3929 FILE_SHARE_NONE, FILE_OVERWRITE, 0, 0);
3932 for (l = 0; l < sizeof(attr_results)/sizeof(struct trunc_open_results); l++) {
3933 if (attr_results[l].num == k) {
3934 printf("[%d] trunc open 0x%x -> 0x%x of %s failed - should have succeeded !(0x%x:%s)\n",
3935 k, open_attrs_table[i],
3936 open_attrs_table[j],
3937 fname, NT_STATUS_V(cli_nt_error(cli1)), cli_errstr(cli1));
3941 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_ACCESS_DENIED)) {
3942 printf("[%d] trunc open 0x%x -> 0x%x failed with wrong error code %s\n",
3943 k, open_attrs_table[i], open_attrs_table[j],
3948 printf("[%d] trunc open 0x%x -> 0x%x failed\n", k, open_attrs_table[i], open_attrs_table[j]);
3954 if (!cli_close(cli1, fnum1)) {
3955 printf("close %d (2) of %s failed (%s)\n", j, fname, cli_errstr(cli1));
3959 if (!cli_getatr(cli1, fname, &attr, NULL, NULL)) {
3960 printf("getatr(2) failed (%s)\n", cli_errstr(cli1));
3965 printf("[%d] getatr check [0x%x] trunc [0x%x] got attr 0x%x\n",
3966 k, open_attrs_table[i], open_attrs_table[j], attr );
3969 for (l = 0; l < sizeof(attr_results)/sizeof(struct trunc_open_results); l++) {
3970 if (attr_results[l].num == k) {
3971 if (attr != attr_results[l].result_attr ||
3972 open_attrs_table[i] != attr_results[l].init_attr ||
3973 open_attrs_table[j] != attr_results[l].trunc_attr) {
3974 printf("getatr check failed. [0x%x] trunc [0x%x] got attr 0x%x, should be 0x%x\n",
3975 open_attrs_table[i],
3976 open_attrs_table[j],
3978 attr_results[l].result_attr);
3988 cli_setatr(cli1, fname, 0, 0);
3989 cli_unlink(cli1, fname);
3991 printf("open attr test %s.\n", correct ? "passed" : "failed");
3993 if (!torture_close_connection(cli1)) {
3999 static void list_fn(file_info *finfo, const char *name, void *state)
4005 test directory listing speed
4007 static BOOL run_dirtest(int dummy)
4010 static struct cli_state *cli;
4013 BOOL correct = True;
4015 printf("starting directory test\n");
4017 if (!torture_open_connection(&cli)) {
4021 cli_sockopt(cli, sockops);
4024 for (i=0;i<torture_numops;i++) {
4026 slprintf(fname, sizeof(fname), "\\%x", (int)random());
4027 fnum = cli_open(cli, fname, O_RDWR|O_CREAT, DENY_NONE);
4029 fprintf(stderr,"Failed to open %s\n", fname);
4032 cli_close(cli, fnum);
4037 printf("Matched %d\n", cli_list(cli, "a*.*", 0, list_fn, NULL));
4038 printf("Matched %d\n", cli_list(cli, "b*.*", 0, list_fn, NULL));
4039 printf("Matched %d\n", cli_list(cli, "xyzabc", 0, list_fn, NULL));
4041 printf("dirtest core %g seconds\n", end_timer() - t1);
4044 for (i=0;i<torture_numops;i++) {
4046 slprintf(fname, sizeof(fname), "\\%x", (int)random());
4047 cli_unlink(cli, fname);
4050 if (!torture_close_connection(cli)) {
4054 printf("finished dirtest\n");
4059 static void del_fn(file_info *finfo, const char *mask, void *state)
4061 struct cli_state *pcli = (struct cli_state *)state;
4063 slprintf(fname, sizeof(fname), "\\LISTDIR\\%s", finfo->name);
4065 if (strcmp(finfo->name, ".") == 0 || strcmp(finfo->name, "..") == 0)
4068 if (finfo->mode & aDIR) {
4069 if (!cli_rmdir(pcli, fname))
4070 printf("del_fn: failed to rmdir %s\n,", fname );
4072 if (!cli_unlink(pcli, fname))
4073 printf("del_fn: failed to unlink %s\n,", fname );
4079 tries varients of chkpath
4081 BOOL torture_chkpath_test(int dummy)
4083 static struct cli_state *cli;
4087 if (!torture_open_connection(&cli)) {
4091 printf("starting chkpath test\n");
4093 /* cleanup from an old run */
4094 cli_rmdir(cli, "\\chkpath.dir\\dir2");
4095 cli_unlink(cli, "\\chkpath.dir\\*");
4096 cli_rmdir(cli, "\\chkpath.dir");
4098 if (!cli_mkdir(cli, "\\chkpath.dir")) {
4099 printf("mkdir1 failed : %s\n", cli_errstr(cli));
4103 if (!cli_mkdir(cli, "\\chkpath.dir\\dir2")) {
4104 printf("mkdir2 failed : %s\n", cli_errstr(cli));
4108 fnum = cli_open(cli, "\\chkpath.dir\\foo.txt", O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
4110 printf("open1 failed (%s)\n", cli_errstr(cli));
4113 cli_close(cli, fnum);
4115 if (!cli_chkpath(cli, "\\chkpath.dir")) {
4116 printf("chkpath1 failed: %s\n", cli_errstr(cli));
4120 if (!cli_chkpath(cli, "\\chkpath.dir\\dir2")) {
4121 printf("chkpath2 failed: %s\n", cli_errstr(cli));
4125 if (!cli_chkpath(cli, "\\chkpath.dir\\foo.txt")) {
4126 ret = check_error(__LINE__, cli, ERRDOS, ERRbadpath,
4127 NT_STATUS_NOT_A_DIRECTORY);
4129 printf("* chkpath on a file should fail\n");
4133 if (!cli_chkpath(cli, "\\chkpath.dir\\bar.txt")) {
4134 ret = check_error(__LINE__, cli, ERRDOS, ERRbadfile,
4135 NT_STATUS_OBJECT_NAME_NOT_FOUND);
4137 printf("* chkpath on a non existant file should fail\n");
4141 if (!cli_chkpath(cli, "\\chkpath.dir\\dirxx\\bar.txt")) {
4142 ret = check_error(__LINE__, cli, ERRDOS, ERRbadpath,
4143 NT_STATUS_OBJECT_PATH_NOT_FOUND);
4145 printf("* chkpath on a non existent component should fail\n");
4149 cli_rmdir(cli, "\\chkpath.dir\\dir2");
4150 cli_unlink(cli, "\\chkpath.dir\\*");
4151 cli_rmdir(cli, "\\chkpath.dir");
4153 if (!torture_close_connection(cli)) {
4163 static BOOL run_dirtest1(int dummy)
4166 static struct cli_state *cli;
4168 BOOL correct = True;
4170 printf("starting directory test\n");
4172 if (!torture_open_connection(&cli)) {
4176 cli_sockopt(cli, sockops);
4178 cli_list(cli, "\\LISTDIR\\*", 0, del_fn, cli);
4179 cli_list(cli, "\\LISTDIR\\*", aDIR, del_fn, cli);
4180 cli_rmdir(cli, "\\LISTDIR");
4181 cli_mkdir(cli, "\\LISTDIR");
4183 /* Create 1000 files and 1000 directories. */
4184 for (i=0;i<1000;i++) {
4186 slprintf(fname, sizeof(fname), "\\LISTDIR\\f%d", i);
4187 fnum = cli_nt_create_full(cli, fname, 0, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
4188 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0);
4190 fprintf(stderr,"Failed to open %s\n", fname);
4193 cli_close(cli, fnum);
4195 for (i=0;i<1000;i++) {
4197 slprintf(fname, sizeof(fname), "\\LISTDIR\\d%d", i);
4198 if (!cli_mkdir(cli, fname)) {
4199 fprintf(stderr,"Failed to open %s\n", fname);
4204 /* Now ensure that doing an old list sees both files and directories. */
4205 num_seen = cli_list_old(cli, "\\LISTDIR\\*", aDIR, list_fn, NULL);
4206 printf("num_seen = %d\n", num_seen );
4207 /* We should see 100 files + 1000 directories + . and .. */
4208 if (num_seen != 2002)
4211 /* Ensure if we have the "must have" bits we only see the
4214 num_seen = cli_list_old(cli, "\\LISTDIR\\*", (aDIR<<8)|aDIR, list_fn, NULL);
4215 printf("num_seen = %d\n", num_seen );
4216 if (num_seen != 1002)
4219 num_seen = cli_list_old(cli, "\\LISTDIR\\*", (aARCH<<8)|aDIR, list_fn, NULL);
4220 printf("num_seen = %d\n", num_seen );
4221 if (num_seen != 1000)
4224 /* Delete everything. */
4225 cli_list(cli, "\\LISTDIR\\*", 0, del_fn, cli);
4226 cli_list(cli, "\\LISTDIR\\*", aDIR, del_fn, cli);
4227 cli_rmdir(cli, "\\LISTDIR");
4230 printf("Matched %d\n", cli_list(cli, "a*.*", 0, list_fn, NULL));
4231 printf("Matched %d\n", cli_list(cli, "b*.*", 0, list_fn, NULL));
4232 printf("Matched %d\n", cli_list(cli, "xyzabc", 0, list_fn, NULL));
4235 if (!torture_close_connection(cli)) {
4239 printf("finished dirtest1\n");
4244 static BOOL run_error_map_extract(int dummy) {
4246 static struct cli_state c_dos;
4247 static struct cli_state c_nt;
4251 uint32 flgs2, errnum;
4258 /* NT-Error connection */
4260 if (!open_nbt_connection(&c_nt)) {
4264 c_nt.use_spnego = False;
4266 if (!cli_negprot(&c_nt)) {
4267 printf("%s rejected the NT-error negprot (%s)\n",host, cli_errstr(&c_nt));
4268 cli_shutdown(&c_nt);
4272 if (!cli_session_setup(&c_nt, "", "", 0, "", 0,
4274 printf("%s rejected the NT-error initial session setup (%s)\n",host, cli_errstr(&c_nt));
4278 /* DOS-Error connection */
4280 if (!open_nbt_connection(&c_dos)) {
4284 c_dos.use_spnego = False;
4285 c_dos.force_dos_errors = True;
4287 if (!cli_negprot(&c_dos)) {
4288 printf("%s rejected the DOS-error negprot (%s)\n",host, cli_errstr(&c_dos));
4289 cli_shutdown(&c_dos);
4293 if (!cli_session_setup(&c_dos, "", "", 0, "", 0,
4295 printf("%s rejected the DOS-error initial session setup (%s)\n",host, cli_errstr(&c_dos));
4299 for (error=(0xc0000000 | 0x1); error < (0xc0000000| 0xFFF); error++) {
4300 snprintf(user, sizeof(user), "%X", error);
4302 if (cli_session_setup(&c_nt, user,
4303 password, strlen(password),
4304 password, strlen(password),
4306 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
4309 flgs2 = SVAL(c_nt.inbuf,smb_flg2);
4311 /* Case #1: 32-bit NT errors */
4312 if (flgs2 & FLAGS2_32_BIT_ERROR_CODES) {
4313 nt_status = NT_STATUS(IVAL(c_nt.inbuf,smb_rcls));
4315 printf("/** Dos error on NT connection! (%s) */\n",
4317 nt_status = NT_STATUS(0xc0000000);
4320 if (cli_session_setup(&c_dos, user,
4321 password, strlen(password),
4322 password, strlen(password),
4324 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
4326 flgs2 = SVAL(c_dos.inbuf,smb_flg2), errnum;
4328 /* Case #1: 32-bit NT errors */
4329 if (flgs2 & FLAGS2_32_BIT_ERROR_CODES) {
4330 printf("/** NT error on DOS connection! (%s) */\n",
4332 errnum = errclass = 0;
4334 cli_dos_error(&c_dos, &errclass, &errnum);
4337 if (NT_STATUS_V(nt_status) != error) {
4338 printf("/*\t{ This NT error code was 'sqashed'\n\t from %s to %s \n\t during the session setup }\n*/\n",
4339 get_nt_error_c_code(NT_STATUS(error)),
4340 get_nt_error_c_code(nt_status));
4343 printf("\t{%s,\t%s,\t%s},\n",
4344 smb_dos_err_class(errclass),
4345 smb_dos_err_name(errclass, errnum),
4346 get_nt_error_c_code(NT_STATUS(error)));
4351 static double create_procs(BOOL (*fn)(int), BOOL *result)
4354 volatile pid_t *child_status;
4355 volatile BOOL *child_status_out;
4361 child_status = (volatile pid_t *)shm_setup(sizeof(pid_t)*nprocs);
4362 if (!child_status) {
4363 printf("Failed to setup shared memory\n");
4367 child_status_out = (volatile BOOL *)shm_setup(sizeof(BOOL)*nprocs);
4368 if (!child_status_out) {
4369 printf("Failed to setup result status shared memory\n");
4373 for (i = 0; i < nprocs; i++) {
4374 child_status[i] = 0;
4375 child_status_out[i] = True;
4380 for (i=0;i<nprocs;i++) {
4383 pid_t mypid = getpid();
4384 sys_srandom(((int)mypid) ^ ((int)time(NULL)));
4386 slprintf(myname,sizeof(myname),"CLIENT%d", i);
4389 if (torture_open_connection(¤t_cli)) break;
4391 printf("pid %d failed to start\n", (int)getpid());
4397 child_status[i] = getpid();
4399 while (child_status[i] && end_timer() < 5) msleep(2);
4401 child_status_out[i] = fn(i);
4408 for (i=0;i<nprocs;i++) {
4409 if (child_status[i]) synccount++;
4411 if (synccount == nprocs) break;
4413 } while (end_timer() < 30);
4415 if (synccount != nprocs) {
4416 printf("FAILED TO START %d CLIENTS (started %d)\n", nprocs, synccount);
4421 /* start the client load */
4424 for (i=0;i<nprocs;i++) {
4425 child_status[i] = 0;
4428 printf("%d clients started\n", nprocs);
4430 for (i=0;i<nprocs;i++) {
4431 while (waitpid(0, &status, 0) == -1 && errno == EINTR) /* noop */ ;
4436 for (i=0;i<nprocs;i++) {
4437 if (!child_status_out[i]) {
4444 #define FLAG_MULTIPROC 1
4451 {"FDPASS", run_fdpasstest, 0},
4452 {"LOCK1", run_locktest1, 0},
4453 {"LOCK2", run_locktest2, 0},
4454 {"LOCK3", run_locktest3, 0},
4455 {"LOCK4", run_locktest4, 0},
4456 {"LOCK5", run_locktest5, 0},
4457 {"LOCK6", run_locktest6, 0},
4458 {"LOCK7", run_locktest7, 0},
4459 {"UNLINK", run_unlinktest, 0},
4460 {"BROWSE", run_browsetest, 0},
4461 {"ATTR", run_attrtest, 0},
4462 {"TRANS2", run_trans2test, 0},
4463 {"MAXFID", run_maxfidtest, FLAG_MULTIPROC},
4464 {"TORTURE",run_torture, FLAG_MULTIPROC},
4465 {"RANDOMIPC", run_randomipc, 0},
4466 {"NEGNOWAIT", run_negprot_nowait, 0},
4467 {"NBENCH", run_nbench, 0},
4468 {"OPLOCK1", run_oplock1, 0},
4469 {"OPLOCK2", run_oplock2, 0},
4470 {"OPLOCK3", run_oplock3, 0},
4471 {"DIR", run_dirtest, 0},
4472 {"DIR1", run_dirtest1, 0},
4473 {"DENY1", torture_denytest1, 0},
4474 {"DENY2", torture_denytest2, 0},
4475 {"TCON", run_tcon_test, 0},
4476 {"TCONDEV", run_tcon_devtype_test, 0},
4477 {"RW1", run_readwritetest, 0},
4478 {"RW2", run_readwritemulti, FLAG_MULTIPROC},
4479 {"RW3", run_readwritelarge, 0},
4480 {"OPEN", run_opentest, 0},
4482 {"OPENATTR", run_openattrtest, 0},
4484 {"XCOPY", run_xcopy, 0},
4485 {"RENAME", run_rename, 0},
4486 {"DELETE", run_deletetest, 0},
4487 {"PROPERTIES", run_properties, 0},
4488 {"MANGLE", torture_mangle, 0},
4489 {"W2K", run_w2ktest, 0},
4490 {"TRANS2SCAN", torture_trans2_scan, 0},
4491 {"NTTRANSSCAN", torture_nttrans_scan, 0},
4492 {"UTABLE", torture_utable, 0},
4493 {"CASETABLE", torture_casetable, 0},
4494 {"ERRMAPEXTRACT", run_error_map_extract, 0},
4495 {"PIPE_NUMBER", run_pipe_number, 0},
4496 {"TCON2", run_tcon2_test, 0},
4497 {"CHKPATH", torture_chkpath_test, 0},
4498 {"FDSESS", run_fdsesstest, 0},
4503 /****************************************************************************
4504 run a specified test or "ALL"
4505 ****************************************************************************/
4506 static BOOL run_test(const char *name)
4512 if (strequal(name,"ALL")) {
4513 for (i=0;torture_ops[i].name;i++) {
4514 run_test(torture_ops[i].name);
4518 for (i=0;torture_ops[i].name;i++) {
4519 snprintf(randomfname, sizeof(randomfname), "\\XX%x",
4520 (unsigned)random());
4522 if (strequal(name, torture_ops[i].name)) {
4523 printf("Running %s\n", name);
4524 if (torture_ops[i].flags & FLAG_MULTIPROC) {
4525 t = create_procs(torture_ops[i].fn, &result);
4528 printf("TEST %s FAILED!\n", name);
4533 if (!torture_ops[i].fn(0)) {
4535 printf("TEST %s FAILED!\n", name);
4539 printf("%s took %g secs\n\n", name, t);
4546 static void usage(void)
4550 printf("Usage: smbtorture //server/share <options> TEST1 TEST2 ...\n");
4552 printf("\t-d debuglevel\n");
4553 printf("\t-U user%%pass\n");
4554 printf("\t-k use kerberos\n");
4555 printf("\t-N numprocs\n");
4556 printf("\t-n my_netbios_name\n");
4557 printf("\t-W workgroup\n");
4558 printf("\t-o num_operations\n");
4559 printf("\t-O socket_options\n");
4560 printf("\t-m maximum protocol\n");
4561 printf("\t-L use oplocks\n");
4562 printf("\t-c CLIENT.TXT specify client load file for NBENCH\n");
4563 printf("\t-A showall\n");
4564 printf("\t-p port\n");
4565 printf("\t-s seed\n");
4568 printf("tests are:");
4569 for (i=0;torture_ops[i].name;i++) {
4570 printf(" %s", torture_ops[i].name);
4574 printf("default test is ALL\n");
4579 /****************************************************************************
4581 ****************************************************************************/
4582 int main(int argc,char *argv[])
4588 extern char *optarg;
4590 BOOL correct = True;
4594 #ifdef HAVE_SETBUFFER
4595 setbuffer(stdout, NULL, 0);
4598 lp_load(dyn_CONFIGFILE,True,False,False);
4605 for(p = argv[1]; *p; p++)
4609 if (strncmp(argv[1], "//", 2)) {
4613 fstrcpy(host, &argv[1][2]);
4614 p = strchr_m(&host[2],'/');
4619 fstrcpy(share, p+1);
4623 if (*username == 0 && getenv("LOGNAME")) {
4624 fstrcpy(username,getenv("LOGNAME"));
4630 srandom(time(NULL));
4632 fstrcpy(workgroup, lp_workgroup());
4634 while ((opt = getopt(argc, argv, "p:hW:U:n:N:O:o:m:Ld:Ac:ks:")) != EOF) {
4637 port_to_use = atoi(optarg);
4640 srandom(atoi(optarg));
4643 fstrcpy(workgroup,optarg);
4646 max_protocol = interpret_protocol(optarg, max_protocol);
4649 nprocs = atoi(optarg);
4652 torture_numops = atoi(optarg);
4655 DEBUGLEVEL = atoi(optarg);
4664 torture_showall = True;
4667 fstrcpy(myname, optarg);
4670 client_txt = optarg;
4674 use_kerberos = True;
4676 d_printf("No kerberos support compiled in\n");
4682 fstrcpy(username,optarg);
4683 p = strchr_m(username,'%');
4686 fstrcpy(password, p+1);
4691 printf("Unknown option %c (%d)\n", (char)opt, opt);
4696 if(use_kerberos && !gotuser) gotpass = True;
4699 p = getpass("Password:");
4701 fstrcpy(password, p);
4706 printf("host=%s share=%s user=%s myname=%s\n",
4707 host, share, username, myname);
4710 correct = run_test("ALL");
4712 for (i=1;i<argc;i++) {
4713 if (!run_test(argv[i])) {