2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 1997-1998
5 Copyright (C) Jeremy Allison 2009
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "system/shmem.h"
23 #include "wbc_async.h"
24 #include "torture/proto.h"
25 #include "libcli/security/security.h"
27 #include "tldap_util.h"
28 #include "../librpc/gen_ndr/svcctl.h"
30 #include "nsswitch/winbind_client.h"
32 #include "talloc_dict.h"
33 #include "async_smb.h"
34 #include "libsmb/libsmb.h"
35 #include "libsmb/clirap.h"
37 #include "libsmb/nmblib.h"
38 #include "../lib/util/tevent_ntstatus.h"
40 #include "libsmb/read_smb.h"
45 fstring host
, workgroup
, share
, password
, username
, myname
;
46 static int max_protocol
= PROTOCOL_NT1
;
47 static const char *sockops
="TCP_NODELAY";
49 static int port_to_use
=0;
50 int torture_numops
=100;
51 int torture_blocksize
=1024*1024;
52 static int procnum
; /* records process count number when forking */
53 static struct cli_state
*current_cli
;
54 static fstring randomfname
;
55 static bool use_oplocks
;
56 static bool use_level_II_oplocks
;
57 static const char *client_txt
= "client_oplocks.txt";
58 static bool use_kerberos
;
59 static fstring multishare_conn_fname
;
60 static bool use_multishare_conn
= False
;
61 static bool do_encrypt
;
62 static const char *local_path
= NULL
;
63 static int signing_state
= Undefined
;
66 bool torture_showall
= False
;
68 static double create_procs(bool (*fn
)(int), bool *result
);
71 /* return a pointer to a anonymous shared memory segment of size "size"
72 which will persist across fork() but will disappear when all processes
75 The memory is not zeroed
77 This function uses system5 shared memory. It takes advantage of a property
78 that the memory is not destroyed if it is attached when the id is removed
80 void *shm_setup(int size
)
86 shmid
= shm_open("private", O_RDWR
| O_CREAT
| O_EXCL
, S_IRUSR
| S_IWUSR
);
88 printf("can't get shared memory\n");
91 shm_unlink("private");
92 if (ftruncate(shmid
, size
) == -1) {
93 printf("can't set shared memory size\n");
96 ret
= mmap(0, size
, PROT_READ
| PROT_WRITE
, MAP_SHARED
, shmid
, 0);
97 if (ret
== MAP_FAILED
) {
98 printf("can't map shared memory\n");
102 shmid
= shmget(IPC_PRIVATE
, size
, S_IRUSR
| S_IWUSR
);
104 printf("can't get shared memory\n");
107 ret
= (void *)shmat(shmid
, 0, 0);
108 if (!ret
|| ret
== (void *)-1) {
109 printf("can't attach to shared memory\n");
112 /* the following releases the ipc, but note that this process
113 and all its children will still have access to the memory, its
114 just that the shmid is no longer valid for other shm calls. This
115 means we don't leave behind lots of shm segments after we exit
117 See Stevens "advanced programming in unix env" for details
119 shmctl(shmid
, IPC_RMID
, 0);
125 /********************************************************************
126 Ensure a connection is encrypted.
127 ********************************************************************/
129 static bool force_cli_encryption(struct cli_state
*c
,
130 const char *sharename
)
133 uint32 caplow
, caphigh
;
136 if (!SERVER_HAS_UNIX_CIFS(c
)) {
137 d_printf("Encryption required and "
138 "server that doesn't support "
139 "UNIX extensions - failing connect\n");
143 status
= cli_unix_extensions_version(c
, &major
, &minor
, &caplow
,
145 if (!NT_STATUS_IS_OK(status
)) {
146 d_printf("Encryption required and "
147 "can't get UNIX CIFS extensions "
148 "version from server: %s\n", nt_errstr(status
));
152 if (!(caplow
& CIFS_UNIX_TRANSPORT_ENCRYPTION_CAP
)) {
153 d_printf("Encryption required and "
154 "share %s doesn't support "
155 "encryption.\n", sharename
);
159 if (c
->use_kerberos
) {
160 status
= cli_gss_smb_encryption_start(c
);
162 status
= cli_raw_ntlm_smb_encryption_start(c
,
168 if (!NT_STATUS_IS_OK(status
)) {
169 d_printf("Encryption required and "
170 "setup failed with error %s.\n",
179 static struct cli_state
*open_nbt_connection(void)
184 status
= cli_connect_nb(host
, NULL
, port_to_use
, 0x20, myname
,
186 if (!NT_STATUS_IS_OK(status
)) {
187 printf("Failed to connect with %s. Error %s\n", host
, nt_errstr(status
) );
191 c
->use_kerberos
= use_kerberos
;
193 c
->timeout
= 120000; /* set a really long timeout (2 minutes) */
194 if (use_oplocks
) c
->use_oplocks
= True
;
195 if (use_level_II_oplocks
) c
->use_level_II_oplocks
= True
;
200 /****************************************************************************
201 Send a corrupt session request. See rfc1002.txt 4.3 and 4.3.2.
202 ****************************************************************************/
204 static bool cli_bad_session_request(int fd
,
205 struct nmb_name
*calling
, struct nmb_name
*called
)
214 uint8_t message_type
;
217 frame
= talloc_stackframe();
219 iov
[0].iov_base
= len_buf
;
220 iov
[0].iov_len
= sizeof(len_buf
);
222 /* put in the destination name */
224 iov
[1].iov_base
= name_mangle(talloc_tos(), called
->name
,
226 if (iov
[1].iov_base
== NULL
) {
229 iov
[1].iov_len
= name_len((unsigned char *)iov
[1].iov_base
,
230 talloc_get_size(iov
[1].iov_base
));
234 iov
[2].iov_base
= name_mangle(talloc_tos(), calling
->name
,
236 if (iov
[2].iov_base
== NULL
) {
239 iov
[2].iov_len
= name_len((unsigned char *)iov
[2].iov_base
,
240 talloc_get_size(iov
[2].iov_base
));
242 /* Deliberately corrupt the name len (first byte) */
243 *((uint8_t *)iov
[2].iov_base
) = 100;
245 /* send a session request (RFC 1002) */
246 /* setup the packet length
247 * Remove four bytes from the length count, since the length
248 * field in the NBT Session Service header counts the number
249 * of bytes which follow. The cli_send_smb() function knows
250 * about this and accounts for those four bytes.
254 _smb_setlen(len_buf
, iov
[1].iov_len
+ iov
[2].iov_len
);
255 SCVAL(len_buf
,0,0x81);
257 len
= write_data_iov(fd
, iov
, 3);
261 len
= read_smb(fd
, talloc_tos(), &inbuf
, &err
);
267 message_type
= CVAL(inbuf
, 0);
268 if (message_type
!= 0x83) {
269 d_fprintf(stderr
, "Expected msg type 0x83, got 0x%2.2x\n",
274 if (smb_len(inbuf
) != 1) {
275 d_fprintf(stderr
, "Expected smb_len 1, got %d\n",
276 (int)smb_len(inbuf
));
280 error
= CVAL(inbuf
, 4);
282 d_fprintf(stderr
, "Expected error 0x82, got %d\n",
293 /* Insert a NULL at the first separator of the given path and return a pointer
294 * to the remainder of the string.
297 terminate_path_at_separator(char * path
)
305 if ((p
= strchr_m(path
, '/'))) {
310 if ((p
= strchr_m(path
, '\\'))) {
320 parse a //server/share type UNC name
322 bool smbcli_parse_unc(const char *unc_name
, TALLOC_CTX
*mem_ctx
,
323 char **hostname
, char **sharename
)
327 *hostname
= *sharename
= NULL
;
329 if (strncmp(unc_name
, "\\\\", 2) &&
330 strncmp(unc_name
, "//", 2)) {
334 *hostname
= talloc_strdup(mem_ctx
, &unc_name
[2]);
335 p
= terminate_path_at_separator(*hostname
);
338 *sharename
= talloc_strdup(mem_ctx
, p
);
339 terminate_path_at_separator(*sharename
);
342 if (*hostname
&& *sharename
) {
346 TALLOC_FREE(*hostname
);
347 TALLOC_FREE(*sharename
);
351 static bool torture_open_connection_share(struct cli_state
**c
,
352 const char *hostname
,
353 const char *sharename
)
359 flags
|= CLI_FULL_CONNECTION_USE_KERBEROS
;
361 flags
|= CLI_FULL_CONNECTION_OPLOCKS
;
362 if (use_level_II_oplocks
)
363 flags
|= CLI_FULL_CONNECTION_LEVEL_II_OPLOCKS
;
365 status
= cli_full_connection(c
, myname
,
366 hostname
, NULL
, port_to_use
,
369 password
, flags
, signing_state
);
370 if (!NT_STATUS_IS_OK(status
)) {
371 printf("failed to open share connection: //%s/%s port:%d - %s\n",
372 hostname
, sharename
, port_to_use
, nt_errstr(status
));
376 (*c
)->timeout
= 120000; /* set a really long timeout (2 minutes) */
379 return force_cli_encryption(*c
,
385 bool torture_open_connection(struct cli_state
**c
, int conn_index
)
387 char **unc_list
= NULL
;
388 int num_unc_names
= 0;
391 if (use_multishare_conn
==True
) {
393 unc_list
= file_lines_load(multishare_conn_fname
, &num_unc_names
, 0, NULL
);
394 if (!unc_list
|| num_unc_names
<= 0) {
395 printf("Failed to load unc names list from '%s'\n", multishare_conn_fname
);
399 if (!smbcli_parse_unc(unc_list
[conn_index
% num_unc_names
],
401 printf("Failed to parse UNC name %s\n",
402 unc_list
[conn_index
% num_unc_names
]);
403 TALLOC_FREE(unc_list
);
407 result
= torture_open_connection_share(c
, h
, s
);
409 /* h, s were copied earlier */
410 TALLOC_FREE(unc_list
);
414 return torture_open_connection_share(c
, host
, share
);
417 bool torture_init_connection(struct cli_state
**pcli
)
419 struct cli_state
*cli
;
421 cli
= open_nbt_connection();
430 bool torture_cli_session_setup2(struct cli_state
*cli
, uint16
*new_vuid
)
432 uint16 old_vuid
= cli
->vuid
;
433 fstring old_user_name
;
434 size_t passlen
= strlen(password
);
438 fstrcpy(old_user_name
, cli
->user_name
);
440 ret
= NT_STATUS_IS_OK(cli_session_setup(cli
, username
,
444 *new_vuid
= cli
->vuid
;
445 cli
->vuid
= old_vuid
;
446 status
= cli_set_username(cli
, old_user_name
);
447 if (!NT_STATUS_IS_OK(status
)) {
454 bool torture_close_connection(struct cli_state
*c
)
459 status
= cli_tdis(c
);
460 if (!NT_STATUS_IS_OK(status
)) {
461 printf("tdis failed (%s)\n", nt_errstr(status
));
471 /* check if the server produced the expected dos or nt error code */
472 static bool check_both_error(int line
, NTSTATUS status
,
473 uint8 eclass
, uint32 ecode
, NTSTATUS nterr
)
475 if (NT_STATUS_IS_DOS(status
)) {
479 /* Check DOS error */
480 cclass
= NT_STATUS_DOS_CLASS(status
);
481 num
= NT_STATUS_DOS_CODE(status
);
483 if (eclass
!= cclass
|| ecode
!= num
) {
484 printf("unexpected error code class=%d code=%d\n",
485 (int)cclass
, (int)num
);
486 printf(" expected %d/%d %s (line=%d)\n",
487 (int)eclass
, (int)ecode
, nt_errstr(nterr
), line
);
492 if (!NT_STATUS_EQUAL(nterr
, status
)) {
493 printf("unexpected error code %s\n",
495 printf(" expected %s (line=%d)\n",
496 nt_errstr(nterr
), line
);
505 /* check if the server produced the expected error code */
506 static bool check_error(int line
, struct cli_state
*c
,
507 uint8 eclass
, uint32 ecode
, NTSTATUS nterr
)
509 if (cli_is_dos_error(c
)) {
513 /* Check DOS error */
515 cli_dos_error(c
, &cclass
, &num
);
517 if (eclass
!= cclass
|| ecode
!= num
) {
518 printf("unexpected error code class=%d code=%d\n",
519 (int)cclass
, (int)num
);
520 printf(" expected %d/%d %s (line=%d)\n",
521 (int)eclass
, (int)ecode
, nt_errstr(nterr
), line
);
530 status
= cli_nt_error(c
);
532 if (NT_STATUS_V(nterr
) != NT_STATUS_V(status
)) {
533 printf("unexpected error code %s\n", nt_errstr(status
));
534 printf(" expected %s (line=%d)\n", nt_errstr(nterr
), line
);
543 static bool wait_lock(struct cli_state
*c
, int fnum
, uint32 offset
, uint32 len
)
545 while (!cli_lock(c
, fnum
, offset
, len
, -1, WRITE_LOCK
)) {
546 if (!check_error(__LINE__
, c
, ERRDOS
, ERRlock
, NT_STATUS_LOCK_NOT_GRANTED
)) return False
;
552 static bool rw_torture(struct cli_state
*c
)
554 const char *lockfname
= "\\torture.lck";
558 pid_t pid2
, pid
= getpid();
564 memset(buf
, '\0', sizeof(buf
));
566 status
= cli_open(c
, lockfname
, O_RDWR
| O_CREAT
| O_EXCL
,
568 if (!NT_STATUS_IS_OK(status
)) {
569 status
= cli_open(c
, lockfname
, O_RDWR
, DENY_NONE
, &fnum2
);
571 if (!NT_STATUS_IS_OK(status
)) {
572 printf("open of %s failed (%s)\n",
573 lockfname
, nt_errstr(status
));
577 for (i
=0;i
<torture_numops
;i
++) {
578 unsigned n
= (unsigned)sys_random()%10;
581 printf("%d\r", i
); fflush(stdout
);
583 slprintf(fname
, sizeof(fstring
) - 1, "\\torture.%u", n
);
585 if (!wait_lock(c
, fnum2
, n
*sizeof(int), sizeof(int))) {
589 status
= cli_open(c
, fname
, O_RDWR
| O_CREAT
| O_TRUNC
,
591 if (!NT_STATUS_IS_OK(status
)) {
592 printf("open failed (%s)\n", nt_errstr(status
));
597 status
= cli_writeall(c
, fnum
, 0, (uint8_t *)&pid
, 0,
599 if (!NT_STATUS_IS_OK(status
)) {
600 printf("write failed (%s)\n", nt_errstr(status
));
605 status
= cli_writeall(c
, fnum
, 0, (uint8_t *)buf
,
606 sizeof(pid
)+(j
*sizeof(buf
)),
608 if (!NT_STATUS_IS_OK(status
)) {
609 printf("write failed (%s)\n",
617 if (cli_read(c
, fnum
, (char *)&pid2
, 0, sizeof(pid
)) != sizeof(pid
)) {
618 printf("read failed (%s)\n", cli_errstr(c
));
623 printf("data corruption!\n");
627 status
= cli_close(c
, fnum
);
628 if (!NT_STATUS_IS_OK(status
)) {
629 printf("close failed (%s)\n", nt_errstr(status
));
633 status
= cli_unlink(c
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
634 if (!NT_STATUS_IS_OK(status
)) {
635 printf("unlink failed (%s)\n", nt_errstr(status
));
639 status
= cli_unlock(c
, fnum2
, n
*sizeof(int), sizeof(int));
640 if (!NT_STATUS_IS_OK(status
)) {
641 printf("unlock failed (%s)\n", nt_errstr(status
));
647 cli_unlink(c
, lockfname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
654 static bool run_torture(int dummy
)
656 struct cli_state
*cli
;
661 cli_sockopt(cli
, sockops
);
663 ret
= rw_torture(cli
);
665 if (!torture_close_connection(cli
)) {
672 static bool rw_torture3(struct cli_state
*c
, char *lockfname
)
674 uint16_t fnum
= (uint16_t)-1;
679 unsigned countprev
= 0;
682 NTSTATUS status
= NT_STATUS_OK
;
685 for (i
= 0; i
< sizeof(buf
); i
+= sizeof(uint32
))
687 SIVAL(buf
, i
, sys_random());
694 FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
695 if (!NT_STATUS_IS_OK(status
)) {
696 printf("unlink failed (%s) (normal, this file should "
697 "not exist)\n", nt_errstr(status
));
700 status
= cli_open(c
, lockfname
, O_RDWR
| O_CREAT
| O_EXCL
,
702 if (!NT_STATUS_IS_OK(status
)) {
703 printf("first open read/write of %s failed (%s)\n",
704 lockfname
, nt_errstr(status
));
710 for (i
= 0; i
< 500 && fnum
== (uint16_t)-1; i
++)
712 status
= cli_open(c
, lockfname
, O_RDONLY
,
714 if (!NT_STATUS_IS_OK(status
)) {
719 if (!NT_STATUS_IS_OK(status
)) {
720 printf("second open read-only of %s failed (%s)\n",
721 lockfname
, nt_errstr(status
));
727 for (count
= 0; count
< sizeof(buf
); count
+= sent
)
729 if (count
>= countprev
) {
730 printf("%d %8d\r", i
, count
);
733 countprev
+= (sizeof(buf
) / 20);
738 sent
= ((unsigned)sys_random()%(20))+ 1;
739 if (sent
> sizeof(buf
) - count
)
741 sent
= sizeof(buf
) - count
;
744 status
= cli_writeall(c
, fnum
, 0, (uint8_t *)buf
+count
,
745 count
, (size_t)sent
, NULL
);
746 if (!NT_STATUS_IS_OK(status
)) {
747 printf("write failed (%s)\n",
754 sent
= cli_read(c
, fnum
, buf_rd
+count
, count
,
758 printf("read failed offset:%d size:%ld (%s)\n",
759 count
, (unsigned long)sizeof(buf
)-count
,
766 if (memcmp(buf_rd
+count
, buf
+count
, sent
) != 0)
768 printf("read/write compare failed\n");
769 printf("offset: %d req %ld recvd %ld\n", count
, (unsigned long)sizeof(buf
)-count
, (unsigned long)sent
);
778 status
= cli_close(c
, fnum
);
779 if (!NT_STATUS_IS_OK(status
)) {
780 printf("close failed (%s)\n", nt_errstr(status
));
787 static bool rw_torture2(struct cli_state
*c1
, struct cli_state
*c2
)
789 const char *lockfname
= "\\torture2.lck";
799 status
= cli_unlink(c1
, lockfname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
800 if (!NT_STATUS_IS_OK(status
)) {
801 printf("unlink failed (%s) (normal, this file should not exist)\n", nt_errstr(status
));
804 status
= cli_open(c1
, lockfname
, O_RDWR
| O_CREAT
| O_EXCL
,
806 if (!NT_STATUS_IS_OK(status
)) {
807 printf("first open read/write of %s failed (%s)\n",
808 lockfname
, nt_errstr(status
));
812 status
= cli_open(c2
, lockfname
, O_RDONLY
, DENY_NONE
, &fnum2
);
813 if (!NT_STATUS_IS_OK(status
)) {
814 printf("second open read-only of %s failed (%s)\n",
815 lockfname
, nt_errstr(status
));
816 cli_close(c1
, fnum1
);
820 for (i
= 0; i
< torture_numops
; i
++)
822 size_t buf_size
= ((unsigned)sys_random()%(sizeof(buf
)-1))+ 1;
824 printf("%d\r", i
); fflush(stdout
);
827 generate_random_buffer((unsigned char *)buf
, buf_size
);
829 status
= cli_writeall(c1
, fnum1
, 0, (uint8_t *)buf
, 0,
831 if (!NT_STATUS_IS_OK(status
)) {
832 printf("write failed (%s)\n", nt_errstr(status
));
837 if ((bytes_read
= cli_read(c2
, fnum2
, buf_rd
, 0, buf_size
)) != buf_size
) {
838 printf("read failed (%s)\n", cli_errstr(c2
));
839 printf("read %d, expected %ld\n", (int)bytes_read
,
840 (unsigned long)buf_size
);
845 if (memcmp(buf_rd
, buf
, buf_size
) != 0)
847 printf("read/write compare failed\n");
853 status
= cli_close(c2
, fnum2
);
854 if (!NT_STATUS_IS_OK(status
)) {
855 printf("close failed (%s)\n", nt_errstr(status
));
859 status
= cli_close(c1
, fnum1
);
860 if (!NT_STATUS_IS_OK(status
)) {
861 printf("close failed (%s)\n", nt_errstr(status
));
865 status
= cli_unlink(c1
, lockfname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
866 if (!NT_STATUS_IS_OK(status
)) {
867 printf("unlink failed (%s)\n", nt_errstr(status
));
874 static bool run_readwritetest(int dummy
)
876 struct cli_state
*cli1
, *cli2
;
877 bool test1
, test2
= False
;
879 if (!torture_open_connection(&cli1
, 0) || !torture_open_connection(&cli2
, 1)) {
882 cli_sockopt(cli1
, sockops
);
883 cli_sockopt(cli2
, sockops
);
885 printf("starting readwritetest\n");
887 test1
= rw_torture2(cli1
, cli2
);
888 printf("Passed readwritetest v1: %s\n", BOOLSTR(test1
));
891 test2
= rw_torture2(cli1
, cli1
);
892 printf("Passed readwritetest v2: %s\n", BOOLSTR(test2
));
895 if (!torture_close_connection(cli1
)) {
899 if (!torture_close_connection(cli2
)) {
903 return (test1
&& test2
);
906 static bool run_readwritemulti(int dummy
)
908 struct cli_state
*cli
;
913 cli_sockopt(cli
, sockops
);
915 printf("run_readwritemulti: fname %s\n", randomfname
);
916 test
= rw_torture3(cli
, randomfname
);
918 if (!torture_close_connection(cli
)) {
925 static bool run_readwritelarge_internal(int max_xmit_k
)
927 static struct cli_state
*cli1
;
929 const char *lockfname
= "\\large.dat";
935 if (!torture_open_connection(&cli1
, 0)) {
938 cli_sockopt(cli1
, sockops
);
939 memset(buf
,'\0',sizeof(buf
));
941 cli1
->max_xmit
= max_xmit_k
*1024;
943 if (signing_state
== Required
) {
944 /* Horrible cheat to force
945 multiple signed outstanding
946 packets against a Samba server.
948 cli1
->is_samba
= false;
951 printf("starting readwritelarge_internal\n");
953 cli_unlink(cli1
, lockfname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
955 status
= cli_open(cli1
, lockfname
, O_RDWR
| O_CREAT
| O_EXCL
,
957 if (!NT_STATUS_IS_OK(status
)) {
958 printf("open read/write of %s failed (%s)\n", lockfname
, nt_errstr(status
));
962 cli_writeall(cli1
, fnum1
, 0, (uint8_t *)buf
, 0, sizeof(buf
), NULL
);
964 status
= cli_qfileinfo_basic(cli1
, fnum1
, NULL
, &fsize
, NULL
, NULL
,
966 if (!NT_STATUS_IS_OK(status
)) {
967 printf("qfileinfo failed (%s)\n", nt_errstr(status
));
971 if (fsize
== sizeof(buf
))
972 printf("readwritelarge_internal test 1 succeeded (size = %lx)\n",
973 (unsigned long)fsize
);
975 printf("readwritelarge_internal test 1 failed (size = %lx)\n",
976 (unsigned long)fsize
);
980 status
= cli_close(cli1
, fnum1
);
981 if (!NT_STATUS_IS_OK(status
)) {
982 printf("close failed (%s)\n", nt_errstr(status
));
986 status
= cli_unlink(cli1
, lockfname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
987 if (!NT_STATUS_IS_OK(status
)) {
988 printf("unlink failed (%s)\n", nt_errstr(status
));
992 status
= cli_open(cli1
, lockfname
, O_RDWR
| O_CREAT
| O_EXCL
,
994 if (!NT_STATUS_IS_OK(status
)) {
995 printf("open read/write of %s failed (%s)\n", lockfname
, nt_errstr(status
));
999 cli1
->max_xmit
= 4*1024;
1001 cli_smbwrite(cli1
, fnum1
, buf
, 0, sizeof(buf
), NULL
);
1003 status
= cli_qfileinfo_basic(cli1
, fnum1
, NULL
, &fsize
, NULL
, NULL
,
1005 if (!NT_STATUS_IS_OK(status
)) {
1006 printf("qfileinfo failed (%s)\n", nt_errstr(status
));
1010 if (fsize
== sizeof(buf
))
1011 printf("readwritelarge_internal test 2 succeeded (size = %lx)\n",
1012 (unsigned long)fsize
);
1014 printf("readwritelarge_internal test 2 failed (size = %lx)\n",
1015 (unsigned long)fsize
);
1020 /* ToDo - set allocation. JRA */
1021 if(!cli_set_allocation_size(cli1
, fnum1
, 0)) {
1022 printf("set allocation size to zero failed (%s)\n", cli_errstr(&cli1
));
1025 if (!cli_qfileinfo_basic(cli1
, fnum1
, NULL
, &fsize
, NULL
, NULL
, NULL
,
1027 printf("qfileinfo failed (%s)\n", cli_errstr(cli1
));
1031 printf("readwritelarge test 3 (truncate test) succeeded (size = %x)\n", fsize
);
1034 status
= cli_close(cli1
, fnum1
);
1035 if (!NT_STATUS_IS_OK(status
)) {
1036 printf("close failed (%s)\n", nt_errstr(status
));
1040 if (!torture_close_connection(cli1
)) {
1046 static bool run_readwritelarge(int dummy
)
1048 return run_readwritelarge_internal(128);
1051 static bool run_readwritelarge_signtest(int dummy
)
1054 signing_state
= Required
;
1055 ret
= run_readwritelarge_internal(2);
1056 signing_state
= Undefined
;
1063 #define ival(s) strtol(s, NULL, 0)
1065 /* run a test that simulates an approximate netbench client load */
1066 static bool run_netbench(int client
)
1068 struct cli_state
*cli
;
1073 const char *params
[20];
1074 bool correct
= True
;
1080 cli_sockopt(cli
, sockops
);
1084 slprintf(cname
,sizeof(cname
)-1, "client%d", client
);
1086 f
= fopen(client_txt
, "r");
1093 while (fgets(line
, sizeof(line
)-1, f
)) {
1097 line
[strlen(line
)-1] = 0;
1099 /* printf("[%d] %s\n", line_count, line); */
1101 all_string_sub(line
,"client1", cname
, sizeof(line
));
1103 /* parse the command parameters */
1104 params
[0] = strtok_r(line
, " ", &saveptr
);
1106 while (params
[i
]) params
[++i
] = strtok_r(NULL
, " ", &saveptr
);
1110 if (i
< 2) continue;
1112 if (!strncmp(params
[0],"SMB", 3)) {
1113 printf("ERROR: You are using a dbench 1 load file\n");
1117 if (!strcmp(params
[0],"NTCreateX")) {
1118 nb_createx(params
[1], ival(params
[2]), ival(params
[3]),
1120 } else if (!strcmp(params
[0],"Close")) {
1121 nb_close(ival(params
[1]));
1122 } else if (!strcmp(params
[0],"Rename")) {
1123 nb_rename(params
[1], params
[2]);
1124 } else if (!strcmp(params
[0],"Unlink")) {
1125 nb_unlink(params
[1]);
1126 } else if (!strcmp(params
[0],"Deltree")) {
1127 nb_deltree(params
[1]);
1128 } else if (!strcmp(params
[0],"Rmdir")) {
1129 nb_rmdir(params
[1]);
1130 } else if (!strcmp(params
[0],"QUERY_PATH_INFORMATION")) {
1131 nb_qpathinfo(params
[1]);
1132 } else if (!strcmp(params
[0],"QUERY_FILE_INFORMATION")) {
1133 nb_qfileinfo(ival(params
[1]));
1134 } else if (!strcmp(params
[0],"QUERY_FS_INFORMATION")) {
1135 nb_qfsinfo(ival(params
[1]));
1136 } else if (!strcmp(params
[0],"FIND_FIRST")) {
1137 nb_findfirst(params
[1]);
1138 } else if (!strcmp(params
[0],"WriteX")) {
1139 nb_writex(ival(params
[1]),
1140 ival(params
[2]), ival(params
[3]), ival(params
[4]));
1141 } else if (!strcmp(params
[0],"ReadX")) {
1142 nb_readx(ival(params
[1]),
1143 ival(params
[2]), ival(params
[3]), ival(params
[4]));
1144 } else if (!strcmp(params
[0],"Flush")) {
1145 nb_flush(ival(params
[1]));
1147 printf("Unknown operation %s\n", params
[0]);
1155 if (!torture_close_connection(cli
)) {
1163 /* run a test that simulates an approximate netbench client load */
1164 static bool run_nbench(int dummy
)
1167 bool correct
= True
;
1173 signal(SIGALRM
, nb_alarm
);
1175 t
= create_procs(run_netbench
, &correct
);
1178 printf("\nThroughput %g MB/sec\n",
1179 1.0e-6 * nbio_total() / t
);
1185 This test checks for two things:
1187 1) correct support for retaining locks over a close (ie. the server
1188 must not use posix semantics)
1189 2) support for lock timeouts
1191 static bool run_locktest1(int dummy
)
1193 struct cli_state
*cli1
, *cli2
;
1194 const char *fname
= "\\lockt1.lck";
1195 uint16_t fnum1
, fnum2
, fnum3
;
1197 unsigned lock_timeout
;
1200 if (!torture_open_connection(&cli1
, 0) || !torture_open_connection(&cli2
, 1)) {
1203 cli_sockopt(cli1
, sockops
);
1204 cli_sockopt(cli2
, sockops
);
1206 printf("starting locktest1\n");
1208 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
1210 status
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
,
1212 if (!NT_STATUS_IS_OK(status
)) {
1213 printf("open of %s failed (%s)\n", fname
, nt_errstr(status
));
1217 status
= cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
, &fnum2
);
1218 if (!NT_STATUS_IS_OK(status
)) {
1219 printf("open2 of %s failed (%s)\n", fname
, nt_errstr(status
));
1223 status
= cli_open(cli2
, fname
, O_RDWR
, DENY_NONE
, &fnum3
);
1224 if (!NT_STATUS_IS_OK(status
)) {
1225 printf("open3 of %s failed (%s)\n", fname
, nt_errstr(status
));
1229 if (!cli_lock(cli1
, fnum1
, 0, 4, 0, WRITE_LOCK
)) {
1230 printf("lock1 failed (%s)\n", cli_errstr(cli1
));
1235 if (cli_lock(cli2
, fnum3
, 0, 4, 0, WRITE_LOCK
)) {
1236 printf("lock2 succeeded! This is a locking bug\n");
1239 if (!check_error(__LINE__
, cli2
, ERRDOS
, ERRlock
,
1240 NT_STATUS_LOCK_NOT_GRANTED
)) return False
;
1244 lock_timeout
= (1 + (random() % 20));
1245 printf("Testing lock timeout with timeout=%u\n", lock_timeout
);
1247 if (cli_lock(cli2
, fnum3
, 0, 4, lock_timeout
* 1000, WRITE_LOCK
)) {
1248 printf("lock3 succeeded! This is a locking bug\n");
1251 if (!check_error(__LINE__
, cli2
, ERRDOS
, ERRlock
,
1252 NT_STATUS_FILE_LOCK_CONFLICT
)) return False
;
1256 if (ABS(t2
- t1
) < lock_timeout
-1) {
1257 printf("error: This server appears not to support timed lock requests\n");
1260 printf("server slept for %u seconds for a %u second timeout\n",
1261 (unsigned int)(t2
-t1
), lock_timeout
);
1263 status
= cli_close(cli1
, fnum2
);
1264 if (!NT_STATUS_IS_OK(status
)) {
1265 printf("close1 failed (%s)\n", nt_errstr(status
));
1269 if (cli_lock(cli2
, fnum3
, 0, 4, 0, WRITE_LOCK
)) {
1270 printf("lock4 succeeded! This is a locking bug\n");
1273 if (!check_error(__LINE__
, cli2
, ERRDOS
, ERRlock
,
1274 NT_STATUS_FILE_LOCK_CONFLICT
)) return False
;
1277 status
= cli_close(cli1
, fnum1
);
1278 if (!NT_STATUS_IS_OK(status
)) {
1279 printf("close2 failed (%s)\n", nt_errstr(status
));
1283 status
= cli_close(cli2
, fnum3
);
1284 if (!NT_STATUS_IS_OK(status
)) {
1285 printf("close3 failed (%s)\n", nt_errstr(status
));
1289 status
= cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
1290 if (!NT_STATUS_IS_OK(status
)) {
1291 printf("unlink failed (%s)\n", nt_errstr(status
));
1296 if (!torture_close_connection(cli1
)) {
1300 if (!torture_close_connection(cli2
)) {
1304 printf("Passed locktest1\n");
1309 this checks to see if a secondary tconx can use open files from an
1312 static bool run_tcon_test(int dummy
)
1314 static struct cli_state
*cli
;
1315 const char *fname
= "\\tcontest.tmp";
1317 uint16 cnum1
, cnum2
, cnum3
;
1318 uint16 vuid1
, vuid2
;
1323 memset(buf
, '\0', sizeof(buf
));
1325 if (!torture_open_connection(&cli
, 0)) {
1328 cli_sockopt(cli
, sockops
);
1330 printf("starting tcontest\n");
1332 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
1334 status
= cli_open(cli
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
);
1335 if (!NT_STATUS_IS_OK(status
)) {
1336 printf("open of %s failed (%s)\n", fname
, nt_errstr(status
));
1343 status
= cli_writeall(cli
, fnum1
, 0, (uint8_t *)buf
, 130, 4, NULL
);
1344 if (!NT_STATUS_IS_OK(status
)) {
1345 printf("initial write failed (%s)", nt_errstr(status
));
1349 status
= cli_tcon_andx(cli
, share
, "?????",
1350 password
, strlen(password
)+1);
1351 if (!NT_STATUS_IS_OK(status
)) {
1352 printf("%s refused 2nd tree connect (%s)\n", host
,
1359 cnum3
= MAX(cnum1
, cnum2
) + 1; /* any invalid number */
1360 vuid2
= cli
->vuid
+ 1;
1362 /* try a write with the wrong tid */
1365 status
= cli_writeall(cli
, fnum1
, 0, (uint8_t *)buf
, 130, 4, NULL
);
1366 if (NT_STATUS_IS_OK(status
)) {
1367 printf("* server allows write with wrong TID\n");
1370 printf("server fails write with wrong TID : %s\n",
1375 /* try a write with an invalid tid */
1378 status
= cli_writeall(cli
, fnum1
, 0, (uint8_t *)buf
, 130, 4, NULL
);
1379 if (NT_STATUS_IS_OK(status
)) {
1380 printf("* server allows write with invalid TID\n");
1383 printf("server fails write with invalid TID : %s\n",
1387 /* try a write with an invalid vuid */
1391 status
= cli_writeall(cli
, fnum1
, 0, (uint8_t *)buf
, 130, 4, NULL
);
1392 if (NT_STATUS_IS_OK(status
)) {
1393 printf("* server allows write with invalid VUID\n");
1396 printf("server fails write with invalid VUID : %s\n",
1403 status
= cli_close(cli
, fnum1
);
1404 if (!NT_STATUS_IS_OK(status
)) {
1405 printf("close failed (%s)\n", nt_errstr(status
));
1411 status
= cli_tdis(cli
);
1412 if (!NT_STATUS_IS_OK(status
)) {
1413 printf("secondary tdis failed (%s)\n", nt_errstr(status
));
1419 if (!torture_close_connection(cli
)) {
1428 checks for old style tcon support
1430 static bool run_tcon2_test(int dummy
)
1432 static struct cli_state
*cli
;
1433 uint16 cnum
, max_xmit
;
1437 if (!torture_open_connection(&cli
, 0)) {
1440 cli_sockopt(cli
, sockops
);
1442 printf("starting tcon2 test\n");
1444 if (asprintf(&service
, "\\\\%s\\%s", host
, share
) == -1) {
1448 status
= cli_raw_tcon(cli
, service
, password
, "?????", &max_xmit
, &cnum
);
1452 if (!NT_STATUS_IS_OK(status
)) {
1453 printf("tcon2 failed : %s\n", nt_errstr(status
));
1455 printf("tcon OK : max_xmit=%d cnum=%d\n",
1456 (int)max_xmit
, (int)cnum
);
1459 if (!torture_close_connection(cli
)) {
1463 printf("Passed tcon2 test\n");
1467 static bool tcon_devtest(struct cli_state
*cli
,
1468 const char *myshare
, const char *devtype
,
1469 const char *return_devtype
,
1470 NTSTATUS expected_error
)
1475 status
= cli_tcon_andx(cli
, myshare
, devtype
,
1476 password
, strlen(password
)+1);
1478 if (NT_STATUS_IS_OK(expected_error
)) {
1479 if (NT_STATUS_IS_OK(status
)) {
1480 if (strcmp(cli
->dev
, return_devtype
) == 0) {
1483 printf("tconX to share %s with type %s "
1484 "succeeded but returned the wrong "
1485 "device type (got [%s] but should have got [%s])\n",
1486 myshare
, devtype
, cli
->dev
, return_devtype
);
1490 printf("tconX to share %s with type %s "
1491 "should have succeeded but failed\n",
1497 if (NT_STATUS_IS_OK(status
)) {
1498 printf("tconx to share %s with type %s "
1499 "should have failed but succeeded\n",
1503 if (NT_STATUS_EQUAL(cli_nt_error(cli
),
1507 printf("Returned unexpected error\n");
1516 checks for correct tconX support
1518 static bool run_tcon_devtype_test(int dummy
)
1520 static struct cli_state
*cli1
= NULL
;
1525 status
= cli_full_connection(&cli1
, myname
,
1526 host
, NULL
, port_to_use
,
1528 username
, workgroup
,
1529 password
, flags
, signing_state
);
1531 if (!NT_STATUS_IS_OK(status
)) {
1532 printf("could not open connection\n");
1536 if (!tcon_devtest(cli1
, "IPC$", "A:", NULL
, NT_STATUS_BAD_DEVICE_TYPE
))
1539 if (!tcon_devtest(cli1
, "IPC$", "?????", "IPC", NT_STATUS_OK
))
1542 if (!tcon_devtest(cli1
, "IPC$", "LPT:", NULL
, NT_STATUS_BAD_DEVICE_TYPE
))
1545 if (!tcon_devtest(cli1
, "IPC$", "IPC", "IPC", NT_STATUS_OK
))
1548 if (!tcon_devtest(cli1
, "IPC$", "FOOBA", NULL
, NT_STATUS_BAD_DEVICE_TYPE
))
1551 if (!tcon_devtest(cli1
, share
, "A:", "A:", NT_STATUS_OK
))
1554 if (!tcon_devtest(cli1
, share
, "?????", "A:", NT_STATUS_OK
))
1557 if (!tcon_devtest(cli1
, share
, "LPT:", NULL
, NT_STATUS_BAD_DEVICE_TYPE
))
1560 if (!tcon_devtest(cli1
, share
, "IPC", NULL
, NT_STATUS_BAD_DEVICE_TYPE
))
1563 if (!tcon_devtest(cli1
, share
, "FOOBA", NULL
, NT_STATUS_BAD_DEVICE_TYPE
))
1569 printf("Passed tcondevtest\n");
1576 This test checks that
1578 1) the server supports multiple locking contexts on the one SMB
1579 connection, distinguished by PID.
1581 2) the server correctly fails overlapping locks made by the same PID (this
1582 goes against POSIX behaviour, which is why it is tricky to implement)
1584 3) the server denies unlock requests by an incorrect client PID
1586 static bool run_locktest2(int dummy
)
1588 static struct cli_state
*cli
;
1589 const char *fname
= "\\lockt2.lck";
1590 uint16_t fnum1
, fnum2
, fnum3
;
1591 bool correct
= True
;
1594 if (!torture_open_connection(&cli
, 0)) {
1598 cli_sockopt(cli
, sockops
);
1600 printf("starting locktest2\n");
1602 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
1606 status
= cli_open(cli
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
);
1607 if (!NT_STATUS_IS_OK(status
)) {
1608 printf("open of %s failed (%s)\n", fname
, nt_errstr(status
));
1612 status
= cli_open(cli
, fname
, O_RDWR
, DENY_NONE
, &fnum2
);
1613 if (!NT_STATUS_IS_OK(status
)) {
1614 printf("open2 of %s failed (%s)\n", fname
, nt_errstr(status
));
1620 status
= cli_open(cli
, fname
, O_RDWR
, DENY_NONE
, &fnum3
);
1621 if (!NT_STATUS_IS_OK(status
)) {
1622 printf("open3 of %s failed (%s)\n", fname
, nt_errstr(status
));
1628 if (!cli_lock(cli
, fnum1
, 0, 4, 0, WRITE_LOCK
)) {
1629 printf("lock1 failed (%s)\n", cli_errstr(cli
));
1633 if (cli_lock(cli
, fnum1
, 0, 4, 0, WRITE_LOCK
)) {
1634 printf("WRITE lock1 succeeded! This is a locking bug\n");
1637 if (!check_error(__LINE__
, cli
, ERRDOS
, ERRlock
,
1638 NT_STATUS_LOCK_NOT_GRANTED
)) return False
;
1641 if (cli_lock(cli
, fnum2
, 0, 4, 0, WRITE_LOCK
)) {
1642 printf("WRITE lock2 succeeded! This is a locking bug\n");
1645 if (!check_error(__LINE__
, cli
, ERRDOS
, ERRlock
,
1646 NT_STATUS_LOCK_NOT_GRANTED
)) return False
;
1649 if (cli_lock(cli
, fnum2
, 0, 4, 0, READ_LOCK
)) {
1650 printf("READ lock2 succeeded! This is a locking bug\n");
1653 if (!check_error(__LINE__
, cli
, ERRDOS
, ERRlock
,
1654 NT_STATUS_FILE_LOCK_CONFLICT
)) return False
;
1657 if (!cli_lock(cli
, fnum1
, 100, 4, 0, WRITE_LOCK
)) {
1658 printf("lock at 100 failed (%s)\n", cli_errstr(cli
));
1661 if (NT_STATUS_IS_OK(cli_unlock(cli
, fnum1
, 100, 4))) {
1662 printf("unlock at 100 succeeded! This is a locking bug\n");
1666 if (NT_STATUS_IS_OK(cli_unlock(cli
, fnum1
, 0, 4))) {
1667 printf("unlock1 succeeded! This is a locking bug\n");
1670 if (!check_error(__LINE__
, cli
,
1672 NT_STATUS_RANGE_NOT_LOCKED
)) return False
;
1675 if (NT_STATUS_IS_OK(cli_unlock(cli
, fnum1
, 0, 8))) {
1676 printf("unlock2 succeeded! This is a locking bug\n");
1679 if (!check_error(__LINE__
, cli
,
1681 NT_STATUS_RANGE_NOT_LOCKED
)) return False
;
1684 if (cli_lock(cli
, fnum3
, 0, 4, 0, WRITE_LOCK
)) {
1685 printf("lock3 succeeded! This is a locking bug\n");
1688 if (!check_error(__LINE__
, cli
, ERRDOS
, ERRlock
, NT_STATUS_LOCK_NOT_GRANTED
)) return False
;
1693 status
= cli_close(cli
, fnum1
);
1694 if (!NT_STATUS_IS_OK(status
)) {
1695 printf("close1 failed (%s)\n", nt_errstr(status
));
1699 status
= cli_close(cli
, fnum2
);
1700 if (!NT_STATUS_IS_OK(status
)) {
1701 printf("close2 failed (%s)\n", nt_errstr(status
));
1705 status
= cli_close(cli
, fnum3
);
1706 if (!NT_STATUS_IS_OK(status
)) {
1707 printf("close3 failed (%s)\n", nt_errstr(status
));
1711 if (!torture_close_connection(cli
)) {
1715 printf("locktest2 finished\n");
1722 This test checks that
1724 1) the server supports the full offset range in lock requests
1726 static bool run_locktest3(int dummy
)
1728 static struct cli_state
*cli1
, *cli2
;
1729 const char *fname
= "\\lockt3.lck";
1730 uint16_t fnum1
, fnum2
;
1733 bool correct
= True
;
1736 #define NEXT_OFFSET offset += (~(uint32)0) / torture_numops
1738 if (!torture_open_connection(&cli1
, 0) || !torture_open_connection(&cli2
, 1)) {
1741 cli_sockopt(cli1
, sockops
);
1742 cli_sockopt(cli2
, sockops
);
1744 printf("starting locktest3\n");
1746 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
1748 status
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
,
1750 if (!NT_STATUS_IS_OK(status
)) {
1751 printf("open of %s failed (%s)\n", fname
, nt_errstr(status
));
1755 status
= cli_open(cli2
, fname
, O_RDWR
, DENY_NONE
, &fnum2
);
1756 if (!NT_STATUS_IS_OK(status
)) {
1757 printf("open2 of %s failed (%s)\n", fname
, nt_errstr(status
));
1761 for (offset
=i
=0;i
<torture_numops
;i
++) {
1763 if (!cli_lock(cli1
, fnum1
, offset
-1, 1, 0, WRITE_LOCK
)) {
1764 printf("lock1 %d failed (%s)\n",
1770 if (!cli_lock(cli2
, fnum2
, offset
-2, 1, 0, WRITE_LOCK
)) {
1771 printf("lock2 %d failed (%s)\n",
1778 for (offset
=i
=0;i
<torture_numops
;i
++) {
1781 if (cli_lock(cli1
, fnum1
, offset
-2, 1, 0, WRITE_LOCK
)) {
1782 printf("error: lock1 %d succeeded!\n", i
);
1786 if (cli_lock(cli2
, fnum2
, offset
-1, 1, 0, WRITE_LOCK
)) {
1787 printf("error: lock2 %d succeeded!\n", i
);
1791 if (cli_lock(cli1
, fnum1
, offset
-1, 1, 0, WRITE_LOCK
)) {
1792 printf("error: lock3 %d succeeded!\n", i
);
1796 if (cli_lock(cli2
, fnum2
, offset
-2, 1, 0, WRITE_LOCK
)) {
1797 printf("error: lock4 %d succeeded!\n", i
);
1802 for (offset
=i
=0;i
<torture_numops
;i
++) {
1805 status
= cli_unlock(cli1
, fnum1
, offset
-1, 1);
1806 if (!NT_STATUS_IS_OK(status
)) {
1807 printf("unlock1 %d failed (%s)\n",
1813 status
= cli_unlock(cli2
, fnum2
, offset
-2, 1);
1814 if (!NT_STATUS_IS_OK(status
)) {
1815 printf("unlock2 %d failed (%s)\n",
1822 status
= cli_close(cli1
, fnum1
);
1823 if (!NT_STATUS_IS_OK(status
)) {
1824 printf("close1 failed (%s)\n", nt_errstr(status
));
1828 status
= cli_close(cli2
, fnum2
);
1829 if (!NT_STATUS_IS_OK(status
)) {
1830 printf("close2 failed (%s)\n", nt_errstr(status
));
1834 status
= cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
1835 if (!NT_STATUS_IS_OK(status
)) {
1836 printf("unlink failed (%s)\n", nt_errstr(status
));
1840 if (!torture_close_connection(cli1
)) {
1844 if (!torture_close_connection(cli2
)) {
1848 printf("finished locktest3\n");
1853 #define EXPECTED(ret, v) if ((ret) != (v)) { \
1854 printf("** "); correct = False; \
1858 looks at overlapping locks
1860 static bool run_locktest4(int dummy
)
1862 static struct cli_state
*cli1
, *cli2
;
1863 const char *fname
= "\\lockt4.lck";
1864 uint16_t fnum1
, fnum2
, f
;
1867 bool correct
= True
;
1870 if (!torture_open_connection(&cli1
, 0) || !torture_open_connection(&cli2
, 1)) {
1874 cli_sockopt(cli1
, sockops
);
1875 cli_sockopt(cli2
, sockops
);
1877 printf("starting locktest4\n");
1879 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
1881 cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
);
1882 cli_open(cli2
, fname
, O_RDWR
, DENY_NONE
, &fnum2
);
1884 memset(buf
, 0, sizeof(buf
));
1886 status
= cli_writeall(cli1
, fnum1
, 0, (uint8_t *)buf
, 0, sizeof(buf
),
1888 if (!NT_STATUS_IS_OK(status
)) {
1889 printf("Failed to create file: %s\n", nt_errstr(status
));
1894 ret
= cli_lock(cli1
, fnum1
, 0, 4, 0, WRITE_LOCK
) &&
1895 cli_lock(cli1
, fnum1
, 2, 4, 0, WRITE_LOCK
);
1896 EXPECTED(ret
, False
);
1897 printf("the same process %s set overlapping write locks\n", ret
?"can":"cannot");
1899 ret
= cli_lock(cli1
, fnum1
, 10, 4, 0, READ_LOCK
) &&
1900 cli_lock(cli1
, fnum1
, 12, 4, 0, READ_LOCK
);
1901 EXPECTED(ret
, True
);
1902 printf("the same process %s set overlapping read locks\n", ret
?"can":"cannot");
1904 ret
= cli_lock(cli1
, fnum1
, 20, 4, 0, WRITE_LOCK
) &&
1905 cli_lock(cli2
, fnum2
, 22, 4, 0, WRITE_LOCK
);
1906 EXPECTED(ret
, False
);
1907 printf("a different connection %s set overlapping write locks\n", ret
?"can":"cannot");
1909 ret
= cli_lock(cli1
, fnum1
, 30, 4, 0, READ_LOCK
) &&
1910 cli_lock(cli2
, fnum2
, 32, 4, 0, READ_LOCK
);
1911 EXPECTED(ret
, True
);
1912 printf("a different connection %s set overlapping read locks\n", ret
?"can":"cannot");
1914 ret
= (cli_setpid(cli1
, 1), cli_lock(cli1
, fnum1
, 40, 4, 0, WRITE_LOCK
)) &&
1915 (cli_setpid(cli1
, 2), cli_lock(cli1
, fnum1
, 42, 4, 0, WRITE_LOCK
));
1916 EXPECTED(ret
, False
);
1917 printf("a different pid %s set overlapping write locks\n", ret
?"can":"cannot");
1919 ret
= (cli_setpid(cli1
, 1), cli_lock(cli1
, fnum1
, 50, 4, 0, READ_LOCK
)) &&
1920 (cli_setpid(cli1
, 2), cli_lock(cli1
, fnum1
, 52, 4, 0, READ_LOCK
));
1921 EXPECTED(ret
, True
);
1922 printf("a different pid %s set overlapping read locks\n", ret
?"can":"cannot");
1924 ret
= cli_lock(cli1
, fnum1
, 60, 4, 0, READ_LOCK
) &&
1925 cli_lock(cli1
, fnum1
, 60, 4, 0, READ_LOCK
);
1926 EXPECTED(ret
, True
);
1927 printf("the same process %s set the same read lock twice\n", ret
?"can":"cannot");
1929 ret
= cli_lock(cli1
, fnum1
, 70, 4, 0, WRITE_LOCK
) &&
1930 cli_lock(cli1
, fnum1
, 70, 4, 0, WRITE_LOCK
);
1931 EXPECTED(ret
, False
);
1932 printf("the same process %s set the same write lock twice\n", ret
?"can":"cannot");
1934 ret
= cli_lock(cli1
, fnum1
, 80, 4, 0, READ_LOCK
) &&
1935 cli_lock(cli1
, fnum1
, 80, 4, 0, WRITE_LOCK
);
1936 EXPECTED(ret
, False
);
1937 printf("the same process %s overlay a read lock with a write lock\n", ret
?"can":"cannot");
1939 ret
= cli_lock(cli1
, fnum1
, 90, 4, 0, WRITE_LOCK
) &&
1940 cli_lock(cli1
, fnum1
, 90, 4, 0, READ_LOCK
);
1941 EXPECTED(ret
, True
);
1942 printf("the same process %s overlay a write lock with a read lock\n", ret
?"can":"cannot");
1944 ret
= (cli_setpid(cli1
, 1), cli_lock(cli1
, fnum1
, 100, 4, 0, WRITE_LOCK
)) &&
1945 (cli_setpid(cli1
, 2), cli_lock(cli1
, fnum1
, 100, 4, 0, READ_LOCK
));
1946 EXPECTED(ret
, False
);
1947 printf("a different pid %s overlay a write lock with a read lock\n", ret
?"can":"cannot");
1949 ret
= cli_lock(cli1
, fnum1
, 110, 4, 0, READ_LOCK
) &&
1950 cli_lock(cli1
, fnum1
, 112, 4, 0, READ_LOCK
) &&
1951 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 110, 6));
1952 EXPECTED(ret
, False
);
1953 printf("the same process %s coalesce read locks\n", ret
?"can":"cannot");
1956 ret
= cli_lock(cli1
, fnum1
, 120, 4, 0, WRITE_LOCK
) &&
1957 (cli_read(cli2
, fnum2
, buf
, 120, 4) == 4);
1958 EXPECTED(ret
, False
);
1959 printf("this server %s strict write locking\n", ret
?"doesn't do":"does");
1961 ret
= cli_lock(cli1
, fnum1
, 130, 4, 0, READ_LOCK
);
1963 status
= cli_writeall(cli2
, fnum2
, 0, (uint8_t *)buf
, 130, 4,
1965 ret
= NT_STATUS_IS_OK(status
);
1967 EXPECTED(ret
, False
);
1968 printf("this server %s strict read locking\n", ret
?"doesn't do":"does");
1971 ret
= cli_lock(cli1
, fnum1
, 140, 4, 0, READ_LOCK
) &&
1972 cli_lock(cli1
, fnum1
, 140, 4, 0, READ_LOCK
) &&
1973 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 140, 4)) &&
1974 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 140, 4));
1975 EXPECTED(ret
, True
);
1976 printf("this server %s do recursive read locking\n", ret
?"does":"doesn't");
1979 ret
= cli_lock(cli1
, fnum1
, 150, 4, 0, WRITE_LOCK
) &&
1980 cli_lock(cli1
, fnum1
, 150, 4, 0, READ_LOCK
) &&
1981 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 150, 4)) &&
1982 (cli_read(cli2
, fnum2
, buf
, 150, 4) == 4) &&
1983 !(NT_STATUS_IS_OK(cli_writeall(cli2
, fnum2
, 0, (uint8_t *)buf
,
1985 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 150, 4));
1986 EXPECTED(ret
, True
);
1987 printf("this server %s do recursive lock overlays\n", ret
?"does":"doesn't");
1989 ret
= cli_lock(cli1
, fnum1
, 160, 4, 0, READ_LOCK
) &&
1990 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 160, 4)) &&
1991 NT_STATUS_IS_OK(cli_writeall(cli2
, fnum2
, 0, (uint8_t *)buf
,
1993 (cli_read(cli2
, fnum2
, buf
, 160, 4) == 4);
1994 EXPECTED(ret
, True
);
1995 printf("the same process %s remove a read lock using write locking\n", ret
?"can":"cannot");
1997 ret
= cli_lock(cli1
, fnum1
, 170, 4, 0, WRITE_LOCK
) &&
1998 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 170, 4)) &&
1999 NT_STATUS_IS_OK(cli_writeall(cli2
, fnum2
, 0, (uint8_t *)buf
,
2001 (cli_read(cli2
, fnum2
, buf
, 170, 4) == 4);
2002 EXPECTED(ret
, True
);
2003 printf("the same process %s remove a write lock using read locking\n", ret
?"can":"cannot");
2005 ret
= cli_lock(cli1
, fnum1
, 190, 4, 0, WRITE_LOCK
) &&
2006 cli_lock(cli1
, fnum1
, 190, 4, 0, READ_LOCK
) &&
2007 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 190, 4)) &&
2008 !NT_STATUS_IS_OK(cli_writeall(cli2
, fnum2
, 0, (uint8_t *)buf
,
2010 (cli_read(cli2
, fnum2
, buf
, 190, 4) == 4);
2011 EXPECTED(ret
, True
);
2012 printf("the same process %s remove the first lock first\n", ret
?"does":"doesn't");
2014 cli_close(cli1
, fnum1
);
2015 cli_close(cli2
, fnum2
);
2016 cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
, &fnum1
);
2017 cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
, &f
);
2018 ret
= cli_lock(cli1
, fnum1
, 0, 8, 0, READ_LOCK
) &&
2019 cli_lock(cli1
, f
, 0, 1, 0, READ_LOCK
) &&
2020 NT_STATUS_IS_OK(cli_close(cli1
, fnum1
)) &&
2021 NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
, &fnum1
)) &&
2022 cli_lock(cli1
, fnum1
, 7, 1, 0, WRITE_LOCK
);
2024 cli_close(cli1
, fnum1
);
2025 EXPECTED(ret
, True
);
2026 printf("the server %s have the NT byte range lock bug\n", !ret
?"does":"doesn't");
2029 cli_close(cli1
, fnum1
);
2030 cli_close(cli2
, fnum2
);
2031 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2032 torture_close_connection(cli1
);
2033 torture_close_connection(cli2
);
2035 printf("finished locktest4\n");
2040 looks at lock upgrade/downgrade.
2042 static bool run_locktest5(int dummy
)
2044 static struct cli_state
*cli1
, *cli2
;
2045 const char *fname
= "\\lockt5.lck";
2046 uint16_t fnum1
, fnum2
, fnum3
;
2049 bool correct
= True
;
2052 if (!torture_open_connection(&cli1
, 0) || !torture_open_connection(&cli2
, 1)) {
2056 cli_sockopt(cli1
, sockops
);
2057 cli_sockopt(cli2
, sockops
);
2059 printf("starting locktest5\n");
2061 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2063 cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
);
2064 cli_open(cli2
, fname
, O_RDWR
, DENY_NONE
, &fnum2
);
2065 cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
, &fnum3
);
2067 memset(buf
, 0, sizeof(buf
));
2069 status
= cli_writeall(cli1
, fnum1
, 0, (uint8_t *)buf
, 0, sizeof(buf
),
2071 if (!NT_STATUS_IS_OK(status
)) {
2072 printf("Failed to create file: %s\n", nt_errstr(status
));
2077 /* Check for NT bug... */
2078 ret
= cli_lock(cli1
, fnum1
, 0, 8, 0, READ_LOCK
) &&
2079 cli_lock(cli1
, fnum3
, 0, 1, 0, READ_LOCK
);
2080 cli_close(cli1
, fnum1
);
2081 cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
, &fnum1
);
2082 ret
= cli_lock(cli1
, fnum1
, 7, 1, 0, WRITE_LOCK
);
2083 EXPECTED(ret
, True
);
2084 printf("this server %s the NT locking bug\n", ret
? "doesn't have" : "has");
2085 cli_close(cli1
, fnum1
);
2086 cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
, &fnum1
);
2087 cli_unlock(cli1
, fnum3
, 0, 1);
2089 ret
= cli_lock(cli1
, fnum1
, 0, 4, 0, WRITE_LOCK
) &&
2090 cli_lock(cli1
, fnum1
, 1, 1, 0, READ_LOCK
);
2091 EXPECTED(ret
, True
);
2092 printf("the same process %s overlay a write with a read lock\n", ret
?"can":"cannot");
2094 ret
= cli_lock(cli2
, fnum2
, 0, 4, 0, READ_LOCK
);
2095 EXPECTED(ret
, False
);
2097 printf("a different processs %s get a read lock on the first process lock stack\n", ret
?"can":"cannot");
2099 /* Unlock the process 2 lock. */
2100 cli_unlock(cli2
, fnum2
, 0, 4);
2102 ret
= cli_lock(cli1
, fnum3
, 0, 4, 0, READ_LOCK
);
2103 EXPECTED(ret
, False
);
2105 printf("the same processs on a different fnum %s get a read lock\n", ret
?"can":"cannot");
2107 /* Unlock the process 1 fnum3 lock. */
2108 cli_unlock(cli1
, fnum3
, 0, 4);
2110 /* Stack 2 more locks here. */
2111 ret
= cli_lock(cli1
, fnum1
, 0, 4, 0, READ_LOCK
) &&
2112 cli_lock(cli1
, fnum1
, 0, 4, 0, READ_LOCK
);
2114 EXPECTED(ret
, True
);
2115 printf("the same process %s stack read locks\n", ret
?"can":"cannot");
2117 /* Unlock the first process lock, then check this was the WRITE lock that was
2120 ret
= NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 0, 4)) &&
2121 cli_lock(cli2
, fnum2
, 0, 4, 0, READ_LOCK
);
2123 EXPECTED(ret
, True
);
2124 printf("the first unlock removes the %s lock\n", ret
?"WRITE":"READ");
2126 /* Unlock the process 2 lock. */
2127 cli_unlock(cli2
, fnum2
, 0, 4);
2129 /* We should have 3 stacked locks here. Ensure we need to do 3 unlocks. */
2131 ret
= NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 1, 1)) &&
2132 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 0, 4)) &&
2133 NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 0, 4));
2135 EXPECTED(ret
, True
);
2136 printf("the same process %s unlock the stack of 4 locks\n", ret
?"can":"cannot");
2138 /* Ensure the next unlock fails. */
2139 ret
= NT_STATUS_IS_OK(cli_unlock(cli1
, fnum1
, 0, 4));
2140 EXPECTED(ret
, False
);
2141 printf("the same process %s count the lock stack\n", !ret
?"can":"cannot");
2143 /* Ensure connection 2 can get a write lock. */
2144 ret
= cli_lock(cli2
, fnum2
, 0, 4, 0, WRITE_LOCK
);
2145 EXPECTED(ret
, True
);
2147 printf("a different processs %s get a write lock on the unlocked stack\n", ret
?"can":"cannot");
2151 cli_close(cli1
, fnum1
);
2152 cli_close(cli2
, fnum2
);
2153 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2154 if (!torture_close_connection(cli1
)) {
2157 if (!torture_close_connection(cli2
)) {
2161 printf("finished locktest5\n");
2167 tries the unusual lockingX locktype bits
2169 static bool run_locktest6(int dummy
)
2171 static struct cli_state
*cli
;
2172 const char *fname
[1] = { "\\lock6.txt" };
2177 if (!torture_open_connection(&cli
, 0)) {
2181 cli_sockopt(cli
, sockops
);
2183 printf("starting locktest6\n");
2186 printf("Testing %s\n", fname
[i
]);
2188 cli_unlink(cli
, fname
[i
], FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2190 cli_open(cli
, fname
[i
], O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum
);
2191 status
= cli_locktype(cli
, fnum
, 0, 8, 0, LOCKING_ANDX_CHANGE_LOCKTYPE
);
2192 cli_close(cli
, fnum
);
2193 printf("CHANGE_LOCKTYPE gave %s\n", nt_errstr(status
));
2195 cli_open(cli
, fname
[i
], O_RDWR
, DENY_NONE
, &fnum
);
2196 status
= cli_locktype(cli
, fnum
, 0, 8, 0, LOCKING_ANDX_CANCEL_LOCK
);
2197 cli_close(cli
, fnum
);
2198 printf("CANCEL_LOCK gave %s\n", nt_errstr(status
));
2200 cli_unlink(cli
, fname
[i
], FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2203 torture_close_connection(cli
);
2205 printf("finished locktest6\n");
2209 static bool run_locktest7(int dummy
)
2211 struct cli_state
*cli1
;
2212 const char *fname
= "\\lockt7.lck";
2215 bool correct
= False
;
2218 if (!torture_open_connection(&cli1
, 0)) {
2222 cli_sockopt(cli1
, sockops
);
2224 printf("starting locktest7\n");
2226 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2228 cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
);
2230 memset(buf
, 0, sizeof(buf
));
2232 status
= cli_writeall(cli1
, fnum1
, 0, (uint8_t *)buf
, 0, sizeof(buf
),
2234 if (!NT_STATUS_IS_OK(status
)) {
2235 printf("Failed to create file: %s\n", nt_errstr(status
));
2239 cli_setpid(cli1
, 1);
2241 if (!cli_lock(cli1
, fnum1
, 130, 4, 0, READ_LOCK
)) {
2242 printf("Unable to apply read lock on range 130:4, error was %s\n", cli_errstr(cli1
));
2245 printf("pid1 successfully locked range 130:4 for READ\n");
2248 if (cli_read(cli1
, fnum1
, buf
, 130, 4) != 4) {
2249 printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(cli1
));
2252 printf("pid1 successfully read the range 130:4\n");
2255 status
= cli_writeall(cli1
, fnum1
, 0, (uint8_t *)buf
, 130, 4, NULL
);
2256 if (!NT_STATUS_IS_OK(status
)) {
2257 printf("pid1 unable to write to the range 130:4, error was "
2258 "%s\n", nt_errstr(status
));
2259 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_LOCK_CONFLICT
)) {
2260 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2264 printf("pid1 successfully wrote to the range 130:4 (should be denied)\n");
2268 cli_setpid(cli1
, 2);
2270 if (cli_read(cli1
, fnum1
, buf
, 130, 4) != 4) {
2271 printf("pid2 unable to read the range 130:4, error was %s\n", cli_errstr(cli1
));
2273 printf("pid2 successfully read the range 130:4\n");
2276 status
= cli_writeall(cli1
, fnum1
, 0, (uint8_t *)buf
, 130, 4, NULL
);
2277 if (!NT_STATUS_IS_OK(status
)) {
2278 printf("pid2 unable to write to the range 130:4, error was "
2279 "%s\n", nt_errstr(status
));
2280 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_LOCK_CONFLICT
)) {
2281 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2285 printf("pid2 successfully wrote to the range 130:4 (should be denied)\n");
2289 cli_setpid(cli1
, 1);
2290 cli_unlock(cli1
, fnum1
, 130, 4);
2292 if (!cli_lock(cli1
, fnum1
, 130, 4, 0, WRITE_LOCK
)) {
2293 printf("Unable to apply write lock on range 130:4, error was %s\n", cli_errstr(cli1
));
2296 printf("pid1 successfully locked range 130:4 for WRITE\n");
2299 if (cli_read(cli1
, fnum1
, buf
, 130, 4) != 4) {
2300 printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(cli1
));
2303 printf("pid1 successfully read the range 130:4\n");
2306 status
= cli_writeall(cli1
, fnum1
, 0, (uint8_t *)buf
, 130, 4, NULL
);
2307 if (!NT_STATUS_IS_OK(status
)) {
2308 printf("pid1 unable to write to the range 130:4, error was "
2309 "%s\n", nt_errstr(status
));
2312 printf("pid1 successfully wrote to the range 130:4\n");
2315 cli_setpid(cli1
, 2);
2317 if (cli_read(cli1
, fnum1
, buf
, 130, 4) != 4) {
2318 printf("pid2 unable to read the range 130:4, error was %s\n", cli_errstr(cli1
));
2319 if (NT_STATUS_V(cli_nt_error(cli1
)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT
)) {
2320 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2324 printf("pid2 successfully read the range 130:4 (should be denied)\n");
2328 status
= cli_writeall(cli1
, fnum1
, 0, (uint8_t *)buf
, 130, 4, NULL
);
2329 if (!NT_STATUS_IS_OK(status
)) {
2330 printf("pid2 unable to write to the range 130:4, error was "
2331 "%s\n", nt_errstr(status
));
2332 if (!NT_STATUS_EQUAL(status
, NT_STATUS_FILE_LOCK_CONFLICT
)) {
2333 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
2337 printf("pid2 successfully wrote to the range 130:4 (should be denied)\n");
2341 cli_unlock(cli1
, fnum1
, 130, 0);
2345 cli_close(cli1
, fnum1
);
2346 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2347 torture_close_connection(cli1
);
2349 printf("finished locktest7\n");
2354 * This demonstrates a problem with our use of GPFS share modes: A file
2355 * descriptor sitting in the pending close queue holding a GPFS share mode
2356 * blocks opening a file another time. Happens with Word 2007 temp files.
2357 * With "posix locking = yes" and "gpfs:sharemodes = yes" enabled, the third
2358 * open is denied with NT_STATUS_SHARING_VIOLATION.
2361 static bool run_locktest8(int dummy
)
2363 struct cli_state
*cli1
;
2364 const char *fname
= "\\lockt8.lck";
2365 uint16_t fnum1
, fnum2
;
2367 bool correct
= False
;
2370 if (!torture_open_connection(&cli1
, 0)) {
2374 cli_sockopt(cli1
, sockops
);
2376 printf("starting locktest8\n");
2378 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2380 status
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_WRITE
,
2382 if (!NT_STATUS_IS_OK(status
)) {
2383 d_fprintf(stderr
, "cli_open returned %s\n", nt_errstr(status
));
2387 memset(buf
, 0, sizeof(buf
));
2389 status
= cli_open(cli1
, fname
, O_RDONLY
, DENY_NONE
, &fnum2
);
2390 if (!NT_STATUS_IS_OK(status
)) {
2391 d_fprintf(stderr
, "cli_open second time returned %s\n",
2396 if (!cli_lock(cli1
, fnum2
, 1, 1, 0, READ_LOCK
)) {
2397 printf("Unable to apply read lock on range 1:1, error was "
2398 "%s\n", cli_errstr(cli1
));
2402 status
= cli_close(cli1
, fnum1
);
2403 if (!NT_STATUS_IS_OK(status
)) {
2404 d_fprintf(stderr
, "cli_close(fnum1) %s\n", nt_errstr(status
));
2408 status
= cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
, &fnum1
);
2409 if (!NT_STATUS_IS_OK(status
)) {
2410 d_fprintf(stderr
, "cli_open third time returned %s\n",
2418 cli_close(cli1
, fnum1
);
2419 cli_close(cli1
, fnum2
);
2420 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2421 torture_close_connection(cli1
);
2423 printf("finished locktest8\n");
2428 * This test is designed to be run in conjunction with
2429 * external NFS or POSIX locks taken in the filesystem.
2430 * It checks that the smbd server will block until the
2431 * lock is released and then acquire it. JRA.
2434 static bool got_alarm
;
2435 static int alarm_fd
;
2437 static void alarm_handler(int dummy
)
2442 static void alarm_handler_parent(int dummy
)
2447 static void do_local_lock(int read_fd
, int write_fd
)
2452 const char *local_pathname
= NULL
;
2455 local_pathname
= talloc_asprintf(talloc_tos(),
2456 "%s/lockt9.lck", local_path
);
2457 if (!local_pathname
) {
2458 printf("child: alloc fail\n");
2462 unlink(local_pathname
);
2463 fd
= open(local_pathname
, O_RDWR
|O_CREAT
, 0666);
2465 printf("child: open of %s failed %s.\n",
2466 local_pathname
, strerror(errno
));
2470 /* Now take a fcntl lock. */
2471 lock
.l_type
= F_WRLCK
;
2472 lock
.l_whence
= SEEK_SET
;
2475 lock
.l_pid
= getpid();
2477 ret
= fcntl(fd
,F_SETLK
,&lock
);
2479 printf("child: failed to get lock 0:4 on file %s. Error %s\n",
2480 local_pathname
, strerror(errno
));
2483 printf("child: got lock 0:4 on file %s.\n",
2488 CatchSignal(SIGALRM
, alarm_handler
);
2490 /* Signal the parent. */
2491 if (write(write_fd
, &c
, 1) != 1) {
2492 printf("child: start signal fail %s.\n",
2499 /* Wait for the parent to be ready. */
2500 if (read(read_fd
, &c
, 1) != 1) {
2501 printf("child: reply signal fail %s.\n",
2509 printf("child: released lock 0:4 on file %s.\n",
2515 static bool run_locktest9(int dummy
)
2517 struct cli_state
*cli1
;
2518 const char *fname
= "\\lockt9.lck";
2520 bool correct
= False
;
2521 int pipe_in
[2], pipe_out
[2];
2525 struct timeval start
;
2529 printf("starting locktest9\n");
2531 if (local_path
== NULL
) {
2532 d_fprintf(stderr
, "locktest9 must be given a local path via -l <localpath>\n");
2536 if (pipe(pipe_in
) == -1 || pipe(pipe_out
) == -1) {
2541 if (child_pid
== -1) {
2545 if (child_pid
== 0) {
2547 do_local_lock(pipe_out
[0], pipe_in
[1]);
2557 ret
= read(pipe_in
[0], &c
, 1);
2559 d_fprintf(stderr
, "failed to read start signal from child. %s\n",
2564 if (!torture_open_connection(&cli1
, 0)) {
2568 cli_sockopt(cli1
, sockops
);
2570 status
= cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
,
2572 if (!NT_STATUS_IS_OK(status
)) {
2573 d_fprintf(stderr
, "cli_open returned %s\n", nt_errstr(status
));
2577 /* Ensure the child has the lock. */
2578 if (cli_lock(cli1
, fnum
, 0, 4, 0, WRITE_LOCK
)) {
2579 d_fprintf(stderr
, "Got the lock on range 0:4 - this should not happen !\n");
2582 d_printf("Child has the lock.\n");
2585 /* Tell the child to wait 5 seconds then exit. */
2586 ret
= write(pipe_out
[1], &c
, 1);
2588 d_fprintf(stderr
, "failed to send exit signal to child. %s\n",
2593 /* Wait 20 seconds for the lock. */
2594 alarm_fd
= cli1
->fd
;
2595 CatchSignal(SIGALRM
, alarm_handler_parent
);
2598 start
= timeval_current();
2600 if (!cli_lock(cli1
, fnum
, 0, 4, -1, WRITE_LOCK
)) {
2601 d_fprintf(stderr
, "Unable to apply write lock on range 0:4, error was "
2602 "%s\n", cli_errstr(cli1
));
2607 seconds
= timeval_elapsed(&start
);
2609 printf("Parent got the lock after %.2f seconds.\n",
2612 status
= cli_close(cli1
, fnum
);
2613 if (!NT_STATUS_IS_OK(status
)) {
2614 d_fprintf(stderr
, "cli_close(fnum1) %s\n", nt_errstr(status
));
2621 cli_close(cli1
, fnum
);
2622 torture_close_connection(cli1
);
2626 printf("finished locktest9\n");
2631 test whether fnums and tids open on one VC are available on another (a major
2634 static bool run_fdpasstest(int dummy
)
2636 struct cli_state
*cli1
, *cli2
;
2637 const char *fname
= "\\fdpass.tst";
2642 if (!torture_open_connection(&cli1
, 0) || !torture_open_connection(&cli2
, 1)) {
2645 cli_sockopt(cli1
, sockops
);
2646 cli_sockopt(cli2
, sockops
);
2648 printf("starting fdpasstest\n");
2650 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2652 status
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
,
2654 if (!NT_STATUS_IS_OK(status
)) {
2655 printf("open of %s failed (%s)\n", fname
, nt_errstr(status
));
2659 status
= cli_writeall(cli1
, fnum1
, 0, (const uint8_t *)"hello world\n", 0,
2661 if (!NT_STATUS_IS_OK(status
)) {
2662 printf("write failed (%s)\n", nt_errstr(status
));
2666 cli2
->vuid
= cli1
->vuid
;
2667 cli2
->cnum
= cli1
->cnum
;
2668 cli2
->pid
= cli1
->pid
;
2670 if (cli_read(cli2
, fnum1
, buf
, 0, 13) == 13) {
2671 printf("read succeeded! nasty security hole [%s]\n",
2676 cli_close(cli1
, fnum1
);
2677 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2679 torture_close_connection(cli1
);
2680 torture_close_connection(cli2
);
2682 printf("finished fdpasstest\n");
2686 static bool run_fdsesstest(int dummy
)
2688 struct cli_state
*cli
;
2693 const char *fname
= "\\fdsess.tst";
2694 const char *fname1
= "\\fdsess1.tst";
2701 if (!torture_open_connection(&cli
, 0))
2703 cli_sockopt(cli
, sockops
);
2705 if (!torture_cli_session_setup2(cli
, &new_vuid
))
2708 saved_cnum
= cli
->cnum
;
2709 if (!NT_STATUS_IS_OK(cli_tcon_andx(cli
, share
, "?????", "", 1)))
2711 new_cnum
= cli
->cnum
;
2712 cli
->cnum
= saved_cnum
;
2714 printf("starting fdsesstest\n");
2716 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2717 cli_unlink(cli
, fname1
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2719 status
= cli_open(cli
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
);
2720 if (!NT_STATUS_IS_OK(status
)) {
2721 printf("open of %s failed (%s)\n", fname
, nt_errstr(status
));
2725 status
= cli_writeall(cli
, fnum1
, 0, (const uint8_t *)"hello world\n", 0, 13,
2727 if (!NT_STATUS_IS_OK(status
)) {
2728 printf("write failed (%s)\n", nt_errstr(status
));
2732 saved_vuid
= cli
->vuid
;
2733 cli
->vuid
= new_vuid
;
2735 if (cli_read(cli
, fnum1
, buf
, 0, 13) == 13) {
2736 printf("read succeeded with different vuid! nasty security hole [%s]\n",
2740 /* Try to open a file with different vuid, samba cnum. */
2741 if (NT_STATUS_IS_OK(cli_open(cli
, fname1
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum2
))) {
2742 printf("create with different vuid, same cnum succeeded.\n");
2743 cli_close(cli
, fnum2
);
2744 cli_unlink(cli
, fname1
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2746 printf("create with different vuid, same cnum failed.\n");
2747 printf("This will cause problems with service clients.\n");
2751 cli
->vuid
= saved_vuid
;
2753 /* Try with same vuid, different cnum. */
2754 cli
->cnum
= new_cnum
;
2756 if (cli_read(cli
, fnum1
, buf
, 0, 13) == 13) {
2757 printf("read succeeded with different cnum![%s]\n",
2762 cli
->cnum
= saved_cnum
;
2763 cli_close(cli
, fnum1
);
2764 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2766 torture_close_connection(cli
);
2768 printf("finished fdsesstest\n");
2773 This test checks that
2775 1) the server does not allow an unlink on a file that is open
2777 static bool run_unlinktest(int dummy
)
2779 struct cli_state
*cli
;
2780 const char *fname
= "\\unlink.tst";
2782 bool correct
= True
;
2785 if (!torture_open_connection(&cli
, 0)) {
2789 cli_sockopt(cli
, sockops
);
2791 printf("starting unlink test\n");
2793 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2797 status
= cli_open(cli
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum
);
2798 if (!NT_STATUS_IS_OK(status
)) {
2799 printf("open of %s failed (%s)\n", fname
, nt_errstr(status
));
2803 status
= cli_unlink(cli
, fname
,
2804 FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2805 if (NT_STATUS_IS_OK(status
)) {
2806 printf("error: server allowed unlink on an open file\n");
2809 correct
= check_error(__LINE__
, cli
, ERRDOS
, ERRbadshare
,
2810 NT_STATUS_SHARING_VIOLATION
);
2813 cli_close(cli
, fnum
);
2814 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2816 if (!torture_close_connection(cli
)) {
2820 printf("unlink test finished\n");
2827 test how many open files this server supports on the one socket
2829 static bool run_maxfidtest(int dummy
)
2831 struct cli_state
*cli
;
2833 uint16_t fnums
[0x11000];
2836 bool correct
= True
;
2842 printf("failed to connect\n");
2846 cli_sockopt(cli
, sockops
);
2848 for (i
=0; i
<0x11000; i
++) {
2849 slprintf(fname
,sizeof(fname
)-1,"\\maxfid.%d.%d", i
,(int)getpid());
2850 status
= cli_open(cli
, fname
, O_RDWR
|O_CREAT
|O_TRUNC
, DENY_NONE
,
2852 if (!NT_STATUS_IS_OK(status
)) {
2853 printf("open of %s failed (%s)\n",
2854 fname
, nt_errstr(status
));
2855 printf("maximum fnum is %d\n", i
);
2863 printf("cleaning up\n");
2865 slprintf(fname
,sizeof(fname
)-1,"\\maxfid.%d.%d", i
,(int)getpid());
2866 cli_close(cli
, fnums
[i
]);
2868 status
= cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2869 if (!NT_STATUS_IS_OK(status
)) {
2870 printf("unlink of %s failed (%s)\n",
2871 fname
, nt_errstr(status
));
2878 printf("maxfid test finished\n");
2879 if (!torture_close_connection(cli
)) {
2885 /* generate a random buffer */
2886 static void rand_buf(char *buf
, int len
)
2889 *buf
= (char)sys_random();
2894 /* send smb negprot commands, not reading the response */
2895 static bool run_negprot_nowait(int dummy
)
2897 struct tevent_context
*ev
;
2899 struct cli_state
*cli
;
2900 bool correct
= True
;
2902 printf("starting negprot nowait test\n");
2904 ev
= tevent_context_init(talloc_tos());
2909 if (!(cli
= open_nbt_connection())) {
2914 for (i
=0;i
<50000;i
++) {
2915 struct tevent_req
*req
;
2917 req
= cli_negprot_send(ev
, ev
, cli
);
2922 if (!tevent_req_poll(req
, ev
)) {
2923 d_fprintf(stderr
, "tevent_req_poll failed: %s\n",
2931 if (torture_close_connection(cli
)) {
2935 printf("finished negprot nowait test\n");
2940 /* send smb negprot commands, not reading the response */
2941 static bool run_bad_nbt_session(int dummy
)
2943 struct nmb_name called
, calling
;
2944 struct sockaddr_storage ss
;
2949 printf("starting bad nbt session test\n");
2951 make_nmb_name(&calling
, myname
, 0x0);
2952 make_nmb_name(&called
, host
, 0x20);
2954 if (!resolve_name(host
, &ss
, 0x20, true)) {
2955 d_fprintf(stderr
, "Could not resolve name %s\n", host
);
2959 status
= open_socket_out(&ss
, 139, 10000, &fd
);
2960 if (!NT_STATUS_IS_OK(status
)) {
2961 d_fprintf(stderr
, "open_socket_out failed: %s\n",
2966 ret
= cli_bad_session_request(fd
, &calling
, &called
);
2969 d_fprintf(stderr
, "open_socket_out failed: %s\n",
2974 printf("finished bad nbt session test\n");
2978 /* send random IPC commands */
2979 static bool run_randomipc(int dummy
)
2981 char *rparam
= NULL
;
2983 unsigned int rdrcnt
,rprcnt
;
2985 int api
, param_len
, i
;
2986 struct cli_state
*cli
;
2987 bool correct
= True
;
2990 printf("starting random ipc test\n");
2992 if (!torture_open_connection(&cli
, 0)) {
2996 for (i
=0;i
<count
;i
++) {
2997 api
= sys_random() % 500;
2998 param_len
= (sys_random() % 64);
3000 rand_buf(param
, param_len
);
3005 param
, param_len
, 8,
3006 NULL
, 0, BUFFER_SIZE
,
3010 printf("%d/%d\r", i
,count
);
3013 printf("%d/%d\n", i
, count
);
3015 if (!torture_close_connection(cli
)) {
3019 printf("finished random ipc test\n");
3026 static void browse_callback(const char *sname
, uint32 stype
,
3027 const char *comment
, void *state
)
3029 printf("\t%20.20s %08x %s\n", sname
, stype
, comment
);
3035 This test checks the browse list code
3038 static bool run_browsetest(int dummy
)
3040 static struct cli_state
*cli
;
3041 bool correct
= True
;
3043 printf("starting browse test\n");
3045 if (!torture_open_connection(&cli
, 0)) {
3049 printf("domain list:\n");
3050 cli_NetServerEnum(cli
, cli
->server_domain
,
3051 SV_TYPE_DOMAIN_ENUM
,
3052 browse_callback
, NULL
);
3054 printf("machine list:\n");
3055 cli_NetServerEnum(cli
, cli
->server_domain
,
3057 browse_callback
, NULL
);
3059 if (!torture_close_connection(cli
)) {
3063 printf("browse test finished\n");
3071 This checks how the getatr calls works
3073 static bool run_attrtest(int dummy
)
3075 struct cli_state
*cli
;
3078 const char *fname
= "\\attrib123456789.tst";
3079 bool correct
= True
;
3082 printf("starting attrib test\n");
3084 if (!torture_open_connection(&cli
, 0)) {
3088 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3089 cli_open(cli
, fname
,
3090 O_RDWR
| O_CREAT
| O_TRUNC
, DENY_NONE
, &fnum
);
3091 cli_close(cli
, fnum
);
3093 status
= cli_getatr(cli
, fname
, NULL
, NULL
, &t
);
3094 if (!NT_STATUS_IS_OK(status
)) {
3095 printf("getatr failed (%s)\n", nt_errstr(status
));
3099 if (abs(t
- time(NULL
)) > 60*60*24*10) {
3100 printf("ERROR: SMBgetatr bug. time is %s",
3106 t2
= t
-60*60*24; /* 1 day ago */
3108 status
= cli_setatr(cli
, fname
, 0, t2
);
3109 if (!NT_STATUS_IS_OK(status
)) {
3110 printf("setatr failed (%s)\n", nt_errstr(status
));
3114 status
= cli_getatr(cli
, fname
, NULL
, NULL
, &t
);
3115 if (!NT_STATUS_IS_OK(status
)) {
3116 printf("getatr failed (%s)\n", nt_errstr(status
));
3121 printf("ERROR: getatr/setatr bug. times are\n%s",
3123 printf("%s", ctime(&t2
));
3127 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3129 if (!torture_close_connection(cli
)) {
3133 printf("attrib test finished\n");
3140 This checks a couple of trans2 calls
3142 static bool run_trans2test(int dummy
)
3144 struct cli_state
*cli
;
3147 time_t c_time
, a_time
, m_time
;
3148 struct timespec c_time_ts
, a_time_ts
, m_time_ts
, w_time_ts
, m_time2_ts
;
3149 const char *fname
= "\\trans2.tst";
3150 const char *dname
= "\\trans2";
3151 const char *fname2
= "\\trans2\\trans2.tst";
3153 bool correct
= True
;
3157 printf("starting trans2 test\n");
3159 if (!torture_open_connection(&cli
, 0)) {
3163 status
= cli_get_fs_attr_info(cli
, &fs_attr
);
3164 if (!NT_STATUS_IS_OK(status
)) {
3165 printf("ERROR: cli_get_fs_attr_info returned %s\n",
3170 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3171 cli_open(cli
, fname
, O_RDWR
| O_CREAT
| O_TRUNC
, DENY_NONE
, &fnum
);
3172 status
= cli_qfileinfo_basic(cli
, fnum
, NULL
, &size
, &c_time_ts
,
3173 &a_time_ts
, &w_time_ts
, &m_time_ts
, NULL
);
3174 if (!NT_STATUS_IS_OK(status
)) {
3175 printf("ERROR: qfileinfo failed (%s)\n", nt_errstr(status
));
3179 status
= cli_qfilename(cli
, fnum
, talloc_tos(), &pname
);
3180 if (!NT_STATUS_IS_OK(status
)) {
3181 printf("ERROR: qfilename failed (%s)\n", nt_errstr(status
));
3185 if (strcmp(pname
, fname
)) {
3186 printf("qfilename gave different name? [%s] [%s]\n",
3191 cli_close(cli
, fnum
);
3195 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3196 status
= cli_open(cli
, fname
, O_RDWR
| O_CREAT
| O_TRUNC
, DENY_NONE
,
3198 if (!NT_STATUS_IS_OK(status
)) {
3199 printf("open of %s failed (%s)\n", fname
, nt_errstr(status
));
3202 cli_close(cli
, fnum
);
3204 status
= cli_qpathinfo1(cli
, fname
, &c_time
, &a_time
, &m_time
, &size
,
3206 if (!NT_STATUS_IS_OK(status
)) {
3207 printf("ERROR: qpathinfo failed (%s)\n", nt_errstr(status
));
3210 if (c_time
!= m_time
) {
3211 printf("create time=%s", ctime(&c_time
));
3212 printf("modify time=%s", ctime(&m_time
));
3213 printf("This system appears to have sticky create times\n");
3215 if (a_time
% (60*60) == 0) {
3216 printf("access time=%s", ctime(&a_time
));
3217 printf("This system appears to set a midnight access time\n");
3221 if (abs(m_time
- time(NULL
)) > 60*60*24*7) {
3222 printf("ERROR: totally incorrect times - maybe word reversed? mtime=%s", ctime(&m_time
));
3228 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3229 cli_open(cli
, fname
,
3230 O_RDWR
| O_CREAT
| O_TRUNC
, DENY_NONE
, &fnum
);
3231 cli_close(cli
, fnum
);
3232 status
= cli_qpathinfo2(cli
, fname
, &c_time_ts
, &a_time_ts
, &w_time_ts
,
3233 &m_time_ts
, &size
, NULL
, NULL
);
3234 if (!NT_STATUS_IS_OK(status
)) {
3235 printf("ERROR: qpathinfo2 failed (%s)\n", nt_errstr(status
));
3238 if (w_time_ts
.tv_sec
< 60*60*24*2) {
3239 printf("write time=%s", ctime(&w_time_ts
.tv_sec
));
3240 printf("This system appears to set a initial 0 write time\n");
3245 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3248 /* check if the server updates the directory modification time
3249 when creating a new file */
3250 status
= cli_mkdir(cli
, dname
);
3251 if (!NT_STATUS_IS_OK(status
)) {
3252 printf("ERROR: mkdir failed (%s)\n", nt_errstr(status
));
3256 status
= cli_qpathinfo2(cli
, "\\trans2\\", &c_time_ts
, &a_time_ts
,
3257 &w_time_ts
, &m_time_ts
, &size
, NULL
, NULL
);
3258 if (!NT_STATUS_IS_OK(status
)) {
3259 printf("ERROR: qpathinfo2 failed (%s)\n", nt_errstr(status
));
3263 cli_open(cli
, fname2
,
3264 O_RDWR
| O_CREAT
| O_TRUNC
, DENY_NONE
, &fnum
);
3265 cli_writeall(cli
, fnum
, 0, (uint8_t *)&fnum
, 0, sizeof(fnum
), NULL
);
3266 cli_close(cli
, fnum
);
3267 status
= cli_qpathinfo2(cli
, "\\trans2\\", &c_time_ts
, &a_time_ts
,
3268 &w_time_ts
, &m_time2_ts
, &size
, NULL
, NULL
);
3269 if (!NT_STATUS_IS_OK(status
)) {
3270 printf("ERROR: qpathinfo2 failed (%s)\n", nt_errstr(status
));
3273 if (memcmp(&m_time_ts
, &m_time2_ts
, sizeof(struct timespec
))
3275 printf("This system does not update directory modification times\n");
3279 cli_unlink(cli
, fname2
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3280 cli_rmdir(cli
, dname
);
3282 if (!torture_close_connection(cli
)) {
3286 printf("trans2 test finished\n");
3292 This checks new W2K calls.
3295 static NTSTATUS
new_trans(struct cli_state
*pcli
, int fnum
, int level
)
3297 uint8_t *buf
= NULL
;
3301 status
= cli_qfileinfo(talloc_tos(), pcli
, fnum
, level
, 0,
3302 pcli
->max_xmit
, NULL
, &buf
, &len
);
3303 if (!NT_STATUS_IS_OK(status
)) {
3304 printf("ERROR: qfileinfo (%d) failed (%s)\n", level
,
3307 printf("qfileinfo: level %d, len = %u\n", level
, len
);
3308 dump_data(0, (uint8
*)buf
, len
);
3315 static bool run_w2ktest(int dummy
)
3317 struct cli_state
*cli
;
3319 const char *fname
= "\\w2ktest\\w2k.tst";
3321 bool correct
= True
;
3323 printf("starting w2k test\n");
3325 if (!torture_open_connection(&cli
, 0)) {
3329 cli_open(cli
, fname
,
3330 O_RDWR
| O_CREAT
, DENY_NONE
, &fnum
);
3332 for (level
= 1004; level
< 1040; level
++) {
3333 new_trans(cli
, fnum
, level
);
3336 cli_close(cli
, fnum
);
3338 if (!torture_close_connection(cli
)) {
3342 printf("w2k test finished\n");
3349 this is a harness for some oplock tests
3351 static bool run_oplock1(int dummy
)
3353 struct cli_state
*cli1
;
3354 const char *fname
= "\\lockt1.lck";
3356 bool correct
= True
;
3359 printf("starting oplock test 1\n");
3361 if (!torture_open_connection(&cli1
, 0)) {
3365 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3367 cli_sockopt(cli1
, sockops
);
3369 cli1
->use_oplocks
= True
;
3371 status
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
,
3373 if (!NT_STATUS_IS_OK(status
)) {
3374 printf("open of %s failed (%s)\n", fname
, nt_errstr(status
));
3378 cli1
->use_oplocks
= False
;
3380 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3381 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3383 status
= cli_close(cli1
, fnum1
);
3384 if (!NT_STATUS_IS_OK(status
)) {
3385 printf("close2 failed (%s)\n", nt_errstr(status
));
3389 status
= cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3390 if (!NT_STATUS_IS_OK(status
)) {
3391 printf("unlink failed (%s)\n", nt_errstr(status
));
3395 if (!torture_close_connection(cli1
)) {
3399 printf("finished oplock test 1\n");
3404 static bool run_oplock2(int dummy
)
3406 struct cli_state
*cli1
, *cli2
;
3407 const char *fname
= "\\lockt2.lck";
3408 uint16_t fnum1
, fnum2
;
3409 int saved_use_oplocks
= use_oplocks
;
3411 bool correct
= True
;
3412 volatile bool *shared_correct
;
3415 shared_correct
= (volatile bool *)shm_setup(sizeof(bool));
3416 *shared_correct
= True
;
3418 use_level_II_oplocks
= True
;
3421 printf("starting oplock test 2\n");
3423 if (!torture_open_connection(&cli1
, 0)) {
3424 use_level_II_oplocks
= False
;
3425 use_oplocks
= saved_use_oplocks
;
3429 cli1
->use_oplocks
= True
;
3430 cli1
->use_level_II_oplocks
= True
;
3432 if (!torture_open_connection(&cli2
, 1)) {
3433 use_level_II_oplocks
= False
;
3434 use_oplocks
= saved_use_oplocks
;
3438 cli2
->use_oplocks
= True
;
3439 cli2
->use_level_II_oplocks
= True
;
3441 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3443 cli_sockopt(cli1
, sockops
);
3444 cli_sockopt(cli2
, sockops
);
3446 status
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
,
3448 if (!NT_STATUS_IS_OK(status
)) {
3449 printf("open of %s failed (%s)\n", fname
, nt_errstr(status
));
3453 /* Don't need the globals any more. */
3454 use_level_II_oplocks
= False
;
3455 use_oplocks
= saved_use_oplocks
;
3459 status
= cli_open(cli2
, fname
, O_RDWR
, DENY_NONE
, &fnum2
);
3460 if (!NT_STATUS_IS_OK(status
)) {
3461 printf("second open of %s failed (%s)\n", fname
, nt_errstr(status
));
3462 *shared_correct
= False
;
3468 status
= cli_close(cli2
, fnum2
);
3469 if (!NT_STATUS_IS_OK(status
)) {
3470 printf("close2 failed (%s)\n", nt_errstr(status
));
3471 *shared_correct
= False
;
3479 /* Ensure cli1 processes the break. Empty file should always return 0
3482 if (cli_read(cli1
, fnum1
, buf
, 0, 4) != 0) {
3483 printf("read on fnum1 failed (%s)\n", cli_errstr(cli1
));
3487 /* Should now be at level II. */
3488 /* Test if sending a write locks causes a break to none. */
3490 if (!cli_lock(cli1
, fnum1
, 0, 4, 0, READ_LOCK
)) {
3491 printf("lock failed (%s)\n", cli_errstr(cli1
));
3495 cli_unlock(cli1
, fnum1
, 0, 4);
3499 if (!cli_lock(cli1
, fnum1
, 0, 4, 0, WRITE_LOCK
)) {
3500 printf("lock failed (%s)\n", cli_errstr(cli1
));
3504 cli_unlock(cli1
, fnum1
, 0, 4);
3508 cli_read(cli1
, fnum1
, buf
, 0, 4);
3510 status
= cli_close(cli1
, fnum1
);
3511 if (!NT_STATUS_IS_OK(status
)) {
3512 printf("close1 failed (%s)\n", nt_errstr(status
));
3518 status
= cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3519 if (!NT_STATUS_IS_OK(status
)) {
3520 printf("unlink failed (%s)\n", nt_errstr(status
));
3524 if (!torture_close_connection(cli1
)) {
3528 if (!*shared_correct
) {
3532 printf("finished oplock test 2\n");
3537 struct oplock4_state
{
3538 struct tevent_context
*ev
;
3539 struct cli_state
*cli
;
3544 static void oplock4_got_break(struct tevent_req
*req
);
3545 static void oplock4_got_open(struct tevent_req
*req
);
3547 static bool run_oplock4(int dummy
)
3549 struct tevent_context
*ev
;
3550 struct cli_state
*cli1
, *cli2
;
3551 struct tevent_req
*oplock_req
, *open_req
;
3552 const char *fname
= "\\lockt4.lck";
3553 const char *fname_ln
= "\\lockt4_ln.lck";
3554 uint16_t fnum1
, fnum2
;
3555 int saved_use_oplocks
= use_oplocks
;
3557 bool correct
= true;
3561 struct oplock4_state
*state
;
3563 printf("starting oplock test 4\n");
3565 if (!torture_open_connection(&cli1
, 0)) {
3566 use_level_II_oplocks
= false;
3567 use_oplocks
= saved_use_oplocks
;
3571 if (!torture_open_connection(&cli2
, 1)) {
3572 use_level_II_oplocks
= false;
3573 use_oplocks
= saved_use_oplocks
;
3577 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3578 cli_unlink(cli1
, fname_ln
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3580 cli_sockopt(cli1
, sockops
);
3581 cli_sockopt(cli2
, sockops
);
3583 /* Create the file. */
3584 status
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
,
3586 if (!NT_STATUS_IS_OK(status
)) {
3587 printf("open of %s failed (%s)\n", fname
, nt_errstr(status
));
3591 status
= cli_close(cli1
, fnum1
);
3592 if (!NT_STATUS_IS_OK(status
)) {
3593 printf("close1 failed (%s)\n", nt_errstr(status
));
3597 /* Now create a hardlink. */
3598 status
= cli_nt_hardlink(cli1
, fname
, fname_ln
);
3599 if (!NT_STATUS_IS_OK(status
)) {
3600 printf("nt hardlink failed (%s)\n", nt_errstr(status
));
3604 /* Prove that opening hardlinks cause deny modes to conflict. */
3605 status
= cli_open(cli1
, fname
, O_RDWR
, DENY_ALL
, &fnum1
);
3606 if (!NT_STATUS_IS_OK(status
)) {
3607 printf("open of %s failed (%s)\n", fname
, nt_errstr(status
));
3611 status
= cli_open(cli1
, fname_ln
, O_RDWR
, DENY_NONE
, &fnum2
);
3612 if (NT_STATUS_IS_OK(status
)) {
3613 printf("open of %s succeeded - should fail with sharing violation.\n",
3618 if (!NT_STATUS_EQUAL(status
, NT_STATUS_SHARING_VIOLATION
)) {
3619 printf("open of %s should fail with sharing violation. Got %s\n",
3620 fname_ln
, nt_errstr(status
));
3624 status
= cli_close(cli1
, fnum1
);
3625 if (!NT_STATUS_IS_OK(status
)) {
3626 printf("close1 failed (%s)\n", nt_errstr(status
));
3630 cli1
->use_oplocks
= true;
3631 cli1
->use_level_II_oplocks
= true;
3633 cli2
->use_oplocks
= true;
3634 cli2
->use_level_II_oplocks
= true;
3636 status
= cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
, &fnum1
);
3637 if (!NT_STATUS_IS_OK(status
)) {
3638 printf("open of %s failed (%s)\n", fname
, nt_errstr(status
));
3642 ev
= tevent_context_init(talloc_tos());
3644 printf("tevent_req_create failed\n");
3648 state
= talloc(ev
, struct oplock4_state
);
3649 if (state
== NULL
) {
3650 printf("talloc failed\n");
3655 state
->got_break
= &got_break
;
3656 state
->fnum2
= &fnum2
;
3658 oplock_req
= cli_smb_oplock_break_waiter_send(
3659 talloc_tos(), ev
, cli1
);
3660 if (oplock_req
== NULL
) {
3661 printf("cli_smb_oplock_break_waiter_send failed\n");
3664 tevent_req_set_callback(oplock_req
, oplock4_got_break
, state
);
3666 open_req
= cli_open_send(
3667 talloc_tos(), ev
, cli2
, fname_ln
, O_RDWR
, DENY_NONE
);
3668 if (oplock_req
== NULL
) {
3669 printf("cli_open_send failed\n");
3672 tevent_req_set_callback(open_req
, oplock4_got_open
, state
);
3677 while (!got_break
|| fnum2
== 0xffff) {
3679 ret
= tevent_loop_once(ev
);
3681 printf("tevent_loop_once failed: %s\n",
3687 status
= cli_close(cli2
, fnum2
);
3688 if (!NT_STATUS_IS_OK(status
)) {
3689 printf("close2 failed (%s)\n", nt_errstr(status
));
3693 status
= cli_close(cli1
, fnum1
);
3694 if (!NT_STATUS_IS_OK(status
)) {
3695 printf("close1 failed (%s)\n", nt_errstr(status
));
3699 status
= cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3700 if (!NT_STATUS_IS_OK(status
)) {
3701 printf("unlink failed (%s)\n", nt_errstr(status
));
3705 status
= cli_unlink(cli1
, fname_ln
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3706 if (!NT_STATUS_IS_OK(status
)) {
3707 printf("unlink failed (%s)\n", nt_errstr(status
));
3711 if (!torture_close_connection(cli1
)) {
3719 printf("finished oplock test 4\n");
3724 static void oplock4_got_break(struct tevent_req
*req
)
3726 struct oplock4_state
*state
= tevent_req_callback_data(
3727 req
, struct oplock4_state
);
3732 status
= cli_smb_oplock_break_waiter_recv(req
, &fnum
, &level
);
3734 if (!NT_STATUS_IS_OK(status
)) {
3735 printf("cli_smb_oplock_break_waiter_recv returned %s\n",
3739 *state
->got_break
= true;
3741 req
= cli_oplock_ack_send(state
, state
->ev
, state
->cli
, fnum
,
3744 printf("cli_oplock_ack_send failed\n");
3749 static void oplock4_got_open(struct tevent_req
*req
)
3751 struct oplock4_state
*state
= tevent_req_callback_data(
3752 req
, struct oplock4_state
);
3755 status
= cli_open_recv(req
, state
->fnum2
);
3756 if (!NT_STATUS_IS_OK(status
)) {
3757 printf("cli_open_recv returned %s\n", nt_errstr(status
));
3758 *state
->fnum2
= 0xffff;
3763 Test delete on close semantics.
3765 static bool run_deletetest(int dummy
)
3767 struct cli_state
*cli1
= NULL
;
3768 struct cli_state
*cli2
= NULL
;
3769 const char *fname
= "\\delete.file";
3770 uint16_t fnum1
= (uint16_t)-1;
3771 uint16_t fnum2
= (uint16_t)-1;
3772 bool correct
= True
;
3775 printf("starting delete test\n");
3777 if (!torture_open_connection(&cli1
, 0)) {
3781 cli_sockopt(cli1
, sockops
);
3783 /* Test 1 - this should delete the file on close. */
3785 cli_setatr(cli1
, fname
, 0, 0);
3786 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3788 status
= cli_ntcreate(cli1
, fname
, 0, GENERIC_ALL_ACCESS
|DELETE_ACCESS
,
3789 FILE_ATTRIBUTE_NORMAL
, 0, FILE_OVERWRITE_IF
,
3790 FILE_DELETE_ON_CLOSE
, 0, &fnum1
);
3791 if (!NT_STATUS_IS_OK(status
)) {
3792 printf("[1] open of %s failed (%s)\n", fname
, nt_errstr(status
));
3797 status
= cli_close(cli1
, fnum1
);
3798 if (!NT_STATUS_IS_OK(status
)) {
3799 printf("[1] close failed (%s)\n", nt_errstr(status
));
3804 if (NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDWR
, DENY_NONE
, &fnum1
))) {
3805 printf("[1] open of %s succeeded (should fail)\n", fname
);
3810 printf("first delete on close test succeeded.\n");
3812 /* Test 2 - this should delete the file on close. */
3814 cli_setatr(cli1
, fname
, 0, 0);
3815 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3817 status
= cli_ntcreate(cli1
, fname
, 0, GENERIC_ALL_ACCESS
,
3818 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_NONE
,
3819 FILE_OVERWRITE_IF
, 0, 0, &fnum1
);
3820 if (!NT_STATUS_IS_OK(status
)) {
3821 printf("[2] open of %s failed (%s)\n", fname
, nt_errstr(status
));
3826 status
= cli_nt_delete_on_close(cli1
, fnum1
, true);
3827 if (!NT_STATUS_IS_OK(status
)) {
3828 printf("[2] setting delete_on_close failed (%s)\n", nt_errstr(status
));
3833 status
= cli_close(cli1
, fnum1
);
3834 if (!NT_STATUS_IS_OK(status
)) {
3835 printf("[2] close failed (%s)\n", nt_errstr(status
));
3840 if (NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDONLY
, DENY_NONE
, &fnum1
))) {
3841 printf("[2] open of %s succeeded should have been deleted on close !\n", fname
);
3842 status
= cli_close(cli1
, fnum1
);
3843 if (!NT_STATUS_IS_OK(status
)) {
3844 printf("[2] close failed (%s)\n", nt_errstr(status
));
3848 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3850 printf("second delete on close test succeeded.\n");
3853 cli_setatr(cli1
, fname
, 0, 0);
3854 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3856 status
= cli_ntcreate(cli1
, fname
, 0, GENERIC_ALL_ACCESS
,
3857 FILE_ATTRIBUTE_NORMAL
,
3858 FILE_SHARE_READ
|FILE_SHARE_WRITE
,
3859 FILE_OVERWRITE_IF
, 0, 0, &fnum1
);
3860 if (!NT_STATUS_IS_OK(status
)) {
3861 printf("[3] open - 1 of %s failed (%s)\n", fname
, nt_errstr(status
));
3866 /* This should fail with a sharing violation - open for delete is only compatible
3867 with SHARE_DELETE. */
3869 if (NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, GENERIC_READ_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
3870 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OPEN
, 0, 0, &fnum2
))) {
3871 printf("[3] open - 2 of %s succeeded - should have failed.\n", fname
);
3876 /* This should succeed. */
3877 status
= cli_ntcreate(cli1
, fname
, 0, GENERIC_READ_ACCESS
,
3878 FILE_ATTRIBUTE_NORMAL
,
3879 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
3880 FILE_OPEN
, 0, 0, &fnum2
);
3881 if (!NT_STATUS_IS_OK(status
)) {
3882 printf("[3] open - 2 of %s failed (%s)\n", fname
, nt_errstr(status
));
3887 status
= cli_nt_delete_on_close(cli1
, fnum1
, true);
3888 if (!NT_STATUS_IS_OK(status
)) {
3889 printf("[3] setting delete_on_close failed (%s)\n", nt_errstr(status
));
3894 status
= cli_close(cli1
, fnum1
);
3895 if (!NT_STATUS_IS_OK(status
)) {
3896 printf("[3] close 1 failed (%s)\n", nt_errstr(status
));
3901 status
= cli_close(cli1
, fnum2
);
3902 if (!NT_STATUS_IS_OK(status
)) {
3903 printf("[3] close 2 failed (%s)\n", nt_errstr(status
));
3908 /* This should fail - file should no longer be there. */
3910 if (NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDONLY
, DENY_NONE
, &fnum1
))) {
3911 printf("[3] open of %s succeeded should have been deleted on close !\n", fname
);
3912 status
= cli_close(cli1
, fnum1
);
3913 if (!NT_STATUS_IS_OK(status
)) {
3914 printf("[3] close failed (%s)\n", nt_errstr(status
));
3916 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3920 printf("third delete on close test succeeded.\n");
3923 cli_setatr(cli1
, fname
, 0, 0);
3924 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3926 status
= cli_ntcreate(cli1
, fname
, 0,
3927 FILE_READ_DATA
|FILE_WRITE_DATA
|DELETE_ACCESS
,
3928 FILE_ATTRIBUTE_NORMAL
,
3929 FILE_SHARE_READ
|FILE_SHARE_WRITE
,
3930 FILE_OVERWRITE_IF
, 0, 0, &fnum1
);
3931 if (!NT_STATUS_IS_OK(status
)) {
3932 printf("[4] open of %s failed (%s)\n", fname
, nt_errstr(status
));
3937 /* This should succeed. */
3938 status
= cli_ntcreate(cli1
, fname
, 0, GENERIC_READ_ACCESS
,
3939 FILE_ATTRIBUTE_NORMAL
,
3940 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
3941 FILE_OPEN
, 0, 0, &fnum2
);
3942 if (!NT_STATUS_IS_OK(status
)) {
3943 printf("[4] open - 2 of %s failed (%s)\n", fname
, nt_errstr(status
));
3948 status
= cli_close(cli1
, fnum2
);
3949 if (!NT_STATUS_IS_OK(status
)) {
3950 printf("[4] close - 1 failed (%s)\n", nt_errstr(status
));
3955 status
= cli_nt_delete_on_close(cli1
, fnum1
, true);
3956 if (!NT_STATUS_IS_OK(status
)) {
3957 printf("[4] setting delete_on_close failed (%s)\n", nt_errstr(status
));
3962 /* This should fail - no more opens once delete on close set. */
3963 if (NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, GENERIC_READ_ACCESS
,
3964 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
3965 FILE_OPEN
, 0, 0, &fnum2
))) {
3966 printf("[4] open - 3 of %s succeeded ! Should have failed.\n", fname
);
3970 printf("fourth delete on close test succeeded.\n");
3972 status
= cli_close(cli1
, fnum1
);
3973 if (!NT_STATUS_IS_OK(status
)) {
3974 printf("[4] close - 2 failed (%s)\n", nt_errstr(status
));
3980 cli_setatr(cli1
, fname
, 0, 0);
3981 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
3983 status
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
, DENY_NONE
, &fnum1
);
3984 if (!NT_STATUS_IS_OK(status
)) {
3985 printf("[5] open of %s failed (%s)\n", fname
, nt_errstr(status
));
3990 /* This should fail - only allowed on NT opens with DELETE access. */
3992 if (NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1
, fnum1
, true))) {
3993 printf("[5] setting delete_on_close on OpenX file succeeded - should fail !\n");
3998 status
= cli_close(cli1
, fnum1
);
3999 if (!NT_STATUS_IS_OK(status
)) {
4000 printf("[5] close - 2 failed (%s)\n", nt_errstr(status
));
4005 printf("fifth delete on close test succeeded.\n");
4008 cli_setatr(cli1
, fname
, 0, 0);
4009 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4011 status
= cli_ntcreate(cli1
, fname
, 0, FILE_READ_DATA
|FILE_WRITE_DATA
,
4012 FILE_ATTRIBUTE_NORMAL
,
4013 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
4014 FILE_OVERWRITE_IF
, 0, 0, &fnum1
);
4015 if (!NT_STATUS_IS_OK(status
)) {
4016 printf("[6] open of %s failed (%s)\n", fname
,
4022 /* This should fail - only allowed on NT opens with DELETE access. */
4024 if (NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1
, fnum1
, true))) {
4025 printf("[6] setting delete_on_close on file with no delete access succeeded - should fail !\n");
4030 status
= cli_close(cli1
, fnum1
);
4031 if (!NT_STATUS_IS_OK(status
)) {
4032 printf("[6] close - 2 failed (%s)\n", nt_errstr(status
));
4037 printf("sixth delete on close test succeeded.\n");
4040 cli_setatr(cli1
, fname
, 0, 0);
4041 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4043 status
= cli_ntcreate(cli1
, fname
, 0,
4044 FILE_READ_DATA
|FILE_WRITE_DATA
|DELETE_ACCESS
,
4045 FILE_ATTRIBUTE_NORMAL
, 0, FILE_OVERWRITE_IF
,
4047 if (!NT_STATUS_IS_OK(status
)) {
4048 printf("[7] open of %s failed (%s)\n", fname
, nt_errstr(status
));
4053 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1
, fnum1
, true))) {
4054 printf("[7] setting delete_on_close on file failed !\n");
4059 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1
, fnum1
, false))) {
4060 printf("[7] unsetting delete_on_close on file failed !\n");
4065 status
= cli_close(cli1
, fnum1
);
4066 if (!NT_STATUS_IS_OK(status
)) {
4067 printf("[7] close - 2 failed (%s)\n", nt_errstr(status
));
4072 /* This next open should succeed - we reset the flag. */
4073 status
= cli_open(cli1
, fname
, O_RDONLY
, DENY_NONE
, &fnum1
);
4074 if (!NT_STATUS_IS_OK(status
)) {
4075 printf("[5] open of %s failed (%s)\n", fname
, nt_errstr(status
));
4080 status
= cli_close(cli1
, fnum1
);
4081 if (!NT_STATUS_IS_OK(status
)) {
4082 printf("[7] close - 2 failed (%s)\n", nt_errstr(status
));
4087 printf("seventh delete on close test succeeded.\n");
4090 cli_setatr(cli1
, fname
, 0, 0);
4091 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4093 if (!torture_open_connection(&cli2
, 1)) {
4094 printf("[8] failed to open second connection.\n");
4099 cli_sockopt(cli1
, sockops
);
4101 status
= cli_ntcreate(cli1
, fname
, 0,
4102 FILE_READ_DATA
|FILE_WRITE_DATA
|DELETE_ACCESS
,
4103 FILE_ATTRIBUTE_NORMAL
,
4104 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
4105 FILE_OVERWRITE_IF
, 0, 0, &fnum1
);
4106 if (!NT_STATUS_IS_OK(status
)) {
4107 printf("[8] open 1 of %s failed (%s)\n", fname
, nt_errstr(status
));
4112 status
= cli_ntcreate(cli2
, fname
, 0,
4113 FILE_READ_DATA
|FILE_WRITE_DATA
|DELETE_ACCESS
,
4114 FILE_ATTRIBUTE_NORMAL
,
4115 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
4116 FILE_OPEN
, 0, 0, &fnum2
);
4117 if (!NT_STATUS_IS_OK(status
)) {
4118 printf("[8] open 2 of %s failed (%s)\n", fname
, nt_errstr(status
));
4123 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1
, fnum1
, true))) {
4124 printf("[8] setting delete_on_close on file failed !\n");
4129 status
= cli_close(cli1
, fnum1
);
4130 if (!NT_STATUS_IS_OK(status
)) {
4131 printf("[8] close - 1 failed (%s)\n", nt_errstr(status
));
4136 status
= cli_close(cli2
, fnum2
);
4137 if (!NT_STATUS_IS_OK(status
)) {
4138 printf("[8] close - 2 failed (%s)\n", nt_errstr(status
));
4143 /* This should fail.. */
4144 status
= cli_open(cli1
, fname
, O_RDONLY
, DENY_NONE
, &fnum1
);
4145 if (NT_STATUS_IS_OK(status
)) {
4146 printf("[8] open of %s succeeded should have been deleted on close !\n", fname
);
4150 printf("eighth delete on close test succeeded.\n");
4152 /* This should fail - we need to set DELETE_ACCESS. */
4153 if (NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0,FILE_READ_DATA
|FILE_WRITE_DATA
,
4154 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, FILE_DELETE_ON_CLOSE
, 0, &fnum1
))) {
4155 printf("[9] open of %s succeeded should have failed!\n", fname
);
4160 printf("ninth delete on close test succeeded.\n");
4162 status
= cli_ntcreate(cli1
, fname
, 0,
4163 FILE_READ_DATA
|FILE_WRITE_DATA
|DELETE_ACCESS
,
4164 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_NONE
,
4165 FILE_OVERWRITE_IF
, FILE_DELETE_ON_CLOSE
,
4167 if (!NT_STATUS_IS_OK(status
)) {
4168 printf("[10] open of %s failed (%s)\n", fname
, nt_errstr(status
));
4173 /* This should delete the file. */
4174 status
= cli_close(cli1
, fnum1
);
4175 if (!NT_STATUS_IS_OK(status
)) {
4176 printf("[10] close failed (%s)\n", nt_errstr(status
));
4181 /* This should fail.. */
4182 if (NT_STATUS_IS_OK(cli_open(cli1
, fname
, O_RDONLY
, DENY_NONE
, &fnum1
))) {
4183 printf("[10] open of %s succeeded should have been deleted on close !\n", fname
);
4187 printf("tenth delete on close test succeeded.\n");
4189 cli_setatr(cli1
, fname
, 0, 0);
4190 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4192 /* What error do we get when attempting to open a read-only file with
4195 /* Create a readonly file. */
4196 status
= cli_ntcreate(cli1
, fname
, 0, FILE_READ_DATA
|FILE_WRITE_DATA
,
4197 FILE_ATTRIBUTE_READONLY
, FILE_SHARE_NONE
,
4198 FILE_OVERWRITE_IF
, 0, 0, &fnum1
);
4199 if (!NT_STATUS_IS_OK(status
)) {
4200 printf("[11] open of %s failed (%s)\n", fname
, nt_errstr(status
));
4205 status
= cli_close(cli1
, fnum1
);
4206 if (!NT_STATUS_IS_OK(status
)) {
4207 printf("[11] close failed (%s)\n", nt_errstr(status
));
4212 /* Now try open for delete access. */
4213 if (NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, FILE_READ_ATTRIBUTES
|DELETE_ACCESS
,
4214 0, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
4215 FILE_OVERWRITE_IF
, 0, 0, &fnum1
))) {
4216 printf("[11] open of %s succeeded should have been denied with ACCESS_DENIED!\n", fname
);
4217 cli_close(cli1
, fnum1
);
4221 NTSTATUS nterr
= cli_nt_error(cli1
);
4222 if (!NT_STATUS_EQUAL(nterr
,NT_STATUS_ACCESS_DENIED
)) {
4223 printf("[11] open of %s should have been denied with ACCESS_DENIED! Got error %s\n", fname
, nt_errstr(nterr
));
4227 printf("eleventh delete on close test succeeded.\n");
4231 printf("finished delete test\n");
4234 /* FIXME: This will crash if we aborted before cli2 got
4235 * intialized, because these functions don't handle
4236 * uninitialized connections. */
4238 if (fnum1
!= (uint16_t)-1) cli_close(cli1
, fnum1
);
4239 if (fnum2
!= (uint16_t)-1) cli_close(cli1
, fnum2
);
4240 cli_setatr(cli1
, fname
, 0, 0);
4241 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4243 if (cli1
&& !torture_close_connection(cli1
)) {
4246 if (cli2
&& !torture_close_connection(cli2
)) {
4252 static bool run_deletetest_ln(int dummy
)
4254 struct cli_state
*cli
;
4255 const char *fname
= "\\delete1";
4256 const char *fname_ln
= "\\delete1_ln";
4260 bool correct
= true;
4263 printf("starting deletetest-ln\n");
4265 if (!torture_open_connection(&cli
, 0)) {
4269 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4270 cli_unlink(cli
, fname_ln
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4272 cli_sockopt(cli
, sockops
);
4274 /* Create the file. */
4275 status
= cli_open(cli
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum
);
4276 if (!NT_STATUS_IS_OK(status
)) {
4277 printf("open of %s failed (%s)\n", fname
, nt_errstr(status
));
4281 status
= cli_close(cli
, fnum
);
4282 if (!NT_STATUS_IS_OK(status
)) {
4283 printf("close1 failed (%s)\n", nt_errstr(status
));
4287 /* Now create a hardlink. */
4288 status
= cli_nt_hardlink(cli
, fname
, fname_ln
);
4289 if (!NT_STATUS_IS_OK(status
)) {
4290 printf("nt hardlink failed (%s)\n", nt_errstr(status
));
4294 /* Open the original file. */
4295 status
= cli_ntcreate(cli
, fname
, 0, FILE_READ_DATA
,
4296 FILE_ATTRIBUTE_NORMAL
,
4297 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
4298 FILE_OPEN_IF
, 0, 0, &fnum
);
4299 if (!NT_STATUS_IS_OK(status
)) {
4300 printf("ntcreate of %s failed (%s)\n", fname
, nt_errstr(status
));
4304 /* Unlink the hard link path. */
4305 status
= cli_ntcreate(cli
, fname_ln
, 0, DELETE_ACCESS
,
4306 FILE_ATTRIBUTE_NORMAL
,
4307 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
4308 FILE_OPEN_IF
, 0, 0, &fnum1
);
4309 if (!NT_STATUS_IS_OK(status
)) {
4310 printf("ntcreate of %s failed (%s)\n", fname_ln
, nt_errstr(status
));
4313 status
= cli_nt_delete_on_close(cli
, fnum1
, true);
4314 if (!NT_STATUS_IS_OK(status
)) {
4315 d_printf("(%s) failed to set delete_on_close %s: %s\n",
4316 __location__
, fname_ln
, nt_errstr(status
));
4320 status
= cli_close(cli
, fnum1
);
4321 if (!NT_STATUS_IS_OK(status
)) {
4322 printf("close %s failed (%s)\n",
4323 fname_ln
, nt_errstr(status
));
4327 status
= cli_close(cli
, fnum
);
4328 if (!NT_STATUS_IS_OK(status
)) {
4329 printf("close %s failed (%s)\n",
4330 fname
, nt_errstr(status
));
4334 /* Ensure the original file is still there. */
4335 status
= cli_getatr(cli
, fname
, NULL
, NULL
, &t
);
4336 if (!NT_STATUS_IS_OK(status
)) {
4337 printf("%s getatr on file %s failed (%s)\n",
4344 /* Ensure the link path is gone. */
4345 status
= cli_getatr(cli
, fname_ln
, NULL
, NULL
, &t
);
4346 if (!NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
)) {
4347 printf("%s, getatr for file %s returned wrong error code %s "
4348 "- should have been deleted\n",
4350 fname_ln
, nt_errstr(status
));
4354 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4355 cli_unlink(cli
, fname_ln
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4357 if (!torture_close_connection(cli
)) {
4361 printf("finished deletetest-ln\n");
4367 print out server properties
4369 static bool run_properties(int dummy
)
4371 struct cli_state
*cli
;
4372 bool correct
= True
;
4374 printf("starting properties test\n");
4378 if (!torture_open_connection(&cli
, 0)) {
4382 cli_sockopt(cli
, sockops
);
4384 d_printf("Capabilities 0x%08x\n", cli
->capabilities
);
4386 if (!torture_close_connection(cli
)) {
4395 /* FIRST_DESIRED_ACCESS 0xf019f */
4396 #define FIRST_DESIRED_ACCESS FILE_READ_DATA|FILE_WRITE_DATA|FILE_APPEND_DATA|\
4397 FILE_READ_EA| /* 0xf */ \
4398 FILE_WRITE_EA|FILE_READ_ATTRIBUTES| /* 0x90 */ \
4399 FILE_WRITE_ATTRIBUTES| /* 0x100 */ \
4400 DELETE_ACCESS|READ_CONTROL_ACCESS|\
4401 WRITE_DAC_ACCESS|WRITE_OWNER_ACCESS /* 0xf0000 */
4402 /* SECOND_DESIRED_ACCESS 0xe0080 */
4403 #define SECOND_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
4404 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
4405 WRITE_OWNER_ACCESS /* 0xe0000 */
4408 #define THIRD_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
4409 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
4411 WRITE_OWNER_ACCESS /* */
4415 Test ntcreate calls made by xcopy
4417 static bool run_xcopy(int dummy
)
4419 static struct cli_state
*cli1
;
4420 const char *fname
= "\\test.txt";
4421 bool correct
= True
;
4422 uint16_t fnum1
, fnum2
;
4425 printf("starting xcopy test\n");
4427 if (!torture_open_connection(&cli1
, 0)) {
4431 status
= cli_ntcreate(cli1
, fname
, 0, FIRST_DESIRED_ACCESS
,
4432 FILE_ATTRIBUTE_ARCHIVE
, FILE_SHARE_NONE
,
4433 FILE_OVERWRITE_IF
, 0x4044, 0, &fnum1
);
4434 if (!NT_STATUS_IS_OK(status
)) {
4435 printf("First open failed - %s\n", nt_errstr(status
));
4439 status
= cli_ntcreate(cli1
, fname
, 0, SECOND_DESIRED_ACCESS
, 0,
4440 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
4441 FILE_OPEN
, 0x200000, 0, &fnum2
);
4442 if (!NT_STATUS_IS_OK(status
)) {
4443 printf("second open failed - %s\n", nt_errstr(status
));
4447 if (!torture_close_connection(cli1
)) {
4455 Test rename on files open with share delete and no share delete.
4457 static bool run_rename(int dummy
)
4459 static struct cli_state
*cli1
;
4460 const char *fname
= "\\test.txt";
4461 const char *fname1
= "\\test1.txt";
4462 bool correct
= True
;
4467 printf("starting rename test\n");
4469 if (!torture_open_connection(&cli1
, 0)) {
4473 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4474 cli_unlink(cli1
, fname1
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4476 status
= cli_ntcreate(cli1
, fname
, 0, GENERIC_READ_ACCESS
,
4477 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_READ
,
4478 FILE_OVERWRITE_IF
, 0, 0, &fnum1
);
4479 if (!NT_STATUS_IS_OK(status
)) {
4480 printf("First open failed - %s\n", nt_errstr(status
));
4484 status
= cli_rename(cli1
, fname
, fname1
);
4485 if (!NT_STATUS_IS_OK(status
)) {
4486 printf("First rename failed (SHARE_READ) (this is correct) - %s\n", nt_errstr(status
));
4488 printf("First rename succeeded (SHARE_READ) - this should have failed !\n");
4492 status
= cli_close(cli1
, fnum1
);
4493 if (!NT_STATUS_IS_OK(status
)) {
4494 printf("close - 1 failed (%s)\n", nt_errstr(status
));
4498 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4499 cli_unlink(cli1
, fname1
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4500 status
= cli_ntcreate(cli1
, fname
, 0, GENERIC_READ_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
4502 FILE_SHARE_DELETE
|FILE_SHARE_NONE
,
4504 FILE_SHARE_DELETE
|FILE_SHARE_READ
,
4506 FILE_OVERWRITE_IF
, 0, 0, &fnum1
);
4507 if (!NT_STATUS_IS_OK(status
)) {
4508 printf("Second open failed - %s\n", nt_errstr(status
));
4512 status
= cli_rename(cli1
, fname
, fname1
);
4513 if (!NT_STATUS_IS_OK(status
)) {
4514 printf("Second rename failed (SHARE_DELETE | SHARE_READ) - this should have succeeded - %s\n", nt_errstr(status
));
4517 printf("Second rename succeeded (SHARE_DELETE | SHARE_READ)\n");
4520 status
= cli_close(cli1
, fnum1
);
4521 if (!NT_STATUS_IS_OK(status
)) {
4522 printf("close - 2 failed (%s)\n", nt_errstr(status
));
4526 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4527 cli_unlink(cli1
, fname1
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4529 status
= cli_ntcreate(cli1
, fname
, 0, READ_CONTROL_ACCESS
,
4530 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_NONE
,
4531 FILE_OVERWRITE_IF
, 0, 0, &fnum1
);
4532 if (!NT_STATUS_IS_OK(status
)) {
4533 printf("Third open failed - %s\n", nt_errstr(status
));
4542 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1
, fname
, 0, DELETE_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
4543 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
, 0, 0, &fnum2
))) {
4544 printf("Fourth open failed - %s\n", cli_errstr(cli1
));
4547 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1
, fnum2
, true))) {
4548 printf("[8] setting delete_on_close on file failed !\n");
4552 if (!NT_STATUS_IS_OK(cli_close(cli1
, fnum2
))) {
4553 printf("close - 4 failed (%s)\n", cli_errstr(cli1
));
4559 status
= cli_rename(cli1
, fname
, fname1
);
4560 if (!NT_STATUS_IS_OK(status
)) {
4561 printf("Third rename failed (SHARE_NONE) - this should have succeeded - %s\n", nt_errstr(status
));
4564 printf("Third rename succeeded (SHARE_NONE)\n");
4567 status
= cli_close(cli1
, fnum1
);
4568 if (!NT_STATUS_IS_OK(status
)) {
4569 printf("close - 3 failed (%s)\n", nt_errstr(status
));
4573 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4574 cli_unlink(cli1
, fname1
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4578 status
= cli_ntcreate(cli1
, fname
, 0, GENERIC_READ_ACCESS
,
4579 FILE_ATTRIBUTE_NORMAL
,
4580 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
4581 FILE_OVERWRITE_IF
, 0, 0, &fnum1
);
4582 if (!NT_STATUS_IS_OK(status
)) {
4583 printf("Fourth open failed - %s\n", nt_errstr(status
));
4587 status
= cli_rename(cli1
, fname
, fname1
);
4588 if (!NT_STATUS_IS_OK(status
)) {
4589 printf("Fourth rename failed (SHARE_READ | SHARE_WRITE) (this is correct) - %s\n", nt_errstr(status
));
4591 printf("Fourth rename succeeded (SHARE_READ | SHARE_WRITE) - this should have failed !\n");
4595 status
= cli_close(cli1
, fnum1
);
4596 if (!NT_STATUS_IS_OK(status
)) {
4597 printf("close - 4 failed (%s)\n", nt_errstr(status
));
4601 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4602 cli_unlink(cli1
, fname1
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4606 status
= cli_ntcreate(cli1
, fname
, 0, GENERIC_READ_ACCESS
,
4607 FILE_ATTRIBUTE_NORMAL
,
4608 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
4609 FILE_OVERWRITE_IF
, 0, 0, &fnum1
);
4610 if (!NT_STATUS_IS_OK(status
)) {
4611 printf("Fifth open failed - %s\n", nt_errstr(status
));
4615 status
= cli_rename(cli1
, fname
, fname1
);
4616 if (!NT_STATUS_IS_OK(status
)) {
4617 printf("Fifth rename failed (SHARE_READ | SHARE_WRITE | SHARE_DELETE) - this should have succeeded - %s ! \n", nt_errstr(status
));
4620 printf("Fifth rename succeeded (SHARE_READ | SHARE_WRITE | SHARE_DELETE) (this is correct) - %s\n", nt_errstr(status
));
4624 * Now check if the first name still exists ...
4627 /* if (!NT_STATUS_OP(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
4628 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0, 0, &fnum2))) {
4629 printf("Opening original file after rename of open file fails: %s\n",
4633 printf("Opening original file after rename of open file works ...\n");
4634 (void)cli_close(cli1, fnum2);
4638 status
= cli_close(cli1
, fnum1
);
4639 if (!NT_STATUS_IS_OK(status
)) {
4640 printf("close - 5 failed (%s)\n", nt_errstr(status
));
4644 /* Check that the renamed file has FILE_ATTRIBUTE_ARCHIVE. */
4645 status
= cli_getatr(cli1
, fname1
, &attr
, NULL
, NULL
);
4646 if (!NT_STATUS_IS_OK(status
)) {
4647 printf("getatr on file %s failed - %s ! \n",
4648 fname1
, nt_errstr(status
));
4651 if (attr
!= FILE_ATTRIBUTE_ARCHIVE
) {
4652 printf("Renamed file %s has wrong attr 0x%x "
4653 "(should be 0x%x)\n",
4656 (unsigned int)FILE_ATTRIBUTE_ARCHIVE
);
4659 printf("Renamed file %s has archive bit set\n", fname1
);
4663 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4664 cli_unlink(cli1
, fname1
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4666 if (!torture_close_connection(cli1
)) {
4673 static bool run_pipe_number(int dummy
)
4675 struct cli_state
*cli1
;
4676 const char *pipe_name
= "\\SPOOLSS";
4681 printf("starting pipenumber test\n");
4682 if (!torture_open_connection(&cli1
, 0)) {
4686 cli_sockopt(cli1
, sockops
);
4688 status
= cli_ntcreate(cli1
, pipe_name
, 0, FILE_READ_DATA
,
4689 FILE_ATTRIBUTE_NORMAL
,
4690 FILE_SHARE_READ
|FILE_SHARE_WRITE
,
4691 FILE_OPEN_IF
, 0, 0, &fnum
);
4692 if (!NT_STATUS_IS_OK(status
)) {
4693 printf("Open of pipe %s failed with error (%s)\n", pipe_name
, nt_errstr(status
));
4697 printf("\r%6d", num_pipes
);
4700 printf("pipe_number test - we can open %d %s pipes.\n", num_pipes
, pipe_name
);
4701 torture_close_connection(cli1
);
4706 Test open mode returns on read-only files.
4708 static bool run_opentest(int dummy
)
4710 static struct cli_state
*cli1
;
4711 static struct cli_state
*cli2
;
4712 const char *fname
= "\\readonly.file";
4713 uint16_t fnum1
, fnum2
;
4716 bool correct
= True
;
4720 printf("starting open test\n");
4722 if (!torture_open_connection(&cli1
, 0)) {
4726 cli_setatr(cli1
, fname
, 0, 0);
4727 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4729 cli_sockopt(cli1
, sockops
);
4731 status
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
);
4732 if (!NT_STATUS_IS_OK(status
)) {
4733 printf("open of %s failed (%s)\n", fname
, nt_errstr(status
));
4737 status
= cli_close(cli1
, fnum1
);
4738 if (!NT_STATUS_IS_OK(status
)) {
4739 printf("close2 failed (%s)\n", nt_errstr(status
));
4743 status
= cli_setatr(cli1
, fname
, FILE_ATTRIBUTE_READONLY
, 0);
4744 if (!NT_STATUS_IS_OK(status
)) {
4745 printf("cli_setatr failed (%s)\n", nt_errstr(status
));
4749 status
= cli_open(cli1
, fname
, O_RDONLY
, DENY_WRITE
, &fnum1
);
4750 if (!NT_STATUS_IS_OK(status
)) {
4751 printf("open of %s failed (%s)\n", fname
, nt_errstr(status
));
4755 /* This will fail - but the error should be ERRnoaccess, not ERRbadshare. */
4756 cli_open(cli1
, fname
, O_RDWR
, DENY_ALL
, &fnum2
);
4758 if (check_error(__LINE__
, cli1
, ERRDOS
, ERRnoaccess
,
4759 NT_STATUS_ACCESS_DENIED
)) {
4760 printf("correct error code ERRDOS/ERRnoaccess returned\n");
4763 printf("finished open test 1\n");
4765 cli_close(cli1
, fnum1
);
4767 /* Now try not readonly and ensure ERRbadshare is returned. */
4769 cli_setatr(cli1
, fname
, 0, 0);
4771 status
= cli_open(cli1
, fname
, O_RDONLY
, DENY_WRITE
, &fnum1
);
4772 if (!NT_STATUS_IS_OK(status
)) {
4773 printf("open of %s failed (%s)\n", fname
, nt_errstr(status
));
4777 /* This will fail - but the error should be ERRshare. */
4778 cli_open(cli1
, fname
, O_RDWR
, DENY_ALL
, &fnum2
);
4780 if (check_error(__LINE__
, cli1
, ERRDOS
, ERRbadshare
,
4781 NT_STATUS_SHARING_VIOLATION
)) {
4782 printf("correct error code ERRDOS/ERRbadshare returned\n");
4785 status
= cli_close(cli1
, fnum1
);
4786 if (!NT_STATUS_IS_OK(status
)) {
4787 printf("close2 failed (%s)\n", nt_errstr(status
));
4791 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4793 printf("finished open test 2\n");
4795 /* Test truncate open disposition on file opened for read. */
4796 status
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum1
);
4797 if (!NT_STATUS_IS_OK(status
)) {
4798 printf("(3) open (1) of %s failed (%s)\n", fname
, nt_errstr(status
));
4802 /* write 20 bytes. */
4804 memset(buf
, '\0', 20);
4806 status
= cli_writeall(cli1
, fnum1
, 0, (uint8_t *)buf
, 0, 20, NULL
);
4807 if (!NT_STATUS_IS_OK(status
)) {
4808 printf("write failed (%s)\n", nt_errstr(status
));
4812 status
= cli_close(cli1
, fnum1
);
4813 if (!NT_STATUS_IS_OK(status
)) {
4814 printf("(3) close1 failed (%s)\n", nt_errstr(status
));
4818 /* Ensure size == 20. */
4819 status
= cli_getatr(cli1
, fname
, NULL
, &fsize
, NULL
);
4820 if (!NT_STATUS_IS_OK(status
)) {
4821 printf("(3) getatr failed (%s)\n", nt_errstr(status
));
4826 printf("(3) file size != 20\n");
4830 /* Now test if we can truncate a file opened for readonly. */
4831 status
= cli_open(cli1
, fname
, O_RDONLY
|O_TRUNC
, DENY_NONE
, &fnum1
);
4832 if (!NT_STATUS_IS_OK(status
)) {
4833 printf("(3) open (2) of %s failed (%s)\n", fname
, nt_errstr(status
));
4837 status
= cli_close(cli1
, fnum1
);
4838 if (!NT_STATUS_IS_OK(status
)) {
4839 printf("close2 failed (%s)\n", nt_errstr(status
));
4843 /* Ensure size == 0. */
4844 status
= cli_getatr(cli1
, fname
, NULL
, &fsize
, NULL
);
4845 if (!NT_STATUS_IS_OK(status
)) {
4846 printf("(3) getatr failed (%s)\n", nt_errstr(status
));
4851 printf("(3) file size != 0\n");
4854 printf("finished open test 3\n");
4856 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4858 printf("Do ctemp tests\n");
4859 status
= cli_ctemp(cli1
, talloc_tos(), "\\", &fnum1
, &tmp_path
);
4860 if (!NT_STATUS_IS_OK(status
)) {
4861 printf("ctemp failed (%s)\n", nt_errstr(status
));
4865 printf("ctemp gave path %s\n", tmp_path
);
4866 status
= cli_close(cli1
, fnum1
);
4867 if (!NT_STATUS_IS_OK(status
)) {
4868 printf("close of temp failed (%s)\n", nt_errstr(status
));
4871 status
= cli_unlink(cli1
, tmp_path
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4872 if (!NT_STATUS_IS_OK(status
)) {
4873 printf("unlink of temp failed (%s)\n", nt_errstr(status
));
4876 /* Test the non-io opens... */
4878 if (!torture_open_connection(&cli2
, 1)) {
4882 cli_setatr(cli2
, fname
, 0, 0);
4883 cli_unlink(cli2
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4885 cli_sockopt(cli2
, sockops
);
4887 printf("TEST #1 testing 2 non-io opens (no delete)\n");
4888 status
= cli_ntcreate(cli1
, fname
, 0, FILE_READ_ATTRIBUTES
,
4889 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_NONE
,
4890 FILE_OVERWRITE_IF
, 0, 0, &fnum1
);
4891 if (!NT_STATUS_IS_OK(status
)) {
4892 printf("TEST #1 open 1 of %s failed (%s)\n", fname
, nt_errstr(status
));
4896 status
= cli_ntcreate(cli2
, fname
, 0, FILE_READ_ATTRIBUTES
,
4897 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_NONE
,
4898 FILE_OPEN_IF
, 0, 0, &fnum2
);
4899 if (!NT_STATUS_IS_OK(status
)) {
4900 printf("TEST #1 open 2 of %s failed (%s)\n", fname
, nt_errstr(status
));
4904 status
= cli_close(cli1
, fnum1
);
4905 if (!NT_STATUS_IS_OK(status
)) {
4906 printf("TEST #1 close 1 of %s failed (%s)\n", fname
, nt_errstr(status
));
4910 status
= cli_close(cli2
, fnum2
);
4911 if (!NT_STATUS_IS_OK(status
)) {
4912 printf("TEST #1 close 2 of %s failed (%s)\n", fname
, nt_errstr(status
));
4916 printf("non-io open test #1 passed.\n");
4918 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4920 printf("TEST #2 testing 2 non-io opens (first with delete)\n");
4922 status
= cli_ntcreate(cli1
, fname
, 0,
4923 DELETE_ACCESS
|FILE_READ_ATTRIBUTES
,
4924 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_NONE
,
4925 FILE_OVERWRITE_IF
, 0, 0, &fnum1
);
4926 if (!NT_STATUS_IS_OK(status
)) {
4927 printf("TEST #2 open 1 of %s failed (%s)\n", fname
, nt_errstr(status
));
4931 status
= cli_ntcreate(cli2
, fname
, 0, FILE_READ_ATTRIBUTES
,
4932 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_NONE
,
4933 FILE_OPEN_IF
, 0, 0, &fnum2
);
4934 if (!NT_STATUS_IS_OK(status
)) {
4935 printf("TEST #2 open 2 of %s failed (%s)\n", fname
, nt_errstr(status
));
4939 status
= cli_close(cli1
, fnum1
);
4940 if (!NT_STATUS_IS_OK(status
)) {
4941 printf("TEST #2 close 1 of %s failed (%s)\n", fname
, nt_errstr(status
));
4945 status
= cli_close(cli2
, fnum2
);
4946 if (!NT_STATUS_IS_OK(status
)) {
4947 printf("TEST #2 close 2 of %s failed (%s)\n", fname
, nt_errstr(status
));
4951 printf("non-io open test #2 passed.\n");
4953 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4955 printf("TEST #3 testing 2 non-io opens (second with delete)\n");
4957 status
= cli_ntcreate(cli1
, fname
, 0, FILE_READ_ATTRIBUTES
,
4958 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_NONE
,
4959 FILE_OVERWRITE_IF
, 0, 0, &fnum1
);
4960 if (!NT_STATUS_IS_OK(status
)) {
4961 printf("TEST #3 open 1 of %s failed (%s)\n", fname
, nt_errstr(status
));
4965 status
= cli_ntcreate(cli2
, fname
, 0,
4966 DELETE_ACCESS
|FILE_READ_ATTRIBUTES
,
4967 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_NONE
,
4968 FILE_OPEN_IF
, 0, 0, &fnum2
);
4969 if (!NT_STATUS_IS_OK(status
)) {
4970 printf("TEST #3 open 2 of %s failed (%s)\n", fname
, nt_errstr(status
));
4974 status
= cli_close(cli1
, fnum1
);
4975 if (!NT_STATUS_IS_OK(status
)) {
4976 printf("TEST #3 close 1 of %s failed (%s)\n", fname
, nt_errstr(status
));
4980 status
= cli_close(cli2
, fnum2
);
4981 if (!NT_STATUS_IS_OK(status
)) {
4982 printf("TEST #3 close 2 of %s failed (%s)\n", fname
, nt_errstr(status
));
4986 printf("non-io open test #3 passed.\n");
4988 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
4990 printf("TEST #4 testing 2 non-io opens (both with delete)\n");
4992 status
= cli_ntcreate(cli1
, fname
, 0,
4993 DELETE_ACCESS
|FILE_READ_ATTRIBUTES
,
4994 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_NONE
,
4995 FILE_OVERWRITE_IF
, 0, 0, &fnum1
);
4996 if (!NT_STATUS_IS_OK(status
)) {
4997 printf("TEST #4 open 1 of %s failed (%s)\n", fname
, nt_errstr(status
));
5001 status
= cli_ntcreate(cli2
, fname
, 0,
5002 DELETE_ACCESS
|FILE_READ_ATTRIBUTES
,
5003 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_NONE
,
5004 FILE_OPEN_IF
, 0, 0, &fnum2
);
5005 if (NT_STATUS_IS_OK(status
)) {
5006 printf("TEST #4 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname
, nt_errstr(status
));
5010 printf("TEST #4 open 2 of %s gave %s (correct error should be %s)\n", fname
, nt_errstr(status
), "sharing violation");
5012 status
= cli_close(cli1
, fnum1
);
5013 if (!NT_STATUS_IS_OK(status
)) {
5014 printf("TEST #4 close 1 of %s failed (%s)\n", fname
, nt_errstr(status
));
5018 printf("non-io open test #4 passed.\n");
5020 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
5022 printf("TEST #5 testing 2 non-io opens (both with delete - both with file share delete)\n");
5024 status
= cli_ntcreate(cli1
, fname
, 0,
5025 DELETE_ACCESS
|FILE_READ_ATTRIBUTES
,
5026 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_DELETE
,
5027 FILE_OVERWRITE_IF
, 0, 0, &fnum1
);
5028 if (!NT_STATUS_IS_OK(status
)) {
5029 printf("TEST #5 open 1 of %s failed (%s)\n", fname
, nt_errstr(status
));
5033 status
= cli_ntcreate(cli2
, fname
, 0,
5034 DELETE_ACCESS
|FILE_READ_ATTRIBUTES
,
5035 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_DELETE
,
5036 FILE_OPEN_IF
, 0, 0, &fnum2
);
5037 if (!NT_STATUS_IS_OK(status
)) {
5038 printf("TEST #5 open 2 of %s failed (%s)\n", fname
, nt_errstr(status
));
5042 status
= cli_close(cli1
, fnum1
);
5043 if (!NT_STATUS_IS_OK(status
)) {
5044 printf("TEST #5 close 1 of %s failed (%s)\n", fname
, nt_errstr(status
));
5048 status
= cli_close(cli2
, fnum2
);
5049 if (!NT_STATUS_IS_OK(status
)) {
5050 printf("TEST #5 close 2 of %s failed (%s)\n", fname
, nt_errstr(status
));
5054 printf("non-io open test #5 passed.\n");
5056 printf("TEST #6 testing 1 non-io open, one io open\n");
5058 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
5060 status
= cli_ntcreate(cli1
, fname
, 0, FILE_READ_DATA
,
5061 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_NONE
,
5062 FILE_OVERWRITE_IF
, 0, 0, &fnum1
);
5063 if (!NT_STATUS_IS_OK(status
)) {
5064 printf("TEST #6 open 1 of %s failed (%s)\n", fname
, nt_errstr(status
));
5068 status
= cli_ntcreate(cli2
, fname
, 0, FILE_READ_ATTRIBUTES
,
5069 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_READ
,
5070 FILE_OPEN_IF
, 0, 0, &fnum2
);
5071 if (!NT_STATUS_IS_OK(status
)) {
5072 printf("TEST #6 open 2 of %s failed (%s)\n", fname
, nt_errstr(status
));
5076 status
= cli_close(cli1
, fnum1
);
5077 if (!NT_STATUS_IS_OK(status
)) {
5078 printf("TEST #6 close 1 of %s failed (%s)\n", fname
, nt_errstr(status
));
5082 status
= cli_close(cli2
, fnum2
);
5083 if (!NT_STATUS_IS_OK(status
)) {
5084 printf("TEST #6 close 2 of %s failed (%s)\n", fname
, nt_errstr(status
));
5088 printf("non-io open test #6 passed.\n");
5090 printf("TEST #7 testing 1 non-io open, one io open with delete\n");
5092 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
5094 status
= cli_ntcreate(cli1
, fname
, 0, FILE_READ_DATA
,
5095 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_NONE
,
5096 FILE_OVERWRITE_IF
, 0, 0, &fnum1
);
5097 if (!NT_STATUS_IS_OK(status
)) {
5098 printf("TEST #7 open 1 of %s failed (%s)\n", fname
, nt_errstr(status
));
5102 status
= cli_ntcreate(cli2
, fname
, 0,
5103 DELETE_ACCESS
|FILE_READ_ATTRIBUTES
,
5104 FILE_ATTRIBUTE_NORMAL
,
5105 FILE_SHARE_READ
|FILE_SHARE_DELETE
,
5106 FILE_OPEN_IF
, 0, 0, &fnum2
);
5107 if (NT_STATUS_IS_OK(status
)) {
5108 printf("TEST #7 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname
, nt_errstr(status
));
5112 printf("TEST #7 open 2 of %s gave %s (correct error should be %s)\n", fname
, nt_errstr(status
), "sharing violation");
5114 status
= cli_close(cli1
, fnum1
);
5115 if (!NT_STATUS_IS_OK(status
)) {
5116 printf("TEST #7 close 1 of %s failed (%s)\n", fname
, nt_errstr(status
));
5120 printf("non-io open test #7 passed.\n");
5122 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
5124 printf("TEST #8 testing open without WRITE_ATTRIBUTES, updating close write time.\n");
5125 status
= cli_ntcreate(cli1
, fname
, 0, FILE_WRITE_DATA
, FILE_ATTRIBUTE_NORMAL
,
5126 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
5127 FILE_OVERWRITE_IF
, 0, 0, &fnum1
);
5128 if (!NT_STATUS_IS_OK(status
)) {
5129 printf("TEST #8 open of %s failed (%s)\n", fname
, nt_errstr(status
));
5134 /* Write to ensure we have to update the file time. */
5135 status
= cli_writeall(cli1
, fnum1
, 0, (const uint8_t *)"TEST DATA\n", 0, 10,
5137 if (!NT_STATUS_IS_OK(status
)) {
5138 printf("TEST #8 cli_write failed: %s\n", nt_errstr(status
));
5143 status
= cli_close(cli1
, fnum1
);
5144 if (!NT_STATUS_IS_OK(status
)) {
5145 printf("TEST #8 close of %s failed (%s)\n", fname
, nt_errstr(status
));
5151 if (!torture_close_connection(cli1
)) {
5154 if (!torture_close_connection(cli2
)) {
5161 NTSTATUS
torture_setup_unix_extensions(struct cli_state
*cli
)
5163 uint16 major
, minor
;
5164 uint32 caplow
, caphigh
;
5167 if (!SERVER_HAS_UNIX_CIFS(cli
)) {
5168 printf("Server doesn't support UNIX CIFS extensions.\n");
5169 return NT_STATUS_NOT_SUPPORTED
;
5172 status
= cli_unix_extensions_version(cli
, &major
, &minor
, &caplow
,
5174 if (!NT_STATUS_IS_OK(status
)) {
5175 printf("Server didn't return UNIX CIFS extensions: %s\n",
5180 status
= cli_set_unix_extensions_capabilities(cli
, major
, minor
,
5182 if (!NT_STATUS_IS_OK(status
)) {
5183 printf("Server doesn't support setting UNIX CIFS extensions: "
5184 "%s.\n", nt_errstr(status
));
5188 return NT_STATUS_OK
;
5192 Test POSIX open /mkdir calls.
5194 static bool run_simple_posix_open_test(int dummy
)
5196 static struct cli_state
*cli1
;
5197 const char *fname
= "posix:file";
5198 const char *hname
= "posix:hlink";
5199 const char *sname
= "posix:symlink";
5200 const char *dname
= "posix:dir";
5203 uint16_t fnum1
= (uint16_t)-1;
5204 SMB_STRUCT_STAT sbuf
;
5205 bool correct
= false;
5208 printf("Starting simple POSIX open test\n");
5210 if (!torture_open_connection(&cli1
, 0)) {
5214 cli_sockopt(cli1
, sockops
);
5216 status
= torture_setup_unix_extensions(cli1
);
5217 if (!NT_STATUS_IS_OK(status
)) {
5221 cli_setatr(cli1
, fname
, 0, 0);
5222 cli_posix_unlink(cli1
, fname
);
5223 cli_setatr(cli1
, dname
, 0, 0);
5224 cli_posix_rmdir(cli1
, dname
);
5225 cli_setatr(cli1
, hname
, 0, 0);
5226 cli_posix_unlink(cli1
, hname
);
5227 cli_setatr(cli1
, sname
, 0, 0);
5228 cli_posix_unlink(cli1
, sname
);
5230 /* Create a directory. */
5231 status
= cli_posix_mkdir(cli1
, dname
, 0777);
5232 if (!NT_STATUS_IS_OK(status
)) {
5233 printf("POSIX mkdir of %s failed (%s)\n", dname
, nt_errstr(status
));
5237 status
= cli_posix_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
,
5239 if (!NT_STATUS_IS_OK(status
)) {
5240 printf("POSIX create of %s failed (%s)\n", fname
, nt_errstr(status
));
5244 /* Test ftruncate - set file size. */
5245 status
= cli_ftruncate(cli1
, fnum1
, 1000);
5246 if (!NT_STATUS_IS_OK(status
)) {
5247 printf("ftruncate failed (%s)\n", nt_errstr(status
));
5251 /* Ensure st_size == 1000 */
5252 status
= cli_posix_stat(cli1
, fname
, &sbuf
);
5253 if (!NT_STATUS_IS_OK(status
)) {
5254 printf("stat failed (%s)\n", nt_errstr(status
));
5258 if (sbuf
.st_ex_size
!= 1000) {
5259 printf("ftruncate - stat size (%u) != 1000\n", (unsigned int)sbuf
.st_ex_size
);
5263 /* Test ftruncate - set file size back to zero. */
5264 status
= cli_ftruncate(cli1
, fnum1
, 0);
5265 if (!NT_STATUS_IS_OK(status
)) {
5266 printf("ftruncate failed (%s)\n", nt_errstr(status
));
5270 status
= cli_close(cli1
, fnum1
);
5271 if (!NT_STATUS_IS_OK(status
)) {
5272 printf("close failed (%s)\n", nt_errstr(status
));
5276 /* Now open the file again for read only. */
5277 status
= cli_posix_open(cli1
, fname
, O_RDONLY
, 0, &fnum1
);
5278 if (!NT_STATUS_IS_OK(status
)) {
5279 printf("POSIX open of %s failed (%s)\n", fname
, nt_errstr(status
));
5283 /* Now unlink while open. */
5284 status
= cli_posix_unlink(cli1
, fname
);
5285 if (!NT_STATUS_IS_OK(status
)) {
5286 printf("POSIX unlink of %s failed (%s)\n", fname
, nt_errstr(status
));
5290 status
= cli_close(cli1
, fnum1
);
5291 if (!NT_STATUS_IS_OK(status
)) {
5292 printf("close(2) failed (%s)\n", nt_errstr(status
));
5296 /* Ensure the file has gone. */
5297 status
= cli_posix_open(cli1
, fname
, O_RDONLY
, 0, &fnum1
);
5298 if (NT_STATUS_IS_OK(status
)) {
5299 printf("POSIX open of %s succeeded, should have been deleted.\n", fname
);
5303 /* Create again to test open with O_TRUNC. */
5304 status
= cli_posix_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, 0600, &fnum1
);
5305 if (!NT_STATUS_IS_OK(status
)) {
5306 printf("POSIX create of %s failed (%s)\n", fname
, nt_errstr(status
));
5310 /* Test ftruncate - set file size. */
5311 status
= cli_ftruncate(cli1
, fnum1
, 1000);
5312 if (!NT_STATUS_IS_OK(status
)) {
5313 printf("ftruncate failed (%s)\n", nt_errstr(status
));
5317 /* Ensure st_size == 1000 */
5318 status
= cli_posix_stat(cli1
, fname
, &sbuf
);
5319 if (!NT_STATUS_IS_OK(status
)) {
5320 printf("stat failed (%s)\n", nt_errstr(status
));
5324 if (sbuf
.st_ex_size
!= 1000) {
5325 printf("ftruncate - stat size (%u) != 1000\n", (unsigned int)sbuf
.st_ex_size
);
5329 status
= cli_close(cli1
, fnum1
);
5330 if (!NT_STATUS_IS_OK(status
)) {
5331 printf("close(2) failed (%s)\n", nt_errstr(status
));
5335 /* Re-open with O_TRUNC. */
5336 status
= cli_posix_open(cli1
, fname
, O_WRONLY
|O_TRUNC
, 0600, &fnum1
);
5337 if (!NT_STATUS_IS_OK(status
)) {
5338 printf("POSIX create of %s failed (%s)\n", fname
, nt_errstr(status
));
5342 /* Ensure st_size == 0 */
5343 status
= cli_posix_stat(cli1
, fname
, &sbuf
);
5344 if (!NT_STATUS_IS_OK(status
)) {
5345 printf("stat failed (%s)\n", nt_errstr(status
));
5349 if (sbuf
.st_ex_size
!= 0) {
5350 printf("O_TRUNC - stat size (%u) != 0\n", (unsigned int)sbuf
.st_ex_size
);
5354 status
= cli_close(cli1
, fnum1
);
5355 if (!NT_STATUS_IS_OK(status
)) {
5356 printf("close failed (%s)\n", nt_errstr(status
));
5360 status
= cli_posix_unlink(cli1
, fname
);
5361 if (!NT_STATUS_IS_OK(status
)) {
5362 printf("POSIX unlink of %s failed (%s)\n", fname
, nt_errstr(status
));
5366 status
= cli_posix_open(cli1
, dname
, O_RDONLY
, 0, &fnum1
);
5367 if (!NT_STATUS_IS_OK(status
)) {
5368 printf("POSIX open directory O_RDONLY of %s failed (%s)\n",
5369 dname
, nt_errstr(status
));
5373 cli_close(cli1
, fnum1
);
5375 /* What happens when we try and POSIX open a directory for write ? */
5376 status
= cli_posix_open(cli1
, dname
, O_RDWR
, 0, &fnum1
);
5377 if (NT_STATUS_IS_OK(status
)) {
5378 printf("POSIX open of directory %s succeeded, should have failed.\n", fname
);
5381 if (!check_both_error(__LINE__
, status
, ERRDOS
, EISDIR
,
5382 NT_STATUS_FILE_IS_A_DIRECTORY
)) {
5387 /* Create the file. */
5388 status
= cli_posix_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
,
5390 if (!NT_STATUS_IS_OK(status
)) {
5391 printf("POSIX create of %s failed (%s)\n", fname
, nt_errstr(status
));
5395 /* Write some data into it. */
5396 status
= cli_writeall(cli1
, fnum1
, 0, (const uint8_t *)"TEST DATA\n", 0, 10,
5398 if (!NT_STATUS_IS_OK(status
)) {
5399 printf("cli_write failed: %s\n", nt_errstr(status
));
5403 cli_close(cli1
, fnum1
);
5405 /* Now create a hardlink. */
5406 status
= cli_posix_hardlink(cli1
, fname
, hname
);
5407 if (!NT_STATUS_IS_OK(status
)) {
5408 printf("POSIX hardlink of %s failed (%s)\n", hname
, nt_errstr(status
));
5412 /* Now create a symlink. */
5413 status
= cli_posix_symlink(cli1
, fname
, sname
);
5414 if (!NT_STATUS_IS_OK(status
)) {
5415 printf("POSIX symlink of %s failed (%s)\n", sname
, nt_errstr(status
));
5419 /* Open the hardlink for read. */
5420 status
= cli_posix_open(cli1
, hname
, O_RDONLY
, 0, &fnum1
);
5421 if (!NT_STATUS_IS_OK(status
)) {
5422 printf("POSIX open of %s failed (%s)\n", hname
, nt_errstr(status
));
5426 if (cli_read(cli1
, fnum1
, buf
, 0, 10) != 10) {
5427 printf("POSIX read of %s failed (%s)\n", hname
, cli_errstr(cli1
));
5431 if (memcmp(buf
, "TEST DATA\n", 10)) {
5432 printf("invalid data read from hardlink\n");
5436 /* Do a POSIX lock/unlock. */
5437 status
= cli_posix_lock(cli1
, fnum1
, 0, 100, true, READ_LOCK
);
5438 if (!NT_STATUS_IS_OK(status
)) {
5439 printf("POSIX lock failed %s\n", nt_errstr(status
));
5443 /* Punch a hole in the locked area. */
5444 status
= cli_posix_unlock(cli1
, fnum1
, 10, 80);
5445 if (!NT_STATUS_IS_OK(status
)) {
5446 printf("POSIX unlock failed %s\n", nt_errstr(status
));
5450 cli_close(cli1
, fnum1
);
5452 /* Open the symlink for read - this should fail. A POSIX
5453 client should not be doing opens on a symlink. */
5454 status
= cli_posix_open(cli1
, sname
, O_RDONLY
, 0, &fnum1
);
5455 if (NT_STATUS_IS_OK(status
)) {
5456 printf("POSIX open of %s succeeded (should have failed)\n", sname
);
5459 if (!check_both_error(__LINE__
, status
, ERRDOS
, ERRbadpath
,
5460 NT_STATUS_OBJECT_PATH_NOT_FOUND
)) {
5461 printf("POSIX open of %s should have failed "
5462 "with NT_STATUS_OBJECT_PATH_NOT_FOUND, "
5463 "failed with %s instead.\n",
5464 sname
, nt_errstr(status
));
5469 status
= cli_posix_readlink(cli1
, sname
, namebuf
, sizeof(namebuf
));
5470 if (!NT_STATUS_IS_OK(status
)) {
5471 printf("POSIX readlink on %s failed (%s)\n", sname
, nt_errstr(status
));
5475 if (strcmp(namebuf
, fname
) != 0) {
5476 printf("POSIX readlink on %s failed to match name %s (read %s)\n",
5477 sname
, fname
, namebuf
);
5481 status
= cli_posix_rmdir(cli1
, dname
);
5482 if (!NT_STATUS_IS_OK(status
)) {
5483 printf("POSIX rmdir failed (%s)\n", nt_errstr(status
));
5487 printf("Simple POSIX open test passed\n");
5492 if (fnum1
!= (uint16_t)-1) {
5493 cli_close(cli1
, fnum1
);
5494 fnum1
= (uint16_t)-1;
5497 cli_setatr(cli1
, sname
, 0, 0);
5498 cli_posix_unlink(cli1
, sname
);
5499 cli_setatr(cli1
, hname
, 0, 0);
5500 cli_posix_unlink(cli1
, hname
);
5501 cli_setatr(cli1
, fname
, 0, 0);
5502 cli_posix_unlink(cli1
, fname
);
5503 cli_setatr(cli1
, dname
, 0, 0);
5504 cli_posix_rmdir(cli1
, dname
);
5506 if (!torture_close_connection(cli1
)) {
5514 static uint32 open_attrs_table
[] = {
5515 FILE_ATTRIBUTE_NORMAL
,
5516 FILE_ATTRIBUTE_ARCHIVE
,
5517 FILE_ATTRIBUTE_READONLY
,
5518 FILE_ATTRIBUTE_HIDDEN
,
5519 FILE_ATTRIBUTE_SYSTEM
,
5521 FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
,
5522 FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
,
5523 FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
,
5524 FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
,
5525 FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_SYSTEM
,
5526 FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_SYSTEM
,
5528 FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
,
5529 FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_SYSTEM
,
5530 FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_SYSTEM
,
5531 FILE_ATTRIBUTE_HIDDEN
,FILE_ATTRIBUTE_SYSTEM
,
5534 struct trunc_open_results
{
5541 static struct trunc_open_results attr_results
[] = {
5542 { 0, FILE_ATTRIBUTE_NORMAL
, FILE_ATTRIBUTE_NORMAL
, FILE_ATTRIBUTE_ARCHIVE
},
5543 { 1, FILE_ATTRIBUTE_NORMAL
, FILE_ATTRIBUTE_ARCHIVE
, FILE_ATTRIBUTE_ARCHIVE
},
5544 { 2, FILE_ATTRIBUTE_NORMAL
, FILE_ATTRIBUTE_READONLY
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
},
5545 { 16, FILE_ATTRIBUTE_ARCHIVE
, FILE_ATTRIBUTE_NORMAL
, FILE_ATTRIBUTE_ARCHIVE
},
5546 { 17, FILE_ATTRIBUTE_ARCHIVE
, FILE_ATTRIBUTE_ARCHIVE
, FILE_ATTRIBUTE_ARCHIVE
},
5547 { 18, FILE_ATTRIBUTE_ARCHIVE
, FILE_ATTRIBUTE_READONLY
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
},
5548 { 51, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
},
5549 { 54, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
},
5550 { 56, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
},
5551 { 68, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
},
5552 { 71, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
},
5553 { 73, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_SYSTEM
},
5554 { 99, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_HIDDEN
,FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
},
5555 { 102, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
},
5556 { 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
},
5557 { 116, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
},
5558 { 119, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
},
5559 { 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
},
5560 { 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
},
5561 { 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
},
5562 { 227, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
},
5563 { 230, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
},
5564 { 232, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
},
5565 { 244, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
},
5566 { 247, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
},
5567 { 249, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_SYSTEM
}
5570 static bool run_openattrtest(int dummy
)
5572 static struct cli_state
*cli1
;
5573 const char *fname
= "\\openattr.file";
5575 bool correct
= True
;
5577 unsigned int i
, j
, k
, l
;
5580 printf("starting open attr test\n");
5582 if (!torture_open_connection(&cli1
, 0)) {
5586 cli_sockopt(cli1
, sockops
);
5588 for (k
= 0, i
= 0; i
< sizeof(open_attrs_table
)/sizeof(uint32
); i
++) {
5589 cli_setatr(cli1
, fname
, 0, 0);
5590 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
5592 status
= cli_ntcreate(cli1
, fname
, 0, FILE_WRITE_DATA
,
5593 open_attrs_table
[i
], FILE_SHARE_NONE
,
5594 FILE_OVERWRITE_IF
, 0, 0, &fnum1
);
5595 if (!NT_STATUS_IS_OK(status
)) {
5596 printf("open %d (1) of %s failed (%s)\n", i
, fname
, nt_errstr(status
));
5600 status
= cli_close(cli1
, fnum1
);
5601 if (!NT_STATUS_IS_OK(status
)) {
5602 printf("close %d (1) of %s failed (%s)\n", i
, fname
, nt_errstr(status
));
5606 for (j
= 0; j
< sizeof(open_attrs_table
)/sizeof(uint32
); j
++) {
5607 status
= cli_ntcreate(cli1
, fname
, 0,
5608 FILE_READ_DATA
|FILE_WRITE_DATA
,
5609 open_attrs_table
[j
],
5610 FILE_SHARE_NONE
, FILE_OVERWRITE
,
5612 if (!NT_STATUS_IS_OK(status
)) {
5613 for (l
= 0; l
< sizeof(attr_results
)/sizeof(struct trunc_open_results
); l
++) {
5614 if (attr_results
[l
].num
== k
) {
5615 printf("[%d] trunc open 0x%x -> 0x%x of %s failed - should have succeeded !(0x%x:%s)\n",
5616 k
, open_attrs_table
[i
],
5617 open_attrs_table
[j
],
5618 fname
, NT_STATUS_V(status
), nt_errstr(status
));
5623 if (!NT_STATUS_EQUAL(status
, NT_STATUS_ACCESS_DENIED
)) {
5624 printf("[%d] trunc open 0x%x -> 0x%x failed with wrong error code %s\n",
5625 k
, open_attrs_table
[i
], open_attrs_table
[j
],
5630 printf("[%d] trunc open 0x%x -> 0x%x failed\n", k
, open_attrs_table
[i
], open_attrs_table
[j
]);
5636 status
= cli_close(cli1
, fnum1
);
5637 if (!NT_STATUS_IS_OK(status
)) {
5638 printf("close %d (2) of %s failed (%s)\n", j
, fname
, nt_errstr(status
));
5642 status
= cli_getatr(cli1
, fname
, &attr
, NULL
, NULL
);
5643 if (!NT_STATUS_IS_OK(status
)) {
5644 printf("getatr(2) failed (%s)\n", nt_errstr(status
));
5649 printf("[%d] getatr check [0x%x] trunc [0x%x] got attr 0x%x\n",
5650 k
, open_attrs_table
[i
], open_attrs_table
[j
], attr
);
5653 for (l
= 0; l
< sizeof(attr_results
)/sizeof(struct trunc_open_results
); l
++) {
5654 if (attr_results
[l
].num
== k
) {
5655 if (attr
!= attr_results
[l
].result_attr
||
5656 open_attrs_table
[i
] != attr_results
[l
].init_attr
||
5657 open_attrs_table
[j
] != attr_results
[l
].trunc_attr
) {
5658 printf("getatr check failed. [0x%x] trunc [0x%x] got attr 0x%x, should be 0x%x\n",
5659 open_attrs_table
[i
],
5660 open_attrs_table
[j
],
5662 attr_results
[l
].result_attr
);
5672 cli_setatr(cli1
, fname
, 0, 0);
5673 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
5675 printf("open attr test %s.\n", correct
? "passed" : "failed");
5677 if (!torture_close_connection(cli1
)) {
5683 static NTSTATUS
list_fn(const char *mnt
, struct file_info
*finfo
,
5684 const char *name
, void *state
)
5686 int *matched
= (int *)state
;
5687 if (matched
!= NULL
) {
5690 return NT_STATUS_OK
;
5694 test directory listing speed
5696 static bool run_dirtest(int dummy
)
5699 static struct cli_state
*cli
;
5701 struct timeval core_start
;
5702 bool correct
= True
;
5705 printf("starting directory test\n");
5707 if (!torture_open_connection(&cli
, 0)) {
5711 cli_sockopt(cli
, sockops
);
5714 for (i
=0;i
<torture_numops
;i
++) {
5716 slprintf(fname
, sizeof(fname
), "\\%x", (int)random());
5717 if (!NT_STATUS_IS_OK(cli_open(cli
, fname
, O_RDWR
|O_CREAT
, DENY_NONE
, &fnum
))) {
5718 fprintf(stderr
,"Failed to open %s\n", fname
);
5721 cli_close(cli
, fnum
);
5724 core_start
= timeval_current();
5727 cli_list(cli
, "a*.*", 0, list_fn
, &matched
);
5728 printf("Matched %d\n", matched
);
5731 cli_list(cli
, "b*.*", 0, list_fn
, &matched
);
5732 printf("Matched %d\n", matched
);
5735 cli_list(cli
, "xyzabc", 0, list_fn
, &matched
);
5736 printf("Matched %d\n", matched
);
5738 printf("dirtest core %g seconds\n", timeval_elapsed(&core_start
));
5741 for (i
=0;i
<torture_numops
;i
++) {
5743 slprintf(fname
, sizeof(fname
), "\\%x", (int)random());
5744 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
5747 if (!torture_close_connection(cli
)) {
5751 printf("finished dirtest\n");
5756 static NTSTATUS
del_fn(const char *mnt
, struct file_info
*finfo
, const char *mask
,
5759 struct cli_state
*pcli
= (struct cli_state
*)state
;
5761 slprintf(fname
, sizeof(fname
), "\\LISTDIR\\%s", finfo
->name
);
5763 if (strcmp(finfo
->name
, ".") == 0 || strcmp(finfo
->name
, "..") == 0)
5764 return NT_STATUS_OK
;
5766 if (finfo
->mode
& FILE_ATTRIBUTE_DIRECTORY
) {
5767 if (!NT_STATUS_IS_OK(cli_rmdir(pcli
, fname
)))
5768 printf("del_fn: failed to rmdir %s\n,", fname
);
5770 if (!NT_STATUS_IS_OK(cli_unlink(pcli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
)))
5771 printf("del_fn: failed to unlink %s\n,", fname
);
5773 return NT_STATUS_OK
;
5778 sees what IOCTLs are supported
5780 bool torture_ioctl_test(int dummy
)
5782 static struct cli_state
*cli
;
5783 uint16_t device
, function
;
5785 const char *fname
= "\\ioctl.dat";
5789 if (!torture_open_connection(&cli
, 0)) {
5793 printf("starting ioctl test\n");
5795 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
5797 status
= cli_open(cli
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum
);
5798 if (!NT_STATUS_IS_OK(status
)) {
5799 printf("open of %s failed (%s)\n", fname
, nt_errstr(status
));
5803 status
= cli_raw_ioctl(cli
, fnum
, 0x2d0000 | (0x0420<<2), &blob
);
5804 printf("ioctl device info: %s\n", nt_errstr(status
));
5806 status
= cli_raw_ioctl(cli
, fnum
, IOCTL_QUERY_JOB_INFO
, &blob
);
5807 printf("ioctl job info: %s\n", nt_errstr(status
));
5809 for (device
=0;device
<0x100;device
++) {
5810 printf("ioctl test with device = 0x%x\n", device
);
5811 for (function
=0;function
<0x100;function
++) {
5812 uint32 code
= (device
<<16) | function
;
5814 status
= cli_raw_ioctl(cli
, fnum
, code
, &blob
);
5816 if (NT_STATUS_IS_OK(status
)) {
5817 printf("ioctl 0x%x OK : %d bytes\n", (int)code
,
5819 data_blob_free(&blob
);
5824 if (!torture_close_connection(cli
)) {
5833 tries varients of chkpath
5835 bool torture_chkpath_test(int dummy
)
5837 static struct cli_state
*cli
;
5842 if (!torture_open_connection(&cli
, 0)) {
5846 printf("starting chkpath test\n");
5848 /* cleanup from an old run */
5849 cli_rmdir(cli
, "\\chkpath.dir\\dir2");
5850 cli_unlink(cli
, "\\chkpath.dir\\*", FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
5851 cli_rmdir(cli
, "\\chkpath.dir");
5853 status
= cli_mkdir(cli
, "\\chkpath.dir");
5854 if (!NT_STATUS_IS_OK(status
)) {
5855 printf("mkdir1 failed : %s\n", nt_errstr(status
));
5859 status
= cli_mkdir(cli
, "\\chkpath.dir\\dir2");
5860 if (!NT_STATUS_IS_OK(status
)) {
5861 printf("mkdir2 failed : %s\n", nt_errstr(status
));
5865 status
= cli_open(cli
, "\\chkpath.dir\\foo.txt", O_RDWR
|O_CREAT
|O_EXCL
,
5867 if (!NT_STATUS_IS_OK(status
)) {
5868 printf("open1 failed (%s)\n", nt_errstr(status
));
5871 cli_close(cli
, fnum
);
5873 status
= cli_chkpath(cli
, "\\chkpath.dir");
5874 if (!NT_STATUS_IS_OK(status
)) {
5875 printf("chkpath1 failed: %s\n", nt_errstr(status
));
5879 status
= cli_chkpath(cli
, "\\chkpath.dir\\dir2");
5880 if (!NT_STATUS_IS_OK(status
)) {
5881 printf("chkpath2 failed: %s\n", nt_errstr(status
));
5885 status
= cli_chkpath(cli
, "\\chkpath.dir\\foo.txt");
5886 if (!NT_STATUS_IS_OK(status
)) {
5887 ret
= check_error(__LINE__
, cli
, ERRDOS
, ERRbadpath
,
5888 NT_STATUS_NOT_A_DIRECTORY
);
5890 printf("* chkpath on a file should fail\n");
5894 if (!NT_STATUS_IS_OK(cli_chkpath(cli
, "\\chkpath.dir\\bar.txt"))) {
5895 ret
= check_error(__LINE__
, cli
, ERRDOS
, ERRbadfile
,
5896 NT_STATUS_OBJECT_NAME_NOT_FOUND
);
5898 printf("* chkpath on a non existant file should fail\n");
5902 if (!NT_STATUS_IS_OK(cli_chkpath(cli
, "\\chkpath.dir\\dirxx\\bar.txt"))) {
5903 ret
= check_error(__LINE__
, cli
, ERRDOS
, ERRbadpath
,
5904 NT_STATUS_OBJECT_PATH_NOT_FOUND
);
5906 printf("* chkpath on a non existent component should fail\n");
5910 cli_rmdir(cli
, "\\chkpath.dir\\dir2");
5911 cli_unlink(cli
, "\\chkpath.dir\\*", FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
5912 cli_rmdir(cli
, "\\chkpath.dir");
5914 if (!torture_close_connection(cli
)) {
5921 static bool run_eatest(int dummy
)
5923 static struct cli_state
*cli
;
5924 const char *fname
= "\\eatest.txt";
5925 bool correct
= True
;
5929 struct ea_struct
*ea_list
= NULL
;
5930 TALLOC_CTX
*mem_ctx
= talloc_init("eatest");
5933 printf("starting eatest\n");
5935 if (!torture_open_connection(&cli
, 0)) {
5936 talloc_destroy(mem_ctx
);
5940 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
5942 status
= cli_ntcreate(cli
, fname
, 0,
5943 FIRST_DESIRED_ACCESS
, FILE_ATTRIBUTE_ARCHIVE
,
5944 FILE_SHARE_NONE
, FILE_OVERWRITE_IF
,
5946 if (!NT_STATUS_IS_OK(status
)) {
5947 printf("open failed - %s\n", nt_errstr(status
));
5948 talloc_destroy(mem_ctx
);
5952 for (i
= 0; i
< 10; i
++) {
5953 fstring ea_name
, ea_val
;
5955 slprintf(ea_name
, sizeof(ea_name
), "EA_%d", i
);
5956 memset(ea_val
, (char)i
+1, i
+1);
5957 status
= cli_set_ea_fnum(cli
, fnum
, ea_name
, ea_val
, i
+1);
5958 if (!NT_STATUS_IS_OK(status
)) {
5959 printf("ea_set of name %s failed - %s\n", ea_name
,
5961 talloc_destroy(mem_ctx
);
5966 cli_close(cli
, fnum
);
5967 for (i
= 0; i
< 10; i
++) {
5968 fstring ea_name
, ea_val
;
5970 slprintf(ea_name
, sizeof(ea_name
), "EA_%d", i
+10);
5971 memset(ea_val
, (char)i
+1, i
+1);
5972 status
= cli_set_ea_path(cli
, fname
, ea_name
, ea_val
, i
+1);
5973 if (!NT_STATUS_IS_OK(status
)) {
5974 printf("ea_set of name %s failed - %s\n", ea_name
,
5976 talloc_destroy(mem_ctx
);
5981 status
= cli_get_ea_list_path(cli
, fname
, mem_ctx
, &num_eas
, &ea_list
);
5982 if (!NT_STATUS_IS_OK(status
)) {
5983 printf("ea_get list failed - %s\n", nt_errstr(status
));
5987 printf("num_eas = %d\n", (int)num_eas
);
5989 if (num_eas
!= 20) {
5990 printf("Should be 20 EA's stored... failing.\n");
5994 for (i
= 0; i
< num_eas
; i
++) {
5995 printf("%d: ea_name = %s. Val = ", i
, ea_list
[i
].name
);
5996 dump_data(0, ea_list
[i
].value
.data
,
5997 ea_list
[i
].value
.length
);
6000 /* Setting EA's to zero length deletes them. Test this */
6001 printf("Now deleting all EA's - case indepenent....\n");
6004 cli_set_ea_path(cli
, fname
, "", "", 0);
6006 for (i
= 0; i
< 20; i
++) {
6008 slprintf(ea_name
, sizeof(ea_name
), "ea_%d", i
);
6009 status
= cli_set_ea_path(cli
, fname
, ea_name
, "", 0);
6010 if (!NT_STATUS_IS_OK(status
)) {
6011 printf("ea_set of name %s failed - %s\n", ea_name
,
6013 talloc_destroy(mem_ctx
);
6019 status
= cli_get_ea_list_path(cli
, fname
, mem_ctx
, &num_eas
, &ea_list
);
6020 if (!NT_STATUS_IS_OK(status
)) {
6021 printf("ea_get list failed - %s\n", nt_errstr(status
));
6025 printf("num_eas = %d\n", (int)num_eas
);
6026 for (i
= 0; i
< num_eas
; i
++) {
6027 printf("%d: ea_name = %s. Val = ", i
, ea_list
[i
].name
);
6028 dump_data(0, ea_list
[i
].value
.data
,
6029 ea_list
[i
].value
.length
);
6033 printf("deleting EA's failed.\n");
6037 /* Try and delete a non existant EA. */
6038 status
= cli_set_ea_path(cli
, fname
, "foo", "", 0);
6039 if (!NT_STATUS_IS_OK(status
)) {
6040 printf("deleting non-existant EA 'foo' should succeed. %s\n",
6045 talloc_destroy(mem_ctx
);
6046 if (!torture_close_connection(cli
)) {
6053 static bool run_dirtest1(int dummy
)
6056 static struct cli_state
*cli
;
6059 bool correct
= True
;
6061 printf("starting directory test\n");
6063 if (!torture_open_connection(&cli
, 0)) {
6067 cli_sockopt(cli
, sockops
);
6069 cli_list(cli
, "\\LISTDIR\\*", 0, del_fn
, cli
);
6070 cli_list(cli
, "\\LISTDIR\\*", FILE_ATTRIBUTE_DIRECTORY
, del_fn
, cli
);
6071 cli_rmdir(cli
, "\\LISTDIR");
6072 cli_mkdir(cli
, "\\LISTDIR");
6074 /* Create 1000 files and 1000 directories. */
6075 for (i
=0;i
<1000;i
++) {
6077 slprintf(fname
, sizeof(fname
), "\\LISTDIR\\f%d", i
);
6078 if (!NT_STATUS_IS_OK(cli_ntcreate(cli
, fname
, 0, GENERIC_ALL_ACCESS
, FILE_ATTRIBUTE_ARCHIVE
,
6079 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OVERWRITE_IF
, 0, 0, &fnum
))) {
6080 fprintf(stderr
,"Failed to open %s\n", fname
);
6083 cli_close(cli
, fnum
);
6085 for (i
=0;i
<1000;i
++) {
6087 slprintf(fname
, sizeof(fname
), "\\LISTDIR\\d%d", i
);
6088 if (!NT_STATUS_IS_OK(cli_mkdir(cli
, fname
))) {
6089 fprintf(stderr
,"Failed to open %s\n", fname
);
6094 /* Now ensure that doing an old list sees both files and directories. */
6096 cli_list_old(cli
, "\\LISTDIR\\*", FILE_ATTRIBUTE_DIRECTORY
, list_fn
, &num_seen
);
6097 printf("num_seen = %d\n", num_seen
);
6098 /* We should see 100 files + 1000 directories + . and .. */
6099 if (num_seen
!= 2002)
6102 /* Ensure if we have the "must have" bits we only see the
6106 cli_list_old(cli
, "\\LISTDIR\\*", (FILE_ATTRIBUTE_DIRECTORY
<<8)|FILE_ATTRIBUTE_DIRECTORY
, list_fn
, &num_seen
);
6107 printf("num_seen = %d\n", num_seen
);
6108 if (num_seen
!= 1002)
6112 cli_list_old(cli
, "\\LISTDIR\\*", (FILE_ATTRIBUTE_ARCHIVE
<<8)|FILE_ATTRIBUTE_DIRECTORY
, list_fn
, &num_seen
);
6113 printf("num_seen = %d\n", num_seen
);
6114 if (num_seen
!= 1000)
6117 /* Delete everything. */
6118 cli_list(cli
, "\\LISTDIR\\*", 0, del_fn
, cli
);
6119 cli_list(cli
, "\\LISTDIR\\*", FILE_ATTRIBUTE_DIRECTORY
, del_fn
, cli
);
6120 cli_rmdir(cli
, "\\LISTDIR");
6123 printf("Matched %d\n", cli_list(cli
, "a*.*", 0, list_fn
, NULL
));
6124 printf("Matched %d\n", cli_list(cli
, "b*.*", 0, list_fn
, NULL
));
6125 printf("Matched %d\n", cli_list(cli
, "xyzabc", 0, list_fn
, NULL
));
6128 if (!torture_close_connection(cli
)) {
6132 printf("finished dirtest1\n");
6137 static bool run_error_map_extract(int dummy
) {
6139 static struct cli_state
*c_dos
;
6140 static struct cli_state
*c_nt
;
6152 /* NT-Error connection */
6154 if (!(c_nt
= open_nbt_connection())) {
6158 c_nt
->use_spnego
= False
;
6160 status
= cli_negprot(c_nt
);
6162 if (!NT_STATUS_IS_OK(status
)) {
6163 printf("%s rejected the NT-error negprot (%s)\n", host
,
6169 status
= cli_session_setup(c_nt
, "", "", 0, "", 0, workgroup
);
6170 if (!NT_STATUS_IS_OK(status
)) {
6171 printf("%s rejected the NT-error initial session setup (%s)\n",host
, nt_errstr(status
));
6175 /* DOS-Error connection */
6177 if (!(c_dos
= open_nbt_connection())) {
6181 c_dos
->use_spnego
= False
;
6182 c_dos
->force_dos_errors
= True
;
6184 status
= cli_negprot(c_dos
);
6185 if (!NT_STATUS_IS_OK(status
)) {
6186 printf("%s rejected the DOS-error negprot (%s)\n", host
,
6188 cli_shutdown(c_dos
);
6192 status
= cli_session_setup(c_dos
, "", "", 0, "", 0, workgroup
);
6193 if (!NT_STATUS_IS_OK(status
)) {
6194 printf("%s rejected the DOS-error initial session setup (%s)\n",
6195 host
, nt_errstr(status
));
6199 for (error
=(0xc0000000 | 0x1); error
< (0xc0000000| 0xFFF); error
++) {
6200 fstr_sprintf(user
, "%X", error
);
6202 status
= cli_session_setup(c_nt
, user
,
6203 password
, strlen(password
),
6204 password
, strlen(password
),
6206 if (NT_STATUS_IS_OK(status
)) {
6207 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
6210 /* Case #1: 32-bit NT errors */
6211 if (cli_is_nt_error(c_nt
)) {
6212 nt_status
= cli_nt_error(c_nt
);
6214 printf("/** Dos error on NT connection! (%s) */\n",
6216 nt_status
= NT_STATUS(0xc0000000);
6219 status
= cli_session_setup(c_dos
, user
,
6220 password
, strlen(password
),
6221 password
, strlen(password
),
6223 if (NT_STATUS_IS_OK(status
)) {
6224 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
6227 /* Case #1: 32-bit NT errors */
6228 if (!cli_is_dos_error(c_dos
)) {
6229 printf("/** NT error on DOS connection! (%s) */\n",
6231 errnum
= errclass
= 0;
6233 cli_dos_error(c_dos
, &errclass
, &errnum
);
6236 if (NT_STATUS_V(nt_status
) != error
) {
6237 printf("/*\t{ This NT error code was 'sqashed'\n\t from %s to %s \n\t during the session setup }\n*/\n",
6238 get_nt_error_c_code(talloc_tos(), NT_STATUS(error
)),
6239 get_nt_error_c_code(talloc_tos(), nt_status
));
6242 printf("\t{%s,\t%s,\t%s},\n",
6243 smb_dos_err_class(errclass
),
6244 smb_dos_err_name(errclass
, errnum
),
6245 get_nt_error_c_code(talloc_tos(), NT_STATUS(error
)));
6250 static bool run_sesssetup_bench(int dummy
)
6252 static struct cli_state
*c
;
6253 const char *fname
= "\\file.dat";
6258 if (!torture_open_connection(&c
, 0)) {
6262 status
= cli_ntcreate(c
, fname
, 0, GENERIC_ALL_ACCESS
|DELETE_ACCESS
,
6263 FILE_ATTRIBUTE_NORMAL
, 0, FILE_OVERWRITE_IF
,
6264 FILE_DELETE_ON_CLOSE
, 0, &fnum
);
6265 if (!NT_STATUS_IS_OK(status
)) {
6266 d_printf("open %s failed: %s\n", fname
, nt_errstr(status
));
6270 for (i
=0; i
<torture_numops
; i
++) {
6271 status
= cli_session_setup(
6273 password
, strlen(password
),
6274 password
, strlen(password
),
6276 if (!NT_STATUS_IS_OK(status
)) {
6277 d_printf("(%s) cli_session_setup failed: %s\n",
6278 __location__
, nt_errstr(status
));
6282 d_printf("\r%d ", (int)c
->vuid
);
6284 status
= cli_ulogoff(c
);
6285 if (!NT_STATUS_IS_OK(status
)) {
6286 d_printf("(%s) cli_ulogoff failed: %s\n",
6287 __location__
, nt_errstr(status
));
6296 static bool subst_test(const char *str
, const char *user
, const char *domain
,
6297 uid_t uid
, gid_t gid
, const char *expected
)
6302 subst
= talloc_sub_specified(talloc_tos(), str
, user
, domain
, uid
, gid
);
6304 if (strcmp(subst
, expected
) != 0) {
6305 printf("sub_specified(%s, %s, %s, %d, %d) returned [%s], expected "
6306 "[%s]\n", str
, user
, domain
, (int)uid
, (int)gid
, subst
,
6315 static void chain1_open_completion(struct tevent_req
*req
)
6319 status
= cli_open_recv(req
, &fnum
);
6322 d_printf("cli_open_recv returned %s: %d\n",
6324 NT_STATUS_IS_OK(status
) ? fnum
: -1);
6327 static void chain1_write_completion(struct tevent_req
*req
)
6331 status
= cli_write_andx_recv(req
, &written
);
6334 d_printf("cli_write_andx_recv returned %s: %d\n",
6336 NT_STATUS_IS_OK(status
) ? (int)written
: -1);
6339 static void chain1_close_completion(struct tevent_req
*req
)
6342 bool *done
= (bool *)tevent_req_callback_data_void(req
);
6344 status
= cli_close_recv(req
);
6349 d_printf("cli_close returned %s\n", nt_errstr(status
));
6352 static bool run_chain1(int dummy
)
6354 struct cli_state
*cli1
;
6355 struct event_context
*evt
= event_context_init(NULL
);
6356 struct tevent_req
*reqs
[3], *smbreqs
[3];
6358 const char *str
= "foobar";
6361 printf("starting chain1 test\n");
6362 if (!torture_open_connection(&cli1
, 0)) {
6366 cli_sockopt(cli1
, sockops
);
6368 reqs
[0] = cli_open_create(talloc_tos(), evt
, cli1
, "\\test",
6369 O_CREAT
|O_RDWR
, 0, &smbreqs
[0]);
6370 if (reqs
[0] == NULL
) return false;
6371 tevent_req_set_callback(reqs
[0], chain1_open_completion
, NULL
);
6374 reqs
[1] = cli_write_andx_create(talloc_tos(), evt
, cli1
, 0, 0,
6375 (const uint8_t *)str
, 0, strlen(str
)+1,
6376 smbreqs
, 1, &smbreqs
[1]);
6377 if (reqs
[1] == NULL
) return false;
6378 tevent_req_set_callback(reqs
[1], chain1_write_completion
, NULL
);
6380 reqs
[2] = cli_close_create(talloc_tos(), evt
, cli1
, 0, &smbreqs
[2]);
6381 if (reqs
[2] == NULL
) return false;
6382 tevent_req_set_callback(reqs
[2], chain1_close_completion
, &done
);
6384 status
= cli_smb_chain_send(smbreqs
, ARRAY_SIZE(smbreqs
));
6385 if (!NT_STATUS_IS_OK(status
)) {
6390 event_loop_once(evt
);
6393 torture_close_connection(cli1
);
6397 static void chain2_sesssetup_completion(struct tevent_req
*req
)
6400 status
= cli_session_setup_guest_recv(req
);
6401 d_printf("sesssetup returned %s\n", nt_errstr(status
));
6404 static void chain2_tcon_completion(struct tevent_req
*req
)
6406 bool *done
= (bool *)tevent_req_callback_data_void(req
);
6408 status
= cli_tcon_andx_recv(req
);
6409 d_printf("tcon_and_x returned %s\n", nt_errstr(status
));
6413 static bool run_chain2(int dummy
)
6415 struct cli_state
*cli1
;
6416 struct event_context
*evt
= event_context_init(NULL
);
6417 struct tevent_req
*reqs
[2], *smbreqs
[2];
6421 printf("starting chain2 test\n");
6422 status
= cli_start_connection(&cli1
, lp_netbios_name(), host
, NULL
,
6423 port_to_use
, Undefined
, 0);
6424 if (!NT_STATUS_IS_OK(status
)) {
6428 cli_sockopt(cli1
, sockops
);
6430 reqs
[0] = cli_session_setup_guest_create(talloc_tos(), evt
, cli1
,
6432 if (reqs
[0] == NULL
) return false;
6433 tevent_req_set_callback(reqs
[0], chain2_sesssetup_completion
, NULL
);
6435 reqs
[1] = cli_tcon_andx_create(talloc_tos(), evt
, cli1
, "IPC$",
6436 "?????", NULL
, 0, &smbreqs
[1]);
6437 if (reqs
[1] == NULL
) return false;
6438 tevent_req_set_callback(reqs
[1], chain2_tcon_completion
, &done
);
6440 status
= cli_smb_chain_send(smbreqs
, ARRAY_SIZE(smbreqs
));
6441 if (!NT_STATUS_IS_OK(status
)) {
6446 event_loop_once(evt
);
6449 torture_close_connection(cli1
);
6454 struct torture_createdel_state
{
6455 struct tevent_context
*ev
;
6456 struct cli_state
*cli
;
6459 static void torture_createdel_created(struct tevent_req
*subreq
);
6460 static void torture_createdel_closed(struct tevent_req
*subreq
);
6462 static struct tevent_req
*torture_createdel_send(TALLOC_CTX
*mem_ctx
,
6463 struct tevent_context
*ev
,
6464 struct cli_state
*cli
,
6467 struct tevent_req
*req
, *subreq
;
6468 struct torture_createdel_state
*state
;
6470 req
= tevent_req_create(mem_ctx
, &state
,
6471 struct torture_createdel_state
);
6478 subreq
= cli_ntcreate_send(
6479 state
, ev
, cli
, name
, 0,
6480 FILE_READ_DATA
|FILE_WRITE_DATA
|DELETE_ACCESS
,
6481 FILE_ATTRIBUTE_NORMAL
,
6482 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
6483 FILE_OPEN_IF
, FILE_DELETE_ON_CLOSE
, 0);
6485 if (tevent_req_nomem(subreq
, req
)) {
6486 return tevent_req_post(req
, ev
);
6488 tevent_req_set_callback(subreq
, torture_createdel_created
, req
);
6492 static void torture_createdel_created(struct tevent_req
*subreq
)
6494 struct tevent_req
*req
= tevent_req_callback_data(
6495 subreq
, struct tevent_req
);
6496 struct torture_createdel_state
*state
= tevent_req_data(
6497 req
, struct torture_createdel_state
);
6501 status
= cli_ntcreate_recv(subreq
, &fnum
);
6502 TALLOC_FREE(subreq
);
6503 if (!NT_STATUS_IS_OK(status
)) {
6504 DEBUG(10, ("cli_ntcreate_recv returned %s\n",
6505 nt_errstr(status
)));
6506 tevent_req_nterror(req
, status
);
6510 subreq
= cli_close_send(state
, state
->ev
, state
->cli
, fnum
);
6511 if (tevent_req_nomem(subreq
, req
)) {
6514 tevent_req_set_callback(subreq
, torture_createdel_closed
, req
);
6517 static void torture_createdel_closed(struct tevent_req
*subreq
)
6519 struct tevent_req
*req
= tevent_req_callback_data(
6520 subreq
, struct tevent_req
);
6523 status
= cli_close_recv(subreq
);
6524 if (!NT_STATUS_IS_OK(status
)) {
6525 DEBUG(10, ("cli_close_recv returned %s\n", nt_errstr(status
)));
6526 tevent_req_nterror(req
, status
);
6529 tevent_req_done(req
);
6532 static NTSTATUS
torture_createdel_recv(struct tevent_req
*req
)
6534 return tevent_req_simple_recv_ntstatus(req
);
6537 struct torture_createdels_state
{
6538 struct tevent_context
*ev
;
6539 struct cli_state
*cli
;
6540 const char *base_name
;
6544 struct tevent_req
**reqs
;
6547 static void torture_createdels_done(struct tevent_req
*subreq
);
6549 static struct tevent_req
*torture_createdels_send(TALLOC_CTX
*mem_ctx
,
6550 struct tevent_context
*ev
,
6551 struct cli_state
*cli
,
6552 const char *base_name
,
6556 struct tevent_req
*req
;
6557 struct torture_createdels_state
*state
;
6560 req
= tevent_req_create(mem_ctx
, &state
,
6561 struct torture_createdels_state
);
6567 state
->base_name
= talloc_strdup(state
, base_name
);
6568 if (tevent_req_nomem(state
->base_name
, req
)) {
6569 return tevent_req_post(req
, ev
);
6571 state
->num_files
= MAX(num_parallel
, num_files
);
6573 state
->received
= 0;
6575 state
->reqs
= talloc_array(state
, struct tevent_req
*, num_parallel
);
6576 if (tevent_req_nomem(state
->reqs
, req
)) {
6577 return tevent_req_post(req
, ev
);
6580 for (i
=0; i
<num_parallel
; i
++) {
6583 name
= talloc_asprintf(state
, "%s%8.8d", state
->base_name
,
6585 if (tevent_req_nomem(name
, req
)) {
6586 return tevent_req_post(req
, ev
);
6588 state
->reqs
[i
] = torture_createdel_send(
6589 state
->reqs
, state
->ev
, state
->cli
, name
);
6590 if (tevent_req_nomem(state
->reqs
[i
], req
)) {
6591 return tevent_req_post(req
, ev
);
6593 name
= talloc_move(state
->reqs
[i
], &name
);
6594 tevent_req_set_callback(state
->reqs
[i
],
6595 torture_createdels_done
, req
);
6601 static void torture_createdels_done(struct tevent_req
*subreq
)
6603 struct tevent_req
*req
= tevent_req_callback_data(
6604 subreq
, struct tevent_req
);
6605 struct torture_createdels_state
*state
= tevent_req_data(
6606 req
, struct torture_createdels_state
);
6607 size_t num_parallel
= talloc_array_length(state
->reqs
);
6612 status
= torture_createdel_recv(subreq
);
6613 if (!NT_STATUS_IS_OK(status
)){
6614 DEBUG(10, ("torture_createdel_recv returned %s\n",
6615 nt_errstr(status
)));
6616 TALLOC_FREE(subreq
);
6617 tevent_req_nterror(req
, status
);
6621 for (i
=0; i
<num_parallel
; i
++) {
6622 if (subreq
== state
->reqs
[i
]) {
6626 if (i
== num_parallel
) {
6627 DEBUG(10, ("received something we did not send\n"));
6628 tevent_req_nterror(req
, NT_STATUS_INTERNAL_ERROR
);
6631 TALLOC_FREE(state
->reqs
[i
]);
6633 if (state
->sent
>= state
->num_files
) {
6634 tevent_req_done(req
);
6638 name
= talloc_asprintf(state
, "%s%8.8d", state
->base_name
,
6640 if (tevent_req_nomem(name
, req
)) {
6643 state
->reqs
[i
] = torture_createdel_send(state
->reqs
, state
->ev
,
6645 if (tevent_req_nomem(state
->reqs
[i
], req
)) {
6648 name
= talloc_move(state
->reqs
[i
], &name
);
6649 tevent_req_set_callback(state
->reqs
[i
], torture_createdels_done
, req
);
6653 static NTSTATUS
torture_createdels_recv(struct tevent_req
*req
)
6655 return tevent_req_simple_recv_ntstatus(req
);
6658 struct swallow_notify_state
{
6659 struct tevent_context
*ev
;
6660 struct cli_state
*cli
;
6662 uint32_t completion_filter
;
6664 bool (*fn
)(uint32_t action
, const char *name
, void *priv
);
6668 static void swallow_notify_done(struct tevent_req
*subreq
);
6670 static struct tevent_req
*swallow_notify_send(TALLOC_CTX
*mem_ctx
,
6671 struct tevent_context
*ev
,
6672 struct cli_state
*cli
,
6674 uint32_t completion_filter
,
6676 bool (*fn
)(uint32_t action
,
6681 struct tevent_req
*req
, *subreq
;
6682 struct swallow_notify_state
*state
;
6684 req
= tevent_req_create(mem_ctx
, &state
,
6685 struct swallow_notify_state
);
6692 state
->completion_filter
= completion_filter
;
6693 state
->recursive
= recursive
;
6697 subreq
= cli_notify_send(state
, state
->ev
, state
->cli
, state
->fnum
,
6698 0xffff, state
->completion_filter
,
6700 if (tevent_req_nomem(subreq
, req
)) {
6701 return tevent_req_post(req
, ev
);
6703 tevent_req_set_callback(subreq
, swallow_notify_done
, req
);
6707 static void swallow_notify_done(struct tevent_req
*subreq
)
6709 struct tevent_req
*req
= tevent_req_callback_data(
6710 subreq
, struct tevent_req
);
6711 struct swallow_notify_state
*state
= tevent_req_data(
6712 req
, struct swallow_notify_state
);
6714 uint32_t i
, num_changes
;
6715 struct notify_change
*changes
;
6717 status
= cli_notify_recv(subreq
, state
, &num_changes
, &changes
);
6718 TALLOC_FREE(subreq
);
6719 if (!NT_STATUS_IS_OK(status
)) {
6720 DEBUG(10, ("cli_notify_recv returned %s\n",
6721 nt_errstr(status
)));
6722 tevent_req_nterror(req
, status
);
6726 for (i
=0; i
<num_changes
; i
++) {
6727 state
->fn(changes
[i
].action
, changes
[i
].name
, state
->priv
);
6729 TALLOC_FREE(changes
);
6731 subreq
= cli_notify_send(state
, state
->ev
, state
->cli
, state
->fnum
,
6732 0xffff, state
->completion_filter
,
6734 if (tevent_req_nomem(subreq
, req
)) {
6737 tevent_req_set_callback(subreq
, swallow_notify_done
, req
);
6740 static bool print_notifies(uint32_t action
, const char *name
, void *priv
)
6742 if (DEBUGLEVEL
> 5) {
6743 d_printf("%d %s\n", (int)action
, name
);
6748 static void notify_bench_done(struct tevent_req
*req
)
6750 int *num_finished
= (int *)tevent_req_callback_data_void(req
);
6754 static bool run_notify_bench(int dummy
)
6756 const char *dname
= "\\notify-bench";
6757 struct tevent_context
*ev
;
6760 struct tevent_req
*req1
;
6761 struct tevent_req
*req2
= NULL
;
6762 int i
, num_unc_names
;
6763 int num_finished
= 0;
6765 printf("starting notify-bench test\n");
6767 if (use_multishare_conn
) {
6769 unc_list
= file_lines_load(multishare_conn_fname
,
6770 &num_unc_names
, 0, NULL
);
6771 if (!unc_list
|| num_unc_names
<= 0) {
6772 d_printf("Failed to load unc names list from '%s'\n",
6773 multishare_conn_fname
);
6776 TALLOC_FREE(unc_list
);
6781 ev
= tevent_context_init(talloc_tos());
6783 d_printf("tevent_context_init failed\n");
6787 for (i
=0; i
<num_unc_names
; i
++) {
6788 struct cli_state
*cli
;
6791 base_fname
= talloc_asprintf(talloc_tos(), "%s\\file%3.3d.",
6793 if (base_fname
== NULL
) {
6797 if (!torture_open_connection(&cli
, i
)) {
6801 status
= cli_ntcreate(cli
, dname
, 0,
6802 MAXIMUM_ALLOWED_ACCESS
,
6803 0, FILE_SHARE_READ
|FILE_SHARE_WRITE
|
6805 FILE_OPEN_IF
, FILE_DIRECTORY_FILE
, 0,
6808 if (!NT_STATUS_IS_OK(status
)) {
6809 d_printf("Could not create %s: %s\n", dname
,
6814 req1
= swallow_notify_send(talloc_tos(), ev
, cli
, dnum
,
6815 FILE_NOTIFY_CHANGE_FILE_NAME
|
6816 FILE_NOTIFY_CHANGE_DIR_NAME
|
6817 FILE_NOTIFY_CHANGE_ATTRIBUTES
|
6818 FILE_NOTIFY_CHANGE_LAST_WRITE
,
6819 false, print_notifies
, NULL
);
6821 d_printf("Could not create notify request\n");
6825 req2
= torture_createdels_send(talloc_tos(), ev
, cli
,
6826 base_fname
, 10, torture_numops
);
6828 d_printf("Could not create createdels request\n");
6831 TALLOC_FREE(base_fname
);
6833 tevent_req_set_callback(req2
, notify_bench_done
,
6837 while (num_finished
< num_unc_names
) {
6839 ret
= tevent_loop_once(ev
);
6841 d_printf("tevent_loop_once failed\n");
6846 if (!tevent_req_poll(req2
, ev
)) {
6847 d_printf("tevent_req_poll failed\n");
6850 status
= torture_createdels_recv(req2
);
6851 d_printf("torture_createdels_recv returned %s\n", nt_errstr(status
));
6856 static bool run_mangle1(int dummy
)
6858 struct cli_state
*cli
;
6859 const char *fname
= "this_is_a_long_fname_to_be_mangled.txt";
6863 time_t change_time
, access_time
, write_time
;
6867 printf("starting mangle1 test\n");
6868 if (!torture_open_connection(&cli
, 0)) {
6872 cli_sockopt(cli
, sockops
);
6874 status
= cli_ntcreate(cli
, fname
, 0, GENERIC_ALL_ACCESS
|DELETE_ACCESS
,
6875 FILE_ATTRIBUTE_NORMAL
, 0, FILE_OVERWRITE_IF
,
6877 if (!NT_STATUS_IS_OK(status
)) {
6878 d_printf("open %s failed: %s\n", fname
, nt_errstr(status
));
6881 cli_close(cli
, fnum
);
6883 status
= cli_qpathinfo_alt_name(cli
, fname
, alt_name
);
6884 if (!NT_STATUS_IS_OK(status
)) {
6885 d_printf("cli_qpathinfo_alt_name failed: %s\n",
6889 d_printf("alt_name: %s\n", alt_name
);
6891 status
= cli_open(cli
, alt_name
, O_RDONLY
, DENY_NONE
, &fnum
);
6892 if (!NT_STATUS_IS_OK(status
)) {
6893 d_printf("cli_open(%s) failed: %s\n", alt_name
,
6897 cli_close(cli
, fnum
);
6899 status
= cli_qpathinfo1(cli
, alt_name
, &change_time
, &access_time
,
6900 &write_time
, &size
, &mode
);
6901 if (!NT_STATUS_IS_OK(status
)) {
6902 d_printf("cli_qpathinfo1(%s) failed: %s\n", alt_name
,
6910 static size_t null_source(uint8_t *buf
, size_t n
, void *priv
)
6912 size_t *to_pull
= (size_t *)priv
;
6913 size_t thistime
= *to_pull
;
6915 thistime
= MIN(thistime
, n
);
6916 if (thistime
== 0) {
6920 memset(buf
, 0, thistime
);
6921 *to_pull
-= thistime
;
6925 static bool run_windows_write(int dummy
)
6927 struct cli_state
*cli1
;
6931 const char *fname
= "\\writetest.txt";
6932 struct timeval start_time
;
6937 printf("starting windows_write test\n");
6938 if (!torture_open_connection(&cli1
, 0)) {
6942 status
= cli_open(cli1
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
, &fnum
);
6943 if (!NT_STATUS_IS_OK(status
)) {
6944 printf("open failed (%s)\n", nt_errstr(status
));
6948 cli_sockopt(cli1
, sockops
);
6950 start_time
= timeval_current();
6952 for (i
=0; i
<torture_numops
; i
++) {
6954 off_t start
= i
* torture_blocksize
;
6955 size_t to_pull
= torture_blocksize
- 1;
6957 status
= cli_writeall(cli1
, fnum
, 0, &c
,
6958 start
+ torture_blocksize
- 1, 1, NULL
);
6959 if (!NT_STATUS_IS_OK(status
)) {
6960 printf("cli_write failed: %s\n", nt_errstr(status
));
6964 status
= cli_push(cli1
, fnum
, 0, i
* torture_blocksize
, torture_blocksize
,
6965 null_source
, &to_pull
);
6966 if (!NT_STATUS_IS_OK(status
)) {
6967 printf("cli_push returned: %s\n", nt_errstr(status
));
6972 seconds
= timeval_elapsed(&start_time
);
6973 kbytes
= (double)torture_blocksize
* torture_numops
;
6976 printf("Wrote %d kbytes in %.2f seconds: %d kb/sec\n", (int)kbytes
,
6977 (double)seconds
, (int)(kbytes
/seconds
));
6981 cli_close(cli1
, fnum
);
6982 cli_unlink(cli1
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
6983 torture_close_connection(cli1
);
6987 static bool run_cli_echo(int dummy
)
6989 struct cli_state
*cli
;
6992 printf("starting cli_echo test\n");
6993 if (!torture_open_connection(&cli
, 0)) {
6996 cli_sockopt(cli
, sockops
);
6998 status
= cli_echo(cli
, 5, data_blob_const("hello", 5));
7000 d_printf("cli_echo returned %s\n", nt_errstr(status
));
7002 torture_close_connection(cli
);
7003 return NT_STATUS_IS_OK(status
);
7006 static bool run_uid_regression_test(int dummy
)
7008 static struct cli_state
*cli
;
7011 bool correct
= True
;
7014 printf("starting uid regression test\n");
7016 if (!torture_open_connection(&cli
, 0)) {
7020 cli_sockopt(cli
, sockops
);
7022 /* Ok - now save then logoff our current user. */
7023 old_vuid
= cli
->vuid
;
7025 status
= cli_ulogoff(cli
);
7026 if (!NT_STATUS_IS_OK(status
)) {
7027 d_printf("(%s) cli_ulogoff failed: %s\n",
7028 __location__
, nt_errstr(status
));
7033 cli
->vuid
= old_vuid
;
7035 /* Try an operation. */
7036 status
= cli_mkdir(cli
, "\\uid_reg_test");
7037 if (NT_STATUS_IS_OK(status
)) {
7038 d_printf("(%s) cli_mkdir succeeded\n",
7043 /* Should be bad uid. */
7044 if (!check_error(__LINE__
, cli
, ERRSRV
, ERRbaduid
,
7045 NT_STATUS_USER_SESSION_DELETED
)) {
7051 old_cnum
= cli
->cnum
;
7053 /* Now try a SMBtdis with the invald vuid set to zero. */
7056 /* This should succeed. */
7057 status
= cli_tdis(cli
);
7059 if (NT_STATUS_IS_OK(status
)) {
7060 d_printf("First tdis with invalid vuid should succeed.\n");
7062 d_printf("First tdis failed (%s)\n", nt_errstr(status
));
7067 cli
->vuid
= old_vuid
;
7068 cli
->cnum
= old_cnum
;
7070 /* This should fail. */
7071 status
= cli_tdis(cli
);
7072 if (NT_STATUS_IS_OK(status
)) {
7073 d_printf("Second tdis with invalid vuid should fail - succeeded instead !.\n");
7077 /* Should be bad tid. */
7078 if (!check_error(__LINE__
, cli
, ERRSRV
, ERRinvnid
,
7079 NT_STATUS_NETWORK_NAME_DELETED
)) {
7085 cli_rmdir(cli
, "\\uid_reg_test");
7094 static const char *illegal_chars
= "*\\/?<>|\":";
7095 static char force_shortname_chars
[] = " +,.[];=\177";
7097 static NTSTATUS
shortname_del_fn(const char *mnt
, struct file_info
*finfo
,
7098 const char *mask
, void *state
)
7100 struct cli_state
*pcli
= (struct cli_state
*)state
;
7102 NTSTATUS status
= NT_STATUS_OK
;
7104 slprintf(fname
, sizeof(fname
), "\\shortname\\%s", finfo
->name
);
7106 if (strcmp(finfo
->name
, ".") == 0 || strcmp(finfo
->name
, "..") == 0)
7107 return NT_STATUS_OK
;
7109 if (finfo
->mode
& FILE_ATTRIBUTE_DIRECTORY
) {
7110 status
= cli_rmdir(pcli
, fname
);
7111 if (!NT_STATUS_IS_OK(status
)) {
7112 printf("del_fn: failed to rmdir %s\n,", fname
);
7115 status
= cli_unlink(pcli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
7116 if (!NT_STATUS_IS_OK(status
)) {
7117 printf("del_fn: failed to unlink %s\n,", fname
);
7129 static NTSTATUS
shortname_list_fn(const char *mnt
, struct file_info
*finfo
,
7130 const char *name
, void *state
)
7132 struct sn_state
*s
= (struct sn_state
*)state
;
7136 printf("shortname list: i = %d, name = |%s|, shortname = |%s|\n",
7137 i
, finfo
->name
, finfo
->short_name
);
7140 if (strchr(force_shortname_chars
, i
)) {
7141 if (!finfo
->short_name
) {
7142 /* Shortname not created when it should be. */
7143 d_printf("(%s) ERROR: Shortname was not created for file %s containing %d\n",
7144 __location__
, finfo
->name
, i
);
7147 } else if (finfo
->short_name
){
7148 /* Shortname created when it should not be. */
7149 d_printf("(%s) ERROR: Shortname %s was created for file %s\n",
7150 __location__
, finfo
->short_name
, finfo
->name
);
7154 return NT_STATUS_OK
;
7157 static bool run_shortname_test(int dummy
)
7159 static struct cli_state
*cli
;
7160 bool correct
= True
;
7166 printf("starting shortname test\n");
7168 if (!torture_open_connection(&cli
, 0)) {
7172 cli_sockopt(cli
, sockops
);
7174 cli_list(cli
, "\\shortname\\*", 0, shortname_del_fn
, cli
);
7175 cli_list(cli
, "\\shortname\\*", FILE_ATTRIBUTE_DIRECTORY
, shortname_del_fn
, cli
);
7176 cli_rmdir(cli
, "\\shortname");
7178 status
= cli_mkdir(cli
, "\\shortname");
7179 if (!NT_STATUS_IS_OK(status
)) {
7180 d_printf("(%s) cli_mkdir of \\shortname failed: %s\n",
7181 __location__
, nt_errstr(status
));
7186 strlcpy(fname
, "\\shortname\\", sizeof(fname
));
7187 strlcat(fname
, "test .txt", sizeof(fname
));
7191 for (i
= 32; i
< 128; i
++) {
7192 uint16_t fnum
= (uint16_t)-1;
7196 if (strchr(illegal_chars
, i
)) {
7201 status
= cli_ntcreate(cli
, fname
, 0, GENERIC_ALL_ACCESS
, FILE_ATTRIBUTE_NORMAL
,
7202 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OVERWRITE_IF
, 0, 0, &fnum
);
7203 if (!NT_STATUS_IS_OK(status
)) {
7204 d_printf("(%s) cli_nt_create of %s failed: %s\n",
7205 __location__
, fname
, nt_errstr(status
));
7209 cli_close(cli
, fnum
);
7212 status
= cli_list(cli
, "\\shortname\\test*.*", 0,
7213 shortname_list_fn
, &s
);
7214 if (s
.matched
!= 1) {
7215 d_printf("(%s) failed to list %s: %s\n",
7216 __location__
, fname
, nt_errstr(status
));
7221 status
= cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
7222 if (!NT_STATUS_IS_OK(status
)) {
7223 d_printf("(%s) failed to delete %s: %s\n",
7224 __location__
, fname
, nt_errstr(status
));
7237 cli_list(cli
, "\\shortname\\*", 0, shortname_del_fn
, cli
);
7238 cli_list(cli
, "\\shortname\\*", FILE_ATTRIBUTE_DIRECTORY
, shortname_del_fn
, cli
);
7239 cli_rmdir(cli
, "\\shortname");
7240 torture_close_connection(cli
);
7244 static void pagedsearch_cb(struct tevent_req
*req
)
7247 struct tldap_message
*msg
;
7250 rc
= tldap_search_paged_recv(req
, talloc_tos(), &msg
);
7251 if (rc
!= TLDAP_SUCCESS
) {
7252 d_printf("tldap_search_paged_recv failed: %s\n",
7253 tldap_err2string(rc
));
7256 if (tldap_msg_type(msg
) != TLDAP_RES_SEARCH_ENTRY
) {
7260 if (!tldap_entry_dn(msg
, &dn
)) {
7261 d_printf("tldap_entry_dn failed\n");
7264 d_printf("%s\n", dn
);
7268 static bool run_tldap(int dummy
)
7270 struct tldap_context
*ld
;
7273 struct sockaddr_storage addr
;
7274 struct tevent_context
*ev
;
7275 struct tevent_req
*req
;
7279 if (!resolve_name(host
, &addr
, 0, false)) {
7280 d_printf("could not find host %s\n", host
);
7283 status
= open_socket_out(&addr
, 389, 9999, &fd
);
7284 if (!NT_STATUS_IS_OK(status
)) {
7285 d_printf("open_socket_out failed: %s\n", nt_errstr(status
));
7289 ld
= tldap_context_create(talloc_tos(), fd
);
7292 d_printf("tldap_context_create failed\n");
7296 rc
= tldap_fetch_rootdse(ld
);
7297 if (rc
!= TLDAP_SUCCESS
) {
7298 d_printf("tldap_fetch_rootdse failed: %s\n",
7299 tldap_errstr(talloc_tos(), ld
, rc
));
7303 basedn
= tldap_talloc_single_attribute(
7304 tldap_rootdse(ld
), "defaultNamingContext", talloc_tos());
7305 if (basedn
== NULL
) {
7306 d_printf("no defaultNamingContext\n");
7309 d_printf("defaultNamingContext: %s\n", basedn
);
7311 ev
= tevent_context_init(talloc_tos());
7313 d_printf("tevent_context_init failed\n");
7317 req
= tldap_search_paged_send(talloc_tos(), ev
, ld
, basedn
,
7318 TLDAP_SCOPE_SUB
, "(objectclass=*)",
7320 NULL
, 0, NULL
, 0, 0, 0, 0, 5);
7322 d_printf("tldap_search_paged_send failed\n");
7325 tevent_req_set_callback(req
, pagedsearch_cb
, NULL
);
7327 tevent_req_poll(req
, ev
);
7331 /* test search filters against rootDSE */
7332 filter
= "(&(|(name=samba)(nextRid<=10000000)(usnChanged>=10)(samba~=ambas)(!(name=s*m*a)))"
7333 "(|(name:=samba)(name:dn:2.5.13.5:=samba)(:dn:2.5.13.5:=samba)(!(name=*samba))))";
7335 rc
= tldap_search(ld
, "", TLDAP_SCOPE_BASE
, filter
,
7336 NULL
, 0, 0, NULL
, 0, NULL
, 0, 0, 0, 0,
7337 talloc_tos(), NULL
, NULL
);
7338 if (rc
!= TLDAP_SUCCESS
) {
7339 d_printf("tldap_search with complex filter failed: %s\n",
7340 tldap_errstr(talloc_tos(), ld
, rc
));
7348 /* Torture test to ensure no regression of :
7349 https://bugzilla.samba.org/show_bug.cgi?id=7084
7352 static bool run_dir_createtime(int dummy
)
7354 struct cli_state
*cli
;
7355 const char *dname
= "\\testdir";
7356 const char *fname
= "\\testdir\\testfile";
7358 struct timespec create_time
;
7359 struct timespec create_time1
;
7363 if (!torture_open_connection(&cli
, 0)) {
7367 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
7368 cli_rmdir(cli
, dname
);
7370 status
= cli_mkdir(cli
, dname
);
7371 if (!NT_STATUS_IS_OK(status
)) {
7372 printf("mkdir failed: %s\n", nt_errstr(status
));
7376 status
= cli_qpathinfo2(cli
, dname
, &create_time
, NULL
, NULL
, NULL
,
7378 if (!NT_STATUS_IS_OK(status
)) {
7379 printf("cli_qpathinfo2 returned %s\n",
7384 /* Sleep 3 seconds, then create a file. */
7387 status
= cli_open(cli
, fname
, O_RDWR
| O_CREAT
| O_EXCL
,
7389 if (!NT_STATUS_IS_OK(status
)) {
7390 printf("cli_open failed: %s\n", nt_errstr(status
));
7394 status
= cli_qpathinfo2(cli
, dname
, &create_time1
, NULL
, NULL
, NULL
,
7396 if (!NT_STATUS_IS_OK(status
)) {
7397 printf("cli_qpathinfo2 (2) returned %s\n",
7402 if (timespec_compare(&create_time1
, &create_time
)) {
7403 printf("run_dir_createtime: create time was updated (error)\n");
7405 printf("run_dir_createtime: create time was not updated (correct)\n");
7411 cli_unlink(cli
, fname
, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
7412 cli_rmdir(cli
, dname
);
7413 if (!torture_close_connection(cli
)) {
7420 static bool run_streamerror(int dummy
)
7422 struct cli_state
*cli
;
7423 const char *dname
= "\\testdir";
7424 const char *streamname
=
7425 "testdir:{4c8cc155-6c1e-11d1-8e41-00c04fb9386d}:$DATA";
7427 time_t change_time
, access_time
, write_time
;
7429 uint16_t mode
, fnum
;
7432 if (!torture_open_connection(&cli
, 0)) {
7436 cli_unlink(cli
, "\\testdir\\*", FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
7437 cli_rmdir(cli
, dname
);
7439 status
= cli_mkdir(cli
, dname
);
7440 if (!NT_STATUS_IS_OK(status
)) {
7441 printf("mkdir failed: %s\n", nt_errstr(status
));
7445 cli_qpathinfo1(cli
, streamname
, &change_time
, &access_time
, &write_time
,
7447 status
= cli_nt_error(cli
);
7449 if (!NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
)) {
7450 printf("pathinfo returned %s, expected "
7451 "NT_STATUS_OBJECT_NAME_NOT_FOUND\n",
7456 status
= cli_ntcreate(cli
, streamname
, 0x16,
7457 FILE_READ_DATA
|FILE_READ_EA
|
7458 FILE_READ_ATTRIBUTES
|READ_CONTROL_ACCESS
,
7459 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_READ
,
7460 FILE_OPEN
, 0, 0, &fnum
);
7462 if (!NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
)) {
7463 printf("ntcreate returned %s, expected "
7464 "NT_STATUS_OBJECT_NAME_NOT_FOUND\n",
7470 cli_rmdir(cli
, dname
);
7474 static bool run_local_substitute(int dummy
)
7478 ok
&= subst_test("%U", "bla", "", -1, -1, "bla");
7479 ok
&= subst_test("%u%U", "bla", "", -1, -1, "blabla");
7480 ok
&= subst_test("%g", "", "", -1, -1, "NO_GROUP");
7481 ok
&= subst_test("%G", "", "", -1, -1, "NO_GROUP");
7482 ok
&= subst_test("%g", "", "", -1, 0, gidtoname(0));
7483 ok
&= subst_test("%G", "", "", -1, 0, gidtoname(0));
7484 ok
&= subst_test("%D%u", "u", "dom", -1, 0, "domu");
7485 ok
&= subst_test("%i %I", "", "", -1, -1, "0.0.0.0 0.0.0.0");
7487 /* Different captialization rules in sub_basic... */
7489 ok
&= (strcmp(talloc_sub_basic(talloc_tos(), "BLA", "dom", "%U%D"),
7495 static bool run_local_base64(int dummy
)
7500 for (i
=1; i
<2000; i
++) {
7501 DATA_BLOB blob1
, blob2
;
7504 blob1
.data
= talloc_array(talloc_tos(), uint8_t, i
);
7506 generate_random_buffer(blob1
.data
, blob1
.length
);
7508 b64
= base64_encode_data_blob(talloc_tos(), blob1
);
7510 d_fprintf(stderr
, "base64_encode_data_blob failed "
7511 "for %d bytes\n", i
);
7514 blob2
= base64_decode_data_blob(b64
);
7517 if (data_blob_cmp(&blob1
, &blob2
)) {
7518 d_fprintf(stderr
, "data_blob_cmp failed for %d "
7522 TALLOC_FREE(blob1
.data
);
7523 data_blob_free(&blob2
);
7528 static bool run_local_gencache(int dummy
)
7534 if (!gencache_set("foo", "bar", time(NULL
) + 1000)) {
7535 d_printf("%s: gencache_set() failed\n", __location__
);
7539 if (!gencache_get("foo", NULL
, NULL
)) {
7540 d_printf("%s: gencache_get() failed\n", __location__
);
7544 if (!gencache_get("foo", &val
, &tm
)) {
7545 d_printf("%s: gencache_get() failed\n", __location__
);
7549 if (strcmp(val
, "bar") != 0) {
7550 d_printf("%s: gencache_get() returned %s, expected %s\n",
7551 __location__
, val
, "bar");
7558 if (!gencache_del("foo")) {
7559 d_printf("%s: gencache_del() failed\n", __location__
);
7562 if (gencache_del("foo")) {
7563 d_printf("%s: second gencache_del() succeeded\n",
7568 if (gencache_get("foo", &val
, &tm
)) {
7569 d_printf("%s: gencache_get() on deleted entry "
7570 "succeeded\n", __location__
);
7574 blob
= data_blob_string_const_null("bar");
7575 tm
= time(NULL
) + 60;
7577 if (!gencache_set_data_blob("foo", &blob
, tm
)) {
7578 d_printf("%s: gencache_set_data_blob() failed\n", __location__
);
7582 if (!gencache_get_data_blob("foo", &blob
, NULL
, NULL
)) {
7583 d_printf("%s: gencache_get_data_blob() failed\n", __location__
);
7587 if (strcmp((const char *)blob
.data
, "bar") != 0) {
7588 d_printf("%s: gencache_get_data_blob() returned %s, expected %s\n",
7589 __location__
, (const char *)blob
.data
, "bar");
7590 data_blob_free(&blob
);
7594 data_blob_free(&blob
);
7596 if (!gencache_del("foo")) {
7597 d_printf("%s: gencache_del() failed\n", __location__
);
7600 if (gencache_del("foo")) {
7601 d_printf("%s: second gencache_del() succeeded\n",
7606 if (gencache_get_data_blob("foo", &blob
, NULL
, NULL
)) {
7607 d_printf("%s: gencache_get_data_blob() on deleted entry "
7608 "succeeded\n", __location__
);
7615 static bool rbt_testval(struct db_context
*db
, const char *key
,
7618 struct db_record
*rec
;
7619 TDB_DATA data
= string_tdb_data(value
);
7623 rec
= db
->fetch_locked(db
, db
, string_tdb_data(key
));
7625 d_fprintf(stderr
, "fetch_locked failed\n");
7628 status
= rec
->store(rec
, data
, 0);
7629 if (!NT_STATUS_IS_OK(status
)) {
7630 d_fprintf(stderr
, "store failed: %s\n", nt_errstr(status
));
7635 rec
= db
->fetch_locked(db
, db
, string_tdb_data(key
));
7637 d_fprintf(stderr
, "second fetch_locked failed\n");
7640 if ((rec
->value
.dsize
!= data
.dsize
)
7641 || (memcmp(rec
->value
.dptr
, data
.dptr
, data
.dsize
) != 0)) {
7642 d_fprintf(stderr
, "Got wrong data back\n");
7652 static bool run_local_rbtree(int dummy
)
7654 struct db_context
*db
;
7658 db
= db_open_rbt(NULL
);
7661 d_fprintf(stderr
, "db_open_rbt failed\n");
7665 for (i
=0; i
<1000; i
++) {
7668 if (asprintf(&key
, "key%ld", random()) == -1) {
7671 if (asprintf(&value
, "value%ld", random()) == -1) {
7676 if (!rbt_testval(db
, key
, value
)) {
7683 if (asprintf(&value
, "value%ld", random()) == -1) {
7688 if (!rbt_testval(db
, key
, value
)) {
7707 local test for character set functions
7709 This is a very simple test for the functionality in convert_string_error()
7711 static bool run_local_convert_string(int dummy
)
7713 TALLOC_CTX
*tmp_ctx
= talloc_new(NULL
);
7714 const char *test_strings
[2] = { "March", "M\303\244rz" };
7718 for (i
=0; i
<2; i
++) {
7719 const char *str
= test_strings
[i
];
7720 int len
= strlen(str
);
7721 size_t converted_size
;
7724 memset(dst
, 'X', sizeof(dst
));
7726 /* first try with real source length */
7727 ret
= convert_string_error(CH_UNIX
, CH_UTF8
,
7732 d_fprintf(stderr
, "Failed to convert '%s' to CH_DISPLAY\n", str
);
7736 if (converted_size
!= len
) {
7737 d_fprintf(stderr
, "Converted size of '%s' should be %d - got %d\n",
7738 str
, len
, (int)converted_size
);
7742 if (strncmp(str
, dst
, converted_size
) != 0) {
7743 d_fprintf(stderr
, "Expected '%s' to match '%s'\n", str
, dst
);
7747 if (strlen(str
) != converted_size
) {
7748 d_fprintf(stderr
, "Expected '%s' length %d - got %d\n", str
,
7749 (int)strlen(str
), (int)converted_size
);
7753 if (dst
[converted_size
] != 'X') {
7754 d_fprintf(stderr
, "Expected no termination of '%s'\n", dst
);
7758 /* now with srclen==-1, this causes the nul to be
7760 ret
= convert_string_error(CH_UNIX
, CH_UTF8
,
7765 d_fprintf(stderr
, "Failed to convert '%s' to CH_DISPLAY\n", str
);
7769 if (converted_size
!= len
+1) {
7770 d_fprintf(stderr
, "Converted size of '%s' should be %d - got %d\n",
7771 str
, len
, (int)converted_size
);
7775 if (strncmp(str
, dst
, converted_size
) != 0) {
7776 d_fprintf(stderr
, "Expected '%s' to match '%s'\n", str
, dst
);
7780 if (len
+1 != converted_size
) {
7781 d_fprintf(stderr
, "Expected '%s' length %d - got %d\n", str
,
7782 len
+1, (int)converted_size
);
7786 if (dst
[converted_size
] != 'X') {
7787 d_fprintf(stderr
, "Expected no termination of '%s'\n", dst
);
7794 TALLOC_FREE(tmp_ctx
);
7797 TALLOC_FREE(tmp_ctx
);
7802 struct talloc_dict_test
{
7806 static int talloc_dict_traverse_fn(DATA_BLOB key
, void *data
, void *priv
)
7808 int *count
= (int *)priv
;
7813 static bool run_local_talloc_dict(int dummy
)
7815 struct talloc_dict
*dict
;
7816 struct talloc_dict_test
*t
;
7819 dict
= talloc_dict_init(talloc_tos());
7824 t
= talloc(talloc_tos(), struct talloc_dict_test
);
7831 if (!talloc_dict_set(dict
, data_blob_const(&key
, sizeof(key
)), t
)) {
7836 if (talloc_dict_traverse(dict
, talloc_dict_traverse_fn
, &count
) != 0) {
7849 static bool run_local_string_to_sid(int dummy
) {
7852 if (string_to_sid(&sid
, "S--1-5-32-545")) {
7853 printf("allowing S--1-5-32-545\n");
7856 if (string_to_sid(&sid
, "S-1-5-32-+545")) {
7857 printf("allowing S-1-5-32-+545\n");
7860 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")) {
7861 printf("allowing S-1-2-3-4-5-6-7-8-9-0-1-2-3-4-5-6-7-8-9-0\n");
7864 if (string_to_sid(&sid
, "S-1-5-32-545-abc")) {
7865 printf("allowing S-1-5-32-545-abc\n");
7868 if (!string_to_sid(&sid
, "S-1-5-32-545")) {
7869 printf("could not parse S-1-5-32-545\n");
7872 if (!dom_sid_equal(&sid
, &global_sid_Builtin_Users
)) {
7873 printf("mis-parsed S-1-5-32-545 as %s\n",
7874 sid_string_tos(&sid
));
7880 static bool run_local_binary_to_sid(int dummy
) {
7881 struct dom_sid
*sid
= talloc(NULL
, struct dom_sid
);
7882 static const char good_binary_sid
[] = {
7883 0x1, /* revision number */
7885 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, /* id_auth */
7886 0x1, 0x1, 0x1, 0x1, /* auth[0] */
7887 0x1, 0x1, 0x1, 0x1, /* auth[1] */
7888 0x1, 0x1, 0x1, 0x1, /* auth[2] */
7889 0x1, 0x1, 0x1, 0x1, /* auth[3] */
7890 0x1, 0x1, 0x1, 0x1, /* auth[4] */
7891 0x1, 0x1, 0x1, 0x1, /* auth[5] */
7892 0x1, 0x1, 0x1, 0x1, /* auth[6] */
7893 0x1, 0x1, 0x1, 0x1, /* auth[7] */
7894 0x1, 0x1, 0x1, 0x1, /* auth[8] */
7895 0x1, 0x1, 0x1, 0x1, /* auth[9] */
7896 0x1, 0x1, 0x1, 0x1, /* auth[10] */
7897 0x1, 0x1, 0x1, 0x1, /* auth[11] */
7898 0x1, 0x1, 0x1, 0x1, /* auth[12] */
7899 0x1, 0x1, 0x1, 0x1, /* auth[13] */
7900 0x1, 0x1, 0x1, 0x1, /* auth[14] */
7903 static const char long_binary_sid
[] = {
7904 0x1, /* revision number */
7906 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, /* id_auth */
7907 0x1, 0x1, 0x1, 0x1, /* auth[0] */
7908 0x1, 0x1, 0x1, 0x1, /* auth[1] */
7909 0x1, 0x1, 0x1, 0x1, /* auth[2] */
7910 0x1, 0x1, 0x1, 0x1, /* auth[3] */
7911 0x1, 0x1, 0x1, 0x1, /* auth[4] */
7912 0x1, 0x1, 0x1, 0x1, /* auth[5] */
7913 0x1, 0x1, 0x1, 0x1, /* auth[6] */
7914 0x1, 0x1, 0x1, 0x1, /* auth[7] */
7915 0x1, 0x1, 0x1, 0x1, /* auth[8] */
7916 0x1, 0x1, 0x1, 0x1, /* auth[9] */
7917 0x1, 0x1, 0x1, 0x1, /* auth[10] */
7918 0x1, 0x1, 0x1, 0x1, /* auth[11] */
7919 0x1, 0x1, 0x1, 0x1, /* auth[12] */
7920 0x1, 0x1, 0x1, 0x1, /* auth[13] */
7921 0x1, 0x1, 0x1, 0x1, /* auth[14] */
7922 0x1, 0x1, 0x1, 0x1, /* auth[15] */
7923 0x1, 0x1, 0x1, 0x1, /* auth[16] */
7924 0x1, 0x1, 0x1, 0x1, /* auth[17] */
7927 static const char long_binary_sid2
[] = {
7928 0x1, /* revision number */
7930 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, /* id_auth */
7931 0x1, 0x1, 0x1, 0x1, /* auth[0] */
7932 0x1, 0x1, 0x1, 0x1, /* auth[1] */
7933 0x1, 0x1, 0x1, 0x1, /* auth[2] */
7934 0x1, 0x1, 0x1, 0x1, /* auth[3] */
7935 0x1, 0x1, 0x1, 0x1, /* auth[4] */
7936 0x1, 0x1, 0x1, 0x1, /* auth[5] */
7937 0x1, 0x1, 0x1, 0x1, /* auth[6] */
7938 0x1, 0x1, 0x1, 0x1, /* auth[7] */
7939 0x1, 0x1, 0x1, 0x1, /* auth[8] */
7940 0x1, 0x1, 0x1, 0x1, /* auth[9] */
7941 0x1, 0x1, 0x1, 0x1, /* auth[10] */
7942 0x1, 0x1, 0x1, 0x1, /* auth[11] */
7943 0x1, 0x1, 0x1, 0x1, /* auth[12] */
7944 0x1, 0x1, 0x1, 0x1, /* auth[13] */
7945 0x1, 0x1, 0x1, 0x1, /* auth[14] */
7946 0x1, 0x1, 0x1, 0x1, /* auth[15] */
7947 0x1, 0x1, 0x1, 0x1, /* auth[16] */
7948 0x1, 0x1, 0x1, 0x1, /* auth[17] */
7949 0x1, 0x1, 0x1, 0x1, /* auth[18] */
7950 0x1, 0x1, 0x1, 0x1, /* auth[19] */
7951 0x1, 0x1, 0x1, 0x1, /* auth[20] */
7952 0x1, 0x1, 0x1, 0x1, /* auth[21] */
7953 0x1, 0x1, 0x1, 0x1, /* auth[22] */
7954 0x1, 0x1, 0x1, 0x1, /* auth[23] */
7955 0x1, 0x1, 0x1, 0x1, /* auth[24] */
7956 0x1, 0x1, 0x1, 0x1, /* auth[25] */
7957 0x1, 0x1, 0x1, 0x1, /* auth[26] */
7958 0x1, 0x1, 0x1, 0x1, /* auth[27] */
7959 0x1, 0x1, 0x1, 0x1, /* auth[28] */
7960 0x1, 0x1, 0x1, 0x1, /* auth[29] */
7961 0x1, 0x1, 0x1, 0x1, /* auth[30] */
7962 0x1, 0x1, 0x1, 0x1, /* auth[31] */
7965 if (!sid_parse(good_binary_sid
, sizeof(good_binary_sid
), sid
)) {
7968 if (sid_parse(long_binary_sid2
, sizeof(long_binary_sid2
), sid
)) {
7971 if (sid_parse(long_binary_sid
, sizeof(long_binary_sid
), sid
)) {
7977 /* Split a path name into filename and stream name components. Canonicalise
7978 * such that an implicit $DATA token is always explicit.
7980 * The "specification" of this function can be found in the
7981 * run_local_stream_name() function in torture.c, I've tried those
7982 * combinations against a W2k3 server.
7985 static NTSTATUS
split_ntfs_stream_name(TALLOC_CTX
*mem_ctx
, const char *fname
,
7986 char **pbase
, char **pstream
)
7989 char *stream
= NULL
;
7990 char *sname
; /* stream name */
7991 const char *stype
; /* stream type */
7993 DEBUG(10, ("split_ntfs_stream_name called for [%s]\n", fname
));
7995 sname
= strchr_m(fname
, ':');
7997 if (lp_posix_pathnames() || (sname
== NULL
)) {
7998 if (pbase
!= NULL
) {
7999 base
= talloc_strdup(mem_ctx
, fname
);
8000 NT_STATUS_HAVE_NO_MEMORY(base
);
8005 if (pbase
!= NULL
) {
8006 base
= talloc_strndup(mem_ctx
, fname
, PTR_DIFF(sname
, fname
));
8007 NT_STATUS_HAVE_NO_MEMORY(base
);
8012 stype
= strchr_m(sname
, ':');
8014 if (stype
== NULL
) {
8015 sname
= talloc_strdup(mem_ctx
, sname
);
8019 if (strcasecmp_m(stype
, ":$DATA") != 0) {
8021 * If there is an explicit stream type, so far we only
8022 * allow $DATA. Is there anything else allowed? -- vl
8024 DEBUG(10, ("[%s] is an invalid stream type\n", stype
));
8026 return NT_STATUS_OBJECT_NAME_INVALID
;
8028 sname
= talloc_strndup(mem_ctx
, sname
, PTR_DIFF(stype
, sname
));
8032 if (sname
== NULL
) {
8034 return NT_STATUS_NO_MEMORY
;
8037 if (sname
[0] == '\0') {
8039 * no stream name, so no stream
8044 if (pstream
!= NULL
) {
8045 stream
= talloc_asprintf(mem_ctx
, "%s:%s", sname
, stype
);
8046 if (stream
== NULL
) {
8049 return NT_STATUS_NO_MEMORY
;
8052 * upper-case the type field
8054 strupper_m(strchr_m(stream
, ':')+1);
8058 if (pbase
!= NULL
) {
8061 if (pstream
!= NULL
) {
8064 return NT_STATUS_OK
;
8067 static bool test_stream_name(const char *fname
, const char *expected_base
,
8068 const char *expected_stream
,
8069 NTSTATUS expected_status
)
8073 char *stream
= NULL
;
8075 status
= split_ntfs_stream_name(talloc_tos(), fname
, &base
, &stream
);
8076 if (!NT_STATUS_EQUAL(status
, expected_status
)) {
8080 if (!NT_STATUS_IS_OK(status
)) {
8084 if (base
== NULL
) goto error
;
8086 if (strcmp(expected_base
, base
) != 0) goto error
;
8088 if ((expected_stream
!= NULL
) && (stream
== NULL
)) goto error
;
8089 if ((expected_stream
== NULL
) && (stream
!= NULL
)) goto error
;
8091 if ((stream
!= NULL
) && (strcmp(expected_stream
, stream
) != 0))
8095 TALLOC_FREE(stream
);
8099 d_fprintf(stderr
, "Do test_stream(%s, %s, %s, %s)\n",
8100 fname
, expected_base
? expected_base
: "<NULL>",
8101 expected_stream
? expected_stream
: "<NULL>",
8102 nt_errstr(expected_status
));
8103 d_fprintf(stderr
, "-> base=%s, stream=%s, status=%s\n",
8104 base
? base
: "<NULL>", stream
? stream
: "<NULL>",
8107 TALLOC_FREE(stream
);
8111 static bool run_local_stream_name(int dummy
)
8115 ret
&= test_stream_name(
8116 "bla", "bla", NULL
, NT_STATUS_OK
);
8117 ret
&= test_stream_name(
8118 "bla::$DATA", "bla", NULL
, NT_STATUS_OK
);
8119 ret
&= test_stream_name(
8120 "bla:blub:", "bla", NULL
, NT_STATUS_OBJECT_NAME_INVALID
);
8121 ret
&= test_stream_name(
8122 "bla::", NULL
, NULL
, NT_STATUS_OBJECT_NAME_INVALID
);
8123 ret
&= test_stream_name(
8124 "bla::123", "bla", NULL
, NT_STATUS_OBJECT_NAME_INVALID
);
8125 ret
&= test_stream_name(
8126 "bla:$DATA", "bla", "$DATA:$DATA", NT_STATUS_OK
);
8127 ret
&= test_stream_name(
8128 "bla:x:$DATA", "bla", "x:$DATA", NT_STATUS_OK
);
8129 ret
&= test_stream_name(
8130 "bla:x", "bla", "x:$DATA", NT_STATUS_OK
);
8135 static bool data_blob_equal(DATA_BLOB a
, DATA_BLOB b
)
8137 if (a
.length
!= b
.length
) {
8138 printf("a.length=%d != b.length=%d\n",
8139 (int)a
.length
, (int)b
.length
);
8142 if (memcmp(a
.data
, b
.data
, a
.length
) != 0) {
8143 printf("a.data and b.data differ\n");
8149 static bool run_local_memcache(int dummy
)
8151 struct memcache
*cache
;
8153 DATA_BLOB d1
, d2
, d3
;
8154 DATA_BLOB v1
, v2
, v3
;
8156 TALLOC_CTX
*mem_ctx
;
8158 size_t size1
, size2
;
8161 cache
= memcache_init(NULL
, 100);
8163 if (cache
== NULL
) {
8164 printf("memcache_init failed\n");
8168 d1
= data_blob_const("d1", 2);
8169 d2
= data_blob_const("d2", 2);
8170 d3
= data_blob_const("d3", 2);
8172 k1
= data_blob_const("d1", 2);
8173 k2
= data_blob_const("d2", 2);
8175 memcache_add(cache
, STAT_CACHE
, k1
, d1
);
8176 memcache_add(cache
, GETWD_CACHE
, k2
, d2
);
8178 if (!memcache_lookup(cache
, STAT_CACHE
, k1
, &v1
)) {
8179 printf("could not find k1\n");
8182 if (!data_blob_equal(d1
, v1
)) {
8186 if (!memcache_lookup(cache
, GETWD_CACHE
, k2
, &v2
)) {
8187 printf("could not find k2\n");
8190 if (!data_blob_equal(d2
, v2
)) {
8194 memcache_add(cache
, STAT_CACHE
, k1
, d3
);
8196 if (!memcache_lookup(cache
, STAT_CACHE
, k1
, &v3
)) {
8197 printf("could not find replaced k1\n");
8200 if (!data_blob_equal(d3
, v3
)) {
8204 memcache_add(cache
, GETWD_CACHE
, k1
, d1
);
8206 if (memcache_lookup(cache
, GETWD_CACHE
, k2
, &v2
)) {
8207 printf("Did find k2, should have been purged\n");
8213 cache
= memcache_init(NULL
, 0);
8215 mem_ctx
= talloc_init("foo");
8217 str1
= talloc_strdup(mem_ctx
, "string1");
8218 str2
= talloc_strdup(mem_ctx
, "string2");
8220 memcache_add_talloc(cache
, SINGLETON_CACHE_TALLOC
,
8221 data_blob_string_const("torture"), &str1
);
8222 size1
= talloc_total_size(cache
);
8224 memcache_add_talloc(cache
, SINGLETON_CACHE_TALLOC
,
8225 data_blob_string_const("torture"), &str2
);
8226 size2
= talloc_total_size(cache
);
8228 printf("size1=%d, size2=%d\n", (int)size1
, (int)size2
);
8230 if (size2
> size1
) {
8231 printf("memcache leaks memory!\n");
8241 static void wbclient_done(struct tevent_req
*req
)
8244 struct winbindd_response
*wb_resp
;
8245 int *i
= (int *)tevent_req_callback_data_void(req
);
8247 wbc_err
= wb_trans_recv(req
, req
, &wb_resp
);
8250 d_printf("wb_trans_recv %d returned %s\n", *i
, wbcErrorString(wbc_err
));
8253 static bool run_local_wbclient(int dummy
)
8255 struct event_context
*ev
;
8256 struct wb_context
**wb_ctx
;
8257 struct winbindd_request wb_req
;
8258 bool result
= false;
8261 BlockSignals(True
, SIGPIPE
);
8263 ev
= tevent_context_init_byname(talloc_tos(), "epoll");
8268 wb_ctx
= talloc_array(ev
, struct wb_context
*, nprocs
);
8269 if (wb_ctx
== NULL
) {
8273 ZERO_STRUCT(wb_req
);
8274 wb_req
.cmd
= WINBINDD_PING
;
8276 d_printf("nprocs=%d, numops=%d\n", (int)nprocs
, (int)torture_numops
);
8278 for (i
=0; i
<nprocs
; i
++) {
8279 wb_ctx
[i
] = wb_context_init(ev
, NULL
);
8280 if (wb_ctx
[i
] == NULL
) {
8283 for (j
=0; j
<torture_numops
; j
++) {
8284 struct tevent_req
*req
;
8285 req
= wb_trans_send(ev
, ev
, wb_ctx
[i
],
8286 (j
% 2) == 0, &wb_req
);
8290 tevent_req_set_callback(req
, wbclient_done
, &i
);
8296 while (i
< nprocs
* torture_numops
) {
8297 event_loop_once(ev
);
8306 static void getaddrinfo_finished(struct tevent_req
*req
)
8308 char *name
= (char *)tevent_req_callback_data_void(req
);
8309 struct addrinfo
*ainfo
;
8312 res
= getaddrinfo_recv(req
, &ainfo
);
8314 d_printf("gai(%s) returned %s\n", name
, gai_strerror(res
));
8317 d_printf("gai(%s) succeeded\n", name
);
8318 freeaddrinfo(ainfo
);
8321 static bool run_getaddrinfo_send(int dummy
)
8323 TALLOC_CTX
*frame
= talloc_stackframe();
8324 struct fncall_context
*ctx
;
8325 struct tevent_context
*ev
;
8326 bool result
= false;
8327 const char *names
[4] = { "www.samba.org", "notfound.samba.org",
8328 "www.slashdot.org", "heise.de" };
8329 struct tevent_req
*reqs
[4];
8332 ev
= event_context_init(frame
);
8337 ctx
= fncall_context_init(frame
, 4);
8339 for (i
=0; i
<ARRAY_SIZE(names
); i
++) {
8340 reqs
[i
] = getaddrinfo_send(frame
, ev
, ctx
, names
[i
], NULL
,
8342 if (reqs
[i
] == NULL
) {
8345 tevent_req_set_callback(reqs
[i
], getaddrinfo_finished
,
8346 discard_const_p(void, names
[i
]));
8349 for (i
=0; i
<ARRAY_SIZE(reqs
); i
++) {
8350 tevent_loop_once(ev
);
8359 static bool dbtrans_inc(struct db_context
*db
)
8361 struct db_record
*rec
;
8366 rec
= db
->fetch_locked(db
, db
, string_term_tdb_data("transtest"));
8368 printf(__location__
"fetch_lock failed\n");
8372 if (rec
->value
.dsize
!= sizeof(uint32_t)) {
8373 printf(__location__
"value.dsize = %d\n",
8374 (int)rec
->value
.dsize
);
8378 val
= (uint32_t *)rec
->value
.dptr
;
8381 status
= rec
->store(rec
, make_tdb_data((uint8_t *)val
,
8384 if (!NT_STATUS_IS_OK(status
)) {
8385 printf(__location__
"store failed: %s\n",
8396 static bool run_local_dbtrans(int dummy
)
8398 struct db_context
*db
;
8399 struct db_record
*rec
;
8404 db
= db_open(talloc_tos(), "transtest.tdb", 0, TDB_DEFAULT
,
8405 O_RDWR
|O_CREAT
, 0600);
8407 printf("Could not open transtest.db\n");
8411 res
= db
->transaction_start(db
);
8413 printf(__location__
"transaction_start failed\n");
8417 rec
= db
->fetch_locked(db
, db
, string_term_tdb_data("transtest"));
8419 printf(__location__
"fetch_lock failed\n");
8423 if (rec
->value
.dptr
== NULL
) {
8425 status
= rec
->store(
8426 rec
, make_tdb_data((uint8_t *)&initial
,
8429 if (!NT_STATUS_IS_OK(status
)) {
8430 printf(__location__
"store returned %s\n",
8438 res
= db
->transaction_commit(db
);
8440 printf(__location__
"transaction_commit failed\n");
8448 res
= db
->transaction_start(db
);
8450 printf(__location__
"transaction_start failed\n");
8454 if (!dbwrap_fetch_uint32(db
, "transtest", &val
)) {
8455 printf(__location__
"dbwrap_fetch_uint32 failed\n");
8459 for (i
=0; i
<10; i
++) {
8460 if (!dbtrans_inc(db
)) {
8465 if (!dbwrap_fetch_uint32(db
, "transtest", &val2
)) {
8466 printf(__location__
"dbwrap_fetch_uint32 failed\n");
8470 if (val2
!= val
+ 10) {
8471 printf(__location__
"val=%d, val2=%d\n",
8472 (int)val
, (int)val2
);
8476 printf("val2=%d\r", val2
);
8478 res
= db
->transaction_commit(db
);
8480 printf(__location__
"transaction_commit failed\n");
8490 * Just a dummy test to be run under a debugger. There's no real way
8491 * to inspect the tevent_select specific function from outside of
8495 static bool run_local_tevent_select(int dummy
)
8497 struct tevent_context
*ev
;
8498 struct tevent_fd
*fd1
, *fd2
;
8499 bool result
= false;
8501 ev
= tevent_context_init_byname(NULL
, "select");
8503 d_fprintf(stderr
, "tevent_context_init_byname failed\n");
8507 fd1
= tevent_add_fd(ev
, ev
, 2, 0, NULL
, NULL
);
8509 d_fprintf(stderr
, "tevent_add_fd failed\n");
8512 fd2
= tevent_add_fd(ev
, ev
, 3, 0, NULL
, NULL
);
8514 d_fprintf(stderr
, "tevent_add_fd failed\n");
8519 fd2
= tevent_add_fd(ev
, ev
, 1, 0, NULL
, NULL
);
8521 d_fprintf(stderr
, "tevent_add_fd failed\n");
8531 static double create_procs(bool (*fn
)(int), bool *result
)
8534 volatile pid_t
*child_status
;
8535 volatile bool *child_status_out
;
8538 struct timeval start
;
8542 child_status
= (volatile pid_t
*)shm_setup(sizeof(pid_t
)*nprocs
);
8543 if (!child_status
) {
8544 printf("Failed to setup shared memory\n");
8548 child_status_out
= (volatile bool *)shm_setup(sizeof(bool)*nprocs
);
8549 if (!child_status_out
) {
8550 printf("Failed to setup result status shared memory\n");
8554 for (i
= 0; i
< nprocs
; i
++) {
8555 child_status
[i
] = 0;
8556 child_status_out
[i
] = True
;
8559 start
= timeval_current();
8561 for (i
=0;i
<nprocs
;i
++) {
8564 pid_t mypid
= getpid();
8565 sys_srandom(((int)mypid
) ^ ((int)time(NULL
)));
8567 slprintf(myname
,sizeof(myname
),"CLIENT%d", i
);
8570 if (torture_open_connection(¤t_cli
, i
)) break;
8572 printf("pid %d failed to start\n", (int)getpid());
8578 child_status
[i
] = getpid();
8580 while (child_status
[i
] && timeval_elapsed(&start
) < 5) smb_msleep(2);
8582 child_status_out
[i
] = fn(i
);
8589 for (i
=0;i
<nprocs
;i
++) {
8590 if (child_status
[i
]) synccount
++;
8592 if (synccount
== nprocs
) break;
8594 } while (timeval_elapsed(&start
) < 30);
8596 if (synccount
!= nprocs
) {
8597 printf("FAILED TO START %d CLIENTS (started %d)\n", nprocs
, synccount
);
8599 return timeval_elapsed(&start
);
8602 /* start the client load */
8603 start
= timeval_current();
8605 for (i
=0;i
<nprocs
;i
++) {
8606 child_status
[i
] = 0;
8609 printf("%d clients started\n", nprocs
);
8611 for (i
=0;i
<nprocs
;i
++) {
8612 while (waitpid(0, &status
, 0) == -1 && errno
== EINTR
) /* noop */ ;
8617 for (i
=0;i
<nprocs
;i
++) {
8618 if (!child_status_out
[i
]) {
8622 return timeval_elapsed(&start
);
8625 #define FLAG_MULTIPROC 1
8632 {"FDPASS", run_fdpasstest
, 0},
8633 {"LOCK1", run_locktest1
, 0},
8634 {"LOCK2", run_locktest2
, 0},
8635 {"LOCK3", run_locktest3
, 0},
8636 {"LOCK4", run_locktest4
, 0},
8637 {"LOCK5", run_locktest5
, 0},
8638 {"LOCK6", run_locktest6
, 0},
8639 {"LOCK7", run_locktest7
, 0},
8640 {"LOCK8", run_locktest8
, 0},
8641 {"LOCK9", run_locktest9
, 0},
8642 {"UNLINK", run_unlinktest
, 0},
8643 {"BROWSE", run_browsetest
, 0},
8644 {"ATTR", run_attrtest
, 0},
8645 {"TRANS2", run_trans2test
, 0},
8646 {"MAXFID", run_maxfidtest
, FLAG_MULTIPROC
},
8647 {"TORTURE",run_torture
, FLAG_MULTIPROC
},
8648 {"RANDOMIPC", run_randomipc
, 0},
8649 {"NEGNOWAIT", run_negprot_nowait
, 0},
8650 {"NBENCH", run_nbench
, 0},
8651 {"NBENCH2", run_nbench2
, 0},
8652 {"OPLOCK1", run_oplock1
, 0},
8653 {"OPLOCK2", run_oplock2
, 0},
8654 {"OPLOCK4", run_oplock4
, 0},
8655 {"DIR", run_dirtest
, 0},
8656 {"DIR1", run_dirtest1
, 0},
8657 {"DIR-CREATETIME", run_dir_createtime
, 0},
8658 {"DENY1", torture_denytest1
, 0},
8659 {"DENY2", torture_denytest2
, 0},
8660 {"TCON", run_tcon_test
, 0},
8661 {"TCONDEV", run_tcon_devtype_test
, 0},
8662 {"RW1", run_readwritetest
, 0},
8663 {"RW2", run_readwritemulti
, FLAG_MULTIPROC
},
8664 {"RW3", run_readwritelarge
, 0},
8665 {"RW-SIGNING", run_readwritelarge_signtest
, 0},
8666 {"OPEN", run_opentest
, 0},
8667 {"POSIX", run_simple_posix_open_test
, 0},
8668 {"POSIX-APPEND", run_posix_append
, 0},
8669 {"CASE-INSENSITIVE-CREATE", run_case_insensitive_create
, 0},
8670 {"ASYNC-ECHO", run_async_echo
, 0},
8671 { "UID-REGRESSION-TEST", run_uid_regression_test
, 0},
8672 { "SHORTNAME-TEST", run_shortname_test
, 0},
8673 { "ADDRCHANGE", run_addrchange
, 0},
8675 {"OPENATTR", run_openattrtest
, 0},
8677 {"XCOPY", run_xcopy
, 0},
8678 {"RENAME", run_rename
, 0},
8679 {"DELETE", run_deletetest
, 0},
8680 {"DELETE-LN", run_deletetest_ln
, 0},
8681 {"PROPERTIES", run_properties
, 0},
8682 {"MANGLE", torture_mangle
, 0},
8683 {"MANGLE1", run_mangle1
, 0},
8684 {"W2K", run_w2ktest
, 0},
8685 {"TRANS2SCAN", torture_trans2_scan
, 0},
8686 {"NTTRANSSCAN", torture_nttrans_scan
, 0},
8687 {"UTABLE", torture_utable
, 0},
8688 {"CASETABLE", torture_casetable
, 0},
8689 {"ERRMAPEXTRACT", run_error_map_extract
, 0},
8690 {"PIPE_NUMBER", run_pipe_number
, 0},
8691 {"TCON2", run_tcon2_test
, 0},
8692 {"IOCTL", torture_ioctl_test
, 0},
8693 {"CHKPATH", torture_chkpath_test
, 0},
8694 {"FDSESS", run_fdsesstest
, 0},
8695 { "EATEST", run_eatest
, 0},
8696 { "SESSSETUP_BENCH", run_sesssetup_bench
, 0},
8697 { "CHAIN1", run_chain1
, 0},
8698 { "CHAIN2", run_chain2
, 0},
8699 { "WINDOWS-WRITE", run_windows_write
, 0},
8700 { "NTTRANS-CREATE", run_nttrans_create
, 0},
8701 { "CLI_ECHO", run_cli_echo
, 0},
8702 { "GETADDRINFO", run_getaddrinfo_send
, 0},
8703 { "TLDAP", run_tldap
},
8704 { "STREAMERROR", run_streamerror
},
8705 { "NOTIFY-BENCH", run_notify_bench
},
8706 { "BAD-NBT-SESSION", run_bad_nbt_session
},
8707 { "SMB-ANY-CONNECT", run_smb_any_connect
},
8708 { "NOTIFY-ONLINE", run_notify_online
},
8709 { "SMB2-BASIC", run_smb2_basic
},
8710 { "LOCAL-SUBSTITUTE", run_local_substitute
, 0},
8711 { "LOCAL-GENCACHE", run_local_gencache
, 0},
8712 { "LOCAL-TALLOC-DICT", run_local_talloc_dict
, 0},
8713 { "LOCAL-BASE64", run_local_base64
, 0},
8714 { "LOCAL-RBTREE", run_local_rbtree
, 0},
8715 { "LOCAL-MEMCACHE", run_local_memcache
, 0},
8716 { "LOCAL-STREAM-NAME", run_local_stream_name
, 0},
8717 { "LOCAL-WBCLIENT", run_local_wbclient
, 0},
8718 { "LOCAL-string_to_sid", run_local_string_to_sid
, 0},
8719 { "LOCAL-binary_to_sid", run_local_binary_to_sid
, 0},
8720 { "LOCAL-DBTRANS", run_local_dbtrans
, 0},
8721 { "LOCAL-TEVENT-SELECT", run_local_tevent_select
, 0},
8722 { "LOCAL-CONVERT-STRING", run_local_convert_string
, 0},
8727 /****************************************************************************
8728 run a specified test or "ALL"
8729 ****************************************************************************/
8730 static bool run_test(const char *name
)
8737 if (strequal(name
,"ALL")) {
8738 for (i
=0;torture_ops
[i
].name
;i
++) {
8739 run_test(torture_ops
[i
].name
);
8744 for (i
=0;torture_ops
[i
].name
;i
++) {
8745 fstr_sprintf(randomfname
, "\\XX%x",
8746 (unsigned)random());
8748 if (strequal(name
, torture_ops
[i
].name
)) {
8750 printf("Running %s\n", name
);
8751 if (torture_ops
[i
].flags
& FLAG_MULTIPROC
) {
8752 t
= create_procs(torture_ops
[i
].fn
, &result
);
8755 printf("TEST %s FAILED!\n", name
);
8758 struct timeval start
;
8759 start
= timeval_current();
8760 if (!torture_ops
[i
].fn(0)) {
8762 printf("TEST %s FAILED!\n", name
);
8764 t
= timeval_elapsed(&start
);
8766 printf("%s took %g secs\n\n", name
, t
);
8771 printf("Did not find a test named %s\n", name
);
8779 static void usage(void)
8783 printf("WARNING samba4 test suite is much more complete nowadays.\n");
8784 printf("Please use samba4 torture.\n\n");
8786 printf("Usage: smbtorture //server/share <options> TEST1 TEST2 ...\n");
8788 printf("\t-d debuglevel\n");
8789 printf("\t-U user%%pass\n");
8790 printf("\t-k use kerberos\n");
8791 printf("\t-N numprocs\n");
8792 printf("\t-n my_netbios_name\n");
8793 printf("\t-W workgroup\n");
8794 printf("\t-o num_operations\n");
8795 printf("\t-O socket_options\n");
8796 printf("\t-m maximum protocol\n");
8797 printf("\t-L use oplocks\n");
8798 printf("\t-c CLIENT.TXT specify client load file for NBENCH\n");
8799 printf("\t-A showall\n");
8800 printf("\t-p port\n");
8801 printf("\t-s seed\n");
8802 printf("\t-b unclist_filename specify multiple shares for multiple connections\n");
8803 printf("\t-f filename filename to test\n");
8806 printf("tests are:");
8807 for (i
=0;torture_ops
[i
].name
;i
++) {
8808 printf(" %s", torture_ops
[i
].name
);
8812 printf("default test is ALL\n");
8817 /****************************************************************************
8819 ****************************************************************************/
8820 int main(int argc
,char *argv
[])
8826 bool correct
= True
;
8827 TALLOC_CTX
*frame
= talloc_stackframe();
8828 int seed
= time(NULL
);
8830 #ifdef HAVE_SETBUFFER
8831 setbuffer(stdout
, NULL
, 0);
8834 setup_logging("smbtorture", DEBUG_STDOUT
);
8838 if (is_default_dyn_CONFIGFILE()) {
8839 if(getenv("SMB_CONF_PATH")) {
8840 set_dyn_CONFIGFILE(getenv("SMB_CONF_PATH"));
8843 lp_load(get_dyn_CONFIGFILE(),True
,False
,False
,True
);
8850 for(p
= argv
[1]; *p
; p
++)
8854 if (strncmp(argv
[1], "//", 2)) {
8858 fstrcpy(host
, &argv
[1][2]);
8859 p
= strchr_m(&host
[2],'/');
8864 fstrcpy(share
, p
+1);
8866 fstrcpy(myname
, get_myname(talloc_tos()));
8868 fprintf(stderr
, "Failed to get my hostname.\n");
8872 if (*username
== 0 && getenv("LOGNAME")) {
8873 fstrcpy(username
,getenv("LOGNAME"));
8879 fstrcpy(workgroup
, lp_workgroup());
8881 while ((opt
= getopt(argc
, argv
, "p:hW:U:n:N:O:o:m:Ll:d:Aec:ks:b:B:f:"))
8885 port_to_use
= atoi(optarg
);
8888 seed
= atoi(optarg
);
8891 fstrcpy(workgroup
,optarg
);
8894 max_protocol
= interpret_protocol(optarg
, max_protocol
);
8897 nprocs
= atoi(optarg
);
8900 torture_numops
= atoi(optarg
);
8903 lp_set_cmdline("log level", optarg
);
8912 local_path
= optarg
;
8915 torture_showall
= True
;
8918 fstrcpy(myname
, optarg
);
8921 client_txt
= optarg
;
8928 use_kerberos
= True
;
8930 d_printf("No kerberos support compiled in\n");
8936 fstrcpy(username
,optarg
);
8937 p
= strchr_m(username
,'%');
8940 fstrcpy(password
, p
+1);
8945 fstrcpy(multishare_conn_fname
, optarg
);
8946 use_multishare_conn
= True
;
8949 torture_blocksize
= atoi(optarg
);
8952 test_filename
= SMB_STRDUP(optarg
);
8955 printf("Unknown option %c (%d)\n", (char)opt
, opt
);
8960 d_printf("using seed %d\n", seed
);
8964 if(use_kerberos
&& !gotuser
) gotpass
= True
;
8967 p
= getpass("Password:");
8969 fstrcpy(password
, p
);
8974 printf("host=%s share=%s user=%s myname=%s\n",
8975 host
, share
, username
, myname
);
8977 if (argc
== optind
) {
8978 correct
= run_test("ALL");
8980 for (i
=optind
;i
<argc
;i
++) {
8981 if (!run_test(argv
[i
])) {