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 "system/shmem.h"
23 #include "wbc_async.h"
24 #include "torture/proto.h"
25 #include "libcli/security/security.h"
27 #include "tldap_util.h"
28 #include "../librpc/gen_ndr/svcctl.h"
30 #include "nsswitch/winbind_client.h"
32 #include "talloc_dict.h"
33 #include "async_smb.h"
34 #include "libsmb/libsmb.h"
35 #include "libsmb/clirap.h"
37 #include "libsmb/nmblib.h"
38 #include "../lib/util/tevent_ntstatus.h"
44 static fstring host
, workgroup
, share
, password
, username
, myname
;
45 static int max_protocol
= PROTOCOL_NT1
;
46 static const char *sockops
="TCP_NODELAY";
48 static int port_to_use
=0;
49 int torture_numops
=100;
50 int torture_blocksize
=1024*1024;
51 static int procnum
; /* records process count number when forking */
52 static struct cli_state
*current_cli
;
53 static fstring randomfname
;
54 static bool use_oplocks
;
55 static bool use_level_II_oplocks
;
56 static const char *client_txt
= "client_oplocks.txt";
57 static bool use_kerberos
;
58 static fstring multishare_conn_fname
;
59 static bool use_multishare_conn
= False
;
60 static bool do_encrypt
;
61 static const char *local_path
= NULL
;
62 static int signing_state
= Undefined
;
64 bool torture_showall
= False
;
66 static double create_procs(bool (*fn
)(int), bool *result
);
69 /* return a pointer to a anonymous shared memory segment of size "size"
70 which will persist across fork() but will disappear when all processes
73 The memory is not zeroed
75 This function uses system5 shared memory. It takes advantage of a property
76 that the memory is not destroyed if it is attached when the id is removed
78 void *shm_setup(int size
)
84 shmid
= shm_open("private", O_RDWR
| O_CREAT
| O_EXCL
, S_IRUSR
| S_IWUSR
);
86 printf("can't get shared memory\n");
89 shm_unlink("private");
90 if (ftruncate(shmid
, size
) == -1) {
91 printf("can't set shared memory size\n");
94 ret
= mmap(0, size
, PROT_READ
| PROT_WRITE
, MAP_SHARED
, shmid
, 0);
95 if (ret
== MAP_FAILED
) {
96 printf("can't map shared memory\n");
100 shmid
= shmget(IPC_PRIVATE
, size
, S_IRUSR
| S_IWUSR
);
102 printf("can't get shared memory\n");
105 ret
= (void *)shmat(shmid
, 0, 0);
106 if (!ret
|| ret
== (void *)-1) {
107 printf("can't attach to shared memory\n");
110 /* the following releases the ipc, but note that this process
111 and all its children will still have access to the memory, its
112 just that the shmid is no longer valid for other shm calls. This
113 means we don't leave behind lots of shm segments after we exit
115 See Stevens "advanced programming in unix env" for details
117 shmctl(shmid
, IPC_RMID
, 0);
123 /********************************************************************
124 Ensure a connection is encrypted.
125 ********************************************************************/
127 static bool force_cli_encryption(struct cli_state
*c
,
128 const char *sharename
)
131 uint32 caplow
, caphigh
;
134 if (!SERVER_HAS_UNIX_CIFS(c
)) {
135 d_printf("Encryption required and "
136 "server that doesn't support "
137 "UNIX extensions - failing connect\n");
141 status
= cli_unix_extensions_version(c
, &major
, &minor
, &caplow
,
143 if (!NT_STATUS_IS_OK(status
)) {
144 d_printf("Encryption required and "
145 "can't get UNIX CIFS extensions "
146 "version from server: %s\n", nt_errstr(status
));
150 if (!(caplow
& CIFS_UNIX_TRANSPORT_ENCRYPTION_CAP
)) {
151 d_printf("Encryption required and "
152 "share %s doesn't support "
153 "encryption.\n", sharename
);
157 if (c
->use_kerberos
) {
158 status
= cli_gss_smb_encryption_start(c
);
160 status
= cli_raw_ntlm_smb_encryption_start(c
,
166 if (!NT_STATUS_IS_OK(status
)) {
167 d_printf("Encryption required and "
168 "setup failed with error %s.\n",
177 static struct cli_state
*open_nbt_connection(void)
179 struct nmb_name called
, calling
;
180 struct sockaddr_storage ss
;
184 make_nmb_name(&calling
, myname
, 0x0);
185 make_nmb_name(&called
, host
, 0x20);
189 if (!(c
= cli_initialise_ex(signing_state
))) {
190 printf("Failed initialize cli_struct to connect with %s\n", host
);
194 c
->port
= port_to_use
;
196 status
= cli_connect(c
, host
, &ss
);
197 if (!NT_STATUS_IS_OK(status
)) {
198 printf("Failed to connect with %s. Error %s\n", host
, nt_errstr(status
) );
202 c
->use_kerberos
= use_kerberos
;
204 c
->timeout
= 120000; /* set a really long timeout (2 minutes) */
205 if (use_oplocks
) c
->use_oplocks
= True
;
206 if (use_level_II_oplocks
) c
->use_level_II_oplocks
= True
;
208 if (!cli_session_request(c
, &calling
, &called
)) {
210 * Well, that failed, try *SMBSERVER ...
211 * However, we must reconnect as well ...
213 status
= cli_connect(c
, host
, &ss
);
214 if (!NT_STATUS_IS_OK(status
)) {
215 printf("Failed to connect with %s. Error %s\n", host
, nt_errstr(status
) );
219 make_nmb_name(&called
, "*SMBSERVER", 0x20);
220 if (!cli_session_request(c
, &calling
, &called
)) {
221 printf("%s rejected the session\n",host
);
222 printf("We tried with a called name of %s & %s\n",
232 /****************************************************************************
233 Send a corrupt session request. See rfc1002.txt 4.3 and 4.3.2.
234 ****************************************************************************/
236 static bool cli_bad_session_request(struct cli_state
*cli
,
237 struct nmb_name
*calling
, struct nmb_name
*called
)
244 memcpy(&(cli
->calling
), calling
, sizeof(*calling
));
245 memcpy(&(cli
->called
), called
, sizeof(*called
));
247 /* put in the destination name */
249 tmp
= name_mangle(talloc_tos(), cli
->called
.name
,
250 cli
->called
.name_type
);
256 namelen
= name_len((unsigned char *)tmp
, talloc_get_size(tmp
));
258 memcpy(p
, tmp
, namelen
);
263 /* Deliberately corrupt the name len (first byte) */
268 tmp
= name_mangle(talloc_tos(), cli
->calling
.name
,
269 cli
->calling
.name_type
);
275 namelen
= name_len((unsigned char *)tmp
, talloc_get_size(tmp
));
277 memcpy(p
, tmp
, namelen
);
281 /* Deliberately corrupt the name len (first byte) */
284 /* send a session request (RFC 1002) */
285 /* setup the packet length
286 * Remove four bytes from the length count, since the length
287 * field in the NBT Session Service header counts the number
288 * of bytes which follow. The cli_send_smb() function knows
289 * about this and accounts for those four bytes.
293 _smb_setlen(cli
->outbuf
,len
);
294 SCVAL(cli
->outbuf
,0,0x81);
297 DEBUG(5,("Sent session request\n"));
299 if (!cli_receive_smb(cli
))
302 if (CVAL(cli
->inbuf
,0) != 0x82) {
303 /* This is the wrong place to put the error... JRA. */
304 cli
->rap_error
= CVAL(cli
->inbuf
,4);
310 static struct cli_state
*open_bad_nbt_connection(void)
312 struct nmb_name called
, calling
;
313 struct sockaddr_storage ss
;
317 make_nmb_name(&calling
, myname
, 0x0);
318 make_nmb_name(&called
, host
, 0x20);
322 if (!(c
= cli_initialise_ex(signing_state
))) {
323 printf("Failed initialize cli_struct to connect with %s\n", host
);
329 status
= cli_connect(c
, host
, &ss
);
330 if (!NT_STATUS_IS_OK(status
)) {
331 printf("Failed to connect with %s. Error %s\n", host
, nt_errstr(status
) );
335 c
->timeout
= 4000; /* set a short timeout (4 seconds) */
337 if (!cli_bad_session_request(c
, &calling
, &called
)) {
338 printf("Failed to connect with %s. Error %s\n", host
, nt_errstr(status
) );
346 /* Insert a NULL at the first separator of the given path and return a pointer
347 * to the remainder of the string.
350 terminate_path_at_separator(char * path
)
358 if ((p
= strchr_m(path
, '/'))) {
363 if ((p
= strchr_m(path
, '\\'))) {
373 parse a //server/share type UNC name
375 bool smbcli_parse_unc(const char *unc_name
, TALLOC_CTX
*mem_ctx
,
376 char **hostname
, char **sharename
)
380 *hostname
= *sharename
= NULL
;
382 if (strncmp(unc_name
, "\\\\", 2) &&
383 strncmp(unc_name
, "//", 2)) {
387 *hostname
= talloc_strdup(mem_ctx
, &unc_name
[2]);
388 p
= terminate_path_at_separator(*hostname
);
391 *sharename
= talloc_strdup(mem_ctx
, p
);
392 terminate_path_at_separator(*sharename
);
395 if (*hostname
&& *sharename
) {
399 TALLOC_FREE(*hostname
);
400 TALLOC_FREE(*sharename
);
404 static bool torture_open_connection_share(struct cli_state
**c
,
405 const char *hostname
,
406 const char *sharename
)
412 flags
|= CLI_FULL_CONNECTION_USE_KERBEROS
;
414 flags
|= CLI_FULL_CONNECTION_OPLOCKS
;
415 if (use_level_II_oplocks
)
416 flags
|= CLI_FULL_CONNECTION_LEVEL_II_OPLOCKS
;
418 status
= cli_full_connection(c
, myname
,
419 hostname
, NULL
, port_to_use
,
422 password
, flags
, signing_state
);
423 if (!NT_STATUS_IS_OK(status
)) {
424 printf("failed to open share connection: //%s/%s port:%d - %s\n",
425 hostname
, sharename
, port_to_use
, nt_errstr(status
));
429 (*c
)->timeout
= 120000; /* set a really long timeout (2 minutes) */
432 return force_cli_encryption(*c
,
438 bool torture_open_connection(struct cli_state
**c
, int conn_index
)
440 char **unc_list
= NULL
;
441 int num_unc_names
= 0;
444 if (use_multishare_conn
==True
) {
446 unc_list
= file_lines_load(multishare_conn_fname
, &num_unc_names
, 0, NULL
);
447 if (!unc_list
|| num_unc_names
<= 0) {
448 printf("Failed to load unc names list from '%s'\n", multishare_conn_fname
);
452 if (!smbcli_parse_unc(unc_list
[conn_index
% num_unc_names
],
454 printf("Failed to parse UNC name %s\n",
455 unc_list
[conn_index
% num_unc_names
]);
456 TALLOC_FREE(unc_list
);
460 result
= torture_open_connection_share(c
, h
, s
);
462 /* h, s were copied earlier */
463 TALLOC_FREE(unc_list
);
467 return torture_open_connection_share(c
, host
, share
);
470 bool torture_cli_session_setup2(struct cli_state
*cli
, uint16
*new_vuid
)
472 uint16 old_vuid
= cli
->vuid
;
473 fstring old_user_name
;
474 size_t passlen
= strlen(password
);
478 fstrcpy(old_user_name
, cli
->user_name
);
480 ret
= NT_STATUS_IS_OK(cli_session_setup(cli
, username
,
484 *new_vuid
= cli
->vuid
;
485 cli
->vuid
= old_vuid
;
486 status
= cli_set_username(cli
, old_user_name
);
487 if (!NT_STATUS_IS_OK(status
)) {
494 bool torture_close_connection(struct cli_state
*c
)
499 status
= cli_tdis(c
);
500 if (!NT_STATUS_IS_OK(status
)) {
501 printf("tdis failed (%s)\n", nt_errstr(status
));
511 /* check if the server produced the expected error code */
512 static bool check_error(int line
, struct cli_state
*c
,
513 uint8 eclass
, uint32 ecode
, NTSTATUS nterr
)
515 if (cli_is_dos_error(c
)) {
519 /* Check DOS error */
521 cli_dos_error(c
, &cclass
, &num
);
523 if (eclass
!= cclass
|| ecode
!= num
) {
524 printf("unexpected error code class=%d code=%d\n",
525 (int)cclass
, (int)num
);
526 printf(" expected %d/%d %s (line=%d)\n",
527 (int)eclass
, (int)ecode
, nt_errstr(nterr
), line
);
536 status
= cli_nt_error(c
);
538 if (NT_STATUS_V(nterr
) != NT_STATUS_V(status
)) {
539 printf("unexpected error code %s\n", nt_errstr(status
));
540 printf(" expected %s (line=%d)\n", nt_errstr(nterr
), line
);
549 static bool wait_lock(struct cli_state
*c
, int fnum
, uint32 offset
, uint32 len
)
551 while (!cli_lock(c
, fnum
, offset
, len
, -1, WRITE_LOCK
)) {
552 if (!check_error(__LINE__
, c
, ERRDOS
, ERRlock
, NT_STATUS_LOCK_NOT_GRANTED
)) return False
;
558 static bool rw_torture(struct cli_state
*c
)
560 const char *lockfname
= "\\torture.lck";
564 pid_t pid2
, pid
= getpid();
570 memset(buf
, '\0', sizeof(buf
));
572 status
= cli_open(c
, lockfname
, O_RDWR
| O_CREAT
| O_EXCL
,
574 if (!NT_STATUS_IS_OK(status
)) {
575 status
= cli_open(c
, lockfname
, O_RDWR
, DENY_NONE
, &fnum2
);
577 if (!NT_STATUS_IS_OK(status
)) {
578 printf("open of %s failed (%s)\n", lockfname
, cli_errstr(c
));
582 for (i
=0;i
<torture_numops
;i
++) {
583 unsigned n
= (unsigned)sys_random()%10;
586 printf("%d\r", i
); fflush(stdout
);
588 slprintf(fname
, sizeof(fstring
) - 1, "\\torture.%u", n
);
590 if (!wait_lock(c
, fnum2
, n
*sizeof(int), sizeof(int))) {
594 if (!NT_STATUS_IS_OK(cli_open(c
, fname
, O_RDWR
| O_CREAT
| O_TRUNC
, DENY_ALL
, &fnum
))) {
595 printf("open failed (%s)\n", cli_errstr(c
));
600 status
= cli_writeall(c
, fnum
, 0, (uint8_t *)&pid
, 0,
602 if (!NT_STATUS_IS_OK(status
)) {
603 printf("write failed (%s)\n", nt_errstr(status
));
608 status
= cli_writeall(c
, fnum
, 0, (uint8_t *)buf
,
609 sizeof(pid
)+(j
*sizeof(buf
)),
611 if (!NT_STATUS_IS_OK(status
)) {
612 printf("write failed (%s)\n",
620 if (cli_read(c
, fnum
, (char *)&pid2
, 0, sizeof(pid
)) != sizeof(pid
)) {
621 printf("read failed (%s)\n", cli_errstr(c
));
626 printf("data corruption!\n");
630 if (!NT_STATUS_IS_OK(cli_close(c
, fnum
))) {
631 printf("close failed (%s)\n", cli_errstr(c
));
635 if (!NT_STATUS_IS_OK(cli_unlink(c
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
))) {
636 printf("unlink failed (%s)\n", cli_errstr(c
));
640 if (!NT_STATUS_IS_OK(cli_unlock(c
, fnum2
, n
*sizeof(int), sizeof(int)))) {
641 printf("unlock failed (%s)\n", cli_errstr(c
));
647 cli_unlink(c
, lockfname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
654 static bool run_torture(int dummy
)
656 struct cli_state
*cli
;
661 cli_sockopt(cli
, sockops
);
663 ret
= rw_torture(cli
);
665 if (!torture_close_connection(cli
)) {
672 static bool rw_torture3(struct cli_state
*c
, char *lockfname
)
674 uint16_t fnum
= (uint16_t)-1;
679 unsigned countprev
= 0;
682 NTSTATUS status
= NT_STATUS_OK
;
685 for (i
= 0; i
< sizeof(buf
); i
+= sizeof(uint32
))
687 SIVAL(buf
, i
, sys_random());
692 if (!NT_STATUS_IS_OK(cli_unlink(c
, lockfname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
))) {
693 printf("unlink failed (%s) (normal, this file should not exist)\n", cli_errstr(c
));
696 if (!NT_STATUS_IS_OK(cli_open(c
, lockfname
, O_RDWR
| O_CREAT
| O_EXCL
,
697 DENY_NONE
, &fnum
))) {
698 printf("first open read/write of %s failed (%s)\n",
699 lockfname
, cli_errstr(c
));
705 for (i
= 0; i
< 500 && fnum
== (uint16_t)-1; i
++)
707 status
= cli_open(c
, lockfname
, O_RDONLY
,
709 if (!NT_STATUS_IS_OK(status
)) {
714 if (!NT_STATUS_IS_OK(status
)) {
715 printf("second open read-only of %s failed (%s)\n",
716 lockfname
, cli_errstr(c
));
722 for (count
= 0; count
< sizeof(buf
); count
+= sent
)
724 if (count
>= countprev
) {
725 printf("%d %8d\r", i
, count
);
728 countprev
+= (sizeof(buf
) / 20);
733 sent
= ((unsigned)sys_random()%(20))+ 1;
734 if (sent
> sizeof(buf
) - count
)
736 sent
= sizeof(buf
) - count
;
739 status
= cli_writeall(c
, fnum
, 0, (uint8_t *)buf
+count
,
740 count
, (size_t)sent
, NULL
);
741 if (!NT_STATUS_IS_OK(status
)) {
742 printf("write failed (%s)\n",
749 sent
= cli_read(c
, fnum
, buf_rd
+count
, count
,
753 printf("read failed offset:%d size:%ld (%s)\n",
754 count
, (unsigned long)sizeof(buf
)-count
,
761 if (memcmp(buf_rd
+count
, buf
+count
, sent
) != 0)
763 printf("read/write compare failed\n");
764 printf("offset: %d req %ld recvd %ld\n", count
, (unsigned long)sizeof(buf
)-count
, (unsigned long)sent
);
773 if (!NT_STATUS_IS_OK(cli_close(c
, fnum
))) {
774 printf("close failed (%s)\n", cli_errstr(c
));
781 static bool rw_torture2(struct cli_state
*c1
, struct cli_state
*c2
)
783 const char *lockfname
= "\\torture2.lck";
792 if (!NT_STATUS_IS_OK(cli_unlink(c1
, lockfname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
))) {
793 printf("unlink failed (%s) (normal, this file should not exist)\n", cli_errstr(c1
));
796 if (!NT_STATUS_IS_OK(cli_open(c1
, lockfname
, O_RDWR
| O_CREAT
| O_EXCL
,
797 DENY_NONE
, &fnum1
))) {
798 printf("first open read/write of %s failed (%s)\n",
799 lockfname
, cli_errstr(c1
));
802 if (!NT_STATUS_IS_OK(cli_open(c2
, lockfname
, O_RDONLY
,
803 DENY_NONE
, &fnum2
))) {
804 printf("second open read-only of %s failed (%s)\n",
805 lockfname
, cli_errstr(c2
));
806 cli_close(c1
, fnum1
);
810 for (i
=0;i
<torture_numops
;i
++)
813 size_t buf_size
= ((unsigned)sys_random()%(sizeof(buf
)-1))+ 1;
815 printf("%d\r", i
); fflush(stdout
);
818 generate_random_buffer((unsigned char *)buf
, buf_size
);
820 status
= cli_writeall(c1
, fnum1
, 0, (uint8_t *)buf
, 0,
822 if (!NT_STATUS_IS_OK(status
)) {
823 printf("write failed (%s)\n", nt_errstr(status
));
828 if ((bytes_read
= cli_read(c2
, fnum2
, buf_rd
, 0, buf_size
)) != buf_size
) {
829 printf("read failed (%s)\n", cli_errstr(c2
));
830 printf("read %d, expected %ld\n", (int)bytes_read
,
831 (unsigned long)buf_size
);
836 if (memcmp(buf_rd
, buf
, buf_size
) != 0)
838 printf("read/write compare failed\n");
844 if (!NT_STATUS_IS_OK(cli_close(c2
, fnum2
))) {
845 printf("close failed (%s)\n", cli_errstr(c2
));
848 if (!NT_STATUS_IS_OK(cli_close(c1
, fnum1
))) {
849 printf("close failed (%s)\n", cli_errstr(c1
));
853 if (!NT_STATUS_IS_OK(cli_unlink(c1
, lockfname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
))) {
854 printf("unlink failed (%s)\n", cli_errstr(c1
));
861 static bool run_readwritetest(int dummy
)
863 struct cli_state
*cli1
, *cli2
;
864 bool test1
, test2
= False
;
866 if (!torture_open_connection(&cli1
, 0) || !torture_open_connection(&cli2
, 1)) {
869 cli_sockopt(cli1
, sockops
);
870 cli_sockopt(cli2
, sockops
);
872 printf("starting readwritetest\n");
874 test1
= rw_torture2(cli1
, cli2
);
875 printf("Passed readwritetest v1: %s\n", BOOLSTR(test1
));
878 test2
= rw_torture2(cli1
, cli1
);
879 printf("Passed readwritetest v2: %s\n", BOOLSTR(test2
));
882 if (!torture_close_connection(cli1
)) {
886 if (!torture_close_connection(cli2
)) {
890 return (test1
&& test2
);
893 static bool run_readwritemulti(int dummy
)
895 struct cli_state
*cli
;
900 cli_sockopt(cli
, sockops
);
902 printf("run_readwritemulti: fname %s\n", randomfname
);
903 test
= rw_torture3(cli
, randomfname
);
905 if (!torture_close_connection(cli
)) {
912 static bool run_readwritelarge_internal(int max_xmit_k
)
914 static struct cli_state
*cli1
;
916 const char *lockfname
= "\\large.dat";
921 if (!torture_open_connection(&cli1
, 0)) {
924 cli_sockopt(cli1
, sockops
);
925 memset(buf
,'\0',sizeof(buf
));
927 cli1
->max_xmit
= max_xmit_k
*1024;
929 if (signing_state
== Required
) {
930 /* Horrible cheat to force
931 multiple signed outstanding
932 packets against a Samba server.
934 cli1
->is_samba
= false;
937 printf("starting readwritelarge_internal\n");
939 cli_unlink(cli1
, lockfname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
941 if (!NT_STATUS_IS_OK(cli_open(cli1
, lockfname
, O_RDWR
| O_CREAT
| O_EXCL
, DENY_NONE
, &fnum1
))) {
942 printf("open read/write of %s failed (%s)\n", lockfname
, cli_errstr(cli1
));
946 cli_writeall(cli1
, fnum1
, 0, (uint8_t *)buf
, 0, sizeof(buf
), NULL
);
948 if (!NT_STATUS_IS_OK(cli_qfileinfo_basic(
949 cli1
, fnum1
, NULL
, &fsize
, NULL
, NULL
,
950 NULL
, NULL
, NULL
))) {
951 printf("qfileinfo failed (%s)\n", cli_errstr(cli1
));
955 if (fsize
== sizeof(buf
))
956 printf("readwritelarge_internal test 1 succeeded (size = %lx)\n",
957 (unsigned long)fsize
);
959 printf("readwritelarge_internal test 1 failed (size = %lx)\n",
960 (unsigned long)fsize
);
964 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
965 printf("close failed (%s)\n", cli_errstr(cli1
));
969 if (!NT_STATUS_IS_OK(cli_unlink(cli1
, lockfname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
))) {
970 printf("unlink failed (%s)\n", cli_errstr(cli1
));
974 if (!NT_STATUS_IS_OK(cli_open(cli1
, lockfname
, O_RDWR
| O_CREAT
| O_EXCL
, DENY_NONE
, &fnum1
))) {
975 printf("open read/write of %s failed (%s)\n", lockfname
, cli_errstr(cli1
));
979 cli1
->max_xmit
= 4*1024;
981 cli_smbwrite(cli1
, fnum1
, buf
, 0, sizeof(buf
), NULL
);
983 if (!NT_STATUS_IS_OK(cli_qfileinfo_basic(
984 cli1
, fnum1
, NULL
, &fsize
, NULL
, NULL
,
985 NULL
, NULL
, NULL
))) {
986 printf("qfileinfo failed (%s)\n", cli_errstr(cli1
));
990 if (fsize
== sizeof(buf
))
991 printf("readwritelarge_internal test 2 succeeded (size = %lx)\n",
992 (unsigned long)fsize
);
994 printf("readwritelarge_internal test 2 failed (size = %lx)\n",
995 (unsigned long)fsize
);
1000 /* ToDo - set allocation. JRA */
1001 if(!cli_set_allocation_size(cli1
, fnum1
, 0)) {
1002 printf("set allocation size to zero failed (%s)\n", cli_errstr(&cli1
));
1005 if (!cli_qfileinfo_basic(cli1
, fnum1
, NULL
, &fsize
, NULL
, NULL
, NULL
,
1007 printf("qfileinfo failed (%s)\n", cli_errstr(cli1
));
1011 printf("readwritelarge test 3 (truncate test) succeeded (size = %x)\n", fsize
);
1014 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
1015 printf("close failed (%s)\n", cli_errstr(cli1
));
1019 if (!torture_close_connection(cli1
)) {
1025 static bool run_readwritelarge(int dummy
)
1027 return run_readwritelarge_internal(128);
1030 static bool run_readwritelarge_signtest(int dummy
)
1033 signing_state
= Required
;
1034 ret
= run_readwritelarge_internal(2);
1035 signing_state
= Undefined
;
1042 #define ival(s) strtol(s, NULL, 0)
1044 /* run a test that simulates an approximate netbench client load */
1045 static bool run_netbench(int client
)
1047 struct cli_state
*cli
;
1052 const char *params
[20];
1053 bool correct
= True
;
1059 cli_sockopt(cli
, sockops
);
1063 slprintf(cname
,sizeof(cname
)-1, "client%d", client
);
1065 f
= fopen(client_txt
, "r");
1072 while (fgets(line
, sizeof(line
)-1, f
)) {
1076 line
[strlen(line
)-1] = 0;
1078 /* printf("[%d] %s\n", line_count, line); */
1080 all_string_sub(line
,"client1", cname
, sizeof(line
));
1082 /* parse the command parameters */
1083 params
[0] = strtok_r(line
, " ", &saveptr
);
1085 while (params
[i
]) params
[++i
] = strtok_r(NULL
, " ", &saveptr
);
1089 if (i
< 2) continue;
1091 if (!strncmp(params
[0],"SMB", 3)) {
1092 printf("ERROR: You are using a dbench 1 load file\n");
1096 if (!strcmp(params
[0],"NTCreateX")) {
1097 nb_createx(params
[1], ival(params
[2]), ival(params
[3]),
1099 } else if (!strcmp(params
[0],"Close")) {
1100 nb_close(ival(params
[1]));
1101 } else if (!strcmp(params
[0],"Rename")) {
1102 nb_rename(params
[1], params
[2]);
1103 } else if (!strcmp(params
[0],"Unlink")) {
1104 nb_unlink(params
[1]);
1105 } else if (!strcmp(params
[0],"Deltree")) {
1106 nb_deltree(params
[1]);
1107 } else if (!strcmp(params
[0],"Rmdir")) {
1108 nb_rmdir(params
[1]);
1109 } else if (!strcmp(params
[0],"QUERY_PATH_INFORMATION")) {
1110 nb_qpathinfo(params
[1]);
1111 } else if (!strcmp(params
[0],"QUERY_FILE_INFORMATION")) {
1112 nb_qfileinfo(ival(params
[1]));
1113 } else if (!strcmp(params
[0],"QUERY_FS_INFORMATION")) {
1114 nb_qfsinfo(ival(params
[1]));
1115 } else if (!strcmp(params
[0],"FIND_FIRST")) {
1116 nb_findfirst(params
[1]);
1117 } else if (!strcmp(params
[0],"WriteX")) {
1118 nb_writex(ival(params
[1]),
1119 ival(params
[2]), ival(params
[3]), ival(params
[4]));
1120 } else if (!strcmp(params
[0],"ReadX")) {
1121 nb_readx(ival(params
[1]),
1122 ival(params
[2]), ival(params
[3]), ival(params
[4]));
1123 } else if (!strcmp(params
[0],"Flush")) {
1124 nb_flush(ival(params
[1]));
1126 printf("Unknown operation %s\n", params
[0]);
1134 if (!torture_close_connection(cli
)) {
1142 /* run a test that simulates an approximate netbench client load */
1143 static bool run_nbench(int dummy
)
1146 bool correct
= True
;
1152 signal(SIGALRM
, nb_alarm
);
1154 t
= create_procs(run_netbench
, &correct
);
1157 printf("\nThroughput %g MB/sec\n",
1158 1.0e-6 * nbio_total() / t
);
1164 This test checks for two things:
1166 1) correct support for retaining locks over a close (ie. the server
1167 must not use posix semantics)
1168 2) support for lock timeouts
1170 static bool run_locktest1(int dummy
)
1172 struct cli_state
*cli1
, *cli2
;
1173 const char *fname
= "\\lockt1.lck";
1174 uint16_t fnum1
, fnum2
, fnum3
;
1176 unsigned lock_timeout
;
1178 if (!torture_open_connection(&cli1
, 0) || !torture_open_connection(&cli2
, 1)) {
1181 cli_sockopt(cli1
, sockops
);
1182 cli_sockopt(cli2
, sockops
);
1184 printf("starting locktest1\n");
1186 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
1188 if (!NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
))) {
1189 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
1192 if (!NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
, &fnum2
))) {
1193 printf("open2 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
1196 if (!NT_STATUS_IS_OK(cli_open(cli2
, fname
, O_RDWR
, DENY_NONE
, &fnum3
))) {
1197 printf("open3 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
1201 if (!cli_lock(cli1
, fnum1
, 0, 4, 0, WRITE_LOCK
)) {
1202 printf("lock1 failed (%s)\n", cli_errstr(cli1
));
1207 if (cli_lock(cli2
, fnum3
, 0, 4, 0, WRITE_LOCK
)) {
1208 printf("lock2 succeeded! This is a locking bug\n");
1211 if (!check_error(__LINE__
, cli2
, ERRDOS
, ERRlock
,
1212 NT_STATUS_LOCK_NOT_GRANTED
)) return False
;
1216 lock_timeout
= (1 + (random() % 20));
1217 printf("Testing lock timeout with timeout=%u\n", lock_timeout
);
1219 if (cli_lock(cli2
, fnum3
, 0, 4, lock_timeout
* 1000, WRITE_LOCK
)) {
1220 printf("lock3 succeeded! This is a locking bug\n");
1223 if (!check_error(__LINE__
, cli2
, ERRDOS
, ERRlock
,
1224 NT_STATUS_FILE_LOCK_CONFLICT
)) return False
;
1228 if (ABS(t2
- t1
) < lock_timeout
-1) {
1229 printf("error: This server appears not to support timed lock requests\n");
1232 printf("server slept for %u seconds for a %u second timeout\n",
1233 (unsigned int)(t2
-t1
), lock_timeout
);
1235 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum2
))) {
1236 printf("close1 failed (%s)\n", cli_errstr(cli1
));
1240 if (cli_lock(cli2
, fnum3
, 0, 4, 0, WRITE_LOCK
)) {
1241 printf("lock4 succeeded! This is a locking bug\n");
1244 if (!check_error(__LINE__
, cli2
, ERRDOS
, ERRlock
,
1245 NT_STATUS_FILE_LOCK_CONFLICT
)) return False
;
1248 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
1249 printf("close2 failed (%s)\n", cli_errstr(cli1
));
1253 if (!NT_STATUS_IS_OK(cli_close(cli2
, fnum3
))) {
1254 printf("close3 failed (%s)\n", cli_errstr(cli2
));
1258 if (!NT_STATUS_IS_OK(cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
))) {
1259 printf("unlink failed (%s)\n", cli_errstr(cli1
));
1264 if (!torture_close_connection(cli1
)) {
1268 if (!torture_close_connection(cli2
)) {
1272 printf("Passed locktest1\n");
1277 this checks to see if a secondary tconx can use open files from an
1280 static bool run_tcon_test(int dummy
)
1282 static struct cli_state
*cli
;
1283 const char *fname
= "\\tcontest.tmp";
1285 uint16 cnum1
, cnum2
, cnum3
;
1286 uint16 vuid1
, vuid2
;
1291 memset(buf
, '\0', sizeof(buf
));
1293 if (!torture_open_connection(&cli
, 0)) {
1296 cli_sockopt(cli
, sockops
);
1298 printf("starting tcontest\n");
1300 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
1302 if (!NT_STATUS_IS_OK(cli_open(cli
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
))) {
1303 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli
));
1310 status
= cli_writeall(cli
, fnum1
, 0, (uint8_t *)buf
, 130, 4, NULL
);
1311 if (!NT_STATUS_IS_OK(status
)) {
1312 printf("initial write failed (%s)", nt_errstr(status
));
1316 status
= cli_tcon_andx(cli
, share
, "?????",
1317 password
, strlen(password
)+1);
1318 if (!NT_STATUS_IS_OK(status
)) {
1319 printf("%s refused 2nd tree connect (%s)\n", host
,
1326 cnum3
= MAX(cnum1
, cnum2
) + 1; /* any invalid number */
1327 vuid2
= cli
->vuid
+ 1;
1329 /* try a write with the wrong tid */
1332 status
= cli_writeall(cli
, fnum1
, 0, (uint8_t *)buf
, 130, 4, NULL
);
1333 if (NT_STATUS_IS_OK(status
)) {
1334 printf("* server allows write with wrong TID\n");
1337 printf("server fails write with wrong TID : %s\n",
1342 /* try a write with an invalid tid */
1345 status
= cli_writeall(cli
, fnum1
, 0, (uint8_t *)buf
, 130, 4, NULL
);
1346 if (NT_STATUS_IS_OK(status
)) {
1347 printf("* server allows write with invalid TID\n");
1350 printf("server fails write with invalid TID : %s\n",
1354 /* try a write with an invalid vuid */
1358 status
= cli_writeall(cli
, fnum1
, 0, (uint8_t *)buf
, 130, 4, NULL
);
1359 if (NT_STATUS_IS_OK(status
)) {
1360 printf("* server allows write with invalid VUID\n");
1363 printf("server fails write with invalid VUID : %s\n",
1370 if (!NT_STATUS_IS_OK(cli_close(cli
, fnum1
))) {
1371 printf("close failed (%s)\n", cli_errstr(cli
));
1377 status
= cli_tdis(cli
);
1378 if (!NT_STATUS_IS_OK(status
)) {
1379 printf("secondary tdis failed (%s)\n", nt_errstr(status
));
1385 if (!torture_close_connection(cli
)) {
1394 checks for old style tcon support
1396 static bool run_tcon2_test(int dummy
)
1398 static struct cli_state
*cli
;
1399 uint16 cnum
, max_xmit
;
1403 if (!torture_open_connection(&cli
, 0)) {
1406 cli_sockopt(cli
, sockops
);
1408 printf("starting tcon2 test\n");
1410 if (asprintf(&service
, "\\\\%s\\%s", host
, share
) == -1) {
1414 status
= cli_raw_tcon(cli
, service
, password
, "?????", &max_xmit
, &cnum
);
1418 if (!NT_STATUS_IS_OK(status
)) {
1419 printf("tcon2 failed : %s\n", nt_errstr(status
));
1421 printf("tcon OK : max_xmit=%d cnum=%d\n",
1422 (int)max_xmit
, (int)cnum
);
1425 if (!torture_close_connection(cli
)) {
1429 printf("Passed tcon2 test\n");
1433 static bool tcon_devtest(struct cli_state
*cli
,
1434 const char *myshare
, const char *devtype
,
1435 const char *return_devtype
,
1436 NTSTATUS expected_error
)
1441 status
= cli_tcon_andx(cli
, myshare
, devtype
,
1442 password
, strlen(password
)+1);
1444 if (NT_STATUS_IS_OK(expected_error
)) {
1445 if (NT_STATUS_IS_OK(status
)) {
1446 if (strcmp(cli
->dev
, return_devtype
) == 0) {
1449 printf("tconX to share %s with type %s "
1450 "succeeded but returned the wrong "
1451 "device type (got [%s] but should have got [%s])\n",
1452 myshare
, devtype
, cli
->dev
, return_devtype
);
1456 printf("tconX to share %s with type %s "
1457 "should have succeeded but failed\n",
1463 if (NT_STATUS_IS_OK(status
)) {
1464 printf("tconx to share %s with type %s "
1465 "should have failed but succeeded\n",
1469 if (NT_STATUS_EQUAL(cli_nt_error(cli
),
1473 printf("Returned unexpected error\n");
1482 checks for correct tconX support
1484 static bool run_tcon_devtype_test(int dummy
)
1486 static struct cli_state
*cli1
= NULL
;
1491 status
= cli_full_connection(&cli1
, myname
,
1492 host
, NULL
, port_to_use
,
1494 username
, workgroup
,
1495 password
, flags
, signing_state
);
1497 if (!NT_STATUS_IS_OK(status
)) {
1498 printf("could not open connection\n");
1502 if (!tcon_devtest(cli1
, "IPC$", "A:", NULL
, NT_STATUS_BAD_DEVICE_TYPE
))
1505 if (!tcon_devtest(cli1
, "IPC$", "?????", "IPC", NT_STATUS_OK
))
1508 if (!tcon_devtest(cli1
, "IPC$", "LPT:", NULL
, NT_STATUS_BAD_DEVICE_TYPE
))
1511 if (!tcon_devtest(cli1
, "IPC$", "IPC", "IPC", NT_STATUS_OK
))
1514 if (!tcon_devtest(cli1
, "IPC$", "FOOBA", NULL
, NT_STATUS_BAD_DEVICE_TYPE
))
1517 if (!tcon_devtest(cli1
, share
, "A:", "A:", NT_STATUS_OK
))
1520 if (!tcon_devtest(cli1
, share
, "?????", "A:", NT_STATUS_OK
))
1523 if (!tcon_devtest(cli1
, share
, "LPT:", NULL
, NT_STATUS_BAD_DEVICE_TYPE
))
1526 if (!tcon_devtest(cli1
, share
, "IPC", NULL
, NT_STATUS_BAD_DEVICE_TYPE
))
1529 if (!tcon_devtest(cli1
, share
, "FOOBA", NULL
, NT_STATUS_BAD_DEVICE_TYPE
))
1535 printf("Passed tcondevtest\n");
1542 This test checks that
1544 1) the server supports multiple locking contexts on the one SMB
1545 connection, distinguished by PID.
1547 2) the server correctly fails overlapping locks made by the same PID (this
1548 goes against POSIX behaviour, which is why it is tricky to implement)
1550 3) the server denies unlock requests by an incorrect client PID
1552 static bool run_locktest2(int dummy
)
1554 static struct cli_state
*cli
;
1555 const char *fname
= "\\lockt2.lck";
1556 uint16_t fnum1
, fnum2
, fnum3
;
1557 bool correct
= True
;
1559 if (!torture_open_connection(&cli
, 0)) {
1563 cli_sockopt(cli
, sockops
);
1565 printf("starting locktest2\n");
1567 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
1571 if (!NT_STATUS_IS_OK(cli_open(cli
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
))) {
1572 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli
));
1576 if (!NT_STATUS_IS_OK(cli_open(cli
, fname
, O_RDWR
, DENY_NONE
, &fnum2
))) {
1577 printf("open2 of %s failed (%s)\n", fname
, cli_errstr(cli
));
1583 if (!NT_STATUS_IS_OK(cli_open(cli
, fname
, O_RDWR
, DENY_NONE
, &fnum3
))) {
1584 printf("open3 of %s failed (%s)\n", fname
, cli_errstr(cli
));
1590 if (!cli_lock(cli
, fnum1
, 0, 4, 0, WRITE_LOCK
)) {
1591 printf("lock1 failed (%s)\n", cli_errstr(cli
));
1595 if (cli_lock(cli
, fnum1
, 0, 4, 0, WRITE_LOCK
)) {
1596 printf("WRITE lock1 succeeded! This is a locking bug\n");
1599 if (!check_error(__LINE__
, cli
, ERRDOS
, ERRlock
,
1600 NT_STATUS_LOCK_NOT_GRANTED
)) return False
;
1603 if (cli_lock(cli
, fnum2
, 0, 4, 0, WRITE_LOCK
)) {
1604 printf("WRITE lock2 succeeded! This is a locking bug\n");
1607 if (!check_error(__LINE__
, cli
, ERRDOS
, ERRlock
,
1608 NT_STATUS_LOCK_NOT_GRANTED
)) return False
;
1611 if (cli_lock(cli
, fnum2
, 0, 4, 0, READ_LOCK
)) {
1612 printf("READ lock2 succeeded! This is a locking bug\n");
1615 if (!check_error(__LINE__
, cli
, ERRDOS
, ERRlock
,
1616 NT_STATUS_FILE_LOCK_CONFLICT
)) return False
;
1619 if (!cli_lock(cli
, fnum1
, 100, 4, 0, WRITE_LOCK
)) {
1620 printf("lock at 100 failed (%s)\n", cli_errstr(cli
));
1623 if (NT_STATUS_IS_OK(cli_unlock(cli
, fnum1
, 100, 4))) {
1624 printf("unlock at 100 succeeded! This is a locking bug\n");
1628 if (NT_STATUS_IS_OK(cli_unlock(cli
, fnum1
, 0, 4))) {
1629 printf("unlock1 succeeded! This is a locking bug\n");
1632 if (!check_error(__LINE__
, cli
,
1634 NT_STATUS_RANGE_NOT_LOCKED
)) return False
;
1637 if (NT_STATUS_IS_OK(cli_unlock(cli
, fnum1
, 0, 8))) {
1638 printf("unlock2 succeeded! This is a locking bug\n");
1641 if (!check_error(__LINE__
, cli
,
1643 NT_STATUS_RANGE_NOT_LOCKED
)) return False
;
1646 if (cli_lock(cli
, fnum3
, 0, 4, 0, WRITE_LOCK
)) {
1647 printf("lock3 succeeded! This is a locking bug\n");
1650 if (!check_error(__LINE__
, cli
, ERRDOS
, ERRlock
, NT_STATUS_LOCK_NOT_GRANTED
)) return False
;
1655 if (!NT_STATUS_IS_OK(cli_close(cli
, fnum1
))) {
1656 printf("close1 failed (%s)\n", cli_errstr(cli
));
1660 if (!NT_STATUS_IS_OK(cli_close(cli
, fnum2
))) {
1661 printf("close2 failed (%s)\n", cli_errstr(cli
));
1665 if (!NT_STATUS_IS_OK(cli_close(cli
, fnum3
))) {
1666 printf("close3 failed (%s)\n", cli_errstr(cli
));
1670 if (!torture_close_connection(cli
)) {
1674 printf("locktest2 finished\n");
1681 This test checks that
1683 1) the server supports the full offset range in lock requests
1685 static bool run_locktest3(int dummy
)
1687 static struct cli_state
*cli1
, *cli2
;
1688 const char *fname
= "\\lockt3.lck";
1689 uint16_t fnum1
, fnum2
;
1692 bool correct
= True
;
1694 #define NEXT_OFFSET offset += (~(uint32)0) / torture_numops
1696 if (!torture_open_connection(&cli1
, 0) || !torture_open_connection(&cli2
, 1)) {
1699 cli_sockopt(cli1
, sockops
);
1700 cli_sockopt(cli2
, sockops
);
1702 printf("starting locktest3\n");
1704 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
1706 if (!NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
))) {
1707 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
1710 if (!NT_STATUS_IS_OK(cli_open(cli2
, fname
, O_RDWR
, DENY_NONE
, &fnum2
))) {
1711 printf("open2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
1715 for (offset
=i
=0;i
<torture_numops
;i
++) {
1717 if (!cli_lock(cli1
, fnum1
, offset
-1, 1, 0, WRITE_LOCK
)) {
1718 printf("lock1 %d failed (%s)\n",
1724 if (!cli_lock(cli2
, fnum2
, offset
-2, 1, 0, WRITE_LOCK
)) {
1725 printf("lock2 %d failed (%s)\n",
1732 for (offset
=i
=0;i
<torture_numops
;i
++) {
1735 if (cli_lock(cli1
, fnum1
, offset
-2, 1, 0, WRITE_LOCK
)) {
1736 printf("error: lock1 %d succeeded!\n", i
);
1740 if (cli_lock(cli2
, fnum2
, offset
-1, 1, 0, WRITE_LOCK
)) {
1741 printf("error: lock2 %d succeeded!\n", i
);
1745 if (cli_lock(cli1
, fnum1
, offset
-1, 1, 0, WRITE_LOCK
)) {
1746 printf("error: lock3 %d succeeded!\n", i
);
1750 if (cli_lock(cli2
, fnum2
, offset
-2, 1, 0, WRITE_LOCK
)) {
1751 printf("error: lock4 %d succeeded!\n", i
);
1756 for (offset
=i
=0;i
<torture_numops
;i
++) {
1759 if (!NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, offset
-1, 1))) {
1760 printf("unlock1 %d failed (%s)\n",
1766 if (!NT_STATUS_IS_OK(cli_unlock(cli2
, fnum2
, offset
-2, 1))) {
1767 printf("unlock2 %d failed (%s)\n",
1774 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
1775 printf("close1 failed (%s)\n", cli_errstr(cli1
));
1779 if (!NT_STATUS_IS_OK(cli_close(cli2
, fnum2
))) {
1780 printf("close2 failed (%s)\n", cli_errstr(cli2
));
1784 if (!NT_STATUS_IS_OK(cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
))) {
1785 printf("unlink failed (%s)\n", cli_errstr(cli1
));
1789 if (!torture_close_connection(cli1
)) {
1793 if (!torture_close_connection(cli2
)) {
1797 printf("finished locktest3\n");
1802 #define EXPECTED(ret, v) if ((ret) != (v)) { \
1803 printf("** "); correct = False; \
1807 looks at overlapping locks
1809 static bool run_locktest4(int dummy
)
1811 static struct cli_state
*cli1
, *cli2
;
1812 const char *fname
= "\\lockt4.lck";
1813 uint16_t fnum1
, fnum2
, f
;
1816 bool correct
= True
;
1819 if (!torture_open_connection(&cli1
, 0) || !torture_open_connection(&cli2
, 1)) {
1823 cli_sockopt(cli1
, sockops
);
1824 cli_sockopt(cli2
, sockops
);
1826 printf("starting locktest4\n");
1828 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
1830 cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
);
1831 cli_open(cli2
, fname
, O_RDWR
, DENY_NONE
, &fnum2
);
1833 memset(buf
, 0, sizeof(buf
));
1835 status
= cli_writeall(cli1
, fnum1
, 0, (uint8_t *)buf
, 0, sizeof(buf
),
1837 if (!NT_STATUS_IS_OK(status
)) {
1838 printf("Failed to create file: %s\n", nt_errstr(status
));
1843 ret
= cli_lock(cli1
, fnum1
, 0, 4, 0, WRITE_LOCK
) &&
1844 cli_lock(cli1
, fnum1
, 2, 4, 0, WRITE_LOCK
);
1845 EXPECTED(ret
, False
);
1846 printf("the same process %s set overlapping write locks\n", ret
?"can":"cannot");
1848 ret
= cli_lock(cli1
, fnum1
, 10, 4, 0, READ_LOCK
) &&
1849 cli_lock(cli1
, fnum1
, 12, 4, 0, READ_LOCK
);
1850 EXPECTED(ret
, True
);
1851 printf("the same process %s set overlapping read locks\n", ret
?"can":"cannot");
1853 ret
= cli_lock(cli1
, fnum1
, 20, 4, 0, WRITE_LOCK
) &&
1854 cli_lock(cli2
, fnum2
, 22, 4, 0, WRITE_LOCK
);
1855 EXPECTED(ret
, False
);
1856 printf("a different connection %s set overlapping write locks\n", ret
?"can":"cannot");
1858 ret
= cli_lock(cli1
, fnum1
, 30, 4, 0, READ_LOCK
) &&
1859 cli_lock(cli2
, fnum2
, 32, 4, 0, READ_LOCK
);
1860 EXPECTED(ret
, True
);
1861 printf("a different connection %s set overlapping read locks\n", ret
?"can":"cannot");
1863 ret
= (cli_setpid(cli1
, 1), cli_lock(cli1
, fnum1
, 40, 4, 0, WRITE_LOCK
)) &&
1864 (cli_setpid(cli1
, 2), cli_lock(cli1
, fnum1
, 42, 4, 0, WRITE_LOCK
));
1865 EXPECTED(ret
, False
);
1866 printf("a different pid %s set overlapping write locks\n", ret
?"can":"cannot");
1868 ret
= (cli_setpid(cli1
, 1), cli_lock(cli1
, fnum1
, 50, 4, 0, READ_LOCK
)) &&
1869 (cli_setpid(cli1
, 2), cli_lock(cli1
, fnum1
, 52, 4, 0, READ_LOCK
));
1870 EXPECTED(ret
, True
);
1871 printf("a different pid %s set overlapping read locks\n", ret
?"can":"cannot");
1873 ret
= cli_lock(cli1
, fnum1
, 60, 4, 0, READ_LOCK
) &&
1874 cli_lock(cli1
, fnum1
, 60, 4, 0, READ_LOCK
);
1875 EXPECTED(ret
, True
);
1876 printf("the same process %s set the same read lock twice\n", ret
?"can":"cannot");
1878 ret
= cli_lock(cli1
, fnum1
, 70, 4, 0, WRITE_LOCK
) &&
1879 cli_lock(cli1
, fnum1
, 70, 4, 0, WRITE_LOCK
);
1880 EXPECTED(ret
, False
);
1881 printf("the same process %s set the same write lock twice\n", ret
?"can":"cannot");
1883 ret
= cli_lock(cli1
, fnum1
, 80, 4, 0, READ_LOCK
) &&
1884 cli_lock(cli1
, fnum1
, 80, 4, 0, WRITE_LOCK
);
1885 EXPECTED(ret
, False
);
1886 printf("the same process %s overlay a read lock with a write lock\n", ret
?"can":"cannot");
1888 ret
= cli_lock(cli1
, fnum1
, 90, 4, 0, WRITE_LOCK
) &&
1889 cli_lock(cli1
, fnum1
, 90, 4, 0, READ_LOCK
);
1890 EXPECTED(ret
, True
);
1891 printf("the same process %s overlay a write lock with a read lock\n", ret
?"can":"cannot");
1893 ret
= (cli_setpid(cli1
, 1), cli_lock(cli1
, fnum1
, 100, 4, 0, WRITE_LOCK
)) &&
1894 (cli_setpid(cli1
, 2), cli_lock(cli1
, fnum1
, 100, 4, 0, READ_LOCK
));
1895 EXPECTED(ret
, False
);
1896 printf("a different pid %s overlay a write lock with a read lock\n", ret
?"can":"cannot");
1898 ret
= cli_lock(cli1
, fnum1
, 110, 4, 0, READ_LOCK
) &&
1899 cli_lock(cli1
, fnum1
, 112, 4, 0, READ_LOCK
) &&
1900 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 110, 6));
1901 EXPECTED(ret
, False
);
1902 printf("the same process %s coalesce read locks\n", ret
?"can":"cannot");
1905 ret
= cli_lock(cli1
, fnum1
, 120, 4, 0, WRITE_LOCK
) &&
1906 (cli_read(cli2
, fnum2
, buf
, 120, 4) == 4);
1907 EXPECTED(ret
, False
);
1908 printf("this server %s strict write locking\n", ret
?"doesn't do":"does");
1910 ret
= cli_lock(cli1
, fnum1
, 130, 4, 0, READ_LOCK
);
1912 status
= cli_writeall(cli2
, fnum2
, 0, (uint8_t *)buf
, 130, 4,
1914 ret
= NT_STATUS_IS_OK(status
);
1916 EXPECTED(ret
, False
);
1917 printf("this server %s strict read locking\n", ret
?"doesn't do":"does");
1920 ret
= cli_lock(cli1
, fnum1
, 140, 4, 0, READ_LOCK
) &&
1921 cli_lock(cli1
, fnum1
, 140, 4, 0, READ_LOCK
) &&
1922 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 140, 4)) &&
1923 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 140, 4));
1924 EXPECTED(ret
, True
);
1925 printf("this server %s do recursive read locking\n", ret
?"does":"doesn't");
1928 ret
= cli_lock(cli1
, fnum1
, 150, 4, 0, WRITE_LOCK
) &&
1929 cli_lock(cli1
, fnum1
, 150, 4, 0, READ_LOCK
) &&
1930 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 150, 4)) &&
1931 (cli_read(cli2
, fnum2
, buf
, 150, 4) == 4) &&
1932 !(NT_STATUS_IS_OK(cli_writeall(cli2
, fnum2
, 0, (uint8_t *)buf
,
1934 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 150, 4));
1935 EXPECTED(ret
, True
);
1936 printf("this server %s do recursive lock overlays\n", ret
?"does":"doesn't");
1938 ret
= cli_lock(cli1
, fnum1
, 160, 4, 0, READ_LOCK
) &&
1939 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 160, 4)) &&
1940 NT_STATUS_IS_OK(cli_writeall(cli2
, fnum2
, 0, (uint8_t *)buf
,
1942 (cli_read(cli2
, fnum2
, buf
, 160, 4) == 4);
1943 EXPECTED(ret
, True
);
1944 printf("the same process %s remove a read lock using write locking\n", ret
?"can":"cannot");
1946 ret
= cli_lock(cli1
, fnum1
, 170, 4, 0, WRITE_LOCK
) &&
1947 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 170, 4)) &&
1948 NT_STATUS_IS_OK(cli_writeall(cli2
, fnum2
, 0, (uint8_t *)buf
,
1950 (cli_read(cli2
, fnum2
, buf
, 170, 4) == 4);
1951 EXPECTED(ret
, True
);
1952 printf("the same process %s remove a write lock using read locking\n", ret
?"can":"cannot");
1954 ret
= cli_lock(cli1
, fnum1
, 190, 4, 0, WRITE_LOCK
) &&
1955 cli_lock(cli1
, fnum1
, 190, 4, 0, READ_LOCK
) &&
1956 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 190, 4)) &&
1957 !NT_STATUS_IS_OK(cli_writeall(cli2
, fnum2
, 0, (uint8_t *)buf
,
1959 (cli_read(cli2
, fnum2
, buf
, 190, 4) == 4);
1960 EXPECTED(ret
, True
);
1961 printf("the same process %s remove the first lock first\n", ret
?"does":"doesn't");
1963 cli_close(cli1
, fnum1
);
1964 cli_close(cli2
, fnum2
);
1965 cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
, &fnum1
);
1966 cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
, &f
);
1967 ret
= cli_lock(cli1
, fnum1
, 0, 8, 0, READ_LOCK
) &&
1968 cli_lock(cli1
, f
, 0, 1, 0, READ_LOCK
) &&
1969 NT_STATUS_IS_OK(cli_close(cli1
, fnum1
)) &&
1970 NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
, &fnum1
)) &&
1971 cli_lock(cli1
, fnum1
, 7, 1, 0, WRITE_LOCK
);
1973 cli_close(cli1
, fnum1
);
1974 EXPECTED(ret
, True
);
1975 printf("the server %s have the NT byte range lock bug\n", !ret
?"does":"doesn't");
1978 cli_close(cli1
, fnum1
);
1979 cli_close(cli2
, fnum2
);
1980 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
1981 torture_close_connection(cli1
);
1982 torture_close_connection(cli2
);
1984 printf("finished locktest4\n");
1989 looks at lock upgrade/downgrade.
1991 static bool run_locktest5(int dummy
)
1993 static struct cli_state
*cli1
, *cli2
;
1994 const char *fname
= "\\lockt5.lck";
1995 uint16_t fnum1
, fnum2
, fnum3
;
1998 bool correct
= True
;
2001 if (!torture_open_connection(&cli1
, 0) || !torture_open_connection(&cli2
, 1)) {
2005 cli_sockopt(cli1
, sockops
);
2006 cli_sockopt(cli2
, sockops
);
2008 printf("starting locktest5\n");
2010 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2012 cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
);
2013 cli_open(cli2
, fname
, O_RDWR
, DENY_NONE
, &fnum2
);
2014 cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
, &fnum3
);
2016 memset(buf
, 0, sizeof(buf
));
2018 status
= cli_writeall(cli1
, fnum1
, 0, (uint8_t *)buf
, 0, sizeof(buf
),
2020 if (!NT_STATUS_IS_OK(status
)) {
2021 printf("Failed to create file: %s\n", nt_errstr(status
));
2026 /* Check for NT bug... */
2027 ret
= cli_lock(cli1
, fnum1
, 0, 8, 0, READ_LOCK
) &&
2028 cli_lock(cli1
, fnum3
, 0, 1, 0, READ_LOCK
);
2029 cli_close(cli1
, fnum1
);
2030 cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
, &fnum1
);
2031 ret
= cli_lock(cli1
, fnum1
, 7, 1, 0, WRITE_LOCK
);
2032 EXPECTED(ret
, True
);
2033 printf("this server %s the NT locking bug\n", ret
? "doesn't have" : "has");
2034 cli_close(cli1
, fnum1
);
2035 cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
, &fnum1
);
2036 cli_unlock(cli1
, fnum3
, 0, 1);
2038 ret
= cli_lock(cli1
, fnum1
, 0, 4, 0, WRITE_LOCK
) &&
2039 cli_lock(cli1
, fnum1
, 1, 1, 0, READ_LOCK
);
2040 EXPECTED(ret
, True
);
2041 printf("the same process %s overlay a write with a read lock\n", ret
?"can":"cannot");
2043 ret
= cli_lock(cli2
, fnum2
, 0, 4, 0, READ_LOCK
);
2044 EXPECTED(ret
, False
);
2046 printf("a different processs %s get a read lock on the first process lock stack\n", ret
?"can":"cannot");
2048 /* Unlock the process 2 lock. */
2049 cli_unlock(cli2
, fnum2
, 0, 4);
2051 ret
= cli_lock(cli1
, fnum3
, 0, 4, 0, READ_LOCK
);
2052 EXPECTED(ret
, False
);
2054 printf("the same processs on a different fnum %s get a read lock\n", ret
?"can":"cannot");
2056 /* Unlock the process 1 fnum3 lock. */
2057 cli_unlock(cli1
, fnum3
, 0, 4);
2059 /* Stack 2 more locks here. */
2060 ret
= cli_lock(cli1
, fnum1
, 0, 4, 0, READ_LOCK
) &&
2061 cli_lock(cli1
, fnum1
, 0, 4, 0, READ_LOCK
);
2063 EXPECTED(ret
, True
);
2064 printf("the same process %s stack read locks\n", ret
?"can":"cannot");
2066 /* Unlock the first process lock, then check this was the WRITE lock that was
2069 ret
= NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 0, 4)) &&
2070 cli_lock(cli2
, fnum2
, 0, 4, 0, READ_LOCK
);
2072 EXPECTED(ret
, True
);
2073 printf("the first unlock removes the %s lock\n", ret
?"WRITE":"READ");
2075 /* Unlock the process 2 lock. */
2076 cli_unlock(cli2
, fnum2
, 0, 4);
2078 /* We should have 3 stacked locks here. Ensure we need to do 3 unlocks. */
2080 ret
= NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 1, 1)) &&
2081 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 0, 4)) &&
2082 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 0, 4));
2084 EXPECTED(ret
, True
);
2085 printf("the same process %s unlock the stack of 4 locks\n", ret
?"can":"cannot");
2087 /* Ensure the next unlock fails. */
2088 ret
= NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 0, 4));
2089 EXPECTED(ret
, False
);
2090 printf("the same process %s count the lock stack\n", !ret
?"can":"cannot");
2092 /* Ensure connection 2 can get a write lock. */
2093 ret
= cli_lock(cli2
, fnum2
, 0, 4, 0, WRITE_LOCK
);
2094 EXPECTED(ret
, True
);
2096 printf("a different processs %s get a write lock on the unlocked stack\n", ret
?"can":"cannot");
2100 cli_close(cli1
, fnum1
);
2101 cli_close(cli2
, fnum2
);
2102 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2103 if (!torture_close_connection(cli1
)) {
2106 if (!torture_close_connection(cli2
)) {
2110 printf("finished locktest5\n");
2116 tries the unusual lockingX locktype bits
2118 static bool run_locktest6(int dummy
)
2120 static struct cli_state
*cli
;
2121 const char *fname
[1] = { "\\lock6.txt" };
2126 if (!torture_open_connection(&cli
, 0)) {
2130 cli_sockopt(cli
, sockops
);
2132 printf("starting locktest6\n");
2135 printf("Testing %s\n", fname
[i
]);
2137 cli_unlink(cli
, fname
[i
], FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2139 cli_open(cli
, fname
[i
], O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum
);
2140 status
= cli_locktype(cli
, fnum
, 0, 8, 0, LOCKING_ANDX_CHANGE_LOCKTYPE
);
2141 cli_close(cli
, fnum
);
2142 printf("CHANGE_LOCKTYPE gave %s\n", nt_errstr(status
));
2144 cli_open(cli
, fname
[i
], O_RDWR
, DENY_NONE
, &fnum
);
2145 status
= cli_locktype(cli
, fnum
, 0, 8, 0, LOCKING_ANDX_CANCEL_LOCK
);
2146 cli_close(cli
, fnum
);
2147 printf("CANCEL_LOCK gave %s\n", nt_errstr(status
));
2149 cli_unlink(cli
, fname
[i
], FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2152 torture_close_connection(cli
);
2154 printf("finished locktest6\n");
2158 static bool run_locktest7(int dummy
)
2160 struct cli_state
*cli1
;
2161 const char *fname
= "\\lockt7.lck";
2164 bool correct
= False
;
2167 if (!torture_open_connection(&cli1
, 0)) {
2171 cli_sockopt(cli1
, sockops
);
2173 printf("starting locktest7\n");
2175 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2177 cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
);
2179 memset(buf
, 0, sizeof(buf
));
2181 status
= cli_writeall(cli1
, fnum1
, 0, (uint8_t *)buf
, 0, sizeof(buf
),
2183 if (!NT_STATUS_IS_OK(status
)) {
2184 printf("Failed to create file: %s\n", nt_errstr(status
));
2188 cli_setpid(cli1
, 1);
2190 if (!cli_lock(cli1
, fnum1
, 130, 4, 0, READ_LOCK
)) {
2191 printf("Unable to apply read lock on range 130:4, error was %s\n", cli_errstr(cli1
));
2194 printf("pid1 successfully locked range 130:4 for READ\n");
2197 if (cli_read(cli1
, fnum1
, buf
, 130, 4) != 4) {
2198 printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(cli1
));
2201 printf("pid1 successfully read the range 130:4\n");
2204 status
= cli_writeall(cli1
, fnum1
, 0, (uint8_t *)buf
, 130, 4, NULL
);
2205 if (!NT_STATUS_IS_OK(status
)) {
2206 printf("pid1 unable to write to the range 130:4, error was "
2207 "%s\n", nt_errstr(status
));
2208 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_LOCK_CONFLICT
)) {
2209 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2213 printf("pid1 successfully wrote to the range 130:4 (should be denied)\n");
2217 cli_setpid(cli1
, 2);
2219 if (cli_read(cli1
, fnum1
, buf
, 130, 4) != 4) {
2220 printf("pid2 unable to read the range 130:4, error was %s\n", cli_errstr(cli1
));
2222 printf("pid2 successfully read the range 130:4\n");
2225 status
= cli_writeall(cli1
, fnum1
, 0, (uint8_t *)buf
, 130, 4, NULL
);
2226 if (!NT_STATUS_IS_OK(status
)) {
2227 printf("pid2 unable to write to the range 130:4, error was "
2228 "%s\n", nt_errstr(status
));
2229 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_LOCK_CONFLICT
)) {
2230 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2234 printf("pid2 successfully wrote to the range 130:4 (should be denied)\n");
2238 cli_setpid(cli1
, 1);
2239 cli_unlock(cli1
, fnum1
, 130, 4);
2241 if (!cli_lock(cli1
, fnum1
, 130, 4, 0, WRITE_LOCK
)) {
2242 printf("Unable to apply write lock on range 130:4, error was %s\n", cli_errstr(cli1
));
2245 printf("pid1 successfully locked range 130:4 for WRITE\n");
2248 if (cli_read(cli1
, fnum1
, buf
, 130, 4) != 4) {
2249 printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(cli1
));
2252 printf("pid1 successfully read the range 130:4\n");
2255 status
= cli_writeall(cli1
, fnum1
, 0, (uint8_t *)buf
, 130, 4, NULL
);
2256 if (!NT_STATUS_IS_OK(status
)) {
2257 printf("pid1 unable to write to the range 130:4, error was "
2258 "%s\n", nt_errstr(status
));
2261 printf("pid1 successfully wrote to the range 130:4\n");
2264 cli_setpid(cli1
, 2);
2266 if (cli_read(cli1
, fnum1
, buf
, 130, 4) != 4) {
2267 printf("pid2 unable to read the range 130:4, error was %s\n", cli_errstr(cli1
));
2268 if (NT_STATUS_V(cli_nt_error(cli1
)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT
)) {
2269 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2273 printf("pid2 successfully read the range 130:4 (should be denied)\n");
2277 status
= cli_writeall(cli1
, fnum1
, 0, (uint8_t *)buf
, 130, 4, NULL
);
2278 if (!NT_STATUS_IS_OK(status
)) {
2279 printf("pid2 unable to write to the range 130:4, error was "
2280 "%s\n", nt_errstr(status
));
2281 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_LOCK_CONFLICT
)) {
2282 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2286 printf("pid2 successfully wrote to the range 130:4 (should be denied)\n");
2290 cli_unlock(cli1
, fnum1
, 130, 0);
2294 cli_close(cli1
, fnum1
);
2295 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2296 torture_close_connection(cli1
);
2298 printf("finished locktest7\n");
2303 * This demonstrates a problem with our use of GPFS share modes: A file
2304 * descriptor sitting in the pending close queue holding a GPFS share mode
2305 * blocks opening a file another time. Happens with Word 2007 temp files.
2306 * With "posix locking = yes" and "gpfs:sharemodes = yes" enabled, the third
2307 * open is denied with NT_STATUS_SHARING_VIOLATION.
2310 static bool run_locktest8(int dummy
)
2312 struct cli_state
*cli1
;
2313 const char *fname
= "\\lockt8.lck";
2314 uint16_t fnum1
, fnum2
;
2316 bool correct
= False
;
2319 if (!torture_open_connection(&cli1
, 0)) {
2323 cli_sockopt(cli1
, sockops
);
2325 printf("starting locktest8\n");
2327 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2329 status
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_WRITE
,
2331 if (!NT_STATUS_IS_OK(status
)) {
2332 d_fprintf(stderr
, "cli_open returned %s\n", cli_errstr(cli1
));
2336 memset(buf
, 0, sizeof(buf
));
2338 status
= cli_open(cli1
, fname
, O_RDONLY
, DENY_NONE
, &fnum2
);
2339 if (!NT_STATUS_IS_OK(status
)) {
2340 d_fprintf(stderr
, "cli_open second time returned %s\n",
2345 if (!cli_lock(cli1
, fnum2
, 1, 1, 0, READ_LOCK
)) {
2346 printf("Unable to apply read lock on range 1:1, error was "
2347 "%s\n", cli_errstr(cli1
));
2351 status
= cli_close(cli1
, fnum1
);
2352 if (!NT_STATUS_IS_OK(status
)) {
2353 d_fprintf(stderr
, "cli_close(fnum1) %s\n", cli_errstr(cli1
));
2357 status
= cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
, &fnum1
);
2358 if (!NT_STATUS_IS_OK(status
)) {
2359 d_fprintf(stderr
, "cli_open third time returned %s\n",
2367 cli_close(cli1
, fnum1
);
2368 cli_close(cli1
, fnum2
);
2369 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2370 torture_close_connection(cli1
);
2372 printf("finished locktest8\n");
2377 * This test is designed to be run in conjunction with
2378 * external NFS or POSIX locks taken in the filesystem.
2379 * It checks that the smbd server will block until the
2380 * lock is released and then acquire it. JRA.
2383 static bool got_alarm
;
2384 static int alarm_fd
;
2386 static void alarm_handler(int dummy
)
2391 static void alarm_handler_parent(int dummy
)
2396 static void do_local_lock(int read_fd
, int write_fd
)
2401 const char *local_pathname
= NULL
;
2404 local_pathname
= talloc_asprintf(talloc_tos(),
2405 "%s/lockt9.lck", local_path
);
2406 if (!local_pathname
) {
2407 printf("child: alloc fail\n");
2411 unlink(local_pathname
);
2412 fd
= open(local_pathname
, O_RDWR
|O_CREAT
, 0666);
2414 printf("child: open of %s failed %s.\n",
2415 local_pathname
, strerror(errno
));
2419 /* Now take a fcntl lock. */
2420 lock
.l_type
= F_WRLCK
;
2421 lock
.l_whence
= SEEK_SET
;
2424 lock
.l_pid
= getpid();
2426 ret
= fcntl(fd
,F_SETLK
,&lock
);
2428 printf("child: failed to get lock 0:4 on file %s. Error %s\n",
2429 local_pathname
, strerror(errno
));
2432 printf("child: got lock 0:4 on file %s.\n",
2437 CatchSignal(SIGALRM
, alarm_handler
);
2439 /* Signal the parent. */
2440 if (write(write_fd
, &c
, 1) != 1) {
2441 printf("child: start signal fail %s.\n",
2448 /* Wait for the parent to be ready. */
2449 if (read(read_fd
, &c
, 1) != 1) {
2450 printf("child: reply signal fail %s.\n",
2458 printf("child: released lock 0:4 on file %s.\n",
2464 static bool run_locktest9(int dummy
)
2466 struct cli_state
*cli1
;
2467 const char *fname
= "\\lockt9.lck";
2469 bool correct
= False
;
2470 int pipe_in
[2], pipe_out
[2];
2474 struct timeval start
;
2478 printf("starting locktest9\n");
2480 if (local_path
== NULL
) {
2481 d_fprintf(stderr
, "locktest9 must be given a local path via -l <localpath>\n");
2485 if (pipe(pipe_in
) == -1 || pipe(pipe_out
) == -1) {
2490 if (child_pid
== -1) {
2494 if (child_pid
== 0) {
2496 do_local_lock(pipe_out
[0], pipe_in
[1]);
2506 ret
= read(pipe_in
[0], &c
, 1);
2508 d_fprintf(stderr
, "failed to read start signal from child. %s\n",
2513 if (!torture_open_connection(&cli1
, 0)) {
2517 cli_sockopt(cli1
, sockops
);
2519 status
= cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
,
2521 if (!NT_STATUS_IS_OK(status
)) {
2522 d_fprintf(stderr
, "cli_open returned %s\n", cli_errstr(cli1
));
2526 /* Ensure the child has the lock. */
2527 if (cli_lock(cli1
, fnum
, 0, 4, 0, WRITE_LOCK
)) {
2528 d_fprintf(stderr
, "Got the lock on range 0:4 - this should not happen !\n");
2531 d_printf("Child has the lock.\n");
2534 /* Tell the child to wait 5 seconds then exit. */
2535 ret
= write(pipe_out
[1], &c
, 1);
2537 d_fprintf(stderr
, "failed to send exit signal to child. %s\n",
2542 /* Wait 20 seconds for the lock. */
2543 alarm_fd
= cli1
->fd
;
2544 CatchSignal(SIGALRM
, alarm_handler_parent
);
2547 start
= timeval_current();
2549 if (!cli_lock(cli1
, fnum
, 0, 4, -1, WRITE_LOCK
)) {
2550 d_fprintf(stderr
, "Unable to apply write lock on range 0:4, error was "
2551 "%s\n", cli_errstr(cli1
));
2556 seconds
= timeval_elapsed(&start
);
2558 printf("Parent got the lock after %.2f seconds.\n",
2561 status
= cli_close(cli1
, fnum
);
2562 if (!NT_STATUS_IS_OK(status
)) {
2563 d_fprintf(stderr
, "cli_close(fnum1) %s\n", cli_errstr(cli1
));
2570 cli_close(cli1
, fnum
);
2571 torture_close_connection(cli1
);
2575 printf("finished locktest9\n");
2580 test whether fnums and tids open on one VC are available on another (a major
2583 static bool run_fdpasstest(int dummy
)
2585 struct cli_state
*cli1
, *cli2
;
2586 const char *fname
= "\\fdpass.tst";
2591 if (!torture_open_connection(&cli1
, 0) || !torture_open_connection(&cli2
, 1)) {
2594 cli_sockopt(cli1
, sockops
);
2595 cli_sockopt(cli2
, sockops
);
2597 printf("starting fdpasstest\n");
2599 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2601 if (!NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
))) {
2602 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
2606 status
= cli_writeall(cli1
, fnum1
, 0, (uint8_t *)"hello world\n", 0,
2608 if (!NT_STATUS_IS_OK(status
)) {
2609 printf("write failed (%s)\n", nt_errstr(status
));
2613 cli2
->vuid
= cli1
->vuid
;
2614 cli2
->cnum
= cli1
->cnum
;
2615 cli2
->pid
= cli1
->pid
;
2617 if (cli_read(cli2
, fnum1
, buf
, 0, 13) == 13) {
2618 printf("read succeeded! nasty security hole [%s]\n",
2623 cli_close(cli1
, fnum1
);
2624 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2626 torture_close_connection(cli1
);
2627 torture_close_connection(cli2
);
2629 printf("finished fdpasstest\n");
2633 static bool run_fdsesstest(int dummy
)
2635 struct cli_state
*cli
;
2640 const char *fname
= "\\fdsess.tst";
2641 const char *fname1
= "\\fdsess1.tst";
2648 if (!torture_open_connection(&cli
, 0))
2650 cli_sockopt(cli
, sockops
);
2652 if (!torture_cli_session_setup2(cli
, &new_vuid
))
2655 saved_cnum
= cli
->cnum
;
2656 if (!NT_STATUS_IS_OK(cli_tcon_andx(cli
, share
, "?????", "", 1)))
2658 new_cnum
= cli
->cnum
;
2659 cli
->cnum
= saved_cnum
;
2661 printf("starting fdsesstest\n");
2663 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2664 cli_unlink(cli
, fname1
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2666 if (!NT_STATUS_IS_OK(cli_open(cli
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
))) {
2667 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli
));
2671 status
= cli_writeall(cli
, fnum1
, 0, (uint8_t *)"hello world\n", 0, 13,
2673 if (!NT_STATUS_IS_OK(status
)) {
2674 printf("write failed (%s)\n", nt_errstr(status
));
2678 saved_vuid
= cli
->vuid
;
2679 cli
->vuid
= new_vuid
;
2681 if (cli_read(cli
, fnum1
, buf
, 0, 13) == 13) {
2682 printf("read succeeded with different vuid! nasty security hole [%s]\n",
2686 /* Try to open a file with different vuid, samba cnum. */
2687 if (NT_STATUS_IS_OK(cli_open(cli
, fname1
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum2
))) {
2688 printf("create with different vuid, same cnum succeeded.\n");
2689 cli_close(cli
, fnum2
);
2690 cli_unlink(cli
, fname1
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2692 printf("create with different vuid, same cnum failed.\n");
2693 printf("This will cause problems with service clients.\n");
2697 cli
->vuid
= saved_vuid
;
2699 /* Try with same vuid, different cnum. */
2700 cli
->cnum
= new_cnum
;
2702 if (cli_read(cli
, fnum1
, buf
, 0, 13) == 13) {
2703 printf("read succeeded with different cnum![%s]\n",
2708 cli
->cnum
= saved_cnum
;
2709 cli_close(cli
, fnum1
);
2710 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2712 torture_close_connection(cli
);
2714 printf("finished fdsesstest\n");
2719 This test checks that
2721 1) the server does not allow an unlink on a file that is open
2723 static bool run_unlinktest(int dummy
)
2725 struct cli_state
*cli
;
2726 const char *fname
= "\\unlink.tst";
2728 bool correct
= True
;
2730 if (!torture_open_connection(&cli
, 0)) {
2734 cli_sockopt(cli
, sockops
);
2736 printf("starting unlink test\n");
2738 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2742 if (!NT_STATUS_IS_OK(cli_open(cli
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum
))) {
2743 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli
));
2747 if (NT_STATUS_IS_OK(cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
))) {
2748 printf("error: server allowed unlink on an open file\n");
2751 correct
= check_error(__LINE__
, cli
, ERRDOS
, ERRbadshare
,
2752 NT_STATUS_SHARING_VIOLATION
);
2755 cli_close(cli
, fnum
);
2756 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2758 if (!torture_close_connection(cli
)) {
2762 printf("unlink test finished\n");
2769 test how many open files this server supports on the one socket
2771 static bool run_maxfidtest(int dummy
)
2773 struct cli_state
*cli
;
2774 const char *ftemplate
= "\\maxfid.%d.%d";
2776 uint16_t fnums
[0x11000];
2779 bool correct
= True
;
2784 printf("failed to connect\n");
2788 cli_sockopt(cli
, sockops
);
2790 for (i
=0; i
<0x11000; i
++) {
2791 slprintf(fname
,sizeof(fname
)-1,ftemplate
, i
,(int)getpid());
2792 if (!NT_STATUS_IS_OK(cli_open(cli
, fname
,
2793 O_RDWR
|O_CREAT
|O_TRUNC
, DENY_NONE
, &fnums
[i
]))) {
2794 printf("open of %s failed (%s)\n",
2795 fname
, cli_errstr(cli
));
2796 printf("maximum fnum is %d\n", i
);
2804 printf("cleaning up\n");
2806 slprintf(fname
,sizeof(fname
)-1,ftemplate
, i
,(int)getpid());
2807 cli_close(cli
, fnums
[i
]);
2808 if (!NT_STATUS_IS_OK(cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
))) {
2809 printf("unlink of %s failed (%s)\n",
2810 fname
, cli_errstr(cli
));
2817 printf("maxfid test finished\n");
2818 if (!torture_close_connection(cli
)) {
2824 /* generate a random buffer */
2825 static void rand_buf(char *buf
, int len
)
2828 *buf
= (char)sys_random();
2833 /* send smb negprot commands, not reading the response */
2834 static bool run_negprot_nowait(int dummy
)
2836 struct tevent_context
*ev
;
2838 struct cli_state
*cli
;
2839 bool correct
= True
;
2841 printf("starting negprot nowait test\n");
2843 ev
= tevent_context_init(talloc_tos());
2848 if (!(cli
= open_nbt_connection())) {
2853 for (i
=0;i
<50000;i
++) {
2854 struct tevent_req
*req
;
2856 req
= cli_negprot_send(ev
, ev
, cli
);
2861 if (!tevent_req_poll(req
, ev
)) {
2862 d_fprintf(stderr
, "tevent_req_poll failed: %s\n",
2870 if (torture_close_connection(cli
)) {
2874 printf("finished negprot nowait test\n");
2879 /* send smb negprot commands, not reading the response */
2880 static bool run_bad_nbt_session(int dummy
)
2882 static struct cli_state
*cli
;
2884 printf("starting bad nbt session test\n");
2886 if (!(cli
= open_bad_nbt_connection())) {
2891 printf("finished bad nbt session test\n");
2895 /* send random IPC commands */
2896 static bool run_randomipc(int dummy
)
2898 char *rparam
= NULL
;
2900 unsigned int rdrcnt
,rprcnt
;
2902 int api
, param_len
, i
;
2903 struct cli_state
*cli
;
2904 bool correct
= True
;
2907 printf("starting random ipc test\n");
2909 if (!torture_open_connection(&cli
, 0)) {
2913 for (i
=0;i
<count
;i
++) {
2914 api
= sys_random() % 500;
2915 param_len
= (sys_random() % 64);
2917 rand_buf(param
, param_len
);
2922 param
, param_len
, 8,
2923 NULL
, 0, BUFFER_SIZE
,
2927 printf("%d/%d\r", i
,count
);
2930 printf("%d/%d\n", i
, count
);
2932 if (!torture_close_connection(cli
)) {
2936 printf("finished random ipc test\n");
2943 static void browse_callback(const char *sname
, uint32 stype
,
2944 const char *comment
, void *state
)
2946 printf("\t%20.20s %08x %s\n", sname
, stype
, comment
);
2952 This test checks the browse list code
2955 static bool run_browsetest(int dummy
)
2957 static struct cli_state
*cli
;
2958 bool correct
= True
;
2960 printf("starting browse test\n");
2962 if (!torture_open_connection(&cli
, 0)) {
2966 printf("domain list:\n");
2967 cli_NetServerEnum(cli
, cli
->server_domain
,
2968 SV_TYPE_DOMAIN_ENUM
,
2969 browse_callback
, NULL
);
2971 printf("machine list:\n");
2972 cli_NetServerEnum(cli
, cli
->server_domain
,
2974 browse_callback
, NULL
);
2976 if (!torture_close_connection(cli
)) {
2980 printf("browse test finished\n");
2988 This checks how the getatr calls works
2990 static bool run_attrtest(int dummy
)
2992 struct cli_state
*cli
;
2995 const char *fname
= "\\attrib123456789.tst";
2996 bool correct
= True
;
2998 printf("starting attrib test\n");
3000 if (!torture_open_connection(&cli
, 0)) {
3004 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3005 cli_open(cli
, fname
,
3006 O_RDWR
| O_CREAT
| O_TRUNC
, DENY_NONE
, &fnum
);
3007 cli_close(cli
, fnum
);
3008 if (!NT_STATUS_IS_OK(cli_getatr(cli
, fname
, NULL
, NULL
, &t
))) {
3009 printf("getatr failed (%s)\n", cli_errstr(cli
));
3013 if (abs(t
- time(NULL
)) > 60*60*24*10) {
3014 printf("ERROR: SMBgetatr bug. time is %s",
3020 t2
= t
-60*60*24; /* 1 day ago */
3022 if (!NT_STATUS_IS_OK(cli_setatr(cli
, fname
, 0, t2
))) {
3023 printf("setatr failed (%s)\n", cli_errstr(cli
));
3027 if (!NT_STATUS_IS_OK(cli_getatr(cli
, fname
, NULL
, NULL
, &t
))) {
3028 printf("getatr failed (%s)\n", cli_errstr(cli
));
3033 printf("ERROR: getatr/setatr bug. times are\n%s",
3035 printf("%s", ctime(&t2
));
3039 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3041 if (!torture_close_connection(cli
)) {
3045 printf("attrib test finished\n");
3052 This checks a couple of trans2 calls
3054 static bool run_trans2test(int dummy
)
3056 struct cli_state
*cli
;
3059 time_t c_time
, a_time
, m_time
;
3060 struct timespec c_time_ts
, a_time_ts
, m_time_ts
, w_time_ts
, m_time2_ts
;
3061 const char *fname
= "\\trans2.tst";
3062 const char *dname
= "\\trans2";
3063 const char *fname2
= "\\trans2\\trans2.tst";
3065 bool correct
= True
;
3069 printf("starting trans2 test\n");
3071 if (!torture_open_connection(&cli
, 0)) {
3075 status
= cli_get_fs_attr_info(cli
, &fs_attr
);
3076 if (!NT_STATUS_IS_OK(status
)) {
3077 printf("ERROR: cli_get_fs_attr_info returned %s\n",
3082 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3083 cli_open(cli
, fname
,
3084 O_RDWR
| O_CREAT
| O_TRUNC
, DENY_NONE
, &fnum
);
3085 if (!NT_STATUS_IS_OK(cli_qfileinfo_basic(
3086 cli
, fnum
, NULL
, &size
, &c_time_ts
,
3087 &a_time_ts
, &w_time_ts
,
3088 &m_time_ts
, NULL
))) {
3089 printf("ERROR: qfileinfo failed (%s)\n", cli_errstr(cli
));
3093 if (!NT_STATUS_IS_OK(cli_qfilename(cli
, fnum
, pname
, sizeof(pname
)))) {
3094 printf("ERROR: qfilename failed (%s)\n", cli_errstr(cli
));
3098 if (strcmp(pname
, fname
)) {
3099 printf("qfilename gave different name? [%s] [%s]\n",
3104 cli_close(cli
, fnum
);
3108 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3109 if (!NT_STATUS_IS_OK(cli_open(cli
, fname
,
3110 O_RDWR
| O_CREAT
| O_TRUNC
, DENY_NONE
, &fnum
))) {
3111 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli
));
3114 cli_close(cli
, fnum
);
3116 status
= cli_qpathinfo1(cli
, fname
, &c_time
, &a_time
, &m_time
, &size
,
3118 if (!NT_STATUS_IS_OK(status
)) {
3119 printf("ERROR: qpathinfo failed (%s)\n", nt_errstr(status
));
3122 if (c_time
!= m_time
) {
3123 printf("create time=%s", ctime(&c_time
));
3124 printf("modify time=%s", ctime(&m_time
));
3125 printf("This system appears to have sticky create times\n");
3127 if (a_time
% (60*60) == 0) {
3128 printf("access time=%s", ctime(&a_time
));
3129 printf("This system appears to set a midnight access time\n");
3133 if (abs(m_time
- time(NULL
)) > 60*60*24*7) {
3134 printf("ERROR: totally incorrect times - maybe word reversed? mtime=%s", ctime(&m_time
));
3140 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3141 cli_open(cli
, fname
,
3142 O_RDWR
| O_CREAT
| O_TRUNC
, DENY_NONE
, &fnum
);
3143 cli_close(cli
, fnum
);
3144 status
= cli_qpathinfo2(cli
, fname
, &c_time_ts
, &a_time_ts
, &w_time_ts
,
3145 &m_time_ts
, &size
, NULL
, NULL
);
3146 if (!NT_STATUS_IS_OK(status
)) {
3147 printf("ERROR: qpathinfo2 failed (%s)\n", nt_errstr(status
));
3150 if (w_time_ts
.tv_sec
< 60*60*24*2) {
3151 printf("write time=%s", ctime(&w_time_ts
.tv_sec
));
3152 printf("This system appears to set a initial 0 write time\n");
3157 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3160 /* check if the server updates the directory modification time
3161 when creating a new file */
3162 if (!NT_STATUS_IS_OK(cli_mkdir(cli
, dname
))) {
3163 printf("ERROR: mkdir failed (%s)\n", cli_errstr(cli
));
3167 status
= cli_qpathinfo2(cli
, "\\trans2\\", &c_time_ts
, &a_time_ts
,
3168 &w_time_ts
, &m_time_ts
, &size
, NULL
, NULL
);
3169 if (!NT_STATUS_IS_OK(status
)) {
3170 printf("ERROR: qpathinfo2 failed (%s)\n", nt_errstr(status
));
3174 cli_open(cli
, fname2
,
3175 O_RDWR
| O_CREAT
| O_TRUNC
, DENY_NONE
, &fnum
);
3176 cli_writeall(cli
, fnum
, 0, (uint8_t *)&fnum
, 0, sizeof(fnum
), NULL
);
3177 cli_close(cli
, fnum
);
3178 status
= cli_qpathinfo2(cli
, "\\trans2\\", &c_time_ts
, &a_time_ts
,
3179 &w_time_ts
, &m_time2_ts
, &size
, NULL
, NULL
);
3180 if (!NT_STATUS_IS_OK(status
)) {
3181 printf("ERROR: qpathinfo2 failed (%s)\n", nt_errstr(status
));
3184 if (memcmp(&m_time_ts
, &m_time2_ts
, sizeof(struct timespec
))
3186 printf("This system does not update directory modification times\n");
3190 cli_unlink(cli
, fname2
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3191 cli_rmdir(cli
, dname
);
3193 if (!torture_close_connection(cli
)) {
3197 printf("trans2 test finished\n");
3203 This checks new W2K calls.
3206 static NTSTATUS
new_trans(struct cli_state
*pcli
, int fnum
, int level
)
3208 uint8_t *buf
= NULL
;
3212 status
= cli_qfileinfo(talloc_tos(), pcli
, fnum
, level
, 0,
3213 pcli
->max_xmit
, &buf
, &len
);
3214 if (!NT_STATUS_IS_OK(status
)) {
3215 printf("ERROR: qfileinfo (%d) failed (%s)\n", level
,
3218 printf("qfileinfo: level %d, len = %u\n", level
, len
);
3219 dump_data(0, (uint8
*)buf
, len
);
3226 static bool run_w2ktest(int dummy
)
3228 struct cli_state
*cli
;
3230 const char *fname
= "\\w2ktest\\w2k.tst";
3232 bool correct
= True
;
3234 printf("starting w2k test\n");
3236 if (!torture_open_connection(&cli
, 0)) {
3240 cli_open(cli
, fname
,
3241 O_RDWR
| O_CREAT
, DENY_NONE
, &fnum
);
3243 for (level
= 1004; level
< 1040; level
++) {
3244 new_trans(cli
, fnum
, level
);
3247 cli_close(cli
, fnum
);
3249 if (!torture_close_connection(cli
)) {
3253 printf("w2k test finished\n");
3260 this is a harness for some oplock tests
3262 static bool run_oplock1(int dummy
)
3264 struct cli_state
*cli1
;
3265 const char *fname
= "\\lockt1.lck";
3267 bool correct
= True
;
3269 printf("starting oplock test 1\n");
3271 if (!torture_open_connection(&cli1
, 0)) {
3275 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3277 cli_sockopt(cli1
, sockops
);
3279 cli1
->use_oplocks
= True
;
3281 if (!NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
))) {
3282 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3286 cli1
->use_oplocks
= False
;
3288 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3289 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3291 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3292 printf("close2 failed (%s)\n", cli_errstr(cli1
));
3296 if (!NT_STATUS_IS_OK(cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
))) {
3297 printf("unlink failed (%s)\n", cli_errstr(cli1
));
3301 if (!torture_close_connection(cli1
)) {
3305 printf("finished oplock test 1\n");
3310 static bool run_oplock2(int dummy
)
3312 struct cli_state
*cli1
, *cli2
;
3313 const char *fname
= "\\lockt2.lck";
3314 uint16_t fnum1
, fnum2
;
3315 int saved_use_oplocks
= use_oplocks
;
3317 bool correct
= True
;
3318 volatile bool *shared_correct
;
3320 shared_correct
= (volatile bool *)shm_setup(sizeof(bool));
3321 *shared_correct
= True
;
3323 use_level_II_oplocks
= True
;
3326 printf("starting oplock test 2\n");
3328 if (!torture_open_connection(&cli1
, 0)) {
3329 use_level_II_oplocks
= False
;
3330 use_oplocks
= saved_use_oplocks
;
3334 cli1
->use_oplocks
= True
;
3335 cli1
->use_level_II_oplocks
= True
;
3337 if (!torture_open_connection(&cli2
, 1)) {
3338 use_level_II_oplocks
= False
;
3339 use_oplocks
= saved_use_oplocks
;
3343 cli2
->use_oplocks
= True
;
3344 cli2
->use_level_II_oplocks
= True
;
3346 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3348 cli_sockopt(cli1
, sockops
);
3349 cli_sockopt(cli2
, sockops
);
3351 if (!NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
))) {
3352 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3356 /* Don't need the globals any more. */
3357 use_level_II_oplocks
= False
;
3358 use_oplocks
= saved_use_oplocks
;
3362 if (!NT_STATUS_IS_OK(cli_open(cli2
, fname
, O_RDWR
, DENY_NONE
, &fnum2
))) {
3363 printf("second open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3364 *shared_correct
= False
;
3370 if (!NT_STATUS_IS_OK(cli_close(cli2
, fnum2
))) {
3371 printf("close2 failed (%s)\n", cli_errstr(cli1
));
3372 *shared_correct
= False
;
3380 /* Ensure cli1 processes the break. Empty file should always return 0
3383 if (cli_read(cli1
, fnum1
, buf
, 0, 4) != 0) {
3384 printf("read on fnum1 failed (%s)\n", cli_errstr(cli1
));
3388 /* Should now be at level II. */
3389 /* Test if sending a write locks causes a break to none. */
3391 if (!cli_lock(cli1
, fnum1
, 0, 4, 0, READ_LOCK
)) {
3392 printf("lock failed (%s)\n", cli_errstr(cli1
));
3396 cli_unlock(cli1
, fnum1
, 0, 4);
3400 if (!cli_lock(cli1
, fnum1
, 0, 4, 0, WRITE_LOCK
)) {
3401 printf("lock failed (%s)\n", cli_errstr(cli1
));
3405 cli_unlock(cli1
, fnum1
, 0, 4);
3409 cli_read(cli1
, fnum1
, buf
, 0, 4);
3411 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3412 printf("close1 failed (%s)\n", cli_errstr(cli1
));
3418 if (!NT_STATUS_IS_OK(cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
))) {
3419 printf("unlink failed (%s)\n", cli_errstr(cli1
));
3423 if (!torture_close_connection(cli1
)) {
3427 if (!*shared_correct
) {
3431 printf("finished oplock test 2\n");
3436 /* handler for oplock 3 tests */
3437 static NTSTATUS
oplock3_handler(struct cli_state
*cli
, uint16_t fnum
, unsigned char level
)
3439 printf("got oplock break fnum=%d level=%d\n",
3441 return cli_oplock_ack(cli
, fnum
, level
);
3444 static bool run_oplock3(int dummy
)
3446 struct cli_state
*cli
;
3447 const char *fname
= "\\oplockt3.dat";
3449 char buf
[4] = "abcd";
3450 bool correct
= True
;
3451 volatile bool *shared_correct
;
3453 shared_correct
= (volatile bool *)shm_setup(sizeof(bool));
3454 *shared_correct
= True
;
3456 printf("starting oplock test 3\n");
3461 use_level_II_oplocks
= True
;
3462 if (!torture_open_connection(&cli
, 0)) {
3463 *shared_correct
= False
;
3467 /* try to trigger a oplock break in parent */
3468 cli_open(cli
, fname
, O_RDWR
, DENY_NONE
, &fnum
);
3469 cli_writeall(cli
, fnum
, 0, (uint8_t *)buf
, 0, 4, NULL
);
3475 use_level_II_oplocks
= True
;
3476 if (!torture_open_connection(&cli
, 1)) { /* other is forked */
3479 cli_oplock_handler(cli
, oplock3_handler
);
3480 cli_open(cli
, fname
, O_RDWR
|O_CREAT
, DENY_NONE
, &fnum
);
3481 cli_writeall(cli
, fnum
, 0, (uint8_t *)buf
, 0, 4, NULL
);
3482 cli_close(cli
, fnum
);
3483 cli_open(cli
, fname
, O_RDWR
, DENY_NONE
, &fnum
);
3484 cli
->timeout
= 20000;
3485 cli_receive_smb(cli
);
3486 printf("finished oplock test 3\n");
3488 return (correct
&& *shared_correct
);
3490 /* What are we looking for here? What's sucess and what's FAILURE? */
3493 /* handler for oplock 4 tests */
3494 bool *oplock4_shared_correct
;
3496 static NTSTATUS
oplock4_handler(struct cli_state
*cli
, uint16_t fnum
, unsigned char level
)
3498 printf("got oplock break fnum=%d level=%d\n",
3500 *oplock4_shared_correct
= true;
3501 cli_oplock_ack(cli
, fnum
, level
);
3502 return NT_STATUS_UNSUCCESSFUL
; /* Cause cli_receive_smb to return. */
3505 static bool run_oplock4(int dummy
)
3507 struct cli_state
*cli1
, *cli2
;
3508 const char *fname
= "\\lockt4.lck";
3509 const char *fname_ln
= "\\lockt4_ln.lck";
3510 uint16_t fnum1
, fnum2
;
3511 int saved_use_oplocks
= use_oplocks
;
3513 bool correct
= true;
3515 oplock4_shared_correct
= (bool *)shm_setup(sizeof(bool));
3516 *oplock4_shared_correct
= false;
3518 printf("starting oplock test 4\n");
3520 if (!torture_open_connection(&cli1
, 0)) {
3521 use_level_II_oplocks
= false;
3522 use_oplocks
= saved_use_oplocks
;
3526 if (!torture_open_connection(&cli2
, 1)) {
3527 use_level_II_oplocks
= false;
3528 use_oplocks
= saved_use_oplocks
;
3532 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3533 cli_unlink(cli1
, fname_ln
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3535 cli_sockopt(cli1
, sockops
);
3536 cli_sockopt(cli2
, sockops
);
3538 /* Create the file. */
3539 if (!NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
))) {
3540 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3544 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3545 printf("close1 failed (%s)\n", cli_errstr(cli1
));
3549 /* Now create a hardlink. */
3550 if (!NT_STATUS_IS_OK(cli_nt_hardlink(cli1
, fname
, fname_ln
))) {
3551 printf("nt hardlink failed (%s)\n", cli_errstr(cli1
));
3555 /* Prove that opening hardlinks cause deny modes to conflict. */
3556 if (!NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDWR
, DENY_ALL
, &fnum1
))) {
3557 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3561 status
= cli_open(cli1
, fname_ln
, O_RDWR
, DENY_NONE
, &fnum2
);
3562 if (NT_STATUS_IS_OK(status
)) {
3563 printf("open of %s succeeded - should fail with sharing violation.\n",
3568 if (!NT_STATUS_EQUAL(status
, NT_STATUS_SHARING_VIOLATION
)) {
3569 printf("open of %s should fail with sharing violation. Got %s\n",
3570 fname_ln
, nt_errstr(status
));
3574 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3575 printf("close1 failed (%s)\n", cli_errstr(cli1
));
3579 cli1
->use_oplocks
= true;
3580 cli1
->use_level_II_oplocks
= true;
3582 cli2
->use_oplocks
= true;
3583 cli2
->use_level_II_oplocks
= true;
3585 cli_oplock_handler(cli1
, oplock4_handler
);
3586 if (!NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
, &fnum1
))) {
3587 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3593 if (!NT_STATUS_IS_OK(cli_open(cli2
, fname_ln
, O_RDWR
, DENY_NONE
, &fnum2
))) {
3594 printf("open of %s failed (%s)\n", fname_ln
, cli_errstr(cli1
));
3595 *oplock4_shared_correct
= false;
3599 if (!NT_STATUS_IS_OK(cli_close(cli2
, fnum2
))) {
3600 printf("close2 failed (%s)\n", cli_errstr(cli1
));
3601 *oplock4_shared_correct
= false;
3609 /* Process the oplock break. */
3610 cli_receive_smb(cli1
);
3612 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3613 printf("close1 failed (%s)\n", cli_errstr(cli1
));
3617 if (!NT_STATUS_IS_OK(cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
))) {
3618 printf("unlink failed (%s)\n", cli_errstr(cli1
));
3621 if (!NT_STATUS_IS_OK(cli_unlink(cli1
, fname_ln
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
))) {
3622 printf("unlink failed (%s)\n", cli_errstr(cli1
));
3626 if (!torture_close_connection(cli1
)) {
3630 if (!*oplock4_shared_correct
) {
3634 printf("finished oplock test 4\n");
3641 Test delete on close semantics.
3643 static bool run_deletetest(int dummy
)
3645 struct cli_state
*cli1
= NULL
;
3646 struct cli_state
*cli2
= NULL
;
3647 const char *fname
= "\\delete.file";
3648 uint16_t fnum1
= (uint16_t)-1;
3649 uint16_t fnum2
= (uint16_t)-1;
3650 bool correct
= True
;
3652 printf("starting delete test\n");
3654 if (!torture_open_connection(&cli1
, 0)) {
3658 cli_sockopt(cli1
, sockops
);
3660 /* Test 1 - this should delete the file on close. */
3662 cli_setatr(cli1
, fname
, 0, 0);
3663 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3665 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, GENERIC_ALL_ACCESS
|DELETE_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
3666 0, FILE_OVERWRITE_IF
,
3667 FILE_DELETE_ON_CLOSE
, 0, &fnum1
))) {
3668 printf("[1] open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3673 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3674 printf("[1] close failed (%s)\n", cli_errstr(cli1
));
3679 if (NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
, &fnum1
))) {
3680 printf("[1] open of %s succeeded (should fail)\n", fname
);
3685 printf("first delete on close test succeeded.\n");
3687 /* Test 2 - this should delete the file on close. */
3689 cli_setatr(cli1
, fname
, 0, 0);
3690 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3692 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, GENERIC_ALL_ACCESS
,
3693 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_NONE
,
3694 FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
3695 printf("[2] open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3700 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1
, fnum1
, true))) {
3701 printf("[2] setting delete_on_close failed (%s)\n", cli_errstr(cli1
));
3706 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3707 printf("[2] close failed (%s)\n", cli_errstr(cli1
));
3712 if (NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDONLY
, DENY_NONE
, &fnum1
))) {
3713 printf("[2] open of %s succeeded should have been deleted on close !\n", fname
);
3714 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3715 printf("[2] close failed (%s)\n", cli_errstr(cli1
));
3719 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3721 printf("second delete on close test succeeded.\n");
3724 cli_setatr(cli1
, fname
, 0, 0);
3725 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3727 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, GENERIC_ALL_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
3728 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
3729 printf("[3] open - 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3734 /* This should fail with a sharing violation - open for delete is only compatible
3735 with SHARE_DELETE. */
3737 if (NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, GENERIC_READ_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
3738 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OPEN
, 0, 0, &fnum2
))) {
3739 printf("[3] open - 2 of %s succeeded - should have failed.\n", fname
);
3744 /* This should succeed. */
3746 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, GENERIC_READ_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
3747 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, FILE_OPEN
, 0, 0, &fnum2
))) {
3748 printf("[3] open - 2 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3753 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1
, fnum1
, true))) {
3754 printf("[3] setting delete_on_close failed (%s)\n", cli_errstr(cli1
));
3759 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3760 printf("[3] close 1 failed (%s)\n", cli_errstr(cli1
));
3765 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum2
))) {
3766 printf("[3] close 2 failed (%s)\n", cli_errstr(cli1
));
3771 /* This should fail - file should no longer be there. */
3773 if (NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDONLY
, DENY_NONE
, &fnum1
))) {
3774 printf("[3] open of %s succeeded should have been deleted on close !\n", fname
);
3775 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3776 printf("[3] close failed (%s)\n", cli_errstr(cli1
));
3778 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3782 printf("third delete on close test succeeded.\n");
3785 cli_setatr(cli1
, fname
, 0, 0);
3786 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3788 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, FILE_READ_DATA
|FILE_WRITE_DATA
|DELETE_ACCESS
,
3789 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
3790 printf("[4] open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3795 /* This should succeed. */
3796 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, GENERIC_READ_ACCESS
,
3797 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, FILE_OPEN
, 0, 0, &fnum2
))) {
3798 printf("[4] open - 2 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3803 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum2
))) {
3804 printf("[4] close - 1 failed (%s)\n", cli_errstr(cli1
));
3809 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1
, fnum1
, true))) {
3810 printf("[4] setting delete_on_close failed (%s)\n", cli_errstr(cli1
));
3815 /* This should fail - no more opens once delete on close set. */
3816 if (NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, GENERIC_READ_ACCESS
,
3817 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
3818 FILE_OPEN
, 0, 0, &fnum2
))) {
3819 printf("[4] open - 3 of %s succeeded ! Should have failed.\n", fname
);
3823 printf("fourth delete on close test succeeded.\n");
3825 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3826 printf("[4] close - 2 failed (%s)\n", cli_errstr(cli1
));
3832 cli_setatr(cli1
, fname
, 0, 0);
3833 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3835 if (!NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDWR
|O_CREAT
, DENY_NONE
, &fnum1
))) {
3836 printf("[5] open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3841 /* This should fail - only allowed on NT opens with DELETE access. */
3843 if (NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1
, fnum1
, true))) {
3844 printf("[5] setting delete_on_close on OpenX file succeeded - should fail !\n");
3849 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3850 printf("[5] close - 2 failed (%s)\n", cli_errstr(cli1
));
3855 printf("fifth delete on close test succeeded.\n");
3858 cli_setatr(cli1
, fname
, 0, 0);
3859 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3861 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, FILE_READ_DATA
|FILE_WRITE_DATA
,
3862 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
3863 FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
3864 printf("[6] open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3869 /* This should fail - only allowed on NT opens with DELETE access. */
3871 if (NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1
, fnum1
, true))) {
3872 printf("[6] setting delete_on_close on file with no delete access succeeded - should fail !\n");
3877 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3878 printf("[6] close - 2 failed (%s)\n", cli_errstr(cli1
));
3883 printf("sixth delete on close test succeeded.\n");
3886 cli_setatr(cli1
, fname
, 0, 0);
3887 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3889 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, FILE_READ_DATA
|FILE_WRITE_DATA
|DELETE_ACCESS
,
3890 FILE_ATTRIBUTE_NORMAL
, 0, FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
3891 printf("[7] open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3896 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1
, fnum1
, true))) {
3897 printf("[7] setting delete_on_close on file failed !\n");
3902 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1
, fnum1
, false))) {
3903 printf("[7] unsetting delete_on_close on file failed !\n");
3908 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3909 printf("[7] close - 2 failed (%s)\n", cli_errstr(cli1
));
3914 /* This next open should succeed - we reset the flag. */
3916 if (!NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDONLY
, DENY_NONE
, &fnum1
))) {
3917 printf("[5] open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3922 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3923 printf("[7] close - 2 failed (%s)\n", cli_errstr(cli1
));
3928 printf("seventh delete on close test succeeded.\n");
3931 cli_setatr(cli1
, fname
, 0, 0);
3932 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3934 if (!torture_open_connection(&cli2
, 1)) {
3935 printf("[8] failed to open second connection.\n");
3940 cli_sockopt(cli1
, sockops
);
3942 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, FILE_READ_DATA
|FILE_WRITE_DATA
|DELETE_ACCESS
,
3943 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
3944 FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
3945 printf("[8] open 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3950 if (!NT_STATUS_IS_OK(cli_ntcreate(cli2
, fname
, 0, FILE_READ_DATA
|FILE_WRITE_DATA
|DELETE_ACCESS
,
3951 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
3952 FILE_OPEN
, 0, 0, &fnum2
))) {
3953 printf("[8] open 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
3958 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1
, fnum1
, true))) {
3959 printf("[8] setting delete_on_close on file failed !\n");
3964 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3965 printf("[8] close - 1 failed (%s)\n", cli_errstr(cli1
));
3970 if (!NT_STATUS_IS_OK(cli_close(cli2
, fnum2
))) {
3971 printf("[8] close - 2 failed (%s)\n", cli_errstr(cli2
));
3976 /* This should fail.. */
3977 if (NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDONLY
, DENY_NONE
, &fnum1
))) {
3978 printf("[8] open of %s succeeded should have been deleted on close !\n", fname
);
3982 printf("eighth delete on close test succeeded.\n");
3984 /* This should fail - we need to set DELETE_ACCESS. */
3985 if (NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0,FILE_READ_DATA
|FILE_WRITE_DATA
,
3986 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, FILE_DELETE_ON_CLOSE
, 0, &fnum1
))) {
3987 printf("[9] open of %s succeeded should have failed!\n", fname
);
3992 printf("ninth delete on close test succeeded.\n");
3994 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, FILE_READ_DATA
|FILE_WRITE_DATA
|DELETE_ACCESS
,
3995 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, FILE_DELETE_ON_CLOSE
, 0, &fnum1
))) {
3996 printf("[10] open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4001 /* This should delete the file. */
4002 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4003 printf("[10] close failed (%s)\n", cli_errstr(cli1
));
4008 /* This should fail.. */
4009 if (NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDONLY
, DENY_NONE
, &fnum1
))) {
4010 printf("[10] open of %s succeeded should have been deleted on close !\n", fname
);
4014 printf("tenth delete on close test succeeded.\n");
4016 cli_setatr(cli1
, fname
, 0, 0);
4017 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4019 /* What error do we get when attempting to open a read-only file with
4022 /* Create a readonly file. */
4023 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, FILE_READ_DATA
|FILE_WRITE_DATA
,
4024 FILE_ATTRIBUTE_READONLY
, FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
4025 printf("[11] open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4030 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4031 printf("[11] close failed (%s)\n", cli_errstr(cli1
));
4036 /* Now try open for delete access. */
4037 if (NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, FILE_READ_ATTRIBUTES
|DELETE_ACCESS
,
4038 0, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
4039 FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
4040 printf("[11] open of %s succeeded should have been denied with ACCESS_DENIED!\n", fname
);
4041 cli_close(cli1
, fnum1
);
4045 NTSTATUS nterr
= cli_nt_error(cli1
);
4046 if (!NT_STATUS_EQUAL(nterr
,NT_STATUS_ACCESS_DENIED
)) {
4047 printf("[11] open of %s should have been denied with ACCESS_DENIED! Got error %s\n", fname
, nt_errstr(nterr
));
4051 printf("eleventh delete on close test succeeded.\n");
4055 printf("finished delete test\n");
4058 /* FIXME: This will crash if we aborted before cli2 got
4059 * intialized, because these functions don't handle
4060 * uninitialized connections. */
4062 if (fnum1
!= (uint16_t)-1) cli_close(cli1
, fnum1
);
4063 if (fnum2
!= (uint16_t)-1) cli_close(cli1
, fnum2
);
4064 cli_setatr(cli1
, fname
, 0, 0);
4065 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4067 if (cli1
&& !torture_close_connection(cli1
)) {
4070 if (cli2
&& !torture_close_connection(cli2
)) {
4076 static bool run_deletetest_ln(int dummy
)
4078 struct cli_state
*cli
;
4079 const char *fname
= "\\delete1";
4080 const char *fname_ln
= "\\delete1_ln";
4084 bool correct
= true;
4087 printf("starting deletetest-ln\n");
4089 if (!torture_open_connection(&cli
, 0)) {
4093 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4094 cli_unlink(cli
, fname_ln
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4096 cli_sockopt(cli
, sockops
);
4098 /* Create the file. */
4099 if (!NT_STATUS_IS_OK(cli_open(cli
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum
))) {
4100 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli
));
4104 if (!NT_STATUS_IS_OK(cli_close(cli
, fnum
))) {
4105 printf("close1 failed (%s)\n", cli_errstr(cli
));
4109 /* Now create a hardlink. */
4110 if (!NT_STATUS_IS_OK(cli_nt_hardlink(cli
, fname
, fname_ln
))) {
4111 printf("nt hardlink failed (%s)\n", cli_errstr(cli
));
4115 /* Open the original file. */
4116 status
= cli_ntcreate(cli
, fname
, 0, FILE_READ_DATA
,
4117 FILE_ATTRIBUTE_NORMAL
,
4118 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
4119 FILE_OPEN_IF
, 0, 0, &fnum
);
4120 if (!NT_STATUS_IS_OK(status
)) {
4121 printf("ntcreate of %s failed (%s)\n", fname
, nt_errstr(status
));
4125 /* Unlink the hard link path. */
4126 status
= cli_ntcreate(cli
, fname_ln
, 0, DELETE_ACCESS
,
4127 FILE_ATTRIBUTE_NORMAL
,
4128 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
4129 FILE_OPEN_IF
, 0, 0, &fnum1
);
4130 if (!NT_STATUS_IS_OK(status
)) {
4131 printf("ntcreate of %s failed (%s)\n", fname_ln
, nt_errstr(status
));
4134 status
= cli_nt_delete_on_close(cli
, fnum1
, true);
4135 if (!NT_STATUS_IS_OK(status
)) {
4136 d_printf("(%s) failed to set delete_on_close %s: %s\n",
4137 __location__
, fname_ln
, nt_errstr(status
));
4141 status
= cli_close(cli
, fnum1
);
4142 if (!NT_STATUS_IS_OK(status
)) {
4143 printf("close %s failed (%s)\n",
4144 fname_ln
, nt_errstr(status
));
4148 status
= cli_close(cli
, fnum
);
4149 if (!NT_STATUS_IS_OK(status
)) {
4150 printf("close %s failed (%s)\n",
4151 fname
, nt_errstr(status
));
4155 /* Ensure the original file is still there. */
4156 status
= cli_getatr(cli
, fname
, NULL
, NULL
, &t
);
4157 if (!NT_STATUS_IS_OK(status
)) {
4158 printf("%s getatr on file %s failed (%s)\n",
4165 /* Ensure the link path is gone. */
4166 status
= cli_getatr(cli
, fname_ln
, NULL
, NULL
, &t
);
4167 if (!NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
)) {
4168 printf("%s, getatr for file %s returned wrong error code %s "
4169 "- should have been deleted\n",
4171 fname_ln
, nt_errstr(status
));
4175 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4176 cli_unlink(cli
, fname_ln
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4178 if (!torture_close_connection(cli
)) {
4182 printf("finished deletetest-ln\n");
4188 print out server properties
4190 static bool run_properties(int dummy
)
4192 struct cli_state
*cli
;
4193 bool correct
= True
;
4195 printf("starting properties test\n");
4199 if (!torture_open_connection(&cli
, 0)) {
4203 cli_sockopt(cli
, sockops
);
4205 d_printf("Capabilities 0x%08x\n", cli
->capabilities
);
4207 if (!torture_close_connection(cli
)) {
4216 /* FIRST_DESIRED_ACCESS 0xf019f */
4217 #define FIRST_DESIRED_ACCESS FILE_READ_DATA|FILE_WRITE_DATA|FILE_APPEND_DATA|\
4218 FILE_READ_EA| /* 0xf */ \
4219 FILE_WRITE_EA|FILE_READ_ATTRIBUTES| /* 0x90 */ \
4220 FILE_WRITE_ATTRIBUTES| /* 0x100 */ \
4221 DELETE_ACCESS|READ_CONTROL_ACCESS|\
4222 WRITE_DAC_ACCESS|WRITE_OWNER_ACCESS /* 0xf0000 */
4223 /* SECOND_DESIRED_ACCESS 0xe0080 */
4224 #define SECOND_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
4225 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
4226 WRITE_OWNER_ACCESS /* 0xe0000 */
4229 #define THIRD_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
4230 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
4232 WRITE_OWNER_ACCESS /* */
4236 Test ntcreate calls made by xcopy
4238 static bool run_xcopy(int dummy
)
4240 static struct cli_state
*cli1
;
4241 const char *fname
= "\\test.txt";
4242 bool correct
= True
;
4243 uint16_t fnum1
, fnum2
;
4245 printf("starting xcopy test\n");
4247 if (!torture_open_connection(&cli1
, 0)) {
4251 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0,
4252 FIRST_DESIRED_ACCESS
, FILE_ATTRIBUTE_ARCHIVE
,
4253 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
,
4254 0x4044, 0, &fnum1
))) {
4255 printf("First open failed - %s\n", cli_errstr(cli1
));
4259 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0,
4260 SECOND_DESIRED_ACCESS
, 0,
4261 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, FILE_OPEN
,
4262 0x200000, 0, &fnum2
))) {
4263 printf("second open failed - %s\n", cli_errstr(cli1
));
4267 if (!torture_close_connection(cli1
)) {
4275 Test rename on files open with share delete and no share delete.
4277 static bool run_rename(int dummy
)
4279 static struct cli_state
*cli1
;
4280 const char *fname
= "\\test.txt";
4281 const char *fname1
= "\\test1.txt";
4282 bool correct
= True
;
4287 printf("starting rename test\n");
4289 if (!torture_open_connection(&cli1
, 0)) {
4293 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4294 cli_unlink(cli1
, fname1
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4295 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, GENERIC_READ_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
4296 FILE_SHARE_READ
, FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
4297 printf("First open failed - %s\n", cli_errstr(cli1
));
4301 if (!NT_STATUS_IS_OK(cli_rename(cli1
, fname
, fname1
))) {
4302 printf("First rename failed (SHARE_READ) (this is correct) - %s\n", cli_errstr(cli1
));
4304 printf("First rename succeeded (SHARE_READ) - this should have failed !\n");
4308 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4309 printf("close - 1 failed (%s)\n", cli_errstr(cli1
));
4313 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4314 cli_unlink(cli1
, fname1
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4315 status
= cli_ntcreate(cli1
, fname
, 0, GENERIC_READ_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
4317 FILE_SHARE_DELETE
|FILE_SHARE_NONE
,
4319 FILE_SHARE_DELETE
|FILE_SHARE_READ
,
4321 FILE_OVERWRITE_IF
, 0, 0, &fnum1
);
4322 if (!NT_STATUS_IS_OK(status
)) {
4323 printf("Second open failed - %s\n", cli_errstr(cli1
));
4327 if (!NT_STATUS_IS_OK(cli_rename(cli1
, fname
, fname1
))) {
4328 printf("Second rename failed (SHARE_DELETE | SHARE_READ) - this should have succeeded - %s\n", cli_errstr(cli1
));
4331 printf("Second rename succeeded (SHARE_DELETE | SHARE_READ)\n");
4334 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4335 printf("close - 2 failed (%s)\n", cli_errstr(cli1
));
4339 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4340 cli_unlink(cli1
, fname1
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4342 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, READ_CONTROL_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
4343 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
4344 printf("Third open failed - %s\n", cli_errstr(cli1
));
4353 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, DELETE_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
4354 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0, &fnum2
))) {
4355 printf("Fourth open failed - %s\n", cli_errstr(cli1
));
4358 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1
, fnum2
, true))) {
4359 printf("[8] setting delete_on_close on file failed !\n");
4363 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum2
))) {
4364 printf("close - 4 failed (%s)\n", cli_errstr(cli1
));
4370 if (!NT_STATUS_IS_OK(cli_rename(cli1
, fname
, fname1
))) {
4371 printf("Third rename failed (SHARE_NONE) - this should have succeeded - %s\n", cli_errstr(cli1
));
4374 printf("Third rename succeeded (SHARE_NONE)\n");
4377 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4378 printf("close - 3 failed (%s)\n", cli_errstr(cli1
));
4382 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4383 cli_unlink(cli1
, fname1
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4387 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, GENERIC_READ_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
4388 FILE_SHARE_READ
| FILE_SHARE_WRITE
, FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
4389 printf("Fourth open failed - %s\n", cli_errstr(cli1
));
4393 if (!NT_STATUS_IS_OK(cli_rename(cli1
, fname
, fname1
))) {
4394 printf("Fourth rename failed (SHARE_READ | SHARE_WRITE) (this is correct) - %s\n", cli_errstr(cli1
));
4396 printf("Fourth rename succeeded (SHARE_READ | SHARE_WRITE) - this should have failed !\n");
4400 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4401 printf("close - 4 failed (%s)\n", cli_errstr(cli1
));
4405 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4406 cli_unlink(cli1
, fname1
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4410 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, GENERIC_READ_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
4411 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
, FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
4412 printf("Fifth open failed - %s\n", cli_errstr(cli1
));
4416 if (!NT_STATUS_IS_OK(cli_rename(cli1
, fname
, fname1
))) {
4417 printf("Fifth rename failed (SHARE_READ | SHARE_WRITE | SHARE_DELETE) - this should have succeeded - %s ! \n",
4421 printf("Fifth rename succeeded (SHARE_READ | SHARE_WRITE | SHARE_DELETE) (this is correct) - %s\n", cli_errstr(cli1
));
4425 * Now check if the first name still exists ...
4428 /* if (!NT_STATUS_OP(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
4429 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0, 0, &fnum2))) {
4430 printf("Opening original file after rename of open file fails: %s\n",
4434 printf("Opening original file after rename of open file works ...\n");
4435 (void)cli_close(cli1, fnum2);
4439 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4440 printf("close - 5 failed (%s)\n", cli_errstr(cli1
));
4444 /* Check that the renamed file has FILE_ATTRIBUTE_ARCHIVE. */
4445 if (!NT_STATUS_IS_OK(cli_getatr(cli1
, fname1
, &attr
, NULL
, NULL
))) {
4446 printf("getatr on file %s failed - %s ! \n",
4451 if (attr
!= FILE_ATTRIBUTE_ARCHIVE
) {
4452 printf("Renamed file %s has wrong attr 0x%x "
4453 "(should be 0x%x)\n",
4456 (unsigned int)FILE_ATTRIBUTE_ARCHIVE
);
4459 printf("Renamed file %s has archive bit set\n", fname1
);
4463 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4464 cli_unlink(cli1
, fname1
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4466 if (!torture_close_connection(cli1
)) {
4473 static bool run_pipe_number(int dummy
)
4475 struct cli_state
*cli1
;
4476 const char *pipe_name
= "\\SPOOLSS";
4480 printf("starting pipenumber test\n");
4481 if (!torture_open_connection(&cli1
, 0)) {
4485 cli_sockopt(cli1
, sockops
);
4487 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, pipe_name
, 0, FILE_READ_DATA
, FILE_ATTRIBUTE_NORMAL
,
4488 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OPEN_IF
, 0, 0, &fnum
))) {
4489 printf("Open of pipe %s failed with error (%s)\n", pipe_name
, cli_errstr(cli1
));
4493 printf("\r%6d", num_pipes
);
4496 printf("pipe_number test - we can open %d %s pipes.\n", num_pipes
, pipe_name
);
4497 torture_close_connection(cli1
);
4502 Test open mode returns on read-only files.
4504 static bool run_opentest(int dummy
)
4506 static struct cli_state
*cli1
;
4507 static struct cli_state
*cli2
;
4508 const char *fname
= "\\readonly.file";
4509 uint16_t fnum1
, fnum2
;
4512 bool correct
= True
;
4516 printf("starting open test\n");
4518 if (!torture_open_connection(&cli1
, 0)) {
4522 cli_setatr(cli1
, fname
, 0, 0);
4523 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4525 cli_sockopt(cli1
, sockops
);
4527 if (!NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
))) {
4528 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4532 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4533 printf("close2 failed (%s)\n", cli_errstr(cli1
));
4537 if (!NT_STATUS_IS_OK(cli_setatr(cli1
, fname
, FILE_ATTRIBUTE_READONLY
, 0))) {
4538 printf("cli_setatr failed (%s)\n", cli_errstr(cli1
));
4542 if (!NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDONLY
, DENY_WRITE
, &fnum1
))) {
4543 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4547 /* This will fail - but the error should be ERRnoaccess, not ERRbadshare. */
4548 cli_open(cli1
, fname
, O_RDWR
, DENY_ALL
, &fnum2
);
4550 if (check_error(__LINE__
, cli1
, ERRDOS
, ERRnoaccess
,
4551 NT_STATUS_ACCESS_DENIED
)) {
4552 printf("correct error code ERRDOS/ERRnoaccess returned\n");
4555 printf("finished open test 1\n");
4557 cli_close(cli1
, fnum1
);
4559 /* Now try not readonly and ensure ERRbadshare is returned. */
4561 cli_setatr(cli1
, fname
, 0, 0);
4563 if (!NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDONLY
, DENY_WRITE
, &fnum1
))) {
4564 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4568 /* This will fail - but the error should be ERRshare. */
4569 cli_open(cli1
, fname
, O_RDWR
, DENY_ALL
, &fnum2
);
4571 if (check_error(__LINE__
, cli1
, ERRDOS
, ERRbadshare
,
4572 NT_STATUS_SHARING_VIOLATION
)) {
4573 printf("correct error code ERRDOS/ERRbadshare returned\n");
4576 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4577 printf("close2 failed (%s)\n", cli_errstr(cli1
));
4581 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4583 printf("finished open test 2\n");
4585 /* Test truncate open disposition on file opened for read. */
4587 if (!NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
))) {
4588 printf("(3) open (1) of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4592 /* write 20 bytes. */
4594 memset(buf
, '\0', 20);
4596 status
= cli_writeall(cli1
, fnum1
, 0, (uint8_t *)buf
, 0, 20, NULL
);
4597 if (!NT_STATUS_IS_OK(status
)) {
4598 printf("write failed (%s)\n", nt_errstr(status
));
4602 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4603 printf("(3) close1 failed (%s)\n", cli_errstr(cli1
));
4607 /* Ensure size == 20. */
4608 if (!NT_STATUS_IS_OK(cli_getatr(cli1
, fname
, NULL
, &fsize
, NULL
))) {
4609 printf("(3) getatr failed (%s)\n", cli_errstr(cli1
));
4614 printf("(3) file size != 20\n");
4618 /* Now test if we can truncate a file opened for readonly. */
4620 if (!NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDONLY
|O_TRUNC
, DENY_NONE
, &fnum1
))) {
4621 printf("(3) open (2) of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4625 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4626 printf("close2 failed (%s)\n", cli_errstr(cli1
));
4630 /* Ensure size == 0. */
4631 if (!NT_STATUS_IS_OK(cli_getatr(cli1
, fname
, NULL
, &fsize
, NULL
))) {
4632 printf("(3) getatr failed (%s)\n", cli_errstr(cli1
));
4637 printf("(3) file size != 0\n");
4640 printf("finished open test 3\n");
4642 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4644 printf("Do ctemp tests\n");
4645 if (!NT_STATUS_IS_OK(cli_ctemp(cli1
, talloc_tos(), "\\", &fnum1
, &tmp_path
))) {
4646 printf("ctemp failed (%s)\n", cli_errstr(cli1
));
4649 printf("ctemp gave path %s\n", tmp_path
);
4650 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4651 printf("close of temp failed (%s)\n", cli_errstr(cli1
));
4653 if (!NT_STATUS_IS_OK(cli_unlink(cli1
, tmp_path
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
))) {
4654 printf("unlink of temp failed (%s)\n", cli_errstr(cli1
));
4657 /* Test the non-io opens... */
4659 if (!torture_open_connection(&cli2
, 1)) {
4663 cli_setatr(cli2
, fname
, 0, 0);
4664 cli_unlink(cli2
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4666 cli_sockopt(cli2
, sockops
);
4668 printf("TEST #1 testing 2 non-io opens (no delete)\n");
4670 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
4671 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
4672 printf("TEST #1 open 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4676 if (!NT_STATUS_IS_OK(cli_ntcreate(cli2
, fname
, 0, FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
4677 FILE_SHARE_NONE
, FILE_OPEN_IF
, 0, 0, &fnum2
))) {
4678 printf("TEST #1 open 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
4682 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4683 printf("TEST #1 close 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4686 if (!NT_STATUS_IS_OK(cli_close(cli2
, fnum2
))) {
4687 printf("TEST #1 close 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
4691 printf("non-io open test #1 passed.\n");
4693 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4695 printf("TEST #2 testing 2 non-io opens (first with delete)\n");
4697 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, DELETE_ACCESS
|FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
4698 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
4699 printf("TEST #2 open 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4703 if (!NT_STATUS_IS_OK(cli_ntcreate(cli2
, fname
, 0, FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
4704 FILE_SHARE_NONE
, FILE_OPEN_IF
, 0, 0, &fnum2
))) {
4705 printf("TEST #2 open 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
4709 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4710 printf("TEST #2 close 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4713 if (!NT_STATUS_IS_OK(cli_close(cli2
, fnum2
))) {
4714 printf("TEST #2 close 2 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4718 printf("non-io open test #2 passed.\n");
4720 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4722 printf("TEST #3 testing 2 non-io opens (second with delete)\n");
4724 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
4725 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
4726 printf("TEST #3 open 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4730 if (!NT_STATUS_IS_OK(cli_ntcreate(cli2
, fname
, 0, DELETE_ACCESS
|FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
4731 FILE_SHARE_NONE
, FILE_OPEN_IF
, 0, 0, &fnum2
))) {
4732 printf("TEST #3 open 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
4736 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4737 printf("TEST #3 close 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4740 if (!NT_STATUS_IS_OK(cli_close(cli2
, fnum2
))) {
4741 printf("TEST #3 close 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
4745 printf("non-io open test #3 passed.\n");
4747 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4749 printf("TEST #4 testing 2 non-io opens (both with delete)\n");
4751 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, DELETE_ACCESS
|FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
4752 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
4753 printf("TEST #4 open 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4757 if (NT_STATUS_IS_OK(cli_ntcreate(cli2
, fname
, 0, DELETE_ACCESS
|FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
4758 FILE_SHARE_NONE
, FILE_OPEN_IF
, 0, 0, &fnum2
))) {
4759 printf("TEST #4 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname
, cli_errstr(cli2
));
4763 printf("TEST #4 open 2 of %s gave %s (correct error should be %s)\n", fname
, cli_errstr(cli2
), "sharing violation");
4765 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4766 printf("TEST #4 close 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4770 printf("non-io open test #4 passed.\n");
4772 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4774 printf("TEST #5 testing 2 non-io opens (both with delete - both with file share delete)\n");
4776 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, DELETE_ACCESS
|FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
4777 FILE_SHARE_DELETE
, FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
4778 printf("TEST #5 open 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4782 if (!NT_STATUS_IS_OK(cli_ntcreate(cli2
, fname
, 0, DELETE_ACCESS
|FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
4783 FILE_SHARE_DELETE
, FILE_OPEN_IF
, 0, 0, &fnum2
))) {
4784 printf("TEST #5 open 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
4788 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4789 printf("TEST #5 close 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4793 if (!NT_STATUS_IS_OK(cli_close(cli2
, fnum2
))) {
4794 printf("TEST #5 close 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
4798 printf("non-io open test #5 passed.\n");
4800 printf("TEST #6 testing 1 non-io open, one io open\n");
4802 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4804 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, FILE_READ_DATA
, FILE_ATTRIBUTE_NORMAL
,
4805 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
4806 printf("TEST #6 open 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4810 if (!NT_STATUS_IS_OK(cli_ntcreate(cli2
, fname
, 0, FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
4811 FILE_SHARE_READ
, FILE_OPEN_IF
, 0, 0, &fnum2
))) {
4812 printf("TEST #6 open 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
4816 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4817 printf("TEST #6 close 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4821 if (!NT_STATUS_IS_OK(cli_close(cli2
, fnum2
))) {
4822 printf("TEST #6 close 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
4826 printf("non-io open test #6 passed.\n");
4828 printf("TEST #7 testing 1 non-io open, one io open with delete\n");
4830 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4832 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, FILE_READ_DATA
, FILE_ATTRIBUTE_NORMAL
,
4833 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
4834 printf("TEST #7 open 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4838 if (NT_STATUS_IS_OK(cli_ntcreate(cli2
, fname
, 0, DELETE_ACCESS
|FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
4839 FILE_SHARE_READ
|FILE_SHARE_DELETE
, FILE_OPEN_IF
, 0, 0, &fnum2
))) {
4840 printf("TEST #7 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname
, cli_errstr(cli2
));
4844 printf("TEST #7 open 2 of %s gave %s (correct error should be %s)\n", fname
, cli_errstr(cli2
), "sharing violation");
4846 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4847 printf("TEST #7 close 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4851 printf("non-io open test #7 passed.\n");
4853 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4855 printf("TEST #8 testing open without WRITE_ATTRIBUTES, updating close write time.\n");
4856 status
= cli_ntcreate(cli1
, fname
, 0, FILE_WRITE_DATA
, FILE_ATTRIBUTE_NORMAL
,
4857 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
4858 FILE_OVERWRITE_IF
, 0, 0, &fnum1
);
4859 if (!NT_STATUS_IS_OK(status
)) {
4860 printf("TEST #8 open of %s failed (%s)\n", fname
, nt_errstr(status
));
4865 /* Write to ensure we have to update the file time. */
4866 status
= cli_writeall(cli1
, fnum1
, 0, (uint8_t *)"TEST DATA\n", 0, 10,
4868 if (!NT_STATUS_IS_OK(status
)) {
4869 printf("TEST #8 cli_write failed: %s\n", nt_errstr(status
));
4874 status
= cli_close(cli1
, fnum1
);
4875 if (!NT_STATUS_IS_OK(status
)) {
4876 printf("TEST #8 close of %s failed (%s)\n", fname
, nt_errstr(status
));
4882 if (!torture_close_connection(cli1
)) {
4885 if (!torture_close_connection(cli2
)) {
4892 NTSTATUS
torture_setup_unix_extensions(struct cli_state
*cli
)
4894 uint16 major
, minor
;
4895 uint32 caplow
, caphigh
;
4898 if (!SERVER_HAS_UNIX_CIFS(cli
)) {
4899 printf("Server doesn't support UNIX CIFS extensions.\n");
4900 return NT_STATUS_NOT_SUPPORTED
;
4903 status
= cli_unix_extensions_version(cli
, &major
, &minor
, &caplow
,
4905 if (!NT_STATUS_IS_OK(status
)) {
4906 printf("Server didn't return UNIX CIFS extensions: %s\n",
4911 status
= cli_set_unix_extensions_capabilities(cli
, major
, minor
,
4913 if (!NT_STATUS_IS_OK(status
)) {
4914 printf("Server doesn't support setting UNIX CIFS extensions: "
4915 "%s.\n", nt_errstr(status
));
4919 return NT_STATUS_OK
;
4923 Test POSIX open /mkdir calls.
4925 static bool run_simple_posix_open_test(int dummy
)
4927 static struct cli_state
*cli1
;
4928 const char *fname
= "posix:file";
4929 const char *hname
= "posix:hlink";
4930 const char *sname
= "posix:symlink";
4931 const char *dname
= "posix:dir";
4934 uint16_t fnum1
= (uint16_t)-1;
4935 SMB_STRUCT_STAT sbuf
;
4936 bool correct
= false;
4939 printf("Starting simple POSIX open test\n");
4941 if (!torture_open_connection(&cli1
, 0)) {
4945 cli_sockopt(cli1
, sockops
);
4947 status
= torture_setup_unix_extensions(cli1
);
4948 if (!NT_STATUS_IS_OK(status
)) {
4952 cli_setatr(cli1
, fname
, 0, 0);
4953 cli_posix_unlink(cli1
, fname
);
4954 cli_setatr(cli1
, dname
, 0, 0);
4955 cli_posix_rmdir(cli1
, dname
);
4956 cli_setatr(cli1
, hname
, 0, 0);
4957 cli_posix_unlink(cli1
, hname
);
4958 cli_setatr(cli1
, sname
, 0, 0);
4959 cli_posix_unlink(cli1
, sname
);
4961 /* Create a directory. */
4962 if (!NT_STATUS_IS_OK(cli_posix_mkdir(cli1
, dname
, 0777))) {
4963 printf("POSIX mkdir of %s failed (%s)\n", dname
, cli_errstr(cli1
));
4967 if (!NT_STATUS_IS_OK(cli_posix_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, 0600, &fnum1
))) {
4968 printf("POSIX create of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4972 /* Test ftruncate - set file size. */
4973 if (!NT_STATUS_IS_OK(cli_ftruncate(cli1
, fnum1
, 1000))) {
4974 printf("ftruncate failed (%s)\n", cli_errstr(cli1
));
4978 /* Ensure st_size == 1000 */
4979 if (!NT_STATUS_IS_OK(cli_posix_stat(cli1
, fname
, &sbuf
))) {
4980 printf("stat failed (%s)\n", cli_errstr(cli1
));
4984 if (sbuf
.st_ex_size
!= 1000) {
4985 printf("ftruncate - stat size (%u) != 1000\n", (unsigned int)sbuf
.st_ex_size
);
4989 /* Test ftruncate - set file size back to zero. */
4990 if (!NT_STATUS_IS_OK(cli_ftruncate(cli1
, fnum1
, 0))) {
4991 printf("ftruncate failed (%s)\n", cli_errstr(cli1
));
4995 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4996 printf("close failed (%s)\n", cli_errstr(cli1
));
5000 /* Now open the file again for read only. */
5001 if (!NT_STATUS_IS_OK(cli_posix_open(cli1
, fname
, O_RDONLY
, 0, &fnum1
))) {
5002 printf("POSIX open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
5006 /* Now unlink while open. */
5007 if (!NT_STATUS_IS_OK(cli_posix_unlink(cli1
, fname
))) {
5008 printf("POSIX unlink of %s failed (%s)\n", fname
, cli_errstr(cli1
));
5012 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
5013 printf("close(2) failed (%s)\n", cli_errstr(cli1
));
5017 /* Ensure the file has gone. */
5018 if (NT_STATUS_IS_OK(cli_posix_open(cli1
, fname
, O_RDONLY
, 0, &fnum1
))) {
5019 printf("POSIX open of %s succeeded, should have been deleted.\n", fname
);
5023 /* Create again to test open with O_TRUNC. */
5024 if (!NT_STATUS_IS_OK(cli_posix_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, 0600, &fnum1
))) {
5025 printf("POSIX create of %s failed (%s)\n", fname
, cli_errstr(cli1
));
5029 /* Test ftruncate - set file size. */
5030 if (!NT_STATUS_IS_OK(cli_ftruncate(cli1
, fnum1
, 1000))) {
5031 printf("ftruncate failed (%s)\n", cli_errstr(cli1
));
5035 /* Ensure st_size == 1000 */
5036 if (!NT_STATUS_IS_OK(cli_posix_stat(cli1
, fname
, &sbuf
))) {
5037 printf("stat failed (%s)\n", cli_errstr(cli1
));
5041 if (sbuf
.st_ex_size
!= 1000) {
5042 printf("ftruncate - stat size (%u) != 1000\n", (unsigned int)sbuf
.st_ex_size
);
5046 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
5047 printf("close(2) failed (%s)\n", cli_errstr(cli1
));
5051 /* Re-open with O_TRUNC. */
5052 if (!NT_STATUS_IS_OK(cli_posix_open(cli1
, fname
, O_WRONLY
|O_TRUNC
, 0600, &fnum1
))) {
5053 printf("POSIX create of %s failed (%s)\n", fname
, cli_errstr(cli1
));
5057 /* Ensure st_size == 0 */
5058 if (!NT_STATUS_IS_OK(cli_posix_stat(cli1
, fname
, &sbuf
))) {
5059 printf("stat failed (%s)\n", cli_errstr(cli1
));
5063 if (sbuf
.st_ex_size
!= 0) {
5064 printf("O_TRUNC - stat size (%u) != 0\n", (unsigned int)sbuf
.st_ex_size
);
5068 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
5069 printf("close failed (%s)\n", cli_errstr(cli1
));
5073 if (!NT_STATUS_IS_OK(cli_posix_unlink(cli1
, fname
))) {
5074 printf("POSIX unlink of %s failed (%s)\n", fname
, cli_errstr(cli1
));
5078 if (!NT_STATUS_IS_OK(cli_posix_open(cli1
, dname
, O_RDONLY
, 0, &fnum1
))) {
5079 printf("POSIX open directory O_RDONLY of %s failed (%s)\n",
5080 dname
, cli_errstr(cli1
));
5084 cli_close(cli1
, fnum1
);
5086 /* What happens when we try and POSIX open a directory for write ? */
5087 if (NT_STATUS_IS_OK(cli_posix_open(cli1
, dname
, O_RDWR
, 0, &fnum1
))) {
5088 printf("POSIX open of directory %s succeeded, should have failed.\n", fname
);
5091 if (!check_error(__LINE__
, cli1
, ERRDOS
, EISDIR
,
5092 NT_STATUS_FILE_IS_A_DIRECTORY
)) {
5097 /* Create the file. */
5098 if (!NT_STATUS_IS_OK(cli_posix_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, 0600, &fnum1
))) {
5099 printf("POSIX create of %s failed (%s)\n", fname
, cli_errstr(cli1
));
5103 /* Write some data into it. */
5104 status
= cli_writeall(cli1
, fnum1
, 0, (uint8_t *)"TEST DATA\n", 0, 10,
5106 if (!NT_STATUS_IS_OK(status
)) {
5107 printf("cli_write failed: %s\n", nt_errstr(status
));
5111 cli_close(cli1
, fnum1
);
5113 /* Now create a hardlink. */
5114 if (!NT_STATUS_IS_OK(cli_posix_hardlink(cli1
, fname
, hname
))) {
5115 printf("POSIX hardlink of %s failed (%s)\n", hname
, cli_errstr(cli1
));
5119 /* Now create a symlink. */
5120 if (!NT_STATUS_IS_OK(cli_posix_symlink(cli1
, fname
, sname
))) {
5121 printf("POSIX symlink of %s failed (%s)\n", sname
, cli_errstr(cli1
));
5125 /* Open the hardlink for read. */
5126 if (!NT_STATUS_IS_OK(cli_posix_open(cli1
, hname
, O_RDONLY
, 0, &fnum1
))) {
5127 printf("POSIX open of %s failed (%s)\n", hname
, cli_errstr(cli1
));
5131 if (cli_read(cli1
, fnum1
, buf
, 0, 10) != 10) {
5132 printf("POSIX read of %s failed (%s)\n", hname
, cli_errstr(cli1
));
5136 if (memcmp(buf
, "TEST DATA\n", 10)) {
5137 printf("invalid data read from hardlink\n");
5141 /* Do a POSIX lock/unlock. */
5142 if (!NT_STATUS_IS_OK(cli_posix_lock(cli1
, fnum1
, 0, 100, true, READ_LOCK
))) {
5143 printf("POSIX lock failed %s\n", cli_errstr(cli1
));
5147 /* Punch a hole in the locked area. */
5148 if (!NT_STATUS_IS_OK(cli_posix_unlock(cli1
, fnum1
, 10, 80))) {
5149 printf("POSIX unlock failed %s\n", cli_errstr(cli1
));
5153 cli_close(cli1
, fnum1
);
5155 /* Open the symlink for read - this should fail. A POSIX
5156 client should not be doing opens on a symlink. */
5157 if (NT_STATUS_IS_OK(cli_posix_open(cli1
, sname
, O_RDONLY
, 0, &fnum1
))) {
5158 printf("POSIX open of %s succeeded (should have failed)\n", sname
);
5161 if (!check_error(__LINE__
, cli1
, ERRDOS
, ERRbadpath
,
5162 NT_STATUS_OBJECT_PATH_NOT_FOUND
)) {
5163 printf("POSIX open of %s should have failed "
5164 "with NT_STATUS_OBJECT_PATH_NOT_FOUND, "
5165 "failed with %s instead.\n",
5166 sname
, cli_errstr(cli1
));
5171 if (!NT_STATUS_IS_OK(cli_posix_readlink(cli1
, sname
, namebuf
, sizeof(namebuf
)))) {
5172 printf("POSIX readlink on %s failed (%s)\n", sname
, cli_errstr(cli1
));
5176 if (strcmp(namebuf
, fname
) != 0) {
5177 printf("POSIX readlink on %s failed to match name %s (read %s)\n",
5178 sname
, fname
, namebuf
);
5182 if (!NT_STATUS_IS_OK(cli_posix_rmdir(cli1
, dname
))) {
5183 printf("POSIX rmdir failed (%s)\n", cli_errstr(cli1
));
5187 printf("Simple POSIX open test passed\n");
5192 if (fnum1
!= (uint16_t)-1) {
5193 cli_close(cli1
, fnum1
);
5194 fnum1
= (uint16_t)-1;
5197 cli_setatr(cli1
, sname
, 0, 0);
5198 cli_posix_unlink(cli1
, sname
);
5199 cli_setatr(cli1
, hname
, 0, 0);
5200 cli_posix_unlink(cli1
, hname
);
5201 cli_setatr(cli1
, fname
, 0, 0);
5202 cli_posix_unlink(cli1
, fname
);
5203 cli_setatr(cli1
, dname
, 0, 0);
5204 cli_posix_rmdir(cli1
, dname
);
5206 if (!torture_close_connection(cli1
)) {
5214 static uint32 open_attrs_table
[] = {
5215 FILE_ATTRIBUTE_NORMAL
,
5216 FILE_ATTRIBUTE_ARCHIVE
,
5217 FILE_ATTRIBUTE_READONLY
,
5218 FILE_ATTRIBUTE_HIDDEN
,
5219 FILE_ATTRIBUTE_SYSTEM
,
5221 FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
,
5222 FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
,
5223 FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
,
5224 FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
,
5225 FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_SYSTEM
,
5226 FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_SYSTEM
,
5228 FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
,
5229 FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_SYSTEM
,
5230 FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_SYSTEM
,
5231 FILE_ATTRIBUTE_HIDDEN
,FILE_ATTRIBUTE_SYSTEM
,
5234 struct trunc_open_results
{
5241 static struct trunc_open_results attr_results
[] = {
5242 { 0, FILE_ATTRIBUTE_NORMAL
, FILE_ATTRIBUTE_NORMAL
, FILE_ATTRIBUTE_ARCHIVE
},
5243 { 1, FILE_ATTRIBUTE_NORMAL
, FILE_ATTRIBUTE_ARCHIVE
, FILE_ATTRIBUTE_ARCHIVE
},
5244 { 2, FILE_ATTRIBUTE_NORMAL
, FILE_ATTRIBUTE_READONLY
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
},
5245 { 16, FILE_ATTRIBUTE_ARCHIVE
, FILE_ATTRIBUTE_NORMAL
, FILE_ATTRIBUTE_ARCHIVE
},
5246 { 17, FILE_ATTRIBUTE_ARCHIVE
, FILE_ATTRIBUTE_ARCHIVE
, FILE_ATTRIBUTE_ARCHIVE
},
5247 { 18, FILE_ATTRIBUTE_ARCHIVE
, FILE_ATTRIBUTE_READONLY
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
},
5248 { 51, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
},
5249 { 54, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
},
5250 { 56, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
},
5251 { 68, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
},
5252 { 71, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
},
5253 { 73, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_SYSTEM
},
5254 { 99, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_HIDDEN
,FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
},
5255 { 102, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
},
5256 { 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
},
5257 { 116, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
},
5258 { 119, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
},
5259 { 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
},
5260 { 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
},
5261 { 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
},
5262 { 227, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
},
5263 { 230, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
},
5264 { 232, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
},
5265 { 244, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
},
5266 { 247, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
},
5267 { 249, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_SYSTEM
}
5270 static bool run_openattrtest(int dummy
)
5272 static struct cli_state
*cli1
;
5273 const char *fname
= "\\openattr.file";
5275 bool correct
= True
;
5277 unsigned int i
, j
, k
, l
;
5279 printf("starting open attr test\n");
5281 if (!torture_open_connection(&cli1
, 0)) {
5285 cli_sockopt(cli1
, sockops
);
5287 for (k
= 0, i
= 0; i
< sizeof(open_attrs_table
)/sizeof(uint32
); i
++) {
5288 cli_setatr(cli1
, fname
, 0, 0);
5289 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
5290 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, FILE_WRITE_DATA
, open_attrs_table
[i
],
5291 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
5292 printf("open %d (1) of %s failed (%s)\n", i
, fname
, cli_errstr(cli1
));
5296 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
5297 printf("close %d (1) of %s failed (%s)\n", i
, fname
, cli_errstr(cli1
));
5301 for (j
= 0; j
< sizeof(open_attrs_table
)/sizeof(uint32
); j
++) {
5302 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, FILE_READ_DATA
|FILE_WRITE_DATA
, open_attrs_table
[j
],
5303 FILE_SHARE_NONE
, FILE_OVERWRITE
, 0, 0, &fnum1
))) {
5304 for (l
= 0; l
< sizeof(attr_results
)/sizeof(struct trunc_open_results
); l
++) {
5305 if (attr_results
[l
].num
== k
) {
5306 printf("[%d] trunc open 0x%x -> 0x%x of %s failed - should have succeeded !(0x%x:%s)\n",
5307 k
, open_attrs_table
[i
],
5308 open_attrs_table
[j
],
5309 fname
, NT_STATUS_V(cli_nt_error(cli1
)), cli_errstr(cli1
));
5313 if (NT_STATUS_V(cli_nt_error(cli1
)) != NT_STATUS_V(NT_STATUS_ACCESS_DENIED
)) {
5314 printf("[%d] trunc open 0x%x -> 0x%x failed with wrong error code %s\n",
5315 k
, open_attrs_table
[i
], open_attrs_table
[j
],
5320 printf("[%d] trunc open 0x%x -> 0x%x failed\n", k
, open_attrs_table
[i
], open_attrs_table
[j
]);
5326 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
5327 printf("close %d (2) of %s failed (%s)\n", j
, fname
, cli_errstr(cli1
));
5331 if (!NT_STATUS_IS_OK(cli_getatr(cli1
, fname
, &attr
, NULL
, NULL
))) {
5332 printf("getatr(2) failed (%s)\n", cli_errstr(cli1
));
5337 printf("[%d] getatr check [0x%x] trunc [0x%x] got attr 0x%x\n",
5338 k
, open_attrs_table
[i
], open_attrs_table
[j
], attr
);
5341 for (l
= 0; l
< sizeof(attr_results
)/sizeof(struct trunc_open_results
); l
++) {
5342 if (attr_results
[l
].num
== k
) {
5343 if (attr
!= attr_results
[l
].result_attr
||
5344 open_attrs_table
[i
] != attr_results
[l
].init_attr
||
5345 open_attrs_table
[j
] != attr_results
[l
].trunc_attr
) {
5346 printf("getatr check failed. [0x%x] trunc [0x%x] got attr 0x%x, should be 0x%x\n",
5347 open_attrs_table
[i
],
5348 open_attrs_table
[j
],
5350 attr_results
[l
].result_attr
);
5360 cli_setatr(cli1
, fname
, 0, 0);
5361 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
5363 printf("open attr test %s.\n", correct
? "passed" : "failed");
5365 if (!torture_close_connection(cli1
)) {
5371 static NTSTATUS
list_fn(const char *mnt
, struct file_info
*finfo
,
5372 const char *name
, void *state
)
5374 int *matched
= (int *)state
;
5375 if (matched
!= NULL
) {
5378 return NT_STATUS_OK
;
5382 test directory listing speed
5384 static bool run_dirtest(int dummy
)
5387 static struct cli_state
*cli
;
5389 struct timeval core_start
;
5390 bool correct
= True
;
5393 printf("starting directory test\n");
5395 if (!torture_open_connection(&cli
, 0)) {
5399 cli_sockopt(cli
, sockops
);
5402 for (i
=0;i
<torture_numops
;i
++) {
5404 slprintf(fname
, sizeof(fname
), "\\%x", (int)random());
5405 if (!NT_STATUS_IS_OK(cli_open(cli
, fname
, O_RDWR
|O_CREAT
, DENY_NONE
, &fnum
))) {
5406 fprintf(stderr
,"Failed to open %s\n", fname
);
5409 cli_close(cli
, fnum
);
5412 core_start
= timeval_current();
5415 cli_list(cli
, "a*.*", 0, list_fn
, &matched
);
5416 printf("Matched %d\n", matched
);
5419 cli_list(cli
, "b*.*", 0, list_fn
, &matched
);
5420 printf("Matched %d\n", matched
);
5423 cli_list(cli
, "xyzabc", 0, list_fn
, &matched
);
5424 printf("Matched %d\n", matched
);
5426 printf("dirtest core %g seconds\n", timeval_elapsed(&core_start
));
5429 for (i
=0;i
<torture_numops
;i
++) {
5431 slprintf(fname
, sizeof(fname
), "\\%x", (int)random());
5432 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
5435 if (!torture_close_connection(cli
)) {
5439 printf("finished dirtest\n");
5444 static NTSTATUS
del_fn(const char *mnt
, struct file_info
*finfo
, const char *mask
,
5447 struct cli_state
*pcli
= (struct cli_state
*)state
;
5449 slprintf(fname
, sizeof(fname
), "\\LISTDIR\\%s", finfo
->name
);
5451 if (strcmp(finfo
->name
, ".") == 0 || strcmp(finfo
->name
, "..") == 0)
5452 return NT_STATUS_OK
;
5454 if (finfo
->mode
& FILE_ATTRIBUTE_DIRECTORY
) {
5455 if (!NT_STATUS_IS_OK(cli_rmdir(pcli
, fname
)))
5456 printf("del_fn: failed to rmdir %s\n,", fname
);
5458 if (!NT_STATUS_IS_OK(cli_unlink(pcli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
)))
5459 printf("del_fn: failed to unlink %s\n,", fname
);
5461 return NT_STATUS_OK
;
5466 sees what IOCTLs are supported
5468 bool torture_ioctl_test(int dummy
)
5470 static struct cli_state
*cli
;
5471 uint16_t device
, function
;
5473 const char *fname
= "\\ioctl.dat";
5477 if (!torture_open_connection(&cli
, 0)) {
5481 printf("starting ioctl test\n");
5483 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
5485 if (!NT_STATUS_IS_OK(cli_open(cli
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum
))) {
5486 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli
));
5490 status
= cli_raw_ioctl(cli
, fnum
, 0x2d0000 | (0x0420<<2), &blob
);
5491 printf("ioctl device info: %s\n", nt_errstr(status
));
5493 status
= cli_raw_ioctl(cli
, fnum
, IOCTL_QUERY_JOB_INFO
, &blob
);
5494 printf("ioctl job info: %s\n", nt_errstr(status
));
5496 for (device
=0;device
<0x100;device
++) {
5497 printf("ioctl test with device = 0x%x\n", device
);
5498 for (function
=0;function
<0x100;function
++) {
5499 uint32 code
= (device
<<16) | function
;
5501 status
= cli_raw_ioctl(cli
, fnum
, code
, &blob
);
5503 if (NT_STATUS_IS_OK(status
)) {
5504 printf("ioctl 0x%x OK : %d bytes\n", (int)code
,
5506 data_blob_free(&blob
);
5511 if (!torture_close_connection(cli
)) {
5520 tries varients of chkpath
5522 bool torture_chkpath_test(int dummy
)
5524 static struct cli_state
*cli
;
5528 if (!torture_open_connection(&cli
, 0)) {
5532 printf("starting chkpath test\n");
5534 /* cleanup from an old run */
5535 cli_rmdir(cli
, "\\chkpath.dir\\dir2");
5536 cli_unlink(cli
, "\\chkpath.dir\\*", FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
5537 cli_rmdir(cli
, "\\chkpath.dir");
5539 if (!NT_STATUS_IS_OK(cli_mkdir(cli
, "\\chkpath.dir"))) {
5540 printf("mkdir1 failed : %s\n", cli_errstr(cli
));
5544 if (!NT_STATUS_IS_OK(cli_mkdir(cli
, "\\chkpath.dir\\dir2"))) {
5545 printf("mkdir2 failed : %s\n", cli_errstr(cli
));
5549 if (!NT_STATUS_IS_OK(cli_open(cli
, "\\chkpath.dir\\foo.txt", O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum
))) {
5550 printf("open1 failed (%s)\n", cli_errstr(cli
));
5553 cli_close(cli
, fnum
);
5555 if (!NT_STATUS_IS_OK(cli_chkpath(cli
, "\\chkpath.dir"))) {
5556 printf("chkpath1 failed: %s\n", cli_errstr(cli
));
5560 if (!NT_STATUS_IS_OK(cli_chkpath(cli
, "\\chkpath.dir\\dir2"))) {
5561 printf("chkpath2 failed: %s\n", cli_errstr(cli
));
5565 if (!NT_STATUS_IS_OK(cli_chkpath(cli
, "\\chkpath.dir\\foo.txt"))) {
5566 ret
= check_error(__LINE__
, cli
, ERRDOS
, ERRbadpath
,
5567 NT_STATUS_NOT_A_DIRECTORY
);
5569 printf("* chkpath on a file should fail\n");
5573 if (!NT_STATUS_IS_OK(cli_chkpath(cli
, "\\chkpath.dir\\bar.txt"))) {
5574 ret
= check_error(__LINE__
, cli
, ERRDOS
, ERRbadfile
,
5575 NT_STATUS_OBJECT_NAME_NOT_FOUND
);
5577 printf("* chkpath on a non existant file should fail\n");
5581 if (!NT_STATUS_IS_OK(cli_chkpath(cli
, "\\chkpath.dir\\dirxx\\bar.txt"))) {
5582 ret
= check_error(__LINE__
, cli
, ERRDOS
, ERRbadpath
,
5583 NT_STATUS_OBJECT_PATH_NOT_FOUND
);
5585 printf("* chkpath on a non existent component should fail\n");
5589 cli_rmdir(cli
, "\\chkpath.dir\\dir2");
5590 cli_unlink(cli
, "\\chkpath.dir\\*", FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
5591 cli_rmdir(cli
, "\\chkpath.dir");
5593 if (!torture_close_connection(cli
)) {
5600 static bool run_eatest(int dummy
)
5602 static struct cli_state
*cli
;
5603 const char *fname
= "\\eatest.txt";
5604 bool correct
= True
;
5608 struct ea_struct
*ea_list
= NULL
;
5609 TALLOC_CTX
*mem_ctx
= talloc_init("eatest");
5612 printf("starting eatest\n");
5614 if (!torture_open_connection(&cli
, 0)) {
5615 talloc_destroy(mem_ctx
);
5619 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
5620 if (!NT_STATUS_IS_OK(cli_ntcreate(cli
, fname
, 0,
5621 FIRST_DESIRED_ACCESS
, FILE_ATTRIBUTE_ARCHIVE
,
5622 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
,
5623 0x4044, 0, &fnum
))) {
5624 printf("open failed - %s\n", cli_errstr(cli
));
5625 talloc_destroy(mem_ctx
);
5629 for (i
= 0; i
< 10; i
++) {
5630 fstring ea_name
, ea_val
;
5632 slprintf(ea_name
, sizeof(ea_name
), "EA_%d", i
);
5633 memset(ea_val
, (char)i
+1, i
+1);
5634 status
= cli_set_ea_fnum(cli
, fnum
, ea_name
, ea_val
, i
+1);
5635 if (!NT_STATUS_IS_OK(status
)) {
5636 printf("ea_set of name %s failed - %s\n", ea_name
,
5638 talloc_destroy(mem_ctx
);
5643 cli_close(cli
, fnum
);
5644 for (i
= 0; i
< 10; i
++) {
5645 fstring ea_name
, ea_val
;
5647 slprintf(ea_name
, sizeof(ea_name
), "EA_%d", i
+10);
5648 memset(ea_val
, (char)i
+1, i
+1);
5649 status
= cli_set_ea_path(cli
, fname
, ea_name
, ea_val
, i
+1);
5650 if (!NT_STATUS_IS_OK(status
)) {
5651 printf("ea_set of name %s failed - %s\n", ea_name
,
5653 talloc_destroy(mem_ctx
);
5658 status
= cli_get_ea_list_path(cli
, fname
, mem_ctx
, &num_eas
, &ea_list
);
5659 if (!NT_STATUS_IS_OK(status
)) {
5660 printf("ea_get list failed - %s\n", nt_errstr(status
));
5664 printf("num_eas = %d\n", (int)num_eas
);
5666 if (num_eas
!= 20) {
5667 printf("Should be 20 EA's stored... failing.\n");
5671 for (i
= 0; i
< num_eas
; i
++) {
5672 printf("%d: ea_name = %s. Val = ", i
, ea_list
[i
].name
);
5673 dump_data(0, ea_list
[i
].value
.data
,
5674 ea_list
[i
].value
.length
);
5677 /* Setting EA's to zero length deletes them. Test this */
5678 printf("Now deleting all EA's - case indepenent....\n");
5681 cli_set_ea_path(cli
, fname
, "", "", 0);
5683 for (i
= 0; i
< 20; i
++) {
5685 slprintf(ea_name
, sizeof(ea_name
), "ea_%d", i
);
5686 status
= cli_set_ea_path(cli
, fname
, ea_name
, "", 0);
5687 if (!NT_STATUS_IS_OK(status
)) {
5688 printf("ea_set of name %s failed - %s\n", ea_name
,
5690 talloc_destroy(mem_ctx
);
5696 status
= cli_get_ea_list_path(cli
, fname
, mem_ctx
, &num_eas
, &ea_list
);
5697 if (!NT_STATUS_IS_OK(status
)) {
5698 printf("ea_get list failed - %s\n", nt_errstr(status
));
5702 printf("num_eas = %d\n", (int)num_eas
);
5703 for (i
= 0; i
< num_eas
; i
++) {
5704 printf("%d: ea_name = %s. Val = ", i
, ea_list
[i
].name
);
5705 dump_data(0, ea_list
[i
].value
.data
,
5706 ea_list
[i
].value
.length
);
5710 printf("deleting EA's failed.\n");
5714 /* Try and delete a non existant EA. */
5715 status
= cli_set_ea_path(cli
, fname
, "foo", "", 0);
5716 if (!NT_STATUS_IS_OK(status
)) {
5717 printf("deleting non-existant EA 'foo' should succeed. %s\n",
5722 talloc_destroy(mem_ctx
);
5723 if (!torture_close_connection(cli
)) {
5730 static bool run_dirtest1(int dummy
)
5733 static struct cli_state
*cli
;
5736 bool correct
= True
;
5738 printf("starting directory test\n");
5740 if (!torture_open_connection(&cli
, 0)) {
5744 cli_sockopt(cli
, sockops
);
5746 cli_list(cli
, "\\LISTDIR\\*", 0, del_fn
, cli
);
5747 cli_list(cli
, "\\LISTDIR\\*", FILE_ATTRIBUTE_DIRECTORY
, del_fn
, cli
);
5748 cli_rmdir(cli
, "\\LISTDIR");
5749 cli_mkdir(cli
, "\\LISTDIR");
5751 /* Create 1000 files and 1000 directories. */
5752 for (i
=0;i
<1000;i
++) {
5754 slprintf(fname
, sizeof(fname
), "\\LISTDIR\\f%d", i
);
5755 if (!NT_STATUS_IS_OK(cli_ntcreate(cli
, fname
, 0, GENERIC_ALL_ACCESS
, FILE_ATTRIBUTE_ARCHIVE
,
5756 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OVERWRITE_IF
, 0, 0, &fnum
))) {
5757 fprintf(stderr
,"Failed to open %s\n", fname
);
5760 cli_close(cli
, fnum
);
5762 for (i
=0;i
<1000;i
++) {
5764 slprintf(fname
, sizeof(fname
), "\\LISTDIR\\d%d", i
);
5765 if (!NT_STATUS_IS_OK(cli_mkdir(cli
, fname
))) {
5766 fprintf(stderr
,"Failed to open %s\n", fname
);
5771 /* Now ensure that doing an old list sees both files and directories. */
5773 cli_list_old(cli
, "\\LISTDIR\\*", FILE_ATTRIBUTE_DIRECTORY
, list_fn
, &num_seen
);
5774 printf("num_seen = %d\n", num_seen
);
5775 /* We should see 100 files + 1000 directories + . and .. */
5776 if (num_seen
!= 2002)
5779 /* Ensure if we have the "must have" bits we only see the
5783 cli_list_old(cli
, "\\LISTDIR\\*", (FILE_ATTRIBUTE_DIRECTORY
<<8)|FILE_ATTRIBUTE_DIRECTORY
, list_fn
, &num_seen
);
5784 printf("num_seen = %d\n", num_seen
);
5785 if (num_seen
!= 1002)
5789 cli_list_old(cli
, "\\LISTDIR\\*", (FILE_ATTRIBUTE_ARCHIVE
<<8)|FILE_ATTRIBUTE_DIRECTORY
, list_fn
, &num_seen
);
5790 printf("num_seen = %d\n", num_seen
);
5791 if (num_seen
!= 1000)
5794 /* Delete everything. */
5795 cli_list(cli
, "\\LISTDIR\\*", 0, del_fn
, cli
);
5796 cli_list(cli
, "\\LISTDIR\\*", FILE_ATTRIBUTE_DIRECTORY
, del_fn
, cli
);
5797 cli_rmdir(cli
, "\\LISTDIR");
5800 printf("Matched %d\n", cli_list(cli
, "a*.*", 0, list_fn
, NULL
));
5801 printf("Matched %d\n", cli_list(cli
, "b*.*", 0, list_fn
, NULL
));
5802 printf("Matched %d\n", cli_list(cli
, "xyzabc", 0, list_fn
, NULL
));
5805 if (!torture_close_connection(cli
)) {
5809 printf("finished dirtest1\n");
5814 static bool run_error_map_extract(int dummy
) {
5816 static struct cli_state
*c_dos
;
5817 static struct cli_state
*c_nt
;
5822 uint32 flgs2
, errnum
;
5829 /* NT-Error connection */
5831 if (!(c_nt
= open_nbt_connection())) {
5835 c_nt
->use_spnego
= False
;
5837 status
= cli_negprot(c_nt
);
5839 if (!NT_STATUS_IS_OK(status
)) {
5840 printf("%s rejected the NT-error negprot (%s)\n", host
,
5846 if (!NT_STATUS_IS_OK(cli_session_setup(c_nt
, "", "", 0, "", 0,
5848 printf("%s rejected the NT-error initial session setup (%s)\n",host
, cli_errstr(c_nt
));
5852 /* DOS-Error connection */
5854 if (!(c_dos
= open_nbt_connection())) {
5858 c_dos
->use_spnego
= False
;
5859 c_dos
->force_dos_errors
= True
;
5861 status
= cli_negprot(c_dos
);
5862 if (!NT_STATUS_IS_OK(status
)) {
5863 printf("%s rejected the DOS-error negprot (%s)\n", host
,
5865 cli_shutdown(c_dos
);
5869 if (!NT_STATUS_IS_OK(cli_session_setup(c_dos
, "", "", 0, "", 0,
5871 printf("%s rejected the DOS-error initial session setup (%s)\n",host
, cli_errstr(c_dos
));
5875 for (error
=(0xc0000000 | 0x1); error
< (0xc0000000| 0xFFF); error
++) {
5876 fstr_sprintf(user
, "%X", error
);
5878 if (NT_STATUS_IS_OK(cli_session_setup(c_nt
, user
,
5879 password
, strlen(password
),
5880 password
, strlen(password
),
5882 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
5885 flgs2
= SVAL(c_nt
->inbuf
,smb_flg2
);
5887 /* Case #1: 32-bit NT errors */
5888 if (flgs2
& FLAGS2_32_BIT_ERROR_CODES
) {
5889 nt_status
= NT_STATUS(IVAL(c_nt
->inbuf
,smb_rcls
));
5891 printf("/** Dos error on NT connection! (%s) */\n",
5893 nt_status
= NT_STATUS(0xc0000000);
5896 if (NT_STATUS_IS_OK(cli_session_setup(c_dos
, user
,
5897 password
, strlen(password
),
5898 password
, strlen(password
),
5900 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
5902 flgs2
= SVAL(c_dos
->inbuf
,smb_flg2
), errnum
;
5904 /* Case #1: 32-bit NT errors */
5905 if (flgs2
& FLAGS2_32_BIT_ERROR_CODES
) {
5906 printf("/** NT error on DOS connection! (%s) */\n",
5908 errnum
= errclass
= 0;
5910 cli_dos_error(c_dos
, &errclass
, &errnum
);
5913 if (NT_STATUS_V(nt_status
) != error
) {
5914 printf("/*\t{ This NT error code was 'sqashed'\n\t from %s to %s \n\t during the session setup }\n*/\n",
5915 get_nt_error_c_code(NT_STATUS(error
)),
5916 get_nt_error_c_code(nt_status
));
5919 printf("\t{%s,\t%s,\t%s},\n",
5920 smb_dos_err_class(errclass
),
5921 smb_dos_err_name(errclass
, errnum
),
5922 get_nt_error_c_code(NT_STATUS(error
)));
5927 static bool run_sesssetup_bench(int dummy
)
5929 static struct cli_state
*c
;
5930 const char *fname
= "\\file.dat";
5935 if (!torture_open_connection(&c
, 0)) {
5939 if (!NT_STATUS_IS_OK(cli_ntcreate(
5940 c
, fname
, 0, GENERIC_ALL_ACCESS
|DELETE_ACCESS
,
5941 FILE_ATTRIBUTE_NORMAL
, 0, FILE_OVERWRITE_IF
,
5942 FILE_DELETE_ON_CLOSE
, 0, &fnum
))) {
5943 d_printf("open %s failed: %s\n", fname
, cli_errstr(c
));
5947 for (i
=0; i
<torture_numops
; i
++) {
5948 status
= cli_session_setup(
5950 password
, strlen(password
),
5951 password
, strlen(password
),
5953 if (!NT_STATUS_IS_OK(status
)) {
5954 d_printf("(%s) cli_session_setup failed: %s\n",
5955 __location__
, nt_errstr(status
));
5959 d_printf("\r%d ", (int)c
->vuid
);
5961 status
= cli_ulogoff(c
);
5962 if (!NT_STATUS_IS_OK(status
)) {
5963 d_printf("(%s) cli_ulogoff failed: %s\n",
5964 __location__
, nt_errstr(status
));
5973 static bool subst_test(const char *str
, const char *user
, const char *domain
,
5974 uid_t uid
, gid_t gid
, const char *expected
)
5979 subst
= talloc_sub_specified(talloc_tos(), str
, user
, domain
, uid
, gid
);
5981 if (strcmp(subst
, expected
) != 0) {
5982 printf("sub_specified(%s, %s, %s, %d, %d) returned [%s], expected "
5983 "[%s]\n", str
, user
, domain
, (int)uid
, (int)gid
, subst
,
5992 static void chain1_open_completion(struct tevent_req
*req
)
5996 status
= cli_open_recv(req
, &fnum
);
5999 d_printf("cli_open_recv returned %s: %d\n",
6001 NT_STATUS_IS_OK(status
) ? fnum
: -1);
6004 static void chain1_write_completion(struct tevent_req
*req
)
6008 status
= cli_write_andx_recv(req
, &written
);
6011 d_printf("cli_write_andx_recv returned %s: %d\n",
6013 NT_STATUS_IS_OK(status
) ? (int)written
: -1);
6016 static void chain1_close_completion(struct tevent_req
*req
)
6019 bool *done
= (bool *)tevent_req_callback_data_void(req
);
6021 status
= cli_close_recv(req
);
6026 d_printf("cli_close returned %s\n", nt_errstr(status
));
6029 static bool run_chain1(int dummy
)
6031 struct cli_state
*cli1
;
6032 struct event_context
*evt
= event_context_init(NULL
);
6033 struct tevent_req
*reqs
[3], *smbreqs
[3];
6035 const char *str
= "foobar";
6038 printf("starting chain1 test\n");
6039 if (!torture_open_connection(&cli1
, 0)) {
6043 cli_sockopt(cli1
, sockops
);
6045 reqs
[0] = cli_open_create(talloc_tos(), evt
, cli1
, "\\test",
6046 O_CREAT
|O_RDWR
, 0, &smbreqs
[0]);
6047 if (reqs
[0] == NULL
) return false;
6048 tevent_req_set_callback(reqs
[0], chain1_open_completion
, NULL
);
6051 reqs
[1] = cli_write_andx_create(talloc_tos(), evt
, cli1
, 0, 0,
6052 (uint8_t *)str
, 0, strlen(str
)+1,
6053 smbreqs
, 1, &smbreqs
[1]);
6054 if (reqs
[1] == NULL
) return false;
6055 tevent_req_set_callback(reqs
[1], chain1_write_completion
, NULL
);
6057 reqs
[2] = cli_close_create(talloc_tos(), evt
, cli1
, 0, &smbreqs
[2]);
6058 if (reqs
[2] == NULL
) return false;
6059 tevent_req_set_callback(reqs
[2], chain1_close_completion
, &done
);
6061 status
= cli_smb_chain_send(smbreqs
, ARRAY_SIZE(smbreqs
));
6062 if (!NT_STATUS_IS_OK(status
)) {
6067 event_loop_once(evt
);
6070 torture_close_connection(cli1
);
6074 static void chain2_sesssetup_completion(struct tevent_req
*req
)
6077 status
= cli_session_setup_guest_recv(req
);
6078 d_printf("sesssetup returned %s\n", nt_errstr(status
));
6081 static void chain2_tcon_completion(struct tevent_req
*req
)
6083 bool *done
= (bool *)tevent_req_callback_data_void(req
);
6085 status
= cli_tcon_andx_recv(req
);
6086 d_printf("tcon_and_x returned %s\n", nt_errstr(status
));
6090 static bool run_chain2(int dummy
)
6092 struct cli_state
*cli1
;
6093 struct event_context
*evt
= event_context_init(NULL
);
6094 struct tevent_req
*reqs
[2], *smbreqs
[2];
6098 printf("starting chain2 test\n");
6099 status
= cli_start_connection(&cli1
, global_myname(), host
, NULL
,
6100 port_to_use
, Undefined
, 0);
6101 if (!NT_STATUS_IS_OK(status
)) {
6105 cli_sockopt(cli1
, sockops
);
6107 reqs
[0] = cli_session_setup_guest_create(talloc_tos(), evt
, cli1
,
6109 if (reqs
[0] == NULL
) return false;
6110 tevent_req_set_callback(reqs
[0], chain2_sesssetup_completion
, NULL
);
6112 reqs
[1] = cli_tcon_andx_create(talloc_tos(), evt
, cli1
, "IPC$",
6113 "?????", NULL
, 0, &smbreqs
[1]);
6114 if (reqs
[1] == NULL
) return false;
6115 tevent_req_set_callback(reqs
[1], chain2_tcon_completion
, &done
);
6117 status
= cli_smb_chain_send(smbreqs
, ARRAY_SIZE(smbreqs
));
6118 if (!NT_STATUS_IS_OK(status
)) {
6123 event_loop_once(evt
);
6126 torture_close_connection(cli1
);
6131 struct torture_createdel_state
{
6132 struct tevent_context
*ev
;
6133 struct cli_state
*cli
;
6136 static void torture_createdel_created(struct tevent_req
*subreq
);
6137 static void torture_createdel_closed(struct tevent_req
*subreq
);
6139 static struct tevent_req
*torture_createdel_send(TALLOC_CTX
*mem_ctx
,
6140 struct tevent_context
*ev
,
6141 struct cli_state
*cli
,
6144 struct tevent_req
*req
, *subreq
;
6145 struct torture_createdel_state
*state
;
6147 req
= tevent_req_create(mem_ctx
, &state
,
6148 struct torture_createdel_state
);
6155 subreq
= cli_ntcreate_send(
6156 state
, ev
, cli
, name
, 0,
6157 FILE_READ_DATA
|FILE_WRITE_DATA
|DELETE_ACCESS
,
6158 FILE_ATTRIBUTE_NORMAL
,
6159 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
6160 FILE_OPEN_IF
, FILE_DELETE_ON_CLOSE
, 0);
6162 if (tevent_req_nomem(subreq
, req
)) {
6163 return tevent_req_post(req
, ev
);
6165 tevent_req_set_callback(subreq
, torture_createdel_created
, req
);
6169 static void torture_createdel_created(struct tevent_req
*subreq
)
6171 struct tevent_req
*req
= tevent_req_callback_data(
6172 subreq
, struct tevent_req
);
6173 struct torture_createdel_state
*state
= tevent_req_data(
6174 req
, struct torture_createdel_state
);
6178 status
= cli_ntcreate_recv(subreq
, &fnum
);
6179 TALLOC_FREE(subreq
);
6180 if (!NT_STATUS_IS_OK(status
)) {
6181 DEBUG(10, ("cli_ntcreate_recv returned %s\n",
6182 nt_errstr(status
)));
6183 tevent_req_nterror(req
, status
);
6187 subreq
= cli_close_send(state
, state
->ev
, state
->cli
, fnum
);
6188 if (tevent_req_nomem(subreq
, req
)) {
6191 tevent_req_set_callback(subreq
, torture_createdel_closed
, req
);
6194 static void torture_createdel_closed(struct tevent_req
*subreq
)
6196 struct tevent_req
*req
= tevent_req_callback_data(
6197 subreq
, struct tevent_req
);
6200 status
= cli_close_recv(subreq
);
6201 if (!NT_STATUS_IS_OK(status
)) {
6202 DEBUG(10, ("cli_close_recv returned %s\n", nt_errstr(status
)));
6203 tevent_req_nterror(req
, status
);
6206 tevent_req_done(req
);
6209 static NTSTATUS
torture_createdel_recv(struct tevent_req
*req
)
6211 return tevent_req_simple_recv_ntstatus(req
);
6214 struct torture_createdels_state
{
6215 struct tevent_context
*ev
;
6216 struct cli_state
*cli
;
6217 const char *base_name
;
6221 struct tevent_req
**reqs
;
6224 static void torture_createdels_done(struct tevent_req
*subreq
);
6226 static struct tevent_req
*torture_createdels_send(TALLOC_CTX
*mem_ctx
,
6227 struct tevent_context
*ev
,
6228 struct cli_state
*cli
,
6229 const char *base_name
,
6233 struct tevent_req
*req
;
6234 struct torture_createdels_state
*state
;
6237 req
= tevent_req_create(mem_ctx
, &state
,
6238 struct torture_createdels_state
);
6244 state
->base_name
= talloc_strdup(state
, base_name
);
6245 if (tevent_req_nomem(state
->base_name
, req
)) {
6246 return tevent_req_post(req
, ev
);
6248 state
->num_files
= MAX(num_parallel
, num_files
);
6250 state
->received
= 0;
6252 state
->reqs
= talloc_array(state
, struct tevent_req
*, num_parallel
);
6253 if (tevent_req_nomem(state
->reqs
, req
)) {
6254 return tevent_req_post(req
, ev
);
6257 for (i
=0; i
<num_parallel
; i
++) {
6260 name
= talloc_asprintf(state
, "%s%8.8d", state
->base_name
,
6262 if (tevent_req_nomem(name
, req
)) {
6263 return tevent_req_post(req
, ev
);
6265 state
->reqs
[i
] = torture_createdel_send(
6266 state
->reqs
, state
->ev
, state
->cli
, name
);
6267 if (tevent_req_nomem(state
->reqs
[i
], req
)) {
6268 return tevent_req_post(req
, ev
);
6270 name
= talloc_move(state
->reqs
[i
], &name
);
6271 tevent_req_set_callback(state
->reqs
[i
],
6272 torture_createdels_done
, req
);
6278 static void torture_createdels_done(struct tevent_req
*subreq
)
6280 struct tevent_req
*req
= tevent_req_callback_data(
6281 subreq
, struct tevent_req
);
6282 struct torture_createdels_state
*state
= tevent_req_data(
6283 req
, struct torture_createdels_state
);
6284 size_t num_parallel
= talloc_array_length(state
->reqs
);
6289 status
= torture_createdel_recv(subreq
);
6290 if (!NT_STATUS_IS_OK(status
)){
6291 DEBUG(10, ("torture_createdel_recv returned %s\n",
6292 nt_errstr(status
)));
6293 TALLOC_FREE(subreq
);
6294 tevent_req_nterror(req
, status
);
6298 for (i
=0; i
<num_parallel
; i
++) {
6299 if (subreq
== state
->reqs
[i
]) {
6303 if (i
== num_parallel
) {
6304 DEBUG(10, ("received something we did not send\n"));
6305 tevent_req_nterror(req
, NT_STATUS_INTERNAL_ERROR
);
6308 TALLOC_FREE(state
->reqs
[i
]);
6310 if (state
->sent
>= state
->num_files
) {
6311 tevent_req_done(req
);
6315 name
= talloc_asprintf(state
, "%s%8.8d", state
->base_name
,
6317 if (tevent_req_nomem(name
, req
)) {
6320 state
->reqs
[i
] = torture_createdel_send(state
->reqs
, state
->ev
,
6322 if (tevent_req_nomem(state
->reqs
[i
], req
)) {
6325 name
= talloc_move(state
->reqs
[i
], &name
);
6326 tevent_req_set_callback(state
->reqs
[i
], torture_createdels_done
, req
);
6330 static NTSTATUS
torture_createdels_recv(struct tevent_req
*req
)
6332 return tevent_req_simple_recv_ntstatus(req
);
6335 struct swallow_notify_state
{
6336 struct tevent_context
*ev
;
6337 struct cli_state
*cli
;
6339 uint32_t completion_filter
;
6341 bool (*fn
)(uint32_t action
, const char *name
, void *priv
);
6345 static void swallow_notify_done(struct tevent_req
*subreq
);
6347 static struct tevent_req
*swallow_notify_send(TALLOC_CTX
*mem_ctx
,
6348 struct tevent_context
*ev
,
6349 struct cli_state
*cli
,
6351 uint32_t completion_filter
,
6353 bool (*fn
)(uint32_t action
,
6358 struct tevent_req
*req
, *subreq
;
6359 struct swallow_notify_state
*state
;
6361 req
= tevent_req_create(mem_ctx
, &state
,
6362 struct swallow_notify_state
);
6369 state
->completion_filter
= completion_filter
;
6370 state
->recursive
= recursive
;
6374 subreq
= cli_notify_send(state
, state
->ev
, state
->cli
, state
->fnum
,
6375 0xffff, state
->completion_filter
,
6377 if (tevent_req_nomem(subreq
, req
)) {
6378 return tevent_req_post(req
, ev
);
6380 tevent_req_set_callback(subreq
, swallow_notify_done
, req
);
6384 static void swallow_notify_done(struct tevent_req
*subreq
)
6386 struct tevent_req
*req
= tevent_req_callback_data(
6387 subreq
, struct tevent_req
);
6388 struct swallow_notify_state
*state
= tevent_req_data(
6389 req
, struct swallow_notify_state
);
6391 uint32_t i
, num_changes
;
6392 struct notify_change
*changes
;
6394 status
= cli_notify_recv(subreq
, state
, &num_changes
, &changes
);
6395 TALLOC_FREE(subreq
);
6396 if (!NT_STATUS_IS_OK(status
)) {
6397 DEBUG(10, ("cli_notify_recv returned %s\n",
6398 nt_errstr(status
)));
6399 tevent_req_nterror(req
, status
);
6403 for (i
=0; i
<num_changes
; i
++) {
6404 state
->fn(changes
[i
].action
, changes
[i
].name
, state
->priv
);
6406 TALLOC_FREE(changes
);
6408 subreq
= cli_notify_send(state
, state
->ev
, state
->cli
, state
->fnum
,
6409 0xffff, state
->completion_filter
,
6411 if (tevent_req_nomem(subreq
, req
)) {
6414 tevent_req_set_callback(subreq
, swallow_notify_done
, req
);
6417 static bool print_notifies(uint32_t action
, const char *name
, void *priv
)
6419 if (DEBUGLEVEL
> 5) {
6420 d_printf("%d %s\n", (int)action
, name
);
6425 static void notify_bench_done(struct tevent_req
*req
)
6427 int *num_finished
= (int *)tevent_req_callback_data_void(req
);
6431 static bool run_notify_bench(int dummy
)
6433 const char *dname
= "\\notify-bench";
6434 struct tevent_context
*ev
;
6437 struct tevent_req
*req1
;
6438 struct tevent_req
*req2
= NULL
;
6439 int i
, num_unc_names
;
6440 int num_finished
= 0;
6442 printf("starting notify-bench test\n");
6444 if (use_multishare_conn
) {
6446 unc_list
= file_lines_load(multishare_conn_fname
,
6447 &num_unc_names
, 0, NULL
);
6448 if (!unc_list
|| num_unc_names
<= 0) {
6449 d_printf("Failed to load unc names list from '%s'\n",
6450 multishare_conn_fname
);
6453 TALLOC_FREE(unc_list
);
6458 ev
= tevent_context_init(talloc_tos());
6460 d_printf("tevent_context_init failed\n");
6464 for (i
=0; i
<num_unc_names
; i
++) {
6465 struct cli_state
*cli
;
6468 base_fname
= talloc_asprintf(talloc_tos(), "%s\\file%3.3d.",
6470 if (base_fname
== NULL
) {
6474 if (!torture_open_connection(&cli
, i
)) {
6478 status
= cli_ntcreate(cli
, dname
, 0,
6479 MAXIMUM_ALLOWED_ACCESS
,
6480 0, FILE_SHARE_READ
|FILE_SHARE_WRITE
|
6482 FILE_OPEN_IF
, FILE_DIRECTORY_FILE
, 0,
6485 if (!NT_STATUS_IS_OK(status
)) {
6486 d_printf("Could not create %s: %s\n", dname
,
6491 req1
= swallow_notify_send(talloc_tos(), ev
, cli
, dnum
,
6492 FILE_NOTIFY_CHANGE_FILE_NAME
|
6493 FILE_NOTIFY_CHANGE_DIR_NAME
|
6494 FILE_NOTIFY_CHANGE_ATTRIBUTES
|
6495 FILE_NOTIFY_CHANGE_LAST_WRITE
,
6496 false, print_notifies
, NULL
);
6498 d_printf("Could not create notify request\n");
6502 req2
= torture_createdels_send(talloc_tos(), ev
, cli
,
6503 base_fname
, 10, torture_numops
);
6505 d_printf("Could not create createdels request\n");
6508 TALLOC_FREE(base_fname
);
6510 tevent_req_set_callback(req2
, notify_bench_done
,
6514 while (num_finished
< num_unc_names
) {
6516 ret
= tevent_loop_once(ev
);
6518 d_printf("tevent_loop_once failed\n");
6523 if (!tevent_req_poll(req2
, ev
)) {
6524 d_printf("tevent_req_poll failed\n");
6527 status
= torture_createdels_recv(req2
);
6528 d_printf("torture_createdels_recv returned %s\n", nt_errstr(status
));
6533 static bool run_mangle1(int dummy
)
6535 struct cli_state
*cli
;
6536 const char *fname
= "this_is_a_long_fname_to_be_mangled.txt";
6540 time_t change_time
, access_time
, write_time
;
6544 printf("starting mangle1 test\n");
6545 if (!torture_open_connection(&cli
, 0)) {
6549 cli_sockopt(cli
, sockops
);
6551 if (!NT_STATUS_IS_OK(cli_ntcreate(
6552 cli
, fname
, 0, GENERIC_ALL_ACCESS
|DELETE_ACCESS
,
6553 FILE_ATTRIBUTE_NORMAL
, 0, FILE_OVERWRITE_IF
, 0, 0, &fnum
))) {
6554 d_printf("open %s failed: %s\n", fname
, cli_errstr(cli
));
6557 cli_close(cli
, fnum
);
6559 status
= cli_qpathinfo_alt_name(cli
, fname
, alt_name
);
6560 if (!NT_STATUS_IS_OK(status
)) {
6561 d_printf("cli_qpathinfo_alt_name failed: %s\n",
6565 d_printf("alt_name: %s\n", alt_name
);
6567 if (!NT_STATUS_IS_OK(cli_open(cli
, alt_name
, O_RDONLY
, DENY_NONE
, &fnum
))) {
6568 d_printf("cli_open(%s) failed: %s\n", alt_name
,
6572 cli_close(cli
, fnum
);
6574 status
= cli_qpathinfo1(cli
, alt_name
, &change_time
, &access_time
,
6575 &write_time
, &size
, &mode
);
6576 if (!NT_STATUS_IS_OK(status
)) {
6577 d_printf("cli_qpathinfo1(%s) failed: %s\n", alt_name
,
6585 static size_t null_source(uint8_t *buf
, size_t n
, void *priv
)
6587 size_t *to_pull
= (size_t *)priv
;
6588 size_t thistime
= *to_pull
;
6590 thistime
= MIN(thistime
, n
);
6591 if (thistime
== 0) {
6595 memset(buf
, 0, thistime
);
6596 *to_pull
-= thistime
;
6600 static bool run_windows_write(int dummy
)
6602 struct cli_state
*cli1
;
6606 const char *fname
= "\\writetest.txt";
6607 struct timeval start_time
;
6611 printf("starting windows_write test\n");
6612 if (!torture_open_connection(&cli1
, 0)) {
6616 if (!NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum
))) {
6617 printf("open failed (%s)\n", cli_errstr(cli1
));
6621 cli_sockopt(cli1
, sockops
);
6623 start_time
= timeval_current();
6625 for (i
=0; i
<torture_numops
; i
++) {
6627 off_t start
= i
* torture_blocksize
;
6629 size_t to_pull
= torture_blocksize
- 1;
6631 status
= cli_writeall(cli1
, fnum
, 0, &c
,
6632 start
+ torture_blocksize
- 1, 1, NULL
);
6633 if (!NT_STATUS_IS_OK(status
)) {
6634 printf("cli_write failed: %s\n", nt_errstr(status
));
6638 status
= cli_push(cli1
, fnum
, 0, i
* torture_blocksize
, torture_blocksize
,
6639 null_source
, &to_pull
);
6640 if (!NT_STATUS_IS_OK(status
)) {
6641 printf("cli_push returned: %s\n", nt_errstr(status
));
6646 seconds
= timeval_elapsed(&start_time
);
6647 kbytes
= (double)torture_blocksize
* torture_numops
;
6650 printf("Wrote %d kbytes in %.2f seconds: %d kb/sec\n", (int)kbytes
,
6651 (double)seconds
, (int)(kbytes
/seconds
));
6655 cli_close(cli1
, fnum
);
6656 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
6657 torture_close_connection(cli1
);
6661 static bool run_cli_echo(int dummy
)
6663 struct cli_state
*cli
;
6666 printf("starting cli_echo test\n");
6667 if (!torture_open_connection(&cli
, 0)) {
6670 cli_sockopt(cli
, sockops
);
6672 status
= cli_echo(cli
, 5, data_blob_const("hello", 5));
6674 d_printf("cli_echo returned %s\n", nt_errstr(status
));
6676 torture_close_connection(cli
);
6677 return NT_STATUS_IS_OK(status
);
6680 static bool run_uid_regression_test(int dummy
)
6682 static struct cli_state
*cli
;
6685 bool correct
= True
;
6688 printf("starting uid regression test\n");
6690 if (!torture_open_connection(&cli
, 0)) {
6694 cli_sockopt(cli
, sockops
);
6696 /* Ok - now save then logoff our current user. */
6697 old_vuid
= cli
->vuid
;
6699 status
= cli_ulogoff(cli
);
6700 if (!NT_STATUS_IS_OK(status
)) {
6701 d_printf("(%s) cli_ulogoff failed: %s\n",
6702 __location__
, nt_errstr(status
));
6707 cli
->vuid
= old_vuid
;
6709 /* Try an operation. */
6710 status
= cli_mkdir(cli
, "\\uid_reg_test");
6711 if (NT_STATUS_IS_OK(status
)) {
6712 d_printf("(%s) cli_mkdir succeeded\n",
6717 /* Should be bad uid. */
6718 if (!check_error(__LINE__
, cli
, ERRSRV
, ERRbaduid
,
6719 NT_STATUS_USER_SESSION_DELETED
)) {
6725 old_cnum
= cli
->cnum
;
6727 /* Now try a SMBtdis with the invald vuid set to zero. */
6730 /* This should succeed. */
6731 status
= cli_tdis(cli
);
6733 if (NT_STATUS_IS_OK(status
)) {
6734 d_printf("First tdis with invalid vuid should succeed.\n");
6736 d_printf("First tdis failed (%s)\n", nt_errstr(status
));
6741 cli
->vuid
= old_vuid
;
6742 cli
->cnum
= old_cnum
;
6744 /* This should fail. */
6745 status
= cli_tdis(cli
);
6746 if (NT_STATUS_IS_OK(status
)) {
6747 d_printf("Second tdis with invalid vuid should fail - succeeded instead !.\n");
6751 /* Should be bad tid. */
6752 if (!check_error(__LINE__
, cli
, ERRSRV
, ERRinvnid
,
6753 NT_STATUS_NETWORK_NAME_DELETED
)) {
6759 cli_rmdir(cli
, "\\uid_reg_test");
6768 static const char *illegal_chars
= "*\\/?<>|\":";
6769 static char force_shortname_chars
[] = " +,.[];=\177";
6771 static NTSTATUS
shortname_del_fn(const char *mnt
, struct file_info
*finfo
,
6772 const char *mask
, void *state
)
6774 struct cli_state
*pcli
= (struct cli_state
*)state
;
6776 NTSTATUS status
= NT_STATUS_OK
;
6778 slprintf(fname
, sizeof(fname
), "\\shortname\\%s", finfo
->name
);
6780 if (strcmp(finfo
->name
, ".") == 0 || strcmp(finfo
->name
, "..") == 0)
6781 return NT_STATUS_OK
;
6783 if (finfo
->mode
& FILE_ATTRIBUTE_DIRECTORY
) {
6784 status
= cli_rmdir(pcli
, fname
);
6785 if (!NT_STATUS_IS_OK(status
)) {
6786 printf("del_fn: failed to rmdir %s\n,", fname
);
6789 status
= cli_unlink(pcli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
6790 if (!NT_STATUS_IS_OK(status
)) {
6791 printf("del_fn: failed to unlink %s\n,", fname
);
6803 static NTSTATUS
shortname_list_fn(const char *mnt
, struct file_info
*finfo
,
6804 const char *name
, void *state
)
6806 struct sn_state
*s
= (struct sn_state
*)state
;
6810 printf("shortname list: i = %d, name = |%s|, shortname = |%s|\n",
6811 i
, finfo
->name
, finfo
->short_name
);
6814 if (strchr(force_shortname_chars
, i
)) {
6815 if (!finfo
->short_name
[0]) {
6816 /* Shortname not created when it should be. */
6817 d_printf("(%s) ERROR: Shortname was not created for file %s containing %d\n",
6818 __location__
, finfo
->name
, i
);
6821 } else if (finfo
->short_name
[0]){
6822 /* Shortname created when it should not be. */
6823 d_printf("(%s) ERROR: Shortname %s was created for file %s\n",
6824 __location__
, finfo
->short_name
, finfo
->name
);
6828 return NT_STATUS_OK
;
6831 static bool run_shortname_test(int dummy
)
6833 static struct cli_state
*cli
;
6834 bool correct
= True
;
6839 printf("starting shortname test\n");
6841 if (!torture_open_connection(&cli
, 0)) {
6845 cli_sockopt(cli
, sockops
);
6847 cli_list(cli
, "\\shortname\\*", 0, shortname_del_fn
, cli
);
6848 cli_list(cli
, "\\shortname\\*", FILE_ATTRIBUTE_DIRECTORY
, shortname_del_fn
, cli
);
6849 cli_rmdir(cli
, "\\shortname");
6851 if (!NT_STATUS_IS_OK(cli_mkdir(cli
, "\\shortname"))) {
6852 d_printf("(%s) cli_mkdir of \\shortname failed: %s\n",
6853 __location__
, cli_errstr(cli
));
6858 strlcpy(fname
, "\\shortname\\", sizeof(fname
));
6859 strlcat(fname
, "test .txt", sizeof(fname
));
6863 for (i
= 32; i
< 128; i
++) {
6865 uint16_t fnum
= (uint16_t)-1;
6869 if (strchr(illegal_chars
, i
)) {
6874 status
= cli_ntcreate(cli
, fname
, 0, GENERIC_ALL_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
6875 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OVERWRITE_IF
, 0, 0, &fnum
);
6876 if (!NT_STATUS_IS_OK(status
)) {
6877 d_printf("(%s) cli_nt_create of %s failed: %s\n",
6878 __location__
, fname
, cli_errstr(cli
));
6882 cli_close(cli
, fnum
);
6885 cli_list(cli
, "\\shortname\\test*.*", 0, shortname_list_fn
,
6887 if (s
.matched
!= 1) {
6888 d_printf("(%s) failed to list %s: %s\n",
6889 __location__
, fname
, cli_errstr(cli
));
6893 if (!NT_STATUS_IS_OK(cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
))) {
6894 d_printf("(%s) failed to delete %s: %s\n",
6895 __location__
, fname
, cli_errstr(cli
));
6908 cli_list(cli
, "\\shortname\\*", 0, shortname_del_fn
, cli
);
6909 cli_list(cli
, "\\shortname\\*", FILE_ATTRIBUTE_DIRECTORY
, shortname_del_fn
, cli
);
6910 cli_rmdir(cli
, "\\shortname");
6911 torture_close_connection(cli
);
6915 static void pagedsearch_cb(struct tevent_req
*req
)
6918 struct tldap_message
*msg
;
6921 rc
= tldap_search_paged_recv(req
, talloc_tos(), &msg
);
6922 if (rc
!= TLDAP_SUCCESS
) {
6923 d_printf("tldap_search_paged_recv failed: %s\n",
6924 tldap_err2string(rc
));
6927 if (tldap_msg_type(msg
) != TLDAP_RES_SEARCH_ENTRY
) {
6931 if (!tldap_entry_dn(msg
, &dn
)) {
6932 d_printf("tldap_entry_dn failed\n");
6935 d_printf("%s\n", dn
);
6939 static bool run_tldap(int dummy
)
6941 struct tldap_context
*ld
;
6944 struct sockaddr_storage addr
;
6945 struct tevent_context
*ev
;
6946 struct tevent_req
*req
;
6950 if (!resolve_name(host
, &addr
, 0, false)) {
6951 d_printf("could not find host %s\n", host
);
6954 status
= open_socket_out(&addr
, 389, 9999, &fd
);
6955 if (!NT_STATUS_IS_OK(status
)) {
6956 d_printf("open_socket_out failed: %s\n", nt_errstr(status
));
6960 ld
= tldap_context_create(talloc_tos(), fd
);
6963 d_printf("tldap_context_create failed\n");
6967 rc
= tldap_fetch_rootdse(ld
);
6968 if (rc
!= TLDAP_SUCCESS
) {
6969 d_printf("tldap_fetch_rootdse failed: %s\n",
6970 tldap_errstr(talloc_tos(), ld
, rc
));
6974 basedn
= tldap_talloc_single_attribute(
6975 tldap_rootdse(ld
), "defaultNamingContext", talloc_tos());
6976 if (basedn
== NULL
) {
6977 d_printf("no defaultNamingContext\n");
6980 d_printf("defaultNamingContext: %s\n", basedn
);
6982 ev
= tevent_context_init(talloc_tos());
6984 d_printf("tevent_context_init failed\n");
6988 req
= tldap_search_paged_send(talloc_tos(), ev
, ld
, basedn
,
6989 TLDAP_SCOPE_SUB
, "(objectclass=*)",
6991 NULL
, 0, NULL
, 0, 0, 0, 0, 5);
6993 d_printf("tldap_search_paged_send failed\n");
6996 tevent_req_set_callback(req
, pagedsearch_cb
, NULL
);
6998 tevent_req_poll(req
, ev
);
7002 /* test search filters against rootDSE */
7003 filter
= "(&(|(name=samba)(nextRid<=10000000)(usnChanged>=10)(samba~=ambas)(!(name=s*m*a)))"
7004 "(|(name:=samba)(name:dn:2.5.13.5:=samba)(:dn:2.5.13.5:=samba)(!(name=*samba))))";
7006 rc
= tldap_search(ld
, "", TLDAP_SCOPE_BASE
, filter
,
7007 NULL
, 0, 0, NULL
, 0, NULL
, 0, 0, 0, 0,
7008 talloc_tos(), NULL
, NULL
);
7009 if (rc
!= TLDAP_SUCCESS
) {
7010 d_printf("tldap_search with complex filter failed: %s\n",
7011 tldap_errstr(talloc_tos(), ld
, rc
));
7019 /* Torture test to ensure no regression of :
7020 https://bugzilla.samba.org/show_bug.cgi?id=7084
7023 static bool run_dir_createtime(int dummy
)
7025 struct cli_state
*cli
;
7026 const char *dname
= "\\testdir";
7027 const char *fname
= "\\testdir\\testfile";
7029 struct timespec create_time
;
7030 struct timespec create_time1
;
7034 if (!torture_open_connection(&cli
, 0)) {
7038 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
7039 cli_rmdir(cli
, dname
);
7041 status
= cli_mkdir(cli
, dname
);
7042 if (!NT_STATUS_IS_OK(status
)) {
7043 printf("mkdir failed: %s\n", nt_errstr(status
));
7047 status
= cli_qpathinfo2(cli
, dname
, &create_time
, NULL
, NULL
, NULL
,
7049 if (!NT_STATUS_IS_OK(status
)) {
7050 printf("cli_qpathinfo2 returned %s\n",
7055 /* Sleep 3 seconds, then create a file. */
7058 status
= cli_open(cli
, fname
, O_RDWR
| O_CREAT
| O_EXCL
,
7060 if (!NT_STATUS_IS_OK(status
)) {
7061 printf("cli_open failed: %s\n", nt_errstr(status
));
7065 status
= cli_qpathinfo2(cli
, dname
, &create_time1
, NULL
, NULL
, NULL
,
7067 if (!NT_STATUS_IS_OK(status
)) {
7068 printf("cli_qpathinfo2 (2) returned %s\n",
7073 if (timespec_compare(&create_time1
, &create_time
)) {
7074 printf("run_dir_createtime: create time was updated (error)\n");
7076 printf("run_dir_createtime: create time was not updated (correct)\n");
7082 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
7083 cli_rmdir(cli
, dname
);
7084 if (!torture_close_connection(cli
)) {
7091 static bool run_streamerror(int dummy
)
7093 struct cli_state
*cli
;
7094 const char *dname
= "\\testdir";
7095 const char *streamname
=
7096 "testdir:{4c8cc155-6c1e-11d1-8e41-00c04fb9386d}:$DATA";
7098 time_t change_time
, access_time
, write_time
;
7100 uint16_t mode
, fnum
;
7103 if (!torture_open_connection(&cli
, 0)) {
7107 cli_unlink(cli
, "\\testdir\\*", FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
7108 cli_rmdir(cli
, dname
);
7110 status
= cli_mkdir(cli
, dname
);
7111 if (!NT_STATUS_IS_OK(status
)) {
7112 printf("mkdir failed: %s\n", nt_errstr(status
));
7116 cli_qpathinfo1(cli
, streamname
, &change_time
, &access_time
, &write_time
,
7118 status
= cli_nt_error(cli
);
7120 if (!NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
)) {
7121 printf("pathinfo returned %s, expected "
7122 "NT_STATUS_OBJECT_NAME_NOT_FOUND\n",
7127 status
= cli_ntcreate(cli
, streamname
, 0x16,
7128 FILE_READ_DATA
|FILE_READ_EA
|
7129 FILE_READ_ATTRIBUTES
|READ_CONTROL_ACCESS
,
7130 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_READ
,
7131 FILE_OPEN
, 0, 0, &fnum
);
7133 if (!NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
)) {
7134 printf("ntcreate returned %s, expected "
7135 "NT_STATUS_OBJECT_NAME_NOT_FOUND\n",
7141 cli_rmdir(cli
, dname
);
7145 static bool run_local_substitute(int dummy
)
7149 ok
&= subst_test("%U", "bla", "", -1, -1, "bla");
7150 ok
&= subst_test("%u%U", "bla", "", -1, -1, "blabla");
7151 ok
&= subst_test("%g", "", "", -1, -1, "NO_GROUP");
7152 ok
&= subst_test("%G", "", "", -1, -1, "NO_GROUP");
7153 ok
&= subst_test("%g", "", "", -1, 0, gidtoname(0));
7154 ok
&= subst_test("%G", "", "", -1, 0, gidtoname(0));
7155 ok
&= subst_test("%D%u", "u", "dom", -1, 0, "domu");
7156 ok
&= subst_test("%i %I", "", "", -1, -1, "0.0.0.0 0.0.0.0");
7158 /* Different captialization rules in sub_basic... */
7160 ok
&= (strcmp(talloc_sub_basic(talloc_tos(), "BLA", "dom", "%U%D"),
7166 static bool run_local_base64(int dummy
)
7171 for (i
=1; i
<2000; i
++) {
7172 DATA_BLOB blob1
, blob2
;
7175 blob1
.data
= talloc_array(talloc_tos(), uint8_t, i
);
7177 generate_random_buffer(blob1
.data
, blob1
.length
);
7179 b64
= base64_encode_data_blob(talloc_tos(), blob1
);
7181 d_fprintf(stderr
, "base64_encode_data_blob failed "
7182 "for %d bytes\n", i
);
7185 blob2
= base64_decode_data_blob(b64
);
7188 if (data_blob_cmp(&blob1
, &blob2
)) {
7189 d_fprintf(stderr
, "data_blob_cmp failed for %d "
7193 TALLOC_FREE(blob1
.data
);
7194 data_blob_free(&blob2
);
7199 static bool run_local_gencache(int dummy
)
7205 if (!gencache_set("foo", "bar", time(NULL
) + 1000)) {
7206 d_printf("%s: gencache_set() failed\n", __location__
);
7210 if (!gencache_get("foo", NULL
, NULL
)) {
7211 d_printf("%s: gencache_get() failed\n", __location__
);
7215 if (!gencache_get("foo", &val
, &tm
)) {
7216 d_printf("%s: gencache_get() failed\n", __location__
);
7220 if (strcmp(val
, "bar") != 0) {
7221 d_printf("%s: gencache_get() returned %s, expected %s\n",
7222 __location__
, val
, "bar");
7229 if (!gencache_del("foo")) {
7230 d_printf("%s: gencache_del() failed\n", __location__
);
7233 if (gencache_del("foo")) {
7234 d_printf("%s: second gencache_del() succeeded\n",
7239 if (gencache_get("foo", &val
, &tm
)) {
7240 d_printf("%s: gencache_get() on deleted entry "
7241 "succeeded\n", __location__
);
7245 blob
= data_blob_string_const_null("bar");
7246 tm
= time(NULL
) + 60;
7248 if (!gencache_set_data_blob("foo", &blob
, tm
)) {
7249 d_printf("%s: gencache_set_data_blob() failed\n", __location__
);
7253 if (!gencache_get_data_blob("foo", &blob
, NULL
, NULL
)) {
7254 d_printf("%s: gencache_get_data_blob() failed\n", __location__
);
7258 if (strcmp((const char *)blob
.data
, "bar") != 0) {
7259 d_printf("%s: gencache_get_data_blob() returned %s, expected %s\n",
7260 __location__
, (const char *)blob
.data
, "bar");
7261 data_blob_free(&blob
);
7265 data_blob_free(&blob
);
7267 if (!gencache_del("foo")) {
7268 d_printf("%s: gencache_del() failed\n", __location__
);
7271 if (gencache_del("foo")) {
7272 d_printf("%s: second gencache_del() succeeded\n",
7277 if (gencache_get_data_blob("foo", &blob
, NULL
, NULL
)) {
7278 d_printf("%s: gencache_get_data_blob() on deleted entry "
7279 "succeeded\n", __location__
);
7286 static bool rbt_testval(struct db_context
*db
, const char *key
,
7289 struct db_record
*rec
;
7290 TDB_DATA data
= string_tdb_data(value
);
7294 rec
= db
->fetch_locked(db
, db
, string_tdb_data(key
));
7296 d_fprintf(stderr
, "fetch_locked failed\n");
7299 status
= rec
->store(rec
, data
, 0);
7300 if (!NT_STATUS_IS_OK(status
)) {
7301 d_fprintf(stderr
, "store failed: %s\n", nt_errstr(status
));
7306 rec
= db
->fetch_locked(db
, db
, string_tdb_data(key
));
7308 d_fprintf(stderr
, "second fetch_locked failed\n");
7311 if ((rec
->value
.dsize
!= data
.dsize
)
7312 || (memcmp(rec
->value
.dptr
, data
.dptr
, data
.dsize
) != 0)) {
7313 d_fprintf(stderr
, "Got wrong data back\n");
7323 static bool run_local_rbtree(int dummy
)
7325 struct db_context
*db
;
7329 db
= db_open_rbt(NULL
);
7332 d_fprintf(stderr
, "db_open_rbt failed\n");
7336 for (i
=0; i
<1000; i
++) {
7339 if (asprintf(&key
, "key%ld", random()) == -1) {
7342 if (asprintf(&value
, "value%ld", random()) == -1) {
7347 if (!rbt_testval(db
, key
, value
)) {
7354 if (asprintf(&value
, "value%ld", random()) == -1) {
7359 if (!rbt_testval(db
, key
, value
)) {
7376 struct talloc_dict_test
{
7380 static int talloc_dict_traverse_fn(DATA_BLOB key
, void *data
, void *priv
)
7382 int *count
= (int *)priv
;
7387 static bool run_local_talloc_dict(int dummy
)
7389 struct talloc_dict
*dict
;
7390 struct talloc_dict_test
*t
;
7393 dict
= talloc_dict_init(talloc_tos());
7398 t
= talloc(talloc_tos(), struct talloc_dict_test
);
7405 if (!talloc_dict_set(dict
, data_blob_const(&key
, sizeof(key
)), t
)) {
7410 if (talloc_dict_traverse(dict
, talloc_dict_traverse_fn
, &count
) != 0) {
7423 static bool run_local_string_to_sid(int dummy
) {
7426 if (string_to_sid(&sid
, "S--1-5-32-545")) {
7427 printf("allowing S--1-5-32-545\n");
7430 if (string_to_sid(&sid
, "S-1-5-32-+545")) {
7431 printf("allowing S-1-5-32-+545\n");
7434 if (string_to_sid(&sid
, "S-1-2-3-4-5-6-7-8-9-0-1-2-3-4-5-6-7-8-9-0")) {
7435 printf("allowing S-1-2-3-4-5-6-7-8-9-0-1-2-3-4-5-6-7-8-9-0\n");
7438 if (string_to_sid(&sid
, "S-1-5-32-545-abc")) {
7439 printf("allowing S-1-5-32-545-abc\n");
7442 if (!string_to_sid(&sid
, "S-1-5-32-545")) {
7443 printf("could not parse S-1-5-32-545\n");
7446 if (!dom_sid_equal(&sid
, &global_sid_Builtin_Users
)) {
7447 printf("mis-parsed S-1-5-32-545 as %s\n",
7448 sid_string_tos(&sid
));
7454 static bool run_local_binary_to_sid(int dummy
) {
7455 struct dom_sid
*sid
= talloc(NULL
, struct dom_sid
);
7456 static const char good_binary_sid
[] = {
7457 0x1, /* revision number */
7459 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, /* id_auth */
7460 0x1, 0x1, 0x1, 0x1, /* auth[0] */
7461 0x1, 0x1, 0x1, 0x1, /* auth[1] */
7462 0x1, 0x1, 0x1, 0x1, /* auth[2] */
7463 0x1, 0x1, 0x1, 0x1, /* auth[3] */
7464 0x1, 0x1, 0x1, 0x1, /* auth[4] */
7465 0x1, 0x1, 0x1, 0x1, /* auth[5] */
7466 0x1, 0x1, 0x1, 0x1, /* auth[6] */
7467 0x1, 0x1, 0x1, 0x1, /* auth[7] */
7468 0x1, 0x1, 0x1, 0x1, /* auth[8] */
7469 0x1, 0x1, 0x1, 0x1, /* auth[9] */
7470 0x1, 0x1, 0x1, 0x1, /* auth[10] */
7471 0x1, 0x1, 0x1, 0x1, /* auth[11] */
7472 0x1, 0x1, 0x1, 0x1, /* auth[12] */
7473 0x1, 0x1, 0x1, 0x1, /* auth[13] */
7474 0x1, 0x1, 0x1, 0x1, /* auth[14] */
7477 static const char long_binary_sid
[] = {
7478 0x1, /* revision number */
7480 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, /* id_auth */
7481 0x1, 0x1, 0x1, 0x1, /* auth[0] */
7482 0x1, 0x1, 0x1, 0x1, /* auth[1] */
7483 0x1, 0x1, 0x1, 0x1, /* auth[2] */
7484 0x1, 0x1, 0x1, 0x1, /* auth[3] */
7485 0x1, 0x1, 0x1, 0x1, /* auth[4] */
7486 0x1, 0x1, 0x1, 0x1, /* auth[5] */
7487 0x1, 0x1, 0x1, 0x1, /* auth[6] */
7488 0x1, 0x1, 0x1, 0x1, /* auth[7] */
7489 0x1, 0x1, 0x1, 0x1, /* auth[8] */
7490 0x1, 0x1, 0x1, 0x1, /* auth[9] */
7491 0x1, 0x1, 0x1, 0x1, /* auth[10] */
7492 0x1, 0x1, 0x1, 0x1, /* auth[11] */
7493 0x1, 0x1, 0x1, 0x1, /* auth[12] */
7494 0x1, 0x1, 0x1, 0x1, /* auth[13] */
7495 0x1, 0x1, 0x1, 0x1, /* auth[14] */
7496 0x1, 0x1, 0x1, 0x1, /* auth[15] */
7497 0x1, 0x1, 0x1, 0x1, /* auth[16] */
7498 0x1, 0x1, 0x1, 0x1, /* auth[17] */
7501 static const char long_binary_sid2
[] = {
7502 0x1, /* revision number */
7504 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, /* id_auth */
7505 0x1, 0x1, 0x1, 0x1, /* auth[0] */
7506 0x1, 0x1, 0x1, 0x1, /* auth[1] */
7507 0x1, 0x1, 0x1, 0x1, /* auth[2] */
7508 0x1, 0x1, 0x1, 0x1, /* auth[3] */
7509 0x1, 0x1, 0x1, 0x1, /* auth[4] */
7510 0x1, 0x1, 0x1, 0x1, /* auth[5] */
7511 0x1, 0x1, 0x1, 0x1, /* auth[6] */
7512 0x1, 0x1, 0x1, 0x1, /* auth[7] */
7513 0x1, 0x1, 0x1, 0x1, /* auth[8] */
7514 0x1, 0x1, 0x1, 0x1, /* auth[9] */
7515 0x1, 0x1, 0x1, 0x1, /* auth[10] */
7516 0x1, 0x1, 0x1, 0x1, /* auth[11] */
7517 0x1, 0x1, 0x1, 0x1, /* auth[12] */
7518 0x1, 0x1, 0x1, 0x1, /* auth[13] */
7519 0x1, 0x1, 0x1, 0x1, /* auth[14] */
7520 0x1, 0x1, 0x1, 0x1, /* auth[15] */
7521 0x1, 0x1, 0x1, 0x1, /* auth[16] */
7522 0x1, 0x1, 0x1, 0x1, /* auth[17] */
7523 0x1, 0x1, 0x1, 0x1, /* auth[18] */
7524 0x1, 0x1, 0x1, 0x1, /* auth[19] */
7525 0x1, 0x1, 0x1, 0x1, /* auth[20] */
7526 0x1, 0x1, 0x1, 0x1, /* auth[21] */
7527 0x1, 0x1, 0x1, 0x1, /* auth[22] */
7528 0x1, 0x1, 0x1, 0x1, /* auth[23] */
7529 0x1, 0x1, 0x1, 0x1, /* auth[24] */
7530 0x1, 0x1, 0x1, 0x1, /* auth[25] */
7531 0x1, 0x1, 0x1, 0x1, /* auth[26] */
7532 0x1, 0x1, 0x1, 0x1, /* auth[27] */
7533 0x1, 0x1, 0x1, 0x1, /* auth[28] */
7534 0x1, 0x1, 0x1, 0x1, /* auth[29] */
7535 0x1, 0x1, 0x1, 0x1, /* auth[30] */
7536 0x1, 0x1, 0x1, 0x1, /* auth[31] */
7539 if (!sid_parse(good_binary_sid
, sizeof(good_binary_sid
), sid
)) {
7542 if (sid_parse(long_binary_sid2
, sizeof(long_binary_sid2
), sid
)) {
7545 if (sid_parse(long_binary_sid
, sizeof(long_binary_sid
), sid
)) {
7551 /* Split a path name into filename and stream name components. Canonicalise
7552 * such that an implicit $DATA token is always explicit.
7554 * The "specification" of this function can be found in the
7555 * run_local_stream_name() function in torture.c, I've tried those
7556 * combinations against a W2k3 server.
7559 static NTSTATUS
split_ntfs_stream_name(TALLOC_CTX
*mem_ctx
, const char *fname
,
7560 char **pbase
, char **pstream
)
7563 char *stream
= NULL
;
7564 char *sname
; /* stream name */
7565 const char *stype
; /* stream type */
7567 DEBUG(10, ("split_ntfs_stream_name called for [%s]\n", fname
));
7569 sname
= strchr_m(fname
, ':');
7571 if (lp_posix_pathnames() || (sname
== NULL
)) {
7572 if (pbase
!= NULL
) {
7573 base
= talloc_strdup(mem_ctx
, fname
);
7574 NT_STATUS_HAVE_NO_MEMORY(base
);
7579 if (pbase
!= NULL
) {
7580 base
= talloc_strndup(mem_ctx
, fname
, PTR_DIFF(sname
, fname
));
7581 NT_STATUS_HAVE_NO_MEMORY(base
);
7586 stype
= strchr_m(sname
, ':');
7588 if (stype
== NULL
) {
7589 sname
= talloc_strdup(mem_ctx
, sname
);
7593 if (StrCaseCmp(stype
, ":$DATA") != 0) {
7595 * If there is an explicit stream type, so far we only
7596 * allow $DATA. Is there anything else allowed? -- vl
7598 DEBUG(10, ("[%s] is an invalid stream type\n", stype
));
7600 return NT_STATUS_OBJECT_NAME_INVALID
;
7602 sname
= talloc_strndup(mem_ctx
, sname
, PTR_DIFF(stype
, sname
));
7606 if (sname
== NULL
) {
7608 return NT_STATUS_NO_MEMORY
;
7611 if (sname
[0] == '\0') {
7613 * no stream name, so no stream
7618 if (pstream
!= NULL
) {
7619 stream
= talloc_asprintf(mem_ctx
, "%s:%s", sname
, stype
);
7620 if (stream
== NULL
) {
7623 return NT_STATUS_NO_MEMORY
;
7626 * upper-case the type field
7628 strupper_m(strchr_m(stream
, ':')+1);
7632 if (pbase
!= NULL
) {
7635 if (pstream
!= NULL
) {
7638 return NT_STATUS_OK
;
7641 static bool test_stream_name(const char *fname
, const char *expected_base
,
7642 const char *expected_stream
,
7643 NTSTATUS expected_status
)
7647 char *stream
= NULL
;
7649 status
= split_ntfs_stream_name(talloc_tos(), fname
, &base
, &stream
);
7650 if (!NT_STATUS_EQUAL(status
, expected_status
)) {
7654 if (!NT_STATUS_IS_OK(status
)) {
7658 if (base
== NULL
) goto error
;
7660 if (strcmp(expected_base
, base
) != 0) goto error
;
7662 if ((expected_stream
!= NULL
) && (stream
== NULL
)) goto error
;
7663 if ((expected_stream
== NULL
) && (stream
!= NULL
)) goto error
;
7665 if ((stream
!= NULL
) && (strcmp(expected_stream
, stream
) != 0))
7669 TALLOC_FREE(stream
);
7673 d_fprintf(stderr
, "Do test_stream(%s, %s, %s, %s)\n",
7674 fname
, expected_base
? expected_base
: "<NULL>",
7675 expected_stream
? expected_stream
: "<NULL>",
7676 nt_errstr(expected_status
));
7677 d_fprintf(stderr
, "-> base=%s, stream=%s, status=%s\n",
7678 base
? base
: "<NULL>", stream
? stream
: "<NULL>",
7681 TALLOC_FREE(stream
);
7685 static bool run_local_stream_name(int dummy
)
7689 ret
&= test_stream_name(
7690 "bla", "bla", NULL
, NT_STATUS_OK
);
7691 ret
&= test_stream_name(
7692 "bla::$DATA", "bla", NULL
, NT_STATUS_OK
);
7693 ret
&= test_stream_name(
7694 "bla:blub:", "bla", NULL
, NT_STATUS_OBJECT_NAME_INVALID
);
7695 ret
&= test_stream_name(
7696 "bla::", NULL
, NULL
, NT_STATUS_OBJECT_NAME_INVALID
);
7697 ret
&= test_stream_name(
7698 "bla::123", "bla", NULL
, NT_STATUS_OBJECT_NAME_INVALID
);
7699 ret
&= test_stream_name(
7700 "bla:$DATA", "bla", "$DATA:$DATA", NT_STATUS_OK
);
7701 ret
&= test_stream_name(
7702 "bla:x:$DATA", "bla", "x:$DATA", NT_STATUS_OK
);
7703 ret
&= test_stream_name(
7704 "bla:x", "bla", "x:$DATA", NT_STATUS_OK
);
7709 static bool data_blob_equal(DATA_BLOB a
, DATA_BLOB b
)
7711 if (a
.length
!= b
.length
) {
7712 printf("a.length=%d != b.length=%d\n",
7713 (int)a
.length
, (int)b
.length
);
7716 if (memcmp(a
.data
, b
.data
, a
.length
) != 0) {
7717 printf("a.data and b.data differ\n");
7723 static bool run_local_memcache(int dummy
)
7725 struct memcache
*cache
;
7727 DATA_BLOB d1
, d2
, d3
;
7728 DATA_BLOB v1
, v2
, v3
;
7730 TALLOC_CTX
*mem_ctx
;
7732 size_t size1
, size2
;
7735 cache
= memcache_init(NULL
, 100);
7737 if (cache
== NULL
) {
7738 printf("memcache_init failed\n");
7742 d1
= data_blob_const("d1", 2);
7743 d2
= data_blob_const("d2", 2);
7744 d3
= data_blob_const("d3", 2);
7746 k1
= data_blob_const("d1", 2);
7747 k2
= data_blob_const("d2", 2);
7749 memcache_add(cache
, STAT_CACHE
, k1
, d1
);
7750 memcache_add(cache
, GETWD_CACHE
, k2
, d2
);
7752 if (!memcache_lookup(cache
, STAT_CACHE
, k1
, &v1
)) {
7753 printf("could not find k1\n");
7756 if (!data_blob_equal(d1
, v1
)) {
7760 if (!memcache_lookup(cache
, GETWD_CACHE
, k2
, &v2
)) {
7761 printf("could not find k2\n");
7764 if (!data_blob_equal(d2
, v2
)) {
7768 memcache_add(cache
, STAT_CACHE
, k1
, d3
);
7770 if (!memcache_lookup(cache
, STAT_CACHE
, k1
, &v3
)) {
7771 printf("could not find replaced k1\n");
7774 if (!data_blob_equal(d3
, v3
)) {
7778 memcache_add(cache
, GETWD_CACHE
, k1
, d1
);
7780 if (memcache_lookup(cache
, GETWD_CACHE
, k2
, &v2
)) {
7781 printf("Did find k2, should have been purged\n");
7787 cache
= memcache_init(NULL
, 0);
7789 mem_ctx
= talloc_init("foo");
7791 str1
= talloc_strdup(mem_ctx
, "string1");
7792 str2
= talloc_strdup(mem_ctx
, "string2");
7794 memcache_add_talloc(cache
, SINGLETON_CACHE_TALLOC
,
7795 data_blob_string_const("torture"), &str1
);
7796 size1
= talloc_total_size(cache
);
7798 memcache_add_talloc(cache
, SINGLETON_CACHE_TALLOC
,
7799 data_blob_string_const("torture"), &str2
);
7800 size2
= talloc_total_size(cache
);
7802 printf("size1=%d, size2=%d\n", (int)size1
, (int)size2
);
7804 if (size2
> size1
) {
7805 printf("memcache leaks memory!\n");
7815 static void wbclient_done(struct tevent_req
*req
)
7818 struct winbindd_response
*wb_resp
;
7819 int *i
= (int *)tevent_req_callback_data_void(req
);
7821 wbc_err
= wb_trans_recv(req
, req
, &wb_resp
);
7824 d_printf("wb_trans_recv %d returned %s\n", *i
, wbcErrorString(wbc_err
));
7827 static bool run_local_wbclient(int dummy
)
7829 struct event_context
*ev
;
7830 struct wb_context
**wb_ctx
;
7831 struct winbindd_request wb_req
;
7832 bool result
= false;
7835 BlockSignals(True
, SIGPIPE
);
7837 ev
= tevent_context_init_byname(talloc_tos(), "epoll");
7842 wb_ctx
= TALLOC_ARRAY(ev
, struct wb_context
*, nprocs
);
7843 if (wb_ctx
== NULL
) {
7847 ZERO_STRUCT(wb_req
);
7848 wb_req
.cmd
= WINBINDD_PING
;
7850 d_printf("nprocs=%d, numops=%d\n", (int)nprocs
, (int)torture_numops
);
7852 for (i
=0; i
<nprocs
; i
++) {
7853 wb_ctx
[i
] = wb_context_init(ev
, NULL
);
7854 if (wb_ctx
[i
] == NULL
) {
7857 for (j
=0; j
<torture_numops
; j
++) {
7858 struct tevent_req
*req
;
7859 req
= wb_trans_send(ev
, ev
, wb_ctx
[i
],
7860 (j
% 2) == 0, &wb_req
);
7864 tevent_req_set_callback(req
, wbclient_done
, &i
);
7870 while (i
< nprocs
* torture_numops
) {
7871 event_loop_once(ev
);
7880 static void getaddrinfo_finished(struct tevent_req
*req
)
7882 char *name
= (char *)tevent_req_callback_data_void(req
);
7883 struct addrinfo
*ainfo
;
7886 res
= getaddrinfo_recv(req
, &ainfo
);
7888 d_printf("gai(%s) returned %s\n", name
, gai_strerror(res
));
7891 d_printf("gai(%s) succeeded\n", name
);
7892 freeaddrinfo(ainfo
);
7895 static bool run_getaddrinfo_send(int dummy
)
7897 TALLOC_CTX
*frame
= talloc_stackframe();
7898 struct fncall_context
*ctx
;
7899 struct tevent_context
*ev
;
7900 bool result
= false;
7901 const char *names
[4] = { "www.samba.org", "notfound.samba.org",
7902 "www.slashdot.org", "heise.de" };
7903 struct tevent_req
*reqs
[4];
7906 ev
= event_context_init(frame
);
7911 ctx
= fncall_context_init(frame
, 4);
7913 for (i
=0; i
<ARRAY_SIZE(names
); i
++) {
7914 reqs
[i
] = getaddrinfo_send(frame
, ev
, ctx
, names
[i
], NULL
,
7916 if (reqs
[i
] == NULL
) {
7919 tevent_req_set_callback(reqs
[i
], getaddrinfo_finished
,
7923 for (i
=0; i
<ARRAY_SIZE(reqs
); i
++) {
7924 tevent_loop_once(ev
);
7933 static bool dbtrans_inc(struct db_context
*db
)
7935 struct db_record
*rec
;
7940 rec
= db
->fetch_locked(db
, db
, string_term_tdb_data("transtest"));
7942 printf(__location__
"fetch_lock failed\n");
7946 if (rec
->value
.dsize
!= sizeof(uint32_t)) {
7947 printf(__location__
"value.dsize = %d\n",
7948 (int)rec
->value
.dsize
);
7952 val
= (uint32_t *)rec
->value
.dptr
;
7955 status
= rec
->store(rec
, make_tdb_data((uint8_t *)val
,
7958 if (!NT_STATUS_IS_OK(status
)) {
7959 printf(__location__
"store failed: %s\n",
7970 static bool run_local_dbtrans(int dummy
)
7972 struct db_context
*db
;
7973 struct db_record
*rec
;
7978 db
= db_open(talloc_tos(), "transtest.tdb", 0, TDB_DEFAULT
,
7979 O_RDWR
|O_CREAT
, 0600);
7981 printf("Could not open transtest.db\n");
7985 res
= db
->transaction_start(db
);
7987 printf(__location__
"transaction_start failed\n");
7991 rec
= db
->fetch_locked(db
, db
, string_term_tdb_data("transtest"));
7993 printf(__location__
"fetch_lock failed\n");
7997 if (rec
->value
.dptr
== NULL
) {
7999 status
= rec
->store(
8000 rec
, make_tdb_data((uint8_t *)&initial
,
8003 if (!NT_STATUS_IS_OK(status
)) {
8004 printf(__location__
"store returned %s\n",
8012 res
= db
->transaction_commit(db
);
8014 printf(__location__
"transaction_commit failed\n");
8022 res
= db
->transaction_start(db
);
8024 printf(__location__
"transaction_start failed\n");
8028 if (!dbwrap_fetch_uint32(db
, "transtest", &val
)) {
8029 printf(__location__
"dbwrap_fetch_uint32 failed\n");
8033 for (i
=0; i
<10; i
++) {
8034 if (!dbtrans_inc(db
)) {
8039 if (!dbwrap_fetch_uint32(db
, "transtest", &val2
)) {
8040 printf(__location__
"dbwrap_fetch_uint32 failed\n");
8044 if (val2
!= val
+ 10) {
8045 printf(__location__
"val=%d, val2=%d\n",
8046 (int)val
, (int)val2
);
8050 printf("val2=%d\r", val2
);
8052 res
= db
->transaction_commit(db
);
8054 printf(__location__
"transaction_commit failed\n");
8064 * Just a dummy test to be run under a debugger. There's no real way
8065 * to inspect the tevent_select specific function from outside of
8069 static bool run_local_tevent_select(int dummy
)
8071 struct tevent_context
*ev
;
8072 struct tevent_fd
*fd1
, *fd2
;
8073 bool result
= false;
8075 ev
= tevent_context_init_byname(NULL
, "select");
8077 d_fprintf(stderr
, "tevent_context_init_byname failed\n");
8081 fd1
= tevent_add_fd(ev
, ev
, 2, 0, NULL
, NULL
);
8083 d_fprintf(stderr
, "tevent_add_fd failed\n");
8086 fd2
= tevent_add_fd(ev
, ev
, 3, 0, NULL
, NULL
);
8088 d_fprintf(stderr
, "tevent_add_fd failed\n");
8093 fd2
= tevent_add_fd(ev
, ev
, 1, 0, NULL
, NULL
);
8095 d_fprintf(stderr
, "tevent_add_fd failed\n");
8105 static bool run_local_tdb_opener(int dummy
)
8111 t
= tdb_open("test.tdb", 1000, TDB_CLEAR_IF_FIRST
,
8112 O_RDWR
|O_CREAT
, 0755);
8114 perror("tdb_open failed");
8125 static bool run_local_tdb_writer(int dummy
)
8131 t
= tdb_open("test.tdb", 1000, 0, O_RDWR
|O_CREAT
, 0755);
8133 perror("tdb_open failed");
8137 val
.dptr
= (uint8_t *)&v
;
8138 val
.dsize
= sizeof(v
);
8144 ret
= tdb_store(t
, val
, val
, 0);
8146 printf("%s\n", tdb_errorstr(t
));
8151 data
= tdb_fetch(t
, val
);
8152 if (data
.dptr
!= NULL
) {
8153 SAFE_FREE(data
.dptr
);
8159 static double create_procs(bool (*fn
)(int), bool *result
)
8162 volatile pid_t
*child_status
;
8163 volatile bool *child_status_out
;
8166 struct timeval start
;
8170 child_status
= (volatile pid_t
*)shm_setup(sizeof(pid_t
)*nprocs
);
8171 if (!child_status
) {
8172 printf("Failed to setup shared memory\n");
8176 child_status_out
= (volatile bool *)shm_setup(sizeof(bool)*nprocs
);
8177 if (!child_status_out
) {
8178 printf("Failed to setup result status shared memory\n");
8182 for (i
= 0; i
< nprocs
; i
++) {
8183 child_status
[i
] = 0;
8184 child_status_out
[i
] = True
;
8187 start
= timeval_current();
8189 for (i
=0;i
<nprocs
;i
++) {
8192 pid_t mypid
= getpid();
8193 sys_srandom(((int)mypid
) ^ ((int)time(NULL
)));
8195 slprintf(myname
,sizeof(myname
),"CLIENT%d", i
);
8198 if (torture_open_connection(¤t_cli
, i
)) break;
8200 printf("pid %d failed to start\n", (int)getpid());
8206 child_status
[i
] = getpid();
8208 while (child_status
[i
] && timeval_elapsed(&start
) < 5) smb_msleep(2);
8210 child_status_out
[i
] = fn(i
);
8217 for (i
=0;i
<nprocs
;i
++) {
8218 if (child_status
[i
]) synccount
++;
8220 if (synccount
== nprocs
) break;
8222 } while (timeval_elapsed(&start
) < 30);
8224 if (synccount
!= nprocs
) {
8225 printf("FAILED TO START %d CLIENTS (started %d)\n", nprocs
, synccount
);
8227 return timeval_elapsed(&start
);
8230 /* start the client load */
8231 start
= timeval_current();
8233 for (i
=0;i
<nprocs
;i
++) {
8234 child_status
[i
] = 0;
8237 printf("%d clients started\n", nprocs
);
8239 for (i
=0;i
<nprocs
;i
++) {
8240 while (waitpid(0, &status
, 0) == -1 && errno
== EINTR
) /* noop */ ;
8245 for (i
=0;i
<nprocs
;i
++) {
8246 if (!child_status_out
[i
]) {
8250 return timeval_elapsed(&start
);
8253 #define FLAG_MULTIPROC 1
8260 {"FDPASS", run_fdpasstest
, 0},
8261 {"LOCK1", run_locktest1
, 0},
8262 {"LOCK2", run_locktest2
, 0},
8263 {"LOCK3", run_locktest3
, 0},
8264 {"LOCK4", run_locktest4
, 0},
8265 {"LOCK5", run_locktest5
, 0},
8266 {"LOCK6", run_locktest6
, 0},
8267 {"LOCK7", run_locktest7
, 0},
8268 {"LOCK8", run_locktest8
, 0},
8269 {"LOCK9", run_locktest9
, 0},
8270 {"UNLINK", run_unlinktest
, 0},
8271 {"BROWSE", run_browsetest
, 0},
8272 {"ATTR", run_attrtest
, 0},
8273 {"TRANS2", run_trans2test
, 0},
8274 {"MAXFID", run_maxfidtest
, FLAG_MULTIPROC
},
8275 {"TORTURE",run_torture
, FLAG_MULTIPROC
},
8276 {"RANDOMIPC", run_randomipc
, 0},
8277 {"NEGNOWAIT", run_negprot_nowait
, 0},
8278 {"NBENCH", run_nbench
, 0},
8279 {"NBENCH2", run_nbench2
, 0},
8280 {"OPLOCK1", run_oplock1
, 0},
8281 {"OPLOCK2", run_oplock2
, 0},
8282 {"OPLOCK3", run_oplock3
, 0},
8283 {"OPLOCK4", run_oplock4
, 0},
8284 {"DIR", run_dirtest
, 0},
8285 {"DIR1", run_dirtest1
, 0},
8286 {"DIR-CREATETIME", run_dir_createtime
, 0},
8287 {"DENY1", torture_denytest1
, 0},
8288 {"DENY2", torture_denytest2
, 0},
8289 {"TCON", run_tcon_test
, 0},
8290 {"TCONDEV", run_tcon_devtype_test
, 0},
8291 {"RW1", run_readwritetest
, 0},
8292 {"RW2", run_readwritemulti
, FLAG_MULTIPROC
},
8293 {"RW3", run_readwritelarge
, 0},
8294 {"RW-SIGNING", run_readwritelarge_signtest
, 0},
8295 {"OPEN", run_opentest
, 0},
8296 {"POSIX", run_simple_posix_open_test
, 0},
8297 {"POSIX-APPEND", run_posix_append
, 0},
8298 {"ASYNC-ECHO", run_async_echo
, 0},
8299 { "UID-REGRESSION-TEST", run_uid_regression_test
, 0},
8300 { "SHORTNAME-TEST", run_shortname_test
, 0},
8301 { "ADDRCHANGE", run_addrchange
, 0},
8303 {"OPENATTR", run_openattrtest
, 0},
8305 {"XCOPY", run_xcopy
, 0},
8306 {"RENAME", run_rename
, 0},
8307 {"DELETE", run_deletetest
, 0},
8308 {"DELETE-LN", run_deletetest_ln
, 0},
8309 {"PROPERTIES", run_properties
, 0},
8310 {"MANGLE", torture_mangle
, 0},
8311 {"MANGLE1", run_mangle1
, 0},
8312 {"W2K", run_w2ktest
, 0},
8313 {"TRANS2SCAN", torture_trans2_scan
, 0},
8314 {"NTTRANSSCAN", torture_nttrans_scan
, 0},
8315 {"UTABLE", torture_utable
, 0},
8316 {"CASETABLE", torture_casetable
, 0},
8317 {"ERRMAPEXTRACT", run_error_map_extract
, 0},
8318 {"PIPE_NUMBER", run_pipe_number
, 0},
8319 {"TCON2", run_tcon2_test
, 0},
8320 {"IOCTL", torture_ioctl_test
, 0},
8321 {"CHKPATH", torture_chkpath_test
, 0},
8322 {"FDSESS", run_fdsesstest
, 0},
8323 { "EATEST", run_eatest
, 0},
8324 { "SESSSETUP_BENCH", run_sesssetup_bench
, 0},
8325 { "CHAIN1", run_chain1
, 0},
8326 { "CHAIN2", run_chain2
, 0},
8327 { "WINDOWS-WRITE", run_windows_write
, 0},
8328 { "CLI_ECHO", run_cli_echo
, 0},
8329 { "GETADDRINFO", run_getaddrinfo_send
, 0},
8330 { "TLDAP", run_tldap
},
8331 { "STREAMERROR", run_streamerror
},
8332 { "NOTIFY-BENCH", run_notify_bench
},
8333 { "BAD-NBT-SESSION", run_bad_nbt_session
},
8334 { "SMB-ANY-CONNECT", run_smb_any_connect
},
8335 { "LOCAL-SUBSTITUTE", run_local_substitute
, 0},
8336 { "LOCAL-GENCACHE", run_local_gencache
, 0},
8337 { "LOCAL-TALLOC-DICT", run_local_talloc_dict
, 0},
8338 { "LOCAL-BASE64", run_local_base64
, 0},
8339 { "LOCAL-RBTREE", run_local_rbtree
, 0},
8340 { "LOCAL-MEMCACHE", run_local_memcache
, 0},
8341 { "LOCAL-STREAM-NAME", run_local_stream_name
, 0},
8342 { "LOCAL-WBCLIENT", run_local_wbclient
, 0},
8343 { "LOCAL-string_to_sid", run_local_string_to_sid
, 0},
8344 { "LOCAL-binary_to_sid", run_local_binary_to_sid
, 0},
8345 { "LOCAL-DBTRANS", run_local_dbtrans
, 0},
8346 { "LOCAL-TEVENT-SELECT", run_local_tevent_select
, 0},
8347 { "LOCAL-TDB-OPENER", run_local_tdb_opener
, 0 },
8348 { "LOCAL-TDB-WRITER", run_local_tdb_writer
, 0 },
8353 /****************************************************************************
8354 run a specified test or "ALL"
8355 ****************************************************************************/
8356 static bool run_test(const char *name
)
8363 if (strequal(name
,"ALL")) {
8364 for (i
=0;torture_ops
[i
].name
;i
++) {
8365 run_test(torture_ops
[i
].name
);
8370 for (i
=0;torture_ops
[i
].name
;i
++) {
8371 fstr_sprintf(randomfname
, "\\XX%x",
8372 (unsigned)random());
8374 if (strequal(name
, torture_ops
[i
].name
)) {
8376 printf("Running %s\n", name
);
8377 if (torture_ops
[i
].flags
& FLAG_MULTIPROC
) {
8378 t
= create_procs(torture_ops
[i
].fn
, &result
);
8381 printf("TEST %s FAILED!\n", name
);
8384 struct timeval start
;
8385 start
= timeval_current();
8386 if (!torture_ops
[i
].fn(0)) {
8388 printf("TEST %s FAILED!\n", name
);
8390 t
= timeval_elapsed(&start
);
8392 printf("%s took %g secs\n\n", name
, t
);
8397 printf("Did not find a test named %s\n", name
);
8405 static void usage(void)
8409 printf("WARNING samba4 test suite is much more complete nowadays.\n");
8410 printf("Please use samba4 torture.\n\n");
8412 printf("Usage: smbtorture //server/share <options> TEST1 TEST2 ...\n");
8414 printf("\t-d debuglevel\n");
8415 printf("\t-U user%%pass\n");
8416 printf("\t-k use kerberos\n");
8417 printf("\t-N numprocs\n");
8418 printf("\t-n my_netbios_name\n");
8419 printf("\t-W workgroup\n");
8420 printf("\t-o num_operations\n");
8421 printf("\t-O socket_options\n");
8422 printf("\t-m maximum protocol\n");
8423 printf("\t-L use oplocks\n");
8424 printf("\t-c CLIENT.TXT specify client load file for NBENCH\n");
8425 printf("\t-A showall\n");
8426 printf("\t-p port\n");
8427 printf("\t-s seed\n");
8428 printf("\t-b unclist_filename specify multiple shares for multiple connections\n");
8431 printf("tests are:");
8432 for (i
=0;torture_ops
[i
].name
;i
++) {
8433 printf(" %s", torture_ops
[i
].name
);
8437 printf("default test is ALL\n");
8442 /****************************************************************************
8444 ****************************************************************************/
8445 int main(int argc
,char *argv
[])
8451 bool correct
= True
;
8452 TALLOC_CTX
*frame
= talloc_stackframe();
8453 int seed
= time(NULL
);
8455 #ifdef HAVE_SETBUFFER
8456 setbuffer(stdout
, NULL
, 0);
8459 setup_logging("smbtorture", DEBUG_STDOUT
);
8463 if (is_default_dyn_CONFIGFILE()) {
8464 if(getenv("SMB_CONF_PATH")) {
8465 set_dyn_CONFIGFILE(getenv("SMB_CONF_PATH"));
8468 lp_load(get_dyn_CONFIGFILE(),True
,False
,False
,True
);
8475 for(p
= argv
[1]; *p
; p
++)
8479 if (strncmp(argv
[1], "//", 2)) {
8483 fstrcpy(host
, &argv
[1][2]);
8484 p
= strchr_m(&host
[2],'/');
8489 fstrcpy(share
, p
+1);
8491 fstrcpy(myname
, get_myname(talloc_tos()));
8493 fprintf(stderr
, "Failed to get my hostname.\n");
8497 if (*username
== 0 && getenv("LOGNAME")) {
8498 fstrcpy(username
,getenv("LOGNAME"));
8504 fstrcpy(workgroup
, lp_workgroup());
8506 while ((opt
= getopt(argc
, argv
, "p:hW:U:n:N:O:o:m:Ll:d:Aec:ks:b:B:")) != EOF
) {
8509 port_to_use
= atoi(optarg
);
8512 seed
= atoi(optarg
);
8515 fstrcpy(workgroup
,optarg
);
8518 max_protocol
= interpret_protocol(optarg
, max_protocol
);
8521 nprocs
= atoi(optarg
);
8524 torture_numops
= atoi(optarg
);
8527 lp_set_cmdline("log level", optarg
);
8536 local_path
= optarg
;
8539 torture_showall
= True
;
8542 fstrcpy(myname
, optarg
);
8545 client_txt
= optarg
;
8552 use_kerberos
= True
;
8554 d_printf("No kerberos support compiled in\n");
8560 fstrcpy(username
,optarg
);
8561 p
= strchr_m(username
,'%');
8564 fstrcpy(password
, p
+1);
8569 fstrcpy(multishare_conn_fname
, optarg
);
8570 use_multishare_conn
= True
;
8573 torture_blocksize
= atoi(optarg
);
8576 printf("Unknown option %c (%d)\n", (char)opt
, opt
);
8581 d_printf("using seed %d\n", seed
);
8585 if(use_kerberos
&& !gotuser
) gotpass
= True
;
8588 p
= getpass("Password:");
8590 fstrcpy(password
, p
);
8595 printf("host=%s share=%s user=%s myname=%s\n",
8596 host
, share
, username
, myname
);
8598 if (argc
== optind
) {
8599 correct
= run_test("ALL");
8601 for (i
=optind
;i
<argc
;i
++) {
8602 if (!run_test(argv
[i
])) {