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.
26 static fstring host
, workgroup
, share
, password
, username
, myname
;
27 static int max_protocol
= PROTOCOL_NT1
;
28 static const char *sockops
="TCP_NODELAY";
30 static int port_to_use
=0;
31 int torture_numops
=100;
32 static int procnum
; /* records process count number when forking */
33 static struct cli_state
*current_cli
;
34 static fstring randomfname
;
35 static BOOL use_oplocks
;
36 static BOOL use_level_II_oplocks
;
37 static const char *client_txt
= "client_oplocks.txt";
38 static BOOL use_kerberos
;
40 BOOL torture_showall
= False
;
42 static double create_procs(BOOL (*fn
)(int), BOOL
*result
);
45 static struct timeval tp1
,tp2
;
47 void start_timer(void)
52 double end_timer(void)
55 return((tp2
.tv_sec
- tp1
.tv_sec
) +
56 (tp2
.tv_usec
- tp1
.tv_usec
)*1.0e-6);
60 /* return a pointer to a anonymous shared memory segment of size "size"
61 which will persist across fork() but will disappear when all processes
64 The memory is not zeroed
66 This function uses system5 shared memory. It takes advantage of a property
67 that the memory is not destroyed if it is attached when the id is removed
69 void *shm_setup(int size
)
74 shmid
= shmget(IPC_PRIVATE
, size
, S_IRUSR
| S_IWUSR
);
76 printf("can't get shared memory\n");
79 ret
= (void *)shmat(shmid
, 0, 0);
80 if (!ret
|| ret
== (void *)-1) {
81 printf("can't attach to shared memory\n");
84 /* the following releases the ipc, but note that this process
85 and all its children will still have access to the memory, its
86 just that the shmid is no longer valid for other shm calls. This
87 means we don't leave behind lots of shm segments after we exit
89 See Stevens "advanced programming in unix env" for details
91 shmctl(shmid
, IPC_RMID
, 0);
97 static BOOL
open_nbt_connection(struct cli_state
*c
)
99 struct nmb_name called
, calling
;
104 make_nmb_name(&calling
, myname
, 0x0);
105 make_nmb_name(&called
, host
, 0x20);
109 if (!cli_initialise(c
)) {
110 printf("Failed initialize cli_struct to connect with %s\n", host
);
114 c
->port
= port_to_use
;
116 if (!cli_connect(c
, host
, &ip
)) {
117 printf("Failed to connect with %s\n", host
);
121 c
->use_kerberos
= use_kerberos
;
123 c
->timeout
= 120000; /* set a really long timeout (2 minutes) */
124 if (use_oplocks
) c
->use_oplocks
= True
;
125 if (use_level_II_oplocks
) c
->use_level_II_oplocks
= True
;
127 if (!cli_session_request(c
, &calling
, &called
)) {
129 * Well, that failed, try *SMBSERVER ...
130 * However, we must reconnect as well ...
132 if (!cli_connect(c
, host
, &ip
)) {
133 printf("Failed to connect with %s\n", host
);
137 make_nmb_name(&called
, "*SMBSERVER", 0x20);
138 if (!cli_session_request(c
, &calling
, &called
)) {
139 printf("%s rejected the session\n",host
);
140 printf("We tried with a called name of %s & %s\n",
150 BOOL
torture_open_connection(struct cli_state
**c
)
157 flags
|= CLI_FULL_CONNECTION_USE_KERBEROS
;
159 status
= cli_full_connection(c
, myname
,
160 host
, NULL
, port_to_use
,
163 password
, flags
, Undefined
, &retry
);
164 if (!NT_STATUS_IS_OK(status
)) {
168 if (use_oplocks
) (*c
)->use_oplocks
= True
;
169 if (use_level_II_oplocks
) (*c
)->use_level_II_oplocks
= True
;
170 (*c
)->timeout
= 120000; /* set a really long timeout (2 minutes) */
175 BOOL
torture_cli_session_setup2(struct cli_state
*cli
, uint16
*new_vuid
)
177 uint16 old_vuid
= cli
->vuid
;
178 fstring old_user_name
;
179 size_t passlen
= strlen(password
);
182 fstrcpy(old_user_name
, cli
->user_name
);
184 ret
= cli_session_setup(cli
, username
, password
, passlen
, password
, passlen
, workgroup
);
185 *new_vuid
= cli
->vuid
;
186 cli
->vuid
= old_vuid
;
187 fstrcpy(cli
->user_name
, old_user_name
);
192 BOOL
torture_close_connection(struct cli_state
*c
)
196 printf("tdis failed (%s)\n", cli_errstr(c
));
206 /* check if the server produced the expected error code */
207 static BOOL
check_error(int line
, struct cli_state
*c
,
208 uint8 eclass
, uint32 ecode
, NTSTATUS nterr
)
210 if (cli_is_dos_error(c
)) {
214 /* Check DOS error */
216 cli_dos_error(c
, &cclass
, &num
);
218 if (eclass
!= cclass
|| ecode
!= num
) {
219 printf("unexpected error code class=%d code=%d\n",
220 (int)cclass
, (int)num
);
221 printf(" expected %d/%d %s (line=%d)\n",
222 (int)eclass
, (int)ecode
, nt_errstr(nterr
), line
);
231 status
= cli_nt_error(c
);
233 if (NT_STATUS_V(nterr
) != NT_STATUS_V(status
)) {
234 printf("unexpected error code %s\n", nt_errstr(status
));
235 printf(" expected %s (line=%d)\n", nt_errstr(nterr
), line
);
244 static BOOL
wait_lock(struct cli_state
*c
, int fnum
, uint32 offset
, uint32 len
)
246 while (!cli_lock(c
, fnum
, offset
, len
, -1, WRITE_LOCK
)) {
247 if (!check_error(__LINE__
, c
, ERRDOS
, ERRlock
, NT_STATUS_LOCK_NOT_GRANTED
)) return False
;
253 static BOOL
rw_torture(struct cli_state
*c
)
255 const char *lockfname
= "\\torture.lck";
259 pid_t pid2
, pid
= getpid();
264 fnum2
= cli_open(c
, lockfname
, O_RDWR
| O_CREAT
| O_EXCL
,
267 fnum2
= cli_open(c
, lockfname
, O_RDWR
, DENY_NONE
);
269 printf("open of %s failed (%s)\n", lockfname
, cli_errstr(c
));
274 for (i
=0;i
<torture_numops
;i
++) {
275 unsigned n
= (unsigned)sys_random()%10;
277 printf("%d\r", i
); fflush(stdout
);
279 slprintf(fname
, sizeof(fstring
) - 1, "\\torture.%u", n
);
281 if (!wait_lock(c
, fnum2
, n
*sizeof(int), sizeof(int))) {
285 fnum
= cli_open(c
, fname
, O_RDWR
| O_CREAT
| O_TRUNC
, DENY_ALL
);
287 printf("open failed (%s)\n", cli_errstr(c
));
292 if (cli_write(c
, fnum
, 0, (char *)&pid
, 0, sizeof(pid
)) != sizeof(pid
)) {
293 printf("write failed (%s)\n", cli_errstr(c
));
298 if (cli_write(c
, fnum
, 0, (char *)buf
,
299 sizeof(pid
)+(j
*sizeof(buf
)),
300 sizeof(buf
)) != sizeof(buf
)) {
301 printf("write failed (%s)\n", cli_errstr(c
));
308 if (cli_read(c
, fnum
, (char *)&pid2
, 0, sizeof(pid
)) != sizeof(pid
)) {
309 printf("read failed (%s)\n", cli_errstr(c
));
314 printf("data corruption!\n");
318 if (!cli_close(c
, fnum
)) {
319 printf("close failed (%s)\n", cli_errstr(c
));
323 if (!cli_unlink(c
, fname
)) {
324 printf("unlink failed (%s)\n", cli_errstr(c
));
328 if (!cli_unlock(c
, fnum2
, n
*sizeof(int), sizeof(int))) {
329 printf("unlock failed (%s)\n", cli_errstr(c
));
335 cli_unlink(c
, lockfname
);
342 static BOOL
run_torture(int dummy
)
344 struct cli_state
*cli
;
349 cli_sockopt(cli
, sockops
);
351 ret
= rw_torture(cli
);
353 if (!torture_close_connection(cli
)) {
360 static BOOL
rw_torture3(struct cli_state
*c
, char *lockfname
)
367 unsigned countprev
= 0;
372 for (i
= 0; i
< sizeof(buf
); i
+= sizeof(uint32
))
374 SIVAL(buf
, i
, sys_random());
379 fnum
= cli_open(c
, lockfname
, O_RDWR
| O_CREAT
| O_EXCL
,
382 printf("first open read/write of %s failed (%s)\n",
383 lockfname
, cli_errstr(c
));
389 for (i
= 0; i
< 500 && fnum
== -1; i
++)
391 fnum
= cli_open(c
, lockfname
, O_RDONLY
,
396 printf("second open read-only of %s failed (%s)\n",
397 lockfname
, cli_errstr(c
));
403 for (count
= 0; count
< sizeof(buf
); count
+= sent
)
405 if (count
>= countprev
) {
406 printf("%d %8d\r", i
, count
);
409 countprev
+= (sizeof(buf
) / 20);
414 sent
= ((unsigned)sys_random()%(20))+ 1;
415 if (sent
> sizeof(buf
) - count
)
417 sent
= sizeof(buf
) - count
;
420 if (cli_write(c
, fnum
, 0, buf
+count
, count
, (size_t)sent
) != sent
) {
421 printf("write failed (%s)\n", cli_errstr(c
));
427 sent
= cli_read(c
, fnum
, buf_rd
+count
, count
,
431 printf("read failed offset:%d size:%ld (%s)\n",
432 count
, (unsigned long)sizeof(buf
)-count
,
439 if (memcmp(buf_rd
+count
, buf
+count
, sent
) != 0)
441 printf("read/write compare failed\n");
442 printf("offset: %d req %ld recvd %ld\n", count
, (unsigned long)sizeof(buf
)-count
, (unsigned long)sent
);
451 if (!cli_close(c
, fnum
)) {
452 printf("close failed (%s)\n", cli_errstr(c
));
459 static BOOL
rw_torture2(struct cli_state
*c1
, struct cli_state
*c2
)
461 const char *lockfname
= "\\torture2.lck";
466 uchar buf_rd
[131072];
470 if (!cli_unlink(c1
, lockfname
)) {
471 printf("unlink failed (%s) (normal, this file should not exist)\n", cli_errstr(c1
));
474 fnum1
= cli_open(c1
, lockfname
, O_RDWR
| O_CREAT
| O_EXCL
,
477 printf("first open read/write of %s failed (%s)\n",
478 lockfname
, cli_errstr(c1
));
481 fnum2
= cli_open(c2
, lockfname
, O_RDONLY
,
484 printf("second open read-only of %s failed (%s)\n",
485 lockfname
, cli_errstr(c2
));
486 cli_close(c1
, fnum1
);
490 for (i
=0;i
<torture_numops
;i
++)
492 size_t buf_size
= ((unsigned)sys_random()%(sizeof(buf
)-1))+ 1;
494 printf("%d\r", i
); fflush(stdout
);
497 generate_random_buffer(buf
, buf_size
);
499 if (cli_write(c1
, fnum1
, 0, buf
, 0, buf_size
) != buf_size
) {
500 printf("write failed (%s)\n", cli_errstr(c1
));
505 if ((bytes_read
= cli_read(c2
, fnum2
, buf_rd
, 0, buf_size
)) != buf_size
) {
506 printf("read failed (%s)\n", cli_errstr(c2
));
507 printf("read %d, expected %ld\n", bytes_read
,
508 (unsigned long)buf_size
);
513 if (memcmp(buf_rd
, buf
, buf_size
) != 0)
515 printf("read/write compare failed\n");
521 if (!cli_close(c2
, fnum2
)) {
522 printf("close failed (%s)\n", cli_errstr(c2
));
525 if (!cli_close(c1
, fnum1
)) {
526 printf("close failed (%s)\n", cli_errstr(c1
));
530 if (!cli_unlink(c1
, lockfname
)) {
531 printf("unlink failed (%s)\n", cli_errstr(c1
));
538 static BOOL
run_readwritetest(int dummy
)
540 static struct cli_state
*cli1
, *cli2
;
541 BOOL test1
, test2
= False
;
543 if (!torture_open_connection(&cli1
) || !torture_open_connection(&cli2
)) {
546 cli_sockopt(cli1
, sockops
);
547 cli_sockopt(cli2
, sockops
);
549 printf("starting readwritetest\n");
551 test1
= rw_torture2(cli1
, cli2
);
552 printf("Passed readwritetest v1: %s\n", BOOLSTR(test1
));
555 test2
= rw_torture2(cli1
, cli1
);
556 printf("Passed readwritetest v2: %s\n", BOOLSTR(test2
));
559 if (!torture_close_connection(cli1
)) {
563 if (!torture_close_connection(cli2
)) {
567 return (test1
&& test2
);
570 static BOOL
run_readwritemulti(int dummy
)
572 struct cli_state
*cli
;
577 cli_sockopt(cli
, sockops
);
579 printf("run_readwritemulti: fname %s\n", randomfname
);
580 test
= rw_torture3(cli
, randomfname
);
582 if (!torture_close_connection(cli
)) {
589 static BOOL
run_readwritelarge(int dummy
)
591 static struct cli_state
*cli1
;
593 const char *lockfname
= "\\large.dat";
598 if (!torture_open_connection(&cli1
)) {
601 cli_sockopt(cli1
, sockops
);
602 memset(buf
,'\0',sizeof(buf
));
604 cli1
->max_xmit
= 128*1024;
606 printf("starting readwritelarge\n");
608 cli_unlink(cli1
, lockfname
);
610 fnum1
= cli_open(cli1
, lockfname
, O_RDWR
| O_CREAT
| O_EXCL
, DENY_NONE
);
612 printf("open read/write of %s failed (%s)\n", lockfname
, cli_errstr(cli1
));
616 cli_write(cli1
, fnum1
, 0, buf
, 0, sizeof(buf
));
618 if (!cli_qfileinfo(cli1
, fnum1
, NULL
, &fsize
, NULL
, NULL
, NULL
, NULL
, NULL
)) {
619 printf("qfileinfo failed (%s)\n", cli_errstr(cli1
));
623 if (fsize
== sizeof(buf
))
624 printf("readwritelarge test 1 succeeded (size = %lx)\n",
625 (unsigned long)fsize
);
627 printf("readwritelarge test 1 failed (size = %lx)\n",
628 (unsigned long)fsize
);
632 if (!cli_close(cli1
, fnum1
)) {
633 printf("close failed (%s)\n", cli_errstr(cli1
));
637 if (!cli_unlink(cli1
, lockfname
)) {
638 printf("unlink failed (%s)\n", cli_errstr(cli1
));
642 fnum1
= cli_open(cli1
, lockfname
, O_RDWR
| O_CREAT
| O_EXCL
, DENY_NONE
);
644 printf("open read/write of %s failed (%s)\n", lockfname
, cli_errstr(cli1
));
648 cli1
->max_xmit
= 4*1024;
650 cli_smbwrite(cli1
, fnum1
, buf
, 0, sizeof(buf
));
652 if (!cli_qfileinfo(cli1
, fnum1
, NULL
, &fsize
, NULL
, NULL
, NULL
, NULL
, NULL
)) {
653 printf("qfileinfo failed (%s)\n", cli_errstr(cli1
));
657 if (fsize
== sizeof(buf
))
658 printf("readwritelarge test 2 succeeded (size = %lx)\n",
659 (unsigned long)fsize
);
661 printf("readwritelarge test 2 failed (size = %lx)\n",
662 (unsigned long)fsize
);
667 /* ToDo - set allocation. JRA */
668 if(!cli_set_allocation_size(cli1
, fnum1
, 0)) {
669 printf("set allocation size to zero failed (%s)\n", cli_errstr(&cli1
));
672 if (!cli_qfileinfo(cli1
, fnum1
, NULL
, &fsize
, NULL
, NULL
, NULL
, NULL
, NULL
)) {
673 printf("qfileinfo failed (%s)\n", cli_errstr(cli1
));
677 printf("readwritelarge test 3 (truncate test) succeeded (size = %x)\n", fsize
);
680 if (!cli_close(cli1
, fnum1
)) {
681 printf("close failed (%s)\n", cli_errstr(cli1
));
685 if (!torture_close_connection(cli1
)) {
694 #define ival(s) strtol(s, NULL, 0)
696 /* run a test that simulates an approximate netbench client load */
697 static BOOL
run_netbench(int client
)
699 struct cli_state
*cli
;
704 const char *params
[20];
711 cli_sockopt(cli
, sockops
);
715 slprintf(cname
,sizeof(cname
)-1, "client%d", client
);
717 f
= fopen(client_txt
, "r");
724 while (fgets(line
, sizeof(line
)-1, f
)) {
727 line
[strlen(line
)-1] = 0;
729 /* printf("[%d] %s\n", line_count, line); */
731 all_string_sub(line
,"client1", cname
, sizeof(line
));
733 /* parse the command parameters */
734 params
[0] = strtok(line
," ");
736 while (params
[i
]) params
[++i
] = strtok(NULL
," ");
742 if (!strncmp(params
[0],"SMB", 3)) {
743 printf("ERROR: You are using a dbench 1 load file\n");
747 if (!strcmp(params
[0],"NTCreateX")) {
748 nb_createx(params
[1], ival(params
[2]), ival(params
[3]),
750 } else if (!strcmp(params
[0],"Close")) {
751 nb_close(ival(params
[1]));
752 } else if (!strcmp(params
[0],"Rename")) {
753 nb_rename(params
[1], params
[2]);
754 } else if (!strcmp(params
[0],"Unlink")) {
755 nb_unlink(params
[1]);
756 } else if (!strcmp(params
[0],"Deltree")) {
757 nb_deltree(params
[1]);
758 } else if (!strcmp(params
[0],"Rmdir")) {
760 } else if (!strcmp(params
[0],"QUERY_PATH_INFORMATION")) {
761 nb_qpathinfo(params
[1]);
762 } else if (!strcmp(params
[0],"QUERY_FILE_INFORMATION")) {
763 nb_qfileinfo(ival(params
[1]));
764 } else if (!strcmp(params
[0],"QUERY_FS_INFORMATION")) {
765 nb_qfsinfo(ival(params
[1]));
766 } else if (!strcmp(params
[0],"FIND_FIRST")) {
767 nb_findfirst(params
[1]);
768 } else if (!strcmp(params
[0],"WriteX")) {
769 nb_writex(ival(params
[1]),
770 ival(params
[2]), ival(params
[3]), ival(params
[4]));
771 } else if (!strcmp(params
[0],"ReadX")) {
772 nb_readx(ival(params
[1]),
773 ival(params
[2]), ival(params
[3]), ival(params
[4]));
774 } else if (!strcmp(params
[0],"Flush")) {
775 nb_flush(ival(params
[1]));
777 printf("Unknown operation %s\n", params
[0]);
785 if (!torture_close_connection(cli
)) {
793 /* run a test that simulates an approximate netbench client load */
794 static BOOL
run_nbench(int dummy
)
803 signal(SIGALRM
, nb_alarm
);
805 t
= create_procs(run_netbench
, &correct
);
808 printf("\nThroughput %g MB/sec\n",
809 1.0e-6 * nbio_total() / t
);
815 This test checks for two things:
817 1) correct support for retaining locks over a close (ie. the server
818 must not use posix semantics)
819 2) support for lock timeouts
821 static BOOL
run_locktest1(int dummy
)
823 struct cli_state
*cli1
, *cli2
;
824 const char *fname
= "\\lockt1.lck";
825 int fnum1
, fnum2
, fnum3
;
827 unsigned lock_timeout
;
829 if (!torture_open_connection(&cli1
) || !torture_open_connection(&cli2
)) {
832 cli_sockopt(cli1
, sockops
);
833 cli_sockopt(cli2
, sockops
);
835 printf("starting locktest1\n");
837 cli_unlink(cli1
, fname
);
839 fnum1
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
);
841 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
844 fnum2
= cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
);
846 printf("open2 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
849 fnum3
= cli_open(cli2
, fname
, O_RDWR
, DENY_NONE
);
851 printf("open3 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
855 if (!cli_lock(cli1
, fnum1
, 0, 4, 0, WRITE_LOCK
)) {
856 printf("lock1 failed (%s)\n", cli_errstr(cli1
));
861 if (cli_lock(cli2
, fnum3
, 0, 4, 0, WRITE_LOCK
)) {
862 printf("lock2 succeeded! This is a locking bug\n");
865 if (!check_error(__LINE__
, cli2
, ERRDOS
, ERRlock
,
866 NT_STATUS_LOCK_NOT_GRANTED
)) return False
;
870 lock_timeout
= (1 + (random() % 20));
871 printf("Testing lock timeout with timeout=%u\n", lock_timeout
);
873 if (cli_lock(cli2
, fnum3
, 0, 4, lock_timeout
* 1000, WRITE_LOCK
)) {
874 printf("lock3 succeeded! This is a locking bug\n");
877 if (!check_error(__LINE__
, cli2
, ERRDOS
, ERRlock
,
878 NT_STATUS_FILE_LOCK_CONFLICT
)) return False
;
882 if (ABS(t2
- t1
) < lock_timeout
-1) {
883 printf("error: This server appears not to support timed lock requests\n");
886 printf("server slept for %u seconds for a %u second timeout\n",
887 (unsigned int)(t2
-t1
), lock_timeout
);
889 if (!cli_close(cli1
, fnum2
)) {
890 printf("close1 failed (%s)\n", cli_errstr(cli1
));
894 if (cli_lock(cli2
, fnum3
, 0, 4, 0, WRITE_LOCK
)) {
895 printf("lock4 succeeded! This is a locking bug\n");
898 if (!check_error(__LINE__
, cli2
, ERRDOS
, ERRlock
,
899 NT_STATUS_FILE_LOCK_CONFLICT
)) return False
;
902 if (!cli_close(cli1
, fnum1
)) {
903 printf("close2 failed (%s)\n", cli_errstr(cli1
));
907 if (!cli_close(cli2
, fnum3
)) {
908 printf("close3 failed (%s)\n", cli_errstr(cli2
));
912 if (!cli_unlink(cli1
, fname
)) {
913 printf("unlink failed (%s)\n", cli_errstr(cli1
));
918 if (!torture_close_connection(cli1
)) {
922 if (!torture_close_connection(cli2
)) {
926 printf("Passed locktest1\n");
931 this checks to see if a secondary tconx can use open files from an
934 static BOOL
run_tcon_test(int dummy
)
936 static struct cli_state
*cli
;
937 const char *fname
= "\\tcontest.tmp";
939 uint16 cnum1
, cnum2
, cnum3
;
944 if (!torture_open_connection(&cli
)) {
947 cli_sockopt(cli
, sockops
);
949 printf("starting tcontest\n");
951 cli_unlink(cli
, fname
);
953 fnum1
= cli_open(cli
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
);
955 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli
));
962 if (cli_write(cli
, fnum1
, 0, buf
, 130, 4) != 4) {
963 printf("initial write failed (%s)", cli_errstr(cli
));
967 if (!cli_send_tconX(cli
, share
, "?????",
968 password
, strlen(password
)+1)) {
969 printf("%s refused 2nd tree connect (%s)\n", host
,
976 cnum3
= MAX(cnum1
, cnum2
) + 1; /* any invalid number */
977 vuid2
= cli
->vuid
+ 1;
979 /* try a write with the wrong tid */
982 if (cli_write(cli
, fnum1
, 0, buf
, 130, 4) == 4) {
983 printf("* server allows write with wrong TID\n");
986 printf("server fails write with wrong TID : %s\n", cli_errstr(cli
));
990 /* try a write with an invalid tid */
993 if (cli_write(cli
, fnum1
, 0, buf
, 130, 4) == 4) {
994 printf("* server allows write with invalid TID\n");
997 printf("server fails write with invalid TID : %s\n", cli_errstr(cli
));
1000 /* try a write with an invalid vuid */
1004 if (cli_write(cli
, fnum1
, 0, buf
, 130, 4) == 4) {
1005 printf("* server allows write with invalid VUID\n");
1008 printf("server fails write with invalid VUID : %s\n", cli_errstr(cli
));
1014 if (!cli_close(cli
, fnum1
)) {
1015 printf("close failed (%s)\n", cli_errstr(cli
));
1021 if (!cli_tdis(cli
)) {
1022 printf("secondary tdis failed (%s)\n", cli_errstr(cli
));
1028 if (!torture_close_connection(cli
)) {
1037 checks for old style tcon support
1039 static BOOL
run_tcon2_test(int dummy
)
1041 static struct cli_state
*cli
;
1042 uint16 cnum
, max_xmit
;
1046 if (!torture_open_connection(&cli
)) {
1049 cli_sockopt(cli
, sockops
);
1051 printf("starting tcon2 test\n");
1053 asprintf(&service
, "\\\\%s\\%s", host
, share
);
1055 status
= cli_raw_tcon(cli
, service
, password
, "?????", &max_xmit
, &cnum
);
1057 if (!NT_STATUS_IS_OK(status
)) {
1058 printf("tcon2 failed : %s\n", cli_errstr(cli
));
1060 printf("tcon OK : max_xmit=%d cnum=%d tid=%d\n",
1061 (int)max_xmit
, (int)cnum
, SVAL(cli
->inbuf
, smb_tid
));
1064 if (!torture_close_connection(cli
)) {
1068 printf("Passed tcon2 test\n");
1072 static BOOL
tcon_devtest(struct cli_state
*cli
,
1073 const char *myshare
, const char *devtype
,
1074 const char *return_devtype
,
1075 NTSTATUS expected_error
)
1080 status
= cli_send_tconX(cli
, myshare
, devtype
,
1081 password
, strlen(password
)+1);
1083 if (NT_STATUS_IS_OK(expected_error
)) {
1085 if (strcmp(cli
->dev
, return_devtype
) == 0) {
1088 printf("tconX to share %s with type %s "
1089 "succeeded but returned the wrong "
1090 "device type (got [%s] but should have got [%s])\n",
1091 myshare
, devtype
, cli
->dev
, return_devtype
);
1095 printf("tconX to share %s with type %s "
1096 "should have succeeded but failed\n",
1103 printf("tconx to share %s with type %s "
1104 "should have failed but succeeded\n",
1108 if (NT_STATUS_EQUAL(cli_nt_error(cli
),
1112 printf("Returned unexpected error\n");
1121 checks for correct tconX support
1123 static BOOL
run_tcon_devtype_test(int dummy
)
1125 static struct cli_state
*cli1
= NULL
;
1131 status
= cli_full_connection(&cli1
, myname
,
1132 host
, NULL
, port_to_use
,
1134 username
, workgroup
,
1135 password
, flags
, Undefined
, &retry
);
1137 if (!NT_STATUS_IS_OK(status
)) {
1138 printf("could not open connection\n");
1142 if (!tcon_devtest(cli1
, "IPC$", "A:", NULL
, NT_STATUS_BAD_DEVICE_TYPE
))
1145 if (!tcon_devtest(cli1
, "IPC$", "?????", "IPC", NT_STATUS_OK
))
1148 if (!tcon_devtest(cli1
, "IPC$", "LPT:", NULL
, NT_STATUS_BAD_DEVICE_TYPE
))
1151 if (!tcon_devtest(cli1
, "IPC$", "IPC", "IPC", NT_STATUS_OK
))
1154 if (!tcon_devtest(cli1
, "IPC$", "FOOBA", NULL
, NT_STATUS_BAD_DEVICE_TYPE
))
1157 if (!tcon_devtest(cli1
, share
, "A:", "A:", NT_STATUS_OK
))
1160 if (!tcon_devtest(cli1
, share
, "?????", "A:", NT_STATUS_OK
))
1163 if (!tcon_devtest(cli1
, share
, "LPT:", NULL
, NT_STATUS_BAD_DEVICE_TYPE
))
1166 if (!tcon_devtest(cli1
, share
, "IPC", NULL
, NT_STATUS_BAD_DEVICE_TYPE
))
1169 if (!tcon_devtest(cli1
, share
, "FOOBA", NULL
, NT_STATUS_BAD_DEVICE_TYPE
))
1175 printf("Passed tcondevtest\n");
1182 This test checks that
1184 1) the server supports multiple locking contexts on the one SMB
1185 connection, distinguished by PID.
1187 2) the server correctly fails overlapping locks made by the same PID (this
1188 goes against POSIX behaviour, which is why it is tricky to implement)
1190 3) the server denies unlock requests by an incorrect client PID
1192 static BOOL
run_locktest2(int dummy
)
1194 static struct cli_state
*cli
;
1195 const char *fname
= "\\lockt2.lck";
1196 int fnum1
, fnum2
, fnum3
;
1197 BOOL correct
= True
;
1199 if (!torture_open_connection(&cli
)) {
1203 cli_sockopt(cli
, sockops
);
1205 printf("starting locktest2\n");
1207 cli_unlink(cli
, fname
);
1211 fnum1
= cli_open(cli
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
);
1213 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli
));
1217 fnum2
= cli_open(cli
, fname
, O_RDWR
, DENY_NONE
);
1219 printf("open2 of %s failed (%s)\n", fname
, cli_errstr(cli
));
1225 fnum3
= cli_open(cli
, fname
, O_RDWR
, DENY_NONE
);
1227 printf("open3 of %s failed (%s)\n", fname
, cli_errstr(cli
));
1233 if (!cli_lock(cli
, fnum1
, 0, 4, 0, WRITE_LOCK
)) {
1234 printf("lock1 failed (%s)\n", cli_errstr(cli
));
1238 if (cli_lock(cli
, fnum1
, 0, 4, 0, WRITE_LOCK
)) {
1239 printf("WRITE lock1 succeeded! This is a locking bug\n");
1242 if (!check_error(__LINE__
, cli
, ERRDOS
, ERRlock
,
1243 NT_STATUS_LOCK_NOT_GRANTED
)) return False
;
1246 if (cli_lock(cli
, fnum2
, 0, 4, 0, WRITE_LOCK
)) {
1247 printf("WRITE lock2 succeeded! This is a locking bug\n");
1250 if (!check_error(__LINE__
, cli
, ERRDOS
, ERRlock
,
1251 NT_STATUS_LOCK_NOT_GRANTED
)) return False
;
1254 if (cli_lock(cli
, fnum2
, 0, 4, 0, READ_LOCK
)) {
1255 printf("READ lock2 succeeded! This is a locking bug\n");
1258 if (!check_error(__LINE__
, cli
, ERRDOS
, ERRlock
,
1259 NT_STATUS_FILE_LOCK_CONFLICT
)) return False
;
1262 if (!cli_lock(cli
, fnum1
, 100, 4, 0, WRITE_LOCK
)) {
1263 printf("lock at 100 failed (%s)\n", cli_errstr(cli
));
1266 if (cli_unlock(cli
, fnum1
, 100, 4)) {
1267 printf("unlock at 100 succeeded! This is a locking bug\n");
1271 if (cli_unlock(cli
, fnum1
, 0, 4)) {
1272 printf("unlock1 succeeded! This is a locking bug\n");
1275 if (!check_error(__LINE__
, cli
,
1277 NT_STATUS_RANGE_NOT_LOCKED
)) return False
;
1280 if (cli_unlock(cli
, fnum1
, 0, 8)) {
1281 printf("unlock2 succeeded! This is a locking bug\n");
1284 if (!check_error(__LINE__
, cli
,
1286 NT_STATUS_RANGE_NOT_LOCKED
)) return False
;
1289 if (cli_lock(cli
, fnum3
, 0, 4, 0, WRITE_LOCK
)) {
1290 printf("lock3 succeeded! This is a locking bug\n");
1293 if (!check_error(__LINE__
, cli
, ERRDOS
, ERRlock
, NT_STATUS_LOCK_NOT_GRANTED
)) return False
;
1298 if (!cli_close(cli
, fnum1
)) {
1299 printf("close1 failed (%s)\n", cli_errstr(cli
));
1303 if (!cli_close(cli
, fnum2
)) {
1304 printf("close2 failed (%s)\n", cli_errstr(cli
));
1308 if (!cli_close(cli
, fnum3
)) {
1309 printf("close3 failed (%s)\n", cli_errstr(cli
));
1313 if (!torture_close_connection(cli
)) {
1317 printf("locktest2 finished\n");
1324 This test checks that
1326 1) the server supports the full offset range in lock requests
1328 static BOOL
run_locktest3(int dummy
)
1330 static struct cli_state
*cli1
, *cli2
;
1331 const char *fname
= "\\lockt3.lck";
1332 int fnum1
, fnum2
, i
;
1334 BOOL correct
= True
;
1336 #define NEXT_OFFSET offset += (~(uint32)0) / torture_numops
1338 if (!torture_open_connection(&cli1
) || !torture_open_connection(&cli2
)) {
1341 cli_sockopt(cli1
, sockops
);
1342 cli_sockopt(cli2
, sockops
);
1344 printf("starting locktest3\n");
1346 cli_unlink(cli1
, fname
);
1348 fnum1
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
);
1350 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
1353 fnum2
= cli_open(cli2
, fname
, O_RDWR
, DENY_NONE
);
1355 printf("open2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
1359 for (offset
=i
=0;i
<torture_numops
;i
++) {
1361 if (!cli_lock(cli1
, fnum1
, offset
-1, 1, 0, WRITE_LOCK
)) {
1362 printf("lock1 %d failed (%s)\n",
1368 if (!cli_lock(cli2
, fnum2
, offset
-2, 1, 0, WRITE_LOCK
)) {
1369 printf("lock2 %d failed (%s)\n",
1376 for (offset
=i
=0;i
<torture_numops
;i
++) {
1379 if (cli_lock(cli1
, fnum1
, offset
-2, 1, 0, WRITE_LOCK
)) {
1380 printf("error: lock1 %d succeeded!\n", i
);
1384 if (cli_lock(cli2
, fnum2
, offset
-1, 1, 0, WRITE_LOCK
)) {
1385 printf("error: lock2 %d succeeded!\n", i
);
1389 if (cli_lock(cli1
, fnum1
, offset
-1, 1, 0, WRITE_LOCK
)) {
1390 printf("error: lock3 %d succeeded!\n", i
);
1394 if (cli_lock(cli2
, fnum2
, offset
-2, 1, 0, WRITE_LOCK
)) {
1395 printf("error: lock4 %d succeeded!\n", i
);
1400 for (offset
=i
=0;i
<torture_numops
;i
++) {
1403 if (!cli_unlock(cli1
, fnum1
, offset
-1, 1)) {
1404 printf("unlock1 %d failed (%s)\n",
1410 if (!cli_unlock(cli2
, fnum2
, offset
-2, 1)) {
1411 printf("unlock2 %d failed (%s)\n",
1418 if (!cli_close(cli1
, fnum1
)) {
1419 printf("close1 failed (%s)\n", cli_errstr(cli1
));
1423 if (!cli_close(cli2
, fnum2
)) {
1424 printf("close2 failed (%s)\n", cli_errstr(cli2
));
1428 if (!cli_unlink(cli1
, fname
)) {
1429 printf("unlink failed (%s)\n", cli_errstr(cli1
));
1433 if (!torture_close_connection(cli1
)) {
1437 if (!torture_close_connection(cli2
)) {
1441 printf("finished locktest3\n");
1446 #define EXPECTED(ret, v) if ((ret) != (v)) { \
1447 printf("** "); correct = False; \
1451 looks at overlapping locks
1453 static BOOL
run_locktest4(int dummy
)
1455 static struct cli_state
*cli1
, *cli2
;
1456 const char *fname
= "\\lockt4.lck";
1457 int fnum1
, fnum2
, f
;
1460 BOOL correct
= True
;
1462 if (!torture_open_connection(&cli1
) || !torture_open_connection(&cli2
)) {
1466 cli_sockopt(cli1
, sockops
);
1467 cli_sockopt(cli2
, sockops
);
1469 printf("starting locktest4\n");
1471 cli_unlink(cli1
, fname
);
1473 fnum1
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
);
1474 fnum2
= cli_open(cli2
, fname
, O_RDWR
, DENY_NONE
);
1476 memset(buf
, 0, sizeof(buf
));
1478 if (cli_write(cli1
, fnum1
, 0, buf
, 0, sizeof(buf
)) != sizeof(buf
)) {
1479 printf("Failed to create file\n");
1484 ret
= cli_lock(cli1
, fnum1
, 0, 4, 0, WRITE_LOCK
) &&
1485 cli_lock(cli1
, fnum1
, 2, 4, 0, WRITE_LOCK
);
1486 EXPECTED(ret
, False
);
1487 printf("the same process %s set overlapping write locks\n", ret
?"can":"cannot");
1489 ret
= cli_lock(cli1
, fnum1
, 10, 4, 0, READ_LOCK
) &&
1490 cli_lock(cli1
, fnum1
, 12, 4, 0, READ_LOCK
);
1491 EXPECTED(ret
, True
);
1492 printf("the same process %s set overlapping read locks\n", ret
?"can":"cannot");
1494 ret
= cli_lock(cli1
, fnum1
, 20, 4, 0, WRITE_LOCK
) &&
1495 cli_lock(cli2
, fnum2
, 22, 4, 0, WRITE_LOCK
);
1496 EXPECTED(ret
, False
);
1497 printf("a different connection %s set overlapping write locks\n", ret
?"can":"cannot");
1499 ret
= cli_lock(cli1
, fnum1
, 30, 4, 0, READ_LOCK
) &&
1500 cli_lock(cli2
, fnum2
, 32, 4, 0, READ_LOCK
);
1501 EXPECTED(ret
, True
);
1502 printf("a different connection %s set overlapping read locks\n", ret
?"can":"cannot");
1504 ret
= (cli_setpid(cli1
, 1), cli_lock(cli1
, fnum1
, 40, 4, 0, WRITE_LOCK
)) &&
1505 (cli_setpid(cli1
, 2), cli_lock(cli1
, fnum1
, 42, 4, 0, WRITE_LOCK
));
1506 EXPECTED(ret
, False
);
1507 printf("a different pid %s set overlapping write locks\n", ret
?"can":"cannot");
1509 ret
= (cli_setpid(cli1
, 1), cli_lock(cli1
, fnum1
, 50, 4, 0, READ_LOCK
)) &&
1510 (cli_setpid(cli1
, 2), cli_lock(cli1
, fnum1
, 52, 4, 0, READ_LOCK
));
1511 EXPECTED(ret
, True
);
1512 printf("a different pid %s set overlapping read locks\n", ret
?"can":"cannot");
1514 ret
= cli_lock(cli1
, fnum1
, 60, 4, 0, READ_LOCK
) &&
1515 cli_lock(cli1
, fnum1
, 60, 4, 0, READ_LOCK
);
1516 EXPECTED(ret
, True
);
1517 printf("the same process %s set the same read lock twice\n", ret
?"can":"cannot");
1519 ret
= cli_lock(cli1
, fnum1
, 70, 4, 0, WRITE_LOCK
) &&
1520 cli_lock(cli1
, fnum1
, 70, 4, 0, WRITE_LOCK
);
1521 EXPECTED(ret
, False
);
1522 printf("the same process %s set the same write lock twice\n", ret
?"can":"cannot");
1524 ret
= cli_lock(cli1
, fnum1
, 80, 4, 0, READ_LOCK
) &&
1525 cli_lock(cli1
, fnum1
, 80, 4, 0, WRITE_LOCK
);
1526 EXPECTED(ret
, False
);
1527 printf("the same process %s overlay a read lock with a write lock\n", ret
?"can":"cannot");
1529 ret
= cli_lock(cli1
, fnum1
, 90, 4, 0, WRITE_LOCK
) &&
1530 cli_lock(cli1
, fnum1
, 90, 4, 0, READ_LOCK
);
1531 EXPECTED(ret
, True
);
1532 printf("the same process %s overlay a write lock with a read lock\n", ret
?"can":"cannot");
1534 ret
= (cli_setpid(cli1
, 1), cli_lock(cli1
, fnum1
, 100, 4, 0, WRITE_LOCK
)) &&
1535 (cli_setpid(cli1
, 2), cli_lock(cli1
, fnum1
, 100, 4, 0, READ_LOCK
));
1536 EXPECTED(ret
, False
);
1537 printf("a different pid %s overlay a write lock with a read lock\n", ret
?"can":"cannot");
1539 ret
= cli_lock(cli1
, fnum1
, 110, 4, 0, READ_LOCK
) &&
1540 cli_lock(cli1
, fnum1
, 112, 4, 0, READ_LOCK
) &&
1541 cli_unlock(cli1
, fnum1
, 110, 6);
1542 EXPECTED(ret
, False
);
1543 printf("the same process %s coalesce read locks\n", ret
?"can":"cannot");
1546 ret
= cli_lock(cli1
, fnum1
, 120, 4, 0, WRITE_LOCK
) &&
1547 (cli_read(cli2
, fnum2
, buf
, 120, 4) == 4);
1548 EXPECTED(ret
, False
);
1549 printf("this server %s strict write locking\n", ret
?"doesn't do":"does");
1551 ret
= cli_lock(cli1
, fnum1
, 130, 4, 0, READ_LOCK
) &&
1552 (cli_write(cli2
, fnum2
, 0, buf
, 130, 4) == 4);
1553 EXPECTED(ret
, False
);
1554 printf("this server %s strict read locking\n", ret
?"doesn't do":"does");
1557 ret
= cli_lock(cli1
, fnum1
, 140, 4, 0, READ_LOCK
) &&
1558 cli_lock(cli1
, fnum1
, 140, 4, 0, READ_LOCK
) &&
1559 cli_unlock(cli1
, fnum1
, 140, 4) &&
1560 cli_unlock(cli1
, fnum1
, 140, 4);
1561 EXPECTED(ret
, True
);
1562 printf("this server %s do recursive read locking\n", ret
?"does":"doesn't");
1565 ret
= cli_lock(cli1
, fnum1
, 150, 4, 0, WRITE_LOCK
) &&
1566 cli_lock(cli1
, fnum1
, 150, 4, 0, READ_LOCK
) &&
1567 cli_unlock(cli1
, fnum1
, 150, 4) &&
1568 (cli_read(cli2
, fnum2
, buf
, 150, 4) == 4) &&
1569 !(cli_write(cli2
, fnum2
, 0, buf
, 150, 4) == 4) &&
1570 cli_unlock(cli1
, fnum1
, 150, 4);
1571 EXPECTED(ret
, True
);
1572 printf("this server %s do recursive lock overlays\n", ret
?"does":"doesn't");
1574 ret
= cli_lock(cli1
, fnum1
, 160, 4, 0, READ_LOCK
) &&
1575 cli_unlock(cli1
, fnum1
, 160, 4) &&
1576 (cli_write(cli2
, fnum2
, 0, buf
, 160, 4) == 4) &&
1577 (cli_read(cli2
, fnum2
, buf
, 160, 4) == 4);
1578 EXPECTED(ret
, True
);
1579 printf("the same process %s remove a read lock using write locking\n", ret
?"can":"cannot");
1581 ret
= cli_lock(cli1
, fnum1
, 170, 4, 0, WRITE_LOCK
) &&
1582 cli_unlock(cli1
, fnum1
, 170, 4) &&
1583 (cli_write(cli2
, fnum2
, 0, buf
, 170, 4) == 4) &&
1584 (cli_read(cli2
, fnum2
, buf
, 170, 4) == 4);
1585 EXPECTED(ret
, True
);
1586 printf("the same process %s remove a write lock using read locking\n", ret
?"can":"cannot");
1588 ret
= cli_lock(cli1
, fnum1
, 190, 4, 0, WRITE_LOCK
) &&
1589 cli_lock(cli1
, fnum1
, 190, 4, 0, READ_LOCK
) &&
1590 cli_unlock(cli1
, fnum1
, 190, 4) &&
1591 !(cli_write(cli2
, fnum2
, 0, buf
, 190, 4) == 4) &&
1592 (cli_read(cli2
, fnum2
, buf
, 190, 4) == 4);
1593 EXPECTED(ret
, True
);
1594 printf("the same process %s remove the first lock first\n", ret
?"does":"doesn't");
1596 cli_close(cli1
, fnum1
);
1597 cli_close(cli2
, fnum2
);
1598 fnum1
= cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
);
1599 f
= cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
);
1600 ret
= cli_lock(cli1
, fnum1
, 0, 8, 0, READ_LOCK
) &&
1601 cli_lock(cli1
, f
, 0, 1, 0, READ_LOCK
) &&
1602 cli_close(cli1
, fnum1
) &&
1603 ((fnum1
= cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
)) != -1) &&
1604 cli_lock(cli1
, fnum1
, 7, 1, 0, WRITE_LOCK
);
1606 cli_close(cli1
, fnum1
);
1607 EXPECTED(ret
, True
);
1608 printf("the server %s have the NT byte range lock bug\n", !ret
?"does":"doesn't");
1611 cli_close(cli1
, fnum1
);
1612 cli_close(cli2
, fnum2
);
1613 cli_unlink(cli1
, fname
);
1614 torture_close_connection(cli1
);
1615 torture_close_connection(cli2
);
1617 printf("finished locktest4\n");
1622 looks at lock upgrade/downgrade.
1624 static BOOL
run_locktest5(int dummy
)
1626 static struct cli_state
*cli1
, *cli2
;
1627 const char *fname
= "\\lockt5.lck";
1628 int fnum1
, fnum2
, fnum3
;
1631 BOOL correct
= True
;
1633 if (!torture_open_connection(&cli1
) || !torture_open_connection(&cli2
)) {
1637 cli_sockopt(cli1
, sockops
);
1638 cli_sockopt(cli2
, sockops
);
1640 printf("starting locktest5\n");
1642 cli_unlink(cli1
, fname
);
1644 fnum1
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
);
1645 fnum2
= cli_open(cli2
, fname
, O_RDWR
, DENY_NONE
);
1646 fnum3
= cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
);
1648 memset(buf
, 0, sizeof(buf
));
1650 if (cli_write(cli1
, fnum1
, 0, buf
, 0, sizeof(buf
)) != sizeof(buf
)) {
1651 printf("Failed to create file\n");
1656 /* Check for NT bug... */
1657 ret
= cli_lock(cli1
, fnum1
, 0, 8, 0, READ_LOCK
) &&
1658 cli_lock(cli1
, fnum3
, 0, 1, 0, READ_LOCK
);
1659 cli_close(cli1
, fnum1
);
1660 fnum1
= cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
);
1661 ret
= cli_lock(cli1
, fnum1
, 7, 1, 0, WRITE_LOCK
);
1662 EXPECTED(ret
, True
);
1663 printf("this server %s the NT locking bug\n", ret
? "doesn't have" : "has");
1664 cli_close(cli1
, fnum1
);
1665 fnum1
= cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
);
1666 cli_unlock(cli1
, fnum3
, 0, 1);
1668 ret
= cli_lock(cli1
, fnum1
, 0, 4, 0, WRITE_LOCK
) &&
1669 cli_lock(cli1
, fnum1
, 1, 1, 0, READ_LOCK
);
1670 EXPECTED(ret
, True
);
1671 printf("the same process %s overlay a write with a read lock\n", ret
?"can":"cannot");
1673 ret
= cli_lock(cli2
, fnum2
, 0, 4, 0, READ_LOCK
);
1674 EXPECTED(ret
, False
);
1676 printf("a different processs %s get a read lock on the first process lock stack\n", ret
?"can":"cannot");
1678 /* Unlock the process 2 lock. */
1679 cli_unlock(cli2
, fnum2
, 0, 4);
1681 ret
= cli_lock(cli1
, fnum3
, 0, 4, 0, READ_LOCK
);
1682 EXPECTED(ret
, False
);
1684 printf("the same processs on a different fnum %s get a read lock\n", ret
?"can":"cannot");
1686 /* Unlock the process 1 fnum3 lock. */
1687 cli_unlock(cli1
, fnum3
, 0, 4);
1689 /* Stack 2 more locks here. */
1690 ret
= cli_lock(cli1
, fnum1
, 0, 4, 0, READ_LOCK
) &&
1691 cli_lock(cli1
, fnum1
, 0, 4, 0, READ_LOCK
);
1693 EXPECTED(ret
, True
);
1694 printf("the same process %s stack read locks\n", ret
?"can":"cannot");
1696 /* Unlock the first process lock, then check this was the WRITE lock that was
1699 ret
= cli_unlock(cli1
, fnum1
, 0, 4) &&
1700 cli_lock(cli2
, fnum2
, 0, 4, 0, READ_LOCK
);
1702 EXPECTED(ret
, True
);
1703 printf("the first unlock removes the %s lock\n", ret
?"WRITE":"READ");
1705 /* Unlock the process 2 lock. */
1706 cli_unlock(cli2
, fnum2
, 0, 4);
1708 /* We should have 3 stacked locks here. Ensure we need to do 3 unlocks. */
1710 ret
= cli_unlock(cli1
, fnum1
, 1, 1) &&
1711 cli_unlock(cli1
, fnum1
, 0, 4) &&
1712 cli_unlock(cli1
, fnum1
, 0, 4);
1714 EXPECTED(ret
, True
);
1715 printf("the same process %s unlock the stack of 4 locks\n", ret
?"can":"cannot");
1717 /* Ensure the next unlock fails. */
1718 ret
= cli_unlock(cli1
, fnum1
, 0, 4);
1719 EXPECTED(ret
, False
);
1720 printf("the same process %s count the lock stack\n", !ret
?"can":"cannot");
1722 /* Ensure connection 2 can get a write lock. */
1723 ret
= cli_lock(cli2
, fnum2
, 0, 4, 0, WRITE_LOCK
);
1724 EXPECTED(ret
, True
);
1726 printf("a different processs %s get a write lock on the unlocked stack\n", ret
?"can":"cannot");
1730 cli_close(cli1
, fnum1
);
1731 cli_close(cli2
, fnum2
);
1732 cli_unlink(cli1
, fname
);
1733 if (!torture_close_connection(cli1
)) {
1736 if (!torture_close_connection(cli2
)) {
1740 printf("finished locktest5\n");
1746 tries the unusual lockingX locktype bits
1748 static BOOL
run_locktest6(int dummy
)
1750 static struct cli_state
*cli
;
1751 const char *fname
[1] = { "\\lock6.txt" };
1756 if (!torture_open_connection(&cli
)) {
1760 cli_sockopt(cli
, sockops
);
1762 printf("starting locktest6\n");
1765 printf("Testing %s\n", fname
[i
]);
1767 cli_unlink(cli
, fname
[i
]);
1769 fnum
= cli_open(cli
, fname
[i
], O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
);
1770 status
= cli_locktype(cli
, fnum
, 0, 8, 0, LOCKING_ANDX_CHANGE_LOCKTYPE
);
1771 cli_close(cli
, fnum
);
1772 printf("CHANGE_LOCKTYPE gave %s\n", nt_errstr(status
));
1774 fnum
= cli_open(cli
, fname
[i
], O_RDWR
, DENY_NONE
);
1775 status
= cli_locktype(cli
, fnum
, 0, 8, 0, LOCKING_ANDX_CANCEL_LOCK
);
1776 cli_close(cli
, fnum
);
1777 printf("CANCEL_LOCK gave %s\n", nt_errstr(status
));
1779 cli_unlink(cli
, fname
[i
]);
1782 torture_close_connection(cli
);
1784 printf("finished locktest6\n");
1788 static BOOL
run_locktest7(int dummy
)
1790 struct cli_state
*cli1
;
1791 const char *fname
= "\\lockt7.lck";
1794 BOOL correct
= False
;
1796 if (!torture_open_connection(&cli1
)) {
1800 cli_sockopt(cli1
, sockops
);
1802 printf("starting locktest7\n");
1804 cli_unlink(cli1
, fname
);
1806 fnum1
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
);
1808 memset(buf
, 0, sizeof(buf
));
1810 if (cli_write(cli1
, fnum1
, 0, buf
, 0, sizeof(buf
)) != sizeof(buf
)) {
1811 printf("Failed to create file\n");
1815 cli_setpid(cli1
, 1);
1817 if (!cli_lock(cli1
, fnum1
, 130, 4, 0, READ_LOCK
)) {
1818 printf("Unable to apply read lock on range 130:4, error was %s\n", cli_errstr(cli1
));
1821 printf("pid1 successfully locked range 130:4 for READ\n");
1824 if (cli_read(cli1
, fnum1
, buf
, 130, 4) != 4) {
1825 printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(cli1
));
1828 printf("pid1 successfully read the range 130:4\n");
1831 if (cli_write(cli1
, fnum1
, 0, buf
, 130, 4) != 4) {
1832 printf("pid1 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1
));
1833 if (NT_STATUS_V(cli_nt_error(cli1
)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT
)) {
1834 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
1838 printf("pid1 successfully wrote to the range 130:4 (should be denied)\n");
1842 cli_setpid(cli1
, 2);
1844 if (cli_read(cli1
, fnum1
, buf
, 130, 4) != 4) {
1845 printf("pid2 unable to read the range 130:4, error was %s\n", cli_errstr(cli1
));
1847 printf("pid2 successfully read the range 130:4\n");
1850 if (cli_write(cli1
, fnum1
, 0, buf
, 130, 4) != 4) {
1851 printf("pid2 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1
));
1852 if (NT_STATUS_V(cli_nt_error(cli1
)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT
)) {
1853 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
1857 printf("pid2 successfully wrote to the range 130:4 (should be denied)\n");
1861 cli_setpid(cli1
, 1);
1862 cli_unlock(cli1
, fnum1
, 130, 4);
1864 if (!cli_lock(cli1
, fnum1
, 130, 4, 0, WRITE_LOCK
)) {
1865 printf("Unable to apply write lock on range 130:4, error was %s\n", cli_errstr(cli1
));
1868 printf("pid1 successfully locked range 130:4 for WRITE\n");
1871 if (cli_read(cli1
, fnum1
, buf
, 130, 4) != 4) {
1872 printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(cli1
));
1875 printf("pid1 successfully read the range 130:4\n");
1878 if (cli_write(cli1
, fnum1
, 0, buf
, 130, 4) != 4) {
1879 printf("pid1 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1
));
1882 printf("pid1 successfully wrote to the range 130:4\n");
1885 cli_setpid(cli1
, 2);
1887 if (cli_read(cli1
, fnum1
, buf
, 130, 4) != 4) {
1888 printf("pid2 unable to read the range 130:4, error was %s\n", cli_errstr(cli1
));
1889 if (NT_STATUS_V(cli_nt_error(cli1
)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT
)) {
1890 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
1894 printf("pid2 successfully read the range 130:4 (should be denied)\n");
1898 if (cli_write(cli1
, fnum1
, 0, buf
, 130, 4) != 4) {
1899 printf("pid2 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1
));
1900 if (NT_STATUS_V(cli_nt_error(cli1
)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT
)) {
1901 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
1905 printf("pid2 successfully wrote to the range 130:4 (should be denied)\n");
1909 cli_unlock(cli1
, fnum1
, 130, 0);
1913 cli_close(cli1
, fnum1
);
1914 cli_unlink(cli1
, fname
);
1915 torture_close_connection(cli1
);
1917 printf("finished locktest7\n");
1922 test whether fnums and tids open on one VC are available on another (a major
1925 static BOOL
run_fdpasstest(int dummy
)
1927 struct cli_state
*cli1
, *cli2
;
1928 const char *fname
= "\\fdpass.tst";
1932 if (!torture_open_connection(&cli1
) || !torture_open_connection(&cli2
)) {
1935 cli_sockopt(cli1
, sockops
);
1936 cli_sockopt(cli2
, sockops
);
1938 printf("starting fdpasstest\n");
1940 cli_unlink(cli1
, fname
);
1942 fnum1
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
);
1944 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
1948 if (cli_write(cli1
, fnum1
, 0, "hello world\n", 0, 13) != 13) {
1949 printf("write failed (%s)\n", cli_errstr(cli1
));
1953 cli2
->vuid
= cli1
->vuid
;
1954 cli2
->cnum
= cli1
->cnum
;
1955 cli2
->pid
= cli1
->pid
;
1957 if (cli_read(cli2
, fnum1
, buf
, 0, 13) == 13) {
1958 printf("read succeeded! nasty security hole [%s]\n",
1963 cli_close(cli1
, fnum1
);
1964 cli_unlink(cli1
, fname
);
1966 torture_close_connection(cli1
);
1967 torture_close_connection(cli2
);
1969 printf("finished fdpasstest\n");
1973 static BOOL
run_fdsesstest(int dummy
)
1975 struct cli_state
*cli
;
1980 const char *fname
= "\\fdsess.tst";
1981 const char *fname1
= "\\fdsess1.tst";
1987 if (!torture_open_connection(&cli
))
1989 cli_sockopt(cli
, sockops
);
1991 if (!torture_cli_session_setup2(cli
, &new_vuid
))
1994 saved_cnum
= cli
->cnum
;
1995 if (!cli_send_tconX(cli
, share
, "?????", "", 1))
1997 new_cnum
= cli
->cnum
;
1998 cli
->cnum
= saved_cnum
;
2000 printf("starting fdsesstest\n");
2002 cli_unlink(cli
, fname
);
2003 cli_unlink(cli
, fname1
);
2005 fnum1
= cli_open(cli
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
);
2007 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli
));
2011 if (cli_write(cli
, fnum1
, 0, "hello world\n", 0, 13) != 13) {
2012 printf("write failed (%s)\n", cli_errstr(cli
));
2016 saved_vuid
= cli
->vuid
;
2017 cli
->vuid
= new_vuid
;
2019 if (cli_read(cli
, fnum1
, buf
, 0, 13) == 13) {
2020 printf("read succeeded with different vuid! nasty security hole [%s]\n",
2024 /* Try to open a file with different vuid, samba cnum. */
2025 fnum2
= cli_open(cli
, fname1
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
);
2027 printf("create with different vuid, same cnum succeeded.\n");
2028 cli_close(cli
, fnum2
);
2029 cli_unlink(cli
, fname1
);
2031 printf("create with different vuid, same cnum failed.\n");
2032 printf("This will cause problems with service clients.\n");
2036 cli
->vuid
= saved_vuid
;
2038 /* Try with same vuid, different cnum. */
2039 cli
->cnum
= new_cnum
;
2041 if (cli_read(cli
, fnum1
, buf
, 0, 13) == 13) {
2042 printf("read succeeded with different cnum![%s]\n",
2047 cli
->cnum
= saved_cnum
;
2048 cli_close(cli
, fnum1
);
2049 cli_unlink(cli
, fname
);
2051 torture_close_connection(cli
);
2053 printf("finished fdsesstest\n");
2058 This test checks that
2060 1) the server does not allow an unlink on a file that is open
2062 static BOOL
run_unlinktest(int dummy
)
2064 struct cli_state
*cli
;
2065 const char *fname
= "\\unlink.tst";
2067 BOOL correct
= True
;
2069 if (!torture_open_connection(&cli
)) {
2073 cli_sockopt(cli
, sockops
);
2075 printf("starting unlink test\n");
2077 cli_unlink(cli
, fname
);
2081 fnum
= cli_open(cli
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
);
2083 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli
));
2087 if (cli_unlink(cli
, fname
)) {
2088 printf("error: server allowed unlink on an open file\n");
2091 correct
= check_error(__LINE__
, cli
, ERRDOS
, ERRbadshare
,
2092 NT_STATUS_SHARING_VIOLATION
);
2095 cli_close(cli
, fnum
);
2096 cli_unlink(cli
, fname
);
2098 if (!torture_close_connection(cli
)) {
2102 printf("unlink test finished\n");
2109 test how many open files this server supports on the one socket
2111 static BOOL
run_maxfidtest(int dummy
)
2113 struct cli_state
*cli
;
2114 const char *ftemplate
= "\\maxfid.%d.%d";
2116 int fnums
[0x11000], i
;
2118 BOOL correct
= True
;
2123 printf("failed to connect\n");
2127 cli_sockopt(cli
, sockops
);
2129 for (i
=0; i
<0x11000; i
++) {
2130 slprintf(fname
,sizeof(fname
)-1,ftemplate
, i
,(int)getpid());
2131 if ((fnums
[i
] = cli_open(cli
, fname
,
2132 O_RDWR
|O_CREAT
|O_TRUNC
, DENY_NONE
)) ==
2134 printf("open of %s failed (%s)\n",
2135 fname
, cli_errstr(cli
));
2136 printf("maximum fnum is %d\n", i
);
2144 printf("cleaning up\n");
2146 slprintf(fname
,sizeof(fname
)-1,ftemplate
, i
,(int)getpid());
2147 cli_close(cli
, fnums
[i
]);
2148 if (!cli_unlink(cli
, fname
)) {
2149 printf("unlink of %s failed (%s)\n",
2150 fname
, cli_errstr(cli
));
2157 printf("maxfid test finished\n");
2158 if (!torture_close_connection(cli
)) {
2164 /* generate a random buffer */
2165 static void rand_buf(char *buf
, int len
)
2168 *buf
= (char)sys_random();
2173 /* send smb negprot commands, not reading the response */
2174 static BOOL
run_negprot_nowait(int dummy
)
2177 static struct cli_state cli
;
2178 BOOL correct
= True
;
2180 printf("starting negprot nowait test\n");
2182 if (!open_nbt_connection(&cli
)) {
2186 for (i
=0;i
<50000;i
++) {
2187 cli_negprot_send(&cli
);
2190 if (!torture_close_connection(&cli
)) {
2194 printf("finished negprot nowait test\n");
2200 /* send random IPC commands */
2201 static BOOL
run_randomipc(int dummy
)
2203 char *rparam
= NULL
;
2207 int api
, param_len
, i
;
2208 struct cli_state
*cli
;
2209 BOOL correct
= True
;
2212 printf("starting random ipc test\n");
2214 if (!torture_open_connection(&cli
)) {
2218 for (i
=0;i
<count
;i
++) {
2219 api
= sys_random() % 500;
2220 param_len
= (sys_random() % 64);
2222 rand_buf(param
, param_len
);
2227 param
, param_len
, 8,
2228 NULL
, 0, BUFFER_SIZE
,
2232 printf("%d/%d\r", i
,count
);
2235 printf("%d/%d\n", i
, count
);
2237 if (!torture_close_connection(cli
)) {
2241 printf("finished random ipc test\n");
2248 static void browse_callback(const char *sname
, uint32 stype
,
2249 const char *comment
, void *state
)
2251 printf("\t%20.20s %08x %s\n", sname
, stype
, comment
);
2257 This test checks the browse list code
2260 static BOOL
run_browsetest(int dummy
)
2262 static struct cli_state
*cli
;
2263 BOOL correct
= True
;
2265 printf("starting browse test\n");
2267 if (!torture_open_connection(&cli
)) {
2271 printf("domain list:\n");
2272 cli_NetServerEnum(cli
, cli
->server_domain
,
2273 SV_TYPE_DOMAIN_ENUM
,
2274 browse_callback
, NULL
);
2276 printf("machine list:\n");
2277 cli_NetServerEnum(cli
, cli
->server_domain
,
2279 browse_callback
, NULL
);
2281 if (!torture_close_connection(cli
)) {
2285 printf("browse test finished\n");
2293 This checks how the getatr calls works
2295 static BOOL
run_attrtest(int dummy
)
2297 struct cli_state
*cli
;
2300 const char *fname
= "\\attrib123456789.tst";
2301 BOOL correct
= True
;
2303 printf("starting attrib test\n");
2305 if (!torture_open_connection(&cli
)) {
2309 cli_unlink(cli
, fname
);
2310 fnum
= cli_open(cli
, fname
,
2311 O_RDWR
| O_CREAT
| O_TRUNC
, DENY_NONE
);
2312 cli_close(cli
, fnum
);
2313 if (!cli_getatr(cli
, fname
, NULL
, NULL
, &t
)) {
2314 printf("getatr failed (%s)\n", cli_errstr(cli
));
2318 if (abs(t
- time(NULL
)) > 60*60*24*10) {
2319 printf("ERROR: SMBgetatr bug. time is %s",
2325 t2
= t
-60*60*24; /* 1 day ago */
2327 if (!cli_setatr(cli
, fname
, 0, t2
)) {
2328 printf("setatr failed (%s)\n", cli_errstr(cli
));
2332 if (!cli_getatr(cli
, fname
, NULL
, NULL
, &t
)) {
2333 printf("getatr failed (%s)\n", cli_errstr(cli
));
2338 printf("ERROR: getatr/setatr bug. times are\n%s",
2340 printf("%s", ctime(&t2
));
2344 cli_unlink(cli
, fname
);
2346 if (!torture_close_connection(cli
)) {
2350 printf("attrib test finished\n");
2357 This checks a couple of trans2 calls
2359 static BOOL
run_trans2test(int dummy
)
2361 struct cli_state
*cli
;
2364 time_t c_time
, a_time
, m_time
, w_time
, m_time2
;
2365 const char *fname
= "\\trans2.tst";
2366 const char *dname
= "\\trans2";
2367 const char *fname2
= "\\trans2\\trans2.tst";
2369 BOOL correct
= True
;
2371 printf("starting trans2 test\n");
2373 if (!torture_open_connection(&cli
)) {
2377 cli_unlink(cli
, fname
);
2378 fnum
= cli_open(cli
, fname
,
2379 O_RDWR
| O_CREAT
| O_TRUNC
, DENY_NONE
);
2380 if (!cli_qfileinfo(cli
, fnum
, NULL
, &size
, &c_time
, &a_time
, &m_time
,
2382 printf("ERROR: qfileinfo failed (%s)\n", cli_errstr(cli
));
2386 if (!cli_qfilename(cli
, fnum
, pname
)) {
2387 printf("ERROR: qfilename failed (%s)\n", cli_errstr(cli
));
2391 if (strcmp(pname
, fname
)) {
2392 printf("qfilename gave different name? [%s] [%s]\n",
2397 cli_close(cli
, fnum
);
2401 cli_unlink(cli
, fname
);
2402 fnum
= cli_open(cli
, fname
,
2403 O_RDWR
| O_CREAT
| O_TRUNC
, DENY_NONE
);
2405 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli
));
2408 cli_close(cli
, fnum
);
2410 if (!cli_qpathinfo(cli
, fname
, &c_time
, &a_time
, &m_time
, &size
, NULL
)) {
2411 printf("ERROR: qpathinfo failed (%s)\n", cli_errstr(cli
));
2414 if (c_time
!= m_time
) {
2415 printf("create time=%s", ctime(&c_time
));
2416 printf("modify time=%s", ctime(&m_time
));
2417 printf("This system appears to have sticky create times\n");
2419 if (a_time
% (60*60) == 0) {
2420 printf("access time=%s", ctime(&a_time
));
2421 printf("This system appears to set a midnight access time\n");
2425 if (abs(m_time
- time(NULL
)) > 60*60*24*7) {
2426 printf("ERROR: totally incorrect times - maybe word reversed? mtime=%s", ctime(&m_time
));
2432 cli_unlink(cli
, fname
);
2433 fnum
= cli_open(cli
, fname
,
2434 O_RDWR
| O_CREAT
| O_TRUNC
, DENY_NONE
);
2435 cli_close(cli
, fnum
);
2436 if (!cli_qpathinfo2(cli
, fname
, &c_time
, &a_time
, &m_time
,
2437 &w_time
, &size
, NULL
, NULL
)) {
2438 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli
));
2441 if (w_time
< 60*60*24*2) {
2442 printf("write time=%s", ctime(&w_time
));
2443 printf("This system appears to set a initial 0 write time\n");
2448 cli_unlink(cli
, fname
);
2451 /* check if the server updates the directory modification time
2452 when creating a new file */
2453 if (!cli_mkdir(cli
, dname
)) {
2454 printf("ERROR: mkdir failed (%s)\n", cli_errstr(cli
));
2458 if (!cli_qpathinfo2(cli
, "\\trans2\\", &c_time
, &a_time
, &m_time
,
2459 &w_time
, &size
, NULL
, NULL
)) {
2460 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli
));
2464 fnum
= cli_open(cli
, fname2
,
2465 O_RDWR
| O_CREAT
| O_TRUNC
, DENY_NONE
);
2466 cli_write(cli
, fnum
, 0, (char *)&fnum
, 0, sizeof(fnum
));
2467 cli_close(cli
, fnum
);
2468 if (!cli_qpathinfo2(cli
, "\\trans2\\", &c_time
, &a_time
, &m_time2
,
2469 &w_time
, &size
, NULL
, NULL
)) {
2470 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli
));
2473 if (m_time2
== m_time
) {
2474 printf("This system does not update directory modification times\n");
2478 cli_unlink(cli
, fname2
);
2479 cli_rmdir(cli
, dname
);
2481 if (!torture_close_connection(cli
)) {
2485 printf("trans2 test finished\n");
2491 This checks new W2K calls.
2494 static BOOL
new_trans(struct cli_state
*pcli
, int fnum
, int level
)
2498 BOOL correct
= True
;
2500 if (!cli_qfileinfo_test(pcli
, fnum
, level
, &buf
, &len
)) {
2501 printf("ERROR: qfileinfo (%d) failed (%s)\n", level
, cli_errstr(pcli
));
2504 printf("qfileinfo: level %d, len = %u\n", level
, len
);
2505 dump_data(0, buf
, len
);
2512 static BOOL
run_w2ktest(int dummy
)
2514 struct cli_state
*cli
;
2516 const char *fname
= "\\w2ktest\\w2k.tst";
2518 BOOL correct
= True
;
2520 printf("starting w2k test\n");
2522 if (!torture_open_connection(&cli
)) {
2526 fnum
= cli_open(cli
, fname
,
2527 O_RDWR
| O_CREAT
, DENY_NONE
);
2529 for (level
= 1004; level
< 1040; level
++) {
2530 new_trans(cli
, fnum
, level
);
2533 cli_close(cli
, fnum
);
2535 if (!torture_close_connection(cli
)) {
2539 printf("w2k test finished\n");
2546 this is a harness for some oplock tests
2548 static BOOL
run_oplock1(int dummy
)
2550 struct cli_state
*cli1
;
2551 const char *fname
= "\\lockt1.lck";
2553 BOOL correct
= True
;
2555 printf("starting oplock test 1\n");
2557 if (!torture_open_connection(&cli1
)) {
2561 cli_unlink(cli1
, fname
);
2563 cli_sockopt(cli1
, sockops
);
2565 cli1
->use_oplocks
= True
;
2567 fnum1
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
);
2569 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
2573 cli1
->use_oplocks
= False
;
2575 cli_unlink(cli1
, fname
);
2576 cli_unlink(cli1
, fname
);
2578 if (!cli_close(cli1
, fnum1
)) {
2579 printf("close2 failed (%s)\n", cli_errstr(cli1
));
2583 if (!cli_unlink(cli1
, fname
)) {
2584 printf("unlink failed (%s)\n", cli_errstr(cli1
));
2588 if (!torture_close_connection(cli1
)) {
2592 printf("finished oplock test 1\n");
2597 static BOOL
run_oplock2(int dummy
)
2599 struct cli_state
*cli1
, *cli2
;
2600 const char *fname
= "\\lockt2.lck";
2602 int saved_use_oplocks
= use_oplocks
;
2604 BOOL correct
= True
;
2605 volatile BOOL
*shared_correct
;
2607 shared_correct
= (volatile BOOL
*)shm_setup(sizeof(BOOL
));
2608 *shared_correct
= True
;
2610 use_level_II_oplocks
= True
;
2613 printf("starting oplock test 2\n");
2615 if (!torture_open_connection(&cli1
)) {
2616 use_level_II_oplocks
= False
;
2617 use_oplocks
= saved_use_oplocks
;
2621 cli1
->use_oplocks
= True
;
2622 cli1
->use_level_II_oplocks
= True
;
2624 if (!torture_open_connection(&cli2
)) {
2625 use_level_II_oplocks
= False
;
2626 use_oplocks
= saved_use_oplocks
;
2630 cli2
->use_oplocks
= True
;
2631 cli2
->use_level_II_oplocks
= True
;
2633 cli_unlink(cli1
, fname
);
2635 cli_sockopt(cli1
, sockops
);
2636 cli_sockopt(cli2
, sockops
);
2638 fnum1
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
);
2640 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
2644 /* Don't need the globals any more. */
2645 use_level_II_oplocks
= False
;
2646 use_oplocks
= saved_use_oplocks
;
2650 fnum2
= cli_open(cli2
, fname
, O_RDWR
, DENY_NONE
);
2652 printf("second open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
2653 *shared_correct
= False
;
2659 if (!cli_close(cli2
, fnum2
)) {
2660 printf("close2 failed (%s)\n", cli_errstr(cli1
));
2661 *shared_correct
= False
;
2669 /* Ensure cli1 processes the break. Empty file should always return 0
2672 if (cli_read(cli1
, fnum1
, buf
, 0, 4) != 0) {
2673 printf("read on fnum1 failed (%s)\n", cli_errstr(cli1
));
2677 /* Should now be at level II. */
2678 /* Test if sending a write locks causes a break to none. */
2680 if (!cli_lock(cli1
, fnum1
, 0, 4, 0, READ_LOCK
)) {
2681 printf("lock failed (%s)\n", cli_errstr(cli1
));
2685 cli_unlock(cli1
, fnum1
, 0, 4);
2689 if (!cli_lock(cli1
, fnum1
, 0, 4, 0, WRITE_LOCK
)) {
2690 printf("lock failed (%s)\n", cli_errstr(cli1
));
2694 cli_unlock(cli1
, fnum1
, 0, 4);
2698 cli_read(cli1
, fnum1
, buf
, 0, 4);
2701 if (cli_write(cli1
, fnum1
, 0, buf
, 0, 4) != 4) {
2702 printf("write on fnum1 failed (%s)\n", cli_errstr(cli1
));
2707 if (!cli_close(cli1
, fnum1
)) {
2708 printf("close1 failed (%s)\n", cli_errstr(cli1
));
2714 if (!cli_unlink(cli1
, fname
)) {
2715 printf("unlink failed (%s)\n", cli_errstr(cli1
));
2719 if (!torture_close_connection(cli1
)) {
2723 if (!*shared_correct
) {
2727 printf("finished oplock test 2\n");
2732 /* handler for oplock 3 tests */
2733 static BOOL
oplock3_handler(struct cli_state
*cli
, int fnum
, unsigned char level
)
2735 printf("got oplock break fnum=%d level=%d\n",
2737 return cli_oplock_ack(cli
, fnum
, level
);
2740 static BOOL
run_oplock3(int dummy
)
2742 struct cli_state
*cli
;
2743 const char *fname
= "\\oplockt3.dat";
2745 char buf
[4] = "abcd";
2746 BOOL correct
= True
;
2747 volatile BOOL
*shared_correct
;
2749 shared_correct
= (volatile BOOL
*)shm_setup(sizeof(BOOL
));
2750 *shared_correct
= True
;
2752 printf("starting oplock test 3\n");
2757 use_level_II_oplocks
= True
;
2758 if (!torture_open_connection(&cli
)) {
2759 *shared_correct
= False
;
2763 /* try to trigger a oplock break in parent */
2764 fnum
= cli_open(cli
, fname
, O_RDWR
, DENY_NONE
);
2765 cli_write(cli
, fnum
, 0, buf
, 0, 4);
2771 use_level_II_oplocks
= True
;
2772 if (!torture_open_connection(&cli
)) {
2775 cli_oplock_handler(cli
, oplock3_handler
);
2776 fnum
= cli_open(cli
, fname
, O_RDWR
|O_CREAT
, DENY_NONE
);
2777 cli_write(cli
, fnum
, 0, buf
, 0, 4);
2778 cli_close(cli
, fnum
);
2779 fnum
= cli_open(cli
, fname
, O_RDWR
, DENY_NONE
);
2780 cli
->timeout
= 20000;
2781 cli_receive_smb(cli
);
2782 printf("finished oplock test 3\n");
2784 return (correct
&& *shared_correct
);
2786 /* What are we looking for here? What's sucess and what's FAILURE? */
2792 Test delete on close semantics.
2794 static BOOL
run_deletetest(int dummy
)
2796 struct cli_state
*cli1
= NULL
;
2797 struct cli_state
*cli2
= NULL
;
2798 const char *fname
= "\\delete.file";
2801 BOOL correct
= True
;
2803 printf("starting delete test\n");
2805 if (!torture_open_connection(&cli1
)) {
2809 cli_sockopt(cli1
, sockops
);
2811 /* Test 1 - this should delete the file on close. */
2813 cli_setatr(cli1
, fname
, 0, 0);
2814 cli_unlink(cli1
, fname
);
2816 fnum1
= cli_nt_create_full(cli1
, fname
, 0, GENERIC_ALL_ACCESS
|DELETE_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
2817 0, FILE_OVERWRITE_IF
,
2818 FILE_DELETE_ON_CLOSE
, 0);
2821 printf("[1] open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
2828 uint32
*accinfo
= NULL
;
2830 cli_qfileinfo_test(cli1
, fnum1
, SMB_FILE_ACCESS_INFORMATION
, (char **)&accinfo
, &len
);
2832 printf("access mode = 0x%lx\n", *accinfo
);
2837 if (!cli_close(cli1
, fnum1
)) {
2838 printf("[1] close failed (%s)\n", cli_errstr(cli1
));
2843 fnum1
= cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
);
2845 printf("[1] open of %s succeeded (should fail)\n", fname
);
2850 printf("first delete on close test succeeded.\n");
2852 /* Test 2 - this should delete the file on close. */
2854 cli_setatr(cli1
, fname
, 0, 0);
2855 cli_unlink(cli1
, fname
);
2857 fnum1
= cli_nt_create_full(cli1
, fname
, 0, GENERIC_ALL_ACCESS
,
2858 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_NONE
,
2859 FILE_OVERWRITE_IF
, 0, 0);
2862 printf("[2] open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
2867 if (!cli_nt_delete_on_close(cli1
, fnum1
, True
)) {
2868 printf("[2] setting delete_on_close failed (%s)\n", cli_errstr(cli1
));
2873 if (!cli_close(cli1
, fnum1
)) {
2874 printf("[2] close failed (%s)\n", cli_errstr(cli1
));
2879 fnum1
= cli_open(cli1
, fname
, O_RDONLY
, DENY_NONE
);
2881 printf("[2] open of %s succeeded should have been deleted on close !\n", fname
);
2882 if (!cli_close(cli1
, fnum1
)) {
2883 printf("[2] close failed (%s)\n", cli_errstr(cli1
));
2887 cli_unlink(cli1
, fname
);
2889 printf("second delete on close test succeeded.\n");
2892 cli_setatr(cli1
, fname
, 0, 0);
2893 cli_unlink(cli1
, fname
);
2895 fnum1
= cli_nt_create_full(cli1
, fname
, 0, GENERIC_ALL_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
2896 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OVERWRITE_IF
, 0, 0);
2899 printf("[3] open - 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
2904 /* This should fail with a sharing violation - open for delete is only compatible
2905 with SHARE_DELETE. */
2907 fnum2
= cli_nt_create_full(cli1
, fname
, 0, GENERIC_READ_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
2908 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OPEN
, 0, 0);
2911 printf("[3] open - 2 of %s succeeded - should have failed.\n", fname
);
2916 /* This should succeed. */
2918 fnum2
= cli_nt_create_full(cli1
, fname
, 0, GENERIC_READ_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
2919 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, FILE_OPEN
, 0, 0);
2922 printf("[3] open - 2 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
2927 if (!cli_nt_delete_on_close(cli1
, fnum1
, True
)) {
2928 printf("[3] setting delete_on_close failed (%s)\n", cli_errstr(cli1
));
2933 if (!cli_close(cli1
, fnum1
)) {
2934 printf("[3] close 1 failed (%s)\n", cli_errstr(cli1
));
2939 if (!cli_close(cli1
, fnum2
)) {
2940 printf("[3] close 2 failed (%s)\n", cli_errstr(cli1
));
2945 /* This should fail - file should no longer be there. */
2947 fnum1
= cli_open(cli1
, fname
, O_RDONLY
, DENY_NONE
);
2949 printf("[3] open of %s succeeded should have been deleted on close !\n", fname
);
2950 if (!cli_close(cli1
, fnum1
)) {
2951 printf("[3] close failed (%s)\n", cli_errstr(cli1
));
2953 cli_unlink(cli1
, fname
);
2957 printf("third delete on close test succeeded.\n");
2960 cli_setatr(cli1
, fname
, 0, 0);
2961 cli_unlink(cli1
, fname
);
2963 fnum1
= cli_nt_create_full(cli1
, fname
, 0, FILE_READ_DATA
|FILE_WRITE_DATA
|DELETE_ACCESS
,
2964 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OVERWRITE_IF
, 0, 0);
2967 printf("[4] open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
2972 /* This should succeed. */
2973 fnum2
= cli_nt_create_full(cli1
, fname
, 0, GENERIC_READ_ACCESS
,
2974 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, FILE_OPEN
, 0, 0);
2976 printf("[4] open - 2 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
2981 if (!cli_close(cli1
, fnum2
)) {
2982 printf("[4] close - 1 failed (%s)\n", cli_errstr(cli1
));
2987 if (!cli_nt_delete_on_close(cli1
, fnum1
, True
)) {
2988 printf("[4] setting delete_on_close failed (%s)\n", cli_errstr(cli1
));
2993 /* This should fail - no more opens once delete on close set. */
2994 fnum2
= cli_nt_create_full(cli1
, fname
, 0, GENERIC_READ_ACCESS
,
2995 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
2998 printf("[4] open - 3 of %s succeeded ! Should have failed.\n", fname
);
3002 printf("fourth delete on close test succeeded.\n");
3004 if (!cli_close(cli1
, fnum1
)) {
3005 printf("[4] close - 2 failed (%s)\n", cli_errstr(cli1
));
3011 cli_setatr(cli1
, fname
, 0, 0);
3012 cli_unlink(cli1
, fname
);
3014 fnum1
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
, DENY_NONE
);
3016 printf("[5] open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3021 /* This should fail - only allowed on NT opens with DELETE access. */
3023 if (cli_nt_delete_on_close(cli1
, fnum1
, True
)) {
3024 printf("[5] setting delete_on_close on OpenX file succeeded - should fail !\n");
3029 if (!cli_close(cli1
, fnum1
)) {
3030 printf("[5] close - 2 failed (%s)\n", cli_errstr(cli1
));
3035 printf("fifth delete on close test succeeded.\n");
3038 cli_setatr(cli1
, fname
, 0, 0);
3039 cli_unlink(cli1
, fname
);
3041 fnum1
= cli_nt_create_full(cli1
, fname
, 0, FILE_READ_DATA
|FILE_WRITE_DATA
,
3042 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
3043 FILE_OVERWRITE_IF
, 0, 0);
3046 printf("[6] open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3051 /* This should fail - only allowed on NT opens with DELETE access. */
3053 if (cli_nt_delete_on_close(cli1
, fnum1
, True
)) {
3054 printf("[6] setting delete_on_close on file with no delete access succeeded - should fail !\n");
3059 if (!cli_close(cli1
, fnum1
)) {
3060 printf("[6] close - 2 failed (%s)\n", cli_errstr(cli1
));
3065 printf("sixth delete on close test succeeded.\n");
3068 cli_setatr(cli1
, fname
, 0, 0);
3069 cli_unlink(cli1
, fname
);
3071 fnum1
= cli_nt_create_full(cli1
, fname
, 0, FILE_READ_DATA
|FILE_WRITE_DATA
|DELETE_ACCESS
,
3072 FILE_ATTRIBUTE_NORMAL
, 0, FILE_OVERWRITE_IF
, 0, 0);
3075 printf("[7] open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3080 if (!cli_nt_delete_on_close(cli1
, fnum1
, True
)) {
3081 printf("[7] setting delete_on_close on file failed !\n");
3086 if (!cli_nt_delete_on_close(cli1
, fnum1
, False
)) {
3087 printf("[7] unsetting delete_on_close on file failed !\n");
3092 if (!cli_close(cli1
, fnum1
)) {
3093 printf("[7] close - 2 failed (%s)\n", cli_errstr(cli1
));
3098 /* This next open should succeed - we reset the flag. */
3100 fnum1
= cli_open(cli1
, fname
, O_RDONLY
, DENY_NONE
);
3102 printf("[5] open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3107 if (!cli_close(cli1
, fnum1
)) {
3108 printf("[7] close - 2 failed (%s)\n", cli_errstr(cli1
));
3113 printf("seventh delete on close test succeeded.\n");
3116 cli_setatr(cli1
, fname
, 0, 0);
3117 cli_unlink(cli1
, fname
);
3119 if (!torture_open_connection(&cli2
)) {
3120 printf("[8] failed to open second connection.\n");
3125 cli_sockopt(cli1
, sockops
);
3127 fnum1
= cli_nt_create_full(cli1
, fname
, 0, FILE_READ_DATA
|FILE_WRITE_DATA
|DELETE_ACCESS
,
3128 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
3129 FILE_OVERWRITE_IF
, 0, 0);
3132 printf("[8] open 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3137 fnum2
= cli_nt_create_full(cli2
, fname
, 0, FILE_READ_DATA
|FILE_WRITE_DATA
|DELETE_ACCESS
,
3138 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
3142 printf("[8] open 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
3147 if (!cli_nt_delete_on_close(cli1
, fnum1
, True
)) {
3148 printf("[8] setting delete_on_close on file failed !\n");
3153 if (!cli_close(cli1
, fnum1
)) {
3154 printf("[8] close - 1 failed (%s)\n", cli_errstr(cli1
));
3159 if (!cli_close(cli2
, fnum2
)) {
3160 printf("[8] close - 2 failed (%s)\n", cli_errstr(cli2
));
3165 /* This should fail.. */
3166 fnum1
= cli_open(cli1
, fname
, O_RDONLY
, DENY_NONE
);
3168 printf("[8] open of %s succeeded should have been deleted on close !\n", fname
);
3172 printf("eighth delete on close test succeeded.\n");
3174 /* This should fail - we need to set DELETE_ACCESS. */
3175 fnum1
= cli_nt_create_full(cli1
, fname
, 0,FILE_READ_DATA
|FILE_WRITE_DATA
,
3176 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, FILE_DELETE_ON_CLOSE
, 0);
3179 printf("[9] open of %s succeeded should have failed!\n", fname
);
3184 printf("ninth delete on close test succeeded.\n");
3186 fnum1
= cli_nt_create_full(cli1
, fname
, 0, FILE_READ_DATA
|FILE_WRITE_DATA
|DELETE_ACCESS
,
3187 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, FILE_DELETE_ON_CLOSE
, 0);
3189 printf("[10] open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3194 /* This should delete the file. */
3195 if (!cli_close(cli1
, fnum1
)) {
3196 printf("[10] close failed (%s)\n", cli_errstr(cli1
));
3201 /* This should fail.. */
3202 fnum1
= cli_open(cli1
, fname
, O_RDONLY
, DENY_NONE
);
3204 printf("[10] open of %s succeeded should have been deleted on close !\n", fname
);
3208 printf("tenth delete on close test succeeded.\n");
3210 cli_setatr(cli1
, fname
, 0, 0);
3211 cli_unlink(cli1
, fname
);
3213 /* What error do we get when attempting to open a read-only file with
3216 /* Create a readonly file. */
3217 fnum1
= cli_nt_create_full(cli1
, fname
, 0, FILE_READ_DATA
|FILE_WRITE_DATA
,
3218 FILE_ATTRIBUTE_READONLY
, FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0);
3220 printf("[11] open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3225 if (!cli_close(cli1
, fnum1
)) {
3226 printf("[11] close failed (%s)\n", cli_errstr(cli1
));
3231 /* Now try open for delete access. */
3232 fnum1
= cli_nt_create_full(cli1
, fname
, 0, FILE_READ_ATTRIBUTES
|DELETE_ACCESS
,
3233 0, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
3234 FILE_OVERWRITE_IF
, 0, 0);
3237 printf("[11] open of %s succeeded should have been denied with ACCESS_DENIED!\n", fname
);
3238 cli_close(cli1
, fnum1
);
3242 NTSTATUS nterr
= cli_nt_error(cli1
);
3243 if (!NT_STATUS_EQUAL(nterr
,NT_STATUS_ACCESS_DENIED
)) {
3244 printf("[11] open of %s should have been denied with ACCESS_DENIED! Got error %s\n", fname
, nt_errstr(nterr
));
3248 printf("eleventh delete on close test succeeded.\n");
3252 printf("finished delete test\n");
3255 /* FIXME: This will crash if we aborted before cli2 got
3256 * intialized, because these functions don't handle
3257 * uninitialized connections. */
3259 if (fnum1
!= -1) cli_close(cli1
, fnum1
);
3260 if (fnum2
!= -1) cli_close(cli1
, fnum2
);
3261 cli_setatr(cli1
, fname
, 0, 0);
3262 cli_unlink(cli1
, fname
);
3264 if (cli1
&& !torture_close_connection(cli1
)) {
3267 if (cli2
&& !torture_close_connection(cli2
)) {
3275 print out server properties
3277 static BOOL
run_properties(int dummy
)
3279 static struct cli_state
*cli
;
3280 BOOL correct
= True
;
3282 printf("starting properties test\n");
3286 if (!torture_open_connection(&cli
)) {
3290 cli_sockopt(cli
, sockops
);
3292 d_printf("Capabilities 0x%08x\n", cli
->capabilities
);
3294 if (!torture_close_connection(cli
)) {
3303 /* FIRST_DESIRED_ACCESS 0xf019f */
3304 #define FIRST_DESIRED_ACCESS FILE_READ_DATA|FILE_WRITE_DATA|FILE_APPEND_DATA|\
3305 FILE_READ_EA| /* 0xf */ \
3306 FILE_WRITE_EA|FILE_READ_ATTRIBUTES| /* 0x90 */ \
3307 FILE_WRITE_ATTRIBUTES| /* 0x100 */ \
3308 DELETE_ACCESS|READ_CONTROL_ACCESS|\
3309 WRITE_DAC_ACCESS|WRITE_OWNER_ACCESS /* 0xf0000 */
3310 /* SECOND_DESIRED_ACCESS 0xe0080 */
3311 #define SECOND_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
3312 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
3313 WRITE_OWNER_ACCESS /* 0xe0000 */
3316 #define THIRD_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
3317 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
3319 WRITE_OWNER_ACCESS /* */
3323 Test ntcreate calls made by xcopy
3325 static BOOL
run_xcopy(int dummy
)
3327 static struct cli_state
*cli1
;
3328 const char *fname
= "\\test.txt";
3329 BOOL correct
= True
;
3332 printf("starting xcopy test\n");
3334 if (!torture_open_connection(&cli1
)) {
3338 fnum1
= cli_nt_create_full(cli1
, fname
, 0,
3339 FIRST_DESIRED_ACCESS
, FILE_ATTRIBUTE_ARCHIVE
,
3340 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
,
3344 printf("First open failed - %s\n", cli_errstr(cli1
));
3348 fnum2
= cli_nt_create_full(cli1
, fname
, 0,
3349 SECOND_DESIRED_ACCESS
, 0,
3350 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, FILE_OPEN
,
3353 printf("second open failed - %s\n", cli_errstr(cli1
));
3357 if (!torture_close_connection(cli1
)) {
3365 Test rename on files open with share delete and no share delete.
3367 static BOOL
run_rename(int dummy
)
3369 static struct cli_state
*cli1
;
3370 const char *fname
= "\\test.txt";
3371 const char *fname1
= "\\test1.txt";
3372 BOOL correct
= True
;
3375 printf("starting rename test\n");
3377 if (!torture_open_connection(&cli1
)) {
3381 cli_unlink(cli1
, fname
);
3382 cli_unlink(cli1
, fname1
);
3383 fnum1
= cli_nt_create_full(cli1
, fname
, 0, GENERIC_READ_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
3384 FILE_SHARE_READ
, FILE_OVERWRITE_IF
, 0, 0);
3387 printf("First open failed - %s\n", cli_errstr(cli1
));
3391 if (!cli_rename(cli1
, fname
, fname1
)) {
3392 printf("First rename failed (SHARE_READ) (this is correct) - %s\n", cli_errstr(cli1
));
3394 printf("First rename succeeded (SHARE_READ) - this should have failed !\n");
3398 if (!cli_close(cli1
, fnum1
)) {
3399 printf("close - 1 failed (%s)\n", cli_errstr(cli1
));
3403 cli_unlink(cli1
, fname
);
3404 cli_unlink(cli1
, fname1
);
3405 fnum1
= cli_nt_create_full(cli1
, fname
, 0, GENERIC_READ_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
3407 FILE_SHARE_DELETE
|FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0);
3409 FILE_SHARE_DELETE
|FILE_SHARE_READ
, FILE_OVERWRITE_IF
, 0, 0);
3413 printf("Second open failed - %s\n", cli_errstr(cli1
));
3417 if (!cli_rename(cli1
, fname
, fname1
)) {
3418 printf("Second rename failed (SHARE_DELETE | SHARE_READ) - this should have succeeded - %s\n", cli_errstr(cli1
));
3421 printf("Second rename succeeded (SHARE_DELETE | SHARE_READ)\n");
3424 if (!cli_close(cli1
, fnum1
)) {
3425 printf("close - 2 failed (%s)\n", cli_errstr(cli1
));
3429 cli_unlink(cli1
, fname
);
3430 cli_unlink(cli1
, fname1
);
3432 fnum1
= cli_nt_create_full(cli1
, fname
, 0, READ_CONTROL_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
3433 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0);
3436 printf("Third open failed - %s\n", cli_errstr(cli1
));
3445 fnum2
= cli_nt_create_full(cli1
, fname
, 0, DELETE_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
3446 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0);
3449 printf("Fourth open failed - %s\n", cli_errstr(cli1
));
3452 if (!cli_nt_delete_on_close(cli1
, fnum2
, True
)) {
3453 printf("[8] setting delete_on_close on file failed !\n");
3457 if (!cli_close(cli1
, fnum2
)) {
3458 printf("close - 4 failed (%s)\n", cli_errstr(cli1
));
3464 if (!cli_rename(cli1
, fname
, fname1
)) {
3465 printf("Third rename failed (SHARE_NONE) - this should have succeeded - %s\n", cli_errstr(cli1
));
3468 printf("Third rename succeeded (SHARE_NONE)\n");
3471 if (!cli_close(cli1
, fnum1
)) {
3472 printf("close - 3 failed (%s)\n", cli_errstr(cli1
));
3476 cli_unlink(cli1
, fname
);
3477 cli_unlink(cli1
, fname1
);
3481 fnum1
= cli_nt_create_full(cli1
, fname
, 0, GENERIC_READ_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
3482 FILE_SHARE_READ
| FILE_SHARE_WRITE
, FILE_OVERWRITE_IF
, 0, 0);
3485 printf("Fourth open failed - %s\n", cli_errstr(cli1
));
3489 if (!cli_rename(cli1
, fname
, fname1
)) {
3490 printf("Fourth rename failed (SHARE_READ | SHARE_WRITE) (this is correct) - %s\n", cli_errstr(cli1
));
3492 printf("Fourth rename succeeded (SHARE_READ | SHARE_WRITE) - this should have failed !\n");
3496 if (!cli_close(cli1
, fnum1
)) {
3497 printf("close - 4 failed (%s)\n", cli_errstr(cli1
));
3501 cli_unlink(cli1
, fname
);
3502 cli_unlink(cli1
, fname1
);
3506 fnum1
= cli_nt_create_full(cli1
, fname
, 0, GENERIC_READ_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
3507 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
, FILE_OVERWRITE_IF
, 0, 0);
3510 printf("Fifth open failed - %s\n", cli_errstr(cli1
));
3514 if (!cli_rename(cli1
, fname
, fname1
)) {
3515 printf("Fifth rename failed (SHARE_READ | SHARE_WRITE | SHARE_DELETE) - this should have failed ! \n");
3518 printf("Fifth rename succeeded (SHARE_READ | SHARE_WRITE | SHARE_DELETE) (this is correct) - %s\n", cli_errstr(cli1
));
3522 * Now check if the first name still exists ...
3525 /*fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3526 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0, 0);
3529 printf("Opening original file after rename of open file fails: %s\n",
3533 printf("Opening original file after rename of open file works ...\n");
3534 (void)cli_close(cli1, fnum2);
3540 if (!cli_close(cli1
, fnum1
)) {
3541 printf("close - 5 failed (%s)\n", cli_errstr(cli1
));
3545 cli_unlink(cli1
, fname
);
3546 cli_unlink(cli1
, fname1
);
3548 if (!torture_close_connection(cli1
)) {
3555 static BOOL
run_pipe_number(int dummy
)
3557 struct cli_state
*cli1
;
3558 const char *pipe_name
= "\\SPOOLSS";
3562 printf("starting pipenumber test\n");
3563 if (!torture_open_connection(&cli1
)) {
3567 cli_sockopt(cli1
, sockops
);
3569 fnum
= cli_nt_create_full(cli1
, pipe_name
, 0, FILE_READ_DATA
, FILE_ATTRIBUTE_NORMAL
,
3570 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OPEN_IF
, 0, 0);
3573 printf("Open of pipe %s failed with error (%s)\n", pipe_name
, cli_errstr(cli1
));
3579 printf("pipe_number test - we can open %d %s pipes.\n", num_pipes
, pipe_name
);
3580 torture_close_connection(cli1
);
3585 Test open mode returns on read-only files.
3587 static BOOL
run_opentest(int dummy
)
3589 static struct cli_state
*cli1
;
3590 static struct cli_state
*cli2
;
3591 const char *fname
= "\\readonly.file";
3595 BOOL correct
= True
;
3598 printf("starting open test\n");
3600 if (!torture_open_connection(&cli1
)) {
3604 cli_setatr(cli1
, fname
, 0, 0);
3605 cli_unlink(cli1
, fname
);
3607 cli_sockopt(cli1
, sockops
);
3609 fnum1
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
);
3611 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3615 if (!cli_close(cli1
, fnum1
)) {
3616 printf("close2 failed (%s)\n", cli_errstr(cli1
));
3620 if (!cli_setatr(cli1
, fname
, aRONLY
, 0)) {
3621 printf("cli_setatr failed (%s)\n", cli_errstr(cli1
));
3625 fnum1
= cli_open(cli1
, fname
, O_RDONLY
, DENY_WRITE
);
3627 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3631 /* This will fail - but the error should be ERRnoaccess, not ERRbadshare. */
3632 fnum2
= cli_open(cli1
, fname
, O_RDWR
, DENY_ALL
);
3634 if (check_error(__LINE__
, cli1
, ERRDOS
, ERRnoaccess
,
3635 NT_STATUS_ACCESS_DENIED
)) {
3636 printf("correct error code ERRDOS/ERRnoaccess returned\n");
3639 printf("finished open test 1\n");
3641 cli_close(cli1
, fnum1
);
3643 /* Now try not readonly and ensure ERRbadshare is returned. */
3645 cli_setatr(cli1
, fname
, 0, 0);
3647 fnum1
= cli_open(cli1
, fname
, O_RDONLY
, DENY_WRITE
);
3649 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3653 /* This will fail - but the error should be ERRshare. */
3654 fnum2
= cli_open(cli1
, fname
, O_RDWR
, DENY_ALL
);
3656 if (check_error(__LINE__
, cli1
, ERRDOS
, ERRbadshare
,
3657 NT_STATUS_SHARING_VIOLATION
)) {
3658 printf("correct error code ERRDOS/ERRbadshare returned\n");
3661 if (!cli_close(cli1
, fnum1
)) {
3662 printf("close2 failed (%s)\n", cli_errstr(cli1
));
3666 cli_unlink(cli1
, fname
);
3668 printf("finished open test 2\n");
3670 /* Test truncate open disposition on file opened for read. */
3672 fnum1
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
);
3674 printf("(3) open (1) of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3678 /* write 20 bytes. */
3680 memset(buf
, '\0', 20);
3682 if (cli_write(cli1
, fnum1
, 0, buf
, 0, 20) != 20) {
3683 printf("write failed (%s)\n", cli_errstr(cli1
));
3687 if (!cli_close(cli1
, fnum1
)) {
3688 printf("(3) close1 failed (%s)\n", cli_errstr(cli1
));
3692 /* Ensure size == 20. */
3693 if (!cli_getatr(cli1
, fname
, NULL
, &fsize
, NULL
)) {
3694 printf("(3) getatr failed (%s)\n", cli_errstr(cli1
));
3699 printf("(3) file size != 20\n");
3703 /* Now test if we can truncate a file opened for readonly. */
3705 fnum1
= cli_open(cli1
, fname
, O_RDONLY
|O_TRUNC
, DENY_NONE
);
3707 printf("(3) open (2) of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3711 if (!cli_close(cli1
, fnum1
)) {
3712 printf("close2 failed (%s)\n", cli_errstr(cli1
));
3716 /* Ensure size == 0. */
3717 if (!cli_getatr(cli1
, fname
, NULL
, &fsize
, NULL
)) {
3718 printf("(3) getatr failed (%s)\n", cli_errstr(cli1
));
3723 printf("(3) file size != 0\n");
3726 printf("finished open test 3\n");
3728 cli_unlink(cli1
, fname
);
3731 printf("testing ctemp\n");
3732 fnum1
= cli_ctemp(cli1
, "\\", &tmp_path
);
3734 printf("ctemp failed (%s)\n", cli_errstr(cli1
));
3737 printf("ctemp gave path %s\n", tmp_path
);
3738 if (!cli_close(cli1
, fnum1
)) {
3739 printf("close of temp failed (%s)\n", cli_errstr(cli1
));
3741 if (!cli_unlink(cli1
, tmp_path
)) {
3742 printf("unlink of temp failed (%s)\n", cli_errstr(cli1
));
3745 /* Test the non-io opens... */
3747 if (!torture_open_connection(&cli2
)) {
3751 cli_setatr(cli2
, fname
, 0, 0);
3752 cli_unlink(cli2
, fname
);
3754 cli_sockopt(cli2
, sockops
);
3756 printf("TEST #1 testing 2 non-io opens (no delete)\n");
3758 fnum1
= cli_nt_create_full(cli1
, fname
, 0, FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
3759 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0);
3762 printf("test 1 open 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3766 fnum2
= cli_nt_create_full(cli2
, fname
, 0, FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
3767 FILE_SHARE_NONE
, FILE_OPEN_IF
, 0, 0);
3770 printf("test 1 open 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
3774 if (!cli_close(cli1
, fnum1
)) {
3775 printf("test 1 close 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3778 if (!cli_close(cli2
, fnum2
)) {
3779 printf("test 1 close 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
3783 printf("non-io open test #1 passed.\n");
3785 cli_unlink(cli1
, fname
);
3787 printf("TEST #2 testing 2 non-io opens (first with delete)\n");
3789 fnum1
= cli_nt_create_full(cli1
, fname
, 0, DELETE_ACCESS
|FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
3790 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0);
3793 printf("test 2 open 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3797 fnum2
= cli_nt_create_full(cli2
, fname
, 0, FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
3798 FILE_SHARE_NONE
, FILE_OPEN_IF
, 0, 0);
3801 printf("test 2 open 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
3805 if (!cli_close(cli1
, fnum1
)) {
3806 printf("test 1 close 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3809 if (!cli_close(cli2
, fnum2
)) {
3810 printf("test 1 close 2 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3814 printf("non-io open test #2 passed.\n");
3816 cli_unlink(cli1
, fname
);
3818 printf("TEST #3 testing 2 non-io opens (second with delete)\n");
3820 fnum1
= cli_nt_create_full(cli1
, fname
, 0, FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
3821 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0);
3824 printf("test 3 open 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3828 fnum2
= cli_nt_create_full(cli2
, fname
, 0, DELETE_ACCESS
|FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
3829 FILE_SHARE_NONE
, FILE_OPEN_IF
, 0, 0);
3832 printf("test 3 open 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
3836 if (!cli_close(cli1
, fnum1
)) {
3837 printf("test 3 close 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3840 if (!cli_close(cli2
, fnum2
)) {
3841 printf("test 3 close 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
3845 printf("non-io open test #3 passed.\n");
3847 cli_unlink(cli1
, fname
);
3849 printf("TEST #4 testing 2 non-io opens (both with delete)\n");
3851 fnum1
= cli_nt_create_full(cli1
, fname
, 0, DELETE_ACCESS
|FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
3852 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0);
3855 printf("test 4 open 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3859 fnum2
= cli_nt_create_full(cli2
, fname
, 0, DELETE_ACCESS
|FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
3860 FILE_SHARE_NONE
, FILE_OPEN_IF
, 0, 0);
3863 printf("test 4 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname
, cli_errstr(cli2
));
3867 printf("test 3 open 2 of %s gave %s (correct error should be %s)\n", fname
, cli_errstr(cli2
), "sharing violation");
3869 if (!cli_close(cli1
, fnum1
)) {
3870 printf("test 4 close 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3874 printf("non-io open test #4 passed.\n");
3876 cli_unlink(cli1
, fname
);
3878 printf("TEST #5 testing 2 non-io opens (both with delete - both with file share delete)\n");
3880 fnum1
= cli_nt_create_full(cli1
, fname
, 0, DELETE_ACCESS
|FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
3881 FILE_SHARE_DELETE
, FILE_OVERWRITE_IF
, 0, 0);
3884 printf("test 5 open 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3888 fnum2
= cli_nt_create_full(cli2
, fname
, 0, DELETE_ACCESS
|FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
3889 FILE_SHARE_DELETE
, FILE_OPEN_IF
, 0, 0);
3892 printf("test 5 open 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
3896 if (!cli_close(cli1
, fnum1
)) {
3897 printf("test 5 close 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3901 if (!cli_close(cli2
, fnum2
)) {
3902 printf("test 5 close 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
3906 printf("non-io open test #5 passed.\n");
3908 printf("TEST #6 testing 1 non-io open, one io open\n");
3910 cli_unlink(cli1
, fname
);
3912 fnum1
= cli_nt_create_full(cli1
, fname
, 0, FILE_READ_DATA
, FILE_ATTRIBUTE_NORMAL
,
3913 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0);
3916 printf("test 6 open 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3920 fnum2
= cli_nt_create_full(cli2
, fname
, 0, FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
3921 FILE_SHARE_READ
, FILE_OPEN_IF
, 0, 0);
3924 printf("test 6 open 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
3928 if (!cli_close(cli1
, fnum1
)) {
3929 printf("test 6 close 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3933 if (!cli_close(cli2
, fnum2
)) {
3934 printf("test 6 close 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
3938 printf("non-io open test #6 passed.\n");
3940 printf("TEST #7 testing 1 non-io open, one io open with delete\n");
3942 cli_unlink(cli1
, fname
);
3944 fnum1
= cli_nt_create_full(cli1
, fname
, 0, FILE_READ_DATA
, FILE_ATTRIBUTE_NORMAL
,
3945 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0);
3948 printf("test 7 open 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3952 fnum2
= cli_nt_create_full(cli2
, fname
, 0, DELETE_ACCESS
|FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
3953 FILE_SHARE_READ
|FILE_SHARE_DELETE
, FILE_OPEN_IF
, 0, 0);
3956 printf("test 7 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname
, cli_errstr(cli2
));
3960 printf("test 7 open 2 of %s gave %s (correct error should be %s)\n", fname
, cli_errstr(cli2
), "sharing violation");
3962 if (!cli_close(cli1
, fnum1
)) {
3963 printf("test 7 close 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3967 printf("non-io open test #7 passed.\n");
3969 cli_unlink(cli1
, fname
);
3971 if (!torture_close_connection(cli1
)) {
3974 if (!torture_close_connection(cli2
)) {
3981 static uint32 open_attrs_table
[] = {
3982 FILE_ATTRIBUTE_NORMAL
,
3983 FILE_ATTRIBUTE_ARCHIVE
,
3984 FILE_ATTRIBUTE_READONLY
,
3985 FILE_ATTRIBUTE_HIDDEN
,
3986 FILE_ATTRIBUTE_SYSTEM
,
3988 FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
,
3989 FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
,
3990 FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
,
3991 FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
,
3992 FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_SYSTEM
,
3993 FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_SYSTEM
,
3995 FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
,
3996 FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_SYSTEM
,
3997 FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_SYSTEM
,
3998 FILE_ATTRIBUTE_HIDDEN
,FILE_ATTRIBUTE_SYSTEM
,
4001 struct trunc_open_results
{
4008 static struct trunc_open_results attr_results
[] = {
4009 { 0, FILE_ATTRIBUTE_NORMAL
, FILE_ATTRIBUTE_NORMAL
, FILE_ATTRIBUTE_ARCHIVE
},
4010 { 1, FILE_ATTRIBUTE_NORMAL
, FILE_ATTRIBUTE_ARCHIVE
, FILE_ATTRIBUTE_ARCHIVE
},
4011 { 2, FILE_ATTRIBUTE_NORMAL
, FILE_ATTRIBUTE_READONLY
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
},
4012 { 16, FILE_ATTRIBUTE_ARCHIVE
, FILE_ATTRIBUTE_NORMAL
, FILE_ATTRIBUTE_ARCHIVE
},
4013 { 17, FILE_ATTRIBUTE_ARCHIVE
, FILE_ATTRIBUTE_ARCHIVE
, FILE_ATTRIBUTE_ARCHIVE
},
4014 { 18, FILE_ATTRIBUTE_ARCHIVE
, FILE_ATTRIBUTE_READONLY
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
},
4015 { 51, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
},
4016 { 54, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
},
4017 { 56, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
},
4018 { 68, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
},
4019 { 71, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
},
4020 { 73, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_SYSTEM
},
4021 { 99, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_HIDDEN
,FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
},
4022 { 102, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
},
4023 { 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
},
4024 { 116, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
},
4025 { 119, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
},
4026 { 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
},
4027 { 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
},
4028 { 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
},
4029 { 227, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
},
4030 { 230, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
},
4031 { 232, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
},
4032 { 244, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
},
4033 { 247, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
},
4034 { 249, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_SYSTEM
}
4037 static BOOL
run_openattrtest(int dummy
)
4039 static struct cli_state
*cli1
;
4040 const char *fname
= "\\openattr.file";
4042 BOOL correct
= True
;
4044 unsigned int i
, j
, k
, l
;
4046 printf("starting open attr test\n");
4048 if (!torture_open_connection(&cli1
)) {
4052 cli_sockopt(cli1
, sockops
);
4054 for (k
= 0, i
= 0; i
< sizeof(open_attrs_table
)/sizeof(uint32
); i
++) {
4055 cli_setatr(cli1
, fname
, 0, 0);
4056 cli_unlink(cli1
, fname
);
4057 fnum1
= cli_nt_create_full(cli1
, fname
, 0, FILE_WRITE_DATA
, open_attrs_table
[i
],
4058 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0);
4061 printf("open %d (1) of %s failed (%s)\n", i
, fname
, cli_errstr(cli1
));
4065 if (!cli_close(cli1
, fnum1
)) {
4066 printf("close %d (1) of %s failed (%s)\n", i
, fname
, cli_errstr(cli1
));
4070 for (j
= 0; j
< sizeof(open_attrs_table
)/sizeof(uint32
); j
++) {
4071 fnum1
= cli_nt_create_full(cli1
, fname
, 0, FILE_READ_DATA
|FILE_WRITE_DATA
, open_attrs_table
[j
],
4072 FILE_SHARE_NONE
, FILE_OVERWRITE
, 0, 0);
4075 for (l
= 0; l
< sizeof(attr_results
)/sizeof(struct trunc_open_results
); l
++) {
4076 if (attr_results
[l
].num
== k
) {
4077 printf("[%d] trunc open 0x%x -> 0x%x of %s failed - should have succeeded !(0x%x:%s)\n",
4078 k
, open_attrs_table
[i
],
4079 open_attrs_table
[j
],
4080 fname
, NT_STATUS_V(cli_nt_error(cli1
)), cli_errstr(cli1
));
4084 if (NT_STATUS_V(cli_nt_error(cli1
)) != NT_STATUS_V(NT_STATUS_ACCESS_DENIED
)) {
4085 printf("[%d] trunc open 0x%x -> 0x%x failed with wrong error code %s\n",
4086 k
, open_attrs_table
[i
], open_attrs_table
[j
],
4091 printf("[%d] trunc open 0x%x -> 0x%x failed\n", k
, open_attrs_table
[i
], open_attrs_table
[j
]);
4097 if (!cli_close(cli1
, fnum1
)) {
4098 printf("close %d (2) of %s failed (%s)\n", j
, fname
, cli_errstr(cli1
));
4102 if (!cli_getatr(cli1
, fname
, &attr
, NULL
, NULL
)) {
4103 printf("getatr(2) failed (%s)\n", cli_errstr(cli1
));
4108 printf("[%d] getatr check [0x%x] trunc [0x%x] got attr 0x%x\n",
4109 k
, open_attrs_table
[i
], open_attrs_table
[j
], attr
);
4112 for (l
= 0; l
< sizeof(attr_results
)/sizeof(struct trunc_open_results
); l
++) {
4113 if (attr_results
[l
].num
== k
) {
4114 if (attr
!= attr_results
[l
].result_attr
||
4115 open_attrs_table
[i
] != attr_results
[l
].init_attr
||
4116 open_attrs_table
[j
] != attr_results
[l
].trunc_attr
) {
4117 printf("getatr check failed. [0x%x] trunc [0x%x] got attr 0x%x, should be 0x%x\n",
4118 open_attrs_table
[i
],
4119 open_attrs_table
[j
],
4121 attr_results
[l
].result_attr
);
4131 cli_setatr(cli1
, fname
, 0, 0);
4132 cli_unlink(cli1
, fname
);
4134 printf("open attr test %s.\n", correct
? "passed" : "failed");
4136 if (!torture_close_connection(cli1
)) {
4142 static void list_fn(const char *mnt
, file_info
*finfo
, const char *name
, void *state
)
4148 test directory listing speed
4150 static BOOL
run_dirtest(int dummy
)
4153 static struct cli_state
*cli
;
4156 BOOL correct
= True
;
4158 printf("starting directory test\n");
4160 if (!torture_open_connection(&cli
)) {
4164 cli_sockopt(cli
, sockops
);
4167 for (i
=0;i
<torture_numops
;i
++) {
4169 slprintf(fname
, sizeof(fname
), "\\%x", (int)random());
4170 fnum
= cli_open(cli
, fname
, O_RDWR
|O_CREAT
, DENY_NONE
);
4172 fprintf(stderr
,"Failed to open %s\n", fname
);
4175 cli_close(cli
, fnum
);
4180 printf("Matched %d\n", cli_list(cli
, "a*.*", 0, list_fn
, NULL
));
4181 printf("Matched %d\n", cli_list(cli
, "b*.*", 0, list_fn
, NULL
));
4182 printf("Matched %d\n", cli_list(cli
, "xyzabc", 0, list_fn
, NULL
));
4184 printf("dirtest core %g seconds\n", end_timer() - t1
);
4187 for (i
=0;i
<torture_numops
;i
++) {
4189 slprintf(fname
, sizeof(fname
), "\\%x", (int)random());
4190 cli_unlink(cli
, fname
);
4193 if (!torture_close_connection(cli
)) {
4197 printf("finished dirtest\n");
4202 static void del_fn(const char *mnt
, file_info
*finfo
, const char *mask
, void *state
)
4204 struct cli_state
*pcli
= (struct cli_state
*)state
;
4206 slprintf(fname
, sizeof(fname
), "\\LISTDIR\\%s", finfo
->name
);
4208 if (strcmp(finfo
->name
, ".") == 0 || strcmp(finfo
->name
, "..") == 0)
4211 if (finfo
->mode
& aDIR
) {
4212 if (!cli_rmdir(pcli
, fname
))
4213 printf("del_fn: failed to rmdir %s\n,", fname
);
4215 if (!cli_unlink(pcli
, fname
))
4216 printf("del_fn: failed to unlink %s\n,", fname
);
4222 sees what IOCTLs are supported
4224 BOOL
torture_ioctl_test(int dummy
)
4226 static struct cli_state
*cli
;
4227 uint16 device
, function
;
4229 const char *fname
= "\\ioctl.dat";
4233 if (!torture_open_connection(&cli
)) {
4237 printf("starting ioctl test\n");
4239 cli_unlink(cli
, fname
);
4241 fnum
= cli_open(cli
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
);
4243 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli
));
4247 status
= cli_raw_ioctl(cli
, fnum
, 0x2d0000 | (0x0420<<2), &blob
);
4248 printf("ioctl device info: %s\n", cli_errstr(cli
));
4250 status
= cli_raw_ioctl(cli
, fnum
, IOCTL_QUERY_JOB_INFO
, &blob
);
4251 printf("ioctl job info: %s\n", cli_errstr(cli
));
4253 for (device
=0;device
<0x100;device
++) {
4254 printf("testing device=0x%x\n", device
);
4255 for (function
=0;function
<0x100;function
++) {
4256 uint32 code
= (device
<<16) | function
;
4258 status
= cli_raw_ioctl(cli
, fnum
, code
, &blob
);
4260 if (NT_STATUS_IS_OK(status
)) {
4261 printf("ioctl 0x%x OK : %d bytes\n", code
, blob
.length
);
4262 data_blob_free(&blob
);
4267 if (!torture_close_connection(cli
)) {
4276 tries varients of chkpath
4278 BOOL
torture_chkpath_test(int dummy
)
4280 static struct cli_state
*cli
;
4284 if (!torture_open_connection(&cli
)) {
4288 printf("starting chkpath test\n");
4290 /* cleanup from an old run */
4291 cli_rmdir(cli
, "\\chkpath.dir\\dir2");
4292 cli_unlink(cli
, "\\chkpath.dir\\*");
4293 cli_rmdir(cli
, "\\chkpath.dir");
4295 if (!cli_mkdir(cli
, "\\chkpath.dir")) {
4296 printf("mkdir1 failed : %s\n", cli_errstr(cli
));
4300 if (!cli_mkdir(cli
, "\\chkpath.dir\\dir2")) {
4301 printf("mkdir2 failed : %s\n", cli_errstr(cli
));
4305 fnum
= cli_open(cli
, "\\chkpath.dir\\foo.txt", O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
);
4307 printf("open1 failed (%s)\n", cli_errstr(cli
));
4310 cli_close(cli
, fnum
);
4312 if (!cli_chkpath(cli
, "\\chkpath.dir")) {
4313 printf("chkpath1 failed: %s\n", cli_errstr(cli
));
4317 if (!cli_chkpath(cli
, "\\chkpath.dir\\dir2")) {
4318 printf("chkpath2 failed: %s\n", cli_errstr(cli
));
4322 if (!cli_chkpath(cli
, "\\chkpath.dir\\foo.txt")) {
4323 ret
= check_error(__LINE__
, cli
, ERRDOS
, ERRbadpath
,
4324 NT_STATUS_NOT_A_DIRECTORY
);
4326 printf("* chkpath on a file should fail\n");
4330 if (!cli_chkpath(cli
, "\\chkpath.dir\\bar.txt")) {
4331 ret
= check_error(__LINE__
, cli
, ERRDOS
, ERRbadfile
,
4332 NT_STATUS_OBJECT_NAME_NOT_FOUND
);
4334 printf("* chkpath on a non existant file should fail\n");
4338 if (!cli_chkpath(cli
, "\\chkpath.dir\\dirxx\\bar.txt")) {
4339 ret
= check_error(__LINE__
, cli
, ERRDOS
, ERRbadpath
,
4340 NT_STATUS_OBJECT_PATH_NOT_FOUND
);
4342 printf("* chkpath on a non existent component should fail\n");
4346 cli_rmdir(cli
, "\\chkpath.dir\\dir2");
4347 cli_unlink(cli
, "\\chkpath.dir\\*");
4348 cli_rmdir(cli
, "\\chkpath.dir");
4350 if (!torture_close_connection(cli
)) {
4357 static BOOL
run_eatest(int dummy
)
4359 static struct cli_state
*cli
;
4360 const char *fname
= "\\eatest.txt";
4361 BOOL correct
= True
;
4364 struct ea_struct
*ea_list
= NULL
;
4365 TALLOC_CTX
*mem_ctx
= talloc_init("eatest");
4367 printf("starting eatest\n");
4369 if (!torture_open_connection(&cli
)) {
4373 cli_unlink(cli
, fname
);
4374 fnum
= cli_nt_create_full(cli
, fname
, 0,
4375 FIRST_DESIRED_ACCESS
, FILE_ATTRIBUTE_ARCHIVE
,
4376 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
,
4380 printf("open failed - %s\n", cli_errstr(cli
));
4384 for (i
= 0; i
< 10; i
++) {
4385 fstring ea_name
, ea_val
;
4387 slprintf(ea_name
, sizeof(ea_name
), "EA_%d", i
);
4388 memset(ea_val
, (char)i
+1, i
+1);
4389 if (!cli_set_ea_fnum(cli
, fnum
, ea_name
, ea_val
, i
+1)) {
4390 printf("ea_set of name %s failed - %s\n", ea_name
, cli_errstr(cli
));
4395 cli_close(cli
, fnum
);
4396 for (i
= 0; i
< 10; i
++) {
4397 fstring ea_name
, ea_val
;
4399 slprintf(ea_name
, sizeof(ea_name
), "EA_%d", i
+10);
4400 memset(ea_val
, (char)i
+1, i
+1);
4401 if (!cli_set_ea_path(cli
, fname
, ea_name
, ea_val
, i
+1)) {
4402 printf("ea_set of name %s failed - %s\n", ea_name
, cli_errstr(cli
));
4407 if (!cli_get_ea_list_path(cli
, fname
, mem_ctx
, &num_eas
, &ea_list
)) {
4408 printf("ea_get list failed - %s\n", cli_errstr(cli
));
4412 printf("num_eas = %d\n", num_eas
);
4414 if (num_eas
!= 20) {
4415 printf("Should be 20 EA's stored... failing.\n");
4419 for (i
= 0; i
< num_eas
; i
++) {
4420 printf("%d: ea_name = %s. Val = ", i
, ea_list
[i
].name
);
4421 dump_data(0, ea_list
[i
].value
.data
, ea_list
[i
].value
.length
);
4424 /* Setting EA's to zero length deletes them. Test this */
4425 printf("Now deleting all EA's - case indepenent....\n");
4428 cli_set_ea_path(cli
, fname
, "", "", 0);
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
));
4440 if (!cli_get_ea_list_path(cli
, fname
, mem_ctx
, &num_eas
, &ea_list
)) {
4441 printf("ea_get list failed - %s\n", cli_errstr(cli
));
4445 printf("num_eas = %d\n", num_eas
);
4446 for (i
= 0; i
< num_eas
; i
++) {
4447 printf("%d: ea_name = %s. Val = ", i
, ea_list
[i
].name
);
4448 dump_data(0, ea_list
[i
].value
.data
, ea_list
[i
].value
.length
);
4452 printf("deleting EA's failed.\n");
4456 /* Try and delete a non existant EA. */
4457 if (!cli_set_ea_path(cli
, fname
, "foo", "", 0)) {
4458 printf("deleting non-existant EA 'foo' should succeed. %s\n", cli_errstr(cli
));
4462 talloc_destroy(mem_ctx
);
4463 if (!torture_close_connection(cli
)) {
4470 static BOOL
run_dirtest1(int dummy
)
4473 static struct cli_state
*cli
;
4475 BOOL correct
= True
;
4477 printf("starting directory test\n");
4479 if (!torture_open_connection(&cli
)) {
4483 cli_sockopt(cli
, sockops
);
4485 cli_list(cli
, "\\LISTDIR\\*", 0, del_fn
, cli
);
4486 cli_list(cli
, "\\LISTDIR\\*", aDIR
, del_fn
, cli
);
4487 cli_rmdir(cli
, "\\LISTDIR");
4488 cli_mkdir(cli
, "\\LISTDIR");
4490 /* Create 1000 files and 1000 directories. */
4491 for (i
=0;i
<1000;i
++) {
4493 slprintf(fname
, sizeof(fname
), "\\LISTDIR\\f%d", i
);
4494 fnum
= cli_nt_create_full(cli
, fname
, 0, GENERIC_ALL_ACCESS
, FILE_ATTRIBUTE_ARCHIVE
,
4495 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OVERWRITE_IF
, 0, 0);
4497 fprintf(stderr
,"Failed to open %s\n", fname
);
4500 cli_close(cli
, fnum
);
4502 for (i
=0;i
<1000;i
++) {
4504 slprintf(fname
, sizeof(fname
), "\\LISTDIR\\d%d", i
);
4505 if (!cli_mkdir(cli
, fname
)) {
4506 fprintf(stderr
,"Failed to open %s\n", fname
);
4511 /* Now ensure that doing an old list sees both files and directories. */
4512 num_seen
= cli_list_old(cli
, "\\LISTDIR\\*", aDIR
, list_fn
, NULL
);
4513 printf("num_seen = %d\n", num_seen
);
4514 /* We should see 100 files + 1000 directories + . and .. */
4515 if (num_seen
!= 2002)
4518 /* Ensure if we have the "must have" bits we only see the
4521 num_seen
= cli_list_old(cli
, "\\LISTDIR\\*", (aDIR
<<8)|aDIR
, list_fn
, NULL
);
4522 printf("num_seen = %d\n", num_seen
);
4523 if (num_seen
!= 1002)
4526 num_seen
= cli_list_old(cli
, "\\LISTDIR\\*", (aARCH
<<8)|aDIR
, list_fn
, NULL
);
4527 printf("num_seen = %d\n", num_seen
);
4528 if (num_seen
!= 1000)
4531 /* Delete everything. */
4532 cli_list(cli
, "\\LISTDIR\\*", 0, del_fn
, cli
);
4533 cli_list(cli
, "\\LISTDIR\\*", aDIR
, del_fn
, cli
);
4534 cli_rmdir(cli
, "\\LISTDIR");
4537 printf("Matched %d\n", cli_list(cli
, "a*.*", 0, list_fn
, NULL
));
4538 printf("Matched %d\n", cli_list(cli
, "b*.*", 0, list_fn
, NULL
));
4539 printf("Matched %d\n", cli_list(cli
, "xyzabc", 0, list_fn
, NULL
));
4542 if (!torture_close_connection(cli
)) {
4546 printf("finished dirtest1\n");
4551 static BOOL
run_error_map_extract(int dummy
) {
4553 static struct cli_state c_dos
;
4554 static struct cli_state c_nt
;
4558 uint32 flgs2
, errnum
;
4565 /* NT-Error connection */
4567 if (!open_nbt_connection(&c_nt
)) {
4571 c_nt
.use_spnego
= False
;
4573 if (!cli_negprot(&c_nt
)) {
4574 printf("%s rejected the NT-error negprot (%s)\n",host
, cli_errstr(&c_nt
));
4575 cli_shutdown(&c_nt
);
4579 if (!cli_session_setup(&c_nt
, "", "", 0, "", 0,
4581 printf("%s rejected the NT-error initial session setup (%s)\n",host
, cli_errstr(&c_nt
));
4585 /* DOS-Error connection */
4587 if (!open_nbt_connection(&c_dos
)) {
4591 c_dos
.use_spnego
= False
;
4592 c_dos
.force_dos_errors
= True
;
4594 if (!cli_negprot(&c_dos
)) {
4595 printf("%s rejected the DOS-error negprot (%s)\n",host
, cli_errstr(&c_dos
));
4596 cli_shutdown(&c_dos
);
4600 if (!cli_session_setup(&c_dos
, "", "", 0, "", 0,
4602 printf("%s rejected the DOS-error initial session setup (%s)\n",host
, cli_errstr(&c_dos
));
4606 for (error
=(0xc0000000 | 0x1); error
< (0xc0000000| 0xFFF); error
++) {
4607 fstr_sprintf(user
, "%X", error
);
4609 if (cli_session_setup(&c_nt
, user
,
4610 password
, strlen(password
),
4611 password
, strlen(password
),
4613 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
4616 flgs2
= SVAL(c_nt
.inbuf
,smb_flg2
);
4618 /* Case #1: 32-bit NT errors */
4619 if (flgs2
& FLAGS2_32_BIT_ERROR_CODES
) {
4620 nt_status
= NT_STATUS(IVAL(c_nt
.inbuf
,smb_rcls
));
4622 printf("/** Dos error on NT connection! (%s) */\n",
4624 nt_status
= NT_STATUS(0xc0000000);
4627 if (cli_session_setup(&c_dos
, user
,
4628 password
, strlen(password
),
4629 password
, strlen(password
),
4631 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
4633 flgs2
= SVAL(c_dos
.inbuf
,smb_flg2
), errnum
;
4635 /* Case #1: 32-bit NT errors */
4636 if (flgs2
& FLAGS2_32_BIT_ERROR_CODES
) {
4637 printf("/** NT error on DOS connection! (%s) */\n",
4639 errnum
= errclass
= 0;
4641 cli_dos_error(&c_dos
, &errclass
, &errnum
);
4644 if (NT_STATUS_V(nt_status
) != error
) {
4645 printf("/*\t{ This NT error code was 'sqashed'\n\t from %s to %s \n\t during the session setup }\n*/\n",
4646 get_nt_error_c_code(NT_STATUS(error
)),
4647 get_nt_error_c_code(nt_status
));
4650 printf("\t{%s,\t%s,\t%s},\n",
4651 smb_dos_err_class(errclass
),
4652 smb_dos_err_name(errclass
, errnum
),
4653 get_nt_error_c_code(NT_STATUS(error
)));
4658 static double create_procs(BOOL (*fn
)(int), BOOL
*result
)
4661 volatile pid_t
*child_status
;
4662 volatile BOOL
*child_status_out
;
4668 child_status
= (volatile pid_t
*)shm_setup(sizeof(pid_t
)*nprocs
);
4669 if (!child_status
) {
4670 printf("Failed to setup shared memory\n");
4674 child_status_out
= (volatile BOOL
*)shm_setup(sizeof(BOOL
)*nprocs
);
4675 if (!child_status_out
) {
4676 printf("Failed to setup result status shared memory\n");
4680 for (i
= 0; i
< nprocs
; i
++) {
4681 child_status
[i
] = 0;
4682 child_status_out
[i
] = True
;
4687 for (i
=0;i
<nprocs
;i
++) {
4690 pid_t mypid
= getpid();
4691 sys_srandom(((int)mypid
) ^ ((int)time(NULL
)));
4693 slprintf(myname
,sizeof(myname
),"CLIENT%d", i
);
4696 if (torture_open_connection(¤t_cli
)) break;
4698 printf("pid %d failed to start\n", (int)getpid());
4704 child_status
[i
] = getpid();
4706 while (child_status
[i
] && end_timer() < 5) smb_msleep(2);
4708 child_status_out
[i
] = fn(i
);
4715 for (i
=0;i
<nprocs
;i
++) {
4716 if (child_status
[i
]) synccount
++;
4718 if (synccount
== nprocs
) break;
4720 } while (end_timer() < 30);
4722 if (synccount
!= nprocs
) {
4723 printf("FAILED TO START %d CLIENTS (started %d)\n", nprocs
, synccount
);
4728 /* start the client load */
4731 for (i
=0;i
<nprocs
;i
++) {
4732 child_status
[i
] = 0;
4735 printf("%d clients started\n", nprocs
);
4737 for (i
=0;i
<nprocs
;i
++) {
4738 while (waitpid(0, &status
, 0) == -1 && errno
== EINTR
) /* noop */ ;
4743 for (i
=0;i
<nprocs
;i
++) {
4744 if (!child_status_out
[i
]) {
4751 #define FLAG_MULTIPROC 1
4758 {"FDPASS", run_fdpasstest
, 0},
4759 {"LOCK1", run_locktest1
, 0},
4760 {"LOCK2", run_locktest2
, 0},
4761 {"LOCK3", run_locktest3
, 0},
4762 {"LOCK4", run_locktest4
, 0},
4763 {"LOCK5", run_locktest5
, 0},
4764 {"LOCK6", run_locktest6
, 0},
4765 {"LOCK7", run_locktest7
, 0},
4766 {"UNLINK", run_unlinktest
, 0},
4767 {"BROWSE", run_browsetest
, 0},
4768 {"ATTR", run_attrtest
, 0},
4769 {"TRANS2", run_trans2test
, 0},
4770 {"MAXFID", run_maxfidtest
, FLAG_MULTIPROC
},
4771 {"TORTURE",run_torture
, FLAG_MULTIPROC
},
4772 {"RANDOMIPC", run_randomipc
, 0},
4773 {"NEGNOWAIT", run_negprot_nowait
, 0},
4774 {"NBENCH", run_nbench
, 0},
4775 {"OPLOCK1", run_oplock1
, 0},
4776 {"OPLOCK2", run_oplock2
, 0},
4777 {"OPLOCK3", run_oplock3
, 0},
4778 {"DIR", run_dirtest
, 0},
4779 {"DIR1", run_dirtest1
, 0},
4780 {"DENY1", torture_denytest1
, 0},
4781 {"DENY2", torture_denytest2
, 0},
4782 {"TCON", run_tcon_test
, 0},
4783 {"TCONDEV", run_tcon_devtype_test
, 0},
4784 {"RW1", run_readwritetest
, 0},
4785 {"RW2", run_readwritemulti
, FLAG_MULTIPROC
},
4786 {"RW3", run_readwritelarge
, 0},
4787 {"OPEN", run_opentest
, 0},
4789 {"OPENATTR", run_openattrtest
, 0},
4791 {"XCOPY", run_xcopy
, 0},
4792 {"RENAME", run_rename
, 0},
4793 {"DELETE", run_deletetest
, 0},
4794 {"PROPERTIES", run_properties
, 0},
4795 {"MANGLE", torture_mangle
, 0},
4796 {"W2K", run_w2ktest
, 0},
4797 {"TRANS2SCAN", torture_trans2_scan
, 0},
4798 {"NTTRANSSCAN", torture_nttrans_scan
, 0},
4799 {"UTABLE", torture_utable
, 0},
4800 {"CASETABLE", torture_casetable
, 0},
4801 {"ERRMAPEXTRACT", run_error_map_extract
, 0},
4802 {"PIPE_NUMBER", run_pipe_number
, 0},
4803 {"TCON2", run_tcon2_test
, 0},
4804 {"IOCTL", torture_ioctl_test
, 0},
4805 {"CHKPATH", torture_chkpath_test
, 0},
4806 {"FDSESS", run_fdsesstest
, 0},
4807 { "EATEST", run_eatest
, 0},
4812 /****************************************************************************
4813 run a specified test or "ALL"
4814 ****************************************************************************/
4815 static BOOL
run_test(const char *name
)
4822 if (strequal(name
,"ALL")) {
4823 for (i
=0;torture_ops
[i
].name
;i
++) {
4824 run_test(torture_ops
[i
].name
);
4829 for (i
=0;torture_ops
[i
].name
;i
++) {
4830 fstr_sprintf(randomfname
, "\\XX%x",
4831 (unsigned)random());
4833 if (strequal(name
, torture_ops
[i
].name
)) {
4835 printf("Running %s\n", name
);
4836 if (torture_ops
[i
].flags
& FLAG_MULTIPROC
) {
4837 t
= create_procs(torture_ops
[i
].fn
, &result
);
4840 printf("TEST %s FAILED!\n", name
);
4845 if (!torture_ops
[i
].fn(0)) {
4847 printf("TEST %s FAILED!\n", name
);
4851 printf("%s took %g secs\n\n", name
, t
);
4856 printf("Did not find a test named %s\n", name
);
4864 static void usage(void)
4868 printf("WARNING samba4 test suite is much more complete nowadays.\n");
4869 printf("Please use samba4 torture.\n\n");
4871 printf("Usage: smbtorture //server/share <options> TEST1 TEST2 ...\n");
4873 printf("\t-d debuglevel\n");
4874 printf("\t-U user%%pass\n");
4875 printf("\t-k use kerberos\n");
4876 printf("\t-N numprocs\n");
4877 printf("\t-n my_netbios_name\n");
4878 printf("\t-W workgroup\n");
4879 printf("\t-o num_operations\n");
4880 printf("\t-O socket_options\n");
4881 printf("\t-m maximum protocol\n");
4882 printf("\t-L use oplocks\n");
4883 printf("\t-c CLIENT.TXT specify client load file for NBENCH\n");
4884 printf("\t-A showall\n");
4885 printf("\t-p port\n");
4886 printf("\t-s seed\n");
4889 printf("tests are:");
4890 for (i
=0;torture_ops
[i
].name
;i
++) {
4891 printf(" %s", torture_ops
[i
].name
);
4895 printf("default test is ALL\n");
4900 /****************************************************************************
4902 ****************************************************************************/
4903 int main(int argc
,char *argv
[])
4909 BOOL correct
= True
;
4913 #ifdef HAVE_SETBUFFER
4914 setbuffer(stdout
, NULL
, 0);
4917 lp_load(dyn_CONFIGFILE
,True
,False
,False
);
4924 for(p
= argv
[1]; *p
; p
++)
4928 if (strncmp(argv
[1], "//", 2)) {
4932 fstrcpy(host
, &argv
[1][2]);
4933 p
= strchr_m(&host
[2],'/');
4938 fstrcpy(share
, p
+1);
4942 if (*username
== 0 && getenv("LOGNAME")) {
4943 fstrcpy(username
,getenv("LOGNAME"));
4949 srandom(time(NULL
));
4951 fstrcpy(workgroup
, lp_workgroup());
4953 while ((opt
= getopt(argc
, argv
, "p:hW:U:n:N:O:o:m:Ld:Ac:ks:")) != EOF
) {
4956 port_to_use
= atoi(optarg
);
4959 srandom(atoi(optarg
));
4962 fstrcpy(workgroup
,optarg
);
4965 max_protocol
= interpret_protocol(optarg
, max_protocol
);
4968 nprocs
= atoi(optarg
);
4971 torture_numops
= atoi(optarg
);
4974 DEBUGLEVEL
= atoi(optarg
);
4983 torture_showall
= True
;
4986 fstrcpy(myname
, optarg
);
4989 client_txt
= optarg
;
4993 use_kerberos
= True
;
4995 d_printf("No kerberos support compiled in\n");
5001 fstrcpy(username
,optarg
);
5002 p
= strchr_m(username
,'%');
5005 fstrcpy(password
, p
+1);
5010 printf("Unknown option %c (%d)\n", (char)opt
, opt
);
5015 if(use_kerberos
&& !gotuser
) gotpass
= True
;
5018 p
= getpass("Password:");
5020 fstrcpy(password
, p
);
5025 printf("host=%s share=%s user=%s myname=%s\n",
5026 host
, share
, username
, myname
);
5028 if (argc
== optind
) {
5029 correct
= run_test("ALL");
5031 for (i
=optind
;i
<argc
;i
++) {
5032 if (!run_test(argv
[i
])) {