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.
28 static fstring host
, workgroup
, share
, password
, username
, myname
;
29 static int max_protocol
= PROTOCOL_NT1
;
30 static const char *sockops
="TCP_NODELAY";
32 static int port_to_use
=0;
33 int torture_numops
=100;
34 static int procnum
; /* records process count number when forking */
35 static struct cli_state
*current_cli
;
36 static fstring randomfname
;
37 static BOOL use_oplocks
;
38 static BOOL use_level_II_oplocks
;
39 static const char *client_txt
= "client_oplocks.txt";
40 static BOOL use_kerberos
;
42 BOOL torture_showall
= False
;
44 static double create_procs(BOOL (*fn
)(int), BOOL
*result
);
47 static struct timeval tp1
,tp2
;
49 void start_timer(void)
54 double end_timer(void)
57 return((tp2
.tv_sec
- tp1
.tv_sec
) +
58 (tp2
.tv_usec
- tp1
.tv_usec
)*1.0e-6);
62 /* return a pointer to a anonymous shared memory segment of size "size"
63 which will persist across fork() but will disappear when all processes
66 The memory is not zeroed
68 This function uses system5 shared memory. It takes advantage of a property
69 that the memory is not destroyed if it is attached when the id is removed
71 void *shm_setup(int size
)
76 shmid
= shmget(IPC_PRIVATE
, size
, S_IRUSR
| S_IWUSR
);
78 printf("can't get shared memory\n");
81 ret
= (void *)shmat(shmid
, 0, 0);
82 if (!ret
|| ret
== (void *)-1) {
83 printf("can't attach to shared memory\n");
86 /* the following releases the ipc, but note that this process
87 and all its children will still have access to the memory, its
88 just that the shmid is no longer valid for other shm calls. This
89 means we don't leave behind lots of shm segments after we exit
91 See Stevens "advanced programming in unix env" for details
93 shmctl(shmid
, IPC_RMID
, 0);
99 static BOOL
open_nbt_connection(struct cli_state
*c
)
101 struct nmb_name called
, calling
;
106 make_nmb_name(&calling
, myname
, 0x0);
107 make_nmb_name(&called
, host
, 0x20);
111 if (!cli_initialise(c
)) {
112 printf("Failed initialize cli_struct to connect with %s\n", host
);
116 c
->port
= port_to_use
;
118 if (!cli_connect(c
, host
, &ip
)) {
119 printf("Failed to connect with %s\n", host
);
123 c
->use_kerberos
= use_kerberos
;
125 c
->timeout
= 120000; /* set a really long timeout (2 minutes) */
126 if (use_oplocks
) c
->use_oplocks
= True
;
127 if (use_level_II_oplocks
) c
->use_level_II_oplocks
= True
;
129 if (!cli_session_request(c
, &calling
, &called
)) {
131 * Well, that failed, try *SMBSERVER ...
132 * However, we must reconnect as well ...
134 if (!cli_connect(c
, host
, &ip
)) {
135 printf("Failed to connect with %s\n", host
);
139 make_nmb_name(&called
, "*SMBSERVER", 0x20);
140 if (!cli_session_request(c
, &calling
, &called
)) {
141 printf("%s rejected the session\n",host
);
142 printf("We tried with a called name of %s & %s\n",
152 BOOL
torture_open_connection(struct cli_state
**c
)
159 flags
|= CLI_FULL_CONNECTION_USE_KERBEROS
;
161 status
= cli_full_connection(c
, myname
,
162 host
, NULL
, port_to_use
,
165 password
, flags
, Undefined
, &retry
);
166 if (!NT_STATUS_IS_OK(status
)) {
170 if (use_oplocks
) (*c
)->use_oplocks
= True
;
171 if (use_level_II_oplocks
) (*c
)->use_level_II_oplocks
= True
;
172 (*c
)->timeout
= 120000; /* set a really long timeout (2 minutes) */
177 BOOL
torture_cli_session_setup2(struct cli_state
*cli
, uint16
*new_vuid
)
179 uint16 old_vuid
= cli
->vuid
;
180 fstring old_user_name
;
181 size_t passlen
= strlen(password
);
184 fstrcpy(old_user_name
, cli
->user_name
);
186 ret
= cli_session_setup(cli
, username
, password
, passlen
, password
, passlen
, workgroup
);
187 *new_vuid
= cli
->vuid
;
188 cli
->vuid
= old_vuid
;
189 fstrcpy(cli
->user_name
, old_user_name
);
194 BOOL
torture_close_connection(struct cli_state
*c
)
198 printf("tdis failed (%s)\n", cli_errstr(c
));
208 /* check if the server produced the expected error code */
209 static BOOL
check_error(int line
, struct cli_state
*c
,
210 uint8 eclass
, uint32 ecode
, NTSTATUS nterr
)
212 if (cli_is_dos_error(c
)) {
216 /* Check DOS error */
218 cli_dos_error(c
, &class, &num
);
220 if (eclass
!= class || ecode
!= num
) {
221 printf("unexpected error code class=%d code=%d\n",
222 (int)class, (int)num
);
223 printf(" expected %d/%d %s (line=%d)\n",
224 (int)eclass
, (int)ecode
, nt_errstr(nterr
), line
);
233 status
= cli_nt_error(c
);
235 if (NT_STATUS_V(nterr
) != NT_STATUS_V(status
)) {
236 printf("unexpected error code %s\n", nt_errstr(status
));
237 printf(" expected %s (line=%d)\n", nt_errstr(nterr
), line
);
246 static BOOL
wait_lock(struct cli_state
*c
, int fnum
, uint32 offset
, uint32 len
)
248 while (!cli_lock(c
, fnum
, offset
, len
, -1, WRITE_LOCK
)) {
249 if (!check_error(__LINE__
, c
, ERRDOS
, ERRlock
, NT_STATUS_LOCK_NOT_GRANTED
)) return False
;
255 static BOOL
rw_torture(struct cli_state
*c
)
257 const char *lockfname
= "\\torture.lck";
261 pid_t pid2
, pid
= getpid();
266 fnum2
= cli_open(c
, lockfname
, O_RDWR
| O_CREAT
| O_EXCL
,
269 fnum2
= cli_open(c
, lockfname
, O_RDWR
, DENY_NONE
);
271 printf("open of %s failed (%s)\n", lockfname
, cli_errstr(c
));
276 for (i
=0;i
<torture_numops
;i
++) {
277 unsigned n
= (unsigned)sys_random()%10;
279 printf("%d\r", i
); fflush(stdout
);
281 slprintf(fname
, sizeof(fstring
) - 1, "\\torture.%u", n
);
283 if (!wait_lock(c
, fnum2
, n
*sizeof(int), sizeof(int))) {
287 fnum
= cli_open(c
, fname
, O_RDWR
| O_CREAT
| O_TRUNC
, DENY_ALL
);
289 printf("open failed (%s)\n", cli_errstr(c
));
294 if (cli_write(c
, fnum
, 0, (char *)&pid
, 0, sizeof(pid
)) != sizeof(pid
)) {
295 printf("write failed (%s)\n", cli_errstr(c
));
300 if (cli_write(c
, fnum
, 0, (char *)buf
,
301 sizeof(pid
)+(j
*sizeof(buf
)),
302 sizeof(buf
)) != sizeof(buf
)) {
303 printf("write failed (%s)\n", cli_errstr(c
));
310 if (cli_read(c
, fnum
, (char *)&pid2
, 0, sizeof(pid
)) != sizeof(pid
)) {
311 printf("read failed (%s)\n", cli_errstr(c
));
316 printf("data corruption!\n");
320 if (!cli_close(c
, fnum
)) {
321 printf("close failed (%s)\n", cli_errstr(c
));
325 if (!cli_unlink(c
, fname
)) {
326 printf("unlink failed (%s)\n", cli_errstr(c
));
330 if (!cli_unlock(c
, fnum2
, n
*sizeof(int), sizeof(int))) {
331 printf("unlock failed (%s)\n", cli_errstr(c
));
337 cli_unlink(c
, lockfname
);
344 static BOOL
run_torture(int dummy
)
346 struct cli_state
*cli
;
351 cli_sockopt(cli
, sockops
);
353 ret
= rw_torture(cli
);
355 if (!torture_close_connection(cli
)) {
362 static BOOL
rw_torture3(struct cli_state
*c
, char *lockfname
)
369 unsigned countprev
= 0;
374 for (i
= 0; i
< sizeof(buf
); i
+= sizeof(uint32
))
376 SIVAL(buf
, i
, sys_random());
381 fnum
= cli_open(c
, lockfname
, O_RDWR
| O_CREAT
| O_EXCL
,
384 printf("first open read/write of %s failed (%s)\n",
385 lockfname
, cli_errstr(c
));
391 for (i
= 0; i
< 500 && fnum
== -1; i
++)
393 fnum
= cli_open(c
, lockfname
, O_RDONLY
,
398 printf("second open read-only of %s failed (%s)\n",
399 lockfname
, cli_errstr(c
));
405 for (count
= 0; count
< sizeof(buf
); count
+= sent
)
407 if (count
>= countprev
) {
408 printf("%d %8d\r", i
, count
);
411 countprev
+= (sizeof(buf
) / 20);
416 sent
= ((unsigned)sys_random()%(20))+ 1;
417 if (sent
> sizeof(buf
) - count
)
419 sent
= sizeof(buf
) - count
;
422 if (cli_write(c
, fnum
, 0, buf
+count
, count
, (size_t)sent
) != sent
) {
423 printf("write failed (%s)\n", cli_errstr(c
));
429 sent
= cli_read(c
, fnum
, buf_rd
+count
, count
,
433 printf("read failed offset:%d size:%ld (%s)\n",
434 count
, (unsigned long)sizeof(buf
)-count
,
441 if (memcmp(buf_rd
+count
, buf
+count
, sent
) != 0)
443 printf("read/write compare failed\n");
444 printf("offset: %d req %ld recvd %ld\n", count
, (unsigned long)sizeof(buf
)-count
, (unsigned long)sent
);
453 if (!cli_close(c
, fnum
)) {
454 printf("close failed (%s)\n", cli_errstr(c
));
461 static BOOL
rw_torture2(struct cli_state
*c1
, struct cli_state
*c2
)
463 const char *lockfname
= "\\torture2.lck";
468 uchar buf_rd
[131072];
472 if (!cli_unlink(c1
, lockfname
)) {
473 printf("unlink failed (%s) (normal, this file should not exist)\n", cli_errstr(c1
));
476 fnum1
= cli_open(c1
, lockfname
, O_RDWR
| O_CREAT
| O_EXCL
,
479 printf("first open read/write of %s failed (%s)\n",
480 lockfname
, cli_errstr(c1
));
483 fnum2
= cli_open(c2
, lockfname
, O_RDONLY
,
486 printf("second open read-only of %s failed (%s)\n",
487 lockfname
, cli_errstr(c2
));
488 cli_close(c1
, fnum1
);
492 for (i
=0;i
<torture_numops
;i
++)
494 size_t buf_size
= ((unsigned)sys_random()%(sizeof(buf
)-1))+ 1;
496 printf("%d\r", i
); fflush(stdout
);
499 generate_random_buffer(buf
, buf_size
);
501 if (cli_write(c1
, fnum1
, 0, buf
, 0, buf_size
) != buf_size
) {
502 printf("write failed (%s)\n", cli_errstr(c1
));
507 if ((bytes_read
= cli_read(c2
, fnum2
, buf_rd
, 0, buf_size
)) != buf_size
) {
508 printf("read failed (%s)\n", cli_errstr(c2
));
509 printf("read %d, expected %ld\n", bytes_read
,
510 (unsigned long)buf_size
);
515 if (memcmp(buf_rd
, buf
, buf_size
) != 0)
517 printf("read/write compare failed\n");
523 if (!cli_close(c2
, fnum2
)) {
524 printf("close failed (%s)\n", cli_errstr(c2
));
527 if (!cli_close(c1
, fnum1
)) {
528 printf("close failed (%s)\n", cli_errstr(c1
));
532 if (!cli_unlink(c1
, lockfname
)) {
533 printf("unlink failed (%s)\n", cli_errstr(c1
));
540 static BOOL
run_readwritetest(int dummy
)
542 static struct cli_state
*cli1
, *cli2
;
543 BOOL test1
, test2
= False
;
545 if (!torture_open_connection(&cli1
) || !torture_open_connection(&cli2
)) {
548 cli_sockopt(cli1
, sockops
);
549 cli_sockopt(cli2
, sockops
);
551 printf("starting readwritetest\n");
553 test1
= rw_torture2(cli1
, cli2
);
554 printf("Passed readwritetest v1: %s\n", BOOLSTR(test1
));
557 test2
= rw_torture2(cli1
, cli1
);
558 printf("Passed readwritetest v2: %s\n", BOOLSTR(test2
));
561 if (!torture_close_connection(cli1
)) {
565 if (!torture_close_connection(cli2
)) {
569 return (test1
&& test2
);
572 static BOOL
run_readwritemulti(int dummy
)
574 struct cli_state
*cli
;
579 cli_sockopt(cli
, sockops
);
581 printf("run_readwritemulti: fname %s\n", randomfname
);
582 test
= rw_torture3(cli
, randomfname
);
584 if (!torture_close_connection(cli
)) {
591 static BOOL
run_readwritelarge(int dummy
)
593 static struct cli_state
*cli1
;
595 const char *lockfname
= "\\large.dat";
600 if (!torture_open_connection(&cli1
)) {
603 cli_sockopt(cli1
, sockops
);
604 memset(buf
,'\0',sizeof(buf
));
606 cli1
->max_xmit
= 128*1024;
608 printf("starting readwritelarge\n");
610 cli_unlink(cli1
, lockfname
);
612 fnum1
= cli_open(cli1
, lockfname
, O_RDWR
| O_CREAT
| O_EXCL
, DENY_NONE
);
614 printf("open read/write of %s failed (%s)\n", lockfname
, cli_errstr(cli1
));
618 cli_write(cli1
, fnum1
, 0, buf
, 0, sizeof(buf
));
620 if (!cli_qfileinfo(cli1
, fnum1
, NULL
, &fsize
, NULL
, NULL
, NULL
, NULL
, NULL
)) {
621 printf("qfileinfo failed (%s)\n", cli_errstr(cli1
));
625 if (fsize
== sizeof(buf
))
626 printf("readwritelarge test 1 succeeded (size = %lx)\n",
627 (unsigned long)fsize
);
629 printf("readwritelarge test 1 failed (size = %lx)\n",
630 (unsigned long)fsize
);
634 if (!cli_close(cli1
, fnum1
)) {
635 printf("close failed (%s)\n", cli_errstr(cli1
));
639 if (!cli_unlink(cli1
, lockfname
)) {
640 printf("unlink failed (%s)\n", cli_errstr(cli1
));
644 fnum1
= cli_open(cli1
, lockfname
, O_RDWR
| O_CREAT
| O_EXCL
, DENY_NONE
);
646 printf("open read/write of %s failed (%s)\n", lockfname
, cli_errstr(cli1
));
650 cli1
->max_xmit
= 4*1024;
652 cli_smbwrite(cli1
, fnum1
, buf
, 0, sizeof(buf
));
654 if (!cli_qfileinfo(cli1
, fnum1
, NULL
, &fsize
, NULL
, NULL
, NULL
, NULL
, NULL
)) {
655 printf("qfileinfo failed (%s)\n", cli_errstr(cli1
));
659 if (fsize
== sizeof(buf
))
660 printf("readwritelarge test 2 succeeded (size = %lx)\n",
661 (unsigned long)fsize
);
663 printf("readwritelarge test 2 failed (size = %lx)\n",
664 (unsigned long)fsize
);
669 /* ToDo - set allocation. JRA */
670 if(!cli_set_allocation_size(cli1
, fnum1
, 0)) {
671 printf("set allocation size to zero failed (%s)\n", cli_errstr(&cli1
));
674 if (!cli_qfileinfo(cli1
, fnum1
, NULL
, &fsize
, NULL
, NULL
, NULL
, NULL
, NULL
)) {
675 printf("qfileinfo failed (%s)\n", cli_errstr(cli1
));
679 printf("readwritelarge test 3 (truncate test) succeeded (size = %x)\n", fsize
);
682 if (!cli_close(cli1
, fnum1
)) {
683 printf("close failed (%s)\n", cli_errstr(cli1
));
687 if (!torture_close_connection(cli1
)) {
696 #define ival(s) strtol(s, NULL, 0)
698 /* run a test that simulates an approximate netbench client load */
699 static BOOL
run_netbench(int client
)
701 struct cli_state
*cli
;
707 const char *params
[20];
714 cli_sockopt(cli
, sockops
);
718 slprintf(cname
,sizeof(fname
), "client%d", client
);
720 f
= fopen(client_txt
, "r");
727 while (fgets(line
, sizeof(line
)-1, f
)) {
730 line
[strlen(line
)-1] = 0;
732 /* printf("[%d] %s\n", line_count, line); */
734 all_string_sub(line
,"client1", cname
, sizeof(line
));
736 /* parse the command parameters */
737 params
[0] = strtok(line
," ");
739 while (params
[i
]) params
[++i
] = strtok(NULL
," ");
745 if (!strncmp(params
[0],"SMB", 3)) {
746 printf("ERROR: You are using a dbench 1 load file\n");
750 if (!strcmp(params
[0],"NTCreateX")) {
751 nb_createx(params
[1], ival(params
[2]), ival(params
[3]),
753 } else if (!strcmp(params
[0],"Close")) {
754 nb_close(ival(params
[1]));
755 } else if (!strcmp(params
[0],"Rename")) {
756 nb_rename(params
[1], params
[2]);
757 } else if (!strcmp(params
[0],"Unlink")) {
758 nb_unlink(params
[1]);
759 } else if (!strcmp(params
[0],"Deltree")) {
760 nb_deltree(params
[1]);
761 } else if (!strcmp(params
[0],"Rmdir")) {
763 } else if (!strcmp(params
[0],"QUERY_PATH_INFORMATION")) {
764 nb_qpathinfo(params
[1]);
765 } else if (!strcmp(params
[0],"QUERY_FILE_INFORMATION")) {
766 nb_qfileinfo(ival(params
[1]));
767 } else if (!strcmp(params
[0],"QUERY_FS_INFORMATION")) {
768 nb_qfsinfo(ival(params
[1]));
769 } else if (!strcmp(params
[0],"FIND_FIRST")) {
770 nb_findfirst(params
[1]);
771 } else if (!strcmp(params
[0],"WriteX")) {
772 nb_writex(ival(params
[1]),
773 ival(params
[2]), ival(params
[3]), ival(params
[4]));
774 } else if (!strcmp(params
[0],"ReadX")) {
775 nb_readx(ival(params
[1]),
776 ival(params
[2]), ival(params
[3]), ival(params
[4]));
777 } else if (!strcmp(params
[0],"Flush")) {
778 nb_flush(ival(params
[1]));
780 printf("Unknown operation %s\n", params
[0]);
788 if (!torture_close_connection(cli
)) {
796 /* run a test that simulates an approximate netbench client load */
797 static BOOL
run_nbench(int dummy
)
806 signal(SIGALRM
, nb_alarm
);
808 t
= create_procs(run_netbench
, &correct
);
811 printf("\nThroughput %g MB/sec\n",
812 1.0e-6 * nbio_total() / t
);
818 This test checks for two things:
820 1) correct support for retaining locks over a close (ie. the server
821 must not use posix semantics)
822 2) support for lock timeouts
824 static BOOL
run_locktest1(int dummy
)
826 struct cli_state
*cli1
, *cli2
;
827 const char *fname
= "\\lockt1.lck";
828 int fnum1
, fnum2
, fnum3
;
830 unsigned lock_timeout
;
832 if (!torture_open_connection(&cli1
) || !torture_open_connection(&cli2
)) {
835 cli_sockopt(cli1
, sockops
);
836 cli_sockopt(cli2
, sockops
);
838 printf("starting locktest1\n");
840 cli_unlink(cli1
, fname
);
842 fnum1
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
);
844 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
847 fnum2
= cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
);
849 printf("open2 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
852 fnum3
= cli_open(cli2
, fname
, O_RDWR
, DENY_NONE
);
854 printf("open3 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
858 if (!cli_lock(cli1
, fnum1
, 0, 4, 0, WRITE_LOCK
)) {
859 printf("lock1 failed (%s)\n", cli_errstr(cli1
));
864 if (cli_lock(cli2
, fnum3
, 0, 4, 0, WRITE_LOCK
)) {
865 printf("lock2 succeeded! This is a locking bug\n");
868 if (!check_error(__LINE__
, cli2
, ERRDOS
, ERRlock
,
869 NT_STATUS_LOCK_NOT_GRANTED
)) return False
;
873 lock_timeout
= (1 + (random() % 20));
874 printf("Testing lock timeout with timeout=%u\n", lock_timeout
);
876 if (cli_lock(cli2
, fnum3
, 0, 4, lock_timeout
* 1000, WRITE_LOCK
)) {
877 printf("lock3 succeeded! This is a locking bug\n");
880 if (!check_error(__LINE__
, cli2
, ERRDOS
, ERRlock
,
881 NT_STATUS_FILE_LOCK_CONFLICT
)) return False
;
885 if (ABS(t2
- t1
) < lock_timeout
-1) {
886 printf("error: This server appears not to support timed lock requests\n");
889 printf("server slept for %u seconds for a %u second timeout\n",
890 (unsigned int)(t2
-t1
), lock_timeout
);
892 if (!cli_close(cli1
, fnum2
)) {
893 printf("close1 failed (%s)\n", cli_errstr(cli1
));
897 if (cli_lock(cli2
, fnum3
, 0, 4, 0, WRITE_LOCK
)) {
898 printf("lock4 succeeded! This is a locking bug\n");
901 if (!check_error(__LINE__
, cli2
, ERRDOS
, ERRlock
,
902 NT_STATUS_FILE_LOCK_CONFLICT
)) return False
;
905 if (!cli_close(cli1
, fnum1
)) {
906 printf("close2 failed (%s)\n", cli_errstr(cli1
));
910 if (!cli_close(cli2
, fnum3
)) {
911 printf("close3 failed (%s)\n", cli_errstr(cli2
));
915 if (!cli_unlink(cli1
, fname
)) {
916 printf("unlink failed (%s)\n", cli_errstr(cli1
));
921 if (!torture_close_connection(cli1
)) {
925 if (!torture_close_connection(cli2
)) {
929 printf("Passed locktest1\n");
934 this checks to see if a secondary tconx can use open files from an
937 static BOOL
run_tcon_test(int dummy
)
939 static struct cli_state
*cli
;
940 const char *fname
= "\\tcontest.tmp";
942 uint16 cnum1
, cnum2
, cnum3
;
947 if (!torture_open_connection(&cli
)) {
950 cli_sockopt(cli
, sockops
);
952 printf("starting tcontest\n");
954 cli_unlink(cli
, fname
);
956 fnum1
= cli_open(cli
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
);
958 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli
));
965 if (cli_write(cli
, fnum1
, 0, buf
, 130, 4) != 4) {
966 printf("initial write failed (%s)", cli_errstr(cli
));
970 if (!cli_send_tconX(cli
, share
, "?????",
971 password
, strlen(password
)+1)) {
972 printf("%s refused 2nd tree connect (%s)\n", host
,
979 cnum3
= MAX(cnum1
, cnum2
) + 1; /* any invalid number */
980 vuid2
= cli
->vuid
+ 1;
982 /* try a write with the wrong tid */
985 if (cli_write(cli
, fnum1
, 0, buf
, 130, 4) == 4) {
986 printf("* server allows write with wrong TID\n");
989 printf("server fails write with wrong TID : %s\n", cli_errstr(cli
));
993 /* try a write with an invalid tid */
996 if (cli_write(cli
, fnum1
, 0, buf
, 130, 4) == 4) {
997 printf("* server allows write with invalid TID\n");
1000 printf("server fails write with invalid TID : %s\n", cli_errstr(cli
));
1003 /* try a write with an invalid vuid */
1007 if (cli_write(cli
, fnum1
, 0, buf
, 130, 4) == 4) {
1008 printf("* server allows write with invalid VUID\n");
1011 printf("server fails write with invalid VUID : %s\n", cli_errstr(cli
));
1017 if (!cli_close(cli
, fnum1
)) {
1018 printf("close failed (%s)\n", cli_errstr(cli
));
1024 if (!cli_tdis(cli
)) {
1025 printf("secondary tdis failed (%s)\n", cli_errstr(cli
));
1031 if (!torture_close_connection(cli
)) {
1040 checks for old style tcon support
1042 static BOOL
run_tcon2_test(int dummy
)
1044 static struct cli_state
*cli
;
1045 uint16 cnum
, max_xmit
;
1049 if (!torture_open_connection(&cli
)) {
1052 cli_sockopt(cli
, sockops
);
1054 printf("starting tcon2 test\n");
1056 asprintf(&service
, "\\\\%s\\%s", host
, share
);
1058 status
= cli_raw_tcon(cli
, service
, password
, "?????", &max_xmit
, &cnum
);
1060 if (!NT_STATUS_IS_OK(status
)) {
1061 printf("tcon2 failed : %s\n", cli_errstr(cli
));
1063 printf("tcon OK : max_xmit=%d cnum=%d tid=%d\n",
1064 (int)max_xmit
, (int)cnum
, SVAL(cli
->inbuf
, smb_tid
));
1067 if (!torture_close_connection(cli
)) {
1071 printf("Passed tcon2 test\n");
1075 static BOOL
tcon_devtest(struct cli_state
*cli
,
1076 const char *myshare
, const char *devtype
,
1077 const char *return_devtype
,
1078 NTSTATUS expected_error
)
1083 status
= cli_send_tconX(cli
, myshare
, devtype
,
1084 password
, strlen(password
)+1);
1086 if (NT_STATUS_IS_OK(expected_error
)) {
1088 if (strcmp(cli
->dev
, return_devtype
) == 0) {
1091 printf("tconX to share %s with type %s "
1092 "succeeded but returned the wrong "
1093 "device type (got [%s] but should have got [%s])\n",
1094 myshare
, devtype
, cli
->dev
, return_devtype
);
1098 printf("tconX to share %s with type %s "
1099 "should have succeeded but failed\n",
1106 printf("tconx to share %s with type %s "
1107 "should have failed but succeeded\n",
1111 if (NT_STATUS_EQUAL(cli_nt_error(cli
),
1115 printf("Returned unexpected error\n");
1124 checks for correct tconX support
1126 static BOOL
run_tcon_devtype_test(int dummy
)
1128 static struct cli_state
*cli1
= NULL
;
1134 status
= cli_full_connection(&cli1
, myname
,
1135 host
, NULL
, port_to_use
,
1137 username
, workgroup
,
1138 password
, flags
, Undefined
, &retry
);
1140 if (!NT_STATUS_IS_OK(status
)) {
1141 printf("could not open connection\n");
1145 if (!tcon_devtest(cli1
, "IPC$", "A:", NULL
, NT_STATUS_BAD_DEVICE_TYPE
))
1148 if (!tcon_devtest(cli1
, "IPC$", "?????", "IPC", NT_STATUS_OK
))
1151 if (!tcon_devtest(cli1
, "IPC$", "LPT:", NULL
, NT_STATUS_BAD_DEVICE_TYPE
))
1154 if (!tcon_devtest(cli1
, "IPC$", "IPC", "IPC", NT_STATUS_OK
))
1157 if (!tcon_devtest(cli1
, "IPC$", "FOOBA", NULL
, NT_STATUS_BAD_DEVICE_TYPE
))
1160 if (!tcon_devtest(cli1
, share
, "A:", "A:", NT_STATUS_OK
))
1163 if (!tcon_devtest(cli1
, share
, "?????", "A:", NT_STATUS_OK
))
1166 if (!tcon_devtest(cli1
, share
, "LPT:", NULL
, NT_STATUS_BAD_DEVICE_TYPE
))
1169 if (!tcon_devtest(cli1
, share
, "IPC", NULL
, NT_STATUS_BAD_DEVICE_TYPE
))
1172 if (!tcon_devtest(cli1
, share
, "FOOBA", NULL
, NT_STATUS_BAD_DEVICE_TYPE
))
1178 printf("Passed tcondevtest\n");
1185 This test checks that
1187 1) the server supports multiple locking contexts on the one SMB
1188 connection, distinguished by PID.
1190 2) the server correctly fails overlapping locks made by the same PID (this
1191 goes against POSIX behaviour, which is why it is tricky to implement)
1193 3) the server denies unlock requests by an incorrect client PID
1195 static BOOL
run_locktest2(int dummy
)
1197 static struct cli_state
*cli
;
1198 const char *fname
= "\\lockt2.lck";
1199 int fnum1
, fnum2
, fnum3
;
1200 BOOL correct
= True
;
1202 if (!torture_open_connection(&cli
)) {
1206 cli_sockopt(cli
, sockops
);
1208 printf("starting locktest2\n");
1210 cli_unlink(cli
, fname
);
1214 fnum1
= cli_open(cli
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
);
1216 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli
));
1220 fnum2
= cli_open(cli
, fname
, O_RDWR
, DENY_NONE
);
1222 printf("open2 of %s failed (%s)\n", fname
, cli_errstr(cli
));
1228 fnum3
= cli_open(cli
, fname
, O_RDWR
, DENY_NONE
);
1230 printf("open3 of %s failed (%s)\n", fname
, cli_errstr(cli
));
1236 if (!cli_lock(cli
, fnum1
, 0, 4, 0, WRITE_LOCK
)) {
1237 printf("lock1 failed (%s)\n", cli_errstr(cli
));
1241 if (cli_lock(cli
, fnum1
, 0, 4, 0, WRITE_LOCK
)) {
1242 printf("WRITE lock1 succeeded! This is a locking bug\n");
1245 if (!check_error(__LINE__
, cli
, ERRDOS
, ERRlock
,
1246 NT_STATUS_LOCK_NOT_GRANTED
)) return False
;
1249 if (cli_lock(cli
, fnum2
, 0, 4, 0, WRITE_LOCK
)) {
1250 printf("WRITE lock2 succeeded! This is a locking bug\n");
1253 if (!check_error(__LINE__
, cli
, ERRDOS
, ERRlock
,
1254 NT_STATUS_LOCK_NOT_GRANTED
)) return False
;
1257 if (cli_lock(cli
, fnum2
, 0, 4, 0, READ_LOCK
)) {
1258 printf("READ lock2 succeeded! This is a locking bug\n");
1261 if (!check_error(__LINE__
, cli
, ERRDOS
, ERRlock
,
1262 NT_STATUS_FILE_LOCK_CONFLICT
)) return False
;
1265 if (!cli_lock(cli
, fnum1
, 100, 4, 0, WRITE_LOCK
)) {
1266 printf("lock at 100 failed (%s)\n", cli_errstr(cli
));
1269 if (cli_unlock(cli
, fnum1
, 100, 4)) {
1270 printf("unlock at 100 succeeded! This is a locking bug\n");
1274 if (cli_unlock(cli
, fnum1
, 0, 4)) {
1275 printf("unlock1 succeeded! This is a locking bug\n");
1278 if (!check_error(__LINE__
, cli
,
1280 NT_STATUS_RANGE_NOT_LOCKED
)) return False
;
1283 if (cli_unlock(cli
, fnum1
, 0, 8)) {
1284 printf("unlock2 succeeded! This is a locking bug\n");
1287 if (!check_error(__LINE__
, cli
,
1289 NT_STATUS_RANGE_NOT_LOCKED
)) return False
;
1292 if (cli_lock(cli
, fnum3
, 0, 4, 0, WRITE_LOCK
)) {
1293 printf("lock3 succeeded! This is a locking bug\n");
1296 if (!check_error(__LINE__
, cli
, ERRDOS
, ERRlock
, NT_STATUS_LOCK_NOT_GRANTED
)) return False
;
1301 if (!cli_close(cli
, fnum1
)) {
1302 printf("close1 failed (%s)\n", cli_errstr(cli
));
1306 if (!cli_close(cli
, fnum2
)) {
1307 printf("close2 failed (%s)\n", cli_errstr(cli
));
1311 if (!cli_close(cli
, fnum3
)) {
1312 printf("close3 failed (%s)\n", cli_errstr(cli
));
1316 if (!torture_close_connection(cli
)) {
1320 printf("locktest2 finished\n");
1327 This test checks that
1329 1) the server supports the full offset range in lock requests
1331 static BOOL
run_locktest3(int dummy
)
1333 static struct cli_state
*cli1
, *cli2
;
1334 const char *fname
= "\\lockt3.lck";
1335 int fnum1
, fnum2
, i
;
1337 BOOL correct
= True
;
1339 #define NEXT_OFFSET offset += (~(uint32)0) / torture_numops
1341 if (!torture_open_connection(&cli1
) || !torture_open_connection(&cli2
)) {
1344 cli_sockopt(cli1
, sockops
);
1345 cli_sockopt(cli2
, sockops
);
1347 printf("starting locktest3\n");
1349 cli_unlink(cli1
, fname
);
1351 fnum1
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
);
1353 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
1356 fnum2
= cli_open(cli2
, fname
, O_RDWR
, DENY_NONE
);
1358 printf("open2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
1362 for (offset
=i
=0;i
<torture_numops
;i
++) {
1364 if (!cli_lock(cli1
, fnum1
, offset
-1, 1, 0, WRITE_LOCK
)) {
1365 printf("lock1 %d failed (%s)\n",
1371 if (!cli_lock(cli2
, fnum2
, offset
-2, 1, 0, WRITE_LOCK
)) {
1372 printf("lock2 %d failed (%s)\n",
1379 for (offset
=i
=0;i
<torture_numops
;i
++) {
1382 if (cli_lock(cli1
, fnum1
, offset
-2, 1, 0, WRITE_LOCK
)) {
1383 printf("error: lock1 %d succeeded!\n", i
);
1387 if (cli_lock(cli2
, fnum2
, offset
-1, 1, 0, WRITE_LOCK
)) {
1388 printf("error: lock2 %d succeeded!\n", i
);
1392 if (cli_lock(cli1
, fnum1
, offset
-1, 1, 0, WRITE_LOCK
)) {
1393 printf("error: lock3 %d succeeded!\n", i
);
1397 if (cli_lock(cli2
, fnum2
, offset
-2, 1, 0, WRITE_LOCK
)) {
1398 printf("error: lock4 %d succeeded!\n", i
);
1403 for (offset
=i
=0;i
<torture_numops
;i
++) {
1406 if (!cli_unlock(cli1
, fnum1
, offset
-1, 1)) {
1407 printf("unlock1 %d failed (%s)\n",
1413 if (!cli_unlock(cli2
, fnum2
, offset
-2, 1)) {
1414 printf("unlock2 %d failed (%s)\n",
1421 if (!cli_close(cli1
, fnum1
)) {
1422 printf("close1 failed (%s)\n", cli_errstr(cli1
));
1426 if (!cli_close(cli2
, fnum2
)) {
1427 printf("close2 failed (%s)\n", cli_errstr(cli2
));
1431 if (!cli_unlink(cli1
, fname
)) {
1432 printf("unlink failed (%s)\n", cli_errstr(cli1
));
1436 if (!torture_close_connection(cli1
)) {
1440 if (!torture_close_connection(cli2
)) {
1444 printf("finished locktest3\n");
1449 #define EXPECTED(ret, v) if ((ret) != (v)) { \
1450 printf("** "); correct = False; \
1454 looks at overlapping locks
1456 static BOOL
run_locktest4(int dummy
)
1458 static struct cli_state
*cli1
, *cli2
;
1459 const char *fname
= "\\lockt4.lck";
1460 int fnum1
, fnum2
, f
;
1463 BOOL correct
= True
;
1465 if (!torture_open_connection(&cli1
) || !torture_open_connection(&cli2
)) {
1469 cli_sockopt(cli1
, sockops
);
1470 cli_sockopt(cli2
, sockops
);
1472 printf("starting locktest4\n");
1474 cli_unlink(cli1
, fname
);
1476 fnum1
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
);
1477 fnum2
= cli_open(cli2
, fname
, O_RDWR
, DENY_NONE
);
1479 memset(buf
, 0, sizeof(buf
));
1481 if (cli_write(cli1
, fnum1
, 0, buf
, 0, sizeof(buf
)) != sizeof(buf
)) {
1482 printf("Failed to create file\n");
1487 ret
= cli_lock(cli1
, fnum1
, 0, 4, 0, WRITE_LOCK
) &&
1488 cli_lock(cli1
, fnum1
, 2, 4, 0, WRITE_LOCK
);
1489 EXPECTED(ret
, False
);
1490 printf("the same process %s set overlapping write locks\n", ret
?"can":"cannot");
1492 ret
= cli_lock(cli1
, fnum1
, 10, 4, 0, READ_LOCK
) &&
1493 cli_lock(cli1
, fnum1
, 12, 4, 0, READ_LOCK
);
1494 EXPECTED(ret
, True
);
1495 printf("the same process %s set overlapping read locks\n", ret
?"can":"cannot");
1497 ret
= cli_lock(cli1
, fnum1
, 20, 4, 0, WRITE_LOCK
) &&
1498 cli_lock(cli2
, fnum2
, 22, 4, 0, WRITE_LOCK
);
1499 EXPECTED(ret
, False
);
1500 printf("a different connection %s set overlapping write locks\n", ret
?"can":"cannot");
1502 ret
= cli_lock(cli1
, fnum1
, 30, 4, 0, READ_LOCK
) &&
1503 cli_lock(cli2
, fnum2
, 32, 4, 0, READ_LOCK
);
1504 EXPECTED(ret
, True
);
1505 printf("a different connection %s set overlapping read locks\n", ret
?"can":"cannot");
1507 ret
= (cli_setpid(cli1
, 1), cli_lock(cli1
, fnum1
, 40, 4, 0, WRITE_LOCK
)) &&
1508 (cli_setpid(cli1
, 2), cli_lock(cli1
, fnum1
, 42, 4, 0, WRITE_LOCK
));
1509 EXPECTED(ret
, False
);
1510 printf("a different pid %s set overlapping write locks\n", ret
?"can":"cannot");
1512 ret
= (cli_setpid(cli1
, 1), cli_lock(cli1
, fnum1
, 50, 4, 0, READ_LOCK
)) &&
1513 (cli_setpid(cli1
, 2), cli_lock(cli1
, fnum1
, 52, 4, 0, READ_LOCK
));
1514 EXPECTED(ret
, True
);
1515 printf("a different pid %s set overlapping read locks\n", ret
?"can":"cannot");
1517 ret
= cli_lock(cli1
, fnum1
, 60, 4, 0, READ_LOCK
) &&
1518 cli_lock(cli1
, fnum1
, 60, 4, 0, READ_LOCK
);
1519 EXPECTED(ret
, True
);
1520 printf("the same process %s set the same read lock twice\n", ret
?"can":"cannot");
1522 ret
= cli_lock(cli1
, fnum1
, 70, 4, 0, WRITE_LOCK
) &&
1523 cli_lock(cli1
, fnum1
, 70, 4, 0, WRITE_LOCK
);
1524 EXPECTED(ret
, False
);
1525 printf("the same process %s set the same write lock twice\n", ret
?"can":"cannot");
1527 ret
= cli_lock(cli1
, fnum1
, 80, 4, 0, READ_LOCK
) &&
1528 cli_lock(cli1
, fnum1
, 80, 4, 0, WRITE_LOCK
);
1529 EXPECTED(ret
, False
);
1530 printf("the same process %s overlay a read lock with a write lock\n", ret
?"can":"cannot");
1532 ret
= cli_lock(cli1
, fnum1
, 90, 4, 0, WRITE_LOCK
) &&
1533 cli_lock(cli1
, fnum1
, 90, 4, 0, READ_LOCK
);
1534 EXPECTED(ret
, True
);
1535 printf("the same process %s overlay a write lock with a read lock\n", ret
?"can":"cannot");
1537 ret
= (cli_setpid(cli1
, 1), cli_lock(cli1
, fnum1
, 100, 4, 0, WRITE_LOCK
)) &&
1538 (cli_setpid(cli1
, 2), cli_lock(cli1
, fnum1
, 100, 4, 0, READ_LOCK
));
1539 EXPECTED(ret
, False
);
1540 printf("a different pid %s overlay a write lock with a read lock\n", ret
?"can":"cannot");
1542 ret
= cli_lock(cli1
, fnum1
, 110, 4, 0, READ_LOCK
) &&
1543 cli_lock(cli1
, fnum1
, 112, 4, 0, READ_LOCK
) &&
1544 cli_unlock(cli1
, fnum1
, 110, 6);
1545 EXPECTED(ret
, False
);
1546 printf("the same process %s coalesce read locks\n", ret
?"can":"cannot");
1549 ret
= cli_lock(cli1
, fnum1
, 120, 4, 0, WRITE_LOCK
) &&
1550 (cli_read(cli2
, fnum2
, buf
, 120, 4) == 4);
1551 EXPECTED(ret
, False
);
1552 printf("this server %s strict write locking\n", ret
?"doesn't do":"does");
1554 ret
= cli_lock(cli1
, fnum1
, 130, 4, 0, READ_LOCK
) &&
1555 (cli_write(cli2
, fnum2
, 0, buf
, 130, 4) == 4);
1556 EXPECTED(ret
, False
);
1557 printf("this server %s strict read locking\n", ret
?"doesn't do":"does");
1560 ret
= cli_lock(cli1
, fnum1
, 140, 4, 0, READ_LOCK
) &&
1561 cli_lock(cli1
, fnum1
, 140, 4, 0, READ_LOCK
) &&
1562 cli_unlock(cli1
, fnum1
, 140, 4) &&
1563 cli_unlock(cli1
, fnum1
, 140, 4);
1564 EXPECTED(ret
, True
);
1565 printf("this server %s do recursive read locking\n", ret
?"does":"doesn't");
1568 ret
= cli_lock(cli1
, fnum1
, 150, 4, 0, WRITE_LOCK
) &&
1569 cli_lock(cli1
, fnum1
, 150, 4, 0, READ_LOCK
) &&
1570 cli_unlock(cli1
, fnum1
, 150, 4) &&
1571 (cli_read(cli2
, fnum2
, buf
, 150, 4) == 4) &&
1572 !(cli_write(cli2
, fnum2
, 0, buf
, 150, 4) == 4) &&
1573 cli_unlock(cli1
, fnum1
, 150, 4);
1574 EXPECTED(ret
, True
);
1575 printf("this server %s do recursive lock overlays\n", ret
?"does":"doesn't");
1577 ret
= cli_lock(cli1
, fnum1
, 160, 4, 0, READ_LOCK
) &&
1578 cli_unlock(cli1
, fnum1
, 160, 4) &&
1579 (cli_write(cli2
, fnum2
, 0, buf
, 160, 4) == 4) &&
1580 (cli_read(cli2
, fnum2
, buf
, 160, 4) == 4);
1581 EXPECTED(ret
, True
);
1582 printf("the same process %s remove a read lock using write locking\n", ret
?"can":"cannot");
1584 ret
= cli_lock(cli1
, fnum1
, 170, 4, 0, WRITE_LOCK
) &&
1585 cli_unlock(cli1
, fnum1
, 170, 4) &&
1586 (cli_write(cli2
, fnum2
, 0, buf
, 170, 4) == 4) &&
1587 (cli_read(cli2
, fnum2
, buf
, 170, 4) == 4);
1588 EXPECTED(ret
, True
);
1589 printf("the same process %s remove a write lock using read locking\n", ret
?"can":"cannot");
1591 ret
= cli_lock(cli1
, fnum1
, 190, 4, 0, WRITE_LOCK
) &&
1592 cli_lock(cli1
, fnum1
, 190, 4, 0, READ_LOCK
) &&
1593 cli_unlock(cli1
, fnum1
, 190, 4) &&
1594 !(cli_write(cli2
, fnum2
, 0, buf
, 190, 4) == 4) &&
1595 (cli_read(cli2
, fnum2
, buf
, 190, 4) == 4);
1596 EXPECTED(ret
, True
);
1597 printf("the same process %s remove the first lock first\n", ret
?"does":"doesn't");
1599 cli_close(cli1
, fnum1
);
1600 cli_close(cli2
, fnum2
);
1601 fnum1
= cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
);
1602 f
= cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
);
1603 ret
= cli_lock(cli1
, fnum1
, 0, 8, 0, READ_LOCK
) &&
1604 cli_lock(cli1
, f
, 0, 1, 0, READ_LOCK
) &&
1605 cli_close(cli1
, fnum1
) &&
1606 ((fnum1
= cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
)) != -1) &&
1607 cli_lock(cli1
, fnum1
, 7, 1, 0, WRITE_LOCK
);
1609 cli_close(cli1
, fnum1
);
1610 EXPECTED(ret
, True
);
1611 printf("the server %s have the NT byte range lock bug\n", !ret
?"does":"doesn't");
1614 cli_close(cli1
, fnum1
);
1615 cli_close(cli2
, fnum2
);
1616 cli_unlink(cli1
, fname
);
1617 torture_close_connection(cli1
);
1618 torture_close_connection(cli2
);
1620 printf("finished locktest4\n");
1625 looks at lock upgrade/downgrade.
1627 static BOOL
run_locktest5(int dummy
)
1629 static struct cli_state
*cli1
, *cli2
;
1630 const char *fname
= "\\lockt5.lck";
1631 int fnum1
, fnum2
, fnum3
;
1634 BOOL correct
= True
;
1636 if (!torture_open_connection(&cli1
) || !torture_open_connection(&cli2
)) {
1640 cli_sockopt(cli1
, sockops
);
1641 cli_sockopt(cli2
, sockops
);
1643 printf("starting locktest5\n");
1645 cli_unlink(cli1
, fname
);
1647 fnum1
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
);
1648 fnum2
= cli_open(cli2
, fname
, O_RDWR
, DENY_NONE
);
1649 fnum3
= cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
);
1651 memset(buf
, 0, sizeof(buf
));
1653 if (cli_write(cli1
, fnum1
, 0, buf
, 0, sizeof(buf
)) != sizeof(buf
)) {
1654 printf("Failed to create file\n");
1659 /* Check for NT bug... */
1660 ret
= cli_lock(cli1
, fnum1
, 0, 8, 0, READ_LOCK
) &&
1661 cli_lock(cli1
, fnum3
, 0, 1, 0, READ_LOCK
);
1662 cli_close(cli1
, fnum1
);
1663 fnum1
= cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
);
1664 ret
= cli_lock(cli1
, fnum1
, 7, 1, 0, WRITE_LOCK
);
1665 EXPECTED(ret
, True
);
1666 printf("this server %s the NT locking bug\n", ret
? "doesn't have" : "has");
1667 cli_close(cli1
, fnum1
);
1668 fnum1
= cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
);
1669 cli_unlock(cli1
, fnum3
, 0, 1);
1671 ret
= cli_lock(cli1
, fnum1
, 0, 4, 0, WRITE_LOCK
) &&
1672 cli_lock(cli1
, fnum1
, 1, 1, 0, READ_LOCK
);
1673 EXPECTED(ret
, True
);
1674 printf("the same process %s overlay a write with a read lock\n", ret
?"can":"cannot");
1676 ret
= cli_lock(cli2
, fnum2
, 0, 4, 0, READ_LOCK
);
1677 EXPECTED(ret
, False
);
1679 printf("a different processs %s get a read lock on the first process lock stack\n", ret
?"can":"cannot");
1681 /* Unlock the process 2 lock. */
1682 cli_unlock(cli2
, fnum2
, 0, 4);
1684 ret
= cli_lock(cli1
, fnum3
, 0, 4, 0, READ_LOCK
);
1685 EXPECTED(ret
, False
);
1687 printf("the same processs on a different fnum %s get a read lock\n", ret
?"can":"cannot");
1689 /* Unlock the process 1 fnum3 lock. */
1690 cli_unlock(cli1
, fnum3
, 0, 4);
1692 /* Stack 2 more locks here. */
1693 ret
= cli_lock(cli1
, fnum1
, 0, 4, 0, READ_LOCK
) &&
1694 cli_lock(cli1
, fnum1
, 0, 4, 0, READ_LOCK
);
1696 EXPECTED(ret
, True
);
1697 printf("the same process %s stack read locks\n", ret
?"can":"cannot");
1699 /* Unlock the first process lock, then check this was the WRITE lock that was
1702 ret
= cli_unlock(cli1
, fnum1
, 0, 4) &&
1703 cli_lock(cli2
, fnum2
, 0, 4, 0, READ_LOCK
);
1705 EXPECTED(ret
, True
);
1706 printf("the first unlock removes the %s lock\n", ret
?"WRITE":"READ");
1708 /* Unlock the process 2 lock. */
1709 cli_unlock(cli2
, fnum2
, 0, 4);
1711 /* We should have 3 stacked locks here. Ensure we need to do 3 unlocks. */
1713 ret
= cli_unlock(cli1
, fnum1
, 1, 1) &&
1714 cli_unlock(cli1
, fnum1
, 0, 4) &&
1715 cli_unlock(cli1
, fnum1
, 0, 4);
1717 EXPECTED(ret
, True
);
1718 printf("the same process %s unlock the stack of 4 locks\n", ret
?"can":"cannot");
1720 /* Ensure the next unlock fails. */
1721 ret
= cli_unlock(cli1
, fnum1
, 0, 4);
1722 EXPECTED(ret
, False
);
1723 printf("the same process %s count the lock stack\n", !ret
?"can":"cannot");
1725 /* Ensure connection 2 can get a write lock. */
1726 ret
= cli_lock(cli2
, fnum2
, 0, 4, 0, WRITE_LOCK
);
1727 EXPECTED(ret
, True
);
1729 printf("a different processs %s get a write lock on the unlocked stack\n", ret
?"can":"cannot");
1733 cli_close(cli1
, fnum1
);
1734 cli_close(cli2
, fnum2
);
1735 cli_unlink(cli1
, fname
);
1736 if (!torture_close_connection(cli1
)) {
1739 if (!torture_close_connection(cli2
)) {
1743 printf("finished locktest5\n");
1749 tries the unusual lockingX locktype bits
1751 static BOOL
run_locktest6(int dummy
)
1753 static struct cli_state
*cli
;
1754 const char *fname
[1] = { "\\lock6.txt" };
1759 if (!torture_open_connection(&cli
)) {
1763 cli_sockopt(cli
, sockops
);
1765 printf("starting locktest6\n");
1768 printf("Testing %s\n", fname
[i
]);
1770 cli_unlink(cli
, fname
[i
]);
1772 fnum
= cli_open(cli
, fname
[i
], O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
);
1773 status
= cli_locktype(cli
, fnum
, 0, 8, 0, LOCKING_ANDX_CHANGE_LOCKTYPE
);
1774 cli_close(cli
, fnum
);
1775 printf("CHANGE_LOCKTYPE gave %s\n", nt_errstr(status
));
1777 fnum
= cli_open(cli
, fname
[i
], O_RDWR
, DENY_NONE
);
1778 status
= cli_locktype(cli
, fnum
, 0, 8, 0, LOCKING_ANDX_CANCEL_LOCK
);
1779 cli_close(cli
, fnum
);
1780 printf("CANCEL_LOCK gave %s\n", nt_errstr(status
));
1782 cli_unlink(cli
, fname
[i
]);
1785 torture_close_connection(cli
);
1787 printf("finished locktest6\n");
1791 static BOOL
run_locktest7(int dummy
)
1793 struct cli_state
*cli1
;
1794 const char *fname
= "\\lockt7.lck";
1797 BOOL correct
= False
;
1799 if (!torture_open_connection(&cli1
)) {
1803 cli_sockopt(cli1
, sockops
);
1805 printf("starting locktest7\n");
1807 cli_unlink(cli1
, fname
);
1809 fnum1
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
);
1811 memset(buf
, 0, sizeof(buf
));
1813 if (cli_write(cli1
, fnum1
, 0, buf
, 0, sizeof(buf
)) != sizeof(buf
)) {
1814 printf("Failed to create file\n");
1818 cli_setpid(cli1
, 1);
1820 if (!cli_lock(cli1
, fnum1
, 130, 4, 0, READ_LOCK
)) {
1821 printf("Unable to apply read lock on range 130:4, error was %s\n", cli_errstr(cli1
));
1824 printf("pid1 successfully locked range 130:4 for READ\n");
1827 if (cli_read(cli1
, fnum1
, buf
, 130, 4) != 4) {
1828 printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(cli1
));
1831 printf("pid1 successfully read the range 130:4\n");
1834 if (cli_write(cli1
, fnum1
, 0, buf
, 130, 4) != 4) {
1835 printf("pid1 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1
));
1836 if (NT_STATUS_V(cli_nt_error(cli1
)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT
)) {
1837 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
1841 printf("pid1 successfully wrote to the range 130:4 (should be denied)\n");
1845 cli_setpid(cli1
, 2);
1847 if (cli_read(cli1
, fnum1
, buf
, 130, 4) != 4) {
1848 printf("pid2 unable to read the range 130:4, error was %s\n", cli_errstr(cli1
));
1850 printf("pid2 successfully read the range 130:4\n");
1853 if (cli_write(cli1
, fnum1
, 0, buf
, 130, 4) != 4) {
1854 printf("pid2 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1
));
1855 if (NT_STATUS_V(cli_nt_error(cli1
)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT
)) {
1856 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
1860 printf("pid2 successfully wrote to the range 130:4 (should be denied)\n");
1864 cli_setpid(cli1
, 1);
1865 cli_unlock(cli1
, fnum1
, 130, 4);
1867 if (!cli_lock(cli1
, fnum1
, 130, 4, 0, WRITE_LOCK
)) {
1868 printf("Unable to apply write lock on range 130:4, error was %s\n", cli_errstr(cli1
));
1871 printf("pid1 successfully locked range 130:4 for WRITE\n");
1874 if (cli_read(cli1
, fnum1
, buf
, 130, 4) != 4) {
1875 printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(cli1
));
1878 printf("pid1 successfully read the range 130:4\n");
1881 if (cli_write(cli1
, fnum1
, 0, buf
, 130, 4) != 4) {
1882 printf("pid1 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1
));
1885 printf("pid1 successfully wrote to the range 130:4\n");
1888 cli_setpid(cli1
, 2);
1890 if (cli_read(cli1
, fnum1
, buf
, 130, 4) != 4) {
1891 printf("pid2 unable to read the range 130:4, error was %s\n", cli_errstr(cli1
));
1892 if (NT_STATUS_V(cli_nt_error(cli1
)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT
)) {
1893 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
1897 printf("pid2 successfully read the range 130:4 (should be denied)\n");
1901 if (cli_write(cli1
, fnum1
, 0, buf
, 130, 4) != 4) {
1902 printf("pid2 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1
));
1903 if (NT_STATUS_V(cli_nt_error(cli1
)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT
)) {
1904 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
1908 printf("pid2 successfully wrote to the range 130:4 (should be denied)\n");
1912 cli_unlock(cli1
, fnum1
, 130, 0);
1916 cli_close(cli1
, fnum1
);
1917 cli_unlink(cli1
, fname
);
1918 torture_close_connection(cli1
);
1920 printf("finished locktest7\n");
1925 test whether fnums and tids open on one VC are available on another (a major
1928 static BOOL
run_fdpasstest(int dummy
)
1930 struct cli_state
*cli1
, *cli2
;
1931 const char *fname
= "\\fdpass.tst";
1935 if (!torture_open_connection(&cli1
) || !torture_open_connection(&cli2
)) {
1938 cli_sockopt(cli1
, sockops
);
1939 cli_sockopt(cli2
, sockops
);
1941 printf("starting fdpasstest\n");
1943 cli_unlink(cli1
, fname
);
1945 fnum1
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
);
1947 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
1951 if (cli_write(cli1
, fnum1
, 0, "hello world\n", 0, 13) != 13) {
1952 printf("write failed (%s)\n", cli_errstr(cli1
));
1956 cli2
->vuid
= cli1
->vuid
;
1957 cli2
->cnum
= cli1
->cnum
;
1958 cli2
->pid
= cli1
->pid
;
1960 if (cli_read(cli2
, fnum1
, buf
, 0, 13) == 13) {
1961 printf("read succeeded! nasty security hole [%s]\n",
1966 cli_close(cli1
, fnum1
);
1967 cli_unlink(cli1
, fname
);
1969 torture_close_connection(cli1
);
1970 torture_close_connection(cli2
);
1972 printf("finished fdpasstest\n");
1976 static BOOL
run_fdsesstest(int dummy
)
1978 struct cli_state
*cli
;
1983 const char *fname
= "\\fdsess.tst";
1984 const char *fname1
= "\\fdsess1.tst";
1990 if (!torture_open_connection(&cli
))
1992 cli_sockopt(cli
, sockops
);
1994 if (!torture_cli_session_setup2(cli
, &new_vuid
))
1997 saved_cnum
= cli
->cnum
;
1998 if (!cli_send_tconX(cli
, share
, "?????", "", 1))
2000 new_cnum
= cli
->cnum
;
2001 cli
->cnum
= saved_cnum
;
2003 printf("starting fdsesstest\n");
2005 cli_unlink(cli
, fname
);
2006 cli_unlink(cli
, fname1
);
2008 fnum1
= cli_open(cli
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
);
2010 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli
));
2014 if (cli_write(cli
, fnum1
, 0, "hello world\n", 0, 13) != 13) {
2015 printf("write failed (%s)\n", cli_errstr(cli
));
2019 saved_vuid
= cli
->vuid
;
2020 cli
->vuid
= new_vuid
;
2022 if (cli_read(cli
, fnum1
, buf
, 0, 13) == 13) {
2023 printf("read succeeded with different vuid! nasty security hole [%s]\n",
2027 /* Try to open a file with different vuid, samba cnum. */
2028 fnum2
= cli_open(cli
, fname1
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
);
2030 printf("create with different vuid, same cnum succeeded.\n");
2031 cli_close(cli
, fnum2
);
2032 cli_unlink(cli
, fname1
);
2034 printf("create with different vuid, same cnum failed.\n");
2035 printf("This will cause problems with service clients.\n");
2039 cli
->vuid
= saved_vuid
;
2041 /* Try with same vuid, different cnum. */
2042 cli
->cnum
= new_cnum
;
2044 if (cli_read(cli
, fnum1
, buf
, 0, 13) == 13) {
2045 printf("read succeeded with different cnum![%s]\n",
2050 cli
->cnum
= saved_cnum
;
2051 cli_close(cli
, fnum1
);
2052 cli_unlink(cli
, fname
);
2054 torture_close_connection(cli
);
2056 printf("finished fdsesstest\n");
2061 This test checks that
2063 1) the server does not allow an unlink on a file that is open
2065 static BOOL
run_unlinktest(int dummy
)
2067 struct cli_state
*cli
;
2068 const char *fname
= "\\unlink.tst";
2070 BOOL correct
= True
;
2072 if (!torture_open_connection(&cli
)) {
2076 cli_sockopt(cli
, sockops
);
2078 printf("starting unlink test\n");
2080 cli_unlink(cli
, fname
);
2084 fnum
= cli_open(cli
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
);
2086 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli
));
2090 if (cli_unlink(cli
, fname
)) {
2091 printf("error: server allowed unlink on an open file\n");
2094 correct
= check_error(__LINE__
, cli
, ERRDOS
, ERRbadshare
,
2095 NT_STATUS_SHARING_VIOLATION
);
2098 cli_close(cli
, fnum
);
2099 cli_unlink(cli
, fname
);
2101 if (!torture_close_connection(cli
)) {
2105 printf("unlink test finished\n");
2112 test how many open files this server supports on the one socket
2114 static BOOL
run_maxfidtest(int dummy
)
2116 struct cli_state
*cli
;
2117 const char *template = "\\maxfid.%d.%d";
2119 int fnums
[0x11000], i
;
2121 BOOL correct
= True
;
2126 printf("failed to connect\n");
2130 cli_sockopt(cli
, sockops
);
2132 for (i
=0; i
<0x11000; i
++) {
2133 slprintf(fname
,sizeof(fname
)-1,template, i
,(int)getpid());
2134 if ((fnums
[i
] = cli_open(cli
, fname
,
2135 O_RDWR
|O_CREAT
|O_TRUNC
, DENY_NONE
)) ==
2137 printf("open of %s failed (%s)\n",
2138 fname
, cli_errstr(cli
));
2139 printf("maximum fnum is %d\n", i
);
2147 printf("cleaning up\n");
2149 slprintf(fname
,sizeof(fname
)-1,template, i
,(int)getpid());
2150 cli_close(cli
, fnums
[i
]);
2151 if (!cli_unlink(cli
, fname
)) {
2152 printf("unlink of %s failed (%s)\n",
2153 fname
, cli_errstr(cli
));
2160 printf("maxfid test finished\n");
2161 if (!torture_close_connection(cli
)) {
2167 /* generate a random buffer */
2168 static void rand_buf(char *buf
, int len
)
2171 *buf
= (char)sys_random();
2176 /* send smb negprot commands, not reading the response */
2177 static BOOL
run_negprot_nowait(int dummy
)
2180 static struct cli_state cli
;
2181 BOOL correct
= True
;
2183 printf("starting negprot nowait test\n");
2185 if (!open_nbt_connection(&cli
)) {
2189 for (i
=0;i
<50000;i
++) {
2190 cli_negprot_send(&cli
);
2193 if (!torture_close_connection(&cli
)) {
2197 printf("finished negprot nowait test\n");
2203 /* send random IPC commands */
2204 static BOOL
run_randomipc(int dummy
)
2206 char *rparam
= NULL
;
2210 int api
, param_len
, i
;
2211 struct cli_state
*cli
;
2212 BOOL correct
= True
;
2215 printf("starting random ipc test\n");
2217 if (!torture_open_connection(&cli
)) {
2221 for (i
=0;i
<count
;i
++) {
2222 api
= sys_random() % 500;
2223 param_len
= (sys_random() % 64);
2225 rand_buf(param
, param_len
);
2230 param
, param_len
, 8,
2231 NULL
, 0, BUFFER_SIZE
,
2235 printf("%d/%d\r", i
,count
);
2238 printf("%d/%d\n", i
, count
);
2240 if (!torture_close_connection(cli
)) {
2244 printf("finished random ipc test\n");
2251 static void browse_callback(const char *sname
, uint32 stype
,
2252 const char *comment
, void *state
)
2254 printf("\t%20.20s %08x %s\n", sname
, stype
, comment
);
2260 This test checks the browse list code
2263 static BOOL
run_browsetest(int dummy
)
2265 static struct cli_state
*cli
;
2266 BOOL correct
= True
;
2268 printf("starting browse test\n");
2270 if (!torture_open_connection(&cli
)) {
2274 printf("domain list:\n");
2275 cli_NetServerEnum(cli
, cli
->server_domain
,
2276 SV_TYPE_DOMAIN_ENUM
,
2277 browse_callback
, NULL
);
2279 printf("machine list:\n");
2280 cli_NetServerEnum(cli
, cli
->server_domain
,
2282 browse_callback
, NULL
);
2284 if (!torture_close_connection(cli
)) {
2288 printf("browse test finished\n");
2296 This checks how the getatr calls works
2298 static BOOL
run_attrtest(int dummy
)
2300 struct cli_state
*cli
;
2303 const char *fname
= "\\attrib123456789.tst";
2304 BOOL correct
= True
;
2306 printf("starting attrib test\n");
2308 if (!torture_open_connection(&cli
)) {
2312 cli_unlink(cli
, fname
);
2313 fnum
= cli_open(cli
, fname
,
2314 O_RDWR
| O_CREAT
| O_TRUNC
, DENY_NONE
);
2315 cli_close(cli
, fnum
);
2316 if (!cli_getatr(cli
, fname
, NULL
, NULL
, &t
)) {
2317 printf("getatr failed (%s)\n", cli_errstr(cli
));
2321 if (abs(t
- time(NULL
)) > 60*60*24*10) {
2322 printf("ERROR: SMBgetatr bug. time is %s",
2328 t2
= t
-60*60*24; /* 1 day ago */
2330 if (!cli_setatr(cli
, fname
, 0, t2
)) {
2331 printf("setatr failed (%s)\n", cli_errstr(cli
));
2335 if (!cli_getatr(cli
, fname
, NULL
, NULL
, &t
)) {
2336 printf("getatr failed (%s)\n", cli_errstr(cli
));
2341 printf("ERROR: getatr/setatr bug. times are\n%s",
2343 printf("%s", ctime(&t2
));
2347 cli_unlink(cli
, fname
);
2349 if (!torture_close_connection(cli
)) {
2353 printf("attrib test finished\n");
2360 This checks a couple of trans2 calls
2362 static BOOL
run_trans2test(int dummy
)
2364 struct cli_state
*cli
;
2367 time_t c_time
, a_time
, m_time
, w_time
, m_time2
;
2368 const char *fname
= "\\trans2.tst";
2369 const char *dname
= "\\trans2";
2370 const char *fname2
= "\\trans2\\trans2.tst";
2372 BOOL correct
= True
;
2374 printf("starting trans2 test\n");
2376 if (!torture_open_connection(&cli
)) {
2380 cli_unlink(cli
, fname
);
2381 fnum
= cli_open(cli
, fname
,
2382 O_RDWR
| O_CREAT
| O_TRUNC
, DENY_NONE
);
2383 if (!cli_qfileinfo(cli
, fnum
, NULL
, &size
, &c_time
, &a_time
, &m_time
,
2385 printf("ERROR: qfileinfo failed (%s)\n", cli_errstr(cli
));
2389 if (!cli_qfilename(cli
, fnum
, pname
)) {
2390 printf("ERROR: qfilename failed (%s)\n", cli_errstr(cli
));
2394 if (strcmp(pname
, fname
)) {
2395 printf("qfilename gave different name? [%s] [%s]\n",
2400 cli_close(cli
, fnum
);
2404 cli_unlink(cli
, fname
);
2405 fnum
= cli_open(cli
, fname
,
2406 O_RDWR
| O_CREAT
| O_TRUNC
, DENY_NONE
);
2408 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli
));
2411 cli_close(cli
, fnum
);
2413 if (!cli_qpathinfo(cli
, fname
, &c_time
, &a_time
, &m_time
, &size
, NULL
)) {
2414 printf("ERROR: qpathinfo failed (%s)\n", cli_errstr(cli
));
2417 if (c_time
!= m_time
) {
2418 printf("create time=%s", ctime(&c_time
));
2419 printf("modify time=%s", ctime(&m_time
));
2420 printf("This system appears to have sticky create times\n");
2422 if (a_time
% (60*60) == 0) {
2423 printf("access time=%s", ctime(&a_time
));
2424 printf("This system appears to set a midnight access time\n");
2428 if (abs(m_time
- time(NULL
)) > 60*60*24*7) {
2429 printf("ERROR: totally incorrect times - maybe word reversed? mtime=%s", ctime(&m_time
));
2435 cli_unlink(cli
, fname
);
2436 fnum
= cli_open(cli
, fname
,
2437 O_RDWR
| O_CREAT
| O_TRUNC
, DENY_NONE
);
2438 cli_close(cli
, fnum
);
2439 if (!cli_qpathinfo2(cli
, fname
, &c_time
, &a_time
, &m_time
,
2440 &w_time
, &size
, NULL
, NULL
)) {
2441 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli
));
2444 if (w_time
< 60*60*24*2) {
2445 printf("write time=%s", ctime(&w_time
));
2446 printf("This system appears to set a initial 0 write time\n");
2451 cli_unlink(cli
, fname
);
2454 /* check if the server updates the directory modification time
2455 when creating a new file */
2456 if (!cli_mkdir(cli
, dname
)) {
2457 printf("ERROR: mkdir failed (%s)\n", cli_errstr(cli
));
2461 if (!cli_qpathinfo2(cli
, "\\trans2\\", &c_time
, &a_time
, &m_time
,
2462 &w_time
, &size
, NULL
, NULL
)) {
2463 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli
));
2467 fnum
= cli_open(cli
, fname2
,
2468 O_RDWR
| O_CREAT
| O_TRUNC
, DENY_NONE
);
2469 cli_write(cli
, fnum
, 0, (char *)&fnum
, 0, sizeof(fnum
));
2470 cli_close(cli
, fnum
);
2471 if (!cli_qpathinfo2(cli
, "\\trans2\\", &c_time
, &a_time
, &m_time2
,
2472 &w_time
, &size
, NULL
, NULL
)) {
2473 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli
));
2476 if (m_time2
== m_time
) {
2477 printf("This system does not update directory modification times\n");
2481 cli_unlink(cli
, fname2
);
2482 cli_rmdir(cli
, dname
);
2484 if (!torture_close_connection(cli
)) {
2488 printf("trans2 test finished\n");
2494 This checks new W2K calls.
2497 static BOOL
new_trans(struct cli_state
*pcli
, int fnum
, int level
)
2501 BOOL correct
= True
;
2503 if (!cli_qfileinfo_test(pcli
, fnum
, level
, &buf
, &len
)) {
2504 printf("ERROR: qfileinfo (%d) failed (%s)\n", level
, cli_errstr(pcli
));
2507 printf("qfileinfo: level %d, len = %u\n", level
, len
);
2508 dump_data(0, buf
, len
);
2515 static BOOL
run_w2ktest(int dummy
)
2517 struct cli_state
*cli
;
2519 const char *fname
= "\\w2ktest\\w2k.tst";
2521 BOOL correct
= True
;
2523 printf("starting w2k test\n");
2525 if (!torture_open_connection(&cli
)) {
2529 fnum
= cli_open(cli
, fname
,
2530 O_RDWR
| O_CREAT
, DENY_NONE
);
2532 for (level
= 1004; level
< 1040; level
++) {
2533 new_trans(cli
, fnum
, level
);
2536 cli_close(cli
, fnum
);
2538 if (!torture_close_connection(cli
)) {
2542 printf("w2k test finished\n");
2549 this is a harness for some oplock tests
2551 static BOOL
run_oplock1(int dummy
)
2553 struct cli_state
*cli1
;
2554 const char *fname
= "\\lockt1.lck";
2556 BOOL correct
= True
;
2558 printf("starting oplock test 1\n");
2560 if (!torture_open_connection(&cli1
)) {
2564 cli_unlink(cli1
, fname
);
2566 cli_sockopt(cli1
, sockops
);
2568 cli1
->use_oplocks
= True
;
2570 fnum1
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
);
2572 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
2576 cli1
->use_oplocks
= False
;
2578 cli_unlink(cli1
, fname
);
2579 cli_unlink(cli1
, fname
);
2581 if (!cli_close(cli1
, fnum1
)) {
2582 printf("close2 failed (%s)\n", cli_errstr(cli1
));
2586 if (!cli_unlink(cli1
, fname
)) {
2587 printf("unlink failed (%s)\n", cli_errstr(cli1
));
2591 if (!torture_close_connection(cli1
)) {
2595 printf("finished oplock test 1\n");
2600 static BOOL
run_oplock2(int dummy
)
2602 struct cli_state
*cli1
, *cli2
;
2603 const char *fname
= "\\lockt2.lck";
2605 int saved_use_oplocks
= use_oplocks
;
2607 BOOL correct
= True
;
2608 volatile BOOL
*shared_correct
;
2610 shared_correct
= (volatile BOOL
*)shm_setup(sizeof(BOOL
));
2611 *shared_correct
= True
;
2613 use_level_II_oplocks
= True
;
2616 printf("starting oplock test 2\n");
2618 if (!torture_open_connection(&cli1
)) {
2619 use_level_II_oplocks
= False
;
2620 use_oplocks
= saved_use_oplocks
;
2624 cli1
->use_oplocks
= True
;
2625 cli1
->use_level_II_oplocks
= True
;
2627 if (!torture_open_connection(&cli2
)) {
2628 use_level_II_oplocks
= False
;
2629 use_oplocks
= saved_use_oplocks
;
2633 cli2
->use_oplocks
= True
;
2634 cli2
->use_level_II_oplocks
= True
;
2636 cli_unlink(cli1
, fname
);
2638 cli_sockopt(cli1
, sockops
);
2639 cli_sockopt(cli2
, sockops
);
2641 fnum1
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
);
2643 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
2647 /* Don't need the globals any more. */
2648 use_level_II_oplocks
= False
;
2649 use_oplocks
= saved_use_oplocks
;
2653 fnum2
= cli_open(cli2
, fname
, O_RDWR
, DENY_NONE
);
2655 printf("second open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
2656 *shared_correct
= False
;
2662 if (!cli_close(cli2
, fnum2
)) {
2663 printf("close2 failed (%s)\n", cli_errstr(cli1
));
2664 *shared_correct
= False
;
2672 /* Ensure cli1 processes the break. Empty file should always return 0
2675 if (cli_read(cli1
, fnum1
, buf
, 0, 4) != 0) {
2676 printf("read on fnum1 failed (%s)\n", cli_errstr(cli1
));
2680 /* Should now be at level II. */
2681 /* Test if sending a write locks causes a break to none. */
2683 if (!cli_lock(cli1
, fnum1
, 0, 4, 0, READ_LOCK
)) {
2684 printf("lock failed (%s)\n", cli_errstr(cli1
));
2688 cli_unlock(cli1
, fnum1
, 0, 4);
2692 if (!cli_lock(cli1
, fnum1
, 0, 4, 0, WRITE_LOCK
)) {
2693 printf("lock failed (%s)\n", cli_errstr(cli1
));
2697 cli_unlock(cli1
, fnum1
, 0, 4);
2701 cli_read(cli1
, fnum1
, buf
, 0, 4);
2704 if (cli_write(cli1
, fnum1
, 0, buf
, 0, 4) != 4) {
2705 printf("write on fnum1 failed (%s)\n", cli_errstr(cli1
));
2710 if (!cli_close(cli1
, fnum1
)) {
2711 printf("close1 failed (%s)\n", cli_errstr(cli1
));
2717 if (!cli_unlink(cli1
, fname
)) {
2718 printf("unlink failed (%s)\n", cli_errstr(cli1
));
2722 if (!torture_close_connection(cli1
)) {
2726 if (!*shared_correct
) {
2730 printf("finished oplock test 2\n");
2735 /* handler for oplock 3 tests */
2736 static BOOL
oplock3_handler(struct cli_state
*cli
, int fnum
, unsigned char level
)
2738 printf("got oplock break fnum=%d level=%d\n",
2740 return cli_oplock_ack(cli
, fnum
, level
);
2743 static BOOL
run_oplock3(int dummy
)
2745 struct cli_state
*cli
;
2746 const char *fname
= "\\oplockt3.dat";
2748 char buf
[4] = "abcd";
2749 BOOL correct
= True
;
2750 volatile BOOL
*shared_correct
;
2752 shared_correct
= (volatile BOOL
*)shm_setup(sizeof(BOOL
));
2753 *shared_correct
= True
;
2755 printf("starting oplock test 3\n");
2760 use_level_II_oplocks
= True
;
2761 if (!torture_open_connection(&cli
)) {
2762 *shared_correct
= False
;
2766 /* try to trigger a oplock break in parent */
2767 fnum
= cli_open(cli
, fname
, O_RDWR
, DENY_NONE
);
2768 cli_write(cli
, fnum
, 0, buf
, 0, 4);
2774 use_level_II_oplocks
= True
;
2775 if (!torture_open_connection(&cli
)) {
2778 cli_oplock_handler(cli
, oplock3_handler
);
2779 fnum
= cli_open(cli
, fname
, O_RDWR
|O_CREAT
, DENY_NONE
);
2780 cli_write(cli
, fnum
, 0, buf
, 0, 4);
2781 cli_close(cli
, fnum
);
2782 fnum
= cli_open(cli
, fname
, O_RDWR
, DENY_NONE
);
2783 cli
->timeout
= 20000;
2784 cli_receive_smb(cli
);
2785 printf("finished oplock test 3\n");
2787 return (correct
&& *shared_correct
);
2789 /* What are we looking for here? What's sucess and what's FAILURE? */
2795 Test delete on close semantics.
2797 static BOOL
run_deletetest(int dummy
)
2799 struct cli_state
*cli1
= NULL
;
2800 struct cli_state
*cli2
= NULL
;
2801 const char *fname
= "\\delete.file";
2804 BOOL correct
= True
;
2806 printf("starting delete test\n");
2808 if (!torture_open_connection(&cli1
)) {
2812 cli_sockopt(cli1
, sockops
);
2814 /* Test 1 - this should delete the file on close. */
2816 cli_setatr(cli1
, fname
, 0, 0);
2817 cli_unlink(cli1
, fname
);
2819 fnum1
= cli_nt_create_full(cli1
, fname
, 0, GENERIC_ALL_ACCESS
|DELETE_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
2820 0, FILE_OVERWRITE_IF
,
2821 FILE_DELETE_ON_CLOSE
, 0);
2824 printf("[1] open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
2831 uint32
*accinfo
= NULL
;
2833 cli_qfileinfo_test(cli1
, fnum1
, SMB_FILE_ACCESS_INFORMATION
, (char **)&accinfo
, &len
);
2835 printf("access mode = 0x%lx\n", *accinfo
);
2840 if (!cli_close(cli1
, fnum1
)) {
2841 printf("[1] close failed (%s)\n", cli_errstr(cli1
));
2846 fnum1
= cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
);
2848 printf("[1] open of %s succeeded (should fail)\n", fname
);
2853 printf("first delete on close test succeeded.\n");
2855 /* Test 2 - this should delete the file on close. */
2857 cli_setatr(cli1
, fname
, 0, 0);
2858 cli_unlink(cli1
, fname
);
2860 fnum1
= cli_nt_create_full(cli1
, fname
, 0, GENERIC_ALL_ACCESS
,
2861 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_NONE
,
2862 FILE_OVERWRITE_IF
, 0, 0);
2865 printf("[2] open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
2870 if (!cli_nt_delete_on_close(cli1
, fnum1
, True
)) {
2871 printf("[2] setting delete_on_close failed (%s)\n", cli_errstr(cli1
));
2876 if (!cli_close(cli1
, fnum1
)) {
2877 printf("[2] close failed (%s)\n", cli_errstr(cli1
));
2882 fnum1
= cli_open(cli1
, fname
, O_RDONLY
, DENY_NONE
);
2884 printf("[2] open of %s succeeded should have been deleted on close !\n", fname
);
2885 if (!cli_close(cli1
, fnum1
)) {
2886 printf("[2] close failed (%s)\n", cli_errstr(cli1
));
2890 cli_unlink(cli1
, fname
);
2892 printf("second delete on close test succeeded.\n");
2895 cli_setatr(cli1
, fname
, 0, 0);
2896 cli_unlink(cli1
, fname
);
2898 fnum1
= cli_nt_create_full(cli1
, fname
, 0, GENERIC_ALL_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
2899 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OVERWRITE_IF
, 0, 0);
2902 printf("[3] open - 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
2907 /* This should fail with a sharing violation - open for delete is only compatible
2908 with SHARE_DELETE. */
2910 fnum2
= cli_nt_create_full(cli1
, fname
, 0, GENERIC_READ_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
2911 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OPEN
, 0, 0);
2914 printf("[3] open - 2 of %s succeeded - should have failed.\n", fname
);
2919 /* This should succeed. */
2921 fnum2
= cli_nt_create_full(cli1
, fname
, 0, GENERIC_READ_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
2922 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, FILE_OPEN
, 0, 0);
2925 printf("[3] open - 2 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
2930 if (!cli_nt_delete_on_close(cli1
, fnum1
, True
)) {
2931 printf("[3] setting delete_on_close failed (%s)\n", cli_errstr(cli1
));
2936 if (!cli_close(cli1
, fnum1
)) {
2937 printf("[3] close 1 failed (%s)\n", cli_errstr(cli1
));
2942 if (!cli_close(cli1
, fnum2
)) {
2943 printf("[3] close 2 failed (%s)\n", cli_errstr(cli1
));
2948 /* This should fail - file should no longer be there. */
2950 fnum1
= cli_open(cli1
, fname
, O_RDONLY
, DENY_NONE
);
2952 printf("[3] open of %s succeeded should have been deleted on close !\n", fname
);
2953 if (!cli_close(cli1
, fnum1
)) {
2954 printf("[3] close failed (%s)\n", cli_errstr(cli1
));
2956 cli_unlink(cli1
, fname
);
2960 printf("third delete on close test succeeded.\n");
2963 cli_setatr(cli1
, fname
, 0, 0);
2964 cli_unlink(cli1
, fname
);
2966 fnum1
= cli_nt_create_full(cli1
, fname
, 0, FILE_READ_DATA
|FILE_WRITE_DATA
|DELETE_ACCESS
,
2967 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OVERWRITE_IF
, 0, 0);
2970 printf("[4] open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
2975 /* This should succeed. */
2976 fnum2
= cli_nt_create_full(cli1
, fname
, 0, GENERIC_READ_ACCESS
,
2977 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, FILE_OPEN
, 0, 0);
2979 printf("[4] open - 2 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
2984 if (!cli_close(cli1
, fnum2
)) {
2985 printf("[4] close - 1 failed (%s)\n", cli_errstr(cli1
));
2990 if (!cli_nt_delete_on_close(cli1
, fnum1
, True
)) {
2991 printf("[4] setting delete_on_close failed (%s)\n", cli_errstr(cli1
));
2996 /* This should fail - no more opens once delete on close set. */
2997 fnum2
= cli_nt_create_full(cli1
, fname
, 0, GENERIC_READ_ACCESS
,
2998 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
3001 printf("[4] open - 3 of %s succeeded ! Should have failed.\n", fname
);
3005 printf("fourth delete on close test succeeded.\n");
3007 if (!cli_close(cli1
, fnum1
)) {
3008 printf("[4] close - 2 failed (%s)\n", cli_errstr(cli1
));
3014 cli_setatr(cli1
, fname
, 0, 0);
3015 cli_unlink(cli1
, fname
);
3017 fnum1
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
, DENY_NONE
);
3019 printf("[5] open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3024 /* This should fail - only allowed on NT opens with DELETE access. */
3026 if (cli_nt_delete_on_close(cli1
, fnum1
, True
)) {
3027 printf("[5] setting delete_on_close on OpenX file succeeded - should fail !\n");
3032 if (!cli_close(cli1
, fnum1
)) {
3033 printf("[5] close - 2 failed (%s)\n", cli_errstr(cli1
));
3038 printf("fifth delete on close test succeeded.\n");
3041 cli_setatr(cli1
, fname
, 0, 0);
3042 cli_unlink(cli1
, fname
);
3044 fnum1
= cli_nt_create_full(cli1
, fname
, 0, FILE_READ_DATA
|FILE_WRITE_DATA
,
3045 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
3046 FILE_OVERWRITE_IF
, 0, 0);
3049 printf("[6] open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3054 /* This should fail - only allowed on NT opens with DELETE access. */
3056 if (cli_nt_delete_on_close(cli1
, fnum1
, True
)) {
3057 printf("[6] setting delete_on_close on file with no delete access succeeded - should fail !\n");
3062 if (!cli_close(cli1
, fnum1
)) {
3063 printf("[6] close - 2 failed (%s)\n", cli_errstr(cli1
));
3068 printf("sixth delete on close test succeeded.\n");
3071 cli_setatr(cli1
, fname
, 0, 0);
3072 cli_unlink(cli1
, fname
);
3074 fnum1
= cli_nt_create_full(cli1
, fname
, 0, FILE_READ_DATA
|FILE_WRITE_DATA
|DELETE_ACCESS
,
3075 FILE_ATTRIBUTE_NORMAL
, 0, FILE_OVERWRITE_IF
, 0, 0);
3078 printf("[7] open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3083 if (!cli_nt_delete_on_close(cli1
, fnum1
, True
)) {
3084 printf("[7] setting delete_on_close on file failed !\n");
3089 if (!cli_nt_delete_on_close(cli1
, fnum1
, False
)) {
3090 printf("[7] unsetting delete_on_close on file failed !\n");
3095 if (!cli_close(cli1
, fnum1
)) {
3096 printf("[7] close - 2 failed (%s)\n", cli_errstr(cli1
));
3101 /* This next open should succeed - we reset the flag. */
3103 fnum1
= cli_open(cli1
, fname
, O_RDONLY
, DENY_NONE
);
3105 printf("[5] open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3110 if (!cli_close(cli1
, fnum1
)) {
3111 printf("[7] close - 2 failed (%s)\n", cli_errstr(cli1
));
3116 printf("seventh delete on close test succeeded.\n");
3119 cli_setatr(cli1
, fname
, 0, 0);
3120 cli_unlink(cli1
, fname
);
3122 if (!torture_open_connection(&cli2
)) {
3123 printf("[8] failed to open second connection.\n");
3128 cli_sockopt(cli1
, sockops
);
3130 fnum1
= cli_nt_create_full(cli1
, fname
, 0, FILE_READ_DATA
|FILE_WRITE_DATA
|DELETE_ACCESS
,
3131 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
3132 FILE_OVERWRITE_IF
, 0, 0);
3135 printf("[8] open 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3140 fnum2
= cli_nt_create_full(cli2
, fname
, 0, FILE_READ_DATA
|FILE_WRITE_DATA
|DELETE_ACCESS
,
3141 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
3145 printf("[8] open 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
3150 if (!cli_nt_delete_on_close(cli1
, fnum1
, True
)) {
3151 printf("[8] setting delete_on_close on file failed !\n");
3156 if (!cli_close(cli1
, fnum1
)) {
3157 printf("[8] close - 1 failed (%s)\n", cli_errstr(cli1
));
3162 if (!cli_close(cli2
, fnum2
)) {
3163 printf("[8] close - 2 failed (%s)\n", cli_errstr(cli2
));
3168 /* This should fail.. */
3169 fnum1
= cli_open(cli1
, fname
, O_RDONLY
, DENY_NONE
);
3171 printf("[8] open of %s succeeded should have been deleted on close !\n", fname
);
3175 printf("eighth delete on close test succeeded.\n");
3177 /* This should fail - we need to set DELETE_ACCESS. */
3178 fnum1
= cli_nt_create_full(cli1
, fname
, 0,FILE_READ_DATA
|FILE_WRITE_DATA
,
3179 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, FILE_DELETE_ON_CLOSE
, 0);
3182 printf("[9] open of %s succeeded should have failed!\n", fname
);
3187 printf("ninth delete on close test succeeded.\n");
3189 fnum1
= cli_nt_create_full(cli1
, fname
, 0, FILE_READ_DATA
|FILE_WRITE_DATA
|DELETE_ACCESS
,
3190 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, FILE_DELETE_ON_CLOSE
, 0);
3192 printf("[10] open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3197 /* This should delete the file. */
3198 if (!cli_close(cli1
, fnum1
)) {
3199 printf("[10] close failed (%s)\n", cli_errstr(cli1
));
3204 /* This should fail.. */
3205 fnum1
= cli_open(cli1
, fname
, O_RDONLY
, DENY_NONE
);
3207 printf("[10] open of %s succeeded should have been deleted on close !\n", fname
);
3211 printf("tenth delete on close test succeeded.\n");
3213 cli_setatr(cli1
, fname
, 0, 0);
3214 cli_unlink(cli1
, fname
);
3216 /* What error do we get when attempting to open a read-only file with
3219 /* Create a readonly file. */
3220 fnum1
= cli_nt_create_full(cli1
, fname
, 0, FILE_READ_DATA
|FILE_WRITE_DATA
,
3221 FILE_ATTRIBUTE_READONLY
, FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0);
3223 printf("[11] open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3228 if (!cli_close(cli1
, fnum1
)) {
3229 printf("[11] close failed (%s)\n", cli_errstr(cli1
));
3234 /* Now try open for delete access. */
3235 fnum1
= cli_nt_create_full(cli1
, fname
, 0, FILE_READ_ATTRIBUTES
|DELETE_ACCESS
,
3236 0, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
3237 FILE_OVERWRITE_IF
, 0, 0);
3240 printf("[11] open of %s succeeded should have been denied with ACCESS_DENIED!\n", fname
);
3241 cli_close(cli1
, fnum1
);
3245 NTSTATUS nterr
= cli_nt_error(cli1
);
3246 if (!NT_STATUS_EQUAL(nterr
,NT_STATUS_ACCESS_DENIED
)) {
3247 printf("[11] open of %s should have been denied with ACCESS_DENIED! Got error %s\n", fname
, nt_errstr(nterr
));
3251 printf("eleventh delete on close test succeeded.\n");
3255 printf("finished delete test\n");
3258 /* FIXME: This will crash if we aborted before cli2 got
3259 * intialized, because these functions don't handle
3260 * uninitialized connections. */
3262 if (fnum1
!= -1) cli_close(cli1
, fnum1
);
3263 if (fnum2
!= -1) cli_close(cli1
, fnum2
);
3264 cli_setatr(cli1
, fname
, 0, 0);
3265 cli_unlink(cli1
, fname
);
3267 if (cli1
&& !torture_close_connection(cli1
)) {
3270 if (cli2
&& !torture_close_connection(cli2
)) {
3278 print out server properties
3280 static BOOL
run_properties(int dummy
)
3282 static struct cli_state
*cli
;
3283 BOOL correct
= True
;
3285 printf("starting properties test\n");
3289 if (!torture_open_connection(&cli
)) {
3293 cli_sockopt(cli
, sockops
);
3295 d_printf("Capabilities 0x%08x\n", cli
->capabilities
);
3297 if (!torture_close_connection(cli
)) {
3306 /* FIRST_DESIRED_ACCESS 0xf019f */
3307 #define FIRST_DESIRED_ACCESS FILE_READ_DATA|FILE_WRITE_DATA|FILE_APPEND_DATA|\
3308 FILE_READ_EA| /* 0xf */ \
3309 FILE_WRITE_EA|FILE_READ_ATTRIBUTES| /* 0x90 */ \
3310 FILE_WRITE_ATTRIBUTES| /* 0x100 */ \
3311 DELETE_ACCESS|READ_CONTROL_ACCESS|\
3312 WRITE_DAC_ACCESS|WRITE_OWNER_ACCESS /* 0xf0000 */
3313 /* SECOND_DESIRED_ACCESS 0xe0080 */
3314 #define SECOND_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
3315 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
3316 WRITE_OWNER_ACCESS /* 0xe0000 */
3319 #define THIRD_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
3320 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
3322 WRITE_OWNER_ACCESS /* */
3326 Test ntcreate calls made by xcopy
3328 static BOOL
run_xcopy(int dummy
)
3330 static struct cli_state
*cli1
;
3331 const char *fname
= "\\test.txt";
3332 BOOL correct
= True
;
3335 printf("starting xcopy test\n");
3337 if (!torture_open_connection(&cli1
)) {
3341 fnum1
= cli_nt_create_full(cli1
, fname
, 0,
3342 FIRST_DESIRED_ACCESS
, FILE_ATTRIBUTE_ARCHIVE
,
3343 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
,
3347 printf("First open failed - %s\n", cli_errstr(cli1
));
3351 fnum2
= cli_nt_create_full(cli1
, fname
, 0,
3352 SECOND_DESIRED_ACCESS
, 0,
3353 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, FILE_OPEN
,
3356 printf("second open failed - %s\n", cli_errstr(cli1
));
3360 if (!torture_close_connection(cli1
)) {
3368 Test rename on files open with share delete and no share delete.
3370 static BOOL
run_rename(int dummy
)
3372 static struct cli_state
*cli1
;
3373 const char *fname
= "\\test.txt";
3374 const char *fname1
= "\\test1.txt";
3375 BOOL correct
= True
;
3378 printf("starting rename test\n");
3380 if (!torture_open_connection(&cli1
)) {
3384 cli_unlink(cli1
, fname
);
3385 cli_unlink(cli1
, fname1
);
3386 fnum1
= cli_nt_create_full(cli1
, fname
, 0, GENERIC_READ_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
3387 FILE_SHARE_READ
, FILE_OVERWRITE_IF
, 0, 0);
3390 printf("First open failed - %s\n", cli_errstr(cli1
));
3394 if (!cli_rename(cli1
, fname
, fname1
)) {
3395 printf("First rename failed (SHARE_READ) (this is correct) - %s\n", cli_errstr(cli1
));
3397 printf("First rename succeeded (SHARE_READ) - this should have failed !\n");
3401 if (!cli_close(cli1
, fnum1
)) {
3402 printf("close - 1 failed (%s)\n", cli_errstr(cli1
));
3406 cli_unlink(cli1
, fname
);
3407 cli_unlink(cli1
, fname1
);
3408 fnum1
= cli_nt_create_full(cli1
, fname
, 0, GENERIC_READ_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
3410 FILE_SHARE_DELETE
|FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0);
3412 FILE_SHARE_DELETE
|FILE_SHARE_READ
, FILE_OVERWRITE_IF
, 0, 0);
3416 printf("Second open failed - %s\n", cli_errstr(cli1
));
3420 if (!cli_rename(cli1
, fname
, fname1
)) {
3421 printf("Second rename failed (SHARE_DELETE | SHARE_READ) - this should have succeeded - %s\n", cli_errstr(cli1
));
3424 printf("Second rename succeeded (SHARE_DELETE | SHARE_READ)\n");
3427 if (!cli_close(cli1
, fnum1
)) {
3428 printf("close - 2 failed (%s)\n", cli_errstr(cli1
));
3432 cli_unlink(cli1
, fname
);
3433 cli_unlink(cli1
, fname1
);
3435 fnum1
= cli_nt_create_full(cli1
, fname
, 0, READ_CONTROL_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
3436 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0);
3439 printf("Third open failed - %s\n", cli_errstr(cli1
));
3448 fnum2
= cli_nt_create_full(cli1
, fname
, 0, DELETE_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
3449 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0);
3452 printf("Fourth open failed - %s\n", cli_errstr(cli1
));
3455 if (!cli_nt_delete_on_close(cli1
, fnum2
, True
)) {
3456 printf("[8] setting delete_on_close on file failed !\n");
3460 if (!cli_close(cli1
, fnum2
)) {
3461 printf("close - 4 failed (%s)\n", cli_errstr(cli1
));
3467 if (!cli_rename(cli1
, fname
, fname1
)) {
3468 printf("Third rename failed (SHARE_NONE) - this should have succeeded - %s\n", cli_errstr(cli1
));
3471 printf("Third rename succeeded (SHARE_NONE)\n");
3474 if (!cli_close(cli1
, fnum1
)) {
3475 printf("close - 3 failed (%s)\n", cli_errstr(cli1
));
3479 cli_unlink(cli1
, fname
);
3480 cli_unlink(cli1
, fname1
);
3484 fnum1
= cli_nt_create_full(cli1
, fname
, 0, GENERIC_READ_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
3485 FILE_SHARE_READ
| FILE_SHARE_WRITE
, FILE_OVERWRITE_IF
, 0, 0);
3488 printf("Fourth open failed - %s\n", cli_errstr(cli1
));
3492 if (!cli_rename(cli1
, fname
, fname1
)) {
3493 printf("Fourth rename failed (SHARE_READ | SHARE_WRITE) (this is correct) - %s\n", cli_errstr(cli1
));
3495 printf("Fourth rename succeeded (SHARE_READ | SHARE_WRITE) - this should have failed !\n");
3499 if (!cli_close(cli1
, fnum1
)) {
3500 printf("close - 4 failed (%s)\n", cli_errstr(cli1
));
3504 cli_unlink(cli1
, fname
);
3505 cli_unlink(cli1
, fname1
);
3509 fnum1
= cli_nt_create_full(cli1
, fname
, 0, GENERIC_READ_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
3510 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
, FILE_OVERWRITE_IF
, 0, 0);
3513 printf("Fifth open failed - %s\n", cli_errstr(cli1
));
3517 if (!cli_rename(cli1
, fname
, fname1
)) {
3518 printf("Fifth rename failed (SHARE_READ | SHARE_WRITE | SHARE_DELETE) - this should have failed ! \n");
3521 printf("Fifth rename succeeded (SHARE_READ | SHARE_WRITE | SHARE_DELETE) (this is correct) - %s\n", cli_errstr(cli1
));
3525 * Now check if the first name still exists ...
3528 /*fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3529 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0, 0);
3532 printf("Opening original file after rename of open file fails: %s\n",
3536 printf("Opening original file after rename of open file works ...\n");
3537 (void)cli_close(cli1, fnum2);
3543 if (!cli_close(cli1
, fnum1
)) {
3544 printf("close - 5 failed (%s)\n", cli_errstr(cli1
));
3548 cli_unlink(cli1
, fname
);
3549 cli_unlink(cli1
, fname1
);
3551 if (!torture_close_connection(cli1
)) {
3558 static BOOL
run_pipe_number(int dummy
)
3560 struct cli_state
*cli1
;
3561 const char *pipe_name
= "\\SPOOLSS";
3565 printf("starting pipenumber test\n");
3566 if (!torture_open_connection(&cli1
)) {
3570 cli_sockopt(cli1
, sockops
);
3572 fnum
= cli_nt_create_full(cli1
, pipe_name
, 0, FILE_READ_DATA
, FILE_ATTRIBUTE_NORMAL
,
3573 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OPEN_IF
, 0, 0);
3576 printf("Open of pipe %s failed with error (%s)\n", pipe_name
, cli_errstr(cli1
));
3582 printf("pipe_number test - we can open %d %s pipes.\n", num_pipes
, pipe_name
);
3583 torture_close_connection(cli1
);
3588 Test open mode returns on read-only files.
3590 static BOOL
run_opentest(int dummy
)
3592 static struct cli_state
*cli1
;
3593 static struct cli_state
*cli2
;
3594 const char *fname
= "\\readonly.file";
3598 BOOL correct
= True
;
3601 printf("starting open test\n");
3603 if (!torture_open_connection(&cli1
)) {
3607 cli_setatr(cli1
, fname
, 0, 0);
3608 cli_unlink(cli1
, fname
);
3610 cli_sockopt(cli1
, sockops
);
3612 fnum1
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
);
3614 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3618 if (!cli_close(cli1
, fnum1
)) {
3619 printf("close2 failed (%s)\n", cli_errstr(cli1
));
3623 if (!cli_setatr(cli1
, fname
, aRONLY
, 0)) {
3624 printf("cli_setatr failed (%s)\n", cli_errstr(cli1
));
3628 fnum1
= cli_open(cli1
, fname
, O_RDONLY
, DENY_WRITE
);
3630 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3634 /* This will fail - but the error should be ERRnoaccess, not ERRbadshare. */
3635 fnum2
= cli_open(cli1
, fname
, O_RDWR
, DENY_ALL
);
3637 if (check_error(__LINE__
, cli1
, ERRDOS
, ERRnoaccess
,
3638 NT_STATUS_ACCESS_DENIED
)) {
3639 printf("correct error code ERRDOS/ERRnoaccess returned\n");
3642 printf("finished open test 1\n");
3644 cli_close(cli1
, fnum1
);
3646 /* Now try not readonly and ensure ERRbadshare is returned. */
3648 cli_setatr(cli1
, fname
, 0, 0);
3650 fnum1
= cli_open(cli1
, fname
, O_RDONLY
, DENY_WRITE
);
3652 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3656 /* This will fail - but the error should be ERRshare. */
3657 fnum2
= cli_open(cli1
, fname
, O_RDWR
, DENY_ALL
);
3659 if (check_error(__LINE__
, cli1
, ERRDOS
, ERRbadshare
,
3660 NT_STATUS_SHARING_VIOLATION
)) {
3661 printf("correct error code ERRDOS/ERRbadshare returned\n");
3664 if (!cli_close(cli1
, fnum1
)) {
3665 printf("close2 failed (%s)\n", cli_errstr(cli1
));
3669 cli_unlink(cli1
, fname
);
3671 printf("finished open test 2\n");
3673 /* Test truncate open disposition on file opened for read. */
3675 fnum1
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
);
3677 printf("(3) open (1) of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3681 /* write 20 bytes. */
3683 memset(buf
, '\0', 20);
3685 if (cli_write(cli1
, fnum1
, 0, buf
, 0, 20) != 20) {
3686 printf("write failed (%s)\n", cli_errstr(cli1
));
3690 if (!cli_close(cli1
, fnum1
)) {
3691 printf("(3) close1 failed (%s)\n", cli_errstr(cli1
));
3695 /* Ensure size == 20. */
3696 if (!cli_getatr(cli1
, fname
, NULL
, &fsize
, NULL
)) {
3697 printf("(3) getatr failed (%s)\n", cli_errstr(cli1
));
3702 printf("(3) file size != 20\n");
3706 /* Now test if we can truncate a file opened for readonly. */
3708 fnum1
= cli_open(cli1
, fname
, O_RDONLY
|O_TRUNC
, DENY_NONE
);
3710 printf("(3) open (2) of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3714 if (!cli_close(cli1
, fnum1
)) {
3715 printf("close2 failed (%s)\n", cli_errstr(cli1
));
3719 /* Ensure size == 0. */
3720 if (!cli_getatr(cli1
, fname
, NULL
, &fsize
, NULL
)) {
3721 printf("(3) getatr failed (%s)\n", cli_errstr(cli1
));
3726 printf("(3) file size != 0\n");
3729 printf("finished open test 3\n");
3731 cli_unlink(cli1
, fname
);
3734 printf("testing ctemp\n");
3735 fnum1
= cli_ctemp(cli1
, "\\", &tmp_path
);
3737 printf("ctemp failed (%s)\n", cli_errstr(cli1
));
3740 printf("ctemp gave path %s\n", tmp_path
);
3741 if (!cli_close(cli1
, fnum1
)) {
3742 printf("close of temp failed (%s)\n", cli_errstr(cli1
));
3744 if (!cli_unlink(cli1
, tmp_path
)) {
3745 printf("unlink of temp failed (%s)\n", cli_errstr(cli1
));
3748 /* Test the non-io opens... */
3750 if (!torture_open_connection(&cli2
)) {
3754 cli_setatr(cli2
, fname
, 0, 0);
3755 cli_unlink(cli2
, fname
);
3757 cli_sockopt(cli2
, sockops
);
3759 printf("TEST #1 testing 2 non-io opens (no delete)\n");
3761 fnum1
= cli_nt_create_full(cli1
, fname
, 0, FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
3762 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0);
3765 printf("test 1 open 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3769 fnum2
= cli_nt_create_full(cli2
, fname
, 0, FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
3770 FILE_SHARE_NONE
, FILE_OPEN_IF
, 0, 0);
3773 printf("test 1 open 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
3777 if (!cli_close(cli1
, fnum1
)) {
3778 printf("test 1 close 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3781 if (!cli_close(cli2
, fnum2
)) {
3782 printf("test 1 close 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
3786 printf("non-io open test #1 passed.\n");
3788 cli_unlink(cli1
, fname
);
3790 printf("TEST #2 testing 2 non-io opens (first with delete)\n");
3792 fnum1
= cli_nt_create_full(cli1
, fname
, 0, DELETE_ACCESS
|FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
3793 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0);
3796 printf("test 2 open 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3800 fnum2
= cli_nt_create_full(cli2
, fname
, 0, FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
3801 FILE_SHARE_NONE
, FILE_OPEN_IF
, 0, 0);
3804 printf("test 2 open 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
3808 if (!cli_close(cli1
, fnum1
)) {
3809 printf("test 1 close 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3812 if (!cli_close(cli2
, fnum2
)) {
3813 printf("test 1 close 2 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3817 printf("non-io open test #2 passed.\n");
3819 cli_unlink(cli1
, fname
);
3821 printf("TEST #3 testing 2 non-io opens (second with delete)\n");
3823 fnum1
= cli_nt_create_full(cli1
, fname
, 0, FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
3824 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0);
3827 printf("test 3 open 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3831 fnum2
= cli_nt_create_full(cli2
, fname
, 0, DELETE_ACCESS
|FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
3832 FILE_SHARE_NONE
, FILE_OPEN_IF
, 0, 0);
3835 printf("test 3 open 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
3839 if (!cli_close(cli1
, fnum1
)) {
3840 printf("test 3 close 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3843 if (!cli_close(cli2
, fnum2
)) {
3844 printf("test 3 close 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
3848 printf("non-io open test #3 passed.\n");
3850 cli_unlink(cli1
, fname
);
3852 printf("TEST #4 testing 2 non-io opens (both with delete)\n");
3854 fnum1
= cli_nt_create_full(cli1
, fname
, 0, DELETE_ACCESS
|FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
3855 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0);
3858 printf("test 4 open 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3862 fnum2
= cli_nt_create_full(cli2
, fname
, 0, DELETE_ACCESS
|FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
3863 FILE_SHARE_NONE
, FILE_OPEN_IF
, 0, 0);
3866 printf("test 4 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname
, cli_errstr(cli2
));
3870 printf("test 3 open 2 of %s gave %s (correct error should be %s)\n", fname
, cli_errstr(cli2
), "sharing violation");
3872 if (!cli_close(cli1
, fnum1
)) {
3873 printf("test 4 close 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3877 printf("non-io open test #4 passed.\n");
3879 cli_unlink(cli1
, fname
);
3881 printf("TEST #5 testing 2 non-io opens (both with delete - both with file share delete)\n");
3883 fnum1
= cli_nt_create_full(cli1
, fname
, 0, DELETE_ACCESS
|FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
3884 FILE_SHARE_DELETE
, FILE_OVERWRITE_IF
, 0, 0);
3887 printf("test 5 open 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3891 fnum2
= cli_nt_create_full(cli2
, fname
, 0, DELETE_ACCESS
|FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
3892 FILE_SHARE_DELETE
, FILE_OPEN_IF
, 0, 0);
3895 printf("test 5 open 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
3899 if (!cli_close(cli1
, fnum1
)) {
3900 printf("test 5 close 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3904 if (!cli_close(cli2
, fnum2
)) {
3905 printf("test 5 close 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
3909 printf("non-io open test #5 passed.\n");
3911 printf("TEST #6 testing 1 non-io open, one io open\n");
3913 cli_unlink(cli1
, fname
);
3915 fnum1
= cli_nt_create_full(cli1
, fname
, 0, FILE_READ_DATA
, FILE_ATTRIBUTE_NORMAL
,
3916 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0);
3919 printf("test 6 open 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3923 fnum2
= cli_nt_create_full(cli2
, fname
, 0, FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
3924 FILE_SHARE_READ
, FILE_OPEN_IF
, 0, 0);
3927 printf("test 6 open 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
3931 if (!cli_close(cli1
, fnum1
)) {
3932 printf("test 6 close 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3936 if (!cli_close(cli2
, fnum2
)) {
3937 printf("test 6 close 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
3941 printf("non-io open test #6 passed.\n");
3943 printf("TEST #7 testing 1 non-io open, one io open with delete\n");
3945 cli_unlink(cli1
, fname
);
3947 fnum1
= cli_nt_create_full(cli1
, fname
, 0, FILE_READ_DATA
, FILE_ATTRIBUTE_NORMAL
,
3948 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0);
3951 printf("test 7 open 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3955 fnum2
= cli_nt_create_full(cli2
, fname
, 0, DELETE_ACCESS
|FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
3956 FILE_SHARE_READ
|FILE_SHARE_DELETE
, FILE_OPEN_IF
, 0, 0);
3959 printf("test 7 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname
, cli_errstr(cli2
));
3963 printf("test 7 open 2 of %s gave %s (correct error should be %s)\n", fname
, cli_errstr(cli2
), "sharing violation");
3965 if (!cli_close(cli1
, fnum1
)) {
3966 printf("test 7 close 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3970 printf("non-io open test #7 passed.\n");
3972 cli_unlink(cli1
, fname
);
3974 if (!torture_close_connection(cli1
)) {
3977 if (!torture_close_connection(cli2
)) {
3984 static uint32 open_attrs_table
[] = {
3985 FILE_ATTRIBUTE_NORMAL
,
3986 FILE_ATTRIBUTE_ARCHIVE
,
3987 FILE_ATTRIBUTE_READONLY
,
3988 FILE_ATTRIBUTE_HIDDEN
,
3989 FILE_ATTRIBUTE_SYSTEM
,
3991 FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
,
3992 FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
,
3993 FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
,
3994 FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
,
3995 FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_SYSTEM
,
3996 FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_SYSTEM
,
3998 FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
,
3999 FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_SYSTEM
,
4000 FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_SYSTEM
,
4001 FILE_ATTRIBUTE_HIDDEN
,FILE_ATTRIBUTE_SYSTEM
,
4004 struct trunc_open_results
{
4011 static struct trunc_open_results attr_results
[] = {
4012 { 0, FILE_ATTRIBUTE_NORMAL
, FILE_ATTRIBUTE_NORMAL
, FILE_ATTRIBUTE_ARCHIVE
},
4013 { 1, FILE_ATTRIBUTE_NORMAL
, FILE_ATTRIBUTE_ARCHIVE
, FILE_ATTRIBUTE_ARCHIVE
},
4014 { 2, FILE_ATTRIBUTE_NORMAL
, FILE_ATTRIBUTE_READONLY
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
},
4015 { 16, FILE_ATTRIBUTE_ARCHIVE
, FILE_ATTRIBUTE_NORMAL
, FILE_ATTRIBUTE_ARCHIVE
},
4016 { 17, FILE_ATTRIBUTE_ARCHIVE
, FILE_ATTRIBUTE_ARCHIVE
, FILE_ATTRIBUTE_ARCHIVE
},
4017 { 18, FILE_ATTRIBUTE_ARCHIVE
, FILE_ATTRIBUTE_READONLY
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
},
4018 { 51, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
},
4019 { 54, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
},
4020 { 56, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
},
4021 { 68, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
},
4022 { 71, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
},
4023 { 73, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_SYSTEM
},
4024 { 99, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_HIDDEN
,FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
},
4025 { 102, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
},
4026 { 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
},
4027 { 116, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
},
4028 { 119, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
},
4029 { 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
},
4030 { 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
},
4031 { 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
},
4032 { 227, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
},
4033 { 230, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
},
4034 { 232, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
},
4035 { 244, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
},
4036 { 247, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
},
4037 { 249, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_SYSTEM
}
4040 static BOOL
run_openattrtest(int dummy
)
4042 static struct cli_state
*cli1
;
4043 const char *fname
= "\\openattr.file";
4045 BOOL correct
= True
;
4047 unsigned int i
, j
, k
, l
;
4049 printf("starting open attr test\n");
4051 if (!torture_open_connection(&cli1
)) {
4055 cli_sockopt(cli1
, sockops
);
4057 for (k
= 0, i
= 0; i
< sizeof(open_attrs_table
)/sizeof(uint32
); i
++) {
4058 cli_setatr(cli1
, fname
, 0, 0);
4059 cli_unlink(cli1
, fname
);
4060 fnum1
= cli_nt_create_full(cli1
, fname
, 0, FILE_WRITE_DATA
, open_attrs_table
[i
],
4061 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0);
4064 printf("open %d (1) of %s failed (%s)\n", i
, fname
, cli_errstr(cli1
));
4068 if (!cli_close(cli1
, fnum1
)) {
4069 printf("close %d (1) of %s failed (%s)\n", i
, fname
, cli_errstr(cli1
));
4073 for (j
= 0; j
< sizeof(open_attrs_table
)/sizeof(uint32
); j
++) {
4074 fnum1
= cli_nt_create_full(cli1
, fname
, 0, FILE_READ_DATA
|FILE_WRITE_DATA
, open_attrs_table
[j
],
4075 FILE_SHARE_NONE
, FILE_OVERWRITE
, 0, 0);
4078 for (l
= 0; l
< sizeof(attr_results
)/sizeof(struct trunc_open_results
); l
++) {
4079 if (attr_results
[l
].num
== k
) {
4080 printf("[%d] trunc open 0x%x -> 0x%x of %s failed - should have succeeded !(0x%x:%s)\n",
4081 k
, open_attrs_table
[i
],
4082 open_attrs_table
[j
],
4083 fname
, NT_STATUS_V(cli_nt_error(cli1
)), cli_errstr(cli1
));
4087 if (NT_STATUS_V(cli_nt_error(cli1
)) != NT_STATUS_V(NT_STATUS_ACCESS_DENIED
)) {
4088 printf("[%d] trunc open 0x%x -> 0x%x failed with wrong error code %s\n",
4089 k
, open_attrs_table
[i
], open_attrs_table
[j
],
4094 printf("[%d] trunc open 0x%x -> 0x%x failed\n", k
, open_attrs_table
[i
], open_attrs_table
[j
]);
4100 if (!cli_close(cli1
, fnum1
)) {
4101 printf("close %d (2) of %s failed (%s)\n", j
, fname
, cli_errstr(cli1
));
4105 if (!cli_getatr(cli1
, fname
, &attr
, NULL
, NULL
)) {
4106 printf("getatr(2) failed (%s)\n", cli_errstr(cli1
));
4111 printf("[%d] getatr check [0x%x] trunc [0x%x] got attr 0x%x\n",
4112 k
, open_attrs_table
[i
], open_attrs_table
[j
], attr
);
4115 for (l
= 0; l
< sizeof(attr_results
)/sizeof(struct trunc_open_results
); l
++) {
4116 if (attr_results
[l
].num
== k
) {
4117 if (attr
!= attr_results
[l
].result_attr
||
4118 open_attrs_table
[i
] != attr_results
[l
].init_attr
||
4119 open_attrs_table
[j
] != attr_results
[l
].trunc_attr
) {
4120 printf("getatr check failed. [0x%x] trunc [0x%x] got attr 0x%x, should be 0x%x\n",
4121 open_attrs_table
[i
],
4122 open_attrs_table
[j
],
4124 attr_results
[l
].result_attr
);
4134 cli_setatr(cli1
, fname
, 0, 0);
4135 cli_unlink(cli1
, fname
);
4137 printf("open attr test %s.\n", correct
? "passed" : "failed");
4139 if (!torture_close_connection(cli1
)) {
4145 static void list_fn(const char *mnt
, file_info
*finfo
, const char *name
, void *state
)
4151 test directory listing speed
4153 static BOOL
run_dirtest(int dummy
)
4156 static struct cli_state
*cli
;
4159 BOOL correct
= True
;
4161 printf("starting directory test\n");
4163 if (!torture_open_connection(&cli
)) {
4167 cli_sockopt(cli
, sockops
);
4170 for (i
=0;i
<torture_numops
;i
++) {
4172 slprintf(fname
, sizeof(fname
), "\\%x", (int)random());
4173 fnum
= cli_open(cli
, fname
, O_RDWR
|O_CREAT
, DENY_NONE
);
4175 fprintf(stderr
,"Failed to open %s\n", fname
);
4178 cli_close(cli
, fnum
);
4183 printf("Matched %d\n", cli_list(cli
, "a*.*", 0, list_fn
, NULL
));
4184 printf("Matched %d\n", cli_list(cli
, "b*.*", 0, list_fn
, NULL
));
4185 printf("Matched %d\n", cli_list(cli
, "xyzabc", 0, list_fn
, NULL
));
4187 printf("dirtest core %g seconds\n", end_timer() - t1
);
4190 for (i
=0;i
<torture_numops
;i
++) {
4192 slprintf(fname
, sizeof(fname
), "\\%x", (int)random());
4193 cli_unlink(cli
, fname
);
4196 if (!torture_close_connection(cli
)) {
4200 printf("finished dirtest\n");
4205 static void del_fn(const char *mnt
, file_info
*finfo
, const char *mask
, void *state
)
4207 struct cli_state
*pcli
= (struct cli_state
*)state
;
4209 slprintf(fname
, sizeof(fname
), "\\LISTDIR\\%s", finfo
->name
);
4211 if (strcmp(finfo
->name
, ".") == 0 || strcmp(finfo
->name
, "..") == 0)
4214 if (finfo
->mode
& aDIR
) {
4215 if (!cli_rmdir(pcli
, fname
))
4216 printf("del_fn: failed to rmdir %s\n,", fname
);
4218 if (!cli_unlink(pcli
, fname
))
4219 printf("del_fn: failed to unlink %s\n,", fname
);
4225 sees what IOCTLs are supported
4227 BOOL
torture_ioctl_test(int dummy
)
4229 static struct cli_state
*cli
;
4230 uint16 device
, function
;
4232 const char *fname
= "\\ioctl.dat";
4236 if (!torture_open_connection(&cli
)) {
4240 printf("starting ioctl test\n");
4242 cli_unlink(cli
, fname
);
4244 fnum
= cli_open(cli
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
);
4246 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli
));
4250 status
= cli_raw_ioctl(cli
, fnum
, 0x2d0000 | (0x0420<<2), &blob
);
4251 printf("ioctl device info: %s\n", cli_errstr(cli
));
4253 status
= cli_raw_ioctl(cli
, fnum
, IOCTL_QUERY_JOB_INFO
, &blob
);
4254 printf("ioctl job info: %s\n", cli_errstr(cli
));
4256 for (device
=0;device
<0x100;device
++) {
4257 printf("testing device=0x%x\n", device
);
4258 for (function
=0;function
<0x100;function
++) {
4259 uint32 code
= (device
<<16) | function
;
4261 status
= cli_raw_ioctl(cli
, fnum
, code
, &blob
);
4263 if (NT_STATUS_IS_OK(status
)) {
4264 printf("ioctl 0x%x OK : %d bytes\n", code
, blob
.length
);
4265 data_blob_free(&blob
);
4270 if (!torture_close_connection(cli
)) {
4279 tries varients of chkpath
4281 BOOL
torture_chkpath_test(int dummy
)
4283 static struct cli_state
*cli
;
4287 if (!torture_open_connection(&cli
)) {
4291 printf("starting chkpath test\n");
4293 /* cleanup from an old run */
4294 cli_rmdir(cli
, "\\chkpath.dir\\dir2");
4295 cli_unlink(cli
, "\\chkpath.dir\\*");
4296 cli_rmdir(cli
, "\\chkpath.dir");
4298 if (!cli_mkdir(cli
, "\\chkpath.dir")) {
4299 printf("mkdir1 failed : %s\n", cli_errstr(cli
));
4303 if (!cli_mkdir(cli
, "\\chkpath.dir\\dir2")) {
4304 printf("mkdir2 failed : %s\n", cli_errstr(cli
));
4308 fnum
= cli_open(cli
, "\\chkpath.dir\\foo.txt", O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
);
4310 printf("open1 failed (%s)\n", cli_errstr(cli
));
4313 cli_close(cli
, fnum
);
4315 if (!cli_chkpath(cli
, "\\chkpath.dir")) {
4316 printf("chkpath1 failed: %s\n", cli_errstr(cli
));
4320 if (!cli_chkpath(cli
, "\\chkpath.dir\\dir2")) {
4321 printf("chkpath2 failed: %s\n", cli_errstr(cli
));
4325 if (!cli_chkpath(cli
, "\\chkpath.dir\\foo.txt")) {
4326 ret
= check_error(__LINE__
, cli
, ERRDOS
, ERRbadpath
,
4327 NT_STATUS_NOT_A_DIRECTORY
);
4329 printf("* chkpath on a file should fail\n");
4333 if (!cli_chkpath(cli
, "\\chkpath.dir\\bar.txt")) {
4334 ret
= check_error(__LINE__
, cli
, ERRDOS
, ERRbadfile
,
4335 NT_STATUS_OBJECT_NAME_NOT_FOUND
);
4337 printf("* chkpath on a non existant file should fail\n");
4341 if (!cli_chkpath(cli
, "\\chkpath.dir\\dirxx\\bar.txt")) {
4342 ret
= check_error(__LINE__
, cli
, ERRDOS
, ERRbadpath
,
4343 NT_STATUS_OBJECT_PATH_NOT_FOUND
);
4345 printf("* chkpath on a non existent component should fail\n");
4349 cli_rmdir(cli
, "\\chkpath.dir\\dir2");
4350 cli_unlink(cli
, "\\chkpath.dir\\*");
4351 cli_rmdir(cli
, "\\chkpath.dir");
4353 if (!torture_close_connection(cli
)) {
4360 static BOOL
run_eatest(int dummy
)
4362 static struct cli_state
*cli
;
4363 const char *fname
= "\\eatest.txt";
4364 BOOL correct
= True
;
4367 struct ea_struct
*ea_list
= NULL
;
4368 TALLOC_CTX
*mem_ctx
= talloc_init("eatest");
4370 printf("starting eatest\n");
4372 if (!torture_open_connection(&cli
)) {
4376 cli_unlink(cli
, fname
);
4377 fnum
= cli_nt_create_full(cli
, fname
, 0,
4378 FIRST_DESIRED_ACCESS
, FILE_ATTRIBUTE_ARCHIVE
,
4379 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
,
4383 printf("open failed - %s\n", cli_errstr(cli
));
4387 for (i
= 0; i
< 10; i
++) {
4388 fstring ea_name
, ea_val
;
4390 slprintf(ea_name
, sizeof(ea_name
), "EA_%d", i
);
4391 memset(ea_val
, (char)i
+1, i
+1);
4392 if (!cli_set_ea_fnum(cli
, fnum
, ea_name
, ea_val
, i
+1)) {
4393 printf("ea_set of name %s failed - %s\n", ea_name
, cli_errstr(cli
));
4398 cli_close(cli
, fnum
);
4399 for (i
= 0; i
< 10; i
++) {
4400 fstring ea_name
, ea_val
;
4402 slprintf(ea_name
, sizeof(ea_name
), "EA_%d", i
+10);
4403 memset(ea_val
, (char)i
+1, i
+1);
4404 if (!cli_set_ea_path(cli
, fname
, ea_name
, ea_val
, i
+1)) {
4405 printf("ea_set of name %s failed - %s\n", ea_name
, cli_errstr(cli
));
4410 if (!cli_get_ea_list_path(cli
, fname
, mem_ctx
, &num_eas
, &ea_list
)) {
4411 printf("ea_get list failed - %s\n", cli_errstr(cli
));
4415 printf("num_eas = %d\n", num_eas
);
4417 if (num_eas
!= 20) {
4418 printf("Should be 20 EA's stored... failing.\n");
4422 for (i
= 0; i
< num_eas
; i
++) {
4423 printf("%d: ea_name = %s. Val = ", i
, ea_list
[i
].name
);
4424 dump_data(0, ea_list
[i
].value
.data
, ea_list
[i
].value
.length
);
4427 /* Setting EA's to zero length deletes them. Test this */
4428 printf("Now deleting all EA's - case indepenent....\n");
4430 for (i
= 0; i
< 20; i
++) {
4432 slprintf(ea_name
, sizeof(ea_name
), "ea_%d", i
);
4433 if (!cli_set_ea_path(cli
, fname
, ea_name
, "", 0)) {
4434 printf("ea_set of name %s failed - %s\n", ea_name
, cli_errstr(cli
));
4439 if (!cli_get_ea_list_path(cli
, fname
, mem_ctx
, &num_eas
, &ea_list
)) {
4440 printf("ea_get list failed - %s\n", cli_errstr(cli
));
4444 printf("num_eas = %d\n", num_eas
);
4445 for (i
= 0; i
< num_eas
; i
++) {
4446 printf("%d: ea_name = %s. Val = ", i
, ea_list
[i
].name
);
4447 dump_data(0, ea_list
[i
].value
.data
, ea_list
[i
].value
.length
);
4451 printf("deleting EA's failed.\n");
4455 /* Try and delete a non existant EA. */
4456 if (!cli_set_ea_path(cli
, fname
, "foo", "", 0)) {
4457 printf("deleting non-existant EA 'foo' should succeed. %s\n", cli_errstr(cli
));
4461 talloc_destroy(mem_ctx
);
4462 if (!torture_close_connection(cli
)) {
4469 static BOOL
run_dirtest1(int dummy
)
4472 static struct cli_state
*cli
;
4474 BOOL correct
= True
;
4476 printf("starting directory test\n");
4478 if (!torture_open_connection(&cli
)) {
4482 cli_sockopt(cli
, sockops
);
4484 /* This is for a particular *slow* machine, lets see whether this then
4485 * shows up in the build farm. */
4488 cli_list(cli
, "\\LISTDIR\\*", 0, del_fn
, cli
);
4489 cli_list(cli
, "\\LISTDIR\\*", aDIR
, del_fn
, cli
);
4490 cli_rmdir(cli
, "\\LISTDIR");
4491 cli_mkdir(cli
, "\\LISTDIR");
4493 /* Create 1000 files and 1000 directories. */
4494 for (i
=0;i
<1000;i
++) {
4496 slprintf(fname
, sizeof(fname
), "\\LISTDIR\\f%d", i
);
4497 fnum
= cli_nt_create_full(cli
, fname
, 0, GENERIC_ALL_ACCESS
, FILE_ATTRIBUTE_ARCHIVE
,
4498 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OVERWRITE_IF
, 0, 0);
4500 fprintf(stderr
,"Failed to open %s\n", fname
);
4503 cli_close(cli
, fnum
);
4505 for (i
=0;i
<1000;i
++) {
4507 slprintf(fname
, sizeof(fname
), "\\LISTDIR\\d%d", i
);
4508 if (!cli_mkdir(cli
, fname
)) {
4509 fprintf(stderr
,"Failed to open %s\n", fname
);
4514 /* Now ensure that doing an old list sees both files and directories. */
4515 num_seen
= cli_list_old(cli
, "\\LISTDIR\\*", aDIR
, list_fn
, NULL
);
4516 printf("num_seen = %d\n", num_seen
);
4517 /* We should see 100 files + 1000 directories + . and .. */
4518 if (num_seen
!= 2002)
4521 /* Ensure if we have the "must have" bits we only see the
4524 num_seen
= cli_list_old(cli
, "\\LISTDIR\\*", (aDIR
<<8)|aDIR
, list_fn
, NULL
);
4525 printf("num_seen = %d\n", num_seen
);
4526 if (num_seen
!= 1002)
4529 num_seen
= cli_list_old(cli
, "\\LISTDIR\\*", (aARCH
<<8)|aDIR
, list_fn
, NULL
);
4530 printf("num_seen = %d\n", num_seen
);
4531 if (num_seen
!= 1000)
4534 /* Delete everything. */
4535 cli_list(cli
, "\\LISTDIR\\*", 0, del_fn
, cli
);
4536 cli_list(cli
, "\\LISTDIR\\*", aDIR
, del_fn
, cli
);
4537 cli_rmdir(cli
, "\\LISTDIR");
4540 printf("Matched %d\n", cli_list(cli
, "a*.*", 0, list_fn
, NULL
));
4541 printf("Matched %d\n", cli_list(cli
, "b*.*", 0, list_fn
, NULL
));
4542 printf("Matched %d\n", cli_list(cli
, "xyzabc", 0, list_fn
, NULL
));
4545 if (!torture_close_connection(cli
)) {
4549 printf("finished dirtest1\n");
4554 static BOOL
run_error_map_extract(int dummy
) {
4556 static struct cli_state c_dos
;
4557 static struct cli_state c_nt
;
4561 uint32 flgs2
, errnum
;
4568 /* NT-Error connection */
4570 if (!open_nbt_connection(&c_nt
)) {
4574 c_nt
.use_spnego
= False
;
4576 if (!cli_negprot(&c_nt
)) {
4577 printf("%s rejected the NT-error negprot (%s)\n",host
, cli_errstr(&c_nt
));
4578 cli_shutdown(&c_nt
);
4582 if (!cli_session_setup(&c_nt
, "", "", 0, "", 0,
4584 printf("%s rejected the NT-error initial session setup (%s)\n",host
, cli_errstr(&c_nt
));
4588 /* DOS-Error connection */
4590 if (!open_nbt_connection(&c_dos
)) {
4594 c_dos
.use_spnego
= False
;
4595 c_dos
.force_dos_errors
= True
;
4597 if (!cli_negprot(&c_dos
)) {
4598 printf("%s rejected the DOS-error negprot (%s)\n",host
, cli_errstr(&c_dos
));
4599 cli_shutdown(&c_dos
);
4603 if (!cli_session_setup(&c_dos
, "", "", 0, "", 0,
4605 printf("%s rejected the DOS-error initial session setup (%s)\n",host
, cli_errstr(&c_dos
));
4609 for (error
=(0xc0000000 | 0x1); error
< (0xc0000000| 0xFFF); error
++) {
4610 fstr_sprintf(user
, "%X", error
);
4612 if (cli_session_setup(&c_nt
, user
,
4613 password
, strlen(password
),
4614 password
, strlen(password
),
4616 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
4619 flgs2
= SVAL(c_nt
.inbuf
,smb_flg2
);
4621 /* Case #1: 32-bit NT errors */
4622 if (flgs2
& FLAGS2_32_BIT_ERROR_CODES
) {
4623 nt_status
= NT_STATUS(IVAL(c_nt
.inbuf
,smb_rcls
));
4625 printf("/** Dos error on NT connection! (%s) */\n",
4627 nt_status
= NT_STATUS(0xc0000000);
4630 if (cli_session_setup(&c_dos
, user
,
4631 password
, strlen(password
),
4632 password
, strlen(password
),
4634 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
4636 flgs2
= SVAL(c_dos
.inbuf
,smb_flg2
), errnum
;
4638 /* Case #1: 32-bit NT errors */
4639 if (flgs2
& FLAGS2_32_BIT_ERROR_CODES
) {
4640 printf("/** NT error on DOS connection! (%s) */\n",
4642 errnum
= errclass
= 0;
4644 cli_dos_error(&c_dos
, &errclass
, &errnum
);
4647 if (NT_STATUS_V(nt_status
) != error
) {
4648 printf("/*\t{ This NT error code was 'sqashed'\n\t from %s to %s \n\t during the session setup }\n*/\n",
4649 get_nt_error_c_code(NT_STATUS(error
)),
4650 get_nt_error_c_code(nt_status
));
4653 printf("\t{%s,\t%s,\t%s},\n",
4654 smb_dos_err_class(errclass
),
4655 smb_dos_err_name(errclass
, errnum
),
4656 get_nt_error_c_code(NT_STATUS(error
)));
4661 static double create_procs(BOOL (*fn
)(int), BOOL
*result
)
4664 volatile pid_t
*child_status
;
4665 volatile BOOL
*child_status_out
;
4671 child_status
= (volatile pid_t
*)shm_setup(sizeof(pid_t
)*nprocs
);
4672 if (!child_status
) {
4673 printf("Failed to setup shared memory\n");
4677 child_status_out
= (volatile BOOL
*)shm_setup(sizeof(BOOL
)*nprocs
);
4678 if (!child_status_out
) {
4679 printf("Failed to setup result status shared memory\n");
4683 for (i
= 0; i
< nprocs
; i
++) {
4684 child_status
[i
] = 0;
4685 child_status_out
[i
] = True
;
4690 for (i
=0;i
<nprocs
;i
++) {
4693 pid_t mypid
= getpid();
4694 sys_srandom(((int)mypid
) ^ ((int)time(NULL
)));
4696 slprintf(myname
,sizeof(myname
),"CLIENT%d", i
);
4699 if (torture_open_connection(¤t_cli
)) break;
4701 printf("pid %d failed to start\n", (int)getpid());
4707 child_status
[i
] = getpid();
4709 while (child_status
[i
] && end_timer() < 5) smb_msleep(2);
4711 child_status_out
[i
] = fn(i
);
4718 for (i
=0;i
<nprocs
;i
++) {
4719 if (child_status
[i
]) synccount
++;
4721 if (synccount
== nprocs
) break;
4723 } while (end_timer() < 30);
4725 if (synccount
!= nprocs
) {
4726 printf("FAILED TO START %d CLIENTS (started %d)\n", nprocs
, synccount
);
4731 /* start the client load */
4734 for (i
=0;i
<nprocs
;i
++) {
4735 child_status
[i
] = 0;
4738 printf("%d clients started\n", nprocs
);
4740 for (i
=0;i
<nprocs
;i
++) {
4741 while (waitpid(0, &status
, 0) == -1 && errno
== EINTR
) /* noop */ ;
4746 for (i
=0;i
<nprocs
;i
++) {
4747 if (!child_status_out
[i
]) {
4754 #define FLAG_MULTIPROC 1
4761 {"FDPASS", run_fdpasstest
, 0},
4762 {"LOCK1", run_locktest1
, 0},
4763 {"LOCK2", run_locktest2
, 0},
4764 {"LOCK3", run_locktest3
, 0},
4765 {"LOCK4", run_locktest4
, 0},
4766 {"LOCK5", run_locktest5
, 0},
4767 {"LOCK6", run_locktest6
, 0},
4768 {"LOCK7", run_locktest7
, 0},
4769 {"UNLINK", run_unlinktest
, 0},
4770 {"BROWSE", run_browsetest
, 0},
4771 {"ATTR", run_attrtest
, 0},
4772 {"TRANS2", run_trans2test
, 0},
4773 {"MAXFID", run_maxfidtest
, FLAG_MULTIPROC
},
4774 {"TORTURE",run_torture
, FLAG_MULTIPROC
},
4775 {"RANDOMIPC", run_randomipc
, 0},
4776 {"NEGNOWAIT", run_negprot_nowait
, 0},
4777 {"NBENCH", run_nbench
, 0},
4778 {"OPLOCK1", run_oplock1
, 0},
4779 {"OPLOCK2", run_oplock2
, 0},
4780 {"OPLOCK3", run_oplock3
, 0},
4781 {"DIR", run_dirtest
, 0},
4782 {"DIR1", run_dirtest1
, 0},
4783 {"DENY1", torture_denytest1
, 0},
4784 {"DENY2", torture_denytest2
, 0},
4785 {"TCON", run_tcon_test
, 0},
4786 {"TCONDEV", run_tcon_devtype_test
, 0},
4787 {"RW1", run_readwritetest
, 0},
4788 {"RW2", run_readwritemulti
, FLAG_MULTIPROC
},
4789 {"RW3", run_readwritelarge
, 0},
4790 {"OPEN", run_opentest
, 0},
4792 {"OPENATTR", run_openattrtest
, 0},
4794 {"XCOPY", run_xcopy
, 0},
4795 {"RENAME", run_rename
, 0},
4796 {"DELETE", run_deletetest
, 0},
4797 {"PROPERTIES", run_properties
, 0},
4798 {"MANGLE", torture_mangle
, 0},
4799 {"W2K", run_w2ktest
, 0},
4800 {"TRANS2SCAN", torture_trans2_scan
, 0},
4801 {"NTTRANSSCAN", torture_nttrans_scan
, 0},
4802 {"UTABLE", torture_utable
, 0},
4803 {"CASETABLE", torture_casetable
, 0},
4804 {"ERRMAPEXTRACT", run_error_map_extract
, 0},
4805 {"PIPE_NUMBER", run_pipe_number
, 0},
4806 {"TCON2", run_tcon2_test
, 0},
4807 {"IOCTL", torture_ioctl_test
, 0},
4808 {"CHKPATH", torture_chkpath_test
, 0},
4809 {"FDSESS", run_fdsesstest
, 0},
4810 { "EATEST", run_eatest
, 0},
4815 /****************************************************************************
4816 run a specified test or "ALL"
4817 ****************************************************************************/
4818 static BOOL
run_test(const char *name
)
4825 if (strequal(name
,"ALL")) {
4826 for (i
=0;torture_ops
[i
].name
;i
++) {
4827 run_test(torture_ops
[i
].name
);
4832 for (i
=0;torture_ops
[i
].name
;i
++) {
4833 fstr_sprintf(randomfname
, "\\XX%x",
4834 (unsigned)random());
4836 if (strequal(name
, torture_ops
[i
].name
)) {
4838 printf("Running %s\n", name
);
4839 if (torture_ops
[i
].flags
& FLAG_MULTIPROC
) {
4840 t
= create_procs(torture_ops
[i
].fn
, &result
);
4843 printf("TEST %s FAILED!\n", name
);
4848 if (!torture_ops
[i
].fn(0)) {
4850 printf("TEST %s FAILED!\n", name
);
4854 printf("%s took %g secs\n\n", name
, t
);
4859 printf("Did not find a test named %s\n", name
);
4867 static void usage(void)
4871 printf("WARNING samba4 test suite is much more complete nowadays.\n");
4872 printf("Please use samba4 torture.\n\n");
4874 printf("Usage: smbtorture //server/share <options> TEST1 TEST2 ...\n");
4876 printf("\t-d debuglevel\n");
4877 printf("\t-U user%%pass\n");
4878 printf("\t-k use kerberos\n");
4879 printf("\t-N numprocs\n");
4880 printf("\t-n my_netbios_name\n");
4881 printf("\t-W workgroup\n");
4882 printf("\t-o num_operations\n");
4883 printf("\t-O socket_options\n");
4884 printf("\t-m maximum protocol\n");
4885 printf("\t-L use oplocks\n");
4886 printf("\t-c CLIENT.TXT specify client load file for NBENCH\n");
4887 printf("\t-A showall\n");
4888 printf("\t-p port\n");
4889 printf("\t-s seed\n");
4892 printf("tests are:");
4893 for (i
=0;torture_ops
[i
].name
;i
++) {
4894 printf(" %s", torture_ops
[i
].name
);
4898 printf("default test is ALL\n");
4903 /****************************************************************************
4905 ****************************************************************************/
4906 int main(int argc
,char *argv
[])
4912 BOOL correct
= True
;
4916 #ifdef HAVE_SETBUFFER
4917 setbuffer(stdout
, NULL
, 0);
4920 lp_load(dyn_CONFIGFILE
,True
,False
,False
);
4927 for(p
= argv
[1]; *p
; p
++)
4931 if (strncmp(argv
[1], "//", 2)) {
4935 fstrcpy(host
, &argv
[1][2]);
4936 p
= strchr_m(&host
[2],'/');
4941 fstrcpy(share
, p
+1);
4945 if (*username
== 0 && getenv("LOGNAME")) {
4946 fstrcpy(username
,getenv("LOGNAME"));
4952 srandom(time(NULL
));
4954 fstrcpy(workgroup
, lp_workgroup());
4956 while ((opt
= getopt(argc
, argv
, "p:hW:U:n:N:O:o:m:Ld:Ac:ks:")) != EOF
) {
4959 port_to_use
= atoi(optarg
);
4962 srandom(atoi(optarg
));
4965 fstrcpy(workgroup
,optarg
);
4968 max_protocol
= interpret_protocol(optarg
, max_protocol
);
4971 nprocs
= atoi(optarg
);
4974 torture_numops
= atoi(optarg
);
4977 DEBUGLEVEL
= atoi(optarg
);
4986 torture_showall
= True
;
4989 fstrcpy(myname
, optarg
);
4992 client_txt
= optarg
;
4996 use_kerberos
= True
;
4998 d_printf("No kerberos support compiled in\n");
5004 fstrcpy(username
,optarg
);
5005 p
= strchr_m(username
,'%');
5008 fstrcpy(password
, p
+1);
5013 printf("Unknown option %c (%d)\n", (char)opt
, opt
);
5018 if(use_kerberos
&& !gotuser
) gotpass
= True
;
5021 p
= getpass("Password:");
5023 fstrcpy(password
, p
);
5028 printf("host=%s share=%s user=%s myname=%s\n",
5029 host
, share
, username
, myname
);
5031 if (argc
== optind
) {
5032 correct
= run_test("ALL");
5034 for (i
=optind
;i
<argc
;i
++) {
5035 if (!run_test(argv
[i
])) {