2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 1997-1998
5 Copyright (C) Jeremy Allison 2009
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "nsswitch/libwbclient/wbc_async.h"
27 static fstring host
, workgroup
, share
, password
, username
, myname
;
28 static int max_protocol
= PROTOCOL_NT1
;
29 static const char *sockops
="TCP_NODELAY";
31 static int port_to_use
=0;
32 int torture_numops
=100;
33 int torture_blocksize
=1024*1024;
34 static int procnum
; /* records process count number when forking */
35 static struct cli_state
*current_cli
;
36 static fstring randomfname
;
37 static bool use_oplocks
;
38 static bool use_level_II_oplocks
;
39 static const char *client_txt
= "client_oplocks.txt";
40 static bool use_kerberos
;
41 static fstring multishare_conn_fname
;
42 static bool use_multishare_conn
= False
;
43 static bool do_encrypt
;
44 static const char *local_path
= NULL
;
46 bool torture_showall
= False
;
48 static double create_procs(bool (*fn
)(int), bool *result
);
51 static struct timeval tp1
,tp2
;
54 void start_timer(void)
59 double end_timer(void)
62 return((tp2
.tv_sec
- tp1
.tv_sec
) +
63 (tp2
.tv_usec
- tp1
.tv_usec
)*1.0e-6);
67 /* return a pointer to a anonymous shared memory segment of size "size"
68 which will persist across fork() but will disappear when all processes
71 The memory is not zeroed
73 This function uses system5 shared memory. It takes advantage of a property
74 that the memory is not destroyed if it is attached when the id is removed
76 void *shm_setup(int size
)
82 shmid
= shm_open("private", O_RDWR
| O_CREAT
| O_EXCL
, S_IRUSR
| S_IWUSR
);
84 printf("can't get shared memory\n");
87 shm_unlink("private");
88 if (ftruncate(shmid
, size
) == -1) {
89 printf("can't set shared memory size\n");
92 ret
= mmap(0, size
, PROT_READ
| PROT_WRITE
, MAP_SHARED
, shmid
, 0);
93 if (ret
== MAP_FAILED
) {
94 printf("can't map shared memory\n");
98 shmid
= shmget(IPC_PRIVATE
, size
, S_IRUSR
| S_IWUSR
);
100 printf("can't get shared memory\n");
103 ret
= (void *)shmat(shmid
, 0, 0);
104 if (!ret
|| ret
== (void *)-1) {
105 printf("can't attach to shared memory\n");
108 /* the following releases the ipc, but note that this process
109 and all its children will still have access to the memory, its
110 just that the shmid is no longer valid for other shm calls. This
111 means we don't leave behind lots of shm segments after we exit
113 See Stevens "advanced programming in unix env" for details
115 shmctl(shmid
, IPC_RMID
, 0);
121 /********************************************************************
122 Ensure a connection is encrypted.
123 ********************************************************************/
125 static bool force_cli_encryption(struct cli_state
*c
,
126 const char *sharename
)
129 uint32 caplow
, caphigh
;
132 if (!SERVER_HAS_UNIX_CIFS(c
)) {
133 d_printf("Encryption required and "
134 "server that doesn't support "
135 "UNIX extensions - failing connect\n");
139 if (!cli_unix_extensions_version(c
, &major
, &minor
, &caplow
, &caphigh
)) {
140 d_printf("Encryption required and "
141 "can't get UNIX CIFS extensions "
142 "version from server.\n");
146 if (!(caplow
& CIFS_UNIX_TRANSPORT_ENCRYPTION_CAP
)) {
147 d_printf("Encryption required and "
148 "share %s doesn't support "
149 "encryption.\n", sharename
);
153 if (c
->use_kerberos
) {
154 status
= cli_gss_smb_encryption_start(c
);
156 status
= cli_raw_ntlm_smb_encryption_start(c
,
162 if (!NT_STATUS_IS_OK(status
)) {
163 d_printf("Encryption required and "
164 "setup failed with error %s.\n",
173 static struct cli_state
*open_nbt_connection(void)
175 struct nmb_name called
, calling
;
176 struct sockaddr_storage ss
;
180 make_nmb_name(&calling
, myname
, 0x0);
181 make_nmb_name(&called
, host
, 0x20);
185 if (!(c
= cli_initialise())) {
186 printf("Failed initialize cli_struct to connect with %s\n", host
);
190 c
->port
= port_to_use
;
192 status
= cli_connect(c
, host
, &ss
);
193 if (!NT_STATUS_IS_OK(status
)) {
194 printf("Failed to connect with %s. Error %s\n", host
, nt_errstr(status
) );
198 c
->use_kerberos
= use_kerberos
;
200 c
->timeout
= 120000; /* set a really long timeout (2 minutes) */
201 if (use_oplocks
) c
->use_oplocks
= True
;
202 if (use_level_II_oplocks
) c
->use_level_II_oplocks
= True
;
204 if (!cli_session_request(c
, &calling
, &called
)) {
206 * Well, that failed, try *SMBSERVER ...
207 * However, we must reconnect as well ...
209 status
= cli_connect(c
, host
, &ss
);
210 if (!NT_STATUS_IS_OK(status
)) {
211 printf("Failed to connect with %s. Error %s\n", host
, nt_errstr(status
) );
215 make_nmb_name(&called
, "*SMBSERVER", 0x20);
216 if (!cli_session_request(c
, &calling
, &called
)) {
217 printf("%s rejected the session\n",host
);
218 printf("We tried with a called name of %s & %s\n",
228 /* Insert a NULL at the first separator of the given path and return a pointer
229 * to the remainder of the string.
232 terminate_path_at_separator(char * path
)
240 if ((p
= strchr_m(path
, '/'))) {
245 if ((p
= strchr_m(path
, '\\'))) {
255 parse a //server/share type UNC name
257 bool smbcli_parse_unc(const char *unc_name
, TALLOC_CTX
*mem_ctx
,
258 char **hostname
, char **sharename
)
262 *hostname
= *sharename
= NULL
;
264 if (strncmp(unc_name
, "\\\\", 2) &&
265 strncmp(unc_name
, "//", 2)) {
269 *hostname
= talloc_strdup(mem_ctx
, &unc_name
[2]);
270 p
= terminate_path_at_separator(*hostname
);
273 *sharename
= talloc_strdup(mem_ctx
, p
);
274 terminate_path_at_separator(*sharename
);
277 if (*hostname
&& *sharename
) {
281 TALLOC_FREE(*hostname
);
282 TALLOC_FREE(*sharename
);
286 static bool torture_open_connection_share(struct cli_state
**c
,
287 const char *hostname
,
288 const char *sharename
)
295 flags
|= CLI_FULL_CONNECTION_USE_KERBEROS
;
297 flags
|= CLI_FULL_CONNECTION_OPLOCKS
;
298 if (use_level_II_oplocks
)
299 flags
|= CLI_FULL_CONNECTION_LEVEL_II_OPLOCKS
;
301 status
= cli_full_connection(c
, myname
,
302 hostname
, NULL
, port_to_use
,
305 password
, flags
, Undefined
, &retry
);
306 if (!NT_STATUS_IS_OK(status
)) {
307 printf("failed to open share connection: //%s/%s port:%d - %s\n",
308 hostname
, sharename
, port_to_use
, nt_errstr(status
));
312 (*c
)->timeout
= 120000; /* set a really long timeout (2 minutes) */
315 return force_cli_encryption(*c
,
321 bool torture_open_connection(struct cli_state
**c
, int conn_index
)
323 char **unc_list
= NULL
;
324 int num_unc_names
= 0;
327 if (use_multishare_conn
==True
) {
329 unc_list
= file_lines_load(multishare_conn_fname
, &num_unc_names
, 0, NULL
);
330 if (!unc_list
|| num_unc_names
<= 0) {
331 printf("Failed to load unc names list from '%s'\n", multishare_conn_fname
);
335 if (!smbcli_parse_unc(unc_list
[conn_index
% num_unc_names
],
337 printf("Failed to parse UNC name %s\n",
338 unc_list
[conn_index
% num_unc_names
]);
339 TALLOC_FREE(unc_list
);
343 result
= torture_open_connection_share(c
, h
, s
);
345 /* h, s were copied earlier */
346 TALLOC_FREE(unc_list
);
350 return torture_open_connection_share(c
, host
, share
);
353 bool torture_cli_session_setup2(struct cli_state
*cli
, uint16
*new_vuid
)
355 uint16 old_vuid
= cli
->vuid
;
356 fstring old_user_name
;
357 size_t passlen
= strlen(password
);
361 fstrcpy(old_user_name
, cli
->user_name
);
363 ret
= NT_STATUS_IS_OK(cli_session_setup(cli
, username
,
367 *new_vuid
= cli
->vuid
;
368 cli
->vuid
= old_vuid
;
369 status
= cli_set_username(cli
, old_user_name
);
370 if (!NT_STATUS_IS_OK(status
)) {
377 bool torture_close_connection(struct cli_state
*c
)
381 printf("tdis failed (%s)\n", cli_errstr(c
));
391 /* check if the server produced the expected error code */
392 static bool check_error(int line
, struct cli_state
*c
,
393 uint8 eclass
, uint32 ecode
, NTSTATUS nterr
)
395 if (cli_is_dos_error(c
)) {
399 /* Check DOS error */
401 cli_dos_error(c
, &cclass
, &num
);
403 if (eclass
!= cclass
|| ecode
!= num
) {
404 printf("unexpected error code class=%d code=%d\n",
405 (int)cclass
, (int)num
);
406 printf(" expected %d/%d %s (line=%d)\n",
407 (int)eclass
, (int)ecode
, nt_errstr(nterr
), line
);
416 status
= cli_nt_error(c
);
418 if (NT_STATUS_V(nterr
) != NT_STATUS_V(status
)) {
419 printf("unexpected error code %s\n", nt_errstr(status
));
420 printf(" expected %s (line=%d)\n", nt_errstr(nterr
), line
);
429 static bool wait_lock(struct cli_state
*c
, int fnum
, uint32 offset
, uint32 len
)
431 while (!cli_lock(c
, fnum
, offset
, len
, -1, WRITE_LOCK
)) {
432 if (!check_error(__LINE__
, c
, ERRDOS
, ERRlock
, NT_STATUS_LOCK_NOT_GRANTED
)) return False
;
438 static bool rw_torture(struct cli_state
*c
)
440 const char *lockfname
= "\\torture.lck";
444 pid_t pid2
, pid
= getpid();
450 memset(buf
, '\0', sizeof(buf
));
452 status
= cli_open(c
, lockfname
, O_RDWR
| O_CREAT
| O_EXCL
,
454 if (!NT_STATUS_IS_OK(status
)) {
455 status
= cli_open(c
, lockfname
, O_RDWR
, DENY_NONE
, &fnum2
);
457 if (!NT_STATUS_IS_OK(status
)) {
458 printf("open of %s failed (%s)\n", lockfname
, cli_errstr(c
));
462 for (i
=0;i
<torture_numops
;i
++) {
463 unsigned n
= (unsigned)sys_random()%10;
465 printf("%d\r", i
); fflush(stdout
);
467 slprintf(fname
, sizeof(fstring
) - 1, "\\torture.%u", n
);
469 if (!wait_lock(c
, fnum2
, n
*sizeof(int), sizeof(int))) {
473 if (!NT_STATUS_IS_OK(cli_open(c
, fname
, O_RDWR
| O_CREAT
| O_TRUNC
, DENY_ALL
, &fnum
))) {
474 printf("open failed (%s)\n", cli_errstr(c
));
479 if (cli_write(c
, fnum
, 0, (char *)&pid
, 0, sizeof(pid
)) != sizeof(pid
)) {
480 printf("write failed (%s)\n", cli_errstr(c
));
485 if (cli_write(c
, fnum
, 0, (char *)buf
,
486 sizeof(pid
)+(j
*sizeof(buf
)),
487 sizeof(buf
)) != sizeof(buf
)) {
488 printf("write failed (%s)\n", cli_errstr(c
));
495 if (cli_read(c
, fnum
, (char *)&pid2
, 0, sizeof(pid
)) != sizeof(pid
)) {
496 printf("read failed (%s)\n", cli_errstr(c
));
501 printf("data corruption!\n");
505 if (!NT_STATUS_IS_OK(cli_close(c
, fnum
))) {
506 printf("close failed (%s)\n", cli_errstr(c
));
510 if (!NT_STATUS_IS_OK(cli_unlink(c
, fname
, aSYSTEM
| aHIDDEN
))) {
511 printf("unlink failed (%s)\n", cli_errstr(c
));
515 if (!NT_STATUS_IS_OK(cli_unlock(c
, fnum2
, n
*sizeof(int), sizeof(int)))) {
516 printf("unlock failed (%s)\n", cli_errstr(c
));
522 cli_unlink(c
, lockfname
, aSYSTEM
| aHIDDEN
);
529 static bool run_torture(int dummy
)
531 struct cli_state
*cli
;
536 cli_sockopt(cli
, sockops
);
538 ret
= rw_torture(cli
);
540 if (!torture_close_connection(cli
)) {
547 static bool rw_torture3(struct cli_state
*c
, char *lockfname
)
549 uint16_t fnum
= (uint16_t)-1;
554 unsigned countprev
= 0;
560 for (i
= 0; i
< sizeof(buf
); i
+= sizeof(uint32
))
562 SIVAL(buf
, i
, sys_random());
567 if (!NT_STATUS_IS_OK(cli_open(c
, lockfname
, O_RDWR
| O_CREAT
| O_EXCL
,
568 DENY_NONE
, &fnum
))) {
569 printf("first open read/write of %s failed (%s)\n",
570 lockfname
, cli_errstr(c
));
576 for (i
= 0; i
< 500 && fnum
== (uint16_t)-1; i
++)
578 status
= cli_open(c
, lockfname
, O_RDONLY
,
580 if (!NT_STATUS_IS_OK(status
)) {
585 if (!NT_STATUS_IS_OK(status
)) {
586 printf("second open read-only of %s failed (%s)\n",
587 lockfname
, cli_errstr(c
));
593 for (count
= 0; count
< sizeof(buf
); count
+= sent
)
595 if (count
>= countprev
) {
596 printf("%d %8d\r", i
, count
);
599 countprev
+= (sizeof(buf
) / 20);
604 sent
= ((unsigned)sys_random()%(20))+ 1;
605 if (sent
> sizeof(buf
) - count
)
607 sent
= sizeof(buf
) - count
;
610 if (cli_write(c
, fnum
, 0, buf
+count
, count
, (size_t)sent
) != sent
) {
611 printf("write failed (%s)\n", cli_errstr(c
));
617 sent
= cli_read(c
, fnum
, buf_rd
+count
, count
,
621 printf("read failed offset:%d size:%ld (%s)\n",
622 count
, (unsigned long)sizeof(buf
)-count
,
629 if (memcmp(buf_rd
+count
, buf
+count
, sent
) != 0)
631 printf("read/write compare failed\n");
632 printf("offset: %d req %ld recvd %ld\n", count
, (unsigned long)sizeof(buf
)-count
, (unsigned long)sent
);
641 if (!NT_STATUS_IS_OK(cli_close(c
, fnum
))) {
642 printf("close failed (%s)\n", cli_errstr(c
));
649 static bool rw_torture2(struct cli_state
*c1
, struct cli_state
*c2
)
651 const char *lockfname
= "\\torture2.lck";
660 if (!NT_STATUS_IS_OK(cli_unlink(c1
, lockfname
, aSYSTEM
| aHIDDEN
))) {
661 printf("unlink failed (%s) (normal, this file should not exist)\n", cli_errstr(c1
));
664 if (!NT_STATUS_IS_OK(cli_open(c1
, lockfname
, O_RDWR
| O_CREAT
| O_EXCL
,
665 DENY_NONE
, &fnum1
))) {
666 printf("first open read/write of %s failed (%s)\n",
667 lockfname
, cli_errstr(c1
));
670 if (!NT_STATUS_IS_OK(cli_open(c2
, lockfname
, O_RDONLY
,
671 DENY_NONE
, &fnum2
))) {
672 printf("second open read-only of %s failed (%s)\n",
673 lockfname
, cli_errstr(c2
));
674 cli_close(c1
, fnum1
);
678 for (i
=0;i
<torture_numops
;i
++)
680 size_t buf_size
= ((unsigned)sys_random()%(sizeof(buf
)-1))+ 1;
682 printf("%d\r", i
); fflush(stdout
);
685 generate_random_buffer((unsigned char *)buf
, buf_size
);
687 if (cli_write(c1
, fnum1
, 0, buf
, 0, buf_size
) != buf_size
) {
688 printf("write failed (%s)\n", cli_errstr(c1
));
693 if ((bytes_read
= cli_read(c2
, fnum2
, buf_rd
, 0, buf_size
)) != buf_size
) {
694 printf("read failed (%s)\n", cli_errstr(c2
));
695 printf("read %d, expected %ld\n", (int)bytes_read
,
696 (unsigned long)buf_size
);
701 if (memcmp(buf_rd
, buf
, buf_size
) != 0)
703 printf("read/write compare failed\n");
709 if (!NT_STATUS_IS_OK(cli_close(c2
, fnum2
))) {
710 printf("close failed (%s)\n", cli_errstr(c2
));
713 if (!NT_STATUS_IS_OK(cli_close(c1
, fnum1
))) {
714 printf("close failed (%s)\n", cli_errstr(c1
));
718 if (!NT_STATUS_IS_OK(cli_unlink(c1
, lockfname
, aSYSTEM
| aHIDDEN
))) {
719 printf("unlink failed (%s)\n", cli_errstr(c1
));
726 static bool run_readwritetest(int dummy
)
728 struct cli_state
*cli1
, *cli2
;
729 bool test1
, test2
= False
;
731 if (!torture_open_connection(&cli1
, 0) || !torture_open_connection(&cli2
, 1)) {
734 cli_sockopt(cli1
, sockops
);
735 cli_sockopt(cli2
, sockops
);
737 printf("starting readwritetest\n");
739 test1
= rw_torture2(cli1
, cli2
);
740 printf("Passed readwritetest v1: %s\n", BOOLSTR(test1
));
743 test2
= rw_torture2(cli1
, cli1
);
744 printf("Passed readwritetest v2: %s\n", BOOLSTR(test2
));
747 if (!torture_close_connection(cli1
)) {
751 if (!torture_close_connection(cli2
)) {
755 return (test1
&& test2
);
758 static bool run_readwritemulti(int dummy
)
760 struct cli_state
*cli
;
765 cli_sockopt(cli
, sockops
);
767 printf("run_readwritemulti: fname %s\n", randomfname
);
768 test
= rw_torture3(cli
, randomfname
);
770 if (!torture_close_connection(cli
)) {
777 static bool run_readwritelarge(int dummy
)
779 static struct cli_state
*cli1
;
781 const char *lockfname
= "\\large.dat";
786 if (!torture_open_connection(&cli1
, 0)) {
789 cli_sockopt(cli1
, sockops
);
790 memset(buf
,'\0',sizeof(buf
));
792 cli1
->max_xmit
= 128*1024;
794 printf("starting readwritelarge\n");
796 cli_unlink(cli1
, lockfname
, aSYSTEM
| aHIDDEN
);
798 if (!NT_STATUS_IS_OK(cli_open(cli1
, lockfname
, O_RDWR
| O_CREAT
| O_EXCL
, DENY_NONE
, &fnum1
))) {
799 printf("open read/write of %s failed (%s)\n", lockfname
, cli_errstr(cli1
));
803 cli_write(cli1
, fnum1
, 0, buf
, 0, sizeof(buf
));
805 if (!cli_qfileinfo(cli1
, fnum1
, NULL
, &fsize
, NULL
, NULL
, NULL
, NULL
, NULL
)) {
806 printf("qfileinfo failed (%s)\n", cli_errstr(cli1
));
810 if (fsize
== sizeof(buf
))
811 printf("readwritelarge test 1 succeeded (size = %lx)\n",
812 (unsigned long)fsize
);
814 printf("readwritelarge test 1 failed (size = %lx)\n",
815 (unsigned long)fsize
);
819 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
820 printf("close failed (%s)\n", cli_errstr(cli1
));
824 if (!NT_STATUS_IS_OK(cli_unlink(cli1
, lockfname
, aSYSTEM
| aHIDDEN
))) {
825 printf("unlink failed (%s)\n", cli_errstr(cli1
));
829 if (!NT_STATUS_IS_OK(cli_open(cli1
, lockfname
, O_RDWR
| O_CREAT
| O_EXCL
, DENY_NONE
, &fnum1
))) {
830 printf("open read/write of %s failed (%s)\n", lockfname
, cli_errstr(cli1
));
834 cli1
->max_xmit
= 4*1024;
836 cli_smbwrite(cli1
, fnum1
, buf
, 0, sizeof(buf
));
838 if (!cli_qfileinfo(cli1
, fnum1
, NULL
, &fsize
, NULL
, NULL
, NULL
, NULL
, NULL
)) {
839 printf("qfileinfo failed (%s)\n", cli_errstr(cli1
));
843 if (fsize
== sizeof(buf
))
844 printf("readwritelarge test 2 succeeded (size = %lx)\n",
845 (unsigned long)fsize
);
847 printf("readwritelarge test 2 failed (size = %lx)\n",
848 (unsigned long)fsize
);
853 /* ToDo - set allocation. JRA */
854 if(!cli_set_allocation_size(cli1
, fnum1
, 0)) {
855 printf("set allocation size to zero failed (%s)\n", cli_errstr(&cli1
));
858 if (!cli_qfileinfo(cli1
, fnum1
, NULL
, &fsize
, NULL
, NULL
, NULL
, NULL
, NULL
)) {
859 printf("qfileinfo failed (%s)\n", cli_errstr(cli1
));
863 printf("readwritelarge test 3 (truncate test) succeeded (size = %x)\n", fsize
);
866 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
867 printf("close failed (%s)\n", cli_errstr(cli1
));
871 if (!torture_close_connection(cli1
)) {
880 #define ival(s) strtol(s, NULL, 0)
882 /* run a test that simulates an approximate netbench client load */
883 static bool run_netbench(int client
)
885 struct cli_state
*cli
;
890 const char *params
[20];
897 cli_sockopt(cli
, sockops
);
901 slprintf(cname
,sizeof(cname
)-1, "client%d", client
);
903 f
= fopen(client_txt
, "r");
910 while (fgets(line
, sizeof(line
)-1, f
)) {
914 line
[strlen(line
)-1] = 0;
916 /* printf("[%d] %s\n", line_count, line); */
918 all_string_sub(line
,"client1", cname
, sizeof(line
));
920 /* parse the command parameters */
921 params
[0] = strtok_r(line
, " ", &saveptr
);
923 while (params
[i
]) params
[++i
] = strtok_r(NULL
, " ", &saveptr
);
929 if (!strncmp(params
[0],"SMB", 3)) {
930 printf("ERROR: You are using a dbench 1 load file\n");
934 if (!strcmp(params
[0],"NTCreateX")) {
935 nb_createx(params
[1], ival(params
[2]), ival(params
[3]),
937 } else if (!strcmp(params
[0],"Close")) {
938 nb_close(ival(params
[1]));
939 } else if (!strcmp(params
[0],"Rename")) {
940 nb_rename(params
[1], params
[2]);
941 } else if (!strcmp(params
[0],"Unlink")) {
942 nb_unlink(params
[1]);
943 } else if (!strcmp(params
[0],"Deltree")) {
944 nb_deltree(params
[1]);
945 } else if (!strcmp(params
[0],"Rmdir")) {
947 } else if (!strcmp(params
[0],"QUERY_PATH_INFORMATION")) {
948 nb_qpathinfo(params
[1]);
949 } else if (!strcmp(params
[0],"QUERY_FILE_INFORMATION")) {
950 nb_qfileinfo(ival(params
[1]));
951 } else if (!strcmp(params
[0],"QUERY_FS_INFORMATION")) {
952 nb_qfsinfo(ival(params
[1]));
953 } else if (!strcmp(params
[0],"FIND_FIRST")) {
954 nb_findfirst(params
[1]);
955 } else if (!strcmp(params
[0],"WriteX")) {
956 nb_writex(ival(params
[1]),
957 ival(params
[2]), ival(params
[3]), ival(params
[4]));
958 } else if (!strcmp(params
[0],"ReadX")) {
959 nb_readx(ival(params
[1]),
960 ival(params
[2]), ival(params
[3]), ival(params
[4]));
961 } else if (!strcmp(params
[0],"Flush")) {
962 nb_flush(ival(params
[1]));
964 printf("Unknown operation %s\n", params
[0]);
972 if (!torture_close_connection(cli
)) {
980 /* run a test that simulates an approximate netbench client load */
981 static bool run_nbench(int dummy
)
990 signal(SIGALRM
, nb_alarm
);
992 t
= create_procs(run_netbench
, &correct
);
995 printf("\nThroughput %g MB/sec\n",
996 1.0e-6 * nbio_total() / t
);
1002 This test checks for two things:
1004 1) correct support for retaining locks over a close (ie. the server
1005 must not use posix semantics)
1006 2) support for lock timeouts
1008 static bool run_locktest1(int dummy
)
1010 struct cli_state
*cli1
, *cli2
;
1011 const char *fname
= "\\lockt1.lck";
1012 uint16_t fnum1
, fnum2
, fnum3
;
1014 unsigned lock_timeout
;
1016 if (!torture_open_connection(&cli1
, 0) || !torture_open_connection(&cli2
, 1)) {
1019 cli_sockopt(cli1
, sockops
);
1020 cli_sockopt(cli2
, sockops
);
1022 printf("starting locktest1\n");
1024 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
1026 if (!NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
))) {
1027 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
1030 if (!NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
, &fnum2
))) {
1031 printf("open2 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
1034 if (!NT_STATUS_IS_OK(cli_open(cli2
, fname
, O_RDWR
, DENY_NONE
, &fnum3
))) {
1035 printf("open3 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
1039 if (!cli_lock(cli1
, fnum1
, 0, 4, 0, WRITE_LOCK
)) {
1040 printf("lock1 failed (%s)\n", cli_errstr(cli1
));
1045 if (cli_lock(cli2
, fnum3
, 0, 4, 0, WRITE_LOCK
)) {
1046 printf("lock2 succeeded! This is a locking bug\n");
1049 if (!check_error(__LINE__
, cli2
, ERRDOS
, ERRlock
,
1050 NT_STATUS_LOCK_NOT_GRANTED
)) return False
;
1054 lock_timeout
= (1 + (random() % 20));
1055 printf("Testing lock timeout with timeout=%u\n", lock_timeout
);
1057 if (cli_lock(cli2
, fnum3
, 0, 4, lock_timeout
* 1000, WRITE_LOCK
)) {
1058 printf("lock3 succeeded! This is a locking bug\n");
1061 if (!check_error(__LINE__
, cli2
, ERRDOS
, ERRlock
,
1062 NT_STATUS_FILE_LOCK_CONFLICT
)) return False
;
1066 if (ABS(t2
- t1
) < lock_timeout
-1) {
1067 printf("error: This server appears not to support timed lock requests\n");
1070 printf("server slept for %u seconds for a %u second timeout\n",
1071 (unsigned int)(t2
-t1
), lock_timeout
);
1073 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum2
))) {
1074 printf("close1 failed (%s)\n", cli_errstr(cli1
));
1078 if (cli_lock(cli2
, fnum3
, 0, 4, 0, WRITE_LOCK
)) {
1079 printf("lock4 succeeded! This is a locking bug\n");
1082 if (!check_error(__LINE__
, cli2
, ERRDOS
, ERRlock
,
1083 NT_STATUS_FILE_LOCK_CONFLICT
)) return False
;
1086 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
1087 printf("close2 failed (%s)\n", cli_errstr(cli1
));
1091 if (!NT_STATUS_IS_OK(cli_close(cli2
, fnum3
))) {
1092 printf("close3 failed (%s)\n", cli_errstr(cli2
));
1096 if (!NT_STATUS_IS_OK(cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
))) {
1097 printf("unlink failed (%s)\n", cli_errstr(cli1
));
1102 if (!torture_close_connection(cli1
)) {
1106 if (!torture_close_connection(cli2
)) {
1110 printf("Passed locktest1\n");
1115 this checks to see if a secondary tconx can use open files from an
1118 static bool run_tcon_test(int dummy
)
1120 static struct cli_state
*cli
;
1121 const char *fname
= "\\tcontest.tmp";
1123 uint16 cnum1
, cnum2
, cnum3
;
1124 uint16 vuid1
, vuid2
;
1129 memset(buf
, '\0', sizeof(buf
));
1131 if (!torture_open_connection(&cli
, 0)) {
1134 cli_sockopt(cli
, sockops
);
1136 printf("starting tcontest\n");
1138 cli_unlink(cli
, fname
, aSYSTEM
| aHIDDEN
);
1140 if (!NT_STATUS_IS_OK(cli_open(cli
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
))) {
1141 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli
));
1148 if (cli_write(cli
, fnum1
, 0, buf
, 130, 4) != 4) {
1149 printf("initial write failed (%s)", cli_errstr(cli
));
1153 status
= cli_tcon_andx(cli
, share
, "?????",
1154 password
, strlen(password
)+1);
1155 if (!NT_STATUS_IS_OK(status
)) {
1156 printf("%s refused 2nd tree connect (%s)\n", host
,
1163 cnum3
= MAX(cnum1
, cnum2
) + 1; /* any invalid number */
1164 vuid2
= cli
->vuid
+ 1;
1166 /* try a write with the wrong tid */
1169 if (cli_write(cli
, fnum1
, 0, buf
, 130, 4) == 4) {
1170 printf("* server allows write with wrong TID\n");
1173 printf("server fails write with wrong TID : %s\n", cli_errstr(cli
));
1177 /* try a write with an invalid tid */
1180 if (cli_write(cli
, fnum1
, 0, buf
, 130, 4) == 4) {
1181 printf("* server allows write with invalid TID\n");
1184 printf("server fails write with invalid TID : %s\n", cli_errstr(cli
));
1187 /* try a write with an invalid vuid */
1191 if (cli_write(cli
, fnum1
, 0, buf
, 130, 4) == 4) {
1192 printf("* server allows write with invalid VUID\n");
1195 printf("server fails write with invalid VUID : %s\n", cli_errstr(cli
));
1201 if (!NT_STATUS_IS_OK(cli_close(cli
, fnum1
))) {
1202 printf("close failed (%s)\n", cli_errstr(cli
));
1208 if (!cli_tdis(cli
)) {
1209 printf("secondary tdis failed (%s)\n", cli_errstr(cli
));
1215 if (!torture_close_connection(cli
)) {
1224 checks for old style tcon support
1226 static bool run_tcon2_test(int dummy
)
1228 static struct cli_state
*cli
;
1229 uint16 cnum
, max_xmit
;
1233 if (!torture_open_connection(&cli
, 0)) {
1236 cli_sockopt(cli
, sockops
);
1238 printf("starting tcon2 test\n");
1240 if (asprintf(&service
, "\\\\%s\\%s", host
, share
) == -1) {
1244 status
= cli_raw_tcon(cli
, service
, password
, "?????", &max_xmit
, &cnum
);
1246 if (!NT_STATUS_IS_OK(status
)) {
1247 printf("tcon2 failed : %s\n", cli_errstr(cli
));
1249 printf("tcon OK : max_xmit=%d cnum=%d tid=%d\n",
1250 (int)max_xmit
, (int)cnum
, SVAL(cli
->inbuf
, smb_tid
));
1253 if (!torture_close_connection(cli
)) {
1257 printf("Passed tcon2 test\n");
1261 static bool tcon_devtest(struct cli_state
*cli
,
1262 const char *myshare
, const char *devtype
,
1263 const char *return_devtype
,
1264 NTSTATUS expected_error
)
1269 status
= cli_tcon_andx(cli
, myshare
, devtype
,
1270 password
, strlen(password
)+1);
1272 if (NT_STATUS_IS_OK(expected_error
)) {
1273 if (NT_STATUS_IS_OK(status
)) {
1274 if (strcmp(cli
->dev
, return_devtype
) == 0) {
1277 printf("tconX to share %s with type %s "
1278 "succeeded but returned the wrong "
1279 "device type (got [%s] but should have got [%s])\n",
1280 myshare
, devtype
, cli
->dev
, return_devtype
);
1284 printf("tconX to share %s with type %s "
1285 "should have succeeded but failed\n",
1291 if (NT_STATUS_IS_OK(status
)) {
1292 printf("tconx to share %s with type %s "
1293 "should have failed but succeeded\n",
1297 if (NT_STATUS_EQUAL(cli_nt_error(cli
),
1301 printf("Returned unexpected error\n");
1310 checks for correct tconX support
1312 static bool run_tcon_devtype_test(int dummy
)
1314 static struct cli_state
*cli1
= NULL
;
1320 status
= cli_full_connection(&cli1
, myname
,
1321 host
, NULL
, port_to_use
,
1323 username
, workgroup
,
1324 password
, flags
, Undefined
, &retry
);
1326 if (!NT_STATUS_IS_OK(status
)) {
1327 printf("could not open connection\n");
1331 if (!tcon_devtest(cli1
, "IPC$", "A:", NULL
, NT_STATUS_BAD_DEVICE_TYPE
))
1334 if (!tcon_devtest(cli1
, "IPC$", "?????", "IPC", NT_STATUS_OK
))
1337 if (!tcon_devtest(cli1
, "IPC$", "LPT:", NULL
, NT_STATUS_BAD_DEVICE_TYPE
))
1340 if (!tcon_devtest(cli1
, "IPC$", "IPC", "IPC", NT_STATUS_OK
))
1343 if (!tcon_devtest(cli1
, "IPC$", "FOOBA", NULL
, NT_STATUS_BAD_DEVICE_TYPE
))
1346 if (!tcon_devtest(cli1
, share
, "A:", "A:", NT_STATUS_OK
))
1349 if (!tcon_devtest(cli1
, share
, "?????", "A:", NT_STATUS_OK
))
1352 if (!tcon_devtest(cli1
, share
, "LPT:", NULL
, NT_STATUS_BAD_DEVICE_TYPE
))
1355 if (!tcon_devtest(cli1
, share
, "IPC", NULL
, NT_STATUS_BAD_DEVICE_TYPE
))
1358 if (!tcon_devtest(cli1
, share
, "FOOBA", NULL
, NT_STATUS_BAD_DEVICE_TYPE
))
1364 printf("Passed tcondevtest\n");
1371 This test checks that
1373 1) the server supports multiple locking contexts on the one SMB
1374 connection, distinguished by PID.
1376 2) the server correctly fails overlapping locks made by the same PID (this
1377 goes against POSIX behaviour, which is why it is tricky to implement)
1379 3) the server denies unlock requests by an incorrect client PID
1381 static bool run_locktest2(int dummy
)
1383 static struct cli_state
*cli
;
1384 const char *fname
= "\\lockt2.lck";
1385 uint16_t fnum1
, fnum2
, fnum3
;
1386 bool correct
= True
;
1388 if (!torture_open_connection(&cli
, 0)) {
1392 cli_sockopt(cli
, sockops
);
1394 printf("starting locktest2\n");
1396 cli_unlink(cli
, fname
, aSYSTEM
| aHIDDEN
);
1400 if (!NT_STATUS_IS_OK(cli_open(cli
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
))) {
1401 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli
));
1405 if (!NT_STATUS_IS_OK(cli_open(cli
, fname
, O_RDWR
, DENY_NONE
, &fnum2
))) {
1406 printf("open2 of %s failed (%s)\n", fname
, cli_errstr(cli
));
1412 if (!NT_STATUS_IS_OK(cli_open(cli
, fname
, O_RDWR
, DENY_NONE
, &fnum3
))) {
1413 printf("open3 of %s failed (%s)\n", fname
, cli_errstr(cli
));
1419 if (!cli_lock(cli
, fnum1
, 0, 4, 0, WRITE_LOCK
)) {
1420 printf("lock1 failed (%s)\n", cli_errstr(cli
));
1424 if (cli_lock(cli
, fnum1
, 0, 4, 0, WRITE_LOCK
)) {
1425 printf("WRITE lock1 succeeded! This is a locking bug\n");
1428 if (!check_error(__LINE__
, cli
, ERRDOS
, ERRlock
,
1429 NT_STATUS_LOCK_NOT_GRANTED
)) return False
;
1432 if (cli_lock(cli
, fnum2
, 0, 4, 0, WRITE_LOCK
)) {
1433 printf("WRITE lock2 succeeded! This is a locking bug\n");
1436 if (!check_error(__LINE__
, cli
, ERRDOS
, ERRlock
,
1437 NT_STATUS_LOCK_NOT_GRANTED
)) return False
;
1440 if (cli_lock(cli
, fnum2
, 0, 4, 0, READ_LOCK
)) {
1441 printf("READ lock2 succeeded! This is a locking bug\n");
1444 if (!check_error(__LINE__
, cli
, ERRDOS
, ERRlock
,
1445 NT_STATUS_FILE_LOCK_CONFLICT
)) return False
;
1448 if (!cli_lock(cli
, fnum1
, 100, 4, 0, WRITE_LOCK
)) {
1449 printf("lock at 100 failed (%s)\n", cli_errstr(cli
));
1452 if (NT_STATUS_IS_OK(cli_unlock(cli
, fnum1
, 100, 4))) {
1453 printf("unlock at 100 succeeded! This is a locking bug\n");
1457 if (NT_STATUS_IS_OK(cli_unlock(cli
, fnum1
, 0, 4))) {
1458 printf("unlock1 succeeded! This is a locking bug\n");
1461 if (!check_error(__LINE__
, cli
,
1463 NT_STATUS_RANGE_NOT_LOCKED
)) return False
;
1466 if (NT_STATUS_IS_OK(cli_unlock(cli
, fnum1
, 0, 8))) {
1467 printf("unlock2 succeeded! This is a locking bug\n");
1470 if (!check_error(__LINE__
, cli
,
1472 NT_STATUS_RANGE_NOT_LOCKED
)) return False
;
1475 if (cli_lock(cli
, fnum3
, 0, 4, 0, WRITE_LOCK
)) {
1476 printf("lock3 succeeded! This is a locking bug\n");
1479 if (!check_error(__LINE__
, cli
, ERRDOS
, ERRlock
, NT_STATUS_LOCK_NOT_GRANTED
)) return False
;
1484 if (!NT_STATUS_IS_OK(cli_close(cli
, fnum1
))) {
1485 printf("close1 failed (%s)\n", cli_errstr(cli
));
1489 if (!NT_STATUS_IS_OK(cli_close(cli
, fnum2
))) {
1490 printf("close2 failed (%s)\n", cli_errstr(cli
));
1494 if (!NT_STATUS_IS_OK(cli_close(cli
, fnum3
))) {
1495 printf("close3 failed (%s)\n", cli_errstr(cli
));
1499 if (!torture_close_connection(cli
)) {
1503 printf("locktest2 finished\n");
1510 This test checks that
1512 1) the server supports the full offset range in lock requests
1514 static bool run_locktest3(int dummy
)
1516 static struct cli_state
*cli1
, *cli2
;
1517 const char *fname
= "\\lockt3.lck";
1518 uint16_t fnum1
, fnum2
;
1521 bool correct
= True
;
1523 #define NEXT_OFFSET offset += (~(uint32)0) / torture_numops
1525 if (!torture_open_connection(&cli1
, 0) || !torture_open_connection(&cli2
, 1)) {
1528 cli_sockopt(cli1
, sockops
);
1529 cli_sockopt(cli2
, sockops
);
1531 printf("starting locktest3\n");
1533 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
1535 if (!NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
))) {
1536 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
1539 if (!NT_STATUS_IS_OK(cli_open(cli2
, fname
, O_RDWR
, DENY_NONE
, &fnum2
))) {
1540 printf("open2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
1544 for (offset
=i
=0;i
<torture_numops
;i
++) {
1546 if (!cli_lock(cli1
, fnum1
, offset
-1, 1, 0, WRITE_LOCK
)) {
1547 printf("lock1 %d failed (%s)\n",
1553 if (!cli_lock(cli2
, fnum2
, offset
-2, 1, 0, WRITE_LOCK
)) {
1554 printf("lock2 %d failed (%s)\n",
1561 for (offset
=i
=0;i
<torture_numops
;i
++) {
1564 if (cli_lock(cli1
, fnum1
, offset
-2, 1, 0, WRITE_LOCK
)) {
1565 printf("error: lock1 %d succeeded!\n", i
);
1569 if (cli_lock(cli2
, fnum2
, offset
-1, 1, 0, WRITE_LOCK
)) {
1570 printf("error: lock2 %d succeeded!\n", i
);
1574 if (cli_lock(cli1
, fnum1
, offset
-1, 1, 0, WRITE_LOCK
)) {
1575 printf("error: lock3 %d succeeded!\n", i
);
1579 if (cli_lock(cli2
, fnum2
, offset
-2, 1, 0, WRITE_LOCK
)) {
1580 printf("error: lock4 %d succeeded!\n", i
);
1585 for (offset
=i
=0;i
<torture_numops
;i
++) {
1588 if (!NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, offset
-1, 1))) {
1589 printf("unlock1 %d failed (%s)\n",
1595 if (!NT_STATUS_IS_OK(cli_unlock(cli2
, fnum2
, offset
-2, 1))) {
1596 printf("unlock2 %d failed (%s)\n",
1603 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
1604 printf("close1 failed (%s)\n", cli_errstr(cli1
));
1608 if (!NT_STATUS_IS_OK(cli_close(cli2
, fnum2
))) {
1609 printf("close2 failed (%s)\n", cli_errstr(cli2
));
1613 if (!NT_STATUS_IS_OK(cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
))) {
1614 printf("unlink failed (%s)\n", cli_errstr(cli1
));
1618 if (!torture_close_connection(cli1
)) {
1622 if (!torture_close_connection(cli2
)) {
1626 printf("finished locktest3\n");
1631 #define EXPECTED(ret, v) if ((ret) != (v)) { \
1632 printf("** "); correct = False; \
1636 looks at overlapping locks
1638 static bool run_locktest4(int dummy
)
1640 static struct cli_state
*cli1
, *cli2
;
1641 const char *fname
= "\\lockt4.lck";
1642 uint16_t fnum1
, fnum2
, f
;
1645 bool correct
= True
;
1647 if (!torture_open_connection(&cli1
, 0) || !torture_open_connection(&cli2
, 1)) {
1651 cli_sockopt(cli1
, sockops
);
1652 cli_sockopt(cli2
, sockops
);
1654 printf("starting locktest4\n");
1656 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
1658 cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
);
1659 cli_open(cli2
, fname
, O_RDWR
, DENY_NONE
, &fnum2
);
1661 memset(buf
, 0, sizeof(buf
));
1663 if (cli_write(cli1
, fnum1
, 0, buf
, 0, sizeof(buf
)) != sizeof(buf
)) {
1664 printf("Failed to create file\n");
1669 ret
= cli_lock(cli1
, fnum1
, 0, 4, 0, WRITE_LOCK
) &&
1670 cli_lock(cli1
, fnum1
, 2, 4, 0, WRITE_LOCK
);
1671 EXPECTED(ret
, False
);
1672 printf("the same process %s set overlapping write locks\n", ret
?"can":"cannot");
1674 ret
= cli_lock(cli1
, fnum1
, 10, 4, 0, READ_LOCK
) &&
1675 cli_lock(cli1
, fnum1
, 12, 4, 0, READ_LOCK
);
1676 EXPECTED(ret
, True
);
1677 printf("the same process %s set overlapping read locks\n", ret
?"can":"cannot");
1679 ret
= cli_lock(cli1
, fnum1
, 20, 4, 0, WRITE_LOCK
) &&
1680 cli_lock(cli2
, fnum2
, 22, 4, 0, WRITE_LOCK
);
1681 EXPECTED(ret
, False
);
1682 printf("a different connection %s set overlapping write locks\n", ret
?"can":"cannot");
1684 ret
= cli_lock(cli1
, fnum1
, 30, 4, 0, READ_LOCK
) &&
1685 cli_lock(cli2
, fnum2
, 32, 4, 0, READ_LOCK
);
1686 EXPECTED(ret
, True
);
1687 printf("a different connection %s set overlapping read locks\n", ret
?"can":"cannot");
1689 ret
= (cli_setpid(cli1
, 1), cli_lock(cli1
, fnum1
, 40, 4, 0, WRITE_LOCK
)) &&
1690 (cli_setpid(cli1
, 2), cli_lock(cli1
, fnum1
, 42, 4, 0, WRITE_LOCK
));
1691 EXPECTED(ret
, False
);
1692 printf("a different pid %s set overlapping write locks\n", ret
?"can":"cannot");
1694 ret
= (cli_setpid(cli1
, 1), cli_lock(cli1
, fnum1
, 50, 4, 0, READ_LOCK
)) &&
1695 (cli_setpid(cli1
, 2), cli_lock(cli1
, fnum1
, 52, 4, 0, READ_LOCK
));
1696 EXPECTED(ret
, True
);
1697 printf("a different pid %s set overlapping read locks\n", ret
?"can":"cannot");
1699 ret
= cli_lock(cli1
, fnum1
, 60, 4, 0, READ_LOCK
) &&
1700 cli_lock(cli1
, fnum1
, 60, 4, 0, READ_LOCK
);
1701 EXPECTED(ret
, True
);
1702 printf("the same process %s set the same read lock twice\n", ret
?"can":"cannot");
1704 ret
= cli_lock(cli1
, fnum1
, 70, 4, 0, WRITE_LOCK
) &&
1705 cli_lock(cli1
, fnum1
, 70, 4, 0, WRITE_LOCK
);
1706 EXPECTED(ret
, False
);
1707 printf("the same process %s set the same write lock twice\n", ret
?"can":"cannot");
1709 ret
= cli_lock(cli1
, fnum1
, 80, 4, 0, READ_LOCK
) &&
1710 cli_lock(cli1
, fnum1
, 80, 4, 0, WRITE_LOCK
);
1711 EXPECTED(ret
, False
);
1712 printf("the same process %s overlay a read lock with a write lock\n", ret
?"can":"cannot");
1714 ret
= cli_lock(cli1
, fnum1
, 90, 4, 0, WRITE_LOCK
) &&
1715 cli_lock(cli1
, fnum1
, 90, 4, 0, READ_LOCK
);
1716 EXPECTED(ret
, True
);
1717 printf("the same process %s overlay a write lock with a read lock\n", ret
?"can":"cannot");
1719 ret
= (cli_setpid(cli1
, 1), cli_lock(cli1
, fnum1
, 100, 4, 0, WRITE_LOCK
)) &&
1720 (cli_setpid(cli1
, 2), cli_lock(cli1
, fnum1
, 100, 4, 0, READ_LOCK
));
1721 EXPECTED(ret
, False
);
1722 printf("a different pid %s overlay a write lock with a read lock\n", ret
?"can":"cannot");
1724 ret
= cli_lock(cli1
, fnum1
, 110, 4, 0, READ_LOCK
) &&
1725 cli_lock(cli1
, fnum1
, 112, 4, 0, READ_LOCK
) &&
1726 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 110, 6));
1727 EXPECTED(ret
, False
);
1728 printf("the same process %s coalesce read locks\n", ret
?"can":"cannot");
1731 ret
= cli_lock(cli1
, fnum1
, 120, 4, 0, WRITE_LOCK
) &&
1732 (cli_read(cli2
, fnum2
, buf
, 120, 4) == 4);
1733 EXPECTED(ret
, False
);
1734 printf("this server %s strict write locking\n", ret
?"doesn't do":"does");
1736 ret
= cli_lock(cli1
, fnum1
, 130, 4, 0, READ_LOCK
) &&
1737 (cli_write(cli2
, fnum2
, 0, buf
, 130, 4) == 4);
1738 EXPECTED(ret
, False
);
1739 printf("this server %s strict read locking\n", ret
?"doesn't do":"does");
1742 ret
= cli_lock(cli1
, fnum1
, 140, 4, 0, READ_LOCK
) &&
1743 cli_lock(cli1
, fnum1
, 140, 4, 0, READ_LOCK
) &&
1744 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 140, 4)) &&
1745 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 140, 4));
1746 EXPECTED(ret
, True
);
1747 printf("this server %s do recursive read locking\n", ret
?"does":"doesn't");
1750 ret
= cli_lock(cli1
, fnum1
, 150, 4, 0, WRITE_LOCK
) &&
1751 cli_lock(cli1
, fnum1
, 150, 4, 0, READ_LOCK
) &&
1752 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 150, 4)) &&
1753 (cli_read(cli2
, fnum2
, buf
, 150, 4) == 4) &&
1754 !(cli_write(cli2
, fnum2
, 0, buf
, 150, 4) == 4) &&
1755 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 150, 4));
1756 EXPECTED(ret
, True
);
1757 printf("this server %s do recursive lock overlays\n", ret
?"does":"doesn't");
1759 ret
= cli_lock(cli1
, fnum1
, 160, 4, 0, READ_LOCK
) &&
1760 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 160, 4)) &&
1761 (cli_write(cli2
, fnum2
, 0, buf
, 160, 4) == 4) &&
1762 (cli_read(cli2
, fnum2
, buf
, 160, 4) == 4);
1763 EXPECTED(ret
, True
);
1764 printf("the same process %s remove a read lock using write locking\n", ret
?"can":"cannot");
1766 ret
= cli_lock(cli1
, fnum1
, 170, 4, 0, WRITE_LOCK
) &&
1767 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 170, 4)) &&
1768 (cli_write(cli2
, fnum2
, 0, buf
, 170, 4) == 4) &&
1769 (cli_read(cli2
, fnum2
, buf
, 170, 4) == 4);
1770 EXPECTED(ret
, True
);
1771 printf("the same process %s remove a write lock using read locking\n", ret
?"can":"cannot");
1773 ret
= cli_lock(cli1
, fnum1
, 190, 4, 0, WRITE_LOCK
) &&
1774 cli_lock(cli1
, fnum1
, 190, 4, 0, READ_LOCK
) &&
1775 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 190, 4)) &&
1776 !(cli_write(cli2
, fnum2
, 0, buf
, 190, 4) == 4) &&
1777 (cli_read(cli2
, fnum2
, buf
, 190, 4) == 4);
1778 EXPECTED(ret
, True
);
1779 printf("the same process %s remove the first lock first\n", ret
?"does":"doesn't");
1781 cli_close(cli1
, fnum1
);
1782 cli_close(cli2
, fnum2
);
1783 cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
, &fnum1
);
1784 cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
, &f
);
1785 ret
= cli_lock(cli1
, fnum1
, 0, 8, 0, READ_LOCK
) &&
1786 cli_lock(cli1
, f
, 0, 1, 0, READ_LOCK
) &&
1787 NT_STATUS_IS_OK(cli_close(cli1
, fnum1
)) &&
1788 NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
, &fnum1
)) &&
1789 cli_lock(cli1
, fnum1
, 7, 1, 0, WRITE_LOCK
);
1791 cli_close(cli1
, fnum1
);
1792 EXPECTED(ret
, True
);
1793 printf("the server %s have the NT byte range lock bug\n", !ret
?"does":"doesn't");
1796 cli_close(cli1
, fnum1
);
1797 cli_close(cli2
, fnum2
);
1798 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
1799 torture_close_connection(cli1
);
1800 torture_close_connection(cli2
);
1802 printf("finished locktest4\n");
1807 looks at lock upgrade/downgrade.
1809 static bool run_locktest5(int dummy
)
1811 static struct cli_state
*cli1
, *cli2
;
1812 const char *fname
= "\\lockt5.lck";
1813 uint16_t fnum1
, fnum2
, fnum3
;
1816 bool correct
= True
;
1818 if (!torture_open_connection(&cli1
, 0) || !torture_open_connection(&cli2
, 1)) {
1822 cli_sockopt(cli1
, sockops
);
1823 cli_sockopt(cli2
, sockops
);
1825 printf("starting locktest5\n");
1827 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
1829 cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
);
1830 cli_open(cli2
, fname
, O_RDWR
, DENY_NONE
, &fnum2
);
1831 cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
, &fnum3
);
1833 memset(buf
, 0, sizeof(buf
));
1835 if (cli_write(cli1
, fnum1
, 0, buf
, 0, sizeof(buf
)) != sizeof(buf
)) {
1836 printf("Failed to create file\n");
1841 /* Check for NT bug... */
1842 ret
= cli_lock(cli1
, fnum1
, 0, 8, 0, READ_LOCK
) &&
1843 cli_lock(cli1
, fnum3
, 0, 1, 0, READ_LOCK
);
1844 cli_close(cli1
, fnum1
);
1845 cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
, &fnum1
);
1846 ret
= cli_lock(cli1
, fnum1
, 7, 1, 0, WRITE_LOCK
);
1847 EXPECTED(ret
, True
);
1848 printf("this server %s the NT locking bug\n", ret
? "doesn't have" : "has");
1849 cli_close(cli1
, fnum1
);
1850 cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
, &fnum1
);
1851 cli_unlock(cli1
, fnum3
, 0, 1);
1853 ret
= cli_lock(cli1
, fnum1
, 0, 4, 0, WRITE_LOCK
) &&
1854 cli_lock(cli1
, fnum1
, 1, 1, 0, READ_LOCK
);
1855 EXPECTED(ret
, True
);
1856 printf("the same process %s overlay a write with a read lock\n", ret
?"can":"cannot");
1858 ret
= cli_lock(cli2
, fnum2
, 0, 4, 0, READ_LOCK
);
1859 EXPECTED(ret
, False
);
1861 printf("a different processs %s get a read lock on the first process lock stack\n", ret
?"can":"cannot");
1863 /* Unlock the process 2 lock. */
1864 cli_unlock(cli2
, fnum2
, 0, 4);
1866 ret
= cli_lock(cli1
, fnum3
, 0, 4, 0, READ_LOCK
);
1867 EXPECTED(ret
, False
);
1869 printf("the same processs on a different fnum %s get a read lock\n", ret
?"can":"cannot");
1871 /* Unlock the process 1 fnum3 lock. */
1872 cli_unlock(cli1
, fnum3
, 0, 4);
1874 /* Stack 2 more locks here. */
1875 ret
= cli_lock(cli1
, fnum1
, 0, 4, 0, READ_LOCK
) &&
1876 cli_lock(cli1
, fnum1
, 0, 4, 0, READ_LOCK
);
1878 EXPECTED(ret
, True
);
1879 printf("the same process %s stack read locks\n", ret
?"can":"cannot");
1881 /* Unlock the first process lock, then check this was the WRITE lock that was
1884 ret
= NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 0, 4)) &&
1885 cli_lock(cli2
, fnum2
, 0, 4, 0, READ_LOCK
);
1887 EXPECTED(ret
, True
);
1888 printf("the first unlock removes the %s lock\n", ret
?"WRITE":"READ");
1890 /* Unlock the process 2 lock. */
1891 cli_unlock(cli2
, fnum2
, 0, 4);
1893 /* We should have 3 stacked locks here. Ensure we need to do 3 unlocks. */
1895 ret
= NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 1, 1)) &&
1896 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 0, 4)) &&
1897 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 0, 4));
1899 EXPECTED(ret
, True
);
1900 printf("the same process %s unlock the stack of 4 locks\n", ret
?"can":"cannot");
1902 /* Ensure the next unlock fails. */
1903 ret
= NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 0, 4));
1904 EXPECTED(ret
, False
);
1905 printf("the same process %s count the lock stack\n", !ret
?"can":"cannot");
1907 /* Ensure connection 2 can get a write lock. */
1908 ret
= cli_lock(cli2
, fnum2
, 0, 4, 0, WRITE_LOCK
);
1909 EXPECTED(ret
, True
);
1911 printf("a different processs %s get a write lock on the unlocked stack\n", ret
?"can":"cannot");
1915 cli_close(cli1
, fnum1
);
1916 cli_close(cli2
, fnum2
);
1917 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
1918 if (!torture_close_connection(cli1
)) {
1921 if (!torture_close_connection(cli2
)) {
1925 printf("finished locktest5\n");
1931 tries the unusual lockingX locktype bits
1933 static bool run_locktest6(int dummy
)
1935 static struct cli_state
*cli
;
1936 const char *fname
[1] = { "\\lock6.txt" };
1941 if (!torture_open_connection(&cli
, 0)) {
1945 cli_sockopt(cli
, sockops
);
1947 printf("starting locktest6\n");
1950 printf("Testing %s\n", fname
[i
]);
1952 cli_unlink(cli
, fname
[i
], aSYSTEM
| aHIDDEN
);
1954 cli_open(cli
, fname
[i
], O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum
);
1955 status
= cli_locktype(cli
, fnum
, 0, 8, 0, LOCKING_ANDX_CHANGE_LOCKTYPE
);
1956 cli_close(cli
, fnum
);
1957 printf("CHANGE_LOCKTYPE gave %s\n", nt_errstr(status
));
1959 cli_open(cli
, fname
[i
], O_RDWR
, DENY_NONE
, &fnum
);
1960 status
= cli_locktype(cli
, fnum
, 0, 8, 0, LOCKING_ANDX_CANCEL_LOCK
);
1961 cli_close(cli
, fnum
);
1962 printf("CANCEL_LOCK gave %s\n", nt_errstr(status
));
1964 cli_unlink(cli
, fname
[i
], aSYSTEM
| aHIDDEN
);
1967 torture_close_connection(cli
);
1969 printf("finished locktest6\n");
1973 static bool run_locktest7(int dummy
)
1975 struct cli_state
*cli1
;
1976 const char *fname
= "\\lockt7.lck";
1979 bool correct
= False
;
1981 if (!torture_open_connection(&cli1
, 0)) {
1985 cli_sockopt(cli1
, sockops
);
1987 printf("starting locktest7\n");
1989 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
1991 cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
);
1993 memset(buf
, 0, sizeof(buf
));
1995 if (cli_write(cli1
, fnum1
, 0, buf
, 0, sizeof(buf
)) != sizeof(buf
)) {
1996 printf("Failed to create file\n");
2000 cli_setpid(cli1
, 1);
2002 if (!cli_lock(cli1
, fnum1
, 130, 4, 0, READ_LOCK
)) {
2003 printf("Unable to apply read lock on range 130:4, error was %s\n", cli_errstr(cli1
));
2006 printf("pid1 successfully locked range 130:4 for READ\n");
2009 if (cli_read(cli1
, fnum1
, buf
, 130, 4) != 4) {
2010 printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(cli1
));
2013 printf("pid1 successfully read the range 130:4\n");
2016 if (cli_write(cli1
, fnum1
, 0, buf
, 130, 4) != 4) {
2017 printf("pid1 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1
));
2018 if (NT_STATUS_V(cli_nt_error(cli1
)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT
)) {
2019 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2023 printf("pid1 successfully wrote to the range 130:4 (should be denied)\n");
2027 cli_setpid(cli1
, 2);
2029 if (cli_read(cli1
, fnum1
, buf
, 130, 4) != 4) {
2030 printf("pid2 unable to read the range 130:4, error was %s\n", cli_errstr(cli1
));
2032 printf("pid2 successfully read the range 130:4\n");
2035 if (cli_write(cli1
, fnum1
, 0, buf
, 130, 4) != 4) {
2036 printf("pid2 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1
));
2037 if (NT_STATUS_V(cli_nt_error(cli1
)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT
)) {
2038 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2042 printf("pid2 successfully wrote to the range 130:4 (should be denied)\n");
2046 cli_setpid(cli1
, 1);
2047 cli_unlock(cli1
, fnum1
, 130, 4);
2049 if (!cli_lock(cli1
, fnum1
, 130, 4, 0, WRITE_LOCK
)) {
2050 printf("Unable to apply write lock on range 130:4, error was %s\n", cli_errstr(cli1
));
2053 printf("pid1 successfully locked range 130:4 for WRITE\n");
2056 if (cli_read(cli1
, fnum1
, buf
, 130, 4) != 4) {
2057 printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(cli1
));
2060 printf("pid1 successfully read the range 130:4\n");
2063 if (cli_write(cli1
, fnum1
, 0, buf
, 130, 4) != 4) {
2064 printf("pid1 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1
));
2067 printf("pid1 successfully wrote to the range 130:4\n");
2070 cli_setpid(cli1
, 2);
2072 if (cli_read(cli1
, fnum1
, buf
, 130, 4) != 4) {
2073 printf("pid2 unable to read the range 130:4, error was %s\n", cli_errstr(cli1
));
2074 if (NT_STATUS_V(cli_nt_error(cli1
)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT
)) {
2075 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2079 printf("pid2 successfully read the range 130:4 (should be denied)\n");
2083 if (cli_write(cli1
, fnum1
, 0, buf
, 130, 4) != 4) {
2084 printf("pid2 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1
));
2085 if (NT_STATUS_V(cli_nt_error(cli1
)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT
)) {
2086 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2090 printf("pid2 successfully wrote to the range 130:4 (should be denied)\n");
2094 cli_unlock(cli1
, fnum1
, 130, 0);
2098 cli_close(cli1
, fnum1
);
2099 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
2100 torture_close_connection(cli1
);
2102 printf("finished locktest7\n");
2107 * This demonstrates a problem with our use of GPFS share modes: A file
2108 * descriptor sitting in the pending close queue holding a GPFS share mode
2109 * blocks opening a file another time. Happens with Word 2007 temp files.
2110 * With "posix locking = yes" and "gpfs:sharemodes = yes" enabled, the third
2111 * open is denied with NT_STATUS_SHARING_VIOLATION.
2114 static bool run_locktest8(int dummy
)
2116 struct cli_state
*cli1
;
2117 const char *fname
= "\\lockt8.lck";
2118 uint16_t fnum1
, fnum2
;
2120 bool correct
= False
;
2123 if (!torture_open_connection(&cli1
, 0)) {
2127 cli_sockopt(cli1
, sockops
);
2129 printf("starting locktest8\n");
2131 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
2133 status
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_WRITE
,
2135 if (!NT_STATUS_IS_OK(status
)) {
2136 d_fprintf(stderr
, "cli_open returned %s\n", cli_errstr(cli1
));
2140 memset(buf
, 0, sizeof(buf
));
2142 status
= cli_open(cli1
, fname
, O_RDONLY
, DENY_NONE
, &fnum2
);
2143 if (!NT_STATUS_IS_OK(status
)) {
2144 d_fprintf(stderr
, "cli_open second time returned %s\n",
2149 if (!cli_lock(cli1
, fnum2
, 1, 1, 0, READ_LOCK
)) {
2150 printf("Unable to apply read lock on range 1:1, error was "
2151 "%s\n", cli_errstr(cli1
));
2155 status
= cli_close(cli1
, fnum1
);
2156 if (!NT_STATUS_IS_OK(status
)) {
2157 d_fprintf(stderr
, "cli_close(fnum1) %s\n", cli_errstr(cli1
));
2161 status
= cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
, &fnum1
);
2162 if (!NT_STATUS_IS_OK(status
)) {
2163 d_fprintf(stderr
, "cli_open third time returned %s\n",
2171 cli_close(cli1
, fnum1
);
2172 cli_close(cli1
, fnum2
);
2173 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
2174 torture_close_connection(cli1
);
2176 printf("finished locktest8\n");
2181 * This test is designed to be run in conjunction with
2182 * external NFS or POSIX locks taken in the filesystem.
2183 * It checks that the smbd server will block until the
2184 * lock is released and then acquire it. JRA.
2187 static bool got_alarm
;
2188 static int alarm_fd
;
2190 static void alarm_handler(int dummy
)
2195 static void alarm_handler_parent(int dummy
)
2200 static void do_local_lock(int read_fd
, int write_fd
)
2205 const char *local_pathname
= NULL
;
2208 local_pathname
= talloc_asprintf(talloc_tos(),
2209 "%s/lockt9.lck", local_path
);
2210 if (!local_pathname
) {
2211 printf("child: alloc fail\n");
2215 unlink(local_pathname
);
2216 fd
= open(local_pathname
, O_RDWR
|O_CREAT
, 0666);
2218 printf("child: open of %s failed %s.\n",
2219 local_pathname
, strerror(errno
));
2223 /* Now take a fcntl lock. */
2224 lock
.l_type
= F_WRLCK
;
2225 lock
.l_whence
= SEEK_SET
;
2228 lock
.l_pid
= getpid();
2230 ret
= fcntl(fd
,F_SETLK
,&lock
);
2232 printf("child: failed to get lock 0:4 on file %s. Error %s\n",
2233 local_pathname
, strerror(errno
));
2236 printf("child: got lock 0:4 on file %s.\n",
2241 CatchSignal(SIGALRM
, alarm_handler
);
2243 /* Signal the parent. */
2244 if (write(write_fd
, &c
, 1) != 1) {
2245 printf("child: start signal fail %s.\n",
2252 /* Wait for the parent to be ready. */
2253 if (read(read_fd
, &c
, 1) != 1) {
2254 printf("child: reply signal fail %s.\n",
2262 printf("child: released lock 0:4 on file %s.\n",
2268 static bool run_locktest9(int dummy
)
2270 struct cli_state
*cli1
;
2271 const char *fname
= "\\lockt9.lck";
2273 bool correct
= False
;
2274 int pipe_in
[2], pipe_out
[2];
2281 printf("starting locktest9\n");
2283 if (local_path
== NULL
) {
2284 d_fprintf(stderr
, "locktest9 must be given a local path via -l <localpath>\n");
2288 if (pipe(pipe_in
) == -1 || pipe(pipe_out
) == -1) {
2293 if (child_pid
== -1) {
2297 if (child_pid
== 0) {
2299 do_local_lock(pipe_out
[0], pipe_in
[1]);
2309 ret
= read(pipe_in
[0], &c
, 1);
2311 d_fprintf(stderr
, "failed to read start signal from child. %s\n",
2316 if (!torture_open_connection(&cli1
, 0)) {
2320 cli_sockopt(cli1
, sockops
);
2322 status
= cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
,
2324 if (!NT_STATUS_IS_OK(status
)) {
2325 d_fprintf(stderr
, "cli_open returned %s\n", cli_errstr(cli1
));
2329 /* Ensure the child has the lock. */
2330 if (cli_lock(cli1
, fnum
, 0, 4, 0, WRITE_LOCK
)) {
2331 d_fprintf(stderr
, "Got the lock on range 0:4 - this should not happen !\n");
2334 d_printf("Child has the lock.\n");
2337 /* Tell the child to wait 5 seconds then exit. */
2338 ret
= write(pipe_out
[1], &c
, 1);
2340 d_fprintf(stderr
, "failed to send exit signal to child. %s\n",
2345 /* Wait 20 seconds for the lock. */
2346 alarm_fd
= cli1
->fd
;
2347 CatchSignal(SIGALRM
, alarm_handler_parent
);
2352 if (!cli_lock(cli1
, fnum
, 0, 4, -1, WRITE_LOCK
)) {
2353 d_fprintf(stderr
, "Unable to apply write lock on range 0:4, error was "
2354 "%s\n", cli_errstr(cli1
));
2359 seconds
= end_timer();
2361 printf("Parent got the lock after %.2f seconds.\n",
2364 status
= cli_close(cli1
, fnum
);
2365 if (!NT_STATUS_IS_OK(status
)) {
2366 d_fprintf(stderr
, "cli_close(fnum1) %s\n", cli_errstr(cli1
));
2373 cli_close(cli1
, fnum
);
2374 torture_close_connection(cli1
);
2378 printf("finished locktest9\n");
2383 test whether fnums and tids open on one VC are available on another (a major
2386 static bool run_fdpasstest(int dummy
)
2388 struct cli_state
*cli1
, *cli2
;
2389 const char *fname
= "\\fdpass.tst";
2393 if (!torture_open_connection(&cli1
, 0) || !torture_open_connection(&cli2
, 1)) {
2396 cli_sockopt(cli1
, sockops
);
2397 cli_sockopt(cli2
, sockops
);
2399 printf("starting fdpasstest\n");
2401 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
2403 if (!NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
))) {
2404 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
2408 if (cli_write(cli1
, fnum1
, 0, "hello world\n", 0, 13) != 13) {
2409 printf("write failed (%s)\n", cli_errstr(cli1
));
2413 cli2
->vuid
= cli1
->vuid
;
2414 cli2
->cnum
= cli1
->cnum
;
2415 cli2
->pid
= cli1
->pid
;
2417 if (cli_read(cli2
, fnum1
, buf
, 0, 13) == 13) {
2418 printf("read succeeded! nasty security hole [%s]\n",
2423 cli_close(cli1
, fnum1
);
2424 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
2426 torture_close_connection(cli1
);
2427 torture_close_connection(cli2
);
2429 printf("finished fdpasstest\n");
2433 static bool run_fdsesstest(int dummy
)
2435 struct cli_state
*cli
;
2440 const char *fname
= "\\fdsess.tst";
2441 const char *fname1
= "\\fdsess1.tst";
2447 if (!torture_open_connection(&cli
, 0))
2449 cli_sockopt(cli
, sockops
);
2451 if (!torture_cli_session_setup2(cli
, &new_vuid
))
2454 saved_cnum
= cli
->cnum
;
2455 if (!NT_STATUS_IS_OK(cli_tcon_andx(cli
, share
, "?????", "", 1)))
2457 new_cnum
= cli
->cnum
;
2458 cli
->cnum
= saved_cnum
;
2460 printf("starting fdsesstest\n");
2462 cli_unlink(cli
, fname
, aSYSTEM
| aHIDDEN
);
2463 cli_unlink(cli
, fname1
, aSYSTEM
| aHIDDEN
);
2465 if (!NT_STATUS_IS_OK(cli_open(cli
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
))) {
2466 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli
));
2470 if (cli_write(cli
, fnum1
, 0, "hello world\n", 0, 13) != 13) {
2471 printf("write failed (%s)\n", cli_errstr(cli
));
2475 saved_vuid
= cli
->vuid
;
2476 cli
->vuid
= new_vuid
;
2478 if (cli_read(cli
, fnum1
, buf
, 0, 13) == 13) {
2479 printf("read succeeded with different vuid! nasty security hole [%s]\n",
2483 /* Try to open a file with different vuid, samba cnum. */
2484 if (NT_STATUS_IS_OK(cli_open(cli
, fname1
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum2
))) {
2485 printf("create with different vuid, same cnum succeeded.\n");
2486 cli_close(cli
, fnum2
);
2487 cli_unlink(cli
, fname1
, aSYSTEM
| aHIDDEN
);
2489 printf("create with different vuid, same cnum failed.\n");
2490 printf("This will cause problems with service clients.\n");
2494 cli
->vuid
= saved_vuid
;
2496 /* Try with same vuid, different cnum. */
2497 cli
->cnum
= new_cnum
;
2499 if (cli_read(cli
, fnum1
, buf
, 0, 13) == 13) {
2500 printf("read succeeded with different cnum![%s]\n",
2505 cli
->cnum
= saved_cnum
;
2506 cli_close(cli
, fnum1
);
2507 cli_unlink(cli
, fname
, aSYSTEM
| aHIDDEN
);
2509 torture_close_connection(cli
);
2511 printf("finished fdsesstest\n");
2516 This test checks that
2518 1) the server does not allow an unlink on a file that is open
2520 static bool run_unlinktest(int dummy
)
2522 struct cli_state
*cli
;
2523 const char *fname
= "\\unlink.tst";
2525 bool correct
= True
;
2527 if (!torture_open_connection(&cli
, 0)) {
2531 cli_sockopt(cli
, sockops
);
2533 printf("starting unlink test\n");
2535 cli_unlink(cli
, fname
, aSYSTEM
| aHIDDEN
);
2539 if (!NT_STATUS_IS_OK(cli_open(cli
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum
))) {
2540 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli
));
2544 if (NT_STATUS_IS_OK(cli_unlink(cli
, fname
, aSYSTEM
| aHIDDEN
))) {
2545 printf("error: server allowed unlink on an open file\n");
2548 correct
= check_error(__LINE__
, cli
, ERRDOS
, ERRbadshare
,
2549 NT_STATUS_SHARING_VIOLATION
);
2552 cli_close(cli
, fnum
);
2553 cli_unlink(cli
, fname
, aSYSTEM
| aHIDDEN
);
2555 if (!torture_close_connection(cli
)) {
2559 printf("unlink test finished\n");
2566 test how many open files this server supports on the one socket
2568 static bool run_maxfidtest(int dummy
)
2570 struct cli_state
*cli
;
2571 const char *ftemplate
= "\\maxfid.%d.%d";
2573 uint16_t fnums
[0x11000];
2576 bool correct
= True
;
2581 printf("failed to connect\n");
2585 cli_sockopt(cli
, sockops
);
2587 for (i
=0; i
<0x11000; i
++) {
2588 slprintf(fname
,sizeof(fname
)-1,ftemplate
, i
,(int)getpid());
2589 if (!NT_STATUS_IS_OK(cli_open(cli
, fname
,
2590 O_RDWR
|O_CREAT
|O_TRUNC
, DENY_NONE
, &fnums
[i
]))) {
2591 printf("open of %s failed (%s)\n",
2592 fname
, cli_errstr(cli
));
2593 printf("maximum fnum is %d\n", i
);
2601 printf("cleaning up\n");
2603 slprintf(fname
,sizeof(fname
)-1,ftemplate
, i
,(int)getpid());
2604 cli_close(cli
, fnums
[i
]);
2605 if (!NT_STATUS_IS_OK(cli_unlink(cli
, fname
, aSYSTEM
| aHIDDEN
))) {
2606 printf("unlink of %s failed (%s)\n",
2607 fname
, cli_errstr(cli
));
2614 printf("maxfid test finished\n");
2615 if (!torture_close_connection(cli
)) {
2621 /* generate a random buffer */
2622 static void rand_buf(char *buf
, int len
)
2625 *buf
= (char)sys_random();
2630 /* send smb negprot commands, not reading the response */
2631 static bool run_negprot_nowait(int dummy
)
2634 static struct cli_state
*cli
;
2635 bool correct
= True
;
2637 printf("starting negprot nowait test\n");
2639 if (!(cli
= open_nbt_connection())) {
2643 for (i
=0;i
<50000;i
++) {
2644 cli_negprot_sendsync(cli
);
2647 if (!torture_close_connection(cli
)) {
2651 printf("finished negprot nowait test\n");
2657 /* send random IPC commands */
2658 static bool run_randomipc(int dummy
)
2660 char *rparam
= NULL
;
2662 unsigned int rdrcnt
,rprcnt
;
2664 int api
, param_len
, i
;
2665 struct cli_state
*cli
;
2666 bool correct
= True
;
2669 printf("starting random ipc test\n");
2671 if (!torture_open_connection(&cli
, 0)) {
2675 for (i
=0;i
<count
;i
++) {
2676 api
= sys_random() % 500;
2677 param_len
= (sys_random() % 64);
2679 rand_buf(param
, param_len
);
2684 param
, param_len
, 8,
2685 NULL
, 0, BUFFER_SIZE
,
2689 printf("%d/%d\r", i
,count
);
2692 printf("%d/%d\n", i
, count
);
2694 if (!torture_close_connection(cli
)) {
2698 printf("finished random ipc test\n");
2705 static void browse_callback(const char *sname
, uint32 stype
,
2706 const char *comment
, void *state
)
2708 printf("\t%20.20s %08x %s\n", sname
, stype
, comment
);
2714 This test checks the browse list code
2717 static bool run_browsetest(int dummy
)
2719 static struct cli_state
*cli
;
2720 bool correct
= True
;
2722 printf("starting browse test\n");
2724 if (!torture_open_connection(&cli
, 0)) {
2728 printf("domain list:\n");
2729 cli_NetServerEnum(cli
, cli
->server_domain
,
2730 SV_TYPE_DOMAIN_ENUM
,
2731 browse_callback
, NULL
);
2733 printf("machine list:\n");
2734 cli_NetServerEnum(cli
, cli
->server_domain
,
2736 browse_callback
, NULL
);
2738 if (!torture_close_connection(cli
)) {
2742 printf("browse test finished\n");
2750 This checks how the getatr calls works
2752 static bool run_attrtest(int dummy
)
2754 struct cli_state
*cli
;
2757 const char *fname
= "\\attrib123456789.tst";
2758 bool correct
= True
;
2760 printf("starting attrib test\n");
2762 if (!torture_open_connection(&cli
, 0)) {
2766 cli_unlink(cli
, fname
, aSYSTEM
| aHIDDEN
);
2767 cli_open(cli
, fname
,
2768 O_RDWR
| O_CREAT
| O_TRUNC
, DENY_NONE
, &fnum
);
2769 cli_close(cli
, fnum
);
2770 if (!NT_STATUS_IS_OK(cli_getatr(cli
, fname
, NULL
, NULL
, &t
))) {
2771 printf("getatr failed (%s)\n", cli_errstr(cli
));
2775 if (abs(t
- time(NULL
)) > 60*60*24*10) {
2776 printf("ERROR: SMBgetatr bug. time is %s",
2782 t2
= t
-60*60*24; /* 1 day ago */
2784 if (!NT_STATUS_IS_OK(cli_setatr(cli
, fname
, 0, t2
))) {
2785 printf("setatr failed (%s)\n", cli_errstr(cli
));
2789 if (!NT_STATUS_IS_OK(cli_getatr(cli
, fname
, NULL
, NULL
, &t
))) {
2790 printf("getatr failed (%s)\n", cli_errstr(cli
));
2795 printf("ERROR: getatr/setatr bug. times are\n%s",
2797 printf("%s", ctime(&t2
));
2801 cli_unlink(cli
, fname
, aSYSTEM
| aHIDDEN
);
2803 if (!torture_close_connection(cli
)) {
2807 printf("attrib test finished\n");
2814 This checks a couple of trans2 calls
2816 static bool run_trans2test(int dummy
)
2818 struct cli_state
*cli
;
2821 time_t c_time
, a_time
, m_time
;
2822 struct timespec c_time_ts
, a_time_ts
, m_time_ts
, w_time_ts
, m_time2_ts
;
2823 const char *fname
= "\\trans2.tst";
2824 const char *dname
= "\\trans2";
2825 const char *fname2
= "\\trans2\\trans2.tst";
2827 bool correct
= True
;
2829 printf("starting trans2 test\n");
2831 if (!torture_open_connection(&cli
, 0)) {
2835 cli_unlink(cli
, fname
, aSYSTEM
| aHIDDEN
);
2836 cli_open(cli
, fname
,
2837 O_RDWR
| O_CREAT
| O_TRUNC
, DENY_NONE
, &fnum
);
2838 if (!cli_qfileinfo(cli
, fnum
, NULL
, &size
, &c_time_ts
, &a_time_ts
, &w_time_ts
,
2839 &m_time_ts
, NULL
)) {
2840 printf("ERROR: qfileinfo failed (%s)\n", cli_errstr(cli
));
2844 if (!cli_qfilename(cli
, fnum
, pname
, sizeof(pname
))) {
2845 printf("ERROR: qfilename failed (%s)\n", cli_errstr(cli
));
2849 if (strcmp(pname
, fname
)) {
2850 printf("qfilename gave different name? [%s] [%s]\n",
2855 cli_close(cli
, fnum
);
2859 cli_unlink(cli
, fname
, aSYSTEM
| aHIDDEN
);
2860 if (!NT_STATUS_IS_OK(cli_open(cli
, fname
,
2861 O_RDWR
| O_CREAT
| O_TRUNC
, DENY_NONE
, &fnum
))) {
2862 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli
));
2865 cli_close(cli
, fnum
);
2867 if (!cli_qpathinfo(cli
, fname
, &c_time
, &a_time
, &m_time
, &size
, NULL
)) {
2868 printf("ERROR: qpathinfo failed (%s)\n", cli_errstr(cli
));
2871 if (c_time
!= m_time
) {
2872 printf("create time=%s", ctime(&c_time
));
2873 printf("modify time=%s", ctime(&m_time
));
2874 printf("This system appears to have sticky create times\n");
2876 if (a_time
% (60*60) == 0) {
2877 printf("access time=%s", ctime(&a_time
));
2878 printf("This system appears to set a midnight access time\n");
2882 if (abs(m_time
- time(NULL
)) > 60*60*24*7) {
2883 printf("ERROR: totally incorrect times - maybe word reversed? mtime=%s", ctime(&m_time
));
2889 cli_unlink(cli
, fname
, aSYSTEM
| aHIDDEN
);
2890 cli_open(cli
, fname
,
2891 O_RDWR
| O_CREAT
| O_TRUNC
, DENY_NONE
, &fnum
);
2892 cli_close(cli
, fnum
);
2893 if (!cli_qpathinfo2(cli
, fname
, &c_time_ts
, &a_time_ts
, &w_time_ts
,
2894 &m_time_ts
, &size
, NULL
, NULL
)) {
2895 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli
));
2898 if (w_time_ts
.tv_sec
< 60*60*24*2) {
2899 printf("write time=%s", ctime(&w_time_ts
.tv_sec
));
2900 printf("This system appears to set a initial 0 write time\n");
2905 cli_unlink(cli
, fname
, aSYSTEM
| aHIDDEN
);
2908 /* check if the server updates the directory modification time
2909 when creating a new file */
2910 if (!NT_STATUS_IS_OK(cli_mkdir(cli
, dname
))) {
2911 printf("ERROR: mkdir failed (%s)\n", cli_errstr(cli
));
2915 if (!cli_qpathinfo2(cli
, "\\trans2\\", &c_time_ts
, &a_time_ts
, &w_time_ts
,
2916 &m_time_ts
, &size
, NULL
, NULL
)) {
2917 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli
));
2921 cli_open(cli
, fname2
,
2922 O_RDWR
| O_CREAT
| O_TRUNC
, DENY_NONE
, &fnum
);
2923 cli_write(cli
, fnum
, 0, (char *)&fnum
, 0, sizeof(fnum
));
2924 cli_close(cli
, fnum
);
2925 if (!cli_qpathinfo2(cli
, "\\trans2\\", &c_time_ts
, &a_time_ts
, &w_time_ts
,
2926 &m_time2_ts
, &size
, NULL
, NULL
)) {
2927 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli
));
2930 if (memcmp(&m_time_ts
, &m_time2_ts
, sizeof(struct timespec
))
2932 printf("This system does not update directory modification times\n");
2936 cli_unlink(cli
, fname2
, aSYSTEM
| aHIDDEN
);
2937 cli_rmdir(cli
, dname
);
2939 if (!torture_close_connection(cli
)) {
2943 printf("trans2 test finished\n");
2949 This checks new W2K calls.
2952 static bool new_trans(struct cli_state
*pcli
, int fnum
, int level
)
2956 bool correct
= True
;
2958 if (!cli_qfileinfo_test(pcli
, fnum
, level
, &buf
, &len
)) {
2959 printf("ERROR: qfileinfo (%d) failed (%s)\n", level
, cli_errstr(pcli
));
2962 printf("qfileinfo: level %d, len = %u\n", level
, len
);
2963 dump_data(0, (uint8
*)buf
, len
);
2970 static bool run_w2ktest(int dummy
)
2972 struct cli_state
*cli
;
2974 const char *fname
= "\\w2ktest\\w2k.tst";
2976 bool correct
= True
;
2978 printf("starting w2k test\n");
2980 if (!torture_open_connection(&cli
, 0)) {
2984 cli_open(cli
, fname
,
2985 O_RDWR
| O_CREAT
, DENY_NONE
, &fnum
);
2987 for (level
= 1004; level
< 1040; level
++) {
2988 new_trans(cli
, fnum
, level
);
2991 cli_close(cli
, fnum
);
2993 if (!torture_close_connection(cli
)) {
2997 printf("w2k test finished\n");
3004 this is a harness for some oplock tests
3006 static bool run_oplock1(int dummy
)
3008 struct cli_state
*cli1
;
3009 const char *fname
= "\\lockt1.lck";
3011 bool correct
= True
;
3013 printf("starting oplock test 1\n");
3015 if (!torture_open_connection(&cli1
, 0)) {
3019 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
3021 cli_sockopt(cli1
, sockops
);
3023 cli1
->use_oplocks
= True
;
3025 if (!NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
))) {
3026 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3030 cli1
->use_oplocks
= False
;
3032 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
3033 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
3035 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3036 printf("close2 failed (%s)\n", cli_errstr(cli1
));
3040 if (!NT_STATUS_IS_OK(cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
))) {
3041 printf("unlink failed (%s)\n", cli_errstr(cli1
));
3045 if (!torture_close_connection(cli1
)) {
3049 printf("finished oplock test 1\n");
3054 static bool run_oplock2(int dummy
)
3056 struct cli_state
*cli1
, *cli2
;
3057 const char *fname
= "\\lockt2.lck";
3058 uint16_t fnum1
, fnum2
;
3059 int saved_use_oplocks
= use_oplocks
;
3061 bool correct
= True
;
3062 volatile bool *shared_correct
;
3064 shared_correct
= (volatile bool *)shm_setup(sizeof(bool));
3065 *shared_correct
= True
;
3067 use_level_II_oplocks
= True
;
3070 printf("starting oplock test 2\n");
3072 if (!torture_open_connection(&cli1
, 0)) {
3073 use_level_II_oplocks
= False
;
3074 use_oplocks
= saved_use_oplocks
;
3078 cli1
->use_oplocks
= True
;
3079 cli1
->use_level_II_oplocks
= True
;
3081 if (!torture_open_connection(&cli2
, 1)) {
3082 use_level_II_oplocks
= False
;
3083 use_oplocks
= saved_use_oplocks
;
3087 cli2
->use_oplocks
= True
;
3088 cli2
->use_level_II_oplocks
= True
;
3090 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
3092 cli_sockopt(cli1
, sockops
);
3093 cli_sockopt(cli2
, sockops
);
3095 if (!NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
))) {
3096 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3100 /* Don't need the globals any more. */
3101 use_level_II_oplocks
= False
;
3102 use_oplocks
= saved_use_oplocks
;
3106 if (!NT_STATUS_IS_OK(cli_open(cli2
, fname
, O_RDWR
, DENY_NONE
, &fnum2
))) {
3107 printf("second open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3108 *shared_correct
= False
;
3114 if (!NT_STATUS_IS_OK(cli_close(cli2
, fnum2
))) {
3115 printf("close2 failed (%s)\n", cli_errstr(cli1
));
3116 *shared_correct
= False
;
3124 /* Ensure cli1 processes the break. Empty file should always return 0
3127 if (cli_read(cli1
, fnum1
, buf
, 0, 4) != 0) {
3128 printf("read on fnum1 failed (%s)\n", cli_errstr(cli1
));
3132 /* Should now be at level II. */
3133 /* Test if sending a write locks causes a break to none. */
3135 if (!cli_lock(cli1
, fnum1
, 0, 4, 0, READ_LOCK
)) {
3136 printf("lock failed (%s)\n", cli_errstr(cli1
));
3140 cli_unlock(cli1
, fnum1
, 0, 4);
3144 if (!cli_lock(cli1
, fnum1
, 0, 4, 0, WRITE_LOCK
)) {
3145 printf("lock failed (%s)\n", cli_errstr(cli1
));
3149 cli_unlock(cli1
, fnum1
, 0, 4);
3153 cli_read(cli1
, fnum1
, buf
, 0, 4);
3156 if (cli_write(cli1
, fnum1
, 0, buf
, 0, 4) != 4) {
3157 printf("write on fnum1 failed (%s)\n", cli_errstr(cli1
));
3162 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3163 printf("close1 failed (%s)\n", cli_errstr(cli1
));
3169 if (!NT_STATUS_IS_OK(cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
))) {
3170 printf("unlink failed (%s)\n", cli_errstr(cli1
));
3174 if (!torture_close_connection(cli1
)) {
3178 if (!*shared_correct
) {
3182 printf("finished oplock test 2\n");
3187 /* handler for oplock 3 tests */
3188 static NTSTATUS
oplock3_handler(struct cli_state
*cli
, uint16_t fnum
, unsigned char level
)
3190 printf("got oplock break fnum=%d level=%d\n",
3192 return cli_oplock_ack(cli
, fnum
, level
);
3195 static bool run_oplock3(int dummy
)
3197 struct cli_state
*cli
;
3198 const char *fname
= "\\oplockt3.dat";
3200 char buf
[4] = "abcd";
3201 bool correct
= True
;
3202 volatile bool *shared_correct
;
3204 shared_correct
= (volatile bool *)shm_setup(sizeof(bool));
3205 *shared_correct
= True
;
3207 printf("starting oplock test 3\n");
3212 use_level_II_oplocks
= True
;
3213 if (!torture_open_connection(&cli
, 0)) {
3214 *shared_correct
= False
;
3218 /* try to trigger a oplock break in parent */
3219 cli_open(cli
, fname
, O_RDWR
, DENY_NONE
, &fnum
);
3220 cli_write(cli
, fnum
, 0, buf
, 0, 4);
3226 use_level_II_oplocks
= True
;
3227 if (!torture_open_connection(&cli
, 1)) { /* other is forked */
3230 cli_oplock_handler(cli
, oplock3_handler
);
3231 cli_open(cli
, fname
, O_RDWR
|O_CREAT
, DENY_NONE
, &fnum
);
3232 cli_write(cli
, fnum
, 0, buf
, 0, 4);
3233 cli_close(cli
, fnum
);
3234 cli_open(cli
, fname
, O_RDWR
, DENY_NONE
, &fnum
);
3235 cli
->timeout
= 20000;
3236 cli_receive_smb(cli
);
3237 printf("finished oplock test 3\n");
3239 return (correct
&& *shared_correct
);
3241 /* What are we looking for here? What's sucess and what's FAILURE? */
3247 Test delete on close semantics.
3249 static bool run_deletetest(int dummy
)
3251 struct cli_state
*cli1
= NULL
;
3252 struct cli_state
*cli2
= NULL
;
3253 const char *fname
= "\\delete.file";
3254 uint16_t fnum1
= (uint16_t)-1;
3255 uint16_t fnum2
= (uint16_t)-1;
3256 bool correct
= True
;
3258 printf("starting delete test\n");
3260 if (!torture_open_connection(&cli1
, 0)) {
3264 cli_sockopt(cli1
, sockops
);
3266 /* Test 1 - this should delete the file on close. */
3268 cli_setatr(cli1
, fname
, 0, 0);
3269 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
3271 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, GENERIC_ALL_ACCESS
|DELETE_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
3272 0, FILE_OVERWRITE_IF
,
3273 FILE_DELETE_ON_CLOSE
, 0, &fnum1
))) {
3274 printf("[1] open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3281 uint32
*accinfo
= NULL
;
3283 cli_qfileinfo_test(cli1
, fnum1
, SMB_FILE_ACCESS_INFORMATION
, (char **)&accinfo
, &len
);
3285 printf("access mode = 0x%lx\n", *accinfo
);
3290 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3291 printf("[1] close failed (%s)\n", cli_errstr(cli1
));
3296 if (NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
, &fnum1
))) {
3297 printf("[1] open of %s succeeded (should fail)\n", fname
);
3302 printf("first delete on close test succeeded.\n");
3304 /* Test 2 - this should delete the file on close. */
3306 cli_setatr(cli1
, fname
, 0, 0);
3307 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
3309 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, GENERIC_ALL_ACCESS
,
3310 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_NONE
,
3311 FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
3312 printf("[2] open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3317 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1
, fnum1
, true))) {
3318 printf("[2] setting delete_on_close failed (%s)\n", cli_errstr(cli1
));
3323 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3324 printf("[2] close failed (%s)\n", cli_errstr(cli1
));
3329 if (NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDONLY
, DENY_NONE
, &fnum1
))) {
3330 printf("[2] open of %s succeeded should have been deleted on close !\n", fname
);
3331 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3332 printf("[2] close failed (%s)\n", cli_errstr(cli1
));
3336 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
3338 printf("second delete on close test succeeded.\n");
3341 cli_setatr(cli1
, fname
, 0, 0);
3342 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
3344 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, GENERIC_ALL_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
3345 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
3346 printf("[3] open - 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3351 /* This should fail with a sharing violation - open for delete is only compatible
3352 with SHARE_DELETE. */
3354 if (NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, GENERIC_READ_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
3355 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OPEN
, 0, 0, &fnum2
))) {
3356 printf("[3] open - 2 of %s succeeded - should have failed.\n", fname
);
3361 /* This should succeed. */
3363 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, GENERIC_READ_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
3364 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, FILE_OPEN
, 0, 0, &fnum2
))) {
3365 printf("[3] open - 2 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3370 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1
, fnum1
, true))) {
3371 printf("[3] setting delete_on_close failed (%s)\n", cli_errstr(cli1
));
3376 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3377 printf("[3] close 1 failed (%s)\n", cli_errstr(cli1
));
3382 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum2
))) {
3383 printf("[3] close 2 failed (%s)\n", cli_errstr(cli1
));
3388 /* This should fail - file should no longer be there. */
3390 if (NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDONLY
, DENY_NONE
, &fnum1
))) {
3391 printf("[3] open of %s succeeded should have been deleted on close !\n", fname
);
3392 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3393 printf("[3] close failed (%s)\n", cli_errstr(cli1
));
3395 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
3399 printf("third delete on close test succeeded.\n");
3402 cli_setatr(cli1
, fname
, 0, 0);
3403 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
3405 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, FILE_READ_DATA
|FILE_WRITE_DATA
|DELETE_ACCESS
,
3406 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
3407 printf("[4] open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3412 /* This should succeed. */
3413 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, GENERIC_READ_ACCESS
,
3414 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, FILE_OPEN
, 0, 0, &fnum2
))) {
3415 printf("[4] open - 2 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3420 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum2
))) {
3421 printf("[4] close - 1 failed (%s)\n", cli_errstr(cli1
));
3426 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1
, fnum1
, true))) {
3427 printf("[4] setting delete_on_close failed (%s)\n", cli_errstr(cli1
));
3432 /* This should fail - no more opens once delete on close set. */
3433 if (NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, GENERIC_READ_ACCESS
,
3434 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
3435 FILE_OPEN
, 0, 0, &fnum2
))) {
3436 printf("[4] open - 3 of %s succeeded ! Should have failed.\n", fname
);
3440 printf("fourth delete on close test succeeded.\n");
3442 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3443 printf("[4] close - 2 failed (%s)\n", cli_errstr(cli1
));
3449 cli_setatr(cli1
, fname
, 0, 0);
3450 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
3452 if (!NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDWR
|O_CREAT
, DENY_NONE
, &fnum1
))) {
3453 printf("[5] open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3458 /* This should fail - only allowed on NT opens with DELETE access. */
3460 if (NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1
, fnum1
, true))) {
3461 printf("[5] setting delete_on_close on OpenX file succeeded - should fail !\n");
3466 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3467 printf("[5] close - 2 failed (%s)\n", cli_errstr(cli1
));
3472 printf("fifth delete on close test succeeded.\n");
3475 cli_setatr(cli1
, fname
, 0, 0);
3476 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
3478 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, FILE_READ_DATA
|FILE_WRITE_DATA
,
3479 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
3480 FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
3481 printf("[6] open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3486 /* This should fail - only allowed on NT opens with DELETE access. */
3488 if (NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1
, fnum1
, true))) {
3489 printf("[6] setting delete_on_close on file with no delete access succeeded - should fail !\n");
3494 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3495 printf("[6] close - 2 failed (%s)\n", cli_errstr(cli1
));
3500 printf("sixth delete on close test succeeded.\n");
3503 cli_setatr(cli1
, fname
, 0, 0);
3504 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
3506 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, FILE_READ_DATA
|FILE_WRITE_DATA
|DELETE_ACCESS
,
3507 FILE_ATTRIBUTE_NORMAL
, 0, FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
3508 printf("[7] open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3513 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1
, fnum1
, true))) {
3514 printf("[7] setting delete_on_close on file failed !\n");
3519 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1
, fnum1
, false))) {
3520 printf("[7] unsetting delete_on_close on file failed !\n");
3525 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3526 printf("[7] close - 2 failed (%s)\n", cli_errstr(cli1
));
3531 /* This next open should succeed - we reset the flag. */
3533 if (!NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDONLY
, DENY_NONE
, &fnum1
))) {
3534 printf("[5] open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3539 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3540 printf("[7] close - 2 failed (%s)\n", cli_errstr(cli1
));
3545 printf("seventh delete on close test succeeded.\n");
3548 cli_setatr(cli1
, fname
, 0, 0);
3549 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
3551 if (!torture_open_connection(&cli2
, 1)) {
3552 printf("[8] failed to open second connection.\n");
3557 cli_sockopt(cli1
, sockops
);
3559 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, FILE_READ_DATA
|FILE_WRITE_DATA
|DELETE_ACCESS
,
3560 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
3561 FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
3562 printf("[8] open 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3567 if (!NT_STATUS_IS_OK(cli_ntcreate(cli2
, fname
, 0, FILE_READ_DATA
|FILE_WRITE_DATA
|DELETE_ACCESS
,
3568 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
3569 FILE_OPEN
, 0, 0, &fnum2
))) {
3570 printf("[8] open 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
3575 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1
, fnum1
, true))) {
3576 printf("[8] setting delete_on_close on file failed !\n");
3581 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3582 printf("[8] close - 1 failed (%s)\n", cli_errstr(cli1
));
3587 if (!NT_STATUS_IS_OK(cli_close(cli2
, fnum2
))) {
3588 printf("[8] close - 2 failed (%s)\n", cli_errstr(cli2
));
3593 /* This should fail.. */
3594 if (NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDONLY
, DENY_NONE
, &fnum1
))) {
3595 printf("[8] open of %s succeeded should have been deleted on close !\n", fname
);
3599 printf("eighth delete on close test succeeded.\n");
3601 /* This should fail - we need to set DELETE_ACCESS. */
3602 if (NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0,FILE_READ_DATA
|FILE_WRITE_DATA
,
3603 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, FILE_DELETE_ON_CLOSE
, 0, &fnum1
))) {
3604 printf("[9] open of %s succeeded should have failed!\n", fname
);
3609 printf("ninth delete on close test succeeded.\n");
3611 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, FILE_READ_DATA
|FILE_WRITE_DATA
|DELETE_ACCESS
,
3612 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, FILE_DELETE_ON_CLOSE
, 0, &fnum1
))) {
3613 printf("[10] open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3618 /* This should delete the file. */
3619 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3620 printf("[10] close failed (%s)\n", cli_errstr(cli1
));
3625 /* This should fail.. */
3626 if (NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDONLY
, DENY_NONE
, &fnum1
))) {
3627 printf("[10] open of %s succeeded should have been deleted on close !\n", fname
);
3631 printf("tenth delete on close test succeeded.\n");
3633 cli_setatr(cli1
, fname
, 0, 0);
3634 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
3636 /* What error do we get when attempting to open a read-only file with
3639 /* Create a readonly file. */
3640 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, FILE_READ_DATA
|FILE_WRITE_DATA
,
3641 FILE_ATTRIBUTE_READONLY
, FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
3642 printf("[11] open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3647 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3648 printf("[11] close failed (%s)\n", cli_errstr(cli1
));
3653 /* Now try open for delete access. */
3654 if (NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, FILE_READ_ATTRIBUTES
|DELETE_ACCESS
,
3655 0, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
3656 FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
3657 printf("[11] open of %s succeeded should have been denied with ACCESS_DENIED!\n", fname
);
3658 cli_close(cli1
, fnum1
);
3662 NTSTATUS nterr
= cli_nt_error(cli1
);
3663 if (!NT_STATUS_EQUAL(nterr
,NT_STATUS_ACCESS_DENIED
)) {
3664 printf("[11] open of %s should have been denied with ACCESS_DENIED! Got error %s\n", fname
, nt_errstr(nterr
));
3668 printf("eleventh delete on close test succeeded.\n");
3672 printf("finished delete test\n");
3675 /* FIXME: This will crash if we aborted before cli2 got
3676 * intialized, because these functions don't handle
3677 * uninitialized connections. */
3679 if (fnum1
!= (uint16_t)-1) cli_close(cli1
, fnum1
);
3680 if (fnum2
!= (uint16_t)-1) cli_close(cli1
, fnum2
);
3681 cli_setatr(cli1
, fname
, 0, 0);
3682 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
3684 if (cli1
&& !torture_close_connection(cli1
)) {
3687 if (cli2
&& !torture_close_connection(cli2
)) {
3695 print out server properties
3697 static bool run_properties(int dummy
)
3699 struct cli_state
*cli
;
3700 bool correct
= True
;
3702 printf("starting properties test\n");
3706 if (!torture_open_connection(&cli
, 0)) {
3710 cli_sockopt(cli
, sockops
);
3712 d_printf("Capabilities 0x%08x\n", cli
->capabilities
);
3714 if (!torture_close_connection(cli
)) {
3723 /* FIRST_DESIRED_ACCESS 0xf019f */
3724 #define FIRST_DESIRED_ACCESS FILE_READ_DATA|FILE_WRITE_DATA|FILE_APPEND_DATA|\
3725 FILE_READ_EA| /* 0xf */ \
3726 FILE_WRITE_EA|FILE_READ_ATTRIBUTES| /* 0x90 */ \
3727 FILE_WRITE_ATTRIBUTES| /* 0x100 */ \
3728 DELETE_ACCESS|READ_CONTROL_ACCESS|\
3729 WRITE_DAC_ACCESS|WRITE_OWNER_ACCESS /* 0xf0000 */
3730 /* SECOND_DESIRED_ACCESS 0xe0080 */
3731 #define SECOND_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
3732 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
3733 WRITE_OWNER_ACCESS /* 0xe0000 */
3736 #define THIRD_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
3737 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
3739 WRITE_OWNER_ACCESS /* */
3743 Test ntcreate calls made by xcopy
3745 static bool run_xcopy(int dummy
)
3747 static struct cli_state
*cli1
;
3748 const char *fname
= "\\test.txt";
3749 bool correct
= True
;
3750 uint16_t fnum1
, fnum2
;
3752 printf("starting xcopy test\n");
3754 if (!torture_open_connection(&cli1
, 0)) {
3758 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0,
3759 FIRST_DESIRED_ACCESS
, FILE_ATTRIBUTE_ARCHIVE
,
3760 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
,
3761 0x4044, 0, &fnum1
))) {
3762 printf("First open failed - %s\n", cli_errstr(cli1
));
3766 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0,
3767 SECOND_DESIRED_ACCESS
, 0,
3768 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, FILE_OPEN
,
3769 0x200000, 0, &fnum2
))) {
3770 printf("second open failed - %s\n", cli_errstr(cli1
));
3774 if (!torture_close_connection(cli1
)) {
3782 Test rename on files open with share delete and no share delete.
3784 static bool run_rename(int dummy
)
3786 static struct cli_state
*cli1
;
3787 const char *fname
= "\\test.txt";
3788 const char *fname1
= "\\test1.txt";
3789 bool correct
= True
;
3793 printf("starting rename test\n");
3795 if (!torture_open_connection(&cli1
, 0)) {
3799 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
3800 cli_unlink(cli1
, fname1
, aSYSTEM
| aHIDDEN
);
3801 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, GENERIC_READ_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
3802 FILE_SHARE_READ
, FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
3803 printf("First open failed - %s\n", cli_errstr(cli1
));
3807 if (!NT_STATUS_IS_OK(cli_rename(cli1
, fname
, fname1
))) {
3808 printf("First rename failed (SHARE_READ) (this is correct) - %s\n", cli_errstr(cli1
));
3810 printf("First rename succeeded (SHARE_READ) - this should have failed !\n");
3814 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3815 printf("close - 1 failed (%s)\n", cli_errstr(cli1
));
3819 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
3820 cli_unlink(cli1
, fname1
, aSYSTEM
| aHIDDEN
);
3821 status
= cli_ntcreate(cli1
, fname
, 0, GENERIC_READ_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
3823 FILE_SHARE_DELETE
|FILE_SHARE_NONE
,
3825 FILE_SHARE_DELETE
|FILE_SHARE_READ
,
3827 FILE_OVERWRITE_IF
, 0, 0, &fnum1
);
3828 if (!NT_STATUS_IS_OK(status
)) {
3829 printf("Second open failed - %s\n", cli_errstr(cli1
));
3833 if (!NT_STATUS_IS_OK(cli_rename(cli1
, fname
, fname1
))) {
3834 printf("Second rename failed (SHARE_DELETE | SHARE_READ) - this should have succeeded - %s\n", cli_errstr(cli1
));
3837 printf("Second rename succeeded (SHARE_DELETE | SHARE_READ)\n");
3840 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3841 printf("close - 2 failed (%s)\n", cli_errstr(cli1
));
3845 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
3846 cli_unlink(cli1
, fname1
, aSYSTEM
| aHIDDEN
);
3848 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, READ_CONTROL_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
3849 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
3850 printf("Third open failed - %s\n", cli_errstr(cli1
));
3859 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, DELETE_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
3860 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0, &fnum2
))) {
3861 printf("Fourth open failed - %s\n", cli_errstr(cli1
));
3864 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1
, fnum2
, true))) {
3865 printf("[8] setting delete_on_close on file failed !\n");
3869 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum2
))) {
3870 printf("close - 4 failed (%s)\n", cli_errstr(cli1
));
3876 if (!NT_STATUS_IS_OK(cli_rename(cli1
, fname
, fname1
))) {
3877 printf("Third rename failed (SHARE_NONE) - this should have succeeded - %s\n", cli_errstr(cli1
));
3880 printf("Third rename succeeded (SHARE_NONE)\n");
3883 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3884 printf("close - 3 failed (%s)\n", cli_errstr(cli1
));
3888 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
3889 cli_unlink(cli1
, fname1
, aSYSTEM
| aHIDDEN
);
3893 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, GENERIC_READ_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
3894 FILE_SHARE_READ
| FILE_SHARE_WRITE
, FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
3895 printf("Fourth open failed - %s\n", cli_errstr(cli1
));
3899 if (!NT_STATUS_IS_OK(cli_rename(cli1
, fname
, fname1
))) {
3900 printf("Fourth rename failed (SHARE_READ | SHARE_WRITE) (this is correct) - %s\n", cli_errstr(cli1
));
3902 printf("Fourth rename succeeded (SHARE_READ | SHARE_WRITE) - this should have failed !\n");
3906 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3907 printf("close - 4 failed (%s)\n", cli_errstr(cli1
));
3911 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
3912 cli_unlink(cli1
, fname1
, aSYSTEM
| aHIDDEN
);
3916 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, GENERIC_READ_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
3917 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
, FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
3918 printf("Fifth open failed - %s\n", cli_errstr(cli1
));
3922 if (!NT_STATUS_IS_OK(cli_rename(cli1
, fname
, fname1
))) {
3923 printf("Fifth rename failed (SHARE_READ | SHARE_WRITE | SHARE_DELETE) - this should have succeeded - %s ! \n",
3927 printf("Fifth rename succeeded (SHARE_READ | SHARE_WRITE | SHARE_DELETE) (this is correct) - %s\n", cli_errstr(cli1
));
3931 * Now check if the first name still exists ...
3934 /* if (!NT_STATUS_OP(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
3935 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0, 0, &fnum2))) {
3936 printf("Opening original file after rename of open file fails: %s\n",
3940 printf("Opening original file after rename of open file works ...\n");
3941 (void)cli_close(cli1, fnum2);
3947 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3948 printf("close - 5 failed (%s)\n", cli_errstr(cli1
));
3952 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
3953 cli_unlink(cli1
, fname1
, aSYSTEM
| aHIDDEN
);
3955 if (!torture_close_connection(cli1
)) {
3962 static bool run_pipe_number(int dummy
)
3964 struct cli_state
*cli1
;
3965 const char *pipe_name
= "\\SPOOLSS";
3969 printf("starting pipenumber test\n");
3970 if (!torture_open_connection(&cli1
, 0)) {
3974 cli_sockopt(cli1
, sockops
);
3976 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, pipe_name
, 0, FILE_READ_DATA
, FILE_ATTRIBUTE_NORMAL
,
3977 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OPEN_IF
, 0, 0, &fnum
))) {
3978 printf("Open of pipe %s failed with error (%s)\n", pipe_name
, cli_errstr(cli1
));
3982 printf("\r%6d", num_pipes
);
3985 printf("pipe_number test - we can open %d %s pipes.\n", num_pipes
, pipe_name
);
3986 torture_close_connection(cli1
);
3991 Test open mode returns on read-only files.
3993 static bool run_opentest(int dummy
)
3995 static struct cli_state
*cli1
;
3996 static struct cli_state
*cli2
;
3997 const char *fname
= "\\readonly.file";
3998 uint16_t fnum1
, fnum2
;
4001 bool correct
= True
;
4004 printf("starting open test\n");
4006 if (!torture_open_connection(&cli1
, 0)) {
4010 cli_setatr(cli1
, fname
, 0, 0);
4011 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
4013 cli_sockopt(cli1
, sockops
);
4015 if (!NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
))) {
4016 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4020 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4021 printf("close2 failed (%s)\n", cli_errstr(cli1
));
4025 if (!NT_STATUS_IS_OK(cli_setatr(cli1
, fname
, aRONLY
, 0))) {
4026 printf("cli_setatr failed (%s)\n", cli_errstr(cli1
));
4030 if (!NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDONLY
, DENY_WRITE
, &fnum1
))) {
4031 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4035 /* This will fail - but the error should be ERRnoaccess, not ERRbadshare. */
4036 cli_open(cli1
, fname
, O_RDWR
, DENY_ALL
, &fnum2
);
4038 if (check_error(__LINE__
, cli1
, ERRDOS
, ERRnoaccess
,
4039 NT_STATUS_ACCESS_DENIED
)) {
4040 printf("correct error code ERRDOS/ERRnoaccess returned\n");
4043 printf("finished open test 1\n");
4045 cli_close(cli1
, fnum1
);
4047 /* Now try not readonly and ensure ERRbadshare is returned. */
4049 cli_setatr(cli1
, fname
, 0, 0);
4051 if (!NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDONLY
, DENY_WRITE
, &fnum1
))) {
4052 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4056 /* This will fail - but the error should be ERRshare. */
4057 cli_open(cli1
, fname
, O_RDWR
, DENY_ALL
, &fnum2
);
4059 if (check_error(__LINE__
, cli1
, ERRDOS
, ERRbadshare
,
4060 NT_STATUS_SHARING_VIOLATION
)) {
4061 printf("correct error code ERRDOS/ERRbadshare returned\n");
4064 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4065 printf("close2 failed (%s)\n", cli_errstr(cli1
));
4069 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
4071 printf("finished open test 2\n");
4073 /* Test truncate open disposition on file opened for read. */
4075 if (!NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
))) {
4076 printf("(3) open (1) of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4080 /* write 20 bytes. */
4082 memset(buf
, '\0', 20);
4084 if (cli_write(cli1
, fnum1
, 0, buf
, 0, 20) != 20) {
4085 printf("write failed (%s)\n", cli_errstr(cli1
));
4089 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4090 printf("(3) close1 failed (%s)\n", cli_errstr(cli1
));
4094 /* Ensure size == 20. */
4095 if (!NT_STATUS_IS_OK(cli_getatr(cli1
, fname
, NULL
, &fsize
, NULL
))) {
4096 printf("(3) getatr failed (%s)\n", cli_errstr(cli1
));
4101 printf("(3) file size != 20\n");
4105 /* Now test if we can truncate a file opened for readonly. */
4107 if (!NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDONLY
|O_TRUNC
, DENY_NONE
, &fnum1
))) {
4108 printf("(3) open (2) of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4112 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4113 printf("close2 failed (%s)\n", cli_errstr(cli1
));
4117 /* Ensure size == 0. */
4118 if (!NT_STATUS_IS_OK(cli_getatr(cli1
, fname
, NULL
, &fsize
, NULL
))) {
4119 printf("(3) getatr failed (%s)\n", cli_errstr(cli1
));
4124 printf("(3) file size != 0\n");
4127 printf("finished open test 3\n");
4129 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
4132 printf("testing ctemp\n");
4133 if (!NT_STATUS_IS_OK(cli_ctemp(cli1
, talloc_tos(), "\\", &fnum1
, &tmp_path
))) {
4134 printf("ctemp failed (%s)\n", cli_errstr(cli1
));
4137 printf("ctemp gave path %s\n", tmp_path
);
4138 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4139 printf("close of temp failed (%s)\n", cli_errstr(cli1
));
4141 if (!NT_STATUS_IS_OK(cli_unlink(cli1
, tmp_path
, aSYSTEM
| aHIDDEN
))) {
4142 printf("unlink of temp failed (%s)\n", cli_errstr(cli1
));
4145 /* Test the non-io opens... */
4147 if (!torture_open_connection(&cli2
, 1)) {
4151 cli_setatr(cli2
, fname
, 0, 0);
4152 cli_unlink(cli2
, fname
, aSYSTEM
| aHIDDEN
);
4154 cli_sockopt(cli2
, sockops
);
4156 printf("TEST #1 testing 2 non-io opens (no delete)\n");
4158 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
4159 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
4160 printf("test 1 open 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4164 if (!NT_STATUS_IS_OK(cli_ntcreate(cli2
, fname
, 0, FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
4165 FILE_SHARE_NONE
, FILE_OPEN_IF
, 0, 0, &fnum2
))) {
4166 printf("test 1 open 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
4170 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4171 printf("test 1 close 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4174 if (!NT_STATUS_IS_OK(cli_close(cli2
, fnum2
))) {
4175 printf("test 1 close 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
4179 printf("non-io open test #1 passed.\n");
4181 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
4183 printf("TEST #2 testing 2 non-io opens (first with delete)\n");
4185 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, DELETE_ACCESS
|FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
4186 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
4187 printf("test 2 open 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4191 if (!NT_STATUS_IS_OK(cli_ntcreate(cli2
, fname
, 0, FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
4192 FILE_SHARE_NONE
, FILE_OPEN_IF
, 0, 0, &fnum2
))) {
4193 printf("test 2 open 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
4197 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4198 printf("test 1 close 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4201 if (!NT_STATUS_IS_OK(cli_close(cli2
, fnum2
))) {
4202 printf("test 1 close 2 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4206 printf("non-io open test #2 passed.\n");
4208 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
4210 printf("TEST #3 testing 2 non-io opens (second with delete)\n");
4212 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
4213 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
4214 printf("test 3 open 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4218 if (!NT_STATUS_IS_OK(cli_ntcreate(cli2
, fname
, 0, DELETE_ACCESS
|FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
4219 FILE_SHARE_NONE
, FILE_OPEN_IF
, 0, 0, &fnum2
))) {
4220 printf("test 3 open 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
4224 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4225 printf("test 3 close 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4228 if (!NT_STATUS_IS_OK(cli_close(cli2
, fnum2
))) {
4229 printf("test 3 close 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
4233 printf("non-io open test #3 passed.\n");
4235 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
4237 printf("TEST #4 testing 2 non-io opens (both with delete)\n");
4239 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, DELETE_ACCESS
|FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
4240 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
4241 printf("test 4 open 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4245 if (NT_STATUS_IS_OK(cli_ntcreate(cli2
, fname
, 0, DELETE_ACCESS
|FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
4246 FILE_SHARE_NONE
, FILE_OPEN_IF
, 0, 0, &fnum2
))) {
4247 printf("test 4 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname
, cli_errstr(cli2
));
4251 printf("test 3 open 2 of %s gave %s (correct error should be %s)\n", fname
, cli_errstr(cli2
), "sharing violation");
4253 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4254 printf("test 4 close 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4258 printf("non-io open test #4 passed.\n");
4260 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
4262 printf("TEST #5 testing 2 non-io opens (both with delete - both with file share delete)\n");
4264 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, DELETE_ACCESS
|FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
4265 FILE_SHARE_DELETE
, FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
4266 printf("test 5 open 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4270 if (!NT_STATUS_IS_OK(cli_ntcreate(cli2
, fname
, 0, DELETE_ACCESS
|FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
4271 FILE_SHARE_DELETE
, FILE_OPEN_IF
, 0, 0, &fnum2
))) {
4272 printf("test 5 open 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
4276 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4277 printf("test 5 close 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4281 if (!NT_STATUS_IS_OK(cli_close(cli2
, fnum2
))) {
4282 printf("test 5 close 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
4286 printf("non-io open test #5 passed.\n");
4288 printf("TEST #6 testing 1 non-io open, one io open\n");
4290 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
4292 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, FILE_READ_DATA
, FILE_ATTRIBUTE_NORMAL
,
4293 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
4294 printf("test 6 open 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4298 if (!NT_STATUS_IS_OK(cli_ntcreate(cli2
, fname
, 0, FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
4299 FILE_SHARE_READ
, FILE_OPEN_IF
, 0, 0, &fnum2
))) {
4300 printf("test 6 open 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
4304 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4305 printf("test 6 close 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4309 if (!NT_STATUS_IS_OK(cli_close(cli2
, fnum2
))) {
4310 printf("test 6 close 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
4314 printf("non-io open test #6 passed.\n");
4316 printf("TEST #7 testing 1 non-io open, one io open with delete\n");
4318 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
4320 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, FILE_READ_DATA
, FILE_ATTRIBUTE_NORMAL
,
4321 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
4322 printf("test 7 open 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4326 if (NT_STATUS_IS_OK(cli_ntcreate(cli2
, fname
, 0, DELETE_ACCESS
|FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
4327 FILE_SHARE_READ
|FILE_SHARE_DELETE
, FILE_OPEN_IF
, 0, 0, &fnum2
))) {
4328 printf("test 7 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname
, cli_errstr(cli2
));
4332 printf("test 7 open 2 of %s gave %s (correct error should be %s)\n", fname
, cli_errstr(cli2
), "sharing violation");
4334 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4335 printf("test 7 close 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4339 printf("non-io open test #7 passed.\n");
4341 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
4343 if (!torture_close_connection(cli1
)) {
4346 if (!torture_close_connection(cli2
)) {
4354 Test POSIX open /mkdir calls.
4356 static bool run_simple_posix_open_test(int dummy
)
4358 static struct cli_state
*cli1
;
4359 const char *fname
= "posix:file";
4360 const char *hname
= "posix:hlink";
4361 const char *sname
= "posix:symlink";
4362 const char *dname
= "posix:dir";
4365 uint16 major
, minor
;
4366 uint32 caplow
, caphigh
;
4367 uint16_t fnum1
= (uint16_t)-1;
4368 SMB_STRUCT_STAT sbuf
;
4369 bool correct
= false;
4371 printf("Starting simple POSIX open test\n");
4373 if (!torture_open_connection(&cli1
, 0)) {
4377 cli_sockopt(cli1
, sockops
);
4379 if (!SERVER_HAS_UNIX_CIFS(cli1
)) {
4380 printf("Server doesn't support UNIX CIFS extensions.\n");
4384 if (!cli_unix_extensions_version(cli1
, &major
,
4385 &minor
, &caplow
, &caphigh
)) {
4386 printf("Server didn't return UNIX CIFS extensions.\n");
4390 if (!cli_set_unix_extensions_capabilities(cli1
,
4391 major
, minor
, caplow
, caphigh
)) {
4392 printf("Server doesn't support setting UNIX CIFS extensions.\n");
4396 cli_setatr(cli1
, fname
, 0, 0);
4397 cli_posix_unlink(cli1
, fname
);
4398 cli_setatr(cli1
, dname
, 0, 0);
4399 cli_posix_rmdir(cli1
, dname
);
4400 cli_setatr(cli1
, hname
, 0, 0);
4401 cli_posix_unlink(cli1
, hname
);
4402 cli_setatr(cli1
, sname
, 0, 0);
4403 cli_posix_unlink(cli1
, sname
);
4405 /* Create a directory. */
4406 if (!NT_STATUS_IS_OK(cli_posix_mkdir(cli1
, dname
, 0777))) {
4407 printf("POSIX mkdir of %s failed (%s)\n", dname
, cli_errstr(cli1
));
4411 if (!NT_STATUS_IS_OK(cli_posix_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, 0600, &fnum1
))) {
4412 printf("POSIX create of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4416 /* Test ftruncate - set file size. */
4417 if (!NT_STATUS_IS_OK(cli_ftruncate(cli1
, fnum1
, 1000))) {
4418 printf("ftruncate failed (%s)\n", cli_errstr(cli1
));
4422 /* Ensure st_size == 1000 */
4423 if (!NT_STATUS_IS_OK(cli_posix_stat(cli1
, fname
, &sbuf
))) {
4424 printf("stat failed (%s)\n", cli_errstr(cli1
));
4428 if (sbuf
.st_ex_size
!= 1000) {
4429 printf("ftruncate - stat size (%u) != 1000\n", (unsigned int)sbuf
.st_ex_size
);
4433 /* Test ftruncate - set file size back to zero. */
4434 if (!NT_STATUS_IS_OK(cli_ftruncate(cli1
, fnum1
, 0))) {
4435 printf("ftruncate failed (%s)\n", cli_errstr(cli1
));
4439 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4440 printf("close failed (%s)\n", cli_errstr(cli1
));
4444 /* Now open the file again for read only. */
4445 if (!NT_STATUS_IS_OK(cli_posix_open(cli1
, fname
, O_RDONLY
, 0, &fnum1
))) {
4446 printf("POSIX open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4450 /* Now unlink while open. */
4451 if (!NT_STATUS_IS_OK(cli_posix_unlink(cli1
, fname
))) {
4452 printf("POSIX unlink of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4456 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4457 printf("close(2) failed (%s)\n", cli_errstr(cli1
));
4461 /* Ensure the file has gone. */
4462 if (NT_STATUS_IS_OK(cli_posix_open(cli1
, fname
, O_RDONLY
, 0, &fnum1
))) {
4463 printf("POSIX open of %s succeeded, should have been deleted.\n", fname
);
4467 /* What happens when we try and POSIX open a directory ? */
4468 if (NT_STATUS_IS_OK(cli_posix_open(cli1
, dname
, O_RDONLY
, 0, &fnum1
))) {
4469 printf("POSIX open of directory %s succeeded, should have failed.\n", fname
);
4472 if (!check_error(__LINE__
, cli1
, ERRDOS
, EISDIR
,
4473 NT_STATUS_FILE_IS_A_DIRECTORY
)) {
4478 /* Create the file. */
4479 if (!NT_STATUS_IS_OK(cli_posix_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, 0600, &fnum1
))) {
4480 printf("POSIX create of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4484 /* Write some data into it. */
4485 if (cli_write(cli1
, fnum1
, 0, "TEST DATA\n", 0, 10) != 10) {
4486 printf("cli_write failed: %s\n", cli_errstr(cli1
));
4490 cli_close(cli1
, fnum1
);
4492 /* Now create a hardlink. */
4493 if (!NT_STATUS_IS_OK(cli_posix_hardlink(cli1
, fname
, hname
))) {
4494 printf("POSIX hardlink of %s failed (%s)\n", hname
, cli_errstr(cli1
));
4498 /* Now create a symlink. */
4499 if (!NT_STATUS_IS_OK(cli_posix_symlink(cli1
, fname
, sname
))) {
4500 printf("POSIX symlink of %s failed (%s)\n", sname
, cli_errstr(cli1
));
4504 /* Open the hardlink for read. */
4505 if (!NT_STATUS_IS_OK(cli_posix_open(cli1
, hname
, O_RDONLY
, 0, &fnum1
))) {
4506 printf("POSIX open of %s failed (%s)\n", hname
, cli_errstr(cli1
));
4510 if (cli_read(cli1
, fnum1
, buf
, 0, 10) != 10) {
4511 printf("POSIX read of %s failed (%s)\n", hname
, cli_errstr(cli1
));
4515 if (memcmp(buf
, "TEST DATA\n", 10)) {
4516 printf("invalid data read from hardlink\n");
4520 /* Do a POSIX lock/unlock. */
4521 if (!NT_STATUS_IS_OK(cli_posix_lock(cli1
, fnum1
, 0, 100, true, READ_LOCK
))) {
4522 printf("POSIX lock failed %s\n", cli_errstr(cli1
));
4526 /* Punch a hole in the locked area. */
4527 if (!NT_STATUS_IS_OK(cli_posix_unlock(cli1
, fnum1
, 10, 80))) {
4528 printf("POSIX unlock failed %s\n", cli_errstr(cli1
));
4532 cli_close(cli1
, fnum1
);
4534 /* Open the symlink for read - this should fail. A POSIX
4535 client should not be doing opens on a symlink. */
4536 if (NT_STATUS_IS_OK(cli_posix_open(cli1
, sname
, O_RDONLY
, 0, &fnum1
))) {
4537 printf("POSIX open of %s succeeded (should have failed)\n", sname
);
4540 if (!check_error(__LINE__
, cli1
, ERRDOS
, ERRbadpath
,
4541 NT_STATUS_OBJECT_PATH_NOT_FOUND
)) {
4542 printf("POSIX open of %s should have failed "
4543 "with NT_STATUS_OBJECT_PATH_NOT_FOUND, "
4544 "failed with %s instead.\n",
4545 sname
, cli_errstr(cli1
));
4550 if (!NT_STATUS_IS_OK(cli_posix_readlink(cli1
, sname
, namebuf
, sizeof(namebuf
)))) {
4551 printf("POSIX readlink on %s failed (%s)\n", sname
, cli_errstr(cli1
));
4555 if (strcmp(namebuf
, fname
) != 0) {
4556 printf("POSIX readlink on %s failed to match name %s (read %s)\n",
4557 sname
, fname
, namebuf
);
4561 if (!NT_STATUS_IS_OK(cli_posix_rmdir(cli1
, dname
))) {
4562 printf("POSIX rmdir failed (%s)\n", cli_errstr(cli1
));
4566 printf("Simple POSIX open test passed\n");
4571 if (fnum1
!= (uint16_t)-1) {
4572 cli_close(cli1
, fnum1
);
4573 fnum1
= (uint16_t)-1;
4576 cli_setatr(cli1
, sname
, 0, 0);
4577 cli_posix_unlink(cli1
, sname
);
4578 cli_setatr(cli1
, hname
, 0, 0);
4579 cli_posix_unlink(cli1
, hname
);
4580 cli_setatr(cli1
, fname
, 0, 0);
4581 cli_posix_unlink(cli1
, fname
);
4582 cli_setatr(cli1
, dname
, 0, 0);
4583 cli_posix_rmdir(cli1
, dname
);
4585 if (!torture_close_connection(cli1
)) {
4593 static uint32 open_attrs_table
[] = {
4594 FILE_ATTRIBUTE_NORMAL
,
4595 FILE_ATTRIBUTE_ARCHIVE
,
4596 FILE_ATTRIBUTE_READONLY
,
4597 FILE_ATTRIBUTE_HIDDEN
,
4598 FILE_ATTRIBUTE_SYSTEM
,
4600 FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
,
4601 FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
,
4602 FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
,
4603 FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
,
4604 FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_SYSTEM
,
4605 FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_SYSTEM
,
4607 FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
,
4608 FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_SYSTEM
,
4609 FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_SYSTEM
,
4610 FILE_ATTRIBUTE_HIDDEN
,FILE_ATTRIBUTE_SYSTEM
,
4613 struct trunc_open_results
{
4620 static struct trunc_open_results attr_results
[] = {
4621 { 0, FILE_ATTRIBUTE_NORMAL
, FILE_ATTRIBUTE_NORMAL
, FILE_ATTRIBUTE_ARCHIVE
},
4622 { 1, FILE_ATTRIBUTE_NORMAL
, FILE_ATTRIBUTE_ARCHIVE
, FILE_ATTRIBUTE_ARCHIVE
},
4623 { 2, FILE_ATTRIBUTE_NORMAL
, FILE_ATTRIBUTE_READONLY
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
},
4624 { 16, FILE_ATTRIBUTE_ARCHIVE
, FILE_ATTRIBUTE_NORMAL
, FILE_ATTRIBUTE_ARCHIVE
},
4625 { 17, FILE_ATTRIBUTE_ARCHIVE
, FILE_ATTRIBUTE_ARCHIVE
, FILE_ATTRIBUTE_ARCHIVE
},
4626 { 18, FILE_ATTRIBUTE_ARCHIVE
, FILE_ATTRIBUTE_READONLY
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
},
4627 { 51, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
},
4628 { 54, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
},
4629 { 56, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
},
4630 { 68, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
},
4631 { 71, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
},
4632 { 73, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_SYSTEM
},
4633 { 99, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_HIDDEN
,FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
},
4634 { 102, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
},
4635 { 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
},
4636 { 116, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
},
4637 { 119, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
},
4638 { 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
},
4639 { 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
},
4640 { 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
},
4641 { 227, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
},
4642 { 230, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
},
4643 { 232, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
},
4644 { 244, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
},
4645 { 247, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
},
4646 { 249, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_SYSTEM
}
4649 static bool run_openattrtest(int dummy
)
4651 static struct cli_state
*cli1
;
4652 const char *fname
= "\\openattr.file";
4654 bool correct
= True
;
4656 unsigned int i
, j
, k
, l
;
4658 printf("starting open attr test\n");
4660 if (!torture_open_connection(&cli1
, 0)) {
4664 cli_sockopt(cli1
, sockops
);
4666 for (k
= 0, i
= 0; i
< sizeof(open_attrs_table
)/sizeof(uint32
); i
++) {
4667 cli_setatr(cli1
, fname
, 0, 0);
4668 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
4669 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, FILE_WRITE_DATA
, open_attrs_table
[i
],
4670 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
4671 printf("open %d (1) of %s failed (%s)\n", i
, fname
, cli_errstr(cli1
));
4675 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4676 printf("close %d (1) of %s failed (%s)\n", i
, fname
, cli_errstr(cli1
));
4680 for (j
= 0; j
< sizeof(open_attrs_table
)/sizeof(uint32
); j
++) {
4681 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, FILE_READ_DATA
|FILE_WRITE_DATA
, open_attrs_table
[j
],
4682 FILE_SHARE_NONE
, FILE_OVERWRITE
, 0, 0, &fnum1
))) {
4683 for (l
= 0; l
< sizeof(attr_results
)/sizeof(struct trunc_open_results
); l
++) {
4684 if (attr_results
[l
].num
== k
) {
4685 printf("[%d] trunc open 0x%x -> 0x%x of %s failed - should have succeeded !(0x%x:%s)\n",
4686 k
, open_attrs_table
[i
],
4687 open_attrs_table
[j
],
4688 fname
, NT_STATUS_V(cli_nt_error(cli1
)), cli_errstr(cli1
));
4692 if (NT_STATUS_V(cli_nt_error(cli1
)) != NT_STATUS_V(NT_STATUS_ACCESS_DENIED
)) {
4693 printf("[%d] trunc open 0x%x -> 0x%x failed with wrong error code %s\n",
4694 k
, open_attrs_table
[i
], open_attrs_table
[j
],
4699 printf("[%d] trunc open 0x%x -> 0x%x failed\n", k
, open_attrs_table
[i
], open_attrs_table
[j
]);
4705 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4706 printf("close %d (2) of %s failed (%s)\n", j
, fname
, cli_errstr(cli1
));
4710 if (!NT_STATUS_IS_OK(cli_getatr(cli1
, fname
, &attr
, NULL
, NULL
))) {
4711 printf("getatr(2) failed (%s)\n", cli_errstr(cli1
));
4716 printf("[%d] getatr check [0x%x] trunc [0x%x] got attr 0x%x\n",
4717 k
, open_attrs_table
[i
], open_attrs_table
[j
], attr
);
4720 for (l
= 0; l
< sizeof(attr_results
)/sizeof(struct trunc_open_results
); l
++) {
4721 if (attr_results
[l
].num
== k
) {
4722 if (attr
!= attr_results
[l
].result_attr
||
4723 open_attrs_table
[i
] != attr_results
[l
].init_attr
||
4724 open_attrs_table
[j
] != attr_results
[l
].trunc_attr
) {
4725 printf("getatr check failed. [0x%x] trunc [0x%x] got attr 0x%x, should be 0x%x\n",
4726 open_attrs_table
[i
],
4727 open_attrs_table
[j
],
4729 attr_results
[l
].result_attr
);
4739 cli_setatr(cli1
, fname
, 0, 0);
4740 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
4742 printf("open attr test %s.\n", correct
? "passed" : "failed");
4744 if (!torture_close_connection(cli1
)) {
4750 static void list_fn(const char *mnt
, file_info
*finfo
, const char *name
, void *state
)
4756 test directory listing speed
4758 static bool run_dirtest(int dummy
)
4761 static struct cli_state
*cli
;
4764 bool correct
= True
;
4766 printf("starting directory test\n");
4768 if (!torture_open_connection(&cli
, 0)) {
4772 cli_sockopt(cli
, sockops
);
4775 for (i
=0;i
<torture_numops
;i
++) {
4777 slprintf(fname
, sizeof(fname
), "\\%x", (int)random());
4778 if (!NT_STATUS_IS_OK(cli_open(cli
, fname
, O_RDWR
|O_CREAT
, DENY_NONE
, &fnum
))) {
4779 fprintf(stderr
,"Failed to open %s\n", fname
);
4782 cli_close(cli
, fnum
);
4787 printf("Matched %d\n", cli_list(cli
, "a*.*", 0, list_fn
, NULL
));
4788 printf("Matched %d\n", cli_list(cli
, "b*.*", 0, list_fn
, NULL
));
4789 printf("Matched %d\n", cli_list(cli
, "xyzabc", 0, list_fn
, NULL
));
4791 printf("dirtest core %g seconds\n", end_timer() - t1
);
4794 for (i
=0;i
<torture_numops
;i
++) {
4796 slprintf(fname
, sizeof(fname
), "\\%x", (int)random());
4797 cli_unlink(cli
, fname
, aSYSTEM
| aHIDDEN
);
4800 if (!torture_close_connection(cli
)) {
4804 printf("finished dirtest\n");
4809 static void del_fn(const char *mnt
, file_info
*finfo
, const char *mask
, void *state
)
4811 struct cli_state
*pcli
= (struct cli_state
*)state
;
4813 slprintf(fname
, sizeof(fname
), "\\LISTDIR\\%s", finfo
->name
);
4815 if (strcmp(finfo
->name
, ".") == 0 || strcmp(finfo
->name
, "..") == 0)
4818 if (finfo
->mode
& aDIR
) {
4819 if (!NT_STATUS_IS_OK(cli_rmdir(pcli
, fname
)))
4820 printf("del_fn: failed to rmdir %s\n,", fname
);
4822 if (!NT_STATUS_IS_OK(cli_unlink(pcli
, fname
, aSYSTEM
| aHIDDEN
)))
4823 printf("del_fn: failed to unlink %s\n,", fname
);
4829 sees what IOCTLs are supported
4831 bool torture_ioctl_test(int dummy
)
4833 static struct cli_state
*cli
;
4834 uint16_t device
, function
;
4836 const char *fname
= "\\ioctl.dat";
4840 if (!torture_open_connection(&cli
, 0)) {
4844 printf("starting ioctl test\n");
4846 cli_unlink(cli
, fname
, aSYSTEM
| aHIDDEN
);
4848 if (!NT_STATUS_IS_OK(cli_open(cli
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum
))) {
4849 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli
));
4853 status
= cli_raw_ioctl(cli
, fnum
, 0x2d0000 | (0x0420<<2), &blob
);
4854 printf("ioctl device info: %s\n", cli_errstr(cli
));
4856 status
= cli_raw_ioctl(cli
, fnum
, IOCTL_QUERY_JOB_INFO
, &blob
);
4857 printf("ioctl job info: %s\n", cli_errstr(cli
));
4859 for (device
=0;device
<0x100;device
++) {
4860 printf("testing device=0x%x\n", device
);
4861 for (function
=0;function
<0x100;function
++) {
4862 uint32 code
= (device
<<16) | function
;
4864 status
= cli_raw_ioctl(cli
, fnum
, code
, &blob
);
4866 if (NT_STATUS_IS_OK(status
)) {
4867 printf("ioctl 0x%x OK : %d bytes\n", (int)code
,
4869 data_blob_free(&blob
);
4874 if (!torture_close_connection(cli
)) {
4883 tries varients of chkpath
4885 bool torture_chkpath_test(int dummy
)
4887 static struct cli_state
*cli
;
4891 if (!torture_open_connection(&cli
, 0)) {
4895 printf("starting chkpath test\n");
4897 /* cleanup from an old run */
4898 cli_rmdir(cli
, "\\chkpath.dir\\dir2");
4899 cli_unlink(cli
, "\\chkpath.dir\\*", aSYSTEM
| aHIDDEN
);
4900 cli_rmdir(cli
, "\\chkpath.dir");
4902 if (!NT_STATUS_IS_OK(cli_mkdir(cli
, "\\chkpath.dir"))) {
4903 printf("mkdir1 failed : %s\n", cli_errstr(cli
));
4907 if (!NT_STATUS_IS_OK(cli_mkdir(cli
, "\\chkpath.dir\\dir2"))) {
4908 printf("mkdir2 failed : %s\n", cli_errstr(cli
));
4912 if (!NT_STATUS_IS_OK(cli_open(cli
, "\\chkpath.dir\\foo.txt", O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum
))) {
4913 printf("open1 failed (%s)\n", cli_errstr(cli
));
4916 cli_close(cli
, fnum
);
4918 if (!NT_STATUS_IS_OK(cli_chkpath(cli
, "\\chkpath.dir"))) {
4919 printf("chkpath1 failed: %s\n", cli_errstr(cli
));
4923 if (!NT_STATUS_IS_OK(cli_chkpath(cli
, "\\chkpath.dir\\dir2"))) {
4924 printf("chkpath2 failed: %s\n", cli_errstr(cli
));
4928 if (!NT_STATUS_IS_OK(cli_chkpath(cli
, "\\chkpath.dir\\foo.txt"))) {
4929 ret
= check_error(__LINE__
, cli
, ERRDOS
, ERRbadpath
,
4930 NT_STATUS_NOT_A_DIRECTORY
);
4932 printf("* chkpath on a file should fail\n");
4936 if (!NT_STATUS_IS_OK(cli_chkpath(cli
, "\\chkpath.dir\\bar.txt"))) {
4937 ret
= check_error(__LINE__
, cli
, ERRDOS
, ERRbadfile
,
4938 NT_STATUS_OBJECT_NAME_NOT_FOUND
);
4940 printf("* chkpath on a non existant file should fail\n");
4944 if (!NT_STATUS_IS_OK(cli_chkpath(cli
, "\\chkpath.dir\\dirxx\\bar.txt"))) {
4945 ret
= check_error(__LINE__
, cli
, ERRDOS
, ERRbadpath
,
4946 NT_STATUS_OBJECT_PATH_NOT_FOUND
);
4948 printf("* chkpath on a non existent component should fail\n");
4952 cli_rmdir(cli
, "\\chkpath.dir\\dir2");
4953 cli_unlink(cli
, "\\chkpath.dir\\*", aSYSTEM
| aHIDDEN
);
4954 cli_rmdir(cli
, "\\chkpath.dir");
4956 if (!torture_close_connection(cli
)) {
4963 static bool run_eatest(int dummy
)
4965 static struct cli_state
*cli
;
4966 const char *fname
= "\\eatest.txt";
4967 bool correct
= True
;
4971 struct ea_struct
*ea_list
= NULL
;
4972 TALLOC_CTX
*mem_ctx
= talloc_init("eatest");
4974 printf("starting eatest\n");
4976 if (!torture_open_connection(&cli
, 0)) {
4977 talloc_destroy(mem_ctx
);
4981 cli_unlink(cli
, fname
, aSYSTEM
| aHIDDEN
);
4982 if (!NT_STATUS_IS_OK(cli_ntcreate(cli
, fname
, 0,
4983 FIRST_DESIRED_ACCESS
, FILE_ATTRIBUTE_ARCHIVE
,
4984 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
,
4985 0x4044, 0, &fnum
))) {
4986 printf("open failed - %s\n", cli_errstr(cli
));
4987 talloc_destroy(mem_ctx
);
4991 for (i
= 0; i
< 10; i
++) {
4992 fstring ea_name
, ea_val
;
4994 slprintf(ea_name
, sizeof(ea_name
), "EA_%d", i
);
4995 memset(ea_val
, (char)i
+1, i
+1);
4996 if (!cli_set_ea_fnum(cli
, fnum
, ea_name
, ea_val
, i
+1)) {
4997 printf("ea_set of name %s failed - %s\n", ea_name
, cli_errstr(cli
));
4998 talloc_destroy(mem_ctx
);
5003 cli_close(cli
, fnum
);
5004 for (i
= 0; i
< 10; i
++) {
5005 fstring ea_name
, ea_val
;
5007 slprintf(ea_name
, sizeof(ea_name
), "EA_%d", i
+10);
5008 memset(ea_val
, (char)i
+1, i
+1);
5009 if (!cli_set_ea_path(cli
, fname
, ea_name
, ea_val
, i
+1)) {
5010 printf("ea_set of name %s failed - %s\n", ea_name
, cli_errstr(cli
));
5011 talloc_destroy(mem_ctx
);
5016 if (!cli_get_ea_list_path(cli
, fname
, mem_ctx
, &num_eas
, &ea_list
)) {
5017 printf("ea_get list failed - %s\n", cli_errstr(cli
));
5021 printf("num_eas = %d\n", (int)num_eas
);
5023 if (num_eas
!= 20) {
5024 printf("Should be 20 EA's stored... failing.\n");
5028 for (i
= 0; i
< num_eas
; i
++) {
5029 printf("%d: ea_name = %s. Val = ", i
, ea_list
[i
].name
);
5030 dump_data(0, ea_list
[i
].value
.data
,
5031 ea_list
[i
].value
.length
);
5034 /* Setting EA's to zero length deletes them. Test this */
5035 printf("Now deleting all EA's - case indepenent....\n");
5038 cli_set_ea_path(cli
, fname
, "", "", 0);
5040 for (i
= 0; i
< 20; i
++) {
5042 slprintf(ea_name
, sizeof(ea_name
), "ea_%d", i
);
5043 if (!cli_set_ea_path(cli
, fname
, ea_name
, "", 0)) {
5044 printf("ea_set of name %s failed - %s\n", ea_name
, cli_errstr(cli
));
5045 talloc_destroy(mem_ctx
);
5051 if (!cli_get_ea_list_path(cli
, fname
, mem_ctx
, &num_eas
, &ea_list
)) {
5052 printf("ea_get list failed - %s\n", cli_errstr(cli
));
5056 printf("num_eas = %d\n", (int)num_eas
);
5057 for (i
= 0; i
< num_eas
; i
++) {
5058 printf("%d: ea_name = %s. Val = ", i
, ea_list
[i
].name
);
5059 dump_data(0, ea_list
[i
].value
.data
,
5060 ea_list
[i
].value
.length
);
5064 printf("deleting EA's failed.\n");
5068 /* Try and delete a non existant EA. */
5069 if (!cli_set_ea_path(cli
, fname
, "foo", "", 0)) {
5070 printf("deleting non-existant EA 'foo' should succeed. %s\n", cli_errstr(cli
));
5074 talloc_destroy(mem_ctx
);
5075 if (!torture_close_connection(cli
)) {
5082 static bool run_dirtest1(int dummy
)
5085 static struct cli_state
*cli
;
5088 bool correct
= True
;
5090 printf("starting directory test\n");
5092 if (!torture_open_connection(&cli
, 0)) {
5096 cli_sockopt(cli
, sockops
);
5098 cli_list(cli
, "\\LISTDIR\\*", 0, del_fn
, cli
);
5099 cli_list(cli
, "\\LISTDIR\\*", aDIR
, del_fn
, cli
);
5100 cli_rmdir(cli
, "\\LISTDIR");
5101 cli_mkdir(cli
, "\\LISTDIR");
5103 /* Create 1000 files and 1000 directories. */
5104 for (i
=0;i
<1000;i
++) {
5106 slprintf(fname
, sizeof(fname
), "\\LISTDIR\\f%d", i
);
5107 if (!NT_STATUS_IS_OK(cli_ntcreate(cli
, fname
, 0, GENERIC_ALL_ACCESS
, FILE_ATTRIBUTE_ARCHIVE
,
5108 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OVERWRITE_IF
, 0, 0, &fnum
))) {
5109 fprintf(stderr
,"Failed to open %s\n", fname
);
5112 cli_close(cli
, fnum
);
5114 for (i
=0;i
<1000;i
++) {
5116 slprintf(fname
, sizeof(fname
), "\\LISTDIR\\d%d", i
);
5117 if (!NT_STATUS_IS_OK(cli_mkdir(cli
, fname
))) {
5118 fprintf(stderr
,"Failed to open %s\n", fname
);
5123 /* Now ensure that doing an old list sees both files and directories. */
5124 num_seen
= cli_list_old(cli
, "\\LISTDIR\\*", aDIR
, list_fn
, NULL
);
5125 printf("num_seen = %d\n", num_seen
);
5126 /* We should see 100 files + 1000 directories + . and .. */
5127 if (num_seen
!= 2002)
5130 /* Ensure if we have the "must have" bits we only see the
5133 num_seen
= cli_list_old(cli
, "\\LISTDIR\\*", (aDIR
<<8)|aDIR
, list_fn
, NULL
);
5134 printf("num_seen = %d\n", num_seen
);
5135 if (num_seen
!= 1002)
5138 num_seen
= cli_list_old(cli
, "\\LISTDIR\\*", (aARCH
<<8)|aDIR
, list_fn
, NULL
);
5139 printf("num_seen = %d\n", num_seen
);
5140 if (num_seen
!= 1000)
5143 /* Delete everything. */
5144 cli_list(cli
, "\\LISTDIR\\*", 0, del_fn
, cli
);
5145 cli_list(cli
, "\\LISTDIR\\*", aDIR
, del_fn
, cli
);
5146 cli_rmdir(cli
, "\\LISTDIR");
5149 printf("Matched %d\n", cli_list(cli
, "a*.*", 0, list_fn
, NULL
));
5150 printf("Matched %d\n", cli_list(cli
, "b*.*", 0, list_fn
, NULL
));
5151 printf("Matched %d\n", cli_list(cli
, "xyzabc", 0, list_fn
, NULL
));
5154 if (!torture_close_connection(cli
)) {
5158 printf("finished dirtest1\n");
5163 static bool run_error_map_extract(int dummy
) {
5165 static struct cli_state
*c_dos
;
5166 static struct cli_state
*c_nt
;
5171 uint32 flgs2
, errnum
;
5178 /* NT-Error connection */
5180 if (!(c_nt
= open_nbt_connection())) {
5184 c_nt
->use_spnego
= False
;
5186 status
= cli_negprot(c_nt
);
5188 if (!NT_STATUS_IS_OK(status
)) {
5189 printf("%s rejected the NT-error negprot (%s)\n", host
,
5195 if (!NT_STATUS_IS_OK(cli_session_setup(c_nt
, "", "", 0, "", 0,
5197 printf("%s rejected the NT-error initial session setup (%s)\n",host
, cli_errstr(c_nt
));
5201 /* DOS-Error connection */
5203 if (!(c_dos
= open_nbt_connection())) {
5207 c_dos
->use_spnego
= False
;
5208 c_dos
->force_dos_errors
= True
;
5210 status
= cli_negprot(c_dos
);
5211 if (!NT_STATUS_IS_OK(status
)) {
5212 printf("%s rejected the DOS-error negprot (%s)\n", host
,
5214 cli_shutdown(c_dos
);
5218 if (!NT_STATUS_IS_OK(cli_session_setup(c_dos
, "", "", 0, "", 0,
5220 printf("%s rejected the DOS-error initial session setup (%s)\n",host
, cli_errstr(c_dos
));
5224 for (error
=(0xc0000000 | 0x1); error
< (0xc0000000| 0xFFF); error
++) {
5225 fstr_sprintf(user
, "%X", error
);
5227 if (NT_STATUS_IS_OK(cli_session_setup(c_nt
, user
,
5228 password
, strlen(password
),
5229 password
, strlen(password
),
5231 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
5234 flgs2
= SVAL(c_nt
->inbuf
,smb_flg2
);
5236 /* Case #1: 32-bit NT errors */
5237 if (flgs2
& FLAGS2_32_BIT_ERROR_CODES
) {
5238 nt_status
= NT_STATUS(IVAL(c_nt
->inbuf
,smb_rcls
));
5240 printf("/** Dos error on NT connection! (%s) */\n",
5242 nt_status
= NT_STATUS(0xc0000000);
5245 if (NT_STATUS_IS_OK(cli_session_setup(c_dos
, user
,
5246 password
, strlen(password
),
5247 password
, strlen(password
),
5249 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
5251 flgs2
= SVAL(c_dos
->inbuf
,smb_flg2
), errnum
;
5253 /* Case #1: 32-bit NT errors */
5254 if (flgs2
& FLAGS2_32_BIT_ERROR_CODES
) {
5255 printf("/** NT error on DOS connection! (%s) */\n",
5257 errnum
= errclass
= 0;
5259 cli_dos_error(c_dos
, &errclass
, &errnum
);
5262 if (NT_STATUS_V(nt_status
) != error
) {
5263 printf("/*\t{ This NT error code was 'sqashed'\n\t from %s to %s \n\t during the session setup }\n*/\n",
5264 get_nt_error_c_code(NT_STATUS(error
)),
5265 get_nt_error_c_code(nt_status
));
5268 printf("\t{%s,\t%s,\t%s},\n",
5269 smb_dos_err_class(errclass
),
5270 smb_dos_err_name(errclass
, errnum
),
5271 get_nt_error_c_code(NT_STATUS(error
)));
5276 static bool run_sesssetup_bench(int dummy
)
5278 static struct cli_state
*c
;
5279 const char *fname
= "\\file.dat";
5284 if (!torture_open_connection(&c
, 0)) {
5288 if (!NT_STATUS_IS_OK(cli_ntcreate(
5289 c
, fname
, 0, GENERIC_ALL_ACCESS
|DELETE_ACCESS
,
5290 FILE_ATTRIBUTE_NORMAL
, 0, FILE_OVERWRITE_IF
,
5291 FILE_DELETE_ON_CLOSE
, 0, &fnum
))) {
5292 d_printf("open %s failed: %s\n", fname
, cli_errstr(c
));
5296 for (i
=0; i
<torture_numops
; i
++) {
5297 status
= cli_session_setup(
5299 password
, strlen(password
),
5300 password
, strlen(password
),
5302 if (!NT_STATUS_IS_OK(status
)) {
5303 d_printf("(%s) cli_session_setup failed: %s\n",
5304 __location__
, nt_errstr(status
));
5308 d_printf("\r%d ", (int)c
->vuid
);
5310 if (!cli_ulogoff(c
)) {
5311 d_printf("(%s) cli_ulogoff failed: %s\n",
5312 __location__
, cli_errstr(c
));
5321 static bool subst_test(const char *str
, const char *user
, const char *domain
,
5322 uid_t uid
, gid_t gid
, const char *expected
)
5327 subst
= talloc_sub_specified(talloc_tos(), str
, user
, domain
, uid
, gid
);
5329 if (strcmp(subst
, expected
) != 0) {
5330 printf("sub_specified(%s, %s, %s, %d, %d) returned [%s], expected "
5331 "[%s]\n", str
, user
, domain
, (int)uid
, (int)gid
, subst
,
5340 static void chain1_open_completion(struct tevent_req
*req
)
5344 status
= cli_open_recv(req
, &fnum
);
5347 d_printf("cli_open_recv returned %s: %d\n",
5349 NT_STATUS_IS_OK(status
) ? fnum
: -1);
5352 static void chain1_write_completion(struct tevent_req
*req
)
5356 status
= cli_write_andx_recv(req
, &written
);
5359 d_printf("cli_write_andx_recv returned %s: %d\n",
5361 NT_STATUS_IS_OK(status
) ? (int)written
: -1);
5364 static void chain1_close_completion(struct tevent_req
*req
)
5367 bool *done
= (bool *)tevent_req_callback_data_void(req
);
5369 status
= cli_close_recv(req
);
5374 d_printf("cli_close returned %s\n", nt_errstr(status
));
5377 static bool run_chain1(int dummy
)
5379 struct cli_state
*cli1
;
5380 struct event_context
*evt
= event_context_init(NULL
);
5381 struct tevent_req
*reqs
[3], *smbreqs
[3];
5383 const char *str
= "foobar";
5386 printf("starting chain1 test\n");
5387 if (!torture_open_connection(&cli1
, 0)) {
5391 cli_sockopt(cli1
, sockops
);
5393 reqs
[0] = cli_open_create(talloc_tos(), evt
, cli1
, "\\test",
5394 O_CREAT
|O_RDWR
, 0, &smbreqs
[0]);
5395 if (reqs
[0] == NULL
) return false;
5396 tevent_req_set_callback(reqs
[0], chain1_open_completion
, NULL
);
5399 reqs
[1] = cli_write_andx_create(talloc_tos(), evt
, cli1
, 0, 0,
5400 (uint8_t *)str
, 0, strlen(str
)+1,
5401 smbreqs
, 1, &smbreqs
[1]);
5402 if (reqs
[1] == NULL
) return false;
5403 tevent_req_set_callback(reqs
[1], chain1_write_completion
, NULL
);
5405 reqs
[2] = cli_close_create(talloc_tos(), evt
, cli1
, 0, &smbreqs
[2]);
5406 if (reqs
[2] == NULL
) return false;
5407 tevent_req_set_callback(reqs
[2], chain1_close_completion
, &done
);
5409 status
= cli_smb_chain_send(smbreqs
, ARRAY_SIZE(smbreqs
));
5410 if (!NT_STATUS_IS_OK(status
)) {
5415 event_loop_once(evt
);
5418 torture_close_connection(cli1
);
5422 static void chain2_sesssetup_completion(struct tevent_req
*req
)
5425 status
= cli_session_setup_guest_recv(req
);
5426 d_printf("sesssetup returned %s\n", nt_errstr(status
));
5429 static void chain2_tcon_completion(struct tevent_req
*req
)
5431 bool *done
= (bool *)tevent_req_callback_data_void(req
);
5433 status
= cli_tcon_andx_recv(req
);
5434 d_printf("tcon_and_x returned %s\n", nt_errstr(status
));
5438 static bool run_chain2(int dummy
)
5440 struct cli_state
*cli1
;
5441 struct event_context
*evt
= event_context_init(NULL
);
5442 struct tevent_req
*reqs
[2], *smbreqs
[2];
5446 printf("starting chain2 test\n");
5447 status
= cli_start_connection(&cli1
, global_myname(), host
, NULL
,
5448 port_to_use
, Undefined
, 0, NULL
);
5449 if (!NT_STATUS_IS_OK(status
)) {
5453 cli_sockopt(cli1
, sockops
);
5455 reqs
[0] = cli_session_setup_guest_create(talloc_tos(), evt
, cli1
,
5457 if (reqs
[0] == NULL
) return false;
5458 tevent_req_set_callback(reqs
[0], chain2_sesssetup_completion
, NULL
);
5460 reqs
[1] = cli_tcon_andx_create(talloc_tos(), evt
, cli1
, "IPC$",
5461 "?????", NULL
, 0, &smbreqs
[1]);
5462 if (reqs
[1] == NULL
) return false;
5463 tevent_req_set_callback(reqs
[1], chain2_tcon_completion
, &done
);
5465 status
= cli_smb_chain_send(smbreqs
, ARRAY_SIZE(smbreqs
));
5466 if (!NT_STATUS_IS_OK(status
)) {
5471 event_loop_once(evt
);
5474 torture_close_connection(cli1
);
5479 struct torture_createdel_state
{
5480 struct tevent_context
*ev
;
5481 struct cli_state
*cli
;
5484 static void torture_createdel_created(struct tevent_req
*subreq
);
5485 static void torture_createdel_closed(struct tevent_req
*subreq
);
5487 static struct tevent_req
*torture_createdel_send(TALLOC_CTX
*mem_ctx
,
5488 struct tevent_context
*ev
,
5489 struct cli_state
*cli
,
5492 struct tevent_req
*req
, *subreq
;
5493 struct torture_createdel_state
*state
;
5495 req
= tevent_req_create(mem_ctx
, &state
,
5496 struct torture_createdel_state
);
5503 subreq
= cli_ntcreate_send(
5504 state
, ev
, cli
, name
, 0,
5505 FILE_READ_DATA
|FILE_WRITE_DATA
|DELETE_ACCESS
,
5506 FILE_ATTRIBUTE_NORMAL
,
5507 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
5508 FILE_OPEN_IF
, FILE_DELETE_ON_CLOSE
, 0);
5510 if (tevent_req_nomem(subreq
, req
)) {
5511 return tevent_req_post(req
, ev
);
5513 tevent_req_set_callback(subreq
, torture_createdel_created
, req
);
5517 static void torture_createdel_created(struct tevent_req
*subreq
)
5519 struct tevent_req
*req
= tevent_req_callback_data(
5520 subreq
, struct tevent_req
);
5521 struct torture_createdel_state
*state
= tevent_req_data(
5522 req
, struct torture_createdel_state
);
5526 status
= cli_ntcreate_recv(subreq
, &fnum
);
5527 TALLOC_FREE(subreq
);
5528 if (!NT_STATUS_IS_OK(status
)) {
5529 DEBUG(10, ("cli_ntcreate_recv returned %s\n",
5530 nt_errstr(status
)));
5531 tevent_req_nterror(req
, status
);
5535 subreq
= cli_close_send(state
, state
->ev
, state
->cli
, fnum
);
5536 if (tevent_req_nomem(subreq
, req
)) {
5539 tevent_req_set_callback(subreq
, torture_createdel_closed
, req
);
5542 static void torture_createdel_closed(struct tevent_req
*subreq
)
5544 struct tevent_req
*req
= tevent_req_callback_data(
5545 subreq
, struct tevent_req
);
5548 status
= cli_close_recv(subreq
);
5549 if (!NT_STATUS_IS_OK(status
)) {
5550 DEBUG(10, ("cli_close_recv returned %s\n", nt_errstr(status
)));
5551 tevent_req_nterror(req
, status
);
5554 tevent_req_done(req
);
5557 static NTSTATUS
torture_createdel_recv(struct tevent_req
*req
)
5559 return tevent_req_simple_recv_ntstatus(req
);
5562 struct torture_createdels_state
{
5563 struct tevent_context
*ev
;
5564 struct cli_state
*cli
;
5565 const char *base_name
;
5569 struct tevent_req
**reqs
;
5572 static void torture_createdels_done(struct tevent_req
*subreq
);
5574 static struct tevent_req
*torture_createdels_send(TALLOC_CTX
*mem_ctx
,
5575 struct tevent_context
*ev
,
5576 struct cli_state
*cli
,
5577 const char *base_name
,
5581 struct tevent_req
*req
;
5582 struct torture_createdels_state
*state
;
5585 req
= tevent_req_create(mem_ctx
, &state
,
5586 struct torture_createdels_state
);
5592 state
->base_name
= talloc_strdup(state
, base_name
);
5593 if (tevent_req_nomem(state
->base_name
, req
)) {
5594 return tevent_req_post(req
, ev
);
5596 state
->num_files
= MAX(num_parallel
, num_files
);
5598 state
->received
= 0;
5600 state
->reqs
= talloc_array(state
, struct tevent_req
*, num_parallel
);
5601 if (tevent_req_nomem(state
->reqs
, req
)) {
5602 return tevent_req_post(req
, ev
);
5605 for (i
=0; i
<num_parallel
; i
++) {
5608 name
= talloc_asprintf(state
, "%s%8.8d", state
->base_name
,
5610 if (tevent_req_nomem(name
, req
)) {
5611 return tevent_req_post(req
, ev
);
5613 state
->reqs
[i
] = torture_createdel_send(
5614 state
->reqs
, state
->ev
, state
->cli
, name
);
5615 if (tevent_req_nomem(state
->reqs
[i
], req
)) {
5616 return tevent_req_post(req
, ev
);
5618 name
= talloc_move(state
->reqs
[i
], &name
);
5619 tevent_req_set_callback(state
->reqs
[i
],
5620 torture_createdels_done
, req
);
5626 static void torture_createdels_done(struct tevent_req
*subreq
)
5628 struct tevent_req
*req
= tevent_req_callback_data(
5629 subreq
, struct tevent_req
);
5630 struct torture_createdels_state
*state
= tevent_req_data(
5631 req
, struct torture_createdels_state
);
5632 size_t num_parallel
= talloc_array_length(state
->reqs
);
5637 status
= torture_createdel_recv(subreq
);
5638 if (!NT_STATUS_IS_OK(status
)){
5639 DEBUG(10, ("torture_createdel_recv returned %s\n",
5640 nt_errstr(status
)));
5641 TALLOC_FREE(subreq
);
5642 tevent_req_nterror(req
, status
);
5646 for (i
=0; i
<num_parallel
; i
++) {
5647 if (subreq
== state
->reqs
[i
]) {
5651 if (i
== num_parallel
) {
5652 DEBUG(10, ("received something we did not send\n"));
5653 tevent_req_nterror(req
, NT_STATUS_INTERNAL_ERROR
);
5656 TALLOC_FREE(state
->reqs
[i
]);
5658 if (state
->sent
>= state
->num_files
) {
5659 tevent_req_done(req
);
5663 name
= talloc_asprintf(state
, "%s%8.8d", state
->base_name
,
5665 if (tevent_req_nomem(name
, req
)) {
5668 state
->reqs
[i
] = torture_createdel_send(state
->reqs
, state
->ev
,
5670 if (tevent_req_nomem(state
->reqs
[i
], req
)) {
5673 name
= talloc_move(state
->reqs
[i
], &name
);
5674 tevent_req_set_callback(state
->reqs
[i
], torture_createdels_done
, req
);
5678 static NTSTATUS
torture_createdels_recv(struct tevent_req
*req
)
5680 return tevent_req_simple_recv_ntstatus(req
);
5683 struct swallow_notify_state
{
5684 struct tevent_context
*ev
;
5685 struct cli_state
*cli
;
5687 uint32_t completion_filter
;
5689 bool (*fn
)(uint32_t action
, const char *name
, void *priv
);
5693 static void swallow_notify_done(struct tevent_req
*subreq
);
5695 static struct tevent_req
*swallow_notify_send(TALLOC_CTX
*mem_ctx
,
5696 struct tevent_context
*ev
,
5697 struct cli_state
*cli
,
5699 uint32_t completion_filter
,
5701 bool (*fn
)(uint32_t action
,
5706 struct tevent_req
*req
, *subreq
;
5707 struct swallow_notify_state
*state
;
5709 req
= tevent_req_create(mem_ctx
, &state
,
5710 struct swallow_notify_state
);
5717 state
->completion_filter
= completion_filter
;
5718 state
->recursive
= recursive
;
5722 subreq
= cli_notify_send(state
, state
->ev
, state
->cli
, state
->fnum
,
5723 0xffff, state
->completion_filter
,
5725 if (tevent_req_nomem(subreq
, req
)) {
5726 return tevent_req_post(req
, ev
);
5728 tevent_req_set_callback(subreq
, swallow_notify_done
, req
);
5732 static void swallow_notify_done(struct tevent_req
*subreq
)
5734 struct tevent_req
*req
= tevent_req_callback_data(
5735 subreq
, struct tevent_req
);
5736 struct swallow_notify_state
*state
= tevent_req_data(
5737 req
, struct swallow_notify_state
);
5739 uint32_t i
, num_changes
;
5740 struct notify_change
*changes
;
5742 status
= cli_notify_recv(subreq
, state
, &num_changes
, &changes
);
5743 TALLOC_FREE(subreq
);
5744 if (!NT_STATUS_IS_OK(status
)) {
5745 DEBUG(10, ("cli_notify_recv returned %s\n",
5746 nt_errstr(status
)));
5747 tevent_req_nterror(req
, status
);
5751 for (i
=0; i
<num_changes
; i
++) {
5752 state
->fn(changes
[i
].action
, changes
[i
].name
, state
->priv
);
5754 TALLOC_FREE(changes
);
5756 subreq
= cli_notify_send(state
, state
->ev
, state
->cli
, state
->fnum
,
5757 0xffff, state
->completion_filter
,
5759 if (tevent_req_nomem(subreq
, req
)) {
5762 tevent_req_set_callback(subreq
, swallow_notify_done
, req
);
5765 static bool print_notifies(uint32_t action
, const char *name
, void *priv
)
5767 if (DEBUGLEVEL
> 5) {
5768 d_printf("%d %s\n", (int)action
, name
);
5773 static void notify_bench_done(struct tevent_req
*req
)
5775 int *num_finished
= (int *)tevent_req_callback_data_void(req
);
5779 static bool run_notify_bench(int dummy
)
5781 const char *dname
= "\\notify-bench";
5782 struct tevent_context
*ev
;
5785 struct tevent_req
*req1
, *req2
;
5786 int i
, num_unc_names
;
5787 int num_finished
= 0;
5789 printf("starting notify-bench test\n");
5791 if (use_multishare_conn
) {
5793 unc_list
= file_lines_load(multishare_conn_fname
,
5794 &num_unc_names
, 0, NULL
);
5795 if (!unc_list
|| num_unc_names
<= 0) {
5796 d_printf("Failed to load unc names list from '%s'\n",
5797 multishare_conn_fname
);
5800 TALLOC_FREE(unc_list
);
5805 ev
= tevent_context_init(talloc_tos());
5807 d_printf("tevent_context_init failed\n");
5811 for (i
=0; i
<num_unc_names
; i
++) {
5812 struct cli_state
*cli
;
5815 base_fname
= talloc_asprintf(talloc_tos(), "%s\\file%3.3d.",
5817 if (base_fname
== NULL
) {
5821 if (!torture_open_connection(&cli
, i
)) {
5825 status
= cli_ntcreate(cli
, dname
, 0,
5826 MAXIMUM_ALLOWED_ACCESS
,
5827 0, FILE_SHARE_READ
|FILE_SHARE_WRITE
|
5829 FILE_OPEN_IF
, FILE_DIRECTORY_FILE
, 0,
5832 if (!NT_STATUS_IS_OK(status
)) {
5833 d_printf("Could not create %s: %s\n", dname
,
5838 req1
= swallow_notify_send(talloc_tos(), ev
, cli
, dnum
,
5839 FILE_NOTIFY_CHANGE_FILE_NAME
|
5840 FILE_NOTIFY_CHANGE_DIR_NAME
|
5841 FILE_NOTIFY_CHANGE_ATTRIBUTES
|
5842 FILE_NOTIFY_CHANGE_LAST_WRITE
,
5843 false, print_notifies
, NULL
);
5845 d_printf("Could not create notify request\n");
5849 req2
= torture_createdels_send(talloc_tos(), ev
, cli
,
5850 base_fname
, 10, torture_numops
);
5852 d_printf("Could not create createdels request\n");
5855 TALLOC_FREE(base_fname
);
5857 tevent_req_set_callback(req2
, notify_bench_done
,
5861 while (num_finished
< num_unc_names
) {
5863 ret
= tevent_loop_once(ev
);
5865 d_printf("tevent_loop_once failed\n");
5870 if (!tevent_req_poll(req2
, ev
)) {
5871 d_printf("tevent_req_poll failed\n");
5874 status
= torture_createdels_recv(req2
);
5875 d_printf("torture_createdels_recv returned %s\n", nt_errstr(status
));
5880 static bool run_mangle1(int dummy
)
5882 struct cli_state
*cli
;
5883 const char *fname
= "this_is_a_long_fname_to_be_mangled.txt";
5887 time_t change_time
, access_time
, write_time
;
5891 printf("starting mangle1 test\n");
5892 if (!torture_open_connection(&cli
, 0)) {
5896 cli_sockopt(cli
, sockops
);
5898 if (!NT_STATUS_IS_OK(cli_ntcreate(
5899 cli
, fname
, 0, GENERIC_ALL_ACCESS
|DELETE_ACCESS
,
5900 FILE_ATTRIBUTE_NORMAL
, 0, FILE_OVERWRITE_IF
, 0, 0, &fnum
))) {
5901 d_printf("open %s failed: %s\n", fname
, cli_errstr(cli
));
5904 cli_close(cli
, fnum
);
5906 status
= cli_qpathinfo_alt_name(cli
, fname
, alt_name
);
5907 if (!NT_STATUS_IS_OK(status
)) {
5908 d_printf("cli_qpathinfo_alt_name failed: %s\n",
5912 d_printf("alt_name: %s\n", alt_name
);
5914 if (!NT_STATUS_IS_OK(cli_open(cli
, alt_name
, O_RDONLY
, DENY_NONE
, &fnum
))) {
5915 d_printf("cli_open(%s) failed: %s\n", alt_name
,
5919 cli_close(cli
, fnum
);
5921 if (!cli_qpathinfo(cli
, alt_name
, &change_time
, &access_time
,
5922 &write_time
, &size
, &mode
)) {
5923 d_printf("cli_qpathinfo(%s) failed: %s\n", alt_name
,
5931 static size_t null_source(uint8_t *buf
, size_t n
, void *priv
)
5933 size_t *to_pull
= (size_t *)priv
;
5934 size_t thistime
= *to_pull
;
5936 thistime
= MIN(thistime
, n
);
5937 if (thistime
== 0) {
5941 memset(buf
, 0, thistime
);
5942 *to_pull
-= thistime
;
5946 static bool run_windows_write(int dummy
)
5948 struct cli_state
*cli1
;
5952 const char *fname
= "\\writetest.txt";
5956 printf("starting windows_write test\n");
5957 if (!torture_open_connection(&cli1
, 0)) {
5961 if (!NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum
))) {
5962 printf("open failed (%s)\n", cli_errstr(cli1
));
5966 cli_sockopt(cli1
, sockops
);
5970 for (i
=0; i
<torture_numops
; i
++) {
5972 off_t start
= i
* torture_blocksize
;
5974 size_t to_pull
= torture_blocksize
- 1;
5976 if (cli_write(cli1
, fnum
, 0, &c
,
5977 start
+ torture_blocksize
- 1, 1) != 1) {
5978 printf("cli_write failed: %s\n", cli_errstr(cli1
));
5982 status
= cli_push(cli1
, fnum
, 0, i
* torture_blocksize
, torture_blocksize
,
5983 null_source
, &to_pull
);
5984 if (!NT_STATUS_IS_OK(status
)) {
5985 printf("cli_push returned: %s\n", nt_errstr(status
));
5990 seconds
= end_timer();
5991 kbytes
= (double)torture_blocksize
* torture_numops
;
5994 printf("Wrote %d kbytes in %.2f seconds: %d kb/sec\n", (int)kbytes
,
5995 (double)seconds
, (int)(kbytes
/seconds
));
5999 cli_close(cli1
, fnum
);
6000 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
6001 torture_close_connection(cli1
);
6005 static bool run_cli_echo(int dummy
)
6007 struct cli_state
*cli
;
6010 printf("starting cli_echo test\n");
6011 if (!torture_open_connection(&cli
, 0)) {
6014 cli_sockopt(cli
, sockops
);
6016 status
= cli_echo(cli
, 5, data_blob_const("hello", 5));
6018 d_printf("cli_echo returned %s\n", nt_errstr(status
));
6020 torture_close_connection(cli
);
6021 return NT_STATUS_IS_OK(status
);
6024 static bool run_uid_regression_test(int dummy
)
6026 static struct cli_state
*cli
;
6029 bool correct
= True
;
6031 printf("starting uid regression test\n");
6033 if (!torture_open_connection(&cli
, 0)) {
6037 cli_sockopt(cli
, sockops
);
6039 /* Ok - now save then logoff our current user. */
6040 old_vuid
= cli
->vuid
;
6042 if (!cli_ulogoff(cli
)) {
6043 d_printf("(%s) cli_ulogoff failed: %s\n",
6044 __location__
, cli_errstr(cli
));
6049 cli
->vuid
= old_vuid
;
6051 /* Try an operation. */
6052 if (!NT_STATUS_IS_OK(cli_mkdir(cli
, "\\uid_reg_test"))) {
6053 /* We expect bad uid. */
6054 if (!check_error(__LINE__
, cli
, ERRSRV
, ERRbaduid
,
6055 NT_STATUS_NO_SUCH_USER
)) {
6060 old_cnum
= cli
->cnum
;
6062 /* Now try a SMBtdis with the invald vuid set to zero. */
6065 /* This should succeed. */
6066 if (cli_tdis(cli
)) {
6067 printf("First tdis with invalid vuid should succeed.\n");
6069 printf("First tdis failed (%s)\n", cli_errstr(cli
));
6072 cli
->vuid
= old_vuid
;
6073 cli
->cnum
= old_cnum
;
6075 /* This should fail. */
6076 if (cli_tdis(cli
)) {
6077 printf("Second tdis with invalid vuid should fail - succeeded instead !.\n");
6079 /* Should be bad tid. */
6080 if (!check_error(__LINE__
, cli
, ERRSRV
, ERRinvnid
,
6081 NT_STATUS_NETWORK_NAME_DELETED
)) {
6086 cli_rmdir(cli
, "\\uid_reg_test");
6095 static const char *illegal_chars
= "*\\/?<>|\":";
6096 static char force_shortname_chars
[] = " +,.[];=\177";
6098 static void shortname_del_fn(const char *mnt
, file_info
*finfo
, const char *mask
, void *state
)
6100 struct cli_state
*pcli
= (struct cli_state
*)state
;
6102 slprintf(fname
, sizeof(fname
), "\\shortname\\%s", finfo
->name
);
6104 if (strcmp(finfo
->name
, ".") == 0 || strcmp(finfo
->name
, "..") == 0)
6107 if (finfo
->mode
& aDIR
) {
6108 if (!NT_STATUS_IS_OK(cli_rmdir(pcli
, fname
)))
6109 printf("del_fn: failed to rmdir %s\n,", fname
);
6111 if (!NT_STATUS_IS_OK(cli_unlink(pcli
, fname
, aSYSTEM
| aHIDDEN
)))
6112 printf("del_fn: failed to unlink %s\n,", fname
);
6121 static void shortname_list_fn(const char *mnt
, file_info
*finfo
, const char *name
, void *state
)
6123 struct sn_state
*s
= (struct sn_state
*)state
;
6127 printf("shortname list: i = %d, name = |%s|, shortname = |%s|\n",
6128 i
, finfo
->name
, finfo
->short_name
);
6131 if (strchr(force_shortname_chars
, i
)) {
6132 if (!finfo
->short_name
[0]) {
6133 /* Shortname not created when it should be. */
6134 d_printf("(%s) ERROR: Shortname was not created for file %s containing %d\n",
6135 __location__
, finfo
->name
, i
);
6138 } else if (finfo
->short_name
[0]){
6139 /* Shortname created when it should not be. */
6140 d_printf("(%s) ERROR: Shortname %s was created for file %s\n",
6141 __location__
, finfo
->short_name
, finfo
->name
);
6146 static bool run_shortname_test(int dummy
)
6148 static struct cli_state
*cli
;
6149 bool correct
= True
;
6154 printf("starting shortname test\n");
6156 if (!torture_open_connection(&cli
, 0)) {
6160 cli_sockopt(cli
, sockops
);
6162 cli_list(cli
, "\\shortname\\*", 0, shortname_del_fn
, cli
);
6163 cli_list(cli
, "\\shortname\\*", aDIR
, shortname_del_fn
, cli
);
6164 cli_rmdir(cli
, "\\shortname");
6166 if (!NT_STATUS_IS_OK(cli_mkdir(cli
, "\\shortname"))) {
6167 d_printf("(%s) cli_mkdir of \\shortname failed: %s\n",
6168 __location__
, cli_errstr(cli
));
6173 strlcpy(fname
, "\\shortname\\", sizeof(fname
));
6174 strlcat(fname
, "test .txt", sizeof(fname
));
6178 for (i
= 32; i
< 128; i
++) {
6180 uint16_t fnum
= (uint16_t)-1;
6184 if (strchr(illegal_chars
, i
)) {
6189 status
= cli_ntcreate(cli
, fname
, 0, GENERIC_ALL_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
6190 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OVERWRITE_IF
, 0, 0, &fnum
);
6191 if (!NT_STATUS_IS_OK(status
)) {
6192 d_printf("(%s) cli_nt_create of %s failed: %s\n",
6193 __location__
, fname
, cli_errstr(cli
));
6197 cli_close(cli
, fnum
);
6198 if (cli_list(cli
, "\\shortname\\test*.*", 0, shortname_list_fn
, &s
) != 1) {
6199 d_printf("(%s) failed to list %s: %s\n",
6200 __location__
, fname
, cli_errstr(cli
));
6204 if (!NT_STATUS_IS_OK(cli_unlink(cli
, fname
, aSYSTEM
| aHIDDEN
))) {
6205 d_printf("(%s) failed to delete %s: %s\n",
6206 __location__
, fname
, cli_errstr(cli
));
6219 cli_list(cli
, "\\shortname\\*", 0, shortname_del_fn
, cli
);
6220 cli_list(cli
, "\\shortname\\*", aDIR
, shortname_del_fn
, cli
);
6221 cli_rmdir(cli
, "\\shortname");
6222 torture_close_connection(cli
);
6226 static void pagedsearch_cb(struct tevent_req
*req
)
6229 struct tldap_message
*msg
;
6232 rc
= tldap_search_paged_recv(req
, talloc_tos(), &msg
);
6233 if (rc
!= TLDAP_SUCCESS
) {
6234 d_printf("tldap_search_paged_recv failed: %s\n",
6235 tldap_err2string(rc
));
6238 if (tldap_msg_type(msg
) != TLDAP_RES_SEARCH_ENTRY
) {
6242 if (!tldap_entry_dn(msg
, &dn
)) {
6243 d_printf("tldap_entry_dn failed\n");
6246 d_printf("%s\n", dn
);
6250 static bool run_tldap(int dummy
)
6252 struct tldap_context
*ld
;
6255 struct sockaddr_storage addr
;
6256 struct tevent_context
*ev
;
6257 struct tevent_req
*req
;
6260 if (!resolve_name(host
, &addr
, 0, false)) {
6261 d_printf("could not find host %s\n", host
);
6264 status
= open_socket_out(&addr
, 389, 9999, &fd
);
6265 if (!NT_STATUS_IS_OK(status
)) {
6266 d_printf("open_socket_out failed: %s\n", nt_errstr(status
));
6270 ld
= tldap_context_create(talloc_tos(), fd
);
6273 d_printf("tldap_context_create failed\n");
6277 rc
= tldap_fetch_rootdse(ld
);
6278 if (rc
!= TLDAP_SUCCESS
) {
6279 d_printf("tldap_fetch_rootdse failed: %s\n",
6280 tldap_errstr(talloc_tos(), ld
, rc
));
6284 basedn
= tldap_talloc_single_attribute(
6285 tldap_rootdse(ld
), "defaultNamingContext", talloc_tos());
6286 if (basedn
== NULL
) {
6287 d_printf("no defaultNamingContext\n");
6290 d_printf("defaultNamingContext: %s\n", basedn
);
6292 ev
= tevent_context_init(talloc_tos());
6294 d_printf("tevent_context_init failed\n");
6298 req
= tldap_search_paged_send(talloc_tos(), ev
, ld
, basedn
,
6299 TLDAP_SCOPE_SUB
, "(objectclass=*)",
6301 NULL
, 0, NULL
, 0, 0, 0, 0, 5);
6303 d_printf("tldap_search_paged_send failed\n");
6306 tevent_req_set_callback(req
, pagedsearch_cb
, NULL
);
6308 tevent_req_poll(req
, ev
);
6316 static bool run_streamerror(int dummy
)
6318 struct cli_state
*cli
;
6319 const char *dname
= "\\testdir";
6320 const char *streamname
=
6321 "testdir:{4c8cc155-6c1e-11d1-8e41-00c04fb9386d}:$DATA";
6323 time_t change_time
, access_time
, write_time
;
6325 uint16_t mode
, fnum
;
6328 if (!torture_open_connection(&cli
, 0)) {
6332 cli_rmdir(cli
, dname
);
6334 status
= cli_mkdir(cli
, dname
);
6335 if (!NT_STATUS_IS_OK(status
)) {
6336 printf("mkdir failed: %s\n", nt_errstr(status
));
6340 cli_qpathinfo(cli
, streamname
, &change_time
, &access_time
, &write_time
,
6342 status
= cli_nt_error(cli
);
6344 if (!NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
)) {
6345 printf("pathinfo returned %s, expected "
6346 "NT_STATUS_OBJECT_NAME_NOT_FOUND\n",
6351 status
= cli_ntcreate(cli
, streamname
, 0x16,
6352 FILE_READ_DATA
|FILE_READ_EA
|
6353 FILE_READ_ATTRIBUTES
|READ_CONTROL_ACCESS
,
6354 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_READ
,
6355 FILE_OPEN
, 0, 0, &fnum
);
6357 if (!NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
)) {
6358 printf("ntcreate returned %s, expected "
6359 "NT_STATUS_OBJECT_NAME_NOT_FOUND\n",
6365 cli_rmdir(cli
, dname
);
6369 static bool run_local_substitute(int dummy
)
6373 ok
&= subst_test("%U", "bla", "", -1, -1, "bla");
6374 ok
&= subst_test("%u%U", "bla", "", -1, -1, "blabla");
6375 ok
&= subst_test("%g", "", "", -1, -1, "NO_GROUP");
6376 ok
&= subst_test("%G", "", "", -1, -1, "NO_GROUP");
6377 ok
&= subst_test("%g", "", "", -1, 0, gidtoname(0));
6378 ok
&= subst_test("%G", "", "", -1, 0, gidtoname(0));
6379 ok
&= subst_test("%D%u", "u", "dom", -1, 0, "domu");
6380 ok
&= subst_test("%i %I", "", "", -1, -1, "0.0.0.0 0.0.0.0");
6382 /* Different captialization rules in sub_basic... */
6384 ok
&= (strcmp(talloc_sub_basic(talloc_tos(), "BLA", "dom", "%U%D"),
6390 static bool run_local_base64(int dummy
)
6395 for (i
=1; i
<2000; i
++) {
6396 DATA_BLOB blob1
, blob2
;
6399 blob1
.data
= talloc_array(talloc_tos(), uint8_t, i
);
6401 generate_random_buffer(blob1
.data
, blob1
.length
);
6403 b64
= base64_encode_data_blob(talloc_tos(), blob1
);
6405 d_fprintf(stderr
, "base64_encode_data_blob failed "
6406 "for %d bytes\n", i
);
6409 blob2
= base64_decode_data_blob(b64
);
6412 if (data_blob_cmp(&blob1
, &blob2
)) {
6413 d_fprintf(stderr
, "data_blob_cmp failed for %d "
6417 TALLOC_FREE(blob1
.data
);
6418 data_blob_free(&blob2
);
6423 static bool run_local_gencache(int dummy
)
6429 if (!gencache_set("foo", "bar", time(NULL
) + 1000)) {
6430 d_printf("%s: gencache_set() failed\n", __location__
);
6434 if (!gencache_get("foo", &val
, &tm
)) {
6435 d_printf("%s: gencache_get() failed\n", __location__
);
6439 if (strcmp(val
, "bar") != 0) {
6440 d_printf("%s: gencache_get() returned %s, expected %s\n",
6441 __location__
, val
, "bar");
6448 if (!gencache_del("foo")) {
6449 d_printf("%s: gencache_del() failed\n", __location__
);
6452 if (gencache_del("foo")) {
6453 d_printf("%s: second gencache_del() succeeded\n",
6458 if (gencache_get("foo", &val
, &tm
)) {
6459 d_printf("%s: gencache_get() on deleted entry "
6460 "succeeded\n", __location__
);
6464 blob
= data_blob_string_const_null("bar");
6465 tm
= time(NULL
) + 60;
6467 if (!gencache_set_data_blob("foo", &blob
, tm
)) {
6468 d_printf("%s: gencache_set_data_blob() failed\n", __location__
);
6472 if (!gencache_get_data_blob("foo", &blob
, NULL
, NULL
)) {
6473 d_printf("%s: gencache_get_data_blob() failed\n", __location__
);
6477 if (strcmp((const char *)blob
.data
, "bar") != 0) {
6478 d_printf("%s: gencache_get_data_blob() returned %s, expected %s\n",
6479 __location__
, (const char *)blob
.data
, "bar");
6480 data_blob_free(&blob
);
6484 data_blob_free(&blob
);
6486 if (!gencache_del("foo")) {
6487 d_printf("%s: gencache_del() failed\n", __location__
);
6490 if (gencache_del("foo")) {
6491 d_printf("%s: second gencache_del() succeeded\n",
6496 if (gencache_get_data_blob("foo", &blob
, NULL
, NULL
)) {
6497 d_printf("%s: gencache_get_data_blob() on deleted entry "
6498 "succeeded\n", __location__
);
6505 static bool rbt_testval(struct db_context
*db
, const char *key
,
6508 struct db_record
*rec
;
6509 TDB_DATA data
= string_tdb_data(value
);
6513 rec
= db
->fetch_locked(db
, db
, string_tdb_data(key
));
6515 d_fprintf(stderr
, "fetch_locked failed\n");
6518 status
= rec
->store(rec
, data
, 0);
6519 if (!NT_STATUS_IS_OK(status
)) {
6520 d_fprintf(stderr
, "store failed: %s\n", nt_errstr(status
));
6525 rec
= db
->fetch_locked(db
, db
, string_tdb_data(key
));
6527 d_fprintf(stderr
, "second fetch_locked failed\n");
6530 if ((rec
->value
.dsize
!= data
.dsize
)
6531 || (memcmp(rec
->value
.dptr
, data
.dptr
, data
.dsize
) != 0)) {
6532 d_fprintf(stderr
, "Got wrong data back\n");
6542 static bool run_local_rbtree(int dummy
)
6544 struct db_context
*db
;
6548 db
= db_open_rbt(NULL
);
6551 d_fprintf(stderr
, "db_open_rbt failed\n");
6555 for (i
=0; i
<1000; i
++) {
6558 if (asprintf(&key
, "key%ld", random()) == -1) {
6561 if (asprintf(&value
, "value%ld", random()) == -1) {
6566 if (!rbt_testval(db
, key
, value
)) {
6573 if (asprintf(&value
, "value%ld", random()) == -1) {
6578 if (!rbt_testval(db
, key
, value
)) {
6595 struct talloc_dict_test
{
6599 static int talloc_dict_traverse_fn(DATA_BLOB key
, void *data
, void *priv
)
6601 int *count
= (int *)priv
;
6606 static bool run_local_talloc_dict(int dummy
)
6608 struct talloc_dict
*dict
;
6609 struct talloc_dict_test
*t
;
6612 dict
= talloc_dict_init(talloc_tos());
6617 t
= talloc(talloc_tos(), struct talloc_dict_test
);
6624 if (!talloc_dict_set(dict
, data_blob_const(&key
, sizeof(key
)), t
)) {
6629 if (talloc_dict_traverse(dict
, talloc_dict_traverse_fn
, &count
) != 0) {
6642 /* Split a path name into filename and stream name components. Canonicalise
6643 * such that an implicit $DATA token is always explicit.
6645 * The "specification" of this function can be found in the
6646 * run_local_stream_name() function in torture.c, I've tried those
6647 * combinations against a W2k3 server.
6650 static NTSTATUS
split_ntfs_stream_name(TALLOC_CTX
*mem_ctx
, const char *fname
,
6651 char **pbase
, char **pstream
)
6654 char *stream
= NULL
;
6655 char *sname
; /* stream name */
6656 const char *stype
; /* stream type */
6658 DEBUG(10, ("split_ntfs_stream_name called for [%s]\n", fname
));
6660 sname
= strchr_m(fname
, ':');
6662 if (lp_posix_pathnames() || (sname
== NULL
)) {
6663 if (pbase
!= NULL
) {
6664 base
= talloc_strdup(mem_ctx
, fname
);
6665 NT_STATUS_HAVE_NO_MEMORY(base
);
6670 if (pbase
!= NULL
) {
6671 base
= talloc_strndup(mem_ctx
, fname
, PTR_DIFF(sname
, fname
));
6672 NT_STATUS_HAVE_NO_MEMORY(base
);
6677 stype
= strchr_m(sname
, ':');
6679 if (stype
== NULL
) {
6680 sname
= talloc_strdup(mem_ctx
, sname
);
6684 if (StrCaseCmp(stype
, ":$DATA") != 0) {
6686 * If there is an explicit stream type, so far we only
6687 * allow $DATA. Is there anything else allowed? -- vl
6689 DEBUG(10, ("[%s] is an invalid stream type\n", stype
));
6691 return NT_STATUS_OBJECT_NAME_INVALID
;
6693 sname
= talloc_strndup(mem_ctx
, sname
, PTR_DIFF(stype
, sname
));
6697 if (sname
== NULL
) {
6699 return NT_STATUS_NO_MEMORY
;
6702 if (sname
[0] == '\0') {
6704 * no stream name, so no stream
6709 if (pstream
!= NULL
) {
6710 stream
= talloc_asprintf(mem_ctx
, "%s:%s", sname
, stype
);
6711 if (stream
== NULL
) {
6714 return NT_STATUS_NO_MEMORY
;
6717 * upper-case the type field
6719 strupper_m(strchr_m(stream
, ':')+1);
6723 if (pbase
!= NULL
) {
6726 if (pstream
!= NULL
) {
6729 return NT_STATUS_OK
;
6732 static bool test_stream_name(const char *fname
, const char *expected_base
,
6733 const char *expected_stream
,
6734 NTSTATUS expected_status
)
6738 char *stream
= NULL
;
6740 status
= split_ntfs_stream_name(talloc_tos(), fname
, &base
, &stream
);
6741 if (!NT_STATUS_EQUAL(status
, expected_status
)) {
6745 if (!NT_STATUS_IS_OK(status
)) {
6749 if (base
== NULL
) goto error
;
6751 if (strcmp(expected_base
, base
) != 0) goto error
;
6753 if ((expected_stream
!= NULL
) && (stream
== NULL
)) goto error
;
6754 if ((expected_stream
== NULL
) && (stream
!= NULL
)) goto error
;
6756 if ((stream
!= NULL
) && (strcmp(expected_stream
, stream
) != 0))
6760 TALLOC_FREE(stream
);
6764 d_fprintf(stderr
, "test_stream(%s, %s, %s, %s)\n",
6765 fname
, expected_base
? expected_base
: "<NULL>",
6766 expected_stream
? expected_stream
: "<NULL>",
6767 nt_errstr(expected_status
));
6768 d_fprintf(stderr
, "-> base=%s, stream=%s, status=%s\n",
6769 base
? base
: "<NULL>", stream
? stream
: "<NULL>",
6772 TALLOC_FREE(stream
);
6776 static bool run_local_stream_name(int dummy
)
6780 ret
&= test_stream_name(
6781 "bla", "bla", NULL
, NT_STATUS_OK
);
6782 ret
&= test_stream_name(
6783 "bla::$DATA", "bla", NULL
, NT_STATUS_OK
);
6784 ret
&= test_stream_name(
6785 "bla:blub:", "bla", NULL
, NT_STATUS_OBJECT_NAME_INVALID
);
6786 ret
&= test_stream_name(
6787 "bla::", NULL
, NULL
, NT_STATUS_OBJECT_NAME_INVALID
);
6788 ret
&= test_stream_name(
6789 "bla::123", "bla", NULL
, NT_STATUS_OBJECT_NAME_INVALID
);
6790 ret
&= test_stream_name(
6791 "bla:$DATA", "bla", "$DATA:$DATA", NT_STATUS_OK
);
6792 ret
&= test_stream_name(
6793 "bla:x:$DATA", "bla", "x:$DATA", NT_STATUS_OK
);
6794 ret
&= test_stream_name(
6795 "bla:x", "bla", "x:$DATA", NT_STATUS_OK
);
6800 static bool data_blob_equal(DATA_BLOB a
, DATA_BLOB b
)
6802 if (a
.length
!= b
.length
) {
6803 printf("a.length=%d != b.length=%d\n",
6804 (int)a
.length
, (int)b
.length
);
6807 if (memcmp(a
.data
, b
.data
, a
.length
) != 0) {
6808 printf("a.data and b.data differ\n");
6814 static bool run_local_memcache(int dummy
)
6816 struct memcache
*cache
;
6818 DATA_BLOB d1
, d2
, d3
;
6819 DATA_BLOB v1
, v2
, v3
;
6821 TALLOC_CTX
*mem_ctx
;
6823 size_t size1
, size2
;
6826 cache
= memcache_init(NULL
, 100);
6828 if (cache
== NULL
) {
6829 printf("memcache_init failed\n");
6833 d1
= data_blob_const("d1", 2);
6834 d2
= data_blob_const("d2", 2);
6835 d3
= data_blob_const("d3", 2);
6837 k1
= data_blob_const("d1", 2);
6838 k2
= data_blob_const("d2", 2);
6840 memcache_add(cache
, STAT_CACHE
, k1
, d1
);
6841 memcache_add(cache
, GETWD_CACHE
, k2
, d2
);
6843 if (!memcache_lookup(cache
, STAT_CACHE
, k1
, &v1
)) {
6844 printf("could not find k1\n");
6847 if (!data_blob_equal(d1
, v1
)) {
6851 if (!memcache_lookup(cache
, GETWD_CACHE
, k2
, &v2
)) {
6852 printf("could not find k2\n");
6855 if (!data_blob_equal(d2
, v2
)) {
6859 memcache_add(cache
, STAT_CACHE
, k1
, d3
);
6861 if (!memcache_lookup(cache
, STAT_CACHE
, k1
, &v3
)) {
6862 printf("could not find replaced k1\n");
6865 if (!data_blob_equal(d3
, v3
)) {
6869 memcache_add(cache
, GETWD_CACHE
, k1
, d1
);
6871 if (memcache_lookup(cache
, GETWD_CACHE
, k2
, &v2
)) {
6872 printf("Did find k2, should have been purged\n");
6878 cache
= memcache_init(NULL
, 0);
6880 mem_ctx
= talloc_init("foo");
6882 str1
= talloc_strdup(mem_ctx
, "string1");
6883 str2
= talloc_strdup(mem_ctx
, "string2");
6885 memcache_add_talloc(cache
, SINGLETON_CACHE_TALLOC
,
6886 data_blob_string_const("torture"), &str1
);
6887 size1
= talloc_total_size(cache
);
6889 memcache_add_talloc(cache
, SINGLETON_CACHE_TALLOC
,
6890 data_blob_string_const("torture"), &str2
);
6891 size2
= talloc_total_size(cache
);
6893 printf("size1=%d, size2=%d\n", (int)size1
, (int)size2
);
6895 if (size2
> size1
) {
6896 printf("memcache leaks memory!\n");
6906 static void wbclient_done(struct tevent_req
*req
)
6909 struct winbindd_response
*wb_resp
;
6910 int *i
= (int *)tevent_req_callback_data_void(req
);
6912 wbc_err
= wb_trans_recv(req
, req
, &wb_resp
);
6915 d_printf("wb_trans_recv %d returned %s\n", *i
, wbcErrorString(wbc_err
));
6918 static bool run_local_wbclient(int dummy
)
6920 struct event_context
*ev
;
6921 struct wb_context
**wb_ctx
;
6922 struct winbindd_request wb_req
;
6923 bool result
= false;
6926 BlockSignals(True
, SIGPIPE
);
6928 ev
= tevent_context_init_byname(talloc_tos(), "epoll");
6933 wb_ctx
= TALLOC_ARRAY(ev
, struct wb_context
*, nprocs
);
6934 if (wb_ctx
== NULL
) {
6938 ZERO_STRUCT(wb_req
);
6939 wb_req
.cmd
= WINBINDD_PING
;
6941 d_printf("nprocs=%d, numops=%d\n", (int)nprocs
, (int)torture_numops
);
6943 for (i
=0; i
<nprocs
; i
++) {
6944 wb_ctx
[i
] = wb_context_init(ev
, NULL
);
6945 if (wb_ctx
[i
] == NULL
) {
6948 for (j
=0; j
<torture_numops
; j
++) {
6949 struct tevent_req
*req
;
6950 req
= wb_trans_send(ev
, ev
, wb_ctx
[i
],
6951 (j
% 2) == 0, &wb_req
);
6955 tevent_req_set_callback(req
, wbclient_done
, &i
);
6961 while (i
< nprocs
* torture_numops
) {
6962 event_loop_once(ev
);
6971 static void getaddrinfo_finished(struct tevent_req
*req
)
6973 char *name
= (char *)tevent_req_callback_data_void(req
);
6974 struct addrinfo
*ainfo
;
6977 res
= getaddrinfo_recv(req
, &ainfo
);
6979 d_printf("gai(%s) returned %s\n", name
, gai_strerror(res
));
6982 d_printf("gai(%s) succeeded\n", name
);
6983 freeaddrinfo(ainfo
);
6986 static bool run_getaddrinfo_send(int dummy
)
6988 TALLOC_CTX
*frame
= talloc_stackframe();
6989 struct fncall_context
*ctx
;
6990 struct tevent_context
*ev
;
6991 bool result
= false;
6992 const char *names
[4] = { "www.samba.org", "notfound.samba.org",
6993 "www.slashdot.org", "heise.de" };
6994 struct tevent_req
*reqs
[4];
6997 ev
= event_context_init(frame
);
7002 ctx
= fncall_context_init(frame
, 4);
7004 for (i
=0; i
<ARRAY_SIZE(names
); i
++) {
7005 reqs
[i
] = getaddrinfo_send(frame
, ev
, ctx
, names
[i
], NULL
,
7007 if (reqs
[i
] == NULL
) {
7010 tevent_req_set_callback(reqs
[i
], getaddrinfo_finished
,
7014 for (i
=0; i
<ARRAY_SIZE(reqs
); i
++) {
7015 tevent_loop_once(ev
);
7025 static double create_procs(bool (*fn
)(int), bool *result
)
7028 volatile pid_t
*child_status
;
7029 volatile bool *child_status_out
;
7035 child_status
= (volatile pid_t
*)shm_setup(sizeof(pid_t
)*nprocs
);
7036 if (!child_status
) {
7037 printf("Failed to setup shared memory\n");
7041 child_status_out
= (volatile bool *)shm_setup(sizeof(bool)*nprocs
);
7042 if (!child_status_out
) {
7043 printf("Failed to setup result status shared memory\n");
7047 for (i
= 0; i
< nprocs
; i
++) {
7048 child_status
[i
] = 0;
7049 child_status_out
[i
] = True
;
7054 for (i
=0;i
<nprocs
;i
++) {
7057 pid_t mypid
= getpid();
7058 sys_srandom(((int)mypid
) ^ ((int)time(NULL
)));
7060 slprintf(myname
,sizeof(myname
),"CLIENT%d", i
);
7063 if (torture_open_connection(¤t_cli
, i
)) break;
7065 printf("pid %d failed to start\n", (int)getpid());
7071 child_status
[i
] = getpid();
7073 while (child_status
[i
] && end_timer() < 5) smb_msleep(2);
7075 child_status_out
[i
] = fn(i
);
7082 for (i
=0;i
<nprocs
;i
++) {
7083 if (child_status
[i
]) synccount
++;
7085 if (synccount
== nprocs
) break;
7087 } while (end_timer() < 30);
7089 if (synccount
!= nprocs
) {
7090 printf("FAILED TO START %d CLIENTS (started %d)\n", nprocs
, synccount
);
7095 /* start the client load */
7098 for (i
=0;i
<nprocs
;i
++) {
7099 child_status
[i
] = 0;
7102 printf("%d clients started\n", nprocs
);
7104 for (i
=0;i
<nprocs
;i
++) {
7105 while (waitpid(0, &status
, 0) == -1 && errno
== EINTR
) /* noop */ ;
7110 for (i
=0;i
<nprocs
;i
++) {
7111 if (!child_status_out
[i
]) {
7118 #define FLAG_MULTIPROC 1
7125 {"FDPASS", run_fdpasstest
, 0},
7126 {"LOCK1", run_locktest1
, 0},
7127 {"LOCK2", run_locktest2
, 0},
7128 {"LOCK3", run_locktest3
, 0},
7129 {"LOCK4", run_locktest4
, 0},
7130 {"LOCK5", run_locktest5
, 0},
7131 {"LOCK6", run_locktest6
, 0},
7132 {"LOCK7", run_locktest7
, 0},
7133 {"LOCK8", run_locktest8
, 0},
7134 {"LOCK9", run_locktest9
, 0},
7135 {"UNLINK", run_unlinktest
, 0},
7136 {"BROWSE", run_browsetest
, 0},
7137 {"ATTR", run_attrtest
, 0},
7138 {"TRANS2", run_trans2test
, 0},
7139 {"MAXFID", run_maxfidtest
, FLAG_MULTIPROC
},
7140 {"TORTURE",run_torture
, FLAG_MULTIPROC
},
7141 {"RANDOMIPC", run_randomipc
, 0},
7142 {"NEGNOWAIT", run_negprot_nowait
, 0},
7143 {"NBENCH", run_nbench
, 0},
7144 {"OPLOCK1", run_oplock1
, 0},
7145 {"OPLOCK2", run_oplock2
, 0},
7146 {"OPLOCK3", run_oplock3
, 0},
7147 {"DIR", run_dirtest
, 0},
7148 {"DIR1", run_dirtest1
, 0},
7149 {"DENY1", torture_denytest1
, 0},
7150 {"DENY2", torture_denytest2
, 0},
7151 {"TCON", run_tcon_test
, 0},
7152 {"TCONDEV", run_tcon_devtype_test
, 0},
7153 {"RW1", run_readwritetest
, 0},
7154 {"RW2", run_readwritemulti
, FLAG_MULTIPROC
},
7155 {"RW3", run_readwritelarge
, 0},
7156 {"OPEN", run_opentest
, 0},
7157 {"POSIX", run_simple_posix_open_test
, 0},
7158 { "UID-REGRESSION-TEST", run_uid_regression_test
, 0},
7159 { "SHORTNAME-TEST", run_shortname_test
, 0},
7161 {"OPENATTR", run_openattrtest
, 0},
7163 {"XCOPY", run_xcopy
, 0},
7164 {"RENAME", run_rename
, 0},
7165 {"DELETE", run_deletetest
, 0},
7166 {"PROPERTIES", run_properties
, 0},
7167 {"MANGLE", torture_mangle
, 0},
7168 {"MANGLE1", run_mangle1
, 0},
7169 {"W2K", run_w2ktest
, 0},
7170 {"TRANS2SCAN", torture_trans2_scan
, 0},
7171 {"NTTRANSSCAN", torture_nttrans_scan
, 0},
7172 {"UTABLE", torture_utable
, 0},
7173 {"CASETABLE", torture_casetable
, 0},
7174 {"ERRMAPEXTRACT", run_error_map_extract
, 0},
7175 {"PIPE_NUMBER", run_pipe_number
, 0},
7176 {"TCON2", run_tcon2_test
, 0},
7177 {"IOCTL", torture_ioctl_test
, 0},
7178 {"CHKPATH", torture_chkpath_test
, 0},
7179 {"FDSESS", run_fdsesstest
, 0},
7180 { "EATEST", run_eatest
, 0},
7181 { "SESSSETUP_BENCH", run_sesssetup_bench
, 0},
7182 { "CHAIN1", run_chain1
, 0},
7183 { "CHAIN2", run_chain2
, 0},
7184 { "WINDOWS-WRITE", run_windows_write
, 0},
7185 { "CLI_ECHO", run_cli_echo
, 0},
7186 { "GETADDRINFO", run_getaddrinfo_send
, 0},
7187 { "TLDAP", run_tldap
},
7188 { "STREAMERROR", run_streamerror
},
7189 { "NOTIFY-BENCH", run_notify_bench
},
7190 { "LOCAL-SUBSTITUTE", run_local_substitute
, 0},
7191 { "LOCAL-GENCACHE", run_local_gencache
, 0},
7192 { "LOCAL-TALLOC-DICT", run_local_talloc_dict
, 0},
7193 { "LOCAL-BASE64", run_local_base64
, 0},
7194 { "LOCAL-RBTREE", run_local_rbtree
, 0},
7195 { "LOCAL-MEMCACHE", run_local_memcache
, 0},
7196 { "LOCAL-STREAM-NAME", run_local_stream_name
, 0},
7197 { "LOCAL-WBCLIENT", run_local_wbclient
, 0},
7202 /****************************************************************************
7203 run a specified test or "ALL"
7204 ****************************************************************************/
7205 static bool run_test(const char *name
)
7212 if (strequal(name
,"ALL")) {
7213 for (i
=0;torture_ops
[i
].name
;i
++) {
7214 run_test(torture_ops
[i
].name
);
7219 for (i
=0;torture_ops
[i
].name
;i
++) {
7220 fstr_sprintf(randomfname
, "\\XX%x",
7221 (unsigned)random());
7223 if (strequal(name
, torture_ops
[i
].name
)) {
7225 printf("Running %s\n", name
);
7226 if (torture_ops
[i
].flags
& FLAG_MULTIPROC
) {
7227 t
= create_procs(torture_ops
[i
].fn
, &result
);
7230 printf("TEST %s FAILED!\n", name
);
7234 if (!torture_ops
[i
].fn(0)) {
7236 printf("TEST %s FAILED!\n", name
);
7240 printf("%s took %g secs\n\n", name
, t
);
7245 printf("Did not find a test named %s\n", name
);
7253 static void usage(void)
7257 printf("WARNING samba4 test suite is much more complete nowadays.\n");
7258 printf("Please use samba4 torture.\n\n");
7260 printf("Usage: smbtorture //server/share <options> TEST1 TEST2 ...\n");
7262 printf("\t-d debuglevel\n");
7263 printf("\t-U user%%pass\n");
7264 printf("\t-k use kerberos\n");
7265 printf("\t-N numprocs\n");
7266 printf("\t-n my_netbios_name\n");
7267 printf("\t-W workgroup\n");
7268 printf("\t-o num_operations\n");
7269 printf("\t-O socket_options\n");
7270 printf("\t-m maximum protocol\n");
7271 printf("\t-L use oplocks\n");
7272 printf("\t-c CLIENT.TXT specify client load file for NBENCH\n");
7273 printf("\t-A showall\n");
7274 printf("\t-p port\n");
7275 printf("\t-s seed\n");
7276 printf("\t-b unclist_filename specify multiple shares for multiple connections\n");
7279 printf("tests are:");
7280 for (i
=0;torture_ops
[i
].name
;i
++) {
7281 printf(" %s", torture_ops
[i
].name
);
7285 printf("default test is ALL\n");
7290 /****************************************************************************
7292 ****************************************************************************/
7293 int main(int argc
,char *argv
[])
7299 bool correct
= True
;
7300 TALLOC_CTX
*frame
= talloc_stackframe();
7301 int seed
= time(NULL
);
7305 #ifdef HAVE_SETBUFFER
7306 setbuffer(stdout
, NULL
, 0);
7311 if (is_default_dyn_CONFIGFILE()) {
7312 if(getenv("SMB_CONF_PATH")) {
7313 set_dyn_CONFIGFILE(getenv("SMB_CONF_PATH"));
7316 lp_load(get_dyn_CONFIGFILE(),True
,False
,False
,True
);
7323 for(p
= argv
[1]; *p
; p
++)
7327 if (strncmp(argv
[1], "//", 2)) {
7331 fstrcpy(host
, &argv
[1][2]);
7332 p
= strchr_m(&host
[2],'/');
7337 fstrcpy(share
, p
+1);
7339 fstrcpy(myname
, get_myname(talloc_tos()));
7341 fprintf(stderr
, "Failed to get my hostname.\n");
7345 if (*username
== 0 && getenv("LOGNAME")) {
7346 fstrcpy(username
,getenv("LOGNAME"));
7352 fstrcpy(workgroup
, lp_workgroup());
7354 while ((opt
= getopt(argc
, argv
, "p:hW:U:n:N:O:o:m:Ll:d:Aec:ks:b:B:")) != EOF
) {
7357 port_to_use
= atoi(optarg
);
7360 seed
= atoi(optarg
);
7363 fstrcpy(workgroup
,optarg
);
7366 max_protocol
= interpret_protocol(optarg
, max_protocol
);
7369 nprocs
= atoi(optarg
);
7372 torture_numops
= atoi(optarg
);
7375 DEBUGLEVEL
= atoi(optarg
);
7384 local_path
= optarg
;
7387 torture_showall
= True
;
7390 fstrcpy(myname
, optarg
);
7393 client_txt
= optarg
;
7400 use_kerberos
= True
;
7402 d_printf("No kerberos support compiled in\n");
7408 fstrcpy(username
,optarg
);
7409 p
= strchr_m(username
,'%');
7412 fstrcpy(password
, p
+1);
7417 fstrcpy(multishare_conn_fname
, optarg
);
7418 use_multishare_conn
= True
;
7421 torture_blocksize
= atoi(optarg
);
7424 printf("Unknown option %c (%d)\n", (char)opt
, opt
);
7429 d_printf("using seed %d\n", seed
);
7433 if(use_kerberos
&& !gotuser
) gotpass
= True
;
7436 p
= getpass("Password:");
7438 fstrcpy(password
, p
);
7443 printf("host=%s share=%s user=%s myname=%s\n",
7444 host
, share
, username
, myname
);
7446 if (argc
== optind
) {
7447 correct
= run_test("ALL");
7449 for (i
=optind
;i
<argc
;i
++) {
7450 if (!run_test(argv
[i
])) {