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 "wbc_async.h"
23 #include "torture/proto.h"
24 #include "libcli/security/security.h"
26 #include "tldap_util.h"
27 #include "../librpc/gen_ndr/svcctl.h"
29 #include "nsswitch/winbind_client.h"
31 #include "talloc_dict.h"
32 #include "async_smb.h"
37 static fstring host
, workgroup
, share
, password
, username
, myname
;
38 static int max_protocol
= PROTOCOL_NT1
;
39 static const char *sockops
="TCP_NODELAY";
41 static int port_to_use
=0;
42 int torture_numops
=100;
43 int torture_blocksize
=1024*1024;
44 static int procnum
; /* records process count number when forking */
45 static struct cli_state
*current_cli
;
46 static fstring randomfname
;
47 static bool use_oplocks
;
48 static bool use_level_II_oplocks
;
49 static const char *client_txt
= "client_oplocks.txt";
50 static bool use_kerberos
;
51 static fstring multishare_conn_fname
;
52 static bool use_multishare_conn
= False
;
53 static bool do_encrypt
;
54 static const char *local_path
= NULL
;
55 static int signing_state
= Undefined
;
57 bool torture_showall
= False
;
59 static double create_procs(bool (*fn
)(int), bool *result
);
62 /* return a pointer to a anonymous shared memory segment of size "size"
63 which will persist across fork() but will disappear when all processes
66 The memory is not zeroed
68 This function uses system5 shared memory. It takes advantage of a property
69 that the memory is not destroyed if it is attached when the id is removed
71 void *shm_setup(int size
)
77 shmid
= shm_open("private", O_RDWR
| O_CREAT
| O_EXCL
, S_IRUSR
| S_IWUSR
);
79 printf("can't get shared memory\n");
82 shm_unlink("private");
83 if (ftruncate(shmid
, size
) == -1) {
84 printf("can't set shared memory size\n");
87 ret
= mmap(0, size
, PROT_READ
| PROT_WRITE
, MAP_SHARED
, shmid
, 0);
88 if (ret
== MAP_FAILED
) {
89 printf("can't map shared memory\n");
93 shmid
= shmget(IPC_PRIVATE
, size
, S_IRUSR
| S_IWUSR
);
95 printf("can't get shared memory\n");
98 ret
= (void *)shmat(shmid
, 0, 0);
99 if (!ret
|| ret
== (void *)-1) {
100 printf("can't attach to shared memory\n");
103 /* the following releases the ipc, but note that this process
104 and all its children will still have access to the memory, its
105 just that the shmid is no longer valid for other shm calls. This
106 means we don't leave behind lots of shm segments after we exit
108 See Stevens "advanced programming in unix env" for details
110 shmctl(shmid
, IPC_RMID
, 0);
116 /********************************************************************
117 Ensure a connection is encrypted.
118 ********************************************************************/
120 static bool force_cli_encryption(struct cli_state
*c
,
121 const char *sharename
)
124 uint32 caplow
, caphigh
;
127 if (!SERVER_HAS_UNIX_CIFS(c
)) {
128 d_printf("Encryption required and "
129 "server that doesn't support "
130 "UNIX extensions - failing connect\n");
134 status
= cli_unix_extensions_version(c
, &major
, &minor
, &caplow
,
136 if (!NT_STATUS_IS_OK(status
)) {
137 d_printf("Encryption required and "
138 "can't get UNIX CIFS extensions "
139 "version from server: %s\n", nt_errstr(status
));
143 if (!(caplow
& CIFS_UNIX_TRANSPORT_ENCRYPTION_CAP
)) {
144 d_printf("Encryption required and "
145 "share %s doesn't support "
146 "encryption.\n", sharename
);
150 if (c
->use_kerberos
) {
151 status
= cli_gss_smb_encryption_start(c
);
153 status
= cli_raw_ntlm_smb_encryption_start(c
,
159 if (!NT_STATUS_IS_OK(status
)) {
160 d_printf("Encryption required and "
161 "setup failed with error %s.\n",
170 static struct cli_state
*open_nbt_connection(void)
172 struct nmb_name called
, calling
;
173 struct sockaddr_storage ss
;
177 make_nmb_name(&calling
, myname
, 0x0);
178 make_nmb_name(&called
, host
, 0x20);
182 if (!(c
= cli_initialise_ex(signing_state
))) {
183 printf("Failed initialize cli_struct to connect with %s\n", host
);
187 c
->port
= port_to_use
;
189 status
= cli_connect(c
, host
, &ss
);
190 if (!NT_STATUS_IS_OK(status
)) {
191 printf("Failed to connect with %s. Error %s\n", host
, nt_errstr(status
) );
195 c
->use_kerberos
= use_kerberos
;
197 c
->timeout
= 120000; /* set a really long timeout (2 minutes) */
198 if (use_oplocks
) c
->use_oplocks
= True
;
199 if (use_level_II_oplocks
) c
->use_level_II_oplocks
= True
;
201 if (!cli_session_request(c
, &calling
, &called
)) {
203 * Well, that failed, try *SMBSERVER ...
204 * However, we must reconnect as well ...
206 status
= cli_connect(c
, host
, &ss
);
207 if (!NT_STATUS_IS_OK(status
)) {
208 printf("Failed to connect with %s. Error %s\n", host
, nt_errstr(status
) );
212 make_nmb_name(&called
, "*SMBSERVER", 0x20);
213 if (!cli_session_request(c
, &calling
, &called
)) {
214 printf("%s rejected the session\n",host
);
215 printf("We tried with a called name of %s & %s\n",
225 /****************************************************************************
226 Send a corrupt session request. See rfc1002.txt 4.3 and 4.3.2.
227 ****************************************************************************/
229 static bool cli_bad_session_request(struct cli_state
*cli
,
230 struct nmb_name
*calling
, struct nmb_name
*called
)
237 memcpy(&(cli
->calling
), calling
, sizeof(*calling
));
238 memcpy(&(cli
->called
), called
, sizeof(*called
));
240 /* put in the destination name */
242 tmp
= name_mangle(talloc_tos(), cli
->called
.name
,
243 cli
->called
.name_type
);
249 namelen
= name_len((unsigned char *)tmp
, talloc_get_size(tmp
));
251 memcpy(p
, tmp
, namelen
);
256 /* Deliberately corrupt the name len (first byte) */
261 tmp
= name_mangle(talloc_tos(), cli
->calling
.name
,
262 cli
->calling
.name_type
);
268 namelen
= name_len((unsigned char *)tmp
, talloc_get_size(tmp
));
270 memcpy(p
, tmp
, namelen
);
274 /* Deliberately corrupt the name len (first byte) */
277 /* send a session request (RFC 1002) */
278 /* setup the packet length
279 * Remove four bytes from the length count, since the length
280 * field in the NBT Session Service header counts the number
281 * of bytes which follow. The cli_send_smb() function knows
282 * about this and accounts for those four bytes.
286 _smb_setlen(cli
->outbuf
,len
);
287 SCVAL(cli
->outbuf
,0,0x81);
290 DEBUG(5,("Sent session request\n"));
292 if (!cli_receive_smb(cli
))
295 if (CVAL(cli
->inbuf
,0) != 0x82) {
296 /* This is the wrong place to put the error... JRA. */
297 cli
->rap_error
= CVAL(cli
->inbuf
,4);
303 static struct cli_state
*open_bad_nbt_connection(void)
305 struct nmb_name called
, calling
;
306 struct sockaddr_storage ss
;
310 make_nmb_name(&calling
, myname
, 0x0);
311 make_nmb_name(&called
, host
, 0x20);
315 if (!(c
= cli_initialise_ex(signing_state
))) {
316 printf("Failed initialize cli_struct to connect with %s\n", host
);
322 status
= cli_connect(c
, host
, &ss
);
323 if (!NT_STATUS_IS_OK(status
)) {
324 printf("Failed to connect with %s. Error %s\n", host
, nt_errstr(status
) );
328 c
->timeout
= 4000; /* set a short timeout (4 seconds) */
330 if (!cli_bad_session_request(c
, &calling
, &called
)) {
331 printf("Failed to connect with %s. Error %s\n", host
, nt_errstr(status
) );
339 /* Insert a NULL at the first separator of the given path and return a pointer
340 * to the remainder of the string.
343 terminate_path_at_separator(char * path
)
351 if ((p
= strchr_m(path
, '/'))) {
356 if ((p
= strchr_m(path
, '\\'))) {
366 parse a //server/share type UNC name
368 bool smbcli_parse_unc(const char *unc_name
, TALLOC_CTX
*mem_ctx
,
369 char **hostname
, char **sharename
)
373 *hostname
= *sharename
= NULL
;
375 if (strncmp(unc_name
, "\\\\", 2) &&
376 strncmp(unc_name
, "//", 2)) {
380 *hostname
= talloc_strdup(mem_ctx
, &unc_name
[2]);
381 p
= terminate_path_at_separator(*hostname
);
384 *sharename
= talloc_strdup(mem_ctx
, p
);
385 terminate_path_at_separator(*sharename
);
388 if (*hostname
&& *sharename
) {
392 TALLOC_FREE(*hostname
);
393 TALLOC_FREE(*sharename
);
397 static bool torture_open_connection_share(struct cli_state
**c
,
398 const char *hostname
,
399 const char *sharename
)
405 flags
|= CLI_FULL_CONNECTION_USE_KERBEROS
;
407 flags
|= CLI_FULL_CONNECTION_OPLOCKS
;
408 if (use_level_II_oplocks
)
409 flags
|= CLI_FULL_CONNECTION_LEVEL_II_OPLOCKS
;
411 status
= cli_full_connection(c
, myname
,
412 hostname
, NULL
, port_to_use
,
415 password
, flags
, signing_state
);
416 if (!NT_STATUS_IS_OK(status
)) {
417 printf("failed to open share connection: //%s/%s port:%d - %s\n",
418 hostname
, sharename
, port_to_use
, nt_errstr(status
));
422 (*c
)->timeout
= 120000; /* set a really long timeout (2 minutes) */
425 return force_cli_encryption(*c
,
431 bool torture_open_connection(struct cli_state
**c
, int conn_index
)
433 char **unc_list
= NULL
;
434 int num_unc_names
= 0;
437 if (use_multishare_conn
==True
) {
439 unc_list
= file_lines_load(multishare_conn_fname
, &num_unc_names
, 0, NULL
);
440 if (!unc_list
|| num_unc_names
<= 0) {
441 printf("Failed to load unc names list from '%s'\n", multishare_conn_fname
);
445 if (!smbcli_parse_unc(unc_list
[conn_index
% num_unc_names
],
447 printf("Failed to parse UNC name %s\n",
448 unc_list
[conn_index
% num_unc_names
]);
449 TALLOC_FREE(unc_list
);
453 result
= torture_open_connection_share(c
, h
, s
);
455 /* h, s were copied earlier */
456 TALLOC_FREE(unc_list
);
460 return torture_open_connection_share(c
, host
, share
);
463 bool torture_cli_session_setup2(struct cli_state
*cli
, uint16
*new_vuid
)
465 uint16 old_vuid
= cli
->vuid
;
466 fstring old_user_name
;
467 size_t passlen
= strlen(password
);
471 fstrcpy(old_user_name
, cli
->user_name
);
473 ret
= NT_STATUS_IS_OK(cli_session_setup(cli
, username
,
477 *new_vuid
= cli
->vuid
;
478 cli
->vuid
= old_vuid
;
479 status
= cli_set_username(cli
, old_user_name
);
480 if (!NT_STATUS_IS_OK(status
)) {
487 bool torture_close_connection(struct cli_state
*c
)
492 status
= cli_tdis(c
);
493 if (!NT_STATUS_IS_OK(status
)) {
494 printf("tdis failed (%s)\n", nt_errstr(status
));
504 /* check if the server produced the expected error code */
505 static bool check_error(int line
, struct cli_state
*c
,
506 uint8 eclass
, uint32 ecode
, NTSTATUS nterr
)
508 if (cli_is_dos_error(c
)) {
512 /* Check DOS error */
514 cli_dos_error(c
, &cclass
, &num
);
516 if (eclass
!= cclass
|| ecode
!= num
) {
517 printf("unexpected error code class=%d code=%d\n",
518 (int)cclass
, (int)num
);
519 printf(" expected %d/%d %s (line=%d)\n",
520 (int)eclass
, (int)ecode
, nt_errstr(nterr
), line
);
529 status
= cli_nt_error(c
);
531 if (NT_STATUS_V(nterr
) != NT_STATUS_V(status
)) {
532 printf("unexpected error code %s\n", nt_errstr(status
));
533 printf(" expected %s (line=%d)\n", nt_errstr(nterr
), line
);
542 static bool wait_lock(struct cli_state
*c
, int fnum
, uint32 offset
, uint32 len
)
544 while (!cli_lock(c
, fnum
, offset
, len
, -1, WRITE_LOCK
)) {
545 if (!check_error(__LINE__
, c
, ERRDOS
, ERRlock
, NT_STATUS_LOCK_NOT_GRANTED
)) return False
;
551 static bool rw_torture(struct cli_state
*c
)
553 const char *lockfname
= "\\torture.lck";
557 pid_t pid2
, pid
= getpid();
563 memset(buf
, '\0', sizeof(buf
));
565 status
= cli_open(c
, lockfname
, O_RDWR
| O_CREAT
| O_EXCL
,
567 if (!NT_STATUS_IS_OK(status
)) {
568 status
= cli_open(c
, lockfname
, O_RDWR
, DENY_NONE
, &fnum2
);
570 if (!NT_STATUS_IS_OK(status
)) {
571 printf("open of %s failed (%s)\n", lockfname
, cli_errstr(c
));
575 for (i
=0;i
<torture_numops
;i
++) {
576 unsigned n
= (unsigned)sys_random()%10;
578 printf("%d\r", i
); fflush(stdout
);
580 slprintf(fname
, sizeof(fstring
) - 1, "\\torture.%u", n
);
582 if (!wait_lock(c
, fnum2
, n
*sizeof(int), sizeof(int))) {
586 if (!NT_STATUS_IS_OK(cli_open(c
, fname
, O_RDWR
| O_CREAT
| O_TRUNC
, DENY_ALL
, &fnum
))) {
587 printf("open failed (%s)\n", cli_errstr(c
));
592 if (cli_write(c
, fnum
, 0, (char *)&pid
, 0, sizeof(pid
)) != sizeof(pid
)) {
593 printf("write failed (%s)\n", cli_errstr(c
));
598 if (cli_write(c
, fnum
, 0, (char *)buf
,
599 sizeof(pid
)+(j
*sizeof(buf
)),
600 sizeof(buf
)) != sizeof(buf
)) {
601 printf("write failed (%s)\n", cli_errstr(c
));
608 if (cli_read(c
, fnum
, (char *)&pid2
, 0, sizeof(pid
)) != sizeof(pid
)) {
609 printf("read failed (%s)\n", cli_errstr(c
));
614 printf("data corruption!\n");
618 if (!NT_STATUS_IS_OK(cli_close(c
, fnum
))) {
619 printf("close failed (%s)\n", cli_errstr(c
));
623 if (!NT_STATUS_IS_OK(cli_unlink(c
, fname
, aSYSTEM
| aHIDDEN
))) {
624 printf("unlink failed (%s)\n", cli_errstr(c
));
628 if (!NT_STATUS_IS_OK(cli_unlock(c
, fnum2
, n
*sizeof(int), sizeof(int)))) {
629 printf("unlock failed (%s)\n", cli_errstr(c
));
635 cli_unlink(c
, lockfname
, aSYSTEM
| aHIDDEN
);
642 static bool run_torture(int dummy
)
644 struct cli_state
*cli
;
649 cli_sockopt(cli
, sockops
);
651 ret
= rw_torture(cli
);
653 if (!torture_close_connection(cli
)) {
660 static bool rw_torture3(struct cli_state
*c
, char *lockfname
)
662 uint16_t fnum
= (uint16_t)-1;
667 unsigned countprev
= 0;
670 NTSTATUS status
= NT_STATUS_OK
;
673 for (i
= 0; i
< sizeof(buf
); i
+= sizeof(uint32
))
675 SIVAL(buf
, i
, sys_random());
680 if (!NT_STATUS_IS_OK(cli_unlink(c
, lockfname
, aSYSTEM
| aHIDDEN
))) {
681 printf("unlink failed (%s) (normal, this file should not exist)\n", cli_errstr(c
));
684 if (!NT_STATUS_IS_OK(cli_open(c
, lockfname
, O_RDWR
| O_CREAT
| O_EXCL
,
685 DENY_NONE
, &fnum
))) {
686 printf("first open read/write of %s failed (%s)\n",
687 lockfname
, cli_errstr(c
));
693 for (i
= 0; i
< 500 && fnum
== (uint16_t)-1; i
++)
695 status
= cli_open(c
, lockfname
, O_RDONLY
,
697 if (!NT_STATUS_IS_OK(status
)) {
702 if (!NT_STATUS_IS_OK(status
)) {
703 printf("second open read-only of %s failed (%s)\n",
704 lockfname
, cli_errstr(c
));
710 for (count
= 0; count
< sizeof(buf
); count
+= sent
)
712 if (count
>= countprev
) {
713 printf("%d %8d\r", i
, count
);
716 countprev
+= (sizeof(buf
) / 20);
721 sent
= ((unsigned)sys_random()%(20))+ 1;
722 if (sent
> sizeof(buf
) - count
)
724 sent
= sizeof(buf
) - count
;
727 if (cli_write(c
, fnum
, 0, buf
+count
, count
, (size_t)sent
) != sent
) {
728 printf("write failed (%s)\n", cli_errstr(c
));
734 sent
= cli_read(c
, fnum
, buf_rd
+count
, count
,
738 printf("read failed offset:%d size:%ld (%s)\n",
739 count
, (unsigned long)sizeof(buf
)-count
,
746 if (memcmp(buf_rd
+count
, buf
+count
, sent
) != 0)
748 printf("read/write compare failed\n");
749 printf("offset: %d req %ld recvd %ld\n", count
, (unsigned long)sizeof(buf
)-count
, (unsigned long)sent
);
758 if (!NT_STATUS_IS_OK(cli_close(c
, fnum
))) {
759 printf("close failed (%s)\n", cli_errstr(c
));
766 static bool rw_torture2(struct cli_state
*c1
, struct cli_state
*c2
)
768 const char *lockfname
= "\\torture2.lck";
777 if (!NT_STATUS_IS_OK(cli_unlink(c1
, lockfname
, aSYSTEM
| aHIDDEN
))) {
778 printf("unlink failed (%s) (normal, this file should not exist)\n", cli_errstr(c1
));
781 if (!NT_STATUS_IS_OK(cli_open(c1
, lockfname
, O_RDWR
| O_CREAT
| O_EXCL
,
782 DENY_NONE
, &fnum1
))) {
783 printf("first open read/write of %s failed (%s)\n",
784 lockfname
, cli_errstr(c1
));
787 if (!NT_STATUS_IS_OK(cli_open(c2
, lockfname
, O_RDONLY
,
788 DENY_NONE
, &fnum2
))) {
789 printf("second open read-only of %s failed (%s)\n",
790 lockfname
, cli_errstr(c2
));
791 cli_close(c1
, fnum1
);
795 for (i
=0;i
<torture_numops
;i
++)
797 size_t buf_size
= ((unsigned)sys_random()%(sizeof(buf
)-1))+ 1;
799 printf("%d\r", i
); fflush(stdout
);
802 generate_random_buffer((unsigned char *)buf
, buf_size
);
804 if (cli_write(c1
, fnum1
, 0, buf
, 0, buf_size
) != buf_size
) {
805 printf("write failed (%s)\n", cli_errstr(c1
));
810 if ((bytes_read
= cli_read(c2
, fnum2
, buf_rd
, 0, buf_size
)) != buf_size
) {
811 printf("read failed (%s)\n", cli_errstr(c2
));
812 printf("read %d, expected %ld\n", (int)bytes_read
,
813 (unsigned long)buf_size
);
818 if (memcmp(buf_rd
, buf
, buf_size
) != 0)
820 printf("read/write compare failed\n");
826 if (!NT_STATUS_IS_OK(cli_close(c2
, fnum2
))) {
827 printf("close failed (%s)\n", cli_errstr(c2
));
830 if (!NT_STATUS_IS_OK(cli_close(c1
, fnum1
))) {
831 printf("close failed (%s)\n", cli_errstr(c1
));
835 if (!NT_STATUS_IS_OK(cli_unlink(c1
, lockfname
, aSYSTEM
| aHIDDEN
))) {
836 printf("unlink failed (%s)\n", cli_errstr(c1
));
843 static bool run_readwritetest(int dummy
)
845 struct cli_state
*cli1
, *cli2
;
846 bool test1
, test2
= False
;
848 if (!torture_open_connection(&cli1
, 0) || !torture_open_connection(&cli2
, 1)) {
851 cli_sockopt(cli1
, sockops
);
852 cli_sockopt(cli2
, sockops
);
854 printf("starting readwritetest\n");
856 test1
= rw_torture2(cli1
, cli2
);
857 printf("Passed readwritetest v1: %s\n", BOOLSTR(test1
));
860 test2
= rw_torture2(cli1
, cli1
);
861 printf("Passed readwritetest v2: %s\n", BOOLSTR(test2
));
864 if (!torture_close_connection(cli1
)) {
868 if (!torture_close_connection(cli2
)) {
872 return (test1
&& test2
);
875 static bool run_readwritemulti(int dummy
)
877 struct cli_state
*cli
;
882 cli_sockopt(cli
, sockops
);
884 printf("run_readwritemulti: fname %s\n", randomfname
);
885 test
= rw_torture3(cli
, randomfname
);
887 if (!torture_close_connection(cli
)) {
894 static bool run_readwritelarge_internal(int max_xmit_k
)
896 static struct cli_state
*cli1
;
898 const char *lockfname
= "\\large.dat";
903 if (!torture_open_connection(&cli1
, 0)) {
906 cli_sockopt(cli1
, sockops
);
907 memset(buf
,'\0',sizeof(buf
));
909 cli1
->max_xmit
= max_xmit_k
*1024;
911 if (signing_state
== Required
) {
912 /* Horrible cheat to force
913 multiple signed outstanding
914 packets against a Samba server.
916 cli1
->is_samba
= false;
919 printf("starting readwritelarge_internal\n");
921 cli_unlink(cli1
, lockfname
, aSYSTEM
| aHIDDEN
);
923 if (!NT_STATUS_IS_OK(cli_open(cli1
, lockfname
, O_RDWR
| O_CREAT
| O_EXCL
, DENY_NONE
, &fnum1
))) {
924 printf("open read/write of %s failed (%s)\n", lockfname
, cli_errstr(cli1
));
928 cli_write(cli1
, fnum1
, 0, buf
, 0, sizeof(buf
));
930 if (!NT_STATUS_IS_OK(cli_qfileinfo_basic(
931 cli1
, fnum1
, NULL
, &fsize
, NULL
, NULL
,
932 NULL
, NULL
, NULL
))) {
933 printf("qfileinfo failed (%s)\n", cli_errstr(cli1
));
937 if (fsize
== sizeof(buf
))
938 printf("readwritelarge_internal test 1 succeeded (size = %lx)\n",
939 (unsigned long)fsize
);
941 printf("readwritelarge_internal test 1 failed (size = %lx)\n",
942 (unsigned long)fsize
);
946 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
947 printf("close failed (%s)\n", cli_errstr(cli1
));
951 if (!NT_STATUS_IS_OK(cli_unlink(cli1
, lockfname
, aSYSTEM
| aHIDDEN
))) {
952 printf("unlink failed (%s)\n", cli_errstr(cli1
));
956 if (!NT_STATUS_IS_OK(cli_open(cli1
, lockfname
, O_RDWR
| O_CREAT
| O_EXCL
, DENY_NONE
, &fnum1
))) {
957 printf("open read/write of %s failed (%s)\n", lockfname
, cli_errstr(cli1
));
961 cli1
->max_xmit
= 4*1024;
963 cli_smbwrite(cli1
, fnum1
, buf
, 0, sizeof(buf
));
965 if (!NT_STATUS_IS_OK(cli_qfileinfo_basic(
966 cli1
, fnum1
, NULL
, &fsize
, NULL
, NULL
,
967 NULL
, NULL
, NULL
))) {
968 printf("qfileinfo failed (%s)\n", cli_errstr(cli1
));
972 if (fsize
== sizeof(buf
))
973 printf("readwritelarge_internal test 2 succeeded (size = %lx)\n",
974 (unsigned long)fsize
);
976 printf("readwritelarge_internal test 2 failed (size = %lx)\n",
977 (unsigned long)fsize
);
982 /* ToDo - set allocation. JRA */
983 if(!cli_set_allocation_size(cli1
, fnum1
, 0)) {
984 printf("set allocation size to zero failed (%s)\n", cli_errstr(&cli1
));
987 if (!cli_qfileinfo_basic(cli1
, fnum1
, NULL
, &fsize
, NULL
, NULL
, NULL
,
989 printf("qfileinfo failed (%s)\n", cli_errstr(cli1
));
993 printf("readwritelarge test 3 (truncate test) succeeded (size = %x)\n", fsize
);
996 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
997 printf("close failed (%s)\n", cli_errstr(cli1
));
1001 if (!torture_close_connection(cli1
)) {
1007 static bool run_readwritelarge(int dummy
)
1009 return run_readwritelarge_internal(128);
1012 static bool run_readwritelarge_signtest(int dummy
)
1015 signing_state
= Required
;
1016 ret
= run_readwritelarge_internal(2);
1017 signing_state
= Undefined
;
1024 #define ival(s) strtol(s, NULL, 0)
1026 /* run a test that simulates an approximate netbench client load */
1027 static bool run_netbench(int client
)
1029 struct cli_state
*cli
;
1034 const char *params
[20];
1035 bool correct
= True
;
1041 cli_sockopt(cli
, sockops
);
1045 slprintf(cname
,sizeof(cname
)-1, "client%d", client
);
1047 f
= fopen(client_txt
, "r");
1054 while (fgets(line
, sizeof(line
)-1, f
)) {
1058 line
[strlen(line
)-1] = 0;
1060 /* printf("[%d] %s\n", line_count, line); */
1062 all_string_sub(line
,"client1", cname
, sizeof(line
));
1064 /* parse the command parameters */
1065 params
[0] = strtok_r(line
, " ", &saveptr
);
1067 while (params
[i
]) params
[++i
] = strtok_r(NULL
, " ", &saveptr
);
1071 if (i
< 2) continue;
1073 if (!strncmp(params
[0],"SMB", 3)) {
1074 printf("ERROR: You are using a dbench 1 load file\n");
1078 if (!strcmp(params
[0],"NTCreateX")) {
1079 nb_createx(params
[1], ival(params
[2]), ival(params
[3]),
1081 } else if (!strcmp(params
[0],"Close")) {
1082 nb_close(ival(params
[1]));
1083 } else if (!strcmp(params
[0],"Rename")) {
1084 nb_rename(params
[1], params
[2]);
1085 } else if (!strcmp(params
[0],"Unlink")) {
1086 nb_unlink(params
[1]);
1087 } else if (!strcmp(params
[0],"Deltree")) {
1088 nb_deltree(params
[1]);
1089 } else if (!strcmp(params
[0],"Rmdir")) {
1090 nb_rmdir(params
[1]);
1091 } else if (!strcmp(params
[0],"QUERY_PATH_INFORMATION")) {
1092 nb_qpathinfo(params
[1]);
1093 } else if (!strcmp(params
[0],"QUERY_FILE_INFORMATION")) {
1094 nb_qfileinfo(ival(params
[1]));
1095 } else if (!strcmp(params
[0],"QUERY_FS_INFORMATION")) {
1096 nb_qfsinfo(ival(params
[1]));
1097 } else if (!strcmp(params
[0],"FIND_FIRST")) {
1098 nb_findfirst(params
[1]);
1099 } else if (!strcmp(params
[0],"WriteX")) {
1100 nb_writex(ival(params
[1]),
1101 ival(params
[2]), ival(params
[3]), ival(params
[4]));
1102 } else if (!strcmp(params
[0],"ReadX")) {
1103 nb_readx(ival(params
[1]),
1104 ival(params
[2]), ival(params
[3]), ival(params
[4]));
1105 } else if (!strcmp(params
[0],"Flush")) {
1106 nb_flush(ival(params
[1]));
1108 printf("Unknown operation %s\n", params
[0]);
1116 if (!torture_close_connection(cli
)) {
1124 /* run a test that simulates an approximate netbench client load */
1125 static bool run_nbench(int dummy
)
1128 bool correct
= True
;
1134 signal(SIGALRM
, nb_alarm
);
1136 t
= create_procs(run_netbench
, &correct
);
1139 printf("\nThroughput %g MB/sec\n",
1140 1.0e-6 * nbio_total() / t
);
1146 This test checks for two things:
1148 1) correct support for retaining locks over a close (ie. the server
1149 must not use posix semantics)
1150 2) support for lock timeouts
1152 static bool run_locktest1(int dummy
)
1154 struct cli_state
*cli1
, *cli2
;
1155 const char *fname
= "\\lockt1.lck";
1156 uint16_t fnum1
, fnum2
, fnum3
;
1158 unsigned lock_timeout
;
1160 if (!torture_open_connection(&cli1
, 0) || !torture_open_connection(&cli2
, 1)) {
1163 cli_sockopt(cli1
, sockops
);
1164 cli_sockopt(cli2
, sockops
);
1166 printf("starting locktest1\n");
1168 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
1170 if (!NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
))) {
1171 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
1174 if (!NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
, &fnum2
))) {
1175 printf("open2 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
1178 if (!NT_STATUS_IS_OK(cli_open(cli2
, fname
, O_RDWR
, DENY_NONE
, &fnum3
))) {
1179 printf("open3 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
1183 if (!cli_lock(cli1
, fnum1
, 0, 4, 0, WRITE_LOCK
)) {
1184 printf("lock1 failed (%s)\n", cli_errstr(cli1
));
1189 if (cli_lock(cli2
, fnum3
, 0, 4, 0, WRITE_LOCK
)) {
1190 printf("lock2 succeeded! This is a locking bug\n");
1193 if (!check_error(__LINE__
, cli2
, ERRDOS
, ERRlock
,
1194 NT_STATUS_LOCK_NOT_GRANTED
)) return False
;
1198 lock_timeout
= (1 + (random() % 20));
1199 printf("Testing lock timeout with timeout=%u\n", lock_timeout
);
1201 if (cli_lock(cli2
, fnum3
, 0, 4, lock_timeout
* 1000, WRITE_LOCK
)) {
1202 printf("lock3 succeeded! This is a locking bug\n");
1205 if (!check_error(__LINE__
, cli2
, ERRDOS
, ERRlock
,
1206 NT_STATUS_FILE_LOCK_CONFLICT
)) return False
;
1210 if (ABS(t2
- t1
) < lock_timeout
-1) {
1211 printf("error: This server appears not to support timed lock requests\n");
1214 printf("server slept for %u seconds for a %u second timeout\n",
1215 (unsigned int)(t2
-t1
), lock_timeout
);
1217 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum2
))) {
1218 printf("close1 failed (%s)\n", cli_errstr(cli1
));
1222 if (cli_lock(cli2
, fnum3
, 0, 4, 0, WRITE_LOCK
)) {
1223 printf("lock4 succeeded! This is a locking bug\n");
1226 if (!check_error(__LINE__
, cli2
, ERRDOS
, ERRlock
,
1227 NT_STATUS_FILE_LOCK_CONFLICT
)) return False
;
1230 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
1231 printf("close2 failed (%s)\n", cli_errstr(cli1
));
1235 if (!NT_STATUS_IS_OK(cli_close(cli2
, fnum3
))) {
1236 printf("close3 failed (%s)\n", cli_errstr(cli2
));
1240 if (!NT_STATUS_IS_OK(cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
))) {
1241 printf("unlink failed (%s)\n", cli_errstr(cli1
));
1246 if (!torture_close_connection(cli1
)) {
1250 if (!torture_close_connection(cli2
)) {
1254 printf("Passed locktest1\n");
1259 this checks to see if a secondary tconx can use open files from an
1262 static bool run_tcon_test(int dummy
)
1264 static struct cli_state
*cli
;
1265 const char *fname
= "\\tcontest.tmp";
1267 uint16 cnum1
, cnum2
, cnum3
;
1268 uint16 vuid1
, vuid2
;
1273 memset(buf
, '\0', sizeof(buf
));
1275 if (!torture_open_connection(&cli
, 0)) {
1278 cli_sockopt(cli
, sockops
);
1280 printf("starting tcontest\n");
1282 cli_unlink(cli
, fname
, aSYSTEM
| aHIDDEN
);
1284 if (!NT_STATUS_IS_OK(cli_open(cli
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
))) {
1285 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli
));
1292 if (cli_write(cli
, fnum1
, 0, buf
, 130, 4) != 4) {
1293 printf("initial write failed (%s)", cli_errstr(cli
));
1297 status
= cli_tcon_andx(cli
, share
, "?????",
1298 password
, strlen(password
)+1);
1299 if (!NT_STATUS_IS_OK(status
)) {
1300 printf("%s refused 2nd tree connect (%s)\n", host
,
1307 cnum3
= MAX(cnum1
, cnum2
) + 1; /* any invalid number */
1308 vuid2
= cli
->vuid
+ 1;
1310 /* try a write with the wrong tid */
1313 if (cli_write(cli
, fnum1
, 0, buf
, 130, 4) == 4) {
1314 printf("* server allows write with wrong TID\n");
1317 printf("server fails write with wrong TID : %s\n", cli_errstr(cli
));
1321 /* try a write with an invalid tid */
1324 if (cli_write(cli
, fnum1
, 0, buf
, 130, 4) == 4) {
1325 printf("* server allows write with invalid TID\n");
1328 printf("server fails write with invalid TID : %s\n", cli_errstr(cli
));
1331 /* try a write with an invalid vuid */
1335 if (cli_write(cli
, fnum1
, 0, buf
, 130, 4) == 4) {
1336 printf("* server allows write with invalid VUID\n");
1339 printf("server fails write with invalid VUID : %s\n", cli_errstr(cli
));
1345 if (!NT_STATUS_IS_OK(cli_close(cli
, fnum1
))) {
1346 printf("close failed (%s)\n", cli_errstr(cli
));
1352 status
= cli_tdis(cli
);
1353 if (!NT_STATUS_IS_OK(status
)) {
1354 printf("secondary tdis failed (%s)\n", nt_errstr(status
));
1360 if (!torture_close_connection(cli
)) {
1369 checks for old style tcon support
1371 static bool run_tcon2_test(int dummy
)
1373 static struct cli_state
*cli
;
1374 uint16 cnum
, max_xmit
;
1378 if (!torture_open_connection(&cli
, 0)) {
1381 cli_sockopt(cli
, sockops
);
1383 printf("starting tcon2 test\n");
1385 if (asprintf(&service
, "\\\\%s\\%s", host
, share
) == -1) {
1389 status
= cli_raw_tcon(cli
, service
, password
, "?????", &max_xmit
, &cnum
);
1391 if (!NT_STATUS_IS_OK(status
)) {
1392 printf("tcon2 failed : %s\n", cli_errstr(cli
));
1394 printf("tcon OK : max_xmit=%d cnum=%d tid=%d\n",
1395 (int)max_xmit
, (int)cnum
, SVAL(cli
->inbuf
, smb_tid
));
1398 if (!torture_close_connection(cli
)) {
1402 printf("Passed tcon2 test\n");
1406 static bool tcon_devtest(struct cli_state
*cli
,
1407 const char *myshare
, const char *devtype
,
1408 const char *return_devtype
,
1409 NTSTATUS expected_error
)
1414 status
= cli_tcon_andx(cli
, myshare
, devtype
,
1415 password
, strlen(password
)+1);
1417 if (NT_STATUS_IS_OK(expected_error
)) {
1418 if (NT_STATUS_IS_OK(status
)) {
1419 if (strcmp(cli
->dev
, return_devtype
) == 0) {
1422 printf("tconX to share %s with type %s "
1423 "succeeded but returned the wrong "
1424 "device type (got [%s] but should have got [%s])\n",
1425 myshare
, devtype
, cli
->dev
, return_devtype
);
1429 printf("tconX to share %s with type %s "
1430 "should have succeeded but failed\n",
1436 if (NT_STATUS_IS_OK(status
)) {
1437 printf("tconx to share %s with type %s "
1438 "should have failed but succeeded\n",
1442 if (NT_STATUS_EQUAL(cli_nt_error(cli
),
1446 printf("Returned unexpected error\n");
1455 checks for correct tconX support
1457 static bool run_tcon_devtype_test(int dummy
)
1459 static struct cli_state
*cli1
= NULL
;
1464 status
= cli_full_connection(&cli1
, myname
,
1465 host
, NULL
, port_to_use
,
1467 username
, workgroup
,
1468 password
, flags
, signing_state
);
1470 if (!NT_STATUS_IS_OK(status
)) {
1471 printf("could not open connection\n");
1475 if (!tcon_devtest(cli1
, "IPC$", "A:", NULL
, NT_STATUS_BAD_DEVICE_TYPE
))
1478 if (!tcon_devtest(cli1
, "IPC$", "?????", "IPC", NT_STATUS_OK
))
1481 if (!tcon_devtest(cli1
, "IPC$", "LPT:", NULL
, NT_STATUS_BAD_DEVICE_TYPE
))
1484 if (!tcon_devtest(cli1
, "IPC$", "IPC", "IPC", NT_STATUS_OK
))
1487 if (!tcon_devtest(cli1
, "IPC$", "FOOBA", NULL
, NT_STATUS_BAD_DEVICE_TYPE
))
1490 if (!tcon_devtest(cli1
, share
, "A:", "A:", NT_STATUS_OK
))
1493 if (!tcon_devtest(cli1
, share
, "?????", "A:", NT_STATUS_OK
))
1496 if (!tcon_devtest(cli1
, share
, "LPT:", NULL
, NT_STATUS_BAD_DEVICE_TYPE
))
1499 if (!tcon_devtest(cli1
, share
, "IPC", NULL
, NT_STATUS_BAD_DEVICE_TYPE
))
1502 if (!tcon_devtest(cli1
, share
, "FOOBA", NULL
, NT_STATUS_BAD_DEVICE_TYPE
))
1508 printf("Passed tcondevtest\n");
1515 This test checks that
1517 1) the server supports multiple locking contexts on the one SMB
1518 connection, distinguished by PID.
1520 2) the server correctly fails overlapping locks made by the same PID (this
1521 goes against POSIX behaviour, which is why it is tricky to implement)
1523 3) the server denies unlock requests by an incorrect client PID
1525 static bool run_locktest2(int dummy
)
1527 static struct cli_state
*cli
;
1528 const char *fname
= "\\lockt2.lck";
1529 uint16_t fnum1
, fnum2
, fnum3
;
1530 bool correct
= True
;
1532 if (!torture_open_connection(&cli
, 0)) {
1536 cli_sockopt(cli
, sockops
);
1538 printf("starting locktest2\n");
1540 cli_unlink(cli
, fname
, aSYSTEM
| aHIDDEN
);
1544 if (!NT_STATUS_IS_OK(cli_open(cli
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
))) {
1545 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli
));
1549 if (!NT_STATUS_IS_OK(cli_open(cli
, fname
, O_RDWR
, DENY_NONE
, &fnum2
))) {
1550 printf("open2 of %s failed (%s)\n", fname
, cli_errstr(cli
));
1556 if (!NT_STATUS_IS_OK(cli_open(cli
, fname
, O_RDWR
, DENY_NONE
, &fnum3
))) {
1557 printf("open3 of %s failed (%s)\n", fname
, cli_errstr(cli
));
1563 if (!cli_lock(cli
, fnum1
, 0, 4, 0, WRITE_LOCK
)) {
1564 printf("lock1 failed (%s)\n", cli_errstr(cli
));
1568 if (cli_lock(cli
, fnum1
, 0, 4, 0, WRITE_LOCK
)) {
1569 printf("WRITE lock1 succeeded! This is a locking bug\n");
1572 if (!check_error(__LINE__
, cli
, ERRDOS
, ERRlock
,
1573 NT_STATUS_LOCK_NOT_GRANTED
)) return False
;
1576 if (cli_lock(cli
, fnum2
, 0, 4, 0, WRITE_LOCK
)) {
1577 printf("WRITE lock2 succeeded! This is a locking bug\n");
1580 if (!check_error(__LINE__
, cli
, ERRDOS
, ERRlock
,
1581 NT_STATUS_LOCK_NOT_GRANTED
)) return False
;
1584 if (cli_lock(cli
, fnum2
, 0, 4, 0, READ_LOCK
)) {
1585 printf("READ lock2 succeeded! This is a locking bug\n");
1588 if (!check_error(__LINE__
, cli
, ERRDOS
, ERRlock
,
1589 NT_STATUS_FILE_LOCK_CONFLICT
)) return False
;
1592 if (!cli_lock(cli
, fnum1
, 100, 4, 0, WRITE_LOCK
)) {
1593 printf("lock at 100 failed (%s)\n", cli_errstr(cli
));
1596 if (NT_STATUS_IS_OK(cli_unlock(cli
, fnum1
, 100, 4))) {
1597 printf("unlock at 100 succeeded! This is a locking bug\n");
1601 if (NT_STATUS_IS_OK(cli_unlock(cli
, fnum1
, 0, 4))) {
1602 printf("unlock1 succeeded! This is a locking bug\n");
1605 if (!check_error(__LINE__
, cli
,
1607 NT_STATUS_RANGE_NOT_LOCKED
)) return False
;
1610 if (NT_STATUS_IS_OK(cli_unlock(cli
, fnum1
, 0, 8))) {
1611 printf("unlock2 succeeded! This is a locking bug\n");
1614 if (!check_error(__LINE__
, cli
,
1616 NT_STATUS_RANGE_NOT_LOCKED
)) return False
;
1619 if (cli_lock(cli
, fnum3
, 0, 4, 0, WRITE_LOCK
)) {
1620 printf("lock3 succeeded! This is a locking bug\n");
1623 if (!check_error(__LINE__
, cli
, ERRDOS
, ERRlock
, NT_STATUS_LOCK_NOT_GRANTED
)) return False
;
1628 if (!NT_STATUS_IS_OK(cli_close(cli
, fnum1
))) {
1629 printf("close1 failed (%s)\n", cli_errstr(cli
));
1633 if (!NT_STATUS_IS_OK(cli_close(cli
, fnum2
))) {
1634 printf("close2 failed (%s)\n", cli_errstr(cli
));
1638 if (!NT_STATUS_IS_OK(cli_close(cli
, fnum3
))) {
1639 printf("close3 failed (%s)\n", cli_errstr(cli
));
1643 if (!torture_close_connection(cli
)) {
1647 printf("locktest2 finished\n");
1654 This test checks that
1656 1) the server supports the full offset range in lock requests
1658 static bool run_locktest3(int dummy
)
1660 static struct cli_state
*cli1
, *cli2
;
1661 const char *fname
= "\\lockt3.lck";
1662 uint16_t fnum1
, fnum2
;
1665 bool correct
= True
;
1667 #define NEXT_OFFSET offset += (~(uint32)0) / torture_numops
1669 if (!torture_open_connection(&cli1
, 0) || !torture_open_connection(&cli2
, 1)) {
1672 cli_sockopt(cli1
, sockops
);
1673 cli_sockopt(cli2
, sockops
);
1675 printf("starting locktest3\n");
1677 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
1679 if (!NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
))) {
1680 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
1683 if (!NT_STATUS_IS_OK(cli_open(cli2
, fname
, O_RDWR
, DENY_NONE
, &fnum2
))) {
1684 printf("open2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
1688 for (offset
=i
=0;i
<torture_numops
;i
++) {
1690 if (!cli_lock(cli1
, fnum1
, offset
-1, 1, 0, WRITE_LOCK
)) {
1691 printf("lock1 %d failed (%s)\n",
1697 if (!cli_lock(cli2
, fnum2
, offset
-2, 1, 0, WRITE_LOCK
)) {
1698 printf("lock2 %d failed (%s)\n",
1705 for (offset
=i
=0;i
<torture_numops
;i
++) {
1708 if (cli_lock(cli1
, fnum1
, offset
-2, 1, 0, WRITE_LOCK
)) {
1709 printf("error: lock1 %d succeeded!\n", i
);
1713 if (cli_lock(cli2
, fnum2
, offset
-1, 1, 0, WRITE_LOCK
)) {
1714 printf("error: lock2 %d succeeded!\n", i
);
1718 if (cli_lock(cli1
, fnum1
, offset
-1, 1, 0, WRITE_LOCK
)) {
1719 printf("error: lock3 %d succeeded!\n", i
);
1723 if (cli_lock(cli2
, fnum2
, offset
-2, 1, 0, WRITE_LOCK
)) {
1724 printf("error: lock4 %d succeeded!\n", i
);
1729 for (offset
=i
=0;i
<torture_numops
;i
++) {
1732 if (!NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, offset
-1, 1))) {
1733 printf("unlock1 %d failed (%s)\n",
1739 if (!NT_STATUS_IS_OK(cli_unlock(cli2
, fnum2
, offset
-2, 1))) {
1740 printf("unlock2 %d failed (%s)\n",
1747 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
1748 printf("close1 failed (%s)\n", cli_errstr(cli1
));
1752 if (!NT_STATUS_IS_OK(cli_close(cli2
, fnum2
))) {
1753 printf("close2 failed (%s)\n", cli_errstr(cli2
));
1757 if (!NT_STATUS_IS_OK(cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
))) {
1758 printf("unlink failed (%s)\n", cli_errstr(cli1
));
1762 if (!torture_close_connection(cli1
)) {
1766 if (!torture_close_connection(cli2
)) {
1770 printf("finished locktest3\n");
1775 #define EXPECTED(ret, v) if ((ret) != (v)) { \
1776 printf("** "); correct = False; \
1780 looks at overlapping locks
1782 static bool run_locktest4(int dummy
)
1784 static struct cli_state
*cli1
, *cli2
;
1785 const char *fname
= "\\lockt4.lck";
1786 uint16_t fnum1
, fnum2
, f
;
1789 bool correct
= True
;
1791 if (!torture_open_connection(&cli1
, 0) || !torture_open_connection(&cli2
, 1)) {
1795 cli_sockopt(cli1
, sockops
);
1796 cli_sockopt(cli2
, sockops
);
1798 printf("starting locktest4\n");
1800 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
1802 cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
);
1803 cli_open(cli2
, fname
, O_RDWR
, DENY_NONE
, &fnum2
);
1805 memset(buf
, 0, sizeof(buf
));
1807 if (cli_write(cli1
, fnum1
, 0, buf
, 0, sizeof(buf
)) != sizeof(buf
)) {
1808 printf("Failed to create file\n");
1813 ret
= cli_lock(cli1
, fnum1
, 0, 4, 0, WRITE_LOCK
) &&
1814 cli_lock(cli1
, fnum1
, 2, 4, 0, WRITE_LOCK
);
1815 EXPECTED(ret
, False
);
1816 printf("the same process %s set overlapping write locks\n", ret
?"can":"cannot");
1818 ret
= cli_lock(cli1
, fnum1
, 10, 4, 0, READ_LOCK
) &&
1819 cli_lock(cli1
, fnum1
, 12, 4, 0, READ_LOCK
);
1820 EXPECTED(ret
, True
);
1821 printf("the same process %s set overlapping read locks\n", ret
?"can":"cannot");
1823 ret
= cli_lock(cli1
, fnum1
, 20, 4, 0, WRITE_LOCK
) &&
1824 cli_lock(cli2
, fnum2
, 22, 4, 0, WRITE_LOCK
);
1825 EXPECTED(ret
, False
);
1826 printf("a different connection %s set overlapping write locks\n", ret
?"can":"cannot");
1828 ret
= cli_lock(cli1
, fnum1
, 30, 4, 0, READ_LOCK
) &&
1829 cli_lock(cli2
, fnum2
, 32, 4, 0, READ_LOCK
);
1830 EXPECTED(ret
, True
);
1831 printf("a different connection %s set overlapping read locks\n", ret
?"can":"cannot");
1833 ret
= (cli_setpid(cli1
, 1), cli_lock(cli1
, fnum1
, 40, 4, 0, WRITE_LOCK
)) &&
1834 (cli_setpid(cli1
, 2), cli_lock(cli1
, fnum1
, 42, 4, 0, WRITE_LOCK
));
1835 EXPECTED(ret
, False
);
1836 printf("a different pid %s set overlapping write locks\n", ret
?"can":"cannot");
1838 ret
= (cli_setpid(cli1
, 1), cli_lock(cli1
, fnum1
, 50, 4, 0, READ_LOCK
)) &&
1839 (cli_setpid(cli1
, 2), cli_lock(cli1
, fnum1
, 52, 4, 0, READ_LOCK
));
1840 EXPECTED(ret
, True
);
1841 printf("a different pid %s set overlapping read locks\n", ret
?"can":"cannot");
1843 ret
= cli_lock(cli1
, fnum1
, 60, 4, 0, READ_LOCK
) &&
1844 cli_lock(cli1
, fnum1
, 60, 4, 0, READ_LOCK
);
1845 EXPECTED(ret
, True
);
1846 printf("the same process %s set the same read lock twice\n", ret
?"can":"cannot");
1848 ret
= cli_lock(cli1
, fnum1
, 70, 4, 0, WRITE_LOCK
) &&
1849 cli_lock(cli1
, fnum1
, 70, 4, 0, WRITE_LOCK
);
1850 EXPECTED(ret
, False
);
1851 printf("the same process %s set the same write lock twice\n", ret
?"can":"cannot");
1853 ret
= cli_lock(cli1
, fnum1
, 80, 4, 0, READ_LOCK
) &&
1854 cli_lock(cli1
, fnum1
, 80, 4, 0, WRITE_LOCK
);
1855 EXPECTED(ret
, False
);
1856 printf("the same process %s overlay a read lock with a write lock\n", ret
?"can":"cannot");
1858 ret
= cli_lock(cli1
, fnum1
, 90, 4, 0, WRITE_LOCK
) &&
1859 cli_lock(cli1
, fnum1
, 90, 4, 0, READ_LOCK
);
1860 EXPECTED(ret
, True
);
1861 printf("the same process %s overlay a write lock with a read lock\n", ret
?"can":"cannot");
1863 ret
= (cli_setpid(cli1
, 1), cli_lock(cli1
, fnum1
, 100, 4, 0, WRITE_LOCK
)) &&
1864 (cli_setpid(cli1
, 2), cli_lock(cli1
, fnum1
, 100, 4, 0, READ_LOCK
));
1865 EXPECTED(ret
, False
);
1866 printf("a different pid %s overlay a write lock with a read lock\n", ret
?"can":"cannot");
1868 ret
= cli_lock(cli1
, fnum1
, 110, 4, 0, READ_LOCK
) &&
1869 cli_lock(cli1
, fnum1
, 112, 4, 0, READ_LOCK
) &&
1870 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 110, 6));
1871 EXPECTED(ret
, False
);
1872 printf("the same process %s coalesce read locks\n", ret
?"can":"cannot");
1875 ret
= cli_lock(cli1
, fnum1
, 120, 4, 0, WRITE_LOCK
) &&
1876 (cli_read(cli2
, fnum2
, buf
, 120, 4) == 4);
1877 EXPECTED(ret
, False
);
1878 printf("this server %s strict write locking\n", ret
?"doesn't do":"does");
1880 ret
= cli_lock(cli1
, fnum1
, 130, 4, 0, READ_LOCK
) &&
1881 (cli_write(cli2
, fnum2
, 0, buf
, 130, 4) == 4);
1882 EXPECTED(ret
, False
);
1883 printf("this server %s strict read locking\n", ret
?"doesn't do":"does");
1886 ret
= cli_lock(cli1
, fnum1
, 140, 4, 0, READ_LOCK
) &&
1887 cli_lock(cli1
, fnum1
, 140, 4, 0, READ_LOCK
) &&
1888 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 140, 4)) &&
1889 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 140, 4));
1890 EXPECTED(ret
, True
);
1891 printf("this server %s do recursive read locking\n", ret
?"does":"doesn't");
1894 ret
= cli_lock(cli1
, fnum1
, 150, 4, 0, WRITE_LOCK
) &&
1895 cli_lock(cli1
, fnum1
, 150, 4, 0, READ_LOCK
) &&
1896 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 150, 4)) &&
1897 (cli_read(cli2
, fnum2
, buf
, 150, 4) == 4) &&
1898 !(cli_write(cli2
, fnum2
, 0, buf
, 150, 4) == 4) &&
1899 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 150, 4));
1900 EXPECTED(ret
, True
);
1901 printf("this server %s do recursive lock overlays\n", ret
?"does":"doesn't");
1903 ret
= cli_lock(cli1
, fnum1
, 160, 4, 0, READ_LOCK
) &&
1904 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 160, 4)) &&
1905 (cli_write(cli2
, fnum2
, 0, buf
, 160, 4) == 4) &&
1906 (cli_read(cli2
, fnum2
, buf
, 160, 4) == 4);
1907 EXPECTED(ret
, True
);
1908 printf("the same process %s remove a read lock using write locking\n", ret
?"can":"cannot");
1910 ret
= cli_lock(cli1
, fnum1
, 170, 4, 0, WRITE_LOCK
) &&
1911 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 170, 4)) &&
1912 (cli_write(cli2
, fnum2
, 0, buf
, 170, 4) == 4) &&
1913 (cli_read(cli2
, fnum2
, buf
, 170, 4) == 4);
1914 EXPECTED(ret
, True
);
1915 printf("the same process %s remove a write lock using read locking\n", ret
?"can":"cannot");
1917 ret
= cli_lock(cli1
, fnum1
, 190, 4, 0, WRITE_LOCK
) &&
1918 cli_lock(cli1
, fnum1
, 190, 4, 0, READ_LOCK
) &&
1919 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 190, 4)) &&
1920 !(cli_write(cli2
, fnum2
, 0, buf
, 190, 4) == 4) &&
1921 (cli_read(cli2
, fnum2
, buf
, 190, 4) == 4);
1922 EXPECTED(ret
, True
);
1923 printf("the same process %s remove the first lock first\n", ret
?"does":"doesn't");
1925 cli_close(cli1
, fnum1
);
1926 cli_close(cli2
, fnum2
);
1927 cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
, &fnum1
);
1928 cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
, &f
);
1929 ret
= cli_lock(cli1
, fnum1
, 0, 8, 0, READ_LOCK
) &&
1930 cli_lock(cli1
, f
, 0, 1, 0, READ_LOCK
) &&
1931 NT_STATUS_IS_OK(cli_close(cli1
, fnum1
)) &&
1932 NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
, &fnum1
)) &&
1933 cli_lock(cli1
, fnum1
, 7, 1, 0, WRITE_LOCK
);
1935 cli_close(cli1
, fnum1
);
1936 EXPECTED(ret
, True
);
1937 printf("the server %s have the NT byte range lock bug\n", !ret
?"does":"doesn't");
1940 cli_close(cli1
, fnum1
);
1941 cli_close(cli2
, fnum2
);
1942 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
1943 torture_close_connection(cli1
);
1944 torture_close_connection(cli2
);
1946 printf("finished locktest4\n");
1951 looks at lock upgrade/downgrade.
1953 static bool run_locktest5(int dummy
)
1955 static struct cli_state
*cli1
, *cli2
;
1956 const char *fname
= "\\lockt5.lck";
1957 uint16_t fnum1
, fnum2
, fnum3
;
1960 bool correct
= True
;
1962 if (!torture_open_connection(&cli1
, 0) || !torture_open_connection(&cli2
, 1)) {
1966 cli_sockopt(cli1
, sockops
);
1967 cli_sockopt(cli2
, sockops
);
1969 printf("starting locktest5\n");
1971 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
1973 cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
);
1974 cli_open(cli2
, fname
, O_RDWR
, DENY_NONE
, &fnum2
);
1975 cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
, &fnum3
);
1977 memset(buf
, 0, sizeof(buf
));
1979 if (cli_write(cli1
, fnum1
, 0, buf
, 0, sizeof(buf
)) != sizeof(buf
)) {
1980 printf("Failed to create file\n");
1985 /* Check for NT bug... */
1986 ret
= cli_lock(cli1
, fnum1
, 0, 8, 0, READ_LOCK
) &&
1987 cli_lock(cli1
, fnum3
, 0, 1, 0, READ_LOCK
);
1988 cli_close(cli1
, fnum1
);
1989 cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
, &fnum1
);
1990 ret
= cli_lock(cli1
, fnum1
, 7, 1, 0, WRITE_LOCK
);
1991 EXPECTED(ret
, True
);
1992 printf("this server %s the NT locking bug\n", ret
? "doesn't have" : "has");
1993 cli_close(cli1
, fnum1
);
1994 cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
, &fnum1
);
1995 cli_unlock(cli1
, fnum3
, 0, 1);
1997 ret
= cli_lock(cli1
, fnum1
, 0, 4, 0, WRITE_LOCK
) &&
1998 cli_lock(cli1
, fnum1
, 1, 1, 0, READ_LOCK
);
1999 EXPECTED(ret
, True
);
2000 printf("the same process %s overlay a write with a read lock\n", ret
?"can":"cannot");
2002 ret
= cli_lock(cli2
, fnum2
, 0, 4, 0, READ_LOCK
);
2003 EXPECTED(ret
, False
);
2005 printf("a different processs %s get a read lock on the first process lock stack\n", ret
?"can":"cannot");
2007 /* Unlock the process 2 lock. */
2008 cli_unlock(cli2
, fnum2
, 0, 4);
2010 ret
= cli_lock(cli1
, fnum3
, 0, 4, 0, READ_LOCK
);
2011 EXPECTED(ret
, False
);
2013 printf("the same processs on a different fnum %s get a read lock\n", ret
?"can":"cannot");
2015 /* Unlock the process 1 fnum3 lock. */
2016 cli_unlock(cli1
, fnum3
, 0, 4);
2018 /* Stack 2 more locks here. */
2019 ret
= cli_lock(cli1
, fnum1
, 0, 4, 0, READ_LOCK
) &&
2020 cli_lock(cli1
, fnum1
, 0, 4, 0, READ_LOCK
);
2022 EXPECTED(ret
, True
);
2023 printf("the same process %s stack read locks\n", ret
?"can":"cannot");
2025 /* Unlock the first process lock, then check this was the WRITE lock that was
2028 ret
= NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 0, 4)) &&
2029 cli_lock(cli2
, fnum2
, 0, 4, 0, READ_LOCK
);
2031 EXPECTED(ret
, True
);
2032 printf("the first unlock removes the %s lock\n", ret
?"WRITE":"READ");
2034 /* Unlock the process 2 lock. */
2035 cli_unlock(cli2
, fnum2
, 0, 4);
2037 /* We should have 3 stacked locks here. Ensure we need to do 3 unlocks. */
2039 ret
= NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 1, 1)) &&
2040 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 0, 4)) &&
2041 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 0, 4));
2043 EXPECTED(ret
, True
);
2044 printf("the same process %s unlock the stack of 4 locks\n", ret
?"can":"cannot");
2046 /* Ensure the next unlock fails. */
2047 ret
= NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 0, 4));
2048 EXPECTED(ret
, False
);
2049 printf("the same process %s count the lock stack\n", !ret
?"can":"cannot");
2051 /* Ensure connection 2 can get a write lock. */
2052 ret
= cli_lock(cli2
, fnum2
, 0, 4, 0, WRITE_LOCK
);
2053 EXPECTED(ret
, True
);
2055 printf("a different processs %s get a write lock on the unlocked stack\n", ret
?"can":"cannot");
2059 cli_close(cli1
, fnum1
);
2060 cli_close(cli2
, fnum2
);
2061 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
2062 if (!torture_close_connection(cli1
)) {
2065 if (!torture_close_connection(cli2
)) {
2069 printf("finished locktest5\n");
2075 tries the unusual lockingX locktype bits
2077 static bool run_locktest6(int dummy
)
2079 static struct cli_state
*cli
;
2080 const char *fname
[1] = { "\\lock6.txt" };
2085 if (!torture_open_connection(&cli
, 0)) {
2089 cli_sockopt(cli
, sockops
);
2091 printf("starting locktest6\n");
2094 printf("Testing %s\n", fname
[i
]);
2096 cli_unlink(cli
, fname
[i
], aSYSTEM
| aHIDDEN
);
2098 cli_open(cli
, fname
[i
], O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum
);
2099 status
= cli_locktype(cli
, fnum
, 0, 8, 0, LOCKING_ANDX_CHANGE_LOCKTYPE
);
2100 cli_close(cli
, fnum
);
2101 printf("CHANGE_LOCKTYPE gave %s\n", nt_errstr(status
));
2103 cli_open(cli
, fname
[i
], O_RDWR
, DENY_NONE
, &fnum
);
2104 status
= cli_locktype(cli
, fnum
, 0, 8, 0, LOCKING_ANDX_CANCEL_LOCK
);
2105 cli_close(cli
, fnum
);
2106 printf("CANCEL_LOCK gave %s\n", nt_errstr(status
));
2108 cli_unlink(cli
, fname
[i
], aSYSTEM
| aHIDDEN
);
2111 torture_close_connection(cli
);
2113 printf("finished locktest6\n");
2117 static bool run_locktest7(int dummy
)
2119 struct cli_state
*cli1
;
2120 const char *fname
= "\\lockt7.lck";
2123 bool correct
= False
;
2125 if (!torture_open_connection(&cli1
, 0)) {
2129 cli_sockopt(cli1
, sockops
);
2131 printf("starting locktest7\n");
2133 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
2135 cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
);
2137 memset(buf
, 0, sizeof(buf
));
2139 if (cli_write(cli1
, fnum1
, 0, buf
, 0, sizeof(buf
)) != sizeof(buf
)) {
2140 printf("Failed to create file\n");
2144 cli_setpid(cli1
, 1);
2146 if (!cli_lock(cli1
, fnum1
, 130, 4, 0, READ_LOCK
)) {
2147 printf("Unable to apply read lock on range 130:4, error was %s\n", cli_errstr(cli1
));
2150 printf("pid1 successfully locked range 130:4 for READ\n");
2153 if (cli_read(cli1
, fnum1
, buf
, 130, 4) != 4) {
2154 printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(cli1
));
2157 printf("pid1 successfully read the range 130:4\n");
2160 if (cli_write(cli1
, fnum1
, 0, buf
, 130, 4) != 4) {
2161 printf("pid1 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1
));
2162 if (NT_STATUS_V(cli_nt_error(cli1
)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT
)) {
2163 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2167 printf("pid1 successfully wrote to the range 130:4 (should be denied)\n");
2171 cli_setpid(cli1
, 2);
2173 if (cli_read(cli1
, fnum1
, buf
, 130, 4) != 4) {
2174 printf("pid2 unable to read the range 130:4, error was %s\n", cli_errstr(cli1
));
2176 printf("pid2 successfully read the range 130:4\n");
2179 if (cli_write(cli1
, fnum1
, 0, buf
, 130, 4) != 4) {
2180 printf("pid2 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1
));
2181 if (NT_STATUS_V(cli_nt_error(cli1
)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT
)) {
2182 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2186 printf("pid2 successfully wrote to the range 130:4 (should be denied)\n");
2190 cli_setpid(cli1
, 1);
2191 cli_unlock(cli1
, fnum1
, 130, 4);
2193 if (!cli_lock(cli1
, fnum1
, 130, 4, 0, WRITE_LOCK
)) {
2194 printf("Unable to apply write lock on range 130:4, error was %s\n", cli_errstr(cli1
));
2197 printf("pid1 successfully locked range 130:4 for WRITE\n");
2200 if (cli_read(cli1
, fnum1
, buf
, 130, 4) != 4) {
2201 printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(cli1
));
2204 printf("pid1 successfully read the range 130:4\n");
2207 if (cli_write(cli1
, fnum1
, 0, buf
, 130, 4) != 4) {
2208 printf("pid1 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1
));
2211 printf("pid1 successfully wrote to the range 130:4\n");
2214 cli_setpid(cli1
, 2);
2216 if (cli_read(cli1
, fnum1
, buf
, 130, 4) != 4) {
2217 printf("pid2 unable to read the range 130:4, error was %s\n", cli_errstr(cli1
));
2218 if (NT_STATUS_V(cli_nt_error(cli1
)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT
)) {
2219 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2223 printf("pid2 successfully read the range 130:4 (should be denied)\n");
2227 if (cli_write(cli1
, fnum1
, 0, buf
, 130, 4) != 4) {
2228 printf("pid2 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1
));
2229 if (NT_STATUS_V(cli_nt_error(cli1
)) != NT_STATUS_V(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_unlock(cli1
, fnum1
, 130, 0);
2242 cli_close(cli1
, fnum1
);
2243 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
2244 torture_close_connection(cli1
);
2246 printf("finished locktest7\n");
2251 * This demonstrates a problem with our use of GPFS share modes: A file
2252 * descriptor sitting in the pending close queue holding a GPFS share mode
2253 * blocks opening a file another time. Happens with Word 2007 temp files.
2254 * With "posix locking = yes" and "gpfs:sharemodes = yes" enabled, the third
2255 * open is denied with NT_STATUS_SHARING_VIOLATION.
2258 static bool run_locktest8(int dummy
)
2260 struct cli_state
*cli1
;
2261 const char *fname
= "\\lockt8.lck";
2262 uint16_t fnum1
, fnum2
;
2264 bool correct
= False
;
2267 if (!torture_open_connection(&cli1
, 0)) {
2271 cli_sockopt(cli1
, sockops
);
2273 printf("starting locktest8\n");
2275 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
2277 status
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_WRITE
,
2279 if (!NT_STATUS_IS_OK(status
)) {
2280 d_fprintf(stderr
, "cli_open returned %s\n", cli_errstr(cli1
));
2284 memset(buf
, 0, sizeof(buf
));
2286 status
= cli_open(cli1
, fname
, O_RDONLY
, DENY_NONE
, &fnum2
);
2287 if (!NT_STATUS_IS_OK(status
)) {
2288 d_fprintf(stderr
, "cli_open second time returned %s\n",
2293 if (!cli_lock(cli1
, fnum2
, 1, 1, 0, READ_LOCK
)) {
2294 printf("Unable to apply read lock on range 1:1, error was "
2295 "%s\n", cli_errstr(cli1
));
2299 status
= cli_close(cli1
, fnum1
);
2300 if (!NT_STATUS_IS_OK(status
)) {
2301 d_fprintf(stderr
, "cli_close(fnum1) %s\n", cli_errstr(cli1
));
2305 status
= cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
, &fnum1
);
2306 if (!NT_STATUS_IS_OK(status
)) {
2307 d_fprintf(stderr
, "cli_open third time returned %s\n",
2315 cli_close(cli1
, fnum1
);
2316 cli_close(cli1
, fnum2
);
2317 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
2318 torture_close_connection(cli1
);
2320 printf("finished locktest8\n");
2325 * This test is designed to be run in conjunction with
2326 * external NFS or POSIX locks taken in the filesystem.
2327 * It checks that the smbd server will block until the
2328 * lock is released and then acquire it. JRA.
2331 static bool got_alarm
;
2332 static int alarm_fd
;
2334 static void alarm_handler(int dummy
)
2339 static void alarm_handler_parent(int dummy
)
2344 static void do_local_lock(int read_fd
, int write_fd
)
2349 const char *local_pathname
= NULL
;
2352 local_pathname
= talloc_asprintf(talloc_tos(),
2353 "%s/lockt9.lck", local_path
);
2354 if (!local_pathname
) {
2355 printf("child: alloc fail\n");
2359 unlink(local_pathname
);
2360 fd
= open(local_pathname
, O_RDWR
|O_CREAT
, 0666);
2362 printf("child: open of %s failed %s.\n",
2363 local_pathname
, strerror(errno
));
2367 /* Now take a fcntl lock. */
2368 lock
.l_type
= F_WRLCK
;
2369 lock
.l_whence
= SEEK_SET
;
2372 lock
.l_pid
= getpid();
2374 ret
= fcntl(fd
,F_SETLK
,&lock
);
2376 printf("child: failed to get lock 0:4 on file %s. Error %s\n",
2377 local_pathname
, strerror(errno
));
2380 printf("child: got lock 0:4 on file %s.\n",
2385 CatchSignal(SIGALRM
, alarm_handler
);
2387 /* Signal the parent. */
2388 if (write(write_fd
, &c
, 1) != 1) {
2389 printf("child: start signal fail %s.\n",
2396 /* Wait for the parent to be ready. */
2397 if (read(read_fd
, &c
, 1) != 1) {
2398 printf("child: reply signal fail %s.\n",
2406 printf("child: released lock 0:4 on file %s.\n",
2412 static bool run_locktest9(int dummy
)
2414 struct cli_state
*cli1
;
2415 const char *fname
= "\\lockt9.lck";
2417 bool correct
= False
;
2418 int pipe_in
[2], pipe_out
[2];
2422 struct timeval start
;
2426 printf("starting locktest9\n");
2428 if (local_path
== NULL
) {
2429 d_fprintf(stderr
, "locktest9 must be given a local path via -l <localpath>\n");
2433 if (pipe(pipe_in
) == -1 || pipe(pipe_out
) == -1) {
2438 if (child_pid
== -1) {
2442 if (child_pid
== 0) {
2444 do_local_lock(pipe_out
[0], pipe_in
[1]);
2454 ret
= read(pipe_in
[0], &c
, 1);
2456 d_fprintf(stderr
, "failed to read start signal from child. %s\n",
2461 if (!torture_open_connection(&cli1
, 0)) {
2465 cli_sockopt(cli1
, sockops
);
2467 status
= cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
,
2469 if (!NT_STATUS_IS_OK(status
)) {
2470 d_fprintf(stderr
, "cli_open returned %s\n", cli_errstr(cli1
));
2474 /* Ensure the child has the lock. */
2475 if (cli_lock(cli1
, fnum
, 0, 4, 0, WRITE_LOCK
)) {
2476 d_fprintf(stderr
, "Got the lock on range 0:4 - this should not happen !\n");
2479 d_printf("Child has the lock.\n");
2482 /* Tell the child to wait 5 seconds then exit. */
2483 ret
= write(pipe_out
[1], &c
, 1);
2485 d_fprintf(stderr
, "failed to send exit signal to child. %s\n",
2490 /* Wait 20 seconds for the lock. */
2491 alarm_fd
= cli1
->fd
;
2492 CatchSignal(SIGALRM
, alarm_handler_parent
);
2495 start
= timeval_current();
2497 if (!cli_lock(cli1
, fnum
, 0, 4, -1, WRITE_LOCK
)) {
2498 d_fprintf(stderr
, "Unable to apply write lock on range 0:4, error was "
2499 "%s\n", cli_errstr(cli1
));
2504 seconds
= timeval_elapsed(&start
);
2506 printf("Parent got the lock after %.2f seconds.\n",
2509 status
= cli_close(cli1
, fnum
);
2510 if (!NT_STATUS_IS_OK(status
)) {
2511 d_fprintf(stderr
, "cli_close(fnum1) %s\n", cli_errstr(cli1
));
2518 cli_close(cli1
, fnum
);
2519 torture_close_connection(cli1
);
2523 printf("finished locktest9\n");
2528 test whether fnums and tids open on one VC are available on another (a major
2531 static bool run_fdpasstest(int dummy
)
2533 struct cli_state
*cli1
, *cli2
;
2534 const char *fname
= "\\fdpass.tst";
2538 if (!torture_open_connection(&cli1
, 0) || !torture_open_connection(&cli2
, 1)) {
2541 cli_sockopt(cli1
, sockops
);
2542 cli_sockopt(cli2
, sockops
);
2544 printf("starting fdpasstest\n");
2546 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
2548 if (!NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
))) {
2549 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
2553 if (cli_write(cli1
, fnum1
, 0, "hello world\n", 0, 13) != 13) {
2554 printf("write failed (%s)\n", cli_errstr(cli1
));
2558 cli2
->vuid
= cli1
->vuid
;
2559 cli2
->cnum
= cli1
->cnum
;
2560 cli2
->pid
= cli1
->pid
;
2562 if (cli_read(cli2
, fnum1
, buf
, 0, 13) == 13) {
2563 printf("read succeeded! nasty security hole [%s]\n",
2568 cli_close(cli1
, fnum1
);
2569 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
2571 torture_close_connection(cli1
);
2572 torture_close_connection(cli2
);
2574 printf("finished fdpasstest\n");
2578 static bool run_fdsesstest(int dummy
)
2580 struct cli_state
*cli
;
2585 const char *fname
= "\\fdsess.tst";
2586 const char *fname1
= "\\fdsess1.tst";
2592 if (!torture_open_connection(&cli
, 0))
2594 cli_sockopt(cli
, sockops
);
2596 if (!torture_cli_session_setup2(cli
, &new_vuid
))
2599 saved_cnum
= cli
->cnum
;
2600 if (!NT_STATUS_IS_OK(cli_tcon_andx(cli
, share
, "?????", "", 1)))
2602 new_cnum
= cli
->cnum
;
2603 cli
->cnum
= saved_cnum
;
2605 printf("starting fdsesstest\n");
2607 cli_unlink(cli
, fname
, aSYSTEM
| aHIDDEN
);
2608 cli_unlink(cli
, fname1
, aSYSTEM
| aHIDDEN
);
2610 if (!NT_STATUS_IS_OK(cli_open(cli
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
))) {
2611 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli
));
2615 if (cli_write(cli
, fnum1
, 0, "hello world\n", 0, 13) != 13) {
2616 printf("write failed (%s)\n", cli_errstr(cli
));
2620 saved_vuid
= cli
->vuid
;
2621 cli
->vuid
= new_vuid
;
2623 if (cli_read(cli
, fnum1
, buf
, 0, 13) == 13) {
2624 printf("read succeeded with different vuid! nasty security hole [%s]\n",
2628 /* Try to open a file with different vuid, samba cnum. */
2629 if (NT_STATUS_IS_OK(cli_open(cli
, fname1
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum2
))) {
2630 printf("create with different vuid, same cnum succeeded.\n");
2631 cli_close(cli
, fnum2
);
2632 cli_unlink(cli
, fname1
, aSYSTEM
| aHIDDEN
);
2634 printf("create with different vuid, same cnum failed.\n");
2635 printf("This will cause problems with service clients.\n");
2639 cli
->vuid
= saved_vuid
;
2641 /* Try with same vuid, different cnum. */
2642 cli
->cnum
= new_cnum
;
2644 if (cli_read(cli
, fnum1
, buf
, 0, 13) == 13) {
2645 printf("read succeeded with different cnum![%s]\n",
2650 cli
->cnum
= saved_cnum
;
2651 cli_close(cli
, fnum1
);
2652 cli_unlink(cli
, fname
, aSYSTEM
| aHIDDEN
);
2654 torture_close_connection(cli
);
2656 printf("finished fdsesstest\n");
2661 This test checks that
2663 1) the server does not allow an unlink on a file that is open
2665 static bool run_unlinktest(int dummy
)
2667 struct cli_state
*cli
;
2668 const char *fname
= "\\unlink.tst";
2670 bool correct
= True
;
2672 if (!torture_open_connection(&cli
, 0)) {
2676 cli_sockopt(cli
, sockops
);
2678 printf("starting unlink test\n");
2680 cli_unlink(cli
, fname
, aSYSTEM
| aHIDDEN
);
2684 if (!NT_STATUS_IS_OK(cli_open(cli
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum
))) {
2685 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli
));
2689 if (NT_STATUS_IS_OK(cli_unlink(cli
, fname
, aSYSTEM
| aHIDDEN
))) {
2690 printf("error: server allowed unlink on an open file\n");
2693 correct
= check_error(__LINE__
, cli
, ERRDOS
, ERRbadshare
,
2694 NT_STATUS_SHARING_VIOLATION
);
2697 cli_close(cli
, fnum
);
2698 cli_unlink(cli
, fname
, aSYSTEM
| aHIDDEN
);
2700 if (!torture_close_connection(cli
)) {
2704 printf("unlink test finished\n");
2711 test how many open files this server supports on the one socket
2713 static bool run_maxfidtest(int dummy
)
2715 struct cli_state
*cli
;
2716 const char *ftemplate
= "\\maxfid.%d.%d";
2718 uint16_t fnums
[0x11000];
2721 bool correct
= True
;
2726 printf("failed to connect\n");
2730 cli_sockopt(cli
, sockops
);
2732 for (i
=0; i
<0x11000; i
++) {
2733 slprintf(fname
,sizeof(fname
)-1,ftemplate
, i
,(int)getpid());
2734 if (!NT_STATUS_IS_OK(cli_open(cli
, fname
,
2735 O_RDWR
|O_CREAT
|O_TRUNC
, DENY_NONE
, &fnums
[i
]))) {
2736 printf("open of %s failed (%s)\n",
2737 fname
, cli_errstr(cli
));
2738 printf("maximum fnum is %d\n", i
);
2746 printf("cleaning up\n");
2748 slprintf(fname
,sizeof(fname
)-1,ftemplate
, i
,(int)getpid());
2749 cli_close(cli
, fnums
[i
]);
2750 if (!NT_STATUS_IS_OK(cli_unlink(cli
, fname
, aSYSTEM
| aHIDDEN
))) {
2751 printf("unlink of %s failed (%s)\n",
2752 fname
, cli_errstr(cli
));
2759 printf("maxfid test finished\n");
2760 if (!torture_close_connection(cli
)) {
2766 /* generate a random buffer */
2767 static void rand_buf(char *buf
, int len
)
2770 *buf
= (char)sys_random();
2775 /* send smb negprot commands, not reading the response */
2776 static bool run_negprot_nowait(int dummy
)
2779 static struct cli_state
*cli
;
2780 bool correct
= True
;
2782 printf("starting negprot nowait test\n");
2784 if (!(cli
= open_nbt_connection())) {
2788 for (i
=0;i
<50000;i
++) {
2789 cli_negprot_sendsync(cli
);
2792 if (!torture_close_connection(cli
)) {
2796 printf("finished negprot nowait test\n");
2801 /* send smb negprot commands, not reading the response */
2802 static bool run_bad_nbt_session(int dummy
)
2804 static struct cli_state
*cli
;
2806 printf("starting bad nbt session test\n");
2808 if (!(cli
= open_bad_nbt_connection())) {
2813 printf("finished bad nbt session test\n");
2817 /* send random IPC commands */
2818 static bool run_randomipc(int dummy
)
2820 char *rparam
= NULL
;
2822 unsigned int rdrcnt
,rprcnt
;
2824 int api
, param_len
, i
;
2825 struct cli_state
*cli
;
2826 bool correct
= True
;
2829 printf("starting random ipc test\n");
2831 if (!torture_open_connection(&cli
, 0)) {
2835 for (i
=0;i
<count
;i
++) {
2836 api
= sys_random() % 500;
2837 param_len
= (sys_random() % 64);
2839 rand_buf(param
, param_len
);
2844 param
, param_len
, 8,
2845 NULL
, 0, BUFFER_SIZE
,
2849 printf("%d/%d\r", i
,count
);
2852 printf("%d/%d\n", i
, count
);
2854 if (!torture_close_connection(cli
)) {
2858 printf("finished random ipc test\n");
2865 static void browse_callback(const char *sname
, uint32 stype
,
2866 const char *comment
, void *state
)
2868 printf("\t%20.20s %08x %s\n", sname
, stype
, comment
);
2874 This test checks the browse list code
2877 static bool run_browsetest(int dummy
)
2879 static struct cli_state
*cli
;
2880 bool correct
= True
;
2882 printf("starting browse test\n");
2884 if (!torture_open_connection(&cli
, 0)) {
2888 printf("domain list:\n");
2889 cli_NetServerEnum(cli
, cli
->server_domain
,
2890 SV_TYPE_DOMAIN_ENUM
,
2891 browse_callback
, NULL
);
2893 printf("machine list:\n");
2894 cli_NetServerEnum(cli
, cli
->server_domain
,
2896 browse_callback
, NULL
);
2898 if (!torture_close_connection(cli
)) {
2902 printf("browse test finished\n");
2910 This checks how the getatr calls works
2912 static bool run_attrtest(int dummy
)
2914 struct cli_state
*cli
;
2917 const char *fname
= "\\attrib123456789.tst";
2918 bool correct
= True
;
2920 printf("starting attrib test\n");
2922 if (!torture_open_connection(&cli
, 0)) {
2926 cli_unlink(cli
, fname
, aSYSTEM
| aHIDDEN
);
2927 cli_open(cli
, fname
,
2928 O_RDWR
| O_CREAT
| O_TRUNC
, DENY_NONE
, &fnum
);
2929 cli_close(cli
, fnum
);
2930 if (!NT_STATUS_IS_OK(cli_getatr(cli
, fname
, NULL
, NULL
, &t
))) {
2931 printf("getatr failed (%s)\n", cli_errstr(cli
));
2935 if (abs(t
- time(NULL
)) > 60*60*24*10) {
2936 printf("ERROR: SMBgetatr bug. time is %s",
2942 t2
= t
-60*60*24; /* 1 day ago */
2944 if (!NT_STATUS_IS_OK(cli_setatr(cli
, fname
, 0, t2
))) {
2945 printf("setatr failed (%s)\n", cli_errstr(cli
));
2949 if (!NT_STATUS_IS_OK(cli_getatr(cli
, fname
, NULL
, NULL
, &t
))) {
2950 printf("getatr failed (%s)\n", cli_errstr(cli
));
2955 printf("ERROR: getatr/setatr bug. times are\n%s",
2957 printf("%s", ctime(&t2
));
2961 cli_unlink(cli
, fname
, aSYSTEM
| aHIDDEN
);
2963 if (!torture_close_connection(cli
)) {
2967 printf("attrib test finished\n");
2974 This checks a couple of trans2 calls
2976 static bool run_trans2test(int dummy
)
2978 struct cli_state
*cli
;
2981 time_t c_time
, a_time
, m_time
;
2982 struct timespec c_time_ts
, a_time_ts
, m_time_ts
, w_time_ts
, m_time2_ts
;
2983 const char *fname
= "\\trans2.tst";
2984 const char *dname
= "\\trans2";
2985 const char *fname2
= "\\trans2\\trans2.tst";
2987 bool correct
= True
;
2991 printf("starting trans2 test\n");
2993 if (!torture_open_connection(&cli
, 0)) {
2997 status
= cli_get_fs_attr_info(cli
, &fs_attr
);
2998 if (!NT_STATUS_IS_OK(status
)) {
2999 printf("ERROR: cli_get_fs_attr_info returned %s\n",
3004 cli_unlink(cli
, fname
, aSYSTEM
| aHIDDEN
);
3005 cli_open(cli
, fname
,
3006 O_RDWR
| O_CREAT
| O_TRUNC
, DENY_NONE
, &fnum
);
3007 if (!NT_STATUS_IS_OK(cli_qfileinfo_basic(
3008 cli
, fnum
, NULL
, &size
, &c_time_ts
,
3009 &a_time_ts
, &w_time_ts
,
3010 &m_time_ts
, NULL
))) {
3011 printf("ERROR: qfileinfo failed (%s)\n", cli_errstr(cli
));
3015 if (!NT_STATUS_IS_OK(cli_qfilename(cli
, fnum
, pname
, sizeof(pname
)))) {
3016 printf("ERROR: qfilename failed (%s)\n", cli_errstr(cli
));
3020 if (strcmp(pname
, fname
)) {
3021 printf("qfilename gave different name? [%s] [%s]\n",
3026 cli_close(cli
, fnum
);
3030 cli_unlink(cli
, fname
, aSYSTEM
| aHIDDEN
);
3031 if (!NT_STATUS_IS_OK(cli_open(cli
, fname
,
3032 O_RDWR
| O_CREAT
| O_TRUNC
, DENY_NONE
, &fnum
))) {
3033 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli
));
3036 cli_close(cli
, fnum
);
3038 status
= cli_qpathinfo1(cli
, fname
, &c_time
, &a_time
, &m_time
, &size
,
3040 if (!NT_STATUS_IS_OK(status
)) {
3041 printf("ERROR: qpathinfo failed (%s)\n", nt_errstr(status
));
3044 if (c_time
!= m_time
) {
3045 printf("create time=%s", ctime(&c_time
));
3046 printf("modify time=%s", ctime(&m_time
));
3047 printf("This system appears to have sticky create times\n");
3049 if (a_time
% (60*60) == 0) {
3050 printf("access time=%s", ctime(&a_time
));
3051 printf("This system appears to set a midnight access time\n");
3055 if (abs(m_time
- time(NULL
)) > 60*60*24*7) {
3056 printf("ERROR: totally incorrect times - maybe word reversed? mtime=%s", ctime(&m_time
));
3062 cli_unlink(cli
, fname
, aSYSTEM
| aHIDDEN
);
3063 cli_open(cli
, fname
,
3064 O_RDWR
| O_CREAT
| O_TRUNC
, DENY_NONE
, &fnum
);
3065 cli_close(cli
, fnum
);
3066 status
= cli_qpathinfo2(cli
, fname
, &c_time_ts
, &a_time_ts
, &w_time_ts
,
3067 &m_time_ts
, &size
, NULL
, NULL
);
3068 if (!NT_STATUS_IS_OK(status
)) {
3069 printf("ERROR: qpathinfo2 failed (%s)\n", nt_errstr(status
));
3072 if (w_time_ts
.tv_sec
< 60*60*24*2) {
3073 printf("write time=%s", ctime(&w_time_ts
.tv_sec
));
3074 printf("This system appears to set a initial 0 write time\n");
3079 cli_unlink(cli
, fname
, aSYSTEM
| aHIDDEN
);
3082 /* check if the server updates the directory modification time
3083 when creating a new file */
3084 if (!NT_STATUS_IS_OK(cli_mkdir(cli
, dname
))) {
3085 printf("ERROR: mkdir failed (%s)\n", cli_errstr(cli
));
3089 status
= cli_qpathinfo2(cli
, "\\trans2\\", &c_time_ts
, &a_time_ts
,
3090 &w_time_ts
, &m_time_ts
, &size
, NULL
, NULL
);
3091 if (!NT_STATUS_IS_OK(status
)) {
3092 printf("ERROR: qpathinfo2 failed (%s)\n", nt_errstr(status
));
3096 cli_open(cli
, fname2
,
3097 O_RDWR
| O_CREAT
| O_TRUNC
, DENY_NONE
, &fnum
);
3098 cli_write(cli
, fnum
, 0, (char *)&fnum
, 0, sizeof(fnum
));
3099 cli_close(cli
, fnum
);
3100 status
= cli_qpathinfo2(cli
, "\\trans2\\", &c_time_ts
, &a_time_ts
,
3101 &w_time_ts
, &m_time2_ts
, &size
, NULL
, NULL
);
3102 if (!NT_STATUS_IS_OK(status
)) {
3103 printf("ERROR: qpathinfo2 failed (%s)\n", nt_errstr(status
));
3106 if (memcmp(&m_time_ts
, &m_time2_ts
, sizeof(struct timespec
))
3108 printf("This system does not update directory modification times\n");
3112 cli_unlink(cli
, fname2
, aSYSTEM
| aHIDDEN
);
3113 cli_rmdir(cli
, dname
);
3115 if (!torture_close_connection(cli
)) {
3119 printf("trans2 test finished\n");
3125 This checks new W2K calls.
3128 static NTSTATUS
new_trans(struct cli_state
*pcli
, int fnum
, int level
)
3130 uint8_t *buf
= NULL
;
3134 status
= cli_qfileinfo(talloc_tos(), pcli
, fnum
, level
, 0,
3135 pcli
->max_xmit
, &buf
, &len
);
3136 if (!NT_STATUS_IS_OK(status
)) {
3137 printf("ERROR: qfileinfo (%d) failed (%s)\n", level
,
3140 printf("qfileinfo: level %d, len = %u\n", level
, len
);
3141 dump_data(0, (uint8
*)buf
, len
);
3148 static bool run_w2ktest(int dummy
)
3150 struct cli_state
*cli
;
3152 const char *fname
= "\\w2ktest\\w2k.tst";
3154 bool correct
= True
;
3156 printf("starting w2k test\n");
3158 if (!torture_open_connection(&cli
, 0)) {
3162 cli_open(cli
, fname
,
3163 O_RDWR
| O_CREAT
, DENY_NONE
, &fnum
);
3165 for (level
= 1004; level
< 1040; level
++) {
3166 new_trans(cli
, fnum
, level
);
3169 cli_close(cli
, fnum
);
3171 if (!torture_close_connection(cli
)) {
3175 printf("w2k test finished\n");
3182 this is a harness for some oplock tests
3184 static bool run_oplock1(int dummy
)
3186 struct cli_state
*cli1
;
3187 const char *fname
= "\\lockt1.lck";
3189 bool correct
= True
;
3191 printf("starting oplock test 1\n");
3193 if (!torture_open_connection(&cli1
, 0)) {
3197 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
3199 cli_sockopt(cli1
, sockops
);
3201 cli1
->use_oplocks
= True
;
3203 if (!NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
))) {
3204 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3208 cli1
->use_oplocks
= False
;
3210 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
3211 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
3213 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3214 printf("close2 failed (%s)\n", cli_errstr(cli1
));
3218 if (!NT_STATUS_IS_OK(cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
))) {
3219 printf("unlink failed (%s)\n", cli_errstr(cli1
));
3223 if (!torture_close_connection(cli1
)) {
3227 printf("finished oplock test 1\n");
3232 static bool run_oplock2(int dummy
)
3234 struct cli_state
*cli1
, *cli2
;
3235 const char *fname
= "\\lockt2.lck";
3236 uint16_t fnum1
, fnum2
;
3237 int saved_use_oplocks
= use_oplocks
;
3239 bool correct
= True
;
3240 volatile bool *shared_correct
;
3242 shared_correct
= (volatile bool *)shm_setup(sizeof(bool));
3243 *shared_correct
= True
;
3245 use_level_II_oplocks
= True
;
3248 printf("starting oplock test 2\n");
3250 if (!torture_open_connection(&cli1
, 0)) {
3251 use_level_II_oplocks
= False
;
3252 use_oplocks
= saved_use_oplocks
;
3256 cli1
->use_oplocks
= True
;
3257 cli1
->use_level_II_oplocks
= True
;
3259 if (!torture_open_connection(&cli2
, 1)) {
3260 use_level_II_oplocks
= False
;
3261 use_oplocks
= saved_use_oplocks
;
3265 cli2
->use_oplocks
= True
;
3266 cli2
->use_level_II_oplocks
= True
;
3268 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
3270 cli_sockopt(cli1
, sockops
);
3271 cli_sockopt(cli2
, sockops
);
3273 if (!NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
))) {
3274 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3278 /* Don't need the globals any more. */
3279 use_level_II_oplocks
= False
;
3280 use_oplocks
= saved_use_oplocks
;
3284 if (!NT_STATUS_IS_OK(cli_open(cli2
, fname
, O_RDWR
, DENY_NONE
, &fnum2
))) {
3285 printf("second open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3286 *shared_correct
= False
;
3292 if (!NT_STATUS_IS_OK(cli_close(cli2
, fnum2
))) {
3293 printf("close2 failed (%s)\n", cli_errstr(cli1
));
3294 *shared_correct
= False
;
3302 /* Ensure cli1 processes the break. Empty file should always return 0
3305 if (cli_read(cli1
, fnum1
, buf
, 0, 4) != 0) {
3306 printf("read on fnum1 failed (%s)\n", cli_errstr(cli1
));
3310 /* Should now be at level II. */
3311 /* Test if sending a write locks causes a break to none. */
3313 if (!cli_lock(cli1
, fnum1
, 0, 4, 0, READ_LOCK
)) {
3314 printf("lock failed (%s)\n", cli_errstr(cli1
));
3318 cli_unlock(cli1
, fnum1
, 0, 4);
3322 if (!cli_lock(cli1
, fnum1
, 0, 4, 0, WRITE_LOCK
)) {
3323 printf("lock failed (%s)\n", cli_errstr(cli1
));
3327 cli_unlock(cli1
, fnum1
, 0, 4);
3331 cli_read(cli1
, fnum1
, buf
, 0, 4);
3334 if (cli_write(cli1
, fnum1
, 0, buf
, 0, 4) != 4) {
3335 printf("write on fnum1 failed (%s)\n", cli_errstr(cli1
));
3340 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3341 printf("close1 failed (%s)\n", cli_errstr(cli1
));
3347 if (!NT_STATUS_IS_OK(cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
))) {
3348 printf("unlink failed (%s)\n", cli_errstr(cli1
));
3352 if (!torture_close_connection(cli1
)) {
3356 if (!*shared_correct
) {
3360 printf("finished oplock test 2\n");
3365 /* handler for oplock 3 tests */
3366 static NTSTATUS
oplock3_handler(struct cli_state
*cli
, uint16_t fnum
, unsigned char level
)
3368 printf("got oplock break fnum=%d level=%d\n",
3370 return cli_oplock_ack(cli
, fnum
, level
);
3373 static bool run_oplock3(int dummy
)
3375 struct cli_state
*cli
;
3376 const char *fname
= "\\oplockt3.dat";
3378 char buf
[4] = "abcd";
3379 bool correct
= True
;
3380 volatile bool *shared_correct
;
3382 shared_correct
= (volatile bool *)shm_setup(sizeof(bool));
3383 *shared_correct
= True
;
3385 printf("starting oplock test 3\n");
3390 use_level_II_oplocks
= True
;
3391 if (!torture_open_connection(&cli
, 0)) {
3392 *shared_correct
= False
;
3396 /* try to trigger a oplock break in parent */
3397 cli_open(cli
, fname
, O_RDWR
, DENY_NONE
, &fnum
);
3398 cli_write(cli
, fnum
, 0, buf
, 0, 4);
3404 use_level_II_oplocks
= True
;
3405 if (!torture_open_connection(&cli
, 1)) { /* other is forked */
3408 cli_oplock_handler(cli
, oplock3_handler
);
3409 cli_open(cli
, fname
, O_RDWR
|O_CREAT
, DENY_NONE
, &fnum
);
3410 cli_write(cli
, fnum
, 0, buf
, 0, 4);
3411 cli_close(cli
, fnum
);
3412 cli_open(cli
, fname
, O_RDWR
, DENY_NONE
, &fnum
);
3413 cli
->timeout
= 20000;
3414 cli_receive_smb(cli
);
3415 printf("finished oplock test 3\n");
3417 return (correct
&& *shared_correct
);
3419 /* What are we looking for here? What's sucess and what's FAILURE? */
3422 /* handler for oplock 4 tests */
3423 bool *oplock4_shared_correct
;
3425 static NTSTATUS
oplock4_handler(struct cli_state
*cli
, uint16_t fnum
, unsigned char level
)
3427 printf("got oplock break fnum=%d level=%d\n",
3429 *oplock4_shared_correct
= true;
3430 cli_oplock_ack(cli
, fnum
, level
);
3431 return NT_STATUS_UNSUCCESSFUL
; /* Cause cli_receive_smb to return. */
3434 static bool run_oplock4(int dummy
)
3436 struct cli_state
*cli1
, *cli2
;
3437 const char *fname
= "\\lockt4.lck";
3438 const char *fname_ln
= "\\lockt4_ln.lck";
3439 uint16_t fnum1
, fnum2
;
3440 int saved_use_oplocks
= use_oplocks
;
3442 bool correct
= true;
3444 oplock4_shared_correct
= (bool *)shm_setup(sizeof(bool));
3445 *oplock4_shared_correct
= false;
3447 printf("starting oplock test 4\n");
3449 if (!torture_open_connection(&cli1
, 0)) {
3450 use_level_II_oplocks
= false;
3451 use_oplocks
= saved_use_oplocks
;
3455 if (!torture_open_connection(&cli2
, 1)) {
3456 use_level_II_oplocks
= false;
3457 use_oplocks
= saved_use_oplocks
;
3461 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
3462 cli_unlink(cli1
, fname_ln
, aSYSTEM
| aHIDDEN
);
3464 cli_sockopt(cli1
, sockops
);
3465 cli_sockopt(cli2
, sockops
);
3467 /* Create the file. */
3468 if (!NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
))) {
3469 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3473 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3474 printf("close1 failed (%s)\n", cli_errstr(cli1
));
3478 /* Now create a hardlink. */
3479 if (!NT_STATUS_IS_OK(cli_nt_hardlink(cli1
, fname
, fname_ln
))) {
3480 printf("nt hardlink failed (%s)\n", cli_errstr(cli1
));
3484 /* Prove that opening hardlinks cause deny modes to conflict. */
3485 if (!NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDWR
, DENY_ALL
, &fnum1
))) {
3486 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3490 status
= cli_open(cli1
, fname_ln
, O_RDWR
, DENY_NONE
, &fnum2
);
3491 if (NT_STATUS_IS_OK(status
)) {
3492 printf("open of %s succeeded - should fail with sharing violation.\n",
3497 if (!NT_STATUS_EQUAL(status
, NT_STATUS_SHARING_VIOLATION
)) {
3498 printf("open of %s should fail with sharing violation. Got %s\n",
3499 fname_ln
, nt_errstr(status
));
3503 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3504 printf("close1 failed (%s)\n", cli_errstr(cli1
));
3508 cli1
->use_oplocks
= true;
3509 cli1
->use_level_II_oplocks
= true;
3511 cli2
->use_oplocks
= true;
3512 cli2
->use_level_II_oplocks
= true;
3514 cli_oplock_handler(cli1
, oplock4_handler
);
3515 if (!NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
, &fnum1
))) {
3516 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3522 if (!NT_STATUS_IS_OK(cli_open(cli2
, fname_ln
, O_RDWR
, DENY_NONE
, &fnum2
))) {
3523 printf("open of %s failed (%s)\n", fname_ln
, cli_errstr(cli1
));
3524 *oplock4_shared_correct
= false;
3528 if (!NT_STATUS_IS_OK(cli_close(cli2
, fnum2
))) {
3529 printf("close2 failed (%s)\n", cli_errstr(cli1
));
3530 *oplock4_shared_correct
= false;
3538 /* Process the oplock break. */
3539 cli_receive_smb(cli1
);
3541 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3542 printf("close1 failed (%s)\n", cli_errstr(cli1
));
3546 if (!NT_STATUS_IS_OK(cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
))) {
3547 printf("unlink failed (%s)\n", cli_errstr(cli1
));
3550 if (!NT_STATUS_IS_OK(cli_unlink(cli1
, fname_ln
, aSYSTEM
| aHIDDEN
))) {
3551 printf("unlink failed (%s)\n", cli_errstr(cli1
));
3555 if (!torture_close_connection(cli1
)) {
3559 if (!*oplock4_shared_correct
) {
3563 printf("finished oplock test 4\n");
3570 Test delete on close semantics.
3572 static bool run_deletetest(int dummy
)
3574 struct cli_state
*cli1
= NULL
;
3575 struct cli_state
*cli2
= NULL
;
3576 const char *fname
= "\\delete.file";
3577 uint16_t fnum1
= (uint16_t)-1;
3578 uint16_t fnum2
= (uint16_t)-1;
3579 bool correct
= True
;
3581 printf("starting delete test\n");
3583 if (!torture_open_connection(&cli1
, 0)) {
3587 cli_sockopt(cli1
, sockops
);
3589 /* Test 1 - this should delete the file on close. */
3591 cli_setatr(cli1
, fname
, 0, 0);
3592 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
3594 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, GENERIC_ALL_ACCESS
|DELETE_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
3595 0, FILE_OVERWRITE_IF
,
3596 FILE_DELETE_ON_CLOSE
, 0, &fnum1
))) {
3597 printf("[1] open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3602 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3603 printf("[1] close failed (%s)\n", cli_errstr(cli1
));
3608 if (NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
, &fnum1
))) {
3609 printf("[1] open of %s succeeded (should fail)\n", fname
);
3614 printf("first delete on close test succeeded.\n");
3616 /* Test 2 - this should delete the file on close. */
3618 cli_setatr(cli1
, fname
, 0, 0);
3619 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
3621 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, GENERIC_ALL_ACCESS
,
3622 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_NONE
,
3623 FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
3624 printf("[2] open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3629 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1
, fnum1
, true))) {
3630 printf("[2] setting delete_on_close failed (%s)\n", cli_errstr(cli1
));
3635 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3636 printf("[2] close failed (%s)\n", cli_errstr(cli1
));
3641 if (NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDONLY
, DENY_NONE
, &fnum1
))) {
3642 printf("[2] open of %s succeeded should have been deleted on close !\n", fname
);
3643 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3644 printf("[2] close failed (%s)\n", cli_errstr(cli1
));
3648 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
3650 printf("second delete on close test succeeded.\n");
3653 cli_setatr(cli1
, fname
, 0, 0);
3654 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
3656 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, GENERIC_ALL_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
3657 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
3658 printf("[3] open - 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3663 /* This should fail with a sharing violation - open for delete is only compatible
3664 with SHARE_DELETE. */
3666 if (NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, GENERIC_READ_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
3667 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OPEN
, 0, 0, &fnum2
))) {
3668 printf("[3] open - 2 of %s succeeded - should have failed.\n", fname
);
3673 /* This should succeed. */
3675 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, GENERIC_READ_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
3676 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, FILE_OPEN
, 0, 0, &fnum2
))) {
3677 printf("[3] open - 2 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3682 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1
, fnum1
, true))) {
3683 printf("[3] setting delete_on_close failed (%s)\n", cli_errstr(cli1
));
3688 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3689 printf("[3] close 1 failed (%s)\n", cli_errstr(cli1
));
3694 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum2
))) {
3695 printf("[3] close 2 failed (%s)\n", cli_errstr(cli1
));
3700 /* This should fail - file should no longer be there. */
3702 if (NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDONLY
, DENY_NONE
, &fnum1
))) {
3703 printf("[3] open of %s succeeded should have been deleted on close !\n", fname
);
3704 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3705 printf("[3] close failed (%s)\n", cli_errstr(cli1
));
3707 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
3711 printf("third delete on close test succeeded.\n");
3714 cli_setatr(cli1
, fname
, 0, 0);
3715 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
3717 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, FILE_READ_DATA
|FILE_WRITE_DATA
|DELETE_ACCESS
,
3718 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
3719 printf("[4] open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3724 /* This should succeed. */
3725 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, GENERIC_READ_ACCESS
,
3726 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, FILE_OPEN
, 0, 0, &fnum2
))) {
3727 printf("[4] open - 2 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3732 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum2
))) {
3733 printf("[4] close - 1 failed (%s)\n", cli_errstr(cli1
));
3738 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1
, fnum1
, true))) {
3739 printf("[4] setting delete_on_close failed (%s)\n", cli_errstr(cli1
));
3744 /* This should fail - no more opens once delete on close set. */
3745 if (NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, GENERIC_READ_ACCESS
,
3746 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
3747 FILE_OPEN
, 0, 0, &fnum2
))) {
3748 printf("[4] open - 3 of %s succeeded ! Should have failed.\n", fname
);
3752 printf("fourth delete on close test succeeded.\n");
3754 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3755 printf("[4] close - 2 failed (%s)\n", cli_errstr(cli1
));
3761 cli_setatr(cli1
, fname
, 0, 0);
3762 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
3764 if (!NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDWR
|O_CREAT
, DENY_NONE
, &fnum1
))) {
3765 printf("[5] open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3770 /* This should fail - only allowed on NT opens with DELETE access. */
3772 if (NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1
, fnum1
, true))) {
3773 printf("[5] setting delete_on_close on OpenX file succeeded - should fail !\n");
3778 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3779 printf("[5] close - 2 failed (%s)\n", cli_errstr(cli1
));
3784 printf("fifth delete on close test succeeded.\n");
3787 cli_setatr(cli1
, fname
, 0, 0);
3788 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
3790 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, FILE_READ_DATA
|FILE_WRITE_DATA
,
3791 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
3792 FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
3793 printf("[6] open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3798 /* This should fail - only allowed on NT opens with DELETE access. */
3800 if (NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1
, fnum1
, true))) {
3801 printf("[6] setting delete_on_close on file with no delete access succeeded - should fail !\n");
3806 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3807 printf("[6] close - 2 failed (%s)\n", cli_errstr(cli1
));
3812 printf("sixth delete on close test succeeded.\n");
3815 cli_setatr(cli1
, fname
, 0, 0);
3816 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
3818 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, FILE_READ_DATA
|FILE_WRITE_DATA
|DELETE_ACCESS
,
3819 FILE_ATTRIBUTE_NORMAL
, 0, FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
3820 printf("[7] open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3825 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1
, fnum1
, true))) {
3826 printf("[7] setting delete_on_close on file failed !\n");
3831 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1
, fnum1
, false))) {
3832 printf("[7] unsetting delete_on_close on file failed !\n");
3837 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3838 printf("[7] close - 2 failed (%s)\n", cli_errstr(cli1
));
3843 /* This next open should succeed - we reset the flag. */
3845 if (!NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDONLY
, DENY_NONE
, &fnum1
))) {
3846 printf("[5] open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3851 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3852 printf("[7] close - 2 failed (%s)\n", cli_errstr(cli1
));
3857 printf("seventh delete on close test succeeded.\n");
3860 cli_setatr(cli1
, fname
, 0, 0);
3861 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
3863 if (!torture_open_connection(&cli2
, 1)) {
3864 printf("[8] failed to open second connection.\n");
3869 cli_sockopt(cli1
, sockops
);
3871 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, FILE_READ_DATA
|FILE_WRITE_DATA
|DELETE_ACCESS
,
3872 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
3873 FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
3874 printf("[8] open 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3879 if (!NT_STATUS_IS_OK(cli_ntcreate(cli2
, fname
, 0, FILE_READ_DATA
|FILE_WRITE_DATA
|DELETE_ACCESS
,
3880 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
3881 FILE_OPEN
, 0, 0, &fnum2
))) {
3882 printf("[8] open 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
3887 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1
, fnum1
, true))) {
3888 printf("[8] setting delete_on_close on file failed !\n");
3893 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3894 printf("[8] close - 1 failed (%s)\n", cli_errstr(cli1
));
3899 if (!NT_STATUS_IS_OK(cli_close(cli2
, fnum2
))) {
3900 printf("[8] close - 2 failed (%s)\n", cli_errstr(cli2
));
3905 /* This should fail.. */
3906 if (NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDONLY
, DENY_NONE
, &fnum1
))) {
3907 printf("[8] open of %s succeeded should have been deleted on close !\n", fname
);
3911 printf("eighth delete on close test succeeded.\n");
3913 /* This should fail - we need to set DELETE_ACCESS. */
3914 if (NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0,FILE_READ_DATA
|FILE_WRITE_DATA
,
3915 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, FILE_DELETE_ON_CLOSE
, 0, &fnum1
))) {
3916 printf("[9] open of %s succeeded should have failed!\n", fname
);
3921 printf("ninth delete on close test succeeded.\n");
3923 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, FILE_READ_DATA
|FILE_WRITE_DATA
|DELETE_ACCESS
,
3924 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, FILE_DELETE_ON_CLOSE
, 0, &fnum1
))) {
3925 printf("[10] open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3930 /* This should delete the file. */
3931 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3932 printf("[10] close failed (%s)\n", cli_errstr(cli1
));
3937 /* This should fail.. */
3938 if (NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDONLY
, DENY_NONE
, &fnum1
))) {
3939 printf("[10] open of %s succeeded should have been deleted on close !\n", fname
);
3943 printf("tenth delete on close test succeeded.\n");
3945 cli_setatr(cli1
, fname
, 0, 0);
3946 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
3948 /* What error do we get when attempting to open a read-only file with
3951 /* Create a readonly file. */
3952 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, FILE_READ_DATA
|FILE_WRITE_DATA
,
3953 FILE_ATTRIBUTE_READONLY
, FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
3954 printf("[11] open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
3959 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
3960 printf("[11] close failed (%s)\n", cli_errstr(cli1
));
3965 /* Now try open for delete access. */
3966 if (NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, FILE_READ_ATTRIBUTES
|DELETE_ACCESS
,
3967 0, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
3968 FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
3969 printf("[11] open of %s succeeded should have been denied with ACCESS_DENIED!\n", fname
);
3970 cli_close(cli1
, fnum1
);
3974 NTSTATUS nterr
= cli_nt_error(cli1
);
3975 if (!NT_STATUS_EQUAL(nterr
,NT_STATUS_ACCESS_DENIED
)) {
3976 printf("[11] open of %s should have been denied with ACCESS_DENIED! Got error %s\n", fname
, nt_errstr(nterr
));
3980 printf("eleventh delete on close test succeeded.\n");
3984 printf("finished delete test\n");
3987 /* FIXME: This will crash if we aborted before cli2 got
3988 * intialized, because these functions don't handle
3989 * uninitialized connections. */
3991 if (fnum1
!= (uint16_t)-1) cli_close(cli1
, fnum1
);
3992 if (fnum2
!= (uint16_t)-1) cli_close(cli1
, fnum2
);
3993 cli_setatr(cli1
, fname
, 0, 0);
3994 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
3996 if (cli1
&& !torture_close_connection(cli1
)) {
3999 if (cli2
&& !torture_close_connection(cli2
)) {
4005 static bool run_deletetest_ln(int dummy
)
4007 struct cli_state
*cli
;
4008 const char *fname
= "\\delete1";
4009 const char *fname_ln
= "\\delete1_ln";
4013 bool correct
= true;
4016 printf("starting deletetest-ln\n");
4018 if (!torture_open_connection(&cli
, 0)) {
4022 cli_unlink(cli
, fname
, aSYSTEM
| aHIDDEN
);
4023 cli_unlink(cli
, fname_ln
, aSYSTEM
| aHIDDEN
);
4025 cli_sockopt(cli
, sockops
);
4027 /* Create the file. */
4028 if (!NT_STATUS_IS_OK(cli_open(cli
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum
))) {
4029 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli
));
4033 if (!NT_STATUS_IS_OK(cli_close(cli
, fnum
))) {
4034 printf("close1 failed (%s)\n", cli_errstr(cli
));
4038 /* Now create a hardlink. */
4039 if (!NT_STATUS_IS_OK(cli_nt_hardlink(cli
, fname
, fname_ln
))) {
4040 printf("nt hardlink failed (%s)\n", cli_errstr(cli
));
4044 /* Open the original file. */
4045 status
= cli_ntcreate(cli
, fname
, 0, FILE_READ_DATA
,
4046 FILE_ATTRIBUTE_NORMAL
,
4047 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
4048 FILE_OPEN_IF
, 0, 0, &fnum
);
4049 if (!NT_STATUS_IS_OK(status
)) {
4050 printf("ntcreate of %s failed (%s)\n", fname
, nt_errstr(status
));
4054 /* Unlink the hard link path. */
4055 status
= cli_ntcreate(cli
, fname_ln
, 0, DELETE_ACCESS
,
4056 FILE_ATTRIBUTE_NORMAL
,
4057 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
4058 FILE_OPEN_IF
, 0, 0, &fnum1
);
4059 if (!NT_STATUS_IS_OK(status
)) {
4060 printf("ntcreate of %s failed (%s)\n", fname_ln
, nt_errstr(status
));
4063 status
= cli_nt_delete_on_close(cli
, fnum1
, true);
4064 if (!NT_STATUS_IS_OK(status
)) {
4065 d_printf("(%s) failed to set delete_on_close %s: %s\n",
4066 __location__
, fname_ln
, nt_errstr(status
));
4070 status
= cli_close(cli
, fnum1
);
4071 if (!NT_STATUS_IS_OK(status
)) {
4072 printf("close %s failed (%s)\n",
4073 fname_ln
, nt_errstr(status
));
4077 status
= cli_close(cli
, fnum
);
4078 if (!NT_STATUS_IS_OK(status
)) {
4079 printf("close %s failed (%s)\n",
4080 fname
, nt_errstr(status
));
4084 /* Ensure the original file is still there. */
4085 status
= cli_getatr(cli
, fname
, NULL
, NULL
, &t
);
4086 if (!NT_STATUS_IS_OK(status
)) {
4087 printf("%s getatr on file %s failed (%s)\n",
4094 /* Ensure the link path is gone. */
4095 status
= cli_getatr(cli
, fname_ln
, NULL
, NULL
, &t
);
4096 if (!NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
)) {
4097 printf("%s, getatr for file %s returned wrong error code %s "
4098 "- should have been deleted\n",
4100 fname_ln
, nt_errstr(status
));
4104 cli_unlink(cli
, fname
, aSYSTEM
| aHIDDEN
);
4105 cli_unlink(cli
, fname_ln
, aSYSTEM
| aHIDDEN
);
4107 if (!torture_close_connection(cli
)) {
4111 printf("finished deletetest-ln\n");
4117 print out server properties
4119 static bool run_properties(int dummy
)
4121 struct cli_state
*cli
;
4122 bool correct
= True
;
4124 printf("starting properties test\n");
4128 if (!torture_open_connection(&cli
, 0)) {
4132 cli_sockopt(cli
, sockops
);
4134 d_printf("Capabilities 0x%08x\n", cli
->capabilities
);
4136 if (!torture_close_connection(cli
)) {
4145 /* FIRST_DESIRED_ACCESS 0xf019f */
4146 #define FIRST_DESIRED_ACCESS FILE_READ_DATA|FILE_WRITE_DATA|FILE_APPEND_DATA|\
4147 FILE_READ_EA| /* 0xf */ \
4148 FILE_WRITE_EA|FILE_READ_ATTRIBUTES| /* 0x90 */ \
4149 FILE_WRITE_ATTRIBUTES| /* 0x100 */ \
4150 DELETE_ACCESS|READ_CONTROL_ACCESS|\
4151 WRITE_DAC_ACCESS|WRITE_OWNER_ACCESS /* 0xf0000 */
4152 /* SECOND_DESIRED_ACCESS 0xe0080 */
4153 #define SECOND_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
4154 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
4155 WRITE_OWNER_ACCESS /* 0xe0000 */
4158 #define THIRD_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
4159 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
4161 WRITE_OWNER_ACCESS /* */
4165 Test ntcreate calls made by xcopy
4167 static bool run_xcopy(int dummy
)
4169 static struct cli_state
*cli1
;
4170 const char *fname
= "\\test.txt";
4171 bool correct
= True
;
4172 uint16_t fnum1
, fnum2
;
4174 printf("starting xcopy test\n");
4176 if (!torture_open_connection(&cli1
, 0)) {
4180 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0,
4181 FIRST_DESIRED_ACCESS
, FILE_ATTRIBUTE_ARCHIVE
,
4182 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
,
4183 0x4044, 0, &fnum1
))) {
4184 printf("First open failed - %s\n", cli_errstr(cli1
));
4188 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0,
4189 SECOND_DESIRED_ACCESS
, 0,
4190 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, FILE_OPEN
,
4191 0x200000, 0, &fnum2
))) {
4192 printf("second open failed - %s\n", cli_errstr(cli1
));
4196 if (!torture_close_connection(cli1
)) {
4204 Test rename on files open with share delete and no share delete.
4206 static bool run_rename(int dummy
)
4208 static struct cli_state
*cli1
;
4209 const char *fname
= "\\test.txt";
4210 const char *fname1
= "\\test1.txt";
4211 bool correct
= True
;
4216 printf("starting rename test\n");
4218 if (!torture_open_connection(&cli1
, 0)) {
4222 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
4223 cli_unlink(cli1
, fname1
, aSYSTEM
| aHIDDEN
);
4224 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, GENERIC_READ_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
4225 FILE_SHARE_READ
, FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
4226 printf("First open failed - %s\n", cli_errstr(cli1
));
4230 if (!NT_STATUS_IS_OK(cli_rename(cli1
, fname
, fname1
))) {
4231 printf("First rename failed (SHARE_READ) (this is correct) - %s\n", cli_errstr(cli1
));
4233 printf("First rename succeeded (SHARE_READ) - this should have failed !\n");
4237 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4238 printf("close - 1 failed (%s)\n", cli_errstr(cli1
));
4242 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
4243 cli_unlink(cli1
, fname1
, aSYSTEM
| aHIDDEN
);
4244 status
= cli_ntcreate(cli1
, fname
, 0, GENERIC_READ_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
4246 FILE_SHARE_DELETE
|FILE_SHARE_NONE
,
4248 FILE_SHARE_DELETE
|FILE_SHARE_READ
,
4250 FILE_OVERWRITE_IF
, 0, 0, &fnum1
);
4251 if (!NT_STATUS_IS_OK(status
)) {
4252 printf("Second open failed - %s\n", cli_errstr(cli1
));
4256 if (!NT_STATUS_IS_OK(cli_rename(cli1
, fname
, fname1
))) {
4257 printf("Second rename failed (SHARE_DELETE | SHARE_READ) - this should have succeeded - %s\n", cli_errstr(cli1
));
4260 printf("Second rename succeeded (SHARE_DELETE | SHARE_READ)\n");
4263 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4264 printf("close - 2 failed (%s)\n", cli_errstr(cli1
));
4268 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
4269 cli_unlink(cli1
, fname1
, aSYSTEM
| aHIDDEN
);
4271 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, READ_CONTROL_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
4272 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
4273 printf("Third open failed - %s\n", cli_errstr(cli1
));
4282 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, DELETE_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
4283 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0, &fnum2
))) {
4284 printf("Fourth open failed - %s\n", cli_errstr(cli1
));
4287 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1
, fnum2
, true))) {
4288 printf("[8] setting delete_on_close on file failed !\n");
4292 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum2
))) {
4293 printf("close - 4 failed (%s)\n", cli_errstr(cli1
));
4299 if (!NT_STATUS_IS_OK(cli_rename(cli1
, fname
, fname1
))) {
4300 printf("Third rename failed (SHARE_NONE) - this should have succeeded - %s\n", cli_errstr(cli1
));
4303 printf("Third rename succeeded (SHARE_NONE)\n");
4306 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4307 printf("close - 3 failed (%s)\n", cli_errstr(cli1
));
4311 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
4312 cli_unlink(cli1
, fname1
, aSYSTEM
| aHIDDEN
);
4316 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, GENERIC_READ_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
4317 FILE_SHARE_READ
| FILE_SHARE_WRITE
, FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
4318 printf("Fourth open failed - %s\n", cli_errstr(cli1
));
4322 if (!NT_STATUS_IS_OK(cli_rename(cli1
, fname
, fname1
))) {
4323 printf("Fourth rename failed (SHARE_READ | SHARE_WRITE) (this is correct) - %s\n", cli_errstr(cli1
));
4325 printf("Fourth rename succeeded (SHARE_READ | SHARE_WRITE) - this should have failed !\n");
4329 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4330 printf("close - 4 failed (%s)\n", cli_errstr(cli1
));
4334 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
4335 cli_unlink(cli1
, fname1
, aSYSTEM
| aHIDDEN
);
4339 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, GENERIC_READ_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
4340 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
, FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
4341 printf("Fifth open failed - %s\n", cli_errstr(cli1
));
4345 if (!NT_STATUS_IS_OK(cli_rename(cli1
, fname
, fname1
))) {
4346 printf("Fifth rename failed (SHARE_READ | SHARE_WRITE | SHARE_DELETE) - this should have succeeded - %s ! \n",
4350 printf("Fifth rename succeeded (SHARE_READ | SHARE_WRITE | SHARE_DELETE) (this is correct) - %s\n", cli_errstr(cli1
));
4354 * Now check if the first name still exists ...
4357 /* if (!NT_STATUS_OP(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
4358 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0, 0, &fnum2))) {
4359 printf("Opening original file after rename of open file fails: %s\n",
4363 printf("Opening original file after rename of open file works ...\n");
4364 (void)cli_close(cli1, fnum2);
4368 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4369 printf("close - 5 failed (%s)\n", cli_errstr(cli1
));
4373 /* Check that the renamed file has FILE_ATTRIBUTE_ARCHIVE. */
4374 if (!NT_STATUS_IS_OK(cli_getatr(cli1
, fname1
, &attr
, NULL
, NULL
))) {
4375 printf("getatr on file %s failed - %s ! \n",
4380 if (attr
!= FILE_ATTRIBUTE_ARCHIVE
) {
4381 printf("Renamed file %s has wrong attr 0x%x "
4382 "(should be 0x%x)\n",
4385 (unsigned int)FILE_ATTRIBUTE_ARCHIVE
);
4388 printf("Renamed file %s has archive bit set\n", fname1
);
4392 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
4393 cli_unlink(cli1
, fname1
, aSYSTEM
| aHIDDEN
);
4395 if (!torture_close_connection(cli1
)) {
4402 static bool run_pipe_number(int dummy
)
4404 struct cli_state
*cli1
;
4405 const char *pipe_name
= "\\SPOOLSS";
4409 printf("starting pipenumber test\n");
4410 if (!torture_open_connection(&cli1
, 0)) {
4414 cli_sockopt(cli1
, sockops
);
4416 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, pipe_name
, 0, FILE_READ_DATA
, FILE_ATTRIBUTE_NORMAL
,
4417 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OPEN_IF
, 0, 0, &fnum
))) {
4418 printf("Open of pipe %s failed with error (%s)\n", pipe_name
, cli_errstr(cli1
));
4422 printf("\r%6d", num_pipes
);
4425 printf("pipe_number test - we can open %d %s pipes.\n", num_pipes
, pipe_name
);
4426 torture_close_connection(cli1
);
4431 Test open mode returns on read-only files.
4433 static bool run_opentest(int dummy
)
4435 static struct cli_state
*cli1
;
4436 static struct cli_state
*cli2
;
4437 const char *fname
= "\\readonly.file";
4438 uint16_t fnum1
, fnum2
;
4441 bool correct
= True
;
4445 printf("starting open test\n");
4447 if (!torture_open_connection(&cli1
, 0)) {
4451 cli_setatr(cli1
, fname
, 0, 0);
4452 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
4454 cli_sockopt(cli1
, sockops
);
4456 if (!NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
))) {
4457 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4461 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4462 printf("close2 failed (%s)\n", cli_errstr(cli1
));
4466 if (!NT_STATUS_IS_OK(cli_setatr(cli1
, fname
, aRONLY
, 0))) {
4467 printf("cli_setatr failed (%s)\n", cli_errstr(cli1
));
4471 if (!NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDONLY
, DENY_WRITE
, &fnum1
))) {
4472 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4476 /* This will fail - but the error should be ERRnoaccess, not ERRbadshare. */
4477 cli_open(cli1
, fname
, O_RDWR
, DENY_ALL
, &fnum2
);
4479 if (check_error(__LINE__
, cli1
, ERRDOS
, ERRnoaccess
,
4480 NT_STATUS_ACCESS_DENIED
)) {
4481 printf("correct error code ERRDOS/ERRnoaccess returned\n");
4484 printf("finished open test 1\n");
4486 cli_close(cli1
, fnum1
);
4488 /* Now try not readonly and ensure ERRbadshare is returned. */
4490 cli_setatr(cli1
, fname
, 0, 0);
4492 if (!NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDONLY
, DENY_WRITE
, &fnum1
))) {
4493 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4497 /* This will fail - but the error should be ERRshare. */
4498 cli_open(cli1
, fname
, O_RDWR
, DENY_ALL
, &fnum2
);
4500 if (check_error(__LINE__
, cli1
, ERRDOS
, ERRbadshare
,
4501 NT_STATUS_SHARING_VIOLATION
)) {
4502 printf("correct error code ERRDOS/ERRbadshare returned\n");
4505 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4506 printf("close2 failed (%s)\n", cli_errstr(cli1
));
4510 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
4512 printf("finished open test 2\n");
4514 /* Test truncate open disposition on file opened for read. */
4516 if (!NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
))) {
4517 printf("(3) open (1) of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4521 /* write 20 bytes. */
4523 memset(buf
, '\0', 20);
4525 if (cli_write(cli1
, fnum1
, 0, buf
, 0, 20) != 20) {
4526 printf("write failed (%s)\n", cli_errstr(cli1
));
4530 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4531 printf("(3) close1 failed (%s)\n", cli_errstr(cli1
));
4535 /* Ensure size == 20. */
4536 if (!NT_STATUS_IS_OK(cli_getatr(cli1
, fname
, NULL
, &fsize
, NULL
))) {
4537 printf("(3) getatr failed (%s)\n", cli_errstr(cli1
));
4542 printf("(3) file size != 20\n");
4546 /* Now test if we can truncate a file opened for readonly. */
4548 if (!NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDONLY
|O_TRUNC
, DENY_NONE
, &fnum1
))) {
4549 printf("(3) open (2) of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4553 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4554 printf("close2 failed (%s)\n", cli_errstr(cli1
));
4558 /* Ensure size == 0. */
4559 if (!NT_STATUS_IS_OK(cli_getatr(cli1
, fname
, NULL
, &fsize
, NULL
))) {
4560 printf("(3) getatr failed (%s)\n", cli_errstr(cli1
));
4565 printf("(3) file size != 0\n");
4568 printf("finished open test 3\n");
4570 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
4572 printf("Do ctemp tests\n");
4573 if (!NT_STATUS_IS_OK(cli_ctemp(cli1
, talloc_tos(), "\\", &fnum1
, &tmp_path
))) {
4574 printf("ctemp failed (%s)\n", cli_errstr(cli1
));
4577 printf("ctemp gave path %s\n", tmp_path
);
4578 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4579 printf("close of temp failed (%s)\n", cli_errstr(cli1
));
4581 if (!NT_STATUS_IS_OK(cli_unlink(cli1
, tmp_path
, aSYSTEM
| aHIDDEN
))) {
4582 printf("unlink of temp failed (%s)\n", cli_errstr(cli1
));
4585 /* Test the non-io opens... */
4587 if (!torture_open_connection(&cli2
, 1)) {
4591 cli_setatr(cli2
, fname
, 0, 0);
4592 cli_unlink(cli2
, fname
, aSYSTEM
| aHIDDEN
);
4594 cli_sockopt(cli2
, sockops
);
4596 printf("TEST #1 testing 2 non-io opens (no delete)\n");
4598 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
4599 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
4600 printf("TEST #1 open 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4604 if (!NT_STATUS_IS_OK(cli_ntcreate(cli2
, fname
, 0, FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
4605 FILE_SHARE_NONE
, FILE_OPEN_IF
, 0, 0, &fnum2
))) {
4606 printf("TEST #1 open 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
4610 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4611 printf("TEST #1 close 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4614 if (!NT_STATUS_IS_OK(cli_close(cli2
, fnum2
))) {
4615 printf("TEST #1 close 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
4619 printf("non-io open test #1 passed.\n");
4621 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
4623 printf("TEST #2 testing 2 non-io opens (first with delete)\n");
4625 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, DELETE_ACCESS
|FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
4626 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
4627 printf("TEST #2 open 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4631 if (!NT_STATUS_IS_OK(cli_ntcreate(cli2
, fname
, 0, FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
4632 FILE_SHARE_NONE
, FILE_OPEN_IF
, 0, 0, &fnum2
))) {
4633 printf("TEST #2 open 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
4637 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4638 printf("TEST #2 close 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4641 if (!NT_STATUS_IS_OK(cli_close(cli2
, fnum2
))) {
4642 printf("TEST #2 close 2 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4646 printf("non-io open test #2 passed.\n");
4648 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
4650 printf("TEST #3 testing 2 non-io opens (second with delete)\n");
4652 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
4653 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
4654 printf("TEST #3 open 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4658 if (!NT_STATUS_IS_OK(cli_ntcreate(cli2
, fname
, 0, DELETE_ACCESS
|FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
4659 FILE_SHARE_NONE
, FILE_OPEN_IF
, 0, 0, &fnum2
))) {
4660 printf("TEST #3 open 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
4664 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4665 printf("TEST #3 close 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4668 if (!NT_STATUS_IS_OK(cli_close(cli2
, fnum2
))) {
4669 printf("TEST #3 close 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
4673 printf("non-io open test #3 passed.\n");
4675 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
4677 printf("TEST #4 testing 2 non-io opens (both with delete)\n");
4679 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, DELETE_ACCESS
|FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
4680 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
4681 printf("TEST #4 open 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4685 if (NT_STATUS_IS_OK(cli_ntcreate(cli2
, fname
, 0, DELETE_ACCESS
|FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
4686 FILE_SHARE_NONE
, FILE_OPEN_IF
, 0, 0, &fnum2
))) {
4687 printf("TEST #4 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname
, cli_errstr(cli2
));
4691 printf("TEST #4 open 2 of %s gave %s (correct error should be %s)\n", fname
, cli_errstr(cli2
), "sharing violation");
4693 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4694 printf("TEST #4 close 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4698 printf("non-io open test #4 passed.\n");
4700 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
4702 printf("TEST #5 testing 2 non-io opens (both with delete - both with file share delete)\n");
4704 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, DELETE_ACCESS
|FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
4705 FILE_SHARE_DELETE
, FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
4706 printf("TEST #5 open 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4710 if (!NT_STATUS_IS_OK(cli_ntcreate(cli2
, fname
, 0, DELETE_ACCESS
|FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
4711 FILE_SHARE_DELETE
, FILE_OPEN_IF
, 0, 0, &fnum2
))) {
4712 printf("TEST #5 open 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
4716 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4717 printf("TEST #5 close 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4721 if (!NT_STATUS_IS_OK(cli_close(cli2
, fnum2
))) {
4722 printf("TEST #5 close 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
4726 printf("non-io open test #5 passed.\n");
4728 printf("TEST #6 testing 1 non-io open, one io open\n");
4730 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
4732 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, FILE_READ_DATA
, FILE_ATTRIBUTE_NORMAL
,
4733 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
4734 printf("TEST #6 open 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4738 if (!NT_STATUS_IS_OK(cli_ntcreate(cli2
, fname
, 0, FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
4739 FILE_SHARE_READ
, FILE_OPEN_IF
, 0, 0, &fnum2
))) {
4740 printf("TEST #6 open 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
4744 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4745 printf("TEST #6 close 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4749 if (!NT_STATUS_IS_OK(cli_close(cli2
, fnum2
))) {
4750 printf("TEST #6 close 2 of %s failed (%s)\n", fname
, cli_errstr(cli2
));
4754 printf("non-io open test #6 passed.\n");
4756 printf("TEST #7 testing 1 non-io open, one io open with delete\n");
4758 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
4760 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, FILE_READ_DATA
, FILE_ATTRIBUTE_NORMAL
,
4761 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
4762 printf("TEST #7 open 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4766 if (NT_STATUS_IS_OK(cli_ntcreate(cli2
, fname
, 0, DELETE_ACCESS
|FILE_READ_ATTRIBUTES
, FILE_ATTRIBUTE_NORMAL
,
4767 FILE_SHARE_READ
|FILE_SHARE_DELETE
, FILE_OPEN_IF
, 0, 0, &fnum2
))) {
4768 printf("TEST #7 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname
, cli_errstr(cli2
));
4772 printf("TEST #7 open 2 of %s gave %s (correct error should be %s)\n", fname
, cli_errstr(cli2
), "sharing violation");
4774 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4775 printf("TEST #7 close 1 of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4779 printf("non-io open test #7 passed.\n");
4781 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
4783 printf("TEST #8 testing open without WRITE_ATTRIBUTES, updating close write time.\n");
4784 status
= cli_ntcreate(cli1
, fname
, 0, FILE_WRITE_DATA
, FILE_ATTRIBUTE_NORMAL
,
4785 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
4786 FILE_OVERWRITE_IF
, 0, 0, &fnum1
);
4787 if (!NT_STATUS_IS_OK(status
)) {
4788 printf("TEST #8 open of %s failed (%s)\n", fname
, nt_errstr(status
));
4793 /* Write to ensure we have to update the file time. */
4794 if (cli_write(cli1
, fnum1
, 0, "TEST DATA\n", 0, 10) != 10) {
4795 printf("TEST #8 cli_write failed: %s\n", cli_errstr(cli1
));
4800 status
= cli_close(cli1
, fnum1
);
4801 if (!NT_STATUS_IS_OK(status
)) {
4802 printf("TEST #8 close of %s failed (%s)\n", fname
, nt_errstr(status
));
4808 if (!torture_close_connection(cli1
)) {
4811 if (!torture_close_connection(cli2
)) {
4818 NTSTATUS
torture_setup_unix_extensions(struct cli_state
*cli
)
4820 uint16 major
, minor
;
4821 uint32 caplow
, caphigh
;
4824 if (!SERVER_HAS_UNIX_CIFS(cli
)) {
4825 printf("Server doesn't support UNIX CIFS extensions.\n");
4826 return NT_STATUS_NOT_SUPPORTED
;
4829 status
= cli_unix_extensions_version(cli
, &major
, &minor
, &caplow
,
4831 if (!NT_STATUS_IS_OK(status
)) {
4832 printf("Server didn't return UNIX CIFS extensions: %s\n",
4837 status
= cli_set_unix_extensions_capabilities(cli
, major
, minor
,
4839 if (!NT_STATUS_IS_OK(status
)) {
4840 printf("Server doesn't support setting UNIX CIFS extensions: "
4841 "%s.\n", nt_errstr(status
));
4845 return NT_STATUS_OK
;
4849 Test POSIX open /mkdir calls.
4851 static bool run_simple_posix_open_test(int dummy
)
4853 static struct cli_state
*cli1
;
4854 const char *fname
= "posix:file";
4855 const char *hname
= "posix:hlink";
4856 const char *sname
= "posix:symlink";
4857 const char *dname
= "posix:dir";
4860 uint16_t fnum1
= (uint16_t)-1;
4861 SMB_STRUCT_STAT sbuf
;
4862 bool correct
= false;
4865 printf("Starting simple POSIX open test\n");
4867 if (!torture_open_connection(&cli1
, 0)) {
4871 cli_sockopt(cli1
, sockops
);
4873 status
= torture_setup_unix_extensions(cli1
);
4874 if (!NT_STATUS_IS_OK(status
)) {
4878 cli_setatr(cli1
, fname
, 0, 0);
4879 cli_posix_unlink(cli1
, fname
);
4880 cli_setatr(cli1
, dname
, 0, 0);
4881 cli_posix_rmdir(cli1
, dname
);
4882 cli_setatr(cli1
, hname
, 0, 0);
4883 cli_posix_unlink(cli1
, hname
);
4884 cli_setatr(cli1
, sname
, 0, 0);
4885 cli_posix_unlink(cli1
, sname
);
4887 /* Create a directory. */
4888 if (!NT_STATUS_IS_OK(cli_posix_mkdir(cli1
, dname
, 0777))) {
4889 printf("POSIX mkdir of %s failed (%s)\n", dname
, cli_errstr(cli1
));
4893 if (!NT_STATUS_IS_OK(cli_posix_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, 0600, &fnum1
))) {
4894 printf("POSIX create of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4898 /* Test ftruncate - set file size. */
4899 if (!NT_STATUS_IS_OK(cli_ftruncate(cli1
, fnum1
, 1000))) {
4900 printf("ftruncate failed (%s)\n", cli_errstr(cli1
));
4904 /* Ensure st_size == 1000 */
4905 if (!NT_STATUS_IS_OK(cli_posix_stat(cli1
, fname
, &sbuf
))) {
4906 printf("stat failed (%s)\n", cli_errstr(cli1
));
4910 if (sbuf
.st_ex_size
!= 1000) {
4911 printf("ftruncate - stat size (%u) != 1000\n", (unsigned int)sbuf
.st_ex_size
);
4915 /* Test ftruncate - set file size back to zero. */
4916 if (!NT_STATUS_IS_OK(cli_ftruncate(cli1
, fnum1
, 0))) {
4917 printf("ftruncate failed (%s)\n", cli_errstr(cli1
));
4921 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4922 printf("close failed (%s)\n", cli_errstr(cli1
));
4926 /* Now open the file again for read only. */
4927 if (!NT_STATUS_IS_OK(cli_posix_open(cli1
, fname
, O_RDONLY
, 0, &fnum1
))) {
4928 printf("POSIX open of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4932 /* Now unlink while open. */
4933 if (!NT_STATUS_IS_OK(cli_posix_unlink(cli1
, fname
))) {
4934 printf("POSIX unlink of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4938 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
4939 printf("close(2) failed (%s)\n", cli_errstr(cli1
));
4943 /* Ensure the file has gone. */
4944 if (NT_STATUS_IS_OK(cli_posix_open(cli1
, fname
, O_RDONLY
, 0, &fnum1
))) {
4945 printf("POSIX open of %s succeeded, should have been deleted.\n", fname
);
4949 /* What happens when we try and POSIX open a directory ? */
4950 if (NT_STATUS_IS_OK(cli_posix_open(cli1
, dname
, O_RDONLY
, 0, &fnum1
))) {
4951 printf("POSIX open of directory %s succeeded, should have failed.\n", fname
);
4954 if (!check_error(__LINE__
, cli1
, ERRDOS
, EISDIR
,
4955 NT_STATUS_FILE_IS_A_DIRECTORY
)) {
4960 /* Create the file. */
4961 if (!NT_STATUS_IS_OK(cli_posix_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, 0600, &fnum1
))) {
4962 printf("POSIX create of %s failed (%s)\n", fname
, cli_errstr(cli1
));
4966 /* Write some data into it. */
4967 if (cli_write(cli1
, fnum1
, 0, "TEST DATA\n", 0, 10) != 10) {
4968 printf("cli_write failed: %s\n", cli_errstr(cli1
));
4972 cli_close(cli1
, fnum1
);
4974 /* Now create a hardlink. */
4975 if (!NT_STATUS_IS_OK(cli_posix_hardlink(cli1
, fname
, hname
))) {
4976 printf("POSIX hardlink of %s failed (%s)\n", hname
, cli_errstr(cli1
));
4980 /* Now create a symlink. */
4981 if (!NT_STATUS_IS_OK(cli_posix_symlink(cli1
, fname
, sname
))) {
4982 printf("POSIX symlink of %s failed (%s)\n", sname
, cli_errstr(cli1
));
4986 /* Open the hardlink for read. */
4987 if (!NT_STATUS_IS_OK(cli_posix_open(cli1
, hname
, O_RDONLY
, 0, &fnum1
))) {
4988 printf("POSIX open of %s failed (%s)\n", hname
, cli_errstr(cli1
));
4992 if (cli_read(cli1
, fnum1
, buf
, 0, 10) != 10) {
4993 printf("POSIX read of %s failed (%s)\n", hname
, cli_errstr(cli1
));
4997 if (memcmp(buf
, "TEST DATA\n", 10)) {
4998 printf("invalid data read from hardlink\n");
5002 /* Do a POSIX lock/unlock. */
5003 if (!NT_STATUS_IS_OK(cli_posix_lock(cli1
, fnum1
, 0, 100, true, READ_LOCK
))) {
5004 printf("POSIX lock failed %s\n", cli_errstr(cli1
));
5008 /* Punch a hole in the locked area. */
5009 if (!NT_STATUS_IS_OK(cli_posix_unlock(cli1
, fnum1
, 10, 80))) {
5010 printf("POSIX unlock failed %s\n", cli_errstr(cli1
));
5014 cli_close(cli1
, fnum1
);
5016 /* Open the symlink for read - this should fail. A POSIX
5017 client should not be doing opens on a symlink. */
5018 if (NT_STATUS_IS_OK(cli_posix_open(cli1
, sname
, O_RDONLY
, 0, &fnum1
))) {
5019 printf("POSIX open of %s succeeded (should have failed)\n", sname
);
5022 if (!check_error(__LINE__
, cli1
, ERRDOS
, ERRbadpath
,
5023 NT_STATUS_OBJECT_PATH_NOT_FOUND
)) {
5024 printf("POSIX open of %s should have failed "
5025 "with NT_STATUS_OBJECT_PATH_NOT_FOUND, "
5026 "failed with %s instead.\n",
5027 sname
, cli_errstr(cli1
));
5032 if (!NT_STATUS_IS_OK(cli_posix_readlink(cli1
, sname
, namebuf
, sizeof(namebuf
)))) {
5033 printf("POSIX readlink on %s failed (%s)\n", sname
, cli_errstr(cli1
));
5037 if (strcmp(namebuf
, fname
) != 0) {
5038 printf("POSIX readlink on %s failed to match name %s (read %s)\n",
5039 sname
, fname
, namebuf
);
5043 if (!NT_STATUS_IS_OK(cli_posix_rmdir(cli1
, dname
))) {
5044 printf("POSIX rmdir failed (%s)\n", cli_errstr(cli1
));
5048 printf("Simple POSIX open test passed\n");
5053 if (fnum1
!= (uint16_t)-1) {
5054 cli_close(cli1
, fnum1
);
5055 fnum1
= (uint16_t)-1;
5058 cli_setatr(cli1
, sname
, 0, 0);
5059 cli_posix_unlink(cli1
, sname
);
5060 cli_setatr(cli1
, hname
, 0, 0);
5061 cli_posix_unlink(cli1
, hname
);
5062 cli_setatr(cli1
, fname
, 0, 0);
5063 cli_posix_unlink(cli1
, fname
);
5064 cli_setatr(cli1
, dname
, 0, 0);
5065 cli_posix_rmdir(cli1
, dname
);
5067 if (!torture_close_connection(cli1
)) {
5075 static uint32 open_attrs_table
[] = {
5076 FILE_ATTRIBUTE_NORMAL
,
5077 FILE_ATTRIBUTE_ARCHIVE
,
5078 FILE_ATTRIBUTE_READONLY
,
5079 FILE_ATTRIBUTE_HIDDEN
,
5080 FILE_ATTRIBUTE_SYSTEM
,
5082 FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
,
5083 FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
,
5084 FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
,
5085 FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
,
5086 FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_SYSTEM
,
5087 FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_SYSTEM
,
5089 FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
,
5090 FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_SYSTEM
,
5091 FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_SYSTEM
,
5092 FILE_ATTRIBUTE_HIDDEN
,FILE_ATTRIBUTE_SYSTEM
,
5095 struct trunc_open_results
{
5102 static struct trunc_open_results attr_results
[] = {
5103 { 0, FILE_ATTRIBUTE_NORMAL
, FILE_ATTRIBUTE_NORMAL
, FILE_ATTRIBUTE_ARCHIVE
},
5104 { 1, FILE_ATTRIBUTE_NORMAL
, FILE_ATTRIBUTE_ARCHIVE
, FILE_ATTRIBUTE_ARCHIVE
},
5105 { 2, FILE_ATTRIBUTE_NORMAL
, FILE_ATTRIBUTE_READONLY
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
},
5106 { 16, FILE_ATTRIBUTE_ARCHIVE
, FILE_ATTRIBUTE_NORMAL
, FILE_ATTRIBUTE_ARCHIVE
},
5107 { 17, FILE_ATTRIBUTE_ARCHIVE
, FILE_ATTRIBUTE_ARCHIVE
, FILE_ATTRIBUTE_ARCHIVE
},
5108 { 18, FILE_ATTRIBUTE_ARCHIVE
, FILE_ATTRIBUTE_READONLY
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
},
5109 { 51, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
},
5110 { 54, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
},
5111 { 56, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
},
5112 { 68, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
},
5113 { 71, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
},
5114 { 73, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_SYSTEM
},
5115 { 99, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_HIDDEN
,FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
},
5116 { 102, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
},
5117 { 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
},
5118 { 116, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
},
5119 { 119, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
},
5120 { 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
},
5121 { 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
},
5122 { 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
},
5123 { 227, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
},
5124 { 230, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
},
5125 { 232, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
},
5126 { 244, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
},
5127 { 247, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
},
5128 { 249, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_SYSTEM
}
5131 static bool run_openattrtest(int dummy
)
5133 static struct cli_state
*cli1
;
5134 const char *fname
= "\\openattr.file";
5136 bool correct
= True
;
5138 unsigned int i
, j
, k
, l
;
5140 printf("starting open attr test\n");
5142 if (!torture_open_connection(&cli1
, 0)) {
5146 cli_sockopt(cli1
, sockops
);
5148 for (k
= 0, i
= 0; i
< sizeof(open_attrs_table
)/sizeof(uint32
); i
++) {
5149 cli_setatr(cli1
, fname
, 0, 0);
5150 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
5151 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, FILE_WRITE_DATA
, open_attrs_table
[i
],
5152 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
5153 printf("open %d (1) of %s failed (%s)\n", i
, fname
, cli_errstr(cli1
));
5157 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
5158 printf("close %d (1) of %s failed (%s)\n", i
, fname
, cli_errstr(cli1
));
5162 for (j
= 0; j
< sizeof(open_attrs_table
)/sizeof(uint32
); j
++) {
5163 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, FILE_READ_DATA
|FILE_WRITE_DATA
, open_attrs_table
[j
],
5164 FILE_SHARE_NONE
, FILE_OVERWRITE
, 0, 0, &fnum1
))) {
5165 for (l
= 0; l
< sizeof(attr_results
)/sizeof(struct trunc_open_results
); l
++) {
5166 if (attr_results
[l
].num
== k
) {
5167 printf("[%d] trunc open 0x%x -> 0x%x of %s failed - should have succeeded !(0x%x:%s)\n",
5168 k
, open_attrs_table
[i
],
5169 open_attrs_table
[j
],
5170 fname
, NT_STATUS_V(cli_nt_error(cli1
)), cli_errstr(cli1
));
5174 if (NT_STATUS_V(cli_nt_error(cli1
)) != NT_STATUS_V(NT_STATUS_ACCESS_DENIED
)) {
5175 printf("[%d] trunc open 0x%x -> 0x%x failed with wrong error code %s\n",
5176 k
, open_attrs_table
[i
], open_attrs_table
[j
],
5181 printf("[%d] trunc open 0x%x -> 0x%x failed\n", k
, open_attrs_table
[i
], open_attrs_table
[j
]);
5187 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum1
))) {
5188 printf("close %d (2) of %s failed (%s)\n", j
, fname
, cli_errstr(cli1
));
5192 if (!NT_STATUS_IS_OK(cli_getatr(cli1
, fname
, &attr
, NULL
, NULL
))) {
5193 printf("getatr(2) failed (%s)\n", cli_errstr(cli1
));
5198 printf("[%d] getatr check [0x%x] trunc [0x%x] got attr 0x%x\n",
5199 k
, open_attrs_table
[i
], open_attrs_table
[j
], attr
);
5202 for (l
= 0; l
< sizeof(attr_results
)/sizeof(struct trunc_open_results
); l
++) {
5203 if (attr_results
[l
].num
== k
) {
5204 if (attr
!= attr_results
[l
].result_attr
||
5205 open_attrs_table
[i
] != attr_results
[l
].init_attr
||
5206 open_attrs_table
[j
] != attr_results
[l
].trunc_attr
) {
5207 printf("getatr check failed. [0x%x] trunc [0x%x] got attr 0x%x, should be 0x%x\n",
5208 open_attrs_table
[i
],
5209 open_attrs_table
[j
],
5211 attr_results
[l
].result_attr
);
5221 cli_setatr(cli1
, fname
, 0, 0);
5222 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
5224 printf("open attr test %s.\n", correct
? "passed" : "failed");
5226 if (!torture_close_connection(cli1
)) {
5232 static NTSTATUS
list_fn(const char *mnt
, struct file_info
*finfo
,
5233 const char *name
, void *state
)
5235 int *matched
= (int *)state
;
5236 if (matched
!= NULL
) {
5239 return NT_STATUS_OK
;
5243 test directory listing speed
5245 static bool run_dirtest(int dummy
)
5248 static struct cli_state
*cli
;
5250 struct timeval core_start
;
5251 bool correct
= True
;
5254 printf("starting directory test\n");
5256 if (!torture_open_connection(&cli
, 0)) {
5260 cli_sockopt(cli
, sockops
);
5263 for (i
=0;i
<torture_numops
;i
++) {
5265 slprintf(fname
, sizeof(fname
), "\\%x", (int)random());
5266 if (!NT_STATUS_IS_OK(cli_open(cli
, fname
, O_RDWR
|O_CREAT
, DENY_NONE
, &fnum
))) {
5267 fprintf(stderr
,"Failed to open %s\n", fname
);
5270 cli_close(cli
, fnum
);
5273 core_start
= timeval_current();
5276 cli_list(cli
, "a*.*", 0, list_fn
, &matched
);
5277 printf("Matched %d\n", matched
);
5280 cli_list(cli
, "b*.*", 0, list_fn
, &matched
);
5281 printf("Matched %d\n", matched
);
5284 cli_list(cli
, "xyzabc", 0, list_fn
, &matched
);
5285 printf("Matched %d\n", matched
);
5287 printf("dirtest core %g seconds\n", timeval_elapsed(&core_start
));
5290 for (i
=0;i
<torture_numops
;i
++) {
5292 slprintf(fname
, sizeof(fname
), "\\%x", (int)random());
5293 cli_unlink(cli
, fname
, aSYSTEM
| aHIDDEN
);
5296 if (!torture_close_connection(cli
)) {
5300 printf("finished dirtest\n");
5305 static NTSTATUS
del_fn(const char *mnt
, struct file_info
*finfo
, const char *mask
,
5308 struct cli_state
*pcli
= (struct cli_state
*)state
;
5310 slprintf(fname
, sizeof(fname
), "\\LISTDIR\\%s", finfo
->name
);
5312 if (strcmp(finfo
->name
, ".") == 0 || strcmp(finfo
->name
, "..") == 0)
5313 return NT_STATUS_OK
;
5315 if (finfo
->mode
& aDIR
) {
5316 if (!NT_STATUS_IS_OK(cli_rmdir(pcli
, fname
)))
5317 printf("del_fn: failed to rmdir %s\n,", fname
);
5319 if (!NT_STATUS_IS_OK(cli_unlink(pcli
, fname
, aSYSTEM
| aHIDDEN
)))
5320 printf("del_fn: failed to unlink %s\n,", fname
);
5322 return NT_STATUS_OK
;
5327 sees what IOCTLs are supported
5329 bool torture_ioctl_test(int dummy
)
5331 static struct cli_state
*cli
;
5332 uint16_t device
, function
;
5334 const char *fname
= "\\ioctl.dat";
5338 if (!torture_open_connection(&cli
, 0)) {
5342 printf("starting ioctl test\n");
5344 cli_unlink(cli
, fname
, aSYSTEM
| aHIDDEN
);
5346 if (!NT_STATUS_IS_OK(cli_open(cli
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum
))) {
5347 printf("open of %s failed (%s)\n", fname
, cli_errstr(cli
));
5351 status
= cli_raw_ioctl(cli
, fnum
, 0x2d0000 | (0x0420<<2), &blob
);
5352 printf("ioctl device info: %s\n", nt_errstr(status
));
5354 status
= cli_raw_ioctl(cli
, fnum
, IOCTL_QUERY_JOB_INFO
, &blob
);
5355 printf("ioctl job info: %s\n", nt_errstr(status
));
5357 for (device
=0;device
<0x100;device
++) {
5358 printf("ioctl test with device = 0x%x\n", device
);
5359 for (function
=0;function
<0x100;function
++) {
5360 uint32 code
= (device
<<16) | function
;
5362 status
= cli_raw_ioctl(cli
, fnum
, code
, &blob
);
5364 if (NT_STATUS_IS_OK(status
)) {
5365 printf("ioctl 0x%x OK : %d bytes\n", (int)code
,
5367 data_blob_free(&blob
);
5372 if (!torture_close_connection(cli
)) {
5381 tries varients of chkpath
5383 bool torture_chkpath_test(int dummy
)
5385 static struct cli_state
*cli
;
5389 if (!torture_open_connection(&cli
, 0)) {
5393 printf("starting chkpath test\n");
5395 /* cleanup from an old run */
5396 cli_rmdir(cli
, "\\chkpath.dir\\dir2");
5397 cli_unlink(cli
, "\\chkpath.dir\\*", aSYSTEM
| aHIDDEN
);
5398 cli_rmdir(cli
, "\\chkpath.dir");
5400 if (!NT_STATUS_IS_OK(cli_mkdir(cli
, "\\chkpath.dir"))) {
5401 printf("mkdir1 failed : %s\n", cli_errstr(cli
));
5405 if (!NT_STATUS_IS_OK(cli_mkdir(cli
, "\\chkpath.dir\\dir2"))) {
5406 printf("mkdir2 failed : %s\n", cli_errstr(cli
));
5410 if (!NT_STATUS_IS_OK(cli_open(cli
, "\\chkpath.dir\\foo.txt", O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum
))) {
5411 printf("open1 failed (%s)\n", cli_errstr(cli
));
5414 cli_close(cli
, fnum
);
5416 if (!NT_STATUS_IS_OK(cli_chkpath(cli
, "\\chkpath.dir"))) {
5417 printf("chkpath1 failed: %s\n", cli_errstr(cli
));
5421 if (!NT_STATUS_IS_OK(cli_chkpath(cli
, "\\chkpath.dir\\dir2"))) {
5422 printf("chkpath2 failed: %s\n", cli_errstr(cli
));
5426 if (!NT_STATUS_IS_OK(cli_chkpath(cli
, "\\chkpath.dir\\foo.txt"))) {
5427 ret
= check_error(__LINE__
, cli
, ERRDOS
, ERRbadpath
,
5428 NT_STATUS_NOT_A_DIRECTORY
);
5430 printf("* chkpath on a file should fail\n");
5434 if (!NT_STATUS_IS_OK(cli_chkpath(cli
, "\\chkpath.dir\\bar.txt"))) {
5435 ret
= check_error(__LINE__
, cli
, ERRDOS
, ERRbadfile
,
5436 NT_STATUS_OBJECT_NAME_NOT_FOUND
);
5438 printf("* chkpath on a non existant file should fail\n");
5442 if (!NT_STATUS_IS_OK(cli_chkpath(cli
, "\\chkpath.dir\\dirxx\\bar.txt"))) {
5443 ret
= check_error(__LINE__
, cli
, ERRDOS
, ERRbadpath
,
5444 NT_STATUS_OBJECT_PATH_NOT_FOUND
);
5446 printf("* chkpath on a non existent component should fail\n");
5450 cli_rmdir(cli
, "\\chkpath.dir\\dir2");
5451 cli_unlink(cli
, "\\chkpath.dir\\*", aSYSTEM
| aHIDDEN
);
5452 cli_rmdir(cli
, "\\chkpath.dir");
5454 if (!torture_close_connection(cli
)) {
5461 static bool run_eatest(int dummy
)
5463 static struct cli_state
*cli
;
5464 const char *fname
= "\\eatest.txt";
5465 bool correct
= True
;
5469 struct ea_struct
*ea_list
= NULL
;
5470 TALLOC_CTX
*mem_ctx
= talloc_init("eatest");
5473 printf("starting eatest\n");
5475 if (!torture_open_connection(&cli
, 0)) {
5476 talloc_destroy(mem_ctx
);
5480 cli_unlink(cli
, fname
, aSYSTEM
| aHIDDEN
);
5481 if (!NT_STATUS_IS_OK(cli_ntcreate(cli
, fname
, 0,
5482 FIRST_DESIRED_ACCESS
, FILE_ATTRIBUTE_ARCHIVE
,
5483 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
,
5484 0x4044, 0, &fnum
))) {
5485 printf("open failed - %s\n", cli_errstr(cli
));
5486 talloc_destroy(mem_ctx
);
5490 for (i
= 0; i
< 10; i
++) {
5491 fstring ea_name
, ea_val
;
5493 slprintf(ea_name
, sizeof(ea_name
), "EA_%d", i
);
5494 memset(ea_val
, (char)i
+1, i
+1);
5495 status
= cli_set_ea_fnum(cli
, fnum
, ea_name
, ea_val
, i
+1);
5496 if (!NT_STATUS_IS_OK(status
)) {
5497 printf("ea_set of name %s failed - %s\n", ea_name
,
5499 talloc_destroy(mem_ctx
);
5504 cli_close(cli
, fnum
);
5505 for (i
= 0; i
< 10; i
++) {
5506 fstring ea_name
, ea_val
;
5508 slprintf(ea_name
, sizeof(ea_name
), "EA_%d", i
+10);
5509 memset(ea_val
, (char)i
+1, i
+1);
5510 status
= cli_set_ea_path(cli
, fname
, ea_name
, ea_val
, i
+1);
5511 if (!NT_STATUS_IS_OK(status
)) {
5512 printf("ea_set of name %s failed - %s\n", ea_name
,
5514 talloc_destroy(mem_ctx
);
5519 status
= cli_get_ea_list_path(cli
, fname
, mem_ctx
, &num_eas
, &ea_list
);
5520 if (!NT_STATUS_IS_OK(status
)) {
5521 printf("ea_get list failed - %s\n", nt_errstr(status
));
5525 printf("num_eas = %d\n", (int)num_eas
);
5527 if (num_eas
!= 20) {
5528 printf("Should be 20 EA's stored... failing.\n");
5532 for (i
= 0; i
< num_eas
; i
++) {
5533 printf("%d: ea_name = %s. Val = ", i
, ea_list
[i
].name
);
5534 dump_data(0, ea_list
[i
].value
.data
,
5535 ea_list
[i
].value
.length
);
5538 /* Setting EA's to zero length deletes them. Test this */
5539 printf("Now deleting all EA's - case indepenent....\n");
5542 cli_set_ea_path(cli
, fname
, "", "", 0);
5544 for (i
= 0; i
< 20; i
++) {
5546 slprintf(ea_name
, sizeof(ea_name
), "ea_%d", i
);
5547 status
= cli_set_ea_path(cli
, fname
, ea_name
, "", 0);
5548 if (!NT_STATUS_IS_OK(status
)) {
5549 printf("ea_set of name %s failed - %s\n", ea_name
,
5551 talloc_destroy(mem_ctx
);
5557 status
= cli_get_ea_list_path(cli
, fname
, mem_ctx
, &num_eas
, &ea_list
);
5558 if (!NT_STATUS_IS_OK(status
)) {
5559 printf("ea_get list failed - %s\n", nt_errstr(status
));
5563 printf("num_eas = %d\n", (int)num_eas
);
5564 for (i
= 0; i
< num_eas
; i
++) {
5565 printf("%d: ea_name = %s. Val = ", i
, ea_list
[i
].name
);
5566 dump_data(0, ea_list
[i
].value
.data
,
5567 ea_list
[i
].value
.length
);
5571 printf("deleting EA's failed.\n");
5575 /* Try and delete a non existant EA. */
5576 status
= cli_set_ea_path(cli
, fname
, "foo", "", 0);
5577 if (!NT_STATUS_IS_OK(status
)) {
5578 printf("deleting non-existant EA 'foo' should succeed. %s\n",
5583 talloc_destroy(mem_ctx
);
5584 if (!torture_close_connection(cli
)) {
5591 static bool run_dirtest1(int dummy
)
5594 static struct cli_state
*cli
;
5597 bool correct
= True
;
5599 printf("starting directory test\n");
5601 if (!torture_open_connection(&cli
, 0)) {
5605 cli_sockopt(cli
, sockops
);
5607 cli_list(cli
, "\\LISTDIR\\*", 0, del_fn
, cli
);
5608 cli_list(cli
, "\\LISTDIR\\*", aDIR
, del_fn
, cli
);
5609 cli_rmdir(cli
, "\\LISTDIR");
5610 cli_mkdir(cli
, "\\LISTDIR");
5612 /* Create 1000 files and 1000 directories. */
5613 for (i
=0;i
<1000;i
++) {
5615 slprintf(fname
, sizeof(fname
), "\\LISTDIR\\f%d", i
);
5616 if (!NT_STATUS_IS_OK(cli_ntcreate(cli
, fname
, 0, GENERIC_ALL_ACCESS
, FILE_ATTRIBUTE_ARCHIVE
,
5617 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OVERWRITE_IF
, 0, 0, &fnum
))) {
5618 fprintf(stderr
,"Failed to open %s\n", fname
);
5621 cli_close(cli
, fnum
);
5623 for (i
=0;i
<1000;i
++) {
5625 slprintf(fname
, sizeof(fname
), "\\LISTDIR\\d%d", i
);
5626 if (!NT_STATUS_IS_OK(cli_mkdir(cli
, fname
))) {
5627 fprintf(stderr
,"Failed to open %s\n", fname
);
5632 /* Now ensure that doing an old list sees both files and directories. */
5634 cli_list_old(cli
, "\\LISTDIR\\*", aDIR
, list_fn
, &num_seen
);
5635 printf("num_seen = %d\n", num_seen
);
5636 /* We should see 100 files + 1000 directories + . and .. */
5637 if (num_seen
!= 2002)
5640 /* Ensure if we have the "must have" bits we only see the
5644 cli_list_old(cli
, "\\LISTDIR\\*", (aDIR
<<8)|aDIR
, list_fn
, &num_seen
);
5645 printf("num_seen = %d\n", num_seen
);
5646 if (num_seen
!= 1002)
5650 cli_list_old(cli
, "\\LISTDIR\\*", (aARCH
<<8)|aDIR
, list_fn
, &num_seen
);
5651 printf("num_seen = %d\n", num_seen
);
5652 if (num_seen
!= 1000)
5655 /* Delete everything. */
5656 cli_list(cli
, "\\LISTDIR\\*", 0, del_fn
, cli
);
5657 cli_list(cli
, "\\LISTDIR\\*", aDIR
, del_fn
, cli
);
5658 cli_rmdir(cli
, "\\LISTDIR");
5661 printf("Matched %d\n", cli_list(cli
, "a*.*", 0, list_fn
, NULL
));
5662 printf("Matched %d\n", cli_list(cli
, "b*.*", 0, list_fn
, NULL
));
5663 printf("Matched %d\n", cli_list(cli
, "xyzabc", 0, list_fn
, NULL
));
5666 if (!torture_close_connection(cli
)) {
5670 printf("finished dirtest1\n");
5675 static bool run_error_map_extract(int dummy
) {
5677 static struct cli_state
*c_dos
;
5678 static struct cli_state
*c_nt
;
5683 uint32 flgs2
, errnum
;
5690 /* NT-Error connection */
5692 if (!(c_nt
= open_nbt_connection())) {
5696 c_nt
->use_spnego
= False
;
5698 status
= cli_negprot(c_nt
);
5700 if (!NT_STATUS_IS_OK(status
)) {
5701 printf("%s rejected the NT-error negprot (%s)\n", host
,
5707 if (!NT_STATUS_IS_OK(cli_session_setup(c_nt
, "", "", 0, "", 0,
5709 printf("%s rejected the NT-error initial session setup (%s)\n",host
, cli_errstr(c_nt
));
5713 /* DOS-Error connection */
5715 if (!(c_dos
= open_nbt_connection())) {
5719 c_dos
->use_spnego
= False
;
5720 c_dos
->force_dos_errors
= True
;
5722 status
= cli_negprot(c_dos
);
5723 if (!NT_STATUS_IS_OK(status
)) {
5724 printf("%s rejected the DOS-error negprot (%s)\n", host
,
5726 cli_shutdown(c_dos
);
5730 if (!NT_STATUS_IS_OK(cli_session_setup(c_dos
, "", "", 0, "", 0,
5732 printf("%s rejected the DOS-error initial session setup (%s)\n",host
, cli_errstr(c_dos
));
5736 for (error
=(0xc0000000 | 0x1); error
< (0xc0000000| 0xFFF); error
++) {
5737 fstr_sprintf(user
, "%X", error
);
5739 if (NT_STATUS_IS_OK(cli_session_setup(c_nt
, user
,
5740 password
, strlen(password
),
5741 password
, strlen(password
),
5743 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
5746 flgs2
= SVAL(c_nt
->inbuf
,smb_flg2
);
5748 /* Case #1: 32-bit NT errors */
5749 if (flgs2
& FLAGS2_32_BIT_ERROR_CODES
) {
5750 nt_status
= NT_STATUS(IVAL(c_nt
->inbuf
,smb_rcls
));
5752 printf("/** Dos error on NT connection! (%s) */\n",
5754 nt_status
= NT_STATUS(0xc0000000);
5757 if (NT_STATUS_IS_OK(cli_session_setup(c_dos
, user
,
5758 password
, strlen(password
),
5759 password
, strlen(password
),
5761 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
5763 flgs2
= SVAL(c_dos
->inbuf
,smb_flg2
), errnum
;
5765 /* Case #1: 32-bit NT errors */
5766 if (flgs2
& FLAGS2_32_BIT_ERROR_CODES
) {
5767 printf("/** NT error on DOS connection! (%s) */\n",
5769 errnum
= errclass
= 0;
5771 cli_dos_error(c_dos
, &errclass
, &errnum
);
5774 if (NT_STATUS_V(nt_status
) != error
) {
5775 printf("/*\t{ This NT error code was 'sqashed'\n\t from %s to %s \n\t during the session setup }\n*/\n",
5776 get_nt_error_c_code(NT_STATUS(error
)),
5777 get_nt_error_c_code(nt_status
));
5780 printf("\t{%s,\t%s,\t%s},\n",
5781 smb_dos_err_class(errclass
),
5782 smb_dos_err_name(errclass
, errnum
),
5783 get_nt_error_c_code(NT_STATUS(error
)));
5788 static bool run_sesssetup_bench(int dummy
)
5790 static struct cli_state
*c
;
5791 const char *fname
= "\\file.dat";
5796 if (!torture_open_connection(&c
, 0)) {
5800 if (!NT_STATUS_IS_OK(cli_ntcreate(
5801 c
, fname
, 0, GENERIC_ALL_ACCESS
|DELETE_ACCESS
,
5802 FILE_ATTRIBUTE_NORMAL
, 0, FILE_OVERWRITE_IF
,
5803 FILE_DELETE_ON_CLOSE
, 0, &fnum
))) {
5804 d_printf("open %s failed: %s\n", fname
, cli_errstr(c
));
5808 for (i
=0; i
<torture_numops
; i
++) {
5809 status
= cli_session_setup(
5811 password
, strlen(password
),
5812 password
, strlen(password
),
5814 if (!NT_STATUS_IS_OK(status
)) {
5815 d_printf("(%s) cli_session_setup failed: %s\n",
5816 __location__
, nt_errstr(status
));
5820 d_printf("\r%d ", (int)c
->vuid
);
5822 status
= cli_ulogoff(c
);
5823 if (!NT_STATUS_IS_OK(status
)) {
5824 d_printf("(%s) cli_ulogoff failed: %s\n",
5825 __location__
, nt_errstr(status
));
5834 static bool subst_test(const char *str
, const char *user
, const char *domain
,
5835 uid_t uid
, gid_t gid
, const char *expected
)
5840 subst
= talloc_sub_specified(talloc_tos(), str
, user
, domain
, uid
, gid
);
5842 if (strcmp(subst
, expected
) != 0) {
5843 printf("sub_specified(%s, %s, %s, %d, %d) returned [%s], expected "
5844 "[%s]\n", str
, user
, domain
, (int)uid
, (int)gid
, subst
,
5853 static void chain1_open_completion(struct tevent_req
*req
)
5857 status
= cli_open_recv(req
, &fnum
);
5860 d_printf("cli_open_recv returned %s: %d\n",
5862 NT_STATUS_IS_OK(status
) ? fnum
: -1);
5865 static void chain1_write_completion(struct tevent_req
*req
)
5869 status
= cli_write_andx_recv(req
, &written
);
5872 d_printf("cli_write_andx_recv returned %s: %d\n",
5874 NT_STATUS_IS_OK(status
) ? (int)written
: -1);
5877 static void chain1_close_completion(struct tevent_req
*req
)
5880 bool *done
= (bool *)tevent_req_callback_data_void(req
);
5882 status
= cli_close_recv(req
);
5887 d_printf("cli_close returned %s\n", nt_errstr(status
));
5890 static bool run_chain1(int dummy
)
5892 struct cli_state
*cli1
;
5893 struct event_context
*evt
= event_context_init(NULL
);
5894 struct tevent_req
*reqs
[3], *smbreqs
[3];
5896 const char *str
= "foobar";
5899 printf("starting chain1 test\n");
5900 if (!torture_open_connection(&cli1
, 0)) {
5904 cli_sockopt(cli1
, sockops
);
5906 reqs
[0] = cli_open_create(talloc_tos(), evt
, cli1
, "\\test",
5907 O_CREAT
|O_RDWR
, 0, &smbreqs
[0]);
5908 if (reqs
[0] == NULL
) return false;
5909 tevent_req_set_callback(reqs
[0], chain1_open_completion
, NULL
);
5912 reqs
[1] = cli_write_andx_create(talloc_tos(), evt
, cli1
, 0, 0,
5913 (uint8_t *)str
, 0, strlen(str
)+1,
5914 smbreqs
, 1, &smbreqs
[1]);
5915 if (reqs
[1] == NULL
) return false;
5916 tevent_req_set_callback(reqs
[1], chain1_write_completion
, NULL
);
5918 reqs
[2] = cli_close_create(talloc_tos(), evt
, cli1
, 0, &smbreqs
[2]);
5919 if (reqs
[2] == NULL
) return false;
5920 tevent_req_set_callback(reqs
[2], chain1_close_completion
, &done
);
5922 status
= cli_smb_chain_send(smbreqs
, ARRAY_SIZE(smbreqs
));
5923 if (!NT_STATUS_IS_OK(status
)) {
5928 event_loop_once(evt
);
5931 torture_close_connection(cli1
);
5935 static void chain2_sesssetup_completion(struct tevent_req
*req
)
5938 status
= cli_session_setup_guest_recv(req
);
5939 d_printf("sesssetup returned %s\n", nt_errstr(status
));
5942 static void chain2_tcon_completion(struct tevent_req
*req
)
5944 bool *done
= (bool *)tevent_req_callback_data_void(req
);
5946 status
= cli_tcon_andx_recv(req
);
5947 d_printf("tcon_and_x returned %s\n", nt_errstr(status
));
5951 static bool run_chain2(int dummy
)
5953 struct cli_state
*cli1
;
5954 struct event_context
*evt
= event_context_init(NULL
);
5955 struct tevent_req
*reqs
[2], *smbreqs
[2];
5959 printf("starting chain2 test\n");
5960 status
= cli_start_connection(&cli1
, global_myname(), host
, NULL
,
5961 port_to_use
, Undefined
, 0);
5962 if (!NT_STATUS_IS_OK(status
)) {
5966 cli_sockopt(cli1
, sockops
);
5968 reqs
[0] = cli_session_setup_guest_create(talloc_tos(), evt
, cli1
,
5970 if (reqs
[0] == NULL
) return false;
5971 tevent_req_set_callback(reqs
[0], chain2_sesssetup_completion
, NULL
);
5973 reqs
[1] = cli_tcon_andx_create(talloc_tos(), evt
, cli1
, "IPC$",
5974 "?????", NULL
, 0, &smbreqs
[1]);
5975 if (reqs
[1] == NULL
) return false;
5976 tevent_req_set_callback(reqs
[1], chain2_tcon_completion
, &done
);
5978 status
= cli_smb_chain_send(smbreqs
, ARRAY_SIZE(smbreqs
));
5979 if (!NT_STATUS_IS_OK(status
)) {
5984 event_loop_once(evt
);
5987 torture_close_connection(cli1
);
5992 struct torture_createdel_state
{
5993 struct tevent_context
*ev
;
5994 struct cli_state
*cli
;
5997 static void torture_createdel_created(struct tevent_req
*subreq
);
5998 static void torture_createdel_closed(struct tevent_req
*subreq
);
6000 static struct tevent_req
*torture_createdel_send(TALLOC_CTX
*mem_ctx
,
6001 struct tevent_context
*ev
,
6002 struct cli_state
*cli
,
6005 struct tevent_req
*req
, *subreq
;
6006 struct torture_createdel_state
*state
;
6008 req
= tevent_req_create(mem_ctx
, &state
,
6009 struct torture_createdel_state
);
6016 subreq
= cli_ntcreate_send(
6017 state
, ev
, cli
, name
, 0,
6018 FILE_READ_DATA
|FILE_WRITE_DATA
|DELETE_ACCESS
,
6019 FILE_ATTRIBUTE_NORMAL
,
6020 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
6021 FILE_OPEN_IF
, FILE_DELETE_ON_CLOSE
, 0);
6023 if (tevent_req_nomem(subreq
, req
)) {
6024 return tevent_req_post(req
, ev
);
6026 tevent_req_set_callback(subreq
, torture_createdel_created
, req
);
6030 static void torture_createdel_created(struct tevent_req
*subreq
)
6032 struct tevent_req
*req
= tevent_req_callback_data(
6033 subreq
, struct tevent_req
);
6034 struct torture_createdel_state
*state
= tevent_req_data(
6035 req
, struct torture_createdel_state
);
6039 status
= cli_ntcreate_recv(subreq
, &fnum
);
6040 TALLOC_FREE(subreq
);
6041 if (!NT_STATUS_IS_OK(status
)) {
6042 DEBUG(10, ("cli_ntcreate_recv returned %s\n",
6043 nt_errstr(status
)));
6044 tevent_req_nterror(req
, status
);
6048 subreq
= cli_close_send(state
, state
->ev
, state
->cli
, fnum
);
6049 if (tevent_req_nomem(subreq
, req
)) {
6052 tevent_req_set_callback(subreq
, torture_createdel_closed
, req
);
6055 static void torture_createdel_closed(struct tevent_req
*subreq
)
6057 struct tevent_req
*req
= tevent_req_callback_data(
6058 subreq
, struct tevent_req
);
6061 status
= cli_close_recv(subreq
);
6062 if (!NT_STATUS_IS_OK(status
)) {
6063 DEBUG(10, ("cli_close_recv returned %s\n", nt_errstr(status
)));
6064 tevent_req_nterror(req
, status
);
6067 tevent_req_done(req
);
6070 static NTSTATUS
torture_createdel_recv(struct tevent_req
*req
)
6072 return tevent_req_simple_recv_ntstatus(req
);
6075 struct torture_createdels_state
{
6076 struct tevent_context
*ev
;
6077 struct cli_state
*cli
;
6078 const char *base_name
;
6082 struct tevent_req
**reqs
;
6085 static void torture_createdels_done(struct tevent_req
*subreq
);
6087 static struct tevent_req
*torture_createdels_send(TALLOC_CTX
*mem_ctx
,
6088 struct tevent_context
*ev
,
6089 struct cli_state
*cli
,
6090 const char *base_name
,
6094 struct tevent_req
*req
;
6095 struct torture_createdels_state
*state
;
6098 req
= tevent_req_create(mem_ctx
, &state
,
6099 struct torture_createdels_state
);
6105 state
->base_name
= talloc_strdup(state
, base_name
);
6106 if (tevent_req_nomem(state
->base_name
, req
)) {
6107 return tevent_req_post(req
, ev
);
6109 state
->num_files
= MAX(num_parallel
, num_files
);
6111 state
->received
= 0;
6113 state
->reqs
= talloc_array(state
, struct tevent_req
*, num_parallel
);
6114 if (tevent_req_nomem(state
->reqs
, req
)) {
6115 return tevent_req_post(req
, ev
);
6118 for (i
=0; i
<num_parallel
; i
++) {
6121 name
= talloc_asprintf(state
, "%s%8.8d", state
->base_name
,
6123 if (tevent_req_nomem(name
, req
)) {
6124 return tevent_req_post(req
, ev
);
6126 state
->reqs
[i
] = torture_createdel_send(
6127 state
->reqs
, state
->ev
, state
->cli
, name
);
6128 if (tevent_req_nomem(state
->reqs
[i
], req
)) {
6129 return tevent_req_post(req
, ev
);
6131 name
= talloc_move(state
->reqs
[i
], &name
);
6132 tevent_req_set_callback(state
->reqs
[i
],
6133 torture_createdels_done
, req
);
6139 static void torture_createdels_done(struct tevent_req
*subreq
)
6141 struct tevent_req
*req
= tevent_req_callback_data(
6142 subreq
, struct tevent_req
);
6143 struct torture_createdels_state
*state
= tevent_req_data(
6144 req
, struct torture_createdels_state
);
6145 size_t num_parallel
= talloc_array_length(state
->reqs
);
6150 status
= torture_createdel_recv(subreq
);
6151 if (!NT_STATUS_IS_OK(status
)){
6152 DEBUG(10, ("torture_createdel_recv returned %s\n",
6153 nt_errstr(status
)));
6154 TALLOC_FREE(subreq
);
6155 tevent_req_nterror(req
, status
);
6159 for (i
=0; i
<num_parallel
; i
++) {
6160 if (subreq
== state
->reqs
[i
]) {
6164 if (i
== num_parallel
) {
6165 DEBUG(10, ("received something we did not send\n"));
6166 tevent_req_nterror(req
, NT_STATUS_INTERNAL_ERROR
);
6169 TALLOC_FREE(state
->reqs
[i
]);
6171 if (state
->sent
>= state
->num_files
) {
6172 tevent_req_done(req
);
6176 name
= talloc_asprintf(state
, "%s%8.8d", state
->base_name
,
6178 if (tevent_req_nomem(name
, req
)) {
6181 state
->reqs
[i
] = torture_createdel_send(state
->reqs
, state
->ev
,
6183 if (tevent_req_nomem(state
->reqs
[i
], req
)) {
6186 name
= talloc_move(state
->reqs
[i
], &name
);
6187 tevent_req_set_callback(state
->reqs
[i
], torture_createdels_done
, req
);
6191 static NTSTATUS
torture_createdels_recv(struct tevent_req
*req
)
6193 return tevent_req_simple_recv_ntstatus(req
);
6196 struct swallow_notify_state
{
6197 struct tevent_context
*ev
;
6198 struct cli_state
*cli
;
6200 uint32_t completion_filter
;
6202 bool (*fn
)(uint32_t action
, const char *name
, void *priv
);
6206 static void swallow_notify_done(struct tevent_req
*subreq
);
6208 static struct tevent_req
*swallow_notify_send(TALLOC_CTX
*mem_ctx
,
6209 struct tevent_context
*ev
,
6210 struct cli_state
*cli
,
6212 uint32_t completion_filter
,
6214 bool (*fn
)(uint32_t action
,
6219 struct tevent_req
*req
, *subreq
;
6220 struct swallow_notify_state
*state
;
6222 req
= tevent_req_create(mem_ctx
, &state
,
6223 struct swallow_notify_state
);
6230 state
->completion_filter
= completion_filter
;
6231 state
->recursive
= recursive
;
6235 subreq
= cli_notify_send(state
, state
->ev
, state
->cli
, state
->fnum
,
6236 0xffff, state
->completion_filter
,
6238 if (tevent_req_nomem(subreq
, req
)) {
6239 return tevent_req_post(req
, ev
);
6241 tevent_req_set_callback(subreq
, swallow_notify_done
, req
);
6245 static void swallow_notify_done(struct tevent_req
*subreq
)
6247 struct tevent_req
*req
= tevent_req_callback_data(
6248 subreq
, struct tevent_req
);
6249 struct swallow_notify_state
*state
= tevent_req_data(
6250 req
, struct swallow_notify_state
);
6252 uint32_t i
, num_changes
;
6253 struct notify_change
*changes
;
6255 status
= cli_notify_recv(subreq
, state
, &num_changes
, &changes
);
6256 TALLOC_FREE(subreq
);
6257 if (!NT_STATUS_IS_OK(status
)) {
6258 DEBUG(10, ("cli_notify_recv returned %s\n",
6259 nt_errstr(status
)));
6260 tevent_req_nterror(req
, status
);
6264 for (i
=0; i
<num_changes
; i
++) {
6265 state
->fn(changes
[i
].action
, changes
[i
].name
, state
->priv
);
6267 TALLOC_FREE(changes
);
6269 subreq
= cli_notify_send(state
, state
->ev
, state
->cli
, state
->fnum
,
6270 0xffff, state
->completion_filter
,
6272 if (tevent_req_nomem(subreq
, req
)) {
6275 tevent_req_set_callback(subreq
, swallow_notify_done
, req
);
6278 static bool print_notifies(uint32_t action
, const char *name
, void *priv
)
6280 if (DEBUGLEVEL
> 5) {
6281 d_printf("%d %s\n", (int)action
, name
);
6286 static void notify_bench_done(struct tevent_req
*req
)
6288 int *num_finished
= (int *)tevent_req_callback_data_void(req
);
6292 static bool run_notify_bench(int dummy
)
6294 const char *dname
= "\\notify-bench";
6295 struct tevent_context
*ev
;
6298 struct tevent_req
*req1
;
6299 struct tevent_req
*req2
= NULL
;
6300 int i
, num_unc_names
;
6301 int num_finished
= 0;
6303 printf("starting notify-bench test\n");
6305 if (use_multishare_conn
) {
6307 unc_list
= file_lines_load(multishare_conn_fname
,
6308 &num_unc_names
, 0, NULL
);
6309 if (!unc_list
|| num_unc_names
<= 0) {
6310 d_printf("Failed to load unc names list from '%s'\n",
6311 multishare_conn_fname
);
6314 TALLOC_FREE(unc_list
);
6319 ev
= tevent_context_init(talloc_tos());
6321 d_printf("tevent_context_init failed\n");
6325 for (i
=0; i
<num_unc_names
; i
++) {
6326 struct cli_state
*cli
;
6329 base_fname
= talloc_asprintf(talloc_tos(), "%s\\file%3.3d.",
6331 if (base_fname
== NULL
) {
6335 if (!torture_open_connection(&cli
, i
)) {
6339 status
= cli_ntcreate(cli
, dname
, 0,
6340 MAXIMUM_ALLOWED_ACCESS
,
6341 0, FILE_SHARE_READ
|FILE_SHARE_WRITE
|
6343 FILE_OPEN_IF
, FILE_DIRECTORY_FILE
, 0,
6346 if (!NT_STATUS_IS_OK(status
)) {
6347 d_printf("Could not create %s: %s\n", dname
,
6352 req1
= swallow_notify_send(talloc_tos(), ev
, cli
, dnum
,
6353 FILE_NOTIFY_CHANGE_FILE_NAME
|
6354 FILE_NOTIFY_CHANGE_DIR_NAME
|
6355 FILE_NOTIFY_CHANGE_ATTRIBUTES
|
6356 FILE_NOTIFY_CHANGE_LAST_WRITE
,
6357 false, print_notifies
, NULL
);
6359 d_printf("Could not create notify request\n");
6363 req2
= torture_createdels_send(talloc_tos(), ev
, cli
,
6364 base_fname
, 10, torture_numops
);
6366 d_printf("Could not create createdels request\n");
6369 TALLOC_FREE(base_fname
);
6371 tevent_req_set_callback(req2
, notify_bench_done
,
6375 while (num_finished
< num_unc_names
) {
6377 ret
= tevent_loop_once(ev
);
6379 d_printf("tevent_loop_once failed\n");
6384 if (!tevent_req_poll(req2
, ev
)) {
6385 d_printf("tevent_req_poll failed\n");
6388 status
= torture_createdels_recv(req2
);
6389 d_printf("torture_createdels_recv returned %s\n", nt_errstr(status
));
6394 static bool run_mangle1(int dummy
)
6396 struct cli_state
*cli
;
6397 const char *fname
= "this_is_a_long_fname_to_be_mangled.txt";
6401 time_t change_time
, access_time
, write_time
;
6405 printf("starting mangle1 test\n");
6406 if (!torture_open_connection(&cli
, 0)) {
6410 cli_sockopt(cli
, sockops
);
6412 if (!NT_STATUS_IS_OK(cli_ntcreate(
6413 cli
, fname
, 0, GENERIC_ALL_ACCESS
|DELETE_ACCESS
,
6414 FILE_ATTRIBUTE_NORMAL
, 0, FILE_OVERWRITE_IF
, 0, 0, &fnum
))) {
6415 d_printf("open %s failed: %s\n", fname
, cli_errstr(cli
));
6418 cli_close(cli
, fnum
);
6420 status
= cli_qpathinfo_alt_name(cli
, fname
, alt_name
);
6421 if (!NT_STATUS_IS_OK(status
)) {
6422 d_printf("cli_qpathinfo_alt_name failed: %s\n",
6426 d_printf("alt_name: %s\n", alt_name
);
6428 if (!NT_STATUS_IS_OK(cli_open(cli
, alt_name
, O_RDONLY
, DENY_NONE
, &fnum
))) {
6429 d_printf("cli_open(%s) failed: %s\n", alt_name
,
6433 cli_close(cli
, fnum
);
6435 status
= cli_qpathinfo1(cli
, alt_name
, &change_time
, &access_time
,
6436 &write_time
, &size
, &mode
);
6437 if (!NT_STATUS_IS_OK(status
)) {
6438 d_printf("cli_qpathinfo1(%s) failed: %s\n", alt_name
,
6446 static size_t null_source(uint8_t *buf
, size_t n
, void *priv
)
6448 size_t *to_pull
= (size_t *)priv
;
6449 size_t thistime
= *to_pull
;
6451 thistime
= MIN(thistime
, n
);
6452 if (thistime
== 0) {
6456 memset(buf
, 0, thistime
);
6457 *to_pull
-= thistime
;
6461 static bool run_windows_write(int dummy
)
6463 struct cli_state
*cli1
;
6467 const char *fname
= "\\writetest.txt";
6468 struct timeval start_time
;
6472 printf("starting windows_write test\n");
6473 if (!torture_open_connection(&cli1
, 0)) {
6477 if (!NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum
))) {
6478 printf("open failed (%s)\n", cli_errstr(cli1
));
6482 cli_sockopt(cli1
, sockops
);
6484 start_time
= timeval_current();
6486 for (i
=0; i
<torture_numops
; i
++) {
6488 off_t start
= i
* torture_blocksize
;
6490 size_t to_pull
= torture_blocksize
- 1;
6492 if (cli_write(cli1
, fnum
, 0, &c
,
6493 start
+ torture_blocksize
- 1, 1) != 1) {
6494 printf("cli_write failed: %s\n", cli_errstr(cli1
));
6498 status
= cli_push(cli1
, fnum
, 0, i
* torture_blocksize
, torture_blocksize
,
6499 null_source
, &to_pull
);
6500 if (!NT_STATUS_IS_OK(status
)) {
6501 printf("cli_push returned: %s\n", nt_errstr(status
));
6506 seconds
= timeval_elapsed(&start_time
);
6507 kbytes
= (double)torture_blocksize
* torture_numops
;
6510 printf("Wrote %d kbytes in %.2f seconds: %d kb/sec\n", (int)kbytes
,
6511 (double)seconds
, (int)(kbytes
/seconds
));
6515 cli_close(cli1
, fnum
);
6516 cli_unlink(cli1
, fname
, aSYSTEM
| aHIDDEN
);
6517 torture_close_connection(cli1
);
6521 static bool run_cli_echo(int dummy
)
6523 struct cli_state
*cli
;
6526 printf("starting cli_echo test\n");
6527 if (!torture_open_connection(&cli
, 0)) {
6530 cli_sockopt(cli
, sockops
);
6532 status
= cli_echo(cli
, 5, data_blob_const("hello", 5));
6534 d_printf("cli_echo returned %s\n", nt_errstr(status
));
6536 torture_close_connection(cli
);
6537 return NT_STATUS_IS_OK(status
);
6540 static bool run_uid_regression_test(int dummy
)
6542 static struct cli_state
*cli
;
6545 bool correct
= True
;
6548 printf("starting uid regression test\n");
6550 if (!torture_open_connection(&cli
, 0)) {
6554 cli_sockopt(cli
, sockops
);
6556 /* Ok - now save then logoff our current user. */
6557 old_vuid
= cli
->vuid
;
6559 status
= cli_ulogoff(cli
);
6560 if (!NT_STATUS_IS_OK(status
)) {
6561 d_printf("(%s) cli_ulogoff failed: %s\n",
6562 __location__
, nt_errstr(status
));
6567 cli
->vuid
= old_vuid
;
6569 /* Try an operation. */
6570 status
= cli_mkdir(cli
, "\\uid_reg_test");
6571 if (NT_STATUS_IS_OK(status
)) {
6572 d_printf("(%s) cli_mkdir succeeded\n",
6577 /* Should be bad uid. */
6578 if (!check_error(__LINE__
, cli
, ERRSRV
, ERRbaduid
,
6579 NT_STATUS_USER_SESSION_DELETED
)) {
6585 old_cnum
= cli
->cnum
;
6587 /* Now try a SMBtdis with the invald vuid set to zero. */
6590 /* This should succeed. */
6591 status
= cli_tdis(cli
);
6593 if (NT_STATUS_IS_OK(status
)) {
6594 d_printf("First tdis with invalid vuid should succeed.\n");
6596 d_printf("First tdis failed (%s)\n", nt_errstr(status
));
6601 cli
->vuid
= old_vuid
;
6602 cli
->cnum
= old_cnum
;
6604 /* This should fail. */
6605 status
= cli_tdis(cli
);
6606 if (NT_STATUS_IS_OK(status
)) {
6607 d_printf("Second tdis with invalid vuid should fail - succeeded instead !.\n");
6611 /* Should be bad tid. */
6612 if (!check_error(__LINE__
, cli
, ERRSRV
, ERRinvnid
,
6613 NT_STATUS_NETWORK_NAME_DELETED
)) {
6619 cli_rmdir(cli
, "\\uid_reg_test");
6628 static const char *illegal_chars
= "*\\/?<>|\":";
6629 static char force_shortname_chars
[] = " +,.[];=\177";
6631 static NTSTATUS
shortname_del_fn(const char *mnt
, struct file_info
*finfo
,
6632 const char *mask
, void *state
)
6634 struct cli_state
*pcli
= (struct cli_state
*)state
;
6636 NTSTATUS status
= NT_STATUS_OK
;
6638 slprintf(fname
, sizeof(fname
), "\\shortname\\%s", finfo
->name
);
6640 if (strcmp(finfo
->name
, ".") == 0 || strcmp(finfo
->name
, "..") == 0)
6641 return NT_STATUS_OK
;
6643 if (finfo
->mode
& aDIR
) {
6644 status
= cli_rmdir(pcli
, fname
);
6645 if (!NT_STATUS_IS_OK(status
)) {
6646 printf("del_fn: failed to rmdir %s\n,", fname
);
6649 status
= cli_unlink(pcli
, fname
, aSYSTEM
| aHIDDEN
);
6650 if (!NT_STATUS_IS_OK(status
)) {
6651 printf("del_fn: failed to unlink %s\n,", fname
);
6663 static NTSTATUS
shortname_list_fn(const char *mnt
, struct file_info
*finfo
,
6664 const char *name
, void *state
)
6666 struct sn_state
*s
= (struct sn_state
*)state
;
6670 printf("shortname list: i = %d, name = |%s|, shortname = |%s|\n",
6671 i
, finfo
->name
, finfo
->short_name
);
6674 if (strchr(force_shortname_chars
, i
)) {
6675 if (!finfo
->short_name
[0]) {
6676 /* Shortname not created when it should be. */
6677 d_printf("(%s) ERROR: Shortname was not created for file %s containing %d\n",
6678 __location__
, finfo
->name
, i
);
6681 } else if (finfo
->short_name
[0]){
6682 /* Shortname created when it should not be. */
6683 d_printf("(%s) ERROR: Shortname %s was created for file %s\n",
6684 __location__
, finfo
->short_name
, finfo
->name
);
6688 return NT_STATUS_OK
;
6691 static bool run_shortname_test(int dummy
)
6693 static struct cli_state
*cli
;
6694 bool correct
= True
;
6699 printf("starting shortname test\n");
6701 if (!torture_open_connection(&cli
, 0)) {
6705 cli_sockopt(cli
, sockops
);
6707 cli_list(cli
, "\\shortname\\*", 0, shortname_del_fn
, cli
);
6708 cli_list(cli
, "\\shortname\\*", aDIR
, shortname_del_fn
, cli
);
6709 cli_rmdir(cli
, "\\shortname");
6711 if (!NT_STATUS_IS_OK(cli_mkdir(cli
, "\\shortname"))) {
6712 d_printf("(%s) cli_mkdir of \\shortname failed: %s\n",
6713 __location__
, cli_errstr(cli
));
6718 strlcpy(fname
, "\\shortname\\", sizeof(fname
));
6719 strlcat(fname
, "test .txt", sizeof(fname
));
6723 for (i
= 32; i
< 128; i
++) {
6725 uint16_t fnum
= (uint16_t)-1;
6729 if (strchr(illegal_chars
, i
)) {
6734 status
= cli_ntcreate(cli
, fname
, 0, GENERIC_ALL_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
6735 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OVERWRITE_IF
, 0, 0, &fnum
);
6736 if (!NT_STATUS_IS_OK(status
)) {
6737 d_printf("(%s) cli_nt_create of %s failed: %s\n",
6738 __location__
, fname
, cli_errstr(cli
));
6742 cli_close(cli
, fnum
);
6745 cli_list(cli
, "\\shortname\\test*.*", 0, shortname_list_fn
,
6747 if (s
.matched
!= 1) {
6748 d_printf("(%s) failed to list %s: %s\n",
6749 __location__
, fname
, cli_errstr(cli
));
6753 if (!NT_STATUS_IS_OK(cli_unlink(cli
, fname
, aSYSTEM
| aHIDDEN
))) {
6754 d_printf("(%s) failed to delete %s: %s\n",
6755 __location__
, fname
, cli_errstr(cli
));
6768 cli_list(cli
, "\\shortname\\*", 0, shortname_del_fn
, cli
);
6769 cli_list(cli
, "\\shortname\\*", aDIR
, shortname_del_fn
, cli
);
6770 cli_rmdir(cli
, "\\shortname");
6771 torture_close_connection(cli
);
6775 static void pagedsearch_cb(struct tevent_req
*req
)
6778 struct tldap_message
*msg
;
6781 rc
= tldap_search_paged_recv(req
, talloc_tos(), &msg
);
6782 if (rc
!= TLDAP_SUCCESS
) {
6783 d_printf("tldap_search_paged_recv failed: %s\n",
6784 tldap_err2string(rc
));
6787 if (tldap_msg_type(msg
) != TLDAP_RES_SEARCH_ENTRY
) {
6791 if (!tldap_entry_dn(msg
, &dn
)) {
6792 d_printf("tldap_entry_dn failed\n");
6795 d_printf("%s\n", dn
);
6799 static bool run_tldap(int dummy
)
6801 struct tldap_context
*ld
;
6804 struct sockaddr_storage addr
;
6805 struct tevent_context
*ev
;
6806 struct tevent_req
*req
;
6810 if (!resolve_name(host
, &addr
, 0, false)) {
6811 d_printf("could not find host %s\n", host
);
6814 status
= open_socket_out(&addr
, 389, 9999, &fd
);
6815 if (!NT_STATUS_IS_OK(status
)) {
6816 d_printf("open_socket_out failed: %s\n", nt_errstr(status
));
6820 ld
= tldap_context_create(talloc_tos(), fd
);
6823 d_printf("tldap_context_create failed\n");
6827 rc
= tldap_fetch_rootdse(ld
);
6828 if (rc
!= TLDAP_SUCCESS
) {
6829 d_printf("tldap_fetch_rootdse failed: %s\n",
6830 tldap_errstr(talloc_tos(), ld
, rc
));
6834 basedn
= tldap_talloc_single_attribute(
6835 tldap_rootdse(ld
), "defaultNamingContext", talloc_tos());
6836 if (basedn
== NULL
) {
6837 d_printf("no defaultNamingContext\n");
6840 d_printf("defaultNamingContext: %s\n", basedn
);
6842 ev
= tevent_context_init(talloc_tos());
6844 d_printf("tevent_context_init failed\n");
6848 req
= tldap_search_paged_send(talloc_tos(), ev
, ld
, basedn
,
6849 TLDAP_SCOPE_SUB
, "(objectclass=*)",
6851 NULL
, 0, NULL
, 0, 0, 0, 0, 5);
6853 d_printf("tldap_search_paged_send failed\n");
6856 tevent_req_set_callback(req
, pagedsearch_cb
, NULL
);
6858 tevent_req_poll(req
, ev
);
6862 /* test search filters against rootDSE */
6863 filter
= "(&(|(name=samba)(nextRid<=10000000)(usnChanged>=10)(samba~=ambas)(!(name=s*m*a)))"
6864 "(|(name:=samba)(name:dn:2.5.13.5:=samba)(:dn:2.5.13.5:=samba)(!(name=*samba))))";
6866 rc
= tldap_search(ld
, "", TLDAP_SCOPE_BASE
, filter
,
6867 NULL
, 0, 0, NULL
, 0, NULL
, 0, 0, 0, 0,
6868 talloc_tos(), NULL
, NULL
);
6869 if (rc
!= TLDAP_SUCCESS
) {
6870 d_printf("tldap_search with complex filter failed: %s\n",
6871 tldap_errstr(talloc_tos(), ld
, rc
));
6879 /* Torture test to ensure no regression of :
6880 https://bugzilla.samba.org/show_bug.cgi?id=7084
6883 static bool run_dir_createtime(int dummy
)
6885 struct cli_state
*cli
;
6886 const char *dname
= "\\testdir";
6887 const char *fname
= "\\testdir\\testfile";
6889 struct timespec create_time
;
6890 struct timespec create_time1
;
6894 if (!torture_open_connection(&cli
, 0)) {
6898 cli_unlink(cli
, fname
, aSYSTEM
| aHIDDEN
);
6899 cli_rmdir(cli
, dname
);
6901 status
= cli_mkdir(cli
, dname
);
6902 if (!NT_STATUS_IS_OK(status
)) {
6903 printf("mkdir failed: %s\n", nt_errstr(status
));
6907 status
= cli_qpathinfo2(cli
, dname
, &create_time
, NULL
, NULL
, NULL
,
6909 if (!NT_STATUS_IS_OK(status
)) {
6910 printf("cli_qpathinfo2 returned %s\n",
6915 /* Sleep 3 seconds, then create a file. */
6918 status
= cli_open(cli
, fname
, O_RDWR
| O_CREAT
| O_EXCL
,
6920 if (!NT_STATUS_IS_OK(status
)) {
6921 printf("cli_open failed: %s\n", nt_errstr(status
));
6925 status
= cli_qpathinfo2(cli
, dname
, &create_time1
, NULL
, NULL
, NULL
,
6927 if (!NT_STATUS_IS_OK(status
)) {
6928 printf("cli_qpathinfo2 (2) returned %s\n",
6933 if (timespec_compare(&create_time1
, &create_time
)) {
6934 printf("run_dir_createtime: create time was updated (error)\n");
6936 printf("run_dir_createtime: create time was not updated (correct)\n");
6942 cli_unlink(cli
, fname
, aSYSTEM
| aHIDDEN
);
6943 cli_rmdir(cli
, dname
);
6944 if (!torture_close_connection(cli
)) {
6951 static bool run_streamerror(int dummy
)
6953 struct cli_state
*cli
;
6954 const char *dname
= "\\testdir";
6955 const char *streamname
=
6956 "testdir:{4c8cc155-6c1e-11d1-8e41-00c04fb9386d}:$DATA";
6958 time_t change_time
, access_time
, write_time
;
6960 uint16_t mode
, fnum
;
6963 if (!torture_open_connection(&cli
, 0)) {
6967 cli_unlink(cli
, "\\testdir\\*", aSYSTEM
| aHIDDEN
);
6968 cli_rmdir(cli
, dname
);
6970 status
= cli_mkdir(cli
, dname
);
6971 if (!NT_STATUS_IS_OK(status
)) {
6972 printf("mkdir failed: %s\n", nt_errstr(status
));
6976 cli_qpathinfo1(cli
, streamname
, &change_time
, &access_time
, &write_time
,
6978 status
= cli_nt_error(cli
);
6980 if (!NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
)) {
6981 printf("pathinfo returned %s, expected "
6982 "NT_STATUS_OBJECT_NAME_NOT_FOUND\n",
6987 status
= cli_ntcreate(cli
, streamname
, 0x16,
6988 FILE_READ_DATA
|FILE_READ_EA
|
6989 FILE_READ_ATTRIBUTES
|READ_CONTROL_ACCESS
,
6990 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_READ
,
6991 FILE_OPEN
, 0, 0, &fnum
);
6993 if (!NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
)) {
6994 printf("ntcreate returned %s, expected "
6995 "NT_STATUS_OBJECT_NAME_NOT_FOUND\n",
7001 cli_rmdir(cli
, dname
);
7005 static bool run_local_substitute(int dummy
)
7009 ok
&= subst_test("%U", "bla", "", -1, -1, "bla");
7010 ok
&= subst_test("%u%U", "bla", "", -1, -1, "blabla");
7011 ok
&= subst_test("%g", "", "", -1, -1, "NO_GROUP");
7012 ok
&= subst_test("%G", "", "", -1, -1, "NO_GROUP");
7013 ok
&= subst_test("%g", "", "", -1, 0, gidtoname(0));
7014 ok
&= subst_test("%G", "", "", -1, 0, gidtoname(0));
7015 ok
&= subst_test("%D%u", "u", "dom", -1, 0, "domu");
7016 ok
&= subst_test("%i %I", "", "", -1, -1, "0.0.0.0 0.0.0.0");
7018 /* Different captialization rules in sub_basic... */
7020 ok
&= (strcmp(talloc_sub_basic(talloc_tos(), "BLA", "dom", "%U%D"),
7026 static bool run_local_base64(int dummy
)
7031 for (i
=1; i
<2000; i
++) {
7032 DATA_BLOB blob1
, blob2
;
7035 blob1
.data
= talloc_array(talloc_tos(), uint8_t, i
);
7037 generate_random_buffer(blob1
.data
, blob1
.length
);
7039 b64
= base64_encode_data_blob(talloc_tos(), blob1
);
7041 d_fprintf(stderr
, "base64_encode_data_blob failed "
7042 "for %d bytes\n", i
);
7045 blob2
= base64_decode_data_blob(b64
);
7048 if (data_blob_cmp(&blob1
, &blob2
)) {
7049 d_fprintf(stderr
, "data_blob_cmp failed for %d "
7053 TALLOC_FREE(blob1
.data
);
7054 data_blob_free(&blob2
);
7059 static bool run_local_gencache(int dummy
)
7065 if (!gencache_set("foo", "bar", time(NULL
) + 1000)) {
7066 d_printf("%s: gencache_set() failed\n", __location__
);
7070 if (!gencache_get("foo", NULL
, NULL
)) {
7071 d_printf("%s: gencache_get() failed\n", __location__
);
7075 if (!gencache_get("foo", &val
, &tm
)) {
7076 d_printf("%s: gencache_get() failed\n", __location__
);
7080 if (strcmp(val
, "bar") != 0) {
7081 d_printf("%s: gencache_get() returned %s, expected %s\n",
7082 __location__
, val
, "bar");
7089 if (!gencache_del("foo")) {
7090 d_printf("%s: gencache_del() failed\n", __location__
);
7093 if (gencache_del("foo")) {
7094 d_printf("%s: second gencache_del() succeeded\n",
7099 if (gencache_get("foo", &val
, &tm
)) {
7100 d_printf("%s: gencache_get() on deleted entry "
7101 "succeeded\n", __location__
);
7105 blob
= data_blob_string_const_null("bar");
7106 tm
= time(NULL
) + 60;
7108 if (!gencache_set_data_blob("foo", &blob
, tm
)) {
7109 d_printf("%s: gencache_set_data_blob() failed\n", __location__
);
7113 if (!gencache_get_data_blob("foo", &blob
, NULL
, NULL
)) {
7114 d_printf("%s: gencache_get_data_blob() failed\n", __location__
);
7118 if (strcmp((const char *)blob
.data
, "bar") != 0) {
7119 d_printf("%s: gencache_get_data_blob() returned %s, expected %s\n",
7120 __location__
, (const char *)blob
.data
, "bar");
7121 data_blob_free(&blob
);
7125 data_blob_free(&blob
);
7127 if (!gencache_del("foo")) {
7128 d_printf("%s: gencache_del() failed\n", __location__
);
7131 if (gencache_del("foo")) {
7132 d_printf("%s: second gencache_del() succeeded\n",
7137 if (gencache_get_data_blob("foo", &blob
, NULL
, NULL
)) {
7138 d_printf("%s: gencache_get_data_blob() on deleted entry "
7139 "succeeded\n", __location__
);
7146 static bool rbt_testval(struct db_context
*db
, const char *key
,
7149 struct db_record
*rec
;
7150 TDB_DATA data
= string_tdb_data(value
);
7154 rec
= db
->fetch_locked(db
, db
, string_tdb_data(key
));
7156 d_fprintf(stderr
, "fetch_locked failed\n");
7159 status
= rec
->store(rec
, data
, 0);
7160 if (!NT_STATUS_IS_OK(status
)) {
7161 d_fprintf(stderr
, "store failed: %s\n", nt_errstr(status
));
7166 rec
= db
->fetch_locked(db
, db
, string_tdb_data(key
));
7168 d_fprintf(stderr
, "second fetch_locked failed\n");
7171 if ((rec
->value
.dsize
!= data
.dsize
)
7172 || (memcmp(rec
->value
.dptr
, data
.dptr
, data
.dsize
) != 0)) {
7173 d_fprintf(stderr
, "Got wrong data back\n");
7183 static bool run_local_rbtree(int dummy
)
7185 struct db_context
*db
;
7189 db
= db_open_rbt(NULL
);
7192 d_fprintf(stderr
, "db_open_rbt failed\n");
7196 for (i
=0; i
<1000; i
++) {
7199 if (asprintf(&key
, "key%ld", random()) == -1) {
7202 if (asprintf(&value
, "value%ld", random()) == -1) {
7207 if (!rbt_testval(db
, key
, value
)) {
7214 if (asprintf(&value
, "value%ld", random()) == -1) {
7219 if (!rbt_testval(db
, key
, value
)) {
7236 struct talloc_dict_test
{
7240 static int talloc_dict_traverse_fn(DATA_BLOB key
, void *data
, void *priv
)
7242 int *count
= (int *)priv
;
7247 static bool run_local_talloc_dict(int dummy
)
7249 struct talloc_dict
*dict
;
7250 struct talloc_dict_test
*t
;
7253 dict
= talloc_dict_init(talloc_tos());
7258 t
= talloc(talloc_tos(), struct talloc_dict_test
);
7265 if (!talloc_dict_set(dict
, data_blob_const(&key
, sizeof(key
)), t
)) {
7270 if (talloc_dict_traverse(dict
, talloc_dict_traverse_fn
, &count
) != 0) {
7283 static bool run_local_string_to_sid(int dummy
) {
7286 if (string_to_sid(&sid
, "S--1-5-32-545")) {
7287 printf("allowing S--1-5-32-545\n");
7290 if (string_to_sid(&sid
, "S-1-5-32-+545")) {
7291 printf("allowing S-1-5-32-+545\n");
7294 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")) {
7295 printf("allowing S-1-2-3-4-5-6-7-8-9-0-1-2-3-4-5-6-7-8-9-0\n");
7298 if (string_to_sid(&sid
, "S-1-5-32-545-abc")) {
7299 printf("allowing S-1-5-32-545-abc\n");
7302 if (!string_to_sid(&sid
, "S-1-5-32-545")) {
7303 printf("could not parse S-1-5-32-545\n");
7306 if (!dom_sid_equal(&sid
, &global_sid_Builtin_Users
)) {
7307 printf("mis-parsed S-1-5-32-545 as %s\n",
7308 sid_string_tos(&sid
));
7314 static bool run_local_binary_to_sid(int dummy
) {
7315 struct dom_sid
*sid
= talloc(NULL
, struct dom_sid
);
7316 static const char good_binary_sid
[] = {
7317 0x1, /* revision number */
7319 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, /* id_auth */
7320 0x1, 0x1, 0x1, 0x1, /* auth[0] */
7321 0x1, 0x1, 0x1, 0x1, /* auth[1] */
7322 0x1, 0x1, 0x1, 0x1, /* auth[2] */
7323 0x1, 0x1, 0x1, 0x1, /* auth[3] */
7324 0x1, 0x1, 0x1, 0x1, /* auth[4] */
7325 0x1, 0x1, 0x1, 0x1, /* auth[5] */
7326 0x1, 0x1, 0x1, 0x1, /* auth[6] */
7327 0x1, 0x1, 0x1, 0x1, /* auth[7] */
7328 0x1, 0x1, 0x1, 0x1, /* auth[8] */
7329 0x1, 0x1, 0x1, 0x1, /* auth[9] */
7330 0x1, 0x1, 0x1, 0x1, /* auth[10] */
7331 0x1, 0x1, 0x1, 0x1, /* auth[11] */
7332 0x1, 0x1, 0x1, 0x1, /* auth[12] */
7333 0x1, 0x1, 0x1, 0x1, /* auth[13] */
7334 0x1, 0x1, 0x1, 0x1, /* auth[14] */
7337 static const char long_binary_sid
[] = {
7338 0x1, /* revision number */
7340 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, /* id_auth */
7341 0x1, 0x1, 0x1, 0x1, /* auth[0] */
7342 0x1, 0x1, 0x1, 0x1, /* auth[1] */
7343 0x1, 0x1, 0x1, 0x1, /* auth[2] */
7344 0x1, 0x1, 0x1, 0x1, /* auth[3] */
7345 0x1, 0x1, 0x1, 0x1, /* auth[4] */
7346 0x1, 0x1, 0x1, 0x1, /* auth[5] */
7347 0x1, 0x1, 0x1, 0x1, /* auth[6] */
7348 0x1, 0x1, 0x1, 0x1, /* auth[7] */
7349 0x1, 0x1, 0x1, 0x1, /* auth[8] */
7350 0x1, 0x1, 0x1, 0x1, /* auth[9] */
7351 0x1, 0x1, 0x1, 0x1, /* auth[10] */
7352 0x1, 0x1, 0x1, 0x1, /* auth[11] */
7353 0x1, 0x1, 0x1, 0x1, /* auth[12] */
7354 0x1, 0x1, 0x1, 0x1, /* auth[13] */
7355 0x1, 0x1, 0x1, 0x1, /* auth[14] */
7356 0x1, 0x1, 0x1, 0x1, /* auth[15] */
7357 0x1, 0x1, 0x1, 0x1, /* auth[16] */
7358 0x1, 0x1, 0x1, 0x1, /* auth[17] */
7361 static const char long_binary_sid2
[] = {
7362 0x1, /* revision number */
7364 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, /* id_auth */
7365 0x1, 0x1, 0x1, 0x1, /* auth[0] */
7366 0x1, 0x1, 0x1, 0x1, /* auth[1] */
7367 0x1, 0x1, 0x1, 0x1, /* auth[2] */
7368 0x1, 0x1, 0x1, 0x1, /* auth[3] */
7369 0x1, 0x1, 0x1, 0x1, /* auth[4] */
7370 0x1, 0x1, 0x1, 0x1, /* auth[5] */
7371 0x1, 0x1, 0x1, 0x1, /* auth[6] */
7372 0x1, 0x1, 0x1, 0x1, /* auth[7] */
7373 0x1, 0x1, 0x1, 0x1, /* auth[8] */
7374 0x1, 0x1, 0x1, 0x1, /* auth[9] */
7375 0x1, 0x1, 0x1, 0x1, /* auth[10] */
7376 0x1, 0x1, 0x1, 0x1, /* auth[11] */
7377 0x1, 0x1, 0x1, 0x1, /* auth[12] */
7378 0x1, 0x1, 0x1, 0x1, /* auth[13] */
7379 0x1, 0x1, 0x1, 0x1, /* auth[14] */
7380 0x1, 0x1, 0x1, 0x1, /* auth[15] */
7381 0x1, 0x1, 0x1, 0x1, /* auth[16] */
7382 0x1, 0x1, 0x1, 0x1, /* auth[17] */
7383 0x1, 0x1, 0x1, 0x1, /* auth[18] */
7384 0x1, 0x1, 0x1, 0x1, /* auth[19] */
7385 0x1, 0x1, 0x1, 0x1, /* auth[20] */
7386 0x1, 0x1, 0x1, 0x1, /* auth[21] */
7387 0x1, 0x1, 0x1, 0x1, /* auth[22] */
7388 0x1, 0x1, 0x1, 0x1, /* auth[23] */
7389 0x1, 0x1, 0x1, 0x1, /* auth[24] */
7390 0x1, 0x1, 0x1, 0x1, /* auth[25] */
7391 0x1, 0x1, 0x1, 0x1, /* auth[26] */
7392 0x1, 0x1, 0x1, 0x1, /* auth[27] */
7393 0x1, 0x1, 0x1, 0x1, /* auth[28] */
7394 0x1, 0x1, 0x1, 0x1, /* auth[29] */
7395 0x1, 0x1, 0x1, 0x1, /* auth[30] */
7396 0x1, 0x1, 0x1, 0x1, /* auth[31] */
7399 if (!sid_parse(good_binary_sid
, sizeof(good_binary_sid
), sid
)) {
7402 if (sid_parse(long_binary_sid2
, sizeof(long_binary_sid2
), sid
)) {
7405 if (sid_parse(long_binary_sid
, sizeof(long_binary_sid
), sid
)) {
7411 /* Split a path name into filename and stream name components. Canonicalise
7412 * such that an implicit $DATA token is always explicit.
7414 * The "specification" of this function can be found in the
7415 * run_local_stream_name() function in torture.c, I've tried those
7416 * combinations against a W2k3 server.
7419 static NTSTATUS
split_ntfs_stream_name(TALLOC_CTX
*mem_ctx
, const char *fname
,
7420 char **pbase
, char **pstream
)
7423 char *stream
= NULL
;
7424 char *sname
; /* stream name */
7425 const char *stype
; /* stream type */
7427 DEBUG(10, ("split_ntfs_stream_name called for [%s]\n", fname
));
7429 sname
= strchr_m(fname
, ':');
7431 if (lp_posix_pathnames() || (sname
== NULL
)) {
7432 if (pbase
!= NULL
) {
7433 base
= talloc_strdup(mem_ctx
, fname
);
7434 NT_STATUS_HAVE_NO_MEMORY(base
);
7439 if (pbase
!= NULL
) {
7440 base
= talloc_strndup(mem_ctx
, fname
, PTR_DIFF(sname
, fname
));
7441 NT_STATUS_HAVE_NO_MEMORY(base
);
7446 stype
= strchr_m(sname
, ':');
7448 if (stype
== NULL
) {
7449 sname
= talloc_strdup(mem_ctx
, sname
);
7453 if (StrCaseCmp(stype
, ":$DATA") != 0) {
7455 * If there is an explicit stream type, so far we only
7456 * allow $DATA. Is there anything else allowed? -- vl
7458 DEBUG(10, ("[%s] is an invalid stream type\n", stype
));
7460 return NT_STATUS_OBJECT_NAME_INVALID
;
7462 sname
= talloc_strndup(mem_ctx
, sname
, PTR_DIFF(stype
, sname
));
7466 if (sname
== NULL
) {
7468 return NT_STATUS_NO_MEMORY
;
7471 if (sname
[0] == '\0') {
7473 * no stream name, so no stream
7478 if (pstream
!= NULL
) {
7479 stream
= talloc_asprintf(mem_ctx
, "%s:%s", sname
, stype
);
7480 if (stream
== NULL
) {
7483 return NT_STATUS_NO_MEMORY
;
7486 * upper-case the type field
7488 strupper_m(strchr_m(stream
, ':')+1);
7492 if (pbase
!= NULL
) {
7495 if (pstream
!= NULL
) {
7498 return NT_STATUS_OK
;
7501 static bool test_stream_name(const char *fname
, const char *expected_base
,
7502 const char *expected_stream
,
7503 NTSTATUS expected_status
)
7507 char *stream
= NULL
;
7509 status
= split_ntfs_stream_name(talloc_tos(), fname
, &base
, &stream
);
7510 if (!NT_STATUS_EQUAL(status
, expected_status
)) {
7514 if (!NT_STATUS_IS_OK(status
)) {
7518 if (base
== NULL
) goto error
;
7520 if (strcmp(expected_base
, base
) != 0) goto error
;
7522 if ((expected_stream
!= NULL
) && (stream
== NULL
)) goto error
;
7523 if ((expected_stream
== NULL
) && (stream
!= NULL
)) goto error
;
7525 if ((stream
!= NULL
) && (strcmp(expected_stream
, stream
) != 0))
7529 TALLOC_FREE(stream
);
7533 d_fprintf(stderr
, "Do test_stream(%s, %s, %s, %s)\n",
7534 fname
, expected_base
? expected_base
: "<NULL>",
7535 expected_stream
? expected_stream
: "<NULL>",
7536 nt_errstr(expected_status
));
7537 d_fprintf(stderr
, "-> base=%s, stream=%s, status=%s\n",
7538 base
? base
: "<NULL>", stream
? stream
: "<NULL>",
7541 TALLOC_FREE(stream
);
7545 static bool run_local_stream_name(int dummy
)
7549 ret
&= test_stream_name(
7550 "bla", "bla", NULL
, NT_STATUS_OK
);
7551 ret
&= test_stream_name(
7552 "bla::$DATA", "bla", NULL
, NT_STATUS_OK
);
7553 ret
&= test_stream_name(
7554 "bla:blub:", "bla", NULL
, NT_STATUS_OBJECT_NAME_INVALID
);
7555 ret
&= test_stream_name(
7556 "bla::", NULL
, NULL
, NT_STATUS_OBJECT_NAME_INVALID
);
7557 ret
&= test_stream_name(
7558 "bla::123", "bla", NULL
, NT_STATUS_OBJECT_NAME_INVALID
);
7559 ret
&= test_stream_name(
7560 "bla:$DATA", "bla", "$DATA:$DATA", NT_STATUS_OK
);
7561 ret
&= test_stream_name(
7562 "bla:x:$DATA", "bla", "x:$DATA", NT_STATUS_OK
);
7563 ret
&= test_stream_name(
7564 "bla:x", "bla", "x:$DATA", NT_STATUS_OK
);
7569 static bool data_blob_equal(DATA_BLOB a
, DATA_BLOB b
)
7571 if (a
.length
!= b
.length
) {
7572 printf("a.length=%d != b.length=%d\n",
7573 (int)a
.length
, (int)b
.length
);
7576 if (memcmp(a
.data
, b
.data
, a
.length
) != 0) {
7577 printf("a.data and b.data differ\n");
7583 static bool run_local_memcache(int dummy
)
7585 struct memcache
*cache
;
7587 DATA_BLOB d1
, d2
, d3
;
7588 DATA_BLOB v1
, v2
, v3
;
7590 TALLOC_CTX
*mem_ctx
;
7592 size_t size1
, size2
;
7595 cache
= memcache_init(NULL
, 100);
7597 if (cache
== NULL
) {
7598 printf("memcache_init failed\n");
7602 d1
= data_blob_const("d1", 2);
7603 d2
= data_blob_const("d2", 2);
7604 d3
= data_blob_const("d3", 2);
7606 k1
= data_blob_const("d1", 2);
7607 k2
= data_blob_const("d2", 2);
7609 memcache_add(cache
, STAT_CACHE
, k1
, d1
);
7610 memcache_add(cache
, GETWD_CACHE
, k2
, d2
);
7612 if (!memcache_lookup(cache
, STAT_CACHE
, k1
, &v1
)) {
7613 printf("could not find k1\n");
7616 if (!data_blob_equal(d1
, v1
)) {
7620 if (!memcache_lookup(cache
, GETWD_CACHE
, k2
, &v2
)) {
7621 printf("could not find k2\n");
7624 if (!data_blob_equal(d2
, v2
)) {
7628 memcache_add(cache
, STAT_CACHE
, k1
, d3
);
7630 if (!memcache_lookup(cache
, STAT_CACHE
, k1
, &v3
)) {
7631 printf("could not find replaced k1\n");
7634 if (!data_blob_equal(d3
, v3
)) {
7638 memcache_add(cache
, GETWD_CACHE
, k1
, d1
);
7640 if (memcache_lookup(cache
, GETWD_CACHE
, k2
, &v2
)) {
7641 printf("Did find k2, should have been purged\n");
7647 cache
= memcache_init(NULL
, 0);
7649 mem_ctx
= talloc_init("foo");
7651 str1
= talloc_strdup(mem_ctx
, "string1");
7652 str2
= talloc_strdup(mem_ctx
, "string2");
7654 memcache_add_talloc(cache
, SINGLETON_CACHE_TALLOC
,
7655 data_blob_string_const("torture"), &str1
);
7656 size1
= talloc_total_size(cache
);
7658 memcache_add_talloc(cache
, SINGLETON_CACHE_TALLOC
,
7659 data_blob_string_const("torture"), &str2
);
7660 size2
= talloc_total_size(cache
);
7662 printf("size1=%d, size2=%d\n", (int)size1
, (int)size2
);
7664 if (size2
> size1
) {
7665 printf("memcache leaks memory!\n");
7675 static void wbclient_done(struct tevent_req
*req
)
7678 struct winbindd_response
*wb_resp
;
7679 int *i
= (int *)tevent_req_callback_data_void(req
);
7681 wbc_err
= wb_trans_recv(req
, req
, &wb_resp
);
7684 d_printf("wb_trans_recv %d returned %s\n", *i
, wbcErrorString(wbc_err
));
7687 static bool run_local_wbclient(int dummy
)
7689 struct event_context
*ev
;
7690 struct wb_context
**wb_ctx
;
7691 struct winbindd_request wb_req
;
7692 bool result
= false;
7695 BlockSignals(True
, SIGPIPE
);
7697 ev
= tevent_context_init_byname(talloc_tos(), "epoll");
7702 wb_ctx
= TALLOC_ARRAY(ev
, struct wb_context
*, nprocs
);
7703 if (wb_ctx
== NULL
) {
7707 ZERO_STRUCT(wb_req
);
7708 wb_req
.cmd
= WINBINDD_PING
;
7710 d_printf("nprocs=%d, numops=%d\n", (int)nprocs
, (int)torture_numops
);
7712 for (i
=0; i
<nprocs
; i
++) {
7713 wb_ctx
[i
] = wb_context_init(ev
, NULL
);
7714 if (wb_ctx
[i
] == NULL
) {
7717 for (j
=0; j
<torture_numops
; j
++) {
7718 struct tevent_req
*req
;
7719 req
= wb_trans_send(ev
, ev
, wb_ctx
[i
],
7720 (j
% 2) == 0, &wb_req
);
7724 tevent_req_set_callback(req
, wbclient_done
, &i
);
7730 while (i
< nprocs
* torture_numops
) {
7731 event_loop_once(ev
);
7740 static void getaddrinfo_finished(struct tevent_req
*req
)
7742 char *name
= (char *)tevent_req_callback_data_void(req
);
7743 struct addrinfo
*ainfo
;
7746 res
= getaddrinfo_recv(req
, &ainfo
);
7748 d_printf("gai(%s) returned %s\n", name
, gai_strerror(res
));
7751 d_printf("gai(%s) succeeded\n", name
);
7752 freeaddrinfo(ainfo
);
7755 static bool run_getaddrinfo_send(int dummy
)
7757 TALLOC_CTX
*frame
= talloc_stackframe();
7758 struct fncall_context
*ctx
;
7759 struct tevent_context
*ev
;
7760 bool result
= false;
7761 const char *names
[4] = { "www.samba.org", "notfound.samba.org",
7762 "www.slashdot.org", "heise.de" };
7763 struct tevent_req
*reqs
[4];
7766 ev
= event_context_init(frame
);
7771 ctx
= fncall_context_init(frame
, 4);
7773 for (i
=0; i
<ARRAY_SIZE(names
); i
++) {
7774 reqs
[i
] = getaddrinfo_send(frame
, ev
, ctx
, names
[i
], NULL
,
7776 if (reqs
[i
] == NULL
) {
7779 tevent_req_set_callback(reqs
[i
], getaddrinfo_finished
,
7783 for (i
=0; i
<ARRAY_SIZE(reqs
); i
++) {
7784 tevent_loop_once(ev
);
7793 static bool dbtrans_inc(struct db_context
*db
)
7795 struct db_record
*rec
;
7800 rec
= db
->fetch_locked(db
, db
, string_term_tdb_data("transtest"));
7802 printf(__location__
"fetch_lock failed\n");
7806 if (rec
->value
.dsize
!= sizeof(uint32_t)) {
7807 printf(__location__
"value.dsize = %d\n",
7808 (int)rec
->value
.dsize
);
7812 val
= (uint32_t *)rec
->value
.dptr
;
7815 status
= rec
->store(rec
, make_tdb_data((uint8_t *)val
,
7818 if (!NT_STATUS_IS_OK(status
)) {
7819 printf(__location__
"store failed: %s\n",
7830 static bool run_local_dbtrans(int dummy
)
7832 struct db_context
*db
;
7833 struct db_record
*rec
;
7838 db
= db_open(talloc_tos(), "transtest.tdb", 0, TDB_DEFAULT
,
7839 O_RDWR
|O_CREAT
, 0600);
7841 printf("Could not open transtest.db\n");
7845 res
= db
->transaction_start(db
);
7847 printf(__location__
"transaction_start failed\n");
7851 rec
= db
->fetch_locked(db
, db
, string_term_tdb_data("transtest"));
7853 printf(__location__
"fetch_lock failed\n");
7857 if (rec
->value
.dptr
== NULL
) {
7859 status
= rec
->store(
7860 rec
, make_tdb_data((uint8_t *)&initial
,
7863 if (!NT_STATUS_IS_OK(status
)) {
7864 printf(__location__
"store returned %s\n",
7872 res
= db
->transaction_commit(db
);
7874 printf(__location__
"transaction_commit failed\n");
7882 res
= db
->transaction_start(db
);
7884 printf(__location__
"transaction_start failed\n");
7888 if (!dbwrap_fetch_uint32(db
, "transtest", &val
)) {
7889 printf(__location__
"dbwrap_fetch_uint32 failed\n");
7893 for (i
=0; i
<10; i
++) {
7894 if (!dbtrans_inc(db
)) {
7899 if (!dbwrap_fetch_uint32(db
, "transtest", &val2
)) {
7900 printf(__location__
"dbwrap_fetch_uint32 failed\n");
7904 if (val2
!= val
+ 10) {
7905 printf(__location__
"val=%d, val2=%d\n",
7906 (int)val
, (int)val2
);
7910 printf("val2=%d\r", val2
);
7912 res
= db
->transaction_commit(db
);
7914 printf(__location__
"transaction_commit failed\n");
7924 * Just a dummy test to be run under a debugger. There's no real way
7925 * to inspect the tevent_select specific function from outside of
7929 static bool run_local_tevent_select(int dummy
)
7931 struct tevent_context
*ev
;
7932 struct tevent_fd
*fd1
, *fd2
;
7933 bool result
= false;
7935 ev
= tevent_context_init_byname(NULL
, "select");
7937 d_fprintf(stderr
, "tevent_context_init_byname failed\n");
7941 fd1
= tevent_add_fd(ev
, ev
, 2, 0, NULL
, NULL
);
7943 d_fprintf(stderr
, "tevent_add_fd failed\n");
7946 fd2
= tevent_add_fd(ev
, ev
, 3, 0, NULL
, NULL
);
7948 d_fprintf(stderr
, "tevent_add_fd failed\n");
7953 fd2
= tevent_add_fd(ev
, ev
, 1, 0, NULL
, NULL
);
7955 d_fprintf(stderr
, "tevent_add_fd failed\n");
7965 static double create_procs(bool (*fn
)(int), bool *result
)
7968 volatile pid_t
*child_status
;
7969 volatile bool *child_status_out
;
7972 struct timeval start
;
7976 child_status
= (volatile pid_t
*)shm_setup(sizeof(pid_t
)*nprocs
);
7977 if (!child_status
) {
7978 printf("Failed to setup shared memory\n");
7982 child_status_out
= (volatile bool *)shm_setup(sizeof(bool)*nprocs
);
7983 if (!child_status_out
) {
7984 printf("Failed to setup result status shared memory\n");
7988 for (i
= 0; i
< nprocs
; i
++) {
7989 child_status
[i
] = 0;
7990 child_status_out
[i
] = True
;
7993 start
= timeval_current();
7995 for (i
=0;i
<nprocs
;i
++) {
7998 pid_t mypid
= getpid();
7999 sys_srandom(((int)mypid
) ^ ((int)time(NULL
)));
8001 slprintf(myname
,sizeof(myname
),"CLIENT%d", i
);
8004 if (torture_open_connection(¤t_cli
, i
)) break;
8006 printf("pid %d failed to start\n", (int)getpid());
8012 child_status
[i
] = getpid();
8014 while (child_status
[i
] && timeval_elapsed(&start
) < 5) smb_msleep(2);
8016 child_status_out
[i
] = fn(i
);
8023 for (i
=0;i
<nprocs
;i
++) {
8024 if (child_status
[i
]) synccount
++;
8026 if (synccount
== nprocs
) break;
8028 } while (timeval_elapsed(&start
) < 30);
8030 if (synccount
!= nprocs
) {
8031 printf("FAILED TO START %d CLIENTS (started %d)\n", nprocs
, synccount
);
8033 return timeval_elapsed(&start
);
8036 /* start the client load */
8037 start
= timeval_current();
8039 for (i
=0;i
<nprocs
;i
++) {
8040 child_status
[i
] = 0;
8043 printf("%d clients started\n", nprocs
);
8045 for (i
=0;i
<nprocs
;i
++) {
8046 while (waitpid(0, &status
, 0) == -1 && errno
== EINTR
) /* noop */ ;
8051 for (i
=0;i
<nprocs
;i
++) {
8052 if (!child_status_out
[i
]) {
8056 return timeval_elapsed(&start
);
8059 #define FLAG_MULTIPROC 1
8066 {"FDPASS", run_fdpasstest
, 0},
8067 {"LOCK1", run_locktest1
, 0},
8068 {"LOCK2", run_locktest2
, 0},
8069 {"LOCK3", run_locktest3
, 0},
8070 {"LOCK4", run_locktest4
, 0},
8071 {"LOCK5", run_locktest5
, 0},
8072 {"LOCK6", run_locktest6
, 0},
8073 {"LOCK7", run_locktest7
, 0},
8074 {"LOCK8", run_locktest8
, 0},
8075 {"LOCK9", run_locktest9
, 0},
8076 {"UNLINK", run_unlinktest
, 0},
8077 {"BROWSE", run_browsetest
, 0},
8078 {"ATTR", run_attrtest
, 0},
8079 {"TRANS2", run_trans2test
, 0},
8080 {"MAXFID", run_maxfidtest
, FLAG_MULTIPROC
},
8081 {"TORTURE",run_torture
, FLAG_MULTIPROC
},
8082 {"RANDOMIPC", run_randomipc
, 0},
8083 {"NEGNOWAIT", run_negprot_nowait
, 0},
8084 {"NBENCH", run_nbench
, 0},
8085 {"NBENCH2", run_nbench2
, 0},
8086 {"OPLOCK1", run_oplock1
, 0},
8087 {"OPLOCK2", run_oplock2
, 0},
8088 {"OPLOCK3", run_oplock3
, 0},
8089 {"OPLOCK4", run_oplock4
, 0},
8090 {"DIR", run_dirtest
, 0},
8091 {"DIR1", run_dirtest1
, 0},
8092 {"DIR-CREATETIME", run_dir_createtime
, 0},
8093 {"DENY1", torture_denytest1
, 0},
8094 {"DENY2", torture_denytest2
, 0},
8095 {"TCON", run_tcon_test
, 0},
8096 {"TCONDEV", run_tcon_devtype_test
, 0},
8097 {"RW1", run_readwritetest
, 0},
8098 {"RW2", run_readwritemulti
, FLAG_MULTIPROC
},
8099 {"RW3", run_readwritelarge
, 0},
8100 {"RW-SIGNING", run_readwritelarge_signtest
, 0},
8101 {"OPEN", run_opentest
, 0},
8102 {"POSIX", run_simple_posix_open_test
, 0},
8103 {"POSIX-APPEND", run_posix_append
, 0},
8104 {"ASYNC-ECHO", run_async_echo
, 0},
8105 { "UID-REGRESSION-TEST", run_uid_regression_test
, 0},
8106 { "SHORTNAME-TEST", run_shortname_test
, 0},
8107 { "ADDRCHANGE", run_addrchange
, 0},
8109 {"OPENATTR", run_openattrtest
, 0},
8111 {"XCOPY", run_xcopy
, 0},
8112 {"RENAME", run_rename
, 0},
8113 {"DELETE", run_deletetest
, 0},
8114 {"DELETE-LN", run_deletetest_ln
, 0},
8115 {"PROPERTIES", run_properties
, 0},
8116 {"MANGLE", torture_mangle
, 0},
8117 {"MANGLE1", run_mangle1
, 0},
8118 {"W2K", run_w2ktest
, 0},
8119 {"TRANS2SCAN", torture_trans2_scan
, 0},
8120 {"NTTRANSSCAN", torture_nttrans_scan
, 0},
8121 {"UTABLE", torture_utable
, 0},
8122 {"CASETABLE", torture_casetable
, 0},
8123 {"ERRMAPEXTRACT", run_error_map_extract
, 0},
8124 {"PIPE_NUMBER", run_pipe_number
, 0},
8125 {"TCON2", run_tcon2_test
, 0},
8126 {"IOCTL", torture_ioctl_test
, 0},
8127 {"CHKPATH", torture_chkpath_test
, 0},
8128 {"FDSESS", run_fdsesstest
, 0},
8129 { "EATEST", run_eatest
, 0},
8130 { "SESSSETUP_BENCH", run_sesssetup_bench
, 0},
8131 { "CHAIN1", run_chain1
, 0},
8132 { "CHAIN2", run_chain2
, 0},
8133 { "WINDOWS-WRITE", run_windows_write
, 0},
8134 { "CLI_ECHO", run_cli_echo
, 0},
8135 { "GETADDRINFO", run_getaddrinfo_send
, 0},
8136 { "TLDAP", run_tldap
},
8137 { "STREAMERROR", run_streamerror
},
8138 { "NOTIFY-BENCH", run_notify_bench
},
8139 { "BAD-NBT-SESSION", run_bad_nbt_session
},
8140 { "SMB-ANY-CONNECT", run_smb_any_connect
},
8141 { "LOCAL-SUBSTITUTE", run_local_substitute
, 0},
8142 { "LOCAL-GENCACHE", run_local_gencache
, 0},
8143 { "LOCAL-TALLOC-DICT", run_local_talloc_dict
, 0},
8144 { "LOCAL-BASE64", run_local_base64
, 0},
8145 { "LOCAL-RBTREE", run_local_rbtree
, 0},
8146 { "LOCAL-MEMCACHE", run_local_memcache
, 0},
8147 { "LOCAL-STREAM-NAME", run_local_stream_name
, 0},
8148 { "LOCAL-WBCLIENT", run_local_wbclient
, 0},
8149 { "LOCAL-string_to_sid", run_local_string_to_sid
, 0},
8150 { "LOCAL-binary_to_sid", run_local_binary_to_sid
, 0},
8151 { "LOCAL-DBTRANS", run_local_dbtrans
, 0},
8152 { "LOCAL-TEVENT-SELECT", run_local_tevent_select
, 0},
8157 /****************************************************************************
8158 run a specified test or "ALL"
8159 ****************************************************************************/
8160 static bool run_test(const char *name
)
8167 if (strequal(name
,"ALL")) {
8168 for (i
=0;torture_ops
[i
].name
;i
++) {
8169 run_test(torture_ops
[i
].name
);
8174 for (i
=0;torture_ops
[i
].name
;i
++) {
8175 fstr_sprintf(randomfname
, "\\XX%x",
8176 (unsigned)random());
8178 if (strequal(name
, torture_ops
[i
].name
)) {
8180 printf("Running %s\n", name
);
8181 if (torture_ops
[i
].flags
& FLAG_MULTIPROC
) {
8182 t
= create_procs(torture_ops
[i
].fn
, &result
);
8185 printf("TEST %s FAILED!\n", name
);
8188 struct timeval start
;
8189 start
= timeval_current();
8190 if (!torture_ops
[i
].fn(0)) {
8192 printf("TEST %s FAILED!\n", name
);
8194 t
= timeval_elapsed(&start
);
8196 printf("%s took %g secs\n\n", name
, t
);
8201 printf("Did not find a test named %s\n", name
);
8209 static void usage(void)
8213 printf("WARNING samba4 test suite is much more complete nowadays.\n");
8214 printf("Please use samba4 torture.\n\n");
8216 printf("Usage: smbtorture //server/share <options> TEST1 TEST2 ...\n");
8218 printf("\t-d debuglevel\n");
8219 printf("\t-U user%%pass\n");
8220 printf("\t-k use kerberos\n");
8221 printf("\t-N numprocs\n");
8222 printf("\t-n my_netbios_name\n");
8223 printf("\t-W workgroup\n");
8224 printf("\t-o num_operations\n");
8225 printf("\t-O socket_options\n");
8226 printf("\t-m maximum protocol\n");
8227 printf("\t-L use oplocks\n");
8228 printf("\t-c CLIENT.TXT specify client load file for NBENCH\n");
8229 printf("\t-A showall\n");
8230 printf("\t-p port\n");
8231 printf("\t-s seed\n");
8232 printf("\t-b unclist_filename specify multiple shares for multiple connections\n");
8235 printf("tests are:");
8236 for (i
=0;torture_ops
[i
].name
;i
++) {
8237 printf(" %s", torture_ops
[i
].name
);
8241 printf("default test is ALL\n");
8246 /****************************************************************************
8248 ****************************************************************************/
8249 int main(int argc
,char *argv
[])
8255 bool correct
= True
;
8256 TALLOC_CTX
*frame
= talloc_stackframe();
8257 int seed
= time(NULL
);
8259 #ifdef HAVE_SETBUFFER
8260 setbuffer(stdout
, NULL
, 0);
8263 setup_logging("smbtorture", DEBUG_STDOUT
);
8267 if (is_default_dyn_CONFIGFILE()) {
8268 if(getenv("SMB_CONF_PATH")) {
8269 set_dyn_CONFIGFILE(getenv("SMB_CONF_PATH"));
8272 lp_load(get_dyn_CONFIGFILE(),True
,False
,False
,True
);
8279 for(p
= argv
[1]; *p
; p
++)
8283 if (strncmp(argv
[1], "//", 2)) {
8287 fstrcpy(host
, &argv
[1][2]);
8288 p
= strchr_m(&host
[2],'/');
8293 fstrcpy(share
, p
+1);
8295 fstrcpy(myname
, get_myname(talloc_tos()));
8297 fprintf(stderr
, "Failed to get my hostname.\n");
8301 if (*username
== 0 && getenv("LOGNAME")) {
8302 fstrcpy(username
,getenv("LOGNAME"));
8308 fstrcpy(workgroup
, lp_workgroup());
8310 while ((opt
= getopt(argc
, argv
, "p:hW:U:n:N:O:o:m:Ll:d:Aec:ks:b:B:")) != EOF
) {
8313 port_to_use
= atoi(optarg
);
8316 seed
= atoi(optarg
);
8319 fstrcpy(workgroup
,optarg
);
8322 max_protocol
= interpret_protocol(optarg
, max_protocol
);
8325 nprocs
= atoi(optarg
);
8328 torture_numops
= atoi(optarg
);
8331 lp_set_cmdline("log level", optarg
);
8340 local_path
= optarg
;
8343 torture_showall
= True
;
8346 fstrcpy(myname
, optarg
);
8349 client_txt
= optarg
;
8356 use_kerberos
= True
;
8358 d_printf("No kerberos support compiled in\n");
8364 fstrcpy(username
,optarg
);
8365 p
= strchr_m(username
,'%');
8368 fstrcpy(password
, p
+1);
8373 fstrcpy(multishare_conn_fname
, optarg
);
8374 use_multishare_conn
= True
;
8377 torture_blocksize
= atoi(optarg
);
8380 printf("Unknown option %c (%d)\n", (char)opt
, opt
);
8385 d_printf("using seed %d\n", seed
);
8389 if(use_kerberos
&& !gotuser
) gotpass
= True
;
8392 p
= getpass("Password:");
8394 fstrcpy(password
, p
);
8399 printf("host=%s share=%s user=%s myname=%s\n",
8400 host
, share
, username
, myname
);
8402 if (argc
== optind
) {
8403 correct
= run_test("ALL");
8405 for (i
=optind
;i
<argc
;i
++) {
8406 if (!run_test(argv
[i
])) {